Mini Win
Mini Win
9 February 2023
1 Introduction .......................................................................................................................................... 7
2 Who is MiniWin For?............................................................................................................................. 8
3 Features ................................................................................................................................................ 8
4 User Interface Controls ......................................................................................................................... 8
5 MiniWin Windows................................................................................................................................. 9
6 Developer Utility Applications .............................................................................................................. 9
7 Drivers and Examples .......................................................................................................................... 11
8 Customisability .................................................................................................................................... 12
9 Dynamic Memory and Recursion ........................................................................................................ 12
10 MISRA Compliance .......................................................................................................................... 13
11 Display Size and Rotation ................................................................................................................ 13
12 Implementing the Hardware Abstraction Layer (hal) ..................................................................... 14
12.1 Delay Driver................................................................................................................................. 14
12.2 Init Driver .................................................................................................................................... 14
12.3 Timer Driver ................................................................................................................................ 14
12.4 Non-Volatile Storage Driver ........................................................................................................ 15
12.5 Touch Driver ................................................................................................................................ 15
12.6 LCD Driver ................................................................................................................................... 16
13 Paint Algorithm ............................................................................................................................... 18
14 Z Orders........................................................................................................................................... 18
15 Multiple Instances of the Same Window ........................................................................................ 19
16 Graphics Library .............................................................................................................................. 19
16.1 Fonts............................................................................................................................................ 20
16.1.1 Always Available Bit-Mapped ............................................................................................. 21
16.1.2 Optional Bit-Mapped .......................................................................................................... 21
16.1.3 Run Length Encoded TrueType Fonts ................................................................................. 21
17 Tree Container Utility ...................................................................................................................... 24
17.1 Tree Nodes .................................................................................................................................. 24
17.2 Tree Container Options ............................................................................................................... 24
17.3 Tree Container Node Options ..................................................................................................... 25
17.4 Creating a Tree Container ........................................................................................................... 25
17.5 Populating the Tree..................................................................................................................... 26
17.6 Retrieving items from the Tree ................................................................................................... 27
18 Standard Controls Overview ........................................................................................................... 28
19 Enabling and Disabling Controls ..................................................................................................... 29
20 Standard Dialogs ............................................................................................................................. 29
20.1 Single Button Message Box ......................................................................................................... 29
20.2 Double Button Message Box ....................................................................................................... 29
20.3 Time Chooser .............................................................................................................................. 29
20.4 Number Entry .............................................................................................................................. 30
20.5 Text Entry .................................................................................................................................... 30
20.6 Date Chooser............................................................................................................................... 30
20.7 Colour Chooser ........................................................................................................................... 30
20.8 File Chooser................................................................................................................................. 30
21 MiniWin Messages .......................................................................................................................... 31
21.1 MiniWin Message Types ............................................................................................................. 31
21.1.1 Messages Posted by the Window Manager........................................................................ 31
21.1.2 Messages Posted by Controls in Response to User Interface Input ................................... 31
21.1.3 Messages Posted to Controls to Change Their State or Appearance ................................. 31
21.1.4 Messages Posted by Standard Dialogs ................................................................................ 32
21.1.5 Utility Messages .................................................................................................................. 32
21.1.6 User Code Defined Messages ............................................................................................. 32
21.2 MiniWin Message Fields ............................................................................................................. 32
22 Transferring Data to Message Handler Functions .......................................................................... 33
23 MiniWin Memory Pools and Handles ............................................................................................. 33
23.1 Resource Handles and Id’s – For Information Only .................................................................... 33
24 Touch Events ................................................................................................................................... 33
25 Painting and Client Areas ................................................................................................................ 34
26 Automatic Painting and User Code Painting ................................................................................... 35
27 Scroll Bars ........................................................................................................................................ 35
27.1 Window Scrolling Techniques ..................................................................................................... 36
27.1.1 Dynamic Repainting ............................................................................................................ 36
27.1.2 Delayed Repainting ............................................................................................................. 36
27.1.3 Window Drags ..................................................................................................................... 36
28 Combining Controls......................................................................................................................... 36
28.1 Scrolling Messages – List Boxes .................................................................................................. 37
28.1.1 Messages Received ............................................................................................................. 37
28.1.2 Messages Sent..................................................................................................................... 37
28.2 Scrolling Messages – Text Boxes ................................................................................................. 37
28.2.1 Messages Received ............................................................................................................. 37
28.2.2 Messages Sent..................................................................................................................... 38
28.3 Scrolling Messages – Trees ......................................................................................................... 38
28.3.1 Messages Received ............................................................................................................. 38
28.3.2 Messages Sent..................................................................................................................... 38
29 Operator Window Interaction ........................................................................................................ 39
30 MiniWin Example Projects .............................................................................................................. 40
30.1 MiniWinTest ................................................................................................................................ 41
30.2 MiniWinSimple............................................................................................................................ 42
30.3 MiniWinRoot ............................................................................................................................... 42
30.4 MiniWinFile ................................................................................................................................. 42
30.4.1 File System Integration ....................................................................................................... 43
30.4.2 Multiple Window Instances ................................................................................................ 43
30.5 MiniWinFixedWindows ............................................................................................................... 43
30.6 MiniWinTTFonts .......................................................................................................................... 44
30.7 MiniWinFreeRTOS ....................................................................................................................... 44
30.8 MiniWinCamera .......................................................................................................................... 45
30.8.1 Installing OpenCV on Windows for cl Compiler .................................................................. 46
30.8.2 Installing OpenCV on Windows for GCC Compiler .............................................................. 46
30.8.3 Installing OpenCV on Windows for Linux ............................................................................ 46
30.8.4 Camera Driver for Embedded Variants ............................................................................... 46
30.8.5 Camera Library Platforms ................................................................................................... 46
30.9 Example Projects for Microsoft Windows and Linux .................................................................. 48
30.10 Example Projects for Raspberry Pi OS ..................................................................................... 48
30.11 Example Projects for Raspberry Pico SDK ............................................................................... 48
30.12 STM32CubeIDE/NXP MCUXpresso/Renesas e2 Studio/Atmel (Microchip) Studio/Microchip
MPLAB X Linked Folders.......................................................................................................................... 49
30.13 ESP32-IDF Components........................................................................................................... 49
30.14 Other Required Project Files ................................................................................................... 49
30.15 Board Support Package Code .................................................................................................. 50
30.16 Arduino IDE Example Projects................................................................................................. 51
31 Standard Controls Details ............................................................................................................... 51
31.1 Button ......................................................................................................................................... 51
31.2 Check Box .................................................................................................................................... 51
31.3 Keypad......................................................................................................................................... 52
31.4 Keyboard ..................................................................................................................................... 52
31.5 Label ............................................................................................................................................ 52
31.6 List Box ........................................................................................................................................ 52
31.7 Progress Bar ................................................................................................................................ 53
31.8 Radio Button ............................................................................................................................... 53
31.9 Horizontal Scroll Bar.................................................................................................................... 53
31.10 Vertical Scroll Bar .................................................................................................................... 53
31.11 Arrow Button .......................................................................................................................... 54
31.12 Text Box................................................................................................................................... 54
31.13 Tabs ......................................................................................................................................... 54
31.14 Tree ......................................................................................................................................... 55
32 Source Code Layout ........................................................................................................................ 55
33 User Code Configuration ................................................................................................................. 59
33.1 Memory Allocation ..................................................................................................................... 59
33.2 Display Rotation .......................................................................................................................... 59
33.3 Sizes............................................................................................................................................. 59
33.4 User Interface Colours ................................................................................................................ 60
33.5 Timings ........................................................................................................................................ 60
33.6 Bitmapped Fonts ......................................................................................................................... 60
33.7 Dialogs ......................................................................................................................................... 60
33.8 Other ........................................................................................................................................... 60
34 MiniWin Asserts .............................................................................................................................. 60
35 MiniWin Naming Convention.......................................................................................................... 61
36 Quick-Start MiniWin Application Guide .......................................................................................... 61
37 MiniWin Code Generator ................................................................................................................ 66
37.1 Building the Code Generator ...................................................................................................... 66
37.2 Running the Code Generator - Overview.................................................................................... 67
37.2.1 Running the Code Generator for Simulator Target............................................................. 67
37.2.2 Running the Code Generator for Arduino/DevKitC target .................................................. 68
37.3 Example Code Generator Configuration Files ............................................................................. 69
37.3.1 Building and Running Code Generator Examples for Linux ................................................ 69
37.3.2 Building and Running Code Generator Examples for Windows.......................................... 69
37.3.3 Building and Running Code Generator Examples for Arduino/DevKitC ............................. 70
37.4 Debugging Simulated Generated Code under Windows using GCC ........................................... 70
37.5 Code Generator Configuration File Format ................................................................................ 71
37.6 Configuration File Format Overview ........................................................................................... 72
37.7 Configuration File Format Details ............................................................................................... 74
37.7.1 General Application Settings ............................................................................................... 74
37.7.2 Window Settings ................................................................................................................. 76
37.7.3 Control Settings................................................................................................................... 78
37.8 Code Generator Error Messages ................................................................................................. 84
38 Known Issues................................................................................................................................... 86
39 Third Party Software ....................................................................................................................... 87
40 Glossary of Terms............................................................................................................................ 87
41 Appendix 1 – MiniWin Flags............................................................................................................ 88
41.1 Window Flags .............................................................................................................................. 89
41.1.1 User Settable Flags .............................................................................................................. 89
41.1.2 Non-User Settable Flags ...................................................................................................... 89
41.2 Control Flags ............................................................................................................................... 90
41.2.1 User Settable Flags .............................................................................................................. 90
41.2.2 Non-User Settable Flags ...................................................................................................... 90
42 Appendix 2 - MiniWin Messages..................................................................................................... 90
42.1 Messages Posted by the Window Manager................................................................................ 90
42.2 Messages Posted by Controls in Response to User Interface Input ........................................... 93
42.3 Messages Posted to Controls from User Code ........................................................................... 95
42.4 Messages Posted by Standard Dialogs........................................................................................ 96
42.5 Utility Messages .......................................................................................................................... 98
43 Appendix 3 – Additional Hardware ................................................................................................. 99
43.1 LCD Panel with Touch Screen and SD Card socket.................................................................... 100
43.2 Camera ...................................................................................................................................... 100
43.3 SD Card Socket .......................................................................................................................... 101
44 Appendix 4 – STM32F429I-DISC1 Board Connections .................................................................. 102
44.1 Display and Touch Screen ......................................................................................................... 102
44.2 File System ................................................................................................................................ 102
44.3 Camera ...................................................................................................................................... 102
45 Appendix 5 – STM32F4DISCOVERY Board Connections ............................................................... 103
45.1 Display and Touch Screen ......................................................................................................... 103
45.2 File System ................................................................................................................................ 103
45.3 Camera ...................................................................................................................................... 103
46 Appendix 6 – NXP OM13098 Board Connections ......................................................................... 104
46.1 Display and Touch Screen ......................................................................................................... 104
46.2 File System ................................................................................................................................ 104
46.3 Camera ...................................................................................................................................... 104
47 Appendix 7 – Renesas Envision Board Connections using CC-RX Compiler .................................. 105
47.1 Display and Touch Screen ......................................................................................................... 105
47.2 File System ................................................................................................................................ 105
47.3 Camera ...................................................................................................................................... 105
48 Appendix 8 – Renesas Envision Board Connections using GCC-RX Compiler ............................... 106
48.1 Display and Touch Screen ......................................................................................................... 106
48.2 File System ................................................................................................................................ 107
48.3 Camera ...................................................................................................................................... 107
49 Appendix 9 – ESP32-DevKitC Board Connections ......................................................................... 108
49.1 Display and Touch Screen ......................................................................................................... 108
49.2 File System ................................................................................................................................ 108
49.3 Camera ...................................................................................................................................... 109
50 Appendix 10 – Microchip Curiosity PIC32 MX470 Board Connections ......................................... 110
50.1 Display and Touch Screen ......................................................................................................... 110
50.2 File System ................................................................................................................................ 110
50.3 Camera ...................................................................................................................................... 111
51 Appendix 11 – Windows Simulator Connections .......................................................................... 111
51.1 Display and Touch Screen ......................................................................................................... 111
51.2 File System ................................................................................................................................ 112
51.3 Camera ...................................................................................................................................... 112
52 Appendix 12 – Linux Simulator Connections ................................................................................ 112
52.1 Display and Touch Screen ......................................................................................................... 112
52.2 File System ................................................................................................................................ 112
52.3 Camera ...................................................................................................................................... 112
53 Appendix 13 – Microchip Curiosity PIC32 MZ EF Board Connections .......................................... 112
53.1 Display and Touch Screen ......................................................................................................... 112
53.2 File System ................................................................................................................................ 113
53.3 Camera ...................................................................................................................................... 113
54 Appendix 14 – Raspberry Pi Zero W Board Connections .............................................................. 114
54.1 Display and Touch Screen ......................................................................................................... 114
54.2 File System ................................................................................................................................ 114
54.3 Camera ...................................................................................................................................... 115
55 Appendix 15 – Raspberry Pi Pico Board Connections ................................................................... 115
55.1 Display and Touch Screen ......................................................................................................... 115
55.2 File System ................................................................................................................................ 115
55.3 Camera ...................................................................................................................................... 116
56 Appendix 16 – Atmel/Microchip ATSAM3X8E on Arduino Due Connections ............................... 116
56.1 Display and Touch Screen ......................................................................................................... 116
56.2 File System ................................................................................................................................ 116
56.3 Camera ...................................................................................................................................... 117
57 Appendix 17 – PK-S5D9 Board Connections ................................................................................. 117
57.1 Display and Touch Screen ......................................................................................................... 117
57.2 File System ................................................................................................................................ 118
57.3 Camera ...................................................................................................................................... 118
58 Hints and Tips ................................................................................................................................ 118
58.1 Setting up Ubuntu ..................................................................................................................... 118
58.2 Setting up MSYS2 ...................................................................................................................... 119
58.3 Setting up Visual Studio cl ......................................................................................................... 119
58.4 Setting up Raspberry Pi Zero W ................................................................................................ 120
58.5 Setting up Raspberry Pi Zero Pico SDK ...................................................................................... 120
58.6 Programming Arduino Due Board with Microchip/Atmel Studio ............................................. 121
1 Introduction
MiniWin is an open source royalty free overlapped window manager for small embedded systems with a
touch screen written in MISRA 2012 compliant C99. The hardware interface is separated out into a small
hardware abstraction layer making the rest of the system re-targetable to a wide variety of processors.
MiniWin will run easily on ARM Cortex M0 or above, PIC32, ESP32, some Arduinos, Raspberry Pi or
Renesas RX processors. It will not run on small 8 bit processors, for example PIC 18F.
2 Who is MiniWin For?
• Open source projects that need a quick-start user interface
• Small commercial products that do not have the budget to buy a window manager or the manpower
to develop one
• Hardware constrained devices that have limited resources but also have limited requirements
• Projects that require a user interface that uses no dynamically allocated memory or recursion.
• Student projects that can build on the supplied example code
• Projects requiring MISRA 2012 compliance.
3 Features
• Written specifically for small embedded systems with a LCD display and a touch screen.
• Apart from a small hardware abstraction layer, platform independent.
• Supports multiple overlapped windows with Z ordering.
• Supports display rotation
• Incorporates a flexible graphics library.
• Comes with a set of user interface controls in two sizes - a standard size for use with a touch screen
and stylus, and large size for a touch screen with finger input.
• Includes a set of standard dialogs that need no further code written to use.
• Optionally no dynamic memory used - all data structures can be allocated at compile time.
• No recursion.
• No display shadow buffers required.
• Six bitmapped fonts included – five fixed width and one proportional.
• TrueType font rendering capability for fonts of your choice
• A clean easy to use API.
• Comprehensive documentation and example projects.
• Runs in bare metal systems or within a single thread of a RTOS.
• Example projects showing FatFS or FileX (USB host, SDIO or SD SPI interface), FreeRTOS and ThreadX
integration, and TrueType font rendering
• Requires minimal memory - no off-screen buffering used.
• Compiles without warning with GCC, clang, Visual Studio cl, XC32 and CC-RX compilers.
• Fully compliant with MISRA 2012 coding standard ‘required’ features.
• Doxygen documentation for every function and type.
• Built-in touch screen calibration capability the first time the window manager is started.
• Code generator to create all your windows and controls from a simple configuration file in JSON
format.
• Simulators allowing your projects to be run and debugged on Windows or Linux speeding up the
development of the user interface part of your embedded code or start development before
hardware is available.
These are the standard ones. All controls come in 2 sizes – standard and large. Typically the smaller size
is for use with a stylus operated touch screen and the larger size for a finger operated touch screen, but
this depends on your display’s pixel size. You can easily add more control types of your own design
following the implementation pattern of the existing controls.
5 MiniWin Windows
• Optional title bar, title, scroll bars and border
• Overlapped with unique Z order, fixed tiled, or a combination
• Operator movable and resizable, or fixed
• User code movable and resizable
• Optional maximise, minimise, resize and close icons
• Minimisable to an icon on the desktop
• Customisable desktop colour or bitmap
• Can have a single system modal window
• Window-aware graphics library for drawing in a window
• Standard or large sized features
You don't have to use overlapped windows at all. If you want fixed dedicated areas of the display with
each area being responsive to operator input and having its own message and paint functions, that's
possible too. Any window can be created with no border or title bar, and like this it's fixed on the screen
(although it can still be changed from user code).
• Converter for monochrome bitmap files in .bmp format to C99 source code.
• Converter for 24 bit colour bitmap files in .bmp format to C99 source code.
• Converter for TrueType font files to run-length encoded C99 source file for a single point size
• Code generator to create your window and control code from a JSON format configuration file.
The C99 source code produced by the font/bitmap utilities can be dropped into your project and used
straight away by routines in the graphics library. Each utility processes a single input file at a time, so
must be run for each input file processed (i.e. .bmp image file or TrueType font file).
The code generator creates the complete source for a buildable MiniWin app and makefiles to build it
for Windows and Linux simulators using a variety of compilers. By changing the driver layer the
generated code can be targeted at your hardware.
Each utility is located in the Tools folder under its own folder where source code and makefiles are
found. These utilities can be built from source and run on either Windows or Linux (the font converter
for Windows is currently provided as an executable only). The utilities come pre-built for Windows as
well as with source code.
These applications are command line console/shell applications. Running an application with no
arguments shows their usage. The code generator is described in its own section later in this document.
These utility applications are all simple and do not contain any IDE project files. Instead they are all built
on the command line using the makefiles provided. The GCC or clang compilers for Linux, or the GCC,
clang or Microsoft cl compilers for Windows are used to build the utilities. For Linux GCC will usually
already be available and the makefiles can be used straight away or clang can be installed. For
Windows, install Microsoft Visual Studio (which contains the cl compiler), or for using the GCC/clang
compilers on Windows it is recommended to use the MSYS2 environment with GCC/clang, as the
provided makefiles have been tested with these packages. This can be found he:
https://www.msys2.org/
Once MSYS2 is installed you need to install GCC or clang compilers. To install the base-devel and GCC
packages using this command in a MSYS2 terminal:
pacman -S base-devel
pacman –S gcc
Installing clang in MSYS2 in Windows (instead of GCC if preferred) from a MSYS2 shell window:
If using clang instead install the clang package using this command in a MSYS2 terminal…
pacman -S base-devel
pacman -S mingw-w64-x86_64-clang
You need to add the following to you PATH environment variable for either compiler…
C:\msys64\usr\bin
C:\msys64\mingw64\bin
Following this, to build any utility for Linux or Windows using GCC or clang use this command line from
its source folder:
make
For building any utility for Windows using Microsoft cl compiler in a Visual Studio command console use
this command line from its source folder:
nmake -f nmakefile
Note that the makefile name for cl builds is nmakefile. There have been issues reported when using
the converter for monochrome bitmaps to C99 source files. The input bitmap file when using this tool
must be a monochrome bitmap. It will not work if the bitmap file has a colour depth of more than 1 bit
per pixel (bpp). If you are having difficulty creating a 1 bpp file use an online converter to convert your
image file to a 1 bpp file, for example…
https://online-converting.com/image/convert2bmp/
• a minimalist (but slow) embedded one for the STM32F407 that uses a generic SPI driven ILI9341
controlled LCD display (see Appendix 5 for connections)
• a hardware accelerated embedded one for the STM32F429DISC1 development board (see
Appendix 4 for connections)
• a hardware accelerated embedded example for the LPC54628 development board with NXP part
number OM13098 (see Appendix 6 for connections)
• an example for the Renesas Envision development board using an RX65N processor with
Renesas part number RTK5RX65N2C00000BR compiled with Renesas CC-RX compiler (see
Appendix 7 for connections)
• another for the same Renesas Envision development board compiled with GCC-RX compiler (see
Appendix 8 for connections)
• an example for the ESP32 processor on a DevKitC board with an ILI9341 controlled LCD display
built with ESP32-IDF development environment (see Appendix 9 for connections)
• a similar example to the previous one for the ESP32 processor on a DevKitC board with an
ILI9341 controlled LCD display but built with the Arduino IDE (see Appendix 9 for connections)
• an example for the PIC32 MX processor on a Microchip Curiosity PIC32 MX470 development
board with an ILI9341 controlled LCD display (see Appendix 10 for connections)
• an example for the PIC32 MZ processor on a Microchip Curiosity PIC32 MZ EF development
board with an ILI9341 controlled LCD display (see Appendix 13 for connections)
• an example for a Raspberry Pi Zero W board that uses a generic SPI driven ILI9341 controlled
LCD display (see Appendix 14 for connections)
• an example for a Raspberry Pi Pico board that uses a generic SPI driven ILI9341 controlled LCD
display (see Appendix 15 for connections)
• an example for an Atmel SAM3X processor on an Arduino Due board that uses a generic SPI
driven ILI9341 controlled LCD display (see Appendix 16 for connections)
• a hardware accelerated embedded one for the Renesas Synergy PK-S5D9 development board
(see Appendix 17 for connections)
• two simulator versions that allows applications to run within a Microsoft Windows window or a
Linux X11 window (see Appendices 11 and 12 for requirements)
Each of the example projects can be built for all of the hardware variants with a few exceptions - some
of the Raspberry Pi Pico and Renesas Synergy S5D9 boards examples. User interface development using
the Windows or Linux simulators reduces application development time. MiniWin application code
developed for either of the simulators can be dropped straight into your embedded project when
completed. In the example projects it’s the same MiniWin and application code running on all platforms.
All sample projects are built with one of these free compilers/IDE’s :
The ST, Microchip, Arduino, NXP compilers/IDE’s and the ESP32-IDF build system can be obtained for
Microsoft Windows or Linux. The Atmel/Microchip Studio IDE, Renesas CC-RX/GCC-RX/e2studio
compiler and Renesas Synergy development environment in e2studio run on Windows only. For
Raspberry Pi OS and Pico SDK the building is done on a Raspberry Pi.
The simulator examples all build using the same development environment as the utilities described
above. This is GCC/clang for Linux, GCC for Raspberry Pi OS, and GCC/clang for Windows running in the
MSYS2 development environment, or cl from Microsoft Visual Studio for Windows.
8 Customisability
Because MiniWin is fully open source its look and feel is fully customisable. Don't like the look of a user
interface component? Simple. Modify its paint function and skin it how you want it to look. More user
interface controls and dialog windows can also be added by copying from the standard set provided.
The tree container utility that is part of MiniWin can be configured to use a statically allocated memory
pool of fixed size decided at compile time, or dynamic memory.
MiniWin code and its 3rd party libraries use no recursion ensuring stack safety in small embedded
systems with limited memory.
10 MISRA Compliance
All source code developed for MiniWin is compliant with all ‘required’ features of the MISRA 2012
coding standard (with a few exceptions of FreeRTOS calls in the FreeRTOS example as these cannot be
made MISRA compliant). This is a unique feature of MiniWin amongst window managers and required
considerable effort to achieve. Open source libraries that MiniWin incorporates are used as is, and have
not been modified to achieve MISRA compliance (these comprise FreeRTOS, driver libraries/start-up
code from silicon vendors, TrueType font library, bitmap font files and the touch screen calibration
routine).
All code generated by the MiniWin development tools (bitmap converters and code generator) is also
compliant with all MISRA 2012 ‘required’ features.
The pixel transformations required to implement display rotation are required in the lcd driver. All the
supplied platform implementations that MiniWin comes with implement this feature and therefore all
example projects can be rotated. The default layout for the supplied hal layers is the natural screen
layout. For the displays used by the embedded ST STM32, Renesas S5D9 and ESP32 examples this is
portrait, for the NXP LPC and Renesas RX examples it is landscape, and for the Windows and Linux
simulators it is portrait.
When display rotation is chosen for the Windows and Linux simulators the window size is adjusted to
reflect the change from portrait to landscape or vice-versa but the displayed window is not actually
rotated on the computer display as this would make development awkward.
Each display’s size for different displays needs to be specified in the hal_lcd.c hal source file. This
value is the physical size in pixels of the display in use (or being simulated). It is not the size after any
rotation is applied. So, for example, the displays attached to the STM32F429DISC1 board has a width of
240 and a height of 320. These vales remain the same in this source file regardless of the display
rotation value chosen in the configuration file.
The touch screen needs recalibrating each time the display rotation in the configuration is changed. This
is described later in this document.
12 Implementing the Hardware Abstraction Layer (hal)
Note: In this document HAL in capitals refers to the ST driver library used for STM32 devices; hal in
lower case refers to the hardware interface part of MiniWin.
The hal sub-project (found under folder hal in the source code) collects all the drivers required by
MiniWin in one location and implements as one low level layer. No other MiniWin code has any
hardware dependency. To port the MiniWin code to your hardware you need to implement the drivers
found here. The following sections describe what you need to do for each driver.
These functions wait in a busy loop for a specified time. This routine is only used by other drivers under
the hal sub-project. If your drivers do not need this capability you do not need to implement these
functions, but some LCD and touch screen drivers need delays during initialisation. Do not use these
functions from within your application code as you will block the responsiveness of your user interface.
It is also imperative not to use these functions from within an interrupt handler or a RTOS task after
initialisation. Use the MiniWin tick timer and message handlers instead.
Function: mw_hal_delay_init
Any hardware initializations for the delay driver are here.
Function: mw_hal_delay_ms
Delay for a specified number of milliseconds.
Function: mw_hal_delay_us
Delay for a specified number of microseconds.
This is not a driver in itself but collects together the initialization routines of all the other drivers. If your
drivers need initialising in a specific order you can implement this here.
Function: mw_hal_init
Calls all other init routines in the hal sub-project.
This driver uses a hardware timer to drive the MiniWin tick counter at 20 Hz.
Function: mw_hal_timer_init
Any hardware initializations for the tick timer driver are here.
Function: mw_hal_timer_fired
This function is called by a timer interrupt handler and increments the MiniWin timer.
Function: varies, timer interrupt handler
This interrupt handler function, which the interrupt routine calls 20 times per second, calls
mw_hal_timer_fired which increments the MiniWin tick counter on each call.
This driver stores settings data in non-volatile memory. This could be a section of internal flash memory,
on chip EEPROM, a SD card or an external chip. Currently only the touch screen parameters are stored
here. If you do not have or wish to use non-volatile storage you can leave these as stubs and your touch
screen will need calibrating on every power up.
Function: hal_non_vol_init
Any hardware inititlisations for the non-vol driver are here.
Function: hal_non_vol_load
This function loads a specified length of data from non-volatile memory into a buffer owned by the
caller.
Function: hal_non_vol_save
This function saves a specified length of data into non-volatile storage. It is up to the driver to decide
where in non-volatile memory to save the data.
This driver detects when the touch screen is pressed and can read the touch screen when requested. It
also contains details about if and when touch screen calibration is required as not all touch screens
require calibration.
Function: mw_hal_touch_init
Any hardware inititlisations for the touch driver are here.
Function: mw_hal_touch_get_state
This function returns whether the screen is currently being touched or not.
Function: mw_hal_touch_get_point
This function gets the current touch point. It should only be called directly after
mw_hal_touch_get_state has been called (and reported that the screen is currently being
touched) to ensure that there is a valid touch point to read. If there is no valid touch point to read then
the function returns false.
This function must return a filtered stable touch point. If this requires multiple reads to be made and
averaged (or otherwise filtered) then this must be performed within this driver function. The function
returns the touch point in raw touch digitizer co-ordinates, which may not be the same as pixel
coordinates. MiniWin incorporates a calibration routine which removes touch screen non-linearities
and also transforms the touch point co-ordinates from raw digitizer co-ordinates (as returned by this
function) to pixel co-ordinates.
Function: mw_hal_touch_is_calibration_required
This function tells MiniWin whether the user has requested a touch screen recalibration by some
hardware method, for example a push-button. If recalibration is required return true. This function is
called only once by the MiniWin window manager at start-up. This functionality is demonstrated in the
embedded driver examples where at start-up a hardware button is checked and if pressed the touch
screen calibration routine is run even if a previous calibration has been performed. For the simulated
drivers and for Raspberry Pi OS deleting file settings.bin found in the same folder as the executable
file achieves the same effect. If calibration is never required by the touchscreen always return false.
This driver implements basic write functions to the display device screen and defines the colour type
and some colours. It also returns details of the screen size in pixels when requested to the MiniWin
window manager or application code.
There is no screen read capability requirement for MiniWin. Memory for display shadow buffers is not
required.
Type: mw_hal_lcd_colour_t
This typedef represents the colour format used by MiniWin and is a 32 bit integer to hold a 24 bit colour
representation.
Function: mw_hal_lcd_init
This function initializes the display device hardware.
Function: mw_hal_lcd_get_screen_width
This function returns the width of the attached display in pixels. When using the Windows or Linux
simulator the values returned by this function can be changed to simulate different sized displays. This
value must be the physical width of the display in pixels regardless of any display rotation requirements.
Display rotation is set in the configuration file (described later).
Function: mw_hal_lcd_get_screen_height
This function returns the height of the attached display in pixels. When using the Windows or Linux
simulator the values returned by this function can be changed to simulate different sized displays. This
value must be the physical height of the display in pixels regardless of any display rotation requirements.
Display rotation is set in the configuration file (described later).
Function: mw_hal_lcd_pixel
This function writes a single pixel with the specified colour to the display device. The x and y
coordinates passed to this function will be within the display’s maximum coordinate bounds and do not
need further checking here.
If you wish to use the display rotation functionality of MiniWin then you need to implement the
coordinate transformations required to achieve that here. If you do not wish to rotate your display but
use the physical layout of your display then no coordinate transformation is required here. See the
example projects for how to implement coordinate transformation if you require it.
If your hardware display supports less than 24 bit colour then the passed in colour must be transformed
in this function to the format required by the hardware display. This technique can be seen in some of
the example LCD hal drivers.
Function mw_hal_lcd_filled_rectangle
This function fills a rectangle on the screen with a single colour. The x and y and x + width and y +
height coordinates passed to this function will already be within the display’s maximum coordinate
bounds and do not need further checking by code in this function.
If you wish to use the display rotation functionality of MiniWin then you need to implement the
coordinate transformations required to achieve that here. If you do not wish to rotate your display but
use the physical layout of your display then no coordinate transformation is required here. See the
example projects for how to implement coordinate transformation if you require it.
If your hardware display supports less than 24 bit colour then the passed in colour must be transformed
in this function to the format required by the hardware display.
Function mw_hal_colour_bitmap_clip
This function fills a full colour rectangle on the screen with data from bitmap specified by the caller. The
bitmap data must be in the format of 3 bytes per pixel. The image data must start at the top left and
proceed across a full row before starting the next row. The co-ordinates of all points within the bitmap's
rectangle must be clipped to a caller specified clip rectangle by code in this function. It is only necessary
to implement this function if your user code is going need it. The MiniWin window manager, dialogs and
user interface components do not require it. The example projects, however, do need it.
If your hardware display supports less than 24 bit colour then the passed in bitmap pixels’ colours must
be transformed in this function to the format required by the hardware display.
Function mw_hal_lcd_monochrome_bitmap_clip
This function fills a monochrome rectangle on the screen with data from bitmap specified by the caller.
The bitmap data must be in 8 pixels per byte format, left most pixel in the byte's msb. The image data
must start at the top left and proceed across a full row before starting the next row. The co-ordinates of
all points within the bitmap's rectangle must be clipped to a caller specified clip rectangle by code in this
function. The actual colours to use for the 2 possible colours are specified in the device colour format.
The previous 3 functions can all be implemented using the pixel plotting function above. This reduces
the amount of work needed porting the driver to your hardware but at the expense of running more
slowly. This technique is used for the STM32F407 hal driver layer so those examples can be copied when
porting your own display driver as a quick start.
13 Paint Algorithm
MiniWin uses a painting algorithm that is optimized for use on a system without a shadow screen buffer
or dual buffers, i.e. all writes to the display memory are shown immediately on the display. To avoid
flickering each part of the display is written to only once for each repaint request.
The repaint algorithm used is the singly-combined sorted intersections algorithm. This algorithm has two
parts.
When a repaint request is received for a rectangular area the first part the algorithm searches for all
window edges that intersect this area. These edges are collected into two arrays, one of horizontal
edges, the other of vertical edges. The edges of the rectangle being repainted are also added to the
arrays. Then the contents of each array are sorted numerically.
For the second part of the algorithm there is a pair of nested loops that iterates through the array of
horizontal edges and for each horizontal edge iterates through the array of vertical edges. For each
horizontal/vertical edge intersection the highest Z order of the visible window (including root) at the
point is found, along with the window that has this Z order. The paint algorithm is called for this window
with a clip area with origin of this intersection point and a width and height of the difference between
the current intersection in the edges arrays and the subsequent intersections.
The singly-combined part of the algorithm means that when a rectangle to repaint is found in the inner
loop the window's paint function is not called immediately. Instead, the call to the repaint is suspended
until the next iteration of the inner loop. If at the next iteration it is found that the subsequent rectangle
has the same Z order as the previous then painting is delayed again. If the subsequent rectangle has a
different Z order then only now is the previously identified rectangle (or combined rectangles) painted.
In this way rectangles along the same row are combined, but rectangles on different rows are not -
hence singly-combined.
Additional optimizations take place when deciding on how to repaint a rectangle. If a rectangle is
completely within a window that has focus then nothing overlaps it and it is painted completely. If a
rectangle is completely overlapped by higher Z order windows then its repaint request is ignored.
14 Z Orders
All windows have a Z order. This is the window's position in the stack of windows and determines which
window is drawn on which. 0 is the lowest Z order and this value is reserved for the root window.
Reasons for a Z ordering change are: a new window is created, a window is removed, a window is sent
to the back, a window is sent to the front, a window is minimized, a window is restored, or a window is
given focus. Whenever a Z ordering change occurs all the Z orders are rationalized, which means that
they go from 1 to the number of currently used windows with no gaps in the numbering. This is done
automatically by MiniWin; no user code is required.
The window with the highest Z order is the window with focus. This window is drawn with a different
colour title bar (blue by default) from unfocused windows (title bar grey by default). When a window is
created or restored it is given the highest Z order and is given focus. When a window loses focus,
because it is removed, minimized, or another window is brought to the front the next highest Z ordered
window gains focus. A message is sent to a window’s message handler whenever it gains or loses focus.
Controls are handled differently. They do not have a Z order compared to other controls in the same
window. It is safest if controls are positioned so that they do no overlap as the painting order (and hence
which one appears on top of which) is uncontrolled. If a control needs to appear temporarily on top of
another control, for example simulating a cascading menu with a pop-up list box, then it is up to the
user code to make sure that the underlying control is temporarily made invisible. This may seem as a
limitation to using layered pop-up controls, but it keeps MiniWin small and simple.
However, there may be cases where multiple instances of the same window type are required to be
displayed. In these cases no window data can be stored within the source file as static data as this would
not allow different data for the different instances of the same window type. In these cases each
window instance’s data needs to be stored externally and a pointer to this data made available to the
window’s message handler and paint functions. Therefore each window has associated with it a void
pointer which is used to store instance data. This pointer is set when the window is created in the
mw_add_window function. If only a single instance of a window is required and window data is stored in
the window’s source file as static data then this pointer can be NULL.
The example project MiniWinFile uses multiple instances of the same window type to show multiple
images and text files, each in its own instance of the same window type.
16 Graphics Library
MiniWin comes with a standard graphics library (gl) supporting the normal lines, fonts and shapes as
well as polygon and shape rotation. It includes simple patterned lines and texture fills. These library
functions can be used to draw window components, or window or control client areas.
All graphics library drawing routines are window aware - you do not have to worry about where your
window or control is, if it is overlapped or partly or fully off screen. You just draw to the client area
regardless using the client area as your frame of reference. MiniWin performs all window offset
translations and clipping required. You will never end up drawing outside of your window or control or
scribbling somewhere you shouldn't.
All painting should be done via this graphics library to ensure correct clipping of any graphics function
coordinates that fall outside of a window or control.
The coordinate system used in all graphics commands in gl is that of the item being painted. If a window
frame is being painted then the origin coordinate (0, 0) represents the top left corner of the window
frame. If a window client area is being painted (0, 0) represents the top left corner of the client area, and
for a control (0, 0) represents the top left corner of the control's client area. Controls do not have
frames.
Calling a gl function with coordinates beyond the boundaries of the item (window frame, client area,
control) being painted (including negative coordinate values) will result in the pixels being automatically
clipped. Pixels up to the boundary will be painted, so for example if a line is asked to be drawn where
the origin is within the area being painted but the end point is outside the line will be drawn from the
origin up to the boundary.
All window and control paint routines pass in a pointer to a mw_gl_draw_info_t parameter. This
contains information on the frame of reference origin of the area item being painted and the clipping
area extents. It is not necessary for the user code to use any values in this data structure, simply pass it
on to any function calls in gl.
The gl library uses the concept of a graphics context in its calls. Individual functions are not passed
parameters describing the required colour, line style, fill pattern etc. These are set in a graphics context
structure that belongs to gl using the gl API. Values in the graphics context are set first and then all
subsequent calls to gl functions will use these values. Values that can be set in the graphics context are
as follows:
• foreground colour
• background colour
• line pattern
• solid fill colour
• solid fill pattern
• background transparency
• border on or off
• which bitmap font to use (not TrueType font)
• text rotation
The contents of a graphics context are not preserved between subsequent calls to paint functions. It is
necessary to set the values at every use. The gl library provides an accessor for a pointer to its internal gl
structure so if setting the contents on every paint function call is not suitable the user code can keep a
local copy and use memcpy() to copy the local copy into gl's copy as an alternative.
16.1 Fonts
MiniWin comes with a viariety of font capabilities as part of gl. Some of these are always available and
others are optional which can be included or excluded by user code configuration, depending on
requirements and available program memory on the target device. The font types fall into the following
categories:
Before calling a bitmapped font rendering function in gl the font style, foreground colour, background
colour, transparency and text rotation must be set in the graphics context. The function call to render
the text is the following:
/**
* Draw a string of small fixed width characters. Foreground
* colour, background colour, rotation, bitmap font and transparency
controlled by gc.
*
* @param draw_info Reference frame origin coordinates and clip region rect
* @param x Coordinate of the left edge of the rectangle containing the first
* character
* @param y Coordinate of the top edge of the rectangle containing the first
* character
* @param s Pointer to the null terminated string containing ASCII characters
*/
void mw_gl_string(const mw_gl_draw_info_t *draw_info, int16_t x, int16_t y,
const char *s);
Like the always available bit-mapped fonts these can be rendered rotated and transparently if required,
contain all the ASCII characters, and are always rendered left justified. The function call is the same as
given in the previous section.
TrueType font files are often large and real-time rendering of the font glyphs from the TrueType font
data to alpha blended pixels as they are required takes significant processing power and program code
space – too much for a small embedded device. Therefore in order to use TrueType fonts the font file is
pre-processed before compiling to convert the data into C99 data structures containing run-length
encoded font data. This increases rendering speed and reduces code space with the downside that the
font sizes available must be chosen before compiling, and every different font size takes extra constant
data space.
make -f makefile_linux.
For Windows users the font conversion tool is supplied pre-built under the Tools\FontEncoder
folder under the MiniWin root folder, named mcufont.exe.
Processing a TrueType .ttf file to a .c file that can be included in your embedded application is a four
stage process, all done via different commands to the same font processing tool. At any time you can
see the required command line by typing mcufont with no parameters.
The first command is to import the .ttf file which converts it to a .dat file. A typical command is…
The next command is to choose which characters from the font you wish to use in your application, as
some TrueType fonts contain thousands of characters (currently MiniWin only supports single byte
characters, so this range’s endpoint should not be greater than 255). A numerical range (or ranges) is
given to choose these values. To choose only ASCII characters for example use 0 – 128 range…
The next command is to optimize your converted font’s data file to the minimum size. This can take a
few minutes. An example command is…
This produces a file called DejaVuSans12.c which can be dropped into your project’s source folder
and added to the project.
This extern reference is how you specify the font you wish to use to the text rendering function. You can
have multiple fonts and point sizes available in your application if you wish.
Before calling the text rendering function in gl you need to set the foreground and background colour in
the graphics context. The rotation and transparency values do not need to be set as these are not
available for TrueType font rendering in MiniWin. Unlike bitmapped font rendering TrueType fonts are
rendered across multiple lines in a box. You therefore specify a containing rectangle rather than just a
start position. The function call in gl is as follows:
/**
* Render justified true type text in a box
*
* @param draw_info Reference frame origin coordinates and clip region rect
* @param text_rect The rect in the window's client area that the text is to
be rendered into
* @param justification The justification to use when rendering the text
* @param rle_font The true type font to use
* @param tt_text The text to render
* @param vert_scroll How many pixel lines to scroll the text up
*/
void mw_gl_tt_render_text(const mw_gl_draw_info_t *draw_info,
mw_util_rect_t *text_rect,
mw_gl_tt_font_justification_t justification,
const struct mf_rlefont_s *rle_font,
const char *tt_text,
uint16_t vert_scroll_pixels);
The memory for the tree container can be allocated in two ways…
1) Statically allocated memory pool defined at compile time which cannot be enlarged at run time
2) Dynamically allocated in blocks at run time with an initial block allocated dynamically at start up
and reallocated to change size as required.
The node types mentioned above are referred to in the API and code as ‘folder’ (for those that can
contain children) and ‘file’ (for those that cannot). Although this matches to the concept of a file system
tree the folder and file node types can be used to represent tree data that is not a file system.
All nodes of both types have the concept of being selected. This is simply a flag that each node has that
can be set or reset on a node by node basis. Options are available as to whether single or multiple nodes
can be selected, or selection is not available at all. It is up to the user of the tree to give any meaning to
a node’s selected status.
Folder nodes have the concept of being open or closed. Again, this is a flag that all folder nodes have.
When a search is performed to retrieve children of a folder, only open sub-folders are searched. This is
explained in more detail later.
Option MW_TREE_CONTAINER_SINGLE_SELECT_ONLY
This option means that zero or one node can be selected at a time. When a node is set as selected any
other node that is already selected is set as unselected.
A lack of either of the 2 previous flags means that multiple nodes can be selected at once.
Option MW_TREE_CONTAINER_FOLDER_SELECT_ONLY
This option means that only folder nodes can be set as selected.
Option MW_TREE_CONTAINER_FILE_SELECT_ONLY
This option means that only file nodes can be set as selected.
A lack of either of the 2 previous flags means that both folder and file nodes can be selected
simultaneously.
Option MW_TREE_CONTAINER_SHOW_FOLDERS_ONLY
This option means that when doing a query on a tree container to retrieve all the children/sub-children
of a folder node only folder nodes will be returned
Option MW_TREE_CONTAINER_NODE_LABEL_MAX_SIZE
This option specifies the maximum size if each node’s text label string, including terminating NULL.
Option MW_TREE_CONTAINER_NODE_IS_SELECTED
This option specifies that a node is selected and can be changed at any time.
Option MW_TREE_CONTAINER_NODE_FOLDER_IS_OPEN
This option only applies to folder nodes and specifies that it is open when set or closed when not set.
The value can be changed at any time.
The root folder path can be any text up to the maximum label size, or none, but must be appended with
the folder separator character. The tree and root node flags are as described above.
If the node array is statically allocated or dynamically allocated but can never be enlarged pass NULL as
the no_space_callback parameter. If the node array requires enlarging pass a pointer to a function
of mw_tree_container_no_space_callback_t type. A simplified example of this function’s
possible implementation is shown below which expands the node array by 5.
mw_tree_container_set_new_node_array(tree, (mw_tree_container_node_t
*)new_array, new_size);
}
The final parameter to mw_tree_container_init is the folder separator which must be the same as
the last character of the root folder path. The returned value from this call is the handle of the root
folder which is used subsequently to refer to the root folder.
mw_handle_t mw_tree_container_add_node(
struct mw_tree_container_t *tree,
mw_handle_t parent_folder_handle,
char *label,
uint8_t node_flags);
Like all calls to the API the first parameter is a pointer to the tree structure variable. The handle of the
folder in which this new member will reside is given next, then its label (which can be an empty string).
A folder node does not need the folder separator appending to its label. Finally the new node flags as
described above. This call can be used to add a folder or a file.
The new node’s handle is returned. If a folder is added then the returned handle needs to be retained if
any further items are added to that folder in order to identify it.
void mw_tree_container_get_all_children(
struct mw_tree_container_t *tree,
mw_handle_t parent_folder_handle,
bool selected_only,
mw_tree_container_next_child_callback_t *callback,
void *callback_data);
The tree parameter is as described for previous calls. The parent_folder_handle parameter is the
handle of the folder to search. Note that there is no call-back for this folder, only its children. If
selected_only is true then only nodes that have their selected flag set are returned. The callback
parameter is a pointer to a function that will be called for each found node. The callback_data
parameter can be any pointer to any data structure that the user requires passing to the call-back
function. It is passed untouched to the call-back function. It can be NULL, but it is up to the call-back
function to ensure that a NULL pointer is not de-referenced.
A similar API call exists to get just the count of children without any call-back function being called.
After calling mw_tree_container_get_all_children a further API function exists that will return
the handle of a node at a specified position that mw_tree_container_get_all_children returned,
assuming that the tree has not had its contents changed before this subsequent call. The function is this
(parameters have the same meaning as mw_tree_container_get_all_children):
mw_handle_t mw_tree_container_get_handle_from_position(
struct mw_tree_container_t *tree,
mw_handle_t parent_folder_handle,
bool selected_only,
uint16_t position);
This function is useful if for example a list has been populated via the
mw_tree_container_get_all_children call and subsequently at item at a known position is
selected and the handle of the node at the selected position is required.
Other API functions of the tree container utility are straightforward and are not described here. See the
Doxygen documentation for details.
18 Standard Controls Overview
There is a set of standard controls available in MiniWin. This set is smaller and simpler than that
provided by more sophisticated window managers, but they can be combined to work collaboratively to
produce a greater range - for example the list box control can be combined with the standalone vertical
scrollbar to produce a scrolling list box. Some extra user code is required to do this, or the code
generator can be configured to do it for you.
All of the controls provided by MiniWin come in two sizes – a small size for stylus operated touch
screens and a large size for finger operated touch screens. Progress bars and text boxes are created with
a size specified in code and there is no small or large concept for these control types.
Each control has its own source and header files. For each control there are a minimum of 3 functions -
the control message handler, the control paint function and a utility function to simplify the creation of
the control. The controls’ message handlers and paint functions must all have the same parameters and
return type. These function signatures are declared in miniwin.h. Some controls also have additional
utility functions to help with their use as required.
Each control has its own data structure storing fields common to all controls, for example visibility, size,
currently used and enabled statuses. These data structures are stored in an array of all the controls. The
size of this array is specified at compile time in the MiniWin configuration header file. In addition to this
common data structure each control type has a control-specific data structure to store instance data
unique to each instance of a particular control in use. For example, a button has a single label but a list
box has an array of labels, icons and the array size. Each instance data structure is declared in the
control's header file and the standard control common data structure contains a void pointer to
reference it. The fields in the control-specific data structure are initialized when the control is created.
Some fields are user code modifiable and some are not; the non-user-code-modifiable fields contain
control state and should not be changed by user code. Each control-specific data structure indicates
which fields are user code modifiable and which should not be changed in the structure’s declaration in
the control's header file.
It is possible in MiniWin to have multiple instances of the same control within the system, for example
multiple buttons. Each instance requires its own entry in the array of control common structures and
also requires its own instance of its control-specific data structure.
When controls are created there are 3 flags that can be specified to alter their appearance and
behaviour. These flags and their effects are:
Controls can only be placed in windows, not in other controls. However, controls can be placed on the
root window, and with suitable code, made pop-up. The MiniWinRoot example project shows this
usage.
19 Enabling and Disabling Controls
Most controls and control like features of a window frame (menu bar, vertical and horizontal scroll bars)
can be enabled and disabled. When a control is disabled it accepts no input and is drawn greyed out. For
list boxes and the menu bar, as well as the global enable/disable feature, these controls can also have
each item enabled and disabled separately. This is done by setting bits in a 16 bit bit-field. This means
that the maximum number of items in a menu bar or list box is 16.
There are utilities functions in miniwin_utilities.c that allow a single bit in a 16 bit bit-field to be
set or read. There are also macros defined in miniwin.h for setting or clearing all bits. If the global
enable flag for list boxes or menu bars is false then all items are disabled. If the global flag is true
then items that also have their bit-field bits set are enabled, all others are disabled.
20 Standard Dialogs
MiniWin contains a set of standard dialogs. These are pre-coded windows that are instantiated with a
single function call that can partly customise them. Dialogs are all shown as system modal – that is the
operator must respond to them and dismiss them before continuing. Because of this only one dialog can
be shown at any time and they are automatically given focus and sent to the top of all other windows
when shown. They cannot be resized. They can be closed only by pressing one of the controls, typically
an OK and/or Cancel button. Data can be sent to any window from a dialog when the dialog is dismissed.
All dialogs can be created as standard or large size. When created as large size the controls within them
are also all created large size. A dialog must be completely on the screen when it is created or else the
creation will fail and it won’t be shown. The text entry dialog needs care in this respect as the large size
keyboard control it creates is large and its width does not fit within a QVGA small dimension of 240
pixels.
The following sections describe the dialogs that exist within MiniWin.
char *app_get_root_folder_path(void);
The MiniWin message queue and message processing function is part of MiniWin. The user code's
interaction with this process is to handle messages in their window's message handler and to call the
message processing function repeatedly and often from their main loop. User code must handle
messages to respond to events and can also post messages of their own to the message queue, either to
coordinate with the window manager or to pass messages to other windows and controls in the system.
Messages are processed by the window manager in the order they were posted. For example, if in user
code a message is posted to change the text in a label and then the paint control function is called
(which is just a utility to post a paint control message), the messages will be processed in that order and
the text in the label will be changed before the label is repainted. The processing of the messages will
happen asynchronously, i.e. at a later time to the post message function calls. A consequence of this is
that debugging is sometimes not straightforward. In the example given the actual painting of the control
will not happen within the paint control function call. The solution to this debugging problem is to place
a breakpoint on the code where the message is handled.
Message id: This is the message identifier from the list in miniwin.h
Sender handle: This is the window handle or control handle of the message poster for messages posted
from window or control code.
Recipient handle: This is the window handle or control handle of the recipient of messages posted to
windows or controls.
Recipient type: This is the type of the recipient and can be a window, a control, the window manager or
a special value indicating that the message has been cancelled and should be removed.
Message data: This is a 32 bit data value sent from the sender to the recipient. Sometimes this value is
used as 2 16 bit integers, 4 bytes or a single precision float. It is up to the recipient code to do the
appropriate shifting, masking and casting if required.
Message pointer: This is a void* value sent from the sender to the recipient. It can be a pointer to
anything and cast appropriately by the message recipient. The memory pointed to must exist for the
lifetime of the message, which means static or global data. Sending a message with a pointer to a local
variable which has gone out of scope by the time the recipient receives the message will not end well.
It is not necessary to fill in all of the fields for all messages. The context will indicate when this is not
necessary, for example a message to the window manager does not have a recipient handle, and both
the message data/pointer field are often not needed. There is a pre-defined value which can be used to
indicate an unused field in miniwin.h called MW_UNUSED_MESSAGE_PARAMETER, but this is simply
defined as zero.
22 Transferring Data to Message Handler Functions
All communication between windows and controls with each other is done by passing messages. The
MiniWin message structure contains a 32 bit data field. This is general purpose and can be used to pass
a 32 bit values, 2 16 bit values, 4 bytes or a single precision float. It should not be used to pass a pointer
as this field is fixed at 32 bits and the pointer size on your system may be different. Use the pointer field
instead.
As no dynamic memory allocations are used in MiniWin, when the pointer field in a message is used, the
object pointed to must not be a local variable that goes out of scope after the message is posted - it
must be either static if it's a local function scope variable, be a file scope variable or a global variable, or
a constant. This restriction does not apply to non-pointer data if the single 32 bit value is used as data as
the value is copied into the message.
When a resource is created a handle to that resource is returned from the resource create function call.
This handle is used to refer to the resource in all subsequent calls to the window manager from user
code or to user code from the window manager. This handle is not a pointer – do not dereference it. All
handles are unique and used only once. A handle is typedef’d as a uint32_t meaning that there can be
over 4 billion of them. Handle numbers can grow large - for example as MiniWin timers are one shot
every timer firing creates a new handle. If there is any risk of the more than 4 billion handles change the
typedef in miniwin.h to a uint64_t.
When calling a MiniWin public function all MiniWin objects are referred to in the public API function call
by their handle. However, in the window manager’s internal code it is necessary to obtain the position in
the array of a particular resource type (window, control or timer). This position in the array is called an
id. Inside MiniWin handles are converted to id’s. All variables within MiniWin that contain a handle end
in the name _handle and all variables that contain an id end in the name _id.
24 Touch Events
WiniMin creates 4 different touch events from operator input on the touch screen. Each message passes
the coordinates of the touch location in the corresponding message's data parameter. The x coordinate
is in the upper 16 bits and the y coordinate in the lower 16 bits.
Touch down: this event has a new location, the point on which the screen has been touched, so this is
passed in the message.
Touch hold down: this event has a location, the point on which the screen has been touched, so this is
passed in the message.
Touch up: only the last known touch screen location is known, so this is passed in the message.
Touch drag: this also has a new touch location which is passed in the message.
For all touch events there is a time difference which must pass between two touch events being created.
This prevents multiple messages being passed for a single operator touch, a touch screen equivalent of
key de-bouncing. For drag messages there is a distance difference which must be exceeded between the
posting of two touch events. This is to prevent a flood of drag messages being created from the touch
point oscillating between two adjacent locations.
Both the touch event time difference and the drag distance difference are customizable in the
configuration header file.
When a touch down is made in a window that does not have focus the window receiving the touch
down event is given focus and brought to the front. By default, after this, the touch event has been
consumed by the giving of focus to the window and the window message function does not receive the
touch down event. This behaviour is unsuitable for non-overlapped fixed windows where windows
without title bars do not show any sign of having focus to the operator. In this case it is desirable if the
touch event in a non-focused window is also passed on to the window’s message handler as a standard
touch down event. It is possible to configure this behaviour when creating the fixed window by
specifying the MW_WINDOW_FLAG_TOUCH_FOCUS_AND_EVENT flag. See the fixed windows example
project which uses this flag.
Window frames: Rendering of window frames is done in window manager code, not in user code.
Window frames have some configurable parts and some non-configurable parts. Optional parts are a
title bar, a border, a menu bar, a vertical scroll bar and a horizontal scroll bar. If a title bar is specified
then on the title bar are a resize control, a title, a minimize icon, a maximize icon and a close window
icon. The close window icon is drawn enabled or disabled depending on if the window is created as
closeable or not. The resize and maximize icons are drawn enabled or disabled depending on if the
window is created as fixed size or not. A message can be sent to the window manager to repaint the
window frame. A parameter specifies which components of the window frame to repaint.
Window client area: Painting of the window client area is done in a window's paint function in user
code. The user code sets values in the gl library's graphics context then calls functions in the gl library
passing to the gl call the draw_info received in the paint function parameter. The client area is painted
before the controls belonging to a window so that the controls will always appear on top. In user code a
request can be made to paint a client area completely or only a sub-section of the client by calling a
different function that takes the rectangle area to repaint as a parameter. The window manager does
not paint the window client area background. It is up to the user code to do this. You will see this being
done in all the example project window paint functions.
Control client area painting: A control has no frame and the client area covers the whole of the control's
area. The painting method is the same as for a window client area except a control cannot contain sub-
controls. Like a window client area a request can be made to paint a control completely or only partly.
The general rule in MiniWin user code development is that when a repaint is required because of
something the operator has done then MiniWin will instigate the required repaint. Examples of this are
moving, resizing, closing, minimizing and restoring a window. All repaints needed as a result of user code
will need to be instigated in user code by calling a MiniWin utility function to post the required repaint
message. An example of this is changing the text a label control displays. The user code posts a message
to change the text, then posts a message to paint the control. Forgetting this behaviour is the most
common answer to the question “why has my control not changed after I updated one of its values?”
There are many different types of painting request. This is also to minimize computation and flicker. A
window frame is requested to paint according to its features (title bar, border, menu bar, 2 scroll bars).
A window client area or a control client area can be requested to be painted in their entirety or a sub-
section defined by a rectangle. Finally a paint all can be requested which paints everything currently
displayed. Always use the minimum painting type for the situation. Requesting a paint all at all times
may be easy and the least code to write, but it will not give a pleasing operator experience.
27 Scroll Bars
There are two types of scroll bars - window frame and control - and each type comes in horizontal and
vertical versions. Each type is described below.
Window frame scroll bars: these scroll bars are part of the window frame. They are always at the
bottom edge (for horizontal scroll bars) or right edge (for vertical scroll bars) of the window just inside
the border, if the window has one, and are always the height/width of the window client area. As a
window is resized these scroll bars will resize and reposition themselves to remain at their respective
edge and full window client area width/height. Window scroll bars have their scroll position set by the
operator or programmatically, and can be enabled and disabled via the MiniWin manager API.
Control scroll bars: these are user interface controls just like any other. They have a location where they
are drawn on a window's client rect and that's where they remain. If a window is resized so that they are
no longer within the client rect they are no longer visible. Control scroll bars have their scroll position
set by the operator or programmatically by sending them a message, and can be enabled or disabled
using the generic MiniWin window manager API for enabling and disabling controls.
Both types of scroll bars do no scroll anything on their own. When the operator scrolls a scroll bar its
scroll position is posted as a message as a proportion of its range (always 0 - 255) and nothing else. It is
up to the owning window's message handler to handle the message and issue a paint request to
perform the correct drawing of its contents, shifted as appropriate according to a scroll bar's position.
28 Combining Controls
MiniWin contains only a limited set of simple controls to keep its code base small. The user code
developer can of course add more controls for more complex functionality, but an alternative is to
combine controls. Two examples are described here:
Cascading menus: a MiniWin window frame can have a menu bar as part of its window frame but not
cascading menus. However, a menu bar item can in its message handler cause a list box to appear
immediately below the menu bar item. Each item in this list box could pop up a further list box, giving
the impression of cascading menus.
Scrolling controls: MiniWin list box, text box and tree controls can have more content than they can
show in their client area at any one time. A solution to this is to make them scrolling. None of these
controls can be created with its own scroll bar, but they can co-operate with a separate vertical scroll
bar control that the user code creates.
To implement this feature these control types are scroll aware. This means that their scroll position can
be set from their parent window and the control will take this into account when it paints itself. In
addition, these controls will inform their parent window if they actually need to be scrolled depending
on their current content. For example, a list box with 4 entries created able to show 6 lines does not
need to be scrolled. A text box created 100 pixels high but currently showing text when rendered that is
400 lines high will need to be scrolled.
This message is sent from the list box’s parent window to the list box control and contains the
proportion (0 – 255) that a list box should scroll. This is useful when a vertical scroll bar is used to scroll a
list box as it is the same value that a scroll bar sends. In the parent window’s message handler handle
this message from the vertical scroll bar and send the data value on to the list box.
MW_LIST_BOX_LINES_TO_SCROLL_MESSAGE
This message is sent from the list box’s parent window to the list box control and contains the absolute
number of lines the list box should scroll (this is list box lines, not vertical pixels). For example, if a list
box can show 4 lines but currently has 6 entries sending a value of 2 will display lines 2, 3, 4 and 5. This is
useful when arrow buttons are used to scroll a list box.
MW_LIST_BOX_SCROLLING_REQUIRED_MESSAGE
This message is sent from a list box to its parent window both when the list box control is created and
when a list box has its array of entries changed. This message indicates if scrolling is necessary and the
maximum number of lines the list box can be scrolled. Handle this message in the list box’s parent
window to enable/disable a scroll bar or arrow buttons and to record the maximum number of lines the
list box can be scrolled if arrow buttons are used for scrolling.
MW_TEXT_BOX_SCROLL_BAR_POSITION_MESSAGE
This message is sent from the text box’s parent window to the text box control and contains the
proportion (0 – 255) that a text box should scroll. This is useful when a vertical scroll bar is used to scroll
a text box as it is the same value that a scroll bar sends. In the parent window’s message handler handle
this message from the vertical scroll bar and send the data value on to the text box.
MW_TEXT_BOX_LINES_TO_SCROLL_MESSAGE
This message is sent from the text box’s parent window to the text box control and contains the
absolute number of vertical pixel lines the text box should scroll. For example, if a text box can show 200
pixel lines but currently has text contents that when rendered is 400 pixel lines high sending a value of
50 will render lines of text from 50 to 250. This is useful when arrow buttons are used to scroll a text
box.
MW_TEXT_BOX_SCROLLING_REQUIRED_MESSAGE
This message is sent from a text box to its parent window both when the text box control is created and
when a text box has its contents changed. This message indicates if scrolling is necessary and the
maximum number of vertical pixel lines the text box can be scrolled. Handle this message in the text
box’s parent window to enable/disable a scroll bar or arrow buttons and to record the maximum
number of vertical pixel lines the text box can be scrolled if arrow buttons are used for scrolling.
MW_TREE_SCROLL_BAR_POSITION_MESSAGE
This message is sent from the tree’s parent window to the tree control and contains the proportion (0 –
255) that a tree should scroll. This is useful when a vertical scroll bar is used to scroll a tree as it is the
same value that a scroll bar sends. In the parent window’s message handler handle this message from
the vertical scroll bar and send the data value on to the tree.
MW_TREE_LINES_TO_SCROLL_MESSAGE
This message is sent from the tree’s parent window to the tree control and contains the absolute
number of lines the tree should scroll (this is tree lines, not vertical pixels). For example, if a tree can
show 4 lines but currently has 6 nodes visible sending a value of 2 will display nodes 2, 3, 4 and 5. This is
useful when arrow buttons are used to scroll a tree.
MW_TREE_SCROLLING_REQUIRED_MESSAGE
This message is sent from a tree to its parent window both when the tree control is created and when
its data are changed. A change in data could be a change in the node entries in the underlying tree
container, or a folder node opened or closed. This message indicates if scrolling is necessary and the
maximum number of lines the tree can be scrolled. Handle this message in the tree’s parent window to
enable/disable a scroll bar or arrow buttons and to record the maximum number of lines the tree can be
scrolled if arrow buttons are used for scrolling.
Moving a window: a window is moved by dragging the window's title bar in an area away from the
icons.
Maximizing a window: a window is maximized by tapping the maximize icon on the window's title bar...
If a window is created as fixed size then the maximize icon is greyed out. When enabled tapping this icon
makes the window the same size as the display.
Minimizing a window: a window can be minimized by tapping the minimize icon on the window's title
bar...
This reduces the window to an icon at the next location along the bottom of the screen. A closed
window icon is a simple grey box with the window's title written across it. Icons cannot be moved on the
screen. An operator has no choice where an icon is located; MiniWin chooses the location automatically.
Resizing a window: a window can be resized by dragging the resize arrow icon at the left side of the
window's title bar...
Only this corner can be used to resize a window. A window's borders cannot be used to resize it as in
MiniWin they are too thin to locate the pointer on.
All example projects go into the touchscreen calibration routine on first start-up. If the operator
completes this successfully the calibration settings are stored in non-volatile memory and calibration
does not need to be repeated on subsequent starts.
It is possible for all projects on all platforms to force a recalibration on any start-up. This is always
required when changing the rotation of the display in the configuration file (see the configuration
section later). The techniques for forcing a recalibration are listed below for each platform:
30.1 MiniWinTest
This is a comprehensive example using most of MiniWin’s user interface features. The MiniWinTest
example project creates a variety of windows to test and demonstrate the MiniWin features. Below is a
description of the windows created in the example project and what they demonstrate.
window_drag.c
This window demonstrates capturing drag events. It stores the 15 most recent drag points received and
draws a line between them all. Additionally it displays details of the touch and drag events in the
window.
window_gl.c
This window demonstrates all the features of the functions found in the gl library except for TrueType
font rendering. The features are separated out into multiple paint sections each of which is changed
after a second by a timer. The test cycles forever.
window_paint_rect.c
This window shows how a window can be partially repainted rather that repainting the whole window
every time a section needs repainting.
window_scroll.c
This window demonstrates window frame scroll bars by allowing a text pattern to be scrolled around
horizontally and vertically.
window_tabs.c
This window demonstrates tabs controls. Two tabs controls are used – an automatic one which resizes
to the window client area width when the window is resized and a fixed one which does not resize with
the window.
window_yield.c
This window shows how a long task (plotting 1000 circles) can be split over multiple window message
function calls. Restoring, moving or resizing the window restarts the task which shows how to capture
these events.
window_test.c
This window demonstrates most of the user interface controls and the menu bar. It shows how controls
with multiple items (menu bar and list box) can have some items enabled and disabled. There are two
scroll bars, one for input and one for output with the position of the input one reflected to the output
one. It shows how touch events on the client area can be captured. It shows how to simulate cascading
menus by appropriately place a list box and also how a list box and a scroll bar can be combined to
simulate a scrolling list box.
window_tree.c
This window demonstrates the tree user interface component. It uses a statically allocated tree
container which has a preloaded and fixed number of nodes of folder and file types. The tree container
is specified as not supporting selection. The tree user interface component when this option is selected
animates briefly the node the user has selected. When a node is selected a label in the window updates
with the path of the selected node.
30.2 MiniWinSimple
This project contains the example code as described in detail later in this document to demonstrate a
minimalistic application with one window, one pop-up standard dialog and 2 controls.
30.3 MiniWinRoot
This project shows how to use the root window. A single button is created on the root window and has
its message handler in the root window message handler. A normally invisible window with no border
and no title bar is created that is completely filled by a list box. When the operator touches the root
window this window is moved to that touch point and made visible. This simulates a pop-up menu on
the desktop. When the top item is selected in this list box a pop-up colour chooser dialog is shown
where the operator can choose a colour. If a colour is chosen and the OK button selected the chosen
colour is used as the fill colour for the root window.
In addition the root window background is drawn with a bitmap to demonstrate this capability.
30.4 MiniWinFile
This project connects to a pen drive via USB for the STM32F4xx, Renesas PK-S5D9 and Renesas CC-RX
compiled RX65N examples, a SD card via an SDIO interface for the LPC54628 example, a SD card via an
SPI interface for the GCC-RX compiled RX65N, the PIC32, Raspberry Pi Pico and the ESP32 examples, or
the Windows/Linux/Raspberry Pi OS file system for the Windows/Linux/Raspberry Pi OS examples, to
show folder listings. This allows directories to be traversed and .txt text file and .bmp image files to be
opened and their contents displayed. Multiple windows (up to a fixed limit) are allowed for each file
type.
When the app starts two windows are shown – titled “File Tree” and “File Demo”.
In window titled “File Demo” tap the button to open the file system. Folders and files are shown, each
type with their own icon. If there are more file/folder entries than can be fitted in to the list box visible
lines you can scroll the list box with the up and down arrows. Tap a folder name to open that folder and
tap the left arrow to go up a folder. Tap a .bmp or a .txt file name and then the Open button to open
that file. A new window pops up showing the file’s contents. Filenames are shown in the 8-dot-3 format
on embedded hardware examples.
In window titled “File Tree” tap the > arrow on the root folder to open it and display its contents.
Further sub-folders can be opened in a similar way, scrolling the tree if it becomes too big to fit in the
tree’s box. Both files and folders can be selected with multiple selections allowed. A label in the window
is updated with the path of the latest selection. Pressing the button labeled “Show” briefly pops up a
window listing the selected files and folders. This pop-up window hides itself automatically.
Hidden and system files and folders are not shown in all examples except the ESP32 variant. This is
because the ESP32-IDF file API does not support filtering on these file attributes.
For the Renesas CC-RX compiled RX65N example similar code is found under the src\smc_gen folder
created by the e2studio code generator.
For the GCC-RX compiled RX65N and Raspberry Pi Pico examples the FatFS source code is under the
FatFS folder.
For the ESP32-IDF and Arduino IDE examples file handling is part of the ESP32-IDF API so there is no
additional code.
For the PIC32 examples a SPI driver is included in the project’s hardware configuration which links to the
FatFS module, the source of which is under the FatFS folder.
For the Atmel SAM3X running on the Arduino Due board the ASF configurator is used to provide code
for both FatFS and a USB MSC class host driver.
For the Windows/Linux simulators and the Raspberry Pi OS example the operating system’s file system is
used.
For the Renesas PK-S5D9 board the Synergy configurator is used to provide code for both FileX and a
USB MSC class host driver.
30.5 MiniWinFixedWindows
This project contains the code for a fixed tiled windows example. The main window displays 6 windows,
each as an icon and with no title bar or border. These windows accept only one event: a touch down.
Some of the windows then bring up a further full screen window with no border or title bar. The 6
windows on the home screen have the flag set upon their window creation that a touch down event in a
window that does not have focus gives the window focus and is also passed on to the window as a touch
down event.
Currently although this project builds and runs for the LPC54628 and RX65N examples the displayed
elements do not fit correctly on the screen as the code is supplied because this devices’ boards’ LCD’s
have a vertical resolution of only 272 pixels. The fix is to change the display rotation for this project from
0 to 90 degrees in this project’s configuration file. This fixes the problem but then causes the same
problem for the other examples as the configuration file is shared. You can have one screen layout or
the other working but not both at the same time.
30.6 MiniWinTTFonts
This project contains the code for a demonstration of MiniWin’s TrueType fonts example. The two
yellow background windows show the same font in two modes – one with anti-aliasing and alpha-
blending, the other in plain pixel mode, so that a comparison can be made between the appearance and
rendering speed of the two modes. The anti-aliased alpha blended mode gives a better appearance but
at the expense of slower rendering, especially when scrolling text.
The other windows show the text box control which can render TrueType fonts. One window shows a
fixed text box, a second with a scroll bar and a third with up/down arrows. The text displayed can be
changed with a button from too big to all fit in the text box (requiring scrolling) to too small to overflow
the text box.
30.7 MiniWinFreeRTOS
This project integrates MiniWin into FreeRTOS. In these examples MiniWin runs in a single thread and 2
other threads are instantiated to perform other duties below:
1) Flash a LED. On the ST Discovery boards, the Microchip Curiosity board and the LPC54628
development board one of the board user LED’s is used for this purpose. On the Windows and
Linux builds a small yellow square to the right of the MiniWin root window is shown in the
MiniWin window. On the Raspberry Pi Zero the board LED which is usually assigned to show disc
activity is reassigned to allow it to be flashed from the application. On the PIC32 boards LED2 is
flashed. On the Renesas Envision and the ESP32 DevKitC boards there is no spare LED to flash.
2) Read accelerometer values from the on-board MEMS accelerometer and display angle arrows
and text for X, Y and Z, each in their own window, along with an offset setting button. The way
the example projects work for the hardware variants differs slightly because of hardware
differences.
The STM32F429IDISC1 board has a gryrometer which senses angular accelerations. These can be
integrated over time to give angular rotations about X, Y and Z axes. However, there is no code
to calibrate the gyroscope output and hence the arrows will drift over time. Pressing the button
in each window will reset the reading to zero.
The STM32F4DISCOVERY and the LPC54628 boards have linear accelerometers which sense
linear accelerations, including gravity. These can be used to calculate angular rotations about X
and Y but not Z axes when the board is not accelerating relative to the earth. The Z axis rotation
cannot be calculated and therefore the Z axis arrow does not move.
On the Windows build there is no accelerometer or gyrometer but the mouse is moved up and
down across the Windows desktop to simulate X and Y rotations and the keyboard left and right
arrows are used to simulate the Z rotation.
On the Linux build there is also no accelerometer or gyrometer but the arrow keys and the ‘l’
and ‘r’ keys are used to simulate rotations.
On the Renesas Envision, Raspberry Pi Zero W, Arduino Due, Microchip Curiosity and the ESP32
DevKitC boards there is no accelerometer so slowly changing values are simulated.
The version of FreeRTOS used in the STM32F4xx integration examples is 10.1.1 and in the LPC54628
example is 10.0.1. This is a few versions on from the FreeRTOS integration examples found in the STM32
Cube package from ST. Later FreeRTOS code was obtained from the FreeRTOS website and the port
partly changed slightly to work on the ST Discovery boards. The LPC54628 example is unchanged from
that supplied with the MCUXpresso SDK.
e2studio for Renesas devices has the ability to integrate FreeRTOS from within the IDE. However, this
method was not chosen as the generated code is not compatible with the FreeRTOS example application
code supplied in the MiniWinFreeRTOS_common folder. Instead FreeRTOS source was obtained
independently (version 10.2.0) and manually integrated using the standard hardware porting layer from
Renesas.
Microchip MPLAB X Harmony 3 code configurator has the capability to generate FreeRTOS code and this
is used unchanged.
Atmel/Microchip Studio ASF configurator allows version 10.0 of FreeRTOS to be generated but the
configurator supplied FreeRTOS configuration file needed amending.
The FreeRTOS examples all use fully static memory allocation by setting the appropriate values in the
configuration files and providing the required hook functions needed for a static memory
implementation (except ESP-IDF example where this is already done). All FreeRTOS dynamic memory
allocation code is removed when using this configuration.
In order for the MiniWinFreeRTOS example to run under Linux, Windows and Raspberry Pi OS the
FreeRTOS Windows/Linux ports are not used as they were found to be based on a too old version of
FreeRTOS and are unreliable. Instead quick and dirty FreeRTOS simulation layers are used using Linux
pthreads and the Windows API. These are not full port of the FreeRTOS API, only the functionality
required by the example application. Do not base any of your code on these samples, they are for
example simulation purposes only.
FreeRTOS has not yet been ported to the Raspberry Pi Pico’s processor so there is no example for that
board. There will be when the OS port is available.
No FreeRTOS port is available for Renesas Synergy processors. Instead ThreadX is used as a RTOS. The
FreeRTOS example therefore is not available for the PK-S5D9 board.
30.8 MiniWinCamera
This example interfaces a video camera and shows a video stream in a MiniWin window. The video
image is sized to QQVGA which is 160 by 120 pixels.
Each example project uses a camera driver. For the simulator example projects running on Windows and
Linux this uses OpenCV. You need to have the OpenCV library installed on your computer to build these
examples.
https://opencv.org/releases
You need to set an OpenCV environment variable pointing to your OpenCV installation location:
set OPENCV_DIR=C:\opencv
To run the MiniWinCamera project you need to set the location of the OpenCV pre-built DLL library
found in the OpenCV installation like this:
set PATH=%OPENCV_DIR%\build\x64\vc15\bin;%PATH%
The makefile at the time of writing uses a path containing the version of OpenCV current at the time
(455). You may need to alter this is you have a later version. Edit nmakefile for the correct path.
pacman -S mingw-w64-x86_64-opencv
Some of the embedded hardware variants’ processors have a digital camera interface peripheral, but
not all do, or if the processor has the capability, the pins are not available on the development board or
clash with other peripherals. Therefore the embedded processors’ camera drivers have all been written
to access the camera using bit banging. This is slow, but allows the camera to be accessed by all
embedded hardware variants with the same or similar code shared across all versions. In addition,
interrupts need to be disabled during reading the camera with this method which causes the MiniWin
tick timer to stop for short periods (these examples demonstrate how to integrate MiniWin with
external hardware, not examples on how to write a camera driver.)
30.8.5.2 Linux
The Linux simulator uses a built in camera that can be accessed by the OpenCV library. This has been
tested in Ubuntu running in Virtual Box with the camera device shared from host to client. When
running this example the OpenCV libraries take a considerable time to initialise. You may have to wait 5
seconds for the image to appear. Video rendering is slow as the Miniwin Linux LCD driver is simplistic.
30.8.5.3 STM43F429
STM32F429DISC1 board. This is using an OV7670 camera module without a hardware buffer. Because of
pin clashes on the board it is not possible to use the on-chip DCMI peripheral. Instead the camera is read
with bit banging which makes it slow. See Appendix for connections.
30.8.5.4 STM32F407
STM32F4DISCOVERY board. This is using an OV7670 camera module without a hardware buffer. To keep
the camera driver the same as the STM32F429 example the camera is read via bit banging. The simplistic
LCD driver for this example also makes the image rendering very slow. See Appendix for connections.
30.8.5.5 LPC54628
OM13098 board. This is using an OV7670 camera module without a hardware buffer. This board's
processor does not have a digital camera interface so bit banging is used instead which makes it slow.
See Appendix for connections.
Menu|Preferences|Raspberry Pi Configuration
Interfaces tab
Set SPI enabled
Restart your Raspberry Pi
The GPIO lines and the SPI interface on the Raspberry Pi Zero board are driven using direct register
access on the BCM2835 peripheral chip. Using the standard SPI and GPIO kernel drivers within
Raspberry Pi OS degrades performance.
cmake .
make
30.12 STM32CubeIDE/NXP MCUXpresso/Renesas e2 Studio/Atmel (Microchip)
Studio/Microchip MPLAB X Linked Folders
None of the example projects contain the MiniWin source code within them. They all use the linked
folder feature in STM32CubeIDE/NXP MCUXpresso/e2 Studio/MPLAB X/Atmel Studio to link to the
MiniWin shared source folder (STM32CubeIDE, NXP MCUXpresso and Renesas e2 Studio are based on
Eclipse so the feature derives from there).
Similarly, the common application code for each application appears only once even though there are
multiple builds for each application (for each hal driver implementation). The application code appears
under the “ProjectName”_Common folder under the root MiniWin installation folder. These folders
are linked to in the project files using the linked folder feature.
Renesas Synergy generated files provide their own own main() function in its library code. The
main.c/h files found in the common folder for each example project are not used and are excluded
from the build.
The ESP32 IDF build system provides its own main() function in its library code. The main.c file found
in the common folder for each example project is not used. Instead an app_main.c file is used for a
similar purpose found under the main component which instantiates the void app_init() and
app_main_loop_process() functions described in the next section.
The ESP32 system can have a task watchdog enabled (this is the default), although it is disabled in the
MiniWin example projects. If this watchdog is enabled then periodically user code must relinquish
control to FreeRTOS with a vTaskDelay()call to allow the idle task to run and kick its watchdog.
Without this the watchdog will time out and reset the processor. Code to do this is in place already in
the ESP32 example applications in function app_main_loop_process().
The ESP32-IDF build system uses long path names which can overflow the maximum Windows limit of
260 characters and cause a build error. See the readme.txt in each project for a solution if you
encounter this problem.
void app_init(void);
This function is called by the main function in main.c (in the “ProjectName”_Common folder). In this
function’s implementation perform application initializations that are not part of MiniWin, for example
setting the system clock for the embedded builds.
void app_main_loop_process(void);
This function is called repeatedly from main in an endless loop and is used to implement main loop
processing required by your particular embedded application.
In the file example file handling functions are implemented in app.c in order to separate out file
handling code from the common application code because file handling is code is target platform
dependent.
The Renesas CC-RX compiled examples have a folder called smc_gen under the src folder which is
created by the code generator within e2 Studio. This folder contains the start-up and FIT drivers
required by the example applications. Each project contains a .scfg file which contains the hardware
configuration used in e2 Studio to generate the driver code. You will need to download the appropriate
FIT modules for the RX65N processor. This can be done within e2 Studio.
The Renesas GCC-RX examples have a folder called generate under the main project folder which is
created by the code generator within e2 Studio. This folder contains the start-up and interrupt handlers
required by the example applications.
The Renesas S5D9 examples have their board support code generated by e2studio using the Synergy
configurator tool. In each project is a configuration.xml file that holds the configuration description
that can be opened in e2studio if it needs to be modified. The generated code is created into the
following folders: synergy, src/synergy_gen and synergy_cfg. The Synergy framework
provides its own main.c Therefore in the MiniWin main.c/h files are excluded from the build in the
project files.
The ESP32 example projects do not need this code as it is supplied by the ESP32-IDF framework.
The Microchip Curiosity board projects all use the MPLAB X Harmony 3 plugin to generate the board
support code which is stored in the standard MPLAB X project format folders.
The Atmel SAM3X Arduino Due board projects all use the ASF configurator to generate the board
support code which is stored in the standard Atmel/Microchip Studio project format folders.
The Windows, Linux and Raspberry Pi OS example projects do not need this code as the services
required are supplied by the operating system (apart from the FreeRTOS examples, where the BSP
folder contains the FreeRTOS simulation source).
30.16 Arduino IDE Example Projects
The Arduino IDE is unlike all other IDE’s. It is highly restrictive in where it expects source and header files
to be and the locations cannot be changed in the IDE. For example, it expects all code to be in the root
folder of the project or under a src folder. This does not fit at all with the MiniWIn code layout where
common code (both example project and window manager) is in folders not under the root project
folder. It is also not possible to set a path variable to direct the compiler where to look for header files.
To overcome this limitation the required source and header files are made to look like they are in the
location expected by Arduino IDE without their actually being there. To achieve this a src folder is
created under the project root folder and filled with hard symbolic links to make the required files
appear in place.
The number of links that needs to be created is large. To achieve this for all example projects there is a
setup.bat file that must be run before the .ino Arduino file is opened in the Arduino IDE.
The Arduino development environment for the ESP32 provides its own drivers and libraries which are
wrappers around the ESP32-IDF native drivers. However, as the driver hal layer was reused from the
ESP32-IDF example projects the native ESP32-IDF drivers and FreeRTOS implementation have been
used. They may be moved to the Arduino equivalents at a later date.
Not all the standard <example_project>_Common source files can be used, for example the MiniWin
supplied main.c as Arduino IDE projects do not need this file. An Arduino IDE project has in its .ino
file with a setup() and a loop() functions and these are used instead. Similarly the app.h/c files
look different from all the other projects.
This arrangement is not ideal and it will be non-trivial for the user to create new MiniWin projects using
the Arduino IDE with the current code layout. To overcome this MiniWin would need duplication into a
new code base and the files significantly rearranged to make an Arduino library. This can be done in the
future if there is sufficient demand.
The hardware connections for all Arduino IDE projects are the same as those used for the ESP32-IDF
projects and are described in Appendix 9.
31.3 Keypad
Initialisation: User code needs to set the is_only_positive flag to allow or disallow negative
numbers.
Resources required: A timer is required to animate the flashing cursor.
Sizes: Small and large
Messages processed: MW_CONTROL_CREATED_MESSAGE, MW_WINDOW_TIMER_MESSAGE,
MW_TOUCH_DOWN_MESSAGE
Messages sent: MW_KEY_PRESSED_MESSAGE Data contains the ASCII value of the pressed key (‘0’ to
‘9’, ‘-’ or ‘\b’).
31.4 Keyboard
Initialisation: None.
Resources required: A timer is required for as long as the containing window has focus to animate the
flashing cursor.
Sizes: Small and large
Messages processed: MW_CONTROL_CREATED_MESSAGE, MW_WINDOW_TIMER_MESSAGE,
MW_TOUCH_DOWN_MESSAGE.
Messages sent: MW_KEY_PRESSED_MESSAGE Data contains the ASCII value of the pressed key (Any
visible ASCII character, ‘ ‘ or ‘\b’).
31.5 Label
Initialisation: User code needs to set the label text.
Resources required: None
Sizes: Small and large
Messages processed: MW_LABEL_SET_LABEL_TEXT_MESSAGE. Data contains a pointer to the new
label text that is copied into the control's memory.
Messages sent: None.
31.13 Tabs
Initialisation: User code needs to set the number of tabs, array of tabs’ labels, foreground and
background colours and if the tabs control is automatic. The background colour is the fill colour used in
the small gap above the tabs’ borders. The foreground colour is the fill colour of the tabs. Automatic
tabs are the width of the containing window’s client area and resize with the window client area width
when the window is resized. They are always fixed location at client area coordinate 0, 0. Non-automatic
tabs can be placed anywhere in the client area and do not resize when the window size changes.The
chosen tab of both types is automatically set to 0 on creation. Tabs controls do not hide or make visible
any controls. When a tab is chosen a tab chosen message is sent to the parent window and it is up to
user code to handle this message and hide and make visible other controls as necessary to implement
the tab change.
Resources required: None
Sizes: Small and large
Messages processed: MW_TOUCH_DOWN_MESSAGE,
MW_CONTROL_PARENT_WINDOW_RESIZED_MESSAGE.
Messages sent: MW_TAB_SELECTED_MESSAGE. Data contains the number of the selected tab starting
from 0 representing the left tab.
Additional API: This control has an additional API call to find out from a tabs control which tab is
currently selected. This information needs to be known when a tabs control is made visible to find out
which further controls need to be made visible depending on which tab is currently selected.
31.14 Tree
Initialisation: User code needs to set the number of lines the tree control has and pointers to
monochrome bitmap data of the appropriate size (8x8 for small, 16x16 for large) for the file and folder
icons to use, or NULL if icons are not used (both must be set or both must be NULL). A node array needs
to be allocated, either statically or dynamically. The tree container object within the tree control’s
instance data structure needs initialising by calling the tree container initialisation function passing in
the address of this tree container object, a pointer to the node array described above, the array size in
(in entries, not bytes), the root folder path, root folder flags, tree global flags, a callback function to
expand a dynamically allocated array (or NULL if this feature is not used), and the folder separator
character. See the section in this document on the tree container utility for further details or the file
example project.
Resources required: A timer for the short period between a selected tree item being drawn as down
and redrawn as up when node selection is disabled. This timer is then released.
Sizes: Small and large
Messages processed: MW_CONTROL_CREATED_MESSAGE, MW_TOUCH_DOWN_MESSAGE,
MW_WINDOW_TIMER_MESSAGE to redraw a selected node (only when selection is disabled),
MW_TREE_SCROLL_BAR_POSITION_MESSAGE to receive an associated scroll bar proportion scrolled
message (0 – 255), MW_TREE_LINES_TO_SCROLL_MESSAGE to receive an absolute number of lines to
scroll the text, or MW_TREE_CONTAINER_DATA_CHANGED_MESSAGE when either the underlying tree
container’s data has changed or a folder node has been opened or closed.
Messages sent: MW_TREE_SCROLLING_REQUIRED_MESSAGE at start-up and also when a data changed
message is received to indicate to parent window that not all the nodes fit in the tree and scrolling or
arrow buttons will be required.
MW_TREE_ITEM_PRESSED_MESSAGE data contains the number of the tree item pressed, starting at 0,
Renesas: This contains project files and application code specific to example applications that run on
Renesas processors (currently RX65N and Synergy S5D9) and are built using the Renesas e2 Studio IDE
and the Renesas CC-RX/GCC-RX compilers (for the RX65N projects) and GCC (for the S5D9 projects).
Under the RX65N folder is a sub-folder for each targeted Renesas compiler, RX65N or RX65N_GCC and
under each of these a further sub-folder for each application example. In these sub-folders are e2 Studio
project files and the start-up code for that application. Under the src folder are source files that are
both application and hardware variant specific. In the root folder for each RX-CC compiler project is a
.scfg file used to configure the hardware.
Under the S5D9 folder are further sub-folders for each application example with a
configuration.xml file for each project used by the Synergy configurator to define and then
generate the BSP files.
Espressif: This contains project files and application code specific to example applications that run on
ESP32 processors and are built using the ESP supplied IDF build system. Under this folder is a sub-folder
for each targeted ESP32 development board (DevKitC). Under this folder is a further sub-folder for each
application example. In these folders are the main and the component CMake files, the SDK
configuration file for that application and under the main folder source files that are both application
and hardware variant specific. ESP32 applications do not use a main.c file but instead have a similar
app_main.c file, found under the main folder.
NXP: This contains project files, BSP and application code specific to example applications that run on
NXP processors and are built using the NXP MCUXpresso IDE. Under this folder is a sub-folder for each
targeted NXP processor (LPC54628). Under this folder are further sub-folder for each application
example. In these folders are MCUXpresso project files, the required BSP for that application and under
the src folder source files that are both application and hardware variant specific.
ST: This contains project files, BSP and application code specific to example applications that run on ST
processors and are built using the STM32CubeIDE. Under this folder are 2 sub-folders for each targeted
processor (STM32F407 and STM32F429). Under these folders are further sub-folder for each application
example. In these folders are STM32CubeIDE project files, the required BSP for that application and
under the src folder source files that are both application and hardware variant specific.
Microchip: This contains project files and application code specific to example applications that run on
Microchip processors and are built using the MPLAB X. Under this folder are 2 sub-folders for each
targeted processor (PIC32MX470F512H and PIC32MZ2048EFM100). Under these folders are further sub-
folder for each application example. In these folders are MPLAB X project files, the required BSP for that
application and under the src folder source files that are both application and hardware variant
specific.
Atmel: This contains project files and application code specific to example applications that run on
Atmel processors and are built using the Atmel/Microchip Studio. Under this folder are sub-folders for
each targeted processor (ATSAM3X8E). Under these folders are further sub-folder for each application
example. In these folders are MPLAB X project files, the required BSP for that application and under the
src folder source files that are both application and hardware variant specific.
Arduino: This contains project files and application code specific to example applications that run on
Arduino IDE supported boards (currently ESP32 based DevKitC) and are built using the Arduino IDE.
Under this folder is a sub-folder for each targeted Arduino board, DevKitC, and under each of this a
further sub-folder for each application example. In these folders are a setup.bat file which must be
run before the Arduino IDE is started, hardware configuration code needed by the example application
in the app folder, and the Arduino IDE .ino file. When the setup.bat file is run a src directory is
created that creates hard links to the source and header files in the MiniWin folder structure. This src
folder can be safely deleted as it only contains links created by the setup.bat file.
RaspberryPi: This contains project files and application code specific to example applications that run on
Raspberry Pi boards and are built using make and GCC natively on the Raspberry Pi. Under this folder are
sub-folders for each targeted board (Zero W and Pico). Under this folder is a further sub-folder for each
application example. This contains project files that are built using make and GCC. In Raspberry Pi OS
GCC will always be available. For the Pico you will need to install the Pico SDK. Important note: when
building any Raspberry Pi example application, always perform a clean first. You may get compile
errors otherwise.
Simulation: This contains project files for example applications that are built to run on a computer as a
simulation rather than on embedded hardware. Under this folder are sub-folders for each targeted
simulation platform (Windows and Linux). Under these folders are further sub-folder for each
application example. These sub-folders each contain a makefile/nmakefile to build the example
application using GCC/clang/Visual Studio cl. For Linux GCC will always be available, but the X11
development package may need to be installed first. For Debian/Ubuntu based Linux distributions use
this command to install the X11 development package:
For Windows a GCC/clang or Visual Studio development environment is required. For GCC/clang under
Windows the MSYS2 environment has been used to test all the examples. See the utilities build
instructions above for MSYS2 configuration. In addition to the makefiles/nmakefiles there are Eclipse
project files allowing the target simulation example applications to be imported, built and debugged
within e2Studio, STM32CubeIDE or MCUXpresso using GCC/clang. This still requires MSYS2 environment
to be available. Important note: when building any Linux or Windows example application, whether
from the command line or within an IDE, always perform a clean first. You may get compile errors
otherwise.
MiniWin: This contains the MiniWin embedded window manager source code which is common to all
example applications for all platforms and processors. It contains the following sub-folders:
Folder hal contains source files common to all hal implementations and then further source files in sub-
folders for different currently supported platforms and processors. Each set of drivers for a particular
target builds only for that target. Other different target files compile to nothing through the use of
#defines.
In addition the following source files are in the MiniWin folder:
MiniWinTest_Common: This contains application source files for the comprehensive MiniWinTest
example that are common to all platform/processor variants.
MiniWinSimple_Common: This contains the application example source files described later in this
document.
MiniWinTTFonts_Common: As above but for the TrueType font rendering example project.
MiniWinCamera: As above but for the video camera integration example project.
Tools: This contains the utility applications that are part of MiniWin that are built for Linux or Windows
using GCC/clang or cl. This folder contains the following sub-folders:
BMPConv24Colour: This is a command line utility for converting a Windows 24 bit per pixel
.bmp file to a 3 bytes per pixel C99 source file. It uses EasyBMP.
BMPConvMono: This is a command line utility for converting a Windows 2 bit per pixel .bmp file
to an 8 pixels per byte C99 source file. It uses EasyBMP.
CodeGen: This contains the MiniWin code generator utility. It is described later in this
document.
FontEncoder: This is a command line utility for converting a TrueType font file to a run-length
encoded C99 source file. It comes as part of the mcufonts library. For Windows it is supplied pre-
built.
EasyBMP: This is source code for a third party Windows .bmp file handling library. It is used by
the utility applications, not MiniWin.
Timers can be reused after they expire. Timers are used by animated controls (for example a button
press/release animation, but only for a very short timer) and flashing cursors. User code can use timers
for its own purposes as well.
Dialogs need one window slot and one to many control slots when they are showing, but these
resources are released when the dialog is dismissed.
The number of messages required depends on the complexity of the system being developed and needs
experimentation to find out the required size.
In debug mode any occurrence of a resource running out will trigger an assert failure enabling instant
discovery of what went wrong. The message queue utility in file miniwin_message_queue.c also has
under debug builds a high water mark of message queue usage in variable max_queue_usage which
can be used to get an estimate of how much of the message queue is being used.
/* #define MW_DISPLAY_ROTATION_0 */
#define MW_DISPLAY_ROTATION_90
/* #define MW_DISPLAY_ROTATION_180 */
/* #define MW_DISPLAY_ROTATION_270 */
33.3 Sizes
Set the window title bar size. The title bar must be big enough to contain the title text and icons. If the
title bar size is changed from default then the icons and text may need to be redesigned.
33.4 User Interface Colours
Customize the look of your windows here. The colours are defined in the LCD hal layer.
33.5 Timings
Customize the feel of your touch screen response here to prevent touch bounce, and the look of
animated controls and window minimization/restoration. The MiniWin system timer is also defined
here. Changing the system timer value will alter the effect of all other timings which are defined in units
of system ticks.
#define MW_FONT_12_INCLUDED
#define MW_FONT_16_INCLUDED
#define MW_FONT_20_INCLUDED
#define MW_FONT_24_INCLUDED
33.7 Dialogs
The file chooser dialog is an option. This is because it requires extra functions to be implemented to
interact with the file system. See the dialogs section in this document for details. Inclusion of the file
chooser dialog is controlled by this #define:
#define MW_DIALOG_FILE_CHOOSER
33.8 Other
The drag threshold prevents slight movement on touch screen taps sending drag events.
The busy text is displayed when the user interface is locked because of a long processing task.
34 MiniWin Asserts
The MiniWin window manager, supporting code and example projects all use the MiniWin assert macro.
Under debug build when NDEBUG is not defined (usually this is not defined for debug builds) a failed
assert will show a blue screen of death with details of the function and line number where the assert
failed along with a simple text message. On release builds the assert macro compiles to nothing.
In debug builds if you run out of resources (message queue space, window or control slots and timers),
attempt to use an un-included font, or something bad is attempted via the public API (i.e. removing a
window with a bad window handle, specifying a null pointer when not allowed) you will get an assert
with an explanation making it easy to solve. On release builds these failures that can be ignored by the
window manager will be, and will not cause an assert, allowing the window manager to continue.
If any assert failures are seen that are not caused by running out of resources, or bad user code calling
the public API, please report the problem via the website.
On the Raspberry Pi Pico SDK the default build is release which means that NDEBUG is defined disabling
asserts. To enable asserts in miniwin_debug.h add this line before the #include lines:
#undef NDEBUG
Once you have implemented you hal functions, or if you are using one of the supplied hal layers, you
need to create a new project and copy in or point to the folder of the MiniWin source. Add the paths to
the MiniWin and MiniWin/gl/fonts/truetype/mcufont folders to your list of include folders to
search in your IDE (or add it to the command line list if you are building on the command line).
2. Create a new source file for your window called window_simple.c. Add these #include and data
structure declaration and definition to your source file. This window is designed not to have multiple
instances simultaneously showing so therefore the window’s data is stored in the window’s source file.
#include "miniwin.h"
#include "miniwin_user.h"
#include "miniwin_simple.h"
typedef struct
{
int16_t circle_x; // x coordinate of where to draw circle
int16_t circle_y; // y coordinate of where to draw circle
bool draw_circle; // if to draw circle
} window_simple_data_t;
static window_simple_data_t window_simple_data;
#include "window_simple.h"
/***********************
*** GLOBAL VARIABLES ***
***********************/
mw_handle_t window_simple_handle;
mw_handle_t button_handle;
mw_handle_t label_handle;
/**********************
*** LOCAL VARIABLES ***
**********************/
6. In function mw_user_init() in miniwin_user.c add the following code. This creates the window
and controls and adds the controls to the window.
void mw_user_init(void)
{
mw_util_rect_t r;
(void)mw_util_safe_strcpy(label_data.label,
MW_UI_LABEL_MAX_CHARS, "Not yet set");
label_handle = mw_ui_label_add_new(80,
10,
84,
window_simple_handle,
MW_CONTROL_FLAG_IS_VISIBLE | MW_CONTROL_FLAG_IS_ENABLED,
&label_data);
(void)mw_util_safe_strcpy(button_data.button_label,
MW_UI_BUTTON_LABEL_MAX_CHARS, "TEST");
button_handle = mw_ui_button_add_new(10,
10,
window_simple_handle,
MW_CONTROL_FLAG_IS_VISIBLE | MW_CONTROL_FLAG_IS_ENABLED,
&button_data);
mw_paint_all();
}
Function app_init() is for any initialisations that need to be performed for your particular hardware,
for example setting up the system clock. Function app_main_loop_process() is for any other code
your embedded application needs to call to implement its behaviour. In this example it can be empty.
This is a good time to build and test your application. You should see a single window appear with an
empty client area other than the 2 controls. You will be able to move, minimize, maximize, resize,
restore and close this window. The window's client area won't be repainted at this stage.
The next stage is to implement the message handling and paint functionality in your window.
8. Give your window's client area a background, as by default it has none. You need to draw a filled
rectangle with no border in function window_simple_paint_function(). Just pass on the
mw_gl_draw_info_t parameter to any gl function that needs it:
mw_gl_set_fill(MW_GL_FILL);
mw_gl_set_solid_fill_colour(MW_HAL_LCD_WHITE);
mw_gl_set_border(MW_GL_BORDER_OFF);
mw_gl_clear_pattern();
mw_gl_rectangle(draw_info,
0,
0,
mw_get_window_client_rect(window_handle).width,
mw_get_window_client_rect(window_handle).height);
While you're here add the code to draw the circle at the touched point in the same function after the
background drawing code above, although at the moment you are not handling the touch message in
your message handler. That's next.
if(window_simple_data.draw_circle)
{
mw_gl_set_fg_colour(MW_HAL_LCD_BLACK);
mw_gl_set_solid_fill_colour(MW_HAL_LCD_YELLOW);
mw_gl_set_line(MW_GL_SOLID_LINE);
mw_gl_set_border(MW_GL_BORDER_ON);
mw_gl_circle(draw_info, window_simple_data.circle_x,
window_simple_data.circle_y, 25);
}
9. Now start adding some message handling in your message handler function
window_simple_message_function(). First create a switch statement. You want to handle the
MW_WINDOW_CREATED_MESSAGE. It's called once when a window is created, and is a good place for
initializations:
switch (message->message_id)
{
case MW_WINDOW_CREATED_MESSAGE:
window_simple_data.draw_circle = false;
break;
default:
break;
}
10. Add code to handle a touch down event and store the touch point. The touch point comes in the
message's data parameter, x coordinate in the left 2 bytes, y in the right 2 bytes:
case MW_TOUCH_DOWN_MESSAGE:
temp_uint32 = message->message_data >> 16;
window_simple_data.circle_x = (int16_t)temp_uint32;
window_simple_data.circle_y = (int16_t)message->message_data;
window_simple_data.draw_circle = true;
mw_paint_window_client(message->recipient_handle);
break;
You will need this variable defined for the above code:
uint32_t temp_uint32;
As the window's client area has been touched we want to redraw it to draw the circle. Don't call your
paint routine directly, call the utility function that posts a repaint message to the message queue.
11. Now add code to respond to the button press message. When this message is received you want to
pop up a single button dialog with customised text, as done below. You can check that the sender of the
button pressed message is our button, although we only have one button in this example application, so
it’s not strictly necessary as it couldn’t be any other button.
case MW_BUTTON_PRESSED_MESSAGE:
if (message->sender_handle == button_handle)
{
(void)mw_create_window_dialog_one_button(20,
50,
150,
"Title",
"This is a message",
"Yep",
false,
message->recipient_handle);
}
break;
This function call to create the pop up dialog is non-blocking, i.e. it returns straightaway. The specified
window (in this case your only window) gets a message when it’s dismissed, so catch that and use it to
change the label’s text on your window by posting it a message.
Posting messages is fundamental to how the user code interacts with the window manager and other
windows in MiniWin so the parameters to this post message example will be discussed in detail
following the code snippet below.
case MW_DIALOG_ONE_BUTTON_DISMISSED_MESSAGE:
mw_post_message(MW_LABEL_SET_LABEL_TEXT_MESSAGE,
message->recipient_handle,
label_handle,
MW_UNUSED_MESSAGE_PARAMETER,
(void *)"Hello world!",
MW_CONTROL_MESSAGE);
mw_paint_control(label_handle);
break;
MW_LABEL_SET_LABEL_TEXT_MESSAGE
This is the message type you are sending to the label control. It is from miniwin.h where you will find
it and many others. It tells the message recipient (the label control in this case) what the message is
about and what the message’s data fields contain.
message->recipient_handle
This is the sender of the message about to be posted. The sender of this new message is the recipient of
the message just received that is being processed. It might seem confusing to see recipient in the sender
field, but it’s a common pattern in MiniWin. It’s because in processing a just received message you are
posting a new one.
label_handle
This is the recipient of the new message you are posting. In this case you are sending a message to your
label control which you refer to by its handle returned by MiniWin when you created the control.
MW_UNUSED_MESSAGE_PARAMETER
You are not sending anything in the uint32_t data field in this example so this field can be anything
but use this #define to indicate that it is unused.
(void *)"Hello world!"
This is the pointer field of the message which contains this message’s data. Remember that it is essential
that whatever is pointed to by this field will still exist when the message is received, so no pointers to
local variables. In this case it’s a pointer to constant data.
MW_CONTROL_MESSAGE
This indicates to MiniWin that the recipient of this message is a control.
You need to get this label repainted after changing its text so call
mw_paint_control(label_handle).
12. That’s it. Build and run. You’ll find this example’s source code under the MiniWinSimple_Common
and hardware target folders.
The configuration file is written in JSON, a simple, widely used and human readable data transfer
language (it’s like a simpler XML). The JSON configuration file is parsed using an open source JSON
parser and the generator produces well documented standard C99 code identical to that found in the
example projects. A makefile is produced for Linux or Windows which can be used to build the
generated code (in addition for Windows target a Visual Studio nmakefile is produced). For Arduino
IDE a .ino sketch file and a configuration file (setup.bat) are produced. There are many example
JSON configuration files to look at, copy and build on. You can get your first MiniWin application running
in the simulator or Arduino board to your design with your layout of controls in minutes. The generated
code is clear and commented where you need to add your code to implement your application’s
behaviour. There are no opaque #defines in the generated code (remember the hideous code that
MFC generated?) - it’s all straight forward easy to understand C99. Once it’s up and running you can get
the generated project into an IDE and debug it. Instructions for doing this within Eclipse are given later.
All generated code produced by the MiniWin code generator is MISRA 2012 compliant for all ‘required’
features.
To build the CodeGen application for Windows or Linux using GCC/clang use this command line:
make
To build the CodeGen application for Windows using cl use this command line:
nmake -f nmakefile
This will create you CodeGen for Linux or CodeGen.exe for Windows.
./CodeGen <config_file.json>
and this command line when the generator has been compiled for Windows :
CodeGen <config_file.json>
After running the code generator using one of the example JSON files (or your own), if using the same
output folder, it is better to delete the generator’s output folder completely before generating code for
a different example configuration file (for the supplied example configuration files the output folder is
always called MiniWinGen). The reason for this is that the generated makefile for building your
generated project uses wildcards to find its C source files. If there are any C source files left over from
the previous generation that are not required for the subsequent one you may get build errors when
building the generated code.
The generation process overwrites any previous output files when running the generator again to the
same output folder. If you have hand edited any of the generated files and want to keep your changes
move your code somewhere else, or otherwise it will be overwritten when you run the generator again.
The generated makefiles expect the MiniWin folder to be available as in the diagram below. If you have
a different arrangement you will need to modify the makefile paths yourself.
MiniWin/
...
Tools/
CodeGen/
CodeGen.exe or CodeGen
config_file.json
...
<NewProjectName>_Common/
main.c
...
...
Simulation/
Linux/ or Windows/
<NewProjectName>/
src/
app.c
app.h
makefile
nmakefile (Windows configuration only)
The generator and setup.bat configuration batch file expect the MiniWin folder to be available as in
the diagram below. If you have a different arrangement you will need to modify the code generator and
setup.bat paths yourself.
MiniWin/
...
Tools/
CodeGen/
CodeGen.exe
config_file.json
...
<NewProjectName>_Common/
main.c
...
...
Arduino/
DevKitC/
<NewProjectName>/
app/
app.c
app.h
<NewProjectName>.ino
setup.bat
“TargetType”: “. . .”,
“TargetType”: “Linux”,
make
To run the example under the Linux simulator in folder Simulation/Linux/MiniWinGen type :
./MiniWinGen
“TargetType”: “. . .”,
“TargetType”: “Windows”,
make
nmake -f nmakefile
To run the example under the Windows simulator in folder Simulation\Windows\MiniWinGen type :
MiniWinGen
“TargetType”: “. . .”,
“TargetType”: “Arduino/DevKitC”,
The setup.bat batch file creates many Windows hard links to make the MiniWin source files appear in
the place that the Arduino IDE expects them under the src folder. It is safe to delete this folder and run
setup.bat again.
Select the MiniWinGen project in the Project Explorer pane. From the main menu choose
Project|Properties then :
When debugging has started you will get a main() at main.c editor appear stating the source cannot
be found. Click the Edit Source Lookup Path... button then :
You should now see source and be able to debug the MiniWin simulation application.
https://jsonlint.com/
If you validation fails have a look at the Common Errors section of that webpage. The most common
error is an extra comma where it should not be. You can get away with that in C but not in JSON.
If you are new to JSON, it is very simple and you will be able to grasp most of it in 10 minutes. It was
invented for transferring data between webpages and servers, but ignore that bit. It’s great for simple
configuration files too. Here’s a quick tutorial…
https://beginnersbook.com/2015/04/json-tutorial/
{
project wide setting
array of windows
[
…
]
}
There are multiple project wide settings and they all come at the same level.
Within the array of windows you can have multiple entries, one for each window in your project. Each
window entry has multiple settings particular to that window…
{
project wide setting 1,
project wide setting 2,
array of windows
[
{
window 1 setting 1,
window 1 setting 2,
...
},
{
window 2 setting 1,
window 2 setting 2,
...
}
]
}
You can also specify controls that belong to your windows (as in window 1 below), or have no controls
for a particular window (window 2 below). Each window has its own list of controls for each type of
control, for example buttons or labels, and you can have one or multiple controls of each type in a
window (i.e. a window with 3 buttons), so these appear as arrays too…
{
project wide setting 1,
project wide setting 2,
array of windows
[
{
window 1 setting 1,
window 1 setting 2,
array of buttons
[
{
…
},
{
…
}
],
array of labels
[
{
…
}
]
},
{
window 2 setting 1,
window 2 setting 2
}
]
}
Each instance of each control type has settings too. These vary by control type. For example, a label just
has location and text but a list box will have an array of entries as well as location and size. This
completes the configuration file layout :
{
project wide setting 1,
project wide setting 2,
array of windows
[
{
window 1 setting 1,
window 1 setting 2,
array of buttons
[
{
button 1 in window 1 setting 1,
button 1 in window 1 setting 2
},
{
button 2 in window 1 setting 1,
button 2 in window 1 setting 2
}
],
array of labels
[
{
label 1 in window 1 setting 1,
label 1 in window 1 setting 2
}
]
},
{
window 2 setting 1,
window 2 setting 2
}
]
}
Key name.
Optional or mandatory, with default value if optional.
Setting purpose.
Object type (direct value, array of direct values, sub-object or array of sub-objects)
Allowed values and any further information.
“TargetName”
Mandatory.
The name of the project to generate. This name is used for the folder where the generated files are
placed.
Direct value string.
This must be a valid folder name for the host operating system.
“LargeSize”
Optional, defaults to “false”.
If the controls and window scroll bars for all windows and controls are to be created large sized or
standard sized.
Direct value boolean.
“true” or “false”.
“MaxWindowCount”
Optional, defaults to number of specified windows + 2.
The number of spaces to reserve in the array of windows.
Direct value number.
Must be at least 1 greater than the number of windows that will be in concurrent use as root window
always takes 1 space. Any dialog shown will take an additional 1 window.
“MaxControlCount”
Optional, defaults to number of specified controls + 5.
The number of spaces to reserve in the array of controls.
Direct value number.
Any dialog shown will take additional control spaces, typically less than 5.
“MaxTimerCount”
Optional, defaults to 8.
The number of spaces to reserve in the array of timers.
Direct value number.
User interface components that are animated or show a cursor will need a timer each while they are
shown.
“MaxMessageCount”
Optional, defaults to 80.
The number of spaces to reserve in the message queue.
Direct value number.
Larger systems may need more than 80.
“CalibrateText”
Optional, defaults to “Touch centre of cross”.
The text to show on the start-up calibration screen.
Direct value string.
No further information.
“BusyText”
Optional, defaults to “BUSY...”.
The text to show on when displaying that the user interface is busy.
Direct value string.
No further information.
37.7.2 Window Settings
“Windows”
Mandatory.
Details of MiniWin windows to generate code for.
Array of sub-objects.
This array must contain at least one entry which must be a sub-object.
“Name”
Mandatory.
Name of this window which is used to create this window’s variable names.
Direct value string.
This must be a legal C99 variable name and must be different for every window.
“Title”
Mandatory.
Title string displayed in this window’s title bar.
Direct value string.
Any text. Text too long will be truncated when the window is created.
“X”
Mandatory.
X position on the display the window will be created at.
Direct value integer.
Any positive integer less than the width of the display in pixels.
“Y”
Mandatory.
Y position on the display the window will be created at.
Direct value integer.
Any positive integer less than the height of the display in pixels.
“Width”
Mandatory.
Width in pixels the window will be created with.
Direct value integer.
Any positive integer but if the value is too small the window will fail to be created when the code runs.
The minimum value depends on whether the window’s optional features like borders and title bar.
“Height”
Mandatory.
Height in pixels the window will be created with.
Direct value integer.
Any positive integer but if the value is too small the window will fail to be created when the code runs.
The minimum value depends on whether the window’s optional features like borders and title bar.
“Border”
Optional, defaults to “false”.
If the window is created with a border.
Direct value boolean.
“true” or “false”.
“TitleBar”
Optional, defaults to “false”.
If the window is created with a title bar.
Direct value boolean.
“true” or “false”.
“CanClose”
Optional, defaults to “false”.
If the window is created with a greyed out window close icon.
Direct value boolean.
“true” or “false”.
“FixedSize”
Optional, defaults to “false”.
If the window is created with greyed out window resize and maximise icons.
Direct value boolean.
“true” or “false”.
“VerticalScrollBar"
Optional, defaults to “false”.
If the window is created with a window vertical scroll bar.
Direct value boolean.
“true” or “false”.
“HorizontalScrollBar”
Optional, defaults to “false”.
If the window is created with a window horizontal scroll bar.
Direct value boolean.
“true” or “false”.
“VerticalScrollBarEnabled”
Optional, defaults to “false”.
If the window vertical scroll bar (if enabled by previous setting) is created enabled or disabled.
Direct value boolean.
“true” or “false”.
“HorizontalScrollBarEnabled”
Optional, defaults to “false”.
If the window horizontal scroll bar (if enabled by previous setting) is created enabled or disabled.
Direct value boolean.
“true” or “false”.
“MenuBar”
Optional, defaults to “false”.
If the window is created with a menu bar.
Direct value boolean.
“true” or “false”.
“MenuBarEnabled”
Optional, defaults to “false”.
If the window is created with a menu bar this controls the menu bar’s global enable flag on window
creation.
Direct value boolean.
“true” or “false”.
“MenuItems”
Mandatory if menu bar is enabled for this window, else superfluous.
Labels for the menu bar items.
Direct value string array.
The number of entries in the array specifies the size of the menu.
“Visible”
Optional, defaults to “false”.
If the window is created visible or hidden.
Direct value boolean.
“true” or “false”.
“Minimised”
Optional, defaults to “false”.
If the window is created minimised.
Direct value boolean.
“true” or “false”.
“Name”
Mandatory.
The name of this control.
Direct value string.
This value is used to create the variable names used in the C99 code to refer to this control. The value
must be a legal C99 variable name and must be unique for all controls of this type across the project.
“X”
Mandatory except in “Tabs” when “Auto” is true.
X position on the display the control will be created at.
Direct value integer.
Any positive integer less than the width of the display in pixels.
“Y”
Mandatory except in “Tabs” when “Auto” is true.
Y position on the display the control will be created at.
Direct value integer.
Any positive integer less than the height of the display in pixels.
“Visible”
Optional, defaults to “false”.
If the control is created visible or hidden.
Direct value boolean.
“true” or “false”.
“Enabled”
Optional, defaults to “false”.
If the control is created enabled or greyed out.
Direct value boolean.
“true” or “false”.
37.7.3.1 Button
“Label”
Mandatory.
Text of the label displayed within the button.
Direct value string.
If the text is too long it is truncated when the button is created.
37.7.3.2 Label
“Label”
Mandatory.
Text displayed within the label.
Direct value string.
If the text is too long for the label width it is truncated when the label is created.
“Width”
Mandatory.
Width in pixels of the space for the label to be displayed in.
Direct value integer.
If the width is too short for the label it is truncated when the label is created.
“Labels”
Mandatory.
The labels for the radio buttons.
Direct value string array.
The number of entries in the array specifies the number of radio buttons to show.
“Lines”
Mandatory.
Number of lines high the list box will be created. This value is not in pixels.
Direct value integer.
The number of lines should be greater than or equal to the number of labels (non-scrolling list box).
The number of lines can be less than the number of labels as scrolling is provided (scrolling list box).
“Labels”
Mandatory.
The labels for the list box lines.
Direct value string array.
The number of entries in the array can be more or less than the number of lines but excess labels will
not be shown (non-scrolling list box).
The number of entries in the array can be more or less than the number of lines as the entries can be
scrolled (scrolling list box).
37.7.3.7 Arrow
“Direction”
Mandatory.
Direction of arrow to draw with the arrow button.
Direct value string.
“Up”, “Left”, “Down” or “Right”.
“Height”
Mandatory.
Height in pixels of a progress bar.
Direct value integer.
No further details.
“Height”
Mandatory.
Height in pixels of a text box.
Direct value integer.
No further details.
“Justification”
Mandatory.
Justification used to render the text.
Direct value string.
“Left”, “Right”, “Centre” or “Full”.
“BackgroundColour”
Mandatory.
The background colour the text will be rendered using.
Direct value string.
This can be a value defined in hal_lcd.h or a C99 RGB hex constant, for example “0xFF00FF”.
“ForegroundColour”
Mandatory.
The foreground colour the text will be rendered using.
Direct value string.
This can be a value defined in hal_lcd.h or a C99 RGB hex constant, for example “0xFF00FF”.
“Font”
Mandatory.
The TrueType font data structure used to render the text.
Direct value string.
This must be a the C99 name of a data structure already available in your project as created by the font
encoder tool.
37.7.3.11 Tabs
“Width”
Mandatory when “Auto” is false, otherwise ignored.
Width in pixels of all the tabs.
Direct value integer.
No further details.
“Labels”
Mandatory.
The labels for the tabs.
Direct value string array.
The number of entries in the array must be the same as the number of tabs.
“Auto”
Mandatory.
If “true” the tabs control is fixed at the top left of the parent window’s client area, is the width of the
client area, and resizes with the window to remain the full client area width. If “false” can be
anywhere in the client area and does not resize.
Direct value boolean.
No further details.
“BackgroundColour”
Mandatory.
The fill colour of the small area above the tabs’ borders .
Direct value string.
This can be a value defined in hal_lcd.h or a C99 RGB hex constant, for example “0xFF00FF”.
“ForegroundColour”
Mandatory.
The fill colour of the tabs.
Direct value string.
This can be a value defined in hal_lcd.h or a C99 RGB hex constant, for example “0xFF00FF”.
“Lines”
Mandatory.
Number of lines high the tree will be created. This value is not in pixels.
Direct value integer.
This value cannot be less than 1.
“StaticAllocated”
Mandatory.
If the nodes array is statically allocated (“true”) or dynamically allocated (“false”).
Direct value boolean.
“true” or “false”.
“NodeArraySize”
Mandatory
The size of the statically allocated array if statically allocated or the size of the initial malloc (in nodes)
if dynamically allocated.
Direct value integer.
This value cannot be less than 1.
“FolderSeparator”
Mandatory
The character used to separate folders when retrieving the path of a node from a tree.
Direct value string.
This value must be 1 character long exactly.
“RootFolderPath”
Mandatory
The path of the root folder. Must end in separator character. Can be just the separator character which
implies an empty root folder label.
Direct value string.
This value must be a minimum of 1 character long.
“Icons”
Optional, defaults to “false”.
If to show icons for folder or file next to each node in the tree control.
Direct value boolean.
“true” or “false”.
“FolderIcon”
Optional, defaults to the standard MiniWin folder icon bitmap.
The variable name of the array containing the bitmap for the folder icon.
Direct value string.
If specified the bitmap must be monochrome 8x8 for small controls or 16x16 for large controls.
“FileIcon”
Optional, defaults to the standard MiniWin file icon bitmap.
The variable name of the array containing the bitmap for the file icon.
Direct value string.
If specified the bitmap must be monochrome 8x8 for small controls or 16x16 for large controls.
“NodeSelect”
Optional, defaults to “Multi”.
The type of node selection allowed by the user in this tree control.
Direct value string.
Allowable values are “Single” or “Multi”.
“NodeTypeSelect”
Optional, defaults to “All”.
The types of nodes that can be selected in the tree control.
Direct value string.
Allowable values are “FilesOnly”, “FoldersOnly” or “All”.
“FoldersOnly”
Optional, defaults to “false”.
If to show only folder in the tree control, not displaying files.
Direct value boolean.
“true” or “false”.
“RootFolderIsOpen”
Optional, defaults to “false”.
If to show the root folder as open (true) or closed (false) on start up.
Direct value boolean.
“true” or “false”.
“RootFolderIsSelected”
Optional defaulting to “false”.
If to show the root folder as selected (true) or not selected (false) on start up.
Direct value boolean.
“true” or “false”.
No windows found
The JSON configuration file does not specify at least one window.
Could not find ... Continuing anyway. You will need to supply your own ...
The MiniWin source tree is not in a folder parallel to where you are running the code generator and
hence the template files could not be found. Generation will continue but you will have to provide or
manually copy the template files.
Menu bar specified for window ... but no menu items specified
You specified a menu bar for a window but didn’t include the menu bar items setting.
Tree root folder must end in separator character for tree ...
The tree control’s root folder path must end in the same character as specified for the folder separator,
38 Known Issues
Some of the example applications are laid out badly on the LCD for the LPC54628/Renesas Envision
development board, in particular the fixed windows examples. While this example compiles and runs for
these hardware variants it can’t really be used. If you are using either of these development boards the
fix is to change display rotation from 0 degrees to 90 degrees in this project’s configuration file.
The font handling is a bit disorganised with functionality being added in a manner that has made the API
inconsistent, for example TrueType fonts cannot be rotated or drawn transparently.
The gl library requires features from ISO C99 that are supported in newlib but not in redlib. This means
that the larger newlib library has to be used to build MiniWin applications. This will be fixed if there is
any demand for it.
39 Third Party Software
MiniWin uses the following open source third party software:
JSON11
40 Glossary of Terms
Operator - the person using the application you develop by interacting with the windows via the touch
screen.
HAL/hal – hardware abstraction layer. HAL in capitals refers to the set of drivers produced by ST for
STM32 ARM processors; hal in lower case refers to the MiniWin interface to the hardware on the board
it is running on and for the STM32 examples uses the ST HAL.
BSP – Board Support Package. All the code required to support the system on the embedded examples.
Contains drivers and start-up code.
Middleware – A library that is used by an application but does not interact with the hardware directly,
instead using the BSP to access the hardware. An example is the FatFS file system library.
User Code - code you the developer writes (or the code generator creates) as opposed to code that is
supplied as part of the MiniWin window manager.
Window - rectangular area on the screen comprising a window frame, the client area within the window
frame and controls within the client area.
Window Frame - The parts of the window outside of the client area comprising title bar, border, menu
bar and scroll bars. All parts are optional.
Icons - Small bitmaps drawn on a window's title bar for window control purposes. Small bitmaps in tree
and listbox controls. Also a minimized window shown as a rectangle at the bottom of the root window.
Root Window - the background behind all the windows. Also called the desktop.
Z Order - the position of a window relative to all others. A high Z order window is drawn on top of a
lower one. The root window always has Z order 0.
Client Area - The area inside the window frame that the user code draws on and which receives touch
down, up and drag events. All controls in a window are limited to the client area. Also a control has a
client area but no frame, so it is the same as the limits of the control.
Clipping - ignoring a pixel location that is requested to be drawn if it falls outside the client area.
Dialog – a standard window that is part of the MiniWin window manager for simple common operator
interaction, for example a message box with a dismiss button.
Modal – an optional property of a window that means that while it is showing no other window can
receive operator input. All MiniWin standard dialogs are modal.
Handle – a reference to a MiniWin resource created by MiniWin, i.e. window, control or handle. The
handle is used in all later API calls to MiniWin to refer to the resource. A handle is unique and never
reused. It is not a pointer.
MW_WINDOW_FLAG_HAS_TITLE_BAR
Indicates that a window is to be created with a title bar.
MW_WINDOW_FLAG_CAN_BE_CLOSED
Indicates that a window is to be created with an enabled close icon.
MW_WINDOW_FLAG_IS_VISIBLE
Indicates that a window is to be created visible.
MW_WINDOW_FLAG_IS_MINIMISED
Indicates that a window is to be created minimised.
MW_WINDOW_FLAG_IS_MODAL
Indicates that a window is to be created modal.
MW_WINDOW_FLAG_HAS_VERT_SCROLL_BAR
Indicates that a window is to be created with a vertical scroll bar.
MW_WINDOW_FLAG_HAS_HORIZ_SCROLL_BAR
Indicates that a window is to be created with horizontal scroll bar.
MW_WINDOW_FLAG_HAS_MENU_BAR
Indicates that a window is to be created with a menu bar.
MW_WINDOW_FLAG_MENU_BAR_ENABLED
Indicates that a menu bar, if existing, is to be created enabled.
MW_WINDOW_FLAG_VERT_SCROLL_BAR_ENABLED
Indicates that a vertical scroll bar, if existing, is to be created enabled.
MW_WINDOW_FLAG_HORIZ_SCROLL_BAR_ENABLED
Indicates that a horizontal scroll bar, if existing, is to be created enabled.
MW_WINDOW_FLAG_TOUCH_FOCUS_AND_EVENT
Indicates that a touch in a non-focused window gives it focus and generates a touch down event.
MW_WINDOW_FLAG_LARGE_SIZE
Indicates that a window's menu bar and scroll bars are to be created large sized.
MW_WINDOW_FLAG_FIXED_SIZE
Indicates that a window cannot be resized or maximised.
MW_WINDOW_FLAG_MENU_BAR_ITEM_IS_SELECTED
Indicates that a menu bar, if existing, has an item selected. This flag is controlled by the window
manager.
MW_CONTROL_FLAG_IS_ENABLED
Indicates that a control is to be created enabled.
MW_CONTROL_FLAG_LARGE_SIZE
Indicates that a control is to be created large size.
MW_WINDOW_REMOVED_MESSAGE
Message sent to window just before it is removed
message_data: Unused
message_pointer: Unused
MW_WINDOW_GAINED_FOCUS_MESSAGE
Message sent to a window when it gains focus
message_data: Unused
message_pointer: Unused
MW_WINDOW_LOST_FOCUS_MESSAGE
Message sent to a window when it loses focus
message_data: Unused
message_pointer: Unused
MW_WINDOW_RESIZED_MESSAGE
Message to a window when it has been resized
message_data: Upper 16 bits = window new width, lower 16 bits = window new height
message_pointer: Unused
MW_WINDOW_MOVED_MESSAGE
Message to a window when it has been moved
message_data: Unused
message_pointer: Unused
MW_WINDOW_MINIMISED_MESSAGE
Message to a window when it has been minimised
message_data: Unused
message_pointer: Unused
MW_WINDOW_RESTORED_MESSAGE
Message to a window when it has been restored
message_data: Unused
message_pointer: Unused
MW_WINDOW_VISIBILITY_CHANGED_MESSAGE
Message to a window when its visibility has changed
message_data: 1 if made visible, 0 if made invisible
message_pointer: Unused
MW_WINDOW_VERT_SCROLL_BAR_SCROLLED_MESSAGE
Message to a window when a window vertical scroll bar has been scrolled
message_data: new vertical scroll position 0 - 255 as a proportion of scroll bar length
message_pointer: Unused
MW_WINDOW_VERT_SCROLL_BAR_SCROLL_ENDED_MESSAGE,
Message to a window when a window vertical scroll bar scrolling has ended
message_data: Unused
message_pointer: Unused
MW_WINDOW_HORIZ_SCROLL_BAR_SCROLLED_MESSAGE
Message to a window when a window horizontal scroll bar has been scrolled
message_data: new vertical scroll position 0 - 255 as a proportion of scroll bar length
message_pointer: Unused
MW_WINDOW_HORIZ_SCROLL_BAR_SCROLL_ENDED_MESSAGE,
Message to a window when a window horizontal scroll bar scrolling has ended
message_data: Unused
message_pointer: Unused
MW_CONTROL_CREATED_MESSAGE
Message send to control as soon as it is created and before it is painted
message_data: Unused
message_pointer: Unused
MW_CONTROL_REMOVED_MESSAGE
Message sent to control just before it is removed
message_data: Unused
message_pointer: Unused
MW_CONTROL_GAINED_FOCUS_MESSAGE
Message sent to all controls in a window when parent window gains focus or control made visible
message_data: Unused
message_pointer: Unused
MW_CONTROL_VISIBILITY_CHANGED_MESSAGE
Message to a control when its visibility has changed
message_data: 1 if made visible, 0 if made invisible
message_pointer: Unused
MW_CONTROL_LOST_FOCUS_MESSAGE
Message sent to all controls in a window when parent window loses focus or control made invisible
message_data: Unused
message_pointer: Unused
MW_CONTROL_RESIZED_MESSAGE
Message sent to a control when it has been resized
message_data: Upper 16 bits = control new width, lower 16 bits = control new height
message_pointer: Unused
MW_CONTROL_PARENT_WINDOW_RESIZED_MESSAGE
Message sent to a control when its parent window has been resized
message_data: Upper 16 bits = parent window’s new width, lower 16 bits = parent window’s new height
message_pointer: Unused
MW_TOUCH_DOWN_MESSAGE
Message sent to a window or control when it receives a touch down event
message_data: Upper 16 bits = x coordinate, lower 16 bits = y coordinate
message_pointer: Unused
MW_TOUCH_HOLD_DOWN_MESSAGE
Message sent to a window or control when it receives a touch hold down event
message_data: Upper 16 bits = x coordinate, lower 16 bits = y coordinate
message_pointer: Unused
MW_TOUCH_UP_MESSAGE
Message sent to a window or control when it receives a touch up event
message_data: The handle of the original window or control where the touch down occurred
message_pointer: Unused
MW_TOUCH_DRAG_MESSAGE
Message sent to a window or control when it receives a drag event
message_data: Upper 16 bits = x coordinate, lower 16 bits = y coordinate
message_pointer: Unused
MW_MENU_BAR_ITEM_PRESSED_MESSAGE
Response message from a menu bar that an item has been pressed
message_data: The menu bar item selected, zero based
message_pointer: Unused
MW_TIMER_MESSAGE
Message sent to a window or control when a timer has expired
message_data: The handle of the timer that has just expired
message_pointer: Unused
MW_BUTTON_PRESSED_MESSAGE
Response message from a button that it has been pressed
message_data: Unused
message_pointer: Unused
MW_CHECKBOX_STATE_CHANGE_MESSAGE
Response message from a check box that its state has changed
message_data: 1 if check box checked, 0 if check box unchecked
message_pointer: Unused
MW_RADIO_BUTTON_ITEM_SELECTED_MESSAGE
Response message from a radio button that its state has changed
message_data: The selected radio button, 0 based
message_pointer: Unused
MW_LIST_BOX_ITEM_PRESSED_MESSAGE
Response message from a list box that an item has been pressed
message_data: The selected list box line, 0 based
message_pointer: Unused
MW_LIST_BOX_SCROLLING_REQUIRED_MESSAGE
Message posted by a list box to its parent window indicating if scrolling is required, i.e. too many lines to
display at once
message_data: upper 16 bits: 1 if scrolling required, 0 if scrolling not required; lower 16 bits: the
maximum lines that can be scrolled
message_pointer: Unused
MW_CONTROL_VERT_SCROLL_BAR_SCROLLED_MESSAGE
Response message from a vertical control scroll bar that it has been scrolled
message_data: Unused
message_pointer: Unused
MW_CONTROL_VERT_SCROLL_BAR_SCROLL_ENDED,
Response message from a vertical control scroll bar when scrolling has ended
message_data: Unused
message_pointer: Unused
MW_CONTROL_HORIZ_SCROLL_BAR_SCROLLED_MESSAGE
Response message from a horizontal control scroll bar that it has been scrolled
message_data: new horizontal scroll position from 0 to 255 as a proportion of the scroll bar
message_pointer: Unused
MW_CONTROL_HORIZ_SCROLL_BAR_SCROLL_ENDED,
Response message from a horizontal control scroll bar when scrolling has ended
message_data: Unused
message_pointer: Unused
MW_ARROW_PRESSED_MESSAGE
Response message from an arrow that it has been pressed
message_data: The arrow direction
message_pointer: Unused
MW_KEY_PRESSED_MESSAGE
ASCII value of key pressed, can be backspace
message_data: The ASCII code of the pressed key
message_pointer: Unused
MW_TEXT_BOX_SCROLLING_REQUIRED_MESSAGE
Message posted by a text box to its parent window indicating if scrolling is required, i.e. too much text
to display in the box at once
message_data: upper 16 bits: 1 if scrolling required, 0 if scrolling not required; lower 16 bits: the
maximum lines that can be scrolled in pixels
message_pointer: Unused
MW_TAB_SELECTED_MESSAGE
A tab has been selected
message_data: The number of the tab that has been selected, 0 based, 0 at left
message_pointer: Unused
MW_TREE_NODE_SELECTED_MESSAGE,
A tree node has been selected
message_data: The handle of the selected node
message_pointer: Unused
MW_TREE_NODE_DESELECTED_MESSAGE,
A tree node has been deselected
message_data: The handle of the deselected node
message_pointer: Unused
MW_TREE_SCROLLING_REQUIRED_MESSAGE,
Message posted by a tree to its parent window indicating if scrolling is required, i.e. too many visible
nodes to display in the box at once
message_data: upper 16 bits: 1 if scrolling required, 0 if scrolling not required; lower 16 bits: the
maximum lines that can be scrolled
message_pointer: Unused
MW_TREE_FOLDER_OPENED_MESSAGE,
Message posted by a tree to its parent window indicating that a tree folder node has been opened
message_data: Handle of the folder
message_pointer: Unused
MW_TREE_FOLDER_CLOSED_MESSAGE,
Message posted by a tree to its parent window indicating that a tree folder node has been closed
message_data: Handle of the folder
message_pointer: Unused
MW_SCROLLED_CONTROL_NEEDS_PAINTING_HINT_MESSAGE,
A control needs repainting by its owning window
message_data: Unused
message_pointer: Unused
MW_LABEL_SET_LABEL_TEXT_MESSAGE
Set the label's text by passing a pointer to a character buffer
message_data: Unused
message_pointer: Pointer to the label's new text
MW_CHECK_BOX_SET_CHECKED_STATE_MESSAGE
Set a check box's checked state
message_data: 1 to set check box checked or 0 to set it unchecked
message_pointer: Unused
MW_PROGRESS_BAR_SET_PROGRESS_MESSAGE
Set a progress bar's progress level as a percentage
message_data: Percentage to set progress bar's progress from 0 - 100
message_pointer: Unused
MW_SCROLL_BAR_SET_SCROLL_MESSAGE
Set a scroll bar's scroll position
message_data: Set a scroll bar's scroll position from 0 - 255
message_pointer: Unused
MW_LIST_BOX_LINES_TO_SCROLL_MESSAGE
Set how many lines to scroll a list box through the list box's lines
message_data: Number of lines to scroll zero based
message_pointer: Unused
MW_LIST_BOX_SCROLL_BAR_POSITION_MESSAGE
Send the position of a scroll bar associated with a list box to the list box
message_data: Scroll bar position, 0 - 255
message_pointer: Unused
MW_LIST_BOX_SET_ENTRIES_MESSAGE
Set new entries and entry count for a list box
message_data: Number of entries in new array of entries
message_pointer: Pointer to array of entries
MW_TREE_LINES_TO_SCROLL_MESSAGE,
Set how many lines to scroll a tree through the tree's visible nodes
message_data: Number of lines to scroll zero based
message_pointer: Unused
MW_TREE_SCROLL_BAR_POSITION_MESSAGE,
Send the position of a scroll bar associated with a tree to the tree
message_data: Scroll bar position, 0 - 255
message_pointer: Unused
MW_RADIO_BUTTON_SET_SELECTED_MESSAGE
Set a radio button's chosen button
message_data: The button to set, 0 based
message_pointer: Unused
MW_TEXT_BOX_SET_TEXT_MESSAGE
Set the scrollable text box's text by passing a pointer to a character buffer
message_data: Unused
message_pointer: Pointer to the scrollable text box's new text
MW_TEXT_BOX_SCROLL_BAR_POSITION_MESSAGE
Send the position of a scroll bar associated with a text box to the text box
message_data: Scroll bar position, 0 - 255
message_pointer: Unused
MW_TEXT_BOX_LINES_TO_SCROLL_MESSAGE
Set how many lines to scroll a text box
message_data: Number of lines to scroll in pixels
message_pointer: Unused
MW_DIALOG_ONE_BUTTON_DISMISSED_MESSAGE
One button dialog has been dismissed
message_data: Unused
message_pointer: Unused
MW_DIALOG_TWO_BUTTONS_DISMISSED_MESSAGE
Two button dialog has been dismissed
message_data: 0 if left button pressed, 1 if right button pressed
message_pointer: Unused
MW_DIALOG_TIME_CHOOSER_OK_MESSAGE
Time chooser dialog has been dismissed by ok button
message_data: Mask with 0x00FF for minutes, mask with 0xFF00 for hours
message_pointer: Unused
MW_DIALOG_TIME_CHOOSER_CANCEL_MESSAGE
Time chooser dialog has been dismissed by cancel button
message_data: Unused
message_pointer: Unused
MW_DIALOG_DATE_CHOOSER_OK_MESSAGE
Date chooser dialog has been dismissed by ok button
message_data: Mask with 0xFFFF0000 for 4 digit year, mask with 0x0000FF00 for month (1-12), mask
with 0x000000FF for date (1-31)
message_pointer: Unused
MW_DIALOG_DATE_CHOOSER_CANCEL_MESSAGE
Date chooser dialog has been dismissed by cancel button
message_data: Unused
message_pointer: Unused
MW_DIALOG_FILE_CHOOSER_FILE_OK_MESSAGE
File chosen in file chooser dialog
message_data: Unused
message_pointer: Pointer to char buffer holding path and file name
MW_DIALOG_FILE_CHOOSER_FOLDER_OK_MESSAGE
Folder chosen in file chooser dialog
message_data: Unused
message_pointer: Pointer to char buffer holding path name
MW_DIALOG_FILE_CHOOSER_CANCEL_MESSAGE
File chooser dialog was canceled with no file or folder chosen
message_data: Unused
message_pointer: Unused
MW_DIALOG_TEXT_ENTRY_OK_MESSAGE
Text entry dialog ok message
message_data: Unused
message_pointer: Pointer to char buffer holding entered text
MW_DIALOG_TEXT_ENTRY_CANCEL_MESSAGE
Text entry dialog cancel message
message_data: Unused
message_pointer: Unused
MW_DIALOG_NUMBER_ENTRY_OK_MESSAGE
Number entry dialog ok message
message_data: Unused
message_pointer: Pointer to char buffer holding entered number as text including '-' if entered by user
MW_DIALOG_NUMBER_ENTRY_CANCEL_MESSAGE
Number entry dialog cancel message
message_data: Unused
message_pointer: Unused
MW_DIALOG_COLOUR_CHOOSER_OK_MESSAGE
Colour chooser dialog ok message
message_data: Chosen colour in 24 bit RGB format
message_pointer: Unused
MW_DIALOG_COLOUR_CHOOSER_CANCEL_MESSAGE
Colour chooser dialog cancel message
message_data: Unused
message_pointer: Unused
MW_WINDOW_FRAME_PAINT_MESSAGE
System message to get a window's frame painted
message_data: Combination of MW_WINDOW_FRAME_COMPONENT_TITLE_BAR,
MW_WINDOW_FRAME_COMPONENT_BORDER,
MW_WINDOW_FRAME_COMPONENT_MENU_BAR,
MW_WINDOW_FRAME_COMPONENT_VERT_SCROLL_BAR,
MW_WINDOW_FRAME_COMPONENT_HORIZ_SCROLL_BAR
message_pointer: Unused
MW_WINDOW_CLIENT_PAINT_MESSAGE
System message to call a window's client area paint function
message_data: Unused
message_pointer: Unused
MW_WINDOW_CLIENT_PAINT_RECT_MESSAGE
System message to call a window's client area paint rect function
message_data: Unused
message_pointer: Pointer to a mw_util_rect_t structure
MW_CONTROL_PAINT_MESSAGE
System message to call a control's paint function
message_data: Unused
message_pointer: Unused
MW_CONTROL_PAINT_RECT_MESSAGE
System message to call a control's paint rect function
message_data: Unused
message_pointer: Pointer to a mw_util_rect_t structure
MW_WINDOW_EXTERNAL_WINDOW_REMOVED
Message to a window when another window has been removed that is not the window receiving the
message. Use this message when a window is removed as a result of user code and another window
needs to know
message_data: Unused
message_pointer: Unused
MW_USER_1_MESSAGE
Message to a window for any user-defined purpose
message_data: Any user meaning
message_pointer: Any user meaning
MW_USER_2_MESSAGE
Message to a window for any user-defined purpose
message_data: Any user meaning
message_pointer: Any user meaning
MW_USER_3_MESSAGE
Message to a window for any user-defined purpose
message_data: Any user meaning
message_pointer: Any user meaning
MW_USER_4_MESSAGE
Message to a window for any user-defined purpose
message_data: Any user meaning
message_pointer: Any user meaning
MW_USER_5_MESSAGE
Message to a window for any user-defined purpose
message_data: Any user meaning
message_pointer: Any user meaning
It is necessary to use a panel with 2 driver chips fitted for both the LCD and the touch sensor (some do
not have the touch sensor chip fitted) and to have the SD card socket fitted. The 2 SPI driver chips are an
ILI9341 for the LCD display and a generic one for the touch panel’s restive sensor.
43.2 Camera
For the embedded variants on the MiniWinCamera example projects a cheap OV7670 camera module
without a hardware buffer is used. These are available from ebay for a few £$€ and look like this:
For the Raspberry Pi Zero W MiniWInCamera example project a cheap generic USB webcam is used. This
is because the Raspberry Pi camera module that plugs into the connector on the board is expensive. A
generic webcam can be bought for a few £$€ on ebay, like this…
44.3 Camera
A digital camera as shown in section 43.2 is required.
3.3V 3V
DGND GND
SCL PB6
SDA PB7
VS PC11
HS PA5
PLK PB4
XLK PF6
D7 PG9
D6 PE6
D5 PE5
D4 PE4
D3 PE3
D2 PE2
D1 PG3
D0 PG2
RET NC
PWDN NC
Touch
T_IRQ PD9
T_DO PC11
T_DIN PC12
T_CS PD10
T_CLK PC10
LCD
MISO PC2
LED 3V
SCK PB13
MOSI PB15
DC PD7
RESET PD6
CS PD8
GND GND
VCC 3V
45.3 Camera
A digital camera as shown in section 43.2 is required.
GPIO pins on port A: PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7
GPIO pins on port C: PC, PC1, PC3
46.3 Camera
A digital camera as shown in section 43.2 is required.
47.3 Camera
A digital camera as shown in section 43.2 is required.
The following connections are required:
1 CS/
2 MOSI
3 MISO
4 SCK
5 GND
6 +3.3V
48.3 Camera
A digital camera as shown in section 43.2 is required.
Touch
ILI9341 DevKitC
T_IRQ G5
T_DO G25
T_DIN G23
T_CS G17
T_CLK G19
LCD
ILI9341 DevKitC
MISO G25
LED 3.3V
SCK G19
MOSI G23
DC G21
RESET G18
CS G22
GND GND
VCC 3.3V
In addition a simple push button is connected between port pin G16 and ground to signal when pressed
that a screen recalibration is required.
SD_CS G13
SD_MOSI G15
SD_MISO G2
SD_SCK G14
49.3 Camera
A digital camera as shown in section 43.2 is required.
OV7670 DevKitC
3.3V 3.3V
DGND GND
SCL G27
SDA G26
VS G2
HS SM (G39)
PLK G4
XLK G12
D7 G15
D6 G14
D5 RXD (G3) (See note below)
D4 SP (G36)
D3 G35
D2 G34
D1 G33
D0 G32
RET -
PWDN -
GPIO pins: G2, G3, G4, G14, G15, G32, G33, G34, G35, G36, G39
I2C channel 0 on G26 and G27 during call of library function camlib_init().
During flashing of the DevKitC board the connection between the camera’s D5 and the board’s RXD
pin must be removed.
This camera driver is slow and requires the watchdog to be switched off and task switching disabled
when reading a frame. This may affect other functionality of the ESP32 processor, like WiFi and
Bluetooth. This example is not intended to be a useful camera driver but instead only to demonstrate
MiniWin. If a proper camera driver is required it is suggested to use the one supplied by Espressif which
can be found here:
https://github.com/espressif/esp32-camera
Touch
LCD
50.3 Camera
A digital camera as shown in section 43.2 is required.
51.3 Camera
This uses the first video camera that is found and must be supported by the OpenCV library. Most USB
and integrated laptop cameras are supported.
52.3 Camera
This uses the first video camera that is found and must be supported by the OpenCV library. Most USB
and integrated laptop cameras are supported. If running in VirtualBox the camera must be shared from
host to guest.
Touch
LCD
53.3 Camera
A digital camera as shown in section 43.2 is required.
Touch
LCD
Touch
LCD
In addition a simple push button is connected between pin 26 (GPIO 20) and ground to signal when
pressed that a screen recalibration is required.
55.3 Camera
Not yet available.
Touch
LCD
Recalibration
A push button is required to be connected between PA14 on connector DIGITAL pin number 23 and
GND.
3.3V - 3V3
DGND - GND
SCL PA18 SCL1
SDA PA17 SDA1
VS PC3 DIGITAL 35
HS PC5 DIGITAL 37
PLK PC1 DIGITAL 33
XLK PC22 PWM 8
D7 PD7 PWM 11
D6 PD6 DIGITAL 29
D5 PD5 RX3
D4 PD4 TX3
D3 PD3 DIGITAL 28
D2 PD2 DIGITAL 27
D1 PD1 DIGITAL 26
D0 PD0 DIGITAL 25
RET - NC
PWDN - NC
57.3 Camera
MiniWinCamera example project has not been ported to this board yet.
make
Obtaining MSYS2:
https://www.msys2.org/
pacman -S base-devel
pacman –S gcc
pacman –S mingw-w64-x86_64-gdb
pacman -S base-devel
pacman -S mingw-w64-x86_64-clang
pacman –S mingw-w64-x86_64-gdb
C:\msys64\usr\bin
C:\msys64\mingw64\bin
If you wish to build the MiniWinCamera example project with GCC or clang you need to install this extra
package:
pacman -S mingw-w64-x86_64-opencv
make
make clean
• Start a Visual Studio X64 Native Tools command prompt (found under the Visual Studio
application folder in Start menu).
• Do all command line building from this command prompt.
Building any simulation project (except MiniWinCamera, see below) or tool with Visual Studio cl in
Windows:
nmake -f nmakefile
To build the MiniWinCamera example project there are some additional steps needed:
https://opencv.org/releases
You need to set an OpenCV environment variable pointing to your OpenCV installation location:
set OPENCV_DIR=C:\opencv
To run the MiniWinCamera project you need to set the location of the OpenCV pre-built DLL library
found in the OpenCV installation like this:
set PATH=%OPENCV_DIR%\build\x64\vc15\bin;%PATH%
The makefile at the time of writing uses a path containing the version of OpenCV current at the time
(455). You may need to alter this is you have a later version. Edit nmakefile for the correct path.
The development environment for native compiling (GCC, make) is a standard part of Raspberry Pi OS.
The SPI interface needs enabling in Preferences|Raspberry Pi Configuration|Interfaces.
sudo ./MiniWinSimple
To build the camera example you need to install the OpenCV development package:
The build process for a Raspberry Pi Pico is done on another Raspberry Pi with Linux, for example the
Zero W. To install the Pico SDK follow instructions in this document:
https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf
To build each project in its project build folder use these commands:
cmake .
make
While holding down the BOOTSEL button plug in the micro USB cable between the Pico and the
development machine. When a Pico file explorer window appears on the development machine drag
the .uf2 file into it from the project folder of the development machine. Once copied the explorer
window will automatically close and the Pico application start running.
1) Download and install the free BOSSA application from this location
http://www.shumatech.com/web/products/bossa
2) In the BOSSA installation folder C:\Program Files (x86)\BOSSA create a text file named
DueProgrammer.txt with this content:
mode %1:1200,n,8,1,p
"C:\Program Files (x86)\bossa\bossac.exe" --port=%1 -i -e -w -v -b %2 -R
3) Plug in the USB cable to the USB port on the Due board labelled Native USB. Press and hold
the ERASE button for 2 seconds. Press and release the RESET button.
4) A new COM port will appear on your computer. Use Window’s Device Manager to find its
number. In the example below COM4 is used but yours may be different.
5) In Microchip/Atmel Studio go to Tools|External Tools. If you have no existing external tool
defined it creates an empty one for you called [New Tool 1]. Otherwise click Add.
6) For Title enter text Due Programmer.
7) For Command enter C:\Program Files (x86)\BOSSA\DueProgrammer.bat
8) For Arguments enter COM4 $(TargetDir)$(TargetName).bin
9) For Initial Directory enter $(TargetDir)
10) Untick Close on Exit. Tick Use Output Window
11) Click OK
You can now build you example project. When it has built plug in the USB cable to the USB port on the
Due board labelled Native USB. Press and hold the ERASE button for 2 seconds. Press and release the
RESET button. In Microchip/Atmel Studio you now use the menu item Tools|Due Programmer to
program the code onto the processor.