Position hold depends on GPS (#14101)
[betaflight.git] / src / main / common / printf_serial.c
blob35876d2de17566ae709c57cdd25855da9857dfbd
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/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <stdarg.h>
24 #include <stdlib.h>
26 #include "platform.h"
28 #include "common/printf.h"
30 #include "drivers/serial.h"
31 #include "io/serial.h"
33 #include "printf_serial.h"
35 #if SERIAL_PORT_COUNT > 0
37 static serialPort_t *printfSerialPort;
39 void setPrintfSerialPort(serialPort_t *serialPort)
41 printfSerialPort = serialPort;
44 #ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
46 int tfp_printf(const char *fmt, ...)
48 va_list va;
49 va_start(va, fmt);
50 int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
51 va_end(va);
52 while (!isSerialTransmitBufferEmpty(printfSerialPort));
53 return written;
56 static void _putc(void *p, char c)
58 UNUSED(p);
59 serialWrite(printfSerialPort, c);
62 void printfSerialInit(void)
64 init_printf(NULL, _putc);
67 #else // REQUIRE_CC_ARM_PRINTF_SUPPORT
69 // keil/armcc version
70 int fputc(int c, FILE *f)
72 // let DMA catch up a bit when using set or dump, we're too fast.
73 while (!isSerialTransmitBufferEmpty(printfSerialPort));
74 serialWrite(printfSerialPort, c);
75 return c;
78 void printfSerialInit(void)
80 // Nothing to do
82 #endif
84 #endif // SERIAL_PORT_COUNT