/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_set_max_graphic_eq * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to send max graphic equalizer value * to the audio device *END*--------------------------------------------------------------------*/ USB_STATUS usb_class_audio_set_max_graphic_eq ( /* [IN] Class Interface structure pointer */ AUDIO_COMMAND_PTR com_ptr, /* [IN] length of the Buffer */ uint16_t blen, /* [IN] channel number */ uint8_t channel_no, /* [IN] Buffer to send data */ void *buf ) { /* Body */ uint16_t wIndex; AUDIO_CONTROL_INTERFACE_STRUCT_PTR if_ptr; USB_STATUS status = USBERR_ERROR; if_ptr = (AUDIO_CONTROL_INTERFACE_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; wIndex = (uint16_t)(((if_ptr->fu_desc->bUnitID)<<8)|(if_ptr->AUDIO_G.IFNUM)); /* Check whether this attribute valid or not */ status = check_valid_fu(if_ptr->fu_desc,FU_GRAPHIC_EQ_MASK,if_ptr->fu_desc->bControlSize*channel_no); if (USB_OK == status) { status = usb_class_audio_cntrl_common(com_ptr,SET_REQUEST_ITF,SET_MAX, (uint16_t)((USB_AUDIO_CTRL_FU_GRAPHIC_EQ << 8) | channel_no),wIndex,blen,buf); } return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_get_max_graphic_eq * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to get max graphic equalizer value * from the audio device *END*--------------------------------------------------------------------*/ usb_status usb_class_audio_get_max_graphic_eq ( /* [IN] Class Interface structure pointer */ audio_command_t* com_ptr, /* [IN] length of the Buffer */ uint16_t blen, /* [IN] channel number */ uint8_t channel_no, /* [IN] Buffer to receive data */ void* buf ) { /* Body */ uint16_t windex; audio_control_struct_t* if_ptr; usb_status status = USBERR_ERROR; if_ptr = (audio_control_struct_t*)com_ptr->class_control_handle; windex = (uint16_t)((uint16_t)((uint16_t)(if_ptr->fu_desc->bunitid)<<8)|(if_ptr->ifnum)); /* Check whether this attribute valid or not */ status = check_valid_fu(if_ptr->fu_desc,FU_GRAPHIC_EQ_MASK,if_ptr->fu_desc->bcontrolsize*channel_no); if (USB_OK == status) { status = usb_class_audio_cntrl_common(com_ptr,GET_REQUEST_ITF,GET_MAX, (uint16_t)((USB_AUDIO_CTRL_FU_GRAPHIC_EQ << 8) | channel_no),windex,blen,(uint8_t *)buf); } return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_set_copy_protect * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to send copy protect value * to the audio device *END*--------------------------------------------------------------------*/ USB_STATUS usb_class_audio_set_copy_protect ( /* [IN] Class Interface structure pointer */ AUDIO_COMMAND_PTR com_ptr, /* [IN] Buffer to send data */ void *buf ) { /* Body */ AUDIO_CONTROL_INTERFACE_STRUCT_PTR if_ptr; uint16_t wIndex; USB_AUDIO_CTRL_DESC_OT_PTR ot_desc; if_ptr = (AUDIO_CONTROL_INTERFACE_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; ot_desc = (USB_AUDIO_CTRL_DESC_OT_PTR)if_ptr->ot_desc; wIndex = (uint16_t)(((ot_desc->bTerminalID)<<8)|(if_ptr->AUDIO_G.IFNUM)); /* check valid of input terminal descriptor */ if (ot_desc==NULL) { return USBERR_NO_DESCRIPTOR; } else { return usb_class_audio_cntrl_common(com_ptr,SET_REQUEST_ITF,SET_CUR, (uint16_t)((COPY_PROTECT_CONTROL << 8)),wIndex,1,buf); } }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_set_copy_protect * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to send copy protect value * to the audio device *END*--------------------------------------------------------------------*/ usb_status usb_class_audio_set_copy_protect ( /* [IN] Class Interface structure pointer */ audio_command_t* com_ptr, /* [IN] Buffer to send data */ void* buf ) { /* Body */ audio_control_struct_t* if_ptr; uint16_t windex; usb_audio_ctrl_desc_ot_t* ot_desc; if_ptr = (audio_control_struct_t*)com_ptr->class_control_handle; ot_desc = (usb_audio_ctrl_desc_ot_t*)if_ptr->ot_desc; windex = (uint16_t)((uint16_t)((uint16_t)(ot_desc->bterminalid)<<8)|(if_ptr->ifnum)); /* check valid of input terminal descriptor */ if (ot_desc==NULL) { return USBERR_NO_DESCRIPTOR; } else { return usb_class_audio_cntrl_common(com_ptr,SET_REQUEST_ITF,SET_CUR, (uint16_t)((COPY_PROTECT_CONTROL << 8)),windex,1,(uint8_t *)buf); } }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_endpoint_command * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to performs services * for endpoint *END*--------------------------------------------------------------------*/ usb_status usb_class_audio_endpoint_command ( /* [IN] Class Interface structure void* */ audio_command_t* com_ptr, /* [IN] Buffer to receive data */ void* buf, /* [IN] The command to perform */ uint32_t cmd ) { uint8_t Endp_num; audio_stream_struct_t* if_ptr; usb_status status = USBERR_ERROR; uint16_t request_value; usb_audio_command_t* p_endpoint_command; if_ptr = (audio_stream_struct_t*)com_ptr->class_stream_handle; /* pointer to command */ p_endpoint_command = &(usb_audio_endpoint_commands[cmd]); /* get request value */ request_value = (uint16_t)((uint16_t)((uint16_t)p_endpoint_command->request_value << 8)); /* Check whether this attribute valid or not */ status = check_valid_ep(if_ptr->iso_endp_spec_desc,p_endpoint_command->control_mask); if (USB_OK == status) { /* Any isochronous pipe is supported? */ if ((NULL == if_ptr->iso_in_pipe) && (NULL == if_ptr->iso_out_pipe)) { return USBERR_INVALID_NUM_OF_ENDPOINTS; } else if (NULL!=if_ptr->iso_in_pipe) { Endp_num = (if_ptr->iso_ep_num | 0x80); } else { Endp_num = if_ptr->iso_ep_num; }/* Endif */ status = usb_class_audio_cntrl_common(com_ptr, p_endpoint_command->request_type, p_endpoint_command->request_code, request_value, (uint16_t)Endp_num, p_endpoint_command->length, (uint8_t *)buf); } return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_endpoint_command * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to performs services * for endpoint *END*--------------------------------------------------------------------*/ USB_STATUS usb_class_audio_endpoint_command ( /* [IN] Class Interface structure pointer */ AUDIO_COMMAND_PTR com_ptr, /* [IN] Buffer to receive data */ void *buf, /* [IN] The command to perform */ uint32_t cmd ) { uint8_t Endp_num; AUDIO_STREAM_INTERFACE_STRUCT_PTR if_ptr; USB_STATUS status = USBERR_ERROR; uint16_t request_value; USB_AUDIO_COMMAND_PTR p_endpoint_command; if_ptr = (AUDIO_STREAM_INTERFACE_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; /* pointer to command */ p_endpoint_command = &(usb_audio_endpoint_commands[cmd]); /* get request value */ request_value = (uint16_t)((p_endpoint_command->request_value << 8)); /* Check whether this attribute valid or not */ status = check_valid_ep(if_ptr->iso_endp_spec_desc,p_endpoint_command->control_mask); if (USB_OK == status) { /* Any isochronous pipe is supported? */ if ((NULL == if_ptr->iso_in_pipe) && (NULL == if_ptr->iso_out_pipe)) { return USBERR_INVALID_NUM_OF_ENDPOINTS; } else if (NULL!=if_ptr->iso_in_pipe) { Endp_num = (if_ptr->iso_in_pipe->ENDPOINT_NUMBER | 0x80); } else { Endp_num = if_ptr->iso_out_pipe->ENDPOINT_NUMBER; }/* Endif */ status = usb_class_audio_cntrl_common(com_ptr, p_endpoint_command->request_type, p_endpoint_command->request_code, request_value, (uint16_t)Endp_num, p_endpoint_command->length, buf); } return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_feature_command * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to get or set feature units * of audio device *END*--------------------------------------------------------------------*/ USB_STATUS usb_class_audio_feature_command ( /* [IN] Class Interface structure pointer */ AUDIO_COMMAND_PTR com_ptr, /* [IN] channel number */ uint8_t channel_no, /* [IN] Buffer to send data */ void *buf, /* [IN] The command to perform */ uint32_t cmd ) { /* Body */ uint16_t wIndex; uint16_t request_value; AUDIO_CONTROL_INTERFACE_STRUCT_PTR if_ptr; USB_AUDIO_COMMAND_PTR p_feature_command; USB_STATUS status = USBERR_ERROR; if_ptr = (AUDIO_CONTROL_INTERFACE_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; /* Validity checking: for audio interface */ status = usb_host_class_intf_validate(if_ptr); if (USB_OK == status) { /* pointer to command */ p_feature_command = &(usb_audio_feature_commands[cmd]); /* get request value */ request_value = (uint16_t)((p_feature_command->request_value << 8) | channel_no); wIndex = (uint16_t)(((if_ptr->fu_desc->bUnitID)<<8)|(if_ptr->AUDIO_G.IFNUM)); /* Check whether this attribute valid or not */ status = check_valid_fu(if_ptr->fu_desc,p_feature_command->control_mask,if_ptr->fu_desc->bControlSize*channel_no); if (USB_OK == status) { status = usb_class_audio_cntrl_common(com_ptr, p_feature_command->request_type, p_feature_command->request_code, request_value, wIndex, p_feature_command->length, buf); } } return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_feature_command * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to get or set feature units * of audio device *END*--------------------------------------------------------------------*/ usb_status usb_class_audio_feature_command ( /* [IN] Class Interface structure pointer */ audio_command_t* com_ptr, /* [IN] channel number */ uint8_t channel_no, /* [IN] Buffer to send data */ void* buf, /* [IN] The command to perform */ uint32_t cmd ) { /* Body */ uint16_t windex; uint16_t request_value; audio_control_struct_t* if_ptr; usb_audio_command_t* p_feature_command; usb_status status = USBERR_ERROR; if_ptr = (audio_control_struct_t*)com_ptr->class_control_handle; /* Validity checking: for audio interface */ status = usb_hostdev_validate(if_ptr->dev_handle); if (USB_OK == status) { /* pointer to command */ p_feature_command = &(usb_audio_feature_commands[cmd]); /* get request value */ request_value = (uint16_t)((uint16_t)((uint16_t)p_feature_command->request_value << 8) | channel_no); windex = (uint16_t)((uint16_t)((uint16_t)(if_ptr->fu_desc->bunitid) << 8)|(if_ptr->ifnum)); /* Check whether this attribute valid or not */ status = check_valid_fu(if_ptr->fu_desc,p_feature_command->control_mask,if_ptr->fu_desc->bcontrolsize*channel_no); if (USB_OK == status) { status = usb_class_audio_cntrl_common(com_ptr, p_feature_command->request_type, p_feature_command->request_code, request_value, windex, p_feature_command->length, (uint8_t *)buf); } } return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_get_mem_endpoint * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to get memory of the endpoint * from the audio device *END*--------------------------------------------------------------------*/ usb_status usb_class_audio_get_mem_endpoint ( /* [IN] Class Interface structure pointer */ audio_command_t* com_ptr, /* [IN] zero-based offset value */ uint16_t offset, /* [IN] length of the Buffer */ uint16_t blen, /* [IN] Buffer to receive data */ void* buf ) { /* Body */ uint8_t Endp_num; audio_stream_struct_t* if_ptr; usb_status status = USBERR_ERROR; // pipe_struct_t* pipe_ptr; if_ptr = (audio_stream_struct_t*)com_ptr->class_stream_handle; /* Any isochronous pipe is supported? */ if ((NULL == if_ptr->iso_in_pipe) && (NULL == if_ptr->iso_out_pipe)) { return USBERR_INVALID_NUM_OF_ENDPOINTS; } else if (if_ptr->iso_in_pipe!=NULL) { Endp_num = if_ptr->iso_ep_num; } else { Endp_num = if_ptr->iso_ep_num; }/* Endif */ status = usb_class_audio_cntrl_common(com_ptr,GET_REQUEST_EP,GET_MEM, offset,(uint16_t)Endp_num,blen,(uint8_t *)buf); return status; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_set_mem_endpoint * Returned Value : USB_OK if command has been passed on USB * Comments : * This function is called by the application to send memory of the endpoint * to the audio device *END*--------------------------------------------------------------------*/ USB_STATUS usb_class_audio_set_mem_endpoint ( /* [IN] Class Interface structure pointer */ AUDIO_COMMAND_PTR com_ptr, /* [IN] zero-based offset value */ uint16_t offset, /* [IN] length of the Buffer */ uint16_t blen, /* [IN] Buffer to send data */ void *buf ) { /* Body */ uint8_t Endp_num; AUDIO_STREAM_INTERFACE_STRUCT_PTR if_ptr; USB_STATUS status = USBERR_ERROR; if_ptr = (AUDIO_STREAM_INTERFACE_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; /* Any isochronous pipe is supported? */ if ((NULL == if_ptr->iso_in_pipe) && (NULL == if_ptr->iso_out_pipe)) { return USBERR_INVALID_NUM_OF_ENDPOINTS; } else if (if_ptr->iso_in_pipe!=NULL) { Endp_num = if_ptr->iso_in_pipe->ENDPOINT_NUMBER; } else { Endp_num = if_ptr->iso_out_pipe->ENDPOINT_NUMBER; }/* Endif */ status = usb_class_audio_cntrl_common(com_ptr,SET_REQUEST_EP,SET_MEM, offset,(uint16_t)Endp_num,blen,buf); return status; }