• Main Page
  • Modules
  • Index
  • File List
  • Globals

hal/nrf24lu1p/hal_usb_hid.c

Go to the documentation of this file.
00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is confidential property of Nordic 
00004  * Semiconductor ASA.Terms and conditions of usage are described in detail 
00005  * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRENTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *              
00011  * $LastChangedRevision: 2409 $
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 // More than 3 parameters passed to this function => need to make it reentrant
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 ) // This is a class specific request D5..6: Type Class(value 1)
00052     { 
00053         switch( req->bRequest )
00054         {
00055             case 0x01: // Get_Report
00056                 retval = true;
00057                 // For now we just send an "empty" report. No mousemoves, no mouse-key pressed.
00058                 // TODO: This breaks the generic nature of usb.c. 
00059                 // Have to create some global "default" reports in the template later.
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: // Get_Idle
00066                 retval = true;
00067                 *resp = STALL;
00068                 break;
00069             case 0x0a: // Set_Idle
00070                 retval = true;
00071                 //idle_value = (req->wValueMsb);
00072                 *resp = DATA;
00073                 break;
00074             case 0x03: // Get_Protocol
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: // Set_Protocol
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: // Set_Report
00099             {
00100                 if( req->wValueMsb == 0x03 ) // Feature report
00101                 {
00102                     retval = true;
00103                     *resp = EMPTY_RESPONSE;
00104                 }
00105                 else if ( req->wValueMsb == 0x02 ) // Output report
00106                 {
00107                     // For now we just assume that the OUT packet is a keyboard report.
00108                     *resp = EMPTY_RESPONSE;
00109                     retval = true;
00110                 }
00111             }
00112                 break;
00113             default:
00114                 break;
00115             }
00116     }
00117 
00118     return retval;
00119 }

Generated on Fri Apr 20 2012 14:11:45 for nRFGo SDK by  doxygen 1.7.2