Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add another Wire requestFrom function signature #5768

Merged
merged 3 commits into from
Nov 8, 2021

Conversation

torntrousers
Copy link
Contributor

Arduino HardwareI2C defines a requestFrom function

    virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0;

whereas the ESP32 Wire doesn't include any requestFrom using size_t types, so this can cause a compile error, eg when using the Arduino ATECC608 library with an ESP32, see arduino-libraries/ArduinoECCX08#25

@torntrousers
Copy link
Contributor Author

torntrousers commented Oct 16, 2021

Actually this change still does not work with the ArduinoECCX08 library and gives this compile error:

{
	"resource": "/C:/cqtlibs/m5stack-atecc608/.pio/libdeps/m5stack-core-esp32/ArduinoECCX08/src/ECCX08.cpp",
	"owner": "C/C++",
	"code": "308",
	"severity": 8,
	"message": "more than one instance of overloaded function \"TwoWire::requestFrom\" matches the argument list: -- function \"TwoWire::requestFrom(uint16_t address, uint8_t size, bool sendStop)\" (declared at line 92 of \"C:\\USERS\\ADMINISTRATOR.CQ-LAP-000001\\.PLATFORMIO\\PACKAGES\\[email protected]\\LIBRARIES\\WIRE\\SRC\\Wire.h\") -- function \"TwoWire::requestFrom(uint16_t address, uint8_t size, uint8_t sendStop)\" (declared at line 93 of \"C:\\USERS\\ADMINISTRATOR.CQ-LAP-000001\\.PLATFORMIO\\PACKAGES\\[email protected]\\LIBRARIES\\WIRE\\SRC\\Wire.h\") -- function \"TwoWire::requestFrom(uint8_t address, uint8_t size, uint8_t sendStop)\" (declared at line 95 of \"C:\\USERS\\ADMINISTRATOR.CQ-LAP-000001\\.PLATFORMIO\\PACKAGES\\[email protected]\\LIBRARIES\\WIRE\\SRC\\Wire.h\") -- function \"TwoWire::requestFrom(int address, int size, int sendStop)\" (declared at line 97 of \"C:\\USERS\\ADMINISTRATOR.CQ-LAP-000001\\.PLATFORMIO\\PACKAGES\\[email protected]\\LIBRARIES\\WIRE\\SRC\\Wire.h\") -- argument types are: (uint8_t, size_t, bool) -- object type is: TwoWire",
	"source": "C/C++",
	"startLineNumber": 730,
	"startColumn": 17,
	"endLineNumber": 730,
	"endColumn": 28
}

My C++ isn't up to this, is there some way to do the overloaded requestFrom functions in the ESP32 so that the ArduinoECCX08 code will compile?

The ArduinoECCX08 code line is this:

  while (_wire->requestFrom((uint8_t)_address, (size_t)responseSize, (bool)true) != responseSize && retries--);

The ESP32 Wire.h requestFrom functions are:

    uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop);
    uint8_t requestFrom(uint16_t address, uint8_t size, uint8_t sendStop);
    size_t requestFrom(uint8_t address, size_t len, bool stopBit);
    uint8_t requestFrom(uint16_t address, uint8_t size);
    uint8_t requestFrom(uint8_t address, uint8_t size, uint8_t sendStop);
    uint8_t requestFrom(uint8_t address, uint8_t size);
    uint8_t requestFrom(int address, int size, int sendStop);
    uint8_t requestFrom(int address, int size);

(I have suggested conditional code in the ArduinoECCX08 library but they don't want to do that.)

/* Added to match the Arduino function definition: https://github.com/arduino/ArduinoCore-API/blob/173e8eadced2ad32eeb93bcbd5c49f8d6a055ea6/api/HardwareI2C.h#L39
* See: https://github.com/arduino-libraries/ArduinoECCX08/issues/25
*/
size_t requestFrom(uint8_t address, size_t len, bool stopBit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing TwoWire:: here

*/
size_t requestFrom(uint8_t address, size_t len, bool stopBit)
{
return requestFrom(address, (uint8_t)len, stopBit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add cast (uint16_t)address

@torntrousers
Copy link
Contributor Author

Thanks @me-no-dev , I will go give those a try!

@me-no-dev
Copy link
Member

fix the other casts

@@ -455,6 +455,14 @@ uint8_t TwoWire::requestFrom(uint16_t address, uint8_t quantity, uint8_t sendSto
return requestFrom(address, static_cast<size_t>(quantity), static_cast<bool>(sendStop));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everywhere that you see static_cast<size_t>(quantity) needs to change to static_cast<uint8_t>(quantity)

@me-no-dev me-no-dev merged commit 16a9cf7 into espressif:master Nov 8, 2021
@torntrousers
Copy link
Contributor Author

OK thats better, I now need to go try it with the the ArduinoECCX08 library...

@rashedtalukder
Copy link

Thanks @torntrousers @me-no-dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants