49 #if (L3GD20_USE_SPI) || defined(__DOXYGEN__) 62 (n == 1) ? (cmd = reg | L3GD20_RW) : (cmd = reg | L3GD20_RW | L3GD20_MS);
81 (n == 1) ? (cmd = reg) : (cmd = reg | L3GD20_MS);
127 "gyro_read_raw(), invalid state");
130 "gyro_read_raw(), channel not ready");
132 #if L3GD20_SHARED_SPI 135 devp->config->spicfg);
139 L3GD20_GYRO_NUMBER_OF_AXES * 2, buff);
141 #if L3GD20_SHARED_SPI 147 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
148 axes[i] = (int32_t)tmp;
179 "gyro_read_cooked(), invalid state");
183 axes[i] = (raw[i] * devp->gyrosensitivity[i]) - devp->gyrobias[i];
213 "gyro_sample_bias(), invalid state");
216 "gyro_sample_bias(), channel not ready");
231 devp->gyrobias[i] *= devp->gyrosensitivity[i];
259 "gyro_set_bias(), invalid state");
262 devp->gyrobias[i] = bp[i];
288 "gyro_reset_bias(), invalid state");
291 devp->gyrobias[i] = L3GD20_GYRO_BIAS;
318 "gyro_set_sensivity(), invalid state");
321 devp->gyrosensitivity[i] = sp[i];
347 "gyro_reset_sensivity(), invalid state");
351 devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_250DPS;
354 devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_500DPS;
357 devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_2000DPS;
386 "gyro_set_full_scale(), invalid state");
389 "gyro_set_full_scale(), channel not ready");
393 newfs = L3GD20_250DPS;
396 newfs = L3GD20_500DPS;
399 newfs = L3GD20_2000DPS;
405 if(newfs != devp->gyrofullscale) {
406 scale = newfs / devp->gyrofullscale;
407 devp->gyrofullscale = newfs;
410 #if L3GD20_SHARED_SPI 413 devp->config->spicfg);
418 L3GD20_AD_CTRL_REG4, 1, &cr);
420 #if L3GD20_SHARED_SPI 424 cr &= ~(L3GD20_CTRL_REG4_FS_MASK);
428 #if L3GD20_SHARED_SPI 431 devp->config->spicfg);
435 L3GD20_AD_CTRL_REG4, 1, &cr);
436 #if L3GD20_SHARED_SPI 443 devp->gyrosensitivity[i] *= scale;
444 devp->gyrobias[i] *= scale;
450 static const struct L3GD20VMT vmt_device = {
474 devp->
vmt = &vmt_device;
492 uint8_t cr[5] = {0, 0, 0, 0, 0};
496 "l3gd20Start(), invalid state");
498 devp->config = config;
502 cr[0] = L3GD20_CTRL_REG1_XEN | L3GD20_CTRL_REG1_YEN |
503 L3GD20_CTRL_REG1_ZEN | L3GD20_CTRL_REG1_PD |
504 devp->config->gyrooutputdatarate;
505 #if L3GD20_GYRO_USE_ADVANCED || defined(__DOXYGEN__) 506 cr[0] |= devp->config->gyrobandwidth;
512 #if L3GD20_GYRO_USE_ADVANCED || defined(__DOXYGEN__) 514 cr[1] = devp->config->gyrohpmode | devp->config->gyrohpconfiguration;
520 cr[3] = devp->config->gyrofullscale;
521 #if L3GD20_GYRO_USE_ADVANCED || defined(__DOXYGEN__) 522 cr[3] |= devp->config->gyroblockdataupdate |
523 devp->config->gyroendianness;
529 #if L3GD20_GYRO_USE_ADVANCED || defined(__DOXYGEN__) 531 cr[4] = L3GD20_CTRL_REG5_HPEN;
533 cr[4] |= L3GD20_CTRL_REG5_INT1_SEL1 |
534 L3GD20_CTRL_REG5_OUT_SEL1;
537 cr[4] |= L3GD20_CTRL_REG5_INT1_SEL0 |
538 L3GD20_CTRL_REG5_OUT_SEL0;
545 #if L3GD20_SHARED_SPI 549 devp->config->spicfg);
553 #if L3GD20_SHARED_SPI 560 devp->gyrofullscale = L3GD20_250DPS;
562 if (devp->config->gyrosensitivity == NULL)
563 devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_250DPS;
565 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
569 devp->gyrofullscale = L3GD20_500DPS;
571 if (devp->config->gyrosensitivity == NULL)
572 devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_500DPS;
574 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
578 devp->gyrofullscale = L3GD20_2000DPS;
580 if (devp->config->gyrosensitivity == NULL)
581 devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_2000DPS;
583 devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
590 if(devp->config->gyrobias != NULL) {
592 devp->gyrobias[i] = devp->config->gyrobias[i];
597 devp->gyrobias[i] = L3GD20_GYRO_BIAS;
618 "l3gd20Stop(), invalid state");
625 #if L3GD20_SHARED_SPI 628 devp->config->spicfg);
635 #if L3GD20_SHARED_SPI void l3gd20ObjectInit(L3GD20Driver *devp)
Initializes an instance.
void spiUnselect(SPIDriver *spip)
Deasserts the slave select signal.
#define L3GD20_BIAS_SETTLING_US
Settling time for bias removal.
void spiSelect(SPIDriver *spip)
Asserts the slave select signal and prepares for transfers.
void spiReceive(SPIDriver *spip, size_t n, void *rxbuf)
Receives data from the SPI bus.
#define osalThreadSleepMicroseconds(usecs)
Delays the invoking thread for the specified number of microseconds.
static msg_t gyro_set_full_scale(L3GD20Driver *devp, l3gd20_fs_t fs)
Changes the L3GD20Driver gyroscope fullscale value.
void spiStart(SPIDriver *spip, const SPIConfig *config)
Configures and activates the SPI peripheral.
L3GD20 MEMS interface module header.
L3GD20 virtual methods table.
BaseGyroscope virtual methods table.
void spiReleaseBus(SPIDriver *spip)
Releases exclusive access to the SPI bus.
static size_t gyro_get_axes_number(void *ip)
Return the number of axes of the BaseGyroscope.
BaseGyroscope gyro_if
Base gyroscope interface.
void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config)
Configures and activates L3GD20 Complex Driver peripheral.
L3GD20 3-axis gyroscope class.
#define objGetInstance(type, ip)
Returns the instance pointer starting from an interface pointer.
void spiAcquireBus(SPIDriver *spip)
Gains exclusive access to the SPI bus.
#define L3GD20_BIAS_ACQ_TIMES
Number of acquisitions for bias removal.
const struct L3GD20VMT * vmt
Virtual Methods Table.
static msg_t gyro_read_raw(void *ip, int32_t axes[L3GD20_GYRO_NUMBER_OF_AXES])
Retrieves raw data from the BaseGyroscope.
#define osalThreadSleepMilliseconds(msecs)
Delays the invoking thread for the specified number of milliseconds.
l3gd20_fs_t
L3GD20 full scale.
static void l3gd20SPIReadRegister(SPIDriver *spip, uint8_t reg, size_t n, uint8_t *b)
Reads a generic register value using SPI.
const struct BaseGyroscopeVMT * vmt
Virtual Methods Table.
static void l3gd20SPIWriteRegister(SPIDriver *spip, uint8_t reg, size_t n, uint8_t *b)
Writes a value into a generic register using SPI.
static msg_t gyro_sample_bias(void *ip)
Samples bias values for the BaseGyroscope.
static msg_t gyro_set_bias(void *ip, float *bp)
Set bias values for the BaseGyroscope.
static msg_t gyro_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseGyroscope.
#define osalDbgCheck(c)
Function parameters check.
static msg_t gyro_reset_sensivity(void *ip)
Reset sensitivity values for the BaseGyroscope.
#define MSG_OK
Normal wakeup message.
#define L3GD20_GYRO_NUMBER_OF_AXES
L3GD20 gyroscope system characteristics.
L3GD20 configuration structure.
void spiSend(SPIDriver *spip, size_t n, const void *txbuf)
Sends data over the SPI bus.
#define osalDbgAssert(c, remark)
Condition assertion.
static msg_t gyro_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseGyroscope.
static msg_t gyro_reset_bias(void *ip)
Reset bias values for the BaseGyroscope.
void l3gd20Stop(L3GD20Driver *devp)
Deactivates the L3GD20 Complex Driver peripheral.
void spiStop(SPIDriver *spip)
Deactivates the SPI peripheral.
Structure representing an SPI driver.
#define FALSE
Generic 'false' preprocessor boolean constant.
#define MSG_RESET
Wakeup caused by a reset condition.