From a981926997bc826f4e8682b4527efecc78936caa Mon Sep 17 00:00:00 2001 From: bkleiner Date: Sat, 4 Nov 2023 15:03:43 +0100 Subject: [PATCH] target: add gyro exti --- src/core/target.c | 12 ++++++++++++ src/core/target.h | 16 ++++++++++++++-- src/driver/spi_gyro.c | 5 ++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/core/target.c b/src/core/target.c index 637c52dd3..015675b65 100644 --- a/src/core/target.c +++ b/src/core/target.c @@ -58,6 +58,10 @@ CBOR_START_STRUCT_ENCODER(target_spi_device_t) TARGET_SPI_DEVICE_MEMBERS CBOR_END_STRUCT_ENCODER() +CBOR_START_STRUCT_ENCODER(target_gyro_spi_device_t) +TARGET_GYRO_SPI_DEVICE_MEMBERS +CBOR_END_STRUCT_ENCODER() + CBOR_START_STRUCT_ENCODER(target_rx_spi_device_t) TARGET_RX_SPI_DEVICE_MEMBERS CBOR_END_STRUCT_ENCODER() @@ -100,6 +104,10 @@ CBOR_START_STRUCT_DECODER(target_spi_port_t) TARGET_SPI_MEMBERS CBOR_END_STRUCT_DECODER() +CBOR_START_STRUCT_DECODER(target_gyro_spi_device_t) +TARGET_GYRO_SPI_DEVICE_MEMBERS +CBOR_END_STRUCT_DECODER() + CBOR_START_STRUCT_DECODER(target_spi_device_t) TARGET_SPI_DEVICE_MEMBERS CBOR_END_STRUCT_DECODER() @@ -271,6 +279,10 @@ bool target_spi_device_valid(const target_spi_device_t *dev) { return dev->port != SPI_PORT_INVALID && dev->nss != PIN_NONE; } +bool target_gyro_spi_device_valid(const target_gyro_spi_device_t *dev) { + return dev->port != SPI_PORT_INVALID && dev->nss != PIN_NONE; +} + bool target_spi_port_valid(const target_spi_port_t *port) { return port->index != 0 && port->miso != PIN_NONE && port->mosi != PIN_NONE && port->sck != PIN_NONE; } diff --git a/src/core/target.h b/src/core/target.h index 3d1fbc883..16447bd52 100644 --- a/src/core/target.h +++ b/src/core/target.h @@ -115,6 +115,17 @@ typedef struct { MEMBER(port, uint8_t) \ MEMBER(nss, gpio_pins_t) +typedef struct { + spi_ports_t port; + gpio_pins_t nss; + gpio_pins_t exti; +} target_gyro_spi_device_t; + +#define TARGET_GYRO_SPI_DEVICE_MEMBERS \ + MEMBER(port, uint8_t) \ + MEMBER(nss, gpio_pins_t) \ + MEMBER(exti, gpio_pins_t) + typedef struct { spi_ports_t port; gpio_pins_t nss; @@ -148,7 +159,7 @@ typedef struct { target_serial_port_t serial_soft_ports[SERIAL_SOFT_COUNT]; target_spi_port_t spi_ports[SPI_PORT_MAX]; - target_spi_device_t gyro; + target_gyro_spi_device_t gyro; uint8_t gyro_orientation; target_spi_device_t osd; target_spi_device_t flash; @@ -175,7 +186,7 @@ typedef struct { INDEX_ARRAY_MEMBER(serial_ports, SERIAL_PORT_MAX, target_serial_port_t) \ INDEX_ARRAY_MEMBER(serial_soft_ports, SERIAL_SOFT_COUNT, target_serial_port_t) \ INDEX_ARRAY_MEMBER(spi_ports, SPI_PORT_MAX, target_spi_port_t) \ - MEMBER(gyro, target_spi_device_t) \ + MEMBER(gyro, target_gyro_spi_device_t) \ MEMBER(gyro_orientation, uint8_t) \ MEMBER(osd, target_spi_device_t) \ MEMBER(flash, target_spi_device_t) \ @@ -227,6 +238,7 @@ void target_add_rx_protocol(rx_protocol_t proto); bool target_has_rx_protocol(rx_protocol_t proto); bool target_serial_port_valid(const target_serial_port_t *port); +bool target_gyro_spi_device_valid(const target_gyro_spi_device_t *dev); bool target_spi_device_valid(const target_spi_device_t *dev); bool target_spi_port_valid(const target_spi_port_t *port); diff --git a/src/driver/spi_gyro.c b/src/driver/spi_gyro.c index 516edb4a6..a20beacc4 100644 --- a/src/driver/spi_gyro.c +++ b/src/driver/spi_gyro.c @@ -5,9 +5,9 @@ #include "driver/time.h" #include "driver/spi_bmi270.h" +#include "driver/spi_bmi323.h" #include "driver/spi_icm42605.h" #include "driver/spi_mpu6xxx.h" -#include "driver/spi_bmi323.h" #ifdef USE_GYRO @@ -72,7 +72,7 @@ uint8_t gyro_spi_init() { gpio_pin_init(GYRO_INT, gpio_init); #endif - if (!target_spi_device_valid(&target.gyro)) { + if (!target_gyro_spi_device_valid(&target.gyro)) { return GYRO_TYPE_INVALID; } @@ -104,7 +104,6 @@ uint8_t gyro_spi_init() { bmi323_configure(); break; - default: break; }