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:
@@ -2,7 +2,7 @@
|
|||||||
* This file is part of the libopencm3 project.
|
* This file is part of the libopencm3 project.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Gareth McMullin <gareth@blacksphere.co.nz>
|
* 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
|
* 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
|
* 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/systemcontrol.h>
|
||||||
#include <libopencm3/lm4f/gpio.h>
|
#include <libopencm3/lm4f/gpio.h>
|
||||||
|
|
||||||
void gpio_setup(void)
|
/* This is how the RGB LED is connected on the stellaris launchpad */
|
||||||
{
|
#define RGB_PORT GPIOF
|
||||||
SYSCTL_RCGCGPIO |= 0x20; /* Enable GPIOF in run mode. */
|
enum {
|
||||||
const u32 outpins = ((1<<3) | (1<<2) | (1<<1));
|
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
|
#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 main(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
gpio_setup();
|
gpio_setup();
|
||||||
|
|
||||||
/* Blink STATUS LED (PF0) on the board. */
|
/* Blink each color of the RGB LED in order. */
|
||||||
while (1) {
|
while (1) {
|
||||||
/*
|
/*
|
||||||
* Flash the Red diode
|
* Flash the Red diode
|
||||||
*/
|
*/
|
||||||
gpio_set(GPIOF, GPIO1);
|
gpio_set(RGB_PORT, LED_R);
|
||||||
|
delay(); /* Wait a bit. */
|
||||||
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
|
gpio_clear(RGB_PORT, LED_R);
|
||||||
__asm__("nop");
|
delay(); /* Wait a bit. */
|
||||||
|
|
||||||
gpio_clear(GPIOF, GPIO1);
|
|
||||||
|
|
||||||
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flash the Green diode
|
* Flash the Green diode
|
||||||
*/
|
*/
|
||||||
gpio_set(GPIOF, GPIO3);
|
gpio_set(RGB_PORT, LED_G);
|
||||||
|
delay(); /* Wait a bit. */
|
||||||
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
|
gpio_clear(RGB_PORT, LED_G);
|
||||||
__asm__("nop");
|
delay(); /* Wait a bit. */
|
||||||
|
|
||||||
gpio_clear(GPIOF, GPIO3);
|
|
||||||
|
|
||||||
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flash the Blue diode
|
* Flash the Blue diode
|
||||||
*/
|
*/
|
||||||
gpio_set(GPIOF, GPIO2);
|
gpio_set(RGB_PORT, LED_B);
|
||||||
|
delay(); /* Wait a bit. */
|
||||||
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
|
gpio_clear(RGB_PORT, LED_B);
|
||||||
__asm__("nop");
|
delay(); /* Wait a bit. */
|
||||||
|
|
||||||
gpio_clear(GPIOF, GPIO2);
|
|
||||||
|
|
||||||
for (i = 0; i < FLASH_DELAY; i++) /* Wait a bit. */
|
|
||||||
__asm__("nop");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user