PropWare  3.0.0.224
C++ objects and CMake build system for Parallax Propeller
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
PropWare::L3G Class Reference

L3G gyroscope driver using SPI communication for the Parallax Propeller. More...

#include <PropWare/sensor/gyroscope/l3g.h>

+ Collaboration diagram for PropWare::L3G:

Public Types

enum  Axis {
  X,
  Y,
  Z,
  AXES
}
 
enum  DPSMode {
  DPS_250 = 0x00,
  DPS_500 = 0x10,
  DPS_2000 = 0x20
}
 
enum  Register {
  WHO_AM_I = 0x0F,
  CTRL_REG1 = 0x20,
  CTRL_REG2 = 0x21,
  CTRL_REG3 = 0x22,
  CTRL_REG4 = 0x23,
  CTRL_REG5 = 0x24,
  REFERENCE = 0x25,
  OUT_TEMP = 0x26,
  STATUS_REG = 0x27,
  OUT_X_L = 0x28,
  OUT_X_H = 0x29,
  OUT_Y_L = 0x2A,
  OUT_Y_H = 0x2B,
  OUT_Z_L = 0x2C,
  OUT_Z_H = 0x2D,
  FIFO_CTRL_REG = 0x2E,
  FIFO_SRC_REG = 0x2F,
  INT1_CFG = 0x30,
  INT1_SRC = 0x31,
  INT1_THS_XH = 0x32,
  INT1_THS_XL = 0x33,
  INT1_THS_YH = 0x34,
  INT1_THS_YL = 0x35,
  INT1_THS_ZH = 0x36,
  INT1_THS_ZL = 0x37,
  INT1_DURATION = 0x38
}
 

Public Member Functions

 L3G (SPI &spi, const Port::Mask cs, const bool alwaysSetMode=false)
 
void always_set_spi_mode (const bool alwaysSetMode)
 Choose whether to always set the SPI mode and bitmode before reading or writing to the L3G module; Useful when multiple devices are connected to the SPI bus. More...
 
void read (int16_t *values) const
 Read data from all three axes. More...
 
int16_t read (const Axis axis) const
 Read a specific axis's data. More...
 
int16_t read_x () const
 Read data from the X axis. More...
 
int16_t read_y () const
 Read data from the Y axis. More...
 
int16_t read_z () const
 Read data from the Z axis. More...
 
void set_dps (const DPSMode dpsMode) const
 Modify the scale of L3G in units of degrees per second. More...
 
void write (const Register address, const uint8_t registerValue) const
 Write one byte to the L3G module. More...
 
uint8_t read (const Register address) const
 Read one byte from the L3G module. More...
 
void set_bit (const Register address, const Bit bit) const
 Set a single bit in a register on the device. More...
 
void clear_bit (const Register address, const Bit bit) const
 Clear a single bit in a register on the device. More...
 

Static Public Member Functions

static double to_dps (const int rawValue, const DPSMode dpsMode)
 Convert the raw, integer value from the gyro into units of degrees-per-second. More...
 

Static Public Attributes

static const SPI::Mode SPI_MODE = SPI::Mode::MODE_3
 
static const SPI::BitMode SPI_BITMODE = SPI::BitMode::MSB_FIRST
 

Detailed Description

L3G gyroscope driver using SPI communication for the Parallax Propeller.

Examples
L3G_Demo.cpp.

Definition at line 37 of file l3g.h.

Member Enumeration Documentation

◆ Axis

Axes of the L3G device

Enumerator

X axis

Y axis

Z axis

AXES 

Number of axes

Definition at line 42 of file l3g.h.

◆ DPSMode

Sensitivity measured in degrees per second

Enumerator
DPS_250 

250 degrees per second

DPS_500 

500 degrees per second

DPS_2000 

2000 degrees per second

Definition at line 52 of file l3g.h.

Constructor & Destructor Documentation

◆ L3G()

