Remove USB

This commit is contained in:
Ben V. Brown 2023-02-04 10:36:08 +11:00
parent 4e8ec04b34
commit 22ba33ecfe
56 changed files with 0 additions and 17238 deletions

View File

@ -23,8 +23,6 @@ subdir-ccflags-y += \
-Iservices/multimedia/speech/inc \ -Iservices/multimedia/speech/inc \
-Iservices/nv_section/include \ -Iservices/nv_section/include \
-Iservices/nv_section/aud_section \ -Iservices/nv_section/aud_section \
-Iplatform/drivers/usb/usb_dev/inc \
-Itests/anc_usb \
-Iutils/hwtimer_list -Iutils/hwtimer_list
CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT) CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
@ -58,9 +56,6 @@ ifeq ($(ADC_CH_SEP_BUFF),1)
ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF
endif endif
include platform/drivers/usb/usb_dev/uaud_cfg_flags.mk
platform/drivers/usb/usb_dev/uaud_cfg_flags.mk: ;
ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS) ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS)

View File

@ -1,41 +0,0 @@
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
obj-y := $(obj-y:.c=.o)
obj-y := $(obj-y:.cpp=.o)
obj-y := $(obj-y:.S=.o)
ccflags-y += \
$(BT_IF_INCLUDES) \
$(BT_PROFILES_INCLUDES) \
-Iservices/bt_app \
-Iservices/bt_app/a2dp_codecs/include \
-Iservices/audioflinger \
-Iservices/nvrecord \
-Iservices/overlay \
-Iservices/resources \
-Iservices/audio_process \
-Iapps/apptester \
-Iapps/factory \
-Iutils/crc32 \
-Iplatform/drivers/bt \
-Iplatform/drivers/ana \
-Iapps/audioplayers/rbplay \
-Itests/anc_usb \
-Iapps/anc/inc \
-Iapps/ota \
-Ithirdparty/userapi \
-Iservices/voicepath \
-Iservices/voicepath/gsound/gsound_service \
-Iservices/voicepath/gsound/gsound_target \
-Iservices/communication \
-Iutils/cqueue \
-Iservices/ai_voice/ama/ama_manager \
-Iservices/ai_voice/manager \
-Iservices/multimedia/audio/codec/sbc/inc \
-Iservices/multimedia/audio/codec/sbc/src/inc \
-Iservices/interconnection

View File

@ -1,260 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "app_audio.h"
#include "cmsis_os.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "stdio.h"
#include "a2dp_api.h"
#include "app_bt.h"
#include "btapp.h"
#include "btusb_audio.h"
#include "usb_audio_app.h"
extern void btusbaudio_entry(void);
extern void btusbaudio_exit(void);
extern a2dp_stream_t *app_bt_get_steam(enum BT_DEVICE_ID_T id);
extern int app_bt_get_bt_addr(enum BT_DEVICE_ID_T id, bt_bdaddr_t *bdaddr);
extern bool app_bt_a2dp_service_is_connected(void);
int app_bt_A2DP_OpenStream(a2dp_stream_t *Stream, bt_bdaddr_t *Addr);
int app_bt_A2DP_CloseStream(a2dp_stream_t *Stream);
extern bool btapp_hfp_is_call_active(void);
static bool btusb_usb_is_on = false;
static enum BTUSB_MODE btusb_mode = BTUSB_MODE_INVALID;
static bool btusb_bt_audio_is_suspend = false;
#define BT_USB_DEBUG() // TRACE(2,"_debug: %s,%d",__func__,__LINE__)
extern struct BT_DEVICE_T app_bt_device;
static void _btusb_stream_open(unsigned int timeout_ms) {
a2dp_stream_t *stream = NULL;
bt_bdaddr_t bdaddr;
uint32_t stime = 0;
uint32_t etime = 0;
stime = hal_sys_timer_get();
// BT_USB_DEBUG();
stream = (a2dp_stream_t *)app_bt_get_steam(BT_DEVICE_ID_1);
app_bt_get_bt_addr(BT_DEVICE_ID_1, &bdaddr);
if (stream) {
// struct BT_DEVICE_T *bt_dev = &app_bt_device;
// A2DP_Register((a2dp_stream_t
// *)bt_dev->a2dp_stream[BT_DEVICE_ID_1]->a2dp_stream, &a2dp_avdtpcodec,
// NULL, (A2dpCallback) a2dp_callback); AVRCP_Register((AvrcpChannel
// *)bt_dev->avrcp_channel[BT_DEVICE_ID_1]->avrcp_channel_handle,
// (AvrcpCallback)avrcp_callback_CT, BTIF_AVRCP_CT_CATEGORY_1 |
// BTIF_AVRCP_CT_CATEGORY_2 | BTIF_AVRCP_TG_CATEGORY_2);
BT_USB_DEBUG();
osDelay(10);
app_bt_A2DP_OpenStream(stream, &bdaddr);
} else {
BT_USB_DEBUG();
return;
}
while (1) {
if (app_bt_a2dp_service_is_connected()) {
etime = hal_sys_timer_get();
TRACE(1, "_debug: a2dp service connected, wait time = 0x%x.",
TICKS_TO_MS(etime - stime));
break;
} else {
etime = hal_sys_timer_get();
if (TICKS_TO_MS(etime - stime) >= timeout_ms) {
TRACE(1, "_debug: a2dp service connect timeout = 0x%x.",
TICKS_TO_MS(etime - stime));
break;
}
osDelay(10);
}
}
// BT_USB_DEBUG();
}
static void _btusb_stream_close(unsigned int timeout_ms) {
a2dp_stream_t *stream = NULL;
uint32_t stime = 0;
uint32_t etime = 0;
stime = hal_sys_timer_get();
BT_USB_DEBUG();
stream = (a2dp_stream_t *)app_bt_get_steam(BT_DEVICE_ID_1);
if (stream) {
BT_USB_DEBUG();
app_bt_A2DP_CloseStream(stream);
} else {
BT_USB_DEBUG();
return;
}
stime = hal_sys_timer_get();
while (1) {
if (!app_bt_a2dp_service_is_connected()) {
// struct BT_DEVICE_T *bt_dev = &app_bt_device;
// AVRCP_Deregister(bt_dev->avrcp_channel[BT_DEVICE_ID_1]->avrcp_channel_handle);
// A2DP_Deregister(stream);
etime = hal_sys_timer_get();
TRACE(1, "a2dp service diconnected, wait time = 0x%x.",
TICKS_TO_MS(etime - stime));
break;
} else {
etime = hal_sys_timer_get();
if (TICKS_TO_MS(etime - stime) >= timeout_ms) {
TRACE(1, "a2dp service diconnect timeout = 0x%x.",
TICKS_TO_MS(etime - stime));
break;
}
osDelay(10);
}
}
BT_USB_DEBUG();
}
static void btusb_usbaudio_entry(void) {
BT_USB_DEBUG();
btusbaudio_entry();
btusb_usb_is_on = true;
}
void btusb_usbaudio_open(void) {
BT_USB_DEBUG();
if (!btusb_usb_is_on) {
btusb_usbaudio_entry();
BT_USB_DEBUG();
} else {
usb_audio_app(1);
}
BT_USB_DEBUG();
}
void btusb_usbaudio_close(void) {
BT_USB_DEBUG();
if (btusb_usb_is_on) {
usb_audio_app(0);
BT_USB_DEBUG();
} else {
BT_USB_DEBUG();
}
}
void btusb_btaudio_close(bool is_wait) {
BT_USB_DEBUG();
// if(!btusb_bt_audio_is_suspend)
{
BT_USB_DEBUG();
if (is_wait) {
app_audio_sendrequest(APP_PLAY_BACK_AUDIO,
(uint8_t)APP_BT_SETTING_CLOSEALL, 0);
_btusb_stream_close(BTUSB_OUTTIME_MS);
} else {
_btusb_stream_close(0);
}
btusb_bt_audio_is_suspend = true;
}
}
void btusb_btaudio_open(bool is_wait) {
BT_USB_DEBUG();
// if(btusb_bt_audio_is_suspend)
{
TRACE(2, "%s: %d.", __func__, __LINE__);
if (is_wait) {
_btusb_stream_open(BTUSB_OUTTIME_MS);
app_audio_sendrequest(APP_PLAY_BACK_AUDIO, (uint8_t)APP_BT_SETTING_CLOSE,
0);
app_audio_sendrequest(APP_PLAY_BACK_AUDIO, (uint8_t)APP_BT_SETTING_SETUP,
0);
} else {
_btusb_stream_open(0);
}
TRACE(2, "%s: %d.", __func__, __LINE__);
btusb_bt_audio_is_suspend = false;
}
}
void btusb_switch(enum BTUSB_MODE mode) {
// BT_USB_DEBUG();
if (mode != BTUSB_MODE_BT && mode != BTUSB_MODE_USB) {
ASSERT(0, "%s:%d, mode = %d.", __func__, __LINE__, mode);
}
if (btusb_mode == mode) {
BT_USB_DEBUG();
return;
}
if (btusb_mode == BTUSB_MODE_INVALID) {
if (mode == BTUSB_MODE_BT) {
TRACE(1, "%s: switch to BT mode.", __func__);
btusb_mode = BTUSB_MODE_BT;
} else {
TRACE(1, "%s: switch to USB mode.", __func__);
// btusb_btaudio_close(true);
osDelay(500);
btusb_usbaudio_open();
btusb_mode = BTUSB_MODE_USB;
}
} else {
if (mode == BTUSB_MODE_BT) {
TRACE(1, "%s: switch to BT mode.", __func__);
if (btusb_usb_is_on) {
TRACE(1, "%s: btusb_usbaudio_close.", __func__);
btusb_usbaudio_close();
TRACE(1, "%s: btusb_usbaudio_close done.", __func__);
osDelay(500);
}
btusb_mode = BTUSB_MODE_BT;
btusb_btaudio_open(true);
TRACE(1, "%s: switch to BT mode done.", __func__);
} else {
if (btapp_hfp_is_call_active() == 1) {
TRACE(1, "%s: hfp is call active.", __func__);
return;
}
TRACE(1, "%s: switch to USB mode.", __func__);
btusb_btaudio_close(true);
TRACE(1, "%s: btusb_btaudio_close done.", __func__);
osDelay(500);
btusb_usbaudio_open();
btusb_mode = BTUSB_MODE_USB;
TRACE(1, "%s: switch to USB mode done.", __func__);
}
}
}
bool btusb_is_bt_mode(void) {
BT_USB_DEBUG();
return btusb_mode == BTUSB_MODE_BT ? true : false;
}
bool btusb_is_usb_mode(void) {
return btusb_mode == BTUSB_MODE_USB ? true : false;
}
#if defined(BT_USB_AUDIO_DUAL_MODE_TEST)
void test_btusb_switch(void) {
if (btusb_mode == BTUSB_MODE_BT) {
btusb_switch(BTUSB_MODE_USB);
} else {
btusb_switch(BTUSB_MODE_BT);
}
}
void test_btusb_switch_to_bt(void) { btusb_switch(BTUSB_MODE_BT); }
void test_btusb_switch_to_usb(void) { btusb_switch(BTUSB_MODE_USB); }
#endif

View File

@ -1,40 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef _BTUSB_AUDIO_H_
#define _BTUSB_AUDIO_H_
#ifdef __cplusplus
extern "C" {
#endif
#define BTUSB_OUTTIME_MS 1000
enum BTUSB_MODE{
BTUSB_MODE_BT,
BTUSB_MODE_USB,
BTUSB_MODE_INVALID
};
void btusb_usbaudio_open(void);
void btusb_usbaudio_close(void);
void btusb_btaudio_open(bool is_wait);
void btusb_btaudio_close(bool is_wait);
void btusb_switch(enum BTUSB_MODE mode);
bool btusb_is_bt_mode(void);
bool btusb_is_usb_mode(void);
#ifdef __cplusplus
}
#endif
#endif // _BTUSB_AUDIO_H_

View File

@ -1,131 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "usbaudio_thread.h"
#include "app_utils.h"
#include "cmsis_os.h"
#include "hal_trace.h"
#include "usb_audio_app.h"
static void usb_thread(void const *argument);
osThreadDef(usb_thread, osPriorityHigh, 1, 2048, "usb");
osMailQDef(usb_mailbox, USB_MAILBOX_MAX, USB_MESSAGE);
static osMailQId usb_mailbox = NULL;
static uint8_t usb_mailbox_cnt = 0;
#define USBAUDIO_DEBUG TRACE
static int usb_mailbox_init(void) {
USBAUDIO_DEBUG("%s,%d", __func__, __LINE__);
usb_mailbox = osMailCreate(osMailQ(usb_mailbox), NULL);
if (usb_mailbox == NULL) {
USBAUDIO_DEBUG("Failed to Create usb_mailbox\n");
return -1;
}
usb_mailbox_cnt = 0;
return 0;
}
int usb_mailbox_put(USB_MESSAGE *msg_src) {
osStatus status;
USB_MESSAGE *msg_p = NULL;
USBAUDIO_DEBUG("%s,%d", __func__, __LINE__);
if (usb_mailbox_cnt >= 1) {
USBAUDIO_DEBUG("%s,%d usb_mailbox_cnt = %d.", __func__, __LINE__,
usb_mailbox_cnt);
return 0;
}
msg_p = (USB_MESSAGE *)osMailAlloc(usb_mailbox, 0);
ASSERT(msg_p, "osMailAlloc error");
msg_p->id = msg_src->id;
msg_p->ptr = msg_src->ptr;
msg_p->param0 = msg_src->param0;
msg_p->param1 = msg_src->param1;
status = osMailPut(usb_mailbox, msg_p);
if (osOK == status)
usb_mailbox_cnt++;
USBAUDIO_DEBUG("%s,%d,usb_mailbox_cnt = %d.", __func__, __LINE__,
usb_mailbox_cnt);
return (int)status;
}
int usb_mailbox_free(USB_MESSAGE *msg_p) {
osStatus status;
USBAUDIO_DEBUG("%s,%d", __func__, __LINE__);
status = osMailFree(usb_mailbox, msg_p);
if (osOK == status)
usb_mailbox_cnt--;
USBAUDIO_DEBUG("%s,%d,usb_mailbox_cnt = %d.", __func__, __LINE__,
usb_mailbox_cnt);
return (int)status;
}
int usb_mailbox_get(USB_MESSAGE **msg_p) {
osEvent evt;
evt = osMailGet(usb_mailbox, osWaitForever);
if (evt.status == osEventMail) {
*msg_p = (USB_MESSAGE *)evt.value.p;
return 0;
}
return -1;
}
static void usb_thread(void const *argument) {
// USB_FUNC_T usb_funcp;
USBAUDIO_DEBUG("%s,%d", __func__, __LINE__);
while (1) {
USB_MESSAGE *msg_p = NULL;
if (!usb_mailbox_get(&msg_p)) {
// TRACE(2,"_debug: %s,%d",__func__,__LINE__);
USBAUDIO_DEBUG(
"usb_thread: id = 0x%x, ptr = 0x%x,param0 = 0x%x,param1 = 0x%x.",
msg_p->id, msg_p->ptr, msg_p->param0, msg_p->param1);
usb_mailbox_free(msg_p);
usb_audio_app_loop();
}
}
}
static void usb_enqueue_cmd(uint32_t data) {
USB_MESSAGE usb_msg;
usb_msg.id = 0;
usb_msg.param0 = 0;
usb_msg.param1 = 0;
usb_msg.ptr = 0;
usb_mailbox_put(&usb_msg);
}
int usb_os_init(void) {
osThreadId usb_tid;
USBAUDIO_DEBUG("%s,%d", __func__, __LINE__);
if (usb_mailbox_init()) {
USBAUDIO_DEBUG("_debug: %s,%d", __func__, __LINE__);
return -1;
}
usb_tid = osThreadCreate(osThread(usb_thread), NULL);
if (usb_tid == NULL) {
USBAUDIO_DEBUG("Failed to Create usb_thread\n");
return 0;
}
usb_audio_set_enqueue_cmd_callback(usb_enqueue_cmd);
return 0;
}

View File

@ -1,49 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_THREAD_H__
#define __USB_THREAD_H__
#ifdef __cplusplus
extern "C" {
#endif
#define USB_MAILBOX_MAX (20)
typedef struct {
uint32_t id;
uint32_t ptr;
uint32_t param0;
uint32_t param1;
} USB_MESSAGE;
//typedef int (*USB_MOD_HANDLER_T)(USB_MESSAGE_BODY *);
typedef void (*USB_FUNC_T)(uint32_t, uint32_t);
int usb_mailbox_put(USB_MESSAGE* msg_src);
int usb_mailbox_free(USB_MESSAGE* msg_p);
int usb_mailbox_get(USB_MESSAGE** msg_p);
int usb_os_init(void);
#ifdef __cplusplus
}
#endif
#endif // __USB_THREAD_H__

View File

@ -18,7 +18,6 @@ ccflags-y += \
-Iapps/key \ -Iapps/key \
-Iplatform/drivers/bt \ -Iplatform/drivers/bt \
-Iplatform/drivers/ana \ -Iplatform/drivers/ana \
-Iplatform/drivers/usb/usb_dev/inc \
-Iapps/battery \ -Iapps/battery \
-Iservices/multimedia/audio/codec/sbc/inc \ -Iservices/multimedia/audio/codec/sbc/inc \
-Iservices/multimedia/audio/codec/sbc/src/inc \ -Iservices/multimedia/audio/codec/sbc/src/inc \

View File

@ -30,7 +30,6 @@ ccflags-y += \
-Iapps/i2c_sensor \ -Iapps/i2c_sensor \
-Iplatform/drivers/bt \ -Iplatform/drivers/bt \
-Iplatform/drivers/ana \ -Iplatform/drivers/ana \
-Iplatform/drivers/usb/usb_dev/inc \
-Iapps/battery -Iapps/battery
ifeq ($(AUDIO_RESAMPLE),1) ifeq ($(AUDIO_RESAMPLE),1)

View File

