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

Bundling USIWire with MegaCore #17

Open
MCUdude opened this issue Apr 26, 2022 · 3 comments
Open

Bundling USIWire with MegaCore #17

MCUdude opened this issue Apr 26, 2022 · 3 comments

Comments

@MCUdude
Copy link

MCUdude commented Apr 26, 2022

Hi!

I'm currently working on adding Arduino support for ATmega165/325/645 and ATmega169/329/649 through an Arduino core called MegaCore. The catch is that they don't have a "standard" TWI interface, but USI instead.

I was wondering. Is it OK for you if I bundle a modified version of this library together with MegaCore? I'll of course give you the credit for your excellent work. The only modifications I'm planning to use is to change the class name from USIWire to TwoWire to make it compatible with other libraries that expect a TwoWire object. I'll also add a little preprocessor glue so that users can include Wire.h, and it automatically includes the USIWire library.

Thanks!

@puuu
Copy link
Owner

puuu commented Apr 27, 2022

Hi, nice to hear that USIWire is of interest.

Feel free to use USIWire as you like. In fact, ATTinyCore bundled it. Unfortunately, changes do not come back to this repository. Please also check ATTinyCore for modifications.

Why TwoWire? isn't it just called Wire in Arduino?

IMHO, the cleanest way would be to use this repository as a git submodule. The glue would be a Wire.h (in a different directory) with include <USIWire.h>. USIWire.h introduce already Wire. If you need TwoWire add a additional line into your Wire.h.

@MCUdude
Copy link
Author

MCUdude commented Apr 27, 2022

Feel free to use USIWire as you like. In fact, ATTinyCore bundled it. Unfortunately, changes do not come back to this repository. Please also check ATTinyCore for modifications.

Thanks! I'll have a look at both libraries then.

Why TwoWire? isn't it just called Wire in Arduino?

The library itself and the object is called Wire. However, the class is called TwoWire. Here and here is examples of libraries that expect a TwoWire object to be passed to their constructors as arguments. These libraries wouldn't accept USIWire as their i2c driver.

I'm using submodules for the bootloader and Arduino core files, but I would prefer to have a copy of the library that I'm free to modify the code as I like. One example is changing the class name (USIWire -> TwoWire). Another example is to get this library to compile for the targets I'm using. At the moment this library does not compile for __AVR_ATmega325P__ and __AVR_ATmega645P__, so that's something I'll have to add to usi_io.h. The code examples bundled with this library appear to be written with ATtinys in mind, so the examples would also have to modified.

@puuu
Copy link
Owner

puuu commented Apr 27, 2022

The library itself and the object is called Wire. However, the class is called TwoWire. Here and here is examples of libraries that expect a TwoWire object to be passed to their constructors as arguments. These libraries wouldn't accept USIWire as their i2c driver.

I see, TwoWire is the class name. In this case typedef USIWire TwoWire; or more C++ style using TwoWire = USIWire; would do the trick in Wire.h.

At the moment this library does not compile for __AVR_ATmega325P__ and __AVR_ATmega645P__, so that's something I'll have to add to usi_io.h.

I would be happy about such tested pull requests.

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

No branches or pull requests

2 participants