PropWare::L3G::L3G ( SPI spi,
const Port::Mask  cs,
const bool  alwaysSetMode = false 
)
Parameters
[in]spiSPI bus used for communication with the L3G device
[in]csChip select pin mask
[in]dpsModePrecision to be used, measured in degrees per second
[in]alwaysSetModeWhen set, the SPI object will always have its mode reset, before every read or write operation

Definition at line 120 of file l3g.h.

Member Function Documentation

◆ always_set_spi_mode()

void PropWare::L3G::always_set_spi_mode ( const bool  alwaysSetMode)

Choose whether to always set the SPI mode and bitmode before reading or writing to the L3G module; Useful when multiple devices are connected to the SPI bus.

Parameters
[in]alwaysSetModeFor any non-zero value, the SPI modes will always be set before a read or write routine

Definition at line 134 of file l3g.h.

◆ clear_bit()

void PropWare::L3G::clear_bit ( const Register  address,
const Bit  bit 
) const

Clear a single bit in a register on the device.

This method is highly inefficient (runtime performance) for multi-bit modifications. Use this only when code size or code legibility is more important than runtime performance.

Parameters
[in]addressAddress of the register to modify
[in]bitBit in the register that should be cleared low

Definition at line 285 of file l3g.h.

◆ read() [1/3]

void PropWare::L3G::read ( int16_t *  values) const

Read data from all three axes.

Parameters
[out]valuesStarting address for data to be placed; 6 contiguous bytes of space are required for the read routine
Returns
Returns 0 upon success, error code otherwise

Definition at line 146 of file l3g.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read() [2/3]

int16_t PropWare::L3G::read ( const Axis  axis) const

Read a specific axis's data.

Parameters
[in]axisSelects the axis to be read
Returns
Returns 0 upon success, error code otherwise

Definition at line 175 of file l3g.h.

◆ read() [3/3]

uint8_t PropWare::L3G::read ( const Register  address) const

Read one byte from the L3G module.

Parameters
[in]addressOrigin register address
Returns
Returns 0 upon success, error code otherwise

Definition at line 248 of file l3g.h.

+ Here is the call graph for this function:

◆ read_x()

int16_t PropWare::L3G::read_x ( ) const

Read data from the X axis.

Returns
Returns 0 upon success, error code otherwise

Definition at line 184 of file l3g.h.

◆ read_y()

int16_t PropWare::L3G::read_y ( ) const

Read data from the Y axis.

Returns
Returns 0 upon success, error code otherwise

Definition at line 193 of file l3g.h.

◆ read_z()

int16_t PropWare::L3G::read_z ( ) const

Read data from the Z axis.

Returns
Returns 0 upon success, error code otherwise

Definition at line 202 of file l3g.h.

◆ set_bit()

void PropWare::L3G::set_bit ( const Register  address,
const Bit  bit 
) const

Set a single bit in a register on the device.

This method is highly inefficient (runtime performance) for multi-bit modifications. Use this only when code size or code legibility is more important than runtime performance.

Parameters
[in]addressAddress of the register to modify
[in]bitBit in the register that should be set high

Definition at line 271 of file l3g.h.

◆ set_dps()

void PropWare::L3G::set_dps ( const DPSMode  dpsMode) const

Modify the scale of L3G in units of degrees per second.

Parameters
[in]dpsModeDesired full-scale mode
Returns
Returns 0 upon success, error code otherwise

Definition at line 213 of file l3g.h.

+ Here is the call graph for this function:

◆ to_dps()

static double PropWare::L3G::to_dps ( const int  rawValue,
const DPSMode  dpsMode 
)
static

Convert the raw, integer value from the gyro into units of degrees-per-second.

Parameters
[in]rawValueValue from the gyroscope
[in]dpsModeThe DPS setting used at the time of reading rawValue
Returns
Returns the rotational value in degrees-per-second

Definition at line 100 of file l3g.h.

◆ write()

void PropWare::L3G::write ( const Register  address,
const uint8_t  registerValue 
) const

Write one byte to the L3G module.

Parameters
[in]addressDestination register address
[in]valueData to be written to the destination register
Returns
Returns 0 upon success, error code otherwise

Definition at line 230 of file l3g.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: