Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #include "hal_usb_hid.h"
00019 #include "nrf24lu1p.h"
00020 #include "nordic_common.h"
00021
00022 static xdata uint8_t tmp_usb_buf[8];
00023 static uint8_t tmp_usb_hid_protocol;
00024
00025
00026 bool hal_usb_hid_device_req_proc(hal_usb_device_req* req, uint8_t** data_ptr, uint8_t* size, hal_usb_dev_req_resp_t* resp) large reentrant
00027 {
00028 bool retval = false;
00029 *resp = STALL;
00030
00031 if(req->bRequest == USB_REQ_GET_DESCRIPTOR )
00032 {
00033 switch( req->wValueMsb )
00034 {
00035 case USB_CLASS_DESCRIPTOR_REPORT:
00036 retval = true;
00037 *data_ptr = g_usb_hid_hids[LSB(req->wIndex)].hid_report_desc;
00038 *size = MIN(g_usb_hid_hids[LSB(req->wIndex)].hid_report_desc_size, LSB(req->wLength));
00039 *resp = DATA;
00040 break;
00041 case USB_CLASS_DESCRIPTOR_HID:
00042 retval = true;
00043 *data_ptr = (uint8_t*)g_usb_hid_hids[LSB(req->wIndex)].hid_desc;
00044 *size = MIN(sizeof(hal_usb_hid_desc_t), LSB(req->wLength));
00045 *resp = DATA;
00046 break;
00047 default:
00048 break;
00049 }
00050 }
00051 else if( ( req->bmRequestType & 0x20 ) == 0x20 )
00052 {
00053 switch( req->bRequest )
00054 {
00055 case 0x01:
00056 retval = true;
00057
00058
00059
00060 tmp_usb_buf[0] = tmp_usb_buf[1] = 0x00;
00061 *data_ptr = &tmp_usb_buf[0];
00062 *size = 0x03;
00063 *resp = DATA;
00064 break;
00065 case 0x02:
00066 retval = true;
00067 *resp = STALL;
00068 break;
00069 case 0x0a:
00070 retval = true;
00071
00072 *resp = DATA;
00073 break;
00074 case 0x03:
00075 retval = true;
00076 tmp_usb_buf[0] = ( tmp_usb_hid_protocol & (1 << LSB(req->wIndex)) ) ? 0x01 : 0x00;
00077 *data_ptr = &tmp_usb_buf[0];
00078 *size = 0x01;
00079 *resp = DATA;
00080 break;
00081 case 0x0b:
00082 retval = true;
00083 #if 1 // Right now we do not support setting of protocol in a intelligent way
00084 if( req->wValueLsb == 0x01 )
00085 {
00086 tmp_usb_hid_protocol |= 1 << LSB(req->wIndex);
00087 }
00088 else
00089 {
00090 tmp_usb_hid_protocol &= ~(1 << LSB(req->wIndex));
00091 }
00092
00093 *resp = EMPTY_RESPONSE;
00094 #else
00095 *resp = EMPTY_RESPONSE;
00096 #endif
00097 break;
00098 case 0x09:
00099 {
00100 if( req->wValueMsb == 0x03 )
00101 {
00102 retval = true;
00103 *resp = EMPTY_RESPONSE;
00104 }
00105 else if ( req->wValueMsb == 0x02 )
00106 {
00107
00108 *resp = EMPTY_RESPONSE;
00109 retval = true;
00110 }
00111 }
00112 break;
00113 default:
00114 break;
00115 }
00116 }
00117
00118 return retval;
00119 }