首页 > 评测 > 亚星娱乐官网注册网站 【技术分享】基于正点原子开发板的中文菜单音乐播放器实现
亚星娱乐官网注册网站 【技术分享】基于正点原子开发板的中文菜单音乐播放器实现
- [导读]
- 本帖最后由 jinglixixi 于 2023-5-17 18:48 编辑 #申请原创# @21小跑堂 正点原子开发板以外设丰富而著称,基本可以全部支撑起多媒体方面的应用,如数码相框功能(已在前面介绍过)、视频播放功能、文本阅读器
#申请原创# @21小跑堂
- void text_show_font(uint16_t x, uint16_t y, uint8_t *font, uint8_t size, uint8_t mode, uint16_t color)
- {
- uint8_t temp, t, t1;
- uint16_t y0 = y;
- uint8_t *dzk;
- uint8_t csize = (size / 8 + ((size % 8) ? 1 : 0)) * (size);
-
- if (size != 12 && size != 16 && size != 24 && size != 32)
- {
- return;
- }
- dzk = mymalloc(SRAMIN, size);
- if (dzk == 0) return;
- text_get_hz_mat(font, dzk, size);
- for (t = 0; t
- {
- temp = dzk[t];
- for (t1 = 0; t1 <8; t1++) // 一个字节
- {
- if (temp & 0x80) // 1000 0000 从左到右
- {
- //lcd_draw_point(x, y, color);
- ili9341_draw_pixel(color, x, y);
- }
- else if (mode == 0)
- {
- //lcd_draw_point(x, y, g_back_color);
- ili9341_draw_pixel(g_back_color, x, y);
- }
- temp <<= 1;
- y++; //由上至下
- if ((y - y0) == size)
- {
- y = y0;
- x++; //换列 --->存放形式:列行式
- break;
- }
- }
- }
- myfree(SRAMIN, dzk);
- }
- int main(void)
- {
- uint8_t key;
- HAL_Init();
- sys_stm32_clock_init(336, 8, 2, 7);
- delay_init(168);
- usart_init(115200);
- usmart_dev.init(84);
- led_init();
- key_init();
- sram_init();
- norflash_init();
- LCD_Init();
- delay_ms(10);
- ili9341_init();
- ili9341_clear(RED);
- BACK_COLOR=RED;
- POINT_COLOR=YELLOW;
- LCD_DrawLine(WHITE ,0, 35, 239, 35);
- LCD_DrawLine(WHITE ,0, 275, 239, 275);
- my_mem_init(SRAMIN);
- my_mem_init(SRAMEX);
- while (sd_init())
- {
- LCD_ShowString(30,50,"SD Card Failed!");
- delay_ms(200);
- delay_ms(200);
- }
- exfuns_init();
- f_mount(fs[0], "0:", 1);
- f_mount(fs[1], "1:", 1);
- while (fonts_init())
- {
- LCD_ShowString(30,50,"Font Error!");
- delay_ms(200);
- }
- es8388_init();
- es8388_adda_cfg(1, 0);
- es8388_output_cfg(1, 1);
- es8388_hpvol_set(25);
- es8388_spkvol_set(26);
- g_back_color=RED;
- text_show_string(30, 13, 200, 16, "中文菜单音乐播放器", 16, 0, YELLOW);
- POINT_COLOR=WHITE;
- text_show_string(30, 50, 200, 16, "1 - 最美的期待", 16, 0, WHITE);
- text_show_string(30, 70, 200, 16, "2 - 野百合也有春天", 16, 0, WHITE);
- text_show_string(30, 90, 200, 16, "3 - 光阴的故事", 16, 0, WHITE);
- text_show_string(30, 110, 200, 16, "4 - 莫斯科郊外的晚上", 16, 0, WHITE);
- text_show_string(30, 130, 200, 16, "5 - 东方之珠", 16, 0, WHITE);
- text_show_string(30, 150, 200, 16, "6 - 光辉岁月", 16, 0, WHITE);
- text_show_string(30, 170, 200, 16, "7 - 同桌的你", 16, 0, WHITE);
- text_show_string(30, 190, 200, 16, "8 - 亚洲雄风", 16, 0, WHITE);
- text_show_string(30, 210, 200, 16, "9 - 咖啡屋", 16, 0, WHITE);
- text_show_string(30, 230, 200, 16, "10- 军港之夜", 16, 0, WHITE);
- POINT_COLOR=YELLOW;
- text_show_string(30, 280, 200, 16, "KEY0:下一首 KEY2:上一首", 16, 0, YELLOW);
- text_show_string(30, 300, 200, 16, "KEY_UP:暂停/播放", 16, 0, YELLOW);
- POINT_COLOR=WHITE;
- key = key_scan(0);
- while(key != KEY1_PRES)
- {
- key = key_scan(0);
- }
- while (1)
- {
- audio_play();
- }
- }
- uint8_t audio_play_song(char* fname)
- {
- uint8_t res;
- res = exfuns_file_type(fname);
- switch (res)
- {
- case T_WAV:
- POINT_COLOR=0xF800;
- text_show_string(12, 50+(np*20), 200, 16, "*", 16, 0, 0xF800);
- POINT_COLOR=0xFFE0;
- text_show_string(12, 50+(n*20), 200, 16, "*", 16, 0, 0xFFE0);
- np=n;
- res = wav_play_song(fname);
- break;
- default:
- res = KEY0_PRES;
- break;
- }
- return res;
- }
- uint16_t audio_get_tnum(char *path)
- {
- uint8_t res;
- uint16_t rval = 0;
- DIR tdir;
- FILINFO* tfileinfo;
- tfileinfo = (FILINFO*)mymalloc(SRAMIN, sizeof(FILINFO));
- res = f_opendir(&tdir, (const TCHAR*)path);
- if ((res == FR_OK) && tfileinfo)
- {
- while (1)
- {
- res = f_readdir(&tdir, tfileinfo);
- if ((res != FR_OK) || (tfileinfo->fname[0] == 0))
- {
- break;
- }
- res = exfuns_file_type(tfileinfo->fname);
- if ((res & 0xF0) == 0x40)
- {
- rval++;
- }
- }
- }
- myfree(SRAMIN, tfileinfo);
- return rval;
- }
- void audio_play(void)
- {
- uint8_t res;
- DIR wavdir;
- FILINFO *wavfileinfo;
- char *pname;
- uint16_t totwavnum;
- uint16_t curindex;
- uint8_t key;
- uint32_t temp;
- uint32_t *wavoffsettbl;
- es8388_adda_cfg(1, 0);
- es8388_output_cfg(1, 1);
- while (f_opendir(&wavdir, "0:/MUSIC"))
- {
- LCD_ShowString(30,190,"MUSIC ERROR");
- delay_ms(200);
- delay_ms(200);
- }
- totwavnum = audio_get_tnum("0:/MUSIC");
- while (totwavnum == NULL)
- {
- LCD_ShowString(30,190,"NO MUSIC !");
- delay_ms(200);
- delay_ms(200);
- }
- wavfileinfo = (FILINFO*)mymalloc(SRAMIN, sizeof(FILINFO));
- pname = mymalloc(SRAMIN, FF_MAX_LFN * 2 + 1);
- wavoffsettbl = mymalloc(SRAMIN, 4 * totwavnum);
- while (!wavfileinfo || !pname || !wavoffsettbl)
- {
- LCD_ShowString(30,190,"memory Failed");
- delay_ms(200);
- delay_ms(200);
- }
-
- res = f_opendir(&wavdir, "0:/MUSIC");
- if (res == FR_OK)
- {
- curindex = 0;
- while (1)
- {
- temp = wavdir.dptr;
- res = f_readdir(&wavdir, wavfileinfo);
- if ((res != FR_OK) || (wavfileinfo->fname[0] == 0))
- {
- break;
- }
- res = exfuns_file_type(wavfileinfo->fname);
- if ((res & 0xF0) == 0x40)
- {
- wavoffsettbl[curindex] = temp;
- curindex++;
- }
- }
- }
- curindex = 0;
- res = f_opendir(&wavdir, (const TCHAR*)"0:/MUSIC");
- while (res == FR_OK)
- {
- dir_sdi(&wavdir, wavoffsettbl[curindex]);
- res = f_readdir(&wavdir, wavfileinfo);
- if ((res != FR_OK) || (wavfileinfo->fname[0] == 0))
- {
- break;
- }
- strcpy((char*)pname, "0:/MUSIC/");
- strcat((char*)pname, (const char*)wavfileinfo->fname);
- audio_index_show(curindex + 1, totwavnum);
- key = audio_play_song(pname);
- if (key == KEY2_PRES)
- {
- if (curindex)
- {
- curindex--;
- }
- else
- {
- curindex = totwavnum - 1;
- }
- }
- else if (key == KEY0_PRES)
- {
- curindex++;
- if (curindex >= totwavnum)
- {
- curindex = 0;
- }
- }
- else
- {
- break;
- }
- n=curindex;
- }
- myfree(SRAMIN, wavfileinfo);
- myfree(SRAMIN, pname);
- myfree(SRAMIN, wavoffsettbl);
- }
- 本文系21ic原创,未经许可禁止转载!
亚星娱乐官网注册开户
- 联系人:巧克力娃娃
- 邮箱:[email protected]
- 我要投稿
-
欢迎入驻,开放投稿
-
RAK831 Lite:基于树莓派3的LoRa网关... 2022-06-17
-
Imagination推出PowerVR AX2185和AX2145神经... 2022-06-17
-
ODROID-GO是一款兼容Arduino的基于ESP32的便... 2022-06-17
-
兼职Java开发
预算:¥10000 5小时前
-
FPGA SCALER IP 预算:¥10000 23小时前
-
水阀流量传感器控制
预算:¥10000 1天前
-
摩托车流水爆闪转向灯
预算:¥10000 1天前
-
fpga做个fir滤波器
预算:¥300 2天前
-
51单片机websocket
预算:¥500 3天前