59 static const uint8_t WHO_AM_I = 0x0F;
61 static const uint8_t CTRL_REG1 = 0x20;
62 static const uint8_t CTRL_REG2 = 0x21;
63 static const uint8_t CTRL_REG3 = 0x22;
64 static const uint8_t CTRL_REG4 = 0x23;
65 static const uint8_t CTRL_REG5 = 0x24;
66 static const uint8_t REFERENCE = 0x25;
67 static const uint8_t OUT_TEMP = 0x26;
68 static const uint8_t STATUS_REG = 0x27;
69 static const uint8_t OUT_X_L = 0x28;
70 static const uint8_t OUT_X_H = 0x29;
71 static const uint8_t OUT_Y_L = 0x2A;
72 static const uint8_t OUT_Y_H = 0x2B;
73 static const uint8_t OUT_Z_L = 0x2C;
74 static const uint8_t OUT_Z_H = 0x2D;
76 static const uint8_t FIFO_CTRL_REG = 0x2E;
77 static const uint8_t FIFO_SRC_REG = 0x2F;
79 static const uint8_t INT1_CFG = 0x30;
80 static const uint8_t INT1_SRC = 0x31;
81 static const uint8_t INT1_THS_XH = 0x32;
82 static const uint8_t INT1_THS_XL = 0x33;
83 static const uint8_t INT1_THS_YH = 0x34;
84 static const uint8_t INT1_THS_YL = 0x35;
85 static const uint8_t INT1_THS_ZH = 0x36;
86 static const uint8_t INT1_THS_ZL = 0x37;
87 static const uint8_t INT1_DURATION = 0x38;
98 this->m_alwaysSetMode =
false;
106 this->m_spi->
set_mode(PropWare::L3G::SPI_MODE);
108 this->m_spi->
set_clock(PropWare::L3G::SPI_DEFAULT_FREQ);
115 this->write8(PropWare::L3G::CTRL_REG1, NIBBLE_0);
116 this->write8(PropWare::L3G::CTRL_REG4, BIT_7);
127 this->m_alwaysSetMode = alwaysSetMode;
138 return this->read16(PropWare::L3G::OUT_X_L + (axis << 1));
147 return this->read16(PropWare::L3G::OUT_X_L);
156 return this->read16(PropWare::L3G::OUT_Y_L);
165 return this->read16(PropWare::L3G::OUT_Z_L);
179 uint8_t addr = PropWare::L3G::OUT_X_L;
183 this->maybe_set_spi_mode();
195 for (i = 0; i < 3; ++i) {
196 temp = (uint32_t) (val[i] >> 8);
212 this->m_dpsMode = dpsMode;
213 this->maybe_set_spi_mode();
215 oldValue = this->read8(PropWare::L3G::CTRL_REG4);
216 oldValue &= ~(BIT_5 | BIT_4);
218 this->write8(PropWare::L3G::CTRL_REG4, oldValue);
227 return this->m_dpsMode;
258 return (
float) (rawValue * 0.00875);
260 return (
float) (rawValue * 0.01750);
262 return (
float) (rawValue * 0.07000);
268 static const uint32_t SPI_DEFAULT_FREQ = 100000;
284 void write8 (uint8_t addr,
const uint8_t dat)
const {
285 uint16_t outputValue;
289 outputValue = ((uint16_t) addr) << 8;
292 this->maybe_set_spi_mode();
307 void write16 (uint8_t addr,
const uint16_t dat)
const {
308 uint16_t outputValue;
313 outputValue = ((uint16_t) addr) << 16;
314 outputValue |= ((uint16_t) ((uint8_t) dat)) << 8;
315 outputValue |= (uint8_t) (dat >> 8);
317 this->maybe_set_spi_mode();
331 uint8_t read8 (uint8_t addr)
const {
337 this->maybe_set_spi_mode();
341 dat = (int8_t) this->m_spi->
shift_in(8);
354 int16_t read16 (uint8_t addr)
const {
361 this->maybe_set_spi_mode();
365 dat = (int16_t) this->m_spi->
shift_in(16);
373 return (int16_t) (dat | temp);
381 void maybe_set_spi_mode ()
const {
382 if (this->m_alwaysSetMode) {
383 this->m_spi->
set_mode(L3G::SPI_MODE);
392 bool m_alwaysSetMode;
void set_mask(const PropWare::Port::Mask mask)
Utility class to handle general purpose I/O pins.
void set_dir(const PropWare::Port::Dir direction) const
Set port as either input or output.
void clear() const
Clear selected output port (set it to 0)
Generic definitions and functions for the Parallax Propeller.
PropWare::ErrorCode set_clock(const int32_t frequency)
Change the SPI module's clock frequency.
static float convert_to_dps(const int16_t rawValue, const PropWare::L3G::DPSMode dpsMode)
Convert the raw, integer value from the gyro into units of degrees-per-second.
void start()
Initialize an L3G module.
L3G gyroscope driver using SPI communication for the Parallax Propeller.
L3G(SPI *spi, const PropWare::Port::Mask cs)
Construction requires an instance of the SPI module.
void shift_out(uint8_t bits, uint32_t value) const
Send a value out to a peripheral device.
Mode
Descriptor for SPI signal as defined by Motorola modes.
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; Us...
float convert_to_dps(const int16_t rawValue) const
Convert the raw, integer value from the gyro into units of degrees-per-second.
PropWare::L3G::DPSMode get_dps() const
Retrieve the current DPS setting.
void set_bit_mode(const BitMode bitmode)
Set the bitmode of SPI communication.
BitMode
Determine if data is communicated with the LSB or MSB sent/received first.
void set() const
Set selected output port high (set all pins to 1)
void read_all(int16_t *val) const
Read data from all three axes.
void set_mode(const Mode mode)
Set the mode of SPI communication.
SPI serial communications library; Core functionality comes from a dedicated assembly cog...
int16_t read(const PropWare::L3G::Axis axis) const
Read a specific axis's data.
void set_dps(const PropWare::L3G::DPSMode dpsMode)
Modify the scale of L3G in units of degrees per second.
int16_t read_x() const
Read data from the X axis.
int16_t read_z() const
Read data from the Z axis.
uint32_t shift_in(const unsigned int bits) const
Read a value from the MISO line.
int16_t read_y() const
Read data from the Y axis.