/** * \brief Decodes the HID mouse report received * * \param add USB address used by the transfer * \param status Transfer status * \param nb_transfered Number of data transferred */ static void uhi_hid_mouse_report_reception( USBHS_Add_t add, USBHS_Ep_t ep, USBH_XfrStatus_t status, uint32_t nb_transfered) { uint8_t state_prev; uint8_t state_new; UNUSED(ep); if ((status == UHD_TRANS_NOTRESPONDING) || (status == UHD_TRANS_TIMEOUT)) { uhi_hid_mouse_start_trans_report(add); return; // HID mouse transfer restart } if ((status != UHD_TRANS_NOERROR) || (nb_transfered < 4)) { return; // HID mouse transfer aborted } SCB_InvalidateDCache_by_Addr((uint32_t *)uhi_hid_mouse_dev.report, nb_transfered); // Decode buttons state_prev = uhi_hid_mouse_dev.report_btn_prev; state_new = uhi_hid_mouse_dev.report[UHI_HID_MOUSE_BTN]; if ((state_prev & 0x01) != (state_new & 0x01)) UHI_HID_MOUSE_EVENT_BTN_LEFT((state_new & 0x01) ? true : false); if ((state_prev & 0x02) != (state_new & 0x02)) UHI_HID_MOUSE_EVENT_BTN_RIGHT((state_new & 0x02) ? true : false); if ((state_prev & 0x04) != (state_new & 0x04)) UHI_HID_MOUSE_EVENT_BTN_MIDDLE((state_new & 0x04) ? true : false); uhi_hid_mouse_dev.report_btn_prev = state_new; // Decode moves if ((uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_X] != 0) || (uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_Y] != 0) || (uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_SCROLL] != 0)) { UHI_HID_MOUSE_EVENT_MOUVE( (int8_t)uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_X], (int8_t)uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_Y], (int8_t)uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_SCROLL]); } uhi_hid_mouse_start_trans_report(add); }
/** * \brief Decodes the HID mouse report received * * \param add USB address used by the transfer * \param status Transfer status * \param nb_transfered Number of data transfered */ static void uhi_hid_mouse_report_reception( usb_add_t add, usb_ep_t ep, uhd_trans_status_t status, iram_size_t nb_transfered) { uint8_t state_prev; uint8_t state_new; UNUSED(ep); if ((status == UHD_TRANS_NOTRESPONDING) || (status == UHD_TRANS_TIMEOUT)) { uhi_hid_mouse_start_trans_report(add); return; // HID mouse transfer restart } if ((status != UHD_TRANS_NOERROR) || (nb_transfered < 4)) { return; // HID mouse transfer aborted } // Decode buttons state_prev = uhi_hid_mouse_dev.report_btn_prev; state_new = uhi_hid_mouse_dev.report[UHI_HID_MOUSE_BTN]; if ((state_prev & 0x01) != (state_new & 0x01)) { UHI_HID_MOUSE_EVENT_BTN_LEFT((state_new & 0x01) ? true : false); } if ((state_prev & 0x02) != (state_new & 0x02)) { UHI_HID_MOUSE_EVENT_BTN_RIGHT((state_new & 0x02) ? true : false); } if ((state_prev & 0x04) != (state_new & 0x04)) { UHI_HID_MOUSE_EVENT_BTN_MIDDLE((state_new & 0x04) ? true : false); } uhi_hid_mouse_dev.report_btn_prev = state_new; // Decode moves if ((uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_X] != 0) || (uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_Y] != 0) || (uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_SCROLL] != 0)) { UHI_HID_MOUSE_EVENT_MOUVE( (int8_t)uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_X], (int8_t)uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_Y], (int8_t)uhi_hid_mouse_dev.report[UHI_HID_MOUSE_MOV_SCROLL]); } uhi_hid_mouse_start_trans_report(add); }