diff --git a/src/board.h b/src/board.h index cf1d29e590..2a8b51433c 100755 --- a/src/board.h +++ b/src/board.h @@ -28,10 +28,10 @@ #include "drivers/sound_beeper.h" #include "boardalignment.h" #include "battery.h" -#include "math.h" #ifdef FY90Q // FY90Q +#include "drivers/accgyro_fy90q.h" #include "drivers/adc_common.h" #include "drivers/adc_fy90q.h" #include "drivers/bus_i2c.h" diff --git a/src/build_config.c b/src/build_config.c index f4940a04f8..2b9ba0d644 100644 --- a/src/build_config.c +++ b/src/build_config.c @@ -1,5 +1,7 @@ #include "stdbool.h" #include "stdint.h" +#include "stdlib.h" +#include "stdarg.h" #include "platform.h" @@ -11,6 +13,12 @@ #include "battery.h" #include "config.h" +#include "drivers/serial_common.h" +#include "runtime_config.h" +#include "printf.h" + +#include "build_config.h" + #if MAX_MOTORS != MAX_SUPPORTED_MOTORS #error Motor configuration mismatch #endif @@ -18,3 +26,34 @@ #if MAX_SERVOS != MAX_SUPPORTED_SERVOS #error Servo configuration mismatch #endif + + +#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT + +// gcc/GNU version +static void _putc(void *p, char c) +{ + serialWrite(core.mainport, c); +} + +void initPrintfSupport(void) +{ + init_printf(NULL, _putc); +} + +#else + +// 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(core.mainport)); + serialWrite(core.mainport, c); + return c; +} + +void initPrintfSupport(void) +{ + // nothing to do +} +#endif diff --git a/src/build_config.h b/src/build_config.h index 55547f99de..2e0b75e8d7 100644 --- a/src/build_config.h +++ b/src/build_config.h @@ -3,6 +3,8 @@ //#define SOFT_I2C // enable to test software i2c #ifndef __CC_ARM -#define USE_LAME_PRINTF -#define PRINTF_LONG_SUPPORT +#define REQUIRE_CC_ARM_PRINTF_SUPPORT +#define REQUIRE_PRINTF_LONG_SUPPORT #endif + +void initPrintfSupport(void); diff --git a/src/drivers/accgyro_fy90q.h b/src/drivers/accgyro_fy90q.h new file mode 100644 index 0000000000..a1de1b4da6 --- /dev/null +++ b/src/drivers/accgyro_fy90q.h @@ -0,0 +1,3 @@ +#pragma once + +void adcSensorInit(sensor_t *acc, sensor_t *gyro); diff --git a/src/drivers/adc_common.h b/src/drivers/adc_common.h index e33d6923f7..28b03d9356 100755 --- a/src/drivers/adc_common.h +++ b/src/drivers/adc_common.h @@ -10,6 +10,3 @@ typedef struct drv_adc_config_t { void adcInit(drv_adc_config_t *init); uint16_t adcGetChannel(uint8_t channel); -#ifdef FY90Q -void adcSensorInit(sensor_t *acc, sensor_t *gyro); -#endif diff --git a/src/main.c b/src/main.c index 105901cc83..6221d9f0b1 100755 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,8 @@ #include "rx.h" #include "telemetry_common.h" +#include "build_config.h" + core_t core; extern rcReadRawDataPtr rcReadRawFunc; @@ -11,23 +13,6 @@ extern rcReadRawDataPtr rcReadRawFunc; // receiver read function extern uint16_t pwmReadRawRC(uint8_t chan); -#ifdef USE_LAME_PRINTF -// gcc/GNU version -static void _putc(void *p, char c) -{ - serialWrite(core.mainport, c); -} -#else -// 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(core.mainport)); - serialWrite(core.mainport, c); - return c; -} -#endif - int main(void) { uint8_t i; @@ -38,9 +23,7 @@ int main(void) serialPort_t* loopbackPort2 = NULL; #endif systemInit(); -#ifdef USE_LAME_PRINTF - init_printf(NULL, _putc); -#endif + initPrintfSupport(); checkFirstTime(false); readEEPROM(); diff --git a/src/printf.c b/src/printf.c index 85c36a009d..389288fba6 100644 --- a/src/printf.c +++ b/src/printf.c @@ -31,7 +31,6 @@ #include #include - #include #include "build_config.h" @@ -41,12 +40,12 @@ #include "printf.h" -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT #include "typeconversion.h" #endif -#ifdef USE_LAME_PRINTF +#ifdef REQUIRE_CC_ARM_PRINTF_SUPPORT typedef void (*putcf) (void *, char); static putcf stdout_putf; @@ -76,7 +75,7 @@ void tfp_format(void *putp, putcf putf, char *fmt, va_list va) putf(putp, ch); else { char lz = 0; -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT char lng = 0; #endif int w = 0; @@ -88,7 +87,7 @@ void tfp_format(void *putp, putcf putf, char *fmt, va_list va) if (ch >= '0' && ch <= '9') { ch = a2i(ch, &fmt, 10, &w); } -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT if (ch == 'l') { ch = *(fmt++); lng = 1; @@ -98,7 +97,7 @@ void tfp_format(void *putp, putcf putf, char *fmt, va_list va) case 0: goto abort; case 'u':{ -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT if (lng) uli2a(va_arg(va, unsigned long int), 10, 0, bf); else @@ -108,7 +107,7 @@ void tfp_format(void *putp, putcf putf, char *fmt, va_list va) break; } case 'd':{ -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT if (lng) li2a(va_arg(va, unsigned long int), bf); else @@ -119,7 +118,7 @@ void tfp_format(void *putp, putcf putf, char *fmt, va_list va) } case 'x': case 'X': -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT if (lng) uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf); else @@ -171,4 +170,5 @@ void tfp_sprintf(char *s, char *fmt, ...) putcp(&s, 0); va_end(va); } -#endif /* USE_LAME_PRINTF */ + +#endif diff --git a/src/serial_cli.c b/src/serial_cli.c index f61dad1ed1..189d5ca041 100644 --- a/src/serial_cli.c +++ b/src/serial_cli.c @@ -61,11 +61,7 @@ static const char * const mixerNames[] = { // sync this with AvailableFeatures enum from board.h static const char * const featureNames[] = { "PPM", "VBAT", "INFLIGHT_ACC_CAL", "SERIALRX", "MOTOR_STOP", - "SERVO_TILT", -#ifndef FY90Q - "SOFTSERIAL", -#endif - "LED_RING", "GPS", + "SERVO_TILT", "SOFTSERIAL", "LED_RING", "GPS", "FAILSAFE", "SONAR", "TELEMETRY", "POWERMETER", "VARIO", "3D", NULL }; diff --git a/src/typeconversion.c b/src/typeconversion.c index a0c6611fcf..376dd3726f 100644 --- a/src/typeconversion.c +++ b/src/typeconversion.c @@ -3,7 +3,7 @@ #include "build_config.h" -#ifdef PRINTF_LONG_SUPPORT +#ifdef REQUIRE_PRINTF_LONG_SUPPORT void uli2a(unsigned long int num, unsigned int base, int uc, char *bf) {