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

Added multi address slave #2403

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

Added multi address slave #2403

wants to merge 3 commits into from

Conversation

corna
Copy link

@corna corna commented Nov 2, 2014

I've removed the pullups enable in twi.c and I've moved it in Wire.cpp in order to make twi.h/twi.c usable in pure avr-libc projects
I've also added the multi address slave capability; the device can now respond multiple addresses (when configured as slave), and know which one was called thanks to twi_slaveAddress (in twi.c) or TwoWire::slaveAddress (in Wire.cpp). This feature is not supported on uCs without the TWAMR (two wire address mask register), like the ATMega8, and it is disabled with an #ifdef
These boards are:

  • Serial Arduino
  • Arduino USB
  • Arduino Extreme
  • Arduino NG (first version)

@corna
Copy link
Author

corna commented Nov 3, 2014

  • As reported here, stdbool.h is only supported in latest c++ revision, so I wasn't sure if I could safely add it. Should I include stdbool.h or leave the code as it is?
  • compat/twi.c is a typo, I'll fix it later. compat/twi.h simply includes util/twi.h, it was moved nine years ago, I'll add this in the commit message later
  • I wasn't sure, therefore I simply followed the original code's style. I'll try
  • To make the new version backward compatible, I can replace setAddress with a macro like this #define setAddress(address) setAddressAndMask((address), 0x00)
  • Ok, I can define a stub setAddressAndMask that calls setAddress without a mask and print a #warning, in unsupported devices

@matthijskooijman
Copy link
Collaborator

As reported here, stdbool.h is only supported in latest c++ revision, so I wasn't sure if I could safely add it. Should I include stdbool.h or leave the code as it is?

According to this, stdbool.h was supported in C (not C++) since C99.

To make the new version backward compatible, I can replace setAddress with a macro like this #define setAddress(address) setAddressAndMask((address), 0x00)

Better not use a macro, but just a static inline function instead (macros get messy quickly, inline function should have the exactly same effect).

Ok, I can define a stub setAddressAndMask that calls setAddress without a mask and print a #warning, in unsupported devices

I'm not sure that a #warning actually triggers when a function is used, or when the function is defiend (e.g. when the preprocessor didnt' remove the #warning). In the latter case, perhaps the "deprecated" or "warning" function attribute may help, see https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html (note that "warning" is only mentioned at the top, but I suspect it works just like "deprecated").

@corna
Copy link
Author

corna commented Dec 12, 2014

I've added the gcc attribute warning that prints a warning only if the function is called somewhere in a microcontroller that doesn't have the TWAMR register. If you don't call it, it doesn't complain.
Last question is: should I remove the double definition for:

void begin(uint8_t);
void begin(int);

void begin(uint8_t, uint8_t);
void begin(int, int);

uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(int, int);

uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
uint8_t requestFrom(int, int, int);

The int versions of these functions just call the uint8_t versions casting explicitely the arguments to uint8_t. For example,

uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
{
     return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop);
}

Is that really necessary? Doesn't the compiler automatically cast them to uint8_t without any complaint or drawback?

@corna
Copy link
Author

corna commented Dec 12, 2014

Also, if you call a function with an argument that exceeds the 8-bit limit, the uint8_t function prints an implicit truncation warning (which is good, the user must know that the function does not accept that argument), while with the overloaded int function doesn't

@corna
Copy link
Author

corna commented Feb 18, 2015

I've committed any requested fix. Can you merge it?

@ffissore
Copy link
Contributor

Sorry for the late reply @corna. After 1.6 release, your PR does not merge any more. Can you update it? We'll make the bot build a test IDE then, so to make others test your patch more easily.

Now utility/twi.* is a pure AVR libc library, that can be used without Arduino
Added begin and setAddressAndMask warnings if called with mask on a uC without mask support
@corna
Copy link
Author

corna commented Feb 19, 2015

Rebased successfully
I've squashed some commits in order to keep the history clean
The latest Arduino IDE doesn't show the unsupported warning anymore, even if i manually create a

#warning Unsupported on this AVR

Is it correct?

@corna corna closed this Feb 19, 2015
@corna corna reopened this Feb 19, 2015
@matthijskooijman
Copy link
Collaborator

Warnings not being shown is a known issue, see #1728.

@ffissore
Copy link
Contributor

@ArduinoBot build this please

@ArduinoBot
Copy link
Contributor

Build failed.

@corna
Copy link
Author

corna commented Feb 19, 2015

Weird, I've built it successfully on my PC... Do you have the build log?

@ffissore
Copy link
Contributor

An error in the job configuration. Fixed

@ffissore
Copy link
Contributor

@ArduinoBot build this please

@ffissore
Copy link
Contributor

Sorry it looks like I broke our bot

@ffissore
Copy link
Contributor

@ArduinoBot build this please

@corna
Copy link
Author

corna commented Feb 20, 2015

I don't have an Arduino at the moment, but I've previously tested it with an ATmega328P. The ATmega had an address mask of 0x08 (8 addresses) and it was able to manage each one independently.
Can someone test it with an Arduino?
Thanks

@ffissore
Copy link
Contributor

I've added a new preference "show all compiler warnings" that turns warnings on
Available as nightly builds in the next few hours

@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) Library: Wire The Wire Arduino library Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) labels Apr 15, 2015
@raphaelcoeffic
Copy link

@corna , @ffissore: do you guys still see a possibility to get that merged into mainline? That would be quite useful I think.

@ffissore
Copy link
Contributor

Sorry you've missed the news, but I don't work for arduino any more. See https://groups.google.com/a/arduino.cc/forum/#!msg/developers/YJLX6AZHem4/kpsLef7XBAAJ

@raphaelcoeffic
Copy link

@ffissore Thx for the reply & good luck where you are now!

@raphaelcoeffic
Copy link

@cmaglie Is there any chance to have this pull request integrated into mainline some time in the future? Thx a lot!

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) feature request A request to make an enhancement (not a bug fix) Library: Wire The Wire Arduino library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants