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)
Committer:
dkato
Date:
Fri Oct 16 04:28:07 2015 +0000
Revision:
0:ee40da884cfc
Child:
2:d9fca8cd7f03
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:ee40da884cfc 1 /*******************************************************************************
dkato 0:ee40da884cfc 2 * DISCLAIMER
dkato 0:ee40da884cfc 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:ee40da884cfc 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:ee40da884cfc 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:ee40da884cfc 6 * all applicable laws, including copyright laws.
dkato 0:ee40da884cfc 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:ee40da884cfc 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:ee40da884cfc 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:ee40da884cfc 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:ee40da884cfc 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:ee40da884cfc 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:ee40da884cfc 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:ee40da884cfc 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:ee40da884cfc 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:ee40da884cfc 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:ee40da884cfc 17 * and to discontinue the availability of this software. By using this software,
dkato 0:ee40da884cfc 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:ee40da884cfc 19 * following link:
dkato 0:ee40da884cfc 20 * http://www.renesas.com/disclaimer*
dkato 0:ee40da884cfc 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:ee40da884cfc 22 *******************************************************************************/
dkato 0:ee40da884cfc 23
dkato 0:ee40da884cfc 24 #include "mbed.h"
dkato 0:ee40da884cfc 25 #include "rtos.h"
dkato 0:ee40da884cfc 26 #include "misratypes.h"
dkato 0:ee40da884cfc 27 #include "display.h"
dkato 0:ee40da884cfc 28 #include "disp_term.h"
dkato 0:ee40da884cfc 29
dkato 0:ee40da884cfc 30 /*--- Macro definition of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 31 #define MAIL_QUEUE_SIZE (12) /* Queue size */
dkato 0:ee40da884cfc 32 #define MAIL_PARAM_NUM (64) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 33
dkato 0:ee40da884cfc 34 /* dsp_mail_t */
dkato 0:ee40da884cfc 35 /* mail_id = DSP_MAILID_CYCLE_IND : No parameter */
dkato 0:ee40da884cfc 36
dkato 0:ee40da884cfc 37 /* mail_id = DSP_MAILID_CMD_STR */
dkato 0:ee40da884cfc 38 #define MAIL_CMDSTR_FIN_FLG (0) /* Completion status of the input by the command-line */
dkato 0:ee40da884cfc 39 #define MAIL_CMDSTR_STR_START (1) /* Start position of input string by the command-line */
dkato 0:ee40da884cfc 40 #define MAIL_CMDSTR_STR_SIZE (DSP_CMD_INPT_STR_MAX_LEN)
dkato 0:ee40da884cfc 41 /* Size of input string by the command-line */
dkato 0:ee40da884cfc 42
dkato 0:ee40da884cfc 43 /* mail_id = DSP_MAILID_PRINT_STR */
dkato 0:ee40da884cfc 44 #define MAIL_DISPSTR_STR_START (0) /* Start position of display string */
dkato 0:ee40da884cfc 45 #define MAIL_DISPSTR_STR_SIZE (DSP_DISP_STR_MAX_LEN) /* Size of display string */
dkato 0:ee40da884cfc 46
dkato 0:ee40da884cfc 47 /* mail_id = DSP_MAILID_PLAY_TIME */
dkato 0:ee40da884cfc 48 #define MAIL_PLAYTIME_STAT (0) /* Playback status */
dkato 0:ee40da884cfc 49 #define MAIL_PLAYTIME_TRACK_L (1) /* Track number */
dkato 0:ee40da884cfc 50 #define MAIL_PLAYTIME_TRACK_H (2) /* Track number */
dkato 0:ee40da884cfc 51 #define MAIL_PLAYTIME_PLAYTIME_L (3) /* Playback time */
dkato 0:ee40da884cfc 52 #define MAIL_PLAYTIME_PLAYTIME_M (4) /* Playback time */
dkato 0:ee40da884cfc 53 #define MAIL_PLAYTIME_PLAYTIME_H (5) /* Playback time */
dkato 0:ee40da884cfc 54 #define MAIL_PLAYTIME_TOTALTIME_L (6) /* Total playback time */
dkato 0:ee40da884cfc 55 #define MAIL_PLAYTIME_TOTALTIME_M (7) /* Total playback time */
dkato 0:ee40da884cfc 56 #define MAIL_PLAYTIME_TOTALTIME_H (8) /* Total playback time */
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 /* mail_id = DSP_MAILID_PLAY_INFO */
dkato 0:ee40da884cfc 59 #define MAIL_PLAYINFO_TRACK_L (0) /* Track number */
dkato 0:ee40da884cfc 60 #define MAIL_PLAYINFO_TRACK_H (1) /* Track number */
dkato 0:ee40da884cfc 61 #define MAIL_PLAYINFO_SAMPFREQ_L (2) /* Sampling frequency */
dkato 0:ee40da884cfc 62 #define MAIL_PLAYINFO_SAMPFREQ_M (3) /* Sampling frequency */
dkato 0:ee40da884cfc 63 #define MAIL_PLAYINFO_SAMPFREQ_H (4) /* Sampling frequency */
dkato 0:ee40da884cfc 64 #define MAIL_PLAYINFO_CHANNEL (5) /* Channel structure */
dkato 0:ee40da884cfc 65
dkato 0:ee40da884cfc 66 /* mail_id = DSP_MAILID_PLAY_MODE */
dkato 0:ee40da884cfc 67 #define MAIL_PLAYMODE_REPEAT (0) /* Repeat mode */
dkato 0:ee40da884cfc 68
dkato 0:ee40da884cfc 69 /* mail_id = DSP_MAILID_FILE_NAME */
dkato 0:ee40da884cfc 70 #define MAIL_FILENAME_STR_START (0) /* Start position of file name string */
dkato 0:ee40da884cfc 71 #define MAIL_FILENAME_STR_SIZE (64) /* Size of file name string */
dkato 0:ee40da884cfc 72
dkato 0:ee40da884cfc 73 #define BYTE_SHIFT (8u)
dkato 0:ee40da884cfc 74 #define WORD_SHIFT (16u)
dkato 0:ee40da884cfc 75
dkato 0:ee40da884cfc 76 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 77 typedef struct {
dkato 0:ee40da884cfc 78 DSP_MAIL_ID mail_id;
dkato 0:ee40da884cfc 79 uint8_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 80 } dsp_mail_t;
dkato 0:ee40da884cfc 81
dkato 0:ee40da884cfc 82 /* Control data of display thread */
dkato 0:ee40da884cfc 83 typedef struct {
dkato 0:ee40da884cfc 84 dsp_com_ctrl_t com; /* Common data */
dkato 0:ee40da884cfc 85 dsp_trm_ctrl_t trm; /* Terminal output module only */
dkato 0:ee40da884cfc 86 dsp_tft_ctrl_t tft; /* TFT module only */
dkato 0:ee40da884cfc 87 } dsp_ctrl_t;
dkato 0:ee40da884cfc 88
dkato 0:ee40da884cfc 89 static Mail<dsp_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 90
dkato 0:ee40da884cfc 91 static void init_ctrl_data(dsp_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 92 static bool send_mail(const dsp_mail_t * const p_data);
dkato 0:ee40da884cfc 93 static bool recv_mail(dsp_mail_t * const p_data);
dkato 0:ee40da884cfc 94 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 95 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 96
dkato 0:ee40da884cfc 97 void dsp_thread(void const *argument)
dkato 0:ee40da884cfc 98 {
dkato 0:ee40da884cfc 99 dsp_mail_t recv_data;
dkato 0:ee40da884cfc 100 bool result;
dkato 0:ee40da884cfc 101 static dsp_ctrl_t dsp_ctrl;
dkato 0:ee40da884cfc 102
dkato 0:ee40da884cfc 103 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 104
dkato 0:ee40da884cfc 105 init_ctrl_data(&dsp_ctrl);
dkato 0:ee40da884cfc 106 dsp_init_term();
dkato 0:ee40da884cfc 107 while (1) {
dkato 0:ee40da884cfc 108 result = recv_mail(&recv_data);
dkato 0:ee40da884cfc 109 if (result == true) {
dkato 0:ee40da884cfc 110 result = decode_mail(&recv_data, &dsp_ctrl);
dkato 0:ee40da884cfc 111 if (result == true) {
dkato 0:ee40da884cfc 112 /* Executes main function of terminal output module */
dkato 0:ee40da884cfc 113 dsp_output_term(recv_data.mail_id, &dsp_ctrl.com, &dsp_ctrl.trm);
dkato 0:ee40da884cfc 114 /* Clears the one shot data */
dkato 0:ee40da884cfc 115 clear_one_shot_data(&dsp_ctrl);
dkato 0:ee40da884cfc 116 }
dkato 0:ee40da884cfc 117 }
dkato 0:ee40da884cfc 118 }
dkato 0:ee40da884cfc 119 }
dkato 0:ee40da884cfc 120
dkato 0:ee40da884cfc 121 bool dsp_notify_play_time(const SYS_PlayStat play_stat, const uint32_t file_no,
dkato 0:ee40da884cfc 122 const uint32_t play_time, const uint32_t total_time)
dkato 0:ee40da884cfc 123 {
dkato 0:ee40da884cfc 124 bool ret;
dkato 0:ee40da884cfc 125 dsp_mail_t data;
dkato 0:ee40da884cfc 126
dkato 0:ee40da884cfc 127 data.mail_id = DSP_MAILID_PLAY_TIME;
dkato 0:ee40da884cfc 128 data.param[MAIL_PLAYTIME_STAT] = (uint8_t)play_stat;
dkato 0:ee40da884cfc 129 data.param[MAIL_PLAYTIME_TRACK_L] = (uint8_t)file_no;
dkato 0:ee40da884cfc 130 data.param[MAIL_PLAYTIME_TRACK_H] = (uint8_t)(file_no >> BYTE_SHIFT);
dkato 0:ee40da884cfc 131 data.param[MAIL_PLAYTIME_PLAYTIME_L] = (uint8_t)play_time;
dkato 0:ee40da884cfc 132 data.param[MAIL_PLAYTIME_PLAYTIME_M] = (uint8_t)(play_time >> BYTE_SHIFT);
dkato 0:ee40da884cfc 133 data.param[MAIL_PLAYTIME_PLAYTIME_H] = (uint8_t)(play_time >> WORD_SHIFT);
dkato 0:ee40da884cfc 134 data.param[MAIL_PLAYTIME_TOTALTIME_L] = (uint8_t)total_time;
dkato 0:ee40da884cfc 135 data.param[MAIL_PLAYTIME_TOTALTIME_M] = (uint8_t)(total_time >> BYTE_SHIFT);
dkato 0:ee40da884cfc 136 data.param[MAIL_PLAYTIME_TOTALTIME_H] = (uint8_t)(total_time >> WORD_SHIFT);
dkato 0:ee40da884cfc 137 ret = send_mail(&data);
dkato 0:ee40da884cfc 138
dkato 0:ee40da884cfc 139 return ret;
dkato 0:ee40da884cfc 140 }
dkato 0:ee40da884cfc 141
dkato 0:ee40da884cfc 142 bool dsp_notify_play_info(const uint32_t file_no,
dkato 0:ee40da884cfc 143 const uint32_t sample_freq, const uint32_t channel_num)
dkato 0:ee40da884cfc 144 {
dkato 0:ee40da884cfc 145 bool ret;
dkato 0:ee40da884cfc 146 dsp_mail_t data;
dkato 0:ee40da884cfc 147
dkato 0:ee40da884cfc 148 data.mail_id = DSP_MAILID_PLAY_INFO;
dkato 0:ee40da884cfc 149 data.param[MAIL_PLAYINFO_TRACK_L] = (uint8_t)file_no;
dkato 0:ee40da884cfc 150 data.param[MAIL_PLAYINFO_TRACK_H] = (uint8_t)(file_no >> BYTE_SHIFT);
dkato 0:ee40da884cfc 151 data.param[MAIL_PLAYINFO_SAMPFREQ_L] = (uint8_t)sample_freq;
dkato 0:ee40da884cfc 152 data.param[MAIL_PLAYINFO_SAMPFREQ_M] = (uint8_t)(sample_freq >> BYTE_SHIFT);
dkato 0:ee40da884cfc 153 data.param[MAIL_PLAYINFO_SAMPFREQ_H] = (uint8_t)(sample_freq >> WORD_SHIFT);
dkato 0:ee40da884cfc 154 data.param[MAIL_PLAYINFO_CHANNEL] = (uint8_t)channel_num;
dkato 0:ee40da884cfc 155 ret = send_mail(&data);
dkato 0:ee40da884cfc 156
dkato 0:ee40da884cfc 157 return ret;
dkato 0:ee40da884cfc 158 }
dkato 0:ee40da884cfc 159
dkato 0:ee40da884cfc 160 bool dsp_notify_play_mode(const bool rep_mode)
dkato 0:ee40da884cfc 161 {
dkato 0:ee40da884cfc 162 bool ret;
dkato 0:ee40da884cfc 163 dsp_mail_t data;
dkato 0:ee40da884cfc 164
dkato 0:ee40da884cfc 165 data.mail_id = DSP_MAILID_PLAY_MODE;
dkato 0:ee40da884cfc 166 data.param[MAIL_PLAYMODE_REPEAT] = (uint8_t)rep_mode;
dkato 0:ee40da884cfc 167 ret = send_mail(&data);
dkato 0:ee40da884cfc 168
dkato 0:ee40da884cfc 169 return ret;
dkato 0:ee40da884cfc 170 }
dkato 0:ee40da884cfc 171
dkato 0:ee40da884cfc 172 bool dsp_notify_file_name(const char_t * const p_str)
dkato 0:ee40da884cfc 173 {
dkato 0:ee40da884cfc 174 bool ret = false;
dkato 0:ee40da884cfc 175 dsp_mail_t data;
dkato 0:ee40da884cfc 176
dkato 0:ee40da884cfc 177 if (p_str != NULL) {
dkato 0:ee40da884cfc 178 data.mail_id = DSP_MAILID_FILE_NAME;
dkato 0:ee40da884cfc 179 (void) memcpy(&data.param[MAIL_FILENAME_STR_START], p_str, MAIL_FILENAME_STR_SIZE);
dkato 0:ee40da884cfc 180 data.param[(MAIL_FILENAME_STR_START + MAIL_FILENAME_STR_SIZE) - 1] = '\0';
dkato 0:ee40da884cfc 181 ret = send_mail(&data);
dkato 0:ee40da884cfc 182 }
dkato 0:ee40da884cfc 183
dkato 0:ee40da884cfc 184 return ret;
dkato 0:ee40da884cfc 185 }
dkato 0:ee40da884cfc 186
dkato 0:ee40da884cfc 187 bool dsp_notify_print_string(const char_t * const p_str)
dkato 0:ee40da884cfc 188 {
dkato 0:ee40da884cfc 189 bool ret = false;
dkato 0:ee40da884cfc 190 dsp_mail_t data;
dkato 0:ee40da884cfc 191
dkato 0:ee40da884cfc 192 if (p_str != NULL) {
dkato 0:ee40da884cfc 193 data.mail_id = DSP_MAILID_PRINT_STR;
dkato 0:ee40da884cfc 194 (void) memcpy(&data.param[MAIL_DISPSTR_STR_START], p_str, MAIL_DISPSTR_STR_SIZE);
dkato 0:ee40da884cfc 195 data.param[(MAIL_DISPSTR_STR_START + MAIL_DISPSTR_STR_SIZE) - 1] = '\0';
dkato 0:ee40da884cfc 196 ret = send_mail(&data);
dkato 0:ee40da884cfc 197 }
dkato 0:ee40da884cfc 198
dkato 0:ee40da884cfc 199 return ret;
dkato 0:ee40da884cfc 200 }
dkato 0:ee40da884cfc 201
dkato 0:ee40da884cfc 202 bool dsp_notify_input_string(const char_t * const p_str, const bool flag_fin)
dkato 0:ee40da884cfc 203 {
dkato 0:ee40da884cfc 204 bool ret = false;
dkato 0:ee40da884cfc 205 dsp_mail_t data;
dkato 0:ee40da884cfc 206
dkato 0:ee40da884cfc 207 if (p_str != NULL) {
dkato 0:ee40da884cfc 208 data.mail_id = DSP_MAILID_CMD_STR;
dkato 0:ee40da884cfc 209 data.param[MAIL_CMDSTR_FIN_FLG] = (uint8_t)flag_fin;
dkato 0:ee40da884cfc 210 (void) memcpy(&data.param[MAIL_CMDSTR_STR_START], p_str, MAIL_CMDSTR_STR_SIZE);
dkato 0:ee40da884cfc 211 data.param[(MAIL_CMDSTR_STR_START + MAIL_CMDSTR_STR_SIZE) - 1] = '\0';
dkato 0:ee40da884cfc 212 ret = send_mail(&data);
dkato 0:ee40da884cfc 213 }
dkato 0:ee40da884cfc 214
dkato 0:ee40da884cfc 215 return ret;
dkato 0:ee40da884cfc 216 }
dkato 0:ee40da884cfc 217
dkato 0:ee40da884cfc 218 /** initialises the control data of the display module
dkato 0:ee40da884cfc 219 *
dkato 0:ee40da884cfc 220 * @param p_ctrl Pointer to control data of display module.
dkato 0:ee40da884cfc 221 */
dkato 0:ee40da884cfc 222 static void init_ctrl_data(dsp_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 223 {
dkato 0:ee40da884cfc 224 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 225 /* Initialises the common data of the display module. */
dkato 0:ee40da884cfc 226 p_ctrl->com.disp_mode = 0u;
dkato 0:ee40da884cfc 227 p_ctrl->com.play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 228 p_ctrl->com.track_id = 0u;
dkato 0:ee40da884cfc 229 p_ctrl->com.play_time = 0u;
dkato 0:ee40da884cfc 230 p_ctrl->com.total_time = 0u;
dkato 0:ee40da884cfc 231 p_ctrl->com.samp_freq = 0u;
dkato 0:ee40da884cfc 232 p_ctrl->com.channel = 0u;
dkato 0:ee40da884cfc 233 p_ctrl->com.repeat_mode = false;
dkato 0:ee40da884cfc 234 p_ctrl->com.file_name[0] = '\0';
dkato 0:ee40da884cfc 235 p_ctrl->com.dspl_str[0] = '\0';
dkato 0:ee40da884cfc 236
dkato 0:ee40da884cfc 237 /* Initialises the data of the terminal output module. */
dkato 0:ee40da884cfc 238 p_ctrl->trm.edge_fin_inpt = false;
dkato 0:ee40da884cfc 239 p_ctrl->trm.inpt_str[0] = '\0';
dkato 0:ee40da884cfc 240
dkato 0:ee40da884cfc 241 /* Does not initialize the data of TFT module. */
dkato 0:ee40da884cfc 242 /* Initial values are different by the display mode. */
dkato 0:ee40da884cfc 243 /* Therefore the data of TFT module is initialized by tft_init_proc function. */
dkato 0:ee40da884cfc 244 }
dkato 0:ee40da884cfc 245 }
dkato 0:ee40da884cfc 246
dkato 0:ee40da884cfc 247 /** Sends the mail to main thread
dkato 0:ee40da884cfc 248 *
dkato 0:ee40da884cfc 249 * @param p_data Pointer to the structure of the data
dkato 0:ee40da884cfc 250 *
dkato 0:ee40da884cfc 251 * @returns
dkato 0:ee40da884cfc 252 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 253 */
dkato 0:ee40da884cfc 254 static bool send_mail(const dsp_mail_t * const p_data)
dkato 0:ee40da884cfc 255 {
dkato 0:ee40da884cfc 256 bool ret = false;
dkato 0:ee40da884cfc 257 osStatus stat;
dkato 0:ee40da884cfc 258 dsp_mail_t *p_mail;
dkato 0:ee40da884cfc 259
dkato 0:ee40da884cfc 260 if (p_data != NULL) {
dkato 0:ee40da884cfc 261 p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 262 if (p_mail != NULL) {
dkato 0:ee40da884cfc 263 *p_mail = *p_data;
dkato 0:ee40da884cfc 264 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 265 if (stat == osOK) {
dkato 0:ee40da884cfc 266 ret = true;
dkato 0:ee40da884cfc 267 } else {
dkato 0:ee40da884cfc 268 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 269 }
dkato 0:ee40da884cfc 270 }
dkato 0:ee40da884cfc 271 }
dkato 0:ee40da884cfc 272 return ret;
dkato 0:ee40da884cfc 273 }
dkato 0:ee40da884cfc 274
dkato 0:ee40da884cfc 275 /** Receives the mail to main thread
dkato 0:ee40da884cfc 276 *
dkato 0:ee40da884cfc 277 * @param p_data Pointer to the structure of the data
dkato 0:ee40da884cfc 278 *
dkato 0:ee40da884cfc 279 * @returns
dkato 0:ee40da884cfc 280 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 281 */
dkato 0:ee40da884cfc 282 static bool recv_mail(dsp_mail_t * const p_data)
dkato 0:ee40da884cfc 283 {
dkato 0:ee40da884cfc 284 bool ret = false;
dkato 0:ee40da884cfc 285 osEvent evt;
dkato 0:ee40da884cfc 286 dsp_mail_t *p_mail;
dkato 0:ee40da884cfc 287
dkato 0:ee40da884cfc 288 if (p_data != NULL) {
dkato 0:ee40da884cfc 289 evt = mail_box.get();
dkato 0:ee40da884cfc 290 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 291 p_mail = (dsp_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 292 if (p_mail != NULL) {
dkato 0:ee40da884cfc 293 *p_data = *p_mail;
dkato 0:ee40da884cfc 294 ret = true;
dkato 0:ee40da884cfc 295 }
dkato 0:ee40da884cfc 296 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 297 }
dkato 0:ee40da884cfc 298 }
dkato 0:ee40da884cfc 299 return ret;
dkato 0:ee40da884cfc 300 }
dkato 0:ee40da884cfc 301
dkato 0:ee40da884cfc 302 /** Decodes the display thread mail
dkato 0:ee40da884cfc 303 *
dkato 0:ee40da884cfc 304 * @param p_mail Pointer to the structure of the data
dkato 0:ee40da884cfc 305 * @param p_ctrl Pointer to control data of display module.
dkato 0:ee40da884cfc 306 *
dkato 0:ee40da884cfc 307 * @returns
dkato 0:ee40da884cfc 308 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 309 */
dkato 0:ee40da884cfc 310 static bool decode_mail(const dsp_mail_t * const p_mail, dsp_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 311 {
dkato 0:ee40da884cfc 312 bool ret = false;
dkato 0:ee40da884cfc 313
dkato 0:ee40da884cfc 314 if ((p_mail != NULL) && (p_ctrl != NULL)) {
dkato 0:ee40da884cfc 315 /* Decodes the received mail */
dkato 0:ee40da884cfc 316 switch(p_mail->mail_id) {
dkato 0:ee40da884cfc 317 case DSP_MAILID_CYCLE_IND: /* Cyclic notice */
dkato 0:ee40da884cfc 318 ret = true;
dkato 0:ee40da884cfc 319 break;
dkato 0:ee40da884cfc 320 case DSP_MAILID_CMD_STR: /* Input character string by the command-line */
dkato 0:ee40da884cfc 321 ret = true;
dkato 0:ee40da884cfc 322 if ((int32_t)p_mail->param[MAIL_CMDSTR_FIN_FLG] == true) {
dkato 0:ee40da884cfc 323 p_ctrl->trm.edge_fin_inpt = true;
dkato 0:ee40da884cfc 324 } else {
dkato 0:ee40da884cfc 325 p_ctrl->trm.edge_fin_inpt = false;
dkato 0:ee40da884cfc 326 }
dkato 0:ee40da884cfc 327 (void) memcpy(&p_ctrl->trm.inpt_str[0],
dkato 0:ee40da884cfc 328 &p_mail->param[MAIL_CMDSTR_STR_START],
dkato 0:ee40da884cfc 329 sizeof(p_ctrl->trm.inpt_str));
dkato 0:ee40da884cfc 330 p_ctrl->trm.inpt_str[DSP_CMD_INPT_STR_MAX_LEN - 1] = '\0';
dkato 0:ee40da884cfc 331 break;
dkato 0:ee40da884cfc 332 case DSP_MAILID_PRINT_STR: /* Character string for the status indication */
dkato 0:ee40da884cfc 333 ret = true;
dkato 0:ee40da884cfc 334 (void) memcpy(&p_ctrl->com.dspl_str[0],
dkato 0:ee40da884cfc 335 &p_mail->param[MAIL_DISPSTR_STR_START],
dkato 0:ee40da884cfc 336 sizeof(p_ctrl->com.dspl_str));
dkato 0:ee40da884cfc 337 p_ctrl->com.dspl_str[DSP_DISP_STR_MAX_LEN - 1] = '\0';
dkato 0:ee40da884cfc 338 break;
dkato 0:ee40da884cfc 339 case DSP_MAILID_PLAY_TIME: /* Playback time */
dkato 0:ee40da884cfc 340 ret = true;
dkato 0:ee40da884cfc 341 p_ctrl->com.play_stat = (SYS_PlayStat)p_mail->param[MAIL_PLAYTIME_STAT];
dkato 0:ee40da884cfc 342 p_ctrl->com.track_id = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_H] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 343 (uint32_t)p_mail->param[MAIL_PLAYTIME_TRACK_L]);
dkato 0:ee40da884cfc 344 p_ctrl->com.play_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_H] << WORD_SHIFT) |
dkato 0:ee40da884cfc 345 ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_M] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 346 ((uint32_t)p_mail->param[MAIL_PLAYTIME_PLAYTIME_L]));
dkato 0:ee40da884cfc 347 p_ctrl->com.total_time = (((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_H] << WORD_SHIFT) |
dkato 0:ee40da884cfc 348 ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_M] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 349 ((uint32_t)p_mail->param[MAIL_PLAYTIME_TOTALTIME_L]));
dkato 0:ee40da884cfc 350 break;
dkato 0:ee40da884cfc 351 case DSP_MAILID_PLAY_INFO: /* Music information */
dkato 0:ee40da884cfc 352 ret = true;
dkato 0:ee40da884cfc 353 p_ctrl->com.track_id = (((uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_H] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 354 (uint32_t)p_mail->param[MAIL_PLAYINFO_TRACK_L]);
dkato 0:ee40da884cfc 355 p_ctrl->com.samp_freq = (((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_H] << WORD_SHIFT) |
dkato 0:ee40da884cfc 356 ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_M] << BYTE_SHIFT) |
dkato 0:ee40da884cfc 357 ((uint32_t)p_mail->param[MAIL_PLAYINFO_SAMPFREQ_L]));
dkato 0:ee40da884cfc 358 p_ctrl->com.channel = p_mail->param[MAIL_PLAYINFO_CHANNEL];
dkato 0:ee40da884cfc 359 break;
dkato 0:ee40da884cfc 360 case DSP_MAILID_PLAY_MODE: /* Repeat mode */
dkato 0:ee40da884cfc 361 ret = true;
dkato 0:ee40da884cfc 362 if ((int32_t)p_mail->param[MAIL_PLAYMODE_REPEAT] == true) {
dkato 0:ee40da884cfc 363 p_ctrl->com.repeat_mode = true;
dkato 0:ee40da884cfc 364 } else {
dkato 0:ee40da884cfc 365 p_ctrl->com.repeat_mode = false;
dkato 0:ee40da884cfc 366 }
dkato 0:ee40da884cfc 367 break;
dkato 0:ee40da884cfc 368 case DSP_MAILID_FILE_NAME: /* File name */
dkato 0:ee40da884cfc 369 ret = true;
dkato 0:ee40da884cfc 370 (void) memcpy(&p_ctrl->com.file_name[0],
dkato 0:ee40da884cfc 371 &p_mail->param[MAIL_FILENAME_STR_START],
dkato 0:ee40da884cfc 372 sizeof(p_ctrl->com.file_name));
dkato 0:ee40da884cfc 373 p_ctrl->com.file_name[DSP_DISP_STR_MAX_LEN - 1] = '\0';
dkato 0:ee40da884cfc 374 break;
dkato 0:ee40da884cfc 375 default:
dkato 0:ee40da884cfc 376 /* Unexpected cases : mail id was illegal. */
dkato 0:ee40da884cfc 377 ret = false;
dkato 0:ee40da884cfc 378 break;
dkato 0:ee40da884cfc 379 }
dkato 0:ee40da884cfc 380 }
dkato 0:ee40da884cfc 381 return ret;
dkato 0:ee40da884cfc 382 }
dkato 0:ee40da884cfc 383
dkato 0:ee40da884cfc 384 /** Clears the one shot data in the control data of display module
dkato 0:ee40da884cfc 385 *
dkato 0:ee40da884cfc 386 * @param p_ctrl Pointer to control data of display module.
dkato 0:ee40da884cfc 387 */
dkato 0:ee40da884cfc 388 static void clear_one_shot_data(dsp_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 389 {
dkato 0:ee40da884cfc 390 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 391 if (p_ctrl->trm.edge_fin_inpt == true) {
dkato 0:ee40da884cfc 392 /* Clears data of input character string. */
dkato 0:ee40da884cfc 393 p_ctrl->trm.edge_fin_inpt = false;
dkato 0:ee40da884cfc 394 p_ctrl->trm.inpt_str[0] = '\0';
dkato 0:ee40da884cfc 395 }
dkato 0:ee40da884cfc 396 }
dkato 0:ee40da884cfc 397 return;
dkato 0:ee40da884cfc 398 }