Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / common / printf_serial.c
blob4e29b993ce8105baf19729ad3f415340cabf053b
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
22 #include <stdbool.h>
23 #include <stdint.h>
24 #include <stdarg.h>
25 #include <stdlib.h>
27 #include "platform.h"
29 #include "common/printf.h"
31 #include "drivers/serial.h"
32 #include "io/serial.h"
34 #include "printf_serial.h"
36 #ifdef SERIAL_PORT_COUNT
38 static serialPort_t *printfSerialPort;
40 void setPrintfSerialPort(serialPort_t *serialPort)
42 printfSerialPort = serialPort;
45 #ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
47 int tfp_printf(const char *fmt, ...)
49 va_list va;
50 va_start(va, fmt);
51 int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
52 va_end(va);
53 while (!isSerialTransmitBufferEmpty(printfSerialPort));
54 return written;
57 static void _putc(void *p, char c)
59 UNUSED(p);
60 serialWrite(printfSerialPort, c);
64 void printfSerialInit(void)
66 init_printf(NULL, _putc);
69 #else // REQUIRE_CC_ARM_PRINTF_SUPPORT
71 // keil/armcc version
72 int fputc(int c, FILE *f)
74 // let DMA catch up a bit when using set or dump, we're too fast.
75 while (!isSerialTransmitBufferEmpty(printfSerialPort));
76 serialWrite(printfSerialPort, c);
77 return c;
80 void printfSerialInit(void)
82 // Nothing to do
84 #endif
86 #endif // SERIAL_PORT_COUNT