From c3e4c9a25c2910d2d66d52215b3406b13d5b23d5 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sun, 29 Jun 2014 12:34:32 +0300 Subject: Add more board models --- boards/ek-tm4c123gxl/drivers/buttons.c | 196 ++++++++++++++++ boards/ek-tm4c123gxl/drivers/buttons.h | 107 +++++++++ boards/ek-tm4c123gxl/drivers/rgb.c | 404 +++++++++++++++++++++++++++++++++ boards/ek-tm4c123gxl/drivers/rgb.h | 142 ++++++++++++ 4 files changed, 849 insertions(+) create mode 100644 boards/ek-tm4c123gxl/drivers/buttons.c create mode 100644 boards/ek-tm4c123gxl/drivers/buttons.h create mode 100644 boards/ek-tm4c123gxl/drivers/rgb.c create mode 100644 boards/ek-tm4c123gxl/drivers/rgb.h (limited to 'boards/ek-tm4c123gxl/drivers') diff --git a/boards/ek-tm4c123gxl/drivers/buttons.c b/boards/ek-tm4c123gxl/drivers/buttons.c new file mode 100644 index 0000000..2621ea2 --- /dev/null +++ b/boards/ek-tm4c123gxl/drivers/buttons.c @@ -0,0 +1,196 @@ +//***************************************************************************** +// +// buttons.c - Evaluation board driver for push buttons. +// +// Copyright (c) 2012-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package. +// +//***************************************************************************** + +#include +#include +#include "inc/hw_types.h" +#include "inc/hw_memmap.h" +#include "inc/hw_gpio.h" +#include "driverlib/sysctl.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/pin_map.h" +#include "driverlib/gpio.h" +#include "drivers/buttons.h" + +//***************************************************************************** +// +//! \addtogroup buttons_api +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +// Holds the current, debounced state of each button. A 0 in a bit indicates +// that that button is currently pressed, otherwise it is released. +// We assume that we start with all the buttons released (though if one is +// pressed when the application starts, this will be detected). +// +//***************************************************************************** +static uint8_t g_ui8ButtonStates = ALL_BUTTONS; + +//***************************************************************************** +// +//! Polls the current state of the buttons and determines which have changed. +//! +//! \param pui8Delta points to a character that will be written to indicate +//! which button states changed since the last time this function was called. +//! This value is derived from the debounced state of the buttons. +//! \param pui8RawState points to a location where the raw button state will +//! be stored. +//! +//! This function should be called periodically by the application to poll the +//! pushbuttons. It determines both the current debounced state of the buttons +//! and also which buttons have changed state since the last time the function +//! was called. +//! +//! In order for button debouncing to work properly, this function should be +//! caled at a regular interval, even if the state of the buttons is not needed +//! that often. +//! +//! If button debouncing is not required, the the caller can pass a pointer +//! for the \e pui8RawState parameter in order to get the raw state of the +//! buttons. The value returned in \e pui8RawState will be a bit mask where +//! a 1 indicates the buttons is pressed. +//! +//! \return Returns the current debounced state of the buttons where a 1 in the +//! button ID's position indicates that the button is pressed and a 0 +//! indicates that it is released. +// +//***************************************************************************** +uint8_t +ButtonsPoll(uint8_t *pui8Delta, uint8_t *pui8RawState) +{ + uint32_t ui32Delta; + uint32_t ui32Data; + static uint8_t ui8SwitchClockA = 0; + static uint8_t ui8SwitchClockB = 0; + + // + // Read the raw state of the push buttons. Save the raw state + // (inverting the bit sense) if the caller supplied storage for the + // raw value. + // + ui32Data = (ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS)); + if(pui8RawState) + { + *pui8RawState = (uint8_t)~ui32Data; + } + + // + // Determine the switches that are at a different state than the debounced + // state. + // + ui32Delta = ui32Data ^ g_ui8ButtonStates; + + // + // Increment the clocks by one. + // + ui8SwitchClockA ^= ui8SwitchClockB; + ui8SwitchClockB = ~ui8SwitchClockB; + + // + // Reset the clocks corresponding to switches that have not changed state. + // + ui8SwitchClockA &= ui32Delta; + ui8SwitchClockB &= ui32Delta; + + // + // Get the new debounced switch state. + // + g_ui8ButtonStates &= ui8SwitchClockA | ui8SwitchClockB; + g_ui8ButtonStates |= (~(ui8SwitchClockA | ui8SwitchClockB)) & ui32Data; + + // + // Determine the switches that just changed debounced state. + // + ui32Delta ^= (ui8SwitchClockA | ui8SwitchClockB); + + // + // Store the bit mask for the buttons that have changed for return to + // caller. + // + if(pui8Delta) + { + *pui8Delta = (uint8_t)ui32Delta; + } + + // + // Return the debounced buttons states to the caller. Invert the bit + // sense so that a '1' indicates the button is pressed, which is a + // sensible way to interpret the return value. + // + return(~g_ui8ButtonStates); +} + +//***************************************************************************** +// +//! Initializes the GPIO pins used by the board pushbuttons. +//! +//! This function must be called during application initialization to +//! configure the GPIO pins to which the pushbuttons are attached. It enables +//! the port used by the buttons and configures each button GPIO as an input +//! with a weak pull-up. +//! +//! \return None. +// +//***************************************************************************** +void +ButtonsInit(void) +{ + // + // Enable the GPIO port to which the pushbuttons are connected. + // + ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); + + // + // Unlock PF0 so we can change it to a GPIO input + // Once we have enabled (unlocked) the commit register then re-lock it + // to prevent further changes. PF0 is muxed with NMI thus a special case. + // + HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; + HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01; + HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0; + + // + // Set each of the button GPIO pins as an input with a pull-up. + // + ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); + MAP_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, + GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); + + // + // Initialize the debounced button state with the current state read from + // the GPIO bank. + // + g_ui8ButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); +} + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** diff --git a/boards/ek-tm4c123gxl/drivers/buttons.h b/boards/ek-tm4c123gxl/drivers/buttons.h new file mode 100644 index 0000000..99ee799 --- /dev/null +++ b/boards/ek-tm4c123gxl/drivers/buttons.h @@ -0,0 +1,107 @@ +//***************************************************************************** +// +// buttons.h - Prototypes for the evaluation board buttons driver. +// +// Copyright (c) 2012-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package. +// +//***************************************************************************** + +#ifndef __BUTTONS_H__ +#define __BUTTONS_H__ + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Defines for the hardware resources used by the pushbuttons. +// +// The switches are on the following ports/pins: +// +// PF4 - Left Button +// PF0 - Right Button +// +// The switches tie the GPIO to ground, so the GPIOs need to be configured +// with pull-ups, and a value of 0 means the switch is pressed. +// +//***************************************************************************** +#define BUTTONS_GPIO_PERIPH SYSCTL_PERIPH_GPIOF +#define BUTTONS_GPIO_BASE GPIO_PORTF_BASE + +#define NUM_BUTTONS 2 +#define LEFT_BUTTON GPIO_PIN_4 +#define RIGHT_BUTTON GPIO_PIN_0 + +#define ALL_BUTTONS (LEFT_BUTTON | RIGHT_BUTTON) + +//***************************************************************************** +// +// Useful macros for detecting button events. +// +//***************************************************************************** +#define BUTTON_PRESSED(button, buttons, changed) \ + (((button) & (changed)) && ((button) & (buttons))) + +#define BUTTON_RELEASED(button, buttons, changed) \ + (((button) & (changed)) && !((button) & (buttons))) + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Functions exported from buttons.c +// +//***************************************************************************** +extern void ButtonsInit(void); +extern uint8_t ButtonsPoll(uint8_t *pui8Delta, + uint8_t *pui8Raw); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +//***************************************************************************** +// +// Prototypes for the globals exported by this driver. +// +//***************************************************************************** + +#endif // __BUTTONS_H__ diff --git a/boards/ek-tm4c123gxl/drivers/rgb.c b/boards/ek-tm4c123gxl/drivers/rgb.c new file mode 100644 index 0000000..40a2c4d --- /dev/null +++ b/boards/ek-tm4c123gxl/drivers/rgb.c @@ -0,0 +1,404 @@ +//***************************************************************************** +// +// rgb.c - Evaluation board driver for RGB LED. +// +// Copyright (c) 2012-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package. +// +//***************************************************************************** + +#include +#include +#include "inc/hw_types.h" +#include "inc/hw_memmap.h" +#include "inc/hw_timer.h" +#include "inc/hw_ints.h" +#include "driverlib/sysctl.h" +#include "driverlib/rom.h" +#include "driverlib/rom_map.h" +#include "driverlib/pin_map.h" +#include "driverlib/timer.h" +#include "driverlib/gpio.h" +#include "driverlib/interrupt.h" +#include "rgb.h" + +//***************************************************************************** +// +//! \addtogroup rgb_api +//! @{ +// +//***************************************************************************** + +//***************************************************************************** +// +// This is a custom driver that allows the easy manipulation of the RGB LED. +// +// The driver uses the general purpose timers to govern the brightness of the +// LED through simple PWM output mode of the GP Timers. +// +// A global array contains the current relative color of each of the three +// LEDs. A global float variable controls intensity of the overall mixed color. +// +// This implementation consumes the following hardware resources +// - Wide Timer 5B for blinking the entire RGB unit. +// - Timer 0B intensity of an RGB element +// - Timer 1A intensity of an RGB element +// - Timer 1B intensity of an RGB element +// +//***************************************************************************** +static uint32_t g_ui32Colors[3]; +static float g_fIntensity = 0.3f; + +//***************************************************************************** +// +//! Wide Timer interrupt to handle blinking effect of the RGB +//! +//! This function is called by the hardware interrupt controller on a timeout +//! of the wide timer. This function must be in the NVIC table in the startup +//! file. When called will toggle the enable flag to turn on or off the entire +//! RGB unit. This creates a blinking effect. A wide timer is used since the +//! blink is intended to be visible to the human eye and thus is expected to +//! have a frequency between 15 and 0.1 hz. Currently blink duty is fixed at +//! 50%. +//! +//! \return None. +// +//***************************************************************************** +void +RGBBlinkIntHandler(void) +{ + static unsigned long ulFlags; + + + // + // Clear the timer interrupt. + // + ROM_TimerIntClear(WTIMER5_BASE, TIMER_TIMB_TIMEOUT); + + // + // Toggle the flag for the blink timer. + // + ulFlags ^= 1; + + if(ulFlags) + { + RGBEnable(); + } + else + { + RGBDisable(); + } + +} + +//***************************************************************************** +// +//! Initializes the Timer and GPIO functionality associated with the RGB LED +//! +//! \param ui32Enable enables RGB immediately if set. +//! +//! This function must be called during application initialization to +//! configure the GPIO pins to which the LEDs are attached. It enables +//! the port used by the LEDs and configures each color's Timer. It optionally +//! enables the RGB LED by configuring the GPIO pins and starting the timers. +//! +//! \return None. +// +//***************************************************************************** +void +RGBInit(uint32_t ui32Enable) +{ + // + // Enable the GPIO Port and Timer for each LED + // + ROM_SysCtlPeripheralEnable(RED_GPIO_PERIPH); + ROM_SysCtlPeripheralEnable(RED_TIMER_PERIPH); + + ROM_SysCtlPeripheralEnable(GREEN_GPIO_PERIPH); + ROM_SysCtlPeripheralEnable(GREEN_TIMER_PERIPH); + + ROM_SysCtlPeripheralEnable(BLUE_GPIO_PERIPH); + ROM_SysCtlPeripheralEnable(BLUE_TIMER_PERIPH); + + // + // Configure each timer for output mode + // + HWREG(GREEN_TIMER_BASE + TIMER_O_CFG) = 0x04; + HWREG(GREEN_TIMER_BASE + TIMER_O_TAMR) = 0x0A; + HWREG(GREEN_TIMER_BASE + TIMER_O_TAILR) = 0xFFFF; + + HWREG(BLUE_TIMER_BASE + TIMER_O_CFG) = 0x04; + HWREG(BLUE_TIMER_BASE + TIMER_O_TBMR) = 0x0A; + HWREG(BLUE_TIMER_BASE + TIMER_O_TBILR) = 0xFFFF; + + HWREG(RED_TIMER_BASE + TIMER_O_CFG) = 0x04; + HWREG(RED_TIMER_BASE + TIMER_O_TBMR) = 0x0A; + HWREG(RED_TIMER_BASE + TIMER_O_TBILR) = 0xFFFF; + + // + // Invert the output signals. + // + HWREG(RED_TIMER_BASE + TIMER_O_CTL) |= 0x4000; + HWREG(GREEN_TIMER_BASE + TIMER_O_CTL) |= 0x40; + HWREG(BLUE_TIMER_BASE + TIMER_O_CTL) |= 0x4000; + + if(ui32Enable) + { + RGBEnable(); + } + + // + // Setup the blink functionality + // + ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER5); + ROM_TimerConfigure(WTIMER5_BASE, TIMER_CFG_B_PERIODIC | TIMER_CFG_SPLIT_PAIR); + ROM_TimerLoadSet64(WTIMER5_BASE, 0xFFFFFFFFFFFFFFFF); + ROM_IntEnable(INT_WTIMER5B); + ROM_TimerIntEnable(WTIMER5_BASE, TIMER_TIMB_TIMEOUT); + + +} + +//***************************************************************************** +// +//! Enable the RGB LED with already configured timer settings +//! +//! This function or RGBDisable should be called during application +//! initialization to configure the GPIO pins to which the LEDs are attached. +//! This function enables the timers and configures the GPIO pins as timer +//! outputs. +//! +//! \return None. +// +//***************************************************************************** +void +RGBEnable(void) +{ + + // + // Enable timers to begin counting + // + ROM_TimerEnable(RED_TIMER_BASE, TIMER_BOTH); + ROM_TimerEnable(GREEN_TIMER_BASE, TIMER_BOTH); + ROM_TimerEnable(BLUE_TIMER_BASE, TIMER_BOTH); + + // + // Reconfigure each LED's GPIO pad for timer control + // + ROM_GPIOPinConfigure(GREEN_GPIO_PIN_CFG); + ROM_GPIOPinTypeTimer(GREEN_GPIO_BASE, GREEN_GPIO_PIN); + MAP_GPIOPadConfigSet(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GPIO_STRENGTH_8MA_SC, + GPIO_PIN_TYPE_STD); + + ROM_GPIOPinConfigure(BLUE_GPIO_PIN_CFG); + ROM_GPIOPinTypeTimer(BLUE_GPIO_BASE, BLUE_GPIO_PIN); + MAP_GPIOPadConfigSet(BLUE_GPIO_BASE, BLUE_GPIO_PIN, GPIO_STRENGTH_8MA_SC, + GPIO_PIN_TYPE_STD); + + ROM_GPIOPinConfigure(RED_GPIO_PIN_CFG); + ROM_GPIOPinTypeTimer(RED_GPIO_BASE, RED_GPIO_PIN); + MAP_GPIOPadConfigSet(RED_GPIO_BASE, RED_GPIO_PIN, GPIO_STRENGTH_8MA_SC, + GPIO_PIN_TYPE_STD); +} + +//***************************************************************************** +// +//! Disable the RGB LED by configuring the GPIO's as inputs. +//! +//! This function or RGBEnable should be called during application +//! initialization to configure the GPIO pins to which the LEDs are attached. +//! This function disables the timers and configures the GPIO pins as inputs +//! for minimum current draw. +//! +//! \return None. +// +//***************************************************************************** +void +RGBDisable(void) +{ + // + // Configure the GPIO pads as general purpose inputs. + // + ROM_GPIOPinTypeGPIOInput(RED_GPIO_BASE, RED_GPIO_PIN); + ROM_GPIOPinTypeGPIOInput(GREEN_GPIO_BASE, GREEN_GPIO_PIN); + ROM_GPIOPinTypeGPIOInput(BLUE_GPIO_BASE, BLUE_GPIO_PIN); + + // + // Stop the timer counting. + // + ROM_TimerDisable(RED_TIMER_BASE, TIMER_BOTH); + ROM_TimerDisable(GREEN_TIMER_BASE, TIMER_BOTH); + ROM_TimerDisable(BLUE_TIMER_BASE, TIMER_BOTH); +} + +//***************************************************************************** +// +//! Set the output color and intensity. +//! +//! \param pui32RGBColor points to a three element array representing the +//! relative intensity of each color. Red is element 0, Green is element 1, +//! Blue is element 2. 0x0000 is off. 0xFFFF is fully on. +//! +//! \param fIntensity is used to scale the intensity of all three colors by +//! the same amount. fIntensity should be between 0.0 and 1.0. This scale +//! factor is applied to all three colors. +//! +//! This function should be called by the application to set the color and +//! intensity of the RGB LED. +//! +//! \return None. +// +//***************************************************************************** +void +RGBSet(volatile uint32_t * pui32RGBColor, float fIntensity) +{ + RGBColorSet(pui32RGBColor); + RGBIntensitySet(fIntensity); +} + +//***************************************************************************** +// +//! Set the output color. +//! +//! \param pui32RGBColor points to a three element array representing the +//! relative intensity of each color. Red is element 0, Green is element 1, +//! Blue is element 2. 0x0000 is off. 0xFFFF is fully on. +//! +//! This function should be called by the application to set the color +//! of the RGB LED. +//! +//! \return None. +// +//***************************************************************************** +void +RGBColorSet(volatile uint32_t * pui32RGBColor) +{ + uint32_t ui32Color[3]; + uint32_t ui32Index; + + for(ui32Index=0; ui32Index < 3; ui32Index++) + { + g_ui32Colors[ui32Index] = pui32RGBColor[ui32Index]; + ui32Color[ui32Index] = (uint32_t) (((float) pui32RGBColor[ui32Index]) * + g_fIntensity + 0.5f); + + if(ui32Color[ui32Index] > 0xFFFF) + { + ui32Color[ui32Index] = 0xFFFF; + } + } + + ROM_TimerMatchSet(RED_TIMER_BASE, RED_TIMER, ui32Color[RED]); + ROM_TimerMatchSet(GREEN_TIMER_BASE, GREEN_TIMER, ui32Color[GREEN]); + ROM_TimerMatchSet(BLUE_TIMER_BASE, BLUE_TIMER, ui32Color[BLUE]); +} + +//***************************************************************************** +// +//! Set the current output intensity. +//! +//! \param fIntensity is used to scale the intensity of all three colors by +//! the same amount. fIntensity should be between 0.0 and 1.0. This scale +//! factor is applied individually to all three colors. +//! +//! This function should be called by the application to set the intensity +//! of the RGB LED. +//! +//! \return None. +// +//***************************************************************************** +void +RGBIntensitySet(float fIntensity) +{ + g_fIntensity = fIntensity; + RGBColorSet(g_ui32Colors); +} + +//***************************************************************************** +// +//! Sets the blink rate of the RGB Led +//! +//! \param fRate is the blink rate in hertz. +//! +//! This function controls the blink rate of the RGB LED in auto blink mode. +//! to enable blinking pass a non-zero floating pointer number. To disable +//! pass 0.0f as the argument. Calling this function will override the current +//! RGBDisable or RGBEnable status. +//! +//! \return None. +// +//***************************************************************************** +void +RGBBlinkRateSet(float fRate) +{ + uint64_t ui64Load; + + if(fRate == 0.0f) + { + // + // Disable the timer and enable the RGB. If blink rate is zero we + // assume we want the RGB to be enabled. To disable call RGBDisable + // + ROM_TimerDisable(WTIMER5_BASE, TIMER_B); + RGBEnable(); + } + else + { + // + // Keep the math in floating pointing until the end so that we keep as + // much precision as we can. + // + ui64Load = (uint64_t) (((float)SysCtlClockGet()) / (fRate * 2.0f)); + ROM_TimerLoadSet(WTIMER5_BASE, TIMER_B, ui64Load); + ROM_TimerEnable(WTIMER5_BASE, TIMER_B); + } + +} + +//***************************************************************************** +// +//! Get the output color. +//! +//! \param pui32RGBColor points to a three element array representing the +//! relative intensity of each color. Red is element 0, Green is element 1, +//! Blue is element 2. 0x0000 is off. 0xFFFF is fully on. Caller must allocate +//! and pass a pointer to a three element array of uint32_ts. +//! +//! This function should be called by the application to get the current color +//! of the RGB LED. +//! +//! \return None. +// +//***************************************************************************** +void +RGBColorGet(uint32_t * pui32RGBColor) +{ + uint32_t ui32Index; + + for(ui32Index=0; ui32Index < 3; ui32Index++) + { + pui32RGBColor[ui32Index] = g_ui32Colors[ui32Index]; + } +} + +//***************************************************************************** +// +// Close the Doxygen group. +//! @} +// +//***************************************************************************** diff --git a/boards/ek-tm4c123gxl/drivers/rgb.h b/boards/ek-tm4c123gxl/drivers/rgb.h new file mode 100644 index 0000000..1a23717 --- /dev/null +++ b/boards/ek-tm4c123gxl/drivers/rgb.h @@ -0,0 +1,142 @@ +//***************************************************************************** +// +// rgb.h - Prototypes for the evaluation board RGB LED driver. +// +// Copyright (c) 2012-2014 Texas Instruments Incorporated. All rights reserved. +// Software License Agreement +// +// Texas Instruments (TI) is supplying this software for use solely and +// exclusively on TI's microcontroller products. The software is owned by +// TI and/or its suppliers, and is protected under applicable copyright +// laws. You may not combine this software with "viral" open-source +// software in order to form a larger program. +// +// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. +// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT +// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY +// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL +// DAMAGES, FOR ANY REASON WHATSOEVER. +// +// This is part of revision 2.1.0.12573 of the EK-TM4C123GXL Firmware Package. +// +//***************************************************************************** + +#ifndef __RGBLED_H__ +#define __RGBLED_H__ + +//***************************************************************************** +// +// Defines for the hardware resources used by the pushbuttons. +// +// The switches are on the following ports/pins: +// +// PF1 - RED (632 nanometer) +// PF2 - GREEN (518 nanometer) +// PF3 - BLUE (465 nanometer) + +// +// The RGB LED is tied up to 5V but since the lowest Vf is 1.75 we can still +// use a General Purpose Timer in pulse out mode. +// +//***************************************************************************** + +// +// Indexes into the array of colors +// +#define RED 0 +#define GREEN 1 +#define BLUE 2 + +// +// Ratio for percent of full on that should be "true" white. +// +#define RED_WHITE_BALANCE 0.497f +#define GREEN_WHITE_BALANCE 0.6f +#define BLUE_WHITE_BALANCE 1.0f + +// +// GPIO, Timer, Peripheral, and Pin assignments for the colors +// +#define RED_GPIO_PERIPH SYSCTL_PERIPH_GPIOF +#define RED_TIMER_PERIPH SYSCTL_PERIPH_TIMER0 +#define BLUE_GPIO_PERIPH SYSCTL_PERIPH_GPIOF +#define BLUE_TIMER_PERIPH SYSCTL_PERIPH_TIMER1 +#define GREEN_GPIO_PERIPH SYSCTL_PERIPH_GPIOF +#define GREEN_TIMER_PERIPH SYSCTL_PERIPH_TIMER1 + + +#define RED_GPIO_BASE GPIO_PORTF_BASE +#define RED_TIMER_BASE TIMER0_BASE +#define BLUE_GPIO_BASE GPIO_PORTF_BASE +#define BLUE_TIMER_BASE TIMER1_BASE +#define GREEN_GPIO_BASE GPIO_PORTF_BASE +#define GREEN_TIMER_BASE TIMER1_BASE + +#define RED_GPIO_PIN GPIO_PIN_1 +#define BLUE_GPIO_PIN GPIO_PIN_2 +#define GREEN_GPIO_PIN GPIO_PIN_3 + + +#define RED_GPIO_PIN_CFG GPIO_PF1_T0CCP1 +#define BLUE_GPIO_PIN_CFG GPIO_PF2_T1CCP0 +#define GREEN_GPIO_PIN_CFG GPIO_PF3_T1CCP1 + +#define RED_TIMER_CFG TIMER_CFG_B_PWM +#define BLUE_TIMER_CFG TIMER_CFG_A_PWM +#define GREEN_TIMER_CFG TIMER_CFG_B_PWM + +#define RED_TIMER TIMER_B +#define BLUE_TIMER TIMER_A +#define GREEN_TIMER TIMER_B + + +//***************************************************************************** +// +// Useful macros +// +//***************************************************************************** + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//***************************************************************************** +// +// Functions exported from rgb.c +// +//***************************************************************************** +extern void RGBInit(uint32_t ui32Enable); + +extern void RGBEnable(void); +extern void RGBDisable(void); +extern void RGBSet(volatile uint32_t * pui32RGBColor, float fIntensity); +extern void RGBColorSet(volatile uint32_t * pui32RGBColor); + +extern void RGBIntensitySet(float fIntensity); +extern void RGBBlinkRateSet(float fRate); +extern void RGBGet(uint32_t * pui32RGBColor, float * pfIntensity); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +//***************************************************************************** +// +// Prototypes for the globals exported by this driver. +// +//***************************************************************************** + +#endif // __RGBLED_H__ -- cgit v1.3.1