[RVB2601 Creative Application Development] + Network Player
[Copy link]
I. Overview
RVB2601 uses Pingtouge's low-power, 32-bit RISC-V Xuantie E906 processor, equipped with AliOS IoT operating system, and through the integrated development environment of end-cloud, it can quickly access the Open Chip Community (OCC) to obtain development resources and conduct convenient application development. Developers can make various application innovations in the fields of IoT access, Bluetooth, audio/playback, etc. It can be applied to smart home, audio and video broadcast control, electronic toys, environmental monitoring, health care, education and learning, etc.
RVB2601 is equipped with the high-performance and secure WiFi4 chip W800 from Lianshengde. W800 is connected to CH2601 through the SPI port. Command transmission and data interaction between the W800 chip and the MCU can be realized through AT commands, and the application scenario of networking can be realized quickly. This time, we will learn the network configuration method of the W800 WiFI chip and the implementation of the network player through the webplayer Demo.
2. Network Configuration
Pull the webplayer Demo from the OCC platform through Jianchi CDK. After compiling DownLoad, you can receive the information shown in the figure on the serial port.
At this point, use the ifconfig ap wifiname wifipassword command to configure the network, where wifiname is your wifi name and wifipassword is your wifi password, which needs to be modified. After successful configuration, you can use the ifconfig command to query the current wifi connection status and the corresponding IP
After that, you can use the player play http://yocbook.oss-cn-hangzhou.aliyuncs.com/av_repo/alibaba.mp3 command to pull MP3 songs from the Internet for playback.
3. Code Analysis
static void network_init()
{
w800_wifi_param_t w800_param;
/* init wifi driver and network */
w800_param.reset_pin = PA21;
w800_param.baud = 1*1000000;
w800_param.cs_pin = PA15;
w800_param.wakeup_pin = PA25;
w800_param.int_pin = PA22;
w800_param.channel_id = 0;
w800_param.buffer_size = 4*1024;
wifi_w800_register(NULL, &w800_param);
app_netmgr_hdl = netmgr_dev_wifi_init();
if (app_netmgr_hdl) {
utask_t *task = utask_new("netmgr", 2 * 1024, QUEUE_MSG_COUNT, AOS_DEFAULT_APP_PRI);
netmgr_service_init(task);
//netmgr_config_wifi(app_netmgr_hdl, "TEST", 4, "TEST1234", 10);
netmgr_start(app_netmgr_hdl);
}
}
The above code can be used to enter commands through the serial terminal to configure the network.
netmgr_config_wifi(app_netmgr_hdl, "TEST", 4, "TEST1234", 10);
Perform network configuration, change TEST to your own wifi name, and change TSET1234 to your own wifi password to avoid the need to reconfigure wifi information after each reset.
__attribute__((weak)) int player_init()
{
static int inited = 0;
if (!inited) {
resample_register();
eqx_register();
aefx_register();
atempo_register();
avparser_register_all();
stream_register_all();
demux_register_all();
ad_register_all();
ao_register_all();
inited = 1;
}
return inited ? 0 : -1;
}
This function is used to initialize the player. Before calling other player interfaces, the player module must be initialized. Its main functions are to register the stream type stream, demux, codec, and audio output ao.
In addition, you can also add functions such as play, pause, resume, jump, stop, and adjust volume in the player module.
static void *at_spi_init(const char *name, void *config)
{
int ret = 0;
w800_wifi_param_t *param = (w800_wifi_param_t *)config;
csi_pin_set_mux(PA16, PA16_SPI0_SCK);
csi_pin_set_mux(PA17, PA17_SPI0_MOSI);
csi_pin_set_mux(PA18, PA18_SPI0_MISO);
// csi_pin_set_mux(PA15, PA15_SPI0_CS); // CS
csi_pin_set_mux(param->cs_pin, PIN_FUNC_GPIO); // CS
csi_pin_set_mux(param->int_pin, PIN_FUNC_GPIO); // INT
csi_gpio_pin_init(&spi_int_pin, param->int_pin);
csi_gpio_pin_dir(&spi_int_pin,GPIO_DIRECTION_INPUT);
csi_gpio_pin_mode(&spi_int_pin,GPIO_MODE_PULLNONE);
csi_gpio_pin_debounce(&spi_int_pin, true);
csi_gpio_pin_attach_callback(&spi_int_pin, spi_in_int_cb, NULL);
csi_gpio_pin_irq_mode(&spi_int_pin,GPIO_IRQ_MODE_FALLING_EDGE);
csi_gpio_pin_irq_enable(&spi_int_pin, 1);
csi_gpio_pin_init(&spi_cs_pin, param->cs_pin);
csi_gpio_pin_mode(&spi_cs_pin,GPIO_MODE_PULLUP);
csi_gpio_pin_dir(&spi_cs_pin,GPIO_DIRECTION_OUTPUT);
CS_HIGH;
csi_gpio_pin_init(&spi_wakeup_pin, param->wakeup_pin);
csi_gpio_pin_mode(&spi_wakeup_pin,GPIO_MODE_PULLUP);
csi_gpio_pin_dir(&spi_wakeup_pin,GPIO_DIRECTION_OUTPUT);
csi_gpio_pin_write(&spi_wakeup_pin, GPIO_PIN_HIGH);
ret = csi_spi_init(&spi_handle, 0);
if (ret < 0) {
printf("csi spi init failed\r\n");
return NULL;
}
csi_spi_mode(&spi_handle, SPI_MASTER);
ret = csi_spi_baud(&spi_handle, param->baud);
LOGD(TAG, "#######################spi speed:%d\r\n", ret);
csi_spi_cp_format(&spi_handle, SPI_FORMAT_CPOL0_CPHA0);
csi_spi_frame_len(&spi_handle, SPI_FRAME_LEN_8);
csi_spi_select_slave(&spi_handle, 0);
#ifdef SPI_USE_DMA
csi_spi_attach_callback(&spi_handle, spi_event_cb, NULL);
csi_spi_link_dma(&spi_handle, NULL, &spi_recv_dma);
#endif
aos_task_t task;
ret = aos_sem_new(&spi_recv_sem, 0);
// aos_check(ret, NULL);
ret = aos_event_new(&spi_event, 0);
ret = aos_task_new_ext(&task, "spi_recv", at_spi_recv_task, NULL, 1536, 9);
// aos_check(ret, NULL);
spi_recv_buffer = (char *)aos_malloc_check(param->buffer_size);
ringbuffer_create(&spi_ringbuffer, spi_recv_buffer, param->buffer_size);
return (void*)1;
}
This function is used to initialize the ports required by W800 to correspond to the SPI interface.
|