Skip to content

Commit 96cdd12

Browse files
committed
pbio/sys/host: Add USB handling to pbsys_host_tx_is_idle()
Add an extra check to make sure USB data has been sent before as well to pbsys_host_tx_is_idle() if applicable. Also document the function while we are here.
1 parent 8375029 commit 96cdd12

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/pbio/sys/host.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,23 @@ pbio_error_t pbsys_host_stdout_write(const uint8_t *data, uint32_t *size) {
155155
#endif
156156
}
157157

158+
/**
159+
* Checks if all data has been transmitted.
160+
*
161+
* This is used to implement, e.g. a flush() function that blocks until all
162+
* data has been sent.
163+
*
164+
* @return true if all data has been transmitted or no one is
165+
* listening, false if there is still data queued to be sent.
166+
*/
158167
bool pbsys_host_tx_is_idle(void) {
168+
#if PBDRV_CONFIG_USB && !PBDRV_CONFIG_USB_CHARGE_ONLY
169+
// The USB part is a bit of a hack since it depends on the USB driver not
170+
// buffering more than one packet at a time to actually be accurate.
171+
return pbsys_bluetooth_tx_is_idle() && pbdrv_usb_stdout_tx_available();
172+
#else
159173
return pbsys_bluetooth_tx_is_idle();
174+
#endif
160175
}
161176

162177
#endif // PBSYS_CONFIG_HOST

0 commit comments

Comments
 (0)