Skip to content

Commit

Permalink
gyro: drop spi from function names
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Aug 3, 2024
1 parent 4a0b64b commit 77d2750
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
34 changes: 20 additions & 14 deletions src/driver/gyro/gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,20 @@ static gyro_types_t gyro_spi_detect() {
return type;
}

uint8_t gyro_spi_init() {
#ifdef GYRO_INT
// Interrupt GPIO
gpio_config_t gpio_init;
gpio_init.mode = GPIO_INPUT;
gpio_init.output = GPIO_PUSHPULL;
gpio_init.pull = GPIO_UP_PULL;
gpio_init.drive = GPIO_DRIVE_HIGH;
gpio_pin_init(GYRO_INT, gpio_init);
#endif

uint8_t gyro_int() {
if (!target_gyro_spi_device_valid(&target.gyro)) {
return GYRO_TYPE_INVALID;
}

if (target.gyro.exti != PIN_NONE) {
gpio_config_t gpio_init;
gpio_init.mode = GPIO_INPUT;
gpio_init.output = GPIO_OPENDRAIN;
gpio_init.pull = GPIO_NO_PULL;
gpio_init.drive = GPIO_DRIVE_HIGH;
gpio_pin_init(target.gyro.exti, gpio_init);
}

gyro_bus.port = target.gyro.port;
gyro_bus.nss = target.gyro.nss;
spi_bus_device_init(&gyro_bus);
Expand Down Expand Up @@ -108,11 +107,18 @@ uint8_t gyro_spi_init() {
break;
}

gyro_spi_read(); // dummy read to fill buffers
gyro_read(); // dummy read to fill buffers

return gyro_type;
}

bool gyro_exti_state() {
if (target.gyro.exti == PIN_NONE) {
return true;
}
return gpio_pin_read(target.gyro.exti);
}

float gyro_update_period() {
switch (gyro_type) {
case GYRO_TYPE_MPU6000:
Expand All @@ -136,7 +142,7 @@ float gyro_update_period() {
}
}

gyro_data_t gyro_spi_read() {
gyro_data_t gyro_read() {
static gyro_data_t data;

switch (gyro_type) {
Expand Down Expand Up @@ -172,7 +178,7 @@ gyro_data_t gyro_spi_read() {
return data;
}

void gyro_spi_calibrate() {
void gyro_calibrate() {
switch (gyro_type) {
case GYRO_TYPE_BMI270: {
bmi270_calibrate();
Expand Down
8 changes: 5 additions & 3 deletions src/driver/gyro/gyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ typedef struct {

extern gyro_types_t gyro_type;

uint8_t gyro_spi_init();
float gyro_update_period();
gyro_data_t gyro_spi_read();
void gyro_spi_calibrate();
bool gyro_exti_state();

uint8_t gyro_int();
gyro_data_t gyro_read();
void gyro_calibrate();
14 changes: 7 additions & 7 deletions src/flight/sixaxis.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static filter_biquad_notch_t notch_filter[SDFT_AXES][SDFT_PEAKS];
static filter_biquad_state_t notch_filter_state[SDFT_AXES][SDFT_PEAKS];

bool sixaxis_detect() {
target_info.gyro_id = gyro_spi_init();
target_info.gyro_id = gyro_int();
return target_info.gyro_id != GYRO_TYPE_INVALID;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ void sixaxis_read() {
filter_coeff(profile.filter.gyro[0].type, &filter[0], profile.filter.gyro[0].cutoff_freq);
filter_coeff(profile.filter.gyro[1].type, &filter[1], profile.filter.gyro[1].cutoff_freq);

const gyro_data_t data = gyro_spi_read();
const gyro_data_t data = gyro_read();

const vec3_t accel = sixaxis_apply_matrix(data.accel);
// swap pitch and roll to match gyro
Expand Down Expand Up @@ -219,7 +219,7 @@ static bool sixaxis_wait_for_still(uint32_t timeout) {
const uint32_t start = time_micros();
uint32_t now = start;
while (now - start < timeout && move_counter > 0) {
const gyro_data_t data = gyro_spi_read();
const gyro_data_t data = gyro_read();

const bool did_move = test_gyro_move(&last_data, &data);
if (did_move) {
Expand Down Expand Up @@ -248,18 +248,18 @@ void sixaxis_gyro_cal() {
}
time_delay_ms(200);
}
gyro_spi_calibrate();
gyro_calibrate();

uint8_t brightness = 0;
led_pwm(brightness, 1000);

gyro_data_t last_data = gyro_spi_read();
gyro_data_t last_data = gyro_read();

uint32_t start = time_micros();
uint32_t now = start;
int32_t cal_counter = CAL_TIME / 1000;
for (int32_t timeout = WAIT_TIME / 1000; timeout > 0; --timeout) {
const gyro_data_t data = gyro_spi_read();
const gyro_data_t data = gyro_read();

led_pwm(brightness, 1000);
if ((brightness & 1) ^ ((now - start) % GLOW_TIME > (GLOW_TIME >> 1))) {
Expand Down Expand Up @@ -290,7 +290,7 @@ void sixaxis_acc_cal() {

flash_storage.accelcal[2] = 2048;
for (uint32_t i = 0; i < 500; i++) {
const gyro_data_t data = gyro_spi_read();
const gyro_data_t data = gyro_read();
const vec3_t accel = sixaxis_apply_matrix(data.accel);

for (uint32_t x = 0; x < 3; x++) {
Expand Down

0 comments on commit 77d2750

Please sign in to comment.