From 4b2d9aca7bcefb1699b852a7573cfa06edd5e8ef Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Tue, 8 Jan 2013 22:18:53 -0600 Subject: [PATCH] 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 --- .../miniblink/miniblink.c | 78 ++++++++++--------- 1 file 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 0231a905..e88413fd 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 - * Copyright (C) 2012 Alexandru Gagniuc + * Copyright (C) 2012-2013 Alexandru Gagniuc * * 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 #include -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;