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:
4:2672de88a46b
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"
dkato 0:ee40da884cfc 26 #include "misratypes.h"
dkato 0:ee40da884cfc 27
dkato 0:ee40da884cfc 28 #include "key.h"
dkato 0:ee40da884cfc 29 #include "key_cmd.h"
dkato 0:ee40da884cfc 30 #include "system.h"
1050186 4:2672de88a46b 31 #include "display.h"
1050186 4:2672de88a46b 32 #include "disp_tft.h"
1050186 4:2672de88a46b 33
1050186 4:2672de88a46b 34 /*--- Macro definition of mbed-rtos mail ---*/
1050186 4:2672de88a46b 35 #define MAIL_QUEUE_SIZE (3) /* Queue size */
1050186 4:2672de88a46b 36 #define MAIL_PARAM_NUM (1) /* Elements number of mail parameter array */
1050186 4:2672de88a46b 37
1050186 4:2672de88a46b 38 /* key_mail_t */
1050186 4:2672de88a46b 39 #define MAIL_PARAM0 (0) /* Index number of mail parameter array */
1050186 4:2672de88a46b 40
1050186 4:2672de88a46b 41 /* mail_id = KEY_MAILID_DISP_MODE */
1050186 4:2672de88a46b 42 #define MAIL_DISPMODE_MODE (MAIL_PARAM0) /* Display mode */
1050186 4:2672de88a46b 43
1050186 4:2672de88a46b 44 #define RECV_MAIL_TIMEOUT_MS (0u)
dkato 0:ee40da884cfc 45
dkato 0:ee40da884cfc 46 /*--- Macro definition of key thread ---*/
dkato 0:ee40da884cfc 47 #define PROC_CYCLE_SW (10u) /* The process cycle of SW module */
dkato 0:ee40da884cfc 48 #define PROC_CYCLE_TFT (50u) /* The process cycle of TFT module */
1050186 4:2672de88a46b 49 #define PROC_CYCLE_CMD (20u) /* The process cycle of command-line module */
dkato 0:ee40da884cfc 50 #define PROC_CYCLE_REFRESH (50u) /* Refresh cycle of counter */
dkato 0:ee40da884cfc 51 #define UNIT_TIME_MS (2u)
dkato 0:ee40da884cfc 52
dkato 0:ee40da884cfc 53 #define PROC_CNT_SW (PROC_CYCLE_SW / UNIT_TIME_MS) /* Counter for 10ms period */
dkato 0:ee40da884cfc 54 #define PROC_CNT_TFT (PROC_CYCLE_TFT / UNIT_TIME_MS) /* Counter for 50ms period */
dkato 0:ee40da884cfc 55 #define PROC_CNT_CMD (PROC_CYCLE_CMD / UNIT_TIME_MS) /* Counter for 2ms period */
dkato 0:ee40da884cfc 56 #define PROC_CNT_REFRESH (PROC_CYCLE_REFRESH / UNIT_TIME_MS) /* Counter for 50ms period */
dkato 0:ee40da884cfc 57
dkato 0:ee40da884cfc 58 /*--- Macro definition of SW module ---*/
dkato 0:ee40da884cfc 59 #define SW0_ACTIVE_LEVEL (0)
dkato 0:ee40da884cfc 60 #define SW0_DECISION_TIME (50u) /* Time until the decision of the input status. */
dkato 0:ee40da884cfc 61 #define SW0_DECISION_CNT (SW0_DECISION_TIME / PROC_CYCLE_SW) /* Counter for 50ms period */
dkato 0:ee40da884cfc 62
1050186 4:2672de88a46b 63 /*--- Macro definition of Touch panel module ---*/
1050186 4:2672de88a46b 64 #define TP_IIC_DEV_ADR (0x55 << 1) /* I2C device address */
1050186 4:2672de88a46b 65 #define TP_REG_ADR_NUM (6u) /* The number of the reading of the register. */
1050186 4:2672de88a46b 66
1050186 4:2672de88a46b 67 /* Register address */
1050186 4:2672de88a46b 68 #define TP_REG_ADR_FINGER (0u) /* Number of touch points[3:0] */
1050186 4:2672de88a46b 69 #define TP_REG_ADR_STATUS (2u) /* 1st Touch valid / 1st Touch X Position[11:8] / 1st Touch Y Position[11:8] */
1050186 4:2672de88a46b 70 #define TP_REG_ADR_TOUCH_XL (3u) /* 1st Touch X Position[7:0] */
1050186 4:2672de88a46b 71 #define TP_REG_ADR_TOUCH_YL (4u) /* 1st Touch Y Position[7:0] */
1050186 4:2672de88a46b 72
1050186 4:2672de88a46b 73 /* Mask for the register */
1050186 4:2672de88a46b 74 #define TP_MASK_FINGER (0x0Fu) /* Used in the finger register */
1050186 4:2672de88a46b 75 #define TP_MASK_TOUCH_YH (0x07u) /* Used in the status register for Y Position */
1050186 4:2672de88a46b 76 #define TP_MASK_TOUCH_XH (0x70u) /* Used in the status register for X Position */
1050186 4:2672de88a46b 77 #define TP_MASK_VALID (0x80u) /* Used in the status register for valid */
1050186 4:2672de88a46b 78
1050186 4:2672de88a46b 79 #define TP_SHIFT_TOUCH_YH (8u) /* Used in combination with the upper and lower bits of the Y position */
1050186 4:2672de88a46b 80 #define TP_SHIFT_TOUCH_XH (4u) /* Used in combination with the upper and lower bits of the X position */
1050186 4:2672de88a46b 81
1050186 4:2672de88a46b 82 #define TP_TOUCH_MAX_NUM (1u)
1050186 4:2672de88a46b 83 #define TP_DEFAULT_POS (0u)
1050186 4:2672de88a46b 84
1050186 4:2672de88a46b 85 #define TP_RELEASE_NUM (0u)
1050186 4:2672de88a46b 86 #define TP_PRESS_NUM (1u)
1050186 4:2672de88a46b 87
1050186 4:2672de88a46b 88 #define TP_MAX_WIDHT (DSP_TFT_WIDTH - 1u)
1050186 4:2672de88a46b 89 #define TP_MAX_HEIGHT (DSP_TFT_HEIGHT - 1u)
1050186 4:2672de88a46b 90
1050186 4:2672de88a46b 91 /*--- User defined types of mbed-rtos mail ---*/
1050186 4:2672de88a46b 92 typedef enum {
1050186 4:2672de88a46b 93 KEY_MAILID_DUMMY = 0,
1050186 4:2672de88a46b 94 KEY_MAILID_DISP_MODE, /* Change display mode */
1050186 4:2672de88a46b 95 KEY_MAILID_NUM
1050186 4:2672de88a46b 96 } KEY_MAIL_ID;
1050186 4:2672de88a46b 97
1050186 4:2672de88a46b 98 typedef struct {
1050186 4:2672de88a46b 99 KEY_MAIL_ID mail_id;
1050186 4:2672de88a46b 100 uint32_t param[MAIL_PARAM_NUM];
1050186 4:2672de88a46b 101 } key_mail_t;
1050186 4:2672de88a46b 102
dkato 0:ee40da884cfc 103 /*--- User defined types ---*/
dkato 0:ee40da884cfc 104 /* Control data of SW module */
dkato 0:ee40da884cfc 105 typedef struct {
dkato 0:ee40da884cfc 106 uint32_t sampling_count; /* Sampling count for decision of input. */
dkato 0:ee40da884cfc 107 bool current_status; /* Current input status. true=push, false=release. */
dkato 0:ee40da884cfc 108 } sw_ctrl_t;
dkato 0:ee40da884cfc 109
dkato 0:ee40da884cfc 110 /* Control data of TFT module */
dkato 0:ee40da884cfc 111 typedef struct {
1050186 4:2672de88a46b 112 uint32_t disp_mode;
1050186 4:2672de88a46b 113 SYS_KeyCode prev_key_event;
1050186 4:2672de88a46b 114 uint32_t prev_key_num;
dkato 0:ee40da884cfc 115 } tft_ctrl_t;
dkato 0:ee40da884cfc 116
dkato 0:ee40da884cfc 117 /* Control data of key thread */
dkato 0:ee40da884cfc 118 typedef struct {
dkato 0:ee40da884cfc 119 sw_ctrl_t sw_data;
dkato 0:ee40da884cfc 120 tft_ctrl_t tft_data;
dkato 0:ee40da884cfc 121 cmd_ctrl_t cmd_data;
dkato 0:ee40da884cfc 122 } key_ctrl_t;
dkato 0:ee40da884cfc 123
1050186 4:2672de88a46b 124 static Mail<key_mail_t, MAIL_QUEUE_SIZE> mail_box;
1050186 4:2672de88a46b 125
dkato 0:ee40da884cfc 126 static void sw_init_proc(sw_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 127 static SYS_KeyCode sw_main_proc(sw_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 128 static void tft_init_proc(tft_ctrl_t * const p_ctrl);
dkato 0:ee40da884cfc 129 static SYS_KeyCode tft_main_proc(tft_ctrl_t * const p_ctrl);
1050186 4:2672de88a46b 130 static bool tft_get_key_code(const uint32_t disp_mode, SYS_KeyCode * const p_key_ev, uint32_t * const p_key_num);
1050186 4:2672de88a46b 131 static bool send_mail(const KEY_MAIL_ID mail_id, const uint32_t param0);
1050186 4:2672de88a46b 132 static bool recv_mail(KEY_MAIL_ID * const p_mail_id, uint32_t * const p_param0);
dkato 0:ee40da884cfc 133
dkato 0:ee40da884cfc 134 void key_thread(void const *argument)
dkato 0:ee40da884cfc 135 {
dkato 0:ee40da884cfc 136 static key_ctrl_t key_data;
dkato 0:ee40da884cfc 137 SYS_KeyCode key_ev;
dkato 0:ee40da884cfc 138 SYS_KeyCode tmp_ev;
dkato 0:ee40da884cfc 139 uint32_t cnt = 0u;
1050186 4:2672de88a46b 140 KEY_MAIL_ID mail_type;
1050186 4:2672de88a46b 141 uint32_t mail_param[MAIL_PARAM_NUM];
1050186 4:2672de88a46b 142 bool result;
dkato 0:ee40da884cfc 143
dkato 0:ee40da884cfc 144 UNUSED_ARG(argument);
dkato 0:ee40da884cfc 145
dkato 0:ee40da884cfc 146 /* Initializes the control data of key thread. */
dkato 0:ee40da884cfc 147 sw_init_proc(&key_data.sw_data);
dkato 0:ee40da884cfc 148 tft_init_proc(&key_data.tft_data);
dkato 0:ee40da884cfc 149 cmd_init_proc(&key_data.cmd_data);
dkato 0:ee40da884cfc 150 while(1) {
dkato 0:ee40da884cfc 151 key_ev = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 152 result = recv_mail(&mail_type, &mail_param[MAIL_PARAM0]);
1050186 4:2672de88a46b 153 if (result == true) {
1050186 4:2672de88a46b 154 if (mail_type == KEY_MAILID_DISP_MODE) {
1050186 4:2672de88a46b 155 /* Changes display mode. */
1050186 4:2672de88a46b 156 key_data.tft_data.disp_mode = mail_param[MAIL_DISPMODE_MODE];
1050186 4:2672de88a46b 157 }
1050186 4:2672de88a46b 158 }
1050186 4:2672de88a46b 159
dkato 0:ee40da884cfc 160 /* Is it a timing of the SW module processing? */
dkato 0:ee40da884cfc 161 if((cnt % PROC_CNT_SW) == 0u) {
dkato 0:ee40da884cfc 162 /* Executes main process of SW module. */
dkato 0:ee40da884cfc 163 tmp_ev = sw_main_proc(&key_data.sw_data);
dkato 0:ee40da884cfc 164 if(tmp_ev != SYS_KEYCODE_NON) {
dkato 0:ee40da884cfc 165 key_ev = tmp_ev;
dkato 0:ee40da884cfc 166 }
dkato 0:ee40da884cfc 167 }
dkato 0:ee40da884cfc 168 /* Is it a timing of TFT module processing? */
dkato 0:ee40da884cfc 169 if((cnt % PROC_CNT_TFT) == 0u) {
dkato 0:ee40da884cfc 170 /* Executes main process of TFT module. */
dkato 0:ee40da884cfc 171 tmp_ev = tft_main_proc(&key_data.tft_data);
dkato 0:ee40da884cfc 172 if(tmp_ev != SYS_KEYCODE_NON) {
dkato 0:ee40da884cfc 173 if(key_ev == SYS_KEYCODE_NON) {
dkato 0:ee40da884cfc 174 /* There is no input from other modules. */
dkato 0:ee40da884cfc 175 key_ev = tmp_ev;
dkato 0:ee40da884cfc 176 }
dkato 0:ee40da884cfc 177 }
dkato 0:ee40da884cfc 178 }
dkato 0:ee40da884cfc 179 /* Is it a timing of command-line module processing? */
dkato 0:ee40da884cfc 180 if((cnt % PROC_CNT_CMD) == 0u) {
dkato 0:ee40da884cfc 181 /* Executes main process of command-line module. */
dkato 0:ee40da884cfc 182 tmp_ev = cmd_main_proc(&key_data.cmd_data);
dkato 0:ee40da884cfc 183 if(tmp_ev != SYS_KEYCODE_NON) {
dkato 0:ee40da884cfc 184 if(key_ev == SYS_KEYCODE_NON) {
dkato 0:ee40da884cfc 185 /* There is no input from other modules. */
dkato 0:ee40da884cfc 186 key_ev = tmp_ev;
dkato 0:ee40da884cfc 187 }
dkato 0:ee40da884cfc 188 }
dkato 0:ee40da884cfc 189 }
dkato 0:ee40da884cfc 190 /* Is it a refresh timing of the counter? */
dkato 0:ee40da884cfc 191 if(cnt >= PROC_CNT_REFRESH) {
dkato 0:ee40da884cfc 192 cnt = 0u;
dkato 0:ee40da884cfc 193 }
dkato 0:ee40da884cfc 194 /* When the event occurs, this mail is sent to main thread. */
dkato 0:ee40da884cfc 195 if(key_ev != SYS_KEYCODE_NON) {
dkato 0:ee40da884cfc 196 (void) sys_notify_key_input(key_ev);
dkato 0:ee40da884cfc 197 }
dkato 0:ee40da884cfc 198 Thread::wait(UNIT_TIME_MS);
dkato 0:ee40da884cfc 199 cnt++;
dkato 0:ee40da884cfc 200 }
dkato 0:ee40da884cfc 201 }
dkato 0:ee40da884cfc 202
1050186 4:2672de88a46b 203 bool key_notify_disp_mode(const uint32_t disp_mode)
1050186 4:2672de88a46b 204 {
1050186 4:2672de88a46b 205 bool ret = false;
1050186 4:2672de88a46b 206
1050186 4:2672de88a46b 207 ret = send_mail(KEY_MAILID_DISP_MODE, disp_mode);
1050186 4:2672de88a46b 208
1050186 4:2672de88a46b 209 return ret;
1050186 4:2672de88a46b 210 }
1050186 4:2672de88a46b 211
dkato 0:ee40da884cfc 212 /** Initialises SW module
dkato 0:ee40da884cfc 213 *
dkato 0:ee40da884cfc 214 * @param p_ctrl Pointer to the control data of SW module.
dkato 0:ee40da884cfc 215 */
dkato 0:ee40da884cfc 216 static void sw_init_proc(sw_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 217 {
dkato 0:ee40da884cfc 218 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 219 p_ctrl->sampling_count = 0u;
dkato 0:ee40da884cfc 220 p_ctrl->current_status = false;
dkato 0:ee40da884cfc 221 }
dkato 0:ee40da884cfc 222 }
dkato 0:ee40da884cfc 223
dkato 0:ee40da884cfc 224 /** Executes the main processing of SW module
dkato 0:ee40da884cfc 225 *
dkato 0:ee40da884cfc 226 * @param p_ctrl Pointer to the control data of SW module.
dkato 0:ee40da884cfc 227 *
dkato 0:ee40da884cfc 228 * @returns
dkato 0:ee40da884cfc 229 * Key code.
dkato 0:ee40da884cfc 230 */
dkato 0:ee40da884cfc 231 static SYS_KeyCode sw_main_proc(sw_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 232 {
dkato 0:ee40da884cfc 233 SYS_KeyCode key_ev = SYS_KEYCODE_NON;
dkato 0:ee40da884cfc 234 int32_t pin_level;
dkato 0:ee40da884cfc 235 static DigitalIn sw0(P6_0);
dkato 0:ee40da884cfc 236
dkato 0:ee40da884cfc 237 if (p_ctrl != NULL) {
dkato 0:ee40da884cfc 238 pin_level = sw0.read();
dkato 0:ee40da884cfc 239 if (pin_level == SW0_ACTIVE_LEVEL) {
dkato 0:ee40da884cfc 240 /* SW0 is pushed. */
dkato 0:ee40da884cfc 241 if (p_ctrl->sampling_count < SW0_DECISION_CNT) {
dkato 0:ee40da884cfc 242 p_ctrl->sampling_count++;
dkato 0:ee40da884cfc 243 if (p_ctrl->sampling_count == SW0_DECISION_CNT) {
dkato 0:ee40da884cfc 244 key_ev = SYS_KEYCODE_PLAYPAUSE;
dkato 0:ee40da884cfc 245 }
dkato 0:ee40da884cfc 246 }
dkato 0:ee40da884cfc 247 p_ctrl->current_status = true;
dkato 0:ee40da884cfc 248 } else {
dkato 0:ee40da884cfc 249 /* SW0 is released. */
dkato 0:ee40da884cfc 250 p_ctrl->sampling_count = 0u;
dkato 0:ee40da884cfc 251 p_ctrl->current_status = false;
dkato 0:ee40da884cfc 252 }
dkato 0:ee40da884cfc 253 }
dkato 0:ee40da884cfc 254 return key_ev;
dkato 0:ee40da884cfc 255 }
dkato 0:ee40da884cfc 256
dkato 0:ee40da884cfc 257 /** Initialises TFT module
dkato 0:ee40da884cfc 258 *
dkato 0:ee40da884cfc 259 * @param p_ctrl Pointer to the control data of TFT module.
dkato 0:ee40da884cfc 260 */
dkato 0:ee40da884cfc 261 static void tft_init_proc(tft_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 262 {
dkato 0:ee40da884cfc 263 if (p_ctrl != NULL) {
1050186 4:2672de88a46b 264 /* Initialization of the TFT key variables. */
1050186 4:2672de88a46b 265 /* Initializes it to a status pushing down an invalid key. */
1050186 4:2672de88a46b 266 /* This is to detect the edge of pushing down a key after having released all keys. */
1050186 4:2672de88a46b 267 p_ctrl->disp_mode = 0u;
1050186 4:2672de88a46b 268 p_ctrl->prev_key_event = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 269 p_ctrl->prev_key_num = TP_PRESS_NUM;
dkato 0:ee40da884cfc 270 }
dkato 0:ee40da884cfc 271 }
dkato 0:ee40da884cfc 272
dkato 0:ee40da884cfc 273 /** Executes the main processing of TFT module
dkato 0:ee40da884cfc 274 *
dkato 0:ee40da884cfc 275 * @param p_ctrl Pointer to the control data of TFT module.
dkato 0:ee40da884cfc 276 *
dkato 0:ee40da884cfc 277 * @returns
dkato 0:ee40da884cfc 278 * Key code.
dkato 0:ee40da884cfc 279 */
dkato 0:ee40da884cfc 280 static SYS_KeyCode tft_main_proc(tft_ctrl_t * const p_ctrl)
dkato 0:ee40da884cfc 281 {
dkato 0:ee40da884cfc 282 SYS_KeyCode key_ev = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 283 SYS_KeyCode cur_key_ev;
1050186 4:2672de88a46b 284 uint32_t cur_key_num;
1050186 4:2672de88a46b 285 bool result;
dkato 0:ee40da884cfc 286
dkato 0:ee40da884cfc 287 if (p_ctrl != NULL) {
1050186 4:2672de88a46b 288 result = tft_get_key_code(p_ctrl->disp_mode, &cur_key_ev, &cur_key_num);
1050186 4:2672de88a46b 289 if (result == true) {
1050186 4:2672de88a46b 290 if ((p_ctrl->prev_key_num == cur_key_num) &&
1050186 4:2672de88a46b 291 (p_ctrl->prev_key_event == cur_key_ev)) {
1050186 4:2672de88a46b 292 /* The touch position on the touch panel did not change. */
1050186 4:2672de88a46b 293 } else {
1050186 4:2672de88a46b 294 /* The touch position on the touch panel changed. */
1050186 4:2672de88a46b 295 if ((p_ctrl->prev_key_num == TP_RELEASE_NUM) && (cur_key_num == TP_PRESS_NUM)) {
1050186 4:2672de88a46b 296 /* Press check */
1050186 4:2672de88a46b 297 if (cur_key_ev != SYS_KEYCODE_NON) {
1050186 4:2672de88a46b 298 key_ev = cur_key_ev;
1050186 4:2672de88a46b 299 /* Notify the touched TFT key information. */
1050186 4:2672de88a46b 300 (void) dsp_notify_tft_key(key_ev);
1050186 4:2672de88a46b 301 }
1050186 4:2672de88a46b 302 p_ctrl->prev_key_event = cur_key_ev;
1050186 4:2672de88a46b 303 } else {
1050186 4:2672de88a46b 304 /* Release check */
1050186 4:2672de88a46b 305 key_ev = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 306 if (p_ctrl->prev_key_event != SYS_KEYCODE_NON) {
1050186 4:2672de88a46b 307 /* Notify the touched TFT key information. */
1050186 4:2672de88a46b 308 (void) dsp_notify_tft_key(key_ev);
1050186 4:2672de88a46b 309 }
1050186 4:2672de88a46b 310 p_ctrl->prev_key_event = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 311 }
1050186 4:2672de88a46b 312 }
1050186 4:2672de88a46b 313 p_ctrl->prev_key_num = cur_key_num;
1050186 4:2672de88a46b 314 } else {
1050186 4:2672de88a46b 315 p_ctrl->prev_key_event = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 316 p_ctrl->prev_key_num = 0u;
1050186 4:2672de88a46b 317 }
dkato 0:ee40da884cfc 318 }
dkato 0:ee40da884cfc 319 return key_ev;
dkato 0:ee40da884cfc 320 }
1050186 4:2672de88a46b 321
1050186 4:2672de88a46b 322 /** Gets the key code of the touch panel via IIC communication.
1050186 4:2672de88a46b 323 *
1050186 4:2672de88a46b 324 * @param disp_mode Display mode
1050186 4:2672de88a46b 325 * @param p_key_ev Pointer to variable to store the event code of the detected key
1050186 4:2672de88a46b 326 * @param p_key_num Pointer to variable to store the number of the detected key
1050186 4:2672de88a46b 327 *
1050186 4:2672de88a46b 328 * @returns
1050186 4:2672de88a46b 329 * Returns true if the API is successful. Returns false if the API fails.
1050186 4:2672de88a46b 330 */
1050186 4:2672de88a46b 331 static bool tft_get_key_code(const uint32_t disp_mode, SYS_KeyCode * const p_key_ev, uint32_t * const p_key_num)
1050186 4:2672de88a46b 332 {
1050186 4:2672de88a46b 333 bool ret = false;
1050186 4:2672de88a46b 334 SYS_KeyCode touch_ev;
1050186 4:2672de88a46b 335 uint32_t touch_num;
1050186 4:2672de88a46b 336 uint32_t valid;
1050186 4:2672de88a46b 337 uint32_t data_h;
1050186 4:2672de88a46b 338 uint32_t data_l;
1050186 4:2672de88a46b 339 uint32_t pos_x;
1050186 4:2672de88a46b 340 uint32_t pos_y;
1050186 4:2672de88a46b 341 int32_t i2c_err;
1050186 4:2672de88a46b 342 char_t tp_buf[TP_REG_ADR_NUM];
1050186 4:2672de88a46b 343 static I2C tft_i2c(I2C_SDA, I2C_SCL);
1050186 4:2672de88a46b 344
1050186 4:2672de88a46b 345 if ((p_key_ev != NULL) && (p_key_num != NULL)) {
1050186 4:2672de88a46b 346 i2c_err = tft_i2c.read(TP_IIC_DEV_ADR, tp_buf, sizeof(tp_buf));
1050186 4:2672de88a46b 347 if (i2c_err == 0) {
1050186 4:2672de88a46b 348 /* Touch num check */
1050186 4:2672de88a46b 349 touch_num = (uint32_t) tp_buf[TP_REG_ADR_FINGER] & TP_MASK_FINGER;
1050186 4:2672de88a46b 350 if (touch_num == TP_TOUCH_MAX_NUM) {
1050186 4:2672de88a46b 351 /* Valid check */
1050186 4:2672de88a46b 352 valid = (uint32_t) tp_buf[TP_REG_ADR_STATUS] & TP_MASK_VALID;
1050186 4:2672de88a46b 353 if (valid == TP_MASK_VALID) {
1050186 4:2672de88a46b 354 /* X position */
1050186 4:2672de88a46b 355 data_h = (uint32_t) tp_buf[TP_REG_ADR_STATUS] & TP_MASK_TOUCH_XH;
1050186 4:2672de88a46b 356 data_l = (uint32_t) tp_buf[TP_REG_ADR_TOUCH_XL];
1050186 4:2672de88a46b 357 pos_x = (data_h << TP_SHIFT_TOUCH_XH) | data_l;
1050186 4:2672de88a46b 358 /* Converts the touch position into TFT display position. */
1050186 4:2672de88a46b 359 if (pos_x > TP_MAX_WIDHT) {
1050186 4:2672de88a46b 360 pos_x = TP_DEFAULT_POS;
1050186 4:2672de88a46b 361 }
1050186 4:2672de88a46b 362
1050186 4:2672de88a46b 363 /* Y position */
1050186 4:2672de88a46b 364 data_h = (uint32_t) tp_buf[TP_REG_ADR_STATUS] & TP_MASK_TOUCH_YH;
1050186 4:2672de88a46b 365 data_l = (uint32_t) tp_buf[TP_REG_ADR_TOUCH_YL];
1050186 4:2672de88a46b 366 pos_y = (data_h << TP_SHIFT_TOUCH_YH) | data_l;
1050186 4:2672de88a46b 367 /* Converts the touch position into TFT display position. */
1050186 4:2672de88a46b 368 if (pos_y > TP_MAX_HEIGHT) {
1050186 4:2672de88a46b 369 pos_y = TP_DEFAULT_POS;
1050186 4:2672de88a46b 370 }
1050186 4:2672de88a46b 371
1050186 4:2672de88a46b 372 /* Converts TFT display position into the key code. */
1050186 4:2672de88a46b 373 touch_ev = dsp_convert_key(disp_mode, pos_x, pos_y);
1050186 4:2672de88a46b 374 } else {
1050186 4:2672de88a46b 375 touch_ev = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 376 }
1050186 4:2672de88a46b 377 } else {
1050186 4:2672de88a46b 378 touch_ev = SYS_KEYCODE_NON;
1050186 4:2672de88a46b 379 }
1050186 4:2672de88a46b 380 ret = true;
1050186 4:2672de88a46b 381 *p_key_ev = touch_ev;
1050186 4:2672de88a46b 382 *p_key_num = touch_num;
1050186 4:2672de88a46b 383 }
1050186 4:2672de88a46b 384 }
1050186 4:2672de88a46b 385
1050186 4:2672de88a46b 386 return ret;
1050186 4:2672de88a46b 387 }
1050186 4:2672de88a46b 388
1050186 4:2672de88a46b 389 /** Sends the mail to key thread
1050186 4:2672de88a46b 390 *
1050186 4:2672de88a46b 391 * @param mail_id Mail ID
1050186 4:2672de88a46b 392 * @param param0 Parameter 0 of this mail
1050186 4:2672de88a46b 393 *
1050186 4:2672de88a46b 394 * @returns
1050186 4:2672de88a46b 395 * Results of process. true is success. false is failure.
1050186 4:2672de88a46b 396 */
1050186 4:2672de88a46b 397 static bool send_mail(const KEY_MAIL_ID mail_id, const uint32_t param0)
1050186 4:2672de88a46b 398 {
1050186 4:2672de88a46b 399 bool ret = false;
1050186 4:2672de88a46b 400 osStatus stat;
1050186 4:2672de88a46b 401 key_mail_t * const p_mail = mail_box.alloc();
1050186 4:2672de88a46b 402
1050186 4:2672de88a46b 403 if (p_mail != NULL) {
1050186 4:2672de88a46b 404 p_mail->mail_id = mail_id;
1050186 4:2672de88a46b 405 p_mail->param[MAIL_PARAM0] = param0;
1050186 4:2672de88a46b 406 stat = mail_box.put(p_mail);
1050186 4:2672de88a46b 407 if (stat == osOK) {
1050186 4:2672de88a46b 408 ret = true;
1050186 4:2672de88a46b 409 } else {
1050186 4:2672de88a46b 410 (void) mail_box.free(p_mail);
1050186 4:2672de88a46b 411 }
1050186 4:2672de88a46b 412 }
1050186 4:2672de88a46b 413 return ret;
1050186 4:2672de88a46b 414 }
1050186 4:2672de88a46b 415
1050186 4:2672de88a46b 416 /** Receives the mail to key thread
1050186 4:2672de88a46b 417 *
1050186 4:2672de88a46b 418 * @param p_mail_id Pointer to the variable to store the mail ID
1050186 4:2672de88a46b 419 * @param p_param0 Pointer to the variable to store the parameter 0 of this mail
1050186 4:2672de88a46b 420 *
1050186 4:2672de88a46b 421 * @returns
1050186 4:2672de88a46b 422 * Results of process. true is success. false is failure.
1050186 4:2672de88a46b 423 */
1050186 4:2672de88a46b 424 static bool recv_mail(KEY_MAIL_ID * const p_mail_id, uint32_t * const p_param0)
1050186 4:2672de88a46b 425 {
1050186 4:2672de88a46b 426 bool ret = false;
1050186 4:2672de88a46b 427 osEvent evt;
1050186 4:2672de88a46b 428 key_mail_t *p_mail;
1050186 4:2672de88a46b 429
1050186 4:2672de88a46b 430 if ((p_mail_id != NULL) && (p_param0 != NULL)) {
1050186 4:2672de88a46b 431 evt = mail_box.get(RECV_MAIL_TIMEOUT_MS);
1050186 4:2672de88a46b 432 if (evt.status == osEventMail) {
1050186 4:2672de88a46b 433 p_mail = (key_mail_t *)evt.value.p;
1050186 4:2672de88a46b 434 if (p_mail != NULL) {
1050186 4:2672de88a46b 435 *p_mail_id = p_mail->mail_id;
1050186 4:2672de88a46b 436 *p_param0 = p_mail->param[MAIL_PARAM0];
1050186 4:2672de88a46b 437 ret = true;
1050186 4:2672de88a46b 438 }
1050186 4:2672de88a46b 439 (void) mail_box.free(p_mail);
1050186 4:2672de88a46b 440 }
1050186 4:2672de88a46b 441 }
1050186 4:2672de88a46b 442 return ret;
1050186 4:2672de88a46b 443 }