前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【中科蓝讯】RT-Thread平台-中科蓝讯AB32VG1开发板audio功能评测

【中科蓝讯】RT-Thread平台-中科蓝讯AB32VG1开发板audio功能评测

作者头像
用户8913398
发布2021-08-16 16:08:02
7900
发布2021-08-16 16:08:02
举报

软件环境

  • RT-Studio 版本: 2.1.0
  • RT-Thread_source_code V4.03
  • bluetrum(中科蓝讯软件包)V1.04
  • wavplayer软件包 V-latest
  • optparse软件包 V-latest
  • multibutton软件包 V-latest

下载工具

  • 中科蓝讯配套下载软件
  • 中科蓝讯配套串口驱动
  • 板子靓照

1、开发环境搭建

最近也是工作比较忙,对audio的评测也没做什么多余的东西,主要是根据官方的指导,实现了功能,后续时间充足了再来好好玩玩这块板子。

使用的是RT-thread官方stduio平台,先更新软件源代码至最新版,下载中科蓝讯软件包,下载RISC-V-GCC工具链,编译程序会用到。

2、软件包配置

选择基于开发板,默认选项就是中科蓝讯,也是本次要测评的板子,点击完成oK。

接下来选择我们本次实验用到的软件包,wavplayer软件包、optparse软件包和multibutton软件包,实现通过板载按键控制声音的播放语音量的增减。

然后对软件包进行简单配置,按键的示例代码可以勾选也可以不勾选,后面要对此进行修改,改为评测板上的用户按键,optparse软件包默认即可。

3、应用代码编写

基于RT-Thread的便利,这部分几乎不需要用户怎么操作,软件包已经配置完成,只需要少量代码将功能整合起来即可,非常的方便。首先修改要存储的音乐文件,把romfs.c的内容替换为本次实验用到的,文件地址:

https://ab32vg1-example.readthedocs.io/zh/latest/rt-thread/wav_player.html#flash-wav

然后需要注意的一点是,需要修改mnt.c的内容,对ROMFS进行挂载,在mnt文件中添加下面代码即可。

代码语言:javascript
复制
#ifdef RT_USING_DFS
#include <dfs_fs.h>
#include "dfs_romfs.h"

int mnt_init(void)
{
    if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0)
    {
        rt_kprintf("ROM file system initializated!\n");
    }
    else
    {
        rt_kprintf("ROM file system initializate failed!\n");
    }

    return 0;
}
INIT_ENV_EXPORT(mnt_init);
#endif

接下来,修改按键应用程序,下面地址中有详细介绍。https://ab32vg1-example.readthedocs.io/zh/latest/rt-thread/wav_player.html#flash-wav

代码语言:javascript
复制
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-03-28     Administrator       the first version
 */
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include <multi_button.h>
#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    (2u)

static struct button btn_0;
static struct button btn_1;

static uint32_t cnt_0 = 0;
static uint32_t cnt_1 = 0;

static char *table[2] =
{
    "wav_1.wav",
    "wav_2.wav",
};

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(30);
        }else if (cnt_0 == 2) {
            saia_volume_set(50);
        }else {
            saia_volume_set(100);
            cnt_0 = 0;
        }
        cnt_0++;
        rt_kprintf("vol=%d\n", saia_volume_get());
        rt_kprintf("button 0 single click\n");
    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 click\n");
    break;

    case LONG_RRESS_START:
        rt_kprintf("button 0 long press start\n");
    break;

    case LONG_PRESS_HOLD:
        rt_kprintf("button 0 long press hold\n");
    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 click\n");
    break;

    case DOUBLE_CLICK:
        rt_kprintf("button 1 double click\n");
    break;

    case LONG_RRESS_START:
        rt_kprintf("button 1 long press start\n");
    break;

    case LONG_PRESS_HOLD:
        rt_kprintf("button 1 long press hold\n");
    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_RRESS_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_RRESS_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);

代码编写完成,build,没有错误,就可以下载了。

4、功能验证

完成上述的配置及代码编写之后,找到我们需要下载的文件的位置,下载文件在所建立工程的debug目录下,.dcf文件,在下载工具找到相应文件即可。串口驱动安装正确的话,连接上板子之后,选择对应的串口,会提示就绪。

下载完成后,控制台会输出hello world,同时板子上LED灯闪烁,接下来就可以来通过按键控制播放啦,需要接上耳机,s2控制播放曲目,s3调节音量,还是非常的方便的。

搭载RT-Thread平台,还是十分的方便的,墙裂推荐!!

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-03-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小飞哥玩嵌入式 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 下载工具
  • 1、开发环境搭建
  • 2、软件包配置
  • 3、应用代码编写
  • 4、功能验证
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档