USB Audio Speaker Tutorial: Step 4

Step 4.1: Rename the Screen Name

1

Open MHGC. To do this, expand theHarmony Framework Configuration > Graphics Library > Harmony Graphics Library selection tree and check theUse Graphics Library? box. Click theExecute button beside Create a Design With MPLAB Harmony Graphics Composer.

2

Find theGraphics Composer Management tab in the bottom-left pane and double-click onScreen1 to change it. Delete Screen1 and then enter "MchpMainScreen".

You are not changing any of the properties of the screen, so keep the screen properties shown in theGraphics Composer Properties tab in the top-right pane.

image_35.png

Step 4.2: Import Images and Fonts (Assets)

  • Images:
    • The Microchip logo will be applied to theLogoImage primitive object.
    • An image of a speaker will be applied to theSpeakerImage primitive object.
    • Two images will be applied to theVolButton widget, one for mute off (play) and one for mute on.
  • System Font:
    • Arial (14) for ASCII numbers 32 to 127. This will be used for multiple schemes in the design.

1

Copy theIcons folder from this folder:
apps/training/middleware/usb_speaker/usb_speaker_lab/dev_files
to this one:
apps/training/middleware/dev/usb_speaker/usb_speaker_lab.

2

In the bottom-left pane, in theGraphics Composer Management tab, click on theAssets sub tab.
Import the following assets:

a

MCHP_LOGO.bmp,
speaker_image.bmp,
AudioMute16_2.bmp, and
AudioPlay16_2.bmp from this folder,
apps/training/middleware/dev/usb_speaker/usb_speaker_lab/Icons.

image_37.png

b

ImportSystem Font Arial 14pt from 32 ASCII to 127 ASCII.

image_38.png

Click onEdit Import Ranges and select the required character range. This is an important feature that enables you to import only the characters you need, thereby limiting the amount of memory needed to store the font.

  • Start Index indicates the starting ASCII value of the character.
  • End Index indicates the last ASCII value of the character.

Alternatively, the range can be provided by Start Character and End Character.

image_39.png
image_39_1.png

Step 4.3: Create Schemes (assign standard colors and fonts)

Create schemes to standardize the look and feel (fonts, colors, styles) of the user interface.

  • VolSliderScheme
    • Applied to VolSlider (see "Add Widget Objects" step below).
  • VolButtonScheme
    • Applied to VolButton.

1

In the bottom-left pane, in theGraphics Composer Management tab, click on theSchemes sub tab. A default scheme is present.

2

Create the following custom schemes by clicking the buttonCreate.

image_40.png
image_41.png
image_42.png

Step 4.4: Add Primitive Objects (rectangle, image, text)

Design the following primitive objects:

1

BgRectangle:

a

In the Graphics Composer Tool Box (top-left pane), under thePrimitives group, left-click and dragRectangle onto theGraphic Composer Screen.

b

In theGraphics Composer Properties tab (top-right pane), observe the properties of thisRectangle.

image_43.png

c

Modify these properties as shown.

image_44.png

d

The screen will now look like this:

image_45.png

2

LogoImage:

a

In the Graphics Composer Tool Box (top-left pane), under thePrimitives group, left-click and dragImage onto theGraphic Composer Screen.

b

Modify the properties of the image through theGraphics Composer Properties as follows:

image_46.png

c

The screen will now look like this:

image_47.png

3

AppNameText:

a

In the Graphics Composer Tool Box, under thePrimitives group, left-click and dragText onto theGraphic Composer Screen.

b

Modify the properties of the text through theGraphics Composer Properties as follows:

image_48.png

c

The screen will now look like this:

image_49.png

4

SpeakerImage:

a

In the Graphics Composer Tool Box (top-left pane), under thePrimitives group, left-click and dragImage onto theGraphic Composer Screen.

b

Modify the properties of the image through theGraphics Composer Properties as follows:

image_50.png

c

The screen will now look like this:

image_51.png

5

SamplingFrequencyText:

a

In the Graphics Composer Tool Box, under thePrimitives group, left-click and dragText onto theGraphic Composer Screen.

b

Modify the properties of the text through theGraphics Composer Properties as follows:

image_52.png

c

The screen will now look like this:

image_53.png

6

BitRateText:

a

In the Graphics Composer Tool Box, under thePrimitives group, left-click and dragText onto theGraphic Composer Screen.

b

Modify the properties of the text through theGraphics Composer Properties as follows:

image_54.png

c

The screen will now look like this:

image_55.png

Step 4.5: Add Widget Objects (list-box, buttons, slider)

Design the following widgets:

1

VolSlider

a

In the Graphics Composer Tool Box, under theWidgets group, left-click and dragSlider onto theGraphic Composer Screen.

b

Modify the properties of the slider in theGraphics Composer Properties window as follows:

image_58.png

c

Notice that the slider eventsIncremented andDecremented are checked. Click on the **browse button ** (ellipsis found beside the check boxes) to add a custom action to the slider events.

d

When the "browse button" is clicked, an Event Editor window will open. Click on theAdd button to add an action to the sliderIncremented event.

image_60.png

e

In theAction window, SelectType of action asCustom. Rename the action toCustomAction. Copy the following code into theCustom Action Definition window.

image_61.png

The custom action increments the audio volume based on the position of the volume slider.

f

Similarly, add the following code to theDecremented event of the slider.

image_63.png

The custom action decrements the audio volume based on the position of the volume slider.

g

The screen will now look like this:

image_59.png

2

VolButton:

a

In the Graphics Composer Tool Box, under theWidgets group, left-click and dragButton onto theGraphic Composer Screen.

b

