/*

                         \\\|///
                       \\  - -  //
                        (  @ @  )
+---------------------oOOo-(_)-oOOo-------------------------+
|              Luminaryボードのサンプルプログラム           |
|                     SSI SPIで液晶を駆動                   |
|                      by Xiaoran Liu                       |
|                        2008.4.16                          |
|                                                           |
|                  株式会社 日昇テクノロジー                |
|                    http://www.csun.co.jp                  |
|                             Oooo                          |
+-----------------------oooO--(   )-------------------------+
                       (   )   ) /
                        \ (   (_/
                         \_)     

*/
/*----------------------------------------------------------*\
 |  CPU関連のHファイル                                      |
\*----------------------------------------------------------*/
#include "hw_memmap.h"
#include "hw_types.h"
#include "debug.h"
#include "gpio.h"
#include "timer.h"
#include "sysctl.h"

#include "PCD5544.h"
/*----------------------------------------------------------*\
 | The error routine that is called			                |
 | if the driver library encounters an error.               |
\*----------------------------------------------------------*/
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
/*----------------------------------------------------------*\
 | LCD Backlight On                                         |
 |  Configure Timer 0 for 50% PWM output                    |
\*----------------------------------------------------------*/
void LCD_Backlight_On(void) {
    // Enable the peripherals used by this example.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

	// Configure Timer 0 for 50% PWM output
	TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
	TimerLoadSet(TIMER0_BASE, TIMER_A, 2);
	GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_DIR_MODE_HW);
	TimerMatchSet(TIMER0_BASE, TIMER_A, 1);

    // Enable the timers.
    TimerEnable(TIMER0_BASE, TIMER_A);
	}
/*----------------------------------------------------------*\
 | LCD Backlight Off                                        |
\*----------------------------------------------------------*/
void LCD_Backlight_Off(void) {
    // Disable the timers.
    TimerDisable(TIMER0_BASE, TIMER_A);
	}
/*----------------------------------------------------------*\
 | MIAN ENTRY                                               |
\*----------------------------------------------------------*/
int main(void) {
    volatile unsigned long ulLoop;

    // Set the clocking to run directly from the crystal.
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_6MHZ);

  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  // Enable the GPIO pin to read the select button.
  GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
  GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); 
  if( GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4) == 0 ) for(;;);

    // Configure the GPIO that drives the on-board LED.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_DIR_MODE_OUT);

	LCD_Backlight_On();
	LCD_Init();
	LCD_Cls();
	LCD_GotoXY(16, 0);	LCD_PrintStr("Cortex-M3");
	LCD_GotoXY(22, 1);	LCD_PrintStr("LM3S102");
	LCD_GotoXY(12, 2);	LCD_PrintStr("Eval Board");
	LCD_GotoXY(12, 4);	LCD_PrintStr("CSUN Tech.");
	LCD_GotoXY(0, 5);	LCD_PrintStr("www.csun.co.jp");
	//LCD_Backlight_Off();

    // Loop forever.
    while(1) {
        // Turn on the LED.
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);

        // Delay for a bit.
        for(ulLoop = 0; ulLoop < 200000; ulLoop++);

        // Turn off the LED.
        GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);

        // Delay for a bit.
        for(ulLoop = 0; ulLoop < 200000; ulLoop++);
	    }
	}
/*----------------------------------------------------------*\
 | END OF FILE                                              |
\*----------------------------------------------------------*/
