📄 app_bluescreen_demo.c
字号:
#include "app_config.h"
#include <stdio.h>
extern void delay_1ms(unsigned int n);
extern volatile unsigned char time_1ms_cnt;
extern volatile unsigned char time_10ms_cnt;
extern volatile unsigned char time_100ms_cnt;
extern volatile unsigned char time_500ms_cnt;
typedef struct
{
unsigned char on;
long x;
long y;
} pos_t;
#define TC_TP_NUM 5
#define CALIB_TEST_TIME 1//2
#ifdef TS_ORN_PORTRAIT
const int tc_tpx[TC_TP_NUM] = {10,65,120,175,230};
const int tc_tpy[TC_TP_NUM] = {10,85,160,235,310};
#else
const int tc_tpy[TC_TP_NUM] = {10,65,120,175,230};
const int tc_tpx[TC_TP_NUM] = {10,85,160,235,310};
#endif
const long chalfx = TS_SIZE_X/2;
const long chalfy = TS_SIZE_Y/2;
//x = ((TCGetH() - ccx)*cm1x)/cm2x + chalfx;
long ccx;
long cm1x;
long cm2x;
//y = ((TCGetV() - ccy)*cm1y)/cm2y + chalfy;
long ccy;
long cm1y;
long cm2y;
long cal_posx(unsigned short x);
long cal_posy(unsigned short y);
unsigned char filp_horizontal = 0;
unsigned char last_pen_check = 0;
so_pos_t hpos,vpos;
pstatus_t p_stat;
#define EP_SIZE 8192
//last 128 bytes of EEPROM is used for configuration data
#define EP_AD_CFG EP_SIZE - 128
//below are address with EP_AD_CFG offset
#define EP_AD_CFG_STATUS 0
#define CAL_VALID_PORTRAIT 0x01
#define CAL_VALID_LANDSCAPE 0x02
#ifdef TS_ORN_PORTRAIT
#define CAL_VALID 0x01
#define TCGetH() TCGetX()
#define TCGetV() TCGetY()
#define EP_AD_CFG_CX 1
#define EP_AD_CFG_M1X 5
#define EP_AD_CFG_M2X 9
#define EP_AD_CFG_CY 13
#define EP_AD_CFG_M1Y 17
#define EP_AD_CFG_M2Y 21
#else
#define CAL_VALID 0x02
#define TCGetH() TCGetY()
#define TCGetV() TCGetX()
#define EP_AD_CFG_CX 13
#define EP_AD_CFG_M1X 17
#define EP_AD_CFG_M2X 21
#define EP_AD_CFG_CY 1
#define EP_AD_CFG_M1Y 5
#define EP_AD_CFG_M2Y 9
#endif
EmbeddedFileSystem efs;
EmbeddedFile filer, filew;
DirList list;
unsigned short e;
char current_dir[128] = "/";
char current_file_name[128];
unsigned char writing_flag = 0;
char writing_mode;
File showing_file;
unsigned char showing_flag = 0;
char showing_path[128];
unsigned char sd_inited = 0;
extern void delay_1ms(unsigned int n);
extern unsigned char mp3_buf[MP3_LOAD_SIZE];
extern volatile unsigned char time_1ms_cnt;
extern volatile unsigned char time_10ms_cnt;
extern volatile unsigned char time_100ms_cnt;
extern volatile unsigned char time_500ms_cnt;
#define TC_TP_NUM 5
//const long chalfx = TS_SIZE_X/2;
//const long chalfy = TS_SIZE_Y/2;
//x = ((TCGetH() - ccx)*cm1x)/cm2x + chalfx;
long ccx;
long cm1x;
long cm2x;
//y = ((TCGetV() - ccy)*cm1y)/cm2y + chalfy;
long ccy;
long cm1y;
long cm2y;
long cal_posx(unsigned short x);
long cal_posy(unsigned short y);
//unsigned char filp_horizontal = 0;
//unsigned char last_pen_check = 0;
so_pos_t hpos,vpos;
pstatus_t p_stat;
#define EP_SIZE 8192
//last 128 bytes of EEPROM is used for configuration data
#define EP_AD_CFG EP_SIZE - 128
//below are address with EP_AD_CFG offset
#define EP_AD_CFG_STATUS 0
#define CAL_VALID_PORTRAIT 0x01
#define CAL_VALID_LANDSCAPE 0x02
#ifdef TS_ORN_PORTRAIT
#define CAL_VALID 0x01
#define TCGetH() TCGetX()
#define TCGetV() TCGetY()
#define EP_AD_CFG_CX 1
#define EP_AD_CFG_M1X 5
#define EP_AD_CFG_M2X 9
#define EP_AD_CFG_CY 13
#define EP_AD_CFG_M1Y 17
#define EP_AD_CFG_M2Y 21
#else
#define CAL_VALID 0x02
#define TCGetH() TCGetY()
#define TCGetV() TCGetX()
#define EP_AD_CFG_CX 13
#define EP_AD_CFG_M1X 17
#define EP_AD_CFG_M2X 21
#define EP_AD_CFG_CY 1
#define EP_AD_CFG_M1Y 5
#define EP_AD_CFG_M2Y 9
#endif
void AppSDInit(void)
{
unsigned char res;
res = efs_init( &efs, 0 );
switch (res)
{
case 0 :
if (!sd_inited) //say only at first time
saystr("\r\nSD card found\r\n");
sd_inited = 1;
break;
case 0xFF :
saystr("\r\nCard not found\r\n");
sd_inited = 0;
writing_flag = 0;
break;
case 0xFE :
saystr("\r\nPlease format the card\r\n");
sd_inited = 0;
writing_flag = 0;
break;
default :
saystr("\r\nUnknown error\r\n");
sd_inited = 0;
writing_flag = 0;
break;
}
}
void AppSDList(void)
{
char res;
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
if (ls_openDir(&list, &(efs.myFs) , current_dir) == 0)
{
res = ls_getNext(&list);
if (res == 0)
{
saystr("Directory of ");
saystr(current_dir);
saystr("\r\n");
while (res == 0)
{
list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
saystr((char *)list.currentEntry.FileName);
saystr(" size : 0x");
sayhex32(list.currentEntry.FileSize);
saystr("bytes\r\n");
res = ls_getNext(&list);
}
}
else
{
saystr("\r\nFolder is empty\r\n");
}
fs_umount(&efs.myFs);
}
else
{
saystr("\r\nFolder not found\r\n");
}
}
void AppSDChangeDir(char *new_dir)
{
char dir_name_buf[128];
unsigned char i = 0;
unsigned char j = 0;
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
while (current_dir[i]) //search for \0
{
dir_name_buf[i] = current_dir[i];
i++;
}
if (i > 1) //folder in root don't need '/'
{
dir_name_buf[i] = '/';
i++;
}
else
{
i = 0;
}
while (new_dir[j])
{
dir_name_buf[i] = new_dir[j];
i++;
j++;
}
dir_name_buf[i] = 0;
i=0;
if (ls_openDir(&list, &(efs.myFs) , dir_name_buf) == 0)
{
while (dir_name_buf[i])
{
current_dir[i] = dir_name_buf[i];
i++;
}
current_dir[i] = 0;
}
else
{
saystr("\r\nFolder not found\r\n");
}
}
void AppSDGetBack(void)
{
unsigned char i = 0;
while (current_dir[i]) //search for \0
{
i++;
}
if (i <= 1)
return;
while ((current_dir[i] != '/') && (i))
{
i--;
}
if (i > 0)
{
current_dir[i] = 0;
}
else
{
current_dir[0] = '/';
current_dir[1] = 0;
}
}
void AppSDRead(char mode,char *file_name)
{
char path_buf[128];
unsigned char i = 0;
unsigned char j = 0;
unsigned int k;
unsigned int res;
File file;
unsigned char buffer[512];
if ((mode == 'C') || (mode == 'H'))
{
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
while (current_dir[i]) //search for \0
{
path_buf[i] = current_dir[i];
i++;
}
if (i > 1) //file in root don't need '/'
{
path_buf[i] = '/';
i++;
}
else
{
i = 0;
}
while (file_name[j])
{
path_buf[i] = file_name[j];
i++;
j++;
}
path_buf[i] = 0;
i=0;
res = file_fopen(&file, &efs.myFs, path_buf, 'r');
if (res == 0)
{
res = file_read(&file,512,buffer);
while (res)
{
for (k=0;k<res;k++)
{
if (mode == 'C')
saych(buffer[k]);
else
sayhex(buffer[k]);
//say();
//delay_1ms(1);
}
res = file_read(&file,512,buffer);
}
saystr("\r\n");
}
else
{
saystr("\r\nFile not found\r\n");
}
file_fclose(&file);
fs_umount(&efs.myFs);
}
else
{
saystr("\r\nmode must be 'c' or 'h'\r\n");
}
}
void AppSDMkDir(char *dir_name)
{
char path_buf[128];
unsigned char i = 0;
unsigned char j = 0;
unsigned char res;
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
while (current_dir[i]) //search for \0
{
path_buf[i] = current_dir[i];
i++;
}
if (i > 1) //folder in root don't need '/'
{
path_buf[i] = '/';
i++;
}
else
{
i = 0;
}
while (dir_name[j])
{
path_buf[i] = dir_name[j];
i++;
j++;
}
path_buf[i] = 0;
i=0;
res = mkdir(&efs.myFs,path_buf);
switch (res)
{
case 0 :
break;
case 0xFF :
saystr("\r\nDirectory already exists\r\n");
break;
case 0xFE :
saystr("\r\nThe path is incorrect\r\n");
break;
case 0xFD :
saystr("\r\nNo free space available\r\n");
break;
default :
saystr("\r\nUnknown error\r\n");
break;
}
fs_umount(&efs.myFs);
}
void AppSDOpenWrite(char mode, char *file_name)
{
unsigned char i = 0;
unsigned char j = 0;
unsigned int res;
File writing_file;
if ((mode == 'A') || (mode == 'W'))
{
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
while (current_dir[i]) //search for \0
{
current_file_name[i] = current_dir[i];
i++;
}
if (i > 1) //file in root don't need '/'
{
current_file_name[i] = '/';
i++;
}
else
{
i = 0;
}
while (file_name[j])
{
current_file_name[i] = file_name[j];
i++;
j++;
}
current_file_name[i] = 0;
writing_mode = mode;
i = 0;
if (mode == 'A')
{
res = file_fopen(&writing_file, &efs.myFs, current_file_name, 'r');
if (res == 0)
{
writing_flag = 1;
}
else
{
saystr("\r\nFile not found\r\n");
}
file_fclose(&writing_file);
}
else
{
writing_flag = 1;
}
fs_umount(&efs.myFs);
}
else
{
saystr("\r\nmode must be 'a' or 'w'\r\n");
}
}
void AppSDWrite(int len, char *data)
{
unsigned char res;
File writing_file;
if (!writing_flag)
{
saystr("\r\nPlease use command openwrite first\r\n");
return;
}
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
if (writing_mode == 'W')
res = file_fopen(&writing_file, &efs.myFs, current_file_name, 'w');
else
res = file_fopen(&writing_file, &efs.myFs, current_file_name, 'a');
switch (res)
{
case 0 :
if (file_write(&writing_file ,len ,data) != len)
{
saystr("\r\nCouldn't write file\r\n");
}
file_fclose(&writing_file);
break;
case 0xFE :
saystr("\r\nFile already exists\r\n");
break;
case 0xFB :
saystr("\r\nNo free spot found for writing\r\n");
break;
default :
saystr("\r\nUnknown error\r\n");
break;
}
fs_umount(&efs.myFs);
}
void AppPlay_(char *file_name)
{
char path_buf[128];
unsigned char i = 0;
unsigned char j = 0;
long l = 0;
unsigned int res;
//unsigned char pass = 0;
File file;
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
while (current_dir[i]) //search for \0
{
path_buf[i] = current_dir[i];
i++;
}
if (i > 1) //file in root don't need '/'
{
path_buf[i] = '/';
i++;
}
else
{
i = 0;
}
while (file_name[j])
{
path_buf[i] = file_name[j];
i++;
j++;
}
path_buf[i] = 0;
i=0;
res = file_fopen(&file, &efs.myFs, path_buf, 'r');
if (res == 0)
{
//pass = 1;
for (j=0;j<45;j++)
res = file_read(&file,1024,mp3_buf);
while (res)
{
SDSPIInit();
res = file_read(&file,512,mp3_buf);
l = 0;
while (!Rdb(VS_DREQ_PINP,VS_DREQ_PIN));
while (l < 512)
{
VSSDITransfer(16,mp3_buf+l);
l += 16;
while (!Rdb(VS_DREQ_PINP,VS_DREQ_PIN));
}
}
file_fclose(&file);
}
else
{
saystr("\r\nFile not found\r\n");
}
fs_umount(&efs.myFs);
delay_1ms(100);
}
void AppPlay(char *file_name)
{
char path_buf[128];
unsigned char i = 0;
unsigned char j = 0;
unsigned int res;
File file;
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
while (current_dir[i]) //search for \0
{
path_buf[i] = current_dir[i];
i++;
}
if (i > 1) //file in root don't need '/'
{
path_buf[i] = '/';
i++;
}
else
{
i = 0;
}
while (file_name[j])
{
path_buf[i] = file_name[j];
i++;
j++;
}
path_buf[i] = 0;
i=0;
res = file_fopen(&file, &efs.myFs, path_buf, 'r');
if (res == 0)
{
VSAudioPlay(file_name,current_dir);
file_fclose(&file);
}
else
{
saystr("\r\nFile not found\r\n");
}
fs_umount(&efs.myFs);
delay_1ms(100);
}
void AppPlayAll(char *dir_name)
{
// AppSDInit();
SDSPIInit();
if (!sd_inited)
{
return;
}
if (ls_openDir(&list, &(efs.myFs) , dir_name) == 0)
{
VSAudioPlayAll(dir_name);
}
else
{
saystr("\r\nFolder not found\r\n");
}
}
void AppSDShowPic2(char *file_name)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -