Make SW3 send the scancode of 'A' to the host.

This commit is contained in:
László Monda
2016-02-27 12:33:04 +01:00
parent f4c778be30
commit b3984c050b
2 changed files with 11 additions and 34 deletions

View File

@@ -1,3 +1,4 @@
#include "fsl_gpio.h"
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
@@ -13,31 +14,9 @@ static usb_device_hid_keyboard_struct_t UsbKeyboardDevice;
static usb_status_t UsbKeyboardAction(void)
{
static int x = 0U;
enum {
DOWN,
UP
};
static uint8_t dir = DOWN;
UsbKeyboardDevice.buffer[2] = 0x00U;
switch (dir) {
case DOWN:
x++;
if (x > 200U) {
dir++;
UsbKeyboardDevice.buffer[2] = KEY_PAGEUP;
}
break;
case UP:
x--;
if (x < 1U) {
dir = DOWN;
UsbKeyboardDevice.buffer[2] = KEY_PAGEDOWN;
}
break;
default:
break;
if (!GPIO_ReadPinInput(GPIOB, 17U)) {
UsbKeyboardDevice.buffer[2] = KEY_A;
}
return USB_DeviceHidSend(UsbCompositeDevice.keyboardHandle, USB_KEYBOARD_ENDPOINT_ID,
UsbKeyboardDevice.buffer, USB_KEYBOARD_REPORT_LENGTH);

View File

@@ -31,19 +31,17 @@
#include "fsl_common.h"
#include "fsl_port.h"
/*******************************************************************************
* Code
******************************************************************************/
/* Function Name : BOARD_InitPins */
void BOARD_InitPins(void)
{
/* Initialize UART1 pins below */
/* Ungate the port clock */
// Set up UART1 for OpenSDA.
CLOCK_EnableClock(kCLOCK_PortE);
/* Affects PORTE_PCR0 register */
PORT_SetPinMux(PORTE, 0u, kPORT_MuxAlt3);
/* Affects PORTE_PCR1 register */
PORT_SetPinMux(PORTE, 1u, kPORT_MuxAlt3);
// Set up SW3.
CLOCK_EnableClock(kCLOCK_PortB);
port_pin_config_t switchConfig = {0};
switchConfig.pullSelect = kPORT_PullUp;
switchConfig.mux = kPORT_MuxAsGpio;
PORT_SetPinConfig(PORTB, 17U, &switchConfig);
}