You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
864 B

2 years ago
  1. #include "xs_log.h"
  2. #include <stdarg.h>
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. bool g_xs_enable_log = true;
  8. extern UART_HandleTypeDef PC_DEBUG_UART;
  9. /*********************************************************************
  10. * @fn _write
  11. *
  12. * @brief Support Printf Function
  13. *
  14. * @param *buf - UART send Data.
  15. * size - Data length
  16. *
  17. * @return size: Data length
  18. */
  19. __attribute__((used)) int _write(int fd, char* buf, int size) {
  20. int i;
  21. for (i = 0; i < size; i++) {
  22. uint8_t c = *buf++;
  23. HAL_UART_Transmit(&PC_DEBUG_UART, &c, 1, 100);
  24. }
  25. return size;
  26. }
  27. void xs_log_enable(bool enable) { g_xs_enable_log = enable; }
  28. void xs_log(const char* fmt, ...) {
  29. if (g_xs_enable_log) {
  30. va_list args;
  31. va_start(args, fmt);
  32. vprintf(fmt, args);
  33. va_end(args);
  34. }
  35. }