Skip to content

Commit 41edda7

Browse files
committed
pbio/sys/host: move stdin buffer to host from bluetooth
Move the stdin buffer from pbsys/bluetooth to pbsys/host so that it can be used by other host interfaces, such as USB stdio. All connections will share the same stdin buffer. All function names are renames from "rx" to "stdin" to reflect the current usage. The "rx" naming was a holdover from when this was originally only used for Bluetooth RX via the Nordic UART Service. A new PBSYS_CONFIG_HOST_STDIN_BUF_SIZE option is introduced to set a platform-specific buffer size. Bluetooth-only hubs continue to use the same size that was used in pbsys/bluetooth. Hubs with USB are set to 64 bytes to match the USB endpoint size.
1 parent aafbd8d commit 41edda7

File tree

16 files changed

+107
-141
lines changed

16 files changed

+107
-141
lines changed

bricks/_common_stm32/mphalport.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void mp_hal_delay_ms(mp_uint_t Delay) {
3838
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
3939
uintptr_t ret = 0;
4040

41-
if ((poll_flags & MP_STREAM_POLL_RD) && pbsys_host_rx_get_available()) {
41+
if ((poll_flags & MP_STREAM_POLL_RD) && pbsys_host_stdin_get_available()) {
4242
ret |= MP_STREAM_POLL_RD;
4343
}
4444

@@ -51,7 +51,7 @@ int mp_hal_stdin_rx_chr(void) {
5151
uint8_t c;
5252

5353
// wait for rx interrupt
54-
while (size = 1, pbsys_host_rx(&c, &size) != PBIO_SUCCESS) {
54+
while (size = 1, pbsys_host_stdin_read(&c, &size) != PBIO_SUCCESS) {
5555
MICROPY_EVENT_POLL_HOOK
5656
}
5757

lib/pbio/include/pbsys/host.h

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,26 @@ typedef bool (*pbsys_host_stdin_event_callback_t)(uint8_t c);
2626
#if PBSYS_CONFIG_HOST
2727

2828
void pbsys_host_init(void);
29-
void pbsys_host_rx_set_callback(pbsys_host_stdin_event_callback_t callback);
30-
void pbsys_host_rx_flush(void);
31-
uint32_t pbsys_host_rx_get_available(void);
32-
uint32_t pbsys_host_rx_get_free(void);
33-
void pbsys_host_rx_write(const uint8_t *data, uint32_t size);
34-
pbio_error_t pbsys_host_rx(uint8_t *data, uint32_t *size);
29+
uint32_t pbsys_host_stdin_get_free(void);
30+
void pbsys_host_stdin_write(const uint8_t *data, uint32_t size);
31+
void pbsys_host_stdin_set_callback(pbsys_host_stdin_event_callback_t callback);
32+
void pbsys_host_stdin_flush(void);
33+
uint32_t pbsys_host_stdin_get_available(void);
34+
pbio_error_t pbsys_host_stdin_read(uint8_t *data, uint32_t *size);
3535
pbio_error_t pbsys_host_tx(const uint8_t *data, uint32_t size);
3636
bool pbsys_host_tx_is_idle(void);
3737

3838
#else // PBSYS_CONFIG_HOST
3939

4040
#define pbsys_host_init()
41-
#define pbsys_host_rx_set_callback(callback)
42-
#define pbsys_host_rx_flush()
43-
#define pbsys_host_rx_get_available() 0
44-
#define pbsys_host_rx_get_free() 0
45-
#define pbsys_host_rx_write(data, size)
46-
47-
static inline pbio_error_t pbsys_host_rx(uint8_t *data, uint32_t *size) {
48-
return PBIO_ERROR_NOT_SUPPORTED;
49-
}
50-
static inline pbio_error_t pbsys_host_tx(const uint8_t *data, uint32_t size) {
51-
return PBIO_ERROR_NOT_SUPPORTED;
52-
}
53-
static inline bool pbsys_host_tx_is_idle(void) {
54-
return false;
55-
}
41+
#define pbsys_host_stdin_get_free() 0
42+
#define pbsys_host_stdin_write(data, size) { (void)(data); (void)(size); }
43+
#define pbsys_host_stdin_set_callback(callback) { (void)(callback); }
44+
#define pbsys_host_stdin_flush()
45+
#define pbsys_host_stdin_get_available() 0
46+
#define pbsys_host_stdin_read(data, size) PBIO_ERROR_NOT_SUPPORTED
47+
#define pbsys_host_tx(data, size) { (void)(data); (void)(size); PBIO_ERROR_NOT_SUPPORTED; }
48+
#define pbsys_host_tx_is_idle() false
5649

5750
#endif // PBSYS_CONFIG_HOST
5851

lib/pbio/platform/city_hub/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
1414
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
1515
#define PBSYS_CONFIG_HOST (1)
16+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (21)
1617
#define PBSYS_CONFIG_MAIN (1)
1718
#define PBSYS_CONFIG_STORAGE (1)
1819
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)

lib/pbio/platform/essential_hub/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
1212
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
1313
#define PBSYS_CONFIG_HOST (1)
14+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (64)
1415
#define PBSYS_CONFIG_MAIN (1)
1516
#define PBSYS_CONFIG_STORAGE (1)
1617
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)

lib/pbio/platform/ev3/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6 (1)
88
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
99
#define PBSYS_CONFIG_HOST (1)
10+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (21)
1011
#define PBSYS_CONFIG_MAIN (1)
1112
#define PBSYS_CONFIG_STORAGE (1)
1213
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)

lib/pbio/platform/move_hub/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
1414
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
1515
#define PBSYS_CONFIG_HOST (1)
16+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (21)
1617
#define PBSYS_CONFIG_MAIN (1)
1718
#define PBSYS_CONFIG_STORAGE (1)
1819
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)

lib/pbio/platform/nxt/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6 (1)
88
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
99
#define PBSYS_CONFIG_HOST (1)
10+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (64)
1011
#define PBSYS_CONFIG_MAIN (1)
1112
#define PBSYS_CONFIG_STORAGE (1)
1213
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)

lib/pbio/platform/prime_hub/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define PBSYS_CONFIG_HMI_NUM_SLOTS (5)
1414
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (1)
1515
#define PBSYS_CONFIG_HOST (1)
16+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (64)
1617
#define PBSYS_CONFIG_MAIN (1)
1718
#define PBSYS_CONFIG_STORAGE (1)
1819
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (5)

lib/pbio/platform/technic_hub/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
1414
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
1515
#define PBSYS_CONFIG_HOST (1)
16+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (21)
1617
#define PBSYS_CONFIG_MAIN (1)
1718
#define PBSYS_CONFIG_STORAGE (1)
1819
#define PBSYS_CONFIG_STORAGE_NUM_SLOTS (1)

lib/pbio/platform/test/pbsysconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PBSYS_CONFIG_FEATURE_PROGRAM_FORMAT_MULTI_MPY_V6_3_NATIVE (0)
99
#define PBSYS_CONFIG_BLUETOOTH (1)
1010
#define PBSYS_CONFIG_HOST (1)
11+
#define PBSYS_CONFIG_HOST_STDIN_BUF_SIZE (64)
1112
#define PBSYS_CONFIG_HMI_NUM_SLOTS (0)
1213
#define PBSYS_CONFIG_HUB_LIGHT_MATRIX (0)
1314
#define PBSYS_CONFIG_MAIN (0)

0 commit comments

Comments
 (0)