Core LCD library not working with Photon (Adaffruit_HX8357)

Hello folks,

I’m getting several errors while trying to use @machadolab [Adafruit_HX8357 library] (https://github.com/machadolab/Adafruit_HX8357_Library) for a 3.5" TFT SPI display on my Photon. The library works just fine on a Core.

Following what @BDub did to add support for the Photon in the NeoPixel library, I added #include "pinm_map_impl.h" but that is not working.

Could you give me some guidance on what changes I need to do to the library for it to work with the Photon.

Thanks,
Sergio

If you should happen to be using my port of this library, I’m sorry to hear that, but I’ve not been able to ensure for it to run on the Photon (due to the lack of hardware :weary:), but I’ll try to look at it as soon as i can.

@sazp96, the solution to the PIN_MAP issue is a little more complex due to the differences in the bitset and reset registers on the STM32F103 (core) and the STM32F205 (photon). Here is a set of macros I used to port the SparkIntervalTimer library:

#if defined(PLATFORM_ID)
  #include "application.h"
  #include "pinmap_impl.h"
  STM32_Pin_Info* PIN_MAP = HAL_Pin_Map(); // Pointer required for highest access speed
#if (PLATFORM_ID == 0) // Core
  #define pinLO(_pin) (PIN_MAP[_pin].gpio_peripheral->BRR = PIN_MAP[_pin].gpio_pin)
  #define pinHI(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRR = PIN_MAP[_pin].gpio_pin)
#elif (PLATFORM_ID == 6) // Photon
  #define pinLO(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRRH = PIN_MAP[_pin].gpio_pin)
  #define pinHI(_pin) (PIN_MAP[_pin].gpio_peripheral->BSRRL = PIN_MAP[_pin].gpio_pin)
#else
  #error "*** PLATFORM_ID not supported by this library. PLATFORM should be Core or Photon ***"
#endif
#endif

You will need to replace any PIN_MAP operation in the code with pinHI and pinLO if you want the code to be common for both the Core and the Photon. :smile:

1 Like

Thanks @peekay123 for that hint.
I’m not sure, but it might well be that this could be unified back together into one set of macros, since I think the HIGH/LOW words of the BSRR register do exist on the 103 too - I’ll have a look to confirm or revoke :wink:

@ScruffR, they are different between the 103 and the 205 and this is why I have conditional compilation. The code is tested!

That’s a nice set of macros! One change I suggest is rather than using platform ID, instead use the various MCU defines - STM32F10X and STM32F2XX so that this is forward compatible with the electron.

1 Like

Awesome. Thanks guys. I will try this.

Some times when I #include "pinmap_impl.h" using Particle Dev IDE (but compiling in the cloud), I get an error that it can’t find the library. Any toughs on why this is the case?

It is also not consistent, sometimes it says PIN_MAP error (this one should be fix with @peekay123’s macros) , and sometimes it says library not found.

If pinmap_impl.h isn’t found then that could be due to the IDE compiling for the core. Be sure your photon is selected in the list of devices. :smile:

Got it!! Thanks

So you got the lib running? :+1:

If so, there is no rush for me to push an update to the lib before this thread brought us to a final decission, or is there still?

I haven’t try it yet. I will give it a try tonight or tomorrow morning and report back. :smile:

Hello folks, so I did a quick and dirty implementation of @peekay123 macros (you can see them [here] (https://github.com/sazp96/Adafruit_HX8357_Library/blob/Ref-For-Photon/Adafruit_HX8357.h)).

Unfortunately once I try to compile the code, I get a “Compiler timed out or encountered an error” message. Any thoughts why I’m doing wrong here?

Thanks!

Phew, as I see you don’t seem to use my port of the lib - good for you :wink: (and for me :sunglasses:)

Have you retried it, a while later, maybe the build farm was down for a moment.
Or have you got blanks or other “funny” characters in your file names, that weren’t there before?

Hi @ScruffR. I just retried to compile and I get the same error. At least it is consistent :sunglasses:

I also checked the file names, and they haven’t changed.

The good news is that after copying the code to Web IDE, I do get a bit more information about the error:

/spark/compile_service/shared/workspace/6_hal_12_0/firmware-privaADAFRUIT_HX8357.cpp:16:29: fatal error: Adafruit_HX8357.h: No such file or directoryindent preformatted text by 4 spaces

Have you got this library in your file tabs too, or are you using the Web IDE provided one?
If you are using the Web IDE one, you’d need to do it like this

#include "Adafruit_HX8356/Adafruit_HX8356.h"

Which would be provided in the main sketch, when you include the lib from the libraries section, but not into your other libraries and header files.

I’m providing my own that has the modified macros for the Photon.

You have included Adafruit_mfGFX but your Adafruit_HX8357 demands the (assumingly) not provided Adafruit_GFX
And maybe you also need to adjust the casing of the file names - they are displayed capitalized, but the error message complains about a mixed case file beeing missing - case does play a role here.

Nice. You were right, the mismatch in the case was causing the error in Web IDE.

I changed the HX8357 libraries for them to use the mfGFX library instead of the GFX one.

Now I’m getting this error:

../../../build/target/user/platform-6/libuser.a(test_3.5_tft_photon.o):(.bss.PIN_MAP+0x0): multiple definition of `PIN_MAP'
../../../build/target/user/platform-6/libuser.a(ADAFRUIT_HX8357.o):/spark/compile_service/shared/workspace/6_hal_12_0/firmware-privaADAFRUIT_HX8357.cpp:506: first defined here
collect2: error: ld returned 1 exit status
make: *** [/spark/compile_service/shared/workspace/6_hal_12_0/firmware-privac7e0917f655a26685cab44569335592e23024427f0e2c129eaf8a5ba48c3.elf] Error 1

The weird part is that I’m defining PIN_MAP only once in HX8357.h.

Could it be due to including the header twice (in Adafruit_HX8357.cpp and in test_3.5_tft_photon.ino)?

Update: Problem fixed:

The root cause of the issue is that I was declaring the PIN_MAP macros in HX8357.h instead of doing so in the HX8357.cpp file. Once I moved the macros the code compiled successfully.

Thanks for all the help @ScruffR.

PS: It would be nice if the Dev IDE would provide the same level of error feedback that the Web IDE does. Is this a known issue?

1 Like