--- /dev/null
+# 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 $@
+
--- /dev/null
+ADC Example
+
+Copyright 2016 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+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.
--- /dev/null
+/****************************************************************************
+ * adc/main.c
+ *
+ * ADC example
+ *
+ * Copyright 2013-2014 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+#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;
+}
+
+
+
--- /dev/null
+# 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 $@
+
--- /dev/null
+CLKOUT Example
+
+Copyright 2016 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+This example shows the support of clock output.
+
--- /dev/null
+/****************************************************************************
+ * clkout/main.c
+ *
+ * CLK example
+ *
+ * Copyright 2013-2014 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+#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;
+}
+
+
+
--- /dev/null
+# 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 $@
+
--- /dev/null
+GPIO interrupt Example
+
+Copyright 2015 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+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.
--- /dev/null
+/****************************************************************************
+ * gpio_intr/main.c
+ *
+ * GPIO interrupt example
+ *
+ * Copyright 2013-2014 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+/* 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;
+}
+
+
+
--- /dev/null
+# 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 $@
+
--- /dev/null
+TMP101 I2C temperature sensor example
+
+Copyright 2013 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+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.
+
--- /dev/null
+/****************************************************************************
+ * i2c_temp/main.c
+ *
+ * TMP101 I2C temperature sensor example
+ *
+ * Copyright 2013-2014 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+#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;
+}
+
--- /dev/null
+# 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 $@
+
--- /dev/null
+WS2812 Chainable leds example
+
+Copyright 2015 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+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.
+
--- /dev/null
+/****************************************************************************
+ * ledstrip/main.c
+ *
+ * WS2812 Chainable leds example using Adafruit les strip
+ *
+ * Copyright 2013-2015 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+#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;
+}
+
+
+
+