From 00c9659c16b4f63252091cb50890db012cbda0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sat, 27 Feb 2016 12:44:38 +0100 Subject: [PATCH] Make SW2 move the mouse pointer downwards. --- right/hid_mouse.c | 56 ++++------------------------------- right/include/board/pin_mux.c | 8 +++-- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/right/hid_mouse.c b/right/hid_mouse.c index 1959036..56da581 100644 --- a/right/hid_mouse.c +++ b/right/hid_mouse.c @@ -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); } diff --git a/right/include/board/pin_mux.c b/right/include/board/pin_mux.c index d17ad84..729a1e8 100644 --- a/right/include/board/pin_mux.c +++ b/right/include/board/pin_mux.c @@ -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); }