Skip to content

Commit 881bec8

Browse files
committed
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.
1 parent 0d6021d commit 881bec8

File tree

2 files changed

+20
-16
lines changed
  • src/rp2_common/hardware_i2c

2 files changed

+20
-16
lines changed

src/rp2_common/hardware_i2c/i2c.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void i2c_set_slave_mode(i2c_inst_t *i2c, bool slave, uint8_t addr) {
131131
}
132132

133133
static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop,
134-
check_timeout_fn timeout_check, struct timeout_state *ts, bool burst) {
134+
check_timeout_fn timeout_check, struct timeout_state *ts) {
135135
invalid_params_if(HARDWARE_I2C, addr >= 0x80); // 7-bit addresses
136136
invalid_params_if(HARDWARE_I2C, i2c_reserved_addr(addr));
137137
// Synopsys hw accepts start/stop flags alongside data items in the same
@@ -238,33 +238,35 @@ static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint
238238
}
239239

240240
// nostop means we are now at the end of a *message* but not the end of a *transfer*
241-
i2c->restart_on_next = burst ? false : nostop;
241+
i2c->restart_on_next = nostop;
242242
return rval;
243243
}
244244

245245
int i2c_write_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop) {
246-
return i2c_write_blocking_internal(i2c, addr, src, len, nostop, NULL, NULL, false);
246+
return i2c_write_blocking_internal(i2c, addr, src, len, nostop, NULL, NULL);
247247
}
248248

249249
int i2c_write_blocking_until(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop,
250250
absolute_time_t until) {
251251
timeout_state_t ts;
252-
return i2c_write_blocking_internal(i2c, addr, src, len, nostop, init_single_timeout_until(&ts, until), &ts, false);
252+
return i2c_write_blocking_internal(i2c, addr, src, len, nostop, init_single_timeout_until(&ts, until), &ts);
253253
}
254254

255255
int i2c_write_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop,
256256
uint timeout_per_char_us) {
257257
timeout_state_t ts;
258258
return i2c_write_blocking_internal(i2c, addr, src, len, nostop,
259-
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts, false);
259+
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts);
260260
}
261261

262-
int i2c_write_blocking_burst_mode(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len) {
263-
return i2c_write_blocking_internal(i2c, addr, src, len, true, NULL, NULL, true);
262+
int i2c_write_burst_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len) {
263+
int rc = i2c_write_blocking_internal(i2c, addr, src, len, true, NULL, NULL);
264+
i2c->restart_on_next = false;
265+
return rc;
264266
}
265267

266268
static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop,
267-
check_timeout_fn timeout_check, timeout_state_t *ts, bool burst) {
269+
check_timeout_fn timeout_check, timeout_state_t *ts) {
268270
invalid_params_if(HARDWARE_I2C, addr >= 0x80); // 7-bit addresses
269271
invalid_params_if(HARDWARE_I2C, i2c_reserved_addr(addr));
270272
invalid_params_if(HARDWARE_I2C, len == 0);
@@ -326,26 +328,28 @@ static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *ds
326328
rval = byte_ctr;
327329
}
328330

329-
i2c->restart_on_next = burst ? false : nostop;
331+
i2c->restart_on_next = nostop;
330332
return rval;
331333
}
332334

333335
int i2c_read_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop) {
334-
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, NULL, NULL, false);
336+
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, NULL, NULL);
335337
}
336338

337339
int i2c_read_blocking_until(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop, absolute_time_t until) {
338340
timeout_state_t ts;
339-
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, init_single_timeout_until(&ts, until), &ts, false);
341+
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, init_single_timeout_until(&ts, until), &ts);
340342
}
341343

342344
int i2c_read_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop,
343345
uint timeout_per_char_us) {
344346
timeout_state_t ts;
345347
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop,
346-
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts, false);
348+
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts);
347349
}
348350

349-
int i2c_read_blocking_burst_mode(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len) {
350-
return i2c_read_blocking_internal(i2c, addr, dst, len, true, NULL, NULL, true);
351+
int i2c_read_burst_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len) {
352+
int rc = i2c_read_blocking_internal(i2c, addr, dst, len, true, NULL, NULL);
353+
i2c->restart_on_next = false;
354+
return rc;
351355
}

src/rp2_common/hardware_i2c/include/hardware/i2c.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ int i2c_write_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t
329329
* \param len Length of data in bytes to receive
330330
* \return Number of bytes read, or PICO_ERROR_GENERIC if address not acknowledged or no device present.
331331
*/
332-
int i2c_write_blocking_burst_mode(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len);
332+
int i2c_write_burst_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len);
333333

334334
/*! \brief Attempt to read specified number of bytes from address, blocking
335335
* \ingroup hardware_i2c
@@ -357,7 +357,7 @@ int i2c_read_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, b
357357
* \param len Length of data in bytes to receive
358358
* \return Number of bytes read, or PICO_ERROR_GENERIC if address not acknowledged or no device present.
359359
*/
360-
int i2c_read_blocking_burst_mode(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len);
360+
int i2c_read_burst_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len);
361361

362362
/*! \brief Determine non-blocking write space available
363363
* \ingroup hardware_i2c

0 commit comments

Comments
 (0)