#include "logger.hpp" #include #include #include #include extern "C" { static zchip_uart_t* m_huart; bool g_enable_log = true; /********************************************************************* * @fn _write * * @brief Support Printf Function * * @param *buf - UART send Data. * size - Data length * * @return size: Data length */ __attribute__((used)) int _write(int fd, char* buf, int size) { int i; for (i = 0; i < size; i++) { uint8_t c = *buf++; if (m_huart != NULL) HAL_UART_Transmit(m_huart, &c, 1, 100); } return size; } void zchip_loggger_init(zchip_uart_t* huart) { m_huart = huart; } void zchip_loggger_enable(bool enable) { g_enable_log = enable; } void zchip_log(const char* fmt, ...) { if (g_enable_log) { va_list args; va_start(args, fmt); vprintf(fmt, args); va_end(args); } } }