Skip to content

Commit 07154af

Browse files
committed
refactor(libraries/Wire): return return types
In TwoWire class return return types.
1 parent 5d3c8c7 commit 07154af

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

cores/esp32/HardwareI2C.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
class HardwareI2C : public Stream
2525
{
2626
public:
27-
virtual void begin() = 0;
28-
virtual void begin(uint8_t address) = 0;
29-
virtual void end() = 0;
27+
virtual bool begin() = 0;
28+
virtual bool begin(uint8_t address) = 0;
29+
virtual bool end() = 0;
3030

31-
virtual void setClock(uint32_t freq) = 0;
31+
virtual bool setClock(uint32_t freq) = 0;
3232

3333
virtual void beginTransmission(uint8_t address) = 0;
3434
virtual uint8_t endTransmission(bool stopBit) = 0;

libraries/Wire/src/Wire.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -332,34 +332,35 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
332332

333333
}
334334

335-
void TwoWire::end()
335+
bool TwoWire::end()
336336
{
337+
esp_err_t err = ESP_OK;
337338
#if !CONFIG_DISABLE_HAL_LOCKS
338339
if(lock != NULL){
339340
//acquire lock
340341
if(xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){
341342
log_e("could not acquire lock");
342-
return;
343+
return false;
343344
}
344345
#endif
345346
#if SOC_I2C_SUPPORT_SLAVE
346347
if(is_slave){
347-
esp_err_t err = i2cSlaveDeinit(num);
348+
err = i2cSlaveDeinit(num);
348349
if(err == ESP_OK){
349350
is_slave = false;
350351
}
351352
} else
352353
#endif /* SOC_I2C_SUPPORT_SLAVE */
353354
if(i2cIsInit(num)){
354-
i2cDeinit(num);
355+
err = i2cDeinit(num);
355356
}
356357
freeWireBuffer();
357358
#if !CONFIG_DISABLE_HAL_LOCKS
358359
//release lock
359360
xSemaphoreGive(lock);
360361
}
361362
#endif
362-
return;
363+
return (err == ESP_OK);
363364
}
364365

365366
uint32_t TwoWire::getClock()
@@ -389,25 +390,28 @@ uint32_t TwoWire::getClock()
389390

390391
void TwoWire::setClock(uint32_t frequency)
391392
{
393+
esp_err_t err = ESP_OK;
392394
#if !CONFIG_DISABLE_HAL_LOCKS
393395
//acquire lock
394396
if(lock == NULL || xSemaphoreTake(lock, portMAX_DELAY) != pdTRUE){
395397
log_e("could not acquire lock");
396-
return;
398+
return false;
397399
}
398400
#endif
399401
#if SOC_I2C_SUPPORT_SLAVE
400402
if(is_slave){
401403
log_e("Bus is in Slave Mode");
404+
err = ESP_FAIL;
402405
} else
403406
#endif /* SOC_I2C_SUPPORT_SLAVE */
404407
{
405-
i2cSetClock(num, frequency);
408+
err = i2cSetClock(num, frequency);
406409
}
407410
#if !CONFIG_DISABLE_HAL_LOCKS
408411
//release lock
409412
xSemaphoreGive(lock);
410413
#endif
414+
return (err == ESP_OK);
411415
}
412416

413417
void TwoWire::setTimeOut(uint16_t timeOutMillis)

libraries/Wire/src/Wire.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,24 @@ class TwoWire: public HardwareI2C
9090
TwoWire(uint8_t bus_num);
9191
~TwoWire();
9292

93-
void begin() override final
93+
bool begin() override final
9494
{
95-
begin(-1, -1);
95+
return begin(-1, -1);
9696
}
9797

98-
void begin(uint8_t address) override final
98+
bool begin(uint8_t address) override final
9999
{
100100
#if SOC_I2C_SUPPORT_SLAVE
101-
begin(address, -1, -1, 0);
101+
return begin(address, -1, -1, 0);
102102
#else
103103
log_e("I2C slave is not supported by you SoC!!!");
104104
#endif
105105
}
106106

107107

108-
void end() override;
108+
bool end() override;
109109

110-
void setClock(uint32_t freq) override;
110+
bool setClock(uint32_t freq) override;
111111

112112
void beginTransmission(uint8_t address) override;
113113
uint8_t endTransmission(bool stopBit) override;

0 commit comments

Comments
 (0)