From: Nathael Pajani Date: Wed, 15 Jun 2016 16:41:56 +0000 (+0200) Subject: Initial commit Most of the code received basic testing. Most of the code comes from... X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=87a84af52ae298cee0db7c165fd5fce143651dd1;p=soft%2Flpc82x%2Fexamples Initial commit Most of the code received basic testing. Most of the code comes from the LPC1224 support code. --- 87a84af52ae298cee0db7c165fd5fce143651dd1 diff --git a/adc/Makefile b/adc/Makefile new file mode 100644 index 0000000..097ff94 --- /dev/null +++ b/adc/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/adc/README b/adc/README new file mode 100644 index 0000000..236b32a --- /dev/null +++ b/adc/README @@ -0,0 +1,28 @@ +ADC Example + +Copyright 2016 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 . + * + *************************************************************************** */ + +This example shows the support of the internal ADC + +The conversion results of channels 9 and 10 are sent on the UART0 serial line +(115200 8n1) at regular intervals. + +Each line displays the decimal and hexadecimal value of the raw conversion +result for one channel. diff --git a/adc/main.c b/adc/main.c new file mode 100644 index 0000000..cbafb64 --- /dev/null +++ b/adc/main.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * adc/main.c + * + * ADC example + * + * Copyright 2013-2014 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 0x01 +#define MODULE_NAME "E-Xanh Gardener" + + +#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_NUM(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((LPC_ADC_CHANNEL(9) | LPC_ADC_CHANNEL(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_NUM(9), UART0); + adc_display(LPC_ADC_NUM(10), UART0); + } + return 0; +} + + + diff --git a/clkout/Makefile b/clkout/Makefile new file mode 100644 index 0000000..097ff94 --- /dev/null +++ b/clkout/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/clkout/README b/clkout/README new file mode 100644 index 0000000..4fd88e4 --- /dev/null +++ b/clkout/README @@ -0,0 +1,23 @@ +CLKOUT Example + +Copyright 2016 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 . + * + *************************************************************************** */ + +This example shows the support of clock output. + diff --git a/clkout/main.c b/clkout/main.c new file mode 100644 index 0000000..06da66f --- /dev/null +++ b/clkout/main.c @@ -0,0 +1,104 @@ +/**************************************************************************** + * clkout/main.c + * + * CLK example + * + * Copyright 2013-2014 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 0x01 +#define MODULE_NAME "E-Xanh Gardener" + + +#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 }, + ARRAY_LAST_PIO, +}; + +const struct pio_config clkout_pins[] = { + { LPC_GPIO_0_1, LPC_CLKOUT, 0 }, + ARRAY_LAST_PIO, +}; + + +void clkout(uint8_t div) +{ + set_pins(clkout_pins); + clkout_on(LPC_CLKOUT_SRC_MAIN_CLK, div); +} + +/***************************************************************************** */ +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); + + /* Configure clkout to main_clock divided by 10 */ + clkout(10); + + while (1) { + msleep(10); + } + return 0; +} + + + diff --git a/gpio_intr/Makefile b/gpio_intr/Makefile new file mode 100644 index 0000000..097ff94 --- /dev/null +++ b/gpio_intr/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/gpio_intr/README b/gpio_intr/README new file mode 100644 index 0000000..ffc6cac --- /dev/null +++ b/gpio_intr/README @@ -0,0 +1,24 @@ +GPIO interrupt Example + +Copyright 2015 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 . + * + *************************************************************************** */ + +This example shows the support of the gpio interrupts from an external button. + +When the ISP button is pressed a message is sent over UART0. diff --git a/gpio_intr/main.c b/gpio_intr/main.c new file mode 100644 index 0000000..3bc4e39 --- /dev/null +++ b/gpio_intr/main.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * gpio_intr/main.c + * + * GPIO interrupt example + * + * Copyright 2013-2014 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 . + * + *************************************************************************** */ + +/* ISP button press send a message on UART0 */ + +#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" + + +#define MODULE_VERSION 0x01 +#define MODULE_NAME "E-Xanh Gardener" + + +#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 }, + /* GPIO */ + { LPC_GPIO_0_12, LPC_GPIO, 0 }, + ARRAY_LAST_PIO, +}; + +const struct pio button = LPC_GPIO_0_12; /* ISP button */ + + +/***************************************************************************** */ +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. This one is not mandatory, the dummy fault handler + * 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. + */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + +uint8_t message_request = 0; +void trigger_message(uint32_t int_num) { + message_request = int_num + 1; +} + + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(0, 115200, NULL); + + /* Activate the message request on Rising edge (button release) */ + set_gpio_callback(trigger_message, &button, EDGE_RISING); + uprintf(UART0, "Config done\n"); + + while (1) { + int delay = 500; + msleep(delay); + if (message_request != 0) { + uprintf(UART0, "Button pressed: %d\n", message_request); + message_request = 0; + } else { + uprintf(UART0, "Nothing in the last %dms\n", delay); + } + } + return 0; +} + + + diff --git a/i2c_temp/Makefile b/i2c_temp/Makefile new file mode 100644 index 0000000..097ff94 --- /dev/null +++ b/i2c_temp/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/i2c_temp/README b/i2c_temp/README new file mode 100644 index 0000000..a4fc804 --- /dev/null +++ b/i2c_temp/README @@ -0,0 +1,27 @@ +TMP101 I2C temperature sensor example + +Copyright 2013 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 . + * + *************************************************************************** */ + +This example shows the support of the TMP101 I2C temperature sensor. + +Periodic temperature conversions (decimal velue and raw conversion value) are +sent on UART0 using the following frame format : +Temp read: 27,3 - raw: 0x1b60. + diff --git a/i2c_temp/main.c b/i2c_temp/main.c new file mode 100644 index 0000000..7a6b9d4 --- /dev/null +++ b/i2c_temp/main.c @@ -0,0 +1,146 @@ +/**************************************************************************** + * i2c_temp/main.c + * + * TMP101 I2C temperature sensor example + * + * Copyright 2013-2014 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/watchdog.h" +#include "core/pio.h" +#include "lib/stdio.h" +#include "drivers/i2c.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" + +#include "extdrv/tmp101_temp_sensor.h" + +#define MODULE_VERSION 0x01 +#define MODULE_NAME "E-Xanh Gardener" + + +#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 }, + /* I2C 0 */ + { LPC_I2C0_SCL_PIO_0_10, LPC_FIXED, 0 }, + { LPC_I2C0_SDA_PIO_0_11, LPC_FIXED, 0 }, + ARRAY_LAST_PIO, +}; + +#define TMP101_ADDR 0x90 /* Pin Addr0 (pin5 of tmp101) connected to GND */ +struct tmp101_sensor_config tmp101_sensor = { + .bus_num = I2C0, + .addr = TMP101_ADDR, + .resolution = TMP_RES_ELEVEN_BITS, +}; + + + +/***************************************************************************** */ +/* Temperature */ +/* The Temperature Alert pin is on GPIO Port 0, pin 7 (PIO0_7) */ +/* The I2C Temperature sensor is at address 0x94 */ +void temp_config(int uart_num) +{ + int ret = 0; + + /* Temp sensor */ + ret = tmp101_sensor_config(&tmp101_sensor); + if (ret != 0) { + serial_write(uart_num, "Temp config error\r\n", 19); + } +} + +void temp_display(int uart_num) +{ + uint16_t raw = 0; + int deci_degrees = 0; + int len = 0; + + tmp101_sensor_start_conversion(&tmp101_sensor); + msleep(250); /* Wait for the end of the conversion : 40ms */ + len = tmp101_sensor_read(&tmp101_sensor, &raw, &deci_degrees); + if (len != 0) { + serial_write(uart_num, "Temp read error\r\n", 19); + } else { + uprintf(uart_num, "Temp read: %d,%d - raw: 0x%04x.\r\n", + (deci_degrees/10), (deci_degrees%10), raw); + } +} + + +/***************************************************************************** */ +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. This one is not mandatory, the dummy fault handler + * 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. + */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(UART0, 115200, NULL); + + + i2c_on(I2C0, I2C_CLK_100KHz, I2C_MASTER); + + /* Configure onboard temp sensor */ + temp_config(UART0); + + while (1) { + /* I2C Test using TMP101 temperature sensor */ + temp_display(UART0); + } + return 0; +} + diff --git a/ledstrip/Makefile b/ledstrip/Makefile new file mode 100644 index 0000000..097ff94 --- /dev/null +++ b/ledstrip/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/ledstrip/README b/ledstrip/README new file mode 100644 index 0000000..8e11795 --- /dev/null +++ b/ledstrip/README @@ -0,0 +1,36 @@ +WS2812 Chainable leds example + +Copyright 2015 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 . + * + *************************************************************************** */ + +This example shows the support of the WS2812 chainable leds. +It has been tested using a 60 leds strip from Adafruit. + +WS2812 external driver development is based on data found in the WS2812.pdf +datasheet provided by Adafruit : https://www.adafruit.com/datasheets/WS2812.pdf + + +The external driver (extdrv/ws2812.[ch]) provides an internal buffer which size +is defined in extdrv/ws2812.h (NB_LEDS) +This buffer is filled using ws2812_set_pixel(), and the led values are sent to +the led strip using ws2812_send_frame(). + + +Leds data is generated by the filling functions from ADC samples. + diff --git a/ledstrip/main.c b/ledstrip/main.c new file mode 100644 index 0000000..c88dc1b --- /dev/null +++ b/ledstrip/main.c @@ -0,0 +1,143 @@ +/**************************************************************************** + * ledstrip/main.c + * + * WS2812 Chainable leds example using Adafruit les strip + * + * Copyright 2013-2015 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" + +#include "extdrv/ws2812.h" + +#define MODULE_VERSION 0x01 +#define MODULE_NAME "E-Xanh Gardener" + + +#define SELECTED_FREQ FREQ_SEL_36MHz + +#define APP_NB_LEDS 1 + +/***************************************************************************** */ +/* 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_AD2_PIO_0_14, LPC_FIXED, 0 }, + { LPC_ADC_AD9_PIO_0_17, LPC_FIXED, 0 }, + { LPC_ADC_AD10_PIO_0_13, LPC_FIXED, 0 }, + /* GPIO */ + { LPC_GPIO_0_2, LPC_GPIO, 0 }, + { LPC_GPIO_0_12, LPC_GPIO, 0 }, + ARRAY_LAST_PIO, +}; + + +const struct pio ws2812_data_out_pin = LPC_GPIO_0_2; /* Led control data pin */ + + +/***************************************************************************** */ +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. This one is not mandatory, the dummy fault handler + * 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. + */ +void fault_info(const char* name, uint32_t len) +{ + uprintf(UART0, name); + while (1); +} + + + +/* This mode reads values from ADC2, ADC9 and ADC10 every 150ms and uses the values to set the leds. + * Pixels are updated when all pixel are set from ADC input. + */ +void mode_adc_colors(void) +{ + static uint8_t pixel = 0; + uint16_t red = 0, green = 0, blue = 0; + + /* Get ADC values */ + adc_get_value(&red, LPC_ADC_NUM(2)); + adc_get_value(&green, LPC_ADC_NUM(9)); + adc_get_value(&blue, LPC_ADC_NUM(10)); + /* Set one pixel */ + ws2812_set_pixel(pixel++, ((red >> 4) & 0xFF), ((green >> 4) & 0xFF), ((blue >> 4) & 0xFF)); + msleep(5); + /* Buffer full, send it ! */ + if ((pixel >= APP_NB_LEDS) || (pixel >= NB_LEDS)) { + ws2812_send_frame(0); + pixel = 0; + } + uprintf(UART0, "Color: %03d, %03d, %03d\n", + ((red >> 4) & 0xFF), ((green >> 4) & 0xFF), ((blue >> 4) & 0xFF)); +} + + + +/***************************************************************************** */ +int main(void) +{ + system_init(); + uart_on(UART0, 115200, NULL); + + /* ADC for potentiometer color settings */ + adc_on(NULL); + adc_start_burst_conversion(LPC_ADC_CHANNEL(2) | LPC_ADC_CHANNEL(9) | LPC_ADC_CHANNEL(10), LPC_ADC_SEQB); + + /* Led strip configuration */ + ws2812_config(&ws2812_data_out_pin); + + uprintf(UART0, "Config OK\n"); + + while (1) { + mode_adc_colors(); + } + return 0; +} + + + +