From 9bf469ac327f164c858506f077d41d63d5c4d5b7 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sun, 1 Jan 2017 12:32:32 +1100 Subject: [PATCH] UART1 SP inversion fix (BlueJayF4) --- src/main/target/BLUEJAYF4/hardware_revision.c | 20 +++++------ src/main/target/BLUEJAYF4/hardware_revision.h | 7 ++-- src/main/target/BLUEJAYF4/initialisation.c | 33 ++++++++++++++----- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/main/target/BLUEJAYF4/hardware_revision.c b/src/main/target/BLUEJAYF4/hardware_revision.c index cb70d05f7..95db1c618 100644 --- a/src/main/target/BLUEJAYF4/hardware_revision.c +++ b/src/main/target/BLUEJAYF4/hardware_revision.c @@ -46,6 +46,14 @@ void detectHardwareRevision(void) */ if (!IORead(pin1)) { hardwareRevision = BJF4_REV3; + + IO_t pin2 = IOGetByTag(IO_TAG(PB13)); + IOInit(pin2, OWNER_SYSTEM, 2); + IOConfigGPIO(pin2, IOCFG_IPU); + + if (!IORead(pin2)) { + hardwareRevision = BJF4_REV4; + } } else { IO_t pin2 = IOGetByTag(IO_TAG(PB13)); IOInit(pin2, OWNER_SYSTEM, 2); @@ -62,18 +70,6 @@ void detectHardwareRevision(void) hardwareRevision = BJF4_REV2; return; } - - /* - enable the UART1 inversion PC9 - - TODO: once param groups are in place, inverter outputs - can be moved to be simple IO outputs, and merely set them - HI or LO in configuration. - */ - IO_t uart1invert = IOGetByTag(IO_TAG(PC9)); - IOInit(uart1invert, OWNER_INVERTER, 2); - IOConfigGPIO(uart1invert, IOCFG_AF_PP); - IOLo(uart1invert); } void updateHardwareRevision(void) diff --git a/src/main/target/BLUEJAYF4/hardware_revision.h b/src/main/target/BLUEJAYF4/hardware_revision.h index 0a2886a16..d2cad3af9 100644 --- a/src/main/target/BLUEJAYF4/hardware_revision.h +++ b/src/main/target/BLUEJAYF4/hardware_revision.h @@ -18,10 +18,11 @@ typedef enum bjf4HardwareRevision_t { UNKNOWN = 0, - BJF4_REV1, // Flash - BJF4_REV2, // SDCard - BJF4_REV3, // SDCard + Flash + BJF4_REV1, // Flash + BJF4_REV2, // SDCard + BJF4_REV3, // SDCard + Flash BJF4_MINI_REV3A, // Flash (20x20 mini format) + BJF4_REV4 // SDCard only - improved UART1 inversion } bjf4HardwareRevision_e; extern uint8_t hardwareRevision; diff --git a/src/main/target/BLUEJAYF4/initialisation.c b/src/main/target/BLUEJAYF4/initialisation.c index a11301baa..389f12e64 100644 --- a/src/main/target/BLUEJAYF4/initialisation.c +++ b/src/main/target/BLUEJAYF4/initialisation.c @@ -28,16 +28,33 @@ void targetPreInit(void) { - /* enable the built in inverter if telemetry is setup for the UART1 */ - if (serialConfig()->portConfigs[SERIAL_PORT_USART1].functionMask & FUNCTION_TELEMETRY_SMARTPORT && - telemetryConfig()->telemetry_inversion && - feature(FEATURE_TELEMETRY)) { - IO_t io = IOGetByTag(IO_TAG(UART1_INVERTER)); - IOInit(io, OWNER_INVERTER, 1); - IOConfigGPIO(io, IOCFG_OUT_PP); - IOHi(io); + switch (hardwareRevision) { + case BJF4_REV3: + case BJF4_MINI_REV3A: + case BJF4_REV4: + break; + default: + return; } + IO_t inverter = IOGetByTag(IO_TAG(UART1_INVERTER)); + IOInit(inverter, OWNER_INVERTER, 1); + IOConfigGPIO(inverter, IOCFG_OUT_PP); + + bool high = false; + serialPortConfig_t *portConfig = serialFindPortConfiguration(SERIAL_PORT_USART1); + if (portConfig) { + bool smartportEnabled = (portConfig->functionMask & FUNCTION_TELEMETRY_SMARTPORT); + if (smartportEnabled && (telemetryConfig()->telemetry_inversion) && (feature(FEATURE_TELEMETRY))) { + high = true; + } + } + /* reverse this for rev4, as it does not use the XOR gate */ + if (hardwareRevision == BJF4_REV4) { + high = !high; + } + IOWrite(inverter, high); + /* ensure the CS pin for the flash is pulled hi so any SD card initialisation does not impact the chip */ if (hardwareRevision == BJF4_REV3) { IO_t io = IOGetByTag(IO_TAG(M25P16_CS_PIN));