Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

I2C slave: allow function wrapped callbacks#1835

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

hitech95
Copy link
Contributor

@hitech95hitech95 commentedSep 27, 2022
edited
Loading

Summary

This PR fixes/implements the followingbugs/features

This allow to have TwoWire callbacks methods inside classes. You can use std::bind to wrap the callback functions.

This is an example of a Class that completely handle the I2C comunication without having the user to manually implement the callbacks:

/* * Lib Functions*/I2Client::I2Client(TwoWire *bus){this->_bus = bus;}boolI2Client::begin(uint8_t baseAddress){    _bus->begin(baseAddress);    _bus->onRequest(std::bind(&I2Client::onHandleRequest,this));returntrue;}voidI2Client::onHandleRequest(){    _bus->write("hello\n");}/* * Library Usage (main.cpp)*/#include<Arduino.h>#include<Wire.h>TwoWirebus(PB9, PB8);I2Clientclient(&bus);voidsetup(){    client.begin(0x4E);// join i2c bus on address 0x4E}voidloop(){// put your main code here, to run repeatedly:}

Validation

  • Ensure CI build is passed.
  • Demonstrate the code is solid. [e.g. Provide a sketch]

Code formatting

  • Ensure AStyle check is passed thanks CI

Closing issues

Closes#1833

@hitech95hitech95force-pushed thefeature/wire-function-wrapper branch fromc528a21 to774cbacCompareSeptember 27, 2022 22:12
@fpistmfpistm requested a review fromABOSTMSeptember 28, 2022 08:24
@fpistm
Copy link
Member

Maybe related to#1617

@hitech95
Copy link
ContributorAuthor

@fpistm I was thinking the same, I've used theattachInterrupt as a reference.
If you think that the failover to void pointers is not necessary I can drop them.

Today I'll do more tests.

@fpistm
Copy link
Member

@fpistm I was thinking the same, I've used theattachInterrupt as a reference. If you think that the failover to void pointers is not necessary I can drop them.

Today I'll do more tests.

Yes it is probably the case but requires to be be tested 😉

@hitech95
Copy link
ContributorAuthor

hitech95 commentedSep 28, 2022
edited
Loading

I've tested with a STM32G030C8T and a NUCLEO F401 and both works.
(One as a slave and the other as a master and the other way round)

fpistm reacted with thumbs up emoji

@fpistmfpistm added the enhancementNew feature or request labelSep 28, 2022
@fpistm
Copy link
Member

I've tested with a STM32G030C8T and a NUCLEO F401 and both works. (One as a slave and the other as a master and the other way round)

So you have tested with the c declaration removed ? if it works could you update the PR.

@hitech95
Copy link
ContributorAuthor

Not yet, I'm gonna do it tomorrow.
I've been quite busy with work.

fpistm reacted with thumbs up emoji

@fpistm
Copy link
Member

Hi@hitech95
any update on this?

@hitech95
Copy link
ContributorAuthor

Hi
sorry I had lot of issues at work.
I'm gonna do some tests this weekend!

@fpistm
Copy link
Member

No worry. I understand perfectly 😉

@hitech95hitech95force-pushed thefeature/wire-function-wrapper branch from774cbac to4aea869CompareNovember 20, 2022 22:20
Signed-off-by: hitech95 <nicveronese@gmail.com>
@hitech95hitech95force-pushed thefeature/wire-function-wrapper branch from4aea869 to8e1da5cCompareNovember 20, 2022 22:22
@hitech95
Copy link
ContributorAuthor

I've tested with theslave_receive andslave_sender examples from the basic arduino enviroment.
They works also by removing the C failbacks.

So I'm pushing a simplified patch for that.

Tested on Nucleo STM32 F401RE

@hitech95hitech95 marked this pull request as ready for reviewNovember 20, 2022 22:24
Copy link
Member

@fpistmfpistm left a comment
edited
Loading

Choose a reason for hiding this comment

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

LGTM.
Tested on several series.

Thank you@hitech95

@fpistmfpistm added this to the2.4.0 milestoneNov 30, 2022
@fpistmfpistm merged commit0c2d58c intostm32duino:mainNov 30, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fpistmfpistmfpistm approved these changes

@ABOSTMABOSTMAwaiting requested review from ABOSTM

Assignees
No one assigned
Labels
enhancementNew feature or request
Projects
None yet
Milestone
2.4.0
Development

Successfully merging this pull request may close these issues.

Wire add support for callback_function_t callbacks
2 participants
@hitech95@fpistm

[8]ページ先頭

©2009-2025 Movatter.jp