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.

Hardware Requirement

Table 5-80. Hardware Prerequisites
S. No.

Tool

Quantity

1

PIC32-BZ6 Curiosity Board

1
2

USB-C cable

1

3Smartphone with MBD application1
424-Bit Passthrough Adapter1
53.5’’maxTouch Curiosity Pro Board Display1

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

  1. Microchip Bluetooth Data (MBD)

Programming the Precompiled Hex File or Application Example

Using MPLAB® X IPE:

  1. 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.
  2. 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:

  1. Perform the following the steps mentioned in Running a Precompiled Example. For more information, refer to Running a Precompiled Application Example from Related Links.

  2. Open and program the application example parallel8080_peripheral _trp_uart.X located in: <Discover Path>\wireless_apps_pic32_bz6\apps\ble\peripheral_applications\parallel8080_peripheral _trp_uart \firmware.
  3. 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

The following diagram shows the basic flow of the demonstration.
To highlight the graphics controlling capabilities, this demo features a coffee maker interface that allows users to select and brew one of five different drinks.

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.

The system acts as a peripheral device that can advertise to nearby devices. Advertising can be enabled or disabled within the Settings screen shown below.
Note: The BLE Throughput Test Mode is enabled for BLE throughput testing. Enabling this checkbox will disable the parsing of received commands and restrict responses and notifications from being sent from the Coffee Maker.
Users can enable or disable BLE advertising by selecting the check box. If a connection is being held, then the button will be disabled. Additionally, if a connection is being held, the BT Status string will display “Connected”. If no device is connected, the checkbox remains enabled, and the BT Status is shown as “Idle.” A Disconnect button is also available to terminate any active BLE connection.
Once a central device is connected, it can send two types of commands to the coffee maker:
  • “start”
  • “select <option>”
    • Where <option> can be: “espresso”, “latte”, “macchiato”, “cappuccino”, or “americano”
Note: The commands are case sensitive and must be sent in all lowercase.

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.

When brewing begins—either by receiving the “start” command or pressing the Start button—the Brewing screen appears.

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.

When the timer elapses, the following Ready screen will be displayed:

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.

When a low water alert is raised, the following Low Water screen will display:

The image at the center of the screen will flash.

As the water is being refilled, the following Refill screen will display:
The image in the center will transition between four images as the screen is shown:
After the water is filled, the following Resume screen will be shown:

After the resume button is pressed, the Brewing screen will be displayed, and the timer will resume from where it left off.

Testing

Hardware setup:

Ensure the cable is connected to a correct position of the LCD module as shown in the above picture.

Important: The 24-bit passthrough adapter supplies 5V to the LCD by default. However, the maxTouch Curiosity Pro Board LCD is rated only for 3.3V. Therefore, resistor R2 on the 24-bit passthrough board must be removed and resoldered to the R1 space.

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:

Select BLE UART:
Select PIC32CXBZ:
Select Start:

Board 1: Open TeraTerm @ (Speed: 115200, Data: 8-bit, Parity: none, stop bits: 1 bit, Flow control: none). Reset the board.

Upon reset, an initial Startup screen will be displayed before the Main screen.
After a 3 second pause, the Main screen will be displayed with Espresso selected by default.

Navigate to the Settings screen by selecting the gear icon in the lower right corner of the screen and ensure that advertising is enabled.

Initiate scanning on MBD and select “Coffee Maker”
After connecting, the following screen will be displayed on MBD

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.

Navigate back to the Main screen and observe that the BLE icon in the upper right has turned from gray to blue.
On MBD, select “Text mode” and confirm that “Display Data” is turned on in the MBD settings.
In MBD, send the command “select latte”
The GUI will automatically update the selected drink on the Main screen and will send a response to MBD.
In MBD, send the “start” command to initiate brewing.

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.

