1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

usart: make CC USART ports compile-time configurable

TODO: This should be dynamic in the future.
But for now define any compatile combination of:
   USE_I2C (shared with USART3)
   USE_TELEMETRY
   USE_GPS
   USE_SPEKTRUM
   USE_SBUS (USART1 only, it needs an invertor)
and optionally define PIOS_PORT_* to USART port numbers

Defaults are:

#define PIOS_PORT_TELEMETRY 1
#define PIOS_PORT_GPS       3
#define PIOS_PORT_SPEKTRUM  3
#define PIOS_PORT_SBUS      1

#define USE_TELEMETRY
#define USE_GPS

Telemetry, GPS and PWM input are enabled by default.
This commit is contained in:
Oleg Semyonov 2011-06-15 22:37:44 +03:00
parent d8201ec45b
commit 50e819192b
2 changed files with 166 additions and 39 deletions

View File

@ -30,11 +30,9 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PIOS_CONFIG_H
#define PIOS_CONFIG_H
/* Enable/Disable PiOS Modules */
#define PIOS_INCLUDE_ADC
#define PIOS_INCLUDE_DELAY
@ -45,17 +43,146 @@
#define PIOS_INCLUDE_IRQ
#define PIOS_INCLUDE_LED
#if defined(USE_SPEKTRUM)
#define PIOS_INCLUDE_SPEKTRUM
#elif defined(USE_SBUS)
#define PIOS_INCLUDE_SBUS
/*
* Serial port configuration.
* TODO: This should be dynamic in the future.
* But for now define any compatile combination of:
* USE_I2C (shared with USART3)
* USE_TELEMETRY
* USE_GPS
* USE_SPEKTRUM
* USE_SBUS (USART1 only, it needs an invertor)
* and optionally define PIOS_PORT_* to USART port numbers
*/
/* Current defaults */
#define USE_TELEMETRY
#define USE_GPS
/* Serial telemetry: USART1 or USART3 */
#if !defined(PIOS_PORT_TELEMETRY)
#define PIOS_PORT_TELEMETRY 1
#endif
/* GPS receiver: USART1 or USART3 */
#if !defined(PIOS_PORT_GPS)
#define PIOS_PORT_GPS 3
#endif
/* Spektrum satellite receiver: USART1 or USART3 */
#if !defined(PIOS_PORT_SPEKTRUM)
#define PIOS_PORT_SPEKTRUM 3
#endif
/* Futaba S.Bus receiver: USART1 only (needs invertor) */
#if !defined(PIOS_PORT_SBUS)
#define PIOS_PORT_SBUS 1
#endif
/*
* Define USART ports and check for conflicts.
* Make sure it does not conflict with each other and with I2C.
*/
#define USART_GPIO(port) (((port) == 1) ? GPIOA : GPIOB)
#define USART_RXIO(port) (((port) == 1) ? GPIO_Pin_10 : GPIO_Pin_11)
#define USART_TXIO(port) (((port) == 1) ? GPIO_Pin_9 : GPIO_Pin_10)
#if defined(USE_TELEMETRY)
#if defined(USE_I2C) && (PIOS_PORT_TELEMETRY == 3)
#error defined(USE_I2C) && (PIOS_PORT_TELEMETRY == 3)
#endif
#if (PIOS_PORT_TELEMETRY == 1)
#define PIOS_USART_TELEMETRY USART1
#define PIOS_IRQH_TELEMETRY USART1_IRQHandler
#define PIOS_IRQC_TELEMETRY USART1_IRQn
#else
#define PIOS_USART_TELEMETRY USART3
#define PIOS_IRQH_TELEMETRY USART3_IRQHandler
#define PIOS_IRQC_TELEMETRY USART3_IRQn
#endif
#define PIOS_GPIO_TELEMETRY USART_GPIO(PIOS_PORT_TELEMETRY)
#define PIOS_RXIO_TELEMETRY USART_RXIO(PIOS_PORT_TELEMETRY)
#define PIOS_TXIO_TELEMETRY USART_TXIO(PIOS_PORT_TELEMETRY)
#endif
#if defined(USE_GPS)
#if defined(USE_I2C) && (PIOS_PORT_GPS == 3)
#error defined(USE_I2C) && (PIOS_PORT_GPS == 3)
#endif
#if defined(USE_TELEMETRY) && (PIOS_PORT_TELEMETRY == PIOS_PORT_GPS)
#error defined(USE_TELEMETRY) && (PIOS_PORT_TELEMETRY == PIOS_PORT_GPS)
#endif
#if (PIOS_PORT_GPS == 1)
#define PIOS_USART_GPS USART1
#define PIOS_IRQH_GPS USART1_IRQHandler
#define PIOS_IRQC_GPS USART1_IRQn
#else
#define PIOS_USART_GPS USART3
#define PIOS_IRQH_GPS USART3_IRQHandler
#define PIOS_IRQC_GPS USART3_IRQn
#endif
#define PIOS_GPIO_GPS USART_GPIO(PIOS_PORT_GPS)
#define PIOS_RXIO_GPS USART_RXIO(PIOS_PORT_GPS)
#define PIOS_TXIO_GPS USART_TXIO(PIOS_PORT_GPS)
#define PIOS_INCLUDE_GPS
#endif
#if defined(USE_SPEKTRUM)
#if defined(USE_I2C) && (PIOS_PORT_SPEKTRUM == 3)
#error defined(USE_I2C) && (PIOS_PORT_SPEKTRUM == 3)
#endif
#if defined(USE_TELEMETRY) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_TELEMETRY)
#error defined(USE_TELEMETRY) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_TELEMETRY)
#endif
#if defined(USE_GPS) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_GPS)
#error defined(USE_GPS) && (PIOS_PORT_SPEKTRUM == PIOS_PORT_GPS)
#endif
#if defined(USE_SBUS)
#error defined(USE_SPEKTRUM) && defined(USE_SBUS)
#endif
#if (PIOS_PORT_SPEKTRUM == 1)
#define PIOS_USART_SPEKTRUM USART1
#define PIOS_IRQH_SPEKTRUM USART1_IRQHandler
#define PIOS_IRQC_SPEKTRUM USART1_IRQn
#else
#define PIOS_USART_SPEKTRUM USART3
#define PIOS_IRQH_SPEKTRUM USART3_IRQHandler
#define PIOS_IRQC_SPEKTRUM USART3_IRQn
#endif
#define PIOS_GPIO_SPEKTRUM USART_GPIO(PIOS_PORT_SPEKTRUM)
#define PIOS_RXIO_SPEKTRUM USART_RXIO(PIOS_PORT_SPEKTRUM)
#define PIOS_TXIO_SPEKTRUM USART_TXIO(PIOS_PORT_SPEKTRUM)
#define PIOS_INCLUDE_SPEKTRUM
#endif
#if defined(USE_SBUS)
#if (PIOS_PORT_SBUS != 1)
#error (PIOS_PORT_SBUS != 1)
#endif
#if defined(USE_TELEMETRY) && (PIOS_PORT_SBUS == PIOS_PORT_TELEMETRY)
#error defined(USE_TELEMETRY) && (PIOS_PORT_SBUS == PIOS_PORT_TELEMETRY)
#endif
#if defined(USE_GPS) && (PIOS_PORT_SBUS == PIOS_PORT_GPS)
#error defined(USE_GPS) && (PIOS_PORT_SBUS == PIOS_PORT_GPS)
#endif
#if defined(USE_SPEKTRUM)
#error defined(USE_SPEKTRUM) && defined(USE_SBUS)
#endif
#define PIOS_USART_SBUS USART1
#define PIOS_IRQH_SBUS USART1_IRQHandler
#define PIOS_IRQC_SBUS USART1_IRQn
#define PIOS_GPIO_SBUS USART_GPIO(PIOS_PORT_SBUS)
#define PIOS_RXIO_SBUS USART_RXIO(PIOS_PORT_SBUS)
#define PIOS_TXIO_SBUS USART_TXIO(PIOS_PORT_SBUS)
#define PIOS_INCLUDE_SBUS
#endif
/* Receiver interfaces - only one allowed */
#if !defined(USE_SPEKTRUM) && !defined(USE_SBUS)
//#define PIOS_INCLUDE_PPM
#define PIOS_INCLUDE_PWM
#endif
#define PIOS_INCLUDE_SERVO
#define PIOS_INCLUDE_SPI
#define PIOS_INCLUDE_SYS

