From: Nathael Pajani Date: Tue, 27 Sep 2016 22:10:53 +0000 (+0200) Subject: Changes to ADC API X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=1cae25e749485e529615fa4f6321f8f1619aa694;p=soft%2Flpc82x%2Fcore Changes to ADC API --- diff --git a/drivers/adc.c b/drivers/adc.c index 1306d68..ae9cdb4 100644 --- a/drivers/adc.c +++ b/drivers/adc.c @@ -41,7 +41,7 @@ void (*adc_int_callback)(uint32_t) = NULL; void ADC_Handler(void) { - volatile struct lpc_adc* adc = LPC_ADC; + volatile struct lpc_adc* adc = LPC_ADC_REGS; uint32_t flags = adc->flags; if (adc_int_callback != NULL) { @@ -57,13 +57,13 @@ void ADC_OVR_Handler(void) __attribute__ ((alias ("ADC_Handler"))); * This function reads the conversion value directly in the data register and * always returns a value. * Return 0 if the value is a new one and no overrun occured. - * Return -1 if channel does not exist + * Return -EINVAL if channel does not exist * Retuen 1 if the value is an old one * Return 2 if an overrun occured */ int adc_get_value(uint16_t * val, uint8_t channel) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; uint32_t save_reg = 0; if (channel >= NB_ADC_CHANNELS) @@ -85,7 +85,7 @@ int adc_get_value(uint16_t * val, uint8_t channel) /* Start a conversion on the given channel (0 to 7) */ void adc_start_convertion_once(uint8_t channel, uint8_t seq_num, uint8_t use_int) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; uint32_t reg_val = 0; if (channel >= NB_ADC_CHANNELS) { @@ -96,12 +96,12 @@ void adc_start_convertion_once(uint8_t channel, uint8_t seq_num, uint8_t use_int } /* Set conversion channel bit */ - reg_val = LPC_ADC_CHANNEL(channel); + reg_val = ADC_MCH(channel); /* Use of interrupts for the specified channel ? */ if (use_int) { /* Set interrupt Bit */ - adc->int_en = LPC_ADC_CHANNEL(channel); + adc->int_en = ADC_MCH(channel); } else { adc->int_en = 0; } @@ -114,11 +114,11 @@ 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 ADC_MCH(x) (x = 0 .. 7) for channels selection. */ void adc_start_burst_conversion(uint16_t channels, uint8_t seq_num) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; uint32_t reg_val = 0; if (seq_num >= NB_ADC_SEQUENCES) { @@ -126,7 +126,7 @@ void adc_start_burst_conversion(uint16_t channels, uint8_t seq_num) } /* Set conversion channel bits and burst mode */ - reg_val = (channels & LPC_ADC_CHANNEL_MASK); + reg_val = (channels & ADC_MCH_MASK); reg_val |= LPC_ADC_BURST; /* Do not use of interrupts in burst mode. */ @@ -143,7 +143,7 @@ void adc_start_burst_conversion(uint16_t channels, uint8_t seq_num) } void adc_stop_burst_conversion(uint8_t seq_num) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; if (seq_num >= NB_ADC_SEQUENCES) { return; } @@ -157,7 +157,7 @@ void adc_stop_burst_conversion(uint8_t seq_num) void adc_prepare_conversion_on_event(uint16_t channels, uint8_t event, uint8_t seq_num, uint8_t use_int, uint32_t mode) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; uint32_t reg_val = 0; if (seq_num >= NB_ADC_SEQUENCES) { @@ -165,7 +165,7 @@ void adc_prepare_conversion_on_event(uint16_t channels, uint8_t event, uint8_t s } /* Set conversion channel bits and burst mode */ - reg_val |= (channels & LPC_ADC_CHANNEL_MASK); + reg_val |= (channels & ADC_MCH_MASK); /* Set conversion condition bits */ switch (event) { case LPC_ADC_START_CONV_ADC_PINTRIG_0: @@ -202,7 +202,7 @@ void adc_prepare_conversion_on_event(uint16_t channels, uint8_t event, uint8_t s /* Software trigger of the given configured sequence */ void adc_trigger_sequence_conversion(uint8_t seq_num) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; if (seq_num >= NB_ADC_SEQUENCES) { return; @@ -220,7 +220,7 @@ void adc_trigger_sequence_conversion(uint8_t seq_num) */ void adc_set_low_power(int lowpower_en) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; if (lowpower_en) { adc->ctrl |= LPC_ADC_LOW_POWER_EN; } else { @@ -230,7 +230,7 @@ void adc_set_low_power(int lowpower_en) void adc_clk_update(void) { - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; uint32_t main_clock = get_main_clock(); uint32_t clkdiv = 0; @@ -244,7 +244,7 @@ void adc_clk_update(void) void adc_on(void (*adc_callback)(uint32_t)) { struct lpc_sys_config* sys_config = LPC_SYS_CONFIG; - struct lpc_adc* adc = LPC_ADC; + struct lpc_adc* adc = LPC_ADC_REGS; /* Disable ADC Interrupts */ NVIC_DisableIRQ(ADC_SEQA_IRQ); diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 0b682ef..8f74185 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -44,7 +44,7 @@ * This function reads the conversion value directly in the data register and * always returns a value. * Return 0 if the value is a new one and no overrun occured. - * Return -1 if channel does not exist + * Return -EINVAL if channel does not exist * Return 1 if the value is an old one. * Return 2 if an overrun occured */ @@ -57,7 +57,7 @@ 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 .. 11) for channels selection. + * Use ADC_MCH(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); @@ -114,7 +114,7 @@ struct lpc_adc volatile const uint32_t flags; /* 0x068 : A/D Flags Register (R/ ) */ volatile uint32_t trim; /* 0x06C : A/D Trim Register (R/W) */ }; -#define LPC_ADC ((struct lpc_adc *) LPC_ADC_BASE) +#define LPC_ADC_REGS ((struct lpc_adc *) LPC_ADC_BASE) /* ADC Control register bits */ #define LPC_ADC_CLK_MASK 0x0FF @@ -122,9 +122,9 @@ struct lpc_adc #define LPC_ADC_LOW_POWER_EN (0x01 << 10) #define LPC_ADC_CALIBRATION (0x01 << 30) -/* LPC_ADC_CHANNEL_* are also used for interrupt register */ -#define LPC_ADC_CHANNEL_MASK (0xFFF << 0) -#define LPC_ADC_CHANNEL(x) (0x01 << (x)) +/* ADC_MCH_* are also used for interrupt register */ +#define ADC_MCH_MASK (0xFFF << 0) +#define ADC_MCH(x) (0x01 << (x)) #define LPC_ADC_START_CONV_EVENT(x) (((x) & 0x7) << 12) #define LPC_ADC_START_EDGE_FALLING (0x0 << 18) #define LPC_ADC_START_EDGE_RISING (0x1 << 18) @@ -154,7 +154,7 @@ struct lpc_adc #define LPC_ADC_THRESHOLD_LEVEL_1 1 /* For more readability when selecting a channel number */ -#define LPC_ADC_NUM(x) (x) +#define LPC_ADC(x) (x)