--- /dev/null
+PWM 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 LPC82x PWM support using SCT timer by
+controling three output as PWM.
+
+The selected period is 1s and each output has a different duty-cycle :
+GPIO 0.8 as output 0 - duty cycle of 2/3
+GPIO 0.9 as output 1 - duty cycle of 1/30
+GPIO 0.3 as output 2 - duty cycle of 45/150
+
--- /dev/null
+/****************************************************************************
+ * timers/main.c
+ *
+ * Timers 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/>.
+ *
+ *************************************************************************** */
+
+/* Timers send messages on UART0 at different intervals */
+
+#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/timers.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 },
+ /* Timers */
+ { LPC_GPIO_0_8, LPC_SCT_POUT0, 0 },
+ { LPC_GPIO_0_9, LPC_SCT_POUT1, 0 },
+ { LPC_GPIO_0_3, LPC_SCT_POUT2, 0 },
+ /* GPIO */
+ { LPC_GPIO_0_12, LPC_GPIO, 0 },
+ ARRAY_LAST_PIO,
+};
+
+const struct pio button = LPC_GPIO_0_12; /* ISP button */
+
+const struct lpc_timer_pwm_config pwm_conf = {
+ .nb_channels = 3,
+ .period = (150 * 1000),
+ .outputs_initial_state = 0x07,
+ .match_values = { (100 * 1000), 5000, 45000, },
+ .outputs = { 0, 1, 2, },
+};
+
+/***************************************************************************** */
+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(0, 115200, NULL);
+ timer_on(LPC_SCT, (150 * 1000), NULL);
+
+ timer_pwm_config(LPC_SCT, &pwm_conf);
+ uprintf(UART0, "Config done\n");
+
+ timer_start(LPC_SCT);
+ uprintf(UART0, "Timer started\n");
+
+ while (1) {
+ msleep(100);
+ uprintf(UART0, "Timer value: %d\n", timer_get_counter_val(LPC_SCT));
+ }
+ return 0;
+}
+
+
+