Professional Documents
Culture Documents
Definitions
"ES_Configure.h" /* gets us event definitions */
"ES_Types.h"
/* gets bool type for returns */
"ES_Framework.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include
#include
#include
#include
#include
#include
#include
"ES_Port.h"
"termio.h"
"inc/hw_memmap.h"
"inc/hw_types.h"
"inc/hw_gpio.h"
"inc/hw_sysctl.h"
"driverlib/gpio.h"
Description
Module to handle button debouncing
Module to change the IO out state for DDM state
Created by Kacyn Fujii on 11/2/14
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "ES_Configure.h"
#include "ES_Timers.h"
#include "ES_Framework.h"
#include "Button.h"
#include "Game.h"
#include "GeneralBase.h"
/*----------------------------- Module Defines ----------------------------*/
// define the IO port needed for the button
#define ButtonPort 'F'
// define the IO input pin for button
#define ButtonIO BIT1HI
// define the LED IO output pin for button
#define ButtonLEDIO BIT0HI
// define the port for DDM output
#define DDMPort 'D'
// define the IO output pin for DDM output
#define DDM BIT7HI
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this machine.They should be functions
relevant to the behavior of this state machine
*/
void SnitchLEDOn(void);
void SnitchLEDOff(void);
/*---------------------------- Module Variables ---------------------------*/
// everybody needs a state variable, you may need others as well.
// type of state variable should match htat of enum in header file
static ButtonState_t CurrentState;
// with the introduction of Gen2, we need a module level Priority var as well
static uint8_t MyPriority;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
InitButton
Parameters
uint8_t : the priorty of this service
Returns
bool, false if error in initialization, true otherwise
Description
Saves away the priority, does button debounce by 2 states
}
/****************************************************************************
Function
RunButtonDebounceFSM
Parameters
ES_Event : the event to process
Returns
ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise
Description
State machine to handle button debouncing
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
ES_Event RunButtonDebounceFSM( ES_Event ThisEvent )
{
//Initialize the return event to ES_NO_EVENT
ES_Event ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
// The event to post to Game SM
ES_Event NewEvent;
// switch on current state
switch ( CurrentState )
{
//If current state is deboucing
case Debouncing :
//If event type is ES_TIMEOUT
if ( ThisEvent.EventType == ES_TIMEOUT )
{
//change state to ready2sample
CurrentState = Ready2Sample;
}
break;
//If state is ready to sample
case Ready2Sample:
//If event is button up
if(ThisEvent.EventType == BUTTON_UP)
{
//start debounce timer, 20 ms
ES_Timer_InitTimer(BUTTON_TIMER, 20);
//change state to deboucing
CurrentState = Debouncing;
}
//If state is button down
if(ThisEvent.EventType == BUTTON_DOWN) {
//start debounce timer, 20 ms
ES_Timer_InitTimer(BUTTON_TIMER, 20);
//change state to deboucing
CurrentState = Debouncing;
//post button press to game SM
NewEvent.EventType = ES_BUTTON_DOWN;
PostGameFSM(NewEvent);
}
break;
default :
;
}
// end switch on Current State
return ReturnEvent;
}
/***************************************************************************
private functions
***************************************************************************/
/****************************************************************************
Function
SnitchLEDOn
Parameters
nothing
Returns
nothing
Description
light LED on the button
Final Editing: Dongao Yang 11/25/2014
****************************************************************************/
void SnitchLEDOn(void)
{
//change button LED pin to high
write(ButtonPort, ButtonLEDIO, 1);
}
/****************************************************************************
Function
SnitchLEDOff
Parameters
nothing
Returns
nothing
Description
Shut down LED on the button
Final Editing: Dongao Yang 11/25/2014
****************************************************************************/
void SnitchLEDOff(void)
{
//change button LED pin to low