Skip to content

Commit

Permalink
target: add gyro exti
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Nov 4, 2023
1 parent 4a8baea commit a981926
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/core/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
}
16 changes: 14 additions & 2 deletions src/core/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) \
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/driver/spi_gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -104,7 +104,6 @@ uint8_t gyro_spi_init() {
bmi323_configure();
break;


default:
break;
}
Expand Down

0 comments on commit a981926

Please sign in to comment.