View File

@ -204,9 +204,9 @@ void PIOS_ADC_handler() {
* Telemetry USART
*/
void PIOS_USART_telem_irq_handler(void);
void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
void PIOS_IRQH_TELEMETRY() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
const struct pios_usart_cfg pios_usart_telem_cfg = {
.regs = USART1,
.regs = PIOS_USART_TELEMETRY,
.init = {
#if defined (PIOS_COM_TELEM_BAUDRATE)
.USART_BaudRate = PIOS_COM_TELEM_BAUDRATE,
@ -222,24 +222,24 @@ const struct pios_usart_cfg pios_usart_telem_cfg = {
.irq = {
.handler = PIOS_USART_telem_irq_handler,
.init = {
.NVIC_IRQChannel = USART1_IRQn,
.NVIC_IRQChannel = PIOS_IRQC_TELEMETRY,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOA,
.gpio = PIOS_GPIO_TELEMETRY,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Pin = PIOS_RXIO_TELEMETRY,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOA,
.gpio = PIOS_GPIO_TELEMETRY,
.init = {
.GPIO_Pin = GPIO_Pin_9,
.GPIO_Pin = PIOS_TXIO_TELEMETRY,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
},
@ -251,9 +251,9 @@ const struct pios_usart_cfg pios_usart_telem_cfg = {
* GPS USART
*/
void PIOS_USART_gps_irq_handler(void);
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_gps_irq_handler")));
void PIOS_IRQH_GPS() __attribute__ ((alias ("PIOS_USART_gps_irq_handler")));
const struct pios_usart_cfg pios_usart_gps_cfg = {
.regs = USART3,
.regs = PIOS_USART_GPS,
.init = {
#if defined (PIOS_COM_GPS_BAUDRATE)
.USART_BaudRate = PIOS_COM_GPS_BAUDRATE,
@ -269,24 +269,24 @@ const struct pios_usart_cfg pios_usart_gps_cfg = {
.irq = {
.handler = PIOS_USART_gps_irq_handler,
.init = {
.NVIC_IRQChannel = USART3_IRQn,
.NVIC_IRQChannel = PIOS_IRQC_GPS,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOB,
.gpio = PIOS_GPIO_GPS,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Pin = PIOS_RXIO_GPS,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOB,
.gpio = PIOS_GPIO_GPS,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Pin = PIOS_TXIO_GPS,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF_PP,
},
@ -299,9 +299,9 @@ const struct pios_usart_cfg pios_usart_gps_cfg = {
* SPEKTRUM USART
*/
void PIOS_USART_spektrum_irq_handler(void);
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
void PIOS_IRQH_SPEKTRUM() __attribute__ ((alias ("PIOS_USART_spektrum_irq_handler")));
const struct pios_usart_cfg pios_usart_spektrum_cfg = {
.regs = USART3,
.regs = PIOS_USART_SPEKTRUM,
.init = {
#if defined (PIOS_COM_SPEKTRUM_BAUDRATE)
.USART_BaudRate = PIOS_COM_SPEKTRUM_BAUDRATE,
@ -317,24 +317,24 @@ const struct pios_usart_cfg pios_usart_spektrum_cfg = {
.irq = {
.handler = PIOS_USART_spektrum_irq_handler,
.init = {
.NVIC_IRQChannel = USART3_IRQn,
.NVIC_IRQChannel = PIOS_IRQC_SPEKTRUM,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOB,
.gpio = PIOS_GPIO_SPEKTRUM,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Pin = PIOS_RXIO_SPEKTRUM,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOB,
.gpio = PIOS_GPIO_SPEKTRUM,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Pin = PIOS_TXIO_SPEKTRUM,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
},
@ -365,8 +365,8 @@ const struct pios_spektrum_cfg pios_spektrum_cfg = {
.NVIC_IRQChannelCmd = ENABLE,
},
},
.port = GPIOB,
.pin = GPIO_Pin_11,
.port = PIOS_GPIO_SPEKTRUM,
.pin = PIOS_RXIO_SPEKTRUM,
};
void PIOS_SUPV_irq_handler() {
@ -388,9 +388,9 @@ void PIOS_SUPV_irq_handler() {
* SBUS USART
*/
void PIOS_USART_sbus_irq_handler(void);
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_sbus_irq_handler")));
void PIOS_IRQH_SBUS() __attribute__ ((alias ("PIOS_USART_sbus_irq_handler")));
const struct pios_usart_cfg pios_usart_sbus_cfg = {
.regs = USART3,
.regs = PIOS_USART_SBUS,
.init = {
#if defined (PIOS_COM_SBUS_BAUDRATE)
.USART_BaudRate = PIOS_COM_SBUS_BAUDRATE,
@ -406,24 +406,24 @@ const struct pios_usart_cfg pios_usart_sbus_cfg = {
.irq = {
.handler = PIOS_USART_sbus_irq_handler,
.init = {
.NVIC_IRQChannel = USART3_IRQn,
.NVIC_IRQChannel = PIOS_IRQC_SBUS,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOB,
.gpio = PIOS_GPIO_SBUS,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Pin = PIOS_RXIO_SBUS,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IPU,
},
},
.tx = {
.gpio = GPIOB,
.gpio = PIOS_GPIO_SBUS,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Pin = PIOS_TXIO_SBUS,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_IN_FLOATING,
},
@ -454,8 +454,8 @@ const struct pios_sbus_cfg pios_sbus_cfg = {
.NVIC_IRQChannelCmd = ENABLE,
},
},
.port = GPIOB,
.pin = GPIO_Pin_11,
.port = PIOS_GPIO_SBUS,
.pin = PIOS_RXIO_SBUS,
};
void PIOS_SUPV_irq_handler() {