Skip to content

Commit

Permalink
add public API to read the buffer for burst reads from imu
Browse files Browse the repository at this point in the history
  • Loading branch information
corruptbear committed Jun 19, 2024
1 parent 7b9f2ed commit 33cc47a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions software/firmware/src/peripherals/include/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ void imu_read_axis_remap(bno055_axis_remap_t *remap);
bool imu_set_axis_remap(bno055_axis_remap_t remap);
void imu_read_euler_data(bno055_euler_t *euler);
bool imu_read_in_motion(void);
void imu_read_burst_buffer(uint8_t *destBuffer);

// Math utilities
void quaternion_to_euler(bno055_quaternion_t quaternion, bno055_euler_t *euler);
Expand Down
14 changes: 9 additions & 5 deletions software/firmware/src/peripherals/src/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ void imu_iom_isr(void)
static void nonblocking_read_complete(void *pCallbackCtxt, uint32_t transactionStatus)
{
uint8_t localBuffer[BURST_READ_LEN] = {0};

AM_CRITICAL_BEGIN
memcpy(localBuffer, gReadBuffer, BURST_READ_LEN);
memset(gReadBuffer, 0, BURST_READ_LEN);
AM_CRITICAL_END
imu_read_burst_buffer(localBuffer);
data_ready_callback(localBuffer);
}

Expand Down Expand Up @@ -527,3 +523,11 @@ bool imu_read_in_motion(void)
{
return previously_in_motion;
}

void imu_read_burst_buffer(uint8_t *destBuffer)
{
AM_CRITICAL_BEGIN
memcpy(destBuffer, gReadBuffer, BURST_READ_LEN);
memset(gReadBuffer, 0, BURST_READ_LEN);
AM_CRITICAL_END
}
4 changes: 2 additions & 2 deletions software/firmware/tests/peripherals/test_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ static void read_data(uint8_t interrupt_status)
}

static void handle_burst_data(uint8_t *localBuffer){
int16_t read_buffer[BURST_READ_SIZE/2] = {0};
int16_t read_buffer[BURST_READ_LEN/2] = {0};

for (uint32_t i = 0; i < BURST_READ_SIZE/2; i++)
for (uint32_t i = 0; i < BURST_READ_LEN/2; i++)
{
read_buffer[i] = ((int16_t)localBuffer[i*2]) | (((int16_t)localBuffer[i*2+1]) << 8);
}
Expand Down

0 comments on commit 33cc47a

Please sign in to comment.