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

Enhancing Arduino compatibility #1191

Merged
merged 2 commits into from Dec 8, 2016

Conversation

Projects
None yet
4 participants
@avtolstoy
Member

avtolstoy commented Nov 30, 2016

By including Arduino.h (or several other Arduino-specific headers such as: Print.h, SPI.h, Stream.h, WProgram.h, WString.h, Wire.h) or defining PARTICLE_ARDUINO_COMPATIBILITY, wiring adds additional Arduino compatibility definitions/symbols.

Related: #1188 #1152 (SPISettings)

Some results of compiling unmodified Arduino libraries and their examples (most of the errors are just preprocessor stumbling on ino files or AVR-specific direct register access or missing dependencies):

[click to expand] results of compiling unmodified Arduino libraries and their example
Info: =========================================================
Info: Library Adafruit_GPS
Info: =========================================================
Info: Example 'GPS_HardwareSerial_EchoTest': OK
Info: Example 'due_parsing': OK
Info: Example 'locus_status': FAIL
Info: Example 'flora_gpslog': FAIL
Info: Example 'locus_erase': FAIL
Info: Example 'parsing': FAIL
Info: Example 'leo_locus_start': FAIL
Info: Example 'leo_locus_dumpbasic': OK
Info: Example 'locus_dumpbasic': FAIL
Info: Example 'blank': OK
Info: Example 'flora_dumplog': OK
Info: Example 'GPS_HardwareSerial_Parsing': OK
Info: Example 'due_shield_sdlog': FAIL
Info: Example 'leo_parsing': OK
Info: Example 'leo_locus_erase': FAIL
Info: Example 'shield_sdlog': FAIL
Info: Example 'locus_start': FAIL
Info: Example 'leo_echo': OK
Info: Example 'leo_locus_status': FAIL
Info: Example 'echo': FAIL
Info: =========================================================
Info: Library DHT-sensor-library
Info: =========================================================
Info: Example 'DHT_Unified_Sensor': OK
Info: Example 'DHTtester': OK
Info: =========================================================
Info: Library Adafruit_Sensor
Info: =========================================================
Warning: No examples directory in 'Adafruit_Sensor' library directory
Info: =========================================================
Info: Library TinyGPS
Info: =========================================================
Info: Example 'test_with_gps_device': OK
Info: Example 'static_test': FAIL
Info: Example 'simple_test': OK
Info: =========================================================
Info: Library rc-switch
Info: =========================================================
Info: Example 'ReceiveDemo_Simple': OK
Info: Example 'TypeD_REV': OK
Info: Example 'TypeC_Intertechno': OK
Info: Example 'Webserver': FAIL
Info: Example 'SendDemo': OK
Info: Example 'TypeA_WithDIPSwitches_Lightweight': OK
Info: Example 'TypeA_WithDIPSwitches': OK
Info: Example 'TypeB_WithRotaryOrSlidingSwitches': OK
Info: Example 'ReceiveDemo_Advanced': FAIL
Info: =========================================================
Info: Library LiquidCrystal
Info: =========================================================
Info: Example 'SerialDisplay': OK
Info: Example 'Scroll': OK
Info: Example 'HelloWorld': OK
Info: Example 'Cursor': OK
Info: Example 'Autoscroll': OK
Info: Example 'CustomCharacter': OK
Info: Example 'setCursor': OK
Info: Example 'TextDirection': OK
Info: Example 'Display': OK
Info: Example 'Blink': OK
Info: =========================================================
Info: Library Stepper
Info: =========================================================
Info: Example 'MotorKnob': OK
Info: Example 'stepper_speedControl': OK
Info: Example 'stepper_oneStepAtATime': OK
Info: Example 'stepper_oneRevolution': OK
Info: =========================================================
Info: Library arduino_midi_library
Info: =========================================================
Info: Example 'Input': OK
Info: Example 'Basic_IO': OK
Info: Example 'Callbacks': OK
Info: Example 'RPN_NRPN': FAIL
Info: Example 'MidiUSB': OK
Info: Example 'SimpleSynth': OK
Info: Example 'Bench': OK
Info: Example 'DualMerger': OK
Info: =========================================================
Info: Library SD
Info: =========================================================
Info: Example 'Files': OK
Info: Example 'listfiles': FAIL
Info: Example 'DumpFile': OK
Info: Example 'ReadWrite': OK
Info: Example 'CardInfo': OK
Info: Example 'Datalogger': OK
Info: =========================================================
Info: Library Adafruit_LSM9DS0_Library
Info: =========================================================
Info: Example 'sensorapi': OK
Info: Example 'lsm9doftest': OK
Info: =========================================================
Info: Library TinyGPSPlus
Info: =========================================================
Info: Example 'DeviceExample': OK
Info: Example 'SatElevTracker': OK
Info: Example 'UsingCustomFields': OK
Info: Example 'BasicExample': OK
Info: Example 'SatelliteTracker': OK
Info: Example 'FullExample': OK
Info: Example 'KitchenSink': OK
Info: =========================================================
Info: Library Adafruit-GFX-Library
Info: =========================================================
Warning: No examples directory in 'Adafruit-GFX-Library' library directory
Info: =========================================================
Info: Library Adafruit-BMP085-Library
Info: =========================================================
Warning: No src directory in 'Adafruit-BMP085-Library' library directory
Info: Example 'BMP085test': FAIL
Info: =========================================================
Info: Library Adafruit_SSD1306
Info: =========================================================
Info: Example 'ssd1306_128x64_i2c': FAIL
Info: Example 'ssd1306_128x32_i2c': FAIL
Info: Example 'ssd1306_128x32_spi': FAIL
Info: Example 'ssd1306_128x64_spi': FAIL
Info: =========================================================
Info: Library rfid
Info: =========================================================
Info: Example 'RFID-Cloner': OK
Info: Example 'FixBrickedUID': OK
Info: Example 'firmware_check': OK
Info: Example 'ChangeUID': OK
Info: Example 'rfid_write_personal_data': OK
Info: Example 'MinimalInterrupt': OK
Info: Example 'AccessControl': FAIL
Info: Example 'Ntag216_AUTH': OK
Info: Example 'ReadNUID': OK
Info: Example 'rfid_default_keys': OK
Info: Example 'ReadAndWrite': OK
Info: Example 'MifareClassicValueBlock': OK
Info: Example 'ReadUidMultiReader': OK
Info: Example 'DumpInfo': OK
Info: =========================================================
Info: Library SparkFun_APDS-9960_Sensor_Arduino_Library
Info: =========================================================
Info: Example 'ProximityInterrupt': OK
Info: Example 'AmbientLightInterrupt': OK
Info: Example 'ColorSensor': OK
Info: Example 'ProximitySensor': OK
Info: Example 'GestureTest': OK
Info: =========================================================
Info: Library SparkFun_Micro_OLED_Arduino_Library
Info: =========================================================
Info: Example 'MicroOLED_Hello': OK
Info: Example 'MicroOLED_DrawBitmap': OK
Info: Example 'MicroOLED_Clock': OK
Info: Example 'MicroOLED_Demo': OK
Info: Example 'MicroOLED_Cube': OK

