From 67d448d8ea30d20d5f571e391fe1adcba606bec1 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 9 Jul 2016 17:03:16 +1000 Subject: [PATCH] Improved Resource command output. --- src/main/drivers/accgyro_l3gd20.c | 2 +- src/main/drivers/accgyro_mma845x.c | 2 +- src/main/drivers/accgyro_mpu.c | 2 +- src/main/drivers/accgyro_spi_mpu6000.c | 2 +- src/main/drivers/accgyro_spi_mpu6500.c | 2 +- src/main/drivers/accgyro_spi_mpu9250.c | 2 +- src/main/drivers/adc_stm32f10x.c | 2 +- src/main/drivers/adc_stm32f30x.c | 2 +- src/main/drivers/adc_stm32f4xx.c | 2 +- src/main/drivers/barometer_bmp085.c | 2 +- src/main/drivers/barometer_spi_bmp280.c | 2 +- src/main/drivers/bus_i2c_stm32f10x.c | 4 +- src/main/drivers/bus_i2c_stm32f30x.c | 3 ++ src/main/drivers/bus_spi.c | 18 +++------ src/main/drivers/flash_m25p16.c | 2 +- src/main/drivers/inverter.c | 2 +- src/main/drivers/io.c | 25 ++++++++++--- src/main/drivers/io.h | 2 +- src/main/drivers/io_impl.h | 3 +- src/main/drivers/light_led.c | 2 +- src/main/drivers/light_ws2811strip_stm32f10x.c | 2 +- src/main/drivers/light_ws2811strip_stm32f30x.c | 2 +- src/main/drivers/light_ws2811strip_stm32f4xx.c | 2 +- src/main/drivers/max7456.c | 5 ++- src/main/drivers/pwm_output.c | 11 ++---- src/main/drivers/pwm_rx.c | 16 ++++---- src/main/drivers/resource.h | 43 ++++++++++++---------- src/main/drivers/sdcard.c | 6 +-- src/main/drivers/serial_softserial.c | 30 ++++++--------- src/main/drivers/serial_uart_stm32f10x.c | 18 ++++----- src/main/drivers/serial_uart_stm32f30x.c | 18 ++++----- src/main/drivers/serial_uart_stm32f4xx.c | 6 +-- src/main/drivers/serial_usb_vcp.c | 4 +- src/main/drivers/sonar_hcsr04.c | 4 +- src/main/drivers/sound_beeper.c | 2 +- src/main/drivers/timer.c | 2 +- src/main/drivers/usb_io.c | 4 +- src/main/io/serial_cli.c | 45 +++++------------------ src/main/rx/spektrum.c | 4 +- src/main/target/ALIENFLIGHTF3/hardware_revision.c | 2 +- src/main/target/BLUEJAYF4/target.h | 9 ++++- 41 files changed, 154 insertions(+), 164 deletions(-) diff --git a/src/main/drivers/accgyro_l3gd20.c b/src/main/drivers/accgyro_l3gd20.c index aade7445b..e227d7f8d 100644 --- a/src/main/drivers/accgyro_l3gd20.c +++ b/src/main/drivers/accgyro_l3gd20.c @@ -76,7 +76,7 @@ static void l3gd20SpiInit(SPI_TypeDef *SPIx) UNUSED(SPIx); // FIXME mpul3gd20CsPin = IOGetByTag(IO_TAG(L3GD20_CS_PIN)); - IOInit(mpul3gd20CsPin, OWNER_SYSTEM, RESOURCE_SPI); + IOInit(mpul3gd20CsPin, OWNER_MPU, RESOURCE_SPI_CS, 0); IOConfigGPIO(mpul3gd20CsPin, SPI_IO_CS_CFG); DISABLE_L3GD20; diff --git a/src/main/drivers/accgyro_mma845x.c b/src/main/drivers/accgyro_mma845x.c index 4adbe59ab..202b90e80 100644 --- a/src/main/drivers/accgyro_mma845x.c +++ b/src/main/drivers/accgyro_mma845x.c @@ -105,7 +105,7 @@ static inline void mma8451ConfigureInterrupt(void) // PA5 - ACC_INT2 output on NAZE rev3/4 hardware // NAZE rev.5 hardware has PA5 (ADC1_IN5) on breakout pad on bottom of board // OLIMEXINO - The PA5 pin is wired up to LED1, if you need to use an mma8452 on an Olimexino use a different pin and provide support in code. - IOInit(IOGetByTag(IO_TAG(PA5)), OWNER_SYSTEM, RESOURCE_I2C); + IOInit(IOGetByTag(IO_TAG(PA5)), OWNER_MPU, RESOURCE_EXTI, 0); IOConfigGPIO(IOGetByTag(IO_TAG(PA5)), IOCFG_IN_FLOATING); // TODO - maybe pullup / pulldown ? #endif diff --git a/src/main/drivers/accgyro_mpu.c b/src/main/drivers/accgyro_mpu.c index b52a2fb79..25b31506c 100644 --- a/src/main/drivers/accgyro_mpu.c +++ b/src/main/drivers/accgyro_mpu.c @@ -244,7 +244,7 @@ void mpuIntExtiInit(void) } #endif - IOInit(mpuIntIO, OWNER_SYSTEM, RESOURCE_INPUT | RESOURCE_EXTI); + IOInit(mpuIntIO, OWNER_MPU, RESOURCE_EXTI, 1); IOConfigGPIO(mpuIntIO, IOCFG_IN_FLOATING); // TODO - maybe pullup / pulldown ? EXTIHandlerInit(&mpuIntCallbackRec, mpuIntExtiHandler); diff --git a/src/main/drivers/accgyro_spi_mpu6000.c b/src/main/drivers/accgyro_spi_mpu6000.c index cb78ffe10..b8c136025 100644 --- a/src/main/drivers/accgyro_spi_mpu6000.c +++ b/src/main/drivers/accgyro_spi_mpu6000.c @@ -159,7 +159,7 @@ bool mpu6000SpiDetect(void) #ifdef MPU6000_CS_PIN mpuSpi6000CsPin = IOGetByTag(IO_TAG(MPU6000_CS_PIN)); #endif - IOInit(mpuSpi6000CsPin, OWNER_SYSTEM, RESOURCE_SPI); + IOInit(mpuSpi6000CsPin, OWNER_MPU, RESOURCE_SPI_CS, 0); IOConfigGPIO(mpuSpi6000CsPin, SPI_IO_CS_CFG); spiSetDivisor(MPU6000_SPI_INSTANCE, SPI_CLOCK_INITIALIZATON); diff --git a/src/main/drivers/accgyro_spi_mpu6500.c b/src/main/drivers/accgyro_spi_mpu6500.c index 273179725..32ae6a1ce 100755 --- a/src/main/drivers/accgyro_spi_mpu6500.c +++ b/src/main/drivers/accgyro_spi_mpu6500.c @@ -69,7 +69,7 @@ static void mpu6500SpiInit(void) } mpuSpi6500CsPin = IOGetByTag(IO_TAG(MPU6500_CS_PIN)); - IOInit(mpuSpi6500CsPin, OWNER_SYSTEM, RESOURCE_SPI); + IOInit(mpuSpi6500CsPin, OWNER_MPU, RESOURCE_SPI_CS, 0); IOConfigGPIO(mpuSpi6500CsPin, SPI_IO_CS_CFG); spiSetDivisor(MPU6500_SPI_INSTANCE, SPI_CLOCK_FAST); diff --git a/src/main/drivers/accgyro_spi_mpu9250.c b/src/main/drivers/accgyro_spi_mpu9250.c index 95c0b3f50..3e4d1635c 100644 --- a/src/main/drivers/accgyro_spi_mpu9250.c +++ b/src/main/drivers/accgyro_spi_mpu9250.c @@ -191,7 +191,7 @@ bool mpu9250SpiDetect(void) #ifdef MPU9250_CS_PIN mpuSpi9250CsPin = IOGetByTag(IO_TAG(MPU9250_CS_PIN)); #endif - IOInit(mpuSpi9250CsPin, OWNER_SYSTEM, RESOURCE_SPI); + IOInit(mpuSpi9250CsPin, OWNER_MPU, RESOURCE_SPI_CS, 0); IOConfigGPIO(mpuSpi9250CsPin, SPI_IO_CS_CFG); spiSetDivisor(MPU9250_SPI_INSTANCE, SPI_CLOCK_INITIALIZATON); //low speed diff --git a/src/main/drivers/adc_stm32f10x.c b/src/main/drivers/adc_stm32f10x.c index 9d9474246..dc0598988 100644 --- a/src/main/drivers/adc_stm32f10x.c +++ b/src/main/drivers/adc_stm32f10x.c @@ -123,7 +123,7 @@ void adcInit(drv_adc_config_t *init) if (!adcConfig[i].tag) continue; - IOInit(IOGetByTag(adcConfig[i].tag), OWNER_SYSTEM, RESOURCE_ADC); + IOInit(IOGetByTag(adcConfig[i].tag), OWNER_ADC, RESOURCE_ADC_BATTERY+i, 0); IOConfigGPIO(IOGetByTag(adcConfig[i].tag), IO_CONFIG(GPIO_Mode_AIN, 0)); adcConfig[i].adcChannel = adcChannelByTag(adcConfig[i].tag); adcConfig[i].dmaIndex = configuredAdcChannels++; diff --git a/src/main/drivers/adc_stm32f30x.c b/src/main/drivers/adc_stm32f30x.c index 0116a6734..c9ae8dc47 100644 --- a/src/main/drivers/adc_stm32f30x.c +++ b/src/main/drivers/adc_stm32f30x.c @@ -139,7 +139,7 @@ void adcInit(drv_adc_config_t *init) if (!adcConfig[i].tag) continue; - IOInit(IOGetByTag(adcConfig[i].tag), OWNER_SYSTEM, RESOURCE_ADC); + IOInit(IOGetByTag(adcConfig[i].tag), OWNER_ADC, RESOURCE_ADC_BATTERY+i,0); IOConfigGPIO(IOGetByTag(adcConfig[i].tag), IO_CONFIG(GPIO_Mode_AN, 0, GPIO_OType_OD, GPIO_PuPd_NOPULL)); adcConfig[i].adcChannel = adcChannelByTag(adcConfig[i].tag); adcConfig[i].dmaIndex = adcChannelCount++; diff --git a/src/main/drivers/adc_stm32f4xx.c b/src/main/drivers/adc_stm32f4xx.c index e0b36a5f3..4466f3443 100644 --- a/src/main/drivers/adc_stm32f4xx.c +++ b/src/main/drivers/adc_stm32f4xx.c @@ -134,7 +134,7 @@ void adcInit(drv_adc_config_t *init) if (!adcConfig[i].tag) continue; - IOInit(IOGetByTag(adcConfig[i].tag), OWNER_SYSTEM, RESOURCE_ADC); + IOInit(IOGetByTag(adcConfig[i].tag), OWNER_ADC, RESOURCE_ADC_BATTERY + i, 0); IOConfigGPIO(IOGetByTag(adcConfig[i].tag), IO_CONFIG(GPIO_Mode_AN, 0, GPIO_OType_OD, GPIO_PuPd_NOPULL)); adcConfig[i].adcChannel = adcChannelByTag(adcConfig[i].tag); adcConfig[i].dmaIndex = configuredAdcChannels++; diff --git a/src/main/drivers/barometer_bmp085.c b/src/main/drivers/barometer_bmp085.c index 34a01cd38..ad4c547bf 100644 --- a/src/main/drivers/barometer_bmp085.c +++ b/src/main/drivers/barometer_bmp085.c @@ -143,7 +143,7 @@ void bmp085InitXclrIO(const bmp085Config_t *config) { if (!xclrIO && config && config->xclrIO) { xclrIO = IOGetByTag(config->xclrIO); - IOInit(xclrIO, OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(xclrIO, OWNER_BARO, RESOURCE_OUTPUT, 0); IOConfigGPIO(xclrIO, IOCFG_OUT_PP); } } diff --git a/src/main/drivers/barometer_spi_bmp280.c b/src/main/drivers/barometer_spi_bmp280.c index 3838ba432..d7a749195 100644 --- a/src/main/drivers/barometer_spi_bmp280.c +++ b/src/main/drivers/barometer_spi_bmp280.c @@ -65,7 +65,7 @@ void bmp280SpiInit(void) } bmp280CsPin = IOGetByTag(IO_TAG(BMP280_CS_PIN)); - IOInit(bmp280CsPin, OWNER_BARO, RESOURCE_SPI); + IOInit(bmp280CsPin, OWNER_BARO, RESOURCE_SPI_CS, 0); IOConfigGPIO(bmp280CsPin, IOCFG_OUT_PP); DISABLE_BMP280; diff --git a/src/main/drivers/bus_i2c_stm32f10x.c b/src/main/drivers/bus_i2c_stm32f10x.c index 72cf8769c..14049461a 100644 --- a/src/main/drivers/bus_i2c_stm32f10x.c +++ b/src/main/drivers/bus_i2c_stm32f10x.c @@ -385,8 +385,8 @@ void i2cInit(I2CDevice device) IO_t scl = IOGetByTag(i2c->scl); IO_t sda = IOGetByTag(i2c->sda); - IOInit(scl, OWNER_SYSTEM, RESOURCE_I2C); - IOInit(sda, OWNER_SYSTEM, RESOURCE_I2C); + IOInit(scl, OWNER_I2C, RESOURCE_I2C_SCL, RESOURCE_INDEX(device)); + IOInit(sda, OWNER_I2C, RESOURCE_I2C_SDA, RESOURCE_INDEX(device)); // Enable RCC RCC_ClockCmd(i2c->rcc, ENABLE); diff --git a/src/main/drivers/bus_i2c_stm32f30x.c b/src/main/drivers/bus_i2c_stm32f30x.c index 11704a3f9..39cdb3b23 100644 --- a/src/main/drivers/bus_i2c_stm32f30x.c +++ b/src/main/drivers/bus_i2c_stm32f30x.c @@ -92,7 +92,10 @@ void i2cInit(I2CDevice device) RCC_ClockCmd(i2c->rcc, ENABLE); RCC_I2CCLKConfig(I2Cx == I2C2 ? RCC_I2C2CLK_SYSCLK : RCC_I2C1CLK_SYSCLK); + IOInit(scl, OWNER_I2C, RESOURCE_I2C_SCL, RESOURCE_INDEX(device)); IOConfigGPIOAF(scl, IOCFG_I2C, GPIO_AF_4); + + IOInit(sda, OWNER_I2C, RESOURCE_I2C_SDA, RESOURCE_INDEX(device)); IOConfigGPIOAF(sda, IOCFG_I2C, GPIO_AF_4); I2C_InitTypeDef i2cInit = { diff --git a/src/main/drivers/bus_spi.c b/src/main/drivers/bus_spi.c index 90224cefc..b3b3f992b 100644 --- a/src/main/drivers/bus_spi.c +++ b/src/main/drivers/bus_spi.c @@ -113,19 +113,13 @@ void spiInitDevice(SPIDevice device) RCC_ClockCmd(spi->rcc, ENABLE); RCC_ResetCmd(spi->rcc, ENABLE); - IOInit(IOGetByTag(spi->sck), OWNER_SYSTEM, RESOURCE_SPI); - IOInit(IOGetByTag(spi->miso), OWNER_SYSTEM, RESOURCE_SPI); - IOInit(IOGetByTag(spi->mosi), OWNER_SYSTEM, RESOURCE_SPI); + IOInit(IOGetByTag(spi->sck), OWNER_SPI, RESOURCE_SPI_SCK, device + 1); + IOInit(IOGetByTag(spi->miso), OWNER_SPI, RESOURCE_SPI_MISO, device + 1); + IOInit(IOGetByTag(spi->mosi), OWNER_SPI, RESOURCE_SPI_MOSI, device + 1); -#if defined(STM32F303xC) || defined(STM32F4) - if (spi->sdcard) { - IOConfigGPIOAF(IOGetByTag(spi->sck), SPI_IO_AF_SCK_CFG, spi->af); - IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_MISO_CFG, spi->af); - } - else { - IOConfigGPIOAF(IOGetByTag(spi->sck), SPI_IO_AF_CFG, spi->af); - IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_CFG, spi->af); - } +#if defined(STM32F3) || defined(STM32F4) + IOConfigGPIOAF(IOGetByTag(spi->sck), SPI_IO_AF_CFG, spi->af); + IOConfigGPIOAF(IOGetByTag(spi->miso), SPI_IO_AF_CFG, spi->af); IOConfigGPIOAF(IOGetByTag(spi->mosi), SPI_IO_AF_CFG, spi->af); if (spi->nss) diff --git a/src/main/drivers/flash_m25p16.c b/src/main/drivers/flash_m25p16.c index 1063debae..f4111e825 100644 --- a/src/main/drivers/flash_m25p16.c +++ b/src/main/drivers/flash_m25p16.c @@ -203,7 +203,7 @@ bool m25p16_init() #ifdef M25P16_CS_PIN m25p16CsPin = IOGetByTag(IO_TAG(M25P16_CS_PIN)); #endif - IOInit(m25p16CsPin, OWNER_FLASH, RESOURCE_SPI); + IOInit(m25p16CsPin, OWNER_FLASH, RESOURCE_SPI_CS, 0); IOConfigGPIO(m25p16CsPin, SPI_IO_CS_CFG); DISABLE_M25P16; diff --git a/src/main/drivers/inverter.c b/src/main/drivers/inverter.c index e0231ddb7..0b31d5d8e 100644 --- a/src/main/drivers/inverter.c +++ b/src/main/drivers/inverter.c @@ -31,7 +31,7 @@ static const IO_t pin = DEFIO_IO(INVERTER); void initInverter(void) { - IOInit(pin, OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(pin, OWNER_INVERTER, RESOURCE_OUTPUT, 0); IOConfigGPIO(pin, IOCFG_OUT_PP); inverterSet(false); diff --git a/src/main/drivers/io.c b/src/main/drivers/io.c index 11562cfc9..bdfd137f6 100644 --- a/src/main/drivers/io.c +++ b/src/main/drivers/io.c @@ -53,6 +53,19 @@ const struct ioPortDef_s ioPortDefs[] = { }; # endif +const char * const ownerNames[OWNER_TOTAL_COUNT] = { + "FREE", "PWM", "PPM", "MOTOR", "SERVO", "SOFTSERIAL", "ADC", "SERIAL", "DEBUG", "TIMER", + "SONAR", "SYSTEM", "SPI", "I2C", "SDCARD", "FLASH", "USB", "BEEPER", "OSD", + "BARO", "MPU", "INVERTER", "LED STRIP", "LED", "RECEIVER", +}; + +const char * const resourceNames[RESOURCE_TOTAL_COUNT] = { + "", // NONE + "IN", "OUT", "IN / OUT", "TIMER","UART TX","UART RX","UART TX/RX","EXTI","SCL", + "SDA", "SCK","MOSI","MISO","CS","BATTERY","RSSI","EXT","CURRENT" +}; + + ioRec_t* IO_Rec(IO_t io) { return io; @@ -190,12 +203,12 @@ void IOToggle(IO_t io) } // claim IO pin, set owner and resources -void IOInit(IO_t io, resourceOwner_t owner, resourceType_t resources) +void IOInit(IO_t io, resourceOwner_t owner, resourceType_t resource, uint8_t index) { ioRec_t *ioRec = IO_Rec(io); - if (owner != OWNER_FREE) // pass OWNER_FREE to keep old owner - ioRec->owner = owner; - ioRec->resourcesUsed |= resources; + ioRec->owner = owner; + ioRec->resource = resource; + ioRec->index = index; } void IORelease(IO_t io) @@ -210,10 +223,10 @@ resourceOwner_t IOGetOwner(IO_t io) return ioRec->owner; } -resourceType_t IOGetResources(IO_t io) +resourceType_t IOGetResource(IO_t io) { ioRec_t *ioRec = IO_Rec(io); - return ioRec->resourcesUsed; + return ioRec->resource; } #if defined(STM32F1) diff --git a/src/main/drivers/io.h b/src/main/drivers/io.h index 315560e43..07c53a203 100644 --- a/src/main/drivers/io.h +++ b/src/main/drivers/io.h @@ -86,7 +86,7 @@ void IOHi(IO_t io); void IOLo(IO_t io); void IOToggle(IO_t io); -void IOInit(IO_t io, resourceOwner_t owner, resourceType_t resources); +void IOInit(IO_t io, resourceOwner_t owner, resourceType_t resource, uint8_t index); void IORelease(IO_t io); // unimplemented resourceOwner_t IOGetOwner(IO_t io); resourceType_t IOGetResources(IO_t io); diff --git a/src/main/drivers/io_impl.h b/src/main/drivers/io_impl.h index 3a084949f..bed28dab3 100644 --- a/src/main/drivers/io_impl.h +++ b/src/main/drivers/io_impl.h @@ -12,7 +12,8 @@ typedef struct ioRec_s { GPIO_TypeDef *gpio; uint16_t pin; resourceOwner_t owner; - resourceType_t resourcesUsed; // TODO! + resourceType_t resource; + uint8_t index; } ioRec_t; extern ioRec_t ioRecs[DEFIO_IO_USED_COUNT]; diff --git a/src/main/drivers/light_led.c b/src/main/drivers/light_led.c index 15075580b..80582c1fa 100644 --- a/src/main/drivers/light_led.c +++ b/src/main/drivers/light_led.c @@ -97,7 +97,7 @@ void ledInit(bool alternative_led) for (i = 0; i < LED_NUMBER; i++) { if (leds[i + ledOffset]) { - IOInit(leds[i + ledOffset], OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(leds[i + ledOffset], OWNER_LED, RESOURCE_OUTPUT, RESOURCE_INDEX(i)); IOConfigGPIO(leds[i + ledOffset], IOCFG_OUT_PP); } } diff --git a/src/main/drivers/light_ws2811strip_stm32f10x.c b/src/main/drivers/light_ws2811strip_stm32f10x.c index 40003663d..863dd24ea 100644 --- a/src/main/drivers/light_ws2811strip_stm32f10x.c +++ b/src/main/drivers/light_ws2811strip_stm32f10x.c @@ -53,7 +53,7 @@ void ws2811LedStripHardwareInit(void) ws2811IO = IOGetByTag(IO_TAG(WS2811_PIN)); /* GPIOA Configuration: TIM5 Channel 1 as alternate function push-pull */ - IOInit(ws2811IO, OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(ws2811IO, OWNER_LED_STRIP, RESOURCE_OUTPUT, 0); IOConfigGPIO(ws2811IO, IO_CONFIG(GPIO_Speed_50MHz, GPIO_Mode_AF_PP)); RCC_ClockCmd(timerRCC(WS2811_TIMER), ENABLE); diff --git a/src/main/drivers/light_ws2811strip_stm32f30x.c b/src/main/drivers/light_ws2811strip_stm32f30x.c index 567fd0b8e..b27e30e51 100644 --- a/src/main/drivers/light_ws2811strip_stm32f30x.c +++ b/src/main/drivers/light_ws2811strip_stm32f30x.c @@ -64,7 +64,7 @@ void ws2811LedStripHardwareInit(void) ws2811IO = IOGetByTag(IO_TAG(WS2811_PIN)); /* GPIOA Configuration: TIM5 Channel 1 as alternate function push-pull */ - IOInit(ws2811IO, OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(ws2811IO, OWNER_LED_STRIP, RESOURCE_OUTPUT, 0); IOConfigGPIOAF(ws2811IO, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_UP), timerGPIOAF(WS2811_TIMER)); RCC_ClockCmd(timerRCC(WS2811_TIMER), ENABLE); diff --git a/src/main/drivers/light_ws2811strip_stm32f4xx.c b/src/main/drivers/light_ws2811strip_stm32f4xx.c index f1d04dfbe..cfde3411c 100644 --- a/src/main/drivers/light_ws2811strip_stm32f4xx.c +++ b/src/main/drivers/light_ws2811strip_stm32f4xx.c @@ -69,7 +69,7 @@ void ws2811LedStripHardwareInit(void) ws2811IO = IOGetByTag(IO_TAG(WS2811_PIN)); /* GPIOA Configuration: TIM5 Channel 1 as alternate function push-pull */ - IOInit(ws2811IO, OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(ws2811IO, OWNER_LED_STRIP, RESOURCE_OUTPUT, 0); IOConfigGPIOAF(ws2811IO, IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_UP), timerGPIOAF(WS2811_TIMER)); // Stop timer diff --git a/src/main/drivers/max7456.c b/src/main/drivers/max7456.c index d3efe7e7d..d71a933a5 100644 --- a/src/main/drivers/max7456.c +++ b/src/main/drivers/max7456.c @@ -49,7 +49,8 @@ static uint8_t video_signal_type = 0; static uint8_t max7456_lock = 0; static IO_t max7456CsPin = IO_NONE; -uint8_t max7456_send(uint8_t add, uint8_t data) { +uint8_t max7456_send(uint8_t add, uint8_t data) +{ spiTransferByte(MAX7456_SPI_INSTANCE, add); return spiTransferByte(MAX7456_SPI_INSTANCE, data); } @@ -64,7 +65,7 @@ void max7456_init(uint8_t video_system) #ifdef MAX7456_SPI_CS_PIN max7456CsPin = IOGetByTag(IO_TAG(MAX7456_SPI_CS_PIN)); #endif - IOInit(max7456CsPin, OWNER_SYSTEM, RESOURCE_SPI); + IOInit(max7456CsPin, OWNER_OSD, RESOURCE_SPI_CS, 0); IOConfigGPIO(max7456CsPin, SPI_IO_CS_CFG); //Minimum spi clock period for max7456 is 100ns (10Mhz) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 277b47736..f9feb1a46 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -84,18 +84,15 @@ static void pwmOCConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t value, uint8 } } -static void pwmGPIOConfig(ioTag_t pin, ioConfig_t mode) -{ - IOInit(IOGetByTag(pin), OWNER_PWMOUTPUT_MOTOR, RESOURCE_OUTPUT); - IOConfigGPIO(IOGetByTag(pin), mode); -} - static pwmOutputPort_t *pwmOutConfig(const timerHardware_t *timerHardware, uint8_t mhz, uint16_t period, uint16_t value) { pwmOutputPort_t *p = &pwmOutputPorts[allocatedOutputPortCount++]; configTimeBase(timerHardware->tim, period, mhz); - pwmGPIOConfig(timerHardware->tag, IOCFG_AF_PP); + + IO_t io = IOGetByTag(timerHardware->tag); + IOInit(io, OWNER_MOTOR, RESOURCE_OUTPUT, allocatedOutputPortCount); + IOConfigGPIO(io, IOCFG_AF_PP); pwmOCConfig(timerHardware->tim, timerHardware->channel, value, timerHardware->output & TIMER_OUTPUT_INVERTED); diff --git a/src/main/drivers/pwm_rx.c b/src/main/drivers/pwm_rx.c index 856613d2b..7250c6e79 100644 --- a/src/main/drivers/pwm_rx.c +++ b/src/main/drivers/pwm_rx.c @@ -337,12 +337,6 @@ static void pwmEdgeCallback(timerCCHandlerRec_t *cbRec, captureCompare_t capture } } -static void pwmGPIOConfig(ioTag_t pin, ioConfig_t mode) -{ - IOInit(IOGetByTag(pin), OWNER_PWMINPUT, RESOURCE_INPUT); - IOConfigGPIO(IOGetByTag(pin), mode); -} - void pwmICConfig(TIM_TypeDef *tim, uint8_t channel, uint16_t polarity) { TIM_ICInitTypeDef TIM_ICInitStructure; @@ -372,7 +366,10 @@ void pwmInConfig(const timerHardware_t *timerHardwarePtr, uint8_t channel) self->mode = INPUT_MODE_PWM; self->timerHardware = timerHardwarePtr; - pwmGPIOConfig(timerHardwarePtr->tag, timerHardwarePtr->ioMode); + IO_t io = IOGetByTag(timerHardwarePtr->tag); + IOInit(io, OWNER_PWMINPUT, RESOURCE_INPUT, RESOURCE_INDEX(channel)); + IOConfigGPIO(io, timerHardwarePtr->ioMode); + pwmICConfig(timerHardwarePtr->tim, timerHardwarePtr->channel, TIM_ICPolarity_Rising); timerConfigure(timerHardwarePtr, (uint16_t)PWM_TIMER_PERIOD, PWM_TIMER_MHZ); @@ -401,7 +398,10 @@ void ppmInConfig(const timerHardware_t *timerHardwarePtr) self->mode = INPUT_MODE_PPM; self->timerHardware = timerHardwarePtr; - pwmGPIOConfig(timerHardwarePtr->tag, timerHardwarePtr->ioMode); + IO_t io = IOGetByTag(timerHardwarePtr->tag); + IOInit(io, OWNER_PPMINPUT, RESOURCE_INPUT, 0); + IOConfigGPIO(io, timerHardwarePtr->ioMode); + pwmICConfig(timerHardwarePtr->tim, timerHardwarePtr->channel, TIM_ICPolarity_Rising); timerConfigure(timerHardwarePtr, (uint16_t)PPM_TIMER_PERIOD, PWM_TIMER_MHZ); diff --git a/src/main/drivers/resource.h b/src/main/drivers/resource.h index a81739bf1..5991f369b 100644 --- a/src/main/drivers/resource.h +++ b/src/main/drivers/resource.h @@ -1,46 +1,51 @@ #pragma once +#define RESOURCE_INDEX(x) x + 1 + typedef enum { OWNER_FREE = 0, OWNER_PWMINPUT, OWNER_PPMINPUT, - OWNER_PWMOUTPUT_MOTOR, - OWNER_PWMOUTPUT_SERVO, - OWNER_SOFTSERIAL_RX, - OWNER_SOFTSERIAL_TX, - OWNER_SOFTSERIAL_RXTX, // bidirectional pin for softserial - OWNER_SOFTSERIAL_AUXTIMER, // timer channel is used for softserial. No IO function on pin + OWNER_MOTOR, + OWNER_SERVO, + OWNER_SOFTSERIAL, OWNER_ADC, - OWNER_SERIAL_RX, - OWNER_SERIAL_TX, - OWNER_SERIAL_RXTX, + OWNER_SERIAL, OWNER_PINDEBUG, OWNER_TIMER, OWNER_SONAR, OWNER_SYSTEM, + OWNER_SPI, + OWNER_I2C, OWNER_SDCARD, OWNER_FLASH, OWNER_USB, OWNER_BEEPER, OWNER_OSD, OWNER_BARO, + OWNER_MPU, + OWNER_INVERTER, + OWNER_LED_STRIP, + OWNER_LED, + OWNER_RX, OWNER_TOTAL_COUNT } resourceOwner_t; +extern const char * const ownerNames[OWNER_TOTAL_COUNT]; + // Currently TIMER should be shared resource (softserial dualtimer and timerqueue needs to allocate timer channel, but pin can be used for other function) // with mode switching (shared serial ports, ...) this will need some improvement typedef enum { RESOURCE_NONE = 0, - RESOURCE_INPUT = 1 << 0, - RESOURCE_OUTPUT = 1 << 1, - RESOURCE_IO = RESOURCE_INPUT | RESOURCE_OUTPUT, - RESOURCE_TIMER = 1 << 2, - RESOURCE_TIMER_DUAL = 1 << 3, // channel used in dual-capture, other channel will be allocated too - RESOURCE_USART = 1 << 4, - RESOURCE_ADC = 1 << 5, - RESOURCE_EXTI = 1 << 6, - RESOURCE_I2C = 1 << 7, - RESOURCE_SPI = 1 << 8, + RESOURCE_INPUT, RESOURCE_OUTPUT, RESOURCE_IO, + RESOURCE_TIMER, + RESOURCE_UART_TX, RESOURCE_UART_RX, RESOURCE_UART_TXRX, + RESOURCE_EXTI, + RESOURCE_I2C_SCL, RESOURCE_I2C_SDA, + RESOURCE_SPI_SCK, RESOURCE_SPI_MOSI, RESOURCE_SPI_MISO, RESOURCE_SPI_CS, + RESOURCE_ADC_BATTERY, RESOURCE_ADC_RSSI, RESOURCE_ADC_EXTERNAL1, RESOURCE_ADC_CURRENT, + RESOURCE_TOTAL_COUNT } resourceType_t; +extern const char * const resourceNames[RESOURCE_TOTAL_COUNT]; diff --git a/src/main/drivers/sdcard.c b/src/main/drivers/sdcard.c index d5ac385e4..852c4adcf 100644 --- a/src/main/drivers/sdcard.c +++ b/src/main/drivers/sdcard.c @@ -126,7 +126,7 @@ void sdcardInsertionDetectDeinit(void) { #ifdef SDCARD_DETECT_PIN sdCardDetectPin = IOGetByTag(IO_TAG(SDCARD_DETECT_PIN)); - IOInit(sdCardDetectPin, OWNER_SYSTEM, RESOURCE_SPI); + IOInit(sdCardDetectPin, OWNER_FREE, RESOURCE_NONE, 0); IOConfigGPIO(sdCardDetectPin, IOCFG_IN_FLOATING); #endif } @@ -135,7 +135,7 @@ void sdcardInsertionDetectInit(void) { #ifdef SDCARD_DETECT_PIN sdCardDetectPin = IOGetByTag(IO_TAG(SDCARD_DETECT_PIN)); - IOInit(sdCardDetectPin, OWNER_SDCARD, RESOURCE_INPUT); + IOInit(sdCardDetectPin, OWNER_SDCARD, RESOURCE_INPUT, 0); IOConfigGPIO(sdCardDetectPin, IOCFG_IPU); #endif } @@ -547,7 +547,7 @@ void sdcard_init(bool useDMA) #ifdef SDCARD_SPI_CS_PIN sdCardCsPin = IOGetByTag(IO_TAG(SDCARD_SPI_CS_PIN)); - IOInit(sdCardCsPin, OWNER_SDCARD, RESOURCE_SPI); + IOInit(sdCardCsPin, OWNER_SDCARD, RESOURCE_SPI_CS, 0); IOConfigGPIO(sdCardCsPin, SPI_IO_CS_CFG); #endif // SDCARD_SPI_CS_PIN diff --git a/src/main/drivers/serial_softserial.c b/src/main/drivers/serial_softserial.c index da2c03268..082fddf9c 100644 --- a/src/main/drivers/serial_softserial.c +++ b/src/main/drivers/serial_softserial.c @@ -100,21 +100,22 @@ void setTxSignal(softSerial_t *softSerial, uint8_t state) } } -static void softSerialGPIOConfig(ioTag_t pin, ioConfig_t mode) -{ - IOInit(IOGetByTag(pin), OWNER_SOFTSERIAL_RXTX, RESOURCE_USART); - IOConfigGPIO(IOGetByTag(pin), mode); -} - -void serialInputPortConfig(ioTag_t pin) +void serialInputPortConfig(ioTag_t pin, uint8_t portIndex) { + IOInit(IOGetByTag(pin), OWNER_SOFTSERIAL, RESOURCE_UART_RX, RESOURCE_INDEX(portIndex)); #ifdef STM32F1 - softSerialGPIOConfig(pin, IOCFG_IPU); + IOConfigGPIO(IOGetByTag(pin), IOCFG_IPU); #else - softSerialGPIOConfig(pin, IOCFG_AF_PP_UP); + IOConfigGPIO(IOGetByTag(pin), IOCFG_AF_PP_UP); #endif } +static void serialOutputPortConfig(ioTag_t pin, uint8_t portIndex) +{ + IOInit(IOGetByTag(pin), OWNER_SOFTSERIAL, RESOURCE_UART_TX, RESOURCE_INDEX(portIndex)); + IOConfigGPIO(IOGetByTag(pin), IOCFG_OUT_PP); +} + static bool isTimerPeriodTooLarge(uint32_t timerPeriod) { return timerPeriod > 0xFFFF; @@ -164,11 +165,6 @@ static void serialTimerRxConfig(const timerHardware_t *timerHardwarePtr, uint8_t timerChConfigCallbacks(timerHardwarePtr, &softSerialPorts[reference].edgeCb, NULL); } -static void serialOutputPortConfig(ioTag_t pin) -{ - softSerialGPIOConfig(pin, IOCFG_OUT_PP); -} - static void resetBuffers(softSerial_t *softSerial) { softSerial->port.rxBufferSize = SOFTSERIAL_BUFFER_SIZE; @@ -219,10 +215,10 @@ serialPort_t *openSoftSerial(softSerialPortIndex_e portIndex, serialReceiveCallb softSerial->softSerialPortIndex = portIndex; softSerial->txIO = IOGetByTag(softSerial->txTimerHardware->tag); - serialOutputPortConfig(softSerial->txTimerHardware->tag); + serialOutputPortConfig(softSerial->txTimerHardware->tag, portIndex); softSerial->rxIO = IOGetByTag(softSerial->rxTimerHardware->tag); - serialInputPortConfig(softSerial->rxTimerHardware->tag); + serialInputPortConfig(softSerial->rxTimerHardware->tag, portIndex); setTxSignal(softSerial, ENABLE); delay(50); @@ -271,8 +267,6 @@ void processTxState(softSerial_t *softSerial) softSerial->isTransmittingData = false; } - - enum { TRAILING, LEADING diff --git a/src/main/drivers/serial_uart_stm32f10x.c b/src/main/drivers/serial_uart_stm32f10x.c index f804b7dea..8e73277fc 100644 --- a/src/main/drivers/serial_uart_stm32f10x.c +++ b/src/main/drivers/serial_uart_stm32f10x.c @@ -112,16 +112,16 @@ uartPort_t *serialUART1(uint32_t baudRate, portMode_t mode, portOptions_t option // UART1_TX PA9 // UART1_RX PA10 if (options & SERIAL_BIDIR) { - IOInit(IOGetByTag(IO_TAG(PA9)), OWNER_SERIAL_RXTX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(PA9)), OWNER_SERIAL, RESOURCE_UART_TXRX, 1); IOConfigGPIO(IOGetByTag(IO_TAG(PA9)), IOCFG_AF_OD); } else { if (mode & MODE_TX) { - IOInit(IOGetByTag(IO_TAG(PA9)), OWNER_SERIAL_TX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(PA9)), OWNER_SERIAL, RESOURCE_UART_TX, 1); IOConfigGPIO(IOGetByTag(IO_TAG(PA9)), IOCFG_AF_PP); } if (mode & MODE_RX) { - IOInit(IOGetByTag(IO_TAG(PA10)), OWNER_SERIAL_RX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(PA10)), OWNER_SERIAL, RESOURCE_UART_RX, 1); IOConfigGPIO(IOGetByTag(IO_TAG(PA10)), IOCFG_IPU); } } @@ -198,16 +198,16 @@ uartPort_t *serialUART2(uint32_t baudRate, portMode_t mode, portOptions_t option // UART2_TX PA2 // UART2_RX PA3 if (options & SERIAL_BIDIR) { - IOInit(IOGetByTag(IO_TAG(PA2)), OWNER_SERIAL_RXTX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(PA2)), OWNER_SERIAL, RESOURCE_UART_TXRX, 2); IOConfigGPIO(IOGetByTag(IO_TAG(PA2)), IOCFG_AF_OD); } else { if (mode & MODE_TX) { - IOInit(IOGetByTag(IO_TAG(PA2)), OWNER_SERIAL_TX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(PA2)), OWNER_SERIAL, RESOURCE_UART_TX, 2); IOConfigGPIO(IOGetByTag(IO_TAG(PA2)), IOCFG_AF_PP); } if (mode & MODE_RX) { - IOInit(IOGetByTag(IO_TAG(PA3)), OWNER_SERIAL_RX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(PA3)), OWNER_SERIAL, RESOURCE_UART_RX, 2); IOConfigGPIO(IOGetByTag(IO_TAG(PA3)), IOCFG_IPU); } } @@ -260,16 +260,16 @@ uartPort_t *serialUART3(uint32_t baudRate, portMode_t mode, portOptions_t option RCC_ClockCmd(RCC_APB1(USART3), ENABLE); if (options & SERIAL_BIDIR) { - IOInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), OWNER_SERIAL_RXTX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), OWNER_SERIAL, RESOURCE_UART_TXRX, 3); IOConfigGPIO(IOGetByTag(IO_TAG(UART3_TX_PIN)), IOCFG_AF_OD); } else { if (mode & MODE_TX) { - IOInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), OWNER_SERIAL_TX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), OWNER_SERIAL, RESOURCE_UART_TX, 3); IOConfigGPIO(IOGetByTag(IO_TAG(UART3_TX_PIN)), IOCFG_AF_PP); } if (mode & MODE_RX) { - IOInit(IOGetByTag(IO_TAG(UART3_RX_PIN)), OWNER_SERIAL_RX, RESOURCE_USART); + IOInit(IOGetByTag(IO_TAG(UART3_RX_PIN)), OWNER_SERIAL, RESOURCE_UART_RX, 3); IOConfigGPIO(IOGetByTag(IO_TAG(UART3_RX_PIN)), IOCFG_IPU); } } diff --git a/src/main/drivers/serial_uart_stm32f30x.c b/src/main/drivers/serial_uart_stm32f30x.c index dae0f1655..a7a3f004b 100644 --- a/src/main/drivers/serial_uart_stm32f30x.c +++ b/src/main/drivers/serial_uart_stm32f30x.c @@ -99,7 +99,7 @@ static uartPort_t uartPort4; static uartPort_t uartPort5; #endif -void serialUARTInit(IO_t tx, IO_t rx, portMode_t mode, portOptions_t options, uint8_t af) +void serialUARTInit(IO_t tx, IO_t rx, portMode_t mode, portOptions_t options, uint8_t af, uint8_t index) { if (options & SERIAL_BIDIR) { ioConfig_t ioCfg = IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, @@ -107,7 +107,7 @@ void serialUARTInit(IO_t tx, IO_t rx, portMode_t mode, portOptions_t options, ui (options & SERIAL_INVERTED) ? GPIO_PuPd_DOWN : GPIO_PuPd_UP ); - IOInit(tx, OWNER_SERIAL_RXTX, RESOURCE_USART); + IOInit(tx, OWNER_SERIAL, RESOURCE_UART_TXRX, index); IOConfigGPIOAF(tx, ioCfg, af); if (!(options & SERIAL_INVERTED)) @@ -115,12 +115,12 @@ void serialUARTInit(IO_t tx, IO_t rx, portMode_t mode, portOptions_t options, ui } else { ioConfig_t ioCfg = IO_CONFIG(GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, (options & SERIAL_INVERTED) ? GPIO_PuPd_DOWN : GPIO_PuPd_UP); if (mode & MODE_TX) { - IOInit(tx, OWNER_SERIAL_TX, RESOURCE_USART); + IOInit(tx, OWNER_SERIAL, RESOURCE_UART_TX, index); IOConfigGPIOAF(tx, ioCfg, af); } if (mode & MODE_RX) { - IOInit(tx, OWNER_SERIAL_RX, RESOURCE_USART); + IOInit(tx, OWNER_SERIAL, RESOURCE_UART_TX, index); IOConfigGPIOAF(rx, ioCfg, af); } } @@ -157,7 +157,7 @@ uartPort_t *serialUART1(uint32_t baudRate, portMode_t mode, portOptions_t option RCC_ClockCmd(RCC_APB2(USART1), ENABLE); RCC_ClockCmd(RCC_AHB(DMA1), ENABLE); - serialUARTInit(IOGetByTag(IO_TAG(UART1_TX_PIN)), IOGetByTag(IO_TAG(UART1_RX_PIN)), mode, options, GPIO_AF_7); + serialUARTInit(IOGetByTag(IO_TAG(UART1_TX_PIN)), IOGetByTag(IO_TAG(UART1_RX_PIN)), mode, options, GPIO_AF_7, 1); // DMA TX Interrupt NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn; @@ -213,7 +213,7 @@ uartPort_t *serialUART2(uint32_t baudRate, portMode_t mode, portOptions_t option RCC_ClockCmd(RCC_AHB(DMA1), ENABLE); #endif - serialUARTInit(IOGetByTag(IO_TAG(UART2_TX_PIN)), IOGetByTag(IO_TAG(UART2_RX_PIN)), mode, options, GPIO_AF_7); + serialUARTInit(IOGetByTag(IO_TAG(UART2_TX_PIN)), IOGetByTag(IO_TAG(UART2_RX_PIN)), mode, options, GPIO_AF_7, 2); #ifdef USE_UART2_TX_DMA // DMA TX Interrupt @@ -271,7 +271,7 @@ uartPort_t *serialUART3(uint32_t baudRate, portMode_t mode, portOptions_t option RCC_AHBClockCmd(RCC_AHB(DMA1), ENABLE); #endif - serialUARTInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), IOGetByTag(IO_TAG(UART3_RX_PIN)), mode, options, GPIO_AF_7); + serialUARTInit(IOGetByTag(IO_TAG(UART3_TX_PIN)), IOGetByTag(IO_TAG(UART3_RX_PIN)), mode, options, GPIO_AF_7, 3); #ifdef USE_UART3_TX_DMA // DMA TX Interrupt @@ -316,7 +316,7 @@ uartPort_t *serialUART4(uint32_t baudRate, portMode_t mode, portOptions_t option RCC_ClockCmd(RCC_APB1(UART4), ENABLE); - serialUARTInit(IOGetByTag(IO_TAG(UART4_TX_PIN)), IOGetByTag(IO_TAG(UART4_RX_PIN)), mode, options, GPIO_AF_5); + serialUARTInit(IOGetByTag(IO_TAG(UART4_TX_PIN)), IOGetByTag(IO_TAG(UART4_RX_PIN)), mode, options, GPIO_AF_5, 4); NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART4); @@ -350,7 +350,7 @@ uartPort_t *serialUART5(uint32_t baudRate, portMode_t mode, portOptions_t option RCC_ClockCmd(RCC_APB1(UART5), ENABLE); - serialUARTInit(IOGetByTag(IO_TAG(UART5_TX_PIN)), IOGetByTag(IO_TAG(UART5_RX_PIN)), mode, options, GPIO_AF_5); + serialUARTInit(IOGetByTag(IO_TAG(UART5_TX_PIN)), IOGetByTag(IO_TAG(UART5_RX_PIN)), mode, options, GPIO_AF_5, 5); NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_PRIORITY_BASE(NVIC_PRIO_SERIALUART5); diff --git a/src/main/drivers/serial_uart_stm32f4xx.c b/src/main/drivers/serial_uart_stm32f4xx.c index 9bac1ceee..40f7a919e 100644 --- a/src/main/drivers/serial_uart_stm32f4xx.c +++ b/src/main/drivers/serial_uart_stm32f4xx.c @@ -312,17 +312,17 @@ uartPort_t *serialUART(UARTDevice device, uint32_t baudRate, portMode_t mode, po RCC_AHB1PeriphClockCmd(uart->rcc_ahb1, ENABLE); if (options & SERIAL_BIDIR) { - IOInit(tx, OWNER_SERIAL_TX, RESOURCE_USART); + IOInit(tx, OWNER_SERIAL, RESOURCE_UART_TXRX, RESOURCE_INDEX(device)); IOConfigGPIOAF(tx, IOCFG_AF_OD, uart->af); } else { if (mode & MODE_TX) { - IOInit(tx, OWNER_SERIAL_TX, RESOURCE_USART); + IOInit(tx, OWNER_SERIAL, RESOURCE_UART_TX, RESOURCE_INDEX(device)); IOConfigGPIOAF(tx, IOCFG_AF_PP, uart->af); } if (mode & MODE_RX) { - IOInit(rx, OWNER_SERIAL_RX, RESOURCE_USART); + IOInit(rx, OWNER_SERIAL, RESOURCE_UART_RX, RESOURCE_INDEX(device)); IOConfigGPIOAF(rx, IOCFG_AF_PP, uart->af); } } diff --git a/src/main/drivers/serial_usb_vcp.c b/src/main/drivers/serial_usb_vcp.c index bb74b36b3..f489b16d3 100644 --- a/src/main/drivers/serial_usb_vcp.c +++ b/src/main/drivers/serial_usb_vcp.c @@ -181,8 +181,8 @@ serialPort_t *usbVcpOpen(void) vcpPort_t *s; #ifdef STM32F4 - IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, RESOURCE_IO); - IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, RESOURCE_IO); + IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, RESOURCE_INPUT, 0); + IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, RESOURCE_OUTPUT, 0); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); #else Set_System(); diff --git a/src/main/drivers/sonar_hcsr04.c b/src/main/drivers/sonar_hcsr04.c index 3b8ec91f7..0cf058a8a 100644 --- a/src/main/drivers/sonar_hcsr04.c +++ b/src/main/drivers/sonar_hcsr04.c @@ -83,12 +83,12 @@ void hcsr04_init(sonarRange_t *sonarRange) // trigger pin triggerIO = IOGetByTag(sonarHardwareHCSR04.triggerTag); - IOInit(triggerIO, OWNER_SONAR, RESOURCE_INPUT); + IOInit(triggerIO, OWNER_SONAR, RESOURCE_OUTPUT, 0); IOConfigGPIO(triggerIO, IOCFG_OUT_PP); // echo pin echoIO = IOGetByTag(sonarHardwareHCSR04.echoTag); - IOInit(echoIO, OWNER_SONAR, RESOURCE_INPUT); + IOInit(echoIO, OWNER_SONAR, RESOURCE_INPUT, 0); IOConfigGPIO(echoIO, IOCFG_IN_FLOATING); #ifdef USE_EXTI diff --git a/src/main/drivers/sound_beeper.c b/src/main/drivers/sound_beeper.c index cba9a2a5c..0c60ca4eb 100644 --- a/src/main/drivers/sound_beeper.c +++ b/src/main/drivers/sound_beeper.c @@ -61,7 +61,7 @@ void beeperInit(const beeperConfig_t *config) beeperInverted = config->isInverted; if (beeperIO) { - IOInit(beeperIO, OWNER_BEEPER, RESOURCE_OUTPUT); + IOInit(beeperIO, OWNER_BEEPER, RESOURCE_OUTPUT, 0); IOConfigGPIO(beeperIO, config->isOD ? IOCFG_OUT_OD : IOCFG_OUT_PP); } systemBeep(false); diff --git a/src/main/drivers/timer.c b/src/main/drivers/timer.c index e168a46df..7938b9a5b 100755 --- a/src/main/drivers/timer.c +++ b/src/main/drivers/timer.c @@ -374,7 +374,7 @@ void timerChClearCCFlag(const timerHardware_t *timHw) // configure timer channel GPIO mode void timerChConfigGPIO(const timerHardware_t* timHw, ioConfig_t mode) { - IOInit(IOGetByTag(timHw->tag), OWNER_TIMER, RESOURCE_TIMER); + IOInit(IOGetByTag(timHw->tag), OWNER_TIMER, RESOURCE_TIMER, 0); IOConfigGPIO(IOGetByTag(timHw->tag), mode); } diff --git a/src/main/drivers/usb_io.c b/src/main/drivers/usb_io.c index 51ac90ad4..14a01bcd6 100644 --- a/src/main/drivers/usb_io.c +++ b/src/main/drivers/usb_io.c @@ -36,7 +36,7 @@ static IO_t usbDetectPin = IO_NONE; void usbCableDetectDeinit(void) { #ifdef USB_DETECT_PIN - IOInit(usbDetectPin, OWNER_FREE, RESOURCE_NONE); + IOInit(usbDetectPin, OWNER_FREE, RESOURCE_NONE, 0); IOConfigGPIO(usbDetectPin, IOCFG_IN_FLOATING); usbDetectPin = IO_NONE; #endif @@ -47,7 +47,7 @@ void usbCableDetectInit(void) #ifdef USB_DETECT_PIN usbDetectPin = IOGetByTag(IO_TAG(USB_DETECT_PIN)); - IOInit(usbDetectPin, OWNER_USB, RESOURCE_INPUT); + IOInit(usbDetectPin, OWNER_USB, RESOURCE_INPUT, 0); IOConfigGPIO(usbDetectPin, IOCFG_OUT_PP); #endif } diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index e160869df..0133d359a 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -3074,47 +3074,22 @@ void cliProcess(void) } } -const char * const ownerNames[OWNER_TOTAL_COUNT] = { - "FREE", - "PWM IN", - "PPM IN", - "MOTOR", - "SERVO", - "SOFTSERIAL RX", - "SOFTSERIAL TX", - "SOFTSERIAL RXTX", // bidirectional pin for softserial - "SOFTSERIAL AUXTIMER", // timer channel is used for softserial. No IO function on pin - "ADC", - "SERIAL RX", - "SERIAL TX", - "SERIAL RXTX", - "PINDEBUG", - "TIMER", - "SONAR", - "SYSTEM", - "SDCARD", - "FLASH", - "USB", - "BEEPER", - "OSD", - "BARO", -}; - static void cliResource(char *cmdline) { UNUSED(cmdline); - cliPrintf("IO:\r\n"); + cliPrintf("IO:\r\n----------------------\r\n"); for (unsigned i = 0; i < DEFIO_IO_USED_COUNT; i++) { const char* owner; - char buff[15]; - if (ioRecs[i].owner < ARRAYLEN(ownerNames)) { - owner = ownerNames[ioRecs[i].owner]; - } - else { - sprintf(buff, "O=%d", ioRecs[i].owner); - owner = buff; + owner = ownerNames[ioRecs[i].owner]; + + const char* resource; + resource = resourceNames[ioRecs[i].resource]; + + if (ioRecs[i].index > 0) { + cliPrintf("%c%02d: %s%d %s\r\n", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner, ioRecs[i].index, resource); + } else { + cliPrintf("%c%02d: %s %s\r\n", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner, resource); } - cliPrintf("%c%02d: %19s\r\n", IO_GPIOPortIdx(ioRecs + i) + 'A', IO_GPIOPinIdx(ioRecs + i), owner); } } diff --git a/src/main/rx/spektrum.c b/src/main/rx/spektrum.c index 9c0f21102..ef6a8fa3d 100644 --- a/src/main/rx/spektrum.c +++ b/src/main/rx/spektrum.c @@ -184,7 +184,7 @@ bool spekShouldBind(uint8_t spektrum_sat_bind) { #ifdef HARDWARE_BIND_PLUG BindPlug = IOGetByTag(IO_TAG(BINDPLUG_PIN)); - IOInit(BindPlug, OWNER_SYSTEM, RESOURCE_INPUT); + IOInit(BindPlug, OWNER_RX, RESOURCE_INPUT, 0); IOConfigGPIO(BindPlug, IOCFG_IPU); // Check status of bind plug and exit if not active @@ -216,7 +216,7 @@ void spektrumBind(rxConfig_t *rxConfig) LED1_ON; BindPin = IOGetByTag(IO_TAG(BIND_PIN)); - IOInit(BindPin, OWNER_SYSTEM, RESOURCE_OUTPUT); + IOInit(BindPin, OWNER_RX, RESOURCE_OUTPUT, 0); IOConfigGPIO(BindPin, IOCFG_OUT_PP); // RX line, set high diff --git a/src/main/target/ALIENFLIGHTF3/hardware_revision.c b/src/main/target/ALIENFLIGHTF3/hardware_revision.c index b51d38658..a8f1ebdb7 100644 --- a/src/main/target/ALIENFLIGHTF3/hardware_revision.c +++ b/src/main/target/ALIENFLIGHTF3/hardware_revision.c @@ -40,7 +40,7 @@ static IO_t HWDetectPin = IO_NONE; void detectHardwareRevision(void) { HWDetectPin = IOGetByTag(IO_TAG(HW_PIN)); - IOInit(HWDetectPin, OWNER_SYSTEM, RESOURCE_INPUT); + IOInit(HWDetectPin, OWNER_SYSTEM, RESOURCE_INPUT, 0); IOConfigGPIO(HWDetectPin, IOCFG_IPU); // Check hardware revision diff --git a/src/main/target/BLUEJAYF4/target.h b/src/main/target/BLUEJAYF4/target.h index 4c53e1599..4d3b7a58a 100644 --- a/src/main/target/BLUEJAYF4/target.h +++ b/src/main/target/BLUEJAYF4/target.h @@ -108,7 +108,13 @@ #define UART6_RX_PIN PC7 #define UART6_TX_PIN PC6 -#define SERIAL_PORT_COUNT 4 +#define USE_SOFTSERIAL1 +#define SERIAL_PORT_COUNT 5 + +#define SOFTSERIAL_1_TIMER TIM3 +#define SOFTSERIAL_1_TIMER_RX_HARDWARE 4 // PWM 5 +#define SOFTSERIAL_1_TIMER_TX_HARDWARE 5 // PWM 6 + #define USE_ESCSERIAL #define ESCSERIAL_TIMER_TX_HARDWARE 0 @@ -160,3 +166,4 @@ #define TARGET_IO_PORTD (BIT(2)) #define USED_TIMERS ( TIM_N(2) | TIM_N(3) | TIM_N(5) | TIM_N(8) | TIM_N(9)) + -- 2.11.4.GIT