Friday, May 12, 2023

Working on user interface code and dealing with non portable example code

EXAMPLE CODE WRITTEN FOR RASPBERRY PI PICO ENVIRONMENT

The touchscreen LCD module I purchased for use with the Virtual 2315 Cartridge project came with example code which is saving quite a bit of time in creating my user interface. The module was intended for use with a Pi Pico board, having a socket to fit that processor board. 

Unfortunately the example code also reflected the RP2040 microcontroller and its software development kit. The way that peripheral connections are managed and Serial Peripheral Interface (SPI) links are controlled is quite a bit different from the methods used with Arduino or in my case the ARM cores in the Intel Cyclone V system on a chip. 

I had to make many changes to adapt the code to the Terasic DE10-Nano using the Cyclone V but it seemed to be reasonably straightforward up until I began to use the touch interface to detect when various screen 'buttons' where being pushed by the operator. 

TOUCHSCREEN MODULE USES SQUARE ROOT EXTENSIVELY

Doing a make to cross compile the code triggered quite a few errors related to an undefined function sqrt which is clearly meant to be the math function calculating a square root. I wasted time believing that my cross compiling environment was not properly pointing at the include files and library files wherein it would find sqrt, before I looked closer at the code and spotted my problem.

This code calls the sqrt function with inputs and outputs that are unsigned integers, whereas the standard function in C only deals with floating point data types. Thus, having math.h included and the math library linked was of no use for the ARM Linux environment. It appears that Pi Pico does support this and the code is thus very unportable. 

REWRITING TO MAKE USE OF STANDARD C LIBRARIES ON ARM LINUX

I am in the midst of understanding the intent behind all the math done in the touchscreen example code so that I can convert it appropriately. It helps quite a bit that my design for the user interface has only three touchable soft buttons, which are largeish and well separated. This reduces the need for careful calculation to associate a touch interrupt with the spot on the screen. I only need to discriminate between three cases - Up, Down, and Select buttons. 

No comments:

Post a Comment