 |
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
60 static const SPI::BitMode SPI_BITMODE = SPI::BitMode::MSB_FIRST;
102 case DPSMode::DPS_250:
103 return rawValue * 0.00875;
104 case DPSMode::DPS_500:
105 return rawValue * 0.01750;
106 case DPSMode::DPS_2000:
107 return rawValue * 0.07000;
122 m_cs(cs,
Pin::Dir::OUT),
123 m_alwaysSetMode(alwaysSetMode) {
135 this->m_alwaysSetMode = alwaysSetMode;
146 void read (int16_t *values)
const {
147 const auto addr =
static_cast<uint8_t
>(Register::OUT_X_L) | BIT_7 | BIT_6;
149 this->maybe_set_spi_mode();
153 values[Axis::X] =
static_cast<int16_t
>(this->m_spi->
shift_in(16));
154 values[Axis::Y] =
static_cast<int16_t
>(this->m_spi->
shift_in(16));
155 values[Axis::Z] =
static_cast<int16_t
>(this->m_spi->
shift_in(16));
161 for (
unsigned int axis = 0; axis <
AXES; ++axis) {
162 temp = (uint32_t) (values[axis] >> 8);
164 values[axis] |= temp;
176 return this->read16(
static_cast<Register
>(
static_cast<unsigned int>(Register::OUT_X_L) + 2 * axis));
185 return this->read16(Register::OUT_X_L);
194 return this->read16(Register::OUT_Y_L);
203 return this->read16(Register::OUT_Z_L);
214 this->maybe_set_spi_mode();
216 uint8_t registerValue = this->
read(Register::CTRL_REG4);
217 registerValue &= ~(BIT_5 | BIT_4);
218 registerValue |= dpsMode;
219 this->
write(Register::CTRL_REG4, registerValue);
230 void write (
const Register address,
const uint8_t registerValue)
const {
231 const uint8_t commandByte =
static_cast<uint8_t
>(address) & ~BIT_7;
232 const uint16_t combinedWord = commandByte << 8 | registerValue;
234 this->maybe_set_spi_mode();
237 this->m_spi->
shift_out(16, combinedWord);
248 uint8_t
read (
const Register address)
const {
250 const uint8_t commandByte =
static_cast<uint8_t
>(address) | BIT_7 | BIT_6;
252 this->maybe_set_spi_mode();
256 const auto registerValue =
static_cast<uint8_t
>(this->m_spi->
shift_in(8));
259 return registerValue;
271 void set_bit (
const Register address,
const Bit bit)
const {
272 const auto startingValue = this->
read(address);
273 this->
write(address, bit | startingValue);
285 void clear_bit (
const Register address,
const Bit bit)
const {
286 const auto startingValue = this->
read(address);
287 this->
write(address, ~bit & startingValue);
298 int16_t read16 (Register address)
const {
300 const uint8_t commandByte =
static_cast<uint8_t
>(address) | BIT_7 | BIT_6;
302 this->maybe_set_spi_mode();
306 uint16_t registerValue =
static_cast<uint16_t
>(this->m_spi->
shift_in(16));
309 uint_fast8_t temp = registerValue >> 8;
311 return static_cast<int16_t
>(registerValue | temp);
319 void maybe_set_spi_mode ()
const {
320 if (this->m_alwaysSetMode) {
329 bool m_alwaysSetMode;
void set_bit_mode(const BitMode bitmode)
Set the bitmode of SPI communication.
int16_t read_y() const
Read data from the Y axis.
void set_dps(const DPSMode dpsMode) const
Modify the scale of L3G in units of degrees per second.
uint8_t read(const Register address) const
Read one byte from the L3G module.
L3G gyroscope driver using SPI communication for the Parallax Propeller.
void set_bit(const Register address, const Bit bit) const
Set a single bit in a register on the device.
SPI serial communications library; Core functionality comes from a dedicated assembly cog.
uint32_t shift_in(const unsigned int bits) const
Read a value from the MISO line.
static double to_dps(const int rawValue, const DPSMode dpsMode)
Convert the raw, integer value from the gyro into units of degrees-per-second.
void write(const Register address, const uint8_t registerValue) const
Write one byte to the L3G module.
L3G(SPI &spi, const Port::Mask cs, const bool alwaysSetMode=false)
Utility class to handle general purpose I/O pins.
int16_t read_z() const
Read data from the Z axis.
void shift_out(uint8_t bits, uint32_t value) const
Send a value out to a peripheral device.
int16_t read_x() const
Read data from the X axis.
int16_t read(const Axis axis) const
Read a specific axis's data.
void set() const
Set selected output port high (set all pins to 1)
void set_mode(const Mode mode)
Set the mode of SPI communication.
void clear_bit(const Register address, const Bit bit) const
Clear a single bit in a register on the device.
void read(int16_t *values) const
Read data from all three axes.
BitMode
Determine if data is communicated with the LSB or MSB sent/received first.
Generic definitions and functions for the Parallax Propeller.
void clear() const
Clear selected output port (set it to 0)
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...
Mode
Descriptor for SPI signal as defined by Motorola modes.