aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/LPC122x/PWM/main.c
diff options
context:
space:
mode:
authortheshed <theshed@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-06-01 22:00:28 +0000
committertheshed <theshed@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-06-01 22:00:28 +0000
commit51af0586c9634da8dfb35c6c71e0726392c1fbb3 (patch)
tree43506df5154db29d232b02f8189871eacc975bc3 /testhal/LPC122x/PWM/main.c
parent62ae17087c620312a24a87ac7435a8c2257ab8b6 (diff)
downloadChibiOS-51af0586c9634da8dfb35c6c71e0726392c1fbb3.tar.gz
ChibiOS-51af0586c9634da8dfb35c6c71e0726392c1fbb3.tar.bz2
ChibiOS-51af0586c9634da8dfb35c6c71e0726392c1fbb3.zip
More LPC122x drivers from Marcin J.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5794 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/LPC122x/PWM/main.c')
-rw-r--r--testhal/LPC122x/PWM/main.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/testhal/LPC122x/PWM/main.c b/testhal/LPC122x/PWM/main.c
new file mode 100644
index 000000000..c77ae045b
--- /dev/null
+++ b/testhal/LPC122x/PWM/main.c
@@ -0,0 +1,99 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011,2012,2013 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT 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 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT 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 "ch.h"
+#include "hal.h"
+
+static void pwm2pcb(PWMDriver *pwmp) {
+
+ (void)pwmp;
+ palSetPad(GPIO1, GPIO1_LED2);
+}
+
+static void pwm2c0cb(PWMDriver *pwmp) {
+
+ (void)pwmp;
+ palClearPad(GPIO1, GPIO1_LED2);
+}
+
+static PWMConfig pwmcfg = {
+ 10000, /* 100kHz PWM clock frequency. */
+ 1000, /* PWM 10 Hz */
+ pwm2pcb,
+ {
+ {PWM_OUTPUT_ACTIVE_LOW, pwm2c0cb},
+ {PWM_OUTPUT_ACTIVE_LOW, NULL}
+ }
+};
+
+/*
+ * Application entry point.
+ */
+int main(void) {
+
+ /*
+ * System initializations.
+ * - HAL initialization, this also initializes the configured device drivers
+ * and performs the board-specific initializations.
+ * - Kernel initialization, the main() function becomes a thread and the
+ * RTOS is active.
+ */
+ halInit();
+ chSysInit();
+
+ /*
+ * Initializes the PWM driver 2.
+ */
+ pwmStart(&PWMD2, &pwmcfg);
+ chThdSleepMilliseconds(2000);
+
+ /*
+ * Starts the PWM channel 1 using 75% duty cycle.
+ */
+ pwmEnableChannel(&PWMD2, 0, 250);
+ chThdSleepMilliseconds(5000);
+
+ /*
+ * Changes the PWM channel 1 to 50% duty cycle.
+ */
+ pwmEnableChannel(&PWMD2, 0, 500);
+ chThdSleepMilliseconds(5000);
+
+ /*
+ * Changes the PWM channel 0 to 75% duty cycle.
+ */
+ pwmEnableChannel(&PWMD2, 0, 250);
+ chThdSleepMilliseconds(5000);
+
+ /*
+ * Changes PWM period to half second the duty cycle becomes 50%
+ * implicitly.
+ */
+ pwmChangePeriod(&PWMD2, 500);
+ chThdSleepMilliseconds(5000);
+
+ /*
+ * Normal main() thread activity, in this demo it does nothing.
+ */
+ while (TRUE) {
+ chThdSleepMilliseconds(500);
+ }
+ return 0;
+}