Skip to content

Commit

Permalink
Separate the I2C chip_id map for AFC devices and RTM devices
Browse files Browse the repository at this point in the history
Create different i2c_chip_mapping_t arrays and reserve chip_id numbers
between 0 and 63 to AFC devices and between 64 and 127 to the RTM
devices.
  • Loading branch information
gustavosr8 committed Oct 17, 2023
1 parent 7a91948 commit a805021
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
21 changes: 19 additions & 2 deletions modules/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,28 @@ bool i2c_take_by_busid( uint8_t bus_id, uint8_t *i2c_interface, TickType_t timeo

bool i2c_take_by_chipid( uint8_t chip_id, uint8_t *i2c_address, uint8_t *i2c_interface, uint32_t timeout )
{
if ( chip_id > I2C_CHIP_CNT ) {

uint8_t bus_id = i2c_chip_map[chip_id].bus_id;

/*AFC devices*/
if (chip_id <= 63) {
if ( chip_id > I2C_CHIP_CNT ) {
return false;
}
bus_id = i2c_chip_map[chip_id].bus_id;

/*RTM devices*/
} else if (64 <= chip_id <= 127 ) {
if ( chip_id > 64+I2C_CHIP_RTM_CNT ) {
return false;
}
bus_id = i2c_chip_rtm_map[chip_id].bus_id;

} else {
return false;
}

uint8_t bus_id = i2c_chip_map[chip_id].bus_id;

if ( i2c_address != NULL ) {
*i2c_address = i2c_chip_map[chip_id].i2c_address;
}
Expand Down
2 changes: 2 additions & 0 deletions port/board/afc-v3/i2c_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ i2c_chip_mapping_t i2c_chip_map[I2C_CHIP_CNT] = {
[CHIP_ID_FMC2_EEPROM] = { I2C_BUS_FMC2_ID, 0x52 },
[CHIP_ID_FMC2_LM75_0] = { I2C_BUS_FMC2_ID, 0x48 },
[CHIP_ID_FMC2_LM75_1] = { I2C_BUS_FMC2_ID, 0x49 },
};

i2c_chip_mapping_t i2c_chip_rtm_map_rtm[I2C_CHIP_RTM_CNT] = {
[CHIP_ID_RTM_PCA9554] = { I2C_BUS_RTM_ID, 0x20 },
[CHIP_ID_RTM_EEPROM] = { I2C_BUS_RTM_ID, 0x50 },
[CHIP_ID_RTM_LM75_0] = { I2C_BUS_RTM_ID, 0x48 },
Expand Down
9 changes: 7 additions & 2 deletions port/board/afc-v3/i2c_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,23 @@ enum {
CHIP_ID_FMC2_EEPROM,
CHIP_ID_FMC2_LM75_1,
CHIP_ID_FMC2_LM75_0,
CHIP_ID_RTM_PCA9554,
};

enum {
CHIP_ID_RTM_PCA9554 = 64,
CHIP_ID_RTM_EEPROM,
CHIP_ID_RTM_LM75_0,
CHIP_ID_RTM_LM75_1
};

#define I2C_MUX_CNT 2
#define I2C_BUS_CNT 7
#define I2C_CHIP_CNT 28
#define I2C_CHIP_CNT 24
#define I2C_CHIP_RTM_CNT 4

extern i2c_mux_state_t i2c_mux[I2C_MUX_CNT];
extern i2c_bus_mapping_t i2c_bus_map[I2C_BUS_CNT];
extern i2c_chip_mapping_t i2c_chip_map[I2C_CHIP_CNT];
extern i2c_chip_mapping_t i2c_chip_rtm_map[I2C_CHIP_RTM_CNT];

#endif

0 comments on commit a805021

Please sign in to comment.