38 #include "hal_platform.h" 40 #ifdef HAL_USB_MODULE_ENABLED 303 #define HAL_USB_MAX_NUMBER_ENDPOINT 4 305 #define HAL_USB_MAX_NUMBER_ENDPOINT_TX 4 307 #define HAL_USB_MAX_NUMBER_ENDPOINT_RX 2 309 #define HAL_USB_MAX_NUMBER_DMA 4 311 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_0 64 313 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_BULK_HIGH_SPEED 512 315 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_BULK_FULL_SPEED 64 317 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_ISOCHRONOUS_HIGH_SPEED 1024 319 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_ISOCHRONOUS_FULL_SPEED 512 321 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_INTERRUPT_HIGH_SPEED 64 323 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_INTERRUPT_FULL_SPEED 64 335 typedef void (*hal_usb_driver_interrupt_handler_t)(void);
339 typedef void (*hal_usb_dma_handler_t)(void);
350 HAL_USB_STATUS_INVALID_PARAMETER = -2,
351 HAL_USB_STATUS_ERROR = -1,
352 HAL_USB_STATUS_OK = 0
358 HAL_USB_POWER_STATE_NORMAL = 0,
359 HAL_USB_POWER_STATE_SUSPEND
360 } hal_usb_power_state_t;
365 HAL_USB_DMA0_TYPE = 0,
367 } hal_usb_dma_type_t;
371 HAL_USB_EP_USE_NO_DMA = 0,
372 HAL_USB_EP_USE_ONLY_DMA,
373 } hal_usb_dma_usage_t;
377 HAL_USB_TEST_MODE_TYPE_NONE = 0,
378 HAL_USB_TEST_MODE_TYPE_J,
379 HAL_USB_TEST_MODE_TYPE_K,
380 HAL_USB_TEST_MODE_TYPE_SE0_NAK,
381 HAL_USB_TEST_MODE_TYPE_PACKET
382 } hal_usb_test_mode_type_t;
386 HAL_USB_EP_DIRECTION_TX = 0,
387 HAL_USB_EP_DIRECTION_RX
388 } hal_usb_endpoint_direction_t;
392 HAL_USB_EP_TRANSFER_CTRL = 0,
393 HAL_USB_EP_TRANSFER_BULK,
394 HAL_USB_EP_TRANSFER_INTR,
395 HAL_USB_EP_TRANSFER_ISO
396 } hal_usb_endpoint_transfer_type_t;
401 HAL_USB_EP_STATE_DISABLE = 0,
402 HAL_USB_EP_STATE_FIFO,
404 } hal_usb_endpoint_state_t;
408 HAL_USB_EP0_DRV_STATE_READ_END = 0,
409 HAL_USB_EP0_DRV_STATE_WRITE_RDY,
410 HAL_USB_EP0_DRV_STATE_TRANSACTION_END,
411 HAL_USB_EP0_DRV_STATE_CLEAR_SENT_STALL
412 } hal_usb_endpoint_0_driver_state_t;
417 HAL_USB_DRV_HDLR_RESET = 0,
418 HAL_USB_DRV_HDLR_SUSPEND,
419 HAL_USB_DRV_HDLR_RESUME,
420 HAL_USB_DRV_HDLR_EP0,
421 HAL_USB_DRV_HDLR_EP_TX,
422 HAL_USB_DRV_HDLR_EP_RX
423 } hal_usb_driver_handler_type_t;
429 HAL_USB_SET_ADDR_DATA = 0,
430 HAL_USB_SET_ADDR_STATUS
431 } hal_usb_set_address_state_t;
447 extern hal_usb_status_t hal_usb_init(
void);
455 extern hal_usb_status_t hal_usb_configure_driver(
void);
466 extern 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);
474 extern hal_usb_status_t hal_usb_pull_up_dp_line(
void);
481 extern hal_usb_status_t hal_usb_reset_hardware(
void);
488 extern hal_usb_status_t hal_usb_reset_fifo(
void);
496 extern hal_usb_status_t hal_usb_deinit(
void);
509 extern hal_usb_status_t hal_usb_set_address(uint8_t addr, hal_usb_set_address_state_t state);
521 extern 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);
532 extern 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);
543 extern 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);
554 extern 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);
569 extern hal_usb_status_t hal_usb_disable_tx_endpoint(uint32_t ep_num);
584 extern hal_usb_status_t hal_usb_disable_rx_endpoint(uint32_t ep_num);
600 extern hal_usb_status_t hal_usb_clear_tx_endpoint_data_toggle(uint32_t ep_num);
616 extern hal_usb_status_t hal_usb_clear_rx_endpoint_data_toggle(uint32_t ep_num);
627 extern hal_usb_status_t hal_usb_read_endpoint_fifo(uint32_t ep_num, uint16_t nBytes,
void *pDst);
638 extern hal_usb_status_t hal_usb_write_endpoint_fifo(uint32_t ep_num, uint16_t nBytes,
void *pSrc);
649 extern hal_usb_status_t hal_usb_set_endpoint_stall(uint32_t ep_num, hal_usb_endpoint_direction_t direction,
bool stall_enable);
668 extern bool hal_usb_get_endpoint_stall_status(uint32_t ep_num, hal_usb_endpoint_direction_t direction);
689 extern hal_usb_status_t hal_usb_get_endpoint_0_status(
bool *p_transaction_end,
bool *p_sent_stall);
722 extern hal_usb_status_t hal_usb_update_endpoint_0_state(hal_usb_endpoint_0_driver_state_t state,
bool stall,
bool end);
730 extern uint32_t hal_usb_get_rx_packet_length(uint32_t ep_num);
740 extern hal_usb_status_t hal_usb_set_endpoint_tx_ready(uint32_t ep_num);
750 extern hal_usb_status_t hal_usb_set_endpoint_rx_ready(uint32_t ep_num);
769 extern 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);
788 extern 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);
800 extern 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);
812 extern 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);
827 extern 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);
837 extern hal_usb_status_t hal_usb_stop_dma_channel(uint32_t ep_num, hal_usb_endpoint_direction_t direction);
846 extern bool hal_usb_is_dma_running(uint32_t ep_num, hal_usb_endpoint_direction_t direction);
862 extern bool hal_usb_is_high_speed(
void);
881 extern bool hal_usb_is_endpoint_tx_empty(uint32_t ep_num);
900 extern bool hal_usb_is_endpoint_rx_empty(uint32_t ep_num);
920 extern hal_usb_status_t hal_usb_enter_test_mode(hal_usb_test_mode_type_t test_selector);