1
0
forked from me/IronOS

Speed up accelerometer data intake.

The LIS2DH12 driver performed an unnecessary endianness conversion, as
data from the sensor was already coming in little-endian format.  The
MMA8652FC driver is now using the rev16 opcode to perform the swap
rather than doing all the bitshuffling operations in multiple steps.
This commit is contained in:
Alessandro Gatti
2019-08-29 04:03:54 +02:00
parent c96f1b528a
commit 5eb3df47df
5 changed files with 29 additions and 23 deletions

View File

@@ -5,9 +5,10 @@
* Author: Ralim
*/
#include <LIS2DH12.hpp>
#include "cmsis_os.h"
#include <array>
#include "LIS2DH12.hpp"
#include "cmsis_os.h"
typedef struct {
const uint8_t reg;
@@ -36,14 +37,14 @@ void LIS2DH12::initalize() {
}
}
void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) {
uint8_t tempArr[6];
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT,
(uint8_t*) tempArr, 6);
void LIS2DH12::getAxisReadings(int16_t& x, int16_t& y, int16_t& z) {
std::array<int16_t, 3> sensorData;
(*x) = ((uint16_t) (tempArr[1] << 8 | tempArr[0]));
(*y) = ((uint16_t) (tempArr[3] << 8 | tempArr[2]));
(*z) = ((uint16_t) (tempArr[5] << 8 | tempArr[4]));
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT,
reinterpret_cast<uint8_t*>(sensorData.begin()),
sensorData.size() * sizeof(int16_t));
x = sensorData[0];
y = sensorData[1];
z = sensorData[2];
}