nrf52: Add a static copy buffer for i2c
Signed-off-by: Brennan Ashton <bashton@brennanashton.com>
This commit is contained in:
parent
4693857b2c
commit
b6fbcb649c
@ -632,5 +632,24 @@ menu "I2C Master Configuration"
|
||||
config NRF52_I2C_MASTER_DISABLE_NOSTART
|
||||
bool "Disable the I2C Master NOSTART flag support"
|
||||
default n
|
||||
---help---
|
||||
To combine two i2c messages that are part of a
|
||||
single transaction (NO_STOP-NO_START) the nrf52
|
||||
hardware requires these be joined into a single
|
||||
transfer. This can be expensive and some devices
|
||||
can get away with multi-part transfers as separate
|
||||
transfers. Enable this at your own risk!
|
||||
|
||||
config NRF52_I2C_MASTER_COPY_BUF_SIZE
|
||||
int "Static buffer size for NOSTART flag support"
|
||||
depends on !NRF52_I2C_MASTER_DISABLE_NOSTART
|
||||
default 4
|
||||
---help---
|
||||
To combine two i2c messages that are part of a
|
||||
single transaction (NO_STOP-NO_START) the nrf52
|
||||
hardware requires these be joined into a single
|
||||
transfer. This static buffer will be used if the
|
||||
transaction will fit otherwise it will fall back
|
||||
on malloc.
|
||||
|
||||
endmenu
|
||||
|
@ -68,6 +68,11 @@ struct nrf52_i2c_priv_s
|
||||
uint8_t msgc; /* Message count */
|
||||
struct i2c_msg_s *msgv; /* Message list */
|
||||
uint8_t *ptr; /* Current message buffer */
|
||||
#ifdef CONFIG_NRF52_I2C_MASTER_COPY_BUF_SIZE
|
||||
/* Static buffer used for continued messages */
|
||||
|
||||
uint8_t copy_buf[CONFIG_NRF52_I2C_MASTER_COPY_BUF_SIZE];
|
||||
#endif
|
||||
uint32_t freq; /* Current I2C frequency */
|
||||
int dcnt; /* Current message length */
|
||||
uint16_t flags; /* Current message flags */
|
||||
@ -308,11 +313,20 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
|
||||
/* Combine buffers */
|
||||
|
||||
if ((priv->msgv[0].length +
|
||||
priv->msgv[1].length) <=
|
||||
CONFIG_NRF52_I2C_MASTER_COPY_BUF_SIZE)
|
||||
{
|
||||
pack_buf = priv->copy_buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
pack_buf = kmm_malloc(priv->msgv[0].length +
|
||||
priv->msgv[1].length);
|
||||
if (pack_buf == NULL)
|
||||
{
|
||||
return -1;
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
/* Combine messages */
|
||||
@ -496,7 +510,7 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
|
||||
|
||||
errout:
|
||||
#ifndef CONFIG_NRF52_I2C_MASTER_DISABLE_NOSTART
|
||||
if (pack_buf != NULL)
|
||||
if (pack_buf != NULL && pack_buf != priv->copy_buf)
|
||||
{
|
||||
kmm_free(pack_buf);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user