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
1050186 4:2672de88a46b 1 /*******************************************************************************
1050186 4:2672de88a46b 2 * DISCLAIMER
1050186 4:2672de88a46b 3 * This software is supplied by Renesas Electronics Corporation and is only
1050186 4:2672de88a46b 4 * intended for use with Renesas products. No other uses are authorized. This
1050186 4:2672de88a46b 5 * software is owned by Renesas Electronics Corporation and is protected under
1050186 4:2672de88a46b 6 * all applicable laws, including copyright laws.
1050186 4:2672de88a46b 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
1050186 4:2672de88a46b 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
1050186 4:2672de88a46b 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
1050186 4:2672de88a46b 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
1050186 4:2672de88a46b 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
1050186 4:2672de88a46b 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
1050186 4:2672de88a46b 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
1050186 4:2672de88a46b 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
1050186 4:2672de88a46b 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
1050186 4:2672de88a46b 16 * Renesas reserves the right, without notice, to make changes to this software
1050186 4:2672de88a46b 17 * and to discontinue the availability of this software. By using this software,
1050186 4:2672de88a46b 18 * you agree to the additional terms and conditions found by accessing the
1050186 4:2672de88a46b 19 * following link:
1050186 4:2672de88a46b 20 * http://www.renesas.com/disclaimer*
1050186 4:2672de88a46b 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
1050186 4:2672de88a46b 22 *******************************************************************************/
1050186 4:2672de88a46b 23
1050186 4:2672de88a46b 24 #include "misratypes.h"
1050186 4:2672de88a46b 25 #include "display.h"
1050186 4:2672de88a46b 26 #include "disp_graphics.h"
1050186 4:2672de88a46b 27 #include "img_tbl.h"
1050186 4:2672de88a46b 28
1050186 4:2672de88a46b 29 /*--- Macro definition ---*/
1050186 4:2672de88a46b 30 /* The number of bytes per pixel. */
1050186 4:2672de88a46b 31 #define BYTENUM_PER_PIXEL_ARGB8888 (4u) /* ARGB8888 : 1pixel = 4byte */
1050186 4:2672de88a46b 32 #define BYTENUM_PER_PIXEL_RGB888 (3u) /* RGB888 : 1pixel = 3byte */
1050186 4:2672de88a46b 33
1050186 4:2672de88a46b 34 /* Alpha blend */
1050186 4:2672de88a46b 35 /* Minimum value of alpha blend. */
1050186 4:2672de88a46b 36 #define BLEND_MIN_VAL_ARGB8888 (0x00u)
1050186 4:2672de88a46b 37 /* Maximum value of alpha blend. */
1050186 4:2672de88a46b 38 #define BLEND_MAX_VAL_ARGB8888 (0xFFu)
1050186 4:2672de88a46b 39 /* In the case of this value, the background color is not blended. */
1050186 4:2672de88a46b 40 #define NOT_BLEND_VAL_ARGB8888 (BLEND_MAX_VAL_ARGB8888)
1050186 4:2672de88a46b 41
1050186 4:2672de88a46b 42 #define SHIFT_1BIT_SIZE (1u)
1050186 4:2672de88a46b 43 #define SHIFT_1BYTE_SIZE (8u)
1050186 4:2672de88a46b 44 #define SHIFT_2BYTE_SIZE (16u)
1050186 4:2672de88a46b 45 #define SHIFT_3BYTE_SIZE (24u)
1050186 4:2672de88a46b 46
1050186 4:2672de88a46b 47 #define MASK_BIT_SIZE (0x01u)
1050186 4:2672de88a46b 48 #define MASK_BYTE_SIZE (0xFFu)
1050186 4:2672de88a46b 49
1050186 4:2672de88a46b 50 #define MAX_LOOP_NUM (128) /* fail-safe processing. */
1050186 4:2672de88a46b 51
1050186 4:2672de88a46b 52 #define COL_CLEAR (0x00000000u)
1050186 4:2672de88a46b 53
1050186 4:2672de88a46b 54 typedef uint32_t (*blend_func_t)(const uint32_t bg_col, const uint32_t fg_col);
1050186 4:2672de88a46b 55
1050186 4:2672de88a46b 56 static void set_bmp_rgb888(const dsp_tftlayer_t * const p_info,
1050186 4:2672de88a46b 57 const int32_t start_x, const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf);
1050186 4:2672de88a46b 58 static void set_bmp_argb8888(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 59 const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf, const blend_func_t p_func);
1050186 4:2672de88a46b 60 static uint32_t alpha_blend(const uint32_t bg_col, const uint32_t fg_col);
1050186 4:2672de88a46b 61 static uint32_t get_fg_col(const uint32_t bg_col, const uint32_t fg_col);
1050186 4:2672de88a46b 62 static void set_font(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 63 const int32_t start_y, const uint32_t * const font_data,
1050186 4:2672de88a46b 64 const uint32_t font_width, const uint32_t font_height);
1050186 4:2672de88a46b 65
1050186 4:2672de88a46b 66 void dsp_clear_all(const dsp_tftlayer_t * const p_info)
1050186 4:2672de88a46b 67 {
1050186 4:2672de88a46b 68 if (p_info != NULL) {
1050186 4:2672de88a46b 69 dsp_clear_area(p_info, 0, 0, (int32_t)p_info->width, (int32_t)p_info->height);
1050186 4:2672de88a46b 70 }
1050186 4:2672de88a46b 71 }
1050186 4:2672de88a46b 72
1050186 4:2672de88a46b 73 void dsp_clear_area(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 74 const int32_t start_y, const int32_t size_x, const int32_t size_y)
1050186 4:2672de88a46b 75 {
1050186 4:2672de88a46b 76 if (p_info != NULL) {
1050186 4:2672de88a46b 77 dsp_fill_rect(p_info, start_x, start_y, size_x, size_y, COL_CLEAR);
1050186 4:2672de88a46b 78 }
1050186 4:2672de88a46b 79 }
1050186 4:2672de88a46b 80
1050186 4:2672de88a46b 81 void dsp_draw_picture(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 82 const int32_t start_y, const int32_t pict_id, const int32_t pict_type)
1050186 4:2672de88a46b 83 {
1050186 4:2672de88a46b 84 int32_t type;
1050186 4:2672de88a46b 85
1050186 4:2672de88a46b 86 if ((p_info != NULL) && (pict_id >= 0) && (pict_id < DSP_IMG_TBL_SIZE)) {
1050186 4:2672de88a46b 87 if (pict_type == DSP_IMG_FORM_AUTOSEL) {
1050186 4:2672de88a46b 88 type = dsp_bitmap_tbl[pict_id].image_type;
1050186 4:2672de88a46b 89 } else {
1050186 4:2672de88a46b 90 type = pict_type;
1050186 4:2672de88a46b 91 }
1050186 4:2672de88a46b 92
1050186 4:2672de88a46b 93 switch (type) {
1050186 4:2672de88a46b 94 case DSP_IMG_FORM_RGB888:
1050186 4:2672de88a46b 95 set_bmp_rgb888(p_info, start_x, start_y, &dsp_bitmap_tbl[pict_id]);
1050186 4:2672de88a46b 96 break;
1050186 4:2672de88a46b 97 case DSP_IMG_FORM_ARGB8888_NO_BLEND:
1050186 4:2672de88a46b 98 set_bmp_argb8888(p_info, start_x, start_y, &dsp_bitmap_tbl[pict_id], &get_fg_col);
1050186 4:2672de88a46b 99 break;
1050186 4:2672de88a46b 100 case DSP_IMG_FORM_ARGB8888:
1050186 4:2672de88a46b 101 default:
1050186 4:2672de88a46b 102 set_bmp_argb8888(p_info, start_x, start_y, &dsp_bitmap_tbl[pict_id], &alpha_blend);
1050186 4:2672de88a46b 103 break;
1050186 4:2672de88a46b 104 }
1050186 4:2672de88a46b 105 }
1050186 4:2672de88a46b 106 return;
1050186 4:2672de88a46b 107 }
1050186 4:2672de88a46b 108
1050186 4:2672de88a46b 109 void dsp_fill_rect(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 110 const int32_t start_y, const int32_t size_x, const int32_t size_y, const uint32_t fg_col)
1050186 4:2672de88a46b 111 {
1050186 4:2672de88a46b 112 uint32_t *p_buff; /* Pointer to VRAM. */
1050186 4:2672de88a46b 113 uint32_t stride_pix; /* The horizontal number of bytes in VRAM. */
1050186 4:2672de88a46b 114 int32_t pos_x; /* The X position in VRAM. */
1050186 4:2672de88a46b 115 int32_t pos_y; /* The Y position in VRAM. */
1050186 4:2672de88a46b 116
1050186 4:2672de88a46b 117 if (p_info != NULL) {
1050186 4:2672de88a46b 118 /* Calculates the horizontal number of bytes. */
1050186 4:2672de88a46b 119 /* The horizontal number of bytes is a multiple of 4. */
1050186 4:2672de88a46b 120 /* VRAM */
1050186 4:2672de88a46b 121 stride_pix = p_info->stride / sizeof(uint32_t);
1050186 4:2672de88a46b 122 for (pos_y = start_y; pos_y < (start_y + size_y); pos_y++) {
1050186 4:2672de88a46b 123 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) {
1050186 4:2672de88a46b 124 /* Sets the position of (0, pos_y) in VRAM. */
1050186 4:2672de88a46b 125 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y];
1050186 4:2672de88a46b 126 for (pos_x = start_x; pos_x < (start_x + size_x); pos_x++) {
1050186 4:2672de88a46b 127 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) {
1050186 4:2672de88a46b 128 p_buff[pos_x] = fg_col;
1050186 4:2672de88a46b 129 }
1050186 4:2672de88a46b 130 }
1050186 4:2672de88a46b 131 }
1050186 4:2672de88a46b 132 }
1050186 4:2672de88a46b 133 }
1050186 4:2672de88a46b 134 return;
1050186 4:2672de88a46b 135 }
1050186 4:2672de88a46b 136
1050186 4:2672de88a46b 137 void dsp_draw_text30x34(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 138 const int32_t start_y, const char_t * const p_str)
1050186 4:2672de88a46b 139 {
1050186 4:2672de88a46b 140 const uint32_t *p_font_data;
1050186 4:2672de88a46b 141 int32_t str_index;
1050186 4:2672de88a46b 142 int32_t i;
1050186 4:2672de88a46b 143 int32_t pos_x;
1050186 4:2672de88a46b 144 const int32_t pos_y = start_y;
1050186 4:2672de88a46b 145 const uint32_t pos_x_offset = DSP_IMG_WS_FONT30X34;
1050186 4:2672de88a46b 146 uint32_t chr_code;
1050186 4:2672de88a46b 147 const dsp_fntinf_t *p_font_info;
1050186 4:2672de88a46b 148
1050186 4:2672de88a46b 149 if ((p_info != NULL) && (p_str != NULL)) {
1050186 4:2672de88a46b 150 str_index = 0;
1050186 4:2672de88a46b 151 pos_x = start_x;
1050186 4:2672de88a46b 152 while ((str_index < MAX_LOOP_NUM) && ((int32_t)p_str[str_index] != '\0')) {
1050186 4:2672de88a46b 153 chr_code = (uint32_t)p_str[str_index];
1050186 4:2672de88a46b 154 for (i = 0; i < (int32_t)(sizeof(dsp_img_fonttbl30x34)/sizeof(dsp_img_fonttbl30x34[0])); i++) {
1050186 4:2672de88a46b 155 p_font_info = &dsp_img_fonttbl30x34[i];
1050186 4:2672de88a46b 156 if ((chr_code >= p_font_info->start_char) && (chr_code <= p_font_info->end_char)) {
1050186 4:2672de88a46b 157 p_font_data = &p_font_info->p_font[(chr_code - p_font_info->start_char) * DSP_IMG_HS_FONT30X34];
1050186 4:2672de88a46b 158 set_font(p_info, pos_x, pos_y, p_font_data, DSP_IMG_WS_FONT30X34, DSP_IMG_HS_FONT30X34);
1050186 4:2672de88a46b 159 }
1050186 4:2672de88a46b 160 }
1050186 4:2672de88a46b 161 pos_x += (int32_t)pos_x_offset;
1050186 4:2672de88a46b 162 str_index ++;
1050186 4:2672de88a46b 163 }
1050186 4:2672de88a46b 164 }
1050186 4:2672de88a46b 165 }
1050186 4:2672de88a46b 166
1050186 4:2672de88a46b 167 void dsp_draw_text15x17(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 168 const int32_t start_y, const char_t * const p_str)
1050186 4:2672de88a46b 169 {
1050186 4:2672de88a46b 170 const uint32_t *p_font_data;
1050186 4:2672de88a46b 171 int32_t str_index;
1050186 4:2672de88a46b 172 int32_t i;
1050186 4:2672de88a46b 173 int32_t pos_x;
1050186 4:2672de88a46b 174 const int32_t pos_y = start_y;
1050186 4:2672de88a46b 175 const uint32_t pos_x_offset = DSP_IMG_WS_FONT15X17;
1050186 4:2672de88a46b 176 uint32_t chr_code;
1050186 4:2672de88a46b 177 const dsp_fntinf_t *p_font_info;
1050186 4:2672de88a46b 178
1050186 4:2672de88a46b 179 if ((p_info != NULL) && (p_str != NULL)) {
1050186 4:2672de88a46b 180 str_index = 0;
1050186 4:2672de88a46b 181 pos_x = start_x;
1050186 4:2672de88a46b 182 while ((str_index < MAX_LOOP_NUM) && ((int32_t)p_str[str_index] != '\0')) {
1050186 4:2672de88a46b 183 chr_code = (uint32_t)p_str[str_index];
1050186 4:2672de88a46b 184 for (i = 0; i < (int32_t)(sizeof(dsp_img_fonttbl15x17)/sizeof(dsp_img_fonttbl15x17[0])); i++) {
1050186 4:2672de88a46b 185 p_font_info = &dsp_img_fonttbl15x17[i];
1050186 4:2672de88a46b 186 if ((chr_code >= p_font_info->start_char) && (chr_code <= p_font_info->end_char)) {
1050186 4:2672de88a46b 187 p_font_data = &p_font_info->p_font[(chr_code - p_font_info->start_char) * DSP_IMG_HS_FONT15X17];
1050186 4:2672de88a46b 188 set_font(p_info, pos_x, pos_y, p_font_data, DSP_IMG_WS_FONT15X17, DSP_IMG_HS_FONT15X17);
1050186 4:2672de88a46b 189 }
1050186 4:2672de88a46b 190 }
1050186 4:2672de88a46b 191 pos_x += (int32_t)pos_x_offset;
1050186 4:2672de88a46b 192 str_index ++;
1050186 4:2672de88a46b 193 }
1050186 4:2672de88a46b 194 }
1050186 4:2672de88a46b 195 }
1050186 4:2672de88a46b 196
1050186 4:2672de88a46b 197 /** Draws BMP image of the RGB888 format in VRAM.
1050186 4:2672de88a46b 198 *
1050186 4:2672de88a46b 199 * @param p_info Pointer to VRAM structure
1050186 4:2672de88a46b 200 * @param start_x Display position X of BMP image
1050186 4:2672de88a46b 201 * @param start_y Display position Y of BMP image
1050186 4:2672de88a46b 202 * @param p_bmpinf Pointer to information of BMP image
1050186 4:2672de88a46b 203 */
1050186 4:2672de88a46b 204 static void set_bmp_rgb888(const dsp_tftlayer_t * const p_info,
1050186 4:2672de88a46b 205 const int32_t start_x, const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf)
1050186 4:2672de88a46b 206 {
1050186 4:2672de88a46b 207 uint32_t *p_buff; /* Pointer to VRAM. */
1050186 4:2672de88a46b 208 uint32_t stride_pix; /* The horizontal number of bytes in VRAM. */
1050186 4:2672de88a46b 209 int32_t pos_x; /* The X position in VRAM. */
1050186 4:2672de88a46b 210 int32_t pos_y; /* The Y position in VRAM. */
1050186 4:2672de88a46b 211 const uint8_t *p_img; /* Pointer to BMP image. */
1050186 4:2672de88a46b 212 uint32_t img_h_byte; /* The horizontal number of bytes in the BMP image. */
1050186 4:2672de88a46b 213 uint32_t img_index;
1050186 4:2672de88a46b 214 uint32_t cnt;
1050186 4:2672de88a46b 215 uint32_t shift_num;
1050186 4:2672de88a46b 216 uint32_t col_data;
1050186 4:2672de88a46b 217
1050186 4:2672de88a46b 218 if ((p_info != NULL) && (p_bmpinf != NULL)) {
1050186 4:2672de88a46b 219 /* Calculates the horizontal number of bytes. */
1050186 4:2672de88a46b 220 /* The horizontal number of bytes is a multiple of 4. */
1050186 4:2672de88a46b 221 /* VRAM */
1050186 4:2672de88a46b 222 stride_pix = p_info->stride / sizeof(uint32_t);
1050186 4:2672de88a46b 223 /* BMP image */
1050186 4:2672de88a46b 224 img_h_byte = (((BYTENUM_PER_PIXEL_RGB888 * p_bmpinf->size_x) +
1050186 4:2672de88a46b 225 (sizeof(uint32_t) - 1u)) / sizeof(uint32_t)) * sizeof(uint32_t);
1050186 4:2672de88a46b 226 for (pos_y = start_y; pos_y < (start_y + (int32_t)p_bmpinf->size_y); pos_y++) {
1050186 4:2672de88a46b 227 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) {
1050186 4:2672de88a46b 228 /* Sets the position of (0, pos_y) in VRAM. */
1050186 4:2672de88a46b 229 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y];
1050186 4:2672de88a46b 230 /* Sets the position of (start_x, pos_y) in BMP image. */
1050186 4:2672de88a46b 231 p_img = &p_bmpinf->p_image[img_h_byte * ((p_bmpinf->size_y - 1u) - (uint32_t)(pos_y - start_y))];
1050186 4:2672de88a46b 232 img_index = 0u;
1050186 4:2672de88a46b 233 for (pos_x = start_x; pos_x < (start_x + (int32_t)p_bmpinf->size_x); pos_x++) {
1050186 4:2672de88a46b 234 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) {
1050186 4:2672de88a46b 235 col_data = BLEND_MAX_VAL_ARGB8888 << SHIFT_3BYTE_SIZE;
1050186 4:2672de88a46b 236 shift_num = 0u;
1050186 4:2672de88a46b 237 for (cnt = 0u; cnt < BYTENUM_PER_PIXEL_RGB888; cnt++) {
1050186 4:2672de88a46b 238 col_data |= ((uint32_t)p_img[img_index + cnt] << shift_num);
1050186 4:2672de88a46b 239 shift_num += SHIFT_1BYTE_SIZE;
1050186 4:2672de88a46b 240 }
1050186 4:2672de88a46b 241 p_buff[pos_x] = col_data;
1050186 4:2672de88a46b 242 }
1050186 4:2672de88a46b 243 img_index += BYTENUM_PER_PIXEL_RGB888;
1050186 4:2672de88a46b 244 }
1050186 4:2672de88a46b 245 }
1050186 4:2672de88a46b 246 }
1050186 4:2672de88a46b 247 }
1050186 4:2672de88a46b 248 }
1050186 4:2672de88a46b 249
1050186 4:2672de88a46b 250 /** Draws BMP image of the ARGB8888 format in VRAM.
1050186 4:2672de88a46b 251 *
1050186 4:2672de88a46b 252 * @param p_info Pointer to VRAM structure
1050186 4:2672de88a46b 253 * @param start_x Display position X of BMP image
1050186 4:2672de88a46b 254 * @param start_y Display position Y of BMP image
1050186 4:2672de88a46b 255 * @param p_bmpinf Pointer to information of BMP image
1050186 4:2672de88a46b 256 * @param p_func Pointer to the data blend function
1050186 4:2672de88a46b 257 */
1050186 4:2672de88a46b 258 static void set_bmp_argb8888(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 259 const int32_t start_y, const dsp_bmpinf_t * const p_bmpinf, const blend_func_t p_func)
1050186 4:2672de88a46b 260 {
1050186 4:2672de88a46b 261 uint32_t *p_buff; /* Pointer to VRAM. */
1050186 4:2672de88a46b 262 uint32_t stride_pix; /* The horizontal number of bytes in VRAM. */
1050186 4:2672de88a46b 263 int32_t pos_x; /* The X position in VRAM. */
1050186 4:2672de88a46b 264 int32_t pos_y; /* The Y position in VRAM. */
1050186 4:2672de88a46b 265 const uint8_t *p_img; /* Pointer to BMP image. */
1050186 4:2672de88a46b 266 uint32_t img_h_byte; /* The horizontal number of bytes in the BMP image. */
1050186 4:2672de88a46b 267 uint32_t img_index;
1050186 4:2672de88a46b 268 uint32_t cnt;
1050186 4:2672de88a46b 269 uint32_t shift_num;
1050186 4:2672de88a46b 270 uint32_t col_data;
1050186 4:2672de88a46b 271
1050186 4:2672de88a46b 272 if ((p_info != NULL) && (p_bmpinf != NULL) && (p_func != NULL)) {
1050186 4:2672de88a46b 273 /* Calculates the horizontal number of bytes. */
1050186 4:2672de88a46b 274 /* The horizontal number of bytes is a multiple of 4. */
1050186 4:2672de88a46b 275 /* VRAM */
1050186 4:2672de88a46b 276 stride_pix = p_info->stride / sizeof(uint32_t);
1050186 4:2672de88a46b 277 /* BMP image */
1050186 4:2672de88a46b 278 img_h_byte = BYTENUM_PER_PIXEL_ARGB8888 * p_bmpinf->size_x;
1050186 4:2672de88a46b 279 for (pos_y = start_y; pos_y < (start_y + (int32_t)p_bmpinf->size_y); pos_y++) {
1050186 4:2672de88a46b 280 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) {
1050186 4:2672de88a46b 281 /* Sets the position of (0, pos_y) in VRAM. */
1050186 4:2672de88a46b 282 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y];
1050186 4:2672de88a46b 283 /* Sets the position of (start_x, pos_y) in BMP image. */
1050186 4:2672de88a46b 284 p_img = &p_bmpinf->p_image[img_h_byte * ((p_bmpinf->size_y - 1u) - (uint32_t)(pos_y - start_y))];
1050186 4:2672de88a46b 285 img_index = 0u;
1050186 4:2672de88a46b 286 for (pos_x = start_x; pos_x < (start_x + (int32_t)p_bmpinf->size_x); pos_x++) {
1050186 4:2672de88a46b 287 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) {
1050186 4:2672de88a46b 288 col_data = 0;
1050186 4:2672de88a46b 289 shift_num = 0u;
1050186 4:2672de88a46b 290 for (cnt = 0; cnt < BYTENUM_PER_PIXEL_ARGB8888; cnt++) {
1050186 4:2672de88a46b 291 col_data |= ((uint32_t)p_img[img_index + cnt] << shift_num);
1050186 4:2672de88a46b 292 shift_num += SHIFT_1BYTE_SIZE;
1050186 4:2672de88a46b 293 }
1050186 4:2672de88a46b 294 p_buff[pos_x] = p_func(p_buff[pos_x],col_data);
1050186 4:2672de88a46b 295 }
1050186 4:2672de88a46b 296 img_index += BYTENUM_PER_PIXEL_ARGB8888;
1050186 4:2672de88a46b 297 }
1050186 4:2672de88a46b 298 }
1050186 4:2672de88a46b 299 }
1050186 4:2672de88a46b 300 }
1050186 4:2672de88a46b 301 }
1050186 4:2672de88a46b 302
1050186 4:2672de88a46b 303 /** Blends foreground color with background color.
1050186 4:2672de88a46b 304 *
1050186 4:2672de88a46b 305 * @param bg_col Background color
1050186 4:2672de88a46b 306 * @param fg_col Foreground color
1050186 4:2672de88a46b 307 */
1050186 4:2672de88a46b 308 static uint32_t alpha_blend(const uint32_t bg_col, const uint32_t fg_col)
1050186 4:2672de88a46b 309 {
1050186 4:2672de88a46b 310 uint32_t ret_col;
1050186 4:2672de88a46b 311 /* Blended data */
1050186 4:2672de88a46b 312 uint32_t new_b;
1050186 4:2672de88a46b 313 uint32_t new_g;
1050186 4:2672de88a46b 314 uint32_t new_r;
1050186 4:2672de88a46b 315 uint32_t new_a;
1050186 4:2672de88a46b 316 /* Background data */
1050186 4:2672de88a46b 317 uint32_t bg_b;
1050186 4:2672de88a46b 318 uint32_t bg_g;
1050186 4:2672de88a46b 319 uint32_t bg_r;
1050186 4:2672de88a46b 320 uint32_t bg_a;
1050186 4:2672de88a46b 321 /* Foreground data */
1050186 4:2672de88a46b 322 uint32_t fg_b;
1050186 4:2672de88a46b 323 uint32_t fg_g;
1050186 4:2672de88a46b 324 uint32_t fg_r;
1050186 4:2672de88a46b 325 const uint32_t fg_a = (fg_col >> SHIFT_3BYTE_SIZE) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 326
1050186 4:2672de88a46b 327 if (fg_a == BLEND_MIN_VAL_ARGB8888) {
1050186 4:2672de88a46b 328 /* The data is not blended. A background data is used. */
1050186 4:2672de88a46b 329 ret_col = bg_col;
1050186 4:2672de88a46b 330 } else if (fg_a == BLEND_MAX_VAL_ARGB8888) {
1050186 4:2672de88a46b 331 /* The data is not blended. A foreground data is used. */
1050186 4:2672de88a46b 332 ret_col = fg_col;
1050186 4:2672de88a46b 333 } else {
1050186 4:2672de88a46b 334 /* A background data and a foreground data is blended. */
1050186 4:2672de88a46b 335 /* Foreground data */
1050186 4:2672de88a46b 336 fg_b = (fg_col ) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 337 fg_g = (fg_col >> SHIFT_1BYTE_SIZE) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 338 fg_r = (fg_col >> SHIFT_2BYTE_SIZE) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 339
1050186 4:2672de88a46b 340 /* Background data */
1050186 4:2672de88a46b 341 bg_b = (bg_col ) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 342 bg_g = (bg_col >> SHIFT_1BYTE_SIZE) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 343 bg_r = (bg_col >> SHIFT_2BYTE_SIZE) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 344 bg_a = (~fg_a ) & MASK_BYTE_SIZE;
1050186 4:2672de88a46b 345
1050186 4:2672de88a46b 346 /* Blended data */
1050186 4:2672de88a46b 347 /* The division calculation by 255 needs the long processing time. */
1050186 4:2672de88a46b 348 /* Therefore we execute the division calculation by 256 using shift calculation. */
1050186 4:2672de88a46b 349 /* An error in calculation occurs to divide it by 256, */
1050186 4:2672de88a46b 350 /* but an error is maximum 1 very small. */
1050186 4:2672de88a46b 351 new_b = ((fg_b * fg_a) + (bg_b * bg_a)) >> SHIFT_1BYTE_SIZE;
1050186 4:2672de88a46b 352 new_g = ((fg_g * fg_a) + (bg_g * bg_a)) >> SHIFT_1BYTE_SIZE;
1050186 4:2672de88a46b 353 new_r = ((fg_r * fg_a) + (bg_r * bg_a)) >> SHIFT_1BYTE_SIZE;
1050186 4:2672de88a46b 354 new_a = fg_a;
1050186 4:2672de88a46b 355
1050186 4:2672de88a46b 356 ret_col = new_b;
1050186 4:2672de88a46b 357 ret_col |= (new_g << SHIFT_1BYTE_SIZE);
1050186 4:2672de88a46b 358 ret_col |= (new_r << SHIFT_2BYTE_SIZE);
1050186 4:2672de88a46b 359 ret_col |= (new_a << SHIFT_3BYTE_SIZE);
1050186 4:2672de88a46b 360 }
1050186 4:2672de88a46b 361 return ret_col;
1050186 4:2672de88a46b 362 }
1050186 4:2672de88a46b 363
1050186 4:2672de88a46b 364 /** Gets the foreground color.
1050186 4:2672de88a46b 365 *
1050186 4:2672de88a46b 366 * @param bg_col Background color
1050186 4:2672de88a46b 367 * @param fg_col Foreground color
1050186 4:2672de88a46b 368 */
1050186 4:2672de88a46b 369 static uint32_t get_fg_col(const uint32_t bg_col, const uint32_t fg_col)
1050186 4:2672de88a46b 370 {
1050186 4:2672de88a46b 371 UNUSED_ARG(bg_col);
1050186 4:2672de88a46b 372 return fg_col;
1050186 4:2672de88a46b 373 }
1050186 4:2672de88a46b 374
1050186 4:2672de88a46b 375 /** Draws font image in VRAM.
1050186 4:2672de88a46b 376 *
1050186 4:2672de88a46b 377 * @param p_info Pointer to VRAM structure
1050186 4:2672de88a46b 378 * @param start_x Display position X of font image
1050186 4:2672de88a46b 379 * @param start_y Display position Y of font image
1050186 4:2672de88a46b 380 * @param font_data Pointer to font data
1050186 4:2672de88a46b 381 * @param font_width The width of font data
1050186 4:2672de88a46b 382 * @param font_height The height of font data
1050186 4:2672de88a46b 383 */
1050186 4:2672de88a46b 384 static void set_font(const dsp_tftlayer_t * const p_info, const int32_t start_x,
1050186 4:2672de88a46b 385 const int32_t start_y, const uint32_t * const font_data,
1050186 4:2672de88a46b 386 const uint32_t font_width, const uint32_t font_height)
1050186 4:2672de88a46b 387 {
1050186 4:2672de88a46b 388 uint32_t *p_buff;
1050186 4:2672de88a46b 389 uint32_t data_val;
1050186 4:2672de88a46b 390 uint32_t stride_pix;
1050186 4:2672de88a46b 391 int32_t pos_x;
1050186 4:2672de88a46b 392 int32_t pos_y;
1050186 4:2672de88a46b 393
1050186 4:2672de88a46b 394 if ((p_info != NULL) && (font_data != NULL)) {
1050186 4:2672de88a46b 395 /* Calculates the horizontal number of bytes. */
1050186 4:2672de88a46b 396 /* The horizontal number of bytes is a multiple of 4. */
1050186 4:2672de88a46b 397 stride_pix = p_info->stride / sizeof(uint32_t);
1050186 4:2672de88a46b 398 for (pos_y = start_y; pos_y < (start_y + (int32_t)font_height); pos_y++) {
1050186 4:2672de88a46b 399 if ((pos_y >= 0) && (pos_y < (int32_t)p_info->height)) {
1050186 4:2672de88a46b 400 /* Sets the position of (0, pos_y) in VRAM. */
1050186 4:2672de88a46b 401 p_buff = &p_info->p_back_buf[stride_pix * (uint32_t)pos_y];
1050186 4:2672de88a46b 402 /* Sets the position of (start_x, pos_y) in font image. */
1050186 4:2672de88a46b 403 data_val = font_data[pos_y - start_y];
1050186 4:2672de88a46b 404 for (pos_x = start_x; pos_x < (start_x + (int32_t)font_width); pos_x++) {
1050186 4:2672de88a46b 405 if ((data_val & MASK_BIT_SIZE) == DSP_IMG_FONT_FG_VAL) {
1050186 4:2672de88a46b 406 if((pos_x >= 0) && (pos_x < (int32_t)p_info->width)) {
1050186 4:2672de88a46b 407 p_buff[pos_x] = DSP_IMG_FONT_FG_COL;
1050186 4:2672de88a46b 408 }
1050186 4:2672de88a46b 409 }
1050186 4:2672de88a46b 410 data_val >>= SHIFT_1BIT_SIZE;
1050186 4:2672de88a46b 411 }
1050186 4:2672de88a46b 412 }
1050186 4:2672de88a46b 413 }
1050186 4:2672de88a46b 414 }
1050186 4:2672de88a46b 415 }