@@ -124,6 +124,8 @@ typedef struct {
124124 struct {
125125 TUD_EPBUF_TYPE_DEF (ntb , xmit_ntb_t );
126126 } xmit [XMIT_NTB_N ];
127+
128+ TUD_EPBUF_TYPE_DEF (epnotif , ncm_notify_t );
127129} ncm_epbuf_t ;
128130
129131static ncm_interface_t ncm_interface ;
@@ -165,30 +167,6 @@ TU_ATTR_ALIGNED(4) static const ntb_parameters_t ntb_parameters = {
165167//
166168// everything about notifications
167169//
168- tu_static struct ncm_notify_t ncm_notify_connected = {
169- .header = {
170- .bmRequestType_bit = {
171- .recipient = TUSB_REQ_RCPT_INTERFACE ,
172- .type = TUSB_REQ_TYPE_CLASS ,
173- .direction = TUSB_DIR_IN },
174- .bRequest = CDC_NOTIF_NETWORK_CONNECTION ,
175- .wValue = 1 /* Connected */ ,
176- .wLength = 0 ,
177- },
178- };
179-
180- tu_static struct ncm_notify_t ncm_notify_speed_change = {
181- .header = {
182- .bmRequestType_bit = {
183- .recipient = TUSB_REQ_RCPT_INTERFACE ,
184- .type = TUSB_REQ_TYPE_CLASS ,
185- .direction = TUSB_DIR_IN },
186- .bRequest = CDC_NOTIF_CONNECTION_SPEED_CHANGE ,
187- .wLength = 8 ,
188- },
189- .downlink = TUD_OPT_HIGH_SPEED ? 480000000 : 12000000 ,
190- .uplink = TUD_OPT_HIGH_SPEED ? 480000000 : 12000000 ,
191- };
192170
193171/**
194172 * Transmit next notification to the host (if appropriate).
@@ -203,14 +181,51 @@ static void notification_xmit(uint8_t rhport, bool force_next) {
203181
204182 if (ncm_interface .notification_xmit_state == NOTIFICATION_SPEED ) {
205183 TU_LOG_DRV (" NOTIFICATION_SPEED\n" );
206- ncm_notify_speed_change .header .wIndex = ncm_interface .itf_num ;
207- usbd_edpt_xfer (rhport , ncm_interface .ep_notif , (uint8_t * ) & ncm_notify_speed_change , sizeof (ncm_notify_speed_change ));
184+ ncm_notify_t notify_speed_change = {
185+ .header = {
186+ .bmRequestType_bit = {
187+ .recipient = TUSB_REQ_RCPT_INTERFACE ,
188+ .type = TUSB_REQ_TYPE_CLASS ,
189+ .direction = TUSB_DIR_IN
190+ },
191+ .bRequest = CDC_NOTIF_CONNECTION_SPEED_CHANGE ,
192+ .wValue = 0 ,
193+ .wIndex = ncm_interface .itf_num ,
194+ .wLength = 8
195+ }
196+ };
197+ if (tud_speed_get () == TUSB_SPEED_HIGH ) {
198+ notify_speed_change .downlink = 480000000 ;
199+ notify_speed_change .uplink = 480000000 ;
200+ } else {
201+ notify_speed_change .downlink = 12000000 ;
202+ notify_speed_change .uplink = 12000000 ;
203+ }
204+
205+ ncm_epbuf .epnotif = notify_speed_change ;
206+ usbd_edpt_xfer (rhport , ncm_interface .ep_notif , (uint8_t * ) & ncm_epbuf .epnotif , sizeof (ncm_notify_t ));
207+
208208 ncm_interface .notification_xmit_state = NOTIFICATION_CONNECTED ;
209209 ncm_interface .notification_xmit_is_running = true;
210210 } else if (ncm_interface .notification_xmit_state == NOTIFICATION_CONNECTED ) {
211211 TU_LOG_DRV (" NOTIFICATION_CONNECTED\n" );
212- ncm_notify_connected .header .wIndex = ncm_interface .itf_num ;
213- usbd_edpt_xfer (rhport , ncm_interface .ep_notif , (uint8_t * ) & ncm_notify_connected , sizeof (ncm_notify_connected ));
212+ ncm_notify_t notify_connected = {
213+ .header = {
214+ .bmRequestType_bit = {
215+ .recipient = TUSB_REQ_RCPT_INTERFACE ,
216+ .type = TUSB_REQ_TYPE_CLASS ,
217+ .direction = TUSB_DIR_IN
218+ },
219+ .bRequest = CDC_NOTIF_NETWORK_CONNECTION ,
220+ .wValue = 1 /* Connected */ ,
221+ .wIndex = ncm_interface .itf_num ,
222+ .wLength = 0 ,
223+ },
224+ };
225+
226+ ncm_epbuf .epnotif = notify_connected ;
227+ usbd_edpt_xfer (rhport , ncm_interface .ep_notif , (uint8_t * ) & ncm_epbuf .epnotif , sizeof (ncm_notify_t ));
228+
214229 ncm_interface .notification_xmit_state = NOTIFICATION_DONE ;
215230 ncm_interface .notification_xmit_is_running = true;
216231 } else {
0 commit comments