@ -1,193 +0,0 @@
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
obj-y += ../../tests/anc_usb/usb_audio_app.c
obj-y += ../../tests/anc_usb/safe_queue.c
obj-y += ../../tests/anc_usb/memutils.c
ifeq ($(USB_AUDIO_SPEECH),1)
obj-y += ../../tests/anc_usb/speech_process.c
endif
ifeq ($(ANC_APP),1)
obj-y += ../../tests/anc_usb/anc_usb_app.c
endif
obj-y := $(obj-y:.c=.o)
obj-y := $(obj-y:.cpp=.o)
obj-y := $(obj-y:.S=.o)
ccflags-y += \
-Iutils/boot_struct \
-Iutils/crc32 \
-Iutils/hexdump \
-Iutils/hwtimer_list \
-Itests/programmer \
-Iplatform/drivers/usb/usb_dev/inc \
-Iplatform/drivers/ana \
-Iservices/multimedia/audio/process/adp/include \
-Iservices/multimedia/audio/process/anc/include \
-Iservices/multimedia/audio/process/filters/include \
-Iservices/multimedia/audio/process/resample/include \
-Iservices/multimedia/speech/inc \
-Iservices/audio_process \
-Iservices/nv_section/aud_section \
-Iservices/nv_section/include \
-Iservices/overlay \
-Itests/anc_usb
CFLAGS_usbaudio_entry.o += -DUSB_AUDIO_APP
CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
CFLAGS_adda_loop_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
ANC_USB_CFG_FLAGS :=
# ANC option
ifeq ($(ANC_APP),1)
ANC_USB_CFG_FLAGS += -DANC_APP
endif
# USB audio option
ifeq ($(USB_AUDIO_APP),1)
ANC_USB_CFG_FLAGS += -DUSB_AUDIO_APP
endif
ifeq ($(USB_HIGH_SPEED),1)
ANC_USB_CFG_FLAGS += -DUSB_HIGH_SPEED
endif
ifeq ($(AUDIO_RESAMPLE),1)
ANC_USB_CFG_FLAGS += -D__AUDIO_RESAMPLE__
endif
ifeq ($(ADC_CH_SEP_BUFF),1)
ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF
endif
include platform/drivers/usb/usb_dev/uaud_cfg_flags.mk
platform/drivers/usb/usb_dev/uaud_cfg_flags.mk: ;
ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS)
# USB audio configuration
ifeq ($(USB_AUDIO_DYN_CFG),1)
ifneq ($(AUDIO_RESAMPLE),1)
SW_CAPTURE_RESAMPLE ?= 1
endif
endif
ifeq ($(AUDIO_PLAYBACK_24BIT),1)
ANC_USB_CFG_FLAGS += -DAUDIO_PLAYBACK_24BIT
endif
# DSD configuration
ifeq ($(HW_FIR_DSD_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_FIR_DSD_PROCESS__
endif
# EQ configuration
ifeq ($(HW_FIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_FIR_EQ_PROCESS__
endif
ifeq ($(HW_IIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_IIR_EQ_PROCESS__
endif
ifeq ($(SW_IIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__SW_IIR_EQ_PROCESS__
endif
ifeq ($(HW_DAC_IIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_DAC_IIR_EQ_PROCESS__
endif
ifeq ($(SW_CAPTURE_RESAMPLE),1)
ANC_USB_CFG_FLAGS += -DSW_CAPTURE_RESAMPLE
endif
CFLAGS_usbaudio_entry.o += $(ANC_USB_CFG_FLAGS)
CFLAGS_usb_audio_app.o += $(ANC_USB_CFG_FLAGS)
CFLAGS_anc_usb_app.o += $(ANC_USB_CFG_FLAGS)
ifeq ($(ANC_KEY_DOUBLE_CLICK_ON_OFF),1)
CFLAGS_anc_usb_app.o += -DANC_KEY_DOUBLE_CLICK_ON_OFF
endif
ifeq ($(ANC_FF_ENABLED),1)
CFLAGS_anc_usb_app.o += -DANC_FF_ENABLED
endif
ifeq ($(ANC_FB_ENABLED),1)
CFLAGS_anc_usb_app.o += -DANC_FB_ENABLED
endif
ifeq ($(AUDIO_SECTION_SUPPT),1)
CFLAGS_anc_usb_app.o += -D__AUDIO_SECTION_SUPPT__
endif
ifeq ($(ANC_INIT_OFF),1)
CFLAGS_anc_usb_app.o += -DANC_INIT_OFF
endif
ifeq ($(PC_CMD_UART),1)
CFLAGS_usbaudio_entry.o += -D__PC_CMD_UART__
endif
ifeq ($(DELAY_STREAM_OPEN),1)
CFLAGS_usb_audio_app.o += -DDELAY_STREAM_OPEN
endif
ifeq ($(NOISE_GATING),1)
CFLAGS_usb_audio_app.o += -DNOISE_GATING
endif
ifeq ($(NOISE_REDUCTION),1)
CFLAGS_usb_audio_app.o += -DNOISE_REDUCTION
endif
ifeq ($(ANC_L_R_MISALIGN_WORKAROUND),1)
CFLAGS_usb_audio_app.o += -DANC_L_R_MISALIGN_WORKAROUND
endif
ifeq ($(ANDROID_ACCESSORY_SPEC),1)
CFLAGS_usb_audio_app.o += -DANDROID_ACCESSORY_SPEC
ifeq ($(ANDROID_VOICE_CMD_KEY),1)
CFLAGS_usb_audio_app.o += -DANDROID_VOICE_CMD_KEY
endif
endif
ifeq ($(DUAL_AUX_MIC_MORE_FILTER),1)
CFLAGS_usb_audio_app.o += -DDUAL_AUX_MIC_MORE_FILTER
endif
ifeq ($(FREQ_RESP_EQ),1)
CFLAGS_usb_audio_app.o += -DFREQ_RESP_EQ
endif
ifeq ($(KEEP_SAME_LATENCY),1)
CFLAGS_usb_audio_app.o += -DKEEP_SAME_LATENCY
CFLAGS_speech_process.o += -DKEEP_SAME_LATENCY
endif
ifeq ($(USB_AUDIO_PWRKEY_TEST),1)
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_PWRKEY_TEST
endif
ifeq ($(AUDIO_RESAMPLE),1)
# If neither best1000 nor best2000
ifeq ($(filter best1000 best2000,$(CHIP)),)
PLL_TUNE_SAMPLE_RATE ?= 1
endif
ifeq ($(PLL_TUNE_SAMPLE_RATE),1)
CFLAGS_usb_audio_app.o += -DPLL_TUNE_SAMPLE_RATE
endif
endif
ifeq ($(USB_AUDIO_SPEECH),1)
CFLAGS_usbaudio_entry.o += -DUSB_AUDIO_SPEECH
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_SPEECH
endif

View File

@ -1,363 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "analog.h"
#include "audioflinger.h"
#include "cmsis.h"
#include "hal_cmu.h"
#include "hal_dma.h"
#include "hal_gpadc.h"
#include "hal_iomux.h"
#include "hal_key.h"
#include "hal_sleep.h"
#include "hal_sysfreq.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "hwtimer_list.h"
#include "plat_addr_map.h"
#include "pmu.h"
#include "string.h"
#if defined(ANC_APP)
#include "anc_usb_app.h"
#endif
#include "audio_process.h"
#include "dualadc_audio_app.h"
#include "tgt_hardware.h"
#include "usb_audio_app.h"
#include "usb_audio_frm_defs.h"
#ifdef RTOS
#include "cmsis_os.h"
#endif
#ifdef __PC_CMD_UART__
#include "hal_cmd.h"
#endif
#ifdef USB_AUDIO_SPEECH
#define CODEC_BUFF_FRAME_NUM (2 * 16)
#define USB_BUFF_FRAME_NUM (CODEC_BUFF_FRAME_NUM * 2)
#else
#define CODEC_BUFF_FRAME_NUM 4
#define USB_BUFF_FRAME_NUM 8
#endif
#if (CODEC_BUFF_FRAME_NUM >= USB_BUFF_FRAME_NUM)
#error \
"Codec buffer frame num should be less than usb buffer frame num (on the requirement of conflict ctrl)"
#endif
#ifdef USB_AUDIO_DYN_CFG
#define USB_AUDIO_PLAYBACK_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_PLAYBACK *CODEC_BUFF_FRAME_NUM, DAC_BUFF_ALIGN)
#define USB_AUDIO_CAPTURE_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_CAPTURE *CODEC_BUFF_FRAME_NUM, ADC_BUFF_ALIGN)
#define USB_AUDIO_RECV_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_RECV *USB_BUFF_FRAME_NUM, RECV_BUFF_ALIGN)
#define USB_AUDIO_SEND_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_SEND *USB_BUFF_FRAME_NUM, SEND_BUFF_ALIGN)
#if defined(CHIP_BEST1000)
// FIR EQ is working on 16-bit
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int16_t)
#define USB_AUDIO_FIR_EQ_BUFF_SIZE USB_AUDIO_PLAYBACK_BUFF_SIZE
#elif defined(CHIP_BEST2000)
// FIR EQ is working on 32-bit
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int32_t)
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * 2)
#elif defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
// FIR EQ is working on 32-bit
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int32_t)
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * 2)
#endif
#else
#define USB_AUDIO_PLAYBACK_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_PLAYBACK *CODEC_BUFF_FRAME_NUM, DAC_BUFF_ALIGN)
#define USB_AUDIO_CAPTURE_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_CAPTURE *CODEC_BUFF_FRAME_NUM, ADC_BUFF_ALIGN)
#define USB_AUDIO_RECV_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_RECV *USB_BUFF_FRAME_NUM, RECV_BUFF_ALIGN)
#define USB_AUDIO_SEND_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_SEND *USB_BUFF_FRAME_NUM, SEND_BUFF_ALIGN)
#if defined(CHIP_BEST1000)
// FIR EQ is working on 16-bit
#define USB_AUDIO_FIR_EQ_BUFF_SIZE \
(USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int16_t) / SAMPLE_SIZE_PLAYBACK)
#elif defined(CHIP_BEST2000)
// FIR EQ is working on 16-bit
#define USB_AUDIO_FIR_EQ_BUFF_SIZE \
(USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int32_t) / SAMPLE_SIZE_PLAYBACK)
#elif defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
// FIR EQ is working on 16-bit
#define USB_AUDIO_FIR_EQ_BUFF_SIZE \
(USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int32_t) / SAMPLE_SIZE_PLAYBACK)
#endif
#endif
#if (defined(CHIP_BEST1000) && \
(defined(ANC_APP) || defined(_DUAL_AUX_MIC_))) && \
(CHAN_NUM_CAPTURE == CHAN_NUM_SEND)
// Resample input buffer size should be (half_of_max_sample_num *
// SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE). half_of_max_sample_num = 48000 /
// 1000 * CODEC_BUFF_FRAME_NUM / 2 * 48 / 44
#define RESAMPLE_INPUT_BUFF_SIZE \
ALIGN(48000 / 1000 * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE * \
CODEC_BUFF_FRAME_NUM / 2 * 48 / 44, \
4)
#else
#define RESAMPLE_INPUT_BUFF_SIZE 0
#endif
// Resample history buffer size should be
// sizeof(struct RESAMPLE_CTRL_T) + ((SAMPLE_NUM + phase_coef_num) *
// SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
#define RESAMPLE_HISTORY_BUFF_SIZE \
(50 + (256 * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE))
#define USB_AUDIO_RESAMPLE_BUFF_SIZE \
(RESAMPLE_INPUT_BUFF_SIZE + RESAMPLE_HISTORY_BUFF_SIZE)
#define ALIGNED4 ALIGNED(4)
#if defined(USB_AUDIO_APP) || defined(DUALADC_AUDIO_TEST)
#ifdef AUDIO_ANC_FB_MC
static uint8_t ALIGNED4 playback_buff[USB_AUDIO_PLAYBACK_BUFF_SIZE *
9]; // max 48->384 or 44.1->44.1*8;
#else
static uint8_t ALIGNED4 playback_buff[USB_AUDIO_PLAYBACK_BUFF_SIZE];
#endif
static uint8_t ALIGNED4 capture_buff[USB_AUDIO_CAPTURE_BUFF_SIZE];
#endif
#ifdef USB_AUDIO_APP
#if defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
static uint8_t ALIGNED4
eq_buff[USB_AUDIO_FIR_EQ_BUFF_SIZE + USB_AUDIO_IIR_EQ_BUFF_SIZE];
#elif defined(__HW_FIR_EQ_PROCESS__) && !defined(__HW_IIR_EQ_PROCESS__)
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_FIR_EQ_BUFF_SIZE];
#elif !defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_IIR_EQ_BUFF_SIZE];
#else
static uint8_t ALIGNED4 eq_buff[0];
#endif
#ifdef SW_CAPTURE_RESAMPLE
static uint8_t ALIGNED4 resample_buff[USB_AUDIO_RESAMPLE_BUFF_SIZE];
#else
static uint8_t ALIGNED4 resample_buff[0];
#endif
static uint8_t ALIGNED4 recv_buff[USB_AUDIO_RECV_BUFF_SIZE];
static uint8_t ALIGNED4 send_buff[USB_AUDIO_SEND_BUFF_SIZE];
#endif
#ifdef CFG_HW_KEY_LED_PIN
const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_key_led[1] = {
{CFG_HW_KEY_LED_PIN, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
HAL_IOMUX_PIN_NOPULL},
};
#endif
#ifdef CFG_MIC_KEY
extern void mic_key_open(void);
#endif
static void uart_i2c_switch(void) {
static int flag = 0;
flag ^= 1;
if (flag) {
hal_iomux_set_analog_i2c();
} else {
hal_iomux_set_uart0();
}
}
static int POSSIBLY_UNUSED key_event_process(uint32_t key_code,
uint8_t key_event) {
TRACE(3, "%s: code=0x%X, event=%u", __FUNCTION__, key_code, key_event);
#ifdef CFG_HW_KEY_LED_PIN
if (key_event == HAL_KEY_EVENT_DOWN) {
hal_gpio_pin_set(CFG_HW_KEY_LED_PIN);
} else if (key_event == HAL_KEY_EVENT_UP) {
hal_gpio_pin_clr(CFG_HW_KEY_LED_PIN);
}
#endif
#ifdef USB_AUDIO_APP
if (usb_audio_app_key(key_code, key_event) == 0) {
return 0;
}
#endif
#ifdef ANC_APP
if (anc_usb_app_key(key_code, key_event) == 0) {
return 0;
}
#endif
if (key_event == HAL_KEY_EVENT_CLICK) {
if (key_code == HAL_KEY_CODE_FN9) {
uart_i2c_switch();
}
}
return 0;
}
void anc_usb_open(void) {
TRACE(1, "%s", __FUNCTION__);
#ifdef __AUDIO_RESAMPLE__
hal_cmu_audio_resample_enable();
#endif
#ifdef USB_AUDIO_APP
struct USB_AUDIO_BUF_CFG cfg;
memset(&cfg, 0, sizeof(cfg));
cfg.play_buf = playback_buff;
#ifdef AUDIO_ANC_FB_MC
cfg.play_size = sizeof(playback_buff) / 9;
#else
cfg.play_size = sizeof(playback_buff);
#endif
cfg.cap_buf = capture_buff;
cfg.cap_size = sizeof(capture_buff);
cfg.recv_buf = recv_buff;
cfg.recv_size = sizeof(recv_buff);
cfg.send_buf = send_buff;
cfg.send_size = sizeof(send_buff);
cfg.eq_buf = eq_buff;
cfg.eq_size = sizeof(eq_buff);
cfg.resample_buf = resample_buff;
cfg.resample_size = sizeof(resample_buff);
usb_audio_app_init(&cfg);
usb_audio_app(1);
#endif
#ifdef ANC_APP
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, SAMPLE_RATE_PLAYBACK,
SAMPLE_RATE_CAPTURE);
#endif
#ifdef DUALADC_AUDIO_TEST
dualadc_audio_app_init(playback_buff, USB_AUDIO_PLAYBACK_BUFF_SIZE,
capture_buff, USB_AUDIO_CAPTURE_BUFF_SIZE);
dualadc_audio_app(1);
#endif
#if defined(CFG_MIC_KEY)
mic_key_open();
#endif
#ifdef BT_USB_AUDIO_DUAL_MODE
return;
#endif
// Allow sleep
hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_32K);
while (1) {
#ifdef USB_AUDIO_APP
usb_audio_app_loop();
#endif
#ifdef ANC_APP
anc_usb_app_loop();
#endif
#ifdef RTOS
// Let the task sleep
osDelay(20);
#else // !RTOS
#ifdef __PC_CMD_UART__
hal_cmd_run();
#endif
hal_sleep_enter_sleep();
#endif // !RTOS
}
}
void anc_usb_close(void) { usb_audio_app(0); }
#ifdef CFG_HW_GPADCKEY
void gpadc_key_handler(uint16_t irq_val, HAL_GPADC_MV_T volt) {
static uint16_t stable_cnt = 0;
static uint16_t click_cnt = 0;
static uint32_t click_time;
uint32_t time;
enum HAL_KEY_EVENT_T event;
bool send_event = false;
time = hal_sys_timer_get();
if (volt < 100) {
stable_cnt++;
// TRACE(5,"adc_key down: volt=%u stable=%u click_cnt=%u click_time=%u
// time=%u", volt, stable_cnt, click_cnt, click_time, time);
} else {
if (stable_cnt > 1) {
// TRACE(5,"adc_key up: volt=%u stable=%u click_cnt=%u click_time=%u
// time=%u", volt, stable_cnt, click_cnt, click_time, time);
if (click_cnt == 0 || (time - click_time) < MS_TO_TICKS(500)) {
click_time = time;
click_cnt++;
if (click_cnt >= 3) {
send_event = true;
}
} else {
send_event = true;
}
}
stable_cnt = 0;
if (click_cnt > 0 && (time - click_time) >= MS_TO_TICKS(500)) {
send_event = true;
}
if (send_event) {
// TRACE(5,"adc_key click: volt=%u stable=%u click_cnt=%u click_time=%u
// time=%u", volt, stable_cnt, click_cnt, click_time, time);
if (click_cnt == 1) {
event = HAL_KEY_EVENT_CLICK;
} else if (click_cnt == 2) {
event = HAL_KEY_EVENT_DOUBLECLICK;
} else {
event = HAL_KEY_EVENT_TRIPLECLICK;
}
key_event_process(CFG_HW_GPADCKEY, event);
click_cnt = 0;
}
}
}
#endif
// GDB can set a breakpoint on the main function only if it is
// declared as below, when linking with STD libraries.
int btusbaudio_entry(void) {
anc_usb_open();
return 0;
}
void btusbaudio_exit(void) { anc_usb_close(); }

View File

@ -1,7 +0,0 @@
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
obj-y := $(obj-y:.c=.o)
obj-y := $(obj-y:.cpp=.o)
obj-y := $(obj-y:.S=.o)

View File

@ -1,18 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "app_thread.h"
#include "cmsis_os.h"
#include "hal_trace.h"

View File

@ -1,27 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __APP_USBHOST_H__
#define __APP_USBHOST_H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif//__FMDEC_H__

View File

@ -19,7 +19,6 @@ obj-y := $(obj-y:.S=.o)
ccflags-y += \ ccflags-y += \
-Iplatform/hal \ -Iplatform/hal \
-Iplatform/drivers/usb/usb_dev/inc \
-Iservices/nv_section/aud_section \ -Iservices/nv_section/aud_section \
-Iservices/nv_section/include \ -Iservices/nv_section/include \
-Iservices/multimedia/speech/inc \ -Iservices/multimedia/speech/inc \

View File

@ -1,9 +1,5 @@
obj-y := ana/ codec/ norflash/ bt/ btpcm/ sbcacc/ obj-y := ana/ codec/ norflash/ bt/ btpcm/ sbcacc/
ifeq ($(CHIP_HAS_USB),1)
obj-y += usb/
endif
subdir-ccflags-y += -Iplatform/drivers/ana \ subdir-ccflags-y += -Iplatform/drivers/ana \
-Iplatform/drivers/bt -Iplatform/drivers/bt

View File

@ -1 +0,0 @@
obj-y := usb_dev/

View File

@ -1,130 +0,0 @@
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
src_obj := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)src/*.c $(cur_dir)src/*.S))
src_obj := $(src_obj:.c=.o)
src_obj := $(src_obj:.S=.o)
cfg_obj := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)cfg/*.c $(cur_dir)cfg/*.S))
cfg_obj := $(cfg_obj:.c=.o)
cfg_obj := $(cfg_obj:.S=.o)
USB_DEV_LIB_NAME := libusbdev
ccflags-y += -Iplatform/drivers/usb/usb_dev/inc
ifeq ($(USB_HIGH_SPEED),1)
ccflags-y += -DUSB_HIGH_SPEED
endif
CFLAGS_usb_cdc.o += -Itests/programmer/inc
CFLAGS_usb_audio.o += -Iutils/hwtimer_list
CFLAGS_usb_audio_sync.o += -Iplatform/drivers/ana
USB_AUDIO_NO_START_ERR ?= 1
ifeq ($(USB_AUDIO_NO_START_ERR),1)
CFLAGS_usb_audio.o += -DUSB_AUDIO_NO_START_ERR
endif
ifneq ($(USYNC_TRACE_VERBOSE),)
CFLAGS_usb_audio_sync.o += -DUSYNC_TRACE_VERBOSE=$(USYNC_TRACE_VERBOSE)
endif
ifneq ($(USB_CDC_VENDOR_ID),)
CFLAGS_usb_dev_desc.o += -DUSB_CDC_VENDOR_ID=$(USB_CDC_VENDOR_ID)
endif
ifneq ($(USB_CDC_PRODUCT_ID),)
CFLAGS_usb_dev_desc.o += -DUSB_CDC_PRODUCT_ID=$(USB_CDC_PRODUCT_ID)
endif
ifneq ($(USB_AUDIO_VENDOR_ID),)
CFLAGS_usb_dev_desc.o += -DUSB_AUDIO_VENDOR_ID=$(USB_AUDIO_VENDOR_ID)
endif
ifneq ($(USB_AUDIO_PRODUCT_ID),)
CFLAGS_usb_dev_desc.o += -DUSB_AUDIO_PRODUCT_ID=$(USB_AUDIO_PRODUCT_ID)
endif
ifeq ($(USB_LPM),1)
CFLAGS_usb_dev_desc.o += -DUSB_LPM
ifeq ($(USB_LPM_DEEP_BESL),1)
CFLAGS_usb_dev_desc.o += -DUSB_LPM_DEEP_BESL
endif
endif
include $(cur_dir)uaud_cfg_flags.mk
$(cur_dir)uaud_cfg_flags.mk: ;
ifeq ($(USB_AUDIO_DYN_CFG),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_dyn
else # USB_AUDIO_DYN_CFG != 1
ifeq ($(USB_AUDIO_384K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_384k
else ifeq ($(USB_AUDIO_352_8K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_352p8k
else ifeq ($(USB_AUDIO_192K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_192k
else ifeq ($(USB_AUDIO_176_4K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_176p4k
else ifeq ($(USB_AUDIO_96K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_96k
else ifeq ($(USB_AUDIO_44_1K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_44p1k
else ifeq ($(USB_AUDIO_16K),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_16k
endif
ifeq ($(USB_AUDIO_32BIT),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_32b
else
ifeq ($(USB_AUDIO_24BIT),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_24b
endif
endif
endif # USB_AUDIO_DYN_CFG != 1
ifneq ($(USB_AUDIO_SEND_CHAN),)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_s$(USB_AUDIO_SEND_CHAN)
endif
ifeq ($(USB_AUDIO_UAC2),1)
USB_DEV_LIB_NAME := $(USB_DEV_LIB_NAME)_uac2
endif
CFLAGS_usb_audio.o += $(UAUD_CFG_FLAGS)
CFLAGS_usb_dev_desc.o += $(UAUD_CFG_FLAGS)
ifeq ($(SIMU_UAUD_MAX_PKT),1)
CFLAGS_usb_audio.o += -DSIMU_UAUD_MAX_PKT
endif
ifeq ($(ANDROID_ACCESSORY_SPEC),1)
CFLAGS_usb_audio.o += -DANDROID_ACCESSORY_SPEC
ifeq ($(STRICT_ANDROID_ACCESSORY_SPEC),1)
CFLAGS_usb_audio.o += -DSTRICT_ANDROID_ACCESSORY_SPEC
ifeq ($(ANDROID_VOICE_CMD_KEY),1)
CFLAGS_usb_audio.o += -DANDROID_VOICE_CMD_KEY
endif
endif
endif
ifneq ($(USB_AUDIO_RECV_ENABLE),0)
CFLAGS_usb_audio.o += -DUSB_AUDIO_RECV_ENABLE
CFLAGS_usb_audio_sync.o += -DUSB_AUDIO_RECV_ENABLE
endif
ifneq ($(USB_AUDIO_SEND_ENABLE),0)
CFLAGS_usb_audio.o += -DUSB_AUDIO_SEND_ENABLE
CFLAGS_usb_audio_sync.o += -DUSB_AUDIO_SEND_ENABLE
endif
$(USB_DEV_LIB_NAME)-y := $(src_obj)
obj-y := $(USB_DEV_LIB_NAME).a $(cfg_obj)

View File

@ -1,499 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "usb_dev_desc.h"
#include "hal_usb.h"
#include "tgt_hardware.h"
#include "usb_descriptor.h"
#ifdef USB_HIGH_SPEED
#define DEV_QUAL_USB_VER 0x0200
#define USB_CDC_USB_VER 0x0200
#define USB_AUDIO_USB_VER 0x0201
#define USB_CDC_PRODUCT_ID_BASE 0x0120
#ifdef USB_AUDIO_UAC2
#define USB_AUDIO_PRODUCT_ID_BASE 0x0400
#else
#define USB_AUDIO_PRODUCT_ID_BASE 0x0300
#endif
#else
#define DEV_QUAL_USB_VER 0x0200
#define USB_CDC_USB_VER 0x0200 // 0x0110
#define USB_AUDIO_USB_VER 0x0200 // 0x0110
#define USB_CDC_PRODUCT_ID_BASE 0x0100
#define USB_AUDIO_PRODUCT_ID_BASE 0x0200
#ifdef USB_AUDIO_UAC2
#error "USB_AUDIO_UAC2 should run on USB_HIGH_SPEED"
#endif
#endif
#ifndef USB_CDC_VENDOR_ID
#define USB_CDC_VENDOR_ID 0xBE57
#endif
#ifndef USB_CDC_PRODUCT_ID
#define USB_CDC_PRODUCT_ID (USB_CDC_PRODUCT_ID_BASE + 0x01)
#endif
#ifndef USB_AUDIO_VENDOR_ID
#define USB_AUDIO_VENDOR_ID 0xBE57
#endif
#ifndef USB_AUDIO_PRODUCT_ID
#ifdef USB_AUDIO_DYN_CFG
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x31)
#ifdef USB_AUDIO_32BIT
#define USB_AUDIO_PRODUCT_32BIT_FLAG 0x0004
#else
#define USB_AUDIO_PRODUCT_32BIT_FLAG 0
#endif
#ifdef USB_AUDIO_24BIT
#define USB_AUDIO_PRODUCT_24BIT_FLAG 0x0002
#else
#define USB_AUDIO_PRODUCT_24BIT_FLAG 0
#endif
#ifdef USB_AUDIO_16BIT
#define USB_AUDIO_PRODUCT_16BIT_FLAG 0x0001
#else
#define USB_AUDIO_PRODUCT_16BIT_FLAG 0
#endif
#define USB_AUDIO_PRODUCT_ID \
(USB_AUDIO_PRODUCT_ID_STEM + USB_AUDIO_PRODUCT_32BIT_FLAG + \
USB_AUDIO_PRODUCT_24BIT_FLAG + USB_AUDIO_PRODUCT_16BIT_FLAG)
#else // !USB_AUDIO_DYN_CFG
#ifdef USB_AUDIO_384K
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x08)
#elif defined(USB_AUDIO_352_8K)
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x07)
#elif defined(USB_AUDIO_192K)
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x06)
#elif defined(USB_AUDIO_176_4K)
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x05)
#elif defined(USB_AUDIO_96K)
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x04)
#elif defined(USB_AUDIO_44_1K)
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x03)
#elif defined(USB_AUDIO_16K)
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x02)
#else // 48K
#define USB_AUDIO_PRODUCT_ID_STEM (USB_AUDIO_PRODUCT_ID_BASE + 0x01)
#endif
#define USB_AUDIO_PRODUCT_32BIT_FLAG 0x0020
#define USB_AUDIO_PRODUCT_24BIT_FLAG 0x0010
#ifdef USB_AUDIO_32BIT
#define USB_AUDIO_PRODUCT_ID \
(USB_AUDIO_PRODUCT_ID_STEM + USB_AUDIO_PRODUCT_32BIT_FLAG)
#elif defined(USB_AUDIO_24BIT)
#define USB_AUDIO_PRODUCT_ID \
(USB_AUDIO_PRODUCT_ID_STEM + USB_AUDIO_PRODUCT_24BIT_FLAG)
#else
#define USB_AUDIO_PRODUCT_ID (USB_AUDIO_PRODUCT_ID_STEM)
#endif
#endif // !USB_AUDIO_DYN_CFG
#endif // !USB_AUDIO_PRODUCT_ID
//----------------------------------------------------------------
// USB device common string descriptions
//----------------------------------------------------------------
static const uint8_t stringLangidDescriptor[] = {
0x04, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
0x09, 0x04, /*bString Lang ID - 0x0409 - English*/
};
static const uint8_t stringIconfigurationDescriptor[] = {
0x06, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'0',
0,
'1',
0, /*bString iConfiguration - 01*/
};
#ifdef USB_HIGH_SPEED
static const uint8_t deviceQualifierDescriptor[] = {
10,
QUALIFIER_DESCRIPTOR,
LSB(DEV_QUAL_USB_VER),
MSB(DEV_QUAL_USB_VER),
0, // bDeviceClass
0, // bDeviceSubClass
0, // bDeviceProtocol
USB_MAX_PACKET_SIZE_CTRL, // bMaxPacketSize0
0,
0,
};
static const uint8_t bosDescriptor[] = {
5,
BOS_DESCRIPTOR,
12,
0, // wTotalLength
1, // bNumDeviceCaps
7, // bLength
0x10, // bDescriptorType
0x02, // bDevCapabilityType
#ifdef USB_LPM
#ifdef USB_LPM_DEEP_BESL
0x1E, // bmAttributes: LPM, BESL, Baseline BESL, Deep BESL
#else
0x0E, // bmAttributes: LPM, BESL, Baseline BESL
#endif
(USB_L1_DEEP_SLEEP_BESL << 4) | USB_L1_LIGHT_SLEEP_BESL,
#else
0x00, // bmAttributes: none
0x00,
#endif
0x00,
0x00};
#endif
//----------------------------------------------------------------
// USB CDC device description and string descriptions
//----------------------------------------------------------------
const uint8_t *cdc_dev_desc(uint8_t type) {
static const uint8_t deviceDescriptor[] = {
18, // bLength
DEVICE_DESCRIPTOR, // bDescriptorType
LSB(USB_CDC_USB_VER),
MSB(USB_CDC_USB_VER), // bcdUSB
2, // bDeviceClass
0, // bDeviceSubClass
0, // bDeviceProtocol
USB_MAX_PACKET_SIZE_CTRL, // bMaxPacketSize0
LSB(USB_CDC_VENDOR_ID),
MSB(USB_CDC_VENDOR_ID), // idVendor
LSB(USB_CDC_PRODUCT_ID),
MSB(USB_CDC_PRODUCT_ID), // idProduct
0x00,
0x01, // bcdDevice
STRING_OFFSET_IMANUFACTURER, // iManufacturer
STRING_OFFSET_IPRODUCT, // iProduct
STRING_OFFSET_ISERIAL, // iSerialNumber
1 // bNumConfigurations
};
if (type == DEVICE_DESCRIPTOR) {
return deviceDescriptor;
#ifdef USB_HIGH_SPEED
} else if (type == QUALIFIER_DESCRIPTOR) {
return deviceQualifierDescriptor;
} else if (type == BOS_DESCRIPTOR) {
return bosDescriptor;
#endif
} else {
return NULL;
}
}
const uint8_t *cdc_string_desc(uint8_t index) {
static const uint8_t stringImanufacturerDescriptor[] =
#ifdef USB_CDC_STR_DESC_MANUFACTURER
USB_CDC_STR_DESC_MANUFACTURER;
#else
{
0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'b',
0,
'e',
0,
's',
0,
't',
0,
'e',
0,
'c',
0,
'h',
0,
'n',
0,
'i',
0,
'c',
0 /*bString iManufacturer - bestechnic*/
};
#endif
static const uint8_t stringIserialDescriptor[] =
#ifdef USB_CDC_STR_DESC_SERIAL
USB_CDC_STR_DESC_SERIAL;
#else
{
0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'2',
0,
'0',
0,
'1',
0,
'5',
0,
'1',
0,
'0',
0,
'0',
0,
'6',
0,
'.',
0,
'1',
0, /*bString iSerial - 20151006.1*/
};
#endif
static const uint8_t stringIinterfaceDescriptor[] =
#ifdef USB_CDC_STR_DESC_INTERFACE
USB_CDC_STR_DESC_INTERFACE;
#else
{
0x08, STRING_DESCRIPTOR, 'C', 0, 'D', 0, 'C', 0,
};
#endif
static const uint8_t stringIproductDescriptor[] =
#ifdef USB_CDC_STR_DESC_PRODUCT
USB_CDC_STR_DESC_PRODUCT;
#else
{0x16, STRING_DESCRIPTOR,
'C', 0,
'D', 0,
'C', 0,
' ', 0,
'D', 0,
'E', 0,
'V', 0,
'I', 0,
'C', 0,
'E', 0};
#endif
const uint8_t *data = NULL;
switch (index) {
case STRING_OFFSET_LANGID:
data = stringLangidDescriptor;
break;
case STRING_OFFSET_IMANUFACTURER:
data = stringImanufacturerDescriptor;
break;
case STRING_OFFSET_IPRODUCT:
data = stringIproductDescriptor;
break;
case STRING_OFFSET_ISERIAL:
data = stringIserialDescriptor;
break;
case STRING_OFFSET_ICONFIGURATION:
data = stringIconfigurationDescriptor;
break;
case STRING_OFFSET_IINTERFACE:
data = stringIinterfaceDescriptor;
break;
}
return data;
}
//----------------------------------------------------------------
// USB audio device description and string descriptions
//----------------------------------------------------------------
const uint8_t *uaud_dev_desc(uint8_t type) {
static const uint8_t deviceDescriptor[] = {
18, // bLength
DEVICE_DESCRIPTOR, // bDescriptorType
LSB(USB_AUDIO_USB_VER),
MSB(USB_AUDIO_USB_VER), // bcdUSB
0, // bDeviceClass
0, // bDeviceSubClass
0, // bDeviceProtocol
USB_MAX_PACKET_SIZE_CTRL, // bMaxPacketSize0
LSB(USB_AUDIO_VENDOR_ID),
MSB(USB_AUDIO_VENDOR_ID), // idVendor
LSB(USB_AUDIO_PRODUCT_ID),
MSB(USB_AUDIO_PRODUCT_ID), // idProduct
0x00,
0x01, // bcdDevice
STRING_OFFSET_IMANUFACTURER, // iManufacturer
STRING_OFFSET_IPRODUCT, // iProduct
STRING_OFFSET_ISERIAL, // iSerialNumber
1 // bNumConfigurations
};
if (type == DEVICE_DESCRIPTOR) {
return deviceDescriptor;
#ifdef USB_HIGH_SPEED
} else if (type == QUALIFIER_DESCRIPTOR) {
return deviceQualifierDescriptor;
} else if (type == BOS_DESCRIPTOR) {
return bosDescriptor;
#endif
} else {
return NULL;
}
}
const uint8_t *uaud_string_desc(uint8_t index) {
static const uint8_t stringImanufacturerDescriptor[] =
#ifdef USB_AUDIO_STR_DESC_MANUFACTURER
USB_AUDIO_STR_DESC_MANUFACTURER;
#else
{
0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'b',
0,
'e',
0,
's',
0,
't',
0,
'e',
0,
'c',
0,
'h',
0,
'n',
0,
'i',
0,
'c',
0 /*bString iManufacturer - bestechnic*/
};
#endif
static const uint8_t stringIserialDescriptor[] =
#ifdef USB_AUDIO_STR_DESC_SERIAL
USB_AUDIO_STR_DESC_SERIAL;
#else
{
0x16, /*bLength*/
STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
'2',
0,
'0',
0,
'1',
0,
'6',
0,
'0',
0,
'4',
0,
'0',
0,
'6',
0,
'.',
0,
'1',
0, /*bString iSerial - 20160406.1*/
};
#endif
static const uint8_t stringIinterfaceDescriptor[] =
#ifdef USB_AUDIO_STR_DESC_INTERFACE
USB_AUDIO_STR_DESC_INTERFACE;
#else
{
0x0c, // bLength
STRING_DESCRIPTOR, // bDescriptorType 0x03
'A',
0,
'u',
0,
'd',
0,
'i',
0,
'o',
0 // bString iInterface - Audio
};
#endif
static const uint8_t stringIproductDescriptor[] =
#ifdef USB_AUDIO_STR_DESC_PRODUCT
USB_AUDIO_STR_DESC_PRODUCT;
#else
{
0x16, // bLength
STRING_DESCRIPTOR, // bDescriptorType 0x03
'B',
0,
'e',
0,
's',
0,
't',
0,
' ',
0,
'A',
0,
'u',
0,
'd',
0,
'i',
0,
'o',
0 // bString iProduct - Best Audio
};
#endif
const uint8_t *data = NULL;
switch (index) {
case STRING_OFFSET_LANGID:
data = stringLangidDescriptor;
break;
case STRING_OFFSET_IMANUFACTURER:
data = stringImanufacturerDescriptor;
break;
case STRING_OFFSET_IPRODUCT:
data = stringIproductDescriptor;
break;
case STRING_OFFSET_ISERIAL:
data = stringIserialDescriptor;
break;
case STRING_OFFSET_ICONFIGURATION:
data = stringIconfigurationDescriptor;
break;
case STRING_OFFSET_IINTERFACE:
data = stringIinterfaceDescriptor;
break;
}
return data;
}

