-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path0061-RP2040-i2c-fix-addressing-mismatch.patch
44 lines (40 loc) · 2.05 KB
/
0061-RP2040-i2c-fix-addressing-mismatch.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
From 087a1126eee098d2817445a10cbfbf5932966c4d Mon Sep 17 00:00:00 2001
From: Martino Facchin <m.facchin@arduino.cc>
Date: Mon, 8 Mar 2021 10:53:48 +0100
Subject: [PATCH 61/87] RP2040: i2c: fix addressing mismatch
---
targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c
index 210279b3b0..ae9f0c0fd3 100644
--- a/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c
+++ b/targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c
@@ -48,7 +48,7 @@ void i2c_frequency(i2c_t *obj, int hz)
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
{
int const bytes_read = i2c_read_blocking(obj->dev,
- (uint8_t)address,
+ (uint8_t)(address >> 1),
(uint8_t *)data,
(size_t)length,
/* nostop = */(stop == 0));
@@ -60,8 +60,17 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
{
+ if (length == 0) {
+ // From pico-sdk:
+ // static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop,
+ // Synopsys hw accepts start/stop flags alongside data items in the same
+ // FIFO word, so no 0 byte transfers.
+ // invalid_params_if(I2C, len == 0);
+ length = 1;
+ }
+
int const bytes_written = i2c_write_blocking(obj->dev,
- address,
+ address >> 1,
(const uint8_t *)data,
(size_t)length,
/* nostop = */(stop == 0));
--
2.30.2