The "GR-PEACH_Audio_Playback_7InchLCD_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

Dependencies:   GR-PEACH_video R_BSP TLV320_RBSP USBHost_custom

Fork of GR-PEACH_Audio_Playback_Sample by Renesas

Note

For a sample program of without LCD Board, please refer to GR-PEACH_Audio_Playback_Sample.

Introduction

The "GR-PEACH_Audio_Playback_7InchLCD_Sample" is a sample code that can provides high-resolution audio playback of FLAC format files. It also allows the user to audio-playback control functions such as play, pause, and stop by manipulating key switches.

1. Overview of the Sample Code

1.1 Software Block Diagram

Figure 1.1 shows the software block diagram.

/media/uploads/1050186/lcd_figure1_1.png

1.2 Pin Definitions

Table 1.1 shows the pins used in this sample code.

/media/uploads/1050186/lcd_table1_1.png

2. Sample Code Operating Environment

In order to operate this sample code, GR-PEACH, Audio Camera Shield and 7.1 inch LCD Shield must be needed. For details on Audio Camera Shield and 7.1 inch LCD Shield, please refer to the following links, respectively:

In this section, it is described that how board is configured and to control audio playback via command line and touch screen.

2.1 Operating Environment

Figure 2.1 shows the overview of the operating environment for this sample code.

/media/uploads/1050186/lcd_figure2_1.png

Figure 2.2 and 2.3 show how to configure GR-PEACH, Audio Camera Shield and 7.1 inch LCD shield when using USB0 and USB1, respectively.

/media/uploads/1050186/lcd_figure2_2.png /media/uploads/1050186/lcd_figure2_3.png

Table 2.1 lists the overview of Graphical User Interface (GUI) of this sample code.

/media/uploads/1050186/lcd_table2_1.png

2.2 List of User Operations

Table 2.2 shows the relationship among Audio Playback, Command Line and Onboard Switch.

/media/uploads/1050186/lcd_table2_2.png

3. Function Outline

Table 3.1, 3.2 and 3.3 shows the overview of functions implemented in this sample code.

/media/uploads/1050186/lcd_table3_1.png /media/uploads/1050186/lcd_table3_2.png /media/uploads/1050186/lcd_table3_3.png /media/uploads/1050186/lcd_figure3_1.png

3.1 Playback Control

This sample program supports the operation "play", "pause", "stop", "play next song" and "play previous song".

3.2 Trick Play Control

In order to enable/disable Repeat Mode, user need to type "repeat" on command line or click the corresponding icon shown in Table 2.2. By derault, Repeat Mode is enabled. When Repeat Mode is enabled, the first song is played back after the playback of the last song is finished. Otherwise, the playback is shopped when finishing to play back the last song.

3.3 How to see Song Information

The information of the song being played back can be seen by typing playinfo on command line. Table 3.4 lists the items user can see on the terminal.

/media/uploads/dkato/audioplayback_table3_4.png

3.4 How to analyze the folder structure in USB stick

In this sample code, the folder structure in USB stick is analyzed in the breadth-first order. Table 3.5 shows how the files in USB stick are numbered.

/media/uploads/dkato/audioplayback_table3_5.png

4.Others

4.1 Serial Communication Setting

With respect to the default serial communication related setting on mbed, please refer to the follwing link:
https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
Please set up the terminal software you would like to use on your PC in consideration of the above. For example, 9600 should be specified for the baud rate on the terminal in order to control this sample via command line.

4.2 Necessary modification when using GCC ARM Embedded

If you would like to use GCC ARM Embedded, you must revise the following linker script incorporated in mbed OS 5 package as follows:

  • Linker Script to be modified
    $(PROJECT_ROOT)/mbed-os/targets/TARGET_RENESAS/TARGET_RZ_A1H/device/TOOLCHAIN_GCC_ARM/RZA1H.ld

    Please note that $(PROJECT_ROOT) in the above denotes the root directory of this sample code

  • Before Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00700000
  RAM_NC (rwx) : ORIGIN = 0x20900000, LENGTH = 0x00100000
}
(snip)
  • After Modification

RZA1H.ld

/* Linker script for mbed RZ_A1H */

