mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-12-10 07:14:36 +01:00
Adding I2C Burst Reading/Writing feature (#1495)
* Adding I2C Burst Reading/Writing feature * Add functions to header file. Fixing: https://github.com/raspberrypi/pico-sdk/pull/1495 * Some missing changes Rename the functions. Lose the "mode" and "blocking" needs to be at the end. Just set restart_on_next in the caller rather than adding a parameter. --------- Co-authored-by: anhnhancao <nhan@earable.ai> Co-authored-by: Peter Harper <peter.harper@raspberrypi.com>
This commit is contained in:
parent
3cb21c8134
commit
3bc866395c
2 changed files with 41 additions and 0 deletions
|
|
@ -259,6 +259,12 @@ int i2c_write_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, const uint8_t *
|
|||
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts);
|
||||
}
|
||||
|
||||
int i2c_write_burst_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len) {
|
||||
int rc = i2c_write_blocking_internal(i2c, addr, src, len, true, NULL, NULL);
|
||||
i2c->restart_on_next = false;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop,
|
||||
check_timeout_fn timeout_check, timeout_state_t *ts) {
|
||||
invalid_params_if(HARDWARE_I2C, addr >= 0x80); // 7-bit addresses
|
||||
|
|
@ -341,3 +347,9 @@ int i2c_read_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, si
|
|||
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop,
|
||||
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts);
|
||||
}
|
||||
|
||||
int i2c_read_burst_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len) {
|
||||
int rc = i2c_read_blocking_internal(i2c, addr, dst, len, true, NULL, NULL);
|
||||
i2c->restart_on_next = false;
|
||||
return rc;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -316,6 +316,21 @@ int i2c_read_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, si
|
|||
*/
|
||||
int i2c_write_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop);
|
||||
|
||||
/*! \brief Attempt to write specified number of bytes to address, blocking in burst mode
|
||||
* \ingroup hardware_i2c
|
||||
*
|
||||
* This version of the function will not issue a stop and will not restart on the next write.
|
||||
* This allows you to write consecutive bytes of data without having to resend a stop bit and
|
||||
* (for example) without having to send address byte(s) repeatedly
|
||||
*
|
||||
* \param i2c Either \ref i2c0 or \ref i2c1
|
||||
* \param addr 7-bit address of device to read from
|
||||
* \param dst Pointer to buffer to receive data
|
||||
* \param len Length of data in bytes to receive
|
||||
* \return Number of bytes read, or PICO_ERROR_GENERIC if address not acknowledged or no device present.
|
||||
*/
|
||||
int i2c_write_burst_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len);
|
||||
|
||||
/*! \brief Attempt to read specified number of bytes from address, blocking
|
||||
* \ingroup hardware_i2c
|
||||
*
|
||||
|
|
@ -329,6 +344,20 @@ int i2c_write_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t
|
|||
*/
|
||||
int i2c_read_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop);
|
||||
|
||||
/*! \brief Attempt to read specified number of bytes from address, blocking in burst mode
|
||||
* \ingroup hardware_i2c
|
||||
*
|
||||
* This version of the function will not issue a stop and will not restart on the next read.
|
||||
* This allows you to read consecutive bytes of data without having to resend a stop bit and
|
||||
* (for example) without having to send address byte(s) repeatedly
|
||||
*
|
||||
* \param i2c Either \ref i2c0 or \ref i2c1
|
||||
* \param addr 7-bit address of device to read from
|
||||
* \param dst Pointer to buffer to receive data
|
||||
* \param len Length of data in bytes to receive
|
||||
* \return Number of bytes read, or PICO_ERROR_GENERIC if address not acknowledged or no device present.
|
||||
*/
|
||||
int i2c_read_burst_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len);
|
||||
|
||||
/*! \brief Determine non-blocking write space available
|
||||
* \ingroup hardware_i2c
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue