diff options
Diffstat (limited to 'drivers/avr/analog.c')
| -rw-r--r-- | drivers/avr/analog.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/avr/analog.c b/drivers/avr/analog.c index 9b8397b93..8d299ffdb 100644 --- a/drivers/avr/analog.c +++ b/drivers/avr/analog.c | |||
| @@ -97,10 +97,11 @@ uint8_t pinToMux(pin_t pin) { | |||
| 97 | #endif | 97 | #endif |
| 98 | // clang-format on | 98 | // clang-format on |
| 99 | } | 99 | } |
| 100 | return 0; | ||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | int16_t adc_read(uint8_t mux) { | 103 | int16_t adc_read(uint8_t mux) { |
| 103 | uint8_t low; | 104 | uint16_t low; |
| 104 | 105 | ||
| 105 | // Enable ADC and configure prescaler | 106 | // Enable ADC and configure prescaler |
| 106 | ADCSRA = _BV(ADEN) | ADC_PRESCALER; | 107 | ADCSRA = _BV(ADEN) | ADC_PRESCALER; |
| @@ -128,5 +129,10 @@ int16_t adc_read(uint8_t mux) { | |||
| 128 | // Must read LSB first | 129 | // Must read LSB first |
| 129 | low = ADCL; | 130 | low = ADCL; |
| 130 | // Must read MSB only once! | 131 | // Must read MSB only once! |
| 131 | return (ADCH << 8) | low; | 132 | low |= (ADCH << 8); |
| 133 | |||
| 134 | // turn off the ADC | ||
| 135 | ADCSRA &= ~(1 << ADEN); | ||
| 136 | |||
| 137 | return low; | ||
| 132 | } | 138 | } |