Special thanks to @ScruffR for ParticleSoftSerial which I've used as a replacement for SoftwareSerial/NewSoftSerial for examples/libraries that require it unconditionally since it's supposed to be always present in Arduino core.


Doneness:

  • Contributor has signed CLA
  • Problem and Solution clearly stated
  • Code peer reviewed
  • API tests compiled
  • Run unit/integration/application tests on device
  • Add documentation
  • Add to CHANGELOG.md after merging (add links to docs and issues)

Enhancements

  • Added more Arduino Library compatibility

@technobly technobly added this to the 0.6.1 milestone Nov 30, 2016

@technobly

This comment has been minimized.

Show comment
Hide comment
@technobly

technobly Nov 30, 2016

Member

@avtolstoy we should add the first paragraph to an appropriate place in the Docs. Perhaps as another subsection of Getting Started: 10. Arduino Compatibility https://docs.particle.io/guide/getting-started/intro/photon/

Member

technobly commented Nov 30, 2016

@avtolstoy we should add the first paragraph to an appropriate place in the Docs. Perhaps as another subsection of Getting Started: 10. Arduino Compatibility https://docs.particle.io/guide/getting-started/intro/photon/

{
return println(reinterpret_cast<const char*>(str));
}

This comment has been minimized.

@technobly

technobly Nov 30, 2016

Member

Can we add these to the wiring/api tests? It might also be worthwhile to add tests for some of the other definitions to ensure they do what we expect such as:

    // Set SS to high so a connected chip will be "deselected" by default
    uint8_t port = digitalPinToPort(SS);
    uint8_t bit = digitalPinToBitMask(SS);
    volatile uint8_t *reg = portModeRegister(port);

    // if the SS pin is not already configured as an output
    // then set it high (to enable the internal pull-up resistor)
    if(!(*reg & bit)){
      digitalWrite(SS, HIGH);
    }

I'm sure there are lots of different ways these are used. I'm hoping that they work as expected with Particle devices given a correct PIN definition.

@technobly

technobly Nov 30, 2016

Member

Can we add these to the wiring/api tests? It might also be worthwhile to add tests for some of the other definitions to ensure they do what we expect such as:

    // Set SS to high so a connected chip will be "deselected" by default
    uint8_t port = digitalPinToPort(SS);
    uint8_t bit = digitalPinToBitMask(SS);
    volatile uint8_t *reg = portModeRegister(port);

    // if the SS pin is not already configured as an output
    // then set it high (to enable the internal pull-up resistor)
    if(!(*reg & bit)){
      digitalWrite(SS, HIGH);
    }

I'm sure there are lots of different ways these are used. I'm hoping that they work as expected with Particle devices given a correct PIN definition.

@ScruffR

This comment has been minimized.

Show comment
Hide comment
@ScruffR

ScruffR Dec 1, 2016

Contributor

Happy for being able to help 😊

Hope it deserves the honour.

Contributor

ScruffR commented Dec 1, 2016

Happy for being able to help 😊

Hope it deserves the honour.

@ScruffR

This comment has been minimized.

Show comment
Hide comment
@ScruffR

ScruffR Dec 1, 2016

Contributor

Just had a report of "porting" problem when a lib uses data type word

Adding a typedef uint16_t word; or similar might help.

Contributor

ScruffR commented Dec 1, 2016

Just had a report of "porting" problem when a lib uses data type word

Adding a typedef uint16_t word; or similar might help.

@technobly

This comment has been minimized.

Show comment
Hide comment
@technobly

technobly Dec 1, 2016

Member

Thanks @ScruffR. word is in this PR already as:

#ifndef word
#define word(...) makeWord(__VA_ARGS__)
#endif
Member

technobly commented Dec 1, 2016

Thanks @ScruffR. word is in this PR already as:

#ifndef word
#define word(...) makeWord(__VA_ARGS__)
#endif

@technobly technobly merged commit 4cfdd65 into develop Dec 8, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@technobly technobly deleted the feature/arduino_compatibility branch Dec 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment