//*****************************************************************************
//
// Modified to drive a three color LED connected to the board's beadboard
// connection.
//
//*****************************************************************************

//*****************************************************************************
//
// project0.c - Example to demonstrate minimal TivaWare setup
//
// Copyright (c) 2012-2020 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.2.0.295 of the EK-TM4C1294XL Firmware Package.
//
//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"

//*****************************************************************************
//
// Define pin to LED mapping.
//
//*****************************************************************************

//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Project Zero (project0)</h1>
//!
//! This example demonstrates the use of TivaWare to setup the clocks and
//! toggle GPIO pins to make the LED blink. This is a good place to start
//! understanding your launchpad and the tools that can be used to program it.
//
//*****************************************************************************

#define CLCLE_PWR_DOWN_R  GPIO_PIN_5
#define CLCLE_PWR_DOWN_G  GPIO_PIN_1
#define CLCLE_PWR_DOWN_Y  GPIO_PIN_0

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************
//
// Main 'C' Language entry point.  Toggle an LED using TivaWare.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    // Note: SYSCTL_CFG_VCO_240 is a new setting provided in TivaWare 2.2.x and
    // later to better reflect the actual VCO speed due to SYSCTL#22.
    //
    ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                       SYSCTL_OSC_MAIN |
                                       SYSCTL_USE_PLL |
                                       SYSCTL_CFG_VCO_240), 120000000);

    //
    // Enable and wait for the ports to be ready for access
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOJ))
    {
    }

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOP))
    {
    }
  
    //
    // Configure the GPIO ports for the LED operation.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, (GPIO_PIN_1|GPIO_PIN_0));
    GPIOPinTypeGPIOOutput(GPIO_PORTP_BASE, GPIO_PIN_5);

    //
    // Loop until the power goes out
    //
    while(1)
    {
        //
        // Turn on the red LED
        //
        GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_5, 1);

        //
        // Delay for a bit
        //
        SysCtlDelay(ui32SysClock/6);

        //
        // Turn off the red LED
        //
        GPIOPinWrite(GPIO_PORTP_BASE, GPIO_PIN_5, 0);

        //
        // Delay for a bit
        //
        SysCtlDelay(ui32SysClock/6);

        //
        // Turn on the green LED
        //
        GPIOPinWrite(GPIO_PORTJ_BASE, (GPIO_PIN_1|GPIO_PIN_0), GPIO_PIN_1);

        //
        // Delay for a bit
        //
        SysCtlDelay(ui32SysClock/6);

        //
        // Turn on the yellow LED
        //
        GPIOPinWrite(GPIO_PORTJ_BASE, (GPIO_PIN_1|GPIO_PIN_0), GPIO_PIN_0);

        //
        // Delay for a bit
        //
        SysCtlDelay(ui32SysClock/6);

    }
}
