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:
Osamu Nakamura
Date:
Tue Apr 11 12:42:10 2017 +0900
Revision:
6:a957aaa284f0
Parent:
5:25de5b925302
Update R-BSP from rev. cbb9d60c8748 to fb9eda52224e so that this program can be compiled with IAR toolchain.

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