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>
This commit is contained in:
parent
7957cffaa3
commit
4b2d9aca7b
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue