diff options
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/pcf50606.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/firmware/drivers/pcf50606.c b/firmware/drivers/pcf50606.c index 6a98b0d021..8592c005fe 100644 --- a/firmware/drivers/pcf50606.c +++ b/firmware/drivers/pcf50606.c | |||
@@ -62,3 +62,26 @@ void pcf50606_reset_timeout(void) | |||
62 | pcf50606_write(PCF5060X_OOCC1, pcf50606_read(PCF5060X_OOCC1) | TOTRST); | 62 | pcf50606_write(PCF5060X_OOCC1, pcf50606_read(PCF5060X_OOCC1) | TOTRST); |
63 | restore_irq(level); | 63 | restore_irq(level); |
64 | } | 64 | } |
65 | |||
66 | void pcf50606_read_adc(int adc, short* res1, short* res2) | ||
67 | { | ||
68 | int adcs1 = 0, adcs2 = 0, adcs3 = 0; | ||
69 | |||
70 | int level = disable_irq_save(); | ||
71 | |||
72 | pcf50606_write(PCF5060X_ADCC2, (adc<<1) | 1); /* ADC start */ | ||
73 | |||
74 | do { | ||
75 | adcs2 = pcf50606_read(PCF5060X_ADCS2); | ||
76 | } while (!(adcs2 & 0x80)); /* Busy wait on ADCRDY flag */ | ||
77 | |||
78 | adcs1 = pcf50606_read(PCF5060X_ADCS1); | ||
79 | if (res2 != NULL) adcs3 = pcf50606_read(PCF5060X_ADCS3); | ||
80 | |||
81 | pcf50606_write(PCF5060X_ADCC2, 0); /* ADC stop */ | ||
82 | |||
83 | restore_interrupt(level); | ||
84 | |||
85 | if (res1 != NULL) *res1 = (adcs1 << 2) | (adcs2 & 3); | ||
86 | if (res2 != NULL) *res2 = (adcs3 << 2) | ((adcs2 & 0xC) >> 2); | ||
87 | } | ||