]> rtime.felk.cvut.cz Git - hydro.git/blob - app/hydro/adc.c
e9aeaf59ddf2f975a6b0c712e9348a94a5c780ce
[hydro.git] / app / hydro / adc.c
1
2 #include "adc.h"
3
4 int init_adc(){
5 #ifndef OS_POSIX
6     // Set P0.22 and P0.23 as AIN0 -> AD0.1 and AD0.2 (pinsel value 01)
7     PINSEL1=(PINSEL1 & ~(0xF << (22*2-32))) | (1 << (22*2-32)) | (1 << (23*2-32));
8     // Set P0.24 and P0.25 as AIN1 -> AD0.1 and AD0.2 (pinsel value 01)
9     PINSEL1=(PINSEL1 & ~(0xF << (24*2-32))) | (1 << (24*2-32)) | (1 << (25*2-32));
10     // Setting of AD control register
11     AD0CR=__val2mfld(ADCR_SEL,3) | __val2mfld(ADCR_CLKDIV,255) | (ADCR_BURST*1) | (ADCR_PDN*1);
12     // Interupt eneable bit
13     AD0INTEN=0;
14 #endif
15     return 0;
16 }
17
18 int get_adc(adc_stat_t * adcst){
19 #ifndef OS_POSIX
20     // Read DATA
21     adcst->temp =__mfld2val(ADDR_RESULT, AD0DR0);
22     adcst->hum =__mfld2val(ADDR_RESULT, AD0DR1);
23 #endif
24
25     return 0;
26 }
27
28