@@ -96,13 +96,14 @@ static int usbd_ctrl_feed_dout(const struct device *dev, const size_t length)
9696static int udc_ambiq_tx (const struct device * dev , uint8_t ep , struct net_buf * buf )
9797{
9898 const struct udc_ambiq_data * priv = udc_get_private (dev );
99+ struct udc_ep_config * cfg = udc_get_ep_cfg (dev , ep );
99100 uint32_t status ;
100101
101- if (udc_ep_is_busy (dev , ep )) {
102+ if (udc_ep_is_busy (cfg )) {
102103 LOG_WRN ("ep 0x%02x is busy!" , ep );
103104 return 0 ;
104105 }
105- udc_ep_set_busy (dev , ep , true);
106+ udc_ep_set_busy (cfg , true);
106107
107108 /* buf equals NULL is used as indication of ZLP request */
108109 if (buf == NULL ) {
@@ -112,7 +113,7 @@ static int udc_ambiq_tx(const struct device *dev, uint8_t ep, struct net_buf *bu
112113 }
113114
114115 if (status != AM_HAL_STATUS_SUCCESS ) {
115- udc_ep_set_busy (dev , ep , false);
116+ udc_ep_set_busy (cfg , false);
116117 LOG_ERR ("am_hal_usb_ep_xfer write failed(0x%02x), %d" , ep , (int )status );
117118 return - EIO ;
118119 }
@@ -123,15 +124,16 @@ static int udc_ambiq_tx(const struct device *dev, uint8_t ep, struct net_buf *bu
123124static int udc_ambiq_rx (const struct device * dev , uint8_t ep , struct net_buf * buf )
124125{
125126 struct udc_ambiq_data * priv = udc_get_private (dev );
127+ struct udc_ep_config * ep_cfg = udc_get_ep_cfg (dev , ep );
126128 struct udc_ep_config * cfg = udc_get_ep_cfg (dev , USB_CONTROL_EP_OUT );
127129 uint32_t status ;
128130 uint16_t rx_size = buf -> size ;
129131
130- if (udc_ep_is_busy (dev , ep )) {
132+ if (udc_ep_is_busy (ep_cfg )) {
131133 LOG_WRN ("ep 0x%02x is busy!" , ep );
132134 return 0 ;
133135 }
134- udc_ep_set_busy (dev , ep , true);
136+ udc_ep_set_busy (ep_cfg , true);
135137
136138 /* Make sure that OUT transaction size triggered doesn't exceed EP's MPS */
137139 if ((ep != USB_CONTROL_EP_OUT ) && (cfg -> mps < rx_size )) {
@@ -140,7 +142,7 @@ static int udc_ambiq_rx(const struct device *dev, uint8_t ep, struct net_buf *bu
140142
141143 status = am_hal_usb_ep_xfer (priv -> usb_handle , ep , buf -> data , rx_size );
142144 if (status != AM_HAL_STATUS_SUCCESS ) {
143- udc_ep_set_busy (dev , ep , false);
145+ udc_ep_set_busy (ep_cfg , false);
144146 LOG_ERR ("am_hal_usb_ep_xfer read(rx) failed(0x%02x), %d" , ep , (int )status );
145147 return - EIO ;
146148 }
@@ -223,7 +225,9 @@ static void udc_ambiq_ep_xfer_complete_callback(const struct device *dev, uint8_
223225 if (USB_EP_DIR_IS_IN (ep_addr )) {
224226 evt .type = UDC_AMBIQ_EVT_HAL_IN_CMP ;
225227 } else {
226- buf = udc_buf_peek (dev , ep_addr );
228+ struct udc_ep_config * ep_cfg = udc_get_ep_cfg (dev , ep_addr );
229+
230+ buf = udc_buf_peek (ep_cfg );
227231 if (buf == NULL ) {
228232 LOG_ERR ("No buffer for ep 0x%02x" , ep_addr );
229233 udc_submit_event (dev , UDC_EVT_ERROR , - ENOBUFS );
@@ -281,12 +285,12 @@ static int udc_ambiq_ep_dequeue(const struct device *dev, struct udc_ep_config *
281285
282286 lock_key = irq_lock ();
283287
284- buf = udc_buf_get_all (dev , ep_cfg -> addr );
288+ buf = udc_buf_get_all (ep_cfg );
285289 if (buf ) {
286290 udc_submit_ep_event (dev , buf , - ECONNABORTED );
287291 }
288292
289- udc_ep_set_busy (dev , ep_cfg -> addr , false);
293+ udc_ep_set_busy (ep_cfg , false);
290294 am_hal_usb_ep_state_reset (priv -> usb_handle , ep_cfg -> addr );
291295 irq_unlock (lock_key );
292296
@@ -320,7 +324,7 @@ static int udc_ambiq_ep_clear_halt(const struct device *dev, struct udc_ep_confi
320324 ep_cfg -> stat .halted = false;
321325
322326 /* Resume queued transfer if any */
323- if (udc_buf_peek (dev , ep_cfg -> addr )) {
327+ if (udc_buf_peek (ep_cfg )) {
324328 struct udc_ambiq_event evt = {
325329 .ep = ep_cfg -> addr ,
326330 .type = UDC_AMBIQ_EVT_XFER ,
@@ -647,14 +651,14 @@ static inline void ambiq_handle_evt_dout(const struct device *dev, struct udc_ep
647651 struct net_buf * buf ;
648652
649653 /* retrieve endpoint buffer */
650- buf = udc_buf_get (dev , cfg -> addr );
654+ buf = udc_buf_get (cfg );
651655 if (buf == NULL ) {
652656 LOG_ERR ("No buffer queued for control ep" );
653657 return ;
654658 }
655659
656660 /* Clear endpoint busy status */
657- udc_ep_set_busy (dev , cfg -> addr , false);
661+ udc_ep_set_busy (cfg , false);
658662
659663 /* Handle transfer complete event */
660664 if (cfg -> addr == USB_CONTROL_EP_OUT ) {
@@ -686,9 +690,9 @@ static void ambiq_handle_evt_din(const struct device *dev, struct udc_ep_config
686690 bool udc_ambiq_rx_status_in_completed = false;
687691
688692 /* Clear endpoint busy status */
689- udc_ep_set_busy (dev , cfg -> addr , false);
693+ udc_ep_set_busy (cfg , false);
690694 /* Check and Handle ZLP flag */
691- buf = udc_buf_peek (dev , cfg -> addr );
695+ buf = udc_buf_peek (cfg );
692696 if (cfg -> addr != USB_CONTROL_EP_IN ) {
693697 if (udc_ep_buf_has_zlp (buf )) {
694698 udc_ep_buf_clear_zlp (buf );
@@ -699,7 +703,7 @@ static void ambiq_handle_evt_din(const struct device *dev, struct udc_ep_config
699703 }
700704
701705 /* retrieve endpoint buffer */
702- buf = udc_buf_get (dev , cfg -> addr );
706+ buf = udc_buf_get (cfg );
703707 if (buf == NULL ) {
704708 LOG_ERR ("No buffer queued for control ep" );
705709 return ;
@@ -754,7 +758,7 @@ static void udc_event_xfer(const struct device *dev, struct udc_ep_config *const
754758{
755759 struct net_buf * buf ;
756760
757- buf = udc_buf_peek (dev , cfg -> addr );
761+ buf = udc_buf_peek (cfg );
758762 if (buf == NULL ) {
759763 LOG_ERR ("No buffer for ep 0x%02x" , cfg -> addr );
760764 return ;
0 commit comments