Brewing updates will be sent to MBD that notify the seconds remaining in increments of 30 seconds.
When brewing completes, the Ready screen will display with the selected coffee image displayed in the center. The GUI will also send a notification to MBD saying that the brewing has completed.
Navigate back to the Main screen and use the scrollbar on the left to select another drink. Initiate brewing again by selecting the Start button. When brewing is initiated within the GUI, a notification will be sent to MBD:
While the timer is still going, select the Settings button in the lower right corner of the Brewing screen.
This will simulate a low water alert and the Low Water screen will display:
The icon in the center will flash and a notification will be sent to MBD:
Refill by pressing the flashing icon. This will display the Refill screen:
To complete the filling process, press the settings icon in the lower right corner of the Refill screen. This will display the Resume screen:

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.

MBD will show that the device has been disconnected.

Developing this Application from Scratch using MCC

Follow the steps below to build the application manually:
Note: It is recommended for the new users of the MPLAB Code Configurator to refer MPLAB® Code Configurator (MCC) User’s Guide in Reference Documentation from Related Links.
  1. Create a new harmony project. For more details, see Creating a New MCC Harmony Project from Related Links.

  2. Accept dependencies or satisfiers when prompted.
  3. 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

  1. Select the BLE Stack component in the Project Graph.
  2. Select Transparent Profile component in the Project Graph.

Verify the FreeRTOS Configuration

Select the FreeRTOS component and verify the configuration.

Figure 5-267. FreeRTOS Configuration

Verify TC4 Configuration

Select the TC4 component in the Project Graph.

Figure 5-268. TC4 Configuration

Verify Core Configuration

Select the Core component in the Project Graph.

Figure 5-269. Core Configuration

Verify EVSYS Configuration

Select the EVSYS component in the Project Graph.

Figure 5-270. EVSYS Configuration

Verify CCL Configuration

Select the CCL component in the Project Graph.

Figure 5-271. CCL Configuration

Verifying SERCOM0 Configuration

  1. Select SERCOM0 component in the Project Graph.

Verifying maxTouch Configuration

  1. Select maxTouch Controller component in the Project Graph.
    Figure 5-272. MaxTouch Controller
  2. Select the I2C component in the Project Graph.
    Figure 5-273. I2C Component
  3. Select the SERCOM1 component in the Project Graph.
    Figure 5-274. SERCOM1 Component

Verify Graphics Configuration

  1. Select the LE Parallel (Port Group) component in the Project Graph.
    Figure 5-275. LE Parallel (Port Group)
  2. Select the LE External Controller component in the Project Graph.
    Figure 5-276. LE External Controller Component
  3. Select the Legato component in the Project Graph.
    Figure 5-277. Legato Component
  4. Select the TC1 component in the Project Graph.
    Figure 5-278. TC1 Component
  5. Select the GFX Core LE component in the Project Graph.
    Figure 5-279. GFX Core LE Component
  6. Select the Input System Service component in the Project Graph.
    Figure 5-280. Input System Service Component

Verifying the Pin Configuration

  1. Select Pin Configuration under Plugins in the Project Graph:
  2. Verify the Pin Settings:

Verify the GUI

  1. Select the Microchip Graphics Composer under the Plugins in the Project Graph.
    Figure 5-281. Microchip Graphics Composer
  2. 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.
New widgets can be dragged and dropped into the MGC screen. Widgets:
Events are disabled for new widgets by default, so they must be enabled if needed. Also, if an event is enabled, the event handler must be defined in the code otherwise the build will fail. See below for details about events.
  • 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:
If the fixed heaps are increased in the project settings, the code must be regenerated to reflect the changes in the code.
  • Events: Refer to Creating a Dynamic UI with Event Handling in Reference Documentation from Related Links.
Events can be enabled or disabled in MGC in the Event Manager under Project:
Events can also be enabled or disabled in the Object Editor when a widget is selected.
  • Event handlers for widgets and screen events are declared in the generated le_gen_screen_<screen name>.h file and must be implemented in user application code. For example, the main screen events are declared in the le_gen_screen_main.h file and the handlers are implemented in the app_Main.c file:
  • Images, fonts, and strings can be added and managed in their respective pages found under Asset:
