aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Gagniuc2013-01-08 22:18:53 -0600
committerAlexandru Gagniuc2013-01-09 00:56:42 -0600
commit4b2d9aca7bcefb1699b852a7573cfa06edd5e8ef (patch)
treefb004f46f0e0cc047e526c874cb886a9ee221efb
parent7957cffaa3ab9f8f9e1a276ba3b9f01054758dfc (diff)
lm4f: Make miniblink example more readable, by defining RGB pins
Instead of setting and clearing RGB pins by PINx constants, define more readable constants such as RGB_RED, and RGB_PORT. Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
-rw-r--r--examples/lm4f/stellaris-ek-lm4f120xl/miniblink/miniblink.c78
1 files changed, 43 insertions, 35 deletions
diff --git a/examples/lm4f/stellaris-ek-lm4f120xl/miniblink/miniblink.c b/examples/lm4f/stellaris-ek-lm4f120xl/miniblink/miniblink.c
index 0231a90..e88413f 100644
--- a/examples/lm4f/stellaris-ek-lm4f120xl/miniblink/miniblink.c
+++ b/examples/lm4f/stellaris-ek-lm4f120xl/miniblink/miniblink.c
@@ -2,7 +2,7 @@
* This file is part of the libopencm3 project.
*
* Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
- * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com>
+ * Copyright (C) 2012-2013 Alexandru Gagniuc <mr.nuke.me@gmail.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -30,62 +30,70 @@
#include <libopencm3/lm4f/systemcontrol.h>
#include <libopencm3/lm4f/gpio.h>
-void gpio_setup(void)
-{
- SYSCTL_RCGCGPIO |= 0x20; /* Enable GPIOF in run mode. */
- const u32 outpins = ((1<<3) | (1<<2) | (1<<1));
+/* This is how the RGB LED is connected on the stellaris launchpad */
+#define RGB_PORT GPIOF
+enum {
+ LED_R = GPIO1,
+ LED_G = GPIO3,
+ LED_B = GPIO2,
+};
- GPIO_DIR(GPIOF) |= outpins; /* Configure outputs. */
- GPIO_DEN(GPIOF) |= outpins; /* Enable digital function on outputs. */
+/*
+ * GPIO setup:
+ * Enable the pins driving the RGB LED as outputs.
+ */
+static void gpio_setup(void)
+{
+ /*
+ * Configure GPIOF
+ * This port is used to control the RGB LED
+ */
+ periph_clock_enable(RCC_GPIOF);
+ const u32 outpins = (LED_R | LED_G | LED_B);
+
+ GPIO_DIR(RGB_PORT) |= outpins; /* Configure outputs. */
+ GPIO_DEN(RGB_PORT) |= outpins; /* Enable digital function on outputs. */
}
#define FLASH_DELAY 800000
+static void delay(void)
+{
+ int i;
+ for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
+ __asm__("nop");
+}
+
int main(void)
{
int i;
gpio_setup();
- /* Blink STATUS LED (PF0) on the board. */
+ /* Blink each color of the RGB LED in order. */
while (1) {
/*
* Flash the Red diode
*/
- gpio_set(GPIOF, GPIO1);
-
- for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
- __asm__("nop");
-
- gpio_clear(GPIOF, GPIO1);
-
- for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
- __asm__("nop");
+ gpio_set(RGB_PORT, LED_R);
+ delay(); /* Wait a bit. */
+ gpio_clear(RGB_PORT, LED_R);
+ delay(); /* Wait a bit. */
/*
* Flash the Green diode
*/
- gpio_set(GPIOF, GPIO3);
-
- for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
- __asm__("nop");
-
- gpio_clear(GPIOF, GPIO3);
-
- for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
- __asm__("nop");
+ gpio_set(RGB_PORT, LED_G);
+ delay(); /* Wait a bit. */
+ gpio_clear(RGB_PORT, LED_G);
+ delay(); /* Wait a bit. */
/*
* Flash the Blue diode
*/
- gpio_set(GPIOF, GPIO2);
-
- for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
- __asm__("nop");
-
- gpio_clear(GPIOF, GPIO2);
-
- for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
- __asm__("nop");
+ gpio_set(RGB_PORT, LED_B);
+ delay(); /* Wait a bit. */
+ gpio_clear(RGB_PORT, LED_B);
+ delay(); /* Wait a bit. */
}
return 0;