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.

45 lines
949 B

12 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. #include "zlog.h"
  2. #include "project_configs.h"
  3. #include "zbase.h"
  4. bool g_xs_enable_log = true;
  5. UART_HandleTypeDef* debuguart;
  6. /*********************************************************************
  7. * @fn _write
  8. *
  9. * @brief Support Printf Function
  10. *
  11. * @param *buf - UART send Data.
  12. * size - Data length
  13. *
  14. * @return size: Data length
  15. */
  16. __attribute__((used)) int _write(int fd, char* buf, int size) {
  17. int i;
  18. for (i = 0; i < size; i++) {
  19. uint8_t c = *buf++;
  20. if (debuguart) HAL_UART_Transmit(debuguart, &c, 1, 100);
  21. }
  22. return size;
  23. }
  24. void zlog_init(UART_HandleTypeDef* uart) { debuguart = uart; }
  25. void zlog_enable(bool enable) { g_xs_enable_log = enable; }
  26. void zlog(const char* fmt, ...) {
  27. if (g_xs_enable_log) {
  28. va_list args;
  29. va_start(args, fmt);
  30. vprintf(fmt, args);
  31. va_end(args);
  32. }
  33. }
  34. void zlog_raw(const char* info) {
  35. if (g_xs_enable_log) {
  36. printf(info);
  37. }
  38. }