FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
I2C device driver for the MPU6050 gyroscope/accelerometer chip. More...
#include <fastarduino/devices/mpu6050.h>
Classes | |
class | BeginFuture |
Create a future to be used by asynchronous method begin(BeginFuture&). More... | |
class | EndFuture |
Create a future to be used by asynchronous method end(EndFuture&). More... | |
class | FifoBeginFuture |
Create a future to be used by asynchronous method begin(FifoBeginFuture&). More... | |
class | ResetFuture |
Create a future to be used by asynchronous method reset(ResetFuture&). More... | |
Public Types | |
using | GyroFuture = Sensor3DFuture< GYRO_XOUT > |
Create a future to be used by asynchronous method gyro_measures(GyroFuture&). More... | |
using | TemperatureFuture = TReadRegisterFuture< TEMP_OUT, int16_t > |
Create a future to be used by asynchronous method temperature(TemperatureFuture&). More... | |
using | AccelFuture = Sensor3DFuture< ACCEL_XOUT > |
Create a future to be used by asynchronous method accel_measures(AccelFuture&). More... | |
using | AllMeasuresFuture = TReadRegisterFuture< ACCEL_XOUT, AllSensors, functor::ChangeEndianness< AllSensors, int16_t > > |
Create a future to be used by asynchronous method all_measures(AllMeasuresFuture&). More... | |
using | InterruptStatusFuture = TReadRegisterFuture< INT_STATUS, INTStatus > |
Create a future to be used by asynchronous method interrupt_status(InterruptStatusFuture&). More... | |
using | ResetFifoFuture = TWriteRegisterFuture< USER_CTRL, uint8_t, functor::Constant< uint8_t, FIFO_ENABLE|FIFO_RESET > > |
Create a future to be used by asynchronous method reset_fifo(ResetFifoFuture&). More... | |
using | FifoCountFuture = TReadRegisterFuture< FIFO_COUNT, uint16_t > |
Create a future to be used by asynchronous method fifo_count(FifoCountFuture&). More... | |
template<typename T > | |
using | FifoPopFuture = TReadRegisterFuture< FIFO_R_W, T, functor::ChangeEndianness< T, int16_t > > |
Create a future to be used by asynchronous method fifo_pop(FifoPopFuture<T>&). More... | |
using | FifoPushFuture = TWriteRegisterFuture< FIFO_R_W > |
Create a future to be used by asynchronous method fifo_push(FifoPushFuture&). More... | |
Public Types inherited from i2c::I2CDevice< MANAGER > | |
using | MANAGER = MANAGER |
the type of I2C Manager that can handle this device. More... | |
Public Member Functions | |
MPU6050 (MANAGER &manager, AD0 ad0=AD0::LOW) | |
Create a new device driver for a MPU6050 chip. More... | |
int | begin (BeginFuture &future) |
Start operation of this gyroscope/accelerometer chip. More... | |
int | begin (FifoBeginFuture &future) |
Start operation of this gyroscope/accelerometer chip. More... | |
int | end (EndFuture &future) INLINE |
Put the chip to sleep mode (low-power mode); stops sampling operations if any. More... | |
int | reset (ResetFuture &future) INLINE |
Reset the chip (register map §4.28). More... | |
int | gyro_measures (GyroFuture &future) |
Get latest gyroscope measurements from the device (register map §4.19). More... | |
int | temperature (TemperatureFuture &future) |
Get latest chip temperature measurement (register map §4.18). More... | |
int | accel_measures (AccelFuture &future) |
Get latest accelerometer measurements from the device (register map §4.17). More... | |
int | all_measures (AllMeasuresFuture &future) |
Get latest measurements of all device sensors (gyroscope, accelerometer, temperature). More... | |
int | interrupt_status (InterruptStatusFuture &future) |
Get the interrupt status (register map §4.16) after an interrupt has occurred. More... | |
int | reset_fifo (ResetFifoFuture &future) |
Reset the FIFO buffer (parameter map §4.27). More... | |
int | fifo_count (FifoCountFuture &future) |
Get the number of bytes currently stored in the FIFO buffer (register map §4.30). More... | |
template<typename T > | |
int | fifo_pop (FifoPopFuture< T > &future) |
Get one sample out of the FIFO buffer (register map §4.31). More... | |
int | fifo_push (FifoPushFuture &future) |
Push one byte to the FIFO buffer (register map §4.31). More... | |
bool | begin (GyroRange gyro_range=GyroRange::RANGE_250, AccelRange accel_range=AccelRange::RANGE_2G, DLPF low_pass_filter=DLPF::ACCEL_BW_260HZ, ClockSelect clock_select=ClockSelect::INTERNAL_8MHZ) |
Start operation of this gyroscope/accelerometer chip. More... | |
bool | begin (FIFOEnable fifo_enable, INTEnable int_enable, uint8_t sample_rate_divider, GyroRange gyro_range=GyroRange::RANGE_250, AccelRange accel_range=AccelRange::RANGE_2G, DLPF low_pass_filter=DLPF::ACCEL_BW_260HZ, ClockSelect clock_select=ClockSelect::INTERNAL_8MHZ) |
Start operation of this gyroscope/accelerometer chip. More... | |
bool | end () INLINE |
Put the chip to sleep mode (low-power mode); stops sampling operations if any. More... | |
bool | reset () INLINE |
Reset the chip (register map §4.28). More... | |
bool | gyro_measures (Sensor3D &gyro) |
Get latest gyroscope measurements from the device (register map §4.19). More... | |
int16_t | temperature () |
Get latest chip temperature measurement (register map §4.18). More... | |
bool | accel_measures (Sensor3D &accel) |
Get latest accelerometer measurements from the device (register map §4.17). More... | |
bool | all_measures (AllSensors &sensors) |
Get latest measurements of all device sensors (gyroscope, accelerometer, temperature). More... | |
INTStatus | interrupt_status () |
Get the interrupt status (register map §4.16) after an interrupt has occurred. More... | |
bool | reset_fifo () |
Reset the FIFO buffer (parameter map §4.27). More... | |
uint16_t | fifo_count () |
Get the number of bytes currently stored in the FIFO buffer (register map §4.30). More... | |
template<typename T > | |
bool | fifo_pop (T &output) |
Get one sample out of the FIFO buffer (register map §4.31). More... | |
bool | fifo_push (uint8_t data) |
Push one byte to the FIFO buffer (register map §4.31). More... | |
Static Public Member Functions | |
static constexpr int16_t | convert_temp_to_centi_degrees (int16_t temp) |
Convert the raw temperature obtained from temperature() to centi-degrees Celsius. More... | |
Additional Inherited Members | |
Protected Types inherited from i2c::I2CDevice< MANAGER > | |
using | ABSTRACT_FUTURE = typename MANAGER::ABSTRACT_FUTURE |
The abstract base class of all futures to be defined for a device. More... | |
using | FUTURE = typename MANAGER::template FUTURE< OUT, IN > |
The template base class of all futures to be defined for a device. More... | |
Protected Member Functions inherited from i2c::I2CDevice< MANAGER > | |
I2CDevice (MANAGER &manager, uint8_t device, UNUSED Mode< MODE > mode, bool auto_stop) | |
Create a new I2C device. More... | |
I2CDevice (const I2CDevice &)=delete | |
I2CDevice & | operator= (const I2CDevice &)=delete |
void | set_device (uint8_t device) |
Change the I2C address of this device. More... | |
int | launch_commands (ABSTRACT_FUTURE &future, utils::range< I2CLightCommand > commands) |
Launch execution (asynchronously or synchronously, depending on MANAGER) of a chain of I2CLightCommand items (constructed with read() and write() methods). More... | |
int | async_read (F &future, bool stop=true) |
Helper method that asynchronously launches I2C commands for a simple Future performing one write followed by one read (typically for device register reading). More... | |
bool | sync_read (T &result) |
Helper method that launches I2C commands for a simple Future performing one write followed by one read (typically for device register reading); the method blocks until the end of the I2C transaction. More... | |
int | async_write (F &future, bool stop=true) |
Helper method that asynchronously launches I2C commands for a simple Future performing only one write (typically for device register writing). More... | |
int | async_multi_write (F &future, bool stop=true) |
Helper method that asynchronously launches I2C commands for a simple Future performing several register writes. More... | |
bool | sync_write (const T &value) |
Helper method that launches I2C commands for a simple Future performing only one write (typically for device register writing); the method blocks until the end of the I2C transaction. More... | |
bool | sync_write () |
Helper method that launches I2C commands for a simple Future performing only one write (typically for device register writing); the method blocks until the end of the I2C transaction. More... | |
Static Protected Member Functions inherited from i2c::I2CDevice< MANAGER > | |
static constexpr I2CLightCommand | read (uint8_t read_count=0, bool finish_future=false, bool stop=false) |
Build a read I2CLightCommand that can be later pushed to the I2C Manager for proper handling. More... | |
static constexpr I2CLightCommand | write (uint8_t write_count=0, bool finish_future=false, bool stop=false) |
Build a write I2CLightCommand that can be later pushed to the I2C Manager for proper handling. More... | |
I2C device driver for the MPU6050 gyroscope/accelerometer chip.
Note that the I2C auxiliary mode of the chip is not supported by the driver.
MANAGER | one of FastArduino available I2C Manager |
using devices::magneto::MPU6050< MANAGER >::GyroFuture = Sensor3DFuture<GYRO_XOUT> |
Create a future to be used by asynchronous method gyro_measures(GyroFuture&).
This is used by gyro_measures()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
using devices::magneto::MPU6050< MANAGER >::TemperatureFuture = TReadRegisterFuture<TEMP_OUT, int16_t> |
Create a future to be used by asynchronous method temperature(TemperatureFuture&).
This is used by temperature()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
The value returned by get()
is internal raw value from the chip, it can be converted to human-readable temperature with convert_temp_to_centi_degrees()
.
using devices::magneto::MPU6050< MANAGER >::AccelFuture = Sensor3DFuture<ACCEL_XOUT> |
Create a future to be used by asynchronous method accel_measures(AccelFuture&).
This is used by accel_measures()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
using devices::magneto::MPU6050< MANAGER >::AllMeasuresFuture = TReadRegisterFuture<ACCEL_XOUT, AllSensors, functor::ChangeEndianness<AllSensors, int16_t> > |
Create a future to be used by asynchronous method all_measures(AllMeasuresFuture&).
This is used by all_measures()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
using devices::magneto::MPU6050< MANAGER >::InterruptStatusFuture = TReadRegisterFuture<INT_STATUS, INTStatus> |
Create a future to be used by asynchronous method interrupt_status(InterruptStatusFuture&).
This is used by interrupt_status()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
using devices::magneto::MPU6050< MANAGER >::ResetFifoFuture = TWriteRegisterFuture<USER_CTRL, uint8_t, functor::Constant<uint8_t, FIFO_ENABLE | FIFO_RESET> > |
Create a future to be used by asynchronous method reset_fifo(ResetFifoFuture&).
This is used by reset_fifo()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
using devices::magneto::MPU6050< MANAGER >::FifoCountFuture = TReadRegisterFuture<FIFO_COUNT, uint16_t> |
Create a future to be used by asynchronous method fifo_count(FifoCountFuture&).
This is used by fifo_count()
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
using devices::magneto::MPU6050< MANAGER >::FifoPopFuture = TReadRegisterFuture<FIFO_R_W, T, functor::ChangeEndianness<T, int16_t> > |
Create a future to be used by asynchronous method fifo_pop(FifoPopFuture<T>&).
This is used by fifo_pop(FifoPopFuture<T>&)
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
T | the type of measurement to read from FIFO; shall be one of Sensor3D (gyroscope or accelerometer measure), int16_t (temperature), AllSensors (eveything), or a combination of these. |
using devices::magneto::MPU6050< MANAGER >::FifoPushFuture = TWriteRegisterFuture<FIFO_R_W> |
Create a future to be used by asynchronous method fifo_push(FifoPushFuture&).
This is used by fifo_push(FifoPushFuture&)
to asynchronously launch the I2C transaction, and it shall be used by the caller to determine when the I2C transaction is finished.
data | the byte value to be pushed |
|
inline |
Start operation of this gyroscope/accelerometer chip.
Once this method has been called, and future
is ready, you may use other methods such as gyro_measures()
to get sensors measurements from the device.
future | a BeginFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Start operation of this gyroscope/accelerometer chip.
Once this method has been called, and future
is ready, you may use other methods such as gyro_measures()
to get sensors measurements from the device. This shall be used when you want continuous measurements performed by the device.
future | a FifoBeginFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Put the chip to sleep mode (low-power mode); stops sampling operations if any.
future | an EndFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Reset the chip (register map §4.28).
future | a ResetFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Get latest gyroscope measurements from the device (register map §4.19).
future | a GyroFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Get latest chip temperature measurement (register map §4.18).
future | a TemperatureFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inlinestaticconstexpr |
Convert the raw temperature obtained from temperature()
to centi-degrees Celsius.
|
inline |
Get latest accelerometer measurements from the device (register map §4.17).
future | an AccelFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Get latest measurements of all device sensors (gyroscope, accelerometer, temperature).
future | an AllMeasuresFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Get the interrupt status (register map §4.16) after an interrupt has occurred.
After this method is called, the Interrupt Status register is cleared.
future | an InterruptStatusFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Reset the FIFO buffer (parameter map §4.27).
future | an ResetFifoFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Get the number of bytes currently stored in the FIFO buffer (register map §4.30).
This number is a multiple of the size of sensor samples as selected by FIFOEnable
in begin(FIFOEnable, INTEnable, uint8_t, GyroRange, AccelRange, DLPF, ClockSelect)
.
future | an FifoCountFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Get one sample out of the FIFO buffer (register map §4.31).
fifo_count()
to ensure the MPU6050 FIFO queue contains a sample of the right size! Otherwise this method will not return any error but set arbitrary values to output
! T | the type of sample to get from the FIFO buffer; must be one of Sensor3D , int16_t or AllSensors , based on the sensor samples selected by FIFOEnable in begin(FIFOEnable, INTEnable, uint8_t, GyroRange, AccelRange, DLPF, ClockSelect) . |
future | an FifoPopFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Push one byte to the FIFO buffer (register map §4.31).
fifo_count()
to ensure the MPU6050 FIFO queue contains a sample of the right size! Otherwise this method will not return any error but set arbitrary values to output
! future | an FifoPushFuture passed by the caller, that will be updated once the current I2C action is finished. |
0 | if no problem occurred during the preparation of I2C transaction |
errors
.
|
inline |
Start operation of this gyroscope/accelerometer chip.
Once this method has been called, you may use other methods such as gyro_measures()
to get sensors measurements from the device.
gyro_range | the GyroRange to use for the gyroscope measurements |
accel_range | the AccelRange to use for the accelerometer measurements |
low_pass_filter | the DLPF bandwidth to use for operations |
clock_select | the ClockSelect to use as the device clock source |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Start operation of this gyroscope/accelerometer chip.
Once this method has been called, you may use other methods such as gyro_measures()
to get sensors measurements from the device. This shall be used when you want continuous measurements performed by the device.
fifo_enable | the FIFOEnable settings for continuous measurements |
int_enable | the INTEnable settings for interrupt generation; note that the device driver does not handle interrupts (ISR) itself, you need to use other FastArduino API for that. |
sample_rate_divider | the divider from the gyroscope output rate to generate the Sample Rate of the chip (register map §4.2) |
gyro_range | the GyroRange to use for the gyroscope measurements |
accel_range | the AccelRange to use for the accelerometer measurements |
low_pass_filter | the DLPF bandwidth to use for operations |
clock_select | the ClockSelect to use as the device clock source |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Put the chip to sleep mode (low-power mode); stops sampling operations if any.
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Reset the chip (register map §4.28).
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get latest gyroscope measurements from the device (register map §4.19).
gyro | a reference to a Sensor3D variable that will be filled with latest gyroscope measurements on 3 axis. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get latest chip temperature measurement (register map §4.18).
The returned value is nternal raw value from the chip, it can be converted to human-readable temperature with convert_temp_to_centi_degrees()
.
-32768 | if the operation failed |
|
inline |
Get latest accelerometer measurements from the device (register map §4.17).
accel | a reference to a Sensor3D variable that will be filled with latest accelerometer measurements on 3 axis. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get latest measurements of all device sensors (gyroscope, accelerometer, temperature).
sensors | a reference to an AllSensors variable that will be filled with all latest measurements. |
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get the interrupt status (register map §4.16) after an interrupt has occurred.
After this method is called, the Interrupt Status register is cleared.
INTStatus
structure where each field maps to the interrupt that occurred; in case of an error, the returned status is fully cleared.
|
inline |
Reset the FIFO buffer (parameter map §4.27).
true | if the operation succeeded |
false | if the operation failed |
|
inline |
Get the number of bytes currently stored in the FIFO buffer (register map §4.30).
This number is a multiple of the size of sensor samples as selected by FIFOEnable
in begin(FIFOEnable, INTEnable, uint8_t, GyroRange, AccelRange, DLPF, ClockSelect)
.
0
, you should read the samples with fifo_pop()
. 0 | if the FIFO buffer is empty or if the operation failed |
|
inline |
Get one sample out of the FIFO buffer (register map §4.31).
fifo_count()
to ensure the MPU6050 FIFO queue contains a sample of the right size! Otherwise this method will not return any error but set arbitrary values to output
! T | the type of sample to get from the FIFO buffer; must be one of Sensor3D , int16_t or AllSensors , based on the sensor samples selected by FIFOEnable in begin(FIFOEnable, INTEnable, uint8_t, GyroRange, AccelRange, DLPF, ClockSelect) . |
output | a reference to a T -type variable that will be filled with the required sample. |
true | if a sample has been read into output |
false | if no sample was ready or if the operation failed |
|
inline |
Push one byte to the FIFO buffer (register map §4.31).
data | the byte value to be pushed |
true | if data has been correctly pushed to the FIFO |
false | if the operation failed |