MT7687 API Reference  LinkIt SDK v4
hal_usb.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2016 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __HAL_USB_H__
36 #define __HAL_USB_H__
37 
38 #include "hal_platform.h"
39 
40 #ifdef HAL_USB_MODULE_ENABLED
41 
296 #ifdef __cplusplus
297 extern "C" {
298 #endif
299 
303 #define HAL_USB_MAX_NUMBER_ENDPOINT 4
304 
305 #define HAL_USB_MAX_NUMBER_ENDPOINT_TX 4
306 
307 #define HAL_USB_MAX_NUMBER_ENDPOINT_RX 2
308 
309 #define HAL_USB_MAX_NUMBER_DMA 4
310 
311 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_0 64
312 
313 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_BULK_HIGH_SPEED 512
314 
315 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_BULK_FULL_SPEED 64
316 
317 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_ISOCHRONOUS_HIGH_SPEED 1024
318 
319 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_ISOCHRONOUS_FULL_SPEED 512
320 
321 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_INTERRUPT_HIGH_SPEED 64
322 
323 #define HAL_USB_MAX_PACKET_SIZE_ENDPOINT_INTERRUPT_FULL_SPEED 64
324 
335 typedef void (*hal_usb_driver_interrupt_handler_t)(void);
339 typedef void (*hal_usb_dma_handler_t)(void);
349 typedef enum {
350  HAL_USB_STATUS_INVALID_PARAMETER = -2,
351  HAL_USB_STATUS_ERROR = -1,
352  HAL_USB_STATUS_OK = 0
353 } hal_usb_status_t;
354 
357 typedef enum {
358  HAL_USB_POWER_STATE_NORMAL = 0,
359  HAL_USB_POWER_STATE_SUSPEND
360 } hal_usb_power_state_t;
361 
362 
364 typedef enum {
365  HAL_USB_DMA0_TYPE = 0,
366  HAL_USB_DMA1_TYPE,
367 } hal_usb_dma_type_t;
368 
370 typedef enum {
371  HAL_USB_EP_USE_NO_DMA = 0,
372  HAL_USB_EP_USE_ONLY_DMA,
373 } hal_usb_dma_usage_t;
374 
376 typedef enum {
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;
383 
385 typedef enum {
386  HAL_USB_EP_DIRECTION_TX = 0,
387  HAL_USB_EP_DIRECTION_RX
388 } hal_usb_endpoint_direction_t;
389 
391 typedef enum {
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;
397 
398 
400 typedef enum {
401  HAL_USB_EP_STATE_DISABLE = 0,
402  HAL_USB_EP_STATE_FIFO,
403  HAL_USB_EP_STATE_DMA
404 } hal_usb_endpoint_state_t;
405 
407 typedef enum {
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;
413 
414 
416 typedef enum {
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;
424 
428 typedef enum {
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);
456 
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);
921 
922 
923 #ifdef __cplusplus
924 }
925 #endif
926 
927 
933 #endif /* HAL_USB_MODULE_ENABLED */
934 #endif /* __HAL_USB_H__ */
935