4
1.sd卡配置
1)确保sd卡跳线正确短接
2)
2.audio 配置
1)rt-set ting 依次添加multibutton、wavplayer、optoarse 三个软件包
wavplayer 添加后,optoarse 自动会添加
开启 dfs 的时候会默认开启 posix 的使能,需要 关闭 posix 的使能 ,否则终端的输入会有问题
使能audio设备
wavplay 设置
使能 flash 只读,如果不勾选发现音频会有卡顿
3.添加代码 参考 https://ab32vg1-example.readthed ... wav_player_rom.html
这里是直接使用sd 卡(mnt.c 内默认挂载sd卡 elm
- void sd_mount(void *parameter)
- {
- while (1)
- {
- rt_thread_mdelay(500);
- if(rt_device_find("sd0") != RT_NULL)
- {
- if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
- {
- LOG_I("sd card mount to '/'");
- break;
- }
- else
- {
- LOG_W("sd card mount to '/' failed!");
- }
- }
- }
- }
复制代码
所以我sd卡内直接放入1.WAV 2.WAV 3.WAV
修改table 数组
- #include
- #include
- #include "board.h"
- #include
- #include "wavplayer.h"
- #define BUTTON_PIN_0 rt_pin_get("PF.0")
- #define BUTTON_PIN_1 rt_pin_get("PF.1")
- #define NUM_OF_SONGS (3u)
- static struct button btn_0;
- static struct button btn_1;
- static uint32_t cnt_0 = 0;
- static uint32_t cnt_1 = 0;
- #if 0
- static char *table[2] =
- {
- "wav_1.wav",
- "wav_2.wav",
- };
- #else
- static char *table[] =
- {
- "1.wav",
- "2.wav",
- "3.wav",
- };
- #endif
- void saia_channels_set(uint8_t channels);
- void saia_volume_set(rt_uint8_t volume);
- uint8_t saia_volume_get(void);
- static uint8_t button_read_pin_0(void)
- {
- return rt_pin_read(BUTTON_PIN_0);
- }
- static uint8_t button_read_pin_1(void)
- {
- return rt_pin_read(BUTTON_PIN_1);
- }
- static void button_0_callback(void *btn)
- {
- uint32_t btn_event_val;
- btn_event_val = get_button_event((struct button *)btn);
- switch(btn_event_val)
- {
- case SINGLE_CLICK:
- if (cnt_0 == 1) {
- saia_volume_set(5);
- }else if (cnt_0 == 2) {
- saia_volume_set(10);
- }else {
- saia_volume_set(15);
- cnt_0 = 0;
- }
- cnt_0++;
- rt_kprintf("vol=%dn", saia_volume_get());
- rt_kprintf("button 0 single clickn");
- break;
- case DOUBLE_CLICK:
- if (cnt_0 == 1) {
- saia_channels_set(1);
- }else {
- saia_channels_set(2);
- cnt_0 = 0;
- }
- cnt_0++;
- rt_kprintf("button 0 double clickn");
- break;
- case LONG_PRESS_START:
- rt_kprintf("button 0 long press startn");
- break;
- case LONG_PRESS_HOLD:
- rt_kprintf("button 0 long press holdn");
- break;
- }
- }
- static void button_1_callback(void *btn)
- {
- uint32_t btn_event_val;
- btn_event_val = get_button_event((struct button *)btn);
- switch(btn_event_val)
- {
- case SINGLE_CLICK:
- wavplayer_play(table[(cnt_1++) % NUM_OF_SONGS]);
- rt_kprintf("button 1 single clickn");
- break;
- case DOUBLE_CLICK:
- rt_kprintf("button 1 double clickn");
- break;
- case LONG_PRESS_START:
- rt_kprintf("button 1 long press startn");
- break;
- case LONG_PRESS_HOLD:
- rt_kprintf("button 1 long press holdn");
- break;
- }
- }
- static void btn_thread_entry(void* p)
- {
- while(1)
- {
- /* 5ms */
- rt_thread_delay(RT_TICK_PER_SECOND/200);
- button_ticks();
- }
- }
- static int multi_button_test(void)
- {
- rt_thread_t thread = RT_NULL;
- /* Create background ticks thread */
- thread = rt_thread_create("btn", btn_thread_entry, RT_NULL, 1024, 10, 10);
- if(thread == RT_NULL)
- {
- return RT_ERROR;
- }
- rt_thread_startup(thread);
- /* low level drive */
- rt_pin_mode (BUTTON_PIN_0, PIN_MODE_INPUT_PULLUP);
- button_init (&btn_0, button_read_pin_0, PIN_LOW);
- button_attach(&btn_0, SINGLE_CLICK, button_0_callback);
- button_attach(&btn_0, DOUBLE_CLICK, button_0_callback);
- button_attach(&btn_0, LONG_PRESS_START, button_0_callback);
- button_attach(&btn_0, LONG_PRESS_HOLD, button_0_callback);
- button_start (&btn_0);
- rt_pin_mode (BUTTON_PIN_1, PIN_MODE_INPUT_PULLUP);
- button_init (&btn_1, button_read_pin_1, PIN_LOW);
- button_attach(&btn_1, SINGLE_CLICK, button_1_callback);
- button_attach(&btn_1, DOUBLE_CLICK, button_1_callback);
- button_attach(&btn_1, LONG_PRESS_START, button_1_callback);
- button_attach(&btn_1, LONG_PRESS_HOLD, button_1_callback);
- button_start (&btn_1);
- return RT_EOK;
- }
- INIT_APP_EXPORT(multi_button_test);
复制代码
总结:
1.发现修改音量后,再切换歌曲,音量又变成默认值
2.没有播放暂停功能
3.没有sd 卡wav 文件扫描功能
4.没有显示功能
后续针对几个改善点进行完善
|
|