From cc51c1a7d8a78d88b479e892074347059a1302eb Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 19 Nov 2024 19:00:43 -0500 Subject: [PATCH 01/14] Initialized I2C driver header file with peripheral definitions and function prototypes --- src/drivers/i2c/i2c.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index e69de29..f2f8003 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -0,0 +1,32 @@ +#ifndef I2C_H +#define I2C_H + +#include +#include "stm32h7xx_hal.h" + +typedef enum +{ + I2C_PERIPHERAL_IMU, // Pololu IMU + I2C_PERIPHERAL_BARO, // Barometer + I2C_PERIPHERAL_MAG // Magnetometer +} i2c_peripheral_t; + +typedef enum +{ + I2C_OK = 0, // Operation completed successfully + I2C_ERROR, // General error occurred + I2C_BUSY, // Bus or device busy + I2C_TIMEOUT, // Operation timed out + I2C_NACK // Device did not acknowledge +} i2c_status_t; + +// Must be called before RTOS scheduler starts +i2c_status_t i2c_init(i2c_peripheral_t periph, uint32_t timeout_ms); + +// Read len bytes from reg into data buffer, max 255 byte +i2c_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); + +// Write len bytes from data buffer to reg, max 255 bytes +i2c_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); + +#endif // I2C_H \ No newline at end of file From 8caedb8b699594406a09ec3304d2be1a02b8a4ec Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 19 Nov 2024 19:07:00 -0500 Subject: [PATCH 02/14] forgot to run clang-format on the i2c.h files so wasn't passing the check --- src/drivers/i2c/i2c.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index f2f8003..9462b64 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -1,32 +1,32 @@ #ifndef I2C_H #define I2C_H -#include #include "stm32h7xx_hal.h" +#include -typedef enum -{ - I2C_PERIPHERAL_IMU, // Pololu IMU - I2C_PERIPHERAL_BARO, // Barometer - I2C_PERIPHERAL_MAG // Magnetometer +typedef enum { + I2C_PERIPHERAL_IMU, // Pololu IMU + I2C_PERIPHERAL_BARO, // Barometer + I2C_PERIPHERAL_MAG // Magnetometer } i2c_peripheral_t; -typedef enum -{ - I2C_OK = 0, // Operation completed successfully - I2C_ERROR, // General error occurred - I2C_BUSY, // Bus or device busy - I2C_TIMEOUT, // Operation timed out - I2C_NACK // Device did not acknowledge +typedef enum { + I2C_OK = 0, // Operation completed successfully + I2C_ERROR, // General error occurred + I2C_BUSY, // Bus or device busy + I2C_TIMEOUT, // Operation timed out + I2C_NACK // Device did not acknowledge } i2c_status_t; // Must be called before RTOS scheduler starts i2c_status_t i2c_init(i2c_peripheral_t periph, uint32_t timeout_ms); // Read len bytes from reg into data buffer, max 255 byte -i2c_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); +i2c_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, + uint16_t len); // Write len bytes from data buffer to reg, max 255 bytes -i2c_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); +i2c_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, + uint16_t len); #endif // I2C_H \ No newline at end of file From ca06f01af67b2615450974708c4f0af2b4437594 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 19 Nov 2024 19:21:21 -0500 Subject: [PATCH 03/14] ok actually fixed the clang formatting issues this time --- src/drivers/i2c/i2c.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index 9462b64..f671510 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -5,28 +5,26 @@ #include typedef enum { - I2C_PERIPHERAL_IMU, // Pololu IMU - I2C_PERIPHERAL_BARO, // Barometer - I2C_PERIPHERAL_MAG // Magnetometer + I2C_PERIPHERAL_IMU, // Pololu IMU + I2C_PERIPHERAL_BARO, // Barometer + I2C_PERIPHERAL_MAG // Magnetometer } i2c_peripheral_t; typedef enum { - I2C_OK = 0, // Operation completed successfully - I2C_ERROR, // General error occurred - I2C_BUSY, // Bus or device busy - I2C_TIMEOUT, // Operation timed out - I2C_NACK // Device did not acknowledge + I2C_OK = 0, // Operation completed successfully + I2C_ERROR, // General error occurred + I2C_BUSY, // Bus or device busy + I2C_TIMEOUT, // Operation timed out + I2C_NACK // Device did not acknowledge } i2c_status_t; // Must be called before RTOS scheduler starts i2c_status_t i2c_init(i2c_peripheral_t periph, uint32_t timeout_ms); // Read len bytes from reg into data buffer, max 255 byte -i2c_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, - uint16_t len); +i2c_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); // Write len bytes from data buffer to reg, max 255 bytes -i2c_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, - uint16_t len); +i2c_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); #endif // I2C_H \ No newline at end of file From 31bfd6734ec5b5a0e4cd46f7aeb05c533f1d4e1e Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 19 Nov 2024 21:52:49 -0500 Subject: [PATCH 04/14] Update I2C peripheral definitions for new IMU sensors --- src/drivers/i2c/i2c.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index f671510..e0b136b 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -5,9 +5,10 @@ #include typedef enum { - I2C_PERIPHERAL_IMU, // Pololu IMU - I2C_PERIPHERAL_BARO, // Barometer - I2C_PERIPHERAL_MAG // Magnetometer + I2C_PERIPHERAL_POLULU, // Polulu AltIMU-v6 + I2C_PERIPHERAL_MOVELLA, // Movella mti-630 IMU + I2C_PERIPHERAL_ST, // ST LSM6DSO32 IMU + I2C_PERIPHERAL_COUNT // Number of peripherals } i2c_peripheral_t; typedef enum { From fd19b08bf772acfdab3fb4d820c6790be176df73 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 19 Nov 2024 23:39:45 -0500 Subject: [PATCH 05/14] Refactored I2C header to include common rocketlib and update status type accordingly for each function --- src/drivers/i2c/i2c.h | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index e0b136b..4c786ed 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -1,7 +1,7 @@ #ifndef I2C_H #define I2C_H -#include "stm32h7xx_hal.h" +#include "src/third_party/rocketlib/include/common.h" #include typedef enum { @@ -11,21 +11,12 @@ typedef enum { I2C_PERIPHERAL_COUNT // Number of peripherals } i2c_peripheral_t; -typedef enum { - I2C_OK = 0, // Operation completed successfully - I2C_ERROR, // General error occurred - I2C_BUSY, // Bus or device busy - I2C_TIMEOUT, // Operation timed out - I2C_NACK // Device did not acknowledge -} i2c_status_t; - // Must be called before RTOS scheduler starts -i2c_status_t i2c_init(i2c_peripheral_t periph, uint32_t timeout_ms); +w_status_t i2c_init(i2c_peripheral_t periph, uint32_t timeout_ms); // Read len bytes from reg into data buffer, max 255 byte -i2c_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); +w_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); -// Write len bytes from data buffer to reg, max 255 bytes -i2c_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); +w_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); #endif // I2C_H \ No newline at end of file From e14ea217c3e8f23b4f7a25086ae8289a1d4c7120 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Tue, 19 Nov 2024 23:58:10 -0500 Subject: [PATCH 06/14] Fix include path for common rocketlib in I2C header --- src/drivers/i2c/i2c.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index 4c786ed..e0bf717 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -1,8 +1,8 @@ #ifndef I2C_H #define I2C_H -#include "src/third_party/rocketlib/include/common.h" #include +#include "rocketlib/include/common.h" typedef enum { I2C_PERIPHERAL_POLULU, // Polulu AltIMU-v6 From addd7f0db57443e8bf48fec6fd16e28055a27061 Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 20 Nov 2024 00:32:15 -0500 Subject: [PATCH 07/14] Made write_reg data const since read-only, and change len to uint8_t since max 255 bytes. --- src/drivers/i2c/i2c.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/i2c/i2c.h b/src/drivers/i2c/i2c.h index e0bf717..94613ac 100644 --- a/src/drivers/i2c/i2c.h +++ b/src/drivers/i2c/i2c.h @@ -1,8 +1,8 @@ #ifndef I2C_H #define I2C_H -#include #include "rocketlib/include/common.h" +#include typedef enum { I2C_PERIPHERAL_POLULU, // Polulu AltIMU-v6 @@ -15,8 +15,8 @@ typedef enum { w_status_t i2c_init(i2c_peripheral_t periph, uint32_t timeout_ms); // Read len bytes from reg into data buffer, max 255 byte -w_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); +w_status_t i2c_read_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint8_t len); -w_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, uint8_t *data, uint16_t len); +w_status_t i2c_write_reg(i2c_peripheral_t periph, uint8_t reg, const uint8_t *data, uint8_t len); #endif // I2C_H \ No newline at end of file From ad049a5c4e898949e08856ece48b949427b983fb Mon Sep 17 00:00:00 2001 From: taisirhassan Date: Wed, 20 Nov 2024 01:22:13 -0500 Subject: [PATCH 08/14] Add linker directory for third-party libraries and reorder includes in I2C header --- .cproject | 2 ++ src/drivers/i2c/i2c.c | 1 + src/drivers/i2c/i2c.h | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.cproject b/.cproject index 8da5a20..b81ed69 100644 --- a/.cproject +++ b/.cproject @@ -60,6 +60,7 @@