5.4.7 BLE and Parallel 8080 Interface Transparent UART
This section provides a comprehensive overview of integrating a parallel 8080-interface driven display with an external controller to deliver advanced graphics capabilities using BLE technology on the PIC32-BZ6 Curiosity Board. The 8080 interface is used to drive the display (320x480, RGB565), with the frame buffer offloaded to the external display controller to save on-board RAM. See GUI Design Decisions below for more information on 8080-interface displays.
This guide highlights the development process of creating a BLE-enabled coffee maker peripheral device that seamlessly accepts and processes commands from a central device such as a smartphone running the Microchip Bluetooth Data (MBD) application. Users can select from five different drink options and initiate the brewing process directly from their smart device or from the GUI itself.
This project leverages the Microchip Graphics Composer to design an intuitive coffee maker GUI featuring a variety of interactive widgets. The demonstration showcases real-time communication between the coffee maker and the central device, including command confirmations, remaining brew time, and low water notifications. The GUI dynamically updates in response to these interactions, providing immediate visual feedback.
This section explores the integration of sophisticated GUI elements and BLE connectivity, demonstrating how the PIC32-BZ6 Curiosity Board can support complex, data-rich applications.
Recommended Readings
-
Getting Started with Application Building Blocks – See Building Block Examples from Related Links.
-
Getting Started with Peripheral Building Blocks – See Peripheral Devices from Related Links.
-
See BLE Connection from Related Links.
- See BLE Transparent UART from Related Links.
- See BLE and LCC Transparent UART from Related Links.
-
BLE Software Specification – See MPLAB® Harmony Wireless BLE in Reference Documentation from Related Links.
Hardware Requirement
| S. No. |
Tool |
Quantity |
|---|---|---|
| 1 |
PIC32-BZ6 Curiosity Board | 1 |
| 2 |
USB-C cable |
1 |
| 3 | Smartphone with MBD application | 1 |
| 4 | 24-Bit Passthrough Adapter | 1 |
| 5 | 3.5’’maxTouch Curiosity Pro Board Display | 1 |
SDK Setup
Refer to Getting Started with Software Development from Related Links.
Software Requirement
To install Tera Term tool, refer to the Tera Term web page in Reference Documentation from Related Links.
Smart phone App
- Microchip Bluetooth Data (MBD)
Programming the Precompiled Hex File or Application Example
Using MPLAB® X IPE:
- Import and program the precompiled hex
file:
<Discover Path>\wireless_apps_pic32_bz6\apps\ble\peripheral_applications\parallel8080_peripheral_trp_uart\precompiled_hex\parallel8080_peripheral_trp_uart.X.production.signed.hex. - For detailed steps, refer to
Programming a Device in MPLAB® IPE in Reference
Documentation from Related Links.Note: Ensure to choose the correct Device and Tool information.
Using MPLAB® X IDE:
-
Perform the following the steps mentioned in Running a Precompiled Example. For more information, refer to Running a Precompiled Application Example from Related Links.
- Open and program the application example
parallel8080_peripheral _trp_uart.Xlocated in:<Discover Path>\wireless_apps_pic32_bz6\apps\ble\peripheral_applications\parallel8080_peripheral _trp_uart \firmware. - For more details on how to find the Discover path, refer to Download Application Example from Discover in Running a Precompiled Application Example from Related Links.
Demo Description
From the Main screen, users can select one of five drinks. The selected drink is the image between the green arrows. A Bluetooth icon in the upper right corner indicates the BLE connection status: gray when disconnected, and blue when a connection is active.
- “start”
- “select <option>”
- Where <option> can be: “espresso”, “latte”, “macchiato”, “cappuccino”, or “americano”
The “start” command will start brewing the selected option and display the Brewing screen regardless of the previous screen that was being displayed. The “select <option>” command will change the selected drink on the Main screen and show the Main screen regardless of the previous screen that was being displayed.
The coffee maker sends confirmation responses for valid commands, or an error response if a command is invalid.
The name of the selected coffee will be displayed in the upper left corner of the screen. If a central device is connected, the coffee maker will send brewing status updates specifying the remaining time in increments of 30 seconds.
The brewed coffee image will be displayed in the center of the screen. If a central device is connected, a notification will be sent indicating that the brewing has been completed.
The image at the center of the screen will flash.
After the resume button is pressed, the Brewing screen will be displayed, and the timer will resume from where it left off.
Testing
Ensure the cable is connected to a correct position of the LCD module as shown in the above picture.
This demo utilizes one smartphone device with MBD installed (See BLE Transparent UART from Related Links). This device will act as a central that will scan and connect to our peripheral PIC32-BZ6 Curiosity Board.
Board1 = PIC32-BZ6 Curiosity Board with parallel8080_peripheral _trp_uart application programmed
Phone1 = Smartphone with MBD installed
iOS MBD Setup
Phone1: To begin scanning on the MBD app, follow the sequence of events below:
Board 1: Open TeraTerm @ (Speed: 115200, Data: 8-bit, Parity: none, stop bits: 1 bit, Flow control: none). Reset the board.
Navigate to the Settings screen by selecting the gear icon in the lower right corner of the screen and ensure that advertising is enabled.
Once connected, the BT Status will change to “Connected” on the Settings screen and the Enable Advertising button will be unchecked and disabled while the connection is active.
The GUI will automatically initiate the brewing and display the Brewing screen. Additionally, the GUI will send a response to MBD notifying that the “start” command was received.
Select the Resume button and the timer will resume where it left off.
“Refill” is mandatory before starting another brew, otherwise further brew attempts will not start and will display the Low Water screen.
Selecting the settings icon on any other screen besides the brewing screen and refill screen will display the Settings screen. In the case of brewing and refill, these buttons are used for testing simulation.
Navigate to the Settings screen and select the disconnect button. The BT Status will change back to “Idle” and the Enable Advertising checkbox will be reenabled.
Developing this Application from Scratch using MCC
-
Create a new harmony project. For more details, see Creating a New MCC Harmony Project from Related Links.
- Accept dependencies or satisfiers when prompted.
- Verify if the project graph window has
all the expected configuration.
Figure 5-266. Project Graph
The following components are from the GFX library:
- GFX Core LE
- Input System Service
- MaxTouch Controller
- maXTouch Curiosity Pro
- LE External Controller
- LE Parallel (Port Group)
- Legato
- Legato Graphics w/ MXT Curiosity Pro Display
This project utilizes the GFX library to generate the code needed for graphics projects. Refer Harmony guide Getting Started with Microchip Graphics Suite (MGS) Harmony in Reference Documentation from Related Links for graphics projects. Additionally, it is recommended that users refer to Getting Started with a New Harmony Graphics Application in Reference Documentation from Related Links to learn how to utilize the library to create projects.
Microchip Graphics Suite (MGS) Harmony Composer is a GUI design tool used to create widgets and configure various screens. For more information about the MGS Composer, refer to Microchip Graphics Suite (MGS) Harmony Composer User Guide in Reference Documentation from Related Links.
For more information on the BLE related components, see BLE Transparent UART from Related Links.
Verifying Advertisement, Connection and Transparent UART Profile Configuration
-
Select the BLE Stack component in the Project Graph.
- Select Transparent Profile
component in the Project Graph.
Verify the FreeRTOS Configuration
Select the FreeRTOS component and verify the configuration.
Verify TC4 Configuration
Select the TC4 component in the Project Graph.
Verify Core Configuration
Select the Core component in the Project Graph.
Verify EVSYS Configuration
Select the EVSYS component in the Project Graph.
Verify CCL Configuration
Select the CCL component in the Project Graph.
Verifying SERCOM0 Configuration
-
Select SERCOM0 component in the Project Graph.
Verifying maxTouch Configuration
-
Select maxTouch Controller component in the Project Graph.
Figure 5-272. MaxTouch Controller - Select the I2C component in the Project Graph.
Figure 5-273. I2C Component - Select the SERCOM1 component in the Project Graph.
Figure 5-274. SERCOM1 Component
Verify Graphics Configuration
- Select the LE Parallel (Port Group) component in the Project Graph.
Figure 5-275. LE Parallel (Port Group) - Select the LE External Controller component in the Project Graph.
Figure 5-276. LE External Controller Component - Select the Legato component in the Project Graph.
Figure 5-277. Legato Component - Select the TC1 component in the Project Graph.
Figure 5-278. TC1 Component - Select the GFX Core LE component in the Project Graph.
Figure 5-279. GFX Core LE Component - Select the Input System Service component in the Project Graph.
Figure 5-280. Input System Service Component
Verifying the Pin Configuration
-
Select Pin Configuration under Plugins in the Project Graph:
- Verify the Pin Settings:
Verify the GUI
- Select the Microchip Graphics Composer under the Plugins in the Project
Graph.
Figure 5-281. Microchip Graphics Composer - Verify the GUI has loaded in:
GUI Design Decisions
The setup that we are using in this demo is the parallel version of #1 in the image above. The design in the BLE and LCC Transparent UART project used an LCC display that was #3 in the above diagram. For more details, refer to the BLE and LCC Transparent UART from Related Links. The main difference is that the display used now has an external controller driven by the parallel 8080-interface. The frame buffer is stored externally. In the LCC project, the frame buffer was stored locally and there was not an external controller. For information on the external controller, see the datasheet. In addition, see the Microchip Graphics Suite (MGS) External Controller Driver User Guide and Hardware Guide for SAME54 Curiosity Ultra with maXTouch® Curiosity Pro Touchscreen Display for information regarding the external controller. This documentation uses the SAME5x devices, but the information can be generalized to this project.
For high resolution displays, one of the main contributors of RAM usage will be the frame buffer which is offloaded to the external display controller.
For this design, the scratch buffer contributes heavily to RAM usage. It is used for drawing segments of the screen on page refreshes. This can be increased or decreased but will impact refreshing performance. For detailed information on the scratch buffer, see Adjusting Scratch Buffer Size in Reference Documentation from Related Links.
Lastly, the fixed heaps also contribute to the RAM usage but are dictated by the number of widgets used. For further information about fixed heaps, see Optimizing the Memory Manager Settings in Reference Documentation from Related Links.
Frame Buffer:
Since we are using Hardware setup 1 for this application, our frame buffer will be allocated outside the PIC32-BZ6 Curiosity Board. In addition, we are using RGB565, so we require two bytes for each pixel. For our 320x480 display, the frame buffer will require 320*480*2byte = 307,200 bytes located on the external controller.
Scratch Buffer:
The tradeoff with better color is that the scratch buffer needs to be equally as large as the frame buffer when the entire screen needs to update. To minimize our memory consumption, we set the scratch Buffer to half of the frame buffer.
Navigating within MGS Harmony Composer for the Coffee Maker GUI
- To launch the composer, click “Microchip Graphics Composer” in the Project Graph
Plugins.
- The individual screens can be selected at the top of the MGC page:
- Adding Widgets: Refer to Widgets Guide in Reference Documentation from Related Links.
- Fixed Heaps: The fixed heaps in this design have been minimized to save memory,
so if a new widget is added, you must increase the number of fixed heaps and reoptimize
later (notes on optimization later). Increase all fixed heap sizes by a large amount
during development to avoid crashes. Fixed heaps can be increased in the memory portion
of the Project Settings:
- Events: Refer to Creating a Dynamic UI with Event Handling in Reference Documentation from Related Links.
- Event handlers for widgets and screen events are declared in the generated
le_gen_screen_<screen name>.hfile and must be implemented in user application code. For example, the main screen events are declared in thele_gen_screen_main.hfile and the handlers are implemented in theapp_Main.cfile: - Images, fonts, and strings can be added and managed in their respective pages
found under Asset:
- Color Schemes Guide: Refer to About the Schemes and Scheme Editor in Reference Documentation from Related Links.
Base Scheme is used for the background color and the white text.
text_lightseagreen is used for the green colored text.
Notes about Reoptimizing Fixed Heaps
Refer to Optimizing the Memory Manager Settings in Reference Documentation from Related Links.
After adding more widgets to the design, the fixed heaps can be increased and reoptimized.
The GFX library provides a function called leMemoryPrintReport() that can
print out the fixedHeap usage of the GUI to a terminal.
- First increase all heap sizes by at least five for each new widget added and generate
the code.
- Second, uncomment the following line in
app_Ready.c.
- Then, enable a breakpoint in the
leMemoryPrintReport()function inlegato_memory.c.
- Add a watch to the fixedHeaps array.
- Run the project in Debug mode.
- Run through the entire GUI, selecting all buttons and making all widgets visible at
least once. Do not press the btnBrew button on the Ready screen until the very
end.
- After all buttons are pressed and the btnBrew button on the Ready screen is pressed
last, the program will break. In the “Variables” tab, you can view the fixedHeaps array.
Here you can view each fixed heaps logical block size and their max usage:
legato_config.h.
fixedHeaps[1] corresponds to LE_FIXEDHEAP_SIZE_32. fixedHeaps[2]
corresponds to LE_FIXEDHEAP_SIZE_64 and so on.- Set the fixed heap sizes to the maxUsage number.
Regenerate the code, program the device not in debug mode, and run through the entire GUI to ensure there are no crashes.
Tasks and Task Priority
The above diagram shows the multiple tasks running simultaneously. Input system service, External Controller, Legato, and MaxTouch Controller all come from GFX while BLE and App core do not. Legato and External Controller have higher priority than MaxTouch to prioritize screen updates over touch events but lower priority than BLE to avoid throughput deterioration.
Generating a Code
For more details on code generation, refer to MPLAB Code Configurator (MCC) Code Generation from Related Links.
Files and Routines Automatically Generated by the MCC
For details about the BLE configuration that is generated, see BLE Transparent UART from Related Links.
For details about GFX code generation, see Getting Started with a New Harmony Graphics Application in Reference Documentation from Related Links.
User Application Development
Include:
- definitions.h must be included
in all the files where UART will be used to print debug information.Note:
definitions.his not specific to UART peripheral, instead it must be included in all application source files where peripheral functionality will be exercised. - Include the user action. For more information, refer to User Action from Related Links.
Required Changes to Generated Graphics File
- After generating the code, the following changes must be made to the
“drv_gfx_disp_intf_parallel_portgroup_dma.c” file:
- Change line 45:
“#define GFX_DISP_INTF_PORT (PORT_GROUP_1)” ---> “#define GFX_DISP_INTF_PORT GPIO_PORT_B” - Change line
47:
“#define DATABUS_PTR (&(PORT_REGS->GROUP[1].PORT_OUT))” ---> “#define DATABUS_PTR ((uint32_t)(&(GPIOB_REGS->GPIO_PORT)))” - Change line
71:
“PORT_GROUP port;” ---> “GPIO_PORT port;”
- Change line 45:
Unique Files
The following list of files were either edited or added to the project.
| File | Added or Edited | Notes |
|---|---|---|
app.c | Edited | Maintains app state machine. Added OSAL queue callbacks for trp service and a timer callback. Added to the initialization. |
app.h | Edited | Definitions and global variables |
app_ble_handler.c | Edited | Maintain a connection handle when a connection is established and destroyed. Utilized GATTC read service to get the name of the connected device. |
app_ble_handler.h | Edited | Global variable definitions |
app_trsps_handler.c | Edited | Parses received commands and sets flags to let the GUI know to update based on the command. Sends command responses to central connected device. |
app_trsps_handler.h | Edited | Global variable definitions |
default_design.zip | Added | MGS composer design |
app_macros.h | Added | Holds macros for gfx library |
app_Main.c | Added | Holds GUI event handling and helper functions for the main screen |
app_Main.h | Added | Definitions and global variables |
app_Brewing.c | Added | Holds GUI event handling and helper functions for the brewing screen |
app_LowWater.c | Added | Holds GUI event handling for the low water screen |
app_Ready.c | Added | Holds GUI event handling for the ready screen |
app_Refill.c | Added | Holds GUI event handling for the refill screen |
app_Resume.c | Added | Holds GUI event handling for the resume screen |
app_Settings.c | Added | Holds GUI event handling for the settings screen |
app_Startup.c | Added | Holds GUI event handling for the startup screen |
Widgets within app_screen_main.c
The following table shows the widgets with their accompanying event handlers.
| Widget | Event handler | Notes |
|---|---|---|
|
| N/A | This indicates if a BLE connection is currently being held. Gray means disconnected, blue means connected. |
|
| event_Main_lstWheelOptions_OnSelectionChanged(leListWheelWidget* wgt, int32_t idx) | This is the scrollbar that selects a drink to brew. The handler changes the current Item index. |
|
| event_Main_btnStart_OnPressed(leButtonWidget* btn) | Initiates brewing by displaying the brewing screen. Sends a start notification to the connected device. |
|
|
| Displays the settings screen. |
|
|
| Toggles the is water low boolean variable. Simulates a low water alert and completing the refill. |
|
|
| Displays the main screen. |
|
| event_LowWater_btnContinue_OnPressed(leButtonWidget* btn) | Displays the refill screen. |
|
| event_Ready_btnContinue_OnPressed(leButtonWidget* btn) | Displays the main screen. The image in the center will depend on the coffee that was selected and brewed. |
|
| event_Resume_btnContinue_OnPressed(leButtonWidget* btn) | Displays the brewing screen. |
|
|
| Enables or disables advertising. |
|
| N/A | Displays BT Status as “Connected” if a connection is being held or “Idle” if there is no connection being held. |
|
|
| This enables the BLE Throughput Testing mode. Enabling this mode sets a flag that will disable parsing of received commands and will restrict sending responses and notifications to the connected device. |
|
| event_Settings_btnDisconnect_OnPressed(leButtonWidget* btn) | Disconnects the connected device and changes the BT Status to “Idle”. |
Additional GUI Interaction within Screen Application Code
All interaction with the GUI should be implemented within the created screen files (In
other words, app_Main.c, app_Settings.c, etc.). Therefore,
various flags are set by the BLE callback functions that allow the GUI to handle the screen
updates. For example, when the start or select commands are received, a
ble_start or ble_select flag will be set. All screen
update functions (In other words, Main_OnUpdate,
Settings_OnUpdate) listen for the flags and perform the screen updates
accordingly.
A timer callback is in app.c that is called every 100 ms. This timer is used for various tasks to help update the GUI.
- Screen event callbacks. These functions must handle all the GUI updates.
- The <screen>_OnShow() function is called once when the screen is first shown.
- <screen>_OnHide() is the function called when another screen is made visible.
- <screen>_OnUpdate() is periodically called to update the GUI.
BLE Implementation
BLE_GAP_EVT_CONNECTED in
app_ble_handler.c. When a disconnect occurs, the connected_flg is cleared.
APP_MSG_COMMAND_RSP_CB is defined in the
APP_MsgId_T enum in app.h.APP_CommandRSPCBHandler() in
app.c.APP_CommandRSPCBHandler() function uses the
BLE_TRSPS_SendData() API to send the buffered response, which is a global
variable set when a response or notification needs to be sent. BLE_TRSPS_EVT_RECEIVE_DATA
in app_trsps_handler.c handles the command parsing and response
sending.app_Brewing.c, app_LowWater.c and
app_Main.c send notifications for brewing updates, low water alerts, and
start alerts to the central device.
