PIN_MAP issue with Adafruit SSD1351 - OLED & SD card

Question 1: I am compiling the Adafruit SSD1351 library code from this repository. It compiles perfectly for the core using CLI using the command:

`particle compile core Adafruit_SSD1351_Library-master/`

However, when compiling the same code for photon using this command:

`particle compile photon Adafruit_SSD1351_Library-master/`

I get the following errors:

    Adafruit_SSD1351.cpp: In member function 'void Adafruit_SSD1351::spiwrite(uint8_t)':
Adafruit_SSD1351.cpp:38:35: error: 'struct GPIO_TypeDef' has no member named 'BRR'
   PIN_MAP[_sclk].gpio_peripheral->BRR = PIN_MAP[_sclk].gpio_pin; // Clock Low
Adafruit_SSD1351.cpp:41:35: error: 'struct GPIO_TypeDef' has no member named 'BSRR'
    PIN_MAP[_sid].gpio_peripheral->BSRR = PIN_MAP[_sid].gpio_pin; // Data High
Adafruit_SSD1351.cpp:43:35: error: 'struct GPIO_TypeDef' has no member named 'BRR'
    PIN_MAP[_sid].gpio_peripheral->BRR = PIN_MAP[_sid].gpio_pin; // Data Low
Adafruit_SSD1351.cpp:45:35: error: 'struct GPIO_TypeDef' has no member named 'BSRR'
   PIN_MAP[_sclk].gpio_peripheral->BSRR = PIN_MAP[_sclk].gpio_pin; // Clock High

This is related to the PIN_MAP discussion. However, I could not find anything conclusive there. Copied the macros provided by @peekay123 at the start of the thread but did not compile.

Question 2: When I use the Particle Dev to compile, it automatically compiles it as a core - successfully. Where can I specify if I want code compiled for core or photon in the Particle Dev?

If you use the target to select one of your Photons and then compile it will create a Photon binary. How to default to a Photon without having to select one? Great question.

Thanks @BulldogLowell - that is helpful. I can select a core / photon even if no device is online / connected - that is what I wanted!

Now I can see the errors in Question 1 in my post when compiling using Particle Dev.

Since we are having the HAL feature released already for Core and Photon libraries can easily be ported for both platforms, but it’ll take some time till the contributors get round to updating existing libs.

But since you got the source code accessible for alterations you can get it working by just replacing some things.


PIN_MAP[_pin].gpio_peripheral->BRR = PIN_MAP[_pin].gpio_pin; 
//  becomes 
pinResetFast(_pin);  // can also replace digitalWrite(_pin, LOW) 

// and

PIN_MAP[_pin].gpio_peripheral->BSRR = PIN_MAP[_pin].gpio_pin; 
//  becomes 
pinSetFast(_pin);  // can also replace digitalWrite(_pin, HIGH) 

// and

digitalWriteFast(_pin, _value);    // can replace any digitalWrite(_pin, _value) 


Perfect!! Works like a charm. Have been struggling with this all week. :stuck_out_tongue_winking_eye:

1 Like

@pteja, I have it in my task list to update all my github libraries. @BulldogLowell’s recommendations are spot on. I tend to leave non-time-critical digitalWrite() code as-is since those calls include a bunch of “safety” checks. However, for time-critical code, using digitalWriteFast() and digitalReadFast() are huge assets. :smile:

1 Like

@pteja, I updated the library to support the new firmware fast GPIO commands and to support the older Core 0.3.4 firmware. If you get a chance to test, I would greatly appreciate it. :smiley:


Just compiled using CLI - compiles with both core & photon! Great!

Here is the link to the updated lib:

1 Like

Also tested it with the OLED display - it works!

Any links to getting the SD card working - that is also present in the same display?

@pteja, fix one thing now you want more ! :stuck_out_tongue:

There is an SD library on the IDE though I’m not sure if it up to date. Otherwise, I have an SD library you could use. Which display unit are you using?

Hello @peekay123, @ScruffR

Am working on the SD library from [GitHub][1]

There is the PIN_MAP issue again:

PIN_MAP[misoPin_].gpio_peripheral->IDR & PIN_MAP[misoPin_].gpio_pin

How does this change for Photon?


Have you had a look at the repo for the Photon compatible library here?

Thanks @ScruffR. This works perfectly!

Just for completeness, the line:

PIN_MAP[misoPin_].gpio_peripheral->IDR & PIN_MAP[misoPin_].gpio_pin

is to be placed with:


Yes, since firmware version 0.4.5 there are dedicated high speed functions that wrap the hardware specifics away that may cause incompatibilities like the one you’ve seen.

These can be found here

But if you want to understand how the original line worked:

PIN_MAP[] is an array that holds some info about each of the GPIO pins.
PIN_MAP[misoPin_].gpio_peripheral points to the memory address of the hardware port to which misoPin_ belongs.
At this address are several hardware registers like the IDR (input data register) which represents all 16 GPIO states of the pins of this port.
By binary “ANDing” this 16bit word with a word that only has the one bit set which identifies misoPin_ you’ll get a result ==0 (considered FALSE or LOW) or !=0 (considered TRUE or HIGH).


Really appreciate this detailed description @ScruffR.

1 Like