View File

@ -1,157 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_AUDIO_H__
#define __USB_AUDIO_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
#include "hal_usb.h"
enum USB_AUDIO_ITF_ID_T {
USB_AUDIO_ITF_ID_RECV,
USB_AUDIO_ITF_ID_SEND,
#ifdef USB_AUDIO_MULTIFUNC
USB_AUDIO_ITF_ID_RECV2,
#endif
USB_AUDIO_ITF_ID_QTY
};
enum USB_AUDIO_ITF_CMD_T {
USB_AUDIO_ITF_STOP,
USB_AUDIO_ITF_START_16BIT,
USB_AUDIO_ITF_START_24BIT,
USB_AUDIO_ITF_START_32BIT,
USB_AUDIO_ITF_CMD_QTY
};
enum USB_AUDIO_STATE_EVENT_T {
USB_AUDIO_STATE_RESET, // RESET event should be processed as quickly as possible
USB_AUDIO_STATE_DISCONNECT,
USB_AUDIO_STATE_SLEEP,
USB_AUDIO_STATE_WAKEUP,
USB_AUDIO_STATE_CONFIG,
USB_AUDIO_STATE_RECV_PAUSE,
USB_AUDIO_STATE_RECV_CONTINUE,
USB_AUDIO_STATE_SET_RECV_RATE,
USB_AUDIO_STATE_SET_SEND_RATE,
USB_AUDIO_STATE_RECV2_PAUSE,
USB_AUDIO_STATE_RECV2_CONTINUE,
USB_AUDIO_STATE_EVENT_QTY
};
enum USB_AUDIO_HID_EVENT_T {
USB_AUDIO_HID_VOL_UP = (1 << 0),
USB_AUDIO_HID_VOL_DOWN = (1 << 1),
USB_AUDIO_HID_PLAY_PAUSE = (1 << 2),
USB_AUDIO_HID_SCAN_NEXT = (1 << 3),
USB_AUDIO_HID_SCAN_PREV = (1 << 4),
USB_AUDIO_HID_STOP = (1 << 5),
USB_AUDIO_HID_FAST_FWD = (1 << 6),
USB_AUDIO_HID_REWIND = (1 << 7),
USB_AUDIO_HID_VOL_MUTE = (1 << 8),
USB_AUDIO_HID_VOICE_CMD = (1 << 9),
USB_AUDIO_HID_REDIAL = (1 << 10),
USB_AUDIO_HID_HOOK_SWITCH = (1 << 11),
USB_AUDIO_HID_MIC_MUTE = (1 << 12),
USB_AUDIO_HID_VOICE_MAIL = (1 << 13),
USB_AUDIO_HID_RESERVED_14 = (1 << 14),
USB_AUDIO_HID_RESERVED_15 = (1 << 15),
};
struct USB_AUDIO_XFER_INFO_T {
const uint8_t *data;
uint32_t size;
uint32_t next_size;
bool pool_enabled;
int8_t cur_compl_err;
int8_t next_xfer_err;
};
struct USB_AUDIO_VENDOR_MSG_T {
const struct SETUP_PACKET *pkt;
uint8_t *data;
uint16_t length;
};
typedef void (*USB_AUDIO_ITF_CALLBACK)(enum USB_AUDIO_ITF_ID_T id, enum USB_AUDIO_ITF_CMD_T cmd);
typedef void (*USB_AUDIO_MUTE_CALLBACK)(enum USB_AUDIO_ITF_ID_T id, uint32_t mute);
typedef void (*USB_AUDIO_SET_VOLUME)(enum USB_AUDIO_ITF_ID_T id, uint32_t percent);
typedef uint32_t (*USB_AUDIO_GET_VOLUME)(enum USB_AUDIO_ITF_ID_T id);
typedef void (*USB_AUDIO_XFER_CALLBACK)(enum USB_AUDIO_ITF_ID_T id, const struct USB_AUDIO_XFER_INFO_T *info);
typedef void (*USB_AUDIO_STATE_CALLBACK)(enum USB_AUDIO_STATE_EVENT_T event, uint32_t param);
typedef void (*HID_XFER_CALLBACK)(enum USB_AUDIO_HID_EVENT_T event, int error);
typedef int (*USB_AUDIO_VENDOR_MSG_CALLBACK)(struct USB_AUDIO_VENDOR_MSG_T *msg);
struct USB_AUDIO_CFG_T {
uint32_t recv_sample_rate;
uint32_t send_sample_rate;
uint8_t *vendor_rx_buf;
uint16_t vendor_rx_size;
USB_AUDIO_ITF_CALLBACK itf_callback;
USB_AUDIO_MUTE_CALLBACK mute_callback;
USB_AUDIO_SET_VOLUME set_volume;
USB_AUDIO_GET_VOLUME get_volume;
USB_AUDIO_STATE_CALLBACK state_callback;
USB_AUDIO_XFER_CALLBACK xfer_callback;
HID_XFER_CALLBACK hid_send_callback;
USB_AUDIO_VENDOR_MSG_CALLBACK vendor_msg_callback;
};
int usb_audio_open(const struct USB_AUDIO_CFG_T *cfg);
void usb_audio_close(void);
int usb_audio_recv_ready(void);
int usb_audio_send_ready(void);
int usb_audio_start_recv(uint8_t *buf, uint32_t pos, uint32_t size);
void usb_audio_stop_recv(void);
int usb_audio_start_send(const uint8_t *buf, uint32_t pos, uint32_t size);
void usb_audio_stop_send(void);
void usb_audio_pause_send(void);
int usb_audio_continue_send(uint32_t pos);
int usb_audio_set_recv_pos(uint32_t pos);
int usb_audio_set_send_pos(uint32_t pos);
void usb_audio_hid_set_event(enum USB_AUDIO_HID_EVENT_T event, int state);
const char *usb_audio_get_hid_event_name(enum USB_AUDIO_HID_EVENT_T event);
int usb_audio_start_recv2(uint8_t *buf, uint32_t pos, uint32_t size);
void usb_audio_stop_recv2(void);
int usb_audio_set_recv2_pos(uint32_t pos);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,72 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_AUDIO_SYNC_H__
#define __USB_AUDIO_SYNC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
typedef uint32_t (*USB_AUDIO_SYNC_TIME_TO_MS)(uint32_t time);
enum UAUD_SYNC_RET_T {
UAUD_SYNC_IDLE,
UAUD_SYNC_START,
UAUD_SYNC_ERR,
};
struct USB_AUDIO_STREAM_INFO_T {
// Difference error threshold
uint16_t err_thresh;
// Difference synchronization threshold
uint16_t sync_thresh;
// Sample rate
uint32_t samp_rate;
// Total sample count of the buffer
uint32_t samp_cnt;
// The number of value to calculate the average
uint8_t diff_avg_cnt;
// The stream info ID
uint8_t id;
// Whether to enable diff_target
uint8_t diff_target_enabled;
// The Max adjust ratio moving to diff_target
float max_target_ratio;
// The abosulte difference value between current diff and diff_target to apply max_target_ratio
uint32_t max_target_thresh;
// The target of the difference
int diff_target;
// Function to convert timestamp to ms. If NULL, default timer will be used.
USB_AUDIO_SYNC_TIME_TO_MS time_to_ms;
// Current timestamp. If time_to_ms is NULL, this member will be ignored.
uint32_t time;
// Internal control block
uint32_t ctrl_block[8];
};
void usb_audio_sync_reset(struct USB_AUDIO_STREAM_INFO_T *info);
int usb_audio_sync_normalize_diff(int diff, uint32_t size);
enum UAUD_SYNC_RET_T usb_audio_sync(uint32_t pos_a, uint32_t pos_b, struct USB_AUDIO_STREAM_INFO_T *info, float *p_ratio);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,126 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_CDC_H__
#define __USB_CDC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
enum USB_SERIAL_API_MODE {
USB_SERIAL_API_NONBLOCKING,
USB_SERIAL_API_BLOCKING,
};
enum USB_SERIAL_STATE_EVENT_T {
USB_SERIAL_STATE_RESET, // RESET event should be processed as quickly as possible
USB_SERIAL_STATE_DISCONNECT,
USB_SERIAL_STATE_SLEEP,
USB_SERIAL_STATE_WAKEUP,
USB_SERIAL_STATE_CONFIG,
USB_SERIAL_STATE_STALL_RECV,
USB_SERIAL_STATE_STALL_SEND,
USB_SERIAL_STATE_STALL_INTR,
USB_SERIAL_STATE_UNSTALL_RECV,
USB_SERIAL_STATE_UNSTALL_SEND,
USB_SERIAL_STATE_UNSTALL_INTR,
};
enum USB_SERIAL_RET_VALUE {
USB_ERR_OK = 0,
USB_ERR_RXTX_DATA = -1,
USB_ERR_NOT_DONE = -2,
USB_ERR_NOT_IDLE = -3,
USB_ERR_NOT_LOCK = -9,
USB_ERR_NOT_CONNECT = -10,
USB_ERR_INV_PARAM = -11,
USB_ERR_UNALIGNED = -12,
USB_ERR_RX_SIZE = -13,
USB_ERR_RXTX_CANCEL = -14,
};
enum USB_SERIAL_STOP_BITS_T {
USB_SERIAL_STOP_BITS_1 = 0,
USB_SERIAL_STOP_BITS_1P5 = 1,
USB_SERIAL_STOP_BITS_2 = 2,
};
enum USB_SERIAL_PARITY_T {
USB_SERIAL_PARITY_NONE = 0,
USB_SERIAL_PARITY_ODD = 1,
USB_SERIAL_PARITY_EVEN = 2,
USB_SERIAL_PARITY_MARK = 3,
USB_SERIAL_PARITY_SPACE = 4,
};
struct USB_SERIAL_LINE_CODING_T {
uint32_t rate;
uint8_t stop_bits;
uint8_t parity;
uint8_t data_bits;
};
typedef void (*USB_SERIAL_STATE_CALLBACK)(enum USB_SERIAL_STATE_EVENT_T event);
typedef void (*USB_SERIAL_BREAK_CALLBACK)(uint16_t ms);
typedef int (*USB_SERIAL_GET_LINE_CODING_CALLBACK)(struct USB_SERIAL_LINE_CODING_T *coding);
typedef int (*USB_SERIAL_SET_LINE_CODING_CALLBACK)(const struct USB_SERIAL_LINE_CODING_T *coding);
typedef void (*USB_SERIAL_XFER_CALLBACK)(const uint8_t *data, uint32_t size, int error);
struct USB_SERIAL_CFG_T {
USB_SERIAL_STATE_CALLBACK state_callback;
USB_SERIAL_BREAK_CALLBACK break_callback;
USB_SERIAL_GET_LINE_CODING_CALLBACK get_line_coding_callback;
USB_SERIAL_SET_LINE_CODING_CALLBACK set_line_coding_callback;
enum USB_SERIAL_API_MODE mode;
};
int usb_serial_open(const struct USB_SERIAL_CFG_T *cfg);
int usb_serial_reopen(USB_SERIAL_BREAK_CALLBACK break_handler);
void usb_serial_close(void);
int usb_serial_ready(void);
int usb_serial_connected(void);
void usb_serial_init_xfer(void);
void usb_serial_cancel_recv(void);
int usb_serial_flush_recv_buffer(void);
int usb_serial_recv(uint8_t *buf, uint32_t size);
int usb_serial_direct_recv(uint8_t *dma_buf, uint32_t size, uint32_t expect, uint32_t *recv,
USB_SERIAL_XFER_CALLBACK callback);
void usb_serial_cancel_send(void);
int usb_serial_send(const uint8_t *buf, uint32_t size);
int usb_serial_direct_send(const uint8_t *dma_buf, uint32_t size, USB_SERIAL_XFER_CALLBACK callback);
int usb_serial_send_break(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,144 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_DESCRIPTOR_H__
#define __USB_DESCRIPTOR_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Standard requests */
#define GET_STATUS (0)
#define CLEAR_FEATURE (1)
#define SET_FEATURE (3)
#define SET_ADDRESS (5)
#define GET_DESCRIPTOR (6)
#define SET_DESCRIPTOR (7)
#define GET_CONFIGURATION (8)
#define SET_CONFIGURATION (9)
#define GET_INTERFACE (10)
#define SET_INTERFACE (11)
/* bmRequestType.direction */
#define HOST_TO_DEVICE (0)
#define DEVICE_TO_HOST (1)
/* bmRequestType.type*/
#define STANDARD_TYPE (0)
#define CLASS_TYPE (1)
#define VENDOR_TYPE (2)
#define RESERVED_TYPE (3)
/* bmRequestType.recipient */
#define DEVICE_RECIPIENT (0)
#define INTERFACE_RECIPIENT (1)
#define ENDPOINT_RECIPIENT (2)
#define OTHER_RECIPIENT (3)
/* Descriptors */
#define DESCRIPTOR_TYPE(wValue) (wValue >> 8)
#define DESCRIPTOR_INDEX(wValue) (wValue & 0xff)
/* Device status */
#define DEVICE_STATUS_SELF_POWERED (1U<<0)
#define DEVICE_STATUS_REMOTE_WAKEUP (1U<<1)
/* Endpoint status */
#define ENDPOINT_STATUS_HALT (1U<<0)
/* Standard feature selectors */
#define DEVICE_REMOTE_WAKEUP (1)
#define ENDPOINT_HALT (0)
#define TEST_MODE (2)
/* Test mode selectors */
#define TEST_MODE_TEST_J (1)
#define TEST_MODE_TEST_K (2)
#define TEST_MODE_TEST_SE0_NAK (3)
#define TEST_MODE_TEST_PACKET (4)
#define TEST_MODE_FORCE_ENABLE (5)
/* Standard descriptor types */
#define DEVICE_DESCRIPTOR (1)
#define CONFIGURATION_DESCRIPTOR (2)
#define STRING_DESCRIPTOR (3)
#define INTERFACE_DESCRIPTOR (4)
#define ENDPOINT_DESCRIPTOR (5)
#define QUALIFIER_DESCRIPTOR (6)
#define BOS_DESCRIPTOR (0xF)
/* Standard descriptor lengths */
#define DEVICE_DESCRIPTOR_LENGTH (0x12)
#define CONFIGURATION_DESCRIPTOR_LENGTH (0x09)
#define INTERFACE_DESCRIPTOR_LENGTH (0x09)
#define ENDPOINT_DESCRIPTOR_LENGTH (0x07)
#define QUALIFIER_DESCRIPTOR_LENGTH (0x0A)
#define BOS_DESCRIPTOR_LENGTH (0x05)
/*string offset*/
#define STRING_OFFSET_LANGID (0)
#define STRING_OFFSET_IMANUFACTURER (1)
#define STRING_OFFSET_IPRODUCT (2)
#define STRING_OFFSET_ISERIAL (3)
#define STRING_OFFSET_ICONFIGURATION (4)
#define STRING_OFFSET_IINTERFACE (5)
/* USB Specification Release Number */
#define USB_VERSION_2_0 (0x0200)
#define USB_VERSION_1_1 (0x0101)
/* Least/Most significant byte of short integer */
#define LSB(n) ((n)&0xff)
#define MSB(n) (((n)&0xff00)>>8)
#define LSB0(n) ((n) & 0xFF)
#define LSB1(n) (((n) >> 8) & 0xFF)
#define LSB2(n) (((n) >> 16) & 0xFF)
#define LSB3(n) (((n) >> 24) & 0xFF)
/* Convert physical endpoint number to descriptor endpoint number */
#define PHY_TO_DESC(endpoint, dir) (((endpoint) & 0xF) | ((dir == EP_OUT) ? 0 : 0x80))
/* bmAttributes in configuration descriptor */
/* C_RESERVED must always be set */
#define C_RESERVED (1U<<7)
#define C_SELF_POWERED (1U<<6)
#define C_REMOTE_WAKEUP (1U<<5)
/* bMaxPower in configuration descriptor */
#define C_POWER(mA) ((mA)/2)
/* bmAttributes in endpoint descriptor */
#define E_CONTROL (0x00)
#define E_ISOCHRONOUS (0x01)
#define E_BULK (0x02)
#define E_INTERRUPT (0x03)
/* For isochronous endpoints only: */
#define E_NO_SYNCHRONIZATION (0x00)
#define E_ASYNCHRONOUS (0x04)
#define E_ADAPTIVE (0x08)
#define E_SYNCHRONOUS (0x0C)
#define E_DATA (0x00)
#define E_FEEDBACK (0x10)
#define E_IMPLICIT_FEEDBACK (0x20)
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,65 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_DEV_DESC_H__
#define __USB_DEV_DESC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
#ifdef USB_AUDIO_32BIT
#if defined(USB_AUDIO_192K) && !defined(USB_HIGH_SPEED)
#error "192K 32BIT stream can run on USB_HIGH_SPEED only"
#endif
#if defined(USB_AUDIO_176_4K) && !defined(USB_HIGH_SPEED)
#error "176.4K 32BIT stream can run on USB_HIGH_SPEED only"
#endif
#elif defined(USB_AUDIO_24BIT)
#if defined(USB_AUDIO_192K) && !defined(USB_HIGH_SPEED)
#error "192K 24BIT stream can run on USB_HIGH_SPEED only"
#endif
#if defined(USB_AUDIO_176_4K) && !defined(USB_HIGH_SPEED)
#error "176.4K 24BIT stream can run on USB_HIGH_SPEED only"
#endif
#endif
#if defined(USB_AUDIO_384K) && !(defined(USB_HIGH_SPEED) && defined(USB_AUDIO_UAC2))
#error "384K stream can run on USB_HIGH_SPEED and USB_AUDIO_UAC2 only"
#endif
#if defined(USB_AUDIO_352_8K) && !(defined(USB_HIGH_SPEED) && defined(USB_AUDIO_UAC2))
#error "352.8K stream can run on USB_HIGH_SPEED and USB_AUDIO_UAC2 only"
#endif
#if defined(USB_AUDIO_UAC2) && !defined(USB_HIGH_SPEED)
#error "USB_AUDIO_UAC2 should run on USB_HIGH_SPEED"
#endif
const uint8_t *cdc_dev_desc(uint8_t type);
const uint8_t *cdc_string_desc(uint8_t index);
const uint8_t *uaud_dev_desc(uint8_t type);
const uint8_t *uaud_string_desc(uint8_t index);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,110 +0,0 @@
UAUD_CFG_FLAGS :=
ifeq ($(USB_AUDIO_DYN_CFG),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_DYN_CFG
USB_AUDIO_32BIT ?= 1
USB_AUDIO_24BIT ?= 1
USB_AUDIO_16BIT ?= 1
USB_AUDIO_16K ?= 1
USB_AUDIO_44_1K ?= 1
USB_AUDIO_48K ?= 1
USB_AUDIO_96K ?= 1
ifeq ($(USB_HIGH_SPEED),1)
USB_AUDIO_176_4K ?= 1
USB_AUDIO_192K ?= 1
ifeq ($(USB_AUDIO_UAC2),1)
USB_AUDIO_352_8K ?= 1
USB_AUDIO_384K ?= 1
endif
endif
else # USB_AUDIO_DYN_CFG != 1
ifeq ($(filter 1,$(USB_AUDIO_384K) $(USB_AUDIO_352_8K) $(USB_AUDIO_192K) $(USB_AUDIO_176_4K) \
$(USB_AUDIO_96K) $(USB_AUDIO_44_1K) $(USB_AUDIO_16K)),)
USB_AUDIO_48K := 1
endif
ifeq ($(filter 1,$(USB_AUDIO_32BIT) $(USB_AUDIO_24BIT)),)
USB_AUDIO_16BIT := 1
endif
endif # USB_AUDIO_DYN_CFG != 1
ifeq ($(filter 1,$(USB_AUDIO_384K) $(USB_AUDIO_352_8K) $(USB_AUDIO_192K) $(USB_AUDIO_176_4K) \
$(USB_AUDIO_96K) $(USB_AUDIO_48K) $(USB_AUDIO_44_1K) $(USB_AUDIO_16K)),)
$(error None of usb audio sample rates is enabled)
endif
ifeq ($(USB_AUDIO_384K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_384K
endif
ifeq ($(USB_AUDIO_352_8K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_352_8K
endif
ifeq ($(USB_AUDIO_192K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_192K
endif
ifeq ($(USB_AUDIO_176_4K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_176_4K
endif
ifeq ($(USB_AUDIO_96K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_96K
endif
ifeq ($(USB_AUDIO_48K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_48K
endif
ifeq ($(USB_AUDIO_44_1K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_44_1K
endif
ifeq ($(USB_AUDIO_16K),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_16K
endif
ifeq ($(filter 1,$(USB_AUDIO_32BIT) $(USB_AUDIO_24BIT) $(USB_AUDIO_16BIT)),)
$(error None of USB_AUDIO_32BIT/USB_AUDIO_24BIT/USB_AUDIO_16BIT is enabled)
endif
ifeq ($(USB_AUDIO_32BIT),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_32BIT
endif
ifeq ($(USB_AUDIO_24BIT),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_24BIT
endif
ifeq ($(USB_AUDIO_16BIT),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_16BIT
endif
ifeq ($(filter 1,$(USB_AUDIO_SEND_32BIT) $(USB_AUDIO_SEND_24BIT)),)
USB_AUDIO_SEND_16BIT := 1
ifneq ($(USB_AUDIO_SEND_16BIT),1)
$(error None of USB_AUDIO_SEND_32BIT/USB_AUDIO_SEND_24BIT/USB_AUDIO_SEND_16BIT is enabled)
endif
endif
ifeq ($(USB_AUDIO_SEND_32BIT),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_SEND_32BIT
endif
ifeq ($(USB_AUDIO_SEND_24BIT),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_SEND_24BIT
endif
ifeq ($(USB_AUDIO_SEND_16BIT),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_SEND_16BIT
endif
ifneq ($(USB_AUDIO_SEND_CHAN),)
UAUD_CFG_FLAGS += -DUSB_AUDIO_SEND_CHAN=$(USB_AUDIO_SEND_CHAN)
endif
ifeq ($(USB_AUDIO_UAC2),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_UAC2
endif
ifeq ($(USB_AUDIO_MULTIFUNC),1)
UAUD_CFG_FLAGS += -DUSB_AUDIO_MULTIFUNC
endif

View File

@ -1,20 +0,0 @@
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
src_obj := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
src_obj := $(src_obj:.c=.o)
src_obj := $(src_obj:.cpp=.o)
src_obj := $(src_obj:.S=.o)
libusbhost-y := $(src_obj)
obj-y := libusbhost.a
ccflags-y := -Iplatform-Iplatform/drivers/usb/usb_host/inc -Iplatform/drivers/ana
ifeq ($(USB_WAKEUP_OPEN),1)
CFLAGS_USBHost.o += -DUSB_WAKEUP_OPEN
endif
ifeq ($(USB_WAKEUP_RESET),1)
CFLAGS_USBHost.o += -DUSB_WAKEUP_RESET
endif

View File

@ -1,193 +0,0 @@
/*
Copyright (c) 2010 Peter Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef USBHOST_H
#define USBHOST_H
#include "plat_types.h"
#define ENDPOINT_CONTROL 0
#define ENDPOINT_ISOCRONOUS 1
#define ENDPOINT_BULK 2
#define ENDPOINT_INTERRUPT 3
#define DESCRIPTOR_TYPE_DEVICE 1
#define DESCRIPTOR_TYPE_CONFIGURATION 2
#define DESCRIPTOR_TYPE_STRING 3
#define DESCRIPTOR_TYPE_INTERFACE 4
#define DESCRIPTOR_TYPE_ENDPOINT 5
#define DESCRIPTOR_TYPE_HID 0x21
#define DESCRIPTOR_TYPE_REPORT 0x22
#define DESCRIPTOR_TYPE_PHYSICAL 0x23
#define DESCRIPTOR_TYPE_HUB 0x29
enum USB_CLASS_CODE
{
CLASS_DEVICE,
CLASS_AUDIO,
CLASS_COMM_AND_CDC_CONTROL,
CLASS_HID,
CLASS_PHYSICAL = 0x05,
CLASS_STILL_IMAGING,
CLASS_PRINTER,
CLASS_MASS_STORAGE,
CLASS_HUB,
CLASS_CDC_DATA,
CLASS_SMART_CARD,
CLASS_CONTENT_SECURITY = 0x0D,
CLASS_VIDEO = 0x0E,
CLASS_DIAGNOSTIC_DEVICE = 0xDC,
CLASS_WIRELESS_CONTROLLER = 0xE0,
CLASS_MISCELLANEOUS = 0xEF,
CLASS_APP_SPECIFIC = 0xFE,
CLASS_VENDOR_SPECIFIC = 0xFF
};
#define DEVICE_TO_HOST 0x80
#define HOST_TO_DEVICE 0x00
#define REQUEST_TYPE_CLASS 0x20
#define RECIPIENT_DEVICE 0x00
#define RECIPIENT_INTERFACE 0x01
#define RECIPIENT_ENDPOINT 0x02
#define RECIPIENT_OTHER 0x03
#define GET_STATUS 0
#define CLEAR_FEATURE 1
#define SET_FEATURE 3
#define SET_ADDRESS 5
#define GET_DESCRIPTOR 6
#define SET_DESCRIPTOR 7
#define GET_CONFIGURATION 8
#define SET_CONFIGURATION 9
#define GET_INTERFACE 10
#define SET_INTERFACE 11
#define SYNCH_FRAME 11
// -5 is nak
/*
0010 ACK Handshake
1010 NAK Handshake
1110 STALL Handshake
0110 NYET (No Response Yet)
*/
#define IO_PENDING -100
#define ERR_ENDPOINT_NONE_LEFT -101
#define ERR_ENDPOINT_NOT_FOUND -102
#define ERR_DEVICE_NOT_FOUND -103
#define ERR_DEVICE_NONE_LEFT -104
#define ERR_HUB_INIT_FAILED -105
#define ERR_INTERFACE_NOT_FOUND -106
typedef struct
{
u8 bLength;
u8 bDescriptorType;
u16 bcdUSB;
u8 bDeviceClass;
u8 bDeviceSubClass;
u8 bDeviceProtocol;
u8 bMaxPacketSize;
u16 idVendor;
u16 idProduct;
u16 bcdDevice; // version
u8 iManufacturer;
u8 iProduct;
u8 iSerialNumber;
u8 bNumConfigurations;
} DeviceDescriptor; // 16 bytes
typedef struct
{
u8 bLength;
u8 bDescriptorType;
u16 wTotalLength;
u8 bNumInterfaces;
u8 bConfigurationValue; // Value to use as an argument to select this configuration
u8 iConfiguration; // Index of String Descriptor describing this configuration
u8 bmAttributes; // Bitmap D7 Reserved, set to 1. (USB 1.0 Bus Powered),D6 Self Powered,D5 Remote Wakeup,D4..0 = 0
u8 bMaxPower; // Maximum Power Consumption in 2mA units
} ConfigurationDescriptor;
typedef struct
{
u8 bLength;
u8 bDescriptorType;
u8 bInterfaceNumber;
u8 bAlternateSetting;
u8 bNumEndpoints;
u8 bInterfaceClass;
u8 bInterfaceSubClass;
u8 bInterfaceProtocol;
u8 iInterface; // Index of String Descriptor Describing this interface
} InterfaceDescriptor;
typedef struct
{
u8 bLength;
u8 bDescriptorType;
u8 bEndpointAddress; // Bits 0:3 endpoint, Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)
u8 bmAttributes; // Bits 0:1 00 = Control, 01 = Isochronous, 10 = Bulk, 11 = Interrupt
u16 wMaxPacketSize;
u8 bInterval; // Interval for polling endpoint data transfers.
} EndpointDescriptor;
typedef struct {
u8 bLength;
u8 bDescriptorType;
u16 bcdHID;
u8 bCountryCode;
u8 bNumDescriptors;
u8 bDescriptorType2;
u16 wDescriptorLength;
} HIDDescriptor;
//============================================================================
//============================================================================
void USBInit();
void USBLoop();
u8* USBGetBuffer(u32* len);
// Optional callback for transfers, called at interrupt time
typedef void (*USBCallback)(int device, int endpoint, int status, u8* data, int len, void* userData);
// Transfers
int USBControlTransfer(int device, int request_type, int request, int value, int index, u8* data, int length, USBCallback callback = 0, void* userData = 0);
int USBInterruptTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0);
int USBBulkTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0);
// Standard Device methods
int GetDescriptor(int device, int descType, int descIndex, u8* data, int length);
int GetString(int device, int index, char* dst, int length);
int SetAddress(int device, int new_addr);
int SetConfiguration(int device, int configNum);
int SetInterface(int device, int ifNum, int altNum);
// Implemented to notify app of the arrival of a device
void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc, u8 *itfDescEnd);
void OnUnloadDevice(int device);
#endif

View File

@ -1,49 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef USB_TESTER_H
#define USB_TESTER_H
#include "FATFileSystem.h"
#include <stdint.h>
class USBFileSystem : public FATFileSystem
{
public:
USBFileSystem();
void SetDevice(int device);
int GetDevice(void);
virtual int disk_initialize();
virtual int disk_write(const uint8_t * buffer, uint64_t sector, uint8_t count);
virtual int disk_read(uint8_t * buffer, uint64_t sector, uint8_t count);
virtual uint64_t disk_sectors();
protected:
int _device;
u32 _blockSize;
u32 _blockCount;
};
#endif

View File

@ -357,7 +357,6 @@ ifneq ($(DEBUG_PORT),)
CFLAGS_hal_uart.o += -DDEBUG_PORT=$(DEBUG_PORT) CFLAGS_hal_uart.o += -DDEBUG_PORT=$(DEBUG_PORT)
endif endif
CFLAGS_hal_usb.o += -Iplatform/drivers/usb/usb_dev/inc -Iutils/hwtimer_list
ifeq ($(USB_ISO),1) ifeq ($(USB_ISO),1)
CFLAGS_hal_usb.o += -DUSB_ISO CFLAGS_hal_usb.o += -DUSB_ISO

File diff suppressed because it is too large Load Diff

View File

@ -1,232 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __HAL_USB_H__
#define __HAL_USB_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
#include "stdbool.h"
#define USB_MAX_PACKET_SIZE_CTRL 64
#ifdef USB_HIGH_SPEED
#define USB_MAX_PACKET_SIZE_BULK 512
#define USB_MAX_PACKET_SIZE_INT 1024
#define USB_MAX_PACKET_SIZE_ISO 1024
#define USB_FIFO_MPS_ISO_SEND 800
#else
#define USB_MAX_PACKET_SIZE_BULK 64
#define USB_MAX_PACKET_SIZE_INT 64
#define USB_MAX_PACKET_SIZE_ISO 1023
#define USB_FIFO_MPS_ISO_SEND 768
#endif
// H/w register bit field width limitation
#define EPN_MAX_PKTCNT ((1 << 10) - 1)
#define EPN_MAX_XFERSIZE ((1 << 19) - 1)
#define EPNUM 6
#define CTRL_EPNUM 2
#define USB_L1_LIGHT_SLEEP_BESL USB_BESL_125US
#define USB_L1_DEEP_SLEEP_BESL USB_BESL_6000US
enum HAL_USB_API_MODE {
HAL_USB_API_NONBLOCKING,
HAL_USB_API_BLOCKING,
};
enum EP_DIR {
EP_OUT,
EP_IN,
};
enum CTRL_STAGE {
NONE_STAGE,
WAIT_SETUP_STAGE,
SETUP_STAGE,
DATA_OUT_STAGE,
DATA_IN_STAGE,
STATUS_OUT_STAGE,
STATUS_IN_STAGE,
};
enum ZLP_STATE {
ZLP_AUTO,
ZLP_DISABLED,
};
enum XFER_COMPL_STATE {
XFER_COMPL_SUCCESS,
XFER_COMPL_ERROR,
};
enum HAL_USB_STATE_EVENT {
HAL_USB_EVENT_RESET, // RESET event should be processed as quickly as possible
HAL_USB_EVENT_DISCONNECT,
HAL_USB_EVENT_SUSPEND,
HAL_USB_EVENT_L1_DEEP_SLEEP,
HAL_USB_EVENT_RESUME,
HAL_USB_EVENT_STALL,
HAL_USB_EVENT_UNSTALL,
HAL_USB_EVENT_QTY
};
enum USB_BESL_T {
USB_BESL_125US = 0,
USB_BESL_150US,
USB_BESL_200US,
USB_BESL_300US,
USB_BESL_400US,
USB_BESL_500US,
USB_BESL_1000US,
USB_BESL_2000US,
USB_BESL_3000US,
USB_BESL_4000US,
USB_BESL_5000US,
USB_BESL_6000US,
USB_BESL_7000US,
USB_BESL_8000US,
USB_BESL_9000US,
USB_BESL_10000US,
};
enum USB_BESL_HIRD_T {
USB_BESL_HIRD_75US,
USB_BESL_HIRD_100US,
USB_BESL_HIRD_150US,
USB_BESL_HIRD_250US,
USB_BESL_HIRD_350US,
USB_BESL_HIRD_450US,
USB_BESL_HIRD_950US,
USB_BESL_HIRD_1950US,
USB_BESL_HIRD_2950US,
USB_BESL_HIRD_3950US,
USB_BESL_HIRD_4950US,
USB_BESL_HIRD_5950US,
USB_BESL_HIRD_6950US,
USB_BESL_HIRD_7950US,
USB_BESL_HIRD_8950US,
USB_BESL_HIRD_9950US,
};
enum USB_HIRD_T {
USB_HIRD_50US,
USB_HIRD_125US,
USB_HIRD_200US,
USB_HIRD_275US,
USB_HIRD_350US,
USB_HIRD_425US,
USB_HIRD_500US,
USB_HIRD_575US,
USB_HIRD_650US,
USB_HIRD_725US,
USB_HIRD_800US,
USB_HIRD_875US,
USB_HIRD_950US,
USB_HIRD_1025US,
USB_HIRD_1100US,
USB_HIRD_1175US,
};
struct SETUP_PACKET {
struct {
uint8_t recipient : 5;
uint8_t type : 2;
uint8_t direction : 1;
} bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
};
struct EP0_TRANSFER {
enum CTRL_STAGE stage;
uint8_t *data;
uint16_t length;
uint16_t trx_len;
struct SETUP_PACKET setup_pkt;
};
typedef const uint8_t *(*HAL_USB_GET_DESCRIPTOR_CALLBACK)(uint8_t);
typedef bool (*HAL_USB_SETUPRECV_CALLBACK)(struct EP0_TRANSFER *);
typedef bool (*HAL_USB_DATARECV_CALLBACK)(struct EP0_TRANSFER *);
typedef bool (*HAL_USB_SETCFG_CALLBACK)(uint8_t);
typedef bool (*HAL_USB_SETITF_CALLBACK)(uint16_t, uint16_t);
typedef void (*HAL_USB_REMOTE_WAKEUP_CALLBACK)(int enable);
typedef void (*HAL_USB_STATE_CHANGE_CALLBACK)(enum HAL_USB_STATE_EVENT, uint32_t);
typedef bool (*HAL_USB_RECV_COMPL_CALLBACK)(const uint8_t *, uint32_t, enum XFER_COMPL_STATE);
typedef bool (*HAL_USB_SEND_COMPL_CALLBACK)(const uint8_t *, uint32_t, enum XFER_COMPL_STATE);
struct HAL_USB_CALLBACKS {
HAL_USB_GET_DESCRIPTOR_CALLBACK device_desc;
HAL_USB_GET_DESCRIPTOR_CALLBACK cfg_desc;
HAL_USB_GET_DESCRIPTOR_CALLBACK string_desc;
HAL_USB_SETUPRECV_CALLBACK setuprecv;
HAL_USB_DATARECV_CALLBACK datarecv;
HAL_USB_SETCFG_CALLBACK setcfg;
HAL_USB_SETITF_CALLBACK setitf;
HAL_USB_REMOTE_WAKEUP_CALLBACK set_remote_wakeup;
HAL_USB_STATE_CHANGE_CALLBACK state_change;
HAL_USB_RECV_COMPL_CALLBACK epn_recv_compl[EPNUM - 1];
HAL_USB_SEND_COMPL_CALLBACK epn_send_compl[EPNUM - 1];
};
int hal_usb_open(const struct HAL_USB_CALLBACKS *c, enum HAL_USB_API_MODE m);
int hal_usb_reopen(const struct HAL_USB_CALLBACKS *c, uint8_t dcfg, uint8_t alt, uint16_t itf);
void hal_usb_close(void);
int hal_usb_remote_wakeup(int signal);
void hal_usb_detect_disconn(void);
void hal_usb_lpm_sleep_enable(void);
void hal_usb_lpm_sleep_disable(void);
int hal_usb_configured(void);
int hal_usb_suspended(void);
uint32_t hal_usb_calc_hshb_ep_mps(uint32_t pkt_size);
int hal_usb_activate_epn(enum EP_DIR dir, uint8_t ep, uint8_t type, uint16_t mps);
int hal_usb_deactivate_epn(enum EP_DIR dir, uint8_t ep);
int hal_usb_update_recv_epn_mps(uint8_t ep, uint16_t mps);
int hal_usb_update_send_epn_mc(uint8_t ep, uint8_t mc);
void hal_usb_disable_ep(enum EP_DIR dir, uint8_t ep);
void hal_usb_stall_ep(enum EP_DIR dir, uint8_t ep);
void hal_usb_unstall_ep(enum EP_DIR dir, uint8_t ep);
int hal_usb_get_ep_stall_state(enum EP_DIR dir, uint8_t ep);
void hal_usb_stop_ep(enum EP_DIR dir, uint8_t ep);
int hal_usb_recv_epn(uint8_t ep, uint8_t *buffer, uint32_t size);
int hal_usb_send_epn(uint8_t ep, const uint8_t *buffer, uint32_t size, enum ZLP_STATE zlp);
uint32_t hal_usb_get_soffn(void);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,173 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __HAL_USB_H__
#define __HAL_USB_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "stdint.h"
#include "stdbool.h"
#ifdef USB_HIGH_SPEED
#define MAX_USBHOST_PACKET_SIZE 512
#else
#define MAX_USBHOST_PACKET_SIZE 64
#endif
#define USBHOST_EPNUM 6
#define HAL_USBHOST_CHAN_NONE 0xFF
enum HAL_USBHOST_EP_TYPE_T {
HAL_USBHOST_EP_CTRL,
HAL_USBHOST_EP_ISO,
HAL_USBHOST_EP_BULK,
HAL_USBHOST_EP_INT,
HAL_USBHOST_EP_QTY
};
enum HAL_USBHOST_PID_TYPE_T {
HAL_USBHOST_PID_DATA0 = 0,
HAL_USBHOST_PID_DATA2 = 1,
HAL_USBHOST_PID_DATA1 = 2,
HAL_USBHOST_PID_MDATA = 3,
HAL_USBHOST_PID_SETUP = 3,
HAL_USBHOST_PID_QTY,
HAL_USBHOST_PID_AUTO = 0xFF,
};
enum HAL_USBHOST_PORT_EVENT_T {
HAL_USBHOST_PORT_CONN,
HAL_USBHOST_PORT_EN_LS,
HAL_USBHOST_PORT_EN_FS,
HAL_USBHOST_PORT_EN_HS,
HAL_USBHOST_PORT_EN_BAD,
HAL_USBHOST_PORT_DISCONN,
HAL_USBHOST_PORT_QTY
};
enum HAL_USBHOST_SETUP_STAGE_T {
HAL_USBHOST_SETUP_DATA_IN,
HAL_USBHOST_SETUP_DATA_OUT,
HAL_USBHOST_SETUP_STATUS_IN,
HAL_USBHOST_SETUP_STATUS_OUT,
HAL_USBHOST_SETUP_DONE,
HAL_USBHOST_SETUP_ERROR,
HAL_USBHOST_SETUP_STAGE_QTY
};
enum HAL_USBHOST_XFER_ERR_T {
HAL_USBHOST_XFER_ERR_NONE,
HAL_USBHOST_XFER_ERR_AHB,
HAL_USBHOST_XFER_ERR_STALL,
HAL_USBHOST_XFER_ERR_TRANSACTION,
HAL_USBHOST_XFER_ERR_BABBLE,
HAL_USBHOST_XFER_ERR_FRAME_OVERRUN,
HAL_USBHOST_XFER_ERR_DATA_TOGGLE,
HAL_USBHOST_XFER_ERR_TIMEOUT,
HAL_USBHOST_XFER_ERR_DISCONN,
HAL_USBHOST_XFER_ERR_QTY
};
struct HAL_USBHOST_SETUP_XFER_T;
typedef void (*HAL_USBHOST_DELAY_FUNC)(uint32_t ms);
typedef void (*HAL_USBHOST_PORT_HANDLER)(enum HAL_USBHOST_PORT_EVENT_T evt);
typedef void (*HAL_USBHOST_XFER_COMPL_HANDLER)(uint8_t chan, uint8_t *buf, uint32_t len, enum HAL_USBHOST_XFER_ERR_T error);
typedef void (*HAL_USBHOST_SETUP_COMPL_HANDLER)(struct HAL_USBHOST_SETUP_XFER_T *setup, int error);
enum HAL_USBHOST_PLUG_STATUS_T {
HAL_USBHOST_PLUG_UNKNOWN,
HAL_USBHOST_PLUG_IN,
HAL_USBHOST_PLUG_OUT,
};
typedef void (*HAL_USBHOST_PLUG_HANDLER)(enum HAL_USBHOST_PLUG_STATUS_T status);
struct HAL_USBHOST_CHAN_TYPE_T {
uint16_t mps;
uint8_t ep_num;
uint8_t ep_in;
enum HAL_USBHOST_EP_TYPE_T ep_type;
uint8_t dev_addr;
};
struct HAL_USBHOST_XFER_T {
uint8_t *buf;
uint32_t size;
uint8_t multi_cnt;
enum HAL_USBHOST_PID_TYPE_T pid;
HAL_USBHOST_XFER_COMPL_HANDLER handler;
};
struct HAL_USBHOST_SETUP_PKT_T {
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
};
struct HAL_USBHOST_SETUP_XFER_T {
struct HAL_USBHOST_SETUP_PKT_T setup_pkt;
enum HAL_USBHOST_SETUP_STAGE_T next_stage;
HAL_USBHOST_SETUP_COMPL_HANDLER handler;
uint8_t *data_buf;
uint8_t chan_out;
uint8_t chan_in;
};
int hal_usbhost_open(HAL_USBHOST_PORT_HANDLER port_cb, HAL_USBHOST_DELAY_FUNC delay_fn);
void hal_usbhost_close(void);
void hal_usbhost_halt_chan(uint8_t chan);
void hal_usbhost_port_reset(uint32_t ms);
int hal_usbhost_get_chan(uint8_t *chan);
int hal_usbhost_free_chan(uint8_t chan);
int hal_usbhost_init_chan(uint8_t chan, const struct HAL_USBHOST_CHAN_TYPE_T *type);
int hal_usbhost_update_chan_dev_addr(uint8_t chan, uint8_t dev_addr);
int hal_usbhost_update_chan_mps(uint8_t chan, uint16_t mps);
int hal_usbhost_start_xfer(uint8_t chan, const struct HAL_USBHOST_XFER_T *xfer);
int hal_usbhost_start_setup_xfer(const struct HAL_USBHOST_SETUP_XFER_T *setup, uint32_t *recv_len);
void hal_usbhost_detect(enum HAL_USBHOST_PLUG_STATUS_T status, HAL_USBHOST_PLUG_HANDLER handler);
void hal_usbhost_sleep(void);
void hal_usbhost_wakeup(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -202,7 +202,6 @@ ccflags-y += \
-Iutils/hwtimer_list \ -Iutils/hwtimer_list \
-Iplatform/drivers/ana \ -Iplatform/drivers/ana \
-Iplatform/drivers/security_engine \ -Iplatform/drivers/security_engine \
-Iplatform/drivers/usb/usb_dev/inc \
-Iapps/main \ -Iapps/main \
-Iapps/factory \ -Iapps/factory \
-Iutils/list \ -Iutils/list \

View File

@ -11,7 +11,6 @@ endif
ccflags-y += \ ccflags-y += \
-Iapps/common \ -Iapps/common \
-Iplatform/drivers/usb/usb_dev/inc \
-Iplatform/drivers/ana \ -Iplatform/drivers/ana \
$(BT_IF_INCLUDES) \ $(BT_IF_INCLUDES) \
-Iservices/communication/comminication_knowles \ -Iservices/communication/comminication_knowles \

View File

@ -10,7 +10,6 @@ obj-y := $(obj_c:.c=.o) $(obj_s:.S=.o) $(obj_cpp:.cpp=.o)
subdir-ccflags-y += \ subdir-ccflags-y += \
-Iapps/common \ -Iapps/common \
-Iplatform/drivers/usb/usb_dev/inc \
-Iplatform/drivers/ana \ -Iplatform/drivers/ana \
-Iutils/crc32 \ -Iutils/crc32 \
-Iservices/bt_app \ -Iservices/bt_app \

View File

@ -1,292 +0,0 @@
cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))
#obj-y := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c $(cur_dir)*.cpp $(cur_dir)*.S))
obj-y :=
ifeq ($(ROM_BUILD),1)
obj-y += ../../tests/rom/startup_ARMCM.S
else
obj-y += ../../platform/main/startup_main.S
endif
obj-y += main.c
ifeq ($(ANC_APP),1)
obj-y += anc_usb_app.c
endif
obj-y += usb_audio_app.c
obj-y += dualadc_audio_app.c
obj-y += adda_loop_app.c
obj-y += safe_queue.c
obj-y += memutils.c
ifeq ($(MIC_KEY),1)
obj-y += mic_key.c
endif
ifeq ($(VENDOR_MSG_SUPPT),1)
obj-y += usb_vendor_msg.c
endif
obj-y += ../../services/audio_process/
obj-y += ../../services/multimedia/
obj-y += ../../services/nv_section/
obj-y += ../../utils/crc32/
ifeq ($(USB_AUDIO_SPEECH),1)
obj-y += speech_process.c
obj-y += ../../apps/audioplayers/bt_sco_chain.c
obj-y += ../../apps/audioplayers/bt_sco_chain_cfg_default.c
obj-y += ../../apps/audioplayers/bt_sco_chain_tuning.cpp
obj-y += ../../services/audio_dump/
obj-y += ../../utils/heap/
ccflags-y += \
-Iapps/audioplayers \
-Iapps/common
endif
obj-y := $(obj-y:.c=.o)
obj-y := $(obj-y:.cpp=.o)
obj-y := $(obj-y:.S=.o)
ifeq ($(INTSRAM_RUN),1)
asflags-y += -DINTSRAM_RUN
ccflags-y += -DINTSRAM_RUN
endif
ccflags-y += \
-Iutils/boot_struct \
-Iutils/crc32 \
-Iutils/heap \
-Iutils/hexdump \
-Iutils/hwtimer_list \
-Iplatform/drivers/usb/usb_dev/inc \
-Iplatform/drivers/ana \
-Iservices/multimedia/audio/process/adp/include \
-Iservices/multimedia/audio/process/anc/include \
-Iservices/multimedia/audio/process/filters/include \
-Iservices/multimedia/audio/process/resample/include \
-Iservices/audio_dump/include \
-Iservices/multimedia/speech/inc \
-Iservices/audio_process \
-Iservices/nv_section/aud_section \
-Iservices/nv_section/include
CFLAGS_usb_audio_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
CFLAGS_adda_loop_app.o += -DAUDIO_OUTPUT_VOLUME_DEFAULT=$(AUDIO_OUTPUT_VOLUME_DEFAULT)
ifneq ($(DEBUG_PORT),)
CFLAGS_main.o += -DDEBUG_PORT=$(DEBUG_PORT)
endif
ifeq ($(USB_AUDIO_SPEECH),1)
CFLAGS_main.o += -DUSB_AUDIO_SPEECH
endif
ANC_USB_CFG_FLAGS :=
# ANC option
ifeq ($(ANC_APP),1)
ANC_USB_CFG_FLAGS += -DANC_APP
endif
# USB audio option
ifeq ($(USB_AUDIO_APP),1)
ANC_USB_CFG_FLAGS += -DUSB_AUDIO_APP
endif
ifeq ($(USB_I2S_APP),1)
ANC_USB_CFG_FLAGS += -DUSB_I2S_APP
ifneq ($(USB_I2S_ID),)
ANC_USB_CFG_FLAGS += -DUSB_I2S_ID=$(USB_I2S_ID)
endif
endif
ifeq ($(USB_HIGH_SPEED),1)
ANC_USB_CFG_FLAGS += -DUSB_HIGH_SPEED
endif
ifeq ($(AUDIO_RESAMPLE),1)
ANC_USB_CFG_FLAGS += -D__AUDIO_RESAMPLE__
endif
ifeq ($(ADC_CH_SEP_BUFF),1)
ANC_USB_CFG_FLAGS += -DADC_CH_SEP_BUFF
endif
include platform/drivers/usb/usb_dev/uaud_cfg_flags.mk
platform/drivers/usb/usb_dev/uaud_cfg_flags.mk: ;
ANC_USB_CFG_FLAGS += $(UAUD_CFG_FLAGS)
# USB audio configuration
ifeq ($(USB_AUDIO_DYN_CFG),1)
ifneq ($(USB_AUDIO_RECV_ENABLE),0)
ifneq ($(AUDIO_RESAMPLE),1)
SW_CAPTURE_RESAMPLE ?= 1
endif
endif
endif
ifeq ($(AUDIO_PLAYBACK_24BIT),1)
ANC_USB_CFG_FLAGS += -DAUDIO_PLAYBACK_24BIT
endif
# DSD configuration
ifeq ($(HW_FIR_DSD_PROCESS),1)
ifeq ($(HW_FIR_DSD_BUF_MID_ADDR),)
$(error HW_FIR_DSD_BUF_MID_ADDR must be defined with HW_FIR_DSD_PROCESS)
endif
ANC_USB_CFG_FLAGS += -D__HW_FIR_DSD_PROCESS__ -DHW_FIR_DSD_BUF_MID_ADDR=$(HW_FIR_DSD_BUF_MID_ADDR)
endif
ifeq ($(CODEC_DSD),1)
ANC_USB_CFG_FLAGS += -DCODEC_DSD
endif
# EQ configuration
ifeq ($(HW_FIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_FIR_EQ_PROCESS__
endif
ifeq ($(HW_IIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_IIR_EQ_PROCESS__
endif
ifeq ($(SW_IIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__SW_IIR_EQ_PROCESS__
endif
ifeq ($(HW_DAC_IIR_EQ_PROCESS),1)
ANC_USB_CFG_FLAGS += -D__HW_DAC_IIR_EQ_PROCESS__
endif
ifeq ($(AUDIO_RESAMPLE),1)
ifeq ($(SW_PLAYBACK_RESAMPLE),1)
ANC_USB_CFG_FLAGS += -DSW_PLAYBACK_RESAMPLE
endif
endif
ifeq ($(SW_CAPTURE_RESAMPLE),1)
ANC_USB_CFG_FLAGS += -DSW_CAPTURE_RESAMPLE
endif
CFLAGS_main.o += $(ANC_USB_CFG_FLAGS)
CFLAGS_usb_audio_app.o += $(ANC_USB_CFG_FLAGS)
CFLAGS_anc_usb_app.o += $(ANC_USB_CFG_FLAGS)
ifeq ($(ANC_KEY_DOUBLE_CLICK_ON_OFF),1)
CFLAGS_anc_usb_app.o += -DANC_KEY_DOUBLE_CLICK_ON_OFF
endif
ifeq ($(ANC_FF_ENABLED),1)
CFLAGS_anc_usb_app.o += -DANC_FF_ENABLED
endif
ifeq ($(ANC_FB_ENABLED),1)
CFLAGS_anc_usb_app.o += -DANC_FB_ENABLED
endif
ifeq ($(AUDIO_SECTION_SUPPT),1)
CFLAGS_anc_usb_app.o += -D__AUDIO_SECTION_SUPPT__
endif
ifeq ($(ANC_INIT_OFF),1)
CFLAGS_anc_usb_app.o += -DANC_INIT_OFF
endif
ifeq ($(ADDA_LOOP_APP),1)
CFLAGS_main.o += -DADDA_LOOP_APP
endif
ifeq ($(PC_CMD_UART),1)
CFLAGS_main.o += -D__PC_CMD_UART__
endif
ifeq ($(JTAG_ENABLE),1)
CFLAGS_main.o += -DJTAG_ENABLE
endif
ifeq ($(DEBUG_MODE_USB_DOWNLOAD),1)
CFLAGS_main.o += -DDEBUG_MODE_USB_DOWNLOAD
endif
ifeq ($(DELAY_STREAM_OPEN),1)
CFLAGS_usb_audio_app.o += -DDELAY_STREAM_OPEN
endif
ifeq ($(NOISE_GATING),1)
CFLAGS_usb_audio_app.o += -DNOISE_GATING
endif
ifeq ($(NOISE_REDUCTION),1)
CFLAGS_usb_audio_app.o += -DNOISE_REDUCTION
endif
ifeq ($(ANC_L_R_MISALIGN_WORKAROUND),1)
CFLAGS_usb_audio_app.o += -DANC_L_R_MISALIGN_WORKAROUND
endif
ifeq ($(ANDROID_ACCESSORY_SPEC),1)
CFLAGS_usb_audio_app.o += -DANDROID_ACCESSORY_SPEC
ifeq ($(ANDROID_VOICE_CMD_KEY),1)
CFLAGS_usb_audio_app.o += -DANDROID_VOICE_CMD_KEY
endif
endif
ifeq ($(DUAL_AUX_MIC_MORE_FILTER),1)
CFLAGS_usb_audio_app.o += -DDUAL_AUX_MIC_MORE_FILTER
endif
ifeq ($(FREQ_RESP_EQ),1)
CFLAGS_usb_audio_app.o += -DFREQ_RESP_EQ
endif
ifeq ($(KEEP_SAME_LATENCY),1)
CFLAGS_usb_audio_app.o += -DKEEP_SAME_LATENCY
CFLAGS_speech_process.o += -DKEEP_SAME_LATENCY
endif
ifeq ($(USB_AUDIO_PWRKEY_TEST),1)
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_PWRKEY_TEST
endif
ifeq ($(AUDIO_RESAMPLE),1)
# If neither best1000 nor best2000
ifeq ($(filter best1000 best2000,$(CHIP)),)
PLL_TUNE_SAMPLE_RATE ?= 1
endif
ifeq ($(PLL_TUNE_SAMPLE_RATE),1)
CFLAGS_usb_audio_app.o += -DPLL_TUNE_SAMPLE_RATE
endif
ifeq ($(PLL_TUNE_XTAL),1)
CFLAGS_usb_audio_app.o += -DPLL_TUNE_XTAL
endif
endif
ifeq ($(TARGET_TO_MAX_DIFF),1)
CFLAGS_usb_audio_app.o += -DTARGET_TO_MAX_DIFF
endif
ifneq ($(USB_AUDIO_RECV_ENABLE),0)
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_RECV_ENABLE
endif
ifneq ($(USB_AUDIO_SEND_ENABLE),0)
CFLAGS_usb_audio_app.o += -DUSB_AUDIO_SEND_ENABLE
endif
ifeq ($(USB_EQ_TUNING), 1)
CFLAGS_main.o += -DUSB_EQ_TUNING
CFLAGS_usb_vendor_msg.o += -DUSB_EQ_TUNING
endif
ifeq ($(VENDOR_MSG_SUPPT), 1)
CFLAGS_main.o += -D_VENDOR_MSG_SUPPT_
CFLAGS_usb_vendor_msg.o += -D_VENDOR_MSG_SUPPT_
CFLAGS_usb_audio_app.o += -D_VENDOR_MSG_SUPPT_
endif
ifeq ($(CHIP_HAS_DCO), 1)
CFLAGS_main.o += -DCHIP_HAS_DCO
CFLAGS_usb_vendor_msg.o += -DCHIP_HAS_DCO
CFLAGS_usb_audio_app.o += -DCHIP_HAS_DCO
endif

View File

@ -1,210 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "adda_loop_app.h"
#include "audioflinger.h"
#include "hal_aud.h"
#include "hal_sysfreq.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "string.h"
#include "tgt_hardware.h"
#define ADDA_SAMPLE_RATE 48000
#define ADDA_SAMPLE_SIZE 2
#define ADDA_PLAYBACK_CHAN 2
#define ADDA_CAPTURE_CHAN 2
#define RATE_TO_SIZE(n) (((n) + (1000 - 1)) / 1000)
#define ADDA_PLAYBACK_FRAME_SIZE \
(RATE_TO_SIZE(ADDA_SAMPLE_RATE) * ADDA_SAMPLE_SIZE * ADDA_PLAYBACK_CHAN)
#define ADDA_CAPTURE_FRAME_SIZE \
(RATE_TO_SIZE(ADDA_SAMPLE_RATE) * ADDA_SAMPLE_SIZE * ADDA_CAPTURE_CHAN)
#define PLAYBACK_FRAME_NUM 4
#define CAPTURE_FRAME_NUM 8
#define ADDA_NON_EXP_ALIGN(val, exp) (((val) + ((exp)-1)) / (exp) * (exp))
#define BUFF_ALIGN (4 * 4)
#define PLAYBACK_SIZE \
ADDA_NON_EXP_ALIGN(ADDA_PLAYBACK_FRAME_SIZE *PLAYBACK_FRAME_NUM, BUFF_ALIGN)
#define CAPTURE_SIZE \
ADDA_NON_EXP_ALIGN(ADDA_CAPTURE_FRAME_SIZE *CAPTURE_FRAME_NUM, BUFF_ALIGN)
#define ALIGNED4 ALIGNED(4)
static uint8_t ALIGNED4 adda_playback_buf[PLAYBACK_SIZE];
static uint8_t ALIGNED4 adda_capture_buf[CAPTURE_SIZE];
static uint32_t cap_rpos;
static uint32_t cap_wpos;
static enum AUD_BITS_T sample_size_to_enum(uint32_t size) {
if (size == 2) {
return AUD_BITS_16;
} else if (size == 4) {
return AUD_BITS_24;
} else {
ASSERT(false, "%s: Invalid sample size: %u", __FUNCTION__, size);
}
return 0;
}
static enum AUD_CHANNEL_NUM_T chan_num_to_enum(uint32_t num) {
if (num == 2) {
return AUD_CHANNEL_NUM_2;
} else if (num == 1) {
return AUD_CHANNEL_NUM_1;
} else {
ASSERT(false, "%s: Invalid channel num: %u", __FUNCTION__, num);
}
return 0;
}
static uint32_t adda_data_playback(uint8_t *buf, uint32_t len) {
uint32_t cur_time;
int16_t *src;
int16_t *dst;
int16_t *src_end;
int16_t *dst_end;
uint32_t avail;
cur_time = hal_sys_timer_get();
if (cap_wpos >= cap_rpos) {
avail = cap_wpos - cap_rpos;
} else {
avail = sizeof(adda_capture_buf) + cap_wpos - cap_rpos;
}
if (avail * ADDA_PLAYBACK_CHAN / ADDA_CAPTURE_CHAN >= len) {
src = (int16_t *)(adda_capture_buf + cap_rpos);
src_end = (int16_t *)(adda_capture_buf + sizeof(adda_capture_buf));
dst = (int16_t *)buf;
dst_end = (int16_t *)(buf + len);
while (dst < dst_end) {
*dst++ = *src++;
if (src == src_end) {
src = (int16_t *)adda_capture_buf;
}
#if (ADDA_PLAYBACK_CHAN == 2) && (ADDA_CAPTURE_CHAN == 1)
*dst = *(dst - 1);
dst++;
#endif
}
cap_rpos = (uint32_t)src - (uint32_t)adda_capture_buf;
} else {
memset(buf, 0, len);
}
TRACE(5, "[%X] playback: len=%4u wpos=%4u rpos=%4u avail=%4u", cur_time, len,
cap_wpos, cap_rpos, avail);
return 0;
}
static uint32_t adda_data_capture(uint8_t *buf, uint32_t len) {
uint32_t cur_time;
cur_time = hal_sys_timer_get();
cap_wpos += len;
if (cap_wpos >= sizeof(adda_capture_buf)) {
cap_wpos = 0;
}
TRACE(4, "[%X] capture : len=%4u wpos=%4u rpos=%4u", cur_time, len, cap_wpos,
cap_rpos);
return 0;
}
static void adda_loop_start(void) {
int ret = 0;
struct AF_STREAM_CONFIG_T stream_cfg;
hal_sysfreq_req(HAL_SYSFREQ_USER_APP_2, HAL_CMU_FREQ_52M);
memset(&stream_cfg, 0, sizeof(stream_cfg));
stream_cfg.bits = sample_size_to_enum(ADDA_SAMPLE_SIZE);
stream_cfg.channel_num = chan_num_to_enum(ADDA_PLAYBACK_CHAN);
stream_cfg.sample_rate = ADDA_SAMPLE_RATE;
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
stream_cfg.vol = AUDIO_OUTPUT_VOLUME_DEFAULT;
stream_cfg.handler = adda_data_playback;
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
stream_cfg.data_ptr = adda_playback_buf;
stream_cfg.data_size = sizeof(adda_playback_buf);
TRACE(3, "[%s] playback sample_rate: %d, bits = %d", __func__,
stream_cfg.sample_rate, stream_cfg.bits);
ret = af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
ASSERT(ret == 0, "af_stream_open playback failed: %d", ret);
memset(&stream_cfg, 0, sizeof(stream_cfg));
stream_cfg.bits = sample_size_to_enum(ADDA_SAMPLE_SIZE);
stream_cfg.channel_num = chan_num_to_enum(ADDA_CAPTURE_CHAN);
stream_cfg.sample_rate = ADDA_SAMPLE_RATE;
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
stream_cfg.vol = CODEC_SADC_VOL;
stream_cfg.handler = adda_data_capture;
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
stream_cfg.data_ptr = adda_capture_buf;
stream_cfg.data_size = sizeof(adda_capture_buf);
TRACE(3, "[%s] capture sample_rate: %d, bits = %d", __func__,
stream_cfg.sample_rate, stream_cfg.bits);
ret = af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
ASSERT(ret == 0, "af_stream_open catpure failed: %d", ret);
ret = af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
ASSERT(ret == 0, "af_stream_start playback failed: %d", ret);
ret = af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
ASSERT(ret == 0, "af_stream_start catpure failed: %d", ret);
}
static void adda_loop_stop(void) {
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
hal_sysfreq_req(HAL_SYSFREQ_USER_APP_2, HAL_CMU_FREQ_32K);
}
void adda_loop_app(bool on) {
if (on) {
adda_loop_start();
} else {
adda_loop_stop();
}
}
void adda_loop_app_loop(void) {
#ifndef RTOS
extern void af_thread(void const *argument);
af_thread(NULL);
#endif
}

View File

@ -1,33 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __ADDA_LOOP_APP_H__
#define __ADDA_LOOP_APP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
void adda_loop_app(bool on);
void adda_loop_app_loop(void);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __ANC_USB_APP_H__
#define __ANC_USB_APP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
#include "hal_aud.h"
#include "hal_key.h"
void anc_usb_app(bool on);
bool anc_usb_app_get_status();
void anc_usb_app_init(enum AUD_IO_PATH_T input_path, enum AUD_SAMPRATE_T playback_rate, enum AUD_SAMPRATE_T capture_rate);
void anc_usb_app_term(void);
void anc_usb_app_loop(void);
int anc_usb_app_key(enum HAL_KEY_CODE_T code, enum HAL_KEY_EVENT_T event);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,321 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "analog.h"
#include "audioflinger.h"
#include "hal_aud.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "pmu.h"
#include "string.h"
static uint8_t *playback_buf;
static uint32_t playback_size;
static uint8_t *capture_buf;
static uint32_t capture_size;
/*
static void get_mic_data_max(short *buf, uint32_t len)
{
int max0 = -32768, min0 = 32767, diff0 = 0;
int max1 = -32768, min1 = 32767, diff1 = 0;
for(uint32_t i=0; i<len/2;i+=2)
{
if(buf[i+0]>max0)
{
max0 = buf[i+0];
}
if(buf[i+0]<min0)
{
min0 = buf[i+0];
}
if(buf[i+1]>max1)
{
max1 = buf[i+1];
}
if(buf[i+1]<min1)
{
min1 = buf[i+1];
}
}
//TRACE(6,"min0 = %d, max0 = %d, diff0 = %d, min1 = %d, max1 = %d, diff1 =
%d", min0, max0, max0 - min0, min1, max1, max1 - min1); TRACE(2,"diff0 = %d,
diff1 = %d", max0 - min0, max1 - min1);
}
*/
static uint32_t dualadc_audio_data_playback(uint8_t *buf, uint32_t len) {
TRACE(0, "play");
#if 0
uint32_t stime;
uint32_t pos;
static uint32_t preIrqTime = 0;
pos = buf + len - playback_buf;
if (pos >= playback_size) {
pos = 0;
}
stime = hal_sys_timer_get();
TRACE(4,"%s irqDur:%d Len:%d pos:%d", __func__, TICKS_TO_MS(stime - preIrqTime), len, pos);
preIrqTime = stime;
#endif
return 0;
}
#if 1
#define MWSPT_NSEC 3
// static const int NL[MWSPT_NSEC] = { 1, 3, 1 };
static const float NUM[MWSPT_NSEC][3] = {
{0.0002616526908, 0, 0}, {1, 2, 1}, {1, 0, 0}};
// static const int DL[MWSPT_NSEC] = { 1, 3, 1 };
static const float DEN[MWSPT_NSEC][3] = {
{1, 0, 0}, {1, -1.953727961, 0.9547745585}, {1, 0, 0}};
#else
#define MWSPT_NSEC 3
static const int NL[MWSPT_NSEC] = {1, 3, 1};
static const float NUM[MWSPT_NSEC][3] = {
{0.0002616526908, 0, 0}, {1, 2, 1}, {1, 0, 0}};
static const int DL[MWSPT_NSEC] = {1, 3, 1};
static const float DEN[MWSPT_NSEC][3] = {
{1, 0, 0}, {1, -1.953727961, 0.9547745585}, {1, 0, 0}};
#endif
static uint32_t dualadc_audio_data_capture(uint8_t *buf, uint32_t len) {
TRACE(0, "capture");
#if 0
if(buf==capture_buf)
{
short *BufSrcL = (short *)capture_buf;
short *BufSrcR = (short *)(capture_buf+2);
short *BufDstL = (short *)playback_buf;
short *BufDstR = (short *)(playback_buf+2);
for(int i=0,j=0;i<playback_size/4;i=i+2,j=j+4)
{
BufDstL[i]=BufSrcL[j];
BufDstR[i]=BufSrcR[j];
}
}
else
{
short *BufSrcL = (short *)(capture_buf+capture_size/2);
short *BufSrcR = (short *)(capture_buf+capture_size/2+2);
short *BufDstL = (short *)(playback_buf+playback_size/2);
short *BufDstR = (short *)(playback_buf+playback_size/2+2);
for(int i=0,j=0;i<playback_size/4;i=i+2,j=j+4)
{
BufDstL[i]=BufSrcL[j];
BufDstR[i]=BufSrcR[j];
}
}
#else
short *BufSrcL;
short *BufSrcR;
short *BufDstL;
short *BufDstR;
int32_t PcmValue;
int32_t OutValue;
// get_mic_data_max(buf,len);
if (buf == capture_buf) {
BufSrcL = (short *)(capture_buf);
BufSrcR = (short *)(capture_buf + 2);
BufDstL = (short *)playback_buf;
BufDstR = (short *)(playback_buf + 2);
} else {
BufSrcL = (short *)(capture_buf + capture_size / 2);
BufSrcR = (short *)(capture_buf + capture_size / 2 + 2);
BufDstL = (short *)(playback_buf + playback_size / 2);
BufDstR = (short *)(playback_buf + playback_size / 2 + 2);
}
for (int i = 0, j = 0; i < capture_size / 4; i = i + 4, j = j + 2) {
PcmValue = BufSrcL[i];
if (PcmValue > 32600) {
OutValue = ((int)BufSrcR[i]) << 6;
} else if (PcmValue > (32600 / 2) && PcmValue < 32600) {
if (BufSrcR[i] > 512) {
OutValue = PcmValue * (32600 - PcmValue) +
(((int)BufSrcR[i]) << 6) * (PcmValue - (32600 / 2));
OutValue = OutValue / (32600 / 2);
} else {
OutValue = PcmValue;
}
} else if (PcmValue < -32700) {
OutValue = ((int)BufSrcR[i]) << 6;
} else if (PcmValue > -32700 && PcmValue < -(32700 / 2)) {
if (BufSrcR[i] < -512) {
OutValue = PcmValue * (-PcmValue - (32700 / 2)) +
(((int)BufSrcR[i]) << 6) * (32700 + PcmValue);
OutValue = OutValue / (32700 / 2);
} else {
OutValue = PcmValue;
}
} else {
OutValue = PcmValue;
}
OutValue = OutValue >> 6;
// OutValue=BufSrcR[i];
{
static float y0 = 0, y1 = 0, y2 = 0, x0 = 0, x1 = 0, x2 = 0;
x0 = (OutValue * NUM[0][0]);
y0 = x0 * NUM[1][0] + x1 * NUM[1][1] + x2 * NUM[1][2] - y1 * DEN[1][1] -
y2 * DEN[1][2];
y2 = y1;
y1 = y0;
x2 = x1;
x1 = x0;
if (y0 > 32767.0f) {
y0 = 32767.0f;
}
if (y0 < -32768.0f) {
y0 = -32768.0f;
}
OutValue = (short)y0;
}
BufDstL[j] = OutValue;
BufDstR[j] = OutValue;
}
#endif
#if 0
uint32_t stime;
uint32_t pos;
static uint32_t preIrqTime = 0;
pos = buf + len - capture_buf;
if (pos >= capture_size) {
pos = 0;
}
stime = hal_sys_timer_get();
TRACE(4,"%s irqDur:%d Len:%d pos:%d", __func__, TICKS_TO_MS(stime - preIrqTime), len, pos);
preIrqTime = stime;
#endif
return 0;
}
void dualadc_audio_app(bool on) {
struct AF_STREAM_CONFIG_T stream_cfg;
enum AUD_SAMPRATE_T sample_rate_play;
enum AUD_SAMPRATE_T POSSIBLY_UNUSED sample_rate_capture;
static bool isRun = false;
if (isRun == on)
return;
else
isRun = on;
TRACE(2, "%s: on=%d", __FUNCTION__, on);
sample_rate_play = AUD_SAMPRATE_192000;
sample_rate_capture = AUD_SAMPRATE_192000;
if (on) {
memset(&stream_cfg, 0, sizeof(stream_cfg));
stream_cfg.bits = AUD_BITS_16;
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
stream_cfg.sample_rate = sample_rate_play;
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
stream_cfg.vol = 0x06;
stream_cfg.handler = dualadc_audio_data_playback;
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
stream_cfg.data_ptr = playback_buf;
stream_cfg.data_size = playback_size;
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
stream_cfg.bits = AUD_BITS_16;
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
stream_cfg.sample_rate = sample_rate_capture;
stream_cfg.vol = 0x01;
stream_cfg.handler = dualadc_audio_data_capture;
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
stream_cfg.data_ptr = capture_buf;
stream_cfg.data_size = capture_size;
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
} else {
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
}
}
void dualadc_audio_app_init(uint8_t *play_buf, uint32_t play_size,
uint8_t *cap_buf, uint32_t cap_size) {
playback_buf = play_buf;
playback_size = play_size;
capture_buf = cap_buf;
capture_size = cap_size;
}
void dualadc_audio_app_term(void) {
playback_buf = NULL;
playback_size = 0;
capture_buf = NULL;
capture_size = 0;
}

View File

@ -1,38 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __DUALADC_AUDIO_TEST_H__
#define __DUALADC_AUDIO_TEST_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
void dualadc_audio_app(bool on);
void dualadc_audio_app_init(uint8_t *play_buf, uint32_t play_size, uint8_t *cap_buf, uint32_t cap_size);
void dualadc_audio_app_term(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,519 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "adda_loop_app.h"
#include "analog.h"
#include "anc_usb_app.h"
#include "audio_process.h"
#include "audioflinger.h"
#include "cmsis.h"
#include "dualadc_audio_app.h"
#include "hal_bootmode.h"
#include "hal_cmu.h"
#include "hal_dma.h"
#include "hal_gpadc.h"
#include "hal_iomux.h"
#include "hal_key.h"
#include "hal_norflash.h"
#include "hal_sleep.h"
#include "hal_sysfreq.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "hwtimer_list.h"
#include "main_entry.h"
#include "plat_addr_map.h"
#include "pmu.h"
#include "string.h"
#include "tgt_hardware.h"
#include "usb_audio_app.h"
#include "usb_audio_frm_defs.h"
#if defined(_VENDOR_MSG_SUPPT_)
#include "usb_vendor_msg.h"
#endif
#ifdef RTOS
#include "cmsis_os.h"
#endif
#ifdef __PC_CMD_UART__
#include "hal_cmd.h"
#endif
#ifdef USB_AUDIO_SPEECH
#define CODEC_BUFF_FRAME_NUM (2 * 16)
#define USB_BUFF_FRAME_NUM (CODEC_BUFF_FRAME_NUM * 2)
#else
#define CODEC_BUFF_FRAME_NUM 4
#define USB_BUFF_FRAME_NUM 10
#endif
#if (CODEC_BUFF_FRAME_NUM >= USB_BUFF_FRAME_NUM)
#error \
"Codec buffer frame num should be less than usb buffer frame num (on the requirement of conflict ctrl)"
#endif
#ifdef USB_AUDIO_DYN_CFG
#define USB_AUDIO_PLAYBACK_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_PLAYBACK *CODEC_BUFF_FRAME_NUM, DAC_BUFF_ALIGN)
#define USB_AUDIO_CAPTURE_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_CAPTURE *CODEC_BUFF_FRAME_NUM, ADC_BUFF_ALIGN)
#define USB_AUDIO_RECV_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_RECV *USB_BUFF_FRAME_NUM, RECV_BUFF_ALIGN)
#define USB_AUDIO_SEND_BUFF_SIZE \
NON_EXP_ALIGN(MAX_FRAME_SIZE_SEND *USB_BUFF_FRAME_NUM, SEND_BUFF_ALIGN)
#if defined(CHIP_BEST1000)
// FIR EQ is working on 16-bit
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int16_t)
#define USB_AUDIO_FIR_EQ_BUFF_SIZE USB_AUDIO_PLAYBACK_BUFF_SIZE
#elif defined(CHIP_BEST2000)
// FIR EQ is working on 32-bit
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int32_t)
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * 2)
#elif defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
// FIR EQ is working on 32-bit
// FIR_EQ_buffer_size = max_playback_symbol_number_in_buffer * sizeof(int32_t)
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE)
#define USB_AUDIO_IIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE)
#define USB_AUDIO_DSD_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * 16)
#endif
#else // !USB_AUDIO_DYN_CFG
#define USB_AUDIO_PLAYBACK_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_PLAYBACK *CODEC_BUFF_FRAME_NUM, DAC_BUFF_ALIGN)
#define USB_AUDIO_CAPTURE_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_CAPTURE *CODEC_BUFF_FRAME_NUM, ADC_BUFF_ALIGN)
#define USB_AUDIO_RECV_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_RECV *USB_BUFF_FRAME_NUM, RECV_BUFF_ALIGN)
#define USB_AUDIO_SEND_BUFF_SIZE \
NON_EXP_ALIGN(FRAME_SIZE_SEND *USB_BUFF_FRAME_NUM, SEND_BUFF_ALIGN)
#if defined(CHIP_BEST1000)
// FIR EQ is working on 16-bit
#define USB_AUDIO_FIR_EQ_BUFF_SIZE \
(USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int16_t) / SAMPLE_SIZE_PLAYBACK)
#elif defined(CHIP_BEST2000)
// FIR EQ is working on 32-bit
#define USB_AUDIO_FIR_EQ_BUFF_SIZE \
(USB_AUDIO_PLAYBACK_BUFF_SIZE * sizeof(int32_t) / SAMPLE_SIZE_PLAYBACK)
#elif defined(CHIP_BEST2300) || defined(CHIP_BEST2300P)
// FIR EQ is working on 32-bit
#define USB_AUDIO_FIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE)
#define USB_AUDIO_IIR_EQ_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE)
#define USB_AUDIO_DSD_BUFF_SIZE (USB_AUDIO_PLAYBACK_BUFF_SIZE * 16)
#endif
#endif // !USB_AUDIO_DYN_CFG
#if (defined(CHIP_BEST1000) && \
(defined(ANC_APP) || defined(_DUAL_AUX_MIC_))) && \
(CHAN_NUM_CAPTURE == CHAN_NUM_SEND)
// Resample input buffer size should be (half_of_max_sample_num *
// SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE). half_of_max_sample_num = 48000 /
// 1000 * CODEC_BUFF_FRAME_NUM / 2 * 48 / 44
#define RESAMPLE_INPUT_BUFF_SIZE \
ALIGN(48000 / 1000 * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE * \
CODEC_BUFF_FRAME_NUM / 2 * 48 / 44, \
4)
#else
#define RESAMPLE_INPUT_BUFF_SIZE 0
#endif
// Resample history buffer size should be
// sizeof(struct RESAMPLE_CTRL_T) + ((SAMPLE_NUM + phase_coef_num) *
// SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
#define RESAMPLE_HISTORY_BUFF_SIZE \
(50 + (256 * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE))
#define USB_AUDIO_RESAMPLE_BUFF_SIZE \
(RESAMPLE_INPUT_BUFF_SIZE + RESAMPLE_HISTORY_BUFF_SIZE)
#define ALIGNED4 ALIGNED(4)
#if defined(USB_AUDIO_APP) || defined(DUALADC_AUDIO_TEST)
#ifdef AUDIO_ANC_FB_MC
static uint8_t ALIGNED4 playback_buff[USB_AUDIO_PLAYBACK_BUFF_SIZE *
9]; // max 48->384 or 44.1->44.1*8;
#else
static uint8_t ALIGNED4 playback_buff[USB_AUDIO_PLAYBACK_BUFF_SIZE];
#endif
static uint8_t ALIGNED4 capture_buff[USB_AUDIO_CAPTURE_BUFF_SIZE];
#endif
#ifdef USB_AUDIO_APP
#if defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
static uint8_t ALIGNED4
eq_buff[USB_AUDIO_FIR_EQ_BUFF_SIZE + USB_AUDIO_IIR_EQ_BUFF_SIZE];
#elif defined(__HW_FIR_EQ_PROCESS__) && !defined(__HW_IIR_EQ_PROCESS__)
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_FIR_EQ_BUFF_SIZE];
#elif !defined(__HW_FIR_EQ_PROCESS__) && defined(__HW_IIR_EQ_PROCESS__)
static uint8_t ALIGNED4 eq_buff[USB_AUDIO_IIR_EQ_BUFF_SIZE];
#else
static uint8_t ALIGNED4 eq_buff[0];
#endif
#ifdef SW_CAPTURE_RESAMPLE
static uint8_t ALIGNED4 resample_buff[USB_AUDIO_RESAMPLE_BUFF_SIZE];
#else
static uint8_t ALIGNED4 resample_buff[0];
#endif
static uint8_t ALIGNED4 recv_buff[USB_AUDIO_RECV_BUFF_SIZE];
static uint8_t ALIGNED4 send_buff[USB_AUDIO_SEND_BUFF_SIZE];
#ifdef USB_AUDIO_MULTIFUNC
static uint8_t ALIGNED4 recv2_buff[USB_AUDIO_RECV_BUFF_SIZE];
#endif
#endif
#ifdef CFG_HW_KEY_LED_PIN
const struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_key_led[1] = {
{CFG_HW_KEY_LED_PIN, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
HAL_IOMUX_PIN_NOPULL},
};
#endif
#ifdef CFG_MIC_KEY
extern void mic_key_open(void);
#endif
static void uart_i2c_switch(void) {
static int flag = 0;
flag ^= 1;
if (flag) {
hal_iomux_set_analog_i2c();
} else {
hal_iomux_set_uart0();
}
}
static int key_event_process(uint32_t key_code, uint8_t key_event) {
TRACE(3, "%s: code=0x%X, event=%u", __FUNCTION__, key_code, key_event);
#ifdef CFG_HW_KEY_LED_PIN
if (key_event == HAL_KEY_EVENT_DOWN) {
hal_gpio_pin_set(CFG_HW_KEY_LED_PIN);
} else if (key_event == HAL_KEY_EVENT_UP) {
hal_gpio_pin_clr(CFG_HW_KEY_LED_PIN);
}
#endif
#ifdef USB_AUDIO_APP
if (usb_audio_app_key(key_code, key_event) == 0) {
return 0;
}
#endif
#ifdef ANC_APP
if (anc_usb_app_key(key_code, key_event) == 0) {
return 0;
}
#endif
if (key_event == HAL_KEY_EVENT_CLICK) {
if (key_code == HAL_KEY_CODE_FN9) {
uart_i2c_switch();
}
}
return 0;
}
void anc_usb_open(void) {
TRACE(1, "%s", __FUNCTION__);
#ifdef __AUDIO_RESAMPLE__
hal_cmu_audio_resample_enable();
#endif
#ifdef USB_AUDIO_APP
struct USB_AUDIO_BUF_CFG cfg;
memset(&cfg, 0, sizeof(cfg));
cfg.play_buf = playback_buff;
#ifdef AUDIO_ANC_FB_MC
cfg.play_size = sizeof(playback_buff) / 9;
#else
cfg.play_size = sizeof(playback_buff);
#endif
cfg.cap_buf = capture_buff;
cfg.cap_size = sizeof(capture_buff);
cfg.recv_buf = recv_buff;
cfg.recv_size = sizeof(recv_buff);
cfg.send_buf = send_buff;
cfg.send_size = sizeof(send_buff);
cfg.eq_buf = eq_buff;
cfg.eq_size = sizeof(eq_buff);
cfg.resample_buf = resample_buff;
cfg.resample_size = sizeof(resample_buff);
#ifdef USB_AUDIO_MULTIFUNC
cfg.recv2_buf = recv2_buff;
cfg.recv2_size = sizeof(recv2_buff);
#endif
usb_audio_app_init(&cfg);
usb_audio_app(true);
#endif
#ifdef ANC_APP
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, SAMPLE_RATE_PLAYBACK,
SAMPLE_RATE_CAPTURE);
#endif
#ifdef DUALADC_AUDIO_TEST
dualadc_audio_app_init(playback_buff, USB_AUDIO_PLAYBACK_BUFF_SIZE,
capture_buff, USB_AUDIO_CAPTURE_BUFF_SIZE);
dualadc_audio_app(true);
#endif
#ifdef ADDA_LOOP_APP
adda_loop_app(true);
#endif
#if defined(_VENDOR_MSG_SUPPT_)
#ifndef USB_ANC_MC_EQ_TUNING
vendor_info_init();
#endif
#endif
#if defined(CFG_MIC_KEY)
mic_key_open();
#endif
// Allow sleep
hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_32K);
while (1) {
#ifdef USB_AUDIO_APP
usb_audio_app_loop();
#endif
#ifdef ANC_APP
anc_usb_app_loop();
#endif
#ifdef ADDA_LOOP_APP
adda_loop_app_loop();
#endif
#ifdef RTOS
// Let the task sleep
osDelay(20);
#else // !RTOS
#ifdef USB_EQ_TUNING
audio_eq_usb_eq_update();
#endif
hal_sleep_enter_sleep();
#endif // !RTOS
}
}
#ifdef CFG_HW_GPADCKEY
void gpadc_key_handler(uint16_t irq_val, HAL_GPADC_MV_T volt) {
static uint16_t stable_cnt = 0;
static uint16_t click_cnt = 0;
static uint32_t click_time;
uint32_t time;
enum HAL_KEY_EVENT_T event;
bool send_event = false;
time = hal_sys_timer_get();
if (volt < 100) {
stable_cnt++;
// TRACE(5,"adc_key down: volt=%u stable=%u click_cnt=%u click_time=%u
// time=%u", volt, stable_cnt, click_cnt, click_time, time);
} else {
if (stable_cnt > 1) {
// TRACE(5,"adc_key up: volt=%u stable=%u click_cnt=%u click_time=%u
// time=%u", volt, stable_cnt, click_cnt, click_time, time);
if (click_cnt == 0 || (time - click_time) < MS_TO_TICKS(500)) {
click_time = time;
click_cnt++;
if (click_cnt >= 3) {
send_event = true;
}
} else {
send_event = true;
}
}
stable_cnt = 0;
if (click_cnt > 0 && (time - click_time) >= MS_TO_TICKS(500)) {
send_event = true;
}
if (send_event) {
// TRACE(5,"adc_key click: volt=%u stable=%u click_cnt=%u click_time=%u
// time=%u", volt, stable_cnt, click_cnt, click_time, time);
if (click_cnt == 1) {
event = HAL_KEY_EVENT_CLICK;
} else if (click_cnt == 2) {
event = HAL_KEY_EVENT_DOUBLECLICK;
} else {
event = HAL_KEY_EVENT_TRIPLECLICK;
}
key_event_process(CFG_HW_GPADCKEY, event);
click_cnt = 0;
}
}
}
#endif
#ifdef DEBUG_MODE_USB_DOWNLOAD
static void process_usb_download_mode(void) {
if (pmu_charger_get_status() == PMU_CHARGER_PLUGIN && hal_pwrkey_pressed()) {
hal_sw_bootmode_set(HAL_SW_BOOTMODE_FORCE_USB_DLD);
hal_cmu_sys_reboot();
}
}
#endif
// GDB can set a breakpoint on the main function only if it is
// declared as below, when linking with STD libraries.
int MAIN_ENTRY(void) {
#ifdef INTSRAM_RUN
// hal_norflash_sleep(HAL_NORFLASH_ID_0);
#endif
#ifdef DEBUG_MODE_USB_DOWNLOAD
process_usb_download_mode();
#endif
hal_cmu_simu_init();
hwtimer_init();
hal_audma_open();
hal_gpdma_open();
#if (DEBUG_PORT == 2)
hal_iomux_set_analog_i2c();
hal_iomux_set_uart1();
hal_trace_open(HAL_TRACE_TRANSPORT_UART1);
#else
hal_iomux_set_uart0();
hal_trace_open(HAL_TRACE_TRANSPORT_UART0);
#endif
#if !defined(SIMU)
uint8_t flash_id[HAL_NORFLASH_DEVICE_ID_LEN];
hal_norflash_get_id(HAL_NORFLASH_ID_0, flash_id, ARRAY_SIZE(flash_id));
TRACE(3, "FLASH_ID: %02X-%02X-%02X", flash_id[0], flash_id[1], flash_id[2]);
#endif
pmu_open();
analog_open();
af_open();
hal_sleep_start_stats(10000, 10000);
#ifdef CHIP_BEST1000
hal_cmu_force_bt_sleep();
#endif
hal_key_open(0, key_event_process);
#ifdef CFG_HW_GPADCKEY
hal_gpadc_open(HAL_GPADC_CHAN_3, HAL_GPADC_ATP_20MS, gpadc_key_handler);
#endif
#ifdef CFG_HW_KEY_LED_PIN
hal_iomux_init(pinmux_key_led, ARRAY_SIZE(pinmux_key_led));
hal_gpio_pin_set_dir(CFG_HW_KEY_LED_PIN, HAL_GPIO_DIR_OUT, 0);
#endif
#if defined(__SW_IIR_EQ_PROCESS__) || defined(__HW_FIR_EQ_PROCESS__) || \
defined(__HW_DAC_IIR_EQ_PROCESS__) || defined(__HW_IIR_EQ_PROCESS__)
audio_process_init();
// TODO: Get EQ store parameter
// audio_eq_fir_update_cfg(int16_t *coef, int16_t num);
// audio_eq_iir_update_cfg(int *gain, int num);
#endif
anc_usb_open();
TRACE(0, "byebye~~~\n");
hal_sys_timer_delay(MS_TO_TICKS(200));
pmu_shutdown();
return 0;
}
//--------------------------------------------------------------------------------
// Start of Programmer Entry
//--------------------------------------------------------------------------------
#ifdef PROGRAMMER
#include "cmsis_nvic.h"
#include "hal_chipid.h"
#include "tool_msg.h"
extern uint32_t __StackTop[];
extern uint32_t __StackLimit[];
extern uint32_t __bss_start__[];
extern uint32_t __bss_end__[];
#define EXEC_STRUCT_LOC __attribute__((section(".exec_struct")))
bool task_yield(void) { return true; }
void anc_usb_ramrun_main(void) {
uint32_t *dst;
for (dst = __bss_start__; dst < __bss_end__; dst++) {
*dst = 0;
}
NVIC_InitVectors();
#ifdef UNALIGNED_ACCESS
SystemInit();
#endif
hal_cmu_setup();
main();
#if !defined(PROGRAMMER_INFLASH)
SAFE_PROGRAM_STOP();
#endif
}
void anc_usb_ramrun_start(void) {
GotBaseInit();
#ifdef __ARM_ARCH_8M_MAIN__
__set_MSPLIM((uint32_t)__StackLimit);
#endif
__set_MSP((uint32_t)__StackTop);
anc_usb_ramrun_main();
}
const struct exec_struct_t EXEC_STRUCT_LOC ramrun_struct = {
.entry = (uint32_t)anc_usb_ramrun_start,
.param = 0,
.sp = 0,
.exec_addr = (uint32_t)&ramrun_struct,
};
void programmer_start(void) __attribute__((weak, alias("anc_usb_ramrun_main")));
#endif
//--------------------------------------------------------------------------------
// End of Programmer Entry
//--------------------------------------------------------------------------------

View File

@ -1,87 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "memutils.h"
#include "plat_types.h"
#include "string.h"
#define ALIGNED32(a) (((uint32_t)(a)&3) == 0)
#define ALIGNED16(a) (((uint32_t)(a)&1) == 0)
void *copy_mem32(void *dst, const void *src, unsigned int size) {
uint32_t *d = dst;
const uint32_t *s = src;
const uint32_t *e = s + size / 4;
while (s < e) {
*d++ = *s++;
}
return dst;
}
void *copy_mem16(void *dst, const void *src, unsigned int size) {
uint16_t *d = dst;
const uint16_t *s = src;
const uint16_t *e = s + size / 2;
while (s < e) {
*d++ = *s++;
}
return dst;
}
void *copy_mem(void *dst, const void *src, unsigned int size) {
if (ALIGNED32(dst) && ALIGNED32(src) && ALIGNED32(size)) {
return copy_mem32(dst, src, size);
} else if (ALIGNED16(dst) && ALIGNED16(src) && ALIGNED16(size)) {
return copy_mem16(dst, src, size);
} else {
return memcpy(dst, src, size);
}
}
void *zero_mem32(void *dst, unsigned int size) {
uint32_t *d = dst;
uint32_t count = size / 4;
while (count--) {
*d++ = 0;
}
return dst;
}
void *zero_mem16(void *dst, unsigned int size) {
uint16_t *d = dst;
uint32_t count = size / 2;
while (count--) {
*d++ = 0;
}
return dst;
}
void *zero_mem(void *dst, unsigned int size) {
if (ALIGNED32(dst) && ALIGNED32(size)) {
return zero_mem32(dst, size);
} else if (ALIGNED16(dst) && ALIGNED16(size)) {
return zero_mem16(dst, size);
} else {
return memset(dst, 0, size);
}
}

View File

@ -1,32 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __MEMUTILS_H__
#define __MEMUTILS_H__
void *copy_mem32(void *dst, const void *src, unsigned int size);
void *copy_mem16(void *dst, const void *src, unsigned int size);
void *copy_mem(void *dst, const void *src, unsigned int size);
void *zero_mem32(void *dst, unsigned int size);
void *zero_mem16(void *dst, unsigned int size);
void *zero_mem(void *dst, unsigned int size);
#endif

View File

@ -1,149 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifdef CFG_MIC_KEY
#include "analog.h"
#include "hal_gpadc.h"
#include "hal_iomux.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "hwtimer_list.h"
#include "tgt_hardware.h"
#include "usb_audio.h"
#define MIC_KEY_CHK_TIMES 20
#define MIC_KEY_SKIP_CNT 8
#define MIC_KEY_CHK_INTERVAL MS_TO_TICKS(1) // in ticks
static struct {
HWTIMER_ID chk_timer;
uint16_t chk_val[MIC_KEY_CHK_TIMES - MIC_KEY_SKIP_CNT];
uint8_t chk_times;
uint8_t gpio_dn;
uint8_t key_dn[MIC_KEY_NUM];
} s_mic_key_ctx;
extern void mic_key_gpio_irq_set(void);
void mic_key_irq_hdl(uint16_t irq_val, HAL_GPADC_MV_T volt) {
hal_gpadc_close(mic_key_gpadc_chan);
if (++s_mic_key_ctx.chk_times >= MIC_KEY_CHK_TIMES) {
uint8_t i, j;
uint32_t mean;
for (i = 0; i < MIC_KEY_NUM; i++) {
mean = 0;
for (j = 0; j < MIC_KEY_CHK_TIMES - MIC_KEY_SKIP_CNT; j++) {
mean += (uint32_t)s_mic_key_ctx.chk_val[j];
}
mean /= MIC_KEY_CHK_TIMES - MIC_KEY_SKIP_CNT;
if ((mean > mic_key_cfg_lst[i].ref_vol_low) &&
(mean <= mic_key_cfg_lst[i].ref_vol_high))
break;
}
if (i < MIC_KEY_NUM) {
TRACE(2, "ana_key: key[%d] matched at [%dmv]", i, mean);
usb_audio_hid_set_event(mic_key_cfg_lst[i].hid_evt, 1);
s_mic_key_ctx.key_dn[i] = 1;
} else {
TRACE(1, "ana_key: no key matched [%dmv]", mean);
}
return;
}
if (s_mic_key_ctx.chk_times > MIC_KEY_SKIP_CNT) {
s_mic_key_ctx.chk_val[s_mic_key_ctx.chk_times - MIC_KEY_SKIP_CNT - 1] =
volt;
}
hwtimer_start(s_mic_key_ctx.chk_timer, MIC_KEY_CHK_INTERVAL);
}
void mic_key_gpio_det_irq_hdl(enum HAL_GPIO_PIN_T pin) {
if (pin != mic_key_det_gpio_pin)
return;
TRACE(1, "GPIO detected at status[%d]", s_mic_key_ctx.gpio_dn);
if (s_mic_key_ctx.gpio_dn) {
uint8_t i;
for (i = 0; i < MIC_KEY_NUM; i++) {
if (s_mic_key_ctx.key_dn[i]) {
break;
}
}
if (i < MIC_KEY_NUM) {
usb_audio_hid_set_event(mic_key_cfg_lst[i].hid_evt, 0);
s_mic_key_ctx.key_dn[i] = 0;
}
s_mic_key_ctx.gpio_dn = 0;
} else {
s_mic_key_ctx.chk_times = 0;
s_mic_key_ctx.gpio_dn = 1;
hal_gpadc_open(mic_key_gpadc_chan, HAL_GPADC_ATP_ONESHOT, mic_key_irq_hdl);
}
mic_key_gpio_irq_set();
}
void mic_key_periodic_check(void *param) {
hal_gpadc_open(mic_key_gpadc_chan, HAL_GPADC_ATP_ONESHOT, mic_key_irq_hdl);
}
void mic_key_gpio_irq_set(void) {
struct HAL_GPIO_IRQ_CFG_T cfg;
cfg.irq_debounce = 1;
cfg.irq_enable = 1;
cfg.irq_type = HAL_GPIO_IRQ_TYPE_EDGE_SENSITIVE;
if (s_mic_key_ctx.gpio_dn) {
cfg.irq_polarity = HAL_GPIO_IRQ_POLARITY_HIGH_RISING;
} else {
cfg.irq_polarity = HAL_GPIO_IRQ_POLARITY_LOW_FALLING;
}
cfg.irq_handler = mic_key_gpio_det_irq_hdl;
hal_gpio_setup_irq(mic_key_det_gpio_pin, &cfg);
}
void mic_key_open(void) {
struct HAL_IOMUX_PIN_FUNCTION_MAP pinmux_key_det[] = {
{0, HAL_IOMUX_FUNC_GPIO, HAL_IOMUX_PIN_VOLTAGE_MEM, HAL_IOMUX_PIN_NOPULL},
};
TRACE(1, "%s", __func__);
pinmux_key_det[0].pin = mic_key_det_gpio_pin;
hal_iomux_init(pinmux_key_det, ARRAY_SIZE(pinmux_key_det));
analog_aud_mickey_enable(true);
s_mic_key_ctx.chk_timer = hwtimer_alloc(mic_key_periodic_check, NULL);
hal_gpio_pin_set_dir(mic_key_det_gpio_pin, HAL_GPIO_DIR_IN, 0);
mic_key_gpio_irq_set();
}
#endif

View File

@ -1,156 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "safe_queue.h"
#include "cmsis.h"
#include "hal_trace.h"
void safe_queue_init(struct SAFE_QUEUE_T *queue, uint32_t *items,
uint32_t size) {
// queue->first points to the first valid item
queue->first = 0;
// queue->last points to the first empty slot (beyond the last valid item)
queue->last = 0;
queue->count = 0;
queue->size = size;
queue->watermark = 0;
queue->items = items;
}
int safe_queue_put(struct SAFE_QUEUE_T *queue, uint32_t item) {
int ret = 0;
uint32_t lock;
lock = int_lock();
if (queue->count >= queue->size) {
ret = 1;
} else {
queue->items[queue->last] = item;
queue->last++;
if (queue->last >= queue->size) {
queue->last = 0;
}
queue->count++;
if (queue->count > queue->watermark) {
queue->watermark = queue->count;
}
}
int_unlock(lock);
return ret;
}
int safe_queue_get(struct SAFE_QUEUE_T *queue, uint32_t *itemp) {
int ret = 0;
uint32_t lock;
lock = int_lock();
if (queue->count == 0) {
ret = 1;
} else {
if (itemp) {
*itemp = queue->items[queue->first];
}
queue->first++;
if (queue->first >= queue->size) {
queue->first = 0;
}
queue->count--;
}
int_unlock(lock);
return ret;
}
int safe_queue_pop(struct SAFE_QUEUE_T *queue, uint32_t *itemp) {
int ret = 0;
uint32_t lock;
lock = int_lock();
if (queue->count == 0) {
ret = 1;
} else {
if (queue->last) {
queue->last--;
} else {
queue->last = queue->size - 1;
}
if (itemp) {
*itemp = queue->items[queue->last];
}
queue->count--;
}
int_unlock(lock);
return ret;
}
int safe_queue_peek(const struct SAFE_QUEUE_T *queue, int offset,
uint32_t *itemp) {
int ret = 0;
uint32_t lock;
uint8_t idx;
lock = int_lock();
if (offset >= 0 && offset < queue->count) {
idx = queue->first + offset;
} else if (offset < 0 && -offset <= queue->count) {
idx = queue->size + queue->last + offset;
} else {
ret = 1;
}
if (ret == 0) {
if (idx >= queue->size) {
idx -= queue->size;
}
*itemp = queue->items[idx];
}
int_unlock(lock);
return ret;
}
uint32_t safe_queue_watermark(const struct SAFE_QUEUE_T *queue) {
return queue->watermark;
}
int safe_queue_dump(const struct SAFE_QUEUE_T *queue) {
uint32_t cnt;
int i;
uint32_t item;
cnt = queue->count;
for (i = 0; i < cnt; i++) {
if (safe_queue_peek(queue, i, &item)) {
break;
}
TRACE_IMM(3, "SAFE-QUEUE-DUMP: [%02d/%02d] 0x%08x", i, cnt, item);
}
return 0;
}

View File

@ -1,44 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __SAFE_QUEUE_H__
#define __SAFE_QUEUE_H__
#include "plat_types.h"
struct SAFE_QUEUE_T {
uint8_t first;
uint8_t last;
uint8_t count;
uint8_t size;
uint8_t watermark;
uint32_t *items;
};
void safe_queue_init(struct SAFE_QUEUE_T *queue, uint32_t *items, uint32_t size);
int safe_queue_put(struct SAFE_QUEUE_T *queue, uint32_t item);
int safe_queue_get(struct SAFE_QUEUE_T *queue, uint32_t *itemp);
int safe_queue_pop(struct SAFE_QUEUE_T *queue, uint32_t *itemp);
int safe_queue_peek(const struct SAFE_QUEUE_T *queue, int offset, uint32_t *itemp);
uint32_t safe_queue_watermark(const struct SAFE_QUEUE_T *queue);
int safe_queue_dump(const struct SAFE_QUEUE_T *queue);
#endif

View File

@ -1,279 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#include "speech_process.h"
#include "cmsis.h"
#include "hal_sysfreq.h"
#include "hal_timer.h"
#include "hal_trace.h"
#if defined(SPEECH_TX_AEC2FLOAT) && !defined(KEEP_SAME_LATENCY)
#error "capture/playback size should be equal when enable AEC"
#endif
#include "bt_sco_chain.h"
#include "iir_resample.h"
#include "speech_memory.h"
#include "speech_utils.h"
#define MED_MEM_POOL_SIZE (1024 * 160)
static uint8_t g_medMemPool[MED_MEM_POOL_SIZE];
#define FFSE_SAMPLE_RATE (16000)
int capture_channel_num = 1;
int capture_sample_rate = 48000;
int capture_sample_bit = 16;
int playback_channel_num = 2;
int playback_sample_rate = 48000;
int playback_sample_bit = 24;
int send_channel_num = 2;
int recv_channel_num = 2;
// resample related
static bool resample_needed_flag = false;
static IirResampleState *upsample_st;
static IirResampleState *downsample_st[4];
int16_t *capture_buffer_deinter = NULL;
int16_t *process_buffer = NULL;
int16_t *process_buffer_inter = NULL;
static short *aec_echo_buf = NULL;
static IirResampleState *rx_downsample_st;
static volatile bool is_speech_init = false;
static void speech_deinterleave(int16_t *in, int16_t *out, int len,
int ch_num) {
int len_per_channel = len / ch_num;
for (int i = 0, j = 0; i < len; i += ch_num, j++) {
int16_t *pout = &out[j];
int16_t *pin = &in[i];
for (int c = 0; c < ch_num; c++) {
*pout = *pin;
pout += len_per_channel;
pin += 1;
}
}
}
static void speech_interleave(int16_t *in, int16_t *out, int len, int ch_num) {
int len_per_channel = len / ch_num;
for (int i = 0, j = 0; j < len; i++, j += ch_num) {
int16_t *pout = &out[j];
int16_t *pin = &in[i];
for (int c = 0; c < ch_num; c++) {
*pout = *pin;
pout += 1;
pin += len_per_channel;
}
}
}
static void speech_extend(int16_t *in, int16_t *out, int len, int ch_num) {
int16_t *pout = out + len * ch_num - 1;
for (int i = len - 1; i >= 0; i--) {
for (int c = 0; c < ch_num; c++) {
*pout-- = in[i];
}
}
}
// This function output remains the same sample rate as input,
// output channel number shoule be CHAN_NUM_SEND.
// TODO: add multi-channel support in iir resampler
void speech_process_capture_run(uint8_t *buf, uint32_t *len) {
// TRACE(2,"[%s], pcm_len: %d", __FUNCTION__, *len / 2);
if (is_speech_init == false)
return;
int16_t *pcm_buf = (int16_t *)buf;
int pcm_len = *len / 2;
int process_len = pcm_len * FFSE_SAMPLE_RATE / capture_sample_rate;
if (resample_needed_flag == true) {
if (capture_channel_num > 1)
speech_deinterleave(pcm_buf, capture_buffer_deinter, pcm_len,
capture_channel_num);
else
speech_copy_int16(capture_buffer_deinter, pcm_buf, pcm_len);
int in_len_per_channel = pcm_len / capture_channel_num;
int out_len_per_channel = process_len / capture_channel_num;
for (int i = 0; i < capture_channel_num; i++) {
iir_resample_process(
downsample_st[i], &capture_buffer_deinter[i * in_len_per_channel],
&process_buffer[i * out_len_per_channel], in_len_per_channel);
}
if (capture_channel_num > 1)
speech_interleave(process_buffer, process_buffer_inter, process_len,
capture_channel_num);
else
speech_copy_int16(process_buffer_inter, process_buffer, process_len);
speech_tx_process(process_buffer_inter, aec_echo_buf, &process_len);
iir_resample_process(upsample_st, process_buffer_inter, pcm_buf,
process_len);
if (send_channel_num > 1)
speech_extend(pcm_buf, pcm_buf, in_len_per_channel, send_channel_num);
} else {
speech_tx_process(pcm_buf, aec_echo_buf, &process_len);
if (send_channel_num > 1)
speech_extend(pcm_buf, pcm_buf, process_len, send_channel_num);
}
pcm_len = pcm_len / capture_channel_num * send_channel_num;
*len = pcm_len * sizeof(int16_t);
}
void speech_process_playback_run(uint8_t *buf, uint32_t *len) {
// TRACE(2,"[%s] pcm_len: %d", __FUNCTION__, *len / 2);
if (is_speech_init == false)
return;
#if defined(SPEECH_TX_AEC2FLOAT)
int16_t *pcm_buf = (int16_t *)buf;
int pcm_len = *len / 2;
if (resample_needed_flag == true) {
// Convert to 16bit if necessary
if (playback_sample_bit == 24) {
int32_t *pcm32 = (int32_t *)buf;
for (int i = 0; i < pcm_len / 2; i++) {
pcm_buf[i] = (pcm32[i] >> 8);
}
pcm_len >>= 1;
}
// Convert to mono if necessary, choose left channel
if (playback_channel_num == 2) {
for (int i = 0, j = 0; i < pcm_len; i += 2, j++)
pcm_buf[j] = pcm_buf[i];
pcm_len >>= 1;
}
iir_resample_process(rx_downsample_st, pcm_buf, pcm_buf, pcm_len);
}
speech_copy_int16(aec_echo_buf, pcm_buf,
pcm_len * FFSE_SAMPLE_RATE / capture_sample_rate);
#endif
}
void speech_process_init(int tx_sample_rate, int tx_channel_num,
int tx_sample_bit, int rx_sample_rate,
int rx_channel_num, int rx_sample_bit, int tx_frame_ms,
int rx_frame_ms, int tx_send_channel_num,
int rx_recv_channel_num) {
ASSERT(tx_sample_rate == 16000 || tx_sample_rate == 48000,
"[%s] sample rate(%d) not supported", __FUNCTION__, tx_sample_rate);
ASSERT(tx_frame_ms == 16, "[%s] just support 16ms frame", __func__);
capture_sample_rate = tx_sample_rate;
capture_channel_num = tx_channel_num;
capture_sample_bit = tx_sample_bit;
playback_sample_rate = rx_sample_rate;
playback_channel_num = rx_channel_num;
playback_sample_bit = rx_sample_bit;
send_channel_num = tx_send_channel_num;
recv_channel_num = rx_recv_channel_num;
resample_needed_flag = (capture_sample_rate != FFSE_SAMPLE_RATE);
TRACE(5,
"[%s] sample_rate: %d, frame_ms: %d, channel_num: %d, "
"resample_needed_flag: %d",
__FUNCTION__, tx_sample_rate, tx_frame_ms, tx_channel_num,
resample_needed_flag);
speech_init(FFSE_SAMPLE_RATE, FFSE_SAMPLE_RATE, tx_frame_ms, tx_frame_ms,
tx_frame_ms, &g_medMemPool[0], MED_MEM_POOL_SIZE);
if (resample_needed_flag == true) {
capture_buffer_deinter =
speech_calloc(SPEECH_FRAME_MS_TO_LEN(capture_sample_rate, tx_frame_ms) *
capture_channel_num,
sizeof(int16_t));
// Resample state must be created after speech init, as it uses speech heap
process_buffer =
speech_calloc(SPEECH_FRAME_MS_TO_LEN(FFSE_SAMPLE_RATE, tx_frame_ms) *
capture_channel_num,
sizeof(int16_t));
process_buffer_inter =
speech_calloc(SPEECH_FRAME_MS_TO_LEN(FFSE_SAMPLE_RATE, tx_frame_ms) *
capture_channel_num,
sizeof(int16_t));
upsample_st = iir_resample_init(
SPEECH_FRAME_MS_TO_LEN(FFSE_SAMPLE_RATE, tx_frame_ms),
iir_resample_choose_mode(FFSE_SAMPLE_RATE, capture_sample_rate));
// as iir resample can only deal with mono signal, we should init
// channel_num states
for (int i = 0; i < capture_channel_num; i++) {
downsample_st[i] = iir_resample_init(
SPEECH_FRAME_MS_TO_LEN(capture_sample_rate, tx_frame_ms),
iir_resample_choose_mode(capture_sample_rate, FFSE_SAMPLE_RATE));
}
//
aec_echo_buf = speech_calloc(
SPEECH_FRAME_MS_TO_LEN(FFSE_SAMPLE_RATE, rx_frame_ms), sizeof(int16_t));
rx_downsample_st = iir_resample_init(
SPEECH_FRAME_MS_TO_LEN(playback_sample_rate, rx_frame_ms),
iir_resample_choose_mode(playback_sample_rate, FFSE_SAMPLE_RATE));
}
is_speech_init = true;
}
void speech_process_deinit(void) {
if (is_speech_init == false)
return;
if (resample_needed_flag == true) {
speech_free(capture_buffer_deinter);
speech_free(process_buffer);
speech_free(process_buffer_inter);
iir_resample_destroy(upsample_st);
for (int i = 0; i < capture_channel_num; i++) {
iir_resample_destroy(downsample_st[i]);
}
speech_free(aec_echo_buf);
iir_resample_destroy(rx_downsample_st);
resample_needed_flag = false;
}
speech_deinit();
is_speech_init = false;
}
enum HAL_CMU_FREQ_T speech_process_need_freq(void) { return HAL_CMU_FREQ_208M; }

View File

@ -1,40 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __SPEECH_PROCESS_H__
#define __SPEECH_PROCESS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
#include "hal_sysfreq.h"
enum HAL_CMU_FREQ_T speech_process_need_freq(void);
void speech_process_init(int tx_sample_rate, int tx_channel_num, int tx_sample_bit,
int rx_sample_rate, int rx_channel_num, int rx_sample_bit,
int tx_frame_ms, int rx_frame_ms,
int tx_send_channel_num, int rx_recv_channel_num);
void speech_process_deinit(void);
void speech_process_capture_run(uint8_t *buf, uint32_t *len);
void speech_process_playback_run(uint8_t *buf, uint32_t *len);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,66 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_AUDIO_APP_H__
#define __USB_AUDIO_APP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "plat_types.h"
#include "hal_key.h"
#include "audio_process.h"
struct USB_AUDIO_BUF_CFG {
uint8_t *play_buf;
uint32_t play_size;
uint8_t *cap_buf;
uint32_t cap_size;
uint8_t *recv_buf;
uint32_t recv_size;
uint8_t *send_buf;
uint32_t send_size;
uint8_t *eq_buf;
uint32_t eq_size;
uint8_t *resample_buf;
uint32_t resample_size;
#ifdef USB_AUDIO_MULTIFUNC
uint8_t *recv2_buf;
uint32_t recv2_size;
#endif
};
typedef void (*USB_AUDIO_ENQUEUE_CMD_CALLBACK)(uint32_t data);
void usb_audio_app(bool on);
void usb_audio_keep_streams_running(bool enable);
void usb_audio_app_init(const struct USB_AUDIO_BUF_CFG *cfg);
void usb_audio_app_term(void);
int usb_audio_app_key(enum HAL_KEY_CODE_T code, enum HAL_KEY_EVENT_T event);
void usb_audio_app_loop(void);
uint32_t usb_audio_get_capture_sample_rate(void);
uint32_t usb_audio_set_eq(AUDIO_EQ_TYPE_T audio_eq_type,uint8_t index);
uint8_t usb_audio_get_eq_index(AUDIO_EQ_TYPE_T audio_eq_type,uint8_t anc_status);
void usb_audio_set_enqueue_cmd_callback(USB_AUDIO_ENQUEUE_CMD_CALLBACK cb);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,232 +0,0 @@
/***************************************************************************
*
* Copyright 2015-2019 BES.
* All rights reserved. All unpublished rights reserved.
*
* No part of this work may be used or reproduced in any form or by any
* means, or stored in a database or retrieval system, without prior written
* permission of BES.
*
* Use of this work is governed by a license granted by BES.
* This work contains confidential and proprietary information of
* BES. which is protected by copyright, trade secret,
* trademark and other intellectual property rights.
*
****************************************************************************/
#ifndef __USB_AUDIO_FRM_DEFS_H__
#define __USB_AUDIO_FRM_DEFS_H__
#ifdef __cplusplus
extern "C" {
#endif
// Recv/send sample rates
#if 0
#elif defined(USB_AUDIO_384K)
#define SAMPLE_RATE_RECV 384000
#define SAMPLE_RATE_SEND 48000
#elif defined(USB_AUDIO_352_8K)
#define SAMPLE_RATE_RECV 352800
#define SAMPLE_RATE_SEND 44100
#elif defined(USB_AUDIO_192K)
#define SAMPLE_RATE_RECV 192000
#define SAMPLE_RATE_SEND 48000
#elif defined(USB_AUDIO_176_4K)
#define SAMPLE_RATE_RECV 176400
#define SAMPLE_RATE_SEND 44100
#elif defined(USB_AUDIO_96K)
#define SAMPLE_RATE_RECV 96000
#define SAMPLE_RATE_SEND 48000
#elif defined(USB_AUDIO_48K)
#define SAMPLE_RATE_RECV 48000
#define SAMPLE_RATE_SEND 48000
#elif defined(USB_AUDIO_44_1K)
#define SAMPLE_RATE_RECV 44100
#define SAMPLE_RATE_SEND 44100
#elif defined(USB_AUDIO_16K)
#define SAMPLE_RATE_RECV 16000
#define SAMPLE_RATE_SEND 16000
#else // 48K by default
#define SAMPLE_RATE_RECV 48000
#define SAMPLE_RATE_SEND 48000
#endif
// Playback sample rate
#if defined(CHIP_BEST1000) && defined(ANC_APP)
#if (SAMPLE_RATE_RECV % 8000)
#define SAMPLE_RATE_PLAYBACK 88200
#else
#define SAMPLE_RATE_PLAYBACK 96000
#endif
#elif defined(__AUDIO_RESAMPLE__) && defined(SW_PLAYBACK_RESAMPLE)
#define SAMPLE_RATE_PLAYBACK 50781
#else
#define SAMPLE_RATE_PLAYBACK SAMPLE_RATE_RECV
#endif
// Capture sample rate
#if defined(CHIP_BEST1000) && defined(ANC_APP)
#ifdef AUD_PLL_DOUBLE
#if defined(_DUAL_AUX_MIC_) || defined(CAPTURE_ANC_DATA)
#define SAMPLE_RATE_CAPTURE (SAMPLE_RATE_PLAYBACK * 8)
#else
#define SAMPLE_RATE_CAPTURE (SAMPLE_RATE_PLAYBACK * 2)
#endif
#else // !AUD_PLL_DOUBLE
#if defined(_DUAL_AUX_MIC_) || defined(CAPTURE_ANC_DATA)
#define SAMPLE_RATE_CAPTURE (SAMPLE_RATE_PLAYBACK * 4)
#else
#define SAMPLE_RATE_CAPTURE SAMPLE_RATE_PLAYBACK
#endif
#endif // !AUD_PLL_DOUBLE
#else // !(CHIP_BEST1000 && ANC_APP)
#if defined(CHIP_BEST1000) && defined(_DUAL_AUX_MIC_)
#define SAMPLE_RATE_CAPTURE (SAMPLE_RATE_SEND * 4)
#elif defined(__AUDIO_RESAMPLE__) && defined(SW_CAPTURE_RESAMPLE)
#define SAMPLE_RATE_CAPTURE 50781
#else
#define SAMPLE_RATE_CAPTURE SAMPLE_RATE_SEND
#endif
#endif // !(CHIP_BEST1000 && ANC_APP)
#ifdef USB_AUDIO_32BIT
#define SAMPLE_SIZE_PLAYBACK 4
#define SAMPLE_SIZE_RECV 4
#elif defined(USB_AUDIO_24BIT)
#define SAMPLE_SIZE_PLAYBACK 4
#define SAMPLE_SIZE_RECV 3
#else
#ifdef AUDIO_PLAYBACK_24BIT
#define SAMPLE_SIZE_PLAYBACK 4
#else
#define SAMPLE_SIZE_PLAYBACK 2
#endif
#define SAMPLE_SIZE_RECV 2
#endif
#ifdef USB_AUDIO_SEND_32BIT
#define SAMPLE_SIZE_CAPTURE 4
#define SAMPLE_SIZE_SEND 4
#elif defined(USB_AUDIO_SEND_24BIT)
#define SAMPLE_SIZE_CAPTURE 4
#define SAMPLE_SIZE_SEND 3
#else
#define SAMPLE_SIZE_CAPTURE 2
#define SAMPLE_SIZE_SEND 2
#endif
#define CHAN_NUM_PLAYBACK 2
#define CHAN_NUM_RECV 2
#ifdef USB_AUDIO_SEND_CHAN
#define CHAN_NUM_SEND USB_AUDIO_SEND_CHAN
#else
#define CHAN_NUM_SEND 2
#endif
#if defined(CHIP_BEST1000) && defined(ANC_APP)
#define CHAN_NUM_CAPTURE 2
#elif defined(USB_AUDIO_SPEECH)
#define CHAN_NUM_CAPTURE SPEECH_CODEC_CAPTURE_CHANNEL_NUM
#else
#define CHAN_NUM_CAPTURE CHAN_NUM_SEND
#endif
#define BYTE_TO_SAMP_PLAYBACK(n) ((n) / SAMPLE_SIZE_PLAYBACK / CHAN_NUM_PLAYBACK)
#define SAMP_TO_BYTE_PLAYBACK(n) ((n) * SAMPLE_SIZE_PLAYBACK * CHAN_NUM_PLAYBACK)
#define BYTE_TO_SAMP_CAPTURE(n) ((n) / SAMPLE_SIZE_CAPTURE / CHAN_NUM_CAPTURE)
#define SAMP_TO_BYTE_CAPTURE(n) ((n) * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
#define BYTE_TO_SAMP_RECV(n) ((n) / SAMPLE_SIZE_RECV / CHAN_NUM_RECV)
#define SAMP_TO_BYTE_RECV(n) ((n) * SAMPLE_SIZE_RECV * CHAN_NUM_RECV)
#define BYTE_TO_SAMP_SEND(n) ((n) / SAMPLE_SIZE_SEND / CHAN_NUM_SEND)
#define SAMP_TO_BYTE_SEND(n) ((n) * SAMPLE_SIZE_SEND * CHAN_NUM_SEND)
#define SAMP_RATE_TO_FRAME_SIZE(n) (((n) + (1000 - 1)) / 1000)
#define SAMPLE_FRAME_PLAYBACK SAMP_RATE_TO_FRAME_SIZE(SAMPLE_RATE_PLAYBACK)
#define SAMPLE_FRAME_CAPTURE SAMP_RATE_TO_FRAME_SIZE(SAMPLE_RATE_CAPTURE)
#define SAMPLE_FRAME_RECV SAMP_RATE_TO_FRAME_SIZE(SAMPLE_RATE_RECV)
#define SAMPLE_FRAME_SEND SAMP_RATE_TO_FRAME_SIZE(SAMPLE_RATE_SEND)
#define FRAME_SIZE_PLAYBACK SAMP_TO_BYTE_PLAYBACK(SAMPLE_FRAME_PLAYBACK)
#define FRAME_SIZE_CAPTURE SAMP_TO_BYTE_CAPTURE(SAMPLE_FRAME_CAPTURE)
#define FRAME_SIZE_RECV SAMP_TO_BYTE_RECV(SAMPLE_FRAME_RECV)
#define FRAME_SIZE_SEND SAMP_TO_BYTE_SEND(SAMPLE_FRAME_SEND)
#define PLAYBACK_TO_RECV_LEN(n) (SAMP_TO_BYTE_RECV((BYTE_TO_SAMP_PLAYBACK(n) * \
(SAMPLE_RATE_RECV / 100) + (SAMPLE_RATE_PLAYBACK / 100) - 1) / (SAMPLE_RATE_PLAYBACK / 100)))
#define CAPTURE_TO_SEND_LEN(n) (SAMP_TO_BYTE_SEND((BYTE_TO_SAMP_CAPTURE(n) * \
(SAMPLE_RATE_SEND / 100) + (SAMPLE_RATE_CAPTURE / 100) - 1) / (SAMPLE_RATE_CAPTURE / 100)))
#ifdef USB_HIGH_SPEED
#if defined(USB_AUDIO_384K) || defined(USB_AUDIO_352_8K)
#define MAX_FRAME_SIZE_PLAYBACK (SAMP_RATE_TO_FRAME_SIZE(384000) * 4 * CHAN_NUM_PLAYBACK)
#else
#define MAX_FRAME_SIZE_PLAYBACK (SAMP_RATE_TO_FRAME_SIZE(192000) * 4 * CHAN_NUM_PLAYBACK)
#endif
#else
// Same as (SAMP_RATE_TO_FRAME_SIZE(192000) * 2 * CHAN_NUM_PLAYBACK)
#define MAX_FRAME_SIZE_PLAYBACK (SAMP_RATE_TO_FRAME_SIZE(96000) * 4 * CHAN_NUM_PLAYBACK)
#endif
#if (defined(__AUDIO_RESAMPLE__) && defined(SW_CAPTURE_RESAMPLE)) || \
(defined(CHIP_BEST1000) && (defined(ANC_APP) || defined(_DUAL_AUX_MIC_)))
// Fixed capture sample rate
#define MAX_FRAME_SIZE_CAPTURE (SAMP_RATE_TO_FRAME_SIZE(SAMPLE_RATE_CAPTURE) * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
#else
#define MAX_FRAME_SIZE_CAPTURE (SAMP_RATE_TO_FRAME_SIZE(48000) * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
#endif
#ifdef USB_HIGH_SPEED
#if defined(USB_AUDIO_384K) || defined(USB_AUDIO_352_8K)
#define MAX_FRAME_SIZE_RECV (SAMP_RATE_TO_FRAME_SIZE(384000) * 4 * CHAN_NUM_RECV)
#else
#define MAX_FRAME_SIZE_RECV (SAMP_RATE_TO_FRAME_SIZE(192000) * 4 * CHAN_NUM_RECV)
#endif
#else
// Same as (SAMP_RATE_TO_FRAME_SIZE(192000) * 2 * CHAN_NUM_RECV)
#define MAX_FRAME_SIZE_RECV (SAMP_RATE_TO_FRAME_SIZE(96000) * 4 * CHAN_NUM_RECV)
#endif
#define MAX_FRAME_SIZE_SEND (SAMP_RATE_TO_FRAME_SIZE(48000) * SAMPLE_SIZE_SEND * CHAN_NUM_SEND)
// ----------------
// Buffer alignment
// ----------------
#define AF_DMA_LIST_CNT 4
#ifdef ADC_CH_SEP_BUFF
#define ADC_BURST_NUM 4
#define ADC_ALL_CH_DMA_BURST_SIZE (ADC_BURST_NUM * SAMPLE_SIZE_CAPTURE * CHAN_NUM_CAPTURE)
#define ADC_BUFF_ALIGN (ADC_ALL_CH_DMA_BURST_SIZE * AF_DMA_LIST_CNT)
#else
#define ADC_BUFF_ALIGN (4 * AF_DMA_LIST_CNT)
#endif
#if defined(__HW_FIR_DSD_PROCESS__)
// FIR DSD requires DAC buffer is aligned to 16-sample boundary for each FIR DMA process loop
#define DAC_BUFF_ALIGN (16 * SAMPLE_SIZE_PLAYBACK * CHAN_NUM_PLAYBACK * 2)
#else
#define DAC_BUFF_ALIGN (4 * AF_DMA_LIST_CNT)
#endif
// USB buffer is split into 2 parts, and transfers from the second half (similar to PING-PONG buffer)
#ifdef USB_AUDIO_DYN_CFG
// RECV type-I frame slot (sample_size*chan_num): 2*2=4, 3*2=6, 4*2=8. The least common multiple is 24
#define RECV_BUFF_ALIGN (2 * 24)
// SEND type-I frame slot (sample_size*chan_num): 2*2=4. The least common multiple is 4
#define SEND_BUFF_ALIGN (2 * 4)
#else
// If usb rx/tx pool is NOT used, the buffer size should be aligned to frame packet size
#define RECV_BUFF_ALIGN SAMP_TO_BYTE_RECV(2)
#define SEND_BUFF_ALIGN SAMP_TO_BYTE_SEND(2)
#endif
#define NON_EXP_ALIGN(val, exp) (((val) + ((exp) - 1)) / (exp) * (exp))
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,261 +0,0 @@
#ifdef _VENDOR_MSG_SUPPT_
#include "cmsis.h"
#include "crc32.h"
#include "hal_bootmode.h"
#include "hal_cmu.h"
#include "hal_norflash.h"
#include "hal_timer.h"
#include "hal_trace.h"
#include "pmu.h"
#include "stdlib.h"
#include "tgt_hardware.h"
#include <stdio.h>
#include <string.h>
#ifdef USB_EQ_TUNING
#include "hal_cmd.h"
#endif
#ifdef USB_ANC_MC_EQ_TUNING
#include "anc_process.h"
#endif
#include "usb_vendor_msg.h"
#define SYS_CHECK_VAL "1.1"
#define FACT_SEC_VER 2
#define FACT_SEC_MAGIC 0xba80
typedef enum {
FACT_SEC_VER_MAGIC,
FACT_SEC_CRC,
FACT_SEC_DATA_START,
FACT_SEC_SEQ = FACT_SEC_DATA_START,
FACT_SEC_PROD_SN,
FACT_SEC_END = FACT_SEC_PROD_SN + 8,
FACT_SEC_NUM = 256
} FACT_SEC_E;
typedef enum {
PC_TOOL_CMD_IDLE,
PC_TOOL_CMD_GET_FW_VER,
PC_TOOL_CMD_GET_PROD_SN,
// QUERY_VOLTAGE,
// BURN_SN,
PC_TOOL_CMD_SYS_REBOOT,
PC_TOOL_CMD_SYS_SHUTDOWN,
PC_TOOL_CMD_PING,
PC_TOOL_CMD_CHECK,
PC_TOOL_CMD_FW_UPDATE,
#ifdef USB_EQ_TUNING
PC_TOOL_CMD_EQ_TUNING,
#endif
#ifdef USB_ANC_MC_EQ_TUNING
PC_TOOL_CMD_ANC_MC_EQ_TUNING,
#endif
PC_TOOL_CMD_NUM,
} PC_TOOL_CMD_E;
static char *s_pc_cmd_lst[PC_TOOL_CMD_NUM] = {
" ",
"QUERY_SW_VER",
"QUERY_SN",
// "QUERY_VOL",
// "BURN_SN",
"SYS_REBOOT",
"SYS_SHUTDOWN",
"PING_THROUGH_VENDOR",
"CHECK",
"FW_UPDATE",
#ifdef USB_EQ_TUNING
"EQ<",
#endif
#ifdef USB_ANC_MC_EQ_TUNING
"ANC_MC_EQ",
#endif
};
static PC_TOOL_CMD_E s_cur_cmd = PC_TOOL_CMD_IDLE;
static uint8_t *s_sn_ptr;
static uint8_t *s_fw_ver_ptr;
static uint8_t s_sn_sz;
static uint8_t s_fw_ver_sz;
uint8_t vendor_msg_rx_buf[VENDOR_RX_BUF_SZ];
extern void analog_aud_codec_mute(void);
int WEAK vendor_get_sn_info(uint8_t **p_ptr, uint8_t *p_size) {
static const char sn[] = "SN-001";
*p_ptr = (uint8_t *)sn;
*p_size = sizeof(sn) - 1;
return 0;
}
int WEAK vendor_get_fw_ver_info(uint8_t **p_ptr, uint8_t *p_size) {
static const char ver[] = "VER-001";
*p_ptr = (uint8_t *)ver;
*p_size = sizeof(ver) - 1;
return 0;
}
void vendor_info_init(void) {
vendor_get_sn_info(&s_sn_ptr, &s_sn_sz);
vendor_get_fw_ver_info(&s_fw_ver_ptr, &s_fw_ver_sz);
}
static void pc_usb_cmd_set(struct USB_AUDIO_VENDOR_MSG_T *msg) {
size_t ret;
uint8_t cmd_id = 0;
if (0 == msg->length)
return;
for (cmd_id = 1; cmd_id < PC_TOOL_CMD_NUM; cmd_id++) {
ret = memcmp((void *)msg->data, (void *)s_pc_cmd_lst[cmd_id],
strlen((char *)s_pc_cmd_lst[cmd_id]));
if (!ret)
break;
}
if (cmd_id > (PC_TOOL_CMD_NUM - 1)) {
return;
}
s_cur_cmd = cmd_id;
// TRACE(3,"%s: cmd[%s], id[%d]", __func__, s_pc_cmd_lst[cmd_id], s_cur_cmd);
msg->data += strlen((char *)s_pc_cmd_lst[cmd_id]);
#ifdef USB_ANC_MC_EQ_TUNING
msg->length -= strlen((char *)s_pc_cmd_lst[cmd_id]);
#endif
switch (s_cur_cmd) {
#ifdef USB_EQ_TUNING
case PC_TOOL_CMD_EQ_TUNING:
hal_cmd_list_process(msg->data);
break;
#endif
#ifdef USB_ANC_MC_EQ_TUNING
case PC_TOOL_CMD_ANC_MC_EQ_TUNING:
// TRACE(1,"recev len:%d",msg->length);
/*
TRACE(0,"***********recev test*************");
for(int i=0;i<msg->length;i++)
{
TRACE(2,"msg->data[%d]:0x%x",i,msg->data[i]);
}
TRACE(0,"***********recev test*************");
*/
anc_cmd_receve_process(msg->data, msg->length);
break;
#endif
default:
break;
}
}
static void pc_usb_cmd_exec(struct USB_AUDIO_VENDOR_MSG_T *msg) {
// TRACE(2,"%s: cmd[%d]", __func__, s_cur_cmd);
static const char *s_str_ret1 = "1";
#ifdef USB_EQ_TUNING
static const char *s_str_ret0 = "0";
#endif
static const char *s_str_failure = "failure";
switch (s_cur_cmd) {
case PC_TOOL_CMD_GET_FW_VER:
msg->data = s_fw_ver_ptr;
msg->length = strlen((char *)s_fw_ver_ptr);
break;
case PC_TOOL_CMD_GET_PROD_SN:
msg->data = s_sn_ptr;
msg->length = strlen((char *)s_sn_ptr);
break;
case PC_TOOL_CMD_SYS_REBOOT:
// TRACE(0,"-> cmd_exec: reboot.....");
hal_sys_timer_delay(MS_TO_TICKS(500));
hal_cmu_sys_reboot();
break;
case PC_TOOL_CMD_SYS_SHUTDOWN:
pmu_shutdown();
break;
case PC_TOOL_CMD_PING:
msg->data = (uint8_t *)s_pc_cmd_lst[PC_TOOL_CMD_PING];
msg->length = (uint32_t)strlen((const char *)msg->data);
break;
case PC_TOOL_CMD_CHECK:
msg->data = (uint8_t *)SYS_CHECK_VAL;
msg->length = strlen((char *)SYS_CHECK_VAL);
break;
case PC_TOOL_CMD_FW_UPDATE:
hal_sw_bootmode_clear(1 << 8); // to clear HAL_SW_BOOTMODE_FORCE_UART_DLD
hal_sw_bootmode_set(1 << 7); // to set HAL_SW_BOOTMODE_FORCE_USB_DLD
#ifdef TGT_PLL_FREQ
extern void pll_config_update(uint32_t);
pll_config_update(960000000);
#endif
analog_aud_codec_mute();
msg->data = (uint8_t *)s_str_ret1;
msg->length = (uint32_t)strlen(s_str_ret1);
break;
#ifdef USB_EQ_TUNING
case PC_TOOL_CMD_EQ_TUNING:
hal_cmd_tx_process(&msg->data, &msg->length);
if (!msg->length) {
msg->data = (uint8_t *)s_str_ret0;
msg->length = (uint32_t)strlen(s_str_ret0);
}
break;
#endif
#ifdef USB_ANC_MC_EQ_TUNING
case PC_TOOL_CMD_ANC_MC_EQ_TUNING:
anc_cmd_send_process(&msg->data, &msg->length);
TRACE(1, "sned len:%d", msg->length);
/* TRACE(0,"***********send test*************");
for(int i=0;i<msg->length;i++)
{
TRACE(2,"msg->data[%d]:0x%x",i,msg->data[i]);
}
TRACE(0,"***********send test*************");
*/
break;
#endif
default:
msg->data = (uint8_t *)s_str_failure;
msg->length = (uint32_t)strlen(s_str_failure);
break;
}
s_cur_cmd = PC_TOOL_CMD_IDLE;
}
int usb_vendor_callback(struct USB_AUDIO_VENDOR_MSG_T *msg) {
if (0 == msg->length) {
pc_usb_cmd_exec(msg);
} else {
pc_usb_cmd_set(msg);
}
return 0;
}
#endif

View File

@ -1,17 +0,0 @@
#ifndef _USB_VENDOR_MSG_H_
#define _USB_VENDOR_MSG_H_
#include "usb_audio.h"
#ifdef USB_ANC_MC_EQ_TUNING
#define VENDOR_RX_BUF_SZ 5000
#else
#define VENDOR_RX_BUF_SZ 240
#endif
extern uint8_t vendor_msg_rx_buf[VENDOR_RX_BUF_SZ];
int usb_vendor_callback (struct USB_AUDIO_VENDOR_MSG_T *msg);
void vendor_info_init (void);
#endif // _USB_VENDOR_MSG_H_