1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +03:00

Extract serial-related code from printf.c

This commit is contained in:
Dominic Clifton 2019-03-06 11:12:19 +01:00
parent 9a82a041f4
commit 672c906067
6 changed files with 125 additions and 76 deletions

View file

@ -52,6 +52,7 @@ extern uint8_t __config_end;
#include "common/color.h"
#include "common/maths.h"
#include "common/printf.h"
#include "common/printf_serial.h"
#include "common/strtol.h"
#include "common/time.h"
#include "common/typeconversion.h"

View file

@ -38,15 +38,6 @@
#include "build/build_config.h"
#include "common/utils.h"
#ifdef SERIAL_PORT_COUNT
#include "drivers/serial.h"
#include "io/serial.h"
static serialPort_t *printfSerialPort;
#endif
#include "printf.h"
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
@ -56,9 +47,8 @@ static serialPort_t *printfSerialPort;
#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
typedef void (*putcf) (void *, char);
static putcf stdout_putf;
static void *stdout_putp;
putcf stdout_putf;
void *stdout_putp;
// print bf, padded from left to at least n characters.
// padding is zero ('0') if z!=0, space (' ') otherwise
@ -169,18 +159,6 @@ void init_printf(void *putp, void (*putf) (void *, char))
stdout_putp = putp;
}
#ifdef SERIAL_PORT_COUNT
int tfp_printf(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
va_end(va);
while (!isSerialTransmitBufferEmpty(printfSerialPort));
return written;
}
#endif
static void putcp(void *p, char c)
{
*(*((char **) p))++ = c;
@ -197,47 +175,5 @@ int tfp_sprintf(char *s, const char *fmt, ...)
return written;
}
#ifdef SERIAL_PORT_COUNT
static void _putc(void *p, char c)
{
UNUSED(p);
serialWrite(printfSerialPort, c);
}
#endif
void printfSupportInit(void)
{
#ifdef SERIAL_PORT_COUNT
init_printf(NULL, _putc);
#endif
}
#else
#ifdef SERIAL_PORT_COUNT
// keil/armcc version
int fputc(int c, FILE *f)
{
// let DMA catch up a bit when using set or dump, we're too fast.
while (!isSerialTransmitBufferEmpty(printfSerialPort));
serialWrite(printfSerialPort, c);
return c;
}
#endif
void printfSupportInit(void)
{
#ifdef SERIAL_PORT_COUNT
// Nothing to do
#endif
}
#endif
#ifdef SERIAL_PORT_COUNT
void setPrintfSerialPort(serialPort_t *serialPort)
{
printfSerialPort = serialPort;
}
#endif
#endif // REQUIRE_CC_ARM_PRINTF_SUPPORT

View file

@ -106,14 +106,11 @@ regs Kusti, 23.10.2004
#include <stdarg.h>
typedef void (*putcf) (void *, char);
extern putcf stdout_putf;
extern void *stdout_putp;
void init_printf(void *putp, void (*putf) (void *, char));
// Disabling this, in favour of tfp_format to be used in cli.c
//int tfp_printf(const char *fmt, ...);
int tfp_sprintf(char *s, const char *fmt, ...);
int tfp_format(void *putp, void (*putf) (void *, char), const char *fmt, va_list va);
struct serialPort_s;
void setPrintfSerialPort(struct serialPort_s *serialPort);
void printfSupportInit(void);

View file

@ -0,0 +1,86 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Cleanflight and Betaflight are distributed in the hope that they
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>
#include <stdlib.h>
#include "platform.h"
#include "common/printf.h"
#include "drivers/serial.h"
#include "io/serial.h"
#include "printf_serial.h"
#ifdef SERIAL_PORT_COUNT
static serialPort_t *printfSerialPort;
void setPrintfSerialPort(serialPort_t *serialPort)
{
printfSerialPort = serialPort;
}
#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT
int tfp_printf(const char *fmt, ...)
{
va_list va;
va_start(va, fmt);
int written = tfp_format(stdout_putp, stdout_putf, fmt, va);
va_end(va);
while (!isSerialTransmitBufferEmpty(printfSerialPort));
return written;
}
static void _putc(void *p, char c)
{
UNUSED(p);
serialWrite(printfSerialPort, c);
}
void printfSerialInit(void)
{
init_printf(NULL, _putc);
}
#else // REQUIRE_CC_ARM_PRINTF_SUPPORT
// keil/armcc version
int fputc(int c, FILE *f)
{
// let DMA catch up a bit when using set or dump, we're too fast.
while (!isSerialTransmitBufferEmpty(printfSerialPort));
serialWrite(printfSerialPort, c);
return c;
}
void printfSerialInit(void)
{
// Nothing to do
}
#endif
#endif // SERIAL_PORT_COUNT

View file

@ -0,0 +1,27 @@
/*
* This file is part of Cleanflight and Betaflight.
*
* Cleanflight and Betaflight are free software. You can redistribute
* this software and/or modify this software under the terms of the
* GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Cleanflight and Betaflight are distributed in the hope that they
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software.
*
* If not, see <http://www.gnu.org/licenses/>.
*/
struct serialPort_s;
void printfSerialInit(void);
void setPrintfSerialPort(struct serialPort_s *serialPort);
int tfp_printf(const char *fmt, ...);

View file

@ -32,7 +32,7 @@
#include "common/axis.h"
#include "common/color.h"
#include "common/maths.h"
#include "common/printf.h"
#include "common/printf_serial.h"
#include "config/config_eeprom.h"
#include "config/feature.h"
@ -249,7 +249,9 @@ void init(void)
HAL_Init();
#endif
printfSupportInit();
#ifdef SERIAL_PORT_COUNT
printfSerialInit();
#endif
systemInit();