Use MCUX Config Tool generated CDC example.
Signed-off-by: imi415 <imi415.public@gmail.com>
This commit is contained in:
parent
06b0b6d731
commit
0649a20515
|
@ -42,8 +42,6 @@ add_executable(${MCUX_SDK_PROJECT_NAME}
|
|||
"${ProjDirPath}/board/pin_mux.h"
|
||||
"${ProjDirPath}/source/FreeRTOSConfig.h"
|
||||
"${ProjDirPath}/source/freertos_hello.c"
|
||||
"${ProjDirPath}/source/usb_application.c"
|
||||
"${ProjDirPath}/source/usb_application.h"
|
||||
"${ProjDirPath}/source/usb_device_interface_0_cic_vcom.c"
|
||||
"${ProjDirPath}/source/usb_device_interface_0_cic_vcom.h"
|
||||
"${ProjDirPath}/source/generated/usb_device_composite.c"
|
||||
|
|
|
@ -139,7 +139,7 @@ instance:
|
|||
- manufacturer_string: 'NXP'
|
||||
- product_string: 'VCOM'
|
||||
- self_powered: 'true'
|
||||
- max_power: '100'
|
||||
- max_power: '500'
|
||||
- interfaces:
|
||||
- 0:
|
||||
- interface_class: 'kClassCic'
|
||||
|
@ -199,7 +199,6 @@ instance:
|
|||
- bRefresh: '0'
|
||||
- bSynchAddress: 'NoSynchronization'
|
||||
- quick_selection: 'QS_INTERFACE_DIC_VCOM'
|
||||
- quick_selection: 'QS_DEVICE_CDC_VCOM'
|
||||
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
|
||||
/* clang-format on */
|
||||
|
||||
|
|
|
@ -119,6 +119,260 @@ static void LPUART1_init(void) {
|
|||
LPUART_Init(LPUART1_PERIPHERAL, &LPUART1_config, LPUART1_CLOCK_SOURCE);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* USB1 initialization code
|
||||
**********************************************************************************************************************/
|
||||
/* clang-format off */
|
||||
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
|
||||
instance:
|
||||
- name: 'USB1'
|
||||
- type: 'usb'
|
||||
- mode: 'device'
|
||||
- custom_name_enabled: 'false'
|
||||
- type_id: 'usb_49b3e4c7d25fbcd298641994d1b911e9'
|
||||
- functional_group: 'BOARD_InitPeripherals'
|
||||
- peripheral: 'USB1'
|
||||
- config_sets:
|
||||
- deviceSetting:
|
||||
- vendor_id: '0x1FC9'
|
||||
- product_id: '0x0094'
|
||||
- manufacturer_string: 'NXP'
|
||||
- product_string: 'VCOM'
|
||||
- self_powered: 'true'
|
||||
- max_power: '500'
|
||||
- interfaces:
|
||||
- 0:
|
||||
- interface_class: 'kClassCic'
|
||||
- setting_cic:
|
||||
- interface_name: 'CIC VCOM'
|
||||
- subclass: 'kSubclassAcm'
|
||||
- protocol: 'kProtocolNone'
|
||||
- implementation: 'kImplementationCicVcom'
|
||||
- endpoints_settings:
|
||||
- 0:
|
||||
- setting_name: 'Default'
|
||||
- endpoints:
|
||||
- 0:
|
||||
- direction: 'kIn'
|
||||
- transfer_type: 'kInterrupt'
|
||||
- synchronization: 'kNoSynchronization'
|
||||
- usage: 'kData'
|
||||
- max_packet_size_fs: 'k16'
|
||||
- polling_interval_fs: '8'
|
||||
- max_packet_size_hs: 'k16'
|
||||
- polling_interval_hs: '7'
|
||||
- bRefresh: '0'
|
||||
- bSynchAddress: 'NoSynchronization'
|
||||
- data_interface_count: '1'
|
||||
- quick_selection: 'QS_INTERFACE_CIC_VCOM'
|
||||
- 1:
|
||||
- interface_class: 'kClassDic'
|
||||
- setting_dic:
|
||||
- interface_name: 'DIC VCOM'
|
||||
- subclass: 'kSubclassNone'
|
||||
- protocol: 'kProtocolNone'
|
||||
- implementation: 'kImplementationDicVcom'
|
||||
- endpoints_settings:
|
||||
- 0:
|
||||
- setting_name: 'Default'
|
||||
- endpoints:
|
||||
- 0:
|
||||
- direction: 'kIn'
|
||||
- transfer_type: 'kBulk'
|
||||
- synchronization: 'kNoSynchronization'
|
||||
- usage: 'kData'
|
||||
- max_packet_size_fs: 'k64'
|
||||
- polling_interval_fs: '0'
|
||||
- max_packet_size_hs: 'k512'
|
||||
- polling_interval_hs: '0'
|
||||
- bRefresh: '0'
|
||||
- bSynchAddress: 'NoSynchronization'
|
||||
- 1:
|
||||
- direction: 'kOut'
|
||||
- transfer_type: 'kBulk'
|
||||
- synchronization: 'kNoSynchronization'
|
||||
- usage: 'kData'
|
||||
- max_packet_size_fs: 'k64'
|
||||
- polling_interval_fs: '0'
|
||||
- max_packet_size_hs: 'k512'
|
||||
- polling_interval_hs: '0'
|
||||
- bRefresh: '0'
|
||||
- bSynchAddress: 'NoSynchronization'
|
||||
- quick_selection: 'QS_INTERFACE_DIC_VCOM'
|
||||
- 2:
|
||||
- interface_class: 'kClassAudio_2_0'
|
||||
- setting_audio_2_0:
|
||||
- interface_name: 'Audio control'
|
||||
- subclass: 'kSubclassAudioControl'
|
||||
- protocol: 'kProtocolIPV20'
|
||||
- implementation: 'kImplementationAudioSpeaker'
|
||||
- endpoints_settings:
|
||||
- 0:
|
||||
- setting_name: 'Default'
|
||||
- endpoints: []
|
||||
- acHeader_descriptor_audio_2_0:
|
||||
- bCategory: 'kDesktopSpeaker'
|
||||
- bmControls: 'kNone'
|
||||
- units_audio_2_0:
|
||||
- 0:
|
||||
- audio_unit: 'kClockSource'
|
||||
- clock_source:
|
||||
- bClockID: '1'
|
||||
- bmAttributesLow: 'kInternalFixedClock'
|
||||
- bmAttributesHigh: 'kFreeRunning'
|
||||
- bmControlsLow: 'kHostProgrammable'
|
||||
- bmControlsHigh: 'kReadOnly'
|
||||
- 1:
|
||||
- audio_unit: 'kInputTerminal'
|
||||
- input_terminal:
|
||||
- bTerminalID: '2'
|
||||
- wTerminalType: 'kStreaming'
|
||||
- bCSourceID: 'bClockID_1'
|
||||
- bNrChannels: '2'
|
||||
- bmChannelConfig: 'USB_INTERFACE_AUDIO_CONTROL_INPUT_TERMINAL_CHANNEL_CONFIG_FL USB_INTERFACE_AUDIO_CONTROL_INPUT_TERMINAL_CHANNEL_CONFIG_FR'
|
||||
- bmControls_0_1bit: 'kNone'
|
||||
- bmControls_2_3bit: 'kNone'
|
||||
- bmControls_4_5bit: 'kNone'
|
||||
- bmControls_6_7bit: 'kNone'
|
||||
- bmControls_8_9bit: 'kNone'
|
||||
- bmControls_10_11bit: 'kNone'
|
||||
- 2:
|
||||
- audio_unit: 'kFeatureUnit'
|
||||
- feature_unit:
|
||||
- bUnitID: '3'
|
||||
- bSourceID: 'bTerminalID_2'
|
||||
- bmaControls:
|
||||
- 0:
|
||||
- bmControls_0_1bit: 'kHostProgrammable'
|
||||
- bmControls_2_3bit: 'kHostProgrammable'
|
||||
- bmControls_4_5bit: 'kNone'
|
||||
- bmControls_6_7bit: 'kNone'
|
||||
- bmControls_8_9bit: 'kNone'
|
||||
- bmControls_10_11bit: 'kNone'
|
||||
- bmControls_12_13bit: 'kNone'
|
||||
- bmControls_14_15bit: 'kNone'
|
||||
- bmControls_16_17bit: 'kNone'
|
||||
- bmControls_18_19bit: 'kNone'
|
||||
- bmControls_20_21bit: 'kNone'
|
||||
- bmControls_22_23bit: 'kNone'
|
||||
- bmControls_24_25bit: 'kNone'
|
||||
- bmControls_26_27bit: 'kNone'
|
||||
- bmControls_28_29bit: 'kNone'
|
||||
- 1:
|
||||
- bmControls_0_1bit: 'kNone'
|
||||
- bmControls_2_3bit: 'kNone'
|
||||
- bmControls_4_5bit: 'kNone'
|
||||
- bmControls_6_7bit: 'kNone'
|
||||
- bmControls_8_9bit: 'kNone'
|
||||
- bmControls_10_11bit: 'kNone'
|
||||
- bmControls_12_13bit: 'kNone'
|
||||
- bmControls_14_15bit: 'kNone'
|
||||
- bmControls_16_17bit: 'kNone'
|
||||
- bmControls_18_19bit: 'kNone'
|
||||
- bmControls_20_21bit: 'kNone'
|
||||
- bmControls_22_23bit: 'kNone'
|
||||
- bmControls_24_25bit: 'kNone'
|
||||
- bmControls_26_27bit: 'kNone'
|
||||
- bmControls_28_29bit: 'kNone'
|
||||
- 2:
|
||||
- bmControls_0_1bit: 'kNone'
|
||||
- bmControls_2_3bit: 'kNone'
|
||||
- bmControls_4_5bit: 'kNone'
|
||||
- bmControls_6_7bit: 'kNone'
|
||||
- bmControls_8_9bit: 'kNone'
|
||||
- bmControls_10_11bit: 'kNone'
|
||||
- bmControls_12_13bit: 'kNone'
|
||||
- bmControls_14_15bit: 'kNone'
|
||||
- bmControls_16_17bit: 'kNone'
|
||||
- bmControls_18_19bit: 'kNone'
|
||||
- bmControls_20_21bit: 'kNone'
|
||||
- bmControls_22_23bit: 'kNone'
|
||||
- bmControls_24_25bit: 'kNone'
|
||||
- bmControls_26_27bit: 'kNone'
|
||||
- bmControls_28_29bit: 'kNone'
|
||||
- 3:
|
||||
- audio_unit: 'kOutputTerminal'
|
||||
- output_terminal:
|
||||
- bTerminalID: '4'
|
||||
- wTerminalType: 'kSpeaker'
|
||||
- bSourceID: 'bTerminalID_3'
|
||||
- bCSourceID: 'bClockID_1'
|
||||
- bmControls_0_1bit: 'kNone'
|
||||
- bmControls_2_3bit: 'kNone'
|
||||
- bmControls_4_5bit: 'kNone'
|
||||
- bmControls_6_7bit: 'kNone'
|
||||
- bmControls_8_9bit: 'kNone'
|
||||
- 3:
|
||||
- interface_class: 'kClassAudio_2_0'
|
||||
- setting_audio_2_0:
|
||||
- interface_name: 'Audio 20'
|
||||
- subclass: 'kSubclassAudioStream'
|
||||
- protocol: 'kProtocolIPV20'
|
||||
- implementation: 'kImplementationNone'
|
||||
- endpoints_settings:
|
||||
- 0:
|
||||
- setting_name: 'Default'
|
||||
- endpoints: []
|
||||
- asInterface_descriptor_audio_2_0:
|
||||
- bTerminalLink: 'bTerminalID_2'
|
||||
- bmControlsLow: 'kNone'
|
||||
- bmControlsHigh: 'kNone'
|
||||
- bFormatType: 'kFormatI'
|
||||
- bmFormats: 'kUndefined'
|
||||
- bNrChannels: '2'
|
||||
- bmChannelConfig: ''
|
||||
- typeIFormat_descriptor_audio_2_0:
|
||||
- bSubslotSize: 'kOne'
|
||||
- bBitResolution: '0'
|
||||
- 1:
|
||||
- setting_name: 'Default2'
|
||||
- endpoints:
|
||||
- 0:
|
||||
- direction: 'kOut'
|
||||
- transfer_type: 'kIsochronous'
|
||||
- synchronization: 'kAdaptive'
|
||||
- usage: 'kData'
|
||||
- max_packet_size_fs: 'k8'
|
||||
- polling_interval_fs: '1'
|
||||
- max_packet_size_hs: 'k8'
|
||||
- polling_interval_hs: '1'
|
||||
- bRefresh: '0'
|
||||
- bSynchAddress: 'NoSynchronization'
|
||||
- cs_as_data_2_0:
|
||||
- bmControls_0_1bit: 'kNone'
|
||||
- bmControls_2_3bit: 'kNone'
|
||||
- bmControls_4_5bit: 'kNone'
|
||||
- bLockDelayUnits: 'undefined'
|
||||
- wLockDelay: '0'
|
||||
- 1:
|
||||
- direction: 'kIn'
|
||||
- transfer_type: 'kIsochronous'
|
||||
- synchronization: 'kNoSynchronization'
|
||||
- usage: 'kFeedback'
|
||||
- max_packet_size_fs: 'k8'
|
||||
- polling_interval_fs: '1'
|
||||
- max_packet_size_hs: 'k8'
|
||||
- polling_interval_hs: '1'
|
||||
- bRefresh: '0'
|
||||
- bSynchAddress: 'NoSynchronization'
|
||||
- asInterface_descriptor_audio_2_0:
|
||||
- bTerminalLink: 'bTerminalID_2'
|
||||
- bmControlsLow: 'kNone'
|
||||
- bmControlsHigh: 'kNone'
|
||||
- bFormatType: 'kFormatI'
|
||||
- bmFormats: 'kPCM'
|
||||
- bNrChannels: '2'
|
||||
- bmChannelConfig: 'USB_INTERFACE_AUDIO_CONTROL_INPUT_TERMINAL_CHANNEL_CONFIG_FL USB_INTERFACE_AUDIO_CONTROL_INPUT_TERMINAL_CHANNEL_CONFIG_FR'
|
||||
- typeIFormat_descriptor_audio_2_0:
|
||||
- bSubslotSize: 'kOne'
|
||||
- bBitResolution: '0'
|
||||
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
|
||||
/* clang-format on */
|
||||
|
||||
static void USB1_init(void) {
|
||||
USB_DeviceApplicationInit();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
* Initialization functions
|
||||
**********************************************************************************************************************/
|
||||
|
@ -126,6 +380,7 @@ void BOARD_InitPeripherals(void)
|
|||
{
|
||||
/* Initialize components */
|
||||
LPUART1_init();
|
||||
USB1_init();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************
|
||||
|
|
|
@ -585,13 +585,13 @@
|
|||
</config_set>
|
||||
</instance>
|
||||
<instance name="USB1" uuid="fa0728df-ea7a-47b6-9678-549e8a96b072" type="usb" type_id="usb_49b3e4c7d25fbcd298641994d1b911e9" mode="device" peripheral="USB1" enabled="true" comment="" custom_name_enabled="false" editing_lock="false">
|
||||
<config_set name="deviceSetting" quick_selection="QS_DEVICE_CDC_VCOM">
|
||||
<config_set name="deviceSetting">
|
||||
<setting name="vendor_id" value="0x1FC9"/>
|
||||
<setting name="product_id" value="0x0094"/>
|
||||
<setting name="manufacturer_string" value="NXP"/>
|
||||
<setting name="product_string" value="VCOM"/>
|
||||
<setting name="self_powered" value="true"/>
|
||||
<setting name="max_power" value="100"/>
|
||||
<setting name="max_power" value="500"/>
|
||||
<array name="interfaces">
|
||||
<struct name="0">
|
||||
<setting name="interface_class" value="kClassCic"/>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
#include "board.h"
|
||||
#include "usb_device_composite.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
|
@ -29,8 +30,7 @@
|
|||
* Prototypes
|
||||
******************************************************************************/
|
||||
static void hello_task(void *pvParameters);
|
||||
|
||||
void USB_DeviceApplicationInit(void);
|
||||
static void usb_task(void *parameters);
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
|
@ -48,13 +48,20 @@ int main(void)
|
|||
|
||||
USB_DeviceApplicationInit();
|
||||
|
||||
if (xTaskCreate(hello_task, "Hello_task", configMINIMAL_STACK_SIZE + 100, NULL, hello_task_PRIORITY, NULL) !=
|
||||
pdPASS)
|
||||
{
|
||||
if (xTaskCreate(hello_task, "Hello_task", configMINIMAL_STACK_SIZE + 100, NULL, hello_task_PRIORITY, NULL) != pdPASS) {
|
||||
PRINTF("Task creation failed!.\r\n");
|
||||
while (1)
|
||||
;
|
||||
for(;;) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
if(xTaskCreate(usb_task, "USB_task", configMINIMAL_STACK_SIZE + 100, NULL, 4, NULL) != pdPASS) {
|
||||
PRINTF("USB task creation failed.\r\n");
|
||||
for(;;) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
vTaskStartScheduler();
|
||||
for (;;)
|
||||
;
|
||||
|
@ -71,3 +78,10 @@ static void hello_task(void *pvParameters)
|
|||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void usb_task(void *pvParameters) {
|
||||
for(;;) {
|
||||
USB_DeviceTasks();
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@
|
|||
#define USB_DEVICE_SUBCLASS (0x02U)
|
||||
#define USB_DEVICE_PROTOCOL (0x01U)
|
||||
/*! @brief Maximum current USB device can draw from bus in milliamperes.*/
|
||||
#define USB_DEVICE_MAX_POWER (0x64U)
|
||||
#define USB_DEVICE_MAX_POWER (0xF4U)
|
||||
|
||||
#define USB_DEVICE_CONFIGURATION_COUNT (1U)
|
||||
#define USB_DEVICE_STRING_COUNT (3U)
|
||||
|
|
|
@ -1,180 +0,0 @@
|
|||
#include "fsl_device_registers.h"
|
||||
#include "fsl_debug_console.h"
|
||||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "usb_device_config.h"
|
||||
#include "usb.h"
|
||||
#include "usb_device.h"
|
||||
#include "usb_device_class.h"
|
||||
#include "usb_device_cdc_acm.h"
|
||||
#include "usb_device_ch9.h"
|
||||
|
||||
#include "usb_phy.h"
|
||||
|
||||
#include "usb_device_descriptor.h"
|
||||
|
||||
#include "usb_application.h"
|
||||
|
||||
#define HS_CDC_VCOM_BULK_OUT_PACKET_SIZE 512
|
||||
|
||||
usb_status_t USB_DeviceCdcVcomCallback(class_handle_t handle, uint32_t event, void *param);
|
||||
usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param);
|
||||
|
||||
extern usb_device_class_struct_t g_UsbDeviceInterface0CicVcomConfig;
|
||||
extern usb_device_endpoint_struct_t g_UsbDeviceInterface1DicVcomSetting0DefaultEndpoints[];
|
||||
|
||||
USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static usb_cdc_acm_info_t s_usbCdcAcmInfo;
|
||||
|
||||
/* Data buffer for receiving and sending*/
|
||||
USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_currRecvBuf[DATA_BUFF_SIZE];
|
||||
USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_currSendBuf[DATA_BUFF_SIZE];
|
||||
|
||||
USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
|
||||
static uint8_t s_lineCoding[LINE_CODING_SIZE] = {
|
||||
/* E.g. 0x00,0xC2,0x01,0x00 : 0x0001C200 is 115200 bits per second */
|
||||
(LINE_CODING_DTERATE >> 0U) & 0x000000FFU,
|
||||
(LINE_CODING_DTERATE >> 8U) & 0x000000FFU,
|
||||
(LINE_CODING_DTERATE >> 16U) & 0x000000FFU,
|
||||
(LINE_CODING_DTERATE >> 24U) & 0x000000FFU,
|
||||
LINE_CODING_CHARFORMAT,
|
||||
LINE_CODING_PARITYTYPE,
|
||||
LINE_CODING_DATABITS};
|
||||
|
||||
static usb_cdc_vcom_struct_t s_cdcVcom;
|
||||
|
||||
static usb_device_class_config_struct_t s_cdcAcmConfig[1] = {{
|
||||
.classCallback = USB_DeviceCdcVcomCallback,
|
||||
.classHandle = 0,
|
||||
.classInfomation = &g_UsbDeviceInterface0CicVcomConfig
|
||||
}};
|
||||
|
||||
static usb_device_class_config_list_struct_t s_cdcAcmConfigList = {
|
||||
.config = s_cdcAcmConfig,
|
||||
.deviceCallback = USB_DeviceCallback,
|
||||
.count = 1
|
||||
};
|
||||
|
||||
void USB_OTG1_IRQHandler(void) {
|
||||
USB_DeviceEhciIsrFunction(s_cdcVcom.deviceHandle);
|
||||
}
|
||||
|
||||
void USB_DeviceClockInit(void) {
|
||||
usb_phy_config_struct_t phy_config = {
|
||||
.D_CAL = 0x0CU, // BOARD_USB_PHY_D_CAL
|
||||
.TXCAL45DP = 0x06U,
|
||||
.TXCAL45DM = 0x06U
|
||||
};
|
||||
|
||||
USB_EhciPhyInit(CONTROLLER_ID, 24000000UL, &phy_config);
|
||||
}
|
||||
|
||||
void USB_DeviceApplicationInit(void) {
|
||||
USB_DeviceClockInit();
|
||||
|
||||
s_cdcVcom.speed = USB_SPEED_HIGH;
|
||||
s_cdcVcom.attach = 0;
|
||||
s_cdcVcom.cdcAcmHandle = (class_handle_t)NULL;
|
||||
s_cdcVcom.deviceHandle = NULL;
|
||||
|
||||
if(kStatus_USB_Success != USB_DeviceClassInit(CONTROLLER_ID, &s_cdcAcmConfigList, &s_cdcVcom.deviceHandle)) {
|
||||
PRINTF("DeviceClass init failed.\r\n");
|
||||
} else {
|
||||
s_cdcVcom.cdcAcmHandle = s_cdcAcmConfigList.config->classHandle;
|
||||
}
|
||||
|
||||
uint8_t usbDeviceEhciIrq[] = USBHS_IRQS;
|
||||
uint8_t irqNumber = usbDeviceEhciIrq[CONTROLLER_ID - kUSB_ControllerEhci0];
|
||||
|
||||
NVIC_SetPriority(irqNumber, 6U);
|
||||
EnableIRQ(irqNumber);
|
||||
|
||||
SDK_DelayAtLeastUs(5000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
|
||||
|
||||
USB_DeviceRun(s_cdcVcom.deviceHandle);
|
||||
}
|
||||
|
||||
usb_status_t USB_DeviceCdcVcomCallback(class_handle_t handle, uint32_t event, void *param) {
|
||||
PRINTF("USB_DeviceCdcVcomCallback 0x%x\r\n", event);
|
||||
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
uint32_t len;
|
||||
uint8_t *uartBitmap;
|
||||
usb_cdc_acm_info_t *acmInfo = &s_usbCdcAcmInfo;
|
||||
usb_device_cdc_acm_request_param_struct_t *acmReqParam;
|
||||
usb_device_endpoint_callback_message_struct_t *epCbParam;
|
||||
acmReqParam = (usb_device_cdc_acm_request_param_struct_t *)param;
|
||||
epCbParam = (usb_device_endpoint_callback_message_struct_t *)param;
|
||||
|
||||
switch(event) {
|
||||
case kUSB_DeviceCdcEventSetLineCoding: {
|
||||
if(acmReqParam->isSetup == 1) {
|
||||
*(acmReqParam->buffer) = s_lineCoding;
|
||||
} else {
|
||||
*(acmReqParam->length) = 0;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
|
||||
return kStatus_USB_Success;
|
||||
}
|
||||
|
||||
usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param) {
|
||||
PRINTF("USB_DeviceCallback 0x%x\r\n", event);
|
||||
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
uint16_t *temp16 = (uint16_t *)param;
|
||||
uint8_t *temp8 = (uint8_t *)param;
|
||||
|
||||
switch(event) {
|
||||
|
||||
// 0x01
|
||||
case kUSB_DeviceEventBusReset: {
|
||||
s_cdcVcom.attach = 0;
|
||||
s_cdcVcom.currentConfiguration = 0;
|
||||
if(USB_DeviceClassGetSpeed(CONTROLLER_ID, &s_cdcVcom.speed) == kStatus_USB_Success) {
|
||||
USB_DeviceSetSpeed(handle, s_cdcVcom.speed);
|
||||
}
|
||||
} break;
|
||||
|
||||
// 0x09
|
||||
case kUSB_DeviceEventSetConfiguration: {
|
||||
if((*temp8) == 0) {
|
||||
s_cdcVcom.attach = 0;
|
||||
s_cdcVcom.currentConfiguration = 0U;
|
||||
} else if((*temp8) == USB_COMPOSITE_CONFIGURATION_INDEX) {
|
||||
s_cdcVcom.attach = 1;
|
||||
s_cdcVcom.currentConfiguration = *temp8;
|
||||
|
||||
USB_DeviceCdcAcmRecv(s_cdcVcom.cdcAcmHandle, USB_INTERFACE_1_DIC_VCOM_SETTING_0_EP_1_BULK_OUT, s_currRecvBuf,
|
||||
g_UsbDeviceInterface1DicVcomSetting0DefaultEndpoints[0].maxPacketSize);
|
||||
}
|
||||
} break;
|
||||
|
||||
// 0xb
|
||||
case kUSB_DeviceEventGetDeviceDescriptor: {
|
||||
if(param) {
|
||||
error = USB_DeviceGetDeviceDescriptor(handle, (usb_device_get_device_descriptor_struct_t *)param);
|
||||
}
|
||||
} break;
|
||||
|
||||
// 0xc
|
||||
case kUSB_DeviceEventGetConfigurationDescriptor: {
|
||||
if(param) {
|
||||
error = USB_DeviceGetConfigurationDescriptor(handle,
|
||||
(usb_device_get_configuration_descriptor_struct_t *)param);
|
||||
}
|
||||
} break;
|
||||
|
||||
// 0xd
|
||||
case kUSB_DeviceEventGetStringDescriptor: {
|
||||
if (param) {
|
||||
error = USB_DeviceGetStringDescriptor(handle, (usb_device_get_string_descriptor_struct_t *)param);
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return kStatus_USB_Success;
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
#ifndef _USB_APPLICATION_H_
|
||||
#define _USB_APPLICATION_H_ 1
|
||||
#include "FreeRTOS.h"
|
||||
#include "semphr.h"
|
||||
#include "event_groups.h"
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
#if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
|
||||
#define CONTROLLER_ID kUSB_ControllerEhci0
|
||||
#define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
|
||||
#endif
|
||||
#if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
|
||||
#define CONTROLLER_ID kUSB_ControllerKhci0
|
||||
#define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
|
||||
#endif
|
||||
#if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
|
||||
#define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0
|
||||
#define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
|
||||
#endif
|
||||
#if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
|
||||
#define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0
|
||||
#define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
|
||||
#endif
|
||||
#if defined(__GIC_PRIO_BITS)
|
||||
#define USB_DEVICE_INTERRUPT_PRIORITY (25U)
|
||||
#elif defined(__NVIC_PRIO_BITS) && (__NVIC_PRIO_BITS >= 3)
|
||||
#define USB_DEVICE_INTERRUPT_PRIORITY (6U)
|
||||
#else
|
||||
#define USB_DEVICE_INTERRUPT_PRIORITY (3U)
|
||||
#endif
|
||||
/* Currently configured line coding */
|
||||
#define LINE_CODING_SIZE (0x07)
|
||||
#define LINE_CODING_DTERATE (115200)
|
||||
#define LINE_CODING_CHARFORMAT (0x00)
|
||||
#define LINE_CODING_PARITYTYPE (0x00)
|
||||
#define LINE_CODING_DATABITS (0x08)
|
||||
/* Communications feature */
|
||||
#define COMM_FEATURE_DATA_SIZE (0x02)
|
||||
#define STATUS_ABSTRACT_STATE (0x0000)
|
||||
#define COUNTRY_SETTING (0x0000)
|
||||
/* Notification of serial state */
|
||||
#define NOTIF_PACKET_SIZE (0x08)
|
||||
#define UART_BITMAP_SIZE (0x02)
|
||||
#define NOTIF_REQUEST_TYPE (0xA1)
|
||||
/* Define the types for application */
|
||||
typedef struct _usb_cdc_vcom_struct
|
||||
{
|
||||
usb_device_handle deviceHandle; /* USB device handle. */
|
||||
class_handle_t cdcAcmHandle; /* USB CDC ACM class handle. */
|
||||
volatile uint8_t attach; /* A flag to indicate whether a usb device is attached. 1: attached, 0: not attached */
|
||||
TaskHandle_t deviceTaskHandle; /* USB device task handle. */
|
||||
TaskHandle_t applicationTaskHandle; /* Application task handle. */
|
||||
uint8_t speed; /* Speed of USB device. USB_SPEED_FULL/USB_SPEED_LOW/USB_SPEED_HIGH. */
|
||||
volatile uint8_t
|
||||
startTransactions; /* A flag to indicate whether a CDC device is ready to transmit and receive data. */
|
||||
uint8_t currentConfiguration; /* Current configuration value. */
|
||||
uint8_t currentInterfaceAlternateSetting[USB_COMPOSITE_INTERFACE_COUNT]; /* Current alternate setting value for each
|
||||
interface. */
|
||||
} usb_cdc_vcom_struct_t;
|
||||
/* Define the information relates to abstract control model */
|
||||
typedef struct _usb_cdc_acm_info
|
||||
{
|
||||
uint8_t serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE]; /* Serial state buffer of the CDC device to notify the
|
||||
serial state to host. */
|
||||
bool dtePresent; /* A flag to indicate whether DTE is present. */
|
||||
uint16_t breakDuration; /* Length of time in milliseconds of the break signal */
|
||||
uint8_t dteStatus; /* Status of data terminal equipment */
|
||||
uint8_t currentInterface; /* Current interface index. */
|
||||
uint16_t uartState; /* UART state of the CDC device. */
|
||||
} usb_cdc_acm_info_t;
|
||||
#endif /* _USB_APPLICATION_H_ */
|
Loading…
Reference in New Issue