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 "platform.h"
|
||||||
|
|
||||||
|
#include "io/serial.h" // For SERIAL_PORT_IDENTIFIER_TO_INDEX
|
||||||
#include "drivers/io.h"
|
#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"
|
#include "inverter.h"
|
||||||
|
|
||||||
#ifdef USE_INVERTER
|
#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)
|
||||||
{
|
{
|
||||||
IOWrite(pin, 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);
|
IO_t pin = IOGetByTag(pSerialPinConfig->ioTagInverter[SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier)]);
|
||||||
IOInit(pin, OWNER_INVERTER, 1);
|
|
||||||
IOConfigGPIO(pin, IOCFG_OUT_PP);
|
|
||||||
|
|
||||||
inverterSet(pin, false);
|
if (pin) {
|
||||||
|
IOInit(pin, OWNER_INVERTER, RESOURCE_INDEX(SERIAL_PORT_IDENTIFIER_TO_INDEX(identifier)));
|
||||||
|
IOConfigGPIO(pin, IOCFG_OUT_PP);
|
||||||
|
|
||||||
|
inverterSet(identifier, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void initInverters(void)
|
void initInverters(const serialPinConfig_t *serialPinConfigToUse)
|
||||||
{
|
{
|
||||||
#ifdef INVERTER_PIN_UART1
|
pSerialPinConfig = serialPinConfigToUse;
|
||||||
initInverter(IO_TAG(INVERTER_PIN_UART1));
|
|
||||||
|
#ifdef USE_UART1
|
||||||
|
initInverter(SERIAL_PORT_USART1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART2
|
#ifdef USE_UART2
|
||||||
initInverter(IO_TAG(INVERTER_PIN_UART2));
|
initInverter(SERIAL_PORT_USART2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART3
|
#ifdef USE_UART3
|
||||||
initInverter(IO_TAG(INVERTER_PIN_UART3));
|
initInverter(SERIAL_PORT_USART3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART4
|
#ifdef USE_UART4
|
||||||
initInverter(IO_TAG(INVERTER_PIN_UART4));
|
initInverter(SERIAL_PORT_UART4);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART5
|
#ifdef USE_UART5
|
||||||
initInverter(IO_TAG(INVERTER_PIN_UART5));
|
initInverter(SERIAL_PORT_UART5);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART6
|
#ifdef USE_UART6
|
||||||
initInverter(IO_TAG(INVERTER_PIN_UART6));
|
initInverter(SERIAL_PORT_USART6);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void enableInverter(USART_TypeDef *USARTx, bool on)
|
void enableInverter(USART_TypeDef *USARTx, bool on)
|
||||||
{
|
{
|
||||||
#ifdef USE_INVERTER
|
int identifier = SERIAL_PORT_NONE;
|
||||||
IO_t pin = IO_NONE;
|
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART1
|
#ifdef USE_UART1
|
||||||
if (USARTx == USART1) {
|
if (USARTx == USART1) {
|
||||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART1));
|
identifier = SERIAL_PORT_USART1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART2
|
#ifdef USE_UART2
|
||||||
if (USARTx == USART2) {
|
if (USARTx == USART2) {
|
||||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART2));
|
identifier = SERIAL_PORT_USART2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART3
|
#ifdef USE_UART3
|
||||||
if (USARTx == USART3) {
|
if (USARTx == USART3) {
|
||||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART3));
|
identifier = SERIAL_PORT_USART3;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART4
|
#ifdef USE_UART4
|
||||||
if (USARTx == UART4) {
|
if (USARTx == UART4) {
|
||||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART4));
|
identifier = SERIAL_PORT_UART4;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART5
|
#ifdef USE_UART5
|
||||||
if (USARTx == UART5) {
|
if (USARTx == UART5) {
|
||||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART5));
|
identifier = SERIAL_PORT_UART5;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INVERTER_PIN_UART6
|
#ifdef USE_UART6
|
||||||
if (USARTx == USART6) {
|
if (USARTx == USART6) {
|
||||||
pin = IOGetByTag(IO_TAG(INVERTER_PIN_UART6));
|
identifier = SERIAL_PORT_USART6;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inverterSet(pin, on);
|
if (identifier != SERIAL_PORT_NONE) {
|
||||||
#else
|
inverterSet(identifier, on);
|
||||||
UNUSED(USARTx);
|
}
|
||||||
UNUSED(on);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif // USE_INVERTER
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
#define USE_INVERTER
|
#define USE_INVERTER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initInverters(void);
|
#include "drivers/serial.h"
|
||||||
|
|
||||||
|
void initInverters(const serialPinConfig_t *serialPinConfigToUse);
|
||||||
|
|
||||||
void enableInverter(USART_TypeDef *USARTx, bool on);
|
void enableInverter(USART_TypeDef *USARTx, bool on);
|
||||||
|
|
|
@ -83,6 +83,7 @@ typedef struct serialPort_s {
|
||||||
typedef struct serialPinConfig_s {
|
typedef struct serialPinConfig_s {
|
||||||
ioTag_t ioTagTx[SERIAL_PORT_MAX_INDEX];
|
ioTag_t ioTagTx[SERIAL_PORT_MAX_INDEX];
|
||||||
ioTag_t ioTagRx[SERIAL_PORT_MAX_INDEX];
|
ioTag_t ioTagRx[SERIAL_PORT_MAX_INDEX];
|
||||||
|
ioTag_t ioTagInverter[SERIAL_PORT_MAX_INDEX];
|
||||||
} serialPinConfig_t;
|
} serialPinConfig_t;
|
||||||
|
|
||||||
struct serialPortVTable {
|
struct serialPortVTable {
|
||||||
|
|
|
@ -62,6 +62,7 @@ extern uint8_t __config_end;
|
||||||
#include "drivers/flash.h"
|
#include "drivers/flash.h"
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
#include "drivers/io_impl.h"
|
#include "drivers/io_impl.h"
|
||||||
|
#include "drivers/inverter.h"
|
||||||
#include "drivers/rx_pwm.h"
|
#include "drivers/rx_pwm.h"
|
||||||
#include "drivers/sdcard.h"
|
#include "drivers/sdcard.h"
|
||||||
#include "drivers/sensor.h"
|
#include "drivers/sensor.h"
|
||||||
|
@ -2744,6 +2745,9 @@ const cliResourceValue_t resourceTable[] = {
|
||||||
#endif
|
#endif
|
||||||
{ OWNER_SERIAL_TX, PG_SERIAL_PIN_CONFIG, offsetof(serialPinConfig_t, ioTagTx[0]), SERIAL_PORT_MAX_INDEX },
|
{ 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 },
|
{ 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)
|
static ioTag_t *getIoTag(const cliResourceValue_t value, uint8_t index)
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
#include "drivers/accgyro/accgyro.h"
|
#include "drivers/accgyro/accgyro.h"
|
||||||
#include "drivers/compass/compass.h"
|
#include "drivers/compass/compass.h"
|
||||||
|
#include "drivers/inverter.h"
|
||||||
#include "drivers/io.h"
|
#include "drivers/io.h"
|
||||||
#include "drivers/light_led.h"
|
#include "drivers/light_led.h"
|
||||||
#include "drivers/light_ws2811strip.h"
|
#include "drivers/light_ws2811strip.h"
|
||||||
|
@ -356,36 +357,54 @@ void pgResetFn_serialPinConfig(serialPinConfig_t *serialPinConfig)
|
||||||
#ifdef USE_UART1
|
#ifdef USE_UART1
|
||||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART1)] = IO_TAG(UART1_RX_PIN);
|
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);
|
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
|
#endif
|
||||||
break;
|
break;
|
||||||
case SERIAL_PORT_USART2:
|
case SERIAL_PORT_USART2:
|
||||||
#ifdef USE_UART2
|
#ifdef USE_UART2
|
||||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART2)] = IO_TAG(UART2_RX_PIN);
|
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);
|
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
|
#endif
|
||||||
break;
|
break;
|
||||||
case SERIAL_PORT_USART3:
|
case SERIAL_PORT_USART3:
|
||||||
#ifdef USE_UART3
|
#ifdef USE_UART3
|
||||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART3)] = IO_TAG(UART3_RX_PIN);
|
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);
|
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
|
#endif
|
||||||
break;
|
break;
|
||||||
case SERIAL_PORT_UART4:
|
case SERIAL_PORT_UART4:
|
||||||
#ifdef USE_UART4
|
#ifdef USE_UART4
|
||||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_UART4)] = IO_TAG(UART4_RX_PIN);
|
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);
|
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
|
#endif
|
||||||
break;
|
break;
|
||||||
case SERIAL_PORT_UART5:
|
case SERIAL_PORT_UART5:
|
||||||
#ifdef USE_UART5
|
#ifdef USE_UART5
|
||||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_UART5)] = IO_TAG(UART5_RX_PIN);
|
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);
|
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
|
#endif
|
||||||
break;
|
break;
|
||||||
case SERIAL_PORT_USART6:
|
case SERIAL_PORT_USART6:
|
||||||
#ifdef USE_UART6
|
#ifdef USE_UART6
|
||||||
serialPinConfig->ioTagRx[SERIAL_PORT_IDENTIFIER_TO_RESOURCE_INDEX(SERIAL_PORT_USART6)] = IO_TAG(UART6_RX_PIN);
|
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);
|
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
|
#endif
|
||||||
break;
|
break;
|
||||||
case SERIAL_PORT_USART7:
|
case SERIAL_PORT_USART7:
|
||||||
|
|
|
@ -339,7 +339,7 @@ void init(void)
|
||||||
#endif
|
#endif
|
||||||
/* temp until PGs are implemented. */
|
/* temp until PGs are implemented. */
|
||||||
#ifdef USE_INVERTER
|
#ifdef USE_INVERTER
|
||||||
initInverters();
|
initInverters(serialPinConfig());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TARGET_BUS_INIT
|
#ifdef TARGET_BUS_INIT
|
||||||
|
|
Loading…
Reference in New Issue