HPM SDK
HPMicro Software Development Kit
hpm_usb_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2025 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_USB_DRV_H
9 #define HPM_USB_DRV_H
10 /*---------------------------------------------------------------------
11  * Includes
12  *---------------------------------------------------------------------
13  */
14 #include "hpm_common.h"
15 #include "hpm_usb_regs.h"
16 #include "hpm_soc_feature.h"
17 
25 /*---------------------------------------------------------------------
26  * Macro Constant Declarations
27  *---------------------------------------------------------------------
28  */
29 #define USB_PHY_INIT_DELAY_COUNT (25U)
30 #define USB_PHY_DEINIT_DELAY_COUNT (5000U)
31 #define USB_HOST_FRAMELIST_SIZE (8U)
33 /*---------------------------------------------------------------------
34  * Macro Enum Declarations
35  *---------------------------------------------------------------------
36  */
40 typedef enum {
43  usb_dir_in_mask = 0x80
49 typedef enum {
59 typedef enum {
68 typedef enum {
71  usb_line_state2 = 2
77 typedef enum {
79  usb_tran_serial = 1
85 typedef enum {
99 typedef enum {
104 /*---------------------------------------------------------------------
105  * Structure Declarations
106  *---------------------------------------------------------------------
107  */
111 typedef struct __attribute__ ((packed)) {
112  union {
113  struct __attribute__ ((packed)) {
114  uint8_t recipient : 5;
115  uint8_t type : 2;
116  uint8_t direction : 1;
117  } bmRequestType_bit;
118 
119  uint8_t bmRequestType;
120  };
121 
122  uint8_t bRequest;
123  uint16_t wValue;
124  uint16_t wIndex;
125  uint16_t wLength;
127 
131 typedef struct {
132  uint8_t xfer;
133  uint8_t ep_addr;
134  uint16_t max_packet_size;
136 
137 #if defined __cplusplus
138 extern "C" {
139 #endif /* __cplusplus */
140 
141 /*---------------------------------------------------------------------
142  * Common API
143  *---------------------------------------------------------------------
144  */
145 
152 static inline uint32_t usb_get_interrupts(USB_Type *ptr)
153 {
154  return ptr->USBINTR;
155 }
156 
163 static inline void usb_enable_interrupts(USB_Type *ptr, uint32_t mask)
164 {
165  ptr->USBINTR |= mask;
166 }
167 
174 static inline void usb_disable_interrupts(USB_Type *ptr, uint32_t mask)
175 {
176  ptr->USBINTR &= ~mask;
177 }
178 
185 static inline uint32_t usb_get_status_flags(USB_Type *ptr)
186 {
187  return ptr->USBSTS;
188 }
189 
199 static inline void usb_clear_status_flags(USB_Type *ptr, uint32_t mask)
200 {
201  ptr->USBSTS = mask;
202 }
203 
209 static inline void usb_otg_enable_dpdm_wakeup(USB_Type *ptr)
210 {
212 }
213 
219 static inline void usb_otg_disable_dpdm_wakeup(USB_Type *ptr)
220 {
222 }
223 
229 static inline void usb_otg_enable_id_wakeup(USB_Type *ptr)
230 {
232 }
233 
239 static inline void usb_otg_disable_id_wakeup(USB_Type *ptr)
240 {
242 }
243 
249 static inline void usb_otg_enable_vbus_wakeup(USB_Type *ptr)
250 {
252 }
253 
259 static inline void usb_otg_disable_vbus_wakeup(USB_Type *ptr)
260 {
262 }
263 
271 {
273 }
274 
280 static inline void usb_otg_enable_wakeup_int(USB_Type *ptr)
281 {
283 }
284 
290 static inline void usb_otg_disable_wakeup_int(USB_Type *ptr)
291 {
293 }
294 
301 static inline bool usb_get_otg_wakeup_int_flag(USB_Type *ptr)
302 {
303  return (USB_TOP_STATUS_WAKEUP_INT_STATUS_GET(ptr->TOP_STATUS) != 0) ? true : false;
304 }
305 
312 static inline uint8_t usb_get_suspend_status(USB_Type *ptr)
313 {
314  return USB_PORTSC1_SUSP_GET(ptr->PORTSC1);
315 }
316 
323 static inline bool usb_get_port_reset_status(USB_Type *ptr)
324 {
325  return USB_PORTSC1_PR_GET(ptr->PORTSC1);
326 }
327 
334 static inline bool usb_get_port_ccs(USB_Type *ptr)
335 {
336  return USB_PORTSC1_CCS_GET(ptr->PORTSC1);
337 }
338 
345 static inline uint8_t usb_get_port_speed(USB_Type *ptr)
346 {
347  return USB_PORTSC1_PSPD_GET(ptr->PORTSC1);
348 }
349 
356 static inline void usb_set_port_test_mode(USB_Type *ptr, usb_test_mode_t test_mode)
357 {
358  ptr->PORTSC1 = (ptr->PORTSC1 & ~USB_PORTSC1_PTC_MASK) | USB_PORTSC1_PTC_SET(test_mode);
359 }
360 
366 static inline void usb_set_port_suspend(USB_Type *ptr)
367 {
369 }
370 
376 static inline void usb_force_port_resume(USB_Type *ptr)
377 {
379  while ((ptr->PORTSC1 & USB_PORTSC1_FPR_MASK) != 0) {
380  }
381 }
382 
389 {
391 }
392 
398 static inline void usb_phy_exit_low_power_suspend(USB_Type *ptr)
399 {
401  /* otg utmi clock detection */
402  ptr->PHY_STATUS |= USB_PHY_STATUS_UTMI_CLK_VALID_MASK; /* write 1 to clear valid status */
403  while (USB_PHY_STATUS_UTMI_CLK_VALID_GET(ptr->PHY_STATUS) == 0) { /* get utmi clock status */
404  ;
405  }
406 }
407 
414 static inline bool usb_phy_get_session_valid_flag(USB_Type *ptr)
415 {
416  return (USB_PHY_STATUS_UTMI_SESS_VALID_GET(ptr->PHY_STATUS) != 0) ? true : false;
417 }
418 
425 {
426  ptr->OTGSC |= USB_OTGSC_ASVIE_MASK;
427 }
428 
435 {
436  ptr->OTGSC &= ~USB_OTGSC_ASVIE_MASK;
437 }
438 
446 {
447  return ((ptr->OTGSC & USB_OTGSC_ASVIE_MASK) != 0);
448 }
449 
457 {
458  return (USB_OTGSC_ASVIS_SET(ptr->OTGSC) != 0) ? true : false;
459 }
460 
467 {
468  ptr->OTGSC |= USB_OTGSC_ASVIS_MASK;
469 }
470 
478 {
479  return (USB_OTGSC_ASV_GET(ptr->OTGSC) != 0) ? true : false;
480 }
481 
487 static inline void usb_otgsc_enable_id_chg_int(USB_Type *ptr)
488 {
489  ptr->OTGSC |= USB_OTGSC_IDIE_MASK;
490 }
491 
497 static inline void usb_otgsc_disable_id_chg_int(USB_Type *ptr)
498 {
499  ptr->OTGSC &= ~USB_OTGSC_IDIE_MASK;
500 }
501 
507 static inline void usb_otgsc_enable_id_pullup(USB_Type *ptr)
508 {
509  ptr->OTGSC |= USB_OTGSC_IDPU_MASK;
510 }
511 
517 static inline void usb_otgsc_disable_id_pullup(USB_Type *ptr)
518 {
519  ptr->OTGSC &= ~USB_OTGSC_IDPU_MASK;
520 }
521 
528 static inline bool usb_otgsc_get_id_chg_flag(USB_Type *ptr)
529 {
530  return (USB_OTGSC_IDIS_GET(ptr->OTGSC) != 0) ? true : false;
531 }
532 
538 static inline void usb_otgsc_clear_id_chg_flag(USB_Type *ptr)
539 {
540  ptr->OTGSC |= USB_OTGSC_IDIS_MASK;
541 }
542 
549 static inline bool usb_otgsc_get_id_status(USB_Type *ptr)
550 {
551  return (USB_OTGSC_ID_GET(ptr->OTGSC) != 0) ? true : false;
552 }
553 
559 void usb_phy_deinit(USB_Type *ptr);
560 
567 void usb_phy_init(USB_Type *ptr, bool host);
568 
574 static inline uint8_t usb_phy_get_line_state(USB_Type *ptr)
575 {
577 }
578 
584 static inline void usb_phy_using_internal_vbus(USB_Type *ptr)
585 {
588 }
589 
595 static inline void usb_phy_using_external_vbus(USB_Type *ptr)
596 {
599 }
600 
606 static inline void usb_phy_disable_dp_dm_pulldown(USB_Type *ptr)
607 {
608  ptr->PHY_CTRL0 |= 0x001000E0u;
609 }
610 
616 static inline void usb_phy_enable_dp_dm_pulldown(USB_Type *ptr)
617 {
618  ptr->PHY_CTRL0 &= ~0x001000E0u;
619 }
620 
627 {
629 }
630 
631 /*---------------------------------------------------------------------
632  * Device API
633  *---------------------------------------------------------------------
634  */
635 
642 void usb_dcd_bus_reset(USB_Type *ptr, uint16_t ep0_max_packet_size);
643 
649 void usb_dcd_init(USB_Type *ptr);
650 
656 void usb_dcd_deinit(USB_Type *ptr);
657 
664 
672 
679 uint8_t usb_dcd_edpt_get_type(USB_Type *ptr, uint8_t ep_addr);
680 
687 void usb_dcd_edpt_xfer(USB_Type *ptr, uint8_t ep_idx);
688 
695 void usb_dcd_edpt_stall(USB_Type *ptr, uint8_t ep_addr);
696 
703 void usb_dcd_edpt_clear_stall(USB_Type *ptr, uint8_t ep_addr);
704 
712 bool usb_dcd_edpt_check_stall(USB_Type *ptr, uint8_t ep_addr);
713 
720 void usb_dcd_edpt_close(USB_Type *ptr, uint8_t ep_addr);
721 
727 void usb_dcd_connect(USB_Type *ptr);
728 
734 void usb_dcd_disconnect(USB_Type *ptr);
735 
742 static inline uint32_t usb_dcd_get_edpt_setup_status(USB_Type *ptr)
743 {
744  return ptr->ENDPTSETUPSTAT;
745 }
746 
753 static inline void usb_dcd_clear_edpt_setup_status(USB_Type *ptr, uint32_t mask)
754 {
755  ptr->ENDPTSETUPSTAT = mask;
756 }
757 
764 static inline void usb_dcd_set_address(USB_Type *ptr, uint8_t dev_addr)
765 {
767 }
768 
775 static inline void usb_dcd_set_edpt_list_addr(USB_Type *ptr, uint32_t addr)
776 {
778 }
779 
786 static inline uint8_t usb_dcd_get_device_addr(USB_Type *ptr)
787 {
789 }
790 
797 static inline uint32_t usb_dcd_get_edpt_complete_status(USB_Type *ptr)
798 {
799  return ptr->ENDPTCOMPLETE;
800 }
801 
808 static inline void usb_dcd_clear_edpt_complete_status(USB_Type *ptr, uint32_t mask)
809 {
810  ptr->ENDPTCOMPLETE = mask;
811 }
812 
813 /*---------------------------------------------------------------------
814  * Host API
815  *---------------------------------------------------------------------
816  */
824 bool usb_hcd_init(USB_Type *ptr, uint32_t int_mask, uint16_t framelist_size);
825 
831 void usb_hcd_port_reset(USB_Type *ptr);
832 
839 static inline void usb_hcd_set_command(USB_Type *ptr, uint32_t mask)
840 {
841  ptr->USBCMD |= mask;
842 }
843 
850 static inline uint32_t usb_hcd_get_frame_index(USB_Type *ptr)
851 {
852  return ptr->FRINDEX;
853 }
854 
861 static inline bool usb_hcd_get_port_csc(USB_Type *ptr)
862 {
863  return USB_PORTSC1_CSC_GET(ptr->PORTSC1);
864 }
865 
872 static inline void usb_hcd_set_power_ctrl_polarity(USB_Type *ptr, bool high)
873 {
874  if (high) {
876  } else {
878  }
879 }
880 
886 static inline void usb_hcd_enable_port_power(USB_Type *ptr)
887 {
889 }
890 
897 static inline void usb_hcd_set_async_list_addr(USB_Type *ptr, uint32_t addr)
898 {
900 }
901 
908 static inline void usb_hcd_set_periodic_list_addr(USB_Type *ptr, uint32_t addr)
909 {
911 }
912 
918 static inline void usb_hcd_run(USB_Type *ptr)
919 {
920  ptr->USBCMD |= USB_USBCMD_RS_MASK;
921 }
922 
928 static inline void usb_hcd_stop(USB_Type *ptr)
929 {
930  ptr->USBCMD &= ~USB_USBCMD_RS_MASK;
931 }
932 
938 static inline void usb_hcd_disable_ase_pse(USB_Type *ptr)
939 {
941  while (ptr->USBCMD & (USB_USBCMD_PSE_MASK | USB_USBCMD_ASE_MASK)) {
942  ;
943  }
944 }
945 
951 static inline void usb_hcd_enable_ase_pse(USB_Type *ptr)
952 {
954 }
955 
956 #if defined __cplusplus
957 }
958 #endif /* __cplusplus */
959 
961 #endif /* HPM_USB_DRV_H */
#define USB_PORTSC1_CSC_GET(x)
Definition: hpm_usb_regs.h:1475
#define USB_OTGSC_IDPU_MASK
Definition: hpm_usb_regs.h:1613
#define USB_PORTSC1_CCS_GET(x)
Definition: hpm_usb_regs.h:1495
#define USB_ASYNCLISTADDR_ASYBASE_MASK
Definition: hpm_usb_regs.h:967
#define USB_OTG_CTRL0_OTG_WKDPDMCHG_EN_MASK
Definition: hpm_usb_regs.h:1994
#define USB_PHY_STATUS_LINE_STATE_GET(x)
Definition: hpm_usb_regs.h:2224
#define USB_PHY_STATUS_UTMI_CLK_VALID_MASK
Definition: hpm_usb_regs.h:2212
#define USB_PHY_CTRL1_UTMI_OTG_SUSPENDM_MASK
Definition: hpm_usb_regs.h:2192
#define USB_OTG_CTRL0_OTG_WAKEUP_INT_ENABLE_MASK
Definition: hpm_usb_regs.h:2059
#define USB_PHY_CTRL0_VBUS_VALID_OVERRIDE_MASK
Definition: hpm_usb_regs.h:2133
#define USB_OTG_CTRL0_OTG_VBUS_SOURCE_SEL_SET(x)
Definition: hpm_usb_regs.h:2032
#define USB_DEVICEADDR_USBADR_SET(x)
Definition: hpm_usb_regs.h:918
#define USB_OTG_CTRL0_OTG_VBUS_SOURCE_SEL_MASK
Definition: hpm_usb_regs.h:2030
#define USB_PHY_CTRL0_VBUS_VALID_OVERRIDE_EN_MASK
Definition: hpm_usb_regs.h:2170
#define USB_OTGSC_ASVIS_MASK
Definition: hpm_usb_regs.h:1541
#define USB_OTGSC_ID_GET(x)
Definition: hpm_usb_regs.h:1603
#define USB_OTGSC_ASVIE_MASK
Definition: hpm_usb_regs.h:1504
#define USB_USBCMD_RS_MASK
Definition: hpm_usb_regs.h:442
#define USB_PHY_STATUS_UTMI_SESS_VALID_GET(x)
Definition: hpm_usb_regs.h:2251
#define USB_PHY_CTRL0_SESS_VALID_OVERRIDE_MASK
Definition: hpm_usb_regs.h:2124
#define USB_OTG_CTRL0_OTG_POWER_MASK_MASK
Definition: hpm_usb_regs.h:2068
#define USB_PERIODICLISTBASE_BASEADR_MASK
Definition: hpm_usb_regs.h:952
#define USB_OTGSC_ASVIS_SET(x)
Definition: hpm_usb_regs.h:1543
#define USB_OTGSC_IDIS_GET(x)
Definition: hpm_usb_regs.h:1570
#define USB_OTGSC_IDIS_MASK
Definition: hpm_usb_regs.h:1567
#define USB_PORTSC1_PP_MASK
Definition: hpm_usb_regs.h:1289
#define USB_DEVICEADDR_USBADR_GET(x)
Definition: hpm_usb_regs.h:919
#define USB_PORTSC1_PTC_SET(x)
Definition: hpm_usb_regs.h:1269
#define USB_OTGSC_ASV_GET(x)
Definition: hpm_usb_regs.h:1581
#define USB_USBCMD_PSE_MASK
Definition: hpm_usb_regs.h:390
#define USB_PORTSC1_PTC_MASK
Definition: hpm_usb_regs.h:1267
#define USB_PORTSC1_PHCD_MASK
Definition: hpm_usb_regs.h:1201
#define USB_PORTSC1_FPR_MASK
Definition: hpm_usb_regs.h:1391
#define USB_PORTSC1_PSPD_GET(x)
Definition: hpm_usb_regs.h:1166
#define USB_OTG_CTRL0_OTG_ID_WAKEUP_EN_MASK
Definition: hpm_usb_regs.h:2021
#define USB_PHY_STATUS_UTMI_CLK_VALID_GET(x)
Definition: hpm_usb_regs.h:2215
#define USB_USBCMD_ASE_MASK
Definition: hpm_usb_regs.h:374
#define USB_PORTSC1_SUSP_MASK
Definition: hpm_usb_regs.h:1365
#define USB_DEVICEADDR_USBADRA_MASK
Definition: hpm_usb_regs.h:938
#define USB_PORTSC1_PR_GET(x)
Definition: hpm_usb_regs.h:1341
#define USB_OTG_CTRL0_OTG_VBUS_WAKEUP_EN_MASK
Definition: hpm_usb_regs.h:2012
#define USB_ENDPTLISTADDR_EPBASE_MASK
Definition: hpm_usb_regs.h:980
#define USB_PHY_CTRL0_SESS_VALID_OVERRIDE_EN_MASK
Definition: hpm_usb_regs.h:2161
#define USB_PORTSC1_SUSP_GET(x)
Definition: hpm_usb_regs.h:1368
#define USB_TOP_STATUS_WAKEUP_INT_STATUS_GET(x)
Definition: hpm_usb_regs.h:2205
#define USB_OTGSC_IDIE_MASK
Definition: hpm_usb_regs.h:1528
static void usb_otg_enable_wakeup_int(USB_Type *ptr)
Enable otg wakeup interrupt.
Definition: hpm_usb_drv.h:280
bool usb_hcd_init(USB_Type *ptr, uint32_t int_mask, uint16_t framelist_size)
Initialize controller to host mode.
Definition: hpm_usb_drv.c:306
static bool usb_get_port_reset_status(USB_Type *ptr)
Get USB reset status.
Definition: hpm_usb_drv.h:323
static void usb_otg_set_vbus_wakeup_source(USB_Type *ptr, usb_vbus_wakeup_source_t src)
Set otg vbus wakeup source.
Definition: hpm_usb_drv.h:270
static void usb_otg_enable_vbus_wakeup(USB_Type *ptr)
Enable otg vbus change wakeup.
Definition: hpm_usb_drv.h:249
static bool usb_otgsc_session_valid_chg_int_is_enable(USB_Type *ptr)
check otgsc session valid change interrupt is enable
Definition: hpm_usb_drv.h:445
static uint8_t usb_get_port_speed(USB_Type *ptr)
Get USB port speed status.
Definition: hpm_usb_drv.h:345
static void usb_otgsc_enable_id_chg_int(USB_Type *ptr)
enable otgsc id change interrupt
Definition: hpm_usb_drv.h:487
static bool usb_get_otg_wakeup_int_flag(USB_Type *ptr)
Get otg wakeup status flags.
Definition: hpm_usb_drv.h:301
void usb_dcd_edpt_close(USB_Type *ptr, uint8_t ep_addr)
Close a specified endpoint.
Definition: hpm_usb_drv.c:274
static uint8_t usb_get_suspend_status(USB_Type *ptr)
Get USB suspend status.
Definition: hpm_usb_drv.h:312
static void usb_otg_disable_dpdm_wakeup(USB_Type *ptr)
Disbable otg dp/dm change wakeup.
Definition: hpm_usb_drv.h:219
static void usb_otg_disable_wakeup_int(USB_Type *ptr)
Disable otg wakeup interrupt.
Definition: hpm_usb_drv.h:290
static bool usb_hcd_get_port_csc(USB_Type *ptr)
Get port connect status change.
Definition: hpm_usb_drv.h:861
void usb_dcd_connect(USB_Type *ptr)
Connect by enabling internal pull-up resistor on D+/D-.
Definition: hpm_usb_drv.c:190
void usb_dcd_edpt_stall(USB_Type *ptr, uint8_t ep_addr)
Stall endpoint.
Definition: hpm_usb_drv.c:248
static uint32_t usb_hcd_get_frame_index(USB_Type *ptr)
Get frame index.
Definition: hpm_usb_drv.h:850
static bool usb_phy_get_session_valid_flag(USB_Type *ptr)
Get phy session valid flag.
Definition: hpm_usb_drv.h:414
static void usb_hcd_set_power_ctrl_polarity(USB_Type *ptr, bool high)
Set power ctrl polarity.
Definition: hpm_usb_drv.h:872
static void usb_otgsc_enable_session_valid_chg_int(USB_Type *ptr)
enable otgsc session valid change interrupt
Definition: hpm_usb_drv.h:424
static uint32_t usb_dcd_get_edpt_setup_status(USB_Type *ptr)
Get setup status of endpoint.
Definition: hpm_usb_drv.h:742
void usb_dcd_deinit(USB_Type *ptr)
Deinitialize controller to device.
Definition: hpm_usb_drv.c:166
static void usb_phy_exit_low_power_suspend(USB_Type *ptr)
USB phy exit low power suspend.
Definition: hpm_usb_drv.h:398
static void usb_otgsc_disable_session_valid_chg_int(USB_Type *ptr)
disable otgsc session valid change interrupt
Definition: hpm_usb_drv.h:434
static void usb_hcd_set_command(USB_Type *ptr, uint32_t mask)
Initialize controller to host modeHost set command register.
Definition: hpm_usb_drv.h:839
static void usb_dcd_set_edpt_list_addr(USB_Type *ptr, uint32_t addr)
Set endpoint list address.
Definition: hpm_usb_drv.h:775
static uint32_t usb_get_status_flags(USB_Type *ptr)
Get all USB status flags.
Definition: hpm_usb_drv.h:185
void usb_dcd_bus_reset(USB_Type *ptr, uint16_t ep0_max_packet_size)
USB device bus reset.
Definition: hpm_usb_drv.c:94
static void usb_dcd_set_address(USB_Type *ptr, uint8_t dev_addr)
Set address.
Definition: hpm_usb_drv.h:764
static void usb_phy_enter_low_power_suspend(USB_Type *ptr)
USB phy enter low power suspend.
Definition: hpm_usb_drv.h:388
static void usb_phy_using_external_vbus(USB_Type *ptr)
USB phy using external vbus.
Definition: hpm_usb_drv.h:595
static void usb_hcd_stop(USB_Type *ptr)
Stop hcd controller.
Definition: hpm_usb_drv.h:928
uint8_t usb_dcd_edpt_get_type(USB_Type *ptr, uint8_t ep_addr)
get a specified endpoint type
Definition: hpm_usb_drv.c:231
static void usb_otg_enable_dpdm_wakeup(USB_Type *ptr)
Enable otg dp/dm change wakeup.
Definition: hpm_usb_drv.h:209
static void usb_set_port_test_mode(USB_Type *ptr, usb_test_mode_t test_mode)
Set port test control mode.
Definition: hpm_usb_drv.h:356
usb_line_state_t
USB line state.
Definition: hpm_usb_drv.h:68
usb_test_mode_t
USB test modes.
Definition: hpm_usb_drv.h:85
static void usb_otg_enable_id_wakeup(USB_Type *ptr)
Enable otg id change wakeup.
Definition: hpm_usb_drv.h:229
static void usb_hcd_run(USB_Type *ptr)
Start hcd controller.
Definition: hpm_usb_drv.h:918
usb_vbus_wakeup_source_t
USB vbus wakeup source.
Definition: hpm_usb_drv.h:99
void usb_phy_init(USB_Type *ptr, bool host)
Initialize USB phy.
Definition: hpm_usb_drv.c:62
static void usb_hcd_set_periodic_list_addr(USB_Type *ptr, uint32_t addr)
Set periodic list address.
Definition: hpm_usb_drv.h:908
static void usb_phy_using_internal_vbus(USB_Type *ptr)
USB phy using internal vbus.
Definition: hpm_usb_drv.h:584
static uint32_t usb_dcd_get_edpt_complete_status(USB_Type *ptr)
Get complete status of endpoint.
Definition: hpm_usb_drv.h:797
static void usb_dcd_clear_edpt_complete_status(USB_Type *ptr, uint32_t mask)
Clear complete status of endpoint.
Definition: hpm_usb_drv.h:808
bool usb_dcd_edpt_check_stall(USB_Type *ptr, uint8_t ep_addr)
Clear stall.
Definition: hpm_usb_drv.c:266
static void usb_otgsc_disable_id_chg_int(USB_Type *ptr)
disable otgsc id change interrupt
Definition: hpm_usb_drv.h:497
void usb_phy_deinit(USB_Type *ptr)
De-Initialize USB phy.
Definition: hpm_usb_drv.c:36
static void usb_enable_interrupts(USB_Type *ptr, uint32_t mask)
Enable interrupts.
Definition: hpm_usb_drv.h:163
static void usb_hcd_enable_ase_pse(USB_Type *ptr)
Enable hcd controller Asynchronous Schedule and Periodic Schedule.
Definition: hpm_usb_drv.h:951
void usb_hcd_port_reset(USB_Type *ptr)
Initialize controller to host modeHost Reset port.
Definition: hpm_usb_drv.c:358
static void usb_otgsc_enable_id_pullup(USB_Type *ptr)
enable otgsc id pull up
Definition: hpm_usb_drv.h:507
static bool usb_otgsc_get_id_chg_flag(USB_Type *ptr)
Get otgsc id change flag.
Definition: hpm_usb_drv.h:528
static void usb_force_port_resume(USB_Type *ptr)
USB force port resume.
Definition: hpm_usb_drv.h:376
static uint32_t usb_get_interrupts(USB_Type *ptr)
Get the mask of all enabled interrupts.
Definition: hpm_usb_drv.h:152
static void usb_otg_disable_id_wakeup(USB_Type *ptr)
Disbable otg id change wakeup.
Definition: hpm_usb_drv.h:239
void usb_dcd_edpt_xfer(USB_Type *ptr, uint8_t ep_idx)
Submit a transfer.
Definition: hpm_usb_drv.c:240
static bool usb_get_port_ccs(USB_Type *ptr)
Get USB current connect status.
Definition: hpm_usb_drv.h:334
void usb_dcd_edpt_open(USB_Type *ptr, usb_endpoint_config_t *config)
Open an endpoint.
Definition: hpm_usb_drv.c:219
static bool usb_otgsc_get_session_valid_chg_flag(USB_Type *ptr)
get otgsc session valid change flag
Definition: hpm_usb_drv.h:456
static void usb_clear_status_flags(USB_Type *ptr, uint32_t mask)
Clear status flags.
Definition: hpm_usb_drv.h:199
void usb_dcd_disconnect(USB_Type *ptr)
Disconnect by disabling internal pull-up resistor on D+/D-.
Definition: hpm_usb_drv.c:196
static uint8_t usb_dcd_get_device_addr(USB_Type *ptr)
Get device address.
Definition: hpm_usb_drv.h:786
void usb_dcd_remote_wakeup(USB_Type *ptr)
Wakeup from host.
Definition: hpm_usb_drv.c:301
usb_transceiver_t
USB transceiver.
Definition: hpm_usb_drv.h:77
static void usb_hcd_set_async_list_addr(USB_Type *ptr, uint32_t addr)
Get port connect status changeSet async list address.
Definition: hpm_usb_drv.h:897
static void usb_otgsc_clear_id_chg_flag(USB_Type *ptr)
clear otgsc id change flag
Definition: hpm_usb_drv.h:538
static void usb_phy_disable_dp_dm_pulldown(USB_Type *ptr)
USB phy disconnect dp/dm pins pulldown resistance.
Definition: hpm_usb_drv.h:606
static void usb_otg_disable_vbus_wakeup(USB_Type *ptr)
Disbable otg vbus change wakeup.
Definition: hpm_usb_drv.h:259
usb_dir_t
USB transfer direction types.
Definition: hpm_usb_drv.h:40
usb_controller_mode_t
USB controller work modes.
Definition: hpm_usb_drv.h:59
static void usb_disable_interrupts(USB_Type *ptr, uint32_t mask)
Disable interrupts.
Definition: hpm_usb_drv.h:174
usb_xfer_type_t
USB transfer types.
Definition: hpm_usb_drv.h:49
static void usb_otgsc_clear_session_valid_chg_flag(USB_Type *ptr)
clear otgsc session valid change flag
Definition: hpm_usb_drv.h:466
static bool usb_otgsc_get_session_valid_flag(USB_Type *ptr)
Get otgsc session valid flag.
Definition: hpm_usb_drv.h:477
usb_control_request_t
Definition: hpm_usb_drv.h:126
static void usb_dcd_clear_edpt_setup_status(USB_Type *ptr, uint32_t mask)
Clear the setup status of all specified endpoints.
Definition: hpm_usb_drv.h:753
void usb_dcd_edpt_clear_stall(USB_Type *ptr, uint8_t ep_addr)
Clear stall.
Definition: hpm_usb_drv.c:256
static void usb_phy_enable_dp_dm_pulldown(USB_Type *ptr)
USB phy connect dp/dm pins pulldown resistance.
Definition: hpm_usb_drv.h:616
static void usb_set_port_suspend(USB_Type *ptr)
USB set port suspend.
Definition: hpm_usb_drv.h:366
static void usb_phyctrl1_set_not_utmi_suspend(USB_Type *ptr)
Set phyctrl1 not utmi suspend.
Definition: hpm_usb_drv.h:626
static void usb_hcd_enable_port_power(USB_Type *ptr)
Enable port power.
Definition: hpm_usb_drv.h:886
static uint8_t usb_phy_get_line_state(USB_Type *ptr)
USB phy get line status.
Definition: hpm_usb_drv.h:574
static void usb_hcd_disable_ase_pse(USB_Type *ptr)
Disable hcd controller Asynchronous Schedule and Periodic Schedule.
Definition: hpm_usb_drv.h:938
static void usb_otgsc_disable_id_pullup(USB_Type *ptr)
disable otgsc id pull up
Definition: hpm_usb_drv.h:517
static bool usb_otgsc_get_id_status(USB_Type *ptr)
Get otgsc id status.
Definition: hpm_usb_drv.h:549
void usb_dcd_init(USB_Type *ptr)
Initialize controller to device mode.
Definition: hpm_usb_drv.c:122
@ usb_line_state1
Definition: hpm_usb_drv.h:70
@ usb_line_state2
Definition: hpm_usb_drv.h:71
@ usb_line_state0
Definition: hpm_usb_drv.h:69
@ usb_test_k_state
Definition: hpm_usb_drv.h:88
@ usb_test_se0_nak
Definition: hpm_usb_drv.h:89
@ usb_test_mode_disable
Definition: hpm_usb_drv.h:86
@ usb_test_j_state
Definition: hpm_usb_drv.h:87
@ usb_test_force_ls
Definition: hpm_usb_drv.h:93
@ usb_test_force_fs
Definition: hpm_usb_drv.h:92
@ usb_test_force_hs
Definition: hpm_usb_drv.h:91
@ usb_test_packet
Definition: hpm_usb_drv.h:90
@ usb_vbus_wakeup_session_valid
Definition: hpm_usb_drv.h:101
@ usb_vbus_wakeup_vbus_valid
Definition: hpm_usb_drv.h:100
@ usb_tran_serial
Definition: hpm_usb_drv.h:79
@ usb_tran_parallel
Definition: hpm_usb_drv.h:78
@ usb_dir_in_mask
Definition: hpm_usb_drv.h:43
@ usb_dir_in
Definition: hpm_usb_drv.h:42
@ usb_dir_out
Definition: hpm_usb_drv.h:41
@ usb_ctrl_mode_device
Definition: hpm_usb_drv.h:61
@ usb_ctrl_mode_host
Definition: hpm_usb_drv.h:62
@ usb_ctrl_mode_otg
Definition: hpm_usb_drv.h:60
@ usb_xfer_bulk
Definition: hpm_usb_drv.h:52
@ usb_xfer_interrupt
Definition: hpm_usb_drv.h:53
@ usb_xfer_isochronous
Definition: hpm_usb_drv.h:51
@ usb_xfer_control
Definition: hpm_usb_drv.h:50
Definition: hpm_usb_regs.h:12
__RW uint32_t OTG_CTRL0
Definition: hpm_usb_regs.h:50
__RW uint32_t PHY_CTRL1
Definition: hpm_usb_regs.h:53
__RW uint32_t PHY_STATUS
Definition: hpm_usb_regs.h:56
__RW uint32_t FRINDEX
Definition: hpm_usb_regs.h:23
__RW uint32_t USBCMD
Definition: hpm_usb_regs.h:20
__RW uint32_t DEVICEADDR
Definition: hpm_usb_regs.h:26
__RW uint32_t ENDPTLISTADDR
Definition: hpm_usb_regs.h:31
__RW uint32_t PERIODICLISTBASE
Definition: hpm_usb_regs.h:27
__RW uint32_t USBINTR
Definition: hpm_usb_regs.h:22
__RW uint32_t ENDPTCOMPLETE
Definition: hpm_usb_regs.h:48
__RW uint32_t PORTSC1
Definition: hpm_usb_regs.h:40
__RW uint32_t PHY_CTRL0
Definition: hpm_usb_regs.h:52
__RW uint32_t ENDPTSETUPSTAT
Definition: hpm_usb_regs.h:44
__RW uint32_t USBSTS
Definition: hpm_usb_regs.h:21
__RW uint32_t OTGSC
Definition: hpm_usb_regs.h:42
__RW uint32_t TOP_STATUS
Definition: hpm_usb_regs.h:55
__RW uint32_t ASYNCLISTADDR
Definition: hpm_usb_regs.h:30
Endpoint config structure.
Definition: hpm_usb_drv.h:131
uint8_t ep_addr
Definition: hpm_usb_drv.h:133
uint8_t xfer
Definition: hpm_usb_drv.h:132
uint16_t max_packet_size
Definition: hpm_usb_drv.h:134