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:
1050186
Date:
Mon Jan 25 02:41:36 2016 +0000
Revision:
4:2672de88a46b
Parent:
2:d9fca8cd7f03
Child:
5:25de5b925302
Audio Playback sample program that use the LCD board

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 "USBHostMSD.h"
dkato 0:ee40da884cfc 27
dkato 0:ee40da884cfc 28 #include "system.h"
dkato 0:ee40da884cfc 29 #include "sys_scan_folder.h"
dkato 0:ee40da884cfc 30 #include "decode.h"
dkato 0:ee40da884cfc 31 #include "display.h"
dkato 0:ee40da884cfc 32
dkato 0:ee40da884cfc 33 #if defined(TARGET_RZ_A1H)
dkato 0:ee40da884cfc 34 #include "usb_host_setting.h"
dkato 0:ee40da884cfc 35 #else
dkato 0:ee40da884cfc 36 #define USB_HOST_CH (0)
dkato 0:ee40da884cfc 37 #endif
dkato 0:ee40da884cfc 38
dkato 0:ee40da884cfc 39 /*--- Macro definition of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 40 #define MAIL_QUEUE_SIZE (12) /* Queue size */
dkato 0:ee40da884cfc 41 #define MAIL_PARAM_NUM (3) /* Elements number of mail parameter array */
dkato 0:ee40da884cfc 42
dkato 0:ee40da884cfc 43 /* sys_mail_t */
dkato 0:ee40da884cfc 44 #define MAIL_PARAM0 (0) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 45 #define MAIL_PARAM1 (1) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 46 #define MAIL_PARAM2 (2) /* Index number of mail parameter array */
dkato 0:ee40da884cfc 47
dkato 0:ee40da884cfc 48 #define MAIL_PARAM_NON (0u) /* Value of unused element of mail parameter array */
dkato 0:ee40da884cfc 49
dkato 0:ee40da884cfc 50 /* mail_id = SYS_MAILID_KEYCODE */
dkato 0:ee40da884cfc 51 #define MAIL_KEYCODE_CODE (MAIL_PARAM0) /* Key code */
dkato 0:ee40da884cfc 52
dkato 0:ee40da884cfc 53 /* mail_id = SYS_MAILID_PLAY_TIME */
dkato 0:ee40da884cfc 54 #define MAIL_PLAYTIME_STAT (MAIL_PARAM0) /* Playback status */
dkato 0:ee40da884cfc 55 #define MAIL_PLAYTIME_TIME (MAIL_PARAM1) /* Playback time */
dkato 0:ee40da884cfc 56 #define MAIL_PLAYTIME_TOTAL (MAIL_PARAM2) /* Total playback time */
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 /* mail_id = SYS_MAILID_DEC_OPEN_FIN */
dkato 0:ee40da884cfc 59 #define MAIL_DECOPEN_RESULT (MAIL_PARAM0) /* Result of the process */
dkato 0:ee40da884cfc 60 #define MAIL_DECOPEN_FREQ (MAIL_PARAM1) /* Sampling rate in Hz of FLAC file */
dkato 0:ee40da884cfc 61 #define MAIL_DECOPEN_CH (MAIL_PARAM2) /* Number of channel */
dkato 0:ee40da884cfc 62
dkato 0:ee40da884cfc 63 #define RECV_MAIL_TIMEOUT_MS (10)
dkato 0:ee40da884cfc 64
dkato 0:ee40da884cfc 65 #define USB1_WAIT_TIME_MS (5)
dkato 0:ee40da884cfc 66 #define TRACK_ID_MIN (0u)
dkato 0:ee40da884cfc 67 #define TRACK_ID_ERR (0xFFFFFFFFu)
dkato 0:ee40da884cfc 68
dkato 0:ee40da884cfc 69 #define PRINT_MSG_USB_CONNECT "USB connection was detected."
dkato 0:ee40da884cfc 70 #define PRINT_MSG_OPEN_ERR "Could not play this file."
dkato 0:ee40da884cfc 71 #define PRINT_MSG_DECODE_ERR "This file format is not supported."
dkato 0:ee40da884cfc 72
dkato 0:ee40da884cfc 73 /*--- User defined types of mbed-rtos mail ---*/
dkato 0:ee40da884cfc 74 typedef enum {
dkato 0:ee40da884cfc 75 SYS_MAILID_DUMMY = 0,
dkato 0:ee40da884cfc 76 SYS_MAILID_KEYCODE, /* Notifies main thread of key code. */
dkato 0:ee40da884cfc 77 SYS_MAILID_PLAY_TIME, /* Notifies main thread of playback time. */
dkato 0:ee40da884cfc 78 SYS_MAILID_DEC_OPEN_FIN, /* Finished the opening process of Decode Thread. */
dkato 0:ee40da884cfc 79 SYS_MAILID_DEC_CLOSE_FIN, /* Finished the closing process of Decode Thread. */
dkato 0:ee40da884cfc 80 SYS_MAILID_NUM
dkato 0:ee40da884cfc 81 } SYS_MAIL_ID;
dkato 0:ee40da884cfc 82
dkato 0:ee40da884cfc 83 typedef struct {
dkato 0:ee40da884cfc 84 SYS_MAIL_ID mail_id;
dkato 0:ee40da884cfc 85 uint32_t param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 86 } sys_mail_t;
dkato 0:ee40da884cfc 87
dkato 0:ee40da884cfc 88 /*--- User defined types of main thread ---*/
dkato 0:ee40da884cfc 89 /* Status of main thread */
dkato 0:ee40da884cfc 90 typedef enum {
dkato 0:ee40da884cfc 91 SYS_ST_WAIT_USB_CONNECT = 0,/* Wait the USB connection */
dkato 0:ee40da884cfc 92 SYS_ST_STOP, /* Stop the playback */
dkato 0:ee40da884cfc 93 SYS_ST_PLAY_PREPARE, /* Preparation of the playback */
dkato 0:ee40da884cfc 94 SYS_ST_PLAY_PREPARE_REQ, /* Holds the stop request until completion */
dkato 0:ee40da884cfc 95 /* of the playback preparation */
dkato 0:ee40da884cfc 96 SYS_ST_PLAY, /* Play */
dkato 0:ee40da884cfc 97 SYS_ST_PAUSE, /* Pause */
dkato 0:ee40da884cfc 98 SYS_ST_STOP_PREPARE, /* Preparation of the stop */
dkato 0:ee40da884cfc 99 SYS_ST_STOP_PREPARE_REQ, /* Holds the playback request until completion */
dkato 0:ee40da884cfc 100 /* of the stop preparation */
dkato 0:ee40da884cfc 101 SYS_ST_NUM
dkato 0:ee40da884cfc 102 } SYS_STATE;
dkato 0:ee40da884cfc 103
dkato 0:ee40da884cfc 104 /* Event of the state transition */
dkato 0:ee40da884cfc 105 typedef enum {
dkato 0:ee40da884cfc 106 SYS_EV_NON = 0,
dkato 0:ee40da884cfc 107 /* Notification of pushed key. */
dkato 0:ee40da884cfc 108 SYS_EV_KEY_STOP, /* "STOP" key */
dkato 0:ee40da884cfc 109 SYS_EV_KEY_PLAY_PAUSE, /* "PLAY/PAUSE" key */
dkato 0:ee40da884cfc 110 SYS_EV_KEY_NEXT, /* "NEXT" key */
dkato 0:ee40da884cfc 111 SYS_EV_KEY_PREV, /* "PREV" key */
dkato 0:ee40da884cfc 112 SYS_EV_KEY_PLAYINFO, /* "PLAYINFO" key */
dkato 0:ee40da884cfc 113 SYS_EV_KEY_REPEAT, /* "REPEAT" key */
dkato 2:d9fca8cd7f03 114 SYS_EV_KEY_HELP, /* "HELP" key */
1050186 4:2672de88a46b 115 SYS_EV_KEY_MODE, /* "MODE" key */
dkato 0:ee40da884cfc 116 /* Notification of decoder process */
dkato 0:ee40da884cfc 117 SYS_EV_DEC_OPEN_COMP, /* Finished the opening process */
dkato 0:ee40da884cfc 118 SYS_EV_DEC_OPEN_COMP_ERR, /* Finished the opening process (An error occured)*/
dkato 0:ee40da884cfc 119 SYS_EV_DEC_CLOSE_COMP, /* Finished the closing process */
dkato 0:ee40da884cfc 120 /* Notification of the playback status */
dkato 0:ee40da884cfc 121 SYS_EV_STAT_STOP, /* Stop */
dkato 0:ee40da884cfc 122 SYS_EV_STAT_PLAY, /* Play */
dkato 0:ee40da884cfc 123 SYS_EV_STAT_PAUSE, /* Pause */
dkato 0:ee40da884cfc 124 /* Notification of USB connection */
dkato 0:ee40da884cfc 125 SYS_EV_USB_CONNECT, /* Connect */
dkato 0:ee40da884cfc 126 SYS_EV_USB_DISCONNECT, /* Disconnect */
dkato 0:ee40da884cfc 127 SYS_EV_NUM
dkato 0:ee40da884cfc 128 } SYS_EVENT;
dkato 0:ee40da884cfc 129
dkato 0:ee40da884cfc 130 /* Control data of USB memory */
dkato 0:ee40da884cfc 131 typedef struct {
dkato 0:ee40da884cfc 132 bool usb_flag_detach;/* Detected the disconnection of USB memory */
dkato 0:ee40da884cfc 133 } usb_ctrl_t;
dkato 0:ee40da884cfc 134
dkato 0:ee40da884cfc 135 /* The playback information of the playback file */
dkato 0:ee40da884cfc 136 typedef struct {
dkato 0:ee40da884cfc 137 SYS_PlayStat play_stat; /* Playback status */
dkato 0:ee40da884cfc 138 bool repeat_mode; /* Repeat mode */
dkato 0:ee40da884cfc 139 uint32_t track_id; /* Number of the selected track */
dkato 0:ee40da884cfc 140 uint32_t open_track_id; /* Number of the track during the open processing */
dkato 0:ee40da884cfc 141 FILE *p_file_handle; /* Handle of the track */
dkato 0:ee40da884cfc 142 uint32_t play_time; /* Playback start time */
dkato 0:ee40da884cfc 143 uint32_t total_time; /* Total playback time */
dkato 0:ee40da884cfc 144 uint32_t sample_rate; /* Sampling rate in Hz of FLAC file */
dkato 0:ee40da884cfc 145 uint32_t channel_num; /* Number of channel */
1050186 4:2672de88a46b 146 uint32_t disp_mode; /* Display mode */
dkato 0:ee40da884cfc 147 } play_info_t;
dkato 0:ee40da884cfc 148
dkato 0:ee40da884cfc 149 /* Control data of main thread */
dkato 0:ee40da884cfc 150 typedef struct {
dkato 0:ee40da884cfc 151 usb_ctrl_t usb_ctrl;
dkato 0:ee40da884cfc 152 fid_scan_folder_t scan_data;
dkato 0:ee40da884cfc 153 play_info_t play_info;
dkato 0:ee40da884cfc 154 } sys_ctrl_t;
dkato 0:ee40da884cfc 155
dkato 0:ee40da884cfc 156 static Mail<sys_mail_t, MAIL_QUEUE_SIZE> mail_box;
dkato 0:ee40da884cfc 157
dkato 0:ee40da884cfc 158 static void open_callback(const bool result, const uint32_t sample_freq,
dkato 0:ee40da884cfc 159 const uint32_t channel_num);
dkato 0:ee40da884cfc 160 static void close_callback(void);
dkato 0:ee40da884cfc 161 static void init_ctrl_data(sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 162 static SYS_EVENT decode_mail(play_info_t * const p_info,
dkato 0:ee40da884cfc 163 const fid_scan_folder_t * const p_data, const SYS_MAIL_ID mail_id,
dkato 0:ee40da884cfc 164 const uint32_t * const p_param);
dkato 0:ee40da884cfc 165 static SYS_EVENT check_usb_event(const SYS_STATE stat,
dkato 0:ee40da884cfc 166 const usb_ctrl_t * const p_ctrl, USBHostMSD * const p_msd);
dkato 0:ee40da884cfc 167 static SYS_STATE state_trans_proc(const SYS_STATE stat,
dkato 0:ee40da884cfc 168 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 169 static SYS_STATE state_trans_proc(const SYS_STATE stat,
dkato 0:ee40da884cfc 170 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 171 static SYS_STATE state_proc_wait_usb_connect(const SYS_STATE stat,
dkato 0:ee40da884cfc 172 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 173 static SYS_STATE state_proc_stop(const SYS_STATE stat,
dkato 0:ee40da884cfc 174 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 175 static SYS_STATE state_proc_play_prepare(const SYS_STATE stat,
dkato 0:ee40da884cfc 176 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 177 static SYS_STATE state_proc_play_prepare_req(const SYS_STATE stat,
dkato 0:ee40da884cfc 178 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 179 static SYS_STATE state_proc_play_pause(const SYS_STATE stat,
dkato 0:ee40da884cfc 180 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 181 static SYS_STATE state_proc_stop_prepare(const SYS_STATE stat,
dkato 0:ee40da884cfc 182 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 183 static SYS_STATE state_proc_stop_prepare_req(const SYS_STATE stat,
dkato 0:ee40da884cfc 184 const SYS_EVENT event, sys_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 185 static bool exe_scan_folder_proc(play_info_t * const p_info,
dkato 0:ee40da884cfc 186 fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 187 static bool exe_open_proc(play_info_t * const p_info,
dkato 0:ee40da884cfc 188 fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 189 static bool exe_play_proc(play_info_t * const p_info,
dkato 0:ee40da884cfc 190 const fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 191 static bool exe_pause_on_proc(void);
dkato 0:ee40da884cfc 192 static bool exe_pause_off_proc(void);
dkato 0:ee40da884cfc 193 static bool exe_stop_proc(void);
dkato 0:ee40da884cfc 194 static bool exe_close_proc(void);
dkato 0:ee40da884cfc 195 static void exe_end_proc(play_info_t * const p_info);
dkato 0:ee40da884cfc 196 static bool is_track_changed(const play_info_t * const p_info);
dkato 0:ee40da884cfc 197 static void change_repeat_mode(play_info_t * const p_info);
dkato 0:ee40da884cfc 198 static bool change_next_track(play_info_t * const p_info,
dkato 0:ee40da884cfc 199 const fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 200 static bool change_prev_track(play_info_t * const p_info,
dkato 0:ee40da884cfc 201 const fid_scan_folder_t * const p_data);
dkato 0:ee40da884cfc 202 static void print_play_time(const play_info_t * const p_info);
dkato 0:ee40da884cfc 203 static void print_play_info(const play_info_t * const p_info);
dkato 0:ee40da884cfc 204 static void print_file_name(const play_info_t * const p_info,
dkato 0:ee40da884cfc 205 const fid_scan_folder_t * const p_data);
dkato 2:d9fca8cd7f03 206 static void print_help_info(void);
1050186 4:2672de88a46b 207 static void print_play_status(const play_info_t * const p_info);
1050186 4:2672de88a46b 208 static void change_display_mode(play_info_t * const p_info);
dkato 0:ee40da884cfc 209 static uint32_t convert_track_id(const uint32_t trk_id);
dkato 0:ee40da884cfc 210 static bool send_mail(const SYS_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 211 const uint32_t param1, const uint32_t param2);
dkato 0:ee40da884cfc 212 static bool recv_mail(SYS_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 213 uint32_t * const p_param1, uint32_t * const p_param2);
dkato 0:ee40da884cfc 214
dkato 0:ee40da884cfc 215 void system_main(void)
dkato 0:ee40da884cfc 216 {
dkato 0:ee40da884cfc 217 SYS_STATE sys_stat;
dkato 0:ee40da884cfc 218 SYS_EVENT sys_ev;
dkato 0:ee40da884cfc 219 bool result;
dkato 0:ee40da884cfc 220 SYS_MAIL_ID mail_type;
dkato 0:ee40da884cfc 221 uint32_t mail_param[MAIL_PARAM_NUM];
dkato 0:ee40da884cfc 222 static sys_ctrl_t sys_ctrl;
dkato 0:ee40da884cfc 223 static USBHostMSD msd(SYS_USB_MOUNT_NAME);
dkato 0:ee40da884cfc 224 #if (USB_HOST_CH == 1) /* Audio Shield USB1 */
dkato 0:ee40da884cfc 225 static DigitalOut usb1en(P3_8);
dkato 0:ee40da884cfc 226
dkato 0:ee40da884cfc 227 /* Audio Shield USB1 enable */
dkato 0:ee40da884cfc 228 usb1en.write(1); /* Outputs high level */
dkato 0:ee40da884cfc 229 Thread::wait(USB1_WAIT_TIME_MS);
dkato 0:ee40da884cfc 230 usb1en.write(0); /* Outputs low level */
dkato 0:ee40da884cfc 231 #endif /* USB_HOST_CH */
dkato 0:ee40da884cfc 232
dkato 0:ee40da884cfc 233 /* Initializes the control data of main thread. */
dkato 0:ee40da884cfc 234 init_ctrl_data(&sys_ctrl);
1050186 4:2672de88a46b 235 /* Notifies the default display mode. */
1050186 4:2672de88a46b 236 (void) dsp_notify_disp_mode(sys_ctrl.play_info.disp_mode);
dkato 0:ee40da884cfc 237 sys_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 238 while (1) {
dkato 0:ee40da884cfc 239 sys_ev = check_usb_event(sys_stat, &sys_ctrl.usb_ctrl, &msd);
dkato 0:ee40da884cfc 240 if (sys_ev == SYS_EV_NON) {
dkato 0:ee40da884cfc 241 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0],
dkato 0:ee40da884cfc 242 &mail_param[MAIL_PARAM1], &mail_param[MAIL_PARAM2]);
dkato 0:ee40da884cfc 243 if (result == true) {
dkato 0:ee40da884cfc 244 sys_ev = decode_mail(&sys_ctrl.play_info,
dkato 0:ee40da884cfc 245 &sys_ctrl.scan_data, mail_type, mail_param);
dkato 0:ee40da884cfc 246 }
dkato 0:ee40da884cfc 247 }
dkato 0:ee40da884cfc 248 if (sys_ev != SYS_EV_NON) {
dkato 0:ee40da884cfc 249 sys_stat = state_trans_proc(sys_stat, sys_ev, &sys_ctrl);
dkato 0:ee40da884cfc 250 }
dkato 0:ee40da884cfc 251 }
dkato 0:ee40da884cfc 252 }
dkato 0:ee40da884cfc 253
dkato 0:ee40da884cfc 254 bool sys_notify_key_input(const SYS_KeyCode key_code)
dkato 0:ee40da884cfc 255 {
dkato 0:ee40da884cfc 256 bool ret = false;
dkato 0:ee40da884cfc 257
dkato 0:ee40da884cfc 258 ret = send_mail(SYS_MAILID_KEYCODE, (uint32_t)key_code, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 259
dkato 0:ee40da884cfc 260 return ret;
dkato 0:ee40da884cfc 261 }
dkato 0:ee40da884cfc 262
dkato 0:ee40da884cfc 263 bool sys_notify_play_time(const SYS_PlayStat play_stat,
dkato 0:ee40da884cfc 264 const uint32_t play_time, const uint32_t total_time)
dkato 0:ee40da884cfc 265 {
dkato 0:ee40da884cfc 266 bool ret = false;
dkato 0:ee40da884cfc 267
dkato 0:ee40da884cfc 268 ret = send_mail(SYS_MAILID_PLAY_TIME, (uint32_t)play_stat, play_time, total_time);
dkato 0:ee40da884cfc 269
dkato 0:ee40da884cfc 270 return ret;
dkato 0:ee40da884cfc 271 }
dkato 0:ee40da884cfc 272
dkato 0:ee40da884cfc 273 /** Callback function of Decode Thread
dkato 0:ee40da884cfc 274 *
dkato 0:ee40da884cfc 275 * @param result Result of the process.
dkato 0:ee40da884cfc 276 * @param sample_freq Sampling rate in Hz of FLAC file.
dkato 0:ee40da884cfc 277 * @param channel_num Number of channel.
dkato 0:ee40da884cfc 278 */
dkato 0:ee40da884cfc 279 static void open_callback(const bool result, const uint32_t sample_freq,
dkato 0:ee40da884cfc 280 const uint32_t channel_num)
dkato 0:ee40da884cfc 281 {
dkato 0:ee40da884cfc 282 (void) send_mail(SYS_MAILID_DEC_OPEN_FIN, (uint32_t)result, sample_freq, channel_num);
dkato 0:ee40da884cfc 283 }
dkato 0:ee40da884cfc 284
dkato 0:ee40da884cfc 285 /** Callback function of Decode Thread
dkato 0:ee40da884cfc 286 *
dkato 0:ee40da884cfc 287 */
dkato 0:ee40da884cfc 288 static void close_callback(void)
dkato 0:ee40da884cfc 289 {
dkato 0:ee40da884cfc 290 (void) send_mail(SYS_MAILID_DEC_CLOSE_FIN, MAIL_PARAM_NON, MAIL_PARAM_NON, MAIL_PARAM_NON);
dkato 0:ee40da884cfc 291 }
dkato 0:ee40da884cfc 292
dkato 0:ee40da884cfc 293 /** Initialises the control data of main thread
dkato 0:ee40da884cfc 294 *
dkato 0:ee40da884cfc 295 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 296 */
dkato 0:ee40da884cfc 297 static void init_ctrl_data(sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 298 {
dkato 0:ee40da884cfc 299 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 300 /* Initialises the control data of USB memory. */
dkato 0:ee40da884cfc 301 p_ctrl->usb_ctrl.usb_flag_detach = false;
dkato 0:ee40da884cfc 302 /* Initialises the information of folder scan. */
dkato 0:ee40da884cfc 303 fid_init(&p_ctrl->scan_data);
dkato 0:ee40da884cfc 304 /* Initialises the playback information of the playback file */
dkato 0:ee40da884cfc 305 p_ctrl->play_info.play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 306 p_ctrl->play_info.repeat_mode = true;
dkato 0:ee40da884cfc 307 p_ctrl->play_info.track_id = TRACK_ID_MIN;
dkato 0:ee40da884cfc 308 p_ctrl->play_info.open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 309 p_ctrl->play_info.p_file_handle = NULL;
dkato 0:ee40da884cfc 310 p_ctrl->play_info.play_time = 0u;
dkato 0:ee40da884cfc 311 p_ctrl->play_info.total_time = 0u;
dkato 0:ee40da884cfc 312 p_ctrl->play_info.sample_rate = 0u;
dkato 0:ee40da884cfc 313 p_ctrl->play_info.channel_num = 0u;
1050186 4:2672de88a46b 314 p_ctrl->play_info.disp_mode = DSP_DISPMODE_1;
dkato 0:ee40da884cfc 315 }
dkato 0:ee40da884cfc 316 }
dkato 0:ee40da884cfc 317
dkato 0:ee40da884cfc 318 /** Converts the code of SYS_MAIL_ID into the code of SYS_EVENT
dkato 0:ee40da884cfc 319 *
dkato 0:ee40da884cfc 320 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 321 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 322 * @param mail_id The event code of SYS_MAIL_ID
dkato 0:ee40da884cfc 323 * @param p_param Pointer to the parameter of the mail
dkato 0:ee40da884cfc 324 *
dkato 0:ee40da884cfc 325 * @returns
dkato 0:ee40da884cfc 326 * The event code of SYS_EVENT
dkato 0:ee40da884cfc 327 */
dkato 0:ee40da884cfc 328 static SYS_EVENT decode_mail(play_info_t * const p_info,
dkato 0:ee40da884cfc 329 const fid_scan_folder_t * const p_data, const SYS_MAIL_ID mail_id,
dkato 0:ee40da884cfc 330 const uint32_t * const p_param)
dkato 0:ee40da884cfc 331 {
dkato 0:ee40da884cfc 332 SYS_EVENT ret = SYS_EV_NON;
dkato 0:ee40da884cfc 333
dkato 0:ee40da884cfc 334 if ((p_info != NULL) && (p_data != NULL) && (p_param != NULL)) {
dkato 0:ee40da884cfc 335 switch (mail_id) {
dkato 0:ee40da884cfc 336 case SYS_MAILID_KEYCODE:
dkato 0:ee40da884cfc 337 switch (p_param[MAIL_KEYCODE_CODE]) {
dkato 0:ee40da884cfc 338 case SYS_KEYCODE_STOP:
dkato 0:ee40da884cfc 339 ret = SYS_EV_KEY_STOP;
dkato 0:ee40da884cfc 340 break;
dkato 0:ee40da884cfc 341 case SYS_KEYCODE_PLAYPAUSE:
dkato 0:ee40da884cfc 342 ret = SYS_EV_KEY_PLAY_PAUSE;
dkato 0:ee40da884cfc 343 break;
dkato 0:ee40da884cfc 344 case SYS_KEYCODE_NEXT:
dkato 0:ee40da884cfc 345 ret = SYS_EV_KEY_NEXT;
dkato 0:ee40da884cfc 346 break;
dkato 0:ee40da884cfc 347 case SYS_KEYCODE_PREV:
dkato 0:ee40da884cfc 348 ret = SYS_EV_KEY_PREV;
dkato 0:ee40da884cfc 349 break;
dkato 0:ee40da884cfc 350 case SYS_KEYCODE_PLAYINFO:
dkato 0:ee40da884cfc 351 ret = SYS_EV_KEY_PLAYINFO;
dkato 0:ee40da884cfc 352 break;
dkato 2:d9fca8cd7f03 353 case SYS_KEYCODE_REPEAT:
dkato 0:ee40da884cfc 354 ret = SYS_EV_KEY_REPEAT;
dkato 0:ee40da884cfc 355 break;
dkato 2:d9fca8cd7f03 356 case SYS_KEYCODE_HELP:
dkato 2:d9fca8cd7f03 357 ret = SYS_EV_KEY_HELP;
dkato 2:d9fca8cd7f03 358 break;
1050186 4:2672de88a46b 359 case SYS_KEYCODE_MODE:
1050186 4:2672de88a46b 360 ret = SYS_EV_KEY_MODE;
1050186 4:2672de88a46b 361 break;
dkato 0:ee40da884cfc 362 default:
dkato 0:ee40da884cfc 363 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 364 ret = SYS_EV_NON;
dkato 0:ee40da884cfc 365 break;
dkato 0:ee40da884cfc 366 }
dkato 0:ee40da884cfc 367 break;
dkato 0:ee40da884cfc 368 case SYS_MAILID_PLAY_TIME:
dkato 0:ee40da884cfc 369 switch (p_param[MAIL_PLAYTIME_STAT]) {
dkato 0:ee40da884cfc 370 case SYS_PLAYSTAT_STOP:
dkato 0:ee40da884cfc 371 ret = SYS_EV_STAT_STOP;
dkato 0:ee40da884cfc 372 break;
dkato 0:ee40da884cfc 373 case SYS_PLAYSTAT_PLAY:
dkato 0:ee40da884cfc 374 ret = SYS_EV_STAT_PLAY;
dkato 0:ee40da884cfc 375 break;
dkato 0:ee40da884cfc 376 case SYS_PLAYSTAT_PAUSE:
dkato 0:ee40da884cfc 377 ret = SYS_EV_STAT_PAUSE;
dkato 0:ee40da884cfc 378 break;
dkato 0:ee40da884cfc 379 default:
dkato 0:ee40da884cfc 380 ret = SYS_EV_NON;
dkato 0:ee40da884cfc 381 break;
dkato 0:ee40da884cfc 382 }
dkato 0:ee40da884cfc 383 /* Is the playback status correct? */
dkato 0:ee40da884cfc 384 if (ret != SYS_EV_NON) {
dkato 0:ee40da884cfc 385 p_info->play_stat = (SYS_PlayStat)p_param[MAIL_PLAYTIME_STAT];
dkato 0:ee40da884cfc 386 p_info->play_time = p_param[MAIL_PLAYTIME_TIME];
dkato 0:ee40da884cfc 387 p_info->total_time = p_param[MAIL_PLAYTIME_TOTAL];
dkato 0:ee40da884cfc 388 } else {
dkato 0:ee40da884cfc 389 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 390 p_info->play_stat = SYS_PLAYSTAT_STOP;
dkato 0:ee40da884cfc 391 p_info->play_time = 0u;
dkato 0:ee40da884cfc 392 p_info->total_time = 0u;
dkato 0:ee40da884cfc 393 }
dkato 0:ee40da884cfc 394 break;
dkato 0:ee40da884cfc 395 case SYS_MAILID_DEC_OPEN_FIN:
dkato 0:ee40da884cfc 396 if ((int32_t)p_param[MAIL_DECOPEN_RESULT] == true) {
dkato 0:ee40da884cfc 397 ret = SYS_EV_DEC_OPEN_COMP;
dkato 0:ee40da884cfc 398 p_info->sample_rate = p_param[MAIL_DECOPEN_FREQ];
dkato 0:ee40da884cfc 399 p_info->channel_num = p_param[MAIL_DECOPEN_CH];
dkato 0:ee40da884cfc 400 } else {
dkato 0:ee40da884cfc 401 /* The opening of the decoder was failure. */
dkato 0:ee40da884cfc 402 ret = SYS_EV_DEC_OPEN_COMP_ERR;
dkato 0:ee40da884cfc 403 p_info->sample_rate = 0u;
dkato 0:ee40da884cfc 404 p_info->channel_num = 0u;
dkato 0:ee40da884cfc 405 /* Tries to open the next file. */
dkato 0:ee40da884cfc 406 print_play_time(p_info);
dkato 0:ee40da884cfc 407 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 408 (void) change_next_track(p_info, p_data);
dkato 0:ee40da884cfc 409 }
dkato 0:ee40da884cfc 410 break;
dkato 0:ee40da884cfc 411 case SYS_MAILID_DEC_CLOSE_FIN:
dkato 0:ee40da884cfc 412 ret = SYS_EV_DEC_CLOSE_COMP;
dkato 0:ee40da884cfc 413 p_info->play_time = 0u;
dkato 0:ee40da884cfc 414 p_info->total_time = 0u;
dkato 0:ee40da884cfc 415 break;
dkato 0:ee40da884cfc 416 default:
dkato 0:ee40da884cfc 417 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 418 ret = SYS_EV_NON;
dkato 0:ee40da884cfc 419 break;
dkato 0:ee40da884cfc 420 }
dkato 0:ee40da884cfc 421 }
dkato 0:ee40da884cfc 422 return ret;
dkato 0:ee40da884cfc 423 }
dkato 0:ee40da884cfc 424
dkato 0:ee40da884cfc 425 /** Checks the event of USB connection
dkato 0:ee40da884cfc 426 *
dkato 0:ee40da884cfc 427 * @param stat Status of main thread
dkato 0:ee40da884cfc 428 * @param p_ctrl Pointer to the control data of USB memory
dkato 0:ee40da884cfc 429 * @param p_msd Pointer to the class object of USBHostMSD
dkato 0:ee40da884cfc 430 *
dkato 0:ee40da884cfc 431 * @returns
dkato 0:ee40da884cfc 432 * The event code of SYS_EVENT
dkato 0:ee40da884cfc 433 */
dkato 0:ee40da884cfc 434 static SYS_EVENT check_usb_event(const SYS_STATE stat,
dkato 0:ee40da884cfc 435 const usb_ctrl_t * const p_ctrl, USBHostMSD * const p_msd)
dkato 0:ee40da884cfc 436 {
dkato 0:ee40da884cfc 437 SYS_EVENT ret = SYS_EV_NON;
dkato 0:ee40da884cfc 438 bool result;
dkato 0:ee40da884cfc 439
dkato 0:ee40da884cfc 440 if ((p_ctrl != NULL) && (p_msd != NULL)) {
dkato 0:ee40da884cfc 441 if (stat == SYS_ST_WAIT_USB_CONNECT) {
dkato 0:ee40da884cfc 442 /* Mounts the FAT filesystem again. */
dkato 0:ee40da884cfc 443 /* Because the connecting USB memory is changed. */
dkato 0:ee40da884cfc 444 result = p_msd->connect();
dkato 0:ee40da884cfc 445 if (result == true) {
dkato 1:315326ec910b 446 (void) p_msd->unmount();
dkato 1:315326ec910b 447 (void) p_msd->mount();
dkato 0:ee40da884cfc 448 ret = SYS_EV_USB_CONNECT;
dkato 0:ee40da884cfc 449 }
dkato 0:ee40da884cfc 450 } else if (p_ctrl->usb_flag_detach != true) {
dkato 0:ee40da884cfc 451 result = p_msd->connected();
dkato 0:ee40da884cfc 452 if (result != true) {
dkato 0:ee40da884cfc 453 ret = SYS_EV_USB_DISCONNECT;
dkato 0:ee40da884cfc 454 }
dkato 0:ee40da884cfc 455 } else {
dkato 0:ee40da884cfc 456 /* DO NOTHING */
dkato 0:ee40da884cfc 457 }
dkato 0:ee40da884cfc 458 }
dkato 0:ee40da884cfc 459 return ret;
dkato 0:ee40da884cfc 460 }
dkato 0:ee40da884cfc 461
dkato 0:ee40da884cfc 462 /** Executes the state transition processing
dkato 0:ee40da884cfc 463 *
dkato 0:ee40da884cfc 464 * @param stat Status of main thread
dkato 0:ee40da884cfc 465 * @param event Event code of main thread
dkato 0:ee40da884cfc 466 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 467 *
dkato 0:ee40da884cfc 468 * @returns
dkato 0:ee40da884cfc 469 * Next status of main thread
dkato 0:ee40da884cfc 470 */
dkato 0:ee40da884cfc 471 static SYS_STATE state_trans_proc(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 472 {
dkato 0:ee40da884cfc 473 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 474
dkato 0:ee40da884cfc 475 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 476 /* State transition processing */
dkato 0:ee40da884cfc 477 switch (stat) {
dkato 0:ee40da884cfc 478 case SYS_ST_WAIT_USB_CONNECT: /* Wait the USB connection */
dkato 0:ee40da884cfc 479 next_stat = state_proc_wait_usb_connect(stat, event, p_ctrl);
dkato 0:ee40da884cfc 480 break;
dkato 0:ee40da884cfc 481 case SYS_ST_STOP: /* Stop the playback */
dkato 0:ee40da884cfc 482 next_stat = state_proc_stop(stat, event, p_ctrl);
dkato 0:ee40da884cfc 483 break;
dkato 0:ee40da884cfc 484 case SYS_ST_PLAY_PREPARE: /* Preparation of the playback */
dkato 0:ee40da884cfc 485 next_stat = state_proc_play_prepare(stat, event, p_ctrl);
dkato 0:ee40da884cfc 486 break;
dkato 0:ee40da884cfc 487 case SYS_ST_PLAY_PREPARE_REQ: /* Holds the stop request until completion */
dkato 0:ee40da884cfc 488 /* of the playback preparation */
dkato 0:ee40da884cfc 489 next_stat = state_proc_play_prepare_req(stat, event, p_ctrl);
dkato 0:ee40da884cfc 490 break;
dkato 0:ee40da884cfc 491 case SYS_ST_PLAY: /* Play */
dkato 0:ee40da884cfc 492 case SYS_ST_PAUSE: /* Pause */
dkato 0:ee40da884cfc 493 next_stat = state_proc_play_pause(stat, event, p_ctrl);
dkato 0:ee40da884cfc 494 break;
dkato 0:ee40da884cfc 495 case SYS_ST_STOP_PREPARE: /* Preparation of the stop */
dkato 0:ee40da884cfc 496 next_stat = state_proc_stop_prepare(stat, event, p_ctrl);
dkato 0:ee40da884cfc 497 break;
dkato 0:ee40da884cfc 498 case SYS_ST_STOP_PREPARE_REQ: /* Holds the playback request until completion */
dkato 0:ee40da884cfc 499 /* of the stop preparation */
dkato 0:ee40da884cfc 500 next_stat = state_proc_stop_prepare_req(stat, event, p_ctrl);
dkato 0:ee40da884cfc 501 break;
dkato 0:ee40da884cfc 502 default:
dkato 0:ee40da884cfc 503 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 504 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 505 break;
dkato 0:ee40da884cfc 506 }
dkato 0:ee40da884cfc 507 }
dkato 0:ee40da884cfc 508 return next_stat;
dkato 0:ee40da884cfc 509 }
dkato 0:ee40da884cfc 510
dkato 0:ee40da884cfc 511 /** Executes the state transition processing in the state of SYS_ST_WAIT_USB_CONNECT.
dkato 0:ee40da884cfc 512 *
dkato 0:ee40da884cfc 513 * @param stat Status of main thread
dkato 0:ee40da884cfc 514 * @param event Event code of main thread
dkato 0:ee40da884cfc 515 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 516 *
dkato 0:ee40da884cfc 517 * @returns
dkato 0:ee40da884cfc 518 * Next status of main thread
dkato 0:ee40da884cfc 519 */
dkato 0:ee40da884cfc 520 static SYS_STATE state_proc_wait_usb_connect(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 521 {
dkato 0:ee40da884cfc 522 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 523
dkato 0:ee40da884cfc 524 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 525 if (event == SYS_EV_USB_CONNECT) {
dkato 0:ee40da884cfc 526 p_ctrl->usb_ctrl.usb_flag_detach = false;
dkato 0:ee40da884cfc 527 (void) exe_scan_folder_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 528 (void) dsp_notify_print_string(PRINT_MSG_USB_CONNECT);
dkato 0:ee40da884cfc 529 next_stat = SYS_ST_STOP;
dkato 2:d9fca8cd7f03 530 } else if (event == SYS_EV_KEY_HELP) {
dkato 2:d9fca8cd7f03 531 print_help_info();
1050186 4:2672de88a46b 532 } else if (event == SYS_EV_KEY_MODE) {
1050186 4:2672de88a46b 533 change_display_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 534 } else {
dkato 0:ee40da884cfc 535 /* DO NOTHING */
dkato 0:ee40da884cfc 536 }
dkato 0:ee40da884cfc 537 }
dkato 0:ee40da884cfc 538 return next_stat;
dkato 0:ee40da884cfc 539 }
dkato 0:ee40da884cfc 540
dkato 0:ee40da884cfc 541 /** Executes the state transition processing in the state of SYS_ST_STOP.
dkato 0:ee40da884cfc 542 *
dkato 0:ee40da884cfc 543 * @param stat Status of main thread
dkato 0:ee40da884cfc 544 * @param event Event code of main thread
dkato 0:ee40da884cfc 545 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 546 *
dkato 0:ee40da884cfc 547 * @returns
dkato 0:ee40da884cfc 548 * Next status of main thread
dkato 0:ee40da884cfc 549 */
dkato 0:ee40da884cfc 550 static SYS_STATE state_proc_stop(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 551 {
dkato 0:ee40da884cfc 552 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 553 bool result;
dkato 0:ee40da884cfc 554
dkato 0:ee40da884cfc 555 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 556 switch (event) {
dkato 0:ee40da884cfc 557 case SYS_EV_KEY_PLAY_PAUSE:
dkato 0:ee40da884cfc 558 print_file_name(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 559 result = exe_open_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 560 if (result == true) {
dkato 0:ee40da884cfc 561 next_stat = SYS_ST_PLAY_PREPARE;
dkato 0:ee40da884cfc 562 }
dkato 0:ee40da884cfc 563 break;
dkato 0:ee40da884cfc 564 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 565 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 566 break;
dkato 2:d9fca8cd7f03 567 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 568 print_help_info();
dkato 2:d9fca8cd7f03 569 break;
1050186 4:2672de88a46b 570 case SYS_EV_KEY_MODE:
1050186 4:2672de88a46b 571 change_display_mode(&p_ctrl->play_info);
1050186 4:2672de88a46b 572 break;
dkato 0:ee40da884cfc 573 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 574 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 575 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 576 break;
dkato 0:ee40da884cfc 577 default:
dkato 0:ee40da884cfc 578 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 579 next_stat = stat;
dkato 0:ee40da884cfc 580 break;
dkato 0:ee40da884cfc 581 }
dkato 0:ee40da884cfc 582 }
dkato 0:ee40da884cfc 583 return next_stat;
dkato 0:ee40da884cfc 584 }
dkato 0:ee40da884cfc 585
dkato 0:ee40da884cfc 586 /** Executes the state transition processing in the state of SYS_ST_PLAY_PREPARE.
dkato 0:ee40da884cfc 587 *
dkato 0:ee40da884cfc 588 * @param stat Status of main thread
dkato 0:ee40da884cfc 589 * @param event Event code of main thread
dkato 0:ee40da884cfc 590 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 591 *
dkato 0:ee40da884cfc 592 * @returns
dkato 0:ee40da884cfc 593 * Next status of main thread
dkato 0:ee40da884cfc 594 */
dkato 0:ee40da884cfc 595 static SYS_STATE state_proc_play_prepare(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 596 {
dkato 0:ee40da884cfc 597 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 598 bool result;
dkato 0:ee40da884cfc 599
dkato 0:ee40da884cfc 600 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 601 switch (event) {
dkato 0:ee40da884cfc 602 case SYS_EV_KEY_STOP:
dkato 0:ee40da884cfc 603 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 604 break;
dkato 0:ee40da884cfc 605 case SYS_EV_KEY_NEXT:
dkato 0:ee40da884cfc 606 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 607 if (result != true) {
dkato 0:ee40da884cfc 608 /* Selected track was out of the playback range. */
dkato 0:ee40da884cfc 609 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 610 }
dkato 0:ee40da884cfc 611 break;
dkato 0:ee40da884cfc 612 case SYS_EV_KEY_PREV:
dkato 0:ee40da884cfc 613 result = change_prev_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 614 if (result != true) {
dkato 0:ee40da884cfc 615 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 616 }
dkato 0:ee40da884cfc 617 break;
dkato 0:ee40da884cfc 618 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 619 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 620 break;
dkato 2:d9fca8cd7f03 621 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 622 print_help_info();
dkato 2:d9fca8cd7f03 623 break;
1050186 4:2672de88a46b 624 case SYS_EV_KEY_MODE:
1050186 4:2672de88a46b 625 change_display_mode(&p_ctrl->play_info);
1050186 4:2672de88a46b 626 break;
dkato 0:ee40da884cfc 627 case SYS_EV_DEC_OPEN_COMP:
dkato 0:ee40da884cfc 628 result = is_track_changed(&p_ctrl->play_info);
dkato 0:ee40da884cfc 629 if (result == true) {
dkato 0:ee40da884cfc 630 /* Track was changed during the waiting of callback. */
dkato 0:ee40da884cfc 631 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 632 result = exe_close_proc();
dkato 0:ee40da884cfc 633 if (result == true) {
dkato 0:ee40da884cfc 634 next_stat = SYS_ST_STOP_PREPARE_REQ;
dkato 0:ee40da884cfc 635 } else {
dkato 0:ee40da884cfc 636 /* Unexpected cases : This is fail-safe processing. */
1050186 4:2672de88a46b 637 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 638 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 639 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 640 }
dkato 0:ee40da884cfc 641 } else {
dkato 0:ee40da884cfc 642 print_play_info(&p_ctrl->play_info);
dkato 0:ee40da884cfc 643 result = exe_play_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 644 if (result == true) {
dkato 0:ee40da884cfc 645 next_stat = SYS_ST_PLAY;
dkato 0:ee40da884cfc 646 } else {
dkato 0:ee40da884cfc 647 result = exe_close_proc();
dkato 0:ee40da884cfc 648 if (result == true) {
dkato 0:ee40da884cfc 649 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 650 } else {
dkato 0:ee40da884cfc 651 /* Unexpected cases : This is fail-safe processing. */
1050186 4:2672de88a46b 652 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 653 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 654 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 655 }
dkato 0:ee40da884cfc 656 }
dkato 0:ee40da884cfc 657 }
dkato 0:ee40da884cfc 658 break;
dkato 0:ee40da884cfc 659 case SYS_EV_DEC_OPEN_COMP_ERR:
dkato 0:ee40da884cfc 660 /* Output error message to PC */
1050186 4:2672de88a46b 661 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 662 (void) dsp_notify_print_string(PRINT_MSG_DECODE_ERR);
dkato 0:ee40da884cfc 663 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 664 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 665 break;
dkato 0:ee40da884cfc 666 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 667 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 668 next_stat = SYS_ST_PLAY_PREPARE_REQ;
dkato 0:ee40da884cfc 669 break;
dkato 0:ee40da884cfc 670 default:
dkato 0:ee40da884cfc 671 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 672 next_stat = stat;
dkato 0:ee40da884cfc 673 break;
dkato 0:ee40da884cfc 674 }
dkato 0:ee40da884cfc 675 }
dkato 0:ee40da884cfc 676 return next_stat;
dkato 0:ee40da884cfc 677 }
dkato 0:ee40da884cfc 678
dkato 0:ee40da884cfc 679 /** Executes the state transition processing in the state of SYS_ST_PLAY_PREPARE_REQ.
dkato 0:ee40da884cfc 680 *
dkato 0:ee40da884cfc 681 * @param stat Status of main thread
dkato 0:ee40da884cfc 682 * @param event Event code of main thread
dkato 0:ee40da884cfc 683 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 684 *
dkato 0:ee40da884cfc 685 * @returns
dkato 0:ee40da884cfc 686 * Next status of main thread
dkato 0:ee40da884cfc 687 */
dkato 0:ee40da884cfc 688 static SYS_STATE state_proc_play_prepare_req(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 689 {
dkato 0:ee40da884cfc 690 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 691 bool result;
dkato 0:ee40da884cfc 692
dkato 0:ee40da884cfc 693 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 694 switch (event) {
dkato 0:ee40da884cfc 695 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 696 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 697 break;
dkato 2:d9fca8cd7f03 698 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 699 print_help_info();
dkato 2:d9fca8cd7f03 700 break;
1050186 4:2672de88a46b 701 case SYS_EV_KEY_MODE:
1050186 4:2672de88a46b 702 change_display_mode(&p_ctrl->play_info);
1050186 4:2672de88a46b 703 break;
dkato 0:ee40da884cfc 704 case SYS_EV_DEC_OPEN_COMP:
dkato 0:ee40da884cfc 705 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 706 result = exe_close_proc();
dkato 0:ee40da884cfc 707 if (result == true) {
dkato 0:ee40da884cfc 708 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 709 } else {
dkato 0:ee40da884cfc 710 /* Unexpected cases : This is fail-safe processing. */
1050186 4:2672de88a46b 711 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 712 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 713 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 714 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 715 } else {
dkato 0:ee40da884cfc 716 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 717 }
dkato 0:ee40da884cfc 718 }
dkato 0:ee40da884cfc 719 break;
dkato 0:ee40da884cfc 720 case SYS_EV_DEC_OPEN_COMP_ERR:
dkato 0:ee40da884cfc 721 /* Output error message to PC */
1050186 4:2672de88a46b 722 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 723 (void) dsp_notify_print_string(PRINT_MSG_DECODE_ERR);
dkato 0:ee40da884cfc 724 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 725 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 726 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 727 } else {
dkato 0:ee40da884cfc 728 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 729 }
dkato 0:ee40da884cfc 730 break;
dkato 0:ee40da884cfc 731 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 732 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 733 break;
dkato 0:ee40da884cfc 734 default:
dkato 0:ee40da884cfc 735 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 736 next_stat = stat;
dkato 0:ee40da884cfc 737 break;
dkato 0:ee40da884cfc 738 }
dkato 0:ee40da884cfc 739 }
dkato 0:ee40da884cfc 740 return next_stat;
dkato 0:ee40da884cfc 741 }
dkato 0:ee40da884cfc 742
dkato 0:ee40da884cfc 743 /** Executes the state transition processing in the state of SYS_ST_PLAY / SYS_ST_PAUSE.
dkato 0:ee40da884cfc 744 *
dkato 0:ee40da884cfc 745 * @param stat Status of main thread
dkato 0:ee40da884cfc 746 * @param event Event code of main thread
dkato 0:ee40da884cfc 747 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 748 *
dkato 0:ee40da884cfc 749 * @returns
dkato 0:ee40da884cfc 750 * Next status of main thread
dkato 0:ee40da884cfc 751 */
dkato 0:ee40da884cfc 752 static SYS_STATE state_proc_play_pause(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 753 {
dkato 0:ee40da884cfc 754 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 755 bool result;
dkato 0:ee40da884cfc 756
dkato 0:ee40da884cfc 757 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 758 switch (event) {
dkato 0:ee40da884cfc 759 case SYS_EV_KEY_STOP:
dkato 0:ee40da884cfc 760 result = exe_stop_proc();
dkato 0:ee40da884cfc 761 if (result == true) {
dkato 0:ee40da884cfc 762 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 763 }
dkato 0:ee40da884cfc 764 break;
dkato 0:ee40da884cfc 765 case SYS_EV_KEY_PLAY_PAUSE:
dkato 0:ee40da884cfc 766 if (stat == SYS_ST_PLAY) {
dkato 0:ee40da884cfc 767 (void) exe_pause_on_proc();
dkato 0:ee40da884cfc 768 } else {
dkato 0:ee40da884cfc 769 (void) exe_pause_off_proc();
dkato 0:ee40da884cfc 770 }
dkato 0:ee40da884cfc 771 break;
dkato 0:ee40da884cfc 772 case SYS_EV_KEY_NEXT:
dkato 0:ee40da884cfc 773 case SYS_EV_KEY_PREV:
dkato 0:ee40da884cfc 774 result = exe_stop_proc();
dkato 0:ee40da884cfc 775 if (result == true) {
dkato 0:ee40da884cfc 776 if (event == SYS_EV_KEY_PREV) {
dkato 0:ee40da884cfc 777 result = change_prev_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 778 } else {
dkato 0:ee40da884cfc 779 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 780 }
dkato 0:ee40da884cfc 781 if (result == true) {
dkato 0:ee40da884cfc 782 next_stat = SYS_ST_STOP_PREPARE_REQ;
dkato 0:ee40da884cfc 783 } else {
dkato 0:ee40da884cfc 784 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 785 }
dkato 0:ee40da884cfc 786 }
dkato 0:ee40da884cfc 787 break;
dkato 0:ee40da884cfc 788 case SYS_EV_KEY_PLAYINFO:
dkato 0:ee40da884cfc 789 print_play_info(&p_ctrl->play_info);
dkato 0:ee40da884cfc 790 break;
dkato 0:ee40da884cfc 791 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 792 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 793 break;
dkato 2:d9fca8cd7f03 794 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 795 print_help_info();
dkato 2:d9fca8cd7f03 796 break;
1050186 4:2672de88a46b 797 case SYS_EV_KEY_MODE:
1050186 4:2672de88a46b 798 change_display_mode(&p_ctrl->play_info);
1050186 4:2672de88a46b 799 break;
dkato 0:ee40da884cfc 800 case SYS_EV_STAT_STOP:
dkato 0:ee40da884cfc 801 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 802 result = exe_close_proc();
dkato 0:ee40da884cfc 803 if (result == true) {
dkato 0:ee40da884cfc 804 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 805 if (result == true) {
dkato 0:ee40da884cfc 806 next_stat = SYS_ST_STOP_PREPARE_REQ;
dkato 0:ee40da884cfc 807 } else {
dkato 0:ee40da884cfc 808 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 809 }
dkato 0:ee40da884cfc 810 } else {
dkato 0:ee40da884cfc 811 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 812 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 813 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 814 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 815 } else {
dkato 0:ee40da884cfc 816 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 817 }
dkato 0:ee40da884cfc 818 }
dkato 0:ee40da884cfc 819 break;
dkato 0:ee40da884cfc 820 case SYS_EV_STAT_PLAY:
dkato 0:ee40da884cfc 821 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 822 next_stat = SYS_ST_PLAY;
dkato 0:ee40da884cfc 823 break;
dkato 0:ee40da884cfc 824 case SYS_EV_STAT_PAUSE:
dkato 0:ee40da884cfc 825 print_play_time(&p_ctrl->play_info);
dkato 0:ee40da884cfc 826 next_stat = SYS_ST_PAUSE;
dkato 0:ee40da884cfc 827 break;
dkato 0:ee40da884cfc 828 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 829 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 830 result = exe_stop_proc();
dkato 0:ee40da884cfc 831 if (result == true) {
dkato 0:ee40da884cfc 832 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 833 } else {
dkato 0:ee40da884cfc 834 /* Unexpected cases : This is fail-safe processing. */
dkato 0:ee40da884cfc 835 /* In this case, main thread wait the notification of the stop status. */
dkato 0:ee40da884cfc 836 /* An error will occur by the disconnection of USB memory. */
dkato 0:ee40da884cfc 837 }
dkato 0:ee40da884cfc 838 break;
dkato 0:ee40da884cfc 839 default:
dkato 0:ee40da884cfc 840 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 841 next_stat = stat;
dkato 0:ee40da884cfc 842 break;
dkato 0:ee40da884cfc 843 }
dkato 0:ee40da884cfc 844 }
dkato 0:ee40da884cfc 845 return next_stat;
dkato 0:ee40da884cfc 846 }
dkato 0:ee40da884cfc 847
dkato 0:ee40da884cfc 848 /** Executes the state transition processing in the state of SYS_ST_STOP_PREPARE.
dkato 0:ee40da884cfc 849 *
dkato 0:ee40da884cfc 850 * @param stat Status of main thread
dkato 0:ee40da884cfc 851 * @param event Event code of main thread
dkato 0:ee40da884cfc 852 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 853 *
dkato 0:ee40da884cfc 854 * @returns
dkato 0:ee40da884cfc 855 * Next status of main thread
dkato 0:ee40da884cfc 856 */
dkato 0:ee40da884cfc 857 static SYS_STATE state_proc_stop_prepare(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 858 {
dkato 0:ee40da884cfc 859 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 860 bool result;
dkato 0:ee40da884cfc 861
dkato 0:ee40da884cfc 862 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 863 switch (event) {
dkato 0:ee40da884cfc 864 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 865 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 866 break;
dkato 2:d9fca8cd7f03 867 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 868 print_help_info();
dkato 2:d9fca8cd7f03 869 break;
1050186 4:2672de88a46b 870 case SYS_EV_KEY_MODE:
1050186 4:2672de88a46b 871 change_display_mode(&p_ctrl->play_info);
1050186 4:2672de88a46b 872 break;
dkato 0:ee40da884cfc 873 case SYS_EV_DEC_CLOSE_COMP:
1050186 4:2672de88a46b 874 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 875 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 876 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 877 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 878 } else {
dkato 0:ee40da884cfc 879 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 880 }
dkato 0:ee40da884cfc 881 break;
dkato 0:ee40da884cfc 882 case SYS_EV_STAT_STOP:
dkato 0:ee40da884cfc 883 result = exe_close_proc();
dkato 0:ee40da884cfc 884 if (result != true) {
dkato 0:ee40da884cfc 885 /* Unexpected cases : This is fail-safe processing. */
1050186 4:2672de88a46b 886 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 887 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 888 if (p_ctrl->usb_ctrl.usb_flag_detach == true) {
dkato 0:ee40da884cfc 889 next_stat = SYS_ST_WAIT_USB_CONNECT;
dkato 0:ee40da884cfc 890 } else {
dkato 0:ee40da884cfc 891 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 892 }
dkato 0:ee40da884cfc 893 }
dkato 0:ee40da884cfc 894 break;
dkato 0:ee40da884cfc 895 case SYS_EV_STAT_PLAY:
dkato 0:ee40da884cfc 896 case SYS_EV_STAT_PAUSE:
dkato 0:ee40da884cfc 897 break;
dkato 0:ee40da884cfc 898 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 899 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 900 break;
dkato 0:ee40da884cfc 901 default:
dkato 0:ee40da884cfc 902 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 903 next_stat = stat;
dkato 0:ee40da884cfc 904 break;
dkato 0:ee40da884cfc 905 }
dkato 0:ee40da884cfc 906 }
dkato 0:ee40da884cfc 907 return next_stat;
dkato 0:ee40da884cfc 908 }
dkato 0:ee40da884cfc 909
dkato 0:ee40da884cfc 910 /** Executes the state transition processing in the state of SYS_ST_STOP_PREPARE_REQ.
dkato 0:ee40da884cfc 911 *
dkato 0:ee40da884cfc 912 * @param stat Status of main thread
dkato 0:ee40da884cfc 913 * @param event Event code of main thread
dkato 0:ee40da884cfc 914 * @param p_ctrl Pointer to the control data of main thread
dkato 0:ee40da884cfc 915 *
dkato 0:ee40da884cfc 916 * @returns
dkato 0:ee40da884cfc 917 * Next status of main thread
dkato 0:ee40da884cfc 918 */
dkato 0:ee40da884cfc 919 static SYS_STATE state_proc_stop_prepare_req(const SYS_STATE stat, const SYS_EVENT event, sys_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 920 {
dkato 0:ee40da884cfc 921 SYS_STATE next_stat = stat;
dkato 0:ee40da884cfc 922 bool result;
dkato 0:ee40da884cfc 923
dkato 0:ee40da884cfc 924 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 925 switch (event) {
dkato 0:ee40da884cfc 926 case SYS_EV_KEY_STOP:
dkato 0:ee40da884cfc 927 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 928 break;
dkato 0:ee40da884cfc 929 case SYS_EV_KEY_NEXT:
dkato 0:ee40da884cfc 930 result = change_next_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 931 if (result != true) {
dkato 0:ee40da884cfc 932 /* Selected track was out of the playback range. */
dkato 0:ee40da884cfc 933 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 934 }
dkato 0:ee40da884cfc 935 break;
dkato 0:ee40da884cfc 936 case SYS_EV_KEY_PREV:
dkato 0:ee40da884cfc 937 result = change_prev_track(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 938 if (result != true) {
dkato 0:ee40da884cfc 939 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 940 }
dkato 0:ee40da884cfc 941 break;
dkato 0:ee40da884cfc 942 case SYS_EV_KEY_REPEAT:
dkato 0:ee40da884cfc 943 change_repeat_mode(&p_ctrl->play_info);
dkato 0:ee40da884cfc 944 break;
dkato 2:d9fca8cd7f03 945 case SYS_EV_KEY_HELP:
dkato 2:d9fca8cd7f03 946 print_help_info();
dkato 2:d9fca8cd7f03 947 break;
1050186 4:2672de88a46b 948 case SYS_EV_KEY_MODE:
1050186 4:2672de88a46b 949 change_display_mode(&p_ctrl->play_info);
1050186 4:2672de88a46b 950 break;
dkato 0:ee40da884cfc 951 case SYS_EV_DEC_CLOSE_COMP:
dkato 0:ee40da884cfc 952 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 953 print_file_name(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 954 result = exe_open_proc(&p_ctrl->play_info, &p_ctrl->scan_data);
dkato 0:ee40da884cfc 955 if (result == true) {
dkato 0:ee40da884cfc 956 next_stat = SYS_ST_PLAY_PREPARE;
dkato 0:ee40da884cfc 957 } else {
1050186 4:2672de88a46b 958 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 959 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 960 }
dkato 0:ee40da884cfc 961 break;
dkato 0:ee40da884cfc 962 case SYS_EV_STAT_STOP:
dkato 0:ee40da884cfc 963 result = exe_close_proc();
dkato 0:ee40da884cfc 964 if (result != true) {
dkato 0:ee40da884cfc 965 /* Unexpected cases : This is fail-safe processing. */
1050186 4:2672de88a46b 966 print_play_status(&p_ctrl->play_info);
dkato 0:ee40da884cfc 967 exe_end_proc(&p_ctrl->play_info);
dkato 0:ee40da884cfc 968 next_stat = SYS_ST_STOP;
dkato 0:ee40da884cfc 969 }
dkato 0:ee40da884cfc 970 break;
dkato 0:ee40da884cfc 971 case SYS_EV_STAT_PLAY:
dkato 0:ee40da884cfc 972 case SYS_EV_STAT_PAUSE:
dkato 0:ee40da884cfc 973 break;
dkato 0:ee40da884cfc 974 case SYS_EV_USB_DISCONNECT:
dkato 0:ee40da884cfc 975 p_ctrl->usb_ctrl.usb_flag_detach = true;
dkato 0:ee40da884cfc 976 next_stat = SYS_ST_STOP_PREPARE;
dkato 0:ee40da884cfc 977 break;
dkato 0:ee40da884cfc 978 default:
dkato 0:ee40da884cfc 979 /* Does not change the state. There is not the action. */
dkato 0:ee40da884cfc 980 next_stat = stat;
dkato 0:ee40da884cfc 981 break;
dkato 0:ee40da884cfc 982 }
dkato 0:ee40da884cfc 983 }
dkato 0:ee40da884cfc 984 return next_stat;
dkato 0:ee40da884cfc 985 }
dkato 0:ee40da884cfc 986
dkato 0:ee40da884cfc 987 /** Executes the scan of the folder structure
dkato 0:ee40da884cfc 988 *
dkato 0:ee40da884cfc 989 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 990 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 991 *
dkato 0:ee40da884cfc 992 * @returns
dkato 0:ee40da884cfc 993 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 994 */
dkato 0:ee40da884cfc 995 static bool exe_scan_folder_proc(play_info_t * const p_info, fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 996 {
dkato 0:ee40da884cfc 997 bool ret = false;
dkato 0:ee40da884cfc 998
dkato 0:ee40da884cfc 999 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1000 (void) fid_scan_folder_struct(p_data);
dkato 0:ee40da884cfc 1001 p_info->track_id = TRACK_ID_MIN;
dkato 0:ee40da884cfc 1002 ret = true;
dkato 0:ee40da884cfc 1003 }
dkato 0:ee40da884cfc 1004 return ret;
dkato 0:ee40da884cfc 1005 }
dkato 0:ee40da884cfc 1006
dkato 0:ee40da884cfc 1007 /** Executes the opening process
dkato 0:ee40da884cfc 1008 *
dkato 0:ee40da884cfc 1009 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1010 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1011 *
dkato 0:ee40da884cfc 1012 * @returns
dkato 0:ee40da884cfc 1013 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1014 */
dkato 0:ee40da884cfc 1015 static bool exe_open_proc(play_info_t * const p_info, fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1016 {
dkato 0:ee40da884cfc 1017 bool ret = false;
dkato 0:ee40da884cfc 1018 bool result;
dkato 0:ee40da884cfc 1019 FILE *fp;
dkato 0:ee40da884cfc 1020 uint32_t total_trk;
dkato 0:ee40da884cfc 1021
dkato 0:ee40da884cfc 1022 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1023 total_trk = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1024 if (p_info->track_id < total_trk) {
dkato 0:ee40da884cfc 1025 fp = fid_open_track(p_data, p_info->track_id);
dkato 0:ee40da884cfc 1026 if (fp != NULL) {
dkato 0:ee40da884cfc 1027 result = dec_open(fp, &open_callback);
dkato 0:ee40da884cfc 1028 if (result == true) {
dkato 0:ee40da884cfc 1029 /* Executes fid_close_track() in exe_end_proc(). */
dkato 0:ee40da884cfc 1030 p_info->p_file_handle = fp;
dkato 0:ee40da884cfc 1031 p_info->open_track_id = p_info->track_id;
dkato 0:ee40da884cfc 1032 ret = true;
dkato 0:ee40da884cfc 1033 } else {
dkato 0:ee40da884cfc 1034 /* The opening of the decoder was failure. */
dkato 0:ee40da884cfc 1035 fid_close_track(fp);
dkato 0:ee40da884cfc 1036 p_info->p_file_handle = NULL;
dkato 0:ee40da884cfc 1037 }
dkato 0:ee40da884cfc 1038 }
dkato 0:ee40da884cfc 1039 if (ret != true) {
dkato 0:ee40da884cfc 1040 print_play_time(p_info);
dkato 0:ee40da884cfc 1041 (void) dsp_notify_print_string(PRINT_MSG_OPEN_ERR);
dkato 0:ee40da884cfc 1042 /* Tries to open the next file. */
dkato 0:ee40da884cfc 1043 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 1044 (void) change_next_track(p_info, p_data);
dkato 0:ee40da884cfc 1045 }
dkato 0:ee40da884cfc 1046 }
dkato 0:ee40da884cfc 1047 }
dkato 0:ee40da884cfc 1048 return ret;
dkato 0:ee40da884cfc 1049 }
dkato 0:ee40da884cfc 1050
dkato 0:ee40da884cfc 1051 /** Executes the starting process of the playback
dkato 0:ee40da884cfc 1052 *
dkato 0:ee40da884cfc 1053 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1054 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1055 *
dkato 0:ee40da884cfc 1056 * @returns
dkato 0:ee40da884cfc 1057 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1058 */
dkato 0:ee40da884cfc 1059 static bool exe_play_proc(play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1060 {
dkato 0:ee40da884cfc 1061 bool ret = false;
dkato 0:ee40da884cfc 1062 bool result;
dkato 0:ee40da884cfc 1063
dkato 0:ee40da884cfc 1064 if (p_info != NULL) {
dkato 0:ee40da884cfc 1065 result = dec_play();
dkato 0:ee40da884cfc 1066 if (result == true) {
dkato 0:ee40da884cfc 1067 ret = true;
dkato 0:ee40da884cfc 1068 } else {
dkato 0:ee40da884cfc 1069 /* The starting of the playback was failure. */
dkato 0:ee40da884cfc 1070 print_play_time(p_info);
dkato 0:ee40da884cfc 1071 /* Tries to open the next file. */
dkato 0:ee40da884cfc 1072 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 1073 (void) change_next_track(p_info, p_data);
dkato 0:ee40da884cfc 1074 }
dkato 0:ee40da884cfc 1075 }
dkato 0:ee40da884cfc 1076 return ret;
dkato 0:ee40da884cfc 1077 }
dkato 0:ee40da884cfc 1078
dkato 0:ee40da884cfc 1079 /** Executes the starting process of the pause
dkato 0:ee40da884cfc 1080 *
dkato 0:ee40da884cfc 1081 * @returns
dkato 0:ee40da884cfc 1082 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1083 */
dkato 0:ee40da884cfc 1084 static bool exe_pause_on_proc(void)
dkato 0:ee40da884cfc 1085 {
dkato 0:ee40da884cfc 1086 bool ret;
dkato 0:ee40da884cfc 1087
dkato 0:ee40da884cfc 1088 ret = dec_pause_on();
dkato 0:ee40da884cfc 1089 return ret;
dkato 0:ee40da884cfc 1090 }
dkato 0:ee40da884cfc 1091
dkato 0:ee40da884cfc 1092 /** Executes the cancel process of the pause
dkato 0:ee40da884cfc 1093 *
dkato 0:ee40da884cfc 1094 * @returns
dkato 0:ee40da884cfc 1095 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1096 */
dkato 0:ee40da884cfc 1097 static bool exe_pause_off_proc(void)
dkato 0:ee40da884cfc 1098 {
dkato 0:ee40da884cfc 1099 bool ret;
dkato 0:ee40da884cfc 1100
dkato 0:ee40da884cfc 1101 ret = dec_pause_off();
dkato 0:ee40da884cfc 1102 return ret;
dkato 0:ee40da884cfc 1103 }
dkato 0:ee40da884cfc 1104
dkato 0:ee40da884cfc 1105 /** Executes the stop process of the playback
dkato 0:ee40da884cfc 1106 *
dkato 0:ee40da884cfc 1107 * @returns
dkato 0:ee40da884cfc 1108 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1109 */
dkato 0:ee40da884cfc 1110 static bool exe_stop_proc(void)
dkato 0:ee40da884cfc 1111 {
dkato 0:ee40da884cfc 1112 bool ret;
dkato 0:ee40da884cfc 1113
dkato 0:ee40da884cfc 1114 ret = dec_stop();
dkato 0:ee40da884cfc 1115 return ret;
dkato 0:ee40da884cfc 1116 }
dkato 0:ee40da884cfc 1117
dkato 0:ee40da884cfc 1118 /** Executes the closing process
dkato 0:ee40da884cfc 1119 *
dkato 0:ee40da884cfc 1120 * @returns
dkato 0:ee40da884cfc 1121 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1122 */
dkato 0:ee40da884cfc 1123 static bool exe_close_proc(void)
dkato 0:ee40da884cfc 1124 {
dkato 0:ee40da884cfc 1125 bool ret;
dkato 0:ee40da884cfc 1126
dkato 0:ee40da884cfc 1127 ret = dec_close(&close_callback);
dkato 0:ee40da884cfc 1128 return ret;
dkato 0:ee40da884cfc 1129 }
dkato 0:ee40da884cfc 1130
dkato 0:ee40da884cfc 1131 /** Executes the end process
dkato 0:ee40da884cfc 1132 *
dkato 0:ee40da884cfc 1133 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1134 */
dkato 0:ee40da884cfc 1135 static void exe_end_proc(play_info_t * const p_info)
dkato 0:ee40da884cfc 1136 {
dkato 0:ee40da884cfc 1137 if (p_info != NULL) {
dkato 0:ee40da884cfc 1138 fid_close_track(p_info->p_file_handle);
dkato 0:ee40da884cfc 1139 p_info->p_file_handle = NULL;
dkato 0:ee40da884cfc 1140 p_info->open_track_id = TRACK_ID_ERR;
dkato 0:ee40da884cfc 1141 }
dkato 0:ee40da884cfc 1142 }
dkato 0:ee40da884cfc 1143
dkato 0:ee40da884cfc 1144 /** Checks the track change
dkato 0:ee40da884cfc 1145 *
dkato 0:ee40da884cfc 1146 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1147 *
dkato 0:ee40da884cfc 1148 * @returns
dkato 0:ee40da884cfc 1149 * Results of check.
dkato 0:ee40da884cfc 1150 */
dkato 0:ee40da884cfc 1151 static bool is_track_changed(const play_info_t * const p_info)
dkato 0:ee40da884cfc 1152 {
dkato 0:ee40da884cfc 1153 bool ret = false;
dkato 0:ee40da884cfc 1154
dkato 0:ee40da884cfc 1155 if (p_info != NULL) {
dkato 0:ee40da884cfc 1156 if (p_info->track_id != p_info->open_track_id) {
dkato 0:ee40da884cfc 1157 ret = true;
dkato 0:ee40da884cfc 1158 }
dkato 0:ee40da884cfc 1159 }
dkato 0:ee40da884cfc 1160 return ret;
dkato 0:ee40da884cfc 1161 }
dkato 0:ee40da884cfc 1162
dkato 0:ee40da884cfc 1163 /** Changes the repeat mode
dkato 0:ee40da884cfc 1164 *
dkato 0:ee40da884cfc 1165 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1166 */
dkato 0:ee40da884cfc 1167 static void change_repeat_mode(play_info_t * const p_info)
dkato 0:ee40da884cfc 1168 {
dkato 0:ee40da884cfc 1169 if (p_info != NULL) {
dkato 0:ee40da884cfc 1170 if (p_info->repeat_mode == true) {
dkato 0:ee40da884cfc 1171 p_info->repeat_mode = false;
dkato 0:ee40da884cfc 1172 } else {
dkato 0:ee40da884cfc 1173 p_info->repeat_mode = true;
dkato 0:ee40da884cfc 1174 }
dkato 0:ee40da884cfc 1175 (void) dsp_notify_play_mode(p_info->repeat_mode);
dkato 0:ee40da884cfc 1176 }
dkato 0:ee40da884cfc 1177 }
dkato 0:ee40da884cfc 1178
dkato 0:ee40da884cfc 1179 /** Changes the next track
dkato 0:ee40da884cfc 1180 *
dkato 0:ee40da884cfc 1181 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1182 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1183 *
dkato 0:ee40da884cfc 1184 * @returns
dkato 0:ee40da884cfc 1185 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1186 */
dkato 0:ee40da884cfc 1187 static bool change_next_track(play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1188 {
dkato 0:ee40da884cfc 1189 bool ret = false;
dkato 0:ee40da884cfc 1190 uint32_t next_trk;
dkato 0:ee40da884cfc 1191 uint32_t total_trk;
dkato 0:ee40da884cfc 1192
dkato 0:ee40da884cfc 1193 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1194 next_trk = p_info->track_id + 1u;
dkato 0:ee40da884cfc 1195 total_trk = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1196 if (next_trk < total_trk) {
dkato 0:ee40da884cfc 1197 ret = true;
dkato 0:ee40da884cfc 1198 } else {
dkato 0:ee40da884cfc 1199 next_trk = 0;
dkato 0:ee40da884cfc 1200 if (p_info->repeat_mode == true) {
dkato 0:ee40da884cfc 1201 ret = true;
dkato 0:ee40da884cfc 1202 }
dkato 0:ee40da884cfc 1203 }
dkato 0:ee40da884cfc 1204 p_info->track_id = next_trk;
dkato 0:ee40da884cfc 1205 }
dkato 0:ee40da884cfc 1206 return ret;
dkato 0:ee40da884cfc 1207 }
dkato 0:ee40da884cfc 1208
dkato 0:ee40da884cfc 1209 /** Changes the previous track
dkato 0:ee40da884cfc 1210 *
dkato 0:ee40da884cfc 1211 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1212 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1213 *
dkato 0:ee40da884cfc 1214 * @returns
dkato 0:ee40da884cfc 1215 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1216 */
dkato 0:ee40da884cfc 1217 static bool change_prev_track(play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1218 {
dkato 0:ee40da884cfc 1219 bool ret = false;
dkato 0:ee40da884cfc 1220 uint32_t prev_trk;
dkato 0:ee40da884cfc 1221 uint32_t total_trk;
dkato 0:ee40da884cfc 1222
dkato 0:ee40da884cfc 1223 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1224 prev_trk = p_info->track_id - 1u;
dkato 0:ee40da884cfc 1225 total_trk = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1226 if (prev_trk < total_trk) {
dkato 0:ee40da884cfc 1227 ret = true;
dkato 0:ee40da884cfc 1228 } else {
dkato 0:ee40da884cfc 1229 if (p_info->repeat_mode == true) {
dkato 0:ee40da884cfc 1230 if (total_trk > 0u) {
dkato 0:ee40da884cfc 1231 ret = true;
dkato 0:ee40da884cfc 1232 prev_trk = total_trk - 1u;
dkato 0:ee40da884cfc 1233 } else {
dkato 0:ee40da884cfc 1234 prev_trk = 0u;
dkato 0:ee40da884cfc 1235 }
dkato 0:ee40da884cfc 1236 } else {
dkato 0:ee40da884cfc 1237 prev_trk = 0u;
dkato 0:ee40da884cfc 1238 }
dkato 0:ee40da884cfc 1239 }
dkato 0:ee40da884cfc 1240 p_info->track_id = prev_trk;
dkato 0:ee40da884cfc 1241 }
dkato 0:ee40da884cfc 1242 return ret;
dkato 0:ee40da884cfc 1243 }
dkato 0:ee40da884cfc 1244 /** Prints the playback information of the playback file
dkato 0:ee40da884cfc 1245 *
dkato 0:ee40da884cfc 1246 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1247 */
dkato 0:ee40da884cfc 1248 static void print_play_info(const play_info_t * const p_info)
dkato 0:ee40da884cfc 1249 {
dkato 0:ee40da884cfc 1250 uint32_t trk_id;
dkato 0:ee40da884cfc 1251
dkato 0:ee40da884cfc 1252 if (p_info != NULL) {
dkato 0:ee40da884cfc 1253 trk_id = convert_track_id(p_info->track_id);
dkato 0:ee40da884cfc 1254 (void) dsp_notify_play_info(trk_id, p_info->sample_rate, p_info->channel_num);
dkato 0:ee40da884cfc 1255 }
dkato 0:ee40da884cfc 1256 }
dkato 0:ee40da884cfc 1257
dkato 0:ee40da884cfc 1258 /** Prints the information of the playback time
dkato 0:ee40da884cfc 1259 *
dkato 0:ee40da884cfc 1260 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1261 */
dkato 0:ee40da884cfc 1262 static void print_play_time(const play_info_t * const p_info)
dkato 0:ee40da884cfc 1263 {
dkato 0:ee40da884cfc 1264 uint32_t trk_id;
dkato 0:ee40da884cfc 1265
dkato 0:ee40da884cfc 1266 if (p_info != NULL) {
dkato 0:ee40da884cfc 1267 trk_id = convert_track_id(p_info->track_id);
dkato 0:ee40da884cfc 1268 (void) dsp_notify_play_time(p_info->play_stat, trk_id,
dkato 0:ee40da884cfc 1269 p_info->play_time, p_info->total_time);
dkato 0:ee40da884cfc 1270 }
dkato 0:ee40da884cfc 1271 }
dkato 0:ee40da884cfc 1272
dkato 0:ee40da884cfc 1273 /** Prints the file name of the playback file
dkato 0:ee40da884cfc 1274 *
dkato 0:ee40da884cfc 1275 * @param p_info Pointer to the playback information of the playback file
dkato 0:ee40da884cfc 1276 * @param p_data Pointer to the control data of folder scan
dkato 0:ee40da884cfc 1277 */
dkato 0:ee40da884cfc 1278 static void print_file_name(const play_info_t * const p_info, const fid_scan_folder_t * const p_data)
dkato 0:ee40da884cfc 1279 {
dkato 0:ee40da884cfc 1280 const char_t *p_path;
dkato 0:ee40da884cfc 1281 uint32_t trk_id;
dkato 0:ee40da884cfc 1282 uint32_t trk_total;
dkato 0:ee40da884cfc 1283
dkato 0:ee40da884cfc 1284 if ((p_info != NULL) && (p_data != NULL)) {
dkato 0:ee40da884cfc 1285 trk_id = p_info->track_id;
dkato 0:ee40da884cfc 1286 trk_total = fid_get_total_track(p_data);
dkato 0:ee40da884cfc 1287 if (trk_id < trk_total) {
dkato 0:ee40da884cfc 1288 p_path = fid_get_track_name(p_data, trk_id);
dkato 0:ee40da884cfc 1289 (void) dsp_notify_file_name(p_path);
dkato 0:ee40da884cfc 1290 }
dkato 0:ee40da884cfc 1291 }
dkato 0:ee40da884cfc 1292 }
dkato 0:ee40da884cfc 1293
dkato 2:d9fca8cd7f03 1294 /** Prints the command help information
dkato 2:d9fca8cd7f03 1295 *
dkato 2:d9fca8cd7f03 1296 */
dkato 2:d9fca8cd7f03 1297 static void print_help_info(void)
dkato 2:d9fca8cd7f03 1298 {
dkato 2:d9fca8cd7f03 1299 (void) dsp_req_help();
dkato 2:d9fca8cd7f03 1300 }
dkato 2:d9fca8cd7f03 1301
1050186 4:2672de88a46b 1302 /** Prints the information of the playback status
1050186 4:2672de88a46b 1303 *
1050186 4:2672de88a46b 1304 * @param p_info Pointer to the playback information of the playback file
1050186 4:2672de88a46b 1305 */
1050186 4:2672de88a46b 1306 static void print_play_status(const play_info_t * const p_info)
1050186 4:2672de88a46b 1307 {
1050186 4:2672de88a46b 1308 if (p_info != NULL) {
1050186 4:2672de88a46b 1309 (void) dsp_notify_play_status(p_info->play_stat);
1050186 4:2672de88a46b 1310 }
1050186 4:2672de88a46b 1311 }
1050186 4:2672de88a46b 1312
1050186 4:2672de88a46b 1313 /** Changes the display mode of the TFT display.
1050186 4:2672de88a46b 1314 *
1050186 4:2672de88a46b 1315 * @param disp_mode Display mode before the change
1050186 4:2672de88a46b 1316 *
1050186 4:2672de88a46b 1317 * @returns
1050186 4:2672de88a46b 1318 * Display mode after changing
1050186 4:2672de88a46b 1319 */
1050186 4:2672de88a46b 1320 static void change_display_mode(play_info_t * const p_info)
1050186 4:2672de88a46b 1321 {
1050186 4:2672de88a46b 1322 if (p_info != NULL) {
1050186 4:2672de88a46b 1323 if (p_info->disp_mode < DSP_DISPMODE_3) {
1050186 4:2672de88a46b 1324 p_info->disp_mode++;
1050186 4:2672de88a46b 1325 } else {
1050186 4:2672de88a46b 1326 p_info->disp_mode = DSP_DISPMODE_1;
1050186 4:2672de88a46b 1327 }
1050186 4:2672de88a46b 1328 (void) dsp_notify_disp_mode(p_info->disp_mode);
1050186 4:2672de88a46b 1329 }
1050186 4:2672de88a46b 1330 }
1050186 4:2672de88a46b 1331
dkato 0:ee40da884cfc 1332 /** Converts the track ID of main thread into the track ID of display thread
dkato 0:ee40da884cfc 1333 *
dkato 0:ee40da884cfc 1334 * @param trk_id Track ID of main thread
dkato 0:ee40da884cfc 1335 *
dkato 0:ee40da884cfc 1336 * @returns
dkato 0:ee40da884cfc 1337 * Track ID of display thread
dkato 0:ee40da884cfc 1338 */
dkato 0:ee40da884cfc 1339 static uint32_t convert_track_id(const uint32_t trk_id)
dkato 0:ee40da884cfc 1340 {
dkato 0:ee40da884cfc 1341 uint32_t ret = 0u;
dkato 0:ee40da884cfc 1342
dkato 0:ee40da884cfc 1343 /* Track ID of main thread begins with 0. */
dkato 0:ee40da884cfc 1344 /* Converts the track ID of main thread into the track ID */
dkato 0:ee40da884cfc 1345 /* of the display thread beginning with 1. */
dkato 0:ee40da884cfc 1346 if (trk_id < SYS_MAX_TRACK_NUM) {
dkato 0:ee40da884cfc 1347 ret = trk_id + 1u;
dkato 0:ee40da884cfc 1348 }
dkato 0:ee40da884cfc 1349 return ret;
dkato 0:ee40da884cfc 1350 }
dkato 0:ee40da884cfc 1351
dkato 0:ee40da884cfc 1352 /** Sends the mail to main thread
dkato 0:ee40da884cfc 1353 *
dkato 0:ee40da884cfc 1354 * @param mail_id Mail ID
dkato 0:ee40da884cfc 1355 * @param param0 Parameter 0 of this mail
dkato 0:ee40da884cfc 1356 * @param param1 Parameter 1 of this mail
dkato 0:ee40da884cfc 1357 * @param param2 Parameter 2 of this mail
dkato 0:ee40da884cfc 1358 *
dkato 0:ee40da884cfc 1359 * @returns
dkato 0:ee40da884cfc 1360 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1361 */
dkato 0:ee40da884cfc 1362 static bool send_mail(const SYS_MAIL_ID mail_id, const uint32_t param0,
dkato 0:ee40da884cfc 1363 const uint32_t param1, const uint32_t param2)
dkato 0:ee40da884cfc 1364 {
dkato 0:ee40da884cfc 1365 bool ret = false;
dkato 0:ee40da884cfc 1366 osStatus stat;
dkato 0:ee40da884cfc 1367 sys_mail_t * const p_mail = mail_box.alloc();
dkato 0:ee40da884cfc 1368
dkato 0:ee40da884cfc 1369 if (p_mail != NULL) {
dkato 0:ee40da884cfc 1370 p_mail->mail_id = mail_id;
dkato 0:ee40da884cfc 1371 p_mail->param[MAIL_PARAM0] = param0;
dkato 0:ee40da884cfc 1372 p_mail->param[MAIL_PARAM1] = param1;
dkato 0:ee40da884cfc 1373 p_mail->param[MAIL_PARAM2] = param2;
dkato 0:ee40da884cfc 1374 stat = mail_box.put(p_mail);
dkato 0:ee40da884cfc 1375 if (stat == osOK) {
dkato 0:ee40da884cfc 1376 ret = true;
dkato 0:ee40da884cfc 1377 } else {
dkato 0:ee40da884cfc 1378 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 1379 }
dkato 0:ee40da884cfc 1380 }
dkato 0:ee40da884cfc 1381 return ret;
dkato 0:ee40da884cfc 1382 }
dkato 0:ee40da884cfc 1383
dkato 0:ee40da884cfc 1384 /** Receives the mail to main thread
dkato 0:ee40da884cfc 1385 *
dkato 0:ee40da884cfc 1386 * @param p_mail_id Pointer to the variable to store the mail ID
dkato 0:ee40da884cfc 1387 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
dkato 0:ee40da884cfc 1388 * @param p_param1 Pointer to the variable to store the parameter 1 of this mail
dkato 0:ee40da884cfc 1389 * @param p_param2 Pointer to the variable to store the parameter 2 of this mail
dkato 0:ee40da884cfc 1390 *
dkato 0:ee40da884cfc 1391 * @returns
dkato 0:ee40da884cfc 1392 * Results of process. true is success. false is failure.
dkato 0:ee40da884cfc 1393 */
dkato 0:ee40da884cfc 1394 static bool recv_mail(SYS_MAIL_ID * const p_mail_id, uint32_t * const p_param0,
dkato 0:ee40da884cfc 1395 uint32_t * const p_param1, uint32_t * const p_param2)
dkato 0:ee40da884cfc 1396 {
dkato 0:ee40da884cfc 1397 bool ret = false;
dkato 0:ee40da884cfc 1398 osEvent evt;
dkato 0:ee40da884cfc 1399 sys_mail_t *p_mail;
dkato 0:ee40da884cfc 1400
dkato 0:ee40da884cfc 1401 if ((p_mail_id != NULL) && (p_param0 != NULL) &&
dkato 0:ee40da884cfc 1402 (p_param1 != NULL) && (p_param2 != NULL)) {
dkato 0:ee40da884cfc 1403 evt = mail_box.get(RECV_MAIL_TIMEOUT_MS);
dkato 0:ee40da884cfc 1404 if (evt.status == osEventMail) {
dkato 0:ee40da884cfc 1405 p_mail = (sys_mail_t *)evt.value.p;
dkato 0:ee40da884cfc 1406 if (p_mail != NULL) {
dkato 0:ee40da884cfc 1407 *p_mail_id = p_mail->mail_id;
dkato 0:ee40da884cfc 1408 *p_param0 = p_mail->param[MAIL_PARAM0];
dkato 0:ee40da884cfc 1409 *p_param1 = p_mail->param[MAIL_PARAM1];
dkato 0:ee40da884cfc 1410 *p_param2 = p_mail->param[MAIL_PARAM2];
dkato 0:ee40da884cfc 1411 ret = true;
dkato 0:ee40da884cfc 1412 }
dkato 0:ee40da884cfc 1413 (void) mail_box.free(p_mail);
dkato 0:ee40da884cfc 1414 }
dkato 0:ee40da884cfc 1415 }
dkato 0:ee40da884cfc 1416 return ret;
dkato 0:ee40da884cfc 1417 }