@@ -49,7 +49,7 @@ static void ss_i2c_err(uint32_t dev_id)
49
49
}
50
50
51
51
static int wait_rx_or_err (bool no_stop ){
52
- uint64_t timeout = TIMEOUT_MS * 20 ;
52
+ uint64_t timeout = TIMEOUT_MS * 200 ;
53
53
while (timeout -- ) {
54
54
if (i2c_err_detect ) {
55
55
if (i2c_err_source & I2C_ABRT_7B_ADDR_NOACK )
@@ -70,7 +70,7 @@ static int wait_rx_or_err(bool no_stop){
70
70
return I2C_OK ;
71
71
}
72
72
}
73
- delayMicroseconds (50 );
73
+ delayMicroseconds (10 );
74
74
}
75
75
if (!no_stop )
76
76
return I2C_TIMEOUT ;
@@ -79,7 +79,7 @@ static int wait_rx_or_err(bool no_stop){
79
79
}
80
80
81
81
static int wait_tx_or_err (bool no_stop ){
82
- uint64_t timeout = TIMEOUT_MS * 20 ;
82
+ uint64_t timeout = TIMEOUT_MS * 200 ;
83
83
while (timeout -- ) {
84
84
if (i2c_err_detect ) {
85
85
if (i2c_err_source & I2C_ABRT_7B_ADDR_NOACK )
@@ -100,7 +100,7 @@ static int wait_tx_or_err(bool no_stop){
100
100
return I2C_OK ;
101
101
}
102
102
}
103
- delayMicroseconds (50 );
103
+ delayMicroseconds (10 );
104
104
}
105
105
if (!no_stop )
106
106
return I2C_TIMEOUT ;
@@ -109,15 +109,15 @@ static int wait_tx_or_err(bool no_stop){
109
109
}
110
110
111
111
static int wait_dev_ready (I2C_CONTROLLER controller_id , bool no_stop ){
112
- uint64_t timeout = TIMEOUT_MS * 20 ;
112
+ uint64_t timeout = TIMEOUT_MS * 200 ;
113
113
int ret = 0 ;
114
114
while (timeout -- ) {
115
115
ret = ss_i2c_status (controller_id , no_stop );
116
116
if (ret == I2C_OK ) {
117
117
return I2C_OK ;
118
118
}
119
119
if (ret == I2C_BUSY ) {
120
- delayMicroseconds (50 );
120
+ delayMicroseconds (10 );
121
121
}
122
122
}
123
123
return I2C_TIMEOUT - ret ;
@@ -128,7 +128,7 @@ int i2c_openadapter(void)
128
128
{
129
129
int ret ;
130
130
131
- SET_PIN_MODE (24 , I2C_MUX_MODE ); // Rdx SOC PIN (Arduino header pin 18)
131
+ SET_PIN_MODE (24 , I2C_MUX_MODE ); // Rxd SOC PIN (Arduino header pin 18)
132
132
SET_PIN_MODE (25 , I2C_MUX_MODE ); // Txd SOC PIN (Arduino header pin 19)
133
133
134
134
SET_PIN_PULLUP (24 , 1 );
@@ -156,6 +156,38 @@ int i2c_openadapter(void)
156
156
return ret ;
157
157
}
158
158
159
+ int i2c_openadapter_speed (int i2c_speed )
160
+ {
161
+ int ret ;
162
+
163
+ SET_PIN_MODE (24 , I2C_MUX_MODE ); // Rxd SOC PIN (Arduino header pin 18)
164
+ SET_PIN_MODE (25 , I2C_MUX_MODE ); // Txd SOC PIN (Arduino header pin 19)
165
+
166
+ SET_PIN_PULLUP (24 , 1 );
167
+ SET_PIN_PULLUP (25 , 1 );
168
+
169
+ i2c_cfg_data_t i2c_cfg ;
170
+ memset (& i2c_cfg , 0 , sizeof (i2c_cfg_data_t ));
171
+
172
+ i2c_cfg .speed = i2c_speed ;
173
+ i2c_cfg .addressing_mode = I2C_7_Bit ;
174
+ i2c_cfg .mode_type = I2C_MASTER ;
175
+ i2c_cfg .cb_tx = ss_i2c_tx ;
176
+ i2c_cfg .cb_rx = ss_i2c_rx ;
177
+ i2c_cfg .cb_err = ss_i2c_err ;
178
+
179
+ i2c_tx_complete = 0 ;
180
+ i2c_rx_complete = 0 ;
181
+ i2c_err_detect = 0 ;
182
+
183
+ ss_i2c_set_config (I2C_SENSING_0 , & i2c_cfg );
184
+ ss_i2c_clock_enable (I2C_SENSING_0 );
185
+ ret = wait_dev_ready (I2C_SENSING_0 , false);
186
+
187
+ return ret ;
188
+ }
189
+
190
+
159
191
void i2c_setslave (uint8_t addr )
160
192
{
161
193
i2c_slave = addr ;
0 commit comments