PlatformIO Community

GUIslice with teensy 4.1

I’m attempting to use GUIslice (a gui framework for touchscreens) on a teensy4.1. The GUIslice library requires that some header and config files are modified to indicate which drivers to use, pin configuration, etc.

I can compile and run a program in the Arduino IDE, but I don’t know where or how to refer to my specific configuration files.

Can someone tell me where to save those files?

I guess you’re refering to the configuration file selection in https://github.com/ImpulseAdventure/GUIslice/blob/master/src/GUIslice_config.h.

There don’t seem to be any macros which make it controllable which file is included. Other display libraries have this and thus it’s very easy to control it in PlatformIO via build_flags. But this one doesn’t.

I’d thus recommend putting the library code in the lib/ folder of the project and modifying the file there, per-project.

If you must work with global libraries (installed via the GUI option or pio lib install impulseadventure/GUIslice), those files will be in <home folder>\.platformio\lib\<library>. But per-project dependency management is to be recommended.

Also make sure that the .pio\libdeps folder is empty, otherwise a previously auto-downloaded version of the library might be sitting there.

Thanks for your response. I checked the global library directory and it is empty. I copied the library files I’m using in Arduino to the project’s lib/ folder. Here is an error message:

lib/Adafruit_TouchScreen/TouchScreen.cpp: In constructor ‘TouchScreen::TouchScreen(uint8_t, uint8_t, uint8_t, uint8_t, uint16_t)’:
lib/Adafruit_TouchScreen/TouchScreen.cpp:205:11: error: cannot convert ‘volatile uint32_t* {aka volatile long unsigned int*}’ to ‘RwReg* {aka volatile unsigned char*}’ in assignment
xp_port = portOutputRegister(digitalPinToPort(_xp));

This code compiles in the Arduino IDE, and I assume it is using the same libraries, since I’ve copied them into the project lib/ folder.

Here’s the platform.io:
[env:uno]
platform = teensy
board = teensy41
framework = arduino
lib_ldf_mode = chain+
; lib_ldf_mode = off
; lib_extra_dirs = /home/tom/Arduino/libraries
lib_deps =
GUIslice
Adafruit_GFX
Adafruit ILI9341
Wire
Adafruit_BusIO

I also compiled with the lib_deps commented out but it threw the same error.

Yeah Adafruit’s library is broken for the Teensy 4.1. I get the same error, it seems to think that for all teensy devices, the Fast I/O output registers are 8-bit wide. They’re 32 bit for the Teensy 4.1

You can hack the header if you change

to

#if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) ||              \
    defined(TEENSYDUINO) || defined(__AVR_ATmega2560__) ||                     \
    defined(__AVR_ATmega4809__)) && !defined(__IMXRT1062__)
typedef volatile uint8_t RwReg;
#elif defined(ARDUINO_STM32_FEATHER)
typedef volatile uint32 RwReg;
#elif defined(NRF52_SERIES) || defined(ESP32) || defined(ESP8266) ||           \
    defined(ARDUINO_ARCH_STM32) || defined(__IMXRT1062__)
typedef volatile uint32_t RwReg;
#else
typedef volatile uint32_t RwReg;
#endif

alternative uncomment the USE_FAST_PINIO macro to regress to the slower I/O macros.

This then compiles for me (first method):

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.9% (used 41660 bytes from 524288 bytes)
Flash: [          ]   0.2% (used 16448 bytes from 8126464 bytes)
============================================================================================ [SUCCESS] Took 4.97 seconds ============================================================================================

But overall you should go to that Adafruit repo and ask them to fix stuff. Above changes are also untested with a reallife touchscreen.

In your suggested change:

#if (defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) ||              \
    defined(TEENSYDUINO) || defined(__AVR_ATmega2560__) ||                     \
    defined(__AVR_ATmega4809__)) && !defined(__IMXRT1062__)
typedef volatile uint8_t RwReg;

I believe you meant that to be typedef volatile uint32_t RwReg;

I made the change, and it both compiles and works properly. Do you have any idea why this code would run properly on the Teensy using the Arduino IDE?

No, since the above condition is and-ed with not defined(__IMXRT1062__), this code will not execute for the Teensy 4.1, which is a iMX.RT1062. This is to get around the fact that it would otherwise trigger since defined(TEENSYDUINO) is true, but this Teensy’s port registers are not 8-bit wide. The Teensy and iMX.RT1062 code is then triggered below. This keeps compatibility with other Teensies which ports are actually 8-bit wide.

I can have a look but what’s happening is either

  • the Arduino IDE uses a different / older compiler which does not treat this error (implicit type widening?)
  • actual used libraries are different between PlatformIO and Arduino IDE
  • wrong target in Arduino IDE selected
  • …other

Ah ok. I see you added the and test, however, it compiles with this error:

lib/Adafruit_TouchScreen/TouchScreen.h:24:1: error: operator ‘||’ has no right operand

I’ve commented everything out except for “typedef volatile uint32_t RwReg;”, which works. I guess if I ever use a different board, I’ll have to fix that, but I’m not planning on that any time soon.

Thanks again.

I have another issue, but not a showstopper.

When compiling, there is this message:
identifier “XKEYPAD_CB_STATE_DONE” is undefined

main.cpp: #include “elem/XKeyPad_Num.h”
XKeyPad_Num.h: #include “elem/XKeyPad.h”
:
#define XKEYPAD_CB_STATE_DONE 1 is in XKeyPad.h

The program uploads and runs but the calling function is highlighted as a problem.

Does the problem go away if you #include "elem/XKeyPad.h" manually in the main.cpp and rebuild the intellisense?

I tried that just now and it did not resolve the issue.

Hi Thomas and Max — sorry for the delay in responding as I didn’t see this thread until now.

I would be happy to make any necessary changes to GUIslice in order to support more native integration within PlatformIO. I am long overdue in adapting the library for PlatformIO. As you are aware, the Arduino IDE is quite limiting in the way in which libraries can offer user configuration (hence the use of the GUIslice_config.h file), but this should be much easier given the flexibility available through platformio.ini.

As for the touchscreen library, as Max points out, it would be good to see a PR for the Adafruit resistive touchscreen library to directly support T4.

Regarding your last point on the keypad, it sounds like something isn’t included correctly. Let me get GUIslice updated for PlatformIO and then I can ensure that the integration is more straightforward for everyone :slight_smile:

Thanks very much for the initial testing!
Cal