Skip to content

Commit

Permalink
Moved pdu #defines to pdu.h since there were a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
bjackson312006 committed Jan 24, 2025
1 parent 0f9679a commit fe59815
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 55 deletions.
51 changes: 49 additions & 2 deletions Core/Inc/pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <stdbool.h>
#include <stdint.h>

#define SOUND_RTDS_FLAG 1U

typedef struct {
I2C_HandleTypeDef *hi2c;
osMutexId_t *mutex;
Expand Down Expand Up @@ -126,4 +124,53 @@ extern const osThreadAttr_t rtds_attributes;
*/
int8_t read_brake_state(pdu_t *pdu, bool *status);

/* CTRL GPIO Expander */
#define CTRL_ADDR PCA_I2C_ADDR_0
#define PIN_PUMP_CTRL_0 0 // P00
#define PIN_PUMP_CTRL_1 1 // P01
#define PIN_24V_12V_BUCK_CTRL 2 // P02
#define PIN_BRKLIGHT_CTRL 3 // P03
#define PIN_FANBATTBOX_CTRL 4 // P04
#define PIN_BATTBOX_FUSE_STAT 5 // P05
#define PIN_LV_BOARDS_FUSE_STAT 6 // P06
#define PIN_RADFAN_FUSE_STAT 7 // P07
#define PIN_BUCK_FUSE_STAT 0 // P10
#define PIN_FANBATTBOX_FUSE_STAT 1 // P11
#define PIN_PUMP_FUSE_STAT0 2 // P12
#define PIN_DASHBOARD_FUSE_STAT 3 // P13
#define PIN_BRKLIGHT_FUSE_STAT 4 // P14
#define PIN_SD_TO_BRB_FUSE_STAT 5 // P15
#define PIN_PUMP_FUSE_STAT1 6 // P16
#define PIN_RTDS_CTRL 7 // P17

/* Shutdown GPIO Expander */
#define SHUTDOWN_ADDR PCA_I2C_ADDR_1
#define PIN_CKPT_BRB_CLR 0 // P00
#define PIN_BMS_GOOD 1 // P01
#define PIN_INERTIA_SW_GOOD 2 // P02
#define PIN_SPARE_GPIO1 3 // P03
#define PIN_IMD_GOOD 4 // P04
#define PIN_BSPD_GOOD 5 // P05
#define PIN_SHUTDOWN_06 6 // P06 (X)
#define PIN_SHUTDOWN_07 7 // P07 (X)
#define PIN_SHUTDOWN_10 0 // P10 (X)
#define PIN_MC_STAT 1 // P11
#define PIN_SPARE_MON 2 // P12
#define PIN_SPARE_FAULT 3 // P13
#define PIN_TSMS_SENSE 4 // P14
#define PIN_BOTS_GOOD 5 // P15
#define PIN_HVD_INTLK_GOOD 6 // P16
#define PIN_HVC_INTLK_GOOD 7 // P17

/* Current Sensors */
#define MOTOR_CONTROLLER_CURRENT_SENSOR_ADDR 0x40
#define BATTBOX_FANS_CURRENT_SENSOR_ADDR 0x42
#define PUMPS_CURRENT_SENSOR_ADDR 0x44
#define LV_BOARDS_CURRENT_SENSOR_ADDR 0x45

/* Misc */
#define MUTEX_TIMEOUT osWaitForever /* ms */
#define RTDS_DURATION 1750 /* ms at 1kHz tick rate */
#define SOUND_RTDS_FLAG 1U

#endif /* PDU_H */
54 changes: 1 addition & 53 deletions Core/Src/pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,10 @@
#include <stdlib.h>
#include <string.h>

/* CTRL GPIO Expander */
#define CTRL_ADDR PCA_I2C_ADDR_0
// BANK 0 (Read with PCA_OUTPUT_0_REG or PCA_INPUT_0_REG):
#define PIN_PUMP_CTRL_0 0 // P00
#define PIN_PUMP_CTRL_1 1 // P01
#define PIN_24V_12V_BUCK_CTRL 2 // P02
#define PIN_BRKLIGHT_CTRL 3 // P03
#define PIN_FANBATTBOX_CTRL 4 // P04
#define PIN_BATTBOX_FUSE_STAT 5 // P05
#define PIN_LV_BOARDS_FUSE_STAT 6 // P06
#define PIN_RADFAN_FUSE_STAT 7 // P07
// BANK 1 (Read with PCA_OUTPUT_1_REG or PCA_INPUT_1_REG):
#define PIN_BUCK_FUSE_STAT 0 // P10
#define PIN_FANBATTBOX_FUSE_STAT 1 // P11
#define PIN_PUMP_FUSE_STAT0 2 // P12
#define PIN_DASHBOARD_FUSE_STAT 3 // P13
#define PIN_BRKLIGHT_FUSE_STAT 4 // P14
#define PIN_SD_TO_BRB_FUSE_STAT 5 // P15
#define PIN_PUMP_FUSE_STAT1 6 // P16
#define PIN_RTDS_CTRL 7 // P17

/* Shutdown GPIO Expander */
#define SHUTDOWN_ADDR PCA_I2C_ADDR_1
// BANK 0 (Read with PCA_OUTPUT_0_REG or PCA_INPUT_0_REG):
#define PIN_CKPT_BRB_CLR 0 // P00
#define PIN_BMS_GOOD 1 // P01
#define PIN_INERTIA_SW_GOOD 2 // P02
#define PIN_SPARE_GPIO1 3 // P03
#define PIN_IMD_GOOD 4 // P04
#define PIN_BSPD_GOOD 5 // P05
#define PIN_SHUTDOWN_06 6 // P06 (X)
#define PIN_SHUTDOWN_07 7 // P07 (X)
// BANK 1 (Read with PCA_OUTPUT_1_REG or PCA_INPUT_1_REG):
#define PIN_SHUTDOWN_10 0 // P10 (X)
#define PIN_MC_STAT 1 // P11
#define PIN_SPARE_MON 2 // P12
#define PIN_SPARE_FAULT 3 // P13
#define PIN_TSMS_SENSE 4 // P14
#define PIN_BOTS_GOOD 5 // P15
#define PIN_HVD_INTLK_GOOD 6 // P16
#define PIN_HVC_INTLK_GOOD 7 // P17

/* Current Sensors */
#define MOTOR_CONTROLLER_CURRENT_SENSOR_ADDR 0x40
#define BATTBOX_FANS_CURRENT_SENSOR_ADDR 0x42
#define PUMPS_CURRENT_SENSOR_ADDR 0x44
#define LV_BOARDS_CURRENT_SENSOR_ADDR 0x45

/* Misc */
#define MUTEX_TIMEOUT osWaitForever /* ms */
#define RTDS_DURATION 1750 /* ms at 1kHz tick rate */

static osMutexAttr_t pdu_mutex_attributes;
extern I2C_HandleTypeDef hi2c2;

/* Wrappers for GPIO Expander I2C */
/* Wrappers for PCA9539 (GPIO Expander) */
static inline uint8_t pca_i2c_write(uint16_t dev_address, uint8_t reg,
uint8_t *data, uint8_t length)
{
Expand Down

0 comments on commit fe59815

Please sign in to comment.