Make inverter resource configurable
Add XXX comment about inverterConfig size Fixed non-USE_INVERTER case Moved inverter pin to serialPinConfig_t Various improvements Per @ledvinap ’s comments. Only include "drivers/serial.h" from inverter.h SERIAL_PORT_UART{4,5}, not _USART{4,5} Dah! Avoid magic number Prepare for SERIAL_PORT_IDENTIFIER_TO_INDEX change (#3015)
This commit is contained in:
parent
1ad0546af3
commit
9461672b46
|
@ -20,98 +20,114 @@
|
|||
|
||||
#include "platform.h"
|
||||
|
||||
#include "io/serial.h" // For SERIAL_PORT_IDENTIFIER_TO_INDEX
|
||||
#include "drivers/io.h"
|
||||
#include "io_impl.h"
|
||||
#include "drivers/serial.h"
|
||||
|
||||
#include "config/parameter_group.h"
|
||||
#include "config/parameter_group_ids.h"
|
||||
|
||||
#include "inverter.h"
|
||||
|
||||
#ifdef USE_INVERTER
|
||||
static void inverterSet(IO_t pin, bool on)
|
||||
|
||||
// XXX This will go away once #3015 is merged.
|
||||
#define SERIAL_PORT_IDENTIFIER_TO_INDEX SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX
|
||||
|
||||
static const serialPinConfig_t *pSerialPinConfig;
|
||||
|
||||
static void inverterSet(int identifier, bool on)
|
||||
{
|
||||
IO_t pin = IOGetByTag(pSerialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier)]);
|
||||
|
||||
if (pin) {
|
||||
IOWrite(pin, on);
|
||||
}
|
||||
}
|
||||
|
||||
static void initInverter(ioTag_t ioTag)
|
||||
static void initInverter(int identifier)
|
||||
{
|
||||
IO_t pin = IOGetByTag(ioTag);
|
||||
IOInit(pin, OWNER_INVERTER, 1);
|
||||
IO_t pin = IOGetByTag(pSerialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier)]);
|
||||
|
||||
if (pin) {
|
||||
IOInit(pin, OWNER_INVERTER, RESOURCE_INDEX(SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier)));
|
||||
IOConfigGPIO(pin, IOCFG_OUT_PP);
|
||||
|
||||
inverterSet(pin, false);
|
||||
inverterSet(identifier, false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void initInverters(void)
|
||||
void initInverters(const serialPinConfig_t *serialPinConfigToUse)
|
||||
{
|
||||
#ifdef INVERTER_PIN_UART1
|
||||
initInverter(IO_TAG(INVERTER_PIN_UART1));
|
||||
pSerialPinConfig = serialPinConfigToUse;
|
||||
|
||||
#ifdef USE_UART1
|
||||
initInverter(SERIAL_PORT_USART1);
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART2
|
||||
initInverter(IO_TAG(INVERTER_PIN_UART2));
|
||||
#ifdef USE_UART2
|
||||
initInverter(SERIAL_PORT_USART2);
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART3
|
||||
initInverter(IO_TAG(INVERTER_PIN_UART3));
|
||||
#ifdef USE_UART3
|
||||
initInverter(SERIAL_PORT_USART3);
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART4
|
||||
initInverter(IO_TAG(INVERTER_PIN_UART4));
|
||||
#ifdef USE_UART4
|
||||
initInverter(SERIAL_PORT_UART4);
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART5
|
||||
initInverter(IO_TAG(INVERTER_PIN_UART5));
|
||||
#ifdef USE_UART5
|
||||
initInverter(SERIAL_PORT_UART5);
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART6
|
||||
initInverter(IO_TAG(INVERTER_PIN_UART6));
|
||||
#ifdef USE_UART6
|
||||
initInverter(SERIAL_PORT_USART6);
|
||||
#endif
|
||||
}
|
||||
|
||||
void enableInverter(USART_TypeDef *USARTx, bool on)
|
||||
{
|
||||
#ifdef USE_INVERTER
|
||||
IO_t pin = IO_NONE;
|
||||
int identifier = SERIAL_PORT_NONE;
|
||||
|
||||
#ifdef INVERTER_PIN_UART1
|
||||
#ifdef USE_UART1
|
||||
if (USARTx == USART1) {
|
||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART1));
|
||||
identifier = SERIAL_PORT_USART1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART2
|
||||
#ifdef USE_UART2
|
||||
if (USARTx == USART2) {
|
||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART2));
|
||||
identifier = SERIAL_PORT_USART2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART3
|
||||
#ifdef USE_UART3
|
||||
if (USARTx == USART3) {
|
||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART3));
|
||||
identifier = SERIAL_PORT_USART3;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART4
|
||||
#ifdef USE_UART4
|
||||
if (USARTx == UART4) {
|
||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART4));
|
||||
identifier = SERIAL_PORT_UART4;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART5
|
||||
#ifdef USE_UART5
|
||||
if (USARTx == UART5) {
|
||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART5));
|
||||
identifier = SERIAL_PORT_UART5;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef INVERTER_PIN_UART6
|
||||
#ifdef USE_UART6
|
||||
if (USARTx == USART6) {
|
||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART6));
|
||||
identifier = SERIAL_PORT_USART6;
|
||||
}
|
||||
#endif
|
||||
|
||||
inverterSet(pin, on);
|
||||
#else
|
||||
UNUSED(USARTx);
|
||||
UNUSED(on);
|
||||
#endif
|
||||
if (identifier != SERIAL_PORT_NONE) {
|
||||
inverterSet(identifier, on);
|
||||
}
|
||||
}
|
||||
#endif // USE_INVERTER
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#define USE_INVERTER
|
||||
#endif
|
||||
|
||||
void initInverters(void);
|
||||
#include "drivers/serial.h"
|
||||
|
||||
void initInverters(const serialPinConfig_t *serialPinConfigToUse);
|
||||
|
||||
void enableInverter(USART_TypeDef *USARTx, bool on);
|
||||
|
|
|
@ -83,6 +83,7 @@ typedef struct serialPort_s {
|
|||
typedef struct serialPinConfig_s {
|
||||
ioTag_t ioTagTx[SERIAL_PORT_MAX_INDEX];
|
||||
ioTag_t ioTagRx[SERIAL_PORT_MAX_INDEX];
|
||||
ioTag_t ioTagInverter[SERIAL_PORT_MAX_INDEX];
|
||||
} serialPinConfig_t;
|
||||
|
||||
struct serialPortVTable {
|
||||
|
|
|
@ -62,6 +62,7 @@ extern uint8_t __config_end;
|
|||
#include "drivers/flash.h"
|
||||
#include "drivers/io.h"
|
||||
#include "drivers/io_impl.h"
|
||||
#include "drivers/inverter.h"
|
||||
#include "drivers/rx_pwm.h"
|
||||
#include "drivers/sdcard.h"
|
||||
#include "drivers/sensor.h"
|
||||
|
@ -2744,6 +2745,9 @@ const cliResourceValue_t resourceTable[] = {
|
|||
#endif
|
||||
{ OWNER_SERIAL_TX, PG_SERIAL_PIN_CONFIG, offsetof(serialPinConfig_t, ioTagTx[0]), SERIAL_PORT_MAX_INDEX },
|
||||
{ OWNER_SERIAL_RX, PG_SERIAL_PIN_CONFIG, offsetof(serialPinConfig_t, ioTagRx[0]), SERIAL_PORT_MAX_INDEX },
|
||||
#ifdef USE_INVERTER
|
||||
{ OWNER_INVERTER, PG_SERIAL_PIN_CONFIG, offsetof(serialPinConfig_t, ioTagInverter[0]), SERIAL_PORT_MAX_INDEX },
|
||||
#endif
|
||||
};
|
||||
|
||||
static ioTag_t *getIoTag(const cliResourceValue_t value, uint8_t index)
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "drivers/accgyro/accgyro.h"
|
||||
#include "drivers/compass/compass.h"
|
||||
#include "drivers/inverter.h"
|
||||
#include "drivers/io.h"
|
||||
#include "drivers/light_led.h"
|
||||
#include "drivers/light_ws2811strip.h"
|
||||
|
@ -356,36 +357,54 @@ void pgResetFn_serialPinConfig(serialPinConfig_t *serialPinConfig)
|
|||
#ifdef USE_UART1
|
||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART1)] = IO_TAG(UART1_RX_PIN);
|
||||
serialPinConfig->ioTagTx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART1)] = IO_TAG(UART1_TX_PIN);
|
||||
#ifdef INVERTER_PIN_UART1
|
||||
serialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART1)] = IO_TAG(INVERTER_PIN_UART1);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case SERIAL_PORT_USART2:
|
||||
#ifdef USE_UART2
|
||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART2)] = IO_TAG(UART2_RX_PIN);
|
||||
serialPinConfig->ioTagTx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART2)] = IO_TAG(UART2_TX_PIN);
|
||||
#ifdef INVERTER_PIN_UART2
|
||||
serialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART2)] = IO_TAG(INVERTER_PIN_UART2);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case SERIAL_PORT_USART3:
|
||||
#ifdef USE_UART3
|
||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART3)] = IO_TAG(UART3_RX_PIN);
|
||||
serialPinConfig->ioTagTx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART3)] = IO_TAG(UART3_TX_PIN);
|
||||
#ifdef INVERTER_PIN_UART3
|
||||
serialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART3)] = IO_TAG(INVERTER_PIN_UART3);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case SERIAL_PORT_UART4:
|
||||
#ifdef USE_UART4
|
||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_UART4)] = IO_TAG(UART4_RX_PIN);
|
||||
serialPinConfig->ioTagTx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_UART4)] = IO_TAG(UART4_TX_PIN);
|
||||
#ifdef INVERTER_PIN_UART4
|
||||
serialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART4)] = IO_TAG(INVERTER_PIN_UART4);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case SERIAL_PORT_UART5:
|
||||
#ifdef USE_UART5
|
||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_UART5)] = IO_TAG(UART5_RX_PIN);
|
||||
serialPinConfig->ioTagTx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_UART5)] = IO_TAG(UART5_TX_PIN);
|
||||
#ifdef INVERTER_PIN_UART5
|
||||
serialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART5)] = IO_TAG(INVERTER_PIN_UART5);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case SERIAL_PORT_USART6:
|
||||
#ifdef USE_UART6
|
||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART6)] = IO_TAG(UART6_RX_PIN);
|
||||
serialPinConfig->ioTagTx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART6)] = IO_TAG(UART6_TX_PIN);
|
||||
#ifdef INVERTER_PIN_UART6
|
||||
serialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART6)] = IO_TAG(INVERTER_PIN_UART6);
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
case SERIAL_PORT_USART7:
|
||||
|
|
|
@ -339,7 +339,7 @@ void init(void)
|
|||
#endif
|
||||
/* temp until PGs are implemented. */
|
||||
#ifdef USE_INVERTER
|
||||
initInverters();
|
||||
initInverters(serialPinConfig());
|
||||
#endif
|
||||
|
||||
#ifdef TARGET_BUS_INIT
|
||||
|
|
Loading…
Reference in New Issue