8000 Create Destructor for Wire Class. by stickbreaker · Pull Request #27 · stickbreaker/arduino-esp32 · GitHub
[go: up one dir, main page]

Skip to content

Create Destructor for Wire Class. #27

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

Merged
merged 5 commits into from
Apr 13, 2018
Merged

Create Destructor for Wire Class. #27

merged 5 commits into from
Apr 13, 2018

Conversation

stickbreaker
Copy link
Owner
@stickbreaker stickbreaker commented Mar 16, 2018

This destructor allows reassigning either hardware peripheral to the default Wire() object.
sequence:

Wire.~TwoWire();
Wire = TwoWire(peripheral); // peripheral is either 0 or 1
Wire.begin(sda,scl); // sda, scl are the pins to use, when using peripheral 1,
  // YOU MUST specifiy the pins, there ARE NO DEFAULT VALUES for peripheral 1.

This destructor allows reassigning either hardware peripheral to the default Wire() objects.
sequence:
Wire.~TwoWire();
Wire = TwoWire(peripherial); // peripheral is either 0 or 1
Wire.begin(sda,scl); // sda, scl are the pins to use, when using peripheral 1, YOU MUST specifiy the pins, there ARE NO DEFAULT VALUES for peripheral 1.
These changes allow both i2c peripherals to be use, if a TwoWire() object is destroyed, the associated peripheral is reset and powered down.
This change will not reset the SCL, SDA and Frequency values to their default value if `Wire.begin()` is call without any parameters.  Arduino libraries that use `Wire()` usually have a call to `Wire.begin()` inside their initialization call.  Without this change, any custom pin assignments are lost whenever `Wire.begin()` is called.
Changed how default parameters are interpreted.  Now calling `Wire.begin()` without parameters will reuse the current values instead of resetting them to the default values.  This change was prompted when it was found than custom pin assignments were being lost.  The standard Arduino library practice is to issue a `Wire.begin()` call inside each library that uses `Wire()`.  If a custom pin assignment was used, when these libraries were init'd, they caused a failure when they re-assigned the SDA and SCL pins.  Changing Frequency back to 100khz was not a fatal problem.
@stickbreaker stickbreaker merged commit fc33cc0 into master Apr 13, 2018
@stickbreaker stickbreaker deleted the Wire-Destructor branch April 13, 2018 23:54
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.

1 participant
0