stdglue.c 864 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "stdglue.h"
  2. #include <main.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. extern UART_HandleTypeDef DEBUG_UART;
  6. static ssize_t stdout_write(void* _cookie, const char* data, size_t size) {
  7. if(data == 0) {
  8. /*
  9. * This means that we should flush internal buffers. Since we
  10. * don't we just return. (Remember, "handle" == -1 means that all
  11. * handles should be flushed.)
  12. */
  13. return 0;
  14. }
  15. HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY);
  16. return size;
  17. }
  18. bool furi_stdglue_init() {
  19. FILE* fp = fopencookie(
  20. NULL,
  21. "w",
  22. (cookie_io_functions_t){
  23. .read = NULL,
  24. .write = stdout_write,
  25. .seek = NULL,
  26. .close = NULL,
  27. });
  28. setvbuf(fp, NULL, _IONBF, 0);
  29. stdout = fp;
  30. return true;
  31. }