diff options
Diffstat (limited to 'src/lpc176x/adc.c')
-rw-r--r-- | src/lpc176x/adc.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/lpc176x/adc.c b/src/lpc176x/adc.c index 4ea4e815..e89d73a4 100644 --- a/src/lpc176x/adc.c +++ b/src/lpc176x/adc.c @@ -36,6 +36,22 @@ static struct { enum { ADC_DONE=0x0100 }; +// ADC hardware irq handler +void __visible +ADC_IRQHandler(void) +{ + uint32_t pos = adc_status.pos, chan = adc_status.chan & 0xff; + uint32_t result = (&LPC_ADC->ADDR0)[chan]; + if (pos >= ARRAY_SIZE(adc_status.samples)) + // All samples complete + return; + if (pos >= ARRAY_SIZE(adc_status.samples) - 2) + // Turn off burst mode + LPC_ADC->ADCR = adc_status.adcr | (1 << chan); + adc_status.samples[pos++] = (result >> 4) & 0x0fff; + adc_status.pos = pos; +} + struct gpio_adc gpio_adc_setup(uint8_t pin) { @@ -64,22 +80,6 @@ gpio_adc_setup(uint8_t pin) return (struct gpio_adc){ .chan = chan }; } -// ADC hardware irq handler -void __visible -ADC_IRQHandler(void) -{ - uint32_t pos = adc_status.pos, chan = adc_status.chan & 0xff; - uint32_t result = (&LPC_ADC->ADDR0)[chan]; - if (pos >= ARRAY_SIZE(adc_status.samples)) - // All samples complete - return; - if (pos >= ARRAY_SIZE(adc_status.samples) - 2) - // Turn off burst mode - LPC_ADC->ADCR = adc_status.adcr | (1 << chan); - adc_status.samples[pos++] = (result >> 4) & 0x0fff; - adc_status.pos = pos; -} - // Try to sample a value. Returns zero if sample ready, otherwise // returns the number of clock ticks the caller should wait before // retrying this function. |