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

Make TicArduino compile for Particle devices #1

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

Conversation

rgiese
Copy link
Contributor

@rgiese rgiese commented Aug 29, 2020

This PR resolves a few compile-time incompatibilities:

  • The Spark implementation of Stream that Particle is based on uses char* buffers instead of uint8_t*. This required one small tweak in Tic.cpp. I hope this still compiles on other implementations; I don't have the setup to test it unfortunately.

  • The Particle device-os headers do a terrible thing and #define SPI ... and other pin constants instead of declaring them as C/C++ const or constexpr. This breaks the (beautifully enum class'd) TicPin enum. Since I can't readily change the headers that the Particle cloud-based compiler uses, I'm introducing new aliases that aren't broken by the preprocessor. A #ifndef guard also allows the existing enum values if the global namespace hasn't already been littered.

  • The Particle gcc config is pretty up-tight about bracing on bit math so I'm adding a few semi-optional parentheses.

I have tested this with the latest Particle tool chain.

@DavidEGrayson
Copy link
Member

Thanks for your interest in the Tic library and getting it to work on more platforms.

I am OK with adding the parentheses, but for the other changes, I think that you should first try reaching out to the Particle team to see if they can fix their header files to make their environment be Arduino-compatible. If Particle can fix these issues, then it will benefit not just users of the Tic library, but anyone trying to port code Arduino code to their platform.

The Arduino documentation for readBytes explicitly says that the buffer argument can either be a char array or a byte array (byte is the same as uint8_t). In order to make their environment be Arduino-compatible, I think the Particle team should add another overload of readByte that supports uint8_t. It just takes a single line of code in the Stream class:

size_t readBytes(uint8_t * b, size_t len) { return readBytes((char *)b, len); }

I also think they should consider defining things like SDA and SCL as constant integers. The code that the Arduino IDE uses to define those constants is here, and it provides them both as integers with short names and also as a preprocessor macros with the PIN_ prefix:

https://github.com/arduino/ArduinoCore-avr/blob/3055c1efa3c6980c864f661e6c8cc5d5ac773af4/variants/standard/pins_arduino.h#L48-L52

Please let me know how those discussions go. If they are on Github, you could tag me by writing @DavidEGrayson.

@rgiese
Copy link
Contributor Author

rgiese commented Sep 5, 2020

You're absolutely right; I tagged you on my PRs to Particle's device-os so you can watch me stumble. :) Thanks for your help so far (not in stumbling, obviously, but in fixing these problems the right way).

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.

2 participants