111 lines
2.3 KiB
C
111 lines
2.3 KiB
C
#include "app_timer.h"
|
|
#include "app_usbd.h"
|
|
#include "app_usbd_core.h"
|
|
#include "app_usbd_hid_generic.h"
|
|
extern "C"
|
|
{
|
|
#include "app_usbd_hid_mouse.h"
|
|
#include "app_usbd_hid_kbd.h"
|
|
}
|
|
#include "app_error.h"
|
|
|
|
/**
|
|
* @brief Enable USB power detection
|
|
*/
|
|
#ifndef USBD_POWER_DETECTION
|
|
#define USBD_POWER_DETECTION false
|
|
#endif
|
|
|
|
/**
|
|
* @brief Enable HID mouse class
|
|
*/
|
|
#define CONFIG_HAS_MOUSE 1
|
|
|
|
/**
|
|
* @brief Enable HID keyboard class
|
|
*/
|
|
#define CONFIG_HAS_KBD 1
|
|
|
|
/**
|
|
* @brief Mouse button count
|
|
*/
|
|
#define CONFIG_MOUSE_BUTTON_COUNT 2
|
|
|
|
/**
|
|
* @brief Mouse speed (value sent via HID when board button is pressed).
|
|
*/
|
|
#define CONFIG_MOUSE_MOVE_STEP (3)
|
|
|
|
/**
|
|
* @brief Mouse move repeat time in milliseconds
|
|
*/
|
|
#define CONFIG_MOUSE_MOVE_TIME_MS (20)
|
|
|
|
/* HID report layout */
|
|
#define BTN_MOUSE_X_POS 0
|
|
#define BTN_MOUSE_Y_POS 1
|
|
#define BTN_MOUSE_LEFT 2
|
|
|
|
/**
|
|
* @brief USB composite interfaces
|
|
*/
|
|
#define APP_USBD_INTERFACE_MOUSE 0
|
|
|
|
/**
|
|
* @brief GPIO pull-up/down configuration
|
|
*
|
|
*/
|
|
enum class USB_DIR : uint8_t
|
|
{
|
|
LEFT = 0, //!< 0
|
|
RIGHT = 1, //!< 1
|
|
DOWN = 2, //!< 2
|
|
UP = 3 //!< 3
|
|
};
|
|
|
|
/**
|
|
* @brief HID generic mouse action types
|
|
*/
|
|
typedef enum {
|
|
HID_GENERIC_MOUSE_X,
|
|
HID_GENERIC_MOUSE_Y,
|
|
HID_GENERIC_MOUSE_BTN_LEFT,
|
|
HID_GENERIC_MOUSE_BTN_RIGHT,
|
|
} hid_generic_mouse_action_t;
|
|
|
|
/**
|
|
* @brief User event handler, HID mouse
|
|
*/
|
|
void hid_mouse_user_ev_handler(app_usbd_class_inst_t const * p_inst,
|
|
app_usbd_hid_user_event_t event);
|
|
|
|
/**
|
|
* @brief Timer to repeat mouse move
|
|
*/
|
|
APP_TIMER_DEF(m_mouse_move_down_timer);
|
|
|
|
/**
|
|
* @brief Timer to repeat mouse move
|
|
*/
|
|
APP_TIMER_DEF(m_mouse_move_up_timer);
|
|
|
|
/**
|
|
* @brief Timer to repeat mouse move
|
|
*/
|
|
APP_TIMER_DEF(m_mouse_move_left_timer);
|
|
|
|
/**
|
|
* @brief Global HID mouse instance
|
|
*/
|
|
APP_USBD_HID_MOUSE_GLOBAL_DEF(m_app_hid_mouse,
|
|
APP_USBD_INTERFACE_MOUSE,
|
|
NRF_DRV_USBD_EPIN1,
|
|
CONFIG_MOUSE_BUTTON_COUNT,
|
|
hid_mouse_user_ev_handler,
|
|
APP_USBD_HID_SUBCLASS_BOOT
|
|
);
|
|
|
|
|
|
void usbSetup();
|
|
void hid_generic_mouse_process_state(USB_DIR direction);
|
|
void hid_generic_mouse_stop_state(void); |