Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 81-bmsfaultpriority
Browse files Browse the repository at this point in the history
  • Loading branch information
tszwinglitw committed Dec 8, 2024
2 parents a08bdeb + f6ffa63 commit 49ff933
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 100 deletions.
33 changes: 17 additions & 16 deletions cangen/can-messages/mpu.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
},
{
Expand Down Expand Up @@ -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"
}
]
}
]
},
Expand Down Expand Up @@ -933,4 +934,4 @@
}
]
}
]
]
80 changes: 40 additions & 40 deletions cangen/can-messages/msb.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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,
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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": [
{
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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": [
{
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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": [
{
Expand Down
95 changes: 73 additions & 22 deletions general/include/pca9539.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <stdint.h>

/*
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
Expand Down Expand Up @@ -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
Loading

0 comments on commit 49ff933

Please sign in to comment.