diff --git a/cangen/can-messages/mpu.json b/cangen/can-messages/mpu.json index 41216d4..9a9f236 100644 --- a/cangen/can-messages/mpu.json +++ b/cangen/can-messages/mpu.json @@ -131,21 +131,6 @@ } ] } - , - { - "name": "MPU/State/TorqueLimit", - "unit": "percentage", - "sim_min": 0, - "sim_max": 1, - "sim_inc_min": 0.1, - "sim_inc_max": 0.1, - "points": [ - { - "size": 8, - "format": "divide100" - } - ] - } ] }, { @@ -373,6 +358,22 @@ "format": "divide10000" } ] + }, + { + "name": "MPU/Sense/SOC", + "unit": "%", + "sim": { + "min": 5, + "max": 99, + "inc_min": 0.1, + "inc_max": 0.5 + }, + "points": [ + { + "size": 8, + "endianness": "little" + } + ] } ] }, @@ -933,4 +934,4 @@ } ] } -] \ No newline at end of file +] diff --git a/cangen/can-messages/msb.json b/cangen/can-messages/msb.json index 858f44d..03892c3 100644 --- a/cangen/can-messages/msb.json +++ b/cangen/can-messages/msb.json @@ -43,12 +43,12 @@ "fields": [ { "name": "MSB/FL/Accel", - "unit": "g", + "unit": "mg", "sim": { - "min": 0, - "max": 2, - "inc_min": 0.01, - "inc_max": 0.25 + "min": -2000, + "max": 2000, + "inc_min": 0.1, + "inc_max": 2.5 }, "points": [ { @@ -74,13 +74,13 @@ "fields": [ { "name": "MSB/FL/Gyro", + "unit": "mdps", "sim": { - "min": 0, - "max": 15, - "inc_min": 0.1, - "inc_max": 0.5 + "min": -500000, + "max": 500000, + "inc_min": 10, + "inc_max": 1000 }, - "unit": "", "points": [ { "size": 16, @@ -234,12 +234,12 @@ "fields": [ { "name": "MSB/FR/Accel", - "unit": "g", + "unit": "mg", "sim": { - "min": 0, - "max": 2, - "inc_min": 0.01, - "inc_max": 0.25 + "min": -2000, + "max": 2000, + "inc_min": 0.1, + "inc_max": 2.5 }, "points": [ { @@ -265,12 +265,12 @@ "fields": [ { "name": "MSB/FR/Gyro", - "unit": "", + "unit": "mdps", "sim": { - "min": 0, - "max": 15, - "inc_min": 0.1, - "inc_max": 0.5 + "min": -500000, + "max": 500000, + "inc_min": 10, + "inc_max": 1000 }, "points": [ { @@ -425,12 +425,12 @@ "fields": [ { "name": "MSB/BL/Accel", - "unit": "g", + "unit": "mg", "sim": { - "min": 0, - "max": 2, - "inc_min": 0.01, - "inc_max": 0.25 + "min": -2000, + "max": 2000, + "inc_min": 0.1, + "inc_max": 2.5 }, "points": [ { @@ -456,12 +456,12 @@ "fields": [ { "name": "MSB/BL/Gyro", - "unit": "", + "unit": "mdps", "sim": { - "min": 0, - "max": 15, - "inc_min": 0.1, - "inc_max": 0.5 + "min": -500000, + "max": 500000, + "inc_min": 10, + "inc_max": 1000 }, "points": [ { @@ -616,12 +616,12 @@ "fields": [ { "name": "MSB/BR/Accel", - "unit": "g", + "unit": "mg", "sim": { - "min": 0, - "max": 2, - "inc_min": 0.01, - "inc_max": 0.25 + "min": -2000, + "max": 2000, + "inc_min": 0.1, + "inc_max": 2.5 }, "points": [ { @@ -647,12 +647,12 @@ "fields": [ { "name": "MSB/BR/Gyro", - "unit": "", + "unit": "mdps", "sim": { - "min": 0, - "max": 15, - "inc_min": 0.1, - "inc_max": 0.5 + "min": -500000, + "max": 500000, + "inc_min": 10, + "inc_max": 1000 }, "points": [ { diff --git a/general/include/pca9539.h b/general/include/pca9539.h index 72a392a..98b0937 100644 --- a/general/include/pca9539.h +++ b/general/include/pca9539.h @@ -5,8 +5,7 @@ #include /* -PCA 9539 16 bit GPIO expander. Datasheet: -https://www.ti.com/lit/ds/symlink/pca9539.pdf?ts=1716785085909 +PCA 9539 16 bit GPIO expander. Datasheet: https://www.ti.com/lit/ds/symlink/pca9539.pdf?ts=1716785085909 */ /// Possible I2C addresses, see comment below @@ -36,31 +35,83 @@ PCA 9539 16 bit GPIO expander. Datasheet: #define PCA_DIRECTION_0_REG 0x06 #define PCA_DIRECTION_1_REG 0x07 +/** + * @brief Pointer to write function + * + */ +typedef int (*WritePtr)(uint16_t dev_addr, uint16_t mem_address, + uint16_t mem_add_size, uint8_t *data, uint16_t size, + int delay); + +/** + * @brief Pointer to read function + * + */ +typedef int (*ReadPtr)(uint16_t dev_addr, uint16_t mem_address, + uint16_t mem_add_size, uint8_t *data, uint16_t size, + int delay); + typedef struct { - I2C_HandleTypeDef *i2c_handle; + WritePtr write; + ReadPtr read; + uint16_t dev_addr; } pca9539_t; -/// Init PCA9539, a 16 bit I2C GPIO expander -void pca9539_init(pca9539_t *pca, I2C_HandleTypeDef *i2c_handle, +/** + * @brief Initialize the PCA9539 Driver + * + * @param pca pointer to a new driver struct + * @param writeFunc function pointer to HAL specific write func + * @param readFunc function pointer to HAL specific read func + * @param dev_addr i2c device address + */ +void pca9539_init(pca9539_t *pca, WritePtr writeFunc, ReadPtr readFunc, uint8_t dev_addr); -/// @brief Read all pins on a bus, for example using reg_type input to get -/// incoming logic level -HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, - uint8_t *buf); -/// @brief Read a specific pin on a bus, do not iterate over this, use read_pins -/// instead -HAL_StatusTypeDef pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, - uint8_t pin, uint8_t *buf); - -/// @brief Write all pins on a bus, for example using reg_type OUTPUT to set -/// logic level or DIRECTION to set as output -HAL_StatusTypeDef pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, - uint8_t buf); -/// @brief Write a specific pin on a bus, do not iterate over this, use -/// write_pins instead -HAL_StatusTypeDef pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, - uint8_t pin, uint8_t buf); +/** + * @brief Read the register of the PCA9539 + * + * @param pca pointer to driver struct with read & write funcs + * @param reg_type type of register being read + * @param buf pointer to buffer storing reg data + * @return int Error code return + */ +int pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, uint8_t *buf); + +/** + * @brief Read the pin state of the PCA9539 + * + * @param pca pointer to driver struct with read & write funcs + * @param reg_type type of register being read + * @param pin pin num to read + * @param buf pointer storing buffer state + * @return int Error code return + */ +int pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, uint8_t pin, + uint8_t *buf); + +/** + + * @brief Write the register of the PCA9539 + * + * @param pca pointer to driver struct with read & write funcs + * @param reg_type type of register being written to + * @param buf pointer with value to write to reg + * @return int Error code return + */ +int pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, uint8_t buf); + +/** + * @brief Write the pin of the PCA9539 + * + * @param pca pointer to driver struct with read & write funcs + * @param reg_type type of register being written to + * @param pin pin to modify + * @param buf pointer with value to write to reg + * @return int Error code return + */ +int pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, uint8_t pin, + uint8_t buf); #endif \ No newline at end of file diff --git a/general/src/pca9539.c b/general/src/pca9539.c index 6e62f2f..2cac0ec 100644 --- a/general/src/pca9539.c +++ b/general/src/pca9539.c @@ -4,31 +4,39 @@ #define REG_SIZE_BITS 8 -HAL_StatusTypeDef pca_write_reg(pca9539_t *pca, uint16_t address, uint8_t *data) +int pca_write_reg(pca9539_t *pca, uint16_t address, uint8_t *data) { - // ensure shifting left one, HAL adds the write bit - return HAL_I2C_Mem_Write(pca->i2c_handle, pca->dev_addr, address, - I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY); + //Parameters in the HAL Function + uint16_t mem_add_size = 8; + uint16_t data_size = 1; + int delay = 0xFFFFFFFFU; + + return pca->write(pca->dev_addr, address, mem_add_size, data, data_size, + delay); } -HAL_StatusTypeDef pca_read_reg(pca9539_t *pca, uint16_t address, uint8_t *data) +int pca_read_reg(pca9539_t *pca, uint16_t address, uint8_t *data) { - return HAL_I2C_Mem_Read(pca->i2c_handle, pca->dev_addr, address, - I2C_MEMADD_SIZE_8BIT, data, 1, HAL_MAX_DELAY); + uint16_t mem_add_size = 8; + uint16_t data_size = 1; + int delay = 0xFFFFFFFFU; + + return pca->read(pca->dev_addr, address, mem_add_size, data, data_size, + delay); } -void pca9539_init(pca9539_t *pca, I2C_HandleTypeDef *i2c_handle, +void pca9539_init(pca9539_t *pca, WritePtr writeFunc, ReadPtr readFunc, uint8_t dev_addr) { - pca->i2c_handle = i2c_handle; - pca->dev_addr = dev_addr - << 1u; /* shifted one to the left cuz STM says so */ + pca->dev_addr = dev_addr << 1u; + + pca->write = writeFunc; + pca->read = readFunc; } -HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, - uint8_t *buf) +int pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, uint8_t *buf) { - HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, buf); + int status = pca_read_reg(pca, reg_type, buf); if (status) { return status; } @@ -36,11 +44,11 @@ HAL_StatusTypeDef pca9539_read_reg(pca9539_t *pca, uint8_t reg_type, return status; } -HAL_StatusTypeDef pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, - uint8_t pin, uint8_t *buf) +int pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, uint8_t pin, + uint8_t *buf) { uint8_t data; - HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, &data); + int status = pca_read_reg(pca, reg_type, &data); if (status) { return status; } @@ -50,19 +58,18 @@ HAL_StatusTypeDef pca9539_read_pin(pca9539_t *pca, uint8_t reg_type, return status; } -HAL_StatusTypeDef pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, - uint8_t buf) +int pca9539_write_reg(pca9539_t *pca, uint8_t reg_type, uint8_t buf) { return pca_write_reg(pca, reg_type, &buf); } -HAL_StatusTypeDef pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, - uint8_t pin, uint8_t buf) +int pca9539_write_pin(pca9539_t *pca, uint8_t reg_type, uint8_t pin, + uint8_t buf) { uint8_t data; uint8_t data_new; - HAL_StatusTypeDef status = pca_read_reg(pca, reg_type, &data); + int status = pca_read_reg(pca, reg_type, &data); if (status) { return status; }