Skip to content

Commit

Permalink
use combined spi txn everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Nov 26, 2022
1 parent ff223c7 commit cce768c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 54 deletions.
16 changes: 4 additions & 12 deletions src/drivers/drv_spi_bmi270.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ uint8_t bmi270_read(uint8_t reg) {

spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg(txn, buffer, buffer, 3);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);

return buffer[2];
}
Expand All @@ -123,9 +121,7 @@ void bmi270_write(uint8_t reg, uint8_t data) {
spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg_const(txn, reg);
spi_txn_add_seg_const(txn, data);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}

void bmi270_write_data(uint8_t reg, uint8_t *data, uint32_t size) {
Expand All @@ -134,9 +130,7 @@ void bmi270_write_data(uint8_t reg, uint8_t *data, uint32_t size) {
spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg_const(txn, reg);
spi_txn_add_seg(txn, NULL, data, size);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}

void bmi270_read_data(uint8_t reg, uint8_t *data, uint32_t size) {
Expand All @@ -146,7 +140,5 @@ void bmi270_read_data(uint8_t reg, uint8_t *data, uint32_t size) {
spi_txn_add_seg_const(txn, reg | 0x80);
spi_txn_add_seg_const(txn, 0xFF);
spi_txn_add_seg(txn, data, NULL, size);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}
12 changes: 3 additions & 9 deletions src/drivers/drv_spi_icm42605.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ uint8_t icm42605_read(uint8_t reg) {

spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg(txn, buffer, buffer, 2);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);

return buffer[1];
}
Expand All @@ -69,9 +67,7 @@ void icm42605_write(uint8_t reg, uint8_t data) {
spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg_const(txn, reg);
spi_txn_add_seg_const(txn, data);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}

void icm42605_read_data(uint8_t reg, uint8_t *data, uint32_t size) {
Expand All @@ -80,7 +76,5 @@ void icm42605_read_data(uint8_t reg, uint8_t *data, uint32_t size) {
spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg_const(txn, reg | 0x80);
spi_txn_add_seg(txn, data, NULL, size);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}
20 changes: 5 additions & 15 deletions src/drivers/drv_spi_m25p16.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ uint8_t m25p16_is_ready() {

spi_txn_t *txn = spi_txn_init(&bus, NULL);
spi_txn_add_seg(txn, buffer, buffer, 2);
spi_txn_submit(txn);

spi_txn_wait(&bus);
spi_txn_submit_wait(&bus, txn);

return (buffer[1] & 0x01) == 0;
}
Expand All @@ -64,9 +62,7 @@ uint8_t m25p16_command(const uint8_t cmd) {

spi_txn_t *txn = spi_txn_init(&bus, NULL);
spi_txn_add_seg(txn, &ret, &cmd, 1);
spi_txn_submit(txn);

spi_txn_wait(&bus);
spi_txn_submit_wait(&bus, txn);

return ret;
}
Expand All @@ -79,9 +75,7 @@ uint8_t m25p16_read_command(const uint8_t cmd, uint8_t *data, const uint32_t len
spi_txn_t *txn = spi_txn_init(&bus, NULL);
spi_txn_add_seg(txn, &ret, &cmd, 1);
spi_txn_add_seg(txn, data, NULL, len);
spi_txn_submit(txn);

spi_txn_wait(&bus);
spi_txn_submit_wait(&bus, txn);

return ret;
}
Expand All @@ -101,9 +95,7 @@ uint8_t m25p16_read_addr(const uint8_t cmd, const uint32_t addr, uint8_t *data,
spi_txn_add_seg(txn, &ret, &cmd, 1);
m25p16_set_addr(txn, addr);
spi_txn_add_seg(txn, data, NULL, len);
spi_txn_submit(txn);

spi_txn_wait(&bus);
spi_txn_submit_wait(&bus, txn);

return ret;
}
Expand Down Expand Up @@ -141,9 +133,7 @@ uint8_t m25p16_write_addr(const uint8_t cmd, const uint32_t addr, uint8_t *data,
spi_txn_add_seg(txn, &ret, &cmd, 1);
m25p16_set_addr(txn, addr);
spi_txn_add_seg(txn, NULL, data, len);
spi_txn_submit(txn);

spi_txn_continue(&bus);
spi_txn_submit_continue(&bus, txn);

return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions src/drivers/drv_spi_max7456.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ bool max7456_push_string(uint8_t attr, uint8_t x, uint8_t y, const uint8_t *data
buf[offset++] = DMDI;
buf[offset++] = 0xFF;

spi_txn_submit(txn);
spi_txn_continue(&bus);
spi_txn_submit_continue(&bus, txn);

return true;
}
Expand Down
13 changes: 3 additions & 10 deletions src/drivers/drv_spi_mpu6xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ uint8_t mpu6xxx_read(uint8_t reg) {

spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg(txn, buffer, buffer, 2);
spi_txn_submit(txn);

spi_txn_continue_ex(&gyro_bus, true);
spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);

return buffer[1];
}
Expand All @@ -113,9 +110,7 @@ void mpu6xxx_write(uint8_t reg, uint8_t data) {
spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg_const(txn, reg);
spi_txn_add_seg_const(txn, data);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}

void mpu6xxx_read_data(uint8_t reg, uint8_t *data, uint32_t size) {
Expand All @@ -124,7 +119,5 @@ void mpu6xxx_read_data(uint8_t reg, uint8_t *data, uint32_t size) {
spi_txn_t *txn = spi_txn_init(&gyro_bus, NULL);
spi_txn_add_seg_const(txn, reg | 0x80);
spi_txn_add_seg(txn, data, NULL, size);
spi_txn_submit(txn);

spi_txn_wait(&gyro_bus);
spi_txn_submit_wait(&gyro_bus, txn);
}
9 changes: 3 additions & 6 deletions src/drivers/drv_spi_sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ sdcard_status_t sdcard_update() {
spi_txn_add_seg_const(txn, 0xff);
spi_txn_add_seg_const(txn, 0xff);

spi_txn_submit(txn);
spi_txn_continue(&bus);
spi_txn_submit_continue(&bus, txn);
}
break;
}
Expand Down Expand Up @@ -472,8 +471,7 @@ sdcard_status_t sdcard_update() {
// write response
spi_txn_add_seg_const(txn, 0xff);

spi_txn_submit(txn);
spi_txn_continue(&bus);
spi_txn_submit_continue(&bus, txn);

state = SDCARD_WRITE_MULTIPLE_VERIFY;
break;
Expand All @@ -492,8 +490,7 @@ sdcard_status_t sdcard_update() {
case SDCARD_WRITE_MULTIPLE_FINISH: {
spi_txn_t *txn = spi_txn_init(&bus, NULL);
spi_txn_add_seg_const(txn, 0xfd);
spi_txn_submit(txn);
spi_txn_continue(&bus);
spi_txn_submit_continue(&bus, txn);

state = SDCARD_WRITE_MULTIPLE_FINISH_WAIT;
break;
Expand Down

0 comments on commit cce768c

Please sign in to comment.