Modify the properties of the button in theGraphics Composer Properties pane as shown in the following image:

image_64.png

c

Notice that the button eventsPressed andReleased are checked. Also, notice that the button has enabled theToggle option. This option allows the button to be used as an ON/OFF button. Also, the default state is specified as "Pressed". The Pressed state corresponds to Mute Off. And release state corresponds to Mute On. This links the images with the appropriate Pressed and Released states.
Click on thebrowse button to add a custom action to the button events.

d

In the Action window, SelectType of action asCustom. Rename the action toCustomAction. Copy the following code into theCustom Action Definition window for thePressed event.

image_67.png

Copy the following code for the Released event.

image_69.png

e

The screen will now look like this:

image_65.png

f

Verify that the Graphics Library is configured as follows by expanding theHarmony Framework Configuration > Graphics Library > Harmony Graphics Library > Use Graphics Library? selection tree.

image_70.png

Step 4.6: Configure the Graphics display and Graphics Touch Driver

Enable the touch control feature of the graphics display on the MEB II board.

1

In MHC'sOptions tab, expand theHarmony Framework Configuration > Drivers > Graphics Displays > Use Graphics Display? selection tree. Notice the display has been correctly selected for you (MEB II uses a 4.3 inch, WQVGA display by NewHaven).

2

ExpandGraphics Displays > Display Settings. You will keep all settings except "Requires Calibration Points?".

The Display Settings have values specific to the display (4.3 inch, WQVGA display by NewHaven). These include horizontal and vertical timing parameters and others. For details, refer to the display datasheet.

3

Expand "Requires Calibration Points?" and check the box besideTouchscreen Resistive Swap. This enables the touch screen.

image_71.png

Step 4.7: Enable Touchscreen Control Using I2C

An instance (Instance 0) of the I2C driver is already configured for the control interface of the audio CODEC. In this step, you will take advantage of this existing dynamic harmony driver, by adding a second I2C driver instance (Instance 1). You will configure this new instance to communicate with the display Touch driver (MTCH6301).

1

Expand theHarmony Framework Configuration > Drivers > Touch > MTCH6301 > Use the MTCH6301 Driver? selection tree.

2

Keep all selections except theI2C driver module index. Change the I2C driver module index toDRV_I2C_INDEX_1. I2C driver instance 1 is used for the touch driver.

image_72.png

3

Verify/Set the I/O pins used by Touch driver using the Graphical Pin Manager.

The touch driver uses PIC32 external interrupts source 1 for touch events. Select MHC'sPin Diagram tab and in the lower pane, select MHC's "Pin Table" tab.

Map the "External Interrupt 1" signal to pin "RPE8" as shown in this image. (For schematic, refer to theMEB II User’s Guide).

image_73.png

4

Add a new client and driver instance for the existing I2C driver.

In a previous step, you created a Dynamic I2C driver and created a client for this driver. You also configured an I2C driver instance (I2C Driver Instance 0) for this client. This client and instance are used by the AK4953 audio CODEC.

In this step, you will add another client and instance (I2C Driver Instance 1) for this driver for the display Touch driver (MTCH6301).

Expand theHarmony Framework Configuration > Drivers > I2C > Use I2C Driver? selection tree.

a

Modify "Number of I2C Driver Clients" and "Number of I2C Driver Instances" to2.

b

You configured "I2C Driver Instance 0" in a previous step. Just verify "Use Bit Bang I2C Implementation" is still unchecked.

c

ExpandI2C Driver Instance 1, and make sure "Use Bit Bang I2C Implementation?" is unchecked. Since you are using the PIC32 I2C peripherals, you do not want to use the bit-banged driver implementation.

d

Retain "I2C_ID_1" as theI2C Module ID.

"I2C_ID_1" refers to the PIC32 I2C1 peripheral (using pins SCL1 & SDA1). These pins are connected to the display touch controller on the MEB II board.

e

Retain default value "DRV_I2C_MODE_MASTER" asOperation Mode. The PIC32 I2C module 1 will be the master and the Touch MTCH6301 interface will be the slave.

f

Change value for "Master Interrupt Priority" and "Master Interrupt Sub-priority" asINT_PRIORITY_LEVEL4 andINT_SUBPRIORITY_LEVEL0 respectively. Lower priority for touch events is OK as this will not be occurring very frequently.

g

Change value for "Error Interrupt Priority" and "Error Interrupt Sub-priority" asINT_PRIORITY_LEVEL4 andINT_SUBPRIORITY_LEVEL0 respectively.

h

The "Baud Rate generator clock" is configured for 100 MHz. This is derived from the Peripheral bus 2 clock frequency generated from the 198 MHz system clock.

i

Retain the default value of50 KHz for "I2C CLOCK FREQUENCY".

j

Retain theSlew Rate Control as unchecked. This function enables the I2C module to use high-frequency signaling, allowing it to use the 400 kHz and 1 MHz signaling rates.

k

Retain the default value ofSYS_MODULE_POWER_RUN_FULL for "Power State". You will want to run the I2C module in normal power mode.

image_74.png

l

Verify the I/O Pins used by the I2C module using the Graphical Pin Manager. Click on MHC's "Pin Diagram" tab, and in MHC's lower pane, click on the “Pin Table” tab.

The I2C1 has dedicated pins for SCL1 and SDA1 signals. These pins are hardcoded and configured by the I2C driver.

image_75.png

Step 4.8: Enable the Graphics Touch System Service

The Harmony touch display driver is used by the Harmony Touch System service. Expand theHarmony Framework Configuration > System Services > Touch selection tree and check theUse Touch System Service box.

image_76.png


Next Step >