30 lines
1.1 KiB
C
30 lines
1.1 KiB
C
|
|
#include <stdarg.h>
|
|
#define UART_NUM_0 0
|
|
static const uint8_t *input;
|
|
static size_t input_size, input_offset;
|
|
static char uart_output[4096];
|
|
static size_t uart_output_length;
|
|
static unsigned publications;
|
|
static esp_err_t uart_flush_input(int uart) { assert(uart==0); ++publications; return ESP_OK; }
|
|
static int uart_read_bytes(int uart, void *out, size_t n, unsigned wait)
|
|
{
|
|
assert(uart==0 && n==1 && wait==portMAX_DELAY && !lock_depth);
|
|
if (input_offset==input_size) return -1;
|
|
*(uint8_t *)out=input[input_offset++];
|
|
return 1;
|
|
}
|
|
static int capture_printf(const char *format, ...)
|
|
{
|
|
va_list ap; va_start(ap,format);
|
|
int n=vsnprintf(uart_output+uart_output_length,
|
|
sizeof(uart_output)-uart_output_length,format,ap);
|
|
va_end(ap); assert(n>=0 && (size_t)n<sizeof(uart_output)-uart_output_length);
|
|
uart_output_length+=(size_t)n; return n;
|
|
}
|
|
static int capture_putchar(int c) { return capture_printf("%c",c); }
|
|
static int capture_fflush(FILE *f) { (void)f; return 0; }
|
|
#define printf capture_printf
|
|
#define putchar capture_putchar
|
|
#define fflush capture_fflush
|