/* Linker script to configure memory regions. */
MEMORY
{
  ROM   (rx)  : ORIGIN = 0x00000000, LENGTH = 0x02000000
  BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00004000 
  SFLASH (rx) : ORIGIN = 0x18004000, LENGTH = 0x07FFC000 
  L_TTB (rw)  : ORIGIN = 0x20000000, LENGTH = 0x00004000 
  RAM (rwx) : ORIGIN = 0x20020000, LENGTH = 0x00180000
  RAM_NC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x00680000
}
(snip)
Revision:
4:2672de88a46b
Parent:
2:d9fca8cd7f03
--- a/display/display.cpp	Mon Dec 07 05:08:45 2015 +0000
+++ b/display/display.cpp	Mon Jan 25 02:41:36 2016 +0000
@@ -26,13 +26,17 @@
 #include "misratypes.h"
 #include "display.h"
 #include "disp_term.h"
+#include "disp_tft.h"
+#include "key.h"
+#include "audio_out.h"
 
 /*--- Macro definition of mbed-rtos mail ---*/
-#define MAIL_QUEUE_SIZE             (12)    /* Queue size */
+#define MAIL_QUEUE_SIZE             (32)    /* Queue size */
 #define MAIL_PARAM_NUM              (64)    /* Elements number of mail parameter array */
 
 /* dsp_mail_t */
 /* mail_id = DSP_MAILID_CYCLE_IND : No parameter */
+#define MAIL_CYCLEIND_PARAM         (0)     /* No mail parameter to be used */
 
 /* mail_id = DSP_MAILID_CMD_STR */
 #define MAIL_CMDSTR_FIN_FLG         (0)     /* Completion status of the input by the command-line */
@@ -73,10 +77,25 @@
 /* mail_id = DSP_MAILID_HELP */
 #define MAIL_HELP_PARAM             (0)     /* No mail parameter to be used */
 
+/* mail_id = DSP_MAILID_DISP_MODE */
+#define MAIL_DISPMODE_MODE          (0)     /* Display mode */
+
+/* mail_id = DSP_MAILID_TFT_KEY */
+#define MAIL_TFTKEY_KEYCODE         (0)     /* Key code */
+
+/* mail_id = DSP_MAILID_AUDIO_FIN */
+#define MAIL_AUDIOFIN_PARAM         (0)     /* No mail parameter to be used */
+
+/* mail_id = DSP_MAILID_PLAY_STAT */
+#define MAIL_PLAYSTAT_STAT          (0)     /* Playback status */
+
 #define MAIL_PARAM_NON              (0u)    /* Value of unused element of mail parameter array */
 
+
 #define BYTE_SHIFT                  (8u)
 #define WORD_SHIFT                  (16u)
+#define AUDIO_DATA_SHIFT            (24u)
+#define PROC_CNT_AUDIO_GET          (6u)    /* Counter for 100ms period */
 
 /*--- User defined types of mbed-rtos mail ---*/
 typedef struct {
@@ -98,6 +117,8 @@
 static bool recv_mail(dsp_mail_t * const p_data);
 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl);
 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl);
+static void audio_data_callback( const bool result, int16_t * const p_buf, 
+                const uint32_t buf_num, const int32_t * const p_audio, const uint32_t audio_num);
 
 void dsp_thread(void const *argument)
 {
@@ -109,11 +130,14 @@
 
     init_ctrl_data(&dsp_ctrl);
     dsp_init_term();
+    dsp_init_tft(&dsp_ctrl.tft);
     while (1) {
         result = recv_mail(&recv_data);
         if (result == true) {
             result = decode_mail(&recv_data, &dsp_ctrl);
             if (result == true) {
+                /* Executes main function of tft output module */
+                dsp_output_tft(recv_data.mail_id, &dsp_ctrl.com, &dsp_ctrl.tft);
                 /* Executes main function of terminal output module */
                 dsp_output_term(recv_data.mail_id, &dsp_ctrl.com, &dsp_ctrl.trm);
                 /* Clears the one shot data */
@@ -123,6 +147,18 @@
     }
 }
 
+bool dsp_notify_cycle_time(void)
+{
+    bool            ret;
+    dsp_mail_t      data;
+
+    data.mail_id = DSP_MAILID_CYCLE_IND;
+    data.param[MAIL_CYCLEIND_PARAM] = (uint8_t)MAIL_PARAM_NON;
+    ret = send_mail(&data);
+
+    return ret;
+}
+
 bool dsp_notify_play_time(const SYS_PlayStat play_stat, const uint32_t file_no, 
                             const uint32_t play_time, const uint32_t total_time)
 {
@@ -231,6 +267,51 @@
     return ret;
 }
 
+bool dsp_notify_disp_mode(const uint32_t disp_mode)
+{
+    bool            ret = false;
+    dsp_mail_t      data;
+
+    data.mail_id                   = DSP_MAILID_DISP_MODE;
+    data.param[MAIL_DISPMODE_MODE] = (uint8_t)disp_mode;
+    ret = send_mail(&data);
+
+    return ret;
+}
+
+bool dsp_notify_tft_key(const SYS_KeyCode key_code)
+{
+    bool            ret = false;
+    dsp_mail_t      data;
+
+    data.mail_id                    = DSP_MAILID_TFT_KEY;
+    data.param[MAIL_TFTKEY_KEYCODE] = (uint8_t)key_code;
+    ret = send_mail(&data);
+
+    return ret;
+}
+
+bool dsp_notify_play_status(const SYS_PlayStat play_stat)
+{
+    bool            ret;
+    dsp_mail_t      data;
+
+    data.mail_id                   = DSP_MAILID_PLAY_STAT;
+    data.param[MAIL_PLAYSTAT_STAT] = (uint8_t)play_stat;
+    ret = send_mail(&data);
+
+    return ret;
+}
+
+SYS_KeyCode dsp_convert_key(const uint32_t disp_mode, const uint32_t pos_x, const uint32_t pos_y)
+{
+    SYS_KeyCode     ret;
+
+    ret = dsp_convert_key_tft(disp_mode, pos_x, pos_y);
+
+    return ret;
+}
+
 /** initialises the control data of the display module
  *
  *  @param p_ctrl Pointer to control data of display module.
@@ -239,7 +320,7 @@
 {
     if (p_ctrl != NULL) {
         /* Initialises the common data of the display module. */
-        p_ctrl->com.disp_mode       = 0u;
+        p_ctrl->com.disp_mode       = DSP_DISPMODE_1;
         p_ctrl->com.play_stat       = SYS_PLAYSTAT_STOP;
         p_ctrl->com.track_id        = 0u;
         p_ctrl->com.play_time       = 0u;
@@ -249,6 +330,7 @@
         p_ctrl->com.repeat_mode     = false;
         p_ctrl->com.file_name[0]    = '\0';
         p_ctrl->com.dspl_str[0]     = '\0';
+        p_ctrl->com.edge_track_change = false;
         
         /* Initialises the data of the terminal output module. */
         p_ctrl->trm.edge_fin_inpt = false;
@@ -326,11 +408,23 @@
 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl)
 {
     bool            ret = false;
-    
+    dsp_audio_t     *p_aud;
+    SYS_PlayStat    cur_stat;
+    uint32_t        trk_id;
+    uint32_t        cur_time;
+
+
     if ((p_mail != NULL) && (p_ctrl != NULL)) {
         /* Decodes the received mail */
         switch(p_mail->mail_id) {
             case DSP_MAILID_CYCLE_IND:       /* Cyclic notice */
+                p_aud = &p_ctrl->tft.audio_data;
+                p_aud->req_cyc_cnt++;
+                if (p_aud->req_cyc_cnt >= PROC_CNT_AUDIO_GET) {
+                    p_aud->req_cyc_cnt = 0u;
+                    (void) aud_get_audio_data(&audio_data_callback, &p_aud->req_buf[0], 
+                                        sizeof(p_aud->req_buf)/sizeof(p_aud->req_buf[0]));
+                }
                 ret = true;
                 break;
             case DSP_MAILID_CMD_STR:         /* Input character string by the command-line */
@@ -354,20 +448,39 @@
                 break;
             case DSP_MAILID_PLAY_TIME:       /* Playback time */
                 ret = true;
-                p_ctrl->com.play_stat   = (SYS_PlayStat)p_mail->param[MAIL_PLAYTIME_STAT];
-                p_ctrl->com.track_id    = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_H] << BYTE_SHIFT) |
+                cur_stat = (SYS_PlayStat)p_mail->param[MAIL_PLAYTIME_STAT];
+                if ((cur_stat != p_ctrl->com.play_stat) && (cur_stat == SYS_PLAYSTAT_STOP)) {
+                    p_ctrl->com.edge_track_change = true;
+                }
+                p_ctrl->com.play_stat = cur_stat;
+                trk_id = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_H] << BYTE_SHIFT) |
                                             (uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_L]);
