Skip to content

Commit 7b322c1

Browse files
committed
Adding I2C Burst Reading/Writing feature
1 parent 263a668 commit 7b322c1

File tree

1 file changed

+18
-10
lines changed
  • src/rp2_common/hardware_i2c

1 file changed

+18
-10
lines changed

src/rp2_common/hardware_i2c/i2c.c

Lines changed: 18 additions & 10 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) {
134+
check_timeout_fn timeout_check, struct timeout_state *ts, bool burst) {
135135
invalid_params_if(I2C, addr >= 0x80); // 7-bit addresses
136136
invalid_params_if(I2C, i2c_reserved_addr(addr));
137137
// Synopsys hw accepts start/stop flags alongside data items in the same
@@ -234,29 +234,33 @@ static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint
234234
}
235235

236236
// nostop means we are now at the end of a *message* but not the end of a *transfer*
237-
i2c->restart_on_next = nostop;
237+
i2c->restart_on_next = burst ? false : nostop;
238238
return rval;
239239
}
240240

241241
int i2c_write_blocking(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop) {
242-
return i2c_write_blocking_internal(i2c, addr, src, len, nostop, NULL, NULL);
242+
return i2c_write_blocking_internal(i2c, addr, src, len, nostop, NULL, NULL, false);
243243
}
244244

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

251251
int i2c_write_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop,
252252
uint timeout_per_char_us) {
253253
timeout_state_t ts;
254254
return i2c_write_blocking_internal(i2c, addr, src, len, nostop,
255-
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts);
255+
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts, false);
256+
}
257+
258+
int i2c_write_blocking_burst_mode(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len) {
259+
return i2c_write_blocking_internal(i2c, addr, src, len, true, NULL, NULL, true);
256260
}
257261

258262
static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop,
259-
check_timeout_fn timeout_check, timeout_state_t *ts) {
263+
check_timeout_fn timeout_check, timeout_state_t *ts, bool burst) {
260264
invalid_params_if(I2C, addr >= 0x80); // 7-bit addresses
261265
invalid_params_if(I2C, i2c_reserved_addr(addr));
262266
invalid_params_if(I2C, len == 0);
@@ -314,22 +318,26 @@ static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *ds
314318
rval = byte_ctr;
315319
}
316320

317-
i2c->restart_on_next = nostop;
321+
i2c->restart_on_next = burst ? false : nostop;
318322
return rval;
319323
}
320324

321325
int i2c_read_blocking(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop) {
322-
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, NULL, NULL);
326+
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, NULL, NULL, false);
323327
}
324328

325329
int i2c_read_blocking_until(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop, absolute_time_t until) {
326330
timeout_state_t ts;
327-
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, init_single_timeout_until(&ts, until), &ts);
331+
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop, init_single_timeout_until(&ts, until), &ts, false);
328332
}
329333

330334
int i2c_read_timeout_per_char_us(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len, bool nostop,
331335
uint timeout_per_char_us) {
332336
timeout_state_t ts;
333337
return i2c_read_blocking_internal(i2c, addr, dst, len, nostop,
334-
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts);
338+
init_per_iteration_timeout_us(&ts, timeout_per_char_us), &ts, false);
339+
}
340+
341+
int i2c_read_blocking_burst_mode(i2c_inst_t *i2c, uint8_t addr, uint8_t *dst, size_t len) {
342+
return i2c_read_blocking_internal(i2c, addr, dst, len, true, NULL, NULL, true);
335343
}

0 commit comments

Comments
 (0)