RA8875 library working on Photon


#1

Hi all,
I’ve now forked Sumotoy’s great library for RA8875 based displays from Eastrising/Buydisplay so it can be used with Photon/P1. You can find the files here https://github.com/jenschr/RA8875/ This version will not work with the alternate SPI1, only the normal SPI.

Feedback much appreciated! :smile:

For others wanting to port libraries using SPI, here’s a few things I learned along the way:

  • The Macro SPI_HAS_TRANSACTION does not seem to be defined for Photon, so you have to set this yourself at the top of your code (#define SPI_HAS_TRANSACTION 1)
  • Most Arduino libraries use SPI.setClockDivider and SPI.setDataMode. Photon does not (need to) use these. Instead we use beginTransaction to set these parameters: SPI.beginTransaction(SPISettings(spi_speed, MSBFIRST, SPI_MODE3));
  • SPI devices have a max speed. What speed you can use will depend on the hardware. Start low and increase is my best advice. The Photon will typically be able to use the same speeds as other ARM based devices.
  • The cloud compiler does a few interesting things, including flattening your directories. This means that any library containing a folder structure cannot compile with either Particle Dev or the online IDE. Instead you’ll have to use Particle CLI for compilation. It’s clumsy, but it works. Adding support for this is on the list, but not yet implemented. Probably because the issue that held the thread was closed? https://github.com/spark/particle-dev-app/issues/6
  • This page was of good help initially https://github.com/harrisonhjones/Spark-Ported-Libraries/ I’m sure that if someone made a more complete list than this, it would cause many more libraries to be ported.
  • The Particle compiler dislikes .c files as used by the RA8875 fonts. Renaming them to .cpp solves the compilation issue, ref Compiling C files error

I hope this can be of use to others porting libraries!

Here’s a video of it running on my custom P1 based board: https://www.youtube.com/watch?v=lLZtcwHS09c


#2

Huh? Since when?
https://docs.particle.io/reference/firmware/photon/#setclockdivider-

Have you used the v2.0 structure for projects and libraries?


#3

@ScruffR Prompt reply! You’re always around with good advice :smile:

I guess I meant that in this case, the Photon do not need to use either setClockDivider or setDataMode but I presume that’s wrong then?

Have you used the v2.0 structure for projects and libraries?

I guess not? How/what is that? Got a URL?


#4

I currently can’t find the official announcement, but here is the beta topic (which isn’t beta anymore)
Beta access to Libraries 2.0 in Particle IDEs

In the most recent CLI you have now particle project create, particle library create and particle library migrate and similar options in Particle Dev.

Some more resources to keep an eye on
Introducing our new firmware library manager!
Particle Tools Changelog


#5

Yeah. I noticed that. I randomly found it via the documentation some hours ago, but it didn’t seem to solve the problem automatically? I’ll dig some further into it.

UPDATE: I tested and this is not working as it should. It works fine from CLI though.


#6

I noticed in the zip you linked on github that your binary is inside the src folder.
To properly build Dev should be pointing to the folder containing the project.properties file.
If that was the case your binary should end up along side the project.properties file.


#7

Hehe. You are everywhere! :stuck_out_tongue:

I read all those 3 links, but it seems some of the important links no longer works? This is supposed to be the link to how things work: https://github.com/spark/docs/blob/libraries-docs/src/content/reference/libraries.md but all I get is a GitHub 404. Maybe someone forgot to make that public? It was linked from here: Libraries 2.0 installation guide


#8

I have no idea where this document is gone nor what it was all about.
All I know about v2.0 libs & projects is what I found out playing and investigating (without reading boring manuals - if it’s not intuitive it’s worth an issue report :wink: )


#9

A few more things on porting libraries. For I2C - there’s no need to include wire.h (but also no problem to leave it in).

Arduino libraries may contain:
Wire.setClock(400000UL);

The Particle way is to do this:
Wire.setSpeed( CLOCK_SPEED_400KHZ );

Some libraries will use Wire.send(x) instead of Wire.write(x). This is deprecated in the Arduino libraries (since version 1.0) and correctly implemented by Particle, but Arduino still have a documentation page up that shows the method, but does not list it as deprecated https://www.arduino.cc/en/Reference/WireSend


#10

I tried using your library that you linked, but I had better luck with the official Adafruit_RA8875 library.