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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers disp_term.cpp Source File

disp_term.cpp

00001 /*******************************************************************************
00002 * DISCLAIMER
00003 * This software is supplied by Renesas Electronics Corporation and is only
00004 * intended for use with Renesas products. No other uses are authorized. This
00005 * software is owned by Renesas Electronics Corporation and is protected under
00006 * all applicable laws, including copyright laws.
00007 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
00008 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
00009 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00010 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
00011 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
00012 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
00013 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
00014 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
00015 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00016 * Renesas reserves the right, without notice, to make changes to this software
00017 * and to discontinue the availability of this software. By using this software,
00018 * you agree to the additional terms and conditions found by accessing the
00019 * following link:
00020 * http://www.renesas.com/disclaimer*
00021 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
00022 *******************************************************************************/
00023 
00024 #include "mbed.h"
00025 #include "rtos.h"
00026 #include "display.h"
00027 #include "disp_term.h"
00028 
00029 /*--- Macro definition ---*/
00030 #define MOVE_CURSOR_TO_LEFT     "\x1b[128D" /* Moves a cursor to the left. */
00031 #define CLEAR_CURSOR_RIGHT      "\x1b[0K"   /* Clears the right side of the cursor position. */
00032 #define CLEAR_CURSOR_LINE       "\x1b[2K"   /* Clears a cursor line. */
00033 #define CLEAR_ALL               "\x1b[2J"   /* Clears all screen. */
00034 #define STR_CR                  "\r\n"
00035 
00036 #define MSG_PROMPT               MOVE_CURSOR_TO_LEFT \
00037                                 "T%ld %ld:%02ld:%02ld > "\
00038                                 CLEAR_CURSOR_RIGHT
00039 #define MSG_FILENAME_PREFIX     "File Name = "
00040 #define MSG_FILE_TYPE           "File type      : FLAC"
00041 #define MSG_SAMPLING_FREQ       "Sampling freq. : %ld Hz"
00042 #define MSG_CHANNEL_PREFIX      "Channel        : "
00043 #define MSG_CHANNEL_MONO        "Mono"
00044 #define MSG_CHANNEL_STEREO      "Stereo"
00045 #define MSG_REPEAT_PREFIX       "Repeat Mode = "
00046 #define MSG_MODE_ON             "on"
00047 #define MSG_MODE_OFF            "off"
00048 
00049 #define HELP_CMD_NUM            (7u)
00050 
00051 /* help information */
00052 #define HELP_INFO_HELP          "help      : Show help information for commands."
00053 #define HELP_INFO_NEXT          "next      : Select the next song."
00054 #define HELP_INFO_PLAYINFO      "playinfo  : Show the song information."
00055 #define HELP_INFO_PLAYPAUSE     "playpause : Control playback/pause."
00056 #define HELP_INFO_PREV          "prev      : Select the previous song."
00057 #define HELP_INFO_REPEAT        "repeat    : Turn on and off the repeat mode."
00058 #define HELP_INFO_STOP          "stop      : Stop playback."
00059 
00060 #define MIN_TO_SEC              (60u)
00061 #define HOUR_TO_SEC             (3600u)
00062 
00063 static Serial pc_out(USBTX, USBRX);
00064 
00065 static void output_prompt(const dsp_com_ctrl_t * const p_com);
00066 static void output_playinfo(const dsp_com_ctrl_t * const p_com);
00067 static void output_help_info(void);
00068 static void clear_current_line(void);
00069 static void output_cr(void);
00070 static void output_string(const char_t * const p_str);
00071 
00072 void dsp_init_term(void)
00073 {
00074     pc_out.baud(DSP_PC_COM_BAUDRATE);
00075     output_string(CLEAR_ALL);       /* Clears all screen. */
00076 }
00077 
00078 void dsp_output_term(const DSP_MAIL_ID mail_id, const dsp_com_ctrl_t * const p_com, 
00079                                             const dsp_trm_ctrl_t * const p_trm)
00080 {
00081     bool            is_update;
00082     const char_t    *p_str;
00083     
00084     if ((p_com != NULL) && (p_trm != NULL)) {
00085         switch(mail_id) {
00086             case DSP_MAILID_CMD_STR:    /* Input character string by the command-line */
00087                 /* Input character string is displayed after Command Prompt. */
00088                 is_update = true;
00089                 break;
00090             case DSP_MAILID_PRINT_STR:  /* Character string for the status indication */
00091                 is_update = true;
00092                 clear_current_line();
00093                 output_string(&p_com->dspl_str[0]);
00094                 output_cr();
00095                 break;
00096             case DSP_MAILID_PLAY_TIME:  /* Playback time */
00097                 /* Playback time is displayed in Command Prompt. */
00098                 is_update = true;
00099                 break;
00100             case DSP_MAILID_PLAY_INFO:  /* Music information */
00101                 is_update = true;
00102                 clear_current_line();
00103                 output_playinfo(p_com);
00104                 break;
00105             case DSP_MAILID_PLAY_MODE:  /* Repeat mode */
00106                 is_update = true;
00107                 clear_current_line();
00108                 output_string(MSG_REPEAT_PREFIX);
00109                 if (p_com->repeat_mode == true) {
00110                     p_str = MSG_MODE_ON;
00111                 } else {
00112                     p_str = MSG_MODE_OFF;
00113                 }
00114                 output_string(p_str);
00115                 output_cr();
00116                 break;
00117             case DSP_MAILID_FILE_NAME:   /* File name */
00118                 is_update = true;
00119                 clear_current_line();
00120                 output_string(MSG_FILENAME_PREFIX);
00121                 output_string(&p_com->file_name[0]);
00122                 output_cr();
00123                 break;
00124             case DSP_MAILID_HELP:        /* Help information */
00125                 is_update = true;
00126                 clear_current_line();
00127                 output_help_info();
00128                 break;
00129             case DSP_MAILID_CYCLE_IND:  /* Cyclic notice */
00130             default:                    /* Unexpected cases : mail id was illegal. */
00131                 is_update = false;
00132                 break;
00133         }
00134         
00135         if (is_update == true) {
00136             /* Outputs the command prompt. */
00137             output_prompt(p_com);
00138             
00139             /* Outputs a input character string. */
00140             output_string(&p_trm->inpt_str[0]);
00141             
00142             if (p_trm->edge_fin_inpt == true) {
00143                 /* Because command input was finished, I move a cursor. */
00144                 /* And outputs the command prompt for next input. */
00145                 output_cr();
00146                 output_prompt(p_com);
00147             }
00148         }
00149     }
00150 }
00151 
00152 /** Prints the command prompt
00153  *
00154  *  @param p_com Pointer to common data in all module.
00155  */
00156 static void output_prompt(const dsp_com_ctrl_t * const p_com)
00157 {
00158     char_t          str_buf[DSP_DISP_STR_MAX_LEN];
00159     uint32_t        tim;
00160     uint32_t        hour;
00161     uint32_t        min;
00162     uint32_t        sec;
00163 
00164     if (p_com != NULL) {
00165         tim  = p_com->play_time;
00166         hour = tim / HOUR_TO_SEC;
00167         tim  = tim % HOUR_TO_SEC;
00168         min  = tim / MIN_TO_SEC;
00169         sec  = tim % MIN_TO_SEC;
00170         (void) sprintf(str_buf, MSG_PROMPT, p_com->track_id, hour, min, sec);
00171         output_string(str_buf);
00172     }
00173 }
00174 
00175 /** Prints the file information of the current playback music.
00176  *
00177  *  @param p_com Pointer to common data in all module.
00178  */
00179 static void output_playinfo(const dsp_com_ctrl_t * const p_com)
00180 {
00181     char_t          str_buf[DSP_DISP_STR_MAX_LEN];
00182     const char_t *  p_str;
00183     
00184     if (p_com != NULL) {
00185         /* Prints the file type */
00186         output_string(MSG_FILE_TYPE);
00187         output_cr();
00188 
00189         /* Prints the sampling frequency */
00190         (void) sprintf(str_buf, MSG_SAMPLING_FREQ, p_com->samp_freq);
00191         output_string(str_buf);
00192         output_cr();
00193 
00194         /* Prints the channel structure */
00195         output_string(MSG_CHANNEL_PREFIX);
00196         if (p_com->channel == 1u) {
00197             p_str = MSG_CHANNEL_MONO;
00198         } else {
00199             p_str = MSG_CHANNEL_STEREO;
00200         }
00201         output_string(p_str);
00202         output_cr();
00203     }
00204 }
00205 
00206 /** Prints the command help informations.
00207  *
00208  */
00209 static void output_help_info(void)
00210 {
00211     uint32_t i;
00212     struct {
00213         const char_t    *p_help_info;
00214     } static const info_list[HELP_CMD_NUM] = {
00215         {   HELP_INFO_HELP        },
00216         {   HELP_INFO_NEXT        },
00217         {   HELP_INFO_PLAYINFO    },
00218         {   HELP_INFO_PLAYPAUSE   },
00219         {   HELP_INFO_PREV        },
00220         {   HELP_INFO_REPEAT      },
00221         {   HELP_INFO_STOP        }
00222     };
00223 
00224     /* Prints the help information in alphabetical order. */
00225     for (i = 0u; i < HELP_CMD_NUM; i++) {
00226         output_string(info_list[i].p_help_info);
00227         output_cr();
00228     }
00229 }
00230 
00231 /** Clears a cursor line
00232  *
00233  */
00234 static void clear_current_line(void)
00235 {
00236     output_string(MOVE_CURSOR_TO_LEFT);     /* Moves a cursor to the left. */
00237     output_string(CLEAR_CURSOR_LINE);       /* Clears a cursor line. */
00238 }
00239 
00240 /** Prints the CARRIAGE RETURN
00241  *
00242  */
00243 static void output_cr(void)
00244 {
00245     output_string(STR_CR);
00246 }
00247 
00248 /** Prints the specified character string
00249  *
00250  *  @param p_str Pointer to the character string.
00251  */
00252 static void output_string(const char_t * const p_str)
00253 {
00254     if (p_str != NULL) {
00255         (void) pc_out.puts(p_str);
00256     }
00257 }