From 548331bbefc18d8667f9cc168fbe159f2daf1184 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Tue, 27 Sep 2016 23:33:55 +0200 Subject: [PATCH] Updated according to new ADC driver API Updated Comments Updated according to new header files Updated use of uprintf and UART* instead of snprintf + serial_write(0, ...) --- adc/main.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/adc/main.c b/adc/main.c index a8edb7c..e4d86a9 100644 --- a/adc/main.c +++ b/adc/main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/adc/main.c + * apps/base/adc/main.c * * ADC example * @@ -22,17 +22,13 @@ *************************************************************************** */ -#include -#include "core/lpc_regs_12xx.h" -#include "core/lpc_core_cm0.h" -#include "core/pio.h" #include "core/system.h" #include "core/systick.h" -#include "lib/stdio.h" +#include "core/pio.h" +#include "drivers/adc.h" #include "drivers/serial.h" -#include "drivers/gpio.h" #include "extdrv/status_led.h" -#include "drivers/adc.h" +#include "lib/stdio.h" #define MODULE_VERSION 0x04 @@ -69,10 +65,10 @@ const struct pio status_led_red = LPC_GPIO_1_5; /***************************************************************************** */ /* This will display the integer value read on the ADC, between 0 and 1024. - * ADC must be initialised prior to calls to adc_display() (it means that adc_on() + * ADC must be initialised prior to calls to adc_display() (it means that adc_on(NULL) * must be called before using this function. * adc_num is an ADC channel number (integer between 0 and 7) - * use LPC_ADC_NUM(x) for channel selection. + * use LPC_ADC(x) for channel selection. * returns ADC convertion value or negative value on error. */ int adc_display(int adc_num, int uart_num) @@ -80,7 +76,7 @@ int adc_display(int adc_num, int uart_num) uint16_t val = 0; int ret = 0; - adc_start_convertion_once(adc_num, 0); + adc_start_convertion_once(adc_num, LPC_ADC_SEQ(0), 0); msleep(10); ret = adc_get_value(&val, adc_num); if (ret < 0) { @@ -93,17 +89,17 @@ int adc_display(int adc_num, int uart_num) /* Display the temperature computed from adc convertion of the voltage output of * a TMP36 analog temperature sensor - * ADC must be initialised prior to calls to TMP36_display() (it means that adc_on() + * ADC must be initialised prior to calls to TMP36_display() (it means that adc_on(NULL) * must be called before using this function. * adc_num is an ADC channel number (integer between 0 and 7) - * use LPC_ADC_NUM(x) for channel selection. + * use LPC_ADC(x) for channel selection. */ void TMP36_display(int adc_num, int uart_num) { uint16_t val = 0; int ret = 0; - adc_start_convertion_once(adc_num, 0); + adc_start_convertion_once(adc_num, LPC_ADC_SEQ(0), 0); msleep(8); ret = adc_get_value(&val, adc_num); if (ret == 0) { @@ -122,15 +118,10 @@ void system_init() { /* Stop the watchdog */ startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */ - - /* Note: Brown-Out detection must be powered to operate the ADC. adc_on() will power - * it back on if called after system_init() */ - system_brown_out_detection_config(0); system_set_default_power_state(); clock_config(SELECTED_FREQ); set_pins(common_pins); set_pins(adc_pins); - gpio_on(); status_led_config(&status_led_green, &status_led_red); /* System tick timer MUST be configured and running in order to use the sleeping * functions */ @@ -142,29 +133,28 @@ void system_init() * will be used when it's not overridden here. * Note : The default one does a simple infinite loop. If the watchdog is deactivated * the system will hang. + * An alternative would be to perform soft reset of the micro-controller. */ void fault_info(const char* name, uint32_t len) { - serial_write(0, name, len); - /* Wait for end of Tx */ - serial_flush(0); - /* FIXME : Perform soft reset of the micro-controller ! */ + uprintf(UART0, name); while (1); } /***************************************************************************** */ -int main(void) { +int main(void) +{ system_init(); - uart_on(0, 115200, NULL); - adc_on(); + uart_on(UART0, 115200, NULL); + adc_on(NULL); while (1) { chenillard(500); /* ADC Test */ - adc_display(LPC_ADC_NUM(0), 0); - TMP36_display(LPC_ADC_NUM(1), 0); + adc_display(LPC_ADC(0), 0); + TMP36_display(LPC_ADC(1), 0); } return 0; } -- 2.43.0