Skip to content

feat(PeriphDrivers,CMSIS): Add support for multiple I2C target addresses #725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
00d6b7b
Update I2C Rev A register set and fix related build errors
Jacob-Scheiffler Aug 24, 2023
6ae2dee
Update MAX32672 (Rev. A and Rev. B) to support multiple slave addresses
Jacob-Scheiffler Aug 25, 2023
07d574f
Update MAX32570 IRev A I2C to support only one slave address
Jacob-Scheiffler Aug 25, 2023
51597b3
Update MAX32655 I2C to prevent multiple slave addresses
Jacob-Scheiffler Aug 25, 2023
5b27e8e
Merge branch 'main' into dev/add_multi_slave_support
Jacob-Scheiffler Sep 5, 2023
9f7c189
Update MAX32660 to support multiple slave addresses.
Jacob-Scheiffler Sep 5, 2023
706586d
Update MAX32662 I2C to allow speeds greater than 1Mhz
Jacob-Scheiffler Sep 5, 2023
204539a
Update MAX32665 I2C to support only one slave address
Jacob-Scheiffler Sep 5, 2023
7a0d2ae
Add address match to interrupt check for MAX32520, MAX32570, and MAX3…
Jacob-Scheiffler Sep 5, 2023
1aa5ad7
Update MAX32670 to support multiple slave addresses
Jacob-Scheiffler Sep 5, 2023
5556dff
Update MAx32675 to support multiple slve addresses{
Jacob-Scheiffler Sep 5, 2023
dfa154f
Prevent MAX32690 from using multiple slave addresses
Jacob-Scheiffler Sep 6, 2023
150ffcc
Prevent MAX78002 from setting multiple slave addresses
Jacob-Scheiffler Sep 6, 2023
77108e7
Resolve clang format errors
Jacob-Scheiffler Sep 6, 2023
b631fe7
Resolve clang format errors (pt. 2)
Jacob-Scheiffler Sep 6, 2023
9e3305b
Revert MAX32672 I2C registers
Jacob-Scheiffler Sep 7, 2023
1048682
Resolve clang-format errors (pt. 3)
Jacob-Scheiffler Sep 7, 2023
5745f2e
Update MAX32650 I2C to accept up to 1Mhz frequency
Jacob-Scheiffler Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32660/Include/max32660.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ typedef enum {
/* I2C */
#define MXC_I2C_INSTANCES (2)
#define MXC_I2C_FIFO_DEPTH (8)
#define MXC_I2C_NUM_TARGET_ADDR (4)

#define MXC_BASE_I2C0 ((uint32_t)0x4001D000UL)
#define MXC_I2C0 ((mxc_i2c_regs_t *)MXC_BASE_I2C0)
Expand Down
1 change: 1 addition & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32670/Include/max32670.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ typedef enum {
/* I2C */
#define MXC_I2C_INSTANCES (3)
#define MXC_I2C_FIFO_DEPTH (8)
#define MXC_I2C_NUM_TARGET_ADDR (4)

#define MXC_BASE_I2C0 ((uint32_t)0x4001D000UL)
#define MXC_I2C0 ((mxc_i2c_regs_t *)MXC_BASE_I2C0)
Expand Down
1 change: 1 addition & 0 deletions Libraries/CMSIS/Device/Maxim/MAX32675/Include/max32675.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ typedef enum {
/* I2C */
#define MXC_I2C_INSTANCES (3)
#define MXC_I2C_FIFO_DEPTH (8)
#define MXC_I2C_NUM_TARGET_ADDR (4)

#define MXC_BASE_I2C0 ((uint32_t)0x4001D000UL)
#define MXC_I2C0 ((mxc_i2c_regs_t *)MXC_BASE_I2C0)
Expand Down
7 changes: 4 additions & 3 deletions Libraries/PeriphDrivers/Include/MAX32672/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ typedef int (*mxc_i2c_slave_handler_t)(mxc_i2c_regs_t *i2c, mxc_i2c_slave_event_
* @param masterMode Whether to put the device in master or slave mode. Use
* non-zero
* for master mode, and zero for slave mode.
* @param slaveAddr 7-bit or 10-bit address to use when in slave mode.
* @param slaveAddr 7-bit or 10-bit address to use when in slave mode. By
* default this value will be set to slave index 0. Use
* MXC_I2C_SetSlaveAddr() to set additional slave addresses
* if needed.
* This parameter is ignored when masterMode is non-zero.
*
* @return Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
Expand All @@ -198,8 +201,6 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr);

/**
* @brief Initialize and enable I2C peripheral.
* @note Set idx to 0, multiple I2C instances acting as slaves is not yet
* supported.
*
* @param i2c Pointer to I2C registers (selects the I2C block used.)
* @param slaveAddr 7-bit or 10-bit address to use when in slave mode.
Expand Down
7 changes: 7 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32672/mxc_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ static inline int MXC_SYS_In_Crit_Section(void)
*/
int MXC_SYS_GetUSN(uint8_t *usn, uint8_t *checksum);

/**
* @brief Gets design revision of the chip.
*
* @return Design revision.
*/
int MXC_SYS_GetRevision(void);

/**
* @brief Determines if the selected peripheral clock is enabled.
* @param clock Enumeration for desired clock.
Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/I2C/i2c_ai87.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)

int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
{
if (idx != 0) {
// MAX78002 does not support multiple slave addresses
return E_NOT_SUPPORTED;
}

return MXC_I2C_RevA_SetSlaveAddr((mxc_i2c_reva_regs_t *)i2c, slaveAddr, idx);
}

Expand Down
3 changes: 2 additions & 1 deletion Libraries/PeriphDrivers/Source/I2C/i2c_es17.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
#define MXC_I2C_FASTPLUS_SPEED 1000000

/* **** Variable Declaration **** */
uint32_t interruptCheck = MXC_F_I2C_INT0_RDAMI | MXC_F_I2C_INT0_WRAMI | MXC_F_I2C_INT0_DNRERI;
uint32_t interruptCheck = MXC_F_I2C_INT0_RDAMI | MXC_F_I2C_INT0_WRAMI | MXC_F_I2C_INT0_AMI |
MXC_F_I2C_INT0_DNRERI;

/* **** Function Prototypes **** */

Expand Down
3 changes: 2 additions & 1 deletion Libraries/PeriphDrivers/Source/I2C/i2c_me10.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define MXC_I2C_MAX_ADDR_WIDTH 0x7F
#define MXC_I2C_STD_MODE 100000
#define MXC_I2C_FAST_SPEED 400000
#define MXC_I2C_FASTPLUS_SPEED 1000000

/* **** Variable Declaration **** */

Expand Down Expand Up @@ -125,7 +126,7 @@ int MXC_I2C_Shutdown(mxc_i2c_regs_t *i2c)
/* ************************************************************************** */
int MXC_I2C_SetFrequency(mxc_i2c_regs_t *i2c, unsigned int hz)
{
if (hz > MXC_I2C_FAST_SPEED) {
if (hz > MXC_I2C_FASTPLUS_SPEED) {
return E_NOT_SUPPORTED;
}

Expand Down
22 changes: 16 additions & 6 deletions Libraries/PeriphDrivers/Source/I2C/i2c_me11.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#include "i2c.h"
#include "i2c_reva.h"

/* **** Definitions **** */
#define MXC_I2C_MAX_ADDR_WIDTH 0x7F

/* **** Variable Declaration **** */
uint32_t interruptCheck = MXC_F_I2C_INTFL0_AMI | MXC_F_I2C_INTFL0_DNRERI;

Expand Down Expand Up @@ -80,8 +83,7 @@ int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
return E_NULL_PTR;
}

if (idx != 0) {
// Multiple slaves are not supported yet
if (idx >= MXC_I2C_NUM_TARGET_ADDR) {
return E_NOT_SUPPORTED;
}

Expand All @@ -90,14 +92,22 @@ int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
return E_BAD_PARAM;
}

i2c->sladdr = 0;
// Set the slave address to operate on
MXC_SETFIELD(i2c->sladdr, MXC_F_I2C_SLADDR_SLAIDX, (idx << MXC_F_I2C_SLADDR_SLAIDX_POS));

if (slaveAddr > MXC_I2C_REVA_MAX_ADDR_WIDTH) {
if (slaveAddr > MXC_I2C_MAX_ADDR_WIDTH) {
// Set for 10bit addressing mode
i2c->sladdr = MXC_F_I2C_SLADDR_EA;
i2c->sladdr |= MXC_F_I2C_SLADDR_EA;
} else {
// Clear for 7bit addressing mode
i2c->sladdr &= ~MXC_F_I2C_SLADDR_EA;
}

i2c->sladdr |= slaveAddr;
// Set the slave address
MXC_SETFIELD(i2c->sladdr, MXC_F_I2C_SLADDR_SLA, (slaveAddr << MXC_F_I2C_SLADDR_SLA_POS));

// Enable the slave address
i2c->sladdr &= ~MXC_F_I2C_SLADDR_SLADIS;

return E_NO_ERROR;
}
Expand Down
5 changes: 0 additions & 5 deletions Libraries/PeriphDrivers/Source/I2C/i2c_me12.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ int MXC_I2C_Reset(mxc_i2c_regs_t *i2c)

int MXC_I2C_SetFrequency(mxc_i2c_regs_t *i2c, unsigned int hz)
{
// ME17 doesn't support high speed more
if (hz > MXC_I2C_FASTPLUS_SPEED) {
return E_NOT_SUPPORTED;
}

return MXC_I2C_RevA_SetFrequency((mxc_i2c_reva_regs_t *)i2c, hz);
}

Expand Down
7 changes: 6 additions & 1 deletion Libraries/PeriphDrivers/Source/I2C/i2c_me13.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

/* **** Variable Declaration **** */
uint32_t interruptCheck = MXC_F_I2C_INT_FL0_RD_ADDR_MATCH | MXC_F_I2C_INT_FL0_WR_ADDR_MATCH |
MXC_F_I2C_INT_FL0_DO_NOT_RESP_ER;
MXC_F_I2C_INT_FL0_ADDR_MATCH | MXC_F_I2C_INT_FL0_DO_NOT_RESP_ER;

/* **** Function Prototypes **** */

Expand Down Expand Up @@ -82,6 +82,11 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)

int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
{
if ((MXC_SYS_GetRev() & 0xF0) == 0xA0 && idx != 0) {
// MAX32570 Rev. A only supports one slave address
return E_NOT_SUPPORTED;
}

return MXC_I2C_RevA_SetSlaveAddr((mxc_i2c_reva_regs_t *)i2c, slaveAddr, idx);
}

Expand Down
7 changes: 6 additions & 1 deletion Libraries/PeriphDrivers/Source/I2C/i2c_me14.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

/* **** Variable Declaration **** */
uint32_t interruptCheck = MXC_F_I2C_INT_FL0_RD_ADDR_MATCH | MXC_F_I2C_INT_FL0_WR_ADDR_MATCH |
MXC_F_I2C_INT_FL0_DO_NOT_RESP_ER;
MXC_F_I2C_INT_FL0_ADDR_MATCH | MXC_F_I2C_INT_FL0_DO_NOT_RESP_ER;

/* **** Function Prototypes **** */

Expand Down Expand Up @@ -80,6 +80,11 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)

int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
{
if (idx != 0) {
// MAX32665 only supports one slave address
return E_NOT_SUPPORTED;
}

return MXC_I2C_RevA_SetSlaveAddr((mxc_i2c_reva_regs_t *)i2c, slaveAddr, idx);
}

Expand Down
22 changes: 16 additions & 6 deletions Libraries/PeriphDrivers/Source/I2C/i2c_me15.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#include "i2c.h"
#include "i2c_reva.h"

/* **** Definitions **** */
#define MXC_I2C_MAX_ADDR_WIDTH 0x7F

/* **** Variable Declaration **** */
uint32_t interruptCheck = MXC_F_I2C_INTFL0_ADDR_MATCH | MXC_F_I2C_INTFL0_DNR_ERR;

Expand Down Expand Up @@ -85,8 +88,7 @@ int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
return E_NULL_PTR;
}

if (idx != 0) {
// Multiple slaves are not supported yet
if (idx >= MXC_I2C_NUM_TARGET_ADDR) {
return E_NOT_SUPPORTED;
}

Expand All @@ -95,14 +97,22 @@ int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
return E_BAD_PARAM;
}

i2c->slave = 0;
// Set the slave address to operate on
MXC_SETFIELD(i2c->slave, MXC_F_I2C_SLAVE_IDX, (idx << MXC_F_I2C_SLAVE_IDX_POS));

if (slaveAddr > MXC_I2C_REVA_MAX_ADDR_WIDTH) {
if (slaveAddr > MXC_I2C_MAX_ADDR_WIDTH) {
// Set for 10bit addressing mode
i2c->slave = MXC_F_I2C_SLAVE_EXT_ADDR_EN;
i2c->slave |= MXC_F_I2C_SLAVE_EXT_ADDR_EN;
} else {
// Clear for 7bit addressing mode
i2c->slave &= ~MXC_F_I2C_SLAVE_EXT_ADDR_EN;
}

i2c->slave |= slaveAddr;
// Set the slave address
MXC_SETFIELD(i2c->slave, MXC_F_I2C_SLAVE_ADDR, (slaveAddr << MXC_F_I2C_SLAVE_ADDR_POS));

// Enable the slave address
i2c->slave &= ~MXC_F_I2C_SLAVE_DIS;

return E_NO_ERROR;
}
Expand Down
32 changes: 31 additions & 1 deletion Libraries/PeriphDrivers/Source/I2C/i2c_me16.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,37 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)

int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
{
return MXC_I2C_RevA_SetSlaveAddr(i2c, slaveAddr, idx);
if (i2c == NULL) {
return E_NULL_PTR;
}

if (idx >= MXC_I2C_NUM_TARGET_ADDR) {
return E_NOT_SUPPORTED;
}

if (slaveAddr > MXC_F_I2C_SLAVE_ADDR) {
// Only support addresses up to 10 bits
return E_BAD_PARAM;
}

// Set the slave address to operate on
MXC_SETFIELD(i2c->slave, MXC_F_I2C_SLAVE_IDX, (idx << MXC_F_I2C_SLAVE_IDX_POS));

if (slaveAddr > MXC_I2C_MAX_ADDR_WIDTH) {
// Set for 10bit addressing mode
i2c->slave |= MXC_F_I2C_SLAVE_EXT_ADDR_EN;
} else {
// Clear for 7bit addressing mode
i2c->slave &= ~MXC_F_I2C_SLAVE_EXT_ADDR_EN;
}

// Set the slave address
MXC_SETFIELD(i2c->slave, MXC_F_I2C_SLAVE_ADDR, (slaveAddr << MXC_F_I2C_SLAVE_ADDR_POS));

// Enable the slave address
i2c->slave &= ~MXC_F_I2C_SLAVE_DIS;

return E_NO_ERROR;
}

int MXC_I2C_Shutdown(mxc_i2c_regs_t *i2c)
Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/I2C/i2c_me17.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)

int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
{
if (idx != 0) {
// MAX32655 only supports one slave device
return E_NOT_SUPPORTED;
}

return MXC_I2C_RevA_SetSlaveAddr((mxc_i2c_reva_regs_t *)i2c, slaveAddr, idx);
}

Expand Down
5 changes: 5 additions & 0 deletions Libraries/PeriphDrivers/Source/I2C/i2c_me18.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ int MXC_I2C_Init(mxc_i2c_regs_t *i2c, int masterMode, unsigned int slaveAddr)

int MXC_I2C_SetSlaveAddr(mxc_i2c_regs_t *i2c, unsigned int slaveAddr, int idx)
{
if (idx != 0) {
// MAX32690 does not support multiple slave addresses
return E_NOT_SUPPORTED;
}

return MXC_I2C_RevA_SetSlaveAddr((mxc_i2c_reva_regs_t *)i2c, slaveAddr, idx);
}

Expand Down
Loading