Skip to content

Commit 92457ec

Browse files
authored
Merge pull request hathach#2202 from Rocky04/patch-4
Invoke unmounted state on configuration reset
2 parents 04f0cd5 + 9602c06 commit 92457ec

File tree

21 files changed

+46
-25
lines changed

21 files changed

+46
-25
lines changed

examples/device/audio_4_channel_mic/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
133133
// Invoked when usb bus is resumed
134134
void tud_resume_cb(void)
135135
{
136-
blink_interval_ms = BLINK_MOUNTED;
136+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
137137
}
138138

139139
//--------------------------------------------------------------------+

examples/device/audio_test/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
134134
// Invoked when usb bus is resumed
135135
void tud_resume_cb(void)
136136
{
137-
blink_interval_ms = BLINK_MOUNTED;
137+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
138138
}
139139

140140
//--------------------------------------------------------------------+

examples/device/audio_test_multi_rate/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
146146
// Invoked when usb bus is resumed
147147
void tud_resume_cb(void)
148148
{
149-
blink_interval_ms = BLINK_MOUNTED;
149+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
150150
}
151151

152152
//--------------------------------------------------------------------+

examples/device/cdc_msc/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
9999
// Invoked when usb bus is resumed
100100
void tud_resume_cb(void)
101101
{
102-
blink_interval_ms = BLINK_MOUNTED;
102+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
103103
}
104104

105105

examples/device/cdc_msc_freertos/src/main.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,14 @@ void tud_suspend_cb(bool remote_wakeup_en)
179179
// Invoked when usb bus is resumed
180180
void tud_resume_cb(void)
181181
{
182-
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
182+
if (tud_mounted())
183+
{
184+
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
185+
}
186+
else
187+
{
188+
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
189+
}
183190
}
184191

185192
//--------------------------------------------------------------------+

examples/device/dfu/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
116116
// Invoked when usb bus is resumed
117117
void tud_resume_cb(void)
118118
{
119-
blink_interval_ms = BLINK_MOUNTED;
119+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
120120
}
121121

122122
//--------------------------------------------------------------------+

examples/device/dfu_runtime/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
111111
// Invoked when usb bus is resumed
112112
void tud_resume_cb(void)
113113
{
114-
blink_interval_ms = BLINK_MOUNTED;
114+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
115115
}
116116

117117
// Invoked on DFU_DETACH request to reboot to the bootloader

examples/device/dynamic_configuration/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
100100
// Invoked when usb bus is resumed
101101
void tud_resume_cb(void)
102102
{
103-
blink_interval_ms = BLINK_MOUNTED;
103+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
104104
}
105105

106106

examples/device/hid_boot_interface/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
102102
// Invoked when usb bus is resumed
103103
void tud_resume_cb(void)
104104
{
105-
blink_interval_ms = BLINK_MOUNTED;
105+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
106106
}
107107

108108
//--------------------------------------------------------------------+

examples/device/hid_composite/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
101101
// Invoked when usb bus is resumed
102102
void tud_resume_cb(void)
103103
{
104-
blink_interval_ms = BLINK_MOUNTED;
104+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
105105
}
106106

107107
//--------------------------------------------------------------------+

examples/device/hid_composite_freertos/src/main.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,14 @@ void tud_suspend_cb(bool remote_wakeup_en)
180180
// Invoked when usb bus is resumed
181181
void tud_resume_cb(void)
182182
{
183-
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
183+
if (tud_mounted())
184+
{
185+
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_MOUNTED), 0);
186+
}
187+
else
188+
{
189+
xTimerChangePeriod(blinky_tm, pdMS_TO_TICKS(BLINK_NOT_MOUNTED), 0);
190+
}
184191
}
185192

186193
//--------------------------------------------------------------------+

examples/device/hid_generic_inout/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
122122
// Invoked when usb bus is resumed
123123
void tud_resume_cb(void)
124124
{
125-
blink_interval_ms = BLINK_MOUNTED;
125+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
126126
}
127127

128128
//--------------------------------------------------------------------+

examples/device/hid_multiple_interface/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
105105
// Invoked when usb bus is resumed
106106
void tud_resume_cb(void)
107107
{
108-
blink_interval_ms = BLINK_MOUNTED;
108+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
109109
}
110110

111111
//--------------------------------------------------------------------+

examples/device/midi_test/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
105105
// Invoked when usb bus is resumed
106106
void tud_resume_cb(void)
107107
{
108-
blink_interval_ms = BLINK_MOUNTED;
108+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
109109
}
110110

111111
//--------------------------------------------------------------------+

examples/device/msc_dual_lun/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
9696
// Invoked when usb bus is resumed
9797
void tud_resume_cb(void)
9898
{
99-
blink_interval_ms = BLINK_MOUNTED;
99+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
100100
}
101101

102102
//--------------------------------------------------------------------+

examples/device/uac2_headset/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
147147
// Invoked when usb bus is resumed
148148
void tud_resume_cb(void)
149149
{
150-
blink_interval_ms = BLINK_MOUNTED;
150+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
151151
}
152152

153153
// Helper for clock get requests

examples/device/usbtmc/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
9797
// Invoked when usb bus is resumed
9898
void tud_resume_cb(void)
9999
{
100-
blink_interval_ms = BLINK_MOUNTED;
100+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
101101
}
102102

103103
//--------------------------------------------------------------------+

examples/device/video_capture/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
100100
// Invoked when usb bus is resumed
101101
void tud_resume_cb(void)
102102
{
103-
blink_interval_ms = BLINK_MOUNTED;
103+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
104104
}
105105

106106

examples/device/webusb_serial/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
160160
// Invoked when usb bus is resumed
161161
void tud_resume_cb(void)
162162
{
163-
blink_interval_ms = BLINK_MOUNTED;
163+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
164164
}
165165

166166
//--------------------------------------------------------------------+

examples/dual/host_hid_to_device_cdc/src/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void tud_suspend_cb(bool remote_wakeup_en)
125125
// Invoked when usb bus is resumed
126126
void tud_resume_cb(void)
127127
{
128-
blink_interval_ms = BLINK_MOUNTED;
128+
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
129129
}
130130

131131
// Invoked when CDC interface received data from host

src/device/usbd.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,18 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
710710
_usbd_dev.speed = speed; // restore speed
711711
}
712712

713-
// switch to new configuration if not zero
714-
if ( cfg_num ) TU_ASSERT( process_set_config(rhport, cfg_num) );
713+
// Handle the new configuration and execute the corresponding callback
714+
if ( cfg_num )
715+
{
716+
// switch to new configuration if not zero
717+
TU_ASSERT( process_set_config(rhport, cfg_num) );
718+
719+
if ( tud_mount_cb ) tud_mount_cb();
720+
}
721+
else
722+
{
723+
if ( tud_umount_cb ) tud_umount_cb();
724+
}
715725
}
716726

717727
_usbd_dev.cfg_num = cfg_num;
@@ -964,9 +974,6 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
964974
TU_ASSERT(drv_id < TOTAL_DRIVER_COUNT);
965975
}
966976

967-
// invoke callback
968-
if (tud_mount_cb) tud_mount_cb();
969-
970977
return true;
971978
}
972979

0 commit comments

Comments
 (0)