Skip to content
New issue

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

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

Already on GitHub? # to your account

Support I2C request and add examples #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tommag
Copy link

@tommag tommag commented Jul 1, 2024

Hi !

Thanks for your work and sharing the lib !

I added new methods to handle I2C requestFrom functions. This allows to transfer data from I2C slave to I2C master as well as I2C 2-way communication.
Request and reply examples are provided and tested on Raspberry Pi Pico (but should work on all platforms)

Solves issues #81 and #106.

port->endTransmission();

if (targetAddress < 0xFF)
port->endTransmission();

return numBytesIncl;
Copy link
Owner

Choose a reason for hiding this comment

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

@tommag I think if the target address is invalid, the function should return 0 since nothing was transferred. Maybe we could put everything dealing with port writing, port closing, and reporting numBytesIncl in the first if statement and return 0 otherwise


void I2C_RequestHandler(void)
{
myTransfer.replyWithDatum(testStruct);
Copy link
Owner

Choose a reason for hiding this comment

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

@tommag I think it would be good to double check that the requested data length matches the struct the sender wants to report. There should be a check for this either at the sketch or lib level. Also, it might be nice to request a specific packet type (Packet ID field)

@PowerBroker2 PowerBroker2 self-assigned this Jul 3, 2024
@PowerBroker2 PowerBroker2 added the enhancement New feature or request label Jul 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants