diff --git a/conf/boards/px4fmu_4.0.makefile b/conf/boards/px4fmu_4.0.makefile index faab9c3dc9..65cf3bd021 100644 --- a/conf/boards/px4fmu_4.0.makefile +++ b/conf/boards/px4fmu_4.0.makefile @@ -39,7 +39,7 @@ SYS_TIME_LED ?= 1 # # default UART configuration (RC receiver, telemetry modem, GPS) # -RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT ?= UART1 +RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT ?= UART6 #RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT ?= UART7 MODEM_PORT ?= UART2 diff --git a/sw/airborne/boards/opa_ftd_1.0.h b/sw/airborne/boards/opa_ftd_1.0.h index 55cde95397..b7e6ef14c4 100644 --- a/sw/airborne/boards/opa_ftd_1.0.h +++ b/sw/airborne/boards/opa_ftd_1.0.h @@ -146,7 +146,7 @@ * Spektrum */ /* Define power pin */ -#define RADIO_CONTROL_POWER GPIOC +#define RADIO_CONTROL_POWER_PORT GPIOC #define RADIO_CONTROL_POWER_PIN GPIO13 #define RADIO_CONTROL_POWER_ON gpio_set #define RADIO_CONTROL_POWER_OFF gpio_clear diff --git a/sw/airborne/boards/px4fmu_4.0.h b/sw/airborne/boards/px4fmu_4.0.h index f1a62aaa17..39acd41e2e 100644 --- a/sw/airborne/boards/px4fmu_4.0.h +++ b/sw/airborne/boards/px4fmu_4.0.h @@ -88,6 +88,11 @@ #define UART4_GPIO_PORT_TX GPIOA #define UART4_GPIO_TX GPIO0 +/* Spektrum (only rx)*/ +#define UART6_GPIO_AF GPIO_AF8 +#define UART6_GPIO_PORT_RX GPIOC +#define UART6_GPIO_RX GPIO7 + /* Serial Debugging Connector, not used with PPRZ, use JTAG, can be put to other good use */ #define UART7_GPIO_AF GPIO_AF8 #define UART7_GPIO_PORT_RX GPIOE @@ -103,30 +108,31 @@ #define UART8_GPIO_TX GPIO1 /* Soft binding Spektrum */ -#define RADIO_CONTROL_POWER GPIOB -#define RADIO_CONTROL_POWER_PIN GPIO0 +//ok +#define RADIO_CONTROL_POWER_PORT GPIOC +#define RADIO_CONTROL_POWER_PIN GPIO5 #define RADIO_CONTROL_POWER_ON gpio_set #define RADIO_CONTROL_POWER_OFF gpio_clear -//FIXME Check -#define SPEKTRUM_UART1_RCC RCC_USART1 -#define SPEKTRUM_UART1_BANK GPIOB -#define SPEKTRUM_UART1_PIN GPIO0 -#define SPEKTRUM_UART1_AF GPIO_AF7 -#define SPEKTRUM_UART1_IRQ NVIC_USART1_IRQ -#define SPEKTRUM_UART1_ISR usart1_isr -#define SPEKTRUM_UART1_DEV USART1 -//FIXME Check -/* -#define SPEKTRUM_UART2_RCC RCC_USART2 -#define SPEKTRUM_UART2_BANK GPIOC -#define SPEKTRUM_UART2_PIN GPIO7 -#define SPEKTRUM_UART2_AF GPIO_AF7 -#define SPEKTRUM_UART2_IRQ NVIC_USART2_IRQ -#define SPEKTRUM_UART2_ISR usart2_isr -#define SPEKTRUM_UART2_DEV USART2 -*/ +#define PERIPHERAL3V3_ENABLE_PORT GPIOE +#define PERIPHERAL3V3_ENABLE_PIN GPIO4 +#define PERIPHERAL3V3_ENABLE_ON gpio_clear // yes, inverted +#define PERIPHERAL3V3_ENABLE_OFF gpio_set + +/* Turn SBUS invert */ +//ok +#define RC_POLARITY_GPIO_PORT GPIOC +#define RC_POLARITY_GPIO_PIN GPIO13 + +//ok +#define SPEKTRUM_UART6_RCC RCC_USART6 +#define SPEKTRUM_UART6_BANK GPIOC +#define SPEKTRUM_UART6_PIN GPIO7 +#define SPEKTRUM_UART6_AF GPIO_AF8 +#define SPEKTRUM_UART6_IRQ NVIC_USART6_IRQ +#define SPEKTRUM_UART6_ISR usart6_isr +#define SPEKTRUM_UART6_DEV USART6 /* SPI */ diff --git a/sw/airborne/boards/px4io_2.4.h b/sw/airborne/boards/px4io_2.4.h index 56ce2fd10f..2e994a2e4d 100644 --- a/sw/airborne/boards/px4io_2.4.h +++ b/sw/airborne/boards/px4io_2.4.h @@ -66,7 +66,7 @@ * Spektrum */ /* The line that is pulled low at power up to initiate the bind process */ -#define RADIO_CONTROL_POWER GPIOC +#define RADIO_CONTROL_POWER_PORT GPIOC #define RADIO_CONTROL_POWER_PIN GPIO13 #define RADIO_CONTROL_POWER_ON gpio_set #define RADIO_CONTROL_POWER_OFF gpio_clear diff --git a/sw/airborne/firmwares/rotorcraft/main.c b/sw/airborne/firmwares/rotorcraft/main.c index 877446886f..61c07d8856 100644 --- a/sw/airborne/firmwares/rotorcraft/main.c +++ b/sw/airborne/firmwares/rotorcraft/main.c @@ -240,6 +240,7 @@ STATIC_INLINE void main_init(void) // Do a failsafe check first failsafe_check(); + } STATIC_INLINE void handle_periodic_tasks(void) diff --git a/sw/airborne/mcu.c b/sw/airborne/mcu.c index a4fc6cdc9a..7a970b9f11 100644 --- a/sw/airborne/mcu.c +++ b/sw/airborne/mcu.c @@ -112,9 +112,9 @@ void mcu_init(void) led_init(); #endif /* First enable power of RC */ -#if defined RADIO_CONTROL_POWER - gpio_setup_output(RADIO_CONTROL_POWER, RADIO_CONTROL_POWER_PIN); - RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER, RADIO_CONTROL_POWER_PIN); +#if defined RADIO_CONTROL_POWER_PORT + gpio_setup_output(RADIO_CONTROL_POWER_PORT, RADIO_CONTROL_POWER_PIN); + RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER_PORT, RADIO_CONTROL_POWER_PIN); #endif /* for now this means using spektrum */ #if defined RADIO_CONTROL & defined RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT & defined RADIO_CONTROL_BIND_IMPL_FUNC & defined SPEKTRUM_BIND_PIN_PORT diff --git a/sw/airborne/modules/boards/opa_controller_fbw.c b/sw/airborne/modules/boards/opa_controller_fbw.c index cd5ba08f80..072833686c 100644 --- a/sw/airborne/modules/boards/opa_controller_fbw.c +++ b/sw/airborne/modules/boards/opa_controller_fbw.c @@ -71,7 +71,7 @@ void opa_controller_periodic(void) { AP_PWR_OFF(AP_PWR, AP_PWR_PIN); MAIN_PWR_OFF(MAIN_PWR, MAIN_PWR_PIN); BAL_PWR_OFF(BAL_PWR, BAL_PWR_PIN); - RADIO_CONTROL_POWER_OFF(RADIO_CONTROL_POWER,RADIO_CONTROL_POWER_PIN); + RADIO_CONTROL_POWER_OFF(RADIO_CONTROL_POWER_PORT,RADIO_CONTROL_POWER_PIN); MCU_PWR_OFF(MCU_PWR, MCU_PWR_PIN); arming_led = false; return; @@ -106,7 +106,7 @@ void opa_controller_periodic(void) { MAIN_PWR_ON(MAIN_PWR, MAIN_PWR_PIN); BAL_PWR_ON(BAL_PWR, BAL_PWR_PIN); //AP_PWR_ON(AP_PWR, AP_PWR_PIN); - //RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER,RADIO_CONTROL_POWER_PIN); + //RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER_PORT,RADIO_CONTROL_POWER_PIN); } else { arming_cnt++; } diff --git a/sw/airborne/modules/spektrum_soft_bind/spektrum_soft_bind_ap.c b/sw/airborne/modules/spektrum_soft_bind/spektrum_soft_bind_ap.c index 8969f6bbcf..7034d16a61 100644 --- a/sw/airborne/modules/spektrum_soft_bind/spektrum_soft_bind_ap.c +++ b/sw/airborne/modules/spektrum_soft_bind/spektrum_soft_bind_ap.c @@ -33,15 +33,24 @@ #include "mcu_periph/gpio.h" -void spektrum_soft_bind_init(void) {} +void spektrum_soft_bind_init(void) { + gpio_setup_output(RADIO_CONTROL_POWER_PORT, RADIO_CONTROL_POWER_PIN); + RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER_PORT, RADIO_CONTROL_POWER_PIN); + +#ifdef PERIPHERAL3V3_ENABLE_PORT // px4fmu 4 (pixracer) has this + gpio_setup_output(PERIPHERAL3V3_ENABLE_PORT, PERIPHERAL3V3_ENABLE_PIN); + PERIPHERAL3V3_ENABLE_ON(PERIPHERAL3V3_ENABLE_PORT, PERIPHERAL3V3_ENABLE_PIN); +#endif + +} uint8_t bind_soft_value; void spektrum_soft_bind_click(uint8_t val __attribute__((unused))) { #ifndef INTER_MCU_AP - send_spektrum_bind(); + send_spektrum_bind(); #else - intermcu_send_spektrum_bind(); + intermcu_send_spektrum_bind(); #endif } @@ -50,9 +59,11 @@ void spektrum_soft_bind_click(uint8_t val __attribute__((unused))) void send_spektrum_bind(void) { //power cycle the spektrum - RADIO_CONTROL_POWER_OFF(RADIO_CONTROL_POWER, RADIO_CONTROL_POWER_PIN); - sys_time_usleep(100000); - RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER, RADIO_CONTROL_POWER_PIN); + RADIO_CONTROL_POWER_OFF(RADIO_CONTROL_POWER_PORT, RADIO_CONTROL_POWER_PIN); + sys_time_usleep(1000000); + RADIO_CONTROL_POWER_ON(RADIO_CONTROL_POWER_PORT, RADIO_CONTROL_POWER_PIN); + + //put to bind mode RADIO_CONTROL_BIND_IMPL_FUNC(); //basically = radio_control_spektrum_try_bind()