diff --git a/lib/pbio/drv/bluetooth/bluetooth.c b/lib/pbio/drv/bluetooth/bluetooth.c index 6fea58ae0..809fd0059 100644 --- a/lib/pbio/drv/bluetooth/bluetooth.c +++ b/lib/pbio/drv/bluetooth/bluetooth.c @@ -62,9 +62,13 @@ static lwrb_t stdout_ring_buf; static bool stdout_send_busy; void pbdrv_bluetooth_init(void) { - // enough for two packets, one currently being sent and one to be ready + // enough for 200 packets, one currently being sent and one to be ready // as soon as the previous one completes + 1 byte for ring buf pointer + #if PBDRV_CONFIG_BLOCK_DEVICE_RAM_SIZE > (20 * 1024) + static uint8_t stdout_buf[PBDRV_BLUETOOTH_MAX_CHAR_SIZE * 200 + 1]; + #else static uint8_t stdout_buf[PBDRV_BLUETOOTH_MAX_CHAR_SIZE * 2 + 1]; + #endif lwrb_init(&stdout_ring_buf, stdout_buf, PBIO_ARRAY_SIZE(stdout_buf)); pbdrv_bluetooth_init_hci(); diff --git a/lib/pbio/src/port_lump.c b/lib/pbio/src/port_lump.c index cba71058e..ad694aa13 100644 --- a/lib/pbio/src/port_lump.c +++ b/lib/pbio/src/port_lump.c @@ -16,16 +16,51 @@ #include #include -#define DEBUG 0 -#if DEBUG +#define DEBUG 2 + +#if DEBUG == 1 #include #include #include -#define debug_pr pbdrv_uart_debug_printf -#define DBG_ERR(expr) expr +#define debug_pr printf +#elif DEBUG == 2 && PBDRV_CONFIG_BLOCK_DEVICE_RAM_SIZE > (20 * 1024) +#include +#include +#include +#include +#include +int debug_pr(const char *format, ...) { + char buffer[256]; + va_list args; + int len; + + + va_start(args, format); + len = vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + + if (len < 0) { + return len; + } + + if ((size_t)len >= sizeof(buffer)) { + len = sizeof(buffer) - 1; + } + + if (len > 0 && buffer[len - 1] == '\n' && (size_t)len + 1 < sizeof(buffer)) { + buffer[len - 1] = '\r'; + buffer[len] = '\n'; + len++; + } + + // Write the formatted string using pbsys_host_stdout_write + uint32_t size = len; + pbsys_host_stdout_write((const uint8_t *)buffer, &size); + + return len; // Return the number of characters written +} #else #define debug_pr(...) -#define DBG_ERR(expr) #endif #define EV3_UART_MAX_MESSAGE_SIZE (LUMP_MAX_MSG_SIZE + 3)