@@ -49,7 +49,7 @@ static void ss_i2c_err(uint32_t dev_id)
4949}
5050
5151static int wait_rx_or_err (bool no_stop ){
52- uint64_t timeout = TIMEOUT_MS * 20 ;
52+ uint64_t timeout = TIMEOUT_MS * 200 ;
5353 while (timeout -- ) {
5454 if (i2c_err_detect ) {
5555 if (i2c_err_source & I2C_ABRT_7B_ADDR_NOACK )
@@ -70,7 +70,7 @@ static int wait_rx_or_err(bool no_stop){
7070 return I2C_OK ;
7171 }
7272 }
73- delayMicroseconds (50 );
73+ delayMicroseconds (10 );
7474 }
7575 if (!no_stop )
7676 return I2C_TIMEOUT ;
@@ -79,7 +79,7 @@ static int wait_rx_or_err(bool no_stop){
7979}
8080
8181static int wait_tx_or_err (bool no_stop ){
82- uint64_t timeout = TIMEOUT_MS * 20 ;
82+ uint64_t timeout = TIMEOUT_MS * 200 ;
8383 while (timeout -- ) {
8484 if (i2c_err_detect ) {
8585 if (i2c_err_source & I2C_ABRT_7B_ADDR_NOACK )
@@ -100,7 +100,7 @@ static int wait_tx_or_err(bool no_stop){
100100 return I2C_OK ;
101101 }
102102 }
103- delayMicroseconds (50 );
103+ delayMicroseconds (10 );
104104 }
105105 if (!no_stop )
106106 return I2C_TIMEOUT ;
@@ -109,15 +109,15 @@ static int wait_tx_or_err(bool no_stop){
109109}
110110
111111static 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 ;
113113 int ret = 0 ;
114114 while (timeout -- ) {
115115 ret = ss_i2c_status (controller_id , no_stop );
116116 if (ret == I2C_OK ) {
117117 return I2C_OK ;
118118 }
119119 if (ret == I2C_BUSY ) {
120- delayMicroseconds (50 );
120+ delayMicroseconds (10 );
121121 }
122122 }
123123 return I2C_TIMEOUT - ret ;
@@ -128,7 +128,7 @@ int i2c_openadapter(void)
128128{
129129 int ret ;
130130
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)
132132 SET_PIN_MODE (25 , I2C_MUX_MODE ); // Txd SOC PIN (Arduino header pin 19)
133133
134134 SET_PIN_PULLUP (24 , 1 );
@@ -156,6 +156,38 @@ int i2c_openadapter(void)
156156 return ret ;
157157}
158158
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+
159191void i2c_setslave (uint8_t addr )
160192{
161193 i2c_slave = addr ;
0 commit comments