From 884c388e8740e55a31e93e46abc845ed203c9045 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Mon, 26 Sep 2016 17:59:17 +0200 Subject: [PATCH] ADC driver fixes and (small) improvements --- drivers/adc.c | 10 ++++++---- include/drivers/adc.h | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/adc.c b/drivers/adc.c index bae9d88..1306d68 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -61,12 +61,12 @@ void ADC_OVR_Handler(void) __attribute__ ((alias ("ADC_Handler"))); * Retuen 1 if the value is an old one * Return 2 if an overrun occured */ -int adc_get_value(uint16_t * val, unsigned int channel) +int adc_get_value(uint16_t * val, uint8_t channel) { struct lpc_adc* adc = LPC_ADC; uint32_t save_reg = 0; - if (channel > NB_ADC_CHANNELS) + if (channel >= NB_ADC_CHANNELS) return -1; /* Save the whole register as some bits are cleared when register is read */ @@ -83,7 +83,7 @@ int adc_get_value(uint16_t * val, unsigned int channel) } /* Start a conversion on the given channel (0 to 7) */ -void adc_start_convertion_once(unsigned int channel, uint8_t seq_num, int use_int) +void adc_start_convertion_once(uint8_t channel, uint8_t seq_num, uint8_t use_int) { struct lpc_adc* adc = LPC_ADC; uint32_t reg_val = 0; @@ -155,7 +155,7 @@ void adc_stop_burst_conversion(uint8_t seq_num) * some signals, or on timer for burst conversions. */ void adc_prepare_conversion_on_event(uint16_t channels, uint8_t event, uint8_t seq_num, - int use_int, uint32_t mode) + uint8_t use_int, uint32_t mode) { struct lpc_adc* adc = LPC_ADC; uint32_t reg_val = 0; @@ -284,6 +284,8 @@ void adc_off(void) NVIC_DisableIRQ(ADC_SEQB_IRQ); NVIC_DisableIRQ(ADC_THCMP_IRQ); NVIC_DisableIRQ(ADC_OVR_IRQ); + /* Remove callback */ + adc_int_callback = NULL; /* Power Down ADC */ sys_config->powerdown_run_cfg |= LPC_POWER_DOWN_ADC; /* Remove clock from ADC block */ diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 7590732..0b682ef 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -48,16 +48,16 @@ * Return 1 if the value is an old one. * Return 2 if an overrun occured */ -int adc_get_value(uint16_t * val, unsigned int channel); +int adc_get_value(uint16_t * val, uint8_t channel); -/* Start a conversion on the given channel (0 to 7) +/* Start a conversion on the given channel * Unsupported yet : Set use_int to 1 to have your interrupt callback called upon conversion done. */ -void adc_start_convertion_once(unsigned int channel, uint8_t seq_num, int use_int); +void adc_start_convertion_once(uint8_t channel, uint8_t seq_num, uint8_t use_int); /* Start burst conversions. * channels is a bit mask of requested channels. - * Use LPC_ADC_CHANNEL(x) (x = 0 .. 7) for channels selection. + * Use LPC_ADC_CHANNEL(x) (x = 0 .. 11) for channels selection. */ void adc_start_burst_conversion(uint16_t channels, uint8_t seq_num); void adc_stop_burst_conversion(uint8_t seq_num); @@ -75,7 +75,7 @@ enum lpc_adc_start_conv_events { * some signals, or on timer for burst conversions. */ void adc_prepare_conversion_on_event(uint16_t channels, uint8_t seq_num, uint8_t event, - int use_int, uint32_t mode); + uint8_t use_int, uint32_t mode); /* Software trigger of the given configured sequence */ void adc_trigger_sequence_conversion(uint8_t seq_num); -- 2.43.0