diff --git a/Makefile b/Makefile index b6159f71f3..84618f8b94 100644 --- a/Makefile +++ b/Makefile @@ -283,7 +283,6 @@ clean: $(Q)rm -f $(GEN_HEADERS) $(Q)find . -mindepth 2 -name Makefile -a ! -path "./sw/ext/*" -exec sh -c 'echo "Cleaning {}"; $(MAKE) -C `dirname {}` $@' \; $(Q)$(MAKE) -C $(EXT) clean - $(Q)$(MAKE) -C $(TOOLS)/bluegiga_usb_dongle clean $(Q)find . -name '*~' -exec rm -f {} \; cleanspaces: diff --git a/conf/boards/lisa_s_1.0.makefile b/conf/boards/lisa_s_1.0.makefile index 9caa9587ec..cc414cb11e 100644 --- a/conf/boards/lisa_s_1.0.makefile +++ b/conf/boards/lisa_s_1.0.makefile @@ -33,6 +33,7 @@ BARO_LED ?= none AHRS_ALIGNER_LED ?= 2 GPS_LED ?= none SYS_TIME_LED ?= 1 +MODEM_LED ?= 3 # # default uart configuration diff --git a/conf/firmwares/subsystems/fixedwing/telemetry_bluegiga.makefile b/conf/firmwares/subsystems/fixedwing/telemetry_bluegiga.makefile new file mode 100644 index 0000000000..a85a9f6e16 --- /dev/null +++ b/conf/firmwares/subsystems/fixedwing/telemetry_bluegiga.makefile @@ -0,0 +1,14 @@ +# Hey Emacs, this is a -*- makefile -*- + +# include shared part for ap +ifeq ($(TARGET),ap) +include $(CFG_SHARED)/telemetry_bluegiga.makefile +endif + +ap.srcs += $(SRC_FIRMWARE)/datalink.c $(SRC_FIRMWARE)/ap_downlink.c + +# avoid fbw_telemetry_mode error +ap.srcs += $(SRC_FIRMWARE)/fbw_downlink.c + +fbw.srcs += $(SRC_FIRMWARE)/fbw_downlink.c + diff --git a/conf/firmwares/subsystems/rotorcraft/telemetry_bluegiga.makefile b/conf/firmwares/subsystems/rotorcraft/telemetry_bluegiga.makefile index b369a8cbaa..0b95743659 100644 --- a/conf/firmwares/subsystems/rotorcraft/telemetry_bluegiga.makefile +++ b/conf/firmwares/subsystems/rotorcraft/telemetry_bluegiga.makefile @@ -1,17 +1,9 @@ # -# The bluegiga module as telemetry downlink/uplink +# The bluegiga module as telemetry downlink/uplink for rotorcraft # -# -ap.CFLAGS += -DUSE_$(MODEM_PORT) -ap.CFLAGS += -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD) -ap.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_DEVICE=bluegiga_p -ap.CFLAGS += -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=BLUEGIGA -#ap.CFLAGS += -DDefaultPeriodic='&telemetry_Main' -ap.CFLAGS += -DUSE_SPI2_SLAVE -DSPI_SLAVE +ifeq ($(TARGET), ap) +include $(CFG_SHARED)/telemetry_bluegiga.makefile +endif -# for some reason the following line required to get GPS over datalink working -ap.CFLAGS += -DUSE_UART3 -DUART3_BAUD=B38400 - -ap.srcs += subsystems/datalink/downlink.c subsystems/datalink/bluegiga.c subsystems/datalink/pprz_transport.c subsystems/datalink/telemetry.c ap.srcs += $(SRC_FIRMWARE)/datalink.c $(SRC_FIRMWARE)/rotorcraft_telemetry.c diff --git a/conf/firmwares/subsystems/shared/telemetry_bluegiga.makefile b/conf/firmwares/subsystems/shared/telemetry_bluegiga.makefile new file mode 100644 index 0000000000..2df1682330 --- /dev/null +++ b/conf/firmwares/subsystems/shared/telemetry_bluegiga.makefile @@ -0,0 +1,35 @@ +# +# The bluegiga module as telemetry downlink/uplink +# +# On Lisa-s, the Superbit-RF module can be replaced with a +# bluegiga-bluetooth 4 low power board. This subsystem puts +# the telemetry over this bluetooth 4 link. +# +# Bluegiga is a SPI-slave device without Chip select but with a compulsory DRDY +# +# Required: +# #define BLUEGIGA_SPI_DEV: the SPI device which MUST have a SLAVE mode without chipselect +# +# Optional: (defaults to SUPERBITRF DRDY) +# #define BLUEGIGA_DRDY_GPIO +# #define BLUEGIGA_DRDY_GPIO_PIN + +# Include SPI if not yet included +include $(CFG_SHARED)/spi_master.makefile + +# Set downlink to paparazzi transport over bluegiga protocol over SPI slave +ap.CFLAGS += -DDOWNLINK -DPERIODIC_TELEMETRY -DDOWNLINK_DEVICE=bluegiga_p +ap.CFLAGS += -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=BLUEGIGA + +BLUEGIGA_SPI_DEV ?= SPI2 +BLUEGIGA_SPI_DEV_LOWER=$(shell echo $(BLUEGIGA_SPI_DEV) | tr A-Z a-z) +ap.CFLAGS += -DUSE_$(BLUEGIGA_SPI_DEV)_SLAVE -DSPI_SLAVE -DBLUEGIGA_SPI_DEV=$(BLUEGIGA_SPI_DEV_LOWER) + +# LED +MODEM_LED ?= none +ifneq ($(MODEM_LED),none) +ap.CFLAGS += -DMODEM_LED=$(MODEM_LED) +endif + +ap.srcs += $(SRC_SUBSYSTEMS)/datalink/downlink.c $(SRC_SUBSYSTEMS)/datalink/bluegiga.c +ap.srcs += $(SRC_SUBSYSTEMS)/datalink/pprz_transport.c $(SRC_SUBSYSTEMS)/datalink/telemetry.c diff --git a/sw/airborne/arch/stm32/mcu_periph/spi_arch.c b/sw/airborne/arch/stm32/mcu_periph/spi_arch.c index 34ed8e916b..7cbe525370 100644 --- a/sw/airborne/arch/stm32/mcu_periph/spi_arch.c +++ b/sw/airborne/arch/stm32/mcu_periph/spi_arch.c @@ -1313,7 +1313,7 @@ void dma1_channel2_isr(void) { // SPI arch slave init #if USE_SPI2_SLAVE -#warning "STM32-SPI2 slave: Configured not to use the NSS pin" +PRINT_CONFIG_MSG("STM32-SPI2 slave: Configured not to use the NSS pin") #ifndef STM32F1 #error "SPI2 slave on STM32 only implemented for STM32F1" diff --git a/sw/airborne/subsystems/datalink/bluegiga.c b/sw/airborne/subsystems/datalink/bluegiga.c index e302ceed6d..1b44cb88f0 100644 --- a/sw/airborne/subsystems/datalink/bluegiga.c +++ b/sw/airborne/subsystems/datalink/bluegiga.c @@ -31,19 +31,16 @@ #include "mcu_periph/gpio.h" #ifndef BLUEGIGA_SPI_DEV -#define BLUEGIGA_SPI_DEV spi2 -#endif - -#ifndef BLUEGIGA_SLAVE_IDX -#define BLUEGIGA_SLAVE_IDX SPI_SLAVE2 +#error "bluegiga: must define a BLUEGIGA_SPI_DEV" #endif +// Bluegiga: DRDY defaults to SuperbitRf DRDY #ifndef BLUEGIGA_DRDY_GPIO -#define BLUEGIGA_DRDY_GPIO GPIOC +#define BLUEGIGA_DRDY_GPIO SUPERBITRF_DRDY_PORT #endif #ifndef BLUEGIGA_DRDY_GPIO_PIN -#define BLUEGIGA_DRDY_GPIO_PIN GPIO6 +#define BLUEGIGA_DRDY_GPIO_PIN SUPERBITRF_DRDY_PIN #endif enum BlueGigaStatus coms_status; @@ -73,14 +70,16 @@ static void trans_cb(struct spi_transaction *trans __attribute__((unused))) void bluegiga_init(void) { - LED_INIT(3); +#ifdef MODEM_LED + LED_INIT(MODEM_LED); +#endif // configure the SPI bus. bluegiga_spi.input_buf = bluegiga_p.work_rx; bluegiga_spi.output_buf = bluegiga_p.work_tx; bluegiga_spi.input_length = 20; bluegiga_spi.output_length = 20; - bluegiga_spi.slave_idx = BLUEGIGA_SLAVE_IDX; + bluegiga_spi.slave_idx = 0; // Not used for SPI-Slave: always NSS pin bluegiga_spi.select = SPISelectUnselect; bluegiga_spi.cpol = SPICpolIdleHigh; bluegiga_spi.cpha = SPICphaEdge2; @@ -191,7 +190,9 @@ void bluegiga_receive(void) bluegiga_p.tx_insert_idx = 0; bluegiga_p.tx_extract_idx = 0; - LED_OFF(3); +#ifdef MODEM_LED + LED_OFF(MODEM_LED); +#endif coms_status = BLUEGIGA_UNINIT; gpio_set(BLUEGIGA_DRDY_GPIO, BLUEGIGA_DRDY_GPIO_PIN); // Reset interrupt pin break; diff --git a/sw/airborne/subsystems/datalink/bluegiga.h b/sw/airborne/subsystems/datalink/bluegiga.h index f2c6466b7e..f82c15a4a0 100644 --- a/sw/airborne/subsystems/datalink/bluegiga.h +++ b/sw/airborne/subsystems/datalink/bluegiga.h @@ -28,7 +28,6 @@ #define BLUEGIGA_DATA_LINK_H #include "mcu_periph/link_device.h" -#include "generated/airframe.h" /* The different statuses the communication can be in */ enum BlueGigaStatus { @@ -91,7 +90,9 @@ static inline void bluegiga_read_buffer(struct pprz_transport *t) // reached end of circular read buffer or message received // if received, decode and advance if (t->trans_rx.msg_received) { - LED_TOGGLE(3); +#ifdef MODEM_LED + LED_TOGGLE(MODEM_LED); +#endif pprz_parse_payload(t); t->trans_rx.msg_received = FALSE; } @@ -99,7 +100,7 @@ static inline void bluegiga_read_buffer(struct pprz_transport *t) } while (BlueGigaChAvailable()); // continue till all messages read } -// transmit previous date in buffer and parse data received +// transmit previous data in buffer and parse data received #define BlueGigaCheckAndParse(_dev,_trans) { \ if (BlueGigaChAvailable()) \ bluegiga_read_buffer( &(_trans) ); \ diff --git a/sw/airborne/subsystems/datalink/datalink.h b/sw/airborne/subsystems/datalink/datalink.h index 40dfc937fa..90950e0b58 100644 --- a/sw/airborne/subsystems/datalink/datalink.h +++ b/sw/airborne/subsystems/datalink/datalink.h @@ -106,7 +106,7 @@ static inline void DlCheckAndParse(void) #elif defined DATALINK && DATALINK == BLUEGIGA #define DatalinkEvent() { \ - BlueGigaCheckAndParse(BLUEGIGA, pprz_tp); \ + BlueGigaCheckAndParse(BLUEGIGA_SPI_DEV, pprz_tp); \ DlCheckAndParse(); \ } diff --git a/sw/airborne/subsystems/datalink/downlink.h b/sw/airborne/subsystems/datalink/downlink.h index a25203b56b..3444c401fa 100644 --- a/sw/airborne/subsystems/datalink/downlink.h +++ b/sw/airborne/subsystems/datalink/downlink.h @@ -46,7 +46,9 @@ #include "subsystems/datalink/pprzlog_transport.h" #include "subsystems/datalink/xbee.h" #include "subsystems/datalink/w5100.h" +#if DATALINK == BLUEGIGA #include "subsystems/datalink/bluegiga.h" +#endif #if USE_SUPERBITRF #include "subsystems/datalink/superbitrf.h" #endif