Add keyin.c, generic joystick input function

This commit is contained in:
Stefan `Sec` Zehl 2011-06-13 23:53:02 +02:00
parent 2b73b15157
commit 4cd3460138
3 changed files with 49 additions and 1 deletions

View File

@ -8,6 +8,7 @@ OBJS = main.o
VPATH += VPATH +=
OBJS += OBJS +=
OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o OBJS += basic/basic.o basic/reinvoke_isp.o basic/delayms.o basic/voltage.o
OBJS += basic/keyin.o
OBJS += eeprom/eeprom.o OBJS += eeprom/eeprom.o
LIBS += core/libcore.a lcd/liblcd.a modules/libmodules.a LIBS += core/libcore.a lcd/liblcd.a modules/libmodules.a

View File

@ -121,7 +121,7 @@ void rbInit(void);
// reinvoke_isp.c // reinvoke_isp.c
void ReinvokeISP(void); void ReinvokeISP(void);
void EnableWatchdog(uint32_t ms); void EnableWatchdog(uint32_t ms);
void EnterISP(void); void ISPandReset(int delay);
// delayms.c // delayms.c
void delayms(uint32_t ms); void delayms(uint32_t ms);
@ -130,4 +130,13 @@ void delayms(uint32_t ms);
void VoltageCheck(void); void VoltageCheck(void);
uint32_t GetVoltage(void); uint32_t GetVoltage(void);
// keyin.c
#define BTN_NONE 0
#define BTN_UP (1<<0)
#define BTN_DOWN (1<<1)
#define BTN_LEFT (1<<2)
#define BTN_RIGHT (1<<3)
#define BTN_ENTER (1<<4)
uint8_t getInput(void);
#endif #endif

38
basic/keyin.c Normal file
View File

@ -0,0 +1,38 @@
#include <sysinit.h>
#include "basic/basic.h"
uint8_t getInput(void) {
uint8_t result = BTN_NONE;
if (gpioGetValue(RB_BTN3)==0) {
while(gpioGetValue(RB_BTN3)==0);
result += BTN_UP;
}
if (gpioGetValue(RB_BTN2)==0) {
while(gpioGetValue(RB_BTN2)==0);
result += BTN_DOWN;
}
if (gpioGetValue(RB_BTN4)==0) {
while(gpioGetValue(RB_BTN4)==0);
result += BTN_ENTER;
}
if (gpioGetValue(RB_BTN0)==0) {
while(gpioGetValue(RB_BTN0)==0);
result += BTN_LEFT;
}
if (gpioGetValue(RB_BTN1)==0) {
while(gpioGetValue(RB_BTN1)==0);
result += BTN_RIGHT;
}
if (result == (BTN_LEFT+BTN_UP+BTN_ENTER)){ /* Development hack */
ISPandReset(5);
}
return result;
}