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.

41 lines
925 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "logger.hpp"
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. extern "C" {
  7. static zchip_uart_t* m_huart;
  8. bool g_enable_log = true;
  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. if (m_huart != NULL) HAL_UART_Transmit(m_huart, &c, 1, 100);
  24. }
  25. return size;
  26. }
  27. void zchip_loggger_init(zchip_uart_t* huart) { m_huart = huart; }
  28. void zchip_loggger_enable(bool enable) { g_enable_log = enable; }
  29. void zchip_log(const char* fmt, ...) {
  30. if (g_enable_log) {
  31. va_list args;
  32. va_start(args, fmt);
  33. vprintf(fmt, args);
  34. va_end(args);
  35. }
  36. }
  37. }