MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / bmi270_read

Function bmi270_read

Drivers/bmi270-module/source/bmi270.cpp:155–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153extern "C" {
154
155error_t bmi270_read(Device* device, Bmi270Data* data) {
156 auto* i2c_controller = device_get_parent(device);
157
158 auto address = GET_CONFIG(device)->address;
159
160 // Burst-read 12 bytes: acc X/Y/Z (6 bytes) + gyro X/Y/Z (6 bytes)
161 // Registers: 0x0C–0x17 are contiguous for acc+gyro in I2C mode (no dummy byte)
162 uint8_t buffer[12] = {};
163 error_t error = i2c_controller_read_register(i2c_controller, address, REG_DATA_ACC, buffer, sizeof(buffer), I2C_TIMEOUT_TICKS);
164 if (error != ERROR_NONE) return error;
165
166 auto toI16 = [](uint8_t lo, uint8_t hi) -> int16_t {
167 return static_cast<int16_t>(static_cast<uint16_t>(hi) << 8 | lo);
168 };
169
170 data->ax = toI16(buffer[0], buffer[1]) * ACCEL_SCALE;
171 data->ay = toI16(buffer[2], buffer[3]) * ACCEL_SCALE;
172 data->az = toI16(buffer[4], buffer[5]) * ACCEL_SCALE;
173 data->gx = toI16(buffer[6], buffer[7]) * GYRO_SCALE;
174 data->gy = toI16(buffer[8], buffer[9]) * GYRO_SCALE;
175 data->gz = toI16(buffer[10], buffer[11]) * GYRO_SCALE;
176
177 return ERROR_NONE;
178}
179
180Driver bmi270_driver = {
181 .name = "bmi270",

Callers

nothing calls this directly

Calls 2

device_get_parentFunction · 0.85

Tested by

no test coverage detected