MGC Assets Guide: Refer to Microchip Graphics Suite (MGS) Harmony Graphics Assets Guide in Reference Documentation from Related Links.
  • Color Schemes Guide: Refer to About the Schemes and Scheme Editor in Reference Documentation from Related Links.
The available schemes in the project can also be used.

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.

Below is an example of how the fixedHeaps can be optimized with this Coffee Maker GUI using Debug mode and breakpoints rather than printing out the fixedHeap usage report.
  • 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 in legato_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.
Once the down button is pressed, the program will break, and you can analyze the fixedHeaps array to see the max usage.
  • 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:
fixedHeaps[0] corresponds to LE_FIXEDHEAP_SIZE_16 in 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.h is 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;”

Unique Files

The following list of files were either edited or added to the project.

FileAdded or EditedNotes
app.cEditedMaintains app state machine. Added OSAL queue callbacks for trp service and a timer callback. Added to the initialization.
app.hEditedDefinitions and global variables
app_ble_handler.cEditedMaintain 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.hEditedGlobal variable definitions
app_trsps_handler.cEditedParses 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.hEditedGlobal variable definitions
default_design.zipAddedMGS composer design
app_macros.hAddedHolds macros for gfx library
app_Main.cAddedHolds GUI event handling and helper functions for the main screen
app_Main.hAddedDefinitions and global variables
app_Brewing.cAddedHolds GUI event handling and helper functions for the brewing screen
app_LowWater.cAddedHolds GUI event handling for the low water screen
app_Ready.cAddedHolds GUI event handling for the ready screen
app_Refill.cAddedHolds GUI event handling for the refill screen
app_Resume.cAddedHolds GUI event handling for the resume screen
app_Settings.cAddedHolds GUI event handling for the settings screen
app_Startup.cAddedHolds GUI event handling for the startup screen

Widgets within app_screen_main.c

The following table shows the widgets with their accompanying event handlers.

WidgetEvent handlerNotes
N/AThis 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.
  • event_LowWater_btnSettings_OnPressed(leButtonWidget* btn)
  • event_Main_btnSettings_OnPressed(leButtonWidget* btn)
  • event_Ready_btnSettings_OnPressed(leButtonWidget* btn)
  • event_Resume_btnSettings_OnPressed(leButtonWidget* btn)
Displays the settings screen.
  • event_Brewing_btnSettings_OnPressed(leButtonWidget* btn)
  • event_Refill_btnSettings_OnPressed(leButtonWidget* btn)
Toggles the is water low boolean variable. Simulates a low water alert and completing the refill.
  • event_Brewing_btnCancel_OnPressed(leButtonWidget* btn)
  • event_LowWater_btnCancel_OnPressed(leButtonWidget* btn)
  • event_Ready_btnCancel_OnPressed(leButtonWidget* btn)
  • event_Refill_btnCancel_OnPressed(leButtonWidget* btn)
  • event_Resume_btnCancel_OnPressed(leButtonWidget* btn)
  • event_Settings_btnCancel_OnPressed(leButtonWidget* btn)
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.
  • event_Settings_btnEnableAdv_OnPressed(leButtonWidget* btn)
  • event_Settings_btnEnableAdv_OnReleased(leButtonWidget* btn)
Enables or disables advertising.
N/ADisplays BT Status as “Connected” if a connection is being held or “Idle” if there is no connection being held.
  • event_Settings_btnThroughputTest_OnPressed(leButtonWidget* btn)
  • event_Settings_btnThroughputTest_OnReleased(leButtonWidget* btn)
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

When a device is connected successfully, the connection handle is captured to be used with data communication with the connected device. Additionally, a connected_flg will be set so the BT Status will change to “Connected” on the Settings screen and the BLE icon will change to blue on the Main screen. This event is BLE_GAP_EVT_CONNECTED in app_ble_handler.c.

When a disconnect occurs, the connected_flg is cleared.

To handle the transmission of data for sending responses and notifications to the connected device, APP_MSG_COMMAND_RSP_CB is defined in the APP_MsgId_T enum in app.h.
In addition, a service task calls the APP_CommandRSPCBHandler() in app.c.
The 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.
When data is received from the central device, 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.