Status_t host_hid_set_idle(uint8_t duration_4_ms, uint8_t report_id, uint8_t s_interface) { usb_request.bmRequestType = 0x21; usb_request.bRequest = HID_SET_IDLE; usb_request.wValue = duration_4_ms << 8 | report_id; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = 0x0000; usb_request.incomplete_read = false; return host_transfer_control(data_stage); }
Status_t host_hid_set_protocol(uint8_t protocol, uint8_t s_interface) { usb_request.bmRequestType = 0x21; usb_request.bRequest = HID_SET_PROTOCOL; usb_request.wValue = protocol; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = 0x0000; usb_request.incomplete_read = false; return host_transfer_control(data_stage); }
Status_t host_hid_set_report(uint8_t report_type, uint8_t report_id, uint8_t s_interface, uint16_t length) { usb_request.bmRequestType = 0x21; usb_request.bRequest = HID_SET_REPORT; usb_request.wValue = report_type << 8 | report_id; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = length; usb_request.incomplete_read = false; return host_transfer_control(data_stage); }
Status_t host_hid_get_report(uint8_t report_type, uint8_t report_id, uint8_t s_interface) { usb_request.bmRequestType = 0xA1; usb_request.bRequest = HID_GET_REPORT; usb_request.wValue = report_type << 8 | report_id; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = SIZEOF_DATA_STAGE; usb_request.incomplete_read = false; return host_transfer_control(data_stage); }
Status_t host_hid_set_descriptor(uint8_t descriptor_type, uint8_t descriptor_index, uint8_t s_interface, uint16_t length) { usb_request.bmRequestType = 0x01; usb_request.bRequest = SET_DESCRIPTOR; usb_request.wValue = descriptor_type << 8 | descriptor_index; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = length; usb_request.incomplete_read = false; return host_transfer_control(data_stage); }
//! @brief In host mode, display basic low level information about the device connected //! //! @note The device should be supported by the host (configured) //! void ushell_cmdusb_ls(void) { uint8_t i,j; // Check USB host status if( (!Is_host_ready()) && (!Is_host_suspended()) ) { fputs(MSG_NO_DEVICE, stdout); return; } if( Is_host_suspended() ) { fputs(MSG_USB_SUSPENDED, stdout); } printf("VID:%04X, PID:%04X, ",Get_VID(),Get_PID()); printf("MaxPower is %imA, ",2*Get_maxpower()); if (Is_device_self_powered()) { fputs(MSG_SELF_POWERED, stdout);} else { fputs(MSG_BUS_POWERED, stdout); } if (Is_usb_full_speed_mode()) { fputs(MSG_DEVICE_FULL_SPEED, stdout);} else #if (USB_HIGH_SPEED_SUPPORT==false) { fputs(MSG_DEVICE_LOW_SPEED, stdout); } #else { fputs(MSG_DEVICE_HIGH_SPEED, stdout); } #endif if (Is_device_supports_remote_wakeup()) { fputs(MSG_REMOTE_WAKEUP_OK, stdout);} else { fputs(MSG_REMOTE_WAKEUP_KO, stdout); } printf("Supported interface(s):%02i\n\r",Get_nb_supported_interface()); for(i=0;i<Get_nb_supported_interface();i++) { printf("Interface nb:%02i, AltS nb:%02i, Class:%02i, SubClass:%02i, Protocol:%02i\n\r",\ Get_interface_number(i), Get_altset_nb(i), Get_class(i), Get_subclass(i), Get_protocol(i)); printf(" Endpoint(s) Addr:"); if(Get_nb_ep(i)) { for(j=0;j<Get_nb_ep(i);j++) { printf(" %02lX", Get_ep_nbr(i,j)); } } else { printf("None"); } putchar(ASCII_CR);putchar(ASCII_LF); } }
uint8_t host_hid_get_protocol(uint8_t s_interface) { usb_request.bmRequestType = 0xA1; usb_request.bRequest = HID_GET_PROTOCOL; usb_request.wValue = 0x0000; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = 0x0001; usb_request.incomplete_read = false; host_transfer_control(data_stage); return data_stage[0x00]; }
uint8_t host_hid_get_idle(uint8_t report_id, uint8_t s_interface) { usb_request.bmRequestType = 0xA1; usb_request.bRequest = HID_GET_IDLE; usb_request.wValue = 0x00 << 8 | report_id; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = 0x0001; usb_request.incomplete_read = false; host_transfer_control(data_stage); return data_stage[0x00]; }
Status_t host_hid_get_descriptor(uint8_t descriptor_type, uint8_t descriptor_index, uint8_t s_interface) { Status_t status; const hid_descriptor_t *hid_descriptor = (hid_descriptor_t *)&data_stage; uint8_t i; usb_request.bmRequestType = 0x81; usb_request.bRequest = GET_DESCRIPTOR; usb_request.wValue = descriptor_type << 8 | descriptor_index; usb_request.wIndex = Get_interface_number(s_interface); usb_request.wLength = SIZEOF_DATA_STAGE; usb_request.incomplete_read = false; status = host_transfer_control(data_stage); switch (descriptor_type) { case HID_DESCRIPTOR: for (i = 0; i < hid_descriptor->bNumDescriptors; i++) { if (hid_descriptor->Descriptor[i].bType == HID_REPORT_DESCRIPTOR) { host_hid_report_descriptor_parser.length = usb_format_usb_to_mcu_data(16, hid_descriptor->Descriptor[i].wLength); break; } } break; case HID_REPORT_DESCRIPTOR: host_hid_report_descriptor_parser.item = (hid_item_t *)&data_stage; break; } return status; }
//! This function is called by the standard USB host_check_class() function when //! the Host is analyzing the configuration descriptor previously sent by a USB Device. //! The function will be called for each descriptor found in the configuration descriptor. //! bool host_user_check_class(const uint8_t* descriptor) { uint32_t num; const uint8_t* p_bmaControls; uint8_t n_sample_freq=0; uint8_t i; if (!n_interface) { free(host_audio_task_data); host_audio_task_data = NULL; } switch (descriptor[OFFSET_FIELD_DESCRIPTOR_TYPE]) { case INTERFACE_DESCRIPTOR: if (n_interface < MAX_INTERFACE_SUPPORTED) n_interface++; break; case CS_INTERFACE: if (!host_audio_task_data) host_audio_task_data = calloc(1, sizeof(*host_audio_task_data));; switch (descriptor[OFFSET_FIELD_DESCRIPTOR_SUBTYPE]) { case HEADER_SUB_TYPE: // This variable allow to detect AUDIO CONTROL sub class to AUDIO STREAMING // sub class transition. state++; break; case FEATURE_UNIT_SUB_TYPE: if( state!=1 ) break; // Still in AUDIO CONTROL sub class // Analysis of the Features Units // Ensure no out-of-limit access in array. num = (descriptor[0]-7)>MAX_BMA_CONTROLS ? MAX_BMA_CONTROLS : descriptor[0]-7; host_audio_task_data->g_cs_feature[host_audio_task_data->g_cs_num_features_unit].n_bmaControls = num; host_audio_task_data->g_cs_feature[host_audio_task_data->g_cs_num_features_unit].unit = descriptor[3]; p_bmaControls = &descriptor[6]; // Point on beginning of bmaControls infos for( i=0 ; i<num ; i++,p_bmaControls++ ) { host_audio_task_data->g_cs_feature[host_audio_task_data->g_cs_num_features_unit].bmaControls[i]=p_bmaControls[0]; } host_audio_task_data->g_cs_num_features_unit++; case FORMAT_SUB_TYPE: if( state<2 ) break; // We are in AUDIO STREAMING sub class // Analysis of the sampling frequencies const uint8_t* p_sampling_freq= &descriptor[8]; uint8_t id_interface=Get_interface_number(n_interface-1); host_audio_task_data->g_n_channels[id_interface] = descriptor[4]; host_audio_task_data->g_n_bits_per_sample[id_interface] = descriptor[6]; n_sample_freq = descriptor[7]; host_audio_task_data->g_sample_freq[id_interface]=0; for( i=0 ; i<n_sample_freq ; i++, p_sampling_freq+=3 ) { // Keep the max declared sampling frequency. An other policy would be to keep the // highest sampling frequency which is compatible with the CPU and PBA frequency host_audio_task_data->g_sample_freq[id_interface]= max( host_audio_task_data->g_sample_freq[id_interface] , p_sampling_freq[0] + (p_sampling_freq[1]<<8) + (p_sampling_freq[2]<<16)); } break; } break; default: break; } return true; }
/*! * \brief In host mode, display basic low-level information about the connected device. * The device should be supported by the host (configured). * No parameters. * Format: lsusb * * \note This function must be of the type pfShellCmd defined by the shell module. * * \param xModId Input. The module that is calling this function. * \param FsNavId Ignored. * \param ac Input. The argument counter. Ignored. * \param av Input. The argument vector. Ignored * \param ppcStringReply Input/Output. The response string. * If Input is NULL, no response string will be output. * Else a malloc for the response string is performed here; * the caller must free this string. * * \return the status of the command execution. */ eExecStatus e_usbsys_lsusb( eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply ) { #if USB_HOST_FEATURE == true signed portCHAR *pcStringToPrint; U8 i, j; if( NULL != ppcStringReply ) *ppcStringReply = NULL; if (!Is_host_ready() && !Is_host_suspended()) { v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE ); return SHELL_EXECSTATUS_KO; } pcStringToPrint = (signed portCHAR *)pvPortMalloc( SHELL_MAX_MSGOUT_LEN ); // Alloc if( NULL == pcStringToPrint ) { return( SHELL_EXECSTATUS_KO ); } if (Is_host_suspended()) { v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_USB_SUSPENDED CRLF ); } sprintf( (char *)pcStringToPrint, "VID: 0x%.4X, PID: 0x%.4X\r\n" "Device MaxPower is %d mA\r\n" "%s" "%s", Get_VID(), Get_PID(), 2 * Get_maxpower(), Is_device_self_powered() ? MSG_SELF_POWERED : MSG_BUS_POWERED, Is_usb_full_speed_mode() ? MSG_DEVICE_FULL_SPEED : MSG_DEVICE_LOW_SPEED ); v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint ); sprintf( (char *)pcStringToPrint, "%s" "Supported interface(s): %u", Is_device_supports_remote_wakeup() ? MSG_REMOTE_WAKEUP_OK : MSG_REMOTE_WAKEUP_KO, Get_nb_supported_interface() ); v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint ); for (i = 0; i < Get_nb_supported_interface(); i++) { sprintf( (char *)pcStringToPrint, "\r\nInterface nb: %u, AltS nb: %u, Class: 0x%.2X," " SubClass: 0x%.2X, Protocol: 0x%.2X\r\n" "\tAssociated Ep Nbrs:", Get_interface_number(i), Get_altset_nb(i), Get_class(i), Get_subclass(i), Get_protocol(i) ); v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint ); if (Get_nb_ep(i)) { for (j = 0; j < Get_nb_ep(i); j++) { sprintf( (char *)pcStringToPrint, " %u", (U16)Get_ep_nbr(i, j) ); v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint ); } } else { v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)"None" ); } } vPortFree( pcStringToPrint ); v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)CRLF ); #else v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE ); #endif return( SHELL_EXECSTATUS_OK ); }