diff --git a/src/motionDetection/MotionDetection.h b/src/motionDetection/MotionDetection.h index c01d0bb..d275d8e 100644 --- a/src/motionDetection/MotionDetection.h +++ b/src/motionDetection/MotionDetection.h @@ -1,6 +1,100 @@ +/** + * @file MotionDetection.h + * @author Hans Haupt + * @brief This component controls the IMU (Accelerometer & Gyroscope) ICM-42670-P + * @version 0.1 + * @date 2023-12-15 + * + * @copyright Copyright (c) 2023 + * + */ #ifndef MotionDetection_h #define MotionDetection_h -class MotionDetection{ +#include "driver/spi_master.h" +struct IMUResult{ + float x; + float y; + float z; +} + + +class MotionDetection{ +protected: + static const uint8_t MCU_HOST = SPI2_HOST; + static const uint8_t PIN_NUM_MISO = 37; + static const uint8_t PIN_NUM_MOSI = 35; + static const uint8_t PIN_NUM_CLK = 36; + static const uint8_t PIN_NUM_CS = 34; + + static const uint8_t PIN_INT0 = 28; + + + static const uint8_t CMD_READ = 0x80; + static const uint8_t CMD_WRITE = 0x00; + static const uint8_t ADDR_MASK = 0x7F; + + //Registers + static const uint8_t REG_TEMP_LOW = 0x0A; + static const uint8_t REG_TEMP_HIGH = 0X09; + + static const uint8_t ACCEL_DATA_X_HIGH = 0x0B; + static const uint8_t ACCEL_DATA_X_LOW = 0x0C; + static const uint8_t ACCEL_DATA_Y_HIGH = 0x0D; + static const uint8_t ACCEL_DATA_Y_LOW = 0x0E; + static const uint8_t ACCEL_DATA_Z_HIGH = 0x0F; + static const uint8_t ACCEL_DATA_Z_LOW = 0x10; + + static const uint8_t GYRO_DATA_X_HIGH = 0x11; + static const uint8_t GYRO_DATA_X_LOW = 0x12; + static const uint8_t GYRO_DATA_Y_HIGH = 0x13; + static const uint8_t GYRO_DATA_Y_LOW = 0x14; + static const uint8_t GYRO_DATA_Z_HIGH = 0x15; + static const uint8_t GYRO_DATA_Z_LOW = 0x16; + + uint16_t imu_read_double_register(uint8_t lowerByteAddress, spi_device_handle_t * spi); + esp_err_t spi_imu_read(spi_device_handle_t * ctx, uint8_t addr, uint8_t* out_data); + esp_err_t spi_imu_write(spi_device_handle_t* ctx, uint8_t addr, uint8_t data); + void cs_high(spi_transaction_t* t); + void cs_low(spi_transaction_t* t); + +public + MotionDetection(); + + /** + * @brief initialized the IMU Component. + * Wakes the IMU from Standby + * Set configuration + * + */ + void begin(void); + + /** + * @brief stops the component + * Sets the IMU to Low-Power-Mode + * + */ + void end(void); + + /** + * @brief Triggers a new Reading of the accelerationvalues and reads them from the IMU + * + * @return IMUResult that contains the new read values + */ + IMUResult getAcceleration(); + + /** + * @brief Triggers a new reading of the gyroscope and reads the values from the imu + * + * @return IMUResult + */ + IMUResult getRotation(); + + /** + * @brief Reads the current On Chip temperature of the IMU + * + * @return normalized temperature in degree Centigrade + */ + float getTemperature(); }; #endif //MotionDetection \ No newline at end of file