From 96ab0c63b508b6f6ad66d46ef8cc7ec9c3a32220 Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Fri, 3 Sep 2021 15:30:18 -0400 Subject: [PATCH] provide data types for the sensor output and collect timestamps Also, what the heck is an 'interger'? --- Drivers/EM7180/Inc/em7180.h | 45 ++++++++++++++++++++++---- Drivers/EM7180/Src/em7180.c | 64 ++++++++++++++++++++----------------- 2 files changed, 74 insertions(+), 35 deletions(-) diff --git a/Drivers/EM7180/Inc/em7180.h b/Drivers/EM7180/Inc/em7180.h index f22b5a1..2ce030c 100644 --- a/Drivers/EM7180/Inc/em7180.h +++ b/Drivers/EM7180/Inc/em7180.h @@ -45,6 +45,39 @@ typedef struct em7180_s i2c_read_func_t i2c_read_func; i2c_write_func_t i2c_write_func; } em7180_t; +typedef struct em7180_quat_data_s { + float x; + float y; + float z; + float w; + uint16_t ts; +} em7180_quat_data_t; +typedef struct em7180_accel_data_s { + int16_t x; + int16_t y; + int16_t z; + uint16_t ts; +} em7180_accel_data_t; +typedef struct em7180_gyro_data_s { + int16_t x; + int16_t y; + int16_t z; + uint16_t ts; +} em7180_gyro_data_t; +typedef struct em7180_mag_data_s { + int16_t x; + int16_t y; + int16_t z; + uint16_t ts; +} em7180_mag_data_t; +typedef struct em7180_baro_data_s { + int16_t pressure; + uint16_t ts; +} em7180_baro_data_t; +typedef struct em7180_temp_data_s { + int16_t val; + uint16_t ts; +} em7180_temp_data_t; /* Function Prototypes */ em7180_status_t em7180_init(em7180_t *em7180, em7180_init_t *init); @@ -55,11 +88,11 @@ em7180_status_t em7180_config(em7180_t *em7180); void em7180_reset(em7180_t *em7180); void em7180_passthrough_enable(em7180_t *em7180); void em7180_passthrough_disable(em7180_t *em7180); -em7180_status_t em7180_quatdata_get(em7180_t *em7180, float *destination); -em7180_status_t em7180_acceldata_get(em7180_t *em7180, int16_t *destination); -em7180_status_t em7180_gyrodata_get(em7180_t *em7180, int16_t *destination); -em7180_status_t em7180_magdata_get(em7180_t *em7180, int16_t *destination); -em7180_status_t em7180_barodata_get(em7180_t *em7180, int16_t *destination); -em7180_status_t em7180_tempdata_get(em7180_t *em7180, int16_t *destination); +em7180_status_t em7180_quatdata_get(em7180_t *em7180, em7180_quat_data_t *destination); +em7180_status_t em7180_acceldata_get(em7180_t *em7180, em7180_accel_data_t *destination); +em7180_status_t em7180_gyrodata_get(em7180_t *em7180, em7180_gyro_data_t *destination); +em7180_status_t em7180_magdata_get(em7180_t *em7180, em7180_mag_data_t *destination); +em7180_status_t em7180_barodata_get(em7180_t *em7180, em7180_baro_data_t *destination); +em7180_status_t em7180_tempdata_get(em7180_t *em7180, em7180_temp_data_t *destination); #endif /* EM7180_H_ */ diff --git a/Drivers/EM7180/Src/em7180.c b/Drivers/EM7180/Src/em7180.c index b78b17d..e31b160 100644 --- a/Drivers/EM7180/Src/em7180.c +++ b/Drivers/EM7180/Src/em7180.c @@ -40,9 +40,9 @@ #define EM7180_GY 0x24 /* int16_t from registers 0x24-25 */ #define EM7180_GZ 0x26 /* int16_t from registers 0x26-27 */ #define EM7180_GTIME 0x28 /* uint16_t from registers 0x28-29 */ -#define EM7180_Baro 0x2A /* start of two-byte MS5637 pressure data, 16-bit signed interger */ +#define EM7180_Baro 0x2A /* start of two-byte MS5637 pressure data, 16-bit signed integer */ #define EM7180_BaroTIME 0x2C /* start of two-byte MS5637 pressure timestamp, 16-bit unsigned */ -#define EM7180_Temp 0x2E /* start of two-byte MS5637 temperature data, 16-bit signed interger */ +#define EM7180_Temp 0x2E /* start of two-byte MS5637 temperature data, 16-bit signed integer */ #define EM7180_TempTIME 0x30 /* start of two-byte MS5637 temperature timestamp, 16-bit unsigned */ #define EM7180_QRateDivisor 0x32 /* uint8_t */ #define EM7180_EnableEvents 0x33 @@ -194,80 +194,86 @@ void em7180_passthrough_disable(em7180_t *em7180) em7180_write_byte(EM7180_AlgorithmControl, 0x00); } -em7180_status_t em7180_quatdata_get(em7180_t *em7180, float *destination) +em7180_status_t em7180_quatdata_get(em7180_t *em7180, em7180_quat_data_t *destination) { int32_t ret = 0; uint8_t data[16]; - ret |= em7180_read(EM7180_QX, data, 16); + ret |= em7180_read(EM7180_QX, data, 18); /* EM7180 quaternion is xi + yj + zk + s */ - destination[0] = uint32_reg_to_float(&data[12]); - destination[1] = uint32_reg_to_float(&data[0]); - destination[2] = uint32_reg_to_float(&data[4]); - destination[3] = uint32_reg_to_float(&data[8]); + destination->w = uint32_reg_to_float(&data[12]); + destination->x = uint32_reg_to_float(&data[0]); + destination->y = uint32_reg_to_float(&data[4]); + destination->z = uint32_reg_to_float(&data[8]); + destination->ts = (((int16_t) data[17] << 8) | data[16]); return ret ? EM7180_BAD_COMM : EM7180_OK; } -em7180_status_t em7180_acceldata_get(em7180_t *em7180, int16_t *destination) +em7180_status_t em7180_acceldata_get(em7180_t *em7180, em7180_accel_data_t *destination) { int32_t ret = 0; uint8_t data[6]; - ret |= em7180_read(EM7180_AX, data, 6); - destination[0] = (int16_t) (((int16_t) data[1] << 8) | data[0]); - destination[1] = (int16_t) (((int16_t) data[3] << 8) | data[2]); - destination[2] = (int16_t) (((int16_t) data[5] << 8) | data[4]); + ret |= em7180_read(EM7180_AX, data, 8); + destination->x = (int16_t) (((int16_t) data[1] << 8) | data[0]); + destination->y = (int16_t) (((int16_t) data[3] << 8) | data[2]); + destination->z = (int16_t) (((int16_t) data[5] << 8) | data[4]); + destination->ts = (int16_t) (((int16_t) data[7] << 8) | data[6]); return ret ? EM7180_BAD_COMM : EM7180_OK; } -em7180_status_t em7180_gyrodata_get(em7180_t *em7180, int16_t *destination) +em7180_status_t em7180_gyrodata_get(em7180_t *em7180, em7180_gyro_data_t *destination) { int32_t ret = 0; uint8_t data[6]; - ret |= em7180_read(EM7180_GX, data, 6); - destination[0] = (int16_t) (((int16_t) data[1] << 8) | data[0]); - destination[1] = (int16_t) (((int16_t) data[3] << 8) | data[2]); - destination[2] = (int16_t) (((int16_t) data[5] << 8) | data[4]); + ret |= em7180_read(EM7180_GX, data, 8); + destination->x = (int16_t) (((int16_t) data[1] << 8) | data[0]); + destination->y = (int16_t) (((int16_t) data[3] << 8) | data[2]); + destination->z = (int16_t) (((int16_t) data[5] << 8) | data[4]); + destination->ts = (int16_t) (((int16_t) data[7] << 8) | data[6]); return ret ? EM7180_BAD_COMM : EM7180_OK; } -em7180_status_t em7180_magdata_get(em7180_t *em7180, int16_t *destination) +em7180_status_t em7180_magdata_get(em7180_t *em7180, em7180_mag_data_t *destination) { int32_t ret = 0; uint8_t data[6]; - ret |= em7180_read(EM7180_MX, data, 6); - destination[0] = (int16_t) (((int16_t) data[1] << 8) | data[0]); - destination[1] = (int16_t) (((int16_t) data[3] << 8) | data[2]); - destination[2] = (int16_t) (((int16_t) data[5] << 8) | data[4]); + ret |= em7180_read(EM7180_MX, data, 8); + destination->x = (int16_t) (((int16_t) data[1] << 8) | data[0]); + destination->y = (int16_t) (((int16_t) data[3] << 8) | data[2]); + destination->z = (int16_t) (((int16_t) data[5] << 8) | data[4]); + destination->ts = (int16_t) (((int16_t) data[7] << 8) | data[6]); return ret ? EM7180_BAD_COMM : EM7180_OK; } -em7180_status_t em7180_barodata_get(em7180_t *em7180, int16_t *destination) +em7180_status_t em7180_barodata_get(em7180_t *em7180, em7180_baro_data_t *destination) { int32_t ret = 0; uint8_t data[2]; - ret |= em7180_read(EM7180_Baro, data, 2); + ret |= em7180_read(EM7180_Baro, data, 4); - *destination = (((int16_t) data[1] << 8) | data[0]); + destination->pressure = (((int16_t) data[1] << 8) | data[0]); + destination->ts = (int16_t) (((int16_t) data[3] << 8) | data[2]); return ret ? EM7180_BAD_COMM : EM7180_OK; } -em7180_status_t em7180_tempdata_get(em7180_t *em7180, int16_t *destination) +em7180_status_t em7180_tempdata_get(em7180_t *em7180, em7180_temp_data_t *destination) { int32_t ret = 0; uint8_t data[2]; - ret |= em7180_read(EM7180_Temp, data, 2); + ret |= em7180_read(EM7180_Temp, data, 4); - *destination = (((int16_t) data[1] << 8) | data[0]); + destination->val = (((int16_t) data[1] << 8) | data[0]); + destination->ts = (int16_t) (((int16_t) data[3] << 8) | data[2]); return ret ? EM7180_BAD_COMM : EM7180_OK; }