Вы находитесь на странице: 1из 4

/****************************************************************************

Header file for TargetLED


based on the Gen2 Events and Services Framework
Author: Kacyn Fujii Date: 11/2/14
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
#ifndef TargetLED_H
#define TargetLED_H
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
// Public Function Prototypes
void InitTargetLED( void );
void LightTargetLED(uint8_t LED);
void VibrationOn(void);
void VibrationOff(void);
#endif
/****************************************************************************
Module
TargetLED.c
Description
Module for control the target LEDs and vibration motor
Author: Kacyn Fujii Date: 11/2/14
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this service
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "Game.h"
#include "EventCheckers.h"
#include "GeneralBase.h"
#include "TargetLED.h"
//used for gpio
#include "ES_Port.h"
#include "termio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/gpio.h"

/*----------------------------- Module Defines ----------------------------*/


// target LED port

#define TargetLEDport 'D'


// target LED data pin
#define TargetLEDDataPin BIT1HI
// target LED SCK pin
#define TargetLEDSCKPin BIT2HI
// target LED RCK pin
#define TargetLEDRCKPin BIT3HI
// vibration motor port
#define VibrationPort 'D'
// vibration motor control pin
#define VibrationIO BIT0HI
#define ALL_BITS (0xff<<2)
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this machine.They should be functions
relevant to the behavior of this state machine
*/
void InitTargetLED( void );
void LightTargetLED(uint8_t LED);
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
InitTargetLED
Parameters
nothing
Returns
nothing
Description
Initialize all pins needed for both target LEDs and vibration motor
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void InitTargetLED( void )
{
// Activate the system clock for the port
InitSystemClock(TargetLEDport);
// Initialize all target LED pins to IO
InitPinIO(TargetLEDport, TargetLEDDataPin);
InitPinIO(TargetLEDport, TargetLEDSCKPin);
InitPinIO(TargetLEDport, TargetLEDRCKPin);
// Initialize all target LED pins to output
InitPinDir(TargetLEDport, TargetLEDDataPin, 1);
InitPinDir(TargetLEDport, TargetLEDSCKPin, 1);
InitPinDir(TargetLEDport, TargetLEDRCKPin, 1);
// Initialize vibration motor pin to IO
InitPinIO(VibrationPort, VibrationIO);
// Initialize vibration motor pin to output
InitPinDir(VibrationPort, VibrationIO, 1);
}

/****************************************************************************
Function
LightTargetLED
Parameters
uint8_t LED, the 8 bits number stands the LED status
Returns
nothing
Description
Light LEDs according to the input
Note: BIT6-4 for Red target LEDs, BIT3-1 for Green target LEDs, BIT7&0
are not used
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void LightTargetLED(uint8_t LED)
{
// for loop 8 times
for (int i=0; i<8; i++)
{
// write data pin to the number of the last digit of LED input
write(TargetLEDport,TargetLEDDataPin, (LED & BIT0HI));
// pulse SCK
pulse(TargetLEDport,TargetLEDSCKPin);
// shift LED input to right by 1 digit
LED = (LED>>1);
}
// pulse RCK
pulse(TargetLEDport,TargetLEDRCKPin);
}
/****************************************************************************
Function
VibrationOn
Parameters
nothing
Returns
nothing
Description
turn on the vibration motor
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void VibrationOn(void)
{
//write vibration control pin to high
write(VibrationPort, VibrationIO, 1);
}
/****************************************************************************
Function
VibrationOff

Parameters
nothing
Returns
nothing
Description
turn off the vibration motor
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void VibrationOff(void)
{
//write vibration control pin to low
write(VibrationPort, VibrationIO, 0);
}

Вам также может понравиться