From bbe8caa95f0c67deaef8b76b8a1c1cc7def8871a Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 18 Aug 2021 10:15:28 +0200 Subject: [PATCH] ROM UART test app --- rom_uart/Makefile | 12 +++++ rom_uart/main.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 rom_uart/Makefile create mode 100644 rom_uart/main.c diff --git a/rom_uart/Makefile b/rom_uart/Makefile new file mode 100644 index 0000000..097ff94 --- /dev/null +++ b/rom_uart/Makefile @@ -0,0 +1,12 @@ +# Makefile for example apps + +MODULE = $(shell basename $(shell cd .. && pwd && cd -)) +NAME = $(shell basename $(CURDIR)) + +.PHONY: $(NAME).bin +$(NAME).bin: + @make -C ../../.. --no-print-directory NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@ + +clean mrproper: + @make -C ../../.. --no-print-directory $@ + diff --git a/rom_uart/main.c b/rom_uart/main.c new file mode 100644 index 0000000..30c788a --- /dev/null +++ b/rom_uart/main.c @@ -0,0 +1,125 @@ +/**************************************************************************** + * rom_uart/main.c + * + * Simple UART example + * + * Copyright 2020 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +#include "lib/stdint.h" +#include "core/system.h" +#include "core/systick.h" +#include "core/pio.h" +#include "lib/stdio.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" +#include "drivers/adc.h" + + +#define MODULE_VERSION 0x04 +#define MODULE_NAME "E-Xanh Gardener Sensor" + + +#define SELECTED_FREQ FREQ_SEL_36MHz + +/***************************************************************************** */ +/* Pins configuration */ +/* pins blocks are passed to set_pins() for pins configuration. + * Unused pin blocks can be removed safely with the corresponding set_pins() call + * All pins blocks may be safelly merged in a single block for single set_pins() call.. + */ +const struct pio_config common_pins[] = { + /* UART 0 */ + { LPC_GPIO_0_0, LPC_UART0_RX, 0 }, + { LPC_GPIO_0_4, LPC_UART0_TX, 0 }, + /* ADC */ + { LPC_ADC_AD9_PIO_0_17, LPC_FIXED, 0 }, + { LPC_ADC_AD10_PIO_0_13, LPC_FIXED, 0 }, + ARRAY_LAST_PIO, +}; + + +/***************************************************************************** */ +/* 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() + * must be called before using this function. + * adc_num is an ADC channel number (integer between 0 and 7) + * 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) +{ + uint16_t val = 0; + int ret = 0; + + ret = adc_get_value(&val, adc_num); + if (ret < 0) { + return ret; + } else { + uprintf(uart_num, "ADC(%d): %d (raw: 0x%04x, ret: %d)\n", adc_num, val, val, ret); + } + return val; +} + +/***************************************************************************** */ +void system_init() +{ + system_set_default_power_state(); + clock_config(SELECTED_FREQ); + set_pins(common_pins); + gpio_on(); + /* System tick timer MUST be configured and running in order to use the sleeping + * functions */ + systick_timer_on(1); /* 1ms */ + systick_start(); +} + +/* Define our fault handler. */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(UART0, 115200, NULL); + + /* ADC Setup */ + adc_on(NULL); + adc_prepare_conversion_on_event((ADC_MCH(9) | ADC_MCH(10)), + LPC_ADC_START_CONV_SOFT, LPC_ADC_SEQA, 0, 0); + + + while (1) { + /* ADC Test */ + adc_trigger_sequence_conversion(LPC_ADC_SEQA); + msleep(10); + adc_display(LPC_ADC(9), UART0); + adc_display(LPC_ADC(10), UART0); + } + return 0; +} + + + -- 2.43.0