15static uint8_t A3G4250D_readRegister(
A3G4250D_t *, uint8_t);
16static void A3G4250D_writeRegister(
A3G4250D_t *, uint8_t, uint8_t);
40 gyro->
base.sensitivity = sensitivity;
51 memcpy(gyro->
base.
axes, axes, A3G4250D_DATA_COUNT);
52 memcpy(gyro->
base.
sign, sign, A3G4250D_DATA_COUNT);
58 A3G4250D_writeRegister(
61 (A3G4250D_CTRL_REG1_ODR_800Hz
62 | A3G4250D_CTRL_REG1_AXIS_ENABLE
63 | A3G4250D_CTRL_REG1_PD_ENABLE)
81 uint8_t bytes[A3G4250D_DATA_TOTAL];
110 for (
int i = 0; i < A3G4250D_DATA_COUNT; i++) {
111 out[i] = (int16_t)(((uint16_t)bytes[i * 2] << 8) | bytes[i * 2 + 1]);
112 out[i] = (out[i] * gyro->
sign[i] * gyro->sensitivity) - gyro->
bias[i];
126#define INDEX_AXES(index, byte) 2 * gyro->axes[index] + byte
127 out[INDEX_AXES(0, 0)] = A3G4250D_readRegister((
A3G4250D_t *)gyro, A3G4250D_OUT_X_H);
128 out[INDEX_AXES(0, 1)] = A3G4250D_readRegister((
A3G4250D_t *)gyro, A3G4250D_OUT_X_L);
129 out[INDEX_AXES(1, 0)] = A3G4250D_readRegister((
A3G4250D_t *)gyro, A3G4250D_OUT_Y_H);
130 out[INDEX_AXES(1, 1)] = A3G4250D_readRegister((
A3G4250D_t *)gyro, A3G4250D_OUT_Y_L);
131 out[INDEX_AXES(2, 0)] = A3G4250D_readRegister((
A3G4250D_t *)gyro, A3G4250D_OUT_Z_H);
132 out[INDEX_AXES(2, 1)] = A3G4250D_readRegister((
A3G4250D_t *)gyro, A3G4250D_OUT_Z_L);
140void A3G4250D_writeRegister(
A3G4250D_t *gyro, uint8_t address, uint8_t data) {
147 uint8_t payload = address & 0x7F;
154uint8_t A3G4250D_readRegister(
A3G4250D_t *gyro, uint8_t address) {
155 uint8_t response = 0;
162 uint8_t payload = address | 0x80;
163 response = spi->
transmit(spi, payload);
164 response = spi->
transmit(spi, 0xFF);
void A3G4250D_readRawBytes(Gyro_t *, uint8_t *)
Read raw 3-axis data.
void A3G4250D_update(Gyro_t *)
Updates internally stored gyro readings.
A3G4250D_t A3G4250D_init(A3G4250D_t *gyro, SPI_t *spi, GPIOpin_t cs, float sensitivity, const uint8_t *axes, const int8_t *sign)
Initialiser for a A3G4250D gyroscope.
void A3G4250D_readGyro(Gyro_t *, float *)
Read 3-axis floating point gyro rates.
void A3G4250D_processRawBytes(Gyro_t *, uint8_t *, float *)
Process raw 3-axis data to floating point gyro rates.
uint8_t * axes
Array defining axes of mounting.
int8_t * sign
Array defining sign of axes.
void(* readRawBytes)(struct Gyro *, uint8_t *)
Pointer to readRawBytes method.
float * gyroData
Processed angular rates array.
uint8_t * rawGyroData
Raw angular rates array.
void(* update)(struct Gyro *gyro)
Pointer to update method.
float * bias
Bias offset array.
uint8_t dataSize
Total data size.
void(* processRawBytes)(struct Gyro *, uint8_t *, float *)
Pointer to processRawBytes method.
void(* readGyro)(struct Gyro *gyro, float *out)
Pointer to readGyro method.
void(* set)(struct GPIOpin *)
void(* reset)(struct GPIOpin *)
Struct definition for a GPIO pin.
uint16_t(* transmit)(struct SPI *, uint16_t)
SPI transmit method.
Struct definition for SPI interface. Provides the interface for API consumers to interact with the SP...
uint8_t rawGyroData[A3G4250D_DATA_TOTAL]
Raw rotation array.
GPIOpin_t cs
Chip select GPIO.
float bias[A3G4250D_DATA_COUNT]
Bias offset array.
int8_t sign[A3G4250D_DATA_COUNT]
Array defining sign of axes.
uint8_t axes[A3G4250D_DATA_COUNT]
Array defining axes of mounting.
Gyro_t base
Base gyroscope API.
SPI_t * spi
Parent SPI interface.
float gyroData[A3G4250D_DATA_COUNT]
Processed rotation array.