/*

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

*/
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "debug.h"
#include "gpio.h"
#include "timer.h"
#include "sysctl.h"
#include "interrupt.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
/*----------------------------------------------------------*\
 | The interrupt handler for the second timer interrupt.    |
\*----------------------------------------------------------*/
void
Timer1IntHandler(void) {
    // Clear the timer interrupt.
    TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    // Toggle the GPIO B6 value.
    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6,GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_6) ^ GPIO_PIN_6);
    // Toggle the GPIO B5 value.
    GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5) ^ GPIO_PIN_5);
    }
/*----------------------------------------------------------*\
 | 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 and buzzer.
    GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_5 | GPIO_PIN_6, GPIO_DIR_MODE_OUT);

    // Enable the peripherals used by this example.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
    // Enable processor interrupts.
    IntMasterEnable();
    // Configure the two 32-bit periodic timers.
    TimerConfigure(TIMER1_BASE, TIMER_CFG_32_BIT_PER);
    TimerLoadSet(TIMER1_BASE, TIMER_A, SysCtlClockGet() / 2);
    // Setup the interrupts for the timer timeouts.
    IntEnable(INT_TIMER1A);
    TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    // Enable the timers.
    TimerEnable(TIMER1_BASE, TIMER_A);

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

    // Loop forever.
    while(1) {
		if( GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4) == 0 ) {
			LCD_GotoXY(26, 3);	LCD_PrintStr(" BP2 ", 1);
	        // Turn on the LED.
	        //GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0);
	        //GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, GPIO_PIN_6);
			}
		else {
			LCD_GotoXY(26, 3);	LCD_PrintStr(" BP2 ", 0);
	        // Turn off the LED.
	        //GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);
	        //GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
			}
	    }
	}
/*----------------------------------------------------------*\
 | END OF FILE                                              |
\*----------------------------------------------------------*/
