Skip to content

Commit 9119c61

Browse files
committed
[rtl872x] hal: resolve review comments.
1 parent 1fb0a87 commit 9119c61

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

hal/src/rtl872x/gpio_hal.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ int hal_gpio_configure(hal_pin_t pin, const hal_gpio_config_t* conf, void* reser
184184
}
185185
}
186186

187+
if ((mode == OUTPUT_OPEN_DRAIN || mode == OUTPUT_OPEN_DRAIN_PULLUP) && conf->set_value && conf->value == 0) {
188+
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
189+
}
190+
187191
GPIO_Init(&GPIO_InitStruct);
188192
pinInfo->pin_mode = mode;
189193

hal/src/rtl872x/i2c_hal.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class I2cClass {
200200
return begin((i2cInitStruct_.I2CMaster == I2C_MASTER_MODE) ? I2C_MODE_MASTER : I2C_MODE_SLAVE, i2cInitStruct_.I2CAckAddr);
201201
}
202202

203-
void reset() {
203+
uint8_t reset() {
204204
end();
205205

206206
// Just in case make sure that the pins are correctly configured (they should anyway be at this point)
@@ -214,9 +214,8 @@ class I2cClass {
214214
hal_gpio_configure(sdaPin_, &conf, nullptr);
215215

216216
// Check if slave is stretching the SCL
217-
if (!WAIT_TIMED(transConfig_.timeout_ms, hal_gpio_read(sclPin_) == 0)) {
218-
// We can't proceed because there is probably hardware issue.
219-
SPARK_ASSERT(false);
217+
if (!WAIT_TIMED(HAL_I2C_DEFAULT_TIMEOUT_MS, hal_gpio_read(sclPin_) == 0)) {
218+
return 1;
220219
}
221220

222221
// Generate up to 9 pulses on SCL to tell slave to release the bus
@@ -246,6 +245,7 @@ class I2cClass {
246245

247246
hal_i2c_mode_t mode = (i2cInitStruct_.I2CMaster == I2C_MASTER_MODE) ? I2C_MODE_MASTER : I2C_MODE_SLAVE;
248247
begin(mode, i2cInitStruct_.I2CAckAddr);
248+
return !isEnabled(); // 0 for success, to be consistent with other Gen3 platforms
249249
}
250250

251251
int setSpeed(uint32_t speed) {
@@ -733,8 +733,7 @@ void hal_i2c_enable_dma_mode(hal_i2c_interface_t i2c, bool enable, void* reserve
733733
uint8_t hal_i2c_reset(hal_i2c_interface_t i2c, uint32_t reserved, void* reserved1) {
734734
auto instance = CHECK_TRUE_RETURN(I2cClass::getInstance(i2c), 1);
735735
I2cLock lk(instance);
736-
instance->reset();
737-
return 0;
736+
return instance->reset();
738737
}
739738

740739
int32_t hal_i2c_lock(hal_i2c_interface_t i2c, void* reserved) {

0 commit comments

Comments
 (0)