-                p_ctrl->com.play_time   = (((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_H] << WORD_SHIFT) |
-                                           ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_M] << BYTE_SHIFT) |
-                                           ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_L]));
+                if (trk_id != p_ctrl->com.track_id) {
+                    p_ctrl->com.edge_track_change = true;
+                    p_ctrl->com.track_id = trk_id;
+                    /* Clears the music information about the previous track. */
+                    p_ctrl->com.samp_freq = 0u;
+                    p_ctrl->com.channel = 0u;
+                }
+                cur_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_H] << WORD_SHIFT) |
+                            ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_M] << BYTE_SHIFT) |
+                            ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_L]));
+                if (p_ctrl->com.play_time != cur_time) {
+                    p_ctrl->com.play_time = cur_time;
+                    p_ctrl->tft.audio_data.m3_target_cnt = cur_time * DSP_TFT_M3_AUDIO_SAMPLE_PER_SEC;
+                }
                 p_ctrl->com.total_time  = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_H] << WORD_SHIFT) |
                                            ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_M] << BYTE_SHIFT) |
                                            ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_L]));
                 break;
             case DSP_MAILID_PLAY_INFO:       /* Music information */
                 ret = true;
-                p_ctrl->com.track_id    = (((uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_H] << BYTE_SHIFT) |
-                                            (uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_L]);
+                trk_id = (((uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_H] << BYTE_SHIFT) |
+                                           (uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_L]);
+                if (trk_id != p_ctrl->com.track_id) {
+                    p_ctrl->com.edge_track_change = true;
+                    p_ctrl->com.track_id = trk_id;
+                }
                 p_ctrl->com.samp_freq   = (((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_H] << WORD_SHIFT) |
                                            ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_M] << BYTE_SHIFT) |
                                            ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_L]));
@@ -391,6 +504,26 @@
             case DSP_MAILID_HELP:            /* Help information */
                 ret = true; 
                 break;
+            case DSP_MAILID_DISP_MODE:       /* Display mode */
+                ret = true;
+                p_ctrl->com.disp_mode = p_mail->param[MAIL_DISPMODE_MODE];
+                (void) key_notify_disp_mode(p_ctrl->com.disp_mode);
+                break;
+            case DSP_MAILID_TFT_KEY:         /* TFT key code */
+                ret = true;
+                p_ctrl->tft.key_code = (SYS_KeyCode)p_mail->param[MAIL_TFTKEY_KEYCODE];
+                break;
+            case DSP_MAILID_AUDIO_FIN:       /* Completion of audio data acquisition. */
+                ret = true;
+                break;
+            case DSP_MAILID_PLAY_STAT:       /* Playback status */
+                ret = true;
+                cur_stat = (SYS_PlayStat)p_mail->param[MAIL_PLAYSTAT_STAT];
+                if ((cur_stat != p_ctrl->com.play_stat) && (cur_stat == SYS_PLAYSTAT_STOP)) {
+                    p_ctrl->com.edge_track_change = true;
+                }
+                p_ctrl->com.play_stat = cur_stat;
+                break;
             default:
                 /* Unexpected cases : mail id was illegal. */
                 ret = false;
@@ -412,6 +545,25 @@
             p_ctrl->trm.edge_fin_inpt = false;
             p_ctrl->trm.inpt_str[0] = '\0';
         }
+        p_ctrl->com.edge_track_change = false;
     }
     return;
 }
+
+static void audio_data_callback( const bool result, int16_t * const p_buf, 
+                const uint32_t buf_num, const int32_t * const p_audio, const uint32_t audio_num)
+{
+    uint32_t        i;
+    dsp_mail_t      data;
+
+    if ((p_buf != NULL) && (p_audio != NULL)) {
+        if ((result == true) && (buf_num > 0u) && (audio_num >= buf_num)) {
+            for (i = 0; i < buf_num; i++) {
+                p_buf[i] = (int16_t)(p_audio[i] >> AUDIO_DATA_SHIFT);
+            }
+        }
+    }
+    data.mail_id = DSP_MAILID_AUDIO_FIN;
+    data.param[MAIL_AUDIOFIN_PARAM] = (uint8_t)MAIL_PARAM_NON;
+    (void) send_mail(&data);
+}