@@ -176,6 +176,8 @@ enum {
176176//--------------------------------------------------------------------+
177177
178178typedef struct {
179+ uint8_t daddr ;
180+
179181 struct TU_ATTR_PACKED {
180182 uint8_t ep_dir : 1 ;
181183 uint8_t is_iso : 1 ;
@@ -184,17 +186,19 @@ typedef struct {
184186 uint8_t xfer_pending : 1 ;
185187 uint8_t xfer_complete : 1 ;
186188 };
189+
187190 struct TU_ATTR_PACKED {
188- uint8_t daddr : 4 ;
189191 uint8_t ep_num : 4 ;
192+ uint16_t packet_size : 12 ;
190193 };
191194
192- uint16_t packet_size ;
193195 uint16_t total_len ;
194196 uint16_t xferred_len ;
195197 uint8_t * buf ;
196198} max3421_ep_t ;
197199
200+ TU_VERIFY_STATIC (sizeof (max3421_ep_t ) == 12 , "size is not correct" );
201+
198202typedef struct {
199203 // cached register
200204 uint8_t sndbc ;
@@ -325,7 +329,7 @@ static void fifo_read(uint8_t rhport, uint8_t * buffer, uint16_t len, bool in_is
325329static inline void hirq_write (uint8_t rhport , uint8_t data , bool in_isr ) {
326330 reg_write (rhport , HIRQ_ADDR , data , in_isr );
327331 // HIRQ write 1 is clear
328- _hcd_data .hirq &= ~data ;
332+ _hcd_data .hirq &= ( uint8_t ) ~data ;
329333}
330334
331335static inline void hien_write (uint8_t rhport , uint8_t data , bool in_isr ) {
@@ -395,13 +399,13 @@ static void free_ep(uint8_t daddr) {
395399}
396400
397401static max3421_ep_t * find_next_pending_ep (max3421_ep_t * cur_ep ) {
398- size_t const idx = cur_ep - _hcd_data .ep ;
402+ size_t const idx = ( size_t ) ( cur_ep - _hcd_data .ep ) ;
399403
400404 // starting from next endpoint
401405 for (size_t i = idx + 1 ; i < CFG_TUH_MAX3421_ENDPOINT_TOTAL ; i ++ ) {
402406 max3421_ep_t * ep = & _hcd_data .ep [i ];
403407 if (ep -> xfer_pending && ep -> packet_size ) {
404- // TU_LOG3("next pending i = %u\n", i);
408+ // TU_LOG3("next pending i = %u\r\ n", i);
405409 return ep ;
406410 }
407411 }
@@ -410,7 +414,7 @@ static max3421_ep_t * find_next_pending_ep(max3421_ep_t * cur_ep) {
410414 for (size_t i = 0 ; i <= idx ; i ++ ) {
411415 max3421_ep_t * ep = & _hcd_data .ep [i ];
412416 if (ep -> xfer_pending && ep -> packet_size ) {
413- // TU_LOG3("next pending i = %u\n", i);
417+ // TU_LOG3("next pending i = %u\r\ n", i);
414418 return ep ;
415419 }
416420 }
@@ -542,8 +546,8 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const * e
542546 (void ) rhport ;
543547 (void ) daddr ;
544548
545- uint8_t ep_num = tu_edpt_number (ep_desc -> bEndpointAddress );
546- uint8_t ep_dir = tu_edpt_dir (ep_desc -> bEndpointAddress );
549+ uint8_t const ep_num = tu_edpt_number (ep_desc -> bEndpointAddress );
550+ tusb_dir_t const ep_dir = tu_edpt_dir (ep_desc -> bEndpointAddress );
547551
548552 max3421_ep_t * ep ;
549553 if (daddr == 0 && ep_num == 0 ) {
@@ -552,15 +556,15 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const * e
552556 ep = allocate_ep ();
553557 TU_ASSERT (ep );
554558 ep -> daddr = daddr ;
555- ep -> ep_num = ep_num ;
556- ep -> ep_dir = ep_dir ;
559+ ep -> ep_num = ( uint8_t ) ( ep_num & 0x0f ) ;
560+ ep -> ep_dir = ( ep_dir == TUSB_DIR_IN ) ? 1 : 0 ;
557561 }
558562
559563 if ( TUSB_XFER_ISOCHRONOUS == ep_desc -> bmAttributes .xfer ) {
560564 ep -> is_iso = 1 ;
561565 }
562566
563- ep -> packet_size = tu_edpt_packet_size (ep_desc );
567+ ep -> packet_size = ( uint16_t ) ( tu_edpt_packet_size (ep_desc ) & 0x7ff );
564568
565569 return true;
566570}
@@ -582,7 +586,7 @@ void xact_out(uint8_t rhport, max3421_ep_t *ep, bool switch_ep, bool in_isr) {
582586 }
583587 sndbc_write (rhport , xact_len , in_isr );
584588
585- uint8_t hxfr = ep -> ep_num | HXFR_OUT_NIN | (ep -> is_iso ? HXFR_ISO : 0 );
589+ uint8_t const hxfr = ( uint8_t ) ( ep -> ep_num | HXFR_OUT_NIN | (ep -> is_iso ? HXFR_ISO : 0 ) );
586590 hxfr_write (rhport , hxfr , in_isr );
587591}
588592
@@ -595,7 +599,7 @@ void xact_in(uint8_t rhport, max3421_ep_t *ep, bool switch_ep, bool in_isr) {
595599 reg_write (rhport , HCTL_ADDR , hctl , in_isr );
596600 }
597601
598- uint8_t hxfr = ep -> ep_num | (ep -> is_iso ? HXFR_ISO : 0 );
602+ uint8_t const hxfr = ( uint8_t ) ( ep -> ep_num | (ep -> is_iso ? HXFR_ISO : 0 ) );
599603 hxfr_write (rhport , hxfr , in_isr );
600604}
601605
@@ -628,13 +632,13 @@ TU_ATTR_ALWAYS_INLINE static inline void xact_inout(uint8_t rhport, max3421_ep_t
628632// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
629633bool hcd_edpt_xfer (uint8_t rhport , uint8_t daddr , uint8_t ep_addr , uint8_t * buffer , uint16_t buflen ) {
630634 uint8_t const ep_num = tu_edpt_number (ep_addr );
631- uint8_t const ep_dir = tu_edpt_dir (ep_addr );
635+ uint8_t const ep_dir = ( uint8_t ) tu_edpt_dir (ep_addr );
632636
633637 max3421_ep_t * ep = find_opened_ep (daddr , ep_num , ep_dir );
634638 TU_VERIFY (ep );
635639
636640 // control transfer can switch direction
637- ep -> ep_dir = ep_dir ;
641+ ep -> ep_dir = ep_dir ? 1u : 0u ;
638642
639643 ep -> buf = buffer ;
640644 ep -> total_len = buflen ;
@@ -736,9 +740,9 @@ static void handle_connect_irq(uint8_t rhport, bool in_isr) {
736740 // However, since we are always in full speed mode, we can just check J-state
737741 if (jk == HRSL_KSTATUS ) {
738742 new_mode |= MODE_LOWSPEED ;
739- TU_LOG3 ("Low speed\n" );
743+ TU_LOG3 ("Low speed\r\ n" );
740744 }else {
741- TU_LOG3 ("Full speed\n" );
745+ TU_LOG3 ("Full speed\r\ n" );
742746 }
743747 new_mode |= MODE_SOFKAENAB ;
744748 mode_write (rhport , new_mode , in_isr );
@@ -758,9 +762,9 @@ static void xfer_complete_isr(uint8_t rhport, max3421_ep_t *ep, xfer_result_t re
758762
759763 // save data toggle
760764 if (ep -> ep_dir ) {
761- ep -> data_toggle = (hrsl & HRSL_RCVTOGRD ) ? 1 : 0 ;
765+ ep -> data_toggle = (hrsl & HRSL_RCVTOGRD ) ? 1u : 0u ;
762766 }else {
763- ep -> data_toggle = (hrsl & HRSL_SNDTOGRD ) ? 1 : 0 ;
767+ ep -> data_toggle = (hrsl & HRSL_SNDTOGRD ) ? 1u : 0u ;
764768 }
765769
766770 ep -> xfer_pending = 0 ;
@@ -944,7 +948,7 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
944948 }
945949
946950 // clear all interrupt except SNDBAV_IRQ (never clear by us). Note RCVDAV_IRQ, HXFRDN_IRQ already clear while processing
947- hirq &= ~HIRQ_SNDBAV_IRQ ;
951+ hirq &= ( uint8_t ) ~HIRQ_SNDBAV_IRQ ;
948952 if ( hirq ) {
949953 hirq_write (rhport , hirq , in_isr );
950954 }
0 commit comments