added board_buttons for lpcxpresso/board_lpcxpresso1769.c

This commit is contained in:
hathach
2014-03-07 12:45:49 +07:00
parent 26b1b879dd
commit 3d17212f29
5 changed files with 118 additions and 51 deletions
@@ -43,6 +43,24 @@
#define BOARD_LED_PORT (0)
#define BOARD_LED_PIN (22)
const static struct {
uint8_t port;
uint8_t pin;
} buttons[] =
{
{2, 3 }, // Joystick up
{0, 15 }, // Joystick down
{2, 4 }, // Joystick left
{0, 16 }, // Joystick right
{0, 17 }, // Joystick press
{0, 4 }, // SW3
// {1, 31 }, // SW4 (require to remove J28)
};
enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
};
#define BOARD_UART_PORT LPC_UART3
void board_init(void)
@@ -53,9 +71,12 @@ void board_init(void)
SysTick_Config(SystemCoreClock / CFG_TICKS_PER_SECOND); // 1 msec tick timer
#endif
// Leds Init
//------------- LED -------------//
GPIO_SetDir(BOARD_LED_PORT, BIT_(BOARD_LED_PIN), 1);
//------------- BUTTON -------------//
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) GPIO_SetDir(buttons[i].port, BIT_(buttons[i].pin), 0);
#if MODE_DEVICE_SUPPORTED
//------------- USB Device -------------//
// VBUS sense is wrongly connected to P0_5 (instead of P1_30). So we need to always pull P1_30 to high
@@ -68,8 +89,7 @@ void board_init(void)
//P0_21 instead of P2_9 as USB connect
#endif
//------------- UART init -------------//
//------------- UART -------------//
PINSEL_CFG_Type PinCfg =
{
.Portnum = 0,
@@ -106,6 +126,23 @@ void board_leds(uint32_t on_mask, uint32_t off_mask)
}
}
//--------------------------------------------------------------------+
// BUTTONS
//--------------------------------------------------------------------+
static uint32_t button_read(uint8_t id)
{
return !BIT_TEST_( GPIO_ReadValue(buttons[id].port), buttons[id].pin ); // button is active low
}
uint32_t board_buttons(void)
{
uint32_t result = 0;
for(uint8_t i=0; i<BOARD_BUTTON_COUNT; i++) result |= (button_read(i) ? BIT_(i) : 0);
return result;
}
//--------------------------------------------------------------------+
// UART
//--------------------------------------------------------------------+
@@ -45,14 +45,14 @@
#define LED_ON (0)
#define LED_OFF (1)
enum {
BOARD_BUTTON_COUNT = 1
};
const static struct {
uint8_t port;
uint8_t pin;
} buttons[BOARD_BUTTON_COUNT] = { 0, 1 };
} buttons[BOARD_BUTTON_COUNT] = { { 0, 1 } };
enum {
BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0])
};
void board_init(void)
{