Skip to content

Commit c043f45

Browse files
committed
pbio/sys/host: Simplify enable conditions.
Makes the logic easier to follow, especially as we add more host functions.
1 parent f6b8436 commit c043f45

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/pbio/sys/host.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include <pbsys/command.h>
1414
#include <pbsys/host.h>
1515

16+
#define BLE_ONLY (PBSYS_CONFIG_BLUETOOTH && (!PBDRV_CONFIG_USB || PBDRV_CONFIG_USB_CHARGE_ONLY))
17+
#define USB_ONLY (!PBSYS_CONFIG_BLUETOOTH && PBDRV_CONFIG_USB && !PBDRV_CONFIG_USB_CHARGE_ONLY)
18+
#define BLE_AND_USB (PBSYS_CONFIG_BLUETOOTH && PBDRV_CONFIG_USB && !PBDRV_CONFIG_USB_CHARGE_ONLY)
19+
1620
static pbsys_host_stdin_event_callback_t pbsys_host_stdin_event_callback;
1721
static lwrb_t pbsys_host_stdin_ring_buf;
1822

@@ -142,11 +146,11 @@ pbio_error_t pbsys_host_stdin_read(uint8_t *data, uint32_t *size) {
142146
* ::PBIO_SUCCESS if at least some data was queued.
143147
*/
144148
pbio_error_t pbsys_host_stdout_write(const uint8_t *data, uint32_t *size) {
145-
#if PBSYS_CONFIG_BLUETOOTH && (!PBDRV_CONFIG_USB || PBDRV_CONFIG_USB_CHARGE_ONLY)
149+
#if BLE_ONLY
146150
return pbdrv_bluetooth_tx(data, size);
147-
#elif !PBSYS_CONFIG_BLUETOOTH && PBDRV_CONFIG_USB && !PBDRV_CONFIG_USB_CHARGE_ONLY
151+
#elif USB_ONLY
148152
return pbdrv_usb_stdout_tx(data, size);
149-
#elif PBSYS_CONFIG_BLUETOOTH && PBDRV_CONFIG_USB && !PBDRV_CONFIG_USB_CHARGE_ONLY
153+
#elif BLE_AND_USB
150154

151155
uint32_t bt_avail = pbdrv_bluetooth_tx_available();
152156
uint32_t usb_avail = pbdrv_usb_stdout_tx_available();
@@ -192,12 +196,16 @@ pbio_error_t pbsys_host_stdout_write(const uint8_t *data, uint32_t *size) {
192196
* listening, false if there is still data queued to be sent.
193197
*/
194198
bool pbsys_host_tx_is_idle(void) {
195-
#if PBDRV_CONFIG_USB && !PBDRV_CONFIG_USB_CHARGE_ONLY
196199
// The USB part is a bit of a hack since it depends on the USB driver not
197200
// buffering more than one packet at a time to actually be accurate.
201+
#if BLE_ONLY
202+
return pbdrv_bluetooth_tx_is_idle();
203+
#elif USB_ONLY
204+
return pbdrv_usb_stdout_tx_available();
205+
#elif BLE_AND_USB
198206
return pbdrv_bluetooth_tx_is_idle() && pbdrv_usb_stdout_tx_available();
199207
#else
200-
return pbdrv_bluetooth_tx_is_idle();
208+
return true;
201209
#endif
202210
}
203211

0 commit comments

Comments
 (0)