![]() |
MT2523 API Reference
LinkIt SDK v4
|
This section introduces the USB APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enumerations, structures and functions. More...
This section introduces the USB APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enumerations, structures and functions.
| Terms | Details |
|---|---|
| USB | Universal Serial Bus. USB was designed to standardize the connection of computer peripherals (including keyboards, pointing devices, digital cameras, printers, portable media players, disk drives and network adapters) to personal computers, both to communicate and to supply electric power. It has become commonplace on other devices, such as smart phones, PDAs and video game consoles.[3] USB has effectively replaced a variety of earlier interfaces, such as serial and parallel ports, as well as separate power chargers for portable devices. For more information, please refer to an introduction to the USB in Wikipedia. |
| PIO | Programmed Input / Output. It is a transmission mode to use CPU to move data. |
The software architecture of the USB driver is shown in the diagram below.
Functions | |
| hal_usb_status_t | hal_usb_init (void) |
| This function initializes the USB hardware module. More... | |
| hal_usb_status_t | hal_usb_configure_driver (void) |
| This function initializes the USB HAL driver. More... | |
| hal_usb_status_t | hal_usb_register_driver_callback (hal_usb_driver_handler_type_t type, uint32_t ep_num, hal_usb_driver_interrupt_handler_t hdlr) |
| This function registers a callback function. More... | |
| hal_usb_status_t | hal_usb_pull_up_dp_line (void) |
| This function pulls the USB DP pin to high. More... | |
| hal_usb_status_t | hal_usb_reset_hardware (void) |
| This function applies the USB hardware soft reset. More... | |
| hal_usb_status_t | hal_usb_reset_fifo (void) |
| This function applies USB FIFO address reset at all endpoints. More... | |
| hal_usb_status_t | hal_usb_deinit (void) |
| This function releases the USB hardware resource. More... | |
| hal_usb_status_t | hal_usb_set_address (uint8_t addr, hal_usb_set_address_state_t state) |
| This function configures the USB address. More... | |
| hal_usb_status_t | hal_usb_init_tx_endpoint (uint32_t ep_num, uint16_t data_size, hal_usb_endpoint_transfer_type_t type, bool double_fifo) |
| This function initializes the USB endpoint in TX direction. More... | |
| hal_usb_status_t | hal_usb_init_rx_endpoint (uint32_t ep_num, uint16_t data_size, hal_usb_endpoint_transfer_type_t type, bool double_fifo) |
| This function initialize the USB endpoint in RX direction. More... | |
| hal_usb_status_t | hal_usb_enable_tx_endpoint (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, hal_usb_dma_usage_t dma_usage_type, bool is_flush) |
| This function enables the USB endpoint TX interrupt. More... | |
| hal_usb_status_t | hal_usb_enable_rx_endpoint (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, hal_usb_dma_usage_t dma_usage_type, bool is_flush) |
| This function enables the USB endpoint RX interrupt. More... | |
| hal_usb_status_t | hal_usb_disable_tx_endpoint (uint32_t ep_num) |
| This function disables the USB endpoint TX interrupt. More... | |
| hal_usb_status_t | hal_usb_disable_rx_endpoint (uint32_t ep_num) |
| This function disables the USB endpoint RX interrupt. More... | |
| hal_usb_status_t | hal_usb_clear_tx_endpoint_data_toggle (uint32_t ep_num) |
| This function clears the TX endpoint data toggle. More... | |
| hal_usb_status_t | hal_usb_clear_rx_endpoint_data_toggle (uint32_t ep_num) |
| This function clears the TX endpoint data toggle. More... | |
| hal_usb_status_t | hal_usb_read_endpoint_fifo (uint32_t ep_num, uint16_t nBytes, void *pDst) |
| This function reads the USB data from FIFO. More... | |
| hal_usb_status_t | hal_usb_write_endpoint_fifo (uint32_t ep_num, uint16_t nBytes, void *pSrc) |
| This function writes the USB data to FIFO. More... | |
| hal_usb_status_t | hal_usb_set_endpoint_stall (uint32_t ep_num, hal_usb_endpoint_direction_t direction, bool stall_enable) |
| This function sets the USB endpoint n to stall, flush or clear data toggle. More... | |
| bool | hal_usb_get_endpoint_stall_status (uint32_t ep_num, hal_usb_endpoint_direction_t direction) |
| This function queries the stall status of the USB endpoint n. More... | |
| hal_usb_status_t | hal_usb_get_endpoint_0_status (bool *p_transaction_end, bool *p_sent_stall) |
| This function gets the USB control pipe hardware status. More... | |
| hal_usb_status_t | hal_usb_update_endpoint_0_state (hal_usb_endpoint_0_driver_state_t state, bool stall, bool end) |
| This function sets the USB control pipe hardware status. More... | |
| uint32_t | hal_usb_get_rx_packet_length (uint32_t ep_num) |
| This function gets the data packet length at the RX endpoint. More... | |
| hal_usb_status_t | hal_usb_set_endpoint_tx_ready (uint32_t ep_num) |
| This function sets the USB packet ready once the data is fully written into FIFO. More... | |
| hal_usb_status_t | hal_usb_set_endpoint_rx_ready (uint32_t ep_num) |
| This function sets the USB packet ready once the data is fully read from FIFO. More... | |
| hal_usb_status_t | hal_usb_clear_tx_endpoint_fifo (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, bool b_reset_toggle) |
| This function flushes data packet in the TX FIFO and clears data toggle by request. More... | |
| hal_usb_status_t | hal_usb_clear_rx_endpoint_fifo (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, bool b_reset_toggle) |
| This function flushes data packet in RX FIFO and clears the data toggle by request. More... | |
| hal_usb_status_t | hal_usb_get_dma_channel (uint32_t ep_tx_num, uint32_t ep_rx_num, hal_usb_endpoint_direction_t direction, bool same_chan) |
| This function allocates a USB DMA channel For more information on the number of DMA channels on the LinkIt platform for RTOS, please refer to HAL_USB_MAX_NUMBER_ENDPOINT. More... | |
| hal_usb_status_t | hal_usb_release_dma_channel (uint32_t ep_tx_num, uint32_t ep_rx_num, hal_usb_endpoint_direction_t direction, bool same_chan) |
| This function frees a USB DMA channel resource. More... | |
| hal_usb_status_t | hal_usb_start_dma_channel (uint32_t ep_num, hal_usb_endpoint_direction_t direction, hal_usb_endpoint_transfer_type_t ep_type, void *addr, uint32_t length, hal_usb_dma_handler_t callback, bool callback_upd_run, hal_usb_dma_type_t dma_type) |
| This function sets up the USB DMA channel to transfer data. More... | |
| hal_usb_status_t | hal_usb_stop_dma_channel (uint32_t ep_num, hal_usb_endpoint_direction_t direction) |
| This function stops the USB DMA channel and clears pending DMA interrupts. More... | |
| bool | hal_usb_is_dma_running (uint32_t ep_num, hal_usb_endpoint_direction_t direction) |
| This function queries the DMA execution status. More... | |
| bool | hal_usb_is_high_speed (void) |
| This function queries current USB speed. More... | |
| bool | hal_usb_is_endpoint_tx_empty (uint32_t ep_num) |
| This function checks if the TX endpoint FIFO is empty or not. More... | |
| bool | hal_usb_is_endpoint_rx_empty (uint32_t ep_num) |
| This function checks if the RX endpoint FIFO is empty or not. More... | |
| hal_usb_status_t | hal_usb_enter_test_mode (hal_usb_test_mode_type_t test_selector) |
| This function sets the USB hardware into test mode. More... | |
Modules | |
| Define | |
| Enum. | |
| Typedefs. | |
| hal_usb_status_t hal_usb_clear_rx_endpoint_data_toggle | ( | uint32_t | ep_num | ) |
This function clears the TX endpoint data toggle.
It's to force the endpoint data toggle to switch and the data packet to be cleared from the FIFO, regardless if the acknowledgement was received.
| [in] | ep_num | is the endpoint number to clear data toggle. |
| hal_usb_status_t hal_usb_clear_rx_endpoint_fifo | ( | uint32_t | ep_num, |
| hal_usb_endpoint_transfer_type_t | ep_type, | ||
| bool | b_reset_toggle | ||
| ) |
This function flushes data packet in RX FIFO and clears the data toggle by request.
| [in] | ep_num | is the endpoint number. |
| [in] | ep_type | is the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | b_reset_toggle | is set to true to execute clear data toggle. |
| hal_usb_status_t hal_usb_clear_tx_endpoint_data_toggle | ( | uint32_t | ep_num | ) |
This function clears the TX endpoint data toggle.
It's to force the endpoint data toggle to switch and the data packet to be cleared from the FIFO, regardless if the acknowledgement was received.
| [in] | ep_num | is the endpoint number to clear data toggle. |
| hal_usb_status_t hal_usb_clear_tx_endpoint_fifo | ( | uint32_t | ep_num, |
| hal_usb_endpoint_transfer_type_t | ep_type, | ||
| bool | b_reset_toggle | ||
| ) |
This function flushes data packet in the TX FIFO and clears data toggle by request.
| [in] | ep_num | is the endpoint number. |
| [in] | ep_type | is the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | b_reset_toggle | is set to true to execute clear data toggle. |
| hal_usb_status_t hal_usb_configure_driver | ( | void | ) |
This function initializes the USB HAL driver.
This function will initialize all required parameters, callback function and endpoint information in USB HAL driver.
| hal_usb_status_t hal_usb_deinit | ( | void | ) |
This function releases the USB hardware resource.
This function deinitializes the USB hardware, sets the USB hardware in low power mode and releases the USB related clock tree and power source.
| hal_usb_status_t hal_usb_disable_rx_endpoint | ( | uint32_t | ep_num | ) |
This function disables the USB endpoint RX interrupt.
| [in] | ep_num | is the endpoint number to disable. |
| hal_usb_status_t hal_usb_disable_tx_endpoint | ( | uint32_t | ep_num | ) |
This function disables the USB endpoint TX interrupt.
| [in] | ep_num | is the endpoint number to disable. |
| hal_usb_status_t hal_usb_enable_rx_endpoint | ( | uint32_t | ep_num, |
| hal_usb_endpoint_transfer_type_t | ep_type, | ||
| hal_usb_dma_usage_t | dma_usage_type, | ||
| bool | is_flush | ||
| ) |
This function enables the USB endpoint RX interrupt.
| [in] | ep_num | is the endpoint to initialize. |
| [in] | ep_type | is the endpoint type defined in USB 2.0 Specification. Such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | dma_usage_type | is set to PIO or DMA mode. |
| [in] | is_flush | flushes the USB FIFO data when the function is executed. |
| hal_usb_status_t hal_usb_enable_tx_endpoint | ( | uint32_t | ep_num, |
| hal_usb_endpoint_transfer_type_t | ep_type, | ||
| hal_usb_dma_usage_t | dma_usage_type, | ||
| bool | is_flush | ||
| ) |
This function enables the USB endpoint TX interrupt.
| [in] | ep_num | is the endpoint to initialize. |
| [in] | ep_type | is the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | dma_usage_type | is set to PIO or DMA mode. |
| [in] | is_flush | flushes the USB FIFO data when the function is executed. |
| hal_usb_status_t hal_usb_enter_test_mode | ( | hal_usb_test_mode_type_t | test_selector | ) |
This function sets the USB hardware into test mode.
To activate a test mode, the USB 2.0 Specification defines the SET_FEATURE command as the desired interface. The USB-IF offers a free High Speed electrical Test Tool (HSET) for Microsoft Windows OS, to activate the various test modes and operations
| [in] | test_selector | select the test function. |
| hal_usb_status_t hal_usb_get_dma_channel | ( | uint32_t | ep_tx_num, |
| uint32_t | ep_rx_num, | ||
| hal_usb_endpoint_direction_t | direction, | ||
| bool | same_chan | ||
| ) |
This function allocates a USB DMA channel For more information on the number of DMA channels on the LinkIt platform for RTOS, please refer to HAL_USB_MAX_NUMBER_ENDPOINT.
| [in] | ep_tx_num | is the endpoint number in TX direction. |
| [in] | ep_rx_num | is the endpoint number in RX direction. |
| [in] | direction | is the USB endpoint direction. This parameter is ignored, if the same channel is used. |
| [in] | same_chan | the TX and RX use the same DMA channel. |
| hal_usb_status_t hal_usb_get_endpoint_0_status | ( | bool * | p_transaction_end, |
| bool * | p_sent_stall | ||
| ) |
This function gets the USB control pipe hardware status.
p_transaction_end: This bit is set when a control transaction ends before the DataEnd bit is set. An interrupt will be generated and the FIFO flushed. p_sent_stall: This bit is set when a STALL handshake is transmitted.
| [out] | p_transaction_end | is the result of control pipe transaction end. |
| [out] | p_sent_stall | is the result of control pipe sent stall. |
| bool hal_usb_get_endpoint_stall_status | ( | uint32_t | ep_num, |
| hal_usb_endpoint_direction_t | direction | ||
| ) |
This function queries the stall status of the USB endpoint n.
It is usually used to response to the host endpoint 0 command: GET_STATUS
| [in] | ep_num | is the endpoint number. |
| [in] | direction | is the USB endpoint direction. |
| uint32_t hal_usb_get_rx_packet_length | ( | uint32_t | ep_num | ) |
This function gets the data packet length at the RX endpoint.
| [in] | ep_num | is the endpoint number. |
| hal_usb_status_t hal_usb_init | ( | void | ) |
This function initializes the USB hardware module.
Call this function before using the USB service. It also enables the USB related clock tree and power source.
| hal_usb_status_t hal_usb_init_rx_endpoint | ( | uint32_t | ep_num, |
| uint16_t | data_size, | ||
| hal_usb_endpoint_transfer_type_t | type, | ||
| bool | double_fifo | ||
| ) |
This function initialize the USB endpoint in RX direction.
| [in] | ep_num | is the endpoint to initialize. |
| [in] | data_size | is the maximum packet size at this endpoint. For more details about maximum packet size, please refer to USB 2.0 Specification. |
| [in] | type | is the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | double_fifo | allocates two FIFO buffers, if double_fifo is enabled. |
| hal_usb_status_t hal_usb_init_tx_endpoint | ( | uint32_t | ep_num, |
| uint16_t | data_size, | ||
| hal_usb_endpoint_transfer_type_t | type, | ||
| bool | double_fifo | ||
| ) |
This function initializes the USB endpoint in TX direction.
| [in] | ep_num | is the endpoint to initialize. |
| [in] | data_size | is the maximum packet size at this endpoint. For more details about maximum packet size, please refer to USB 2.0 Specification. |
| [in] | type | is the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | double_fifo | two FIFO buffers are allocated, if double_fifo is enabled. It may cost more FIFO SRAM. |
| bool hal_usb_is_dma_running | ( | uint32_t | ep_num, |
| hal_usb_endpoint_direction_t | direction | ||
| ) |
This function queries the DMA execution status.
| [in] | ep_num | is the endpoint number. |
| [in] | direction | is the USB endpoint direction. |
| bool hal_usb_is_endpoint_rx_empty | ( | uint32_t | ep_num | ) |
This function checks if the RX endpoint FIFO is empty or not.
| [in] | ep_num | is the endpoint number. |
| bool hal_usb_is_endpoint_tx_empty | ( | uint32_t | ep_num | ) |
This function checks if the TX endpoint FIFO is empty or not.
| [in] | ep_num | is the endpoint number. |
| bool hal_usb_is_high_speed | ( | void | ) |
| hal_usb_status_t hal_usb_pull_up_dp_line | ( | void | ) |
This function pulls the USB DP pin to high.
It starts the USB connection flow. For more details on DP, please refer to the USB 2.0 Specification.
| hal_usb_status_t hal_usb_read_endpoint_fifo | ( | uint32_t | ep_num, |
| uint16_t | nBytes, | ||
| void * | pDst | ||
| ) |
This function reads the USB data from FIFO.
Reading from these addresses unloads data from the RX FIFO for the corresponding endpoint.
| [in] | ep_num | is the endpoint number. |
| [in] | nBytes | is the number of bytes to read. |
| [in] | pDst | is a pointer to the destination. |
| hal_usb_status_t hal_usb_register_driver_callback | ( | hal_usb_driver_handler_type_t | type, |
| uint32_t | ep_num, | ||
| hal_usb_driver_interrupt_handler_t | hdlr | ||
| ) |
This function registers a callback function.
| [in] | type | is the interrupt handler type. Please refer to hal_usb_driver_handler_type_t. |
| [in] | ep_num | is the endpoint number. The interrupt handler must be binding to a specific endpoint number if it uses HAL_USB_DRV_HDLR_EP_TX and HAL_USB_DRV_HDLR_EP_RX. |
| [in] | hdlr | is the callback function. Please refer to hal_usb_driver_interrupt_handler_t. |
| hal_usb_status_t hal_usb_release_dma_channel | ( | uint32_t | ep_tx_num, |
| uint32_t | ep_rx_num, | ||
| hal_usb_endpoint_direction_t | direction, | ||
| bool | same_chan | ||
| ) |
This function frees a USB DMA channel resource.
For more information on the number of DMA channels on the LinkIt platform for RTOS, please refer to HAL_USB_MAX_NUMBER_ENDPOINT.
| [in] | ep_tx_num | is the endpoint number in TX direction. |
| [in] | ep_rx_num | is the endpoint number in RX direction. |
| [in] | direction | is the USB endpoint direction. This parameter is ignored, if the same channel is used. |
| [in] | same_chan | the TX and RX use the same DMA channel. |
| hal_usb_status_t hal_usb_reset_fifo | ( | void | ) |
This function applies USB FIFO address reset at all endpoints.
| hal_usb_status_t hal_usb_reset_hardware | ( | void | ) |
This function applies the USB hardware soft reset.
| hal_usb_status_t hal_usb_set_address | ( | uint8_t | addr, |
| hal_usb_set_address_state_t | state | ||
| ) |
This function configures the USB address.
In the USB 2.0 Specifications, the USB address is set by the USB control pipe. The address is 1~127(7-bits). This address should be written with the address received through a SET_ADDRESS command, which will then be used for decoding the function address in subsequent token packets.
| [in] | addr | the USB address set by the USB control pipe through a SET_ADDRESS command. |
| [in] | state | the current state for the set address function. The address writes to hardware only in HAL_USB_SET_ADDR_STATUS state. It must make sure the SET_ADDRESS command is completed. |
| hal_usb_status_t hal_usb_set_endpoint_rx_ready | ( | uint32_t | ep_num | ) |
This function sets the USB packet ready once the data is fully read from FIFO.
Hardware issues an interrupt if RX endpoint received a packet. Hardware will start to receive the next packet if data is read from FIFO and RX packet is set to ready.
| [in] | ep_num | is the endpoint number. |
| hal_usb_status_t hal_usb_set_endpoint_stall | ( | uint32_t | ep_num, |
| hal_usb_endpoint_direction_t | direction, | ||
| bool | stall_enable | ||
| ) |
This function sets the USB endpoint n to stall, flush or clear data toggle.
This function is used to execute (1) endpoint stall, (2) FIFO flush and (3) clear data toggle.
| [in] | ep_num | is the endpoint number. |
| [in] | direction | is the USB endpoint direction. |
| [in] | stall_enable | enables or disables the stall operation. |
| hal_usb_status_t hal_usb_set_endpoint_tx_ready | ( | uint32_t | ep_num | ) |
This function sets the USB packet ready once the data is fully written into FIFO.
Hardware will send the packet out if data is written to the FIFO and the TX packet is set to ready. Null length packet (ZLP) will be sent if the data is not written to the FIFO.
| [in] | ep_num | is the endpoint number. |
| hal_usb_status_t hal_usb_start_dma_channel | ( | uint32_t | ep_num, |
| hal_usb_endpoint_direction_t | direction, | ||
| hal_usb_endpoint_transfer_type_t | ep_type, | ||
| void * | addr, | ||
| uint32_t | length, | ||
| hal_usb_dma_handler_t | callback, | ||
| bool | callback_upd_run, | ||
| hal_usb_dma_type_t | dma_type | ||
| ) |
This function sets up the USB DMA channel to transfer data.
| [in] | ep_num | is the endpoint number. |
| [in] | direction | is the USB endpoint direction. |
| [in] | ep_type | is the endpoint type defined in USB 2.0 Specification. Such as CTRL, BULK, INTR, ISO endpoint. |
| [in] | addr | is a pointer to the address to apply the DMA transaction. |
| [in] | length | is the data length in bytes. |
| [in] | callback | is called once the DMA transaction is complete. |
| [in] | callback_upd_run | configures the DMA running state. Set true, if application callback function requests to clear the DMA running by itself. |
| [in] | dma_type | executes a single packet operation or multiple packets operation, hal_usb_dma_type_t. |
| hal_usb_status_t hal_usb_stop_dma_channel | ( | uint32_t | ep_num, |
| hal_usb_endpoint_direction_t | direction | ||
| ) |
This function stops the USB DMA channel and clears pending DMA interrupts.
After that, drop data in FIFO.
| [in] | ep_num | is the endpoint number. |
| [in] | direction | is the USB endpoint direction. |
| hal_usb_status_t hal_usb_update_endpoint_0_state | ( | hal_usb_endpoint_0_driver_state_t | state, |
| bool | stall, | ||
| bool | end | ||
| ) |
This function sets the USB control pipe hardware status.
| [in] | state | is the endpoint0 hardware control state. Please refer to hal_usb_endpoint_0_driver_state_t. |
| [in] | stall | is set to true to execute endpoint stall. |
| [in] | end | is set to true to execute transaction end. |
| hal_usb_status_t hal_usb_write_endpoint_fifo | ( | uint32_t | ep_num, |
| uint16_t | nBytes, | ||
| void * | pSrc | ||
| ) |
This function writes the USB data to FIFO.
Writing to these addresses loads data into the TX FIFO for the corresponding endpoint.
| [in] | ep_num | is the endpoint number. |
| [in] | nBytes | is the number of bytes to write. |
| [in] | pSrc | is a pointer to the source. |