Make SW2 move the mouse pointer downwards.

This commit is contained in:
László Monda
2016-02-27 12:44:38 +01:00
parent b3984c050b
commit 00c9659c16
2 changed files with 11 additions and 53 deletions

View File

@@ -1,3 +1,4 @@
#include "fsl_gpio.h"
#include "usb_device_config.h"
#include "usb.h"
#include "usb_device.h"
@@ -10,60 +11,13 @@
static usb_device_hid_mouse_struct_t UsbMouseDevice;
/* Update mouse pointer location: draw a rectangular rotation. */
static usb_status_t UsbMouseAction(void)
{
static int8_t x = 0U;
static int8_t y = 0U;
enum {
RIGHT,
DOWN,
LEFT,
UP
};
static uint8_t dir = RIGHT;
switch (dir) {
case RIGHT:
/* Move right. Increase X value. */
UsbMouseDevice.buffer[1] = 1U;
UsbMouseDevice.buffer[2] = 0U;
x++;
if (x > 99U) {
dir++;
}
break;
case DOWN:
/* Move down. Increase Y value. */
UsbMouseDevice.buffer[1] = 0U;
UsbMouseDevice.buffer[2] = 1U;
y++;
if (y > 99U) {
dir++;
}
break;
case LEFT:
/* Move left. Discrease X value. */
UsbMouseDevice.buffer[1] = (uint8_t)(0xFFU);
UsbMouseDevice.buffer[2] = 0U;
x--;
if (x < 1U) {
dir++;
}
break;
case UP:
/* Move up. Discrease Y value. */
UsbMouseDevice.buffer[1] = 0U;
UsbMouseDevice.buffer[2] = (uint8_t)(0xFFU);
y--;
if (y < 1U) {
dir = RIGHT;
}
break;
default:
break;
UsbMouseDevice.buffer[1] = 0U;
UsbMouseDevice.buffer[2] = 0U;
if (!GPIO_ReadPinInput(GPIOC, 1U)) {
UsbMouseDevice.buffer[2] = 1U;
}
return USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_ID,
UsbMouseDevice.buffer, USB_MOUSE_REPORT_LENGTH);
}

View File

@@ -38,10 +38,14 @@ void BOARD_InitPins(void)
PORT_SetPinMux(PORTE, 0u, kPORT_MuxAlt3);
PORT_SetPinMux(PORTE, 1u, kPORT_MuxAlt3);
// Set up SW3.
CLOCK_EnableClock(kCLOCK_PortB);
// Set up SW2.
port_pin_config_t switchConfig = {0};
switchConfig.pullSelect = kPORT_PullUp;
switchConfig.mux = kPORT_MuxAsGpio;
CLOCK_EnableClock(kCLOCK_PortC);
PORT_SetPinConfig(PORTC, 1U, &switchConfig);
// Set up SW3.
CLOCK_EnableClock(kCLOCK_PortB);
PORT_SetPinConfig(PORTB, 17U, &switchConfig);
}