Reduce code size for accelerometer support (#288)

* Reduce the LIS2DH12 driver's code size.
* Reduce the MMA8652FC driver's code size.
* Make orientation detection smaller.


* Inlined C++ class constructor.
* De-unroll I2C register writes.
* Removed unused setSensitivity method.
This commit is contained in:
Alessandro Gatti
2018-05-10 02:02:29 +02:00
committed by Ben V. Brown
parent 4718efe79b
commit 215fe8e9e8
6 changed files with 76 additions and 75 deletions

View File

@@ -10,16 +10,16 @@
#include "stm32f1xx_hal.h"
#include "FRToSI2C.hpp"
#include "LIS2DH12_defines.hpp"
#include "hardware.h"
class LIS2DH12 {
public:
LIS2DH12(FRToSI2C* i2cHandle);
LIS2DH12(FRToSI2C* i2cHandle) : i2c(i2cHandle) {}
void initalize();
uint8_t getOrientation();
Orientation getOrientation() { return static_cast<Orientation>((I2C_RegisterRead(LIS_INT2_SRC) >> 2) - 1); }
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
private:
void setSensitivity(uint8_t threshold, uint8_t filterTime); // Sets the sensitivity of the unit
void I2C_RegisterWrite(uint8_t reg, uint8_t data);
uint8_t I2C_RegisterRead(uint8_t reg);
FRToSI2C* i2c;

View File

@@ -10,17 +10,18 @@
#include "stm32f1xx_hal.h"
#include "MMA8652FC_defines.h"
#include "FRToSI2C.hpp"
#include "hardware.h"
class MMA8652FC {
public:
MMA8652FC(FRToSI2C* i2cHandle);
MMA8652FC(FRToSI2C* i2cHandle) : i2c(i2cHandle) {}
void initalize(); // Initalize the system
uint8_t getOrientation();// Reads the I2C register and returns the orientation (true == left)
Orientation getOrientation();// Reads the I2C register and returns the orientation (true == left)
void getAxisReadings(int16_t *x, int16_t *y, int16_t *z);
private:
void setSensitivity(uint8_t threshold, uint8_t filterTime); // Sets the sensitivity of the unit
void I2C_RegisterWrite(uint8_t reg, uint8_t data);
uint8_t I2C_RegisterRead(uint8_t reg);

View File

@@ -13,6 +13,12 @@
extern "C" {
#endif
enum Orientation {
ORIENTATION_LEFT_HAND = 0,
ORIENTATION_RIGHT_HAND = 1,
ORIENTATION_FLAT = 3
};
#define KEY_B_Pin GPIO_PIN_6
#define KEY_B_GPIO_Port GPIOA
#define TMP36_INPUT_Pin GPIO_PIN_7