diff --git a/source/usb.cpp b/source/usb.cpp index 158e5e7..8073900 100644 --- a/source/usb.cpp +++ b/source/usb.cpp @@ -7,7 +7,11 @@ extern AconnoGPIO ld1; static int8_t hid_acc_for_report_get(int16_t acc); -static void mouse_move_timer_handler(void * p_context); +static void mouse_move_down_timer_handler(void * p_context); + +static void mouse_move_up_timer_handler(void * p_context); + +static void mouse_move_left_timer_handler(void * p_context); static void usbd_user_ev_handler(app_usbd_event_type_t event); @@ -19,17 +23,37 @@ static void usbd_user_ev_handler(app_usbd_event_type_t event); * If report sending was successful it clears accumulated positions * and mark last button state that was transfered. */ -void hid_generic_mouse_process_state() +void hid_generic_mouse_process_state(USB_DIR direction) { ret_code_t ret; - ret = app_usbd_hid_mouse_x_move(&m_app_hid_mouse, CONFIG_MOUSE_MOVE_STEP); - APP_ERROR_CHECK(ret); - UNUSED_RETURN_VALUE(app_timer_start(m_mouse_move_timer, APP_TIMER_TICKS(CONFIG_MOUSE_MOVE_TIME_MS), NULL)); + switch(direction) + { + case USB_DIR::DOWN: + { + ret = app_usbd_hid_mouse_y_move(&m_app_hid_mouse, CONFIG_MOUSE_MOVE_STEP); + APP_ERROR_CHECK(ret); + UNUSED_RETURN_VALUE(app_timer_start(m_mouse_move_down_timer, APP_TIMER_TICKS(CONFIG_MOUSE_MOVE_TIME_MS), NULL)); + break; + } + case USB_DIR::LEFT: + { + ret = app_usbd_hid_mouse_x_move(&m_app_hid_mouse, -CONFIG_MOUSE_MOVE_STEP); + APP_ERROR_CHECK(ret); + UNUSED_RETURN_VALUE(app_timer_start(m_mouse_move_left_timer, APP_TIMER_TICKS(CONFIG_MOUSE_MOVE_TIME_MS), NULL)); + break; + } + default: + { + break; + } + } } void hid_generic_mouse_stop_state(void) { - UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_timer)); + UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_down_timer)); + //UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_up_timer)); + UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_left_timer)); } void usbSetup() @@ -41,8 +65,15 @@ void usbSetup() usbd_user_ev_handler }; - app_timer_create(&m_mouse_move_timer, APP_TIMER_MODE_REPEATED, - mouse_move_timer_handler); + app_timer_create(&m_mouse_move_down_timer, APP_TIMER_MODE_REPEATED, + mouse_move_down_timer_handler); + + app_timer_create(&m_mouse_move_up_timer, APP_TIMER_MODE_REPEATED, + mouse_move_up_timer_handler); + + app_timer_create(&m_mouse_move_left_timer, APP_TIMER_MODE_REPEATED, + mouse_move_left_timer_handler); + APP_ERROR_CHECK(ret); //NRF_LOG_INFO("BEFORE USB INIT"); @@ -76,14 +107,26 @@ void usbSetup() } } -static void mouse_move_timer_handler(void * p_context) +static void mouse_move_down_timer_handler(void * p_context) { UNUSED_PARAMETER(p_context); - UNUSED_RETURN_VALUE(app_usbd_hid_mouse_x_move(&m_app_hid_mouse, CONFIG_MOUSE_MOVE_STEP)); + UNUSED_RETURN_VALUE(app_usbd_hid_mouse_y_move(&m_app_hid_mouse, CONFIG_MOUSE_MOVE_STEP)); } +static void mouse_move_up_timer_handler(void * p_context) +{ + UNUSED_PARAMETER(p_context); + UNUSED_RETURN_VALUE(app_usbd_hid_mouse_y_move(&m_app_hid_mouse, -CONFIG_MOUSE_MOVE_STEP)); +} + +static void mouse_move_left_timer_handler(void * p_context) +{ + UNUSED_PARAMETER(p_context); + UNUSED_RETURN_VALUE(app_usbd_hid_mouse_x_move(&m_app_hid_mouse, -CONFIG_MOUSE_MOVE_STEP)); + +} /** * @brief Class specific event handler. diff --git a/source/usb.h b/source/usb.h index ba4c16a..cb63c40 100644 --- a/source/usb.h +++ b/source/usb.h @@ -43,7 +43,8 @@ extern "C" /* HID report layout */ #define BTN_MOUSE_X_POS 0 -#define BTN_MOUSE_LEFT 1 +#define BTN_MOUSE_Y_POS 1 +#define BTN_MOUSE_LEFT 2 /** * @brief USB composite interfaces @@ -81,8 +82,17 @@ void hid_mouse_user_ev_handler(app_usbd_class_inst_t const * p_inst, /** * @brief Timer to repeat mouse move */ -APP_TIMER_DEF(m_mouse_move_timer); +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 @@ -97,5 +107,5 @@ APP_USBD_HID_MOUSE_GLOBAL_DEF(m_app_hid_mouse, void usbSetup(); -void hid_generic_mouse_process_state(); +void hid_generic_mouse_process_state(USB_DIR direction); void hid_generic_mouse_stop_state(void); \ No newline at end of file diff --git a/tasks/aconnoTasks.cpp b/tasks/aconnoTasks.cpp index 9a1fc0e..e2d292b 100644 --- a/tasks/aconnoTasks.cpp +++ b/tasks/aconnoTasks.cpp @@ -803,41 +803,46 @@ void usbFunction(void *arg) if(xQueueReceive(interruptSourceQueueSecondary, &(intSourceRecvSecondary), (TickType_t) 10)) - { - switch(intSourceRecvSecondary) { - case INT_SOURCE::JOY_UP: + switch(intSourceRecvSecondary) { - NRF_LOG_INFO("INT_SOURCE::JOY_UP"); - - break; - } - case INT_SOURCE::JOY_DOWN: - { - NRF_LOG_INFO("INT_SOURCE::JOY_DOWN"); - - break; - } - case INT_SOURCE::JOY_LEFT: - { - NRF_LOG_INFO("INT_SOURCE::JOY_LEFT"); - hid_generic_mouse_process_state(); - break; - } - case INT_SOURCE::JOY_RIGHT: - { - NRF_LOG_INFO("INT_SOURCE::JOY_RIGHT"); - hid_generic_mouse_stop_state(); - //UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_timer)); - break; - } - default: - { - break; + case INT_SOURCE::JOY_UP: + { + NRF_LOG_INFO("INT_SOURCE::JOY_UP"); + hid_generic_mouse_stop_state(); + + break; + } + case INT_SOURCE::JOY_DOWN: + { + NRF_LOG_INFO("INT_SOURCE::JOY_DOWN"); + hid_generic_mouse_process_state(USB_DIR::DOWN); + + break; + } + case INT_SOURCE::JOY_LEFT: + { + NRF_LOG_INFO("INT_SOURCE::JOY_LEFT"); + hid_generic_mouse_process_state(USB_DIR::LEFT); + break; + } + case INT_SOURCE::JOY_RIGHT: + { + NRF_LOG_INFO("INT_SOURCE::JOY_RIGHT"); + hid_generic_mouse_stop_state(); + //UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_timer)); + break; + } + default: + { + break; + } } } - - } + else if(sw1.read() == GPIO_STATE::LOW) + { + hid_generic_mouse_stop_state(); + } @@ -845,55 +850,7 @@ void usbFunction(void *arg) /* Sleep CPU only if there was no interrupt since last loop processing */ __WFE(); } - - - while (app_usbd_event_queue_process()) - { - /* Nothing to do */ - } - - - if(xQueueReceive(interruptSourceQueueSecondary, - &(intSourceRecvSecondary), - (TickType_t) 10)) - { - switch(intSourceRecvSecondary) - { - case INT_SOURCE::JOY_UP: - { - NRF_LOG_INFO("INT_SOURCE::JOY_UP"); - - break; - } - case INT_SOURCE::JOY_DOWN: - { - NRF_LOG_INFO("INT_SOURCE::JOY_DOWN"); - - break; - } - case INT_SOURCE::JOY_LEFT: - { - NRF_LOG_INFO("INT_SOURCE::JOY_LEFT"); - ret = app_usbd_hid_mouse_x_move(&m_app_hid_mouse, CONFIG_MOUSE_MOVE_STEP); - APP_ERROR_CHECK(ret); - UNUSED_RETURN_VALUE(app_timer_start(m_mouse_move_timer, APP_TIMER_TICKS(CONFIG_MOUSE_MOVE_TIME_MS), NULL)); - break; - } - case INT_SOURCE::JOY_RIGHT: - { - NRF_LOG_INFO("INT_SOURCE::JOY_RIGHT"); - UNUSED_RETURN_VALUE(app_timer_stop(m_mouse_move_timer)); - break; - } - default: - { - break; - } - } - - } - //*/ - vTaskDelay(2000); + } }; //--------------------------- INTERRUPT HANDLERS ------------------------------