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.

44 lines
977 B

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