1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 01:05:27 +03:00

Merge pull request #1963 from blckmn/bluejay_updates

UART1 SP inversion fix (BlueJayF4)
This commit is contained in:
J Blackman 2017-01-01 13:49:17 +11:00 committed by GitHub
commit 656835a1f8
3 changed files with 37 additions and 23 deletions

View file

@ -46,6 +46,14 @@ void detectHardwareRevision(void)
*/ */
if (!IORead(pin1)) { if (!IORead(pin1)) {
hardwareRevision = BJF4_REV3; 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 { } else {
IO_t pin2 = IOGetByTag(IO_TAG(PB13)); IO_t pin2 = IOGetByTag(IO_TAG(PB13));
IOInit(pin2, OWNER_SYSTEM, 2); IOInit(pin2, OWNER_SYSTEM, 2);
@ -62,18 +70,6 @@ void detectHardwareRevision(void)
hardwareRevision = BJF4_REV2; hardwareRevision = BJF4_REV2;
return; 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) void updateHardwareRevision(void)

View file

@ -18,10 +18,11 @@
typedef enum bjf4HardwareRevision_t { typedef enum bjf4HardwareRevision_t {
UNKNOWN = 0, UNKNOWN = 0,
BJF4_REV1, // Flash BJF4_REV1, // Flash
BJF4_REV2, // SDCard BJF4_REV2, // SDCard
BJF4_REV3, // SDCard + Flash BJF4_REV3, // SDCard + Flash
BJF4_MINI_REV3A, // Flash (20x20 mini format) BJF4_MINI_REV3A, // Flash (20x20 mini format)
BJF4_REV4 // SDCard only - improved UART1 inversion
} bjf4HardwareRevision_e; } bjf4HardwareRevision_e;
extern uint8_t hardwareRevision; extern uint8_t hardwareRevision;

View file

@ -28,16 +28,33 @@
void targetPreInit(void) void targetPreInit(void)
{ {
/* enable the built in inverter if telemetry is setup for the UART1 */ switch (hardwareRevision) {
if (serialConfig()->portConfigs[SERIAL_PORT_USART1].functionMask & FUNCTION_TELEMETRY_SMARTPORT && case BJF4_REV3:
telemetryConfig()->telemetry_inversion && case BJF4_MINI_REV3A:
feature(FEATURE_TELEMETRY)) { case BJF4_REV4:
IO_t io = IOGetByTag(IO_TAG(UART1_INVERTER)); break;
IOInit(io, OWNER_INVERTER, 1); default:
IOConfigGPIO(io, IOCFG_OUT_PP); return;
IOHi(io);
} }
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 */ /* ensure the CS pin for the flash is pulled hi so any SD card initialisation does not impact the chip */
if (hardwareRevision == BJF4_REV3) { if (hardwareRevision == BJF4_REV3) {
IO_t io = IOGetByTag(IO_TAG(M25P16_CS_PIN)); IO_t io = IOGetByTag(IO_TAG(M25P16_CS_PIN));