Merge pull request #33 from pine64/developer-comforts
Developer comforts part 1
This commit is contained in:
commit
8a7e040fc7
|
@ -0,0 +1 @@
|
|||
BasedOnStyle: LLVM
|
|
@ -0,0 +1,17 @@
|
|||
name: CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build-firmware:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/pine64/openpinebuds:latest-sdk
|
||||
steps:
|
||||
- name: Build the main firmware
|
||||
run: cd /usr/src/ && ./build.sh || cat /usr/src/log.txt
|
||||
|
||||
- name: Archive produced firmware
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
path: /usr/src/out/open_source/open_source.bin
|
33
Dockerfile
33
Dockerfile
|
@ -9,12 +9,12 @@ ENV PATH="/root/.cargo/bin:$PATH"
|
|||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
bc \
|
||||
build-essential \
|
||||
curl \
|
||||
git \
|
||||
libudev-dev \
|
||||
pkg-config \
|
||||
bc \
|
||||
build-essential \
|
||||
curl \
|
||||
git \
|
||||
libudev-dev \
|
||||
pkg-config \
|
||||
&& curl https://sh.rustup.rs -sSf | bash -s -- -y \
|
||||
&& git clone https://github.com/Ralim/bestool.git \
|
||||
&& cd /usr/src/bestool/bestool/ \
|
||||
|
@ -26,19 +26,20 @@ WORKDIR /usr/src
|
|||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y \
|
||||
bash \
|
||||
bc \
|
||||
bzip2 \
|
||||
curl \
|
||||
ffmpeg \
|
||||
git \
|
||||
make \
|
||||
tar \
|
||||
xxd \
|
||||
bash \
|
||||
bc \
|
||||
bzip2 \
|
||||
curl \
|
||||
ffmpeg \
|
||||
clang-format \
|
||||
git \
|
||||
make \
|
||||
tar \
|
||||
xxd \
|
||||
&& git config --global --add safe.directory /src \
|
||||
&& mkdir -pv /src \
|
||||
&& curl \
|
||||
https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-$(arch)-linux.tar.bz2 | tar -xj -C /src/
|
||||
https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/9-2019q4/gcc-arm-none-eabi-9-2019-q4-major-$(arch)-linux.tar.bz2 | tar -xj -C /src/
|
||||
|
||||
ENV PATH="${PATH}:/src/gcc-arm-none-eabi-9-2019-q4-major/bin"
|
||||
COPY --from=rust_build /usr/src/bestool/bestool/target/release/bestool /usr/local/bin/bestool
|
||||
|
|
25
Makefile
25
Makefile
|
@ -1037,7 +1037,32 @@ endif
|
|||
|
||||
PHONY += FORCE
|
||||
FORCE: ;
|
||||
### Formatting
|
||||
ALL_SOURCE = $(shell find . \( -type f \( -name '*.c' -o -name '*.cpp' \) \) )
|
||||
|
||||
|
||||
style:
|
||||
@for src in $(ALL_SOURCE) $(ALL_INCLUDES); do \
|
||||
echo "Formatting $$src..." ; \
|
||||
clang-format -i "$$src" ; \
|
||||
done
|
||||
@echo "Done"
|
||||
|
||||
check-style:
|
||||
@for src in $(ALL_SOURCE) $(ALL_INCLUDES) ; do \
|
||||
var=`clang-format "$$src" | diff "$$src" - | wc -l` ; \
|
||||
if [ $$var -ne 0 ] ; then \
|
||||
echo "$$src does not respect the coding style (diff: $$var lines)" ; \
|
||||
clang-format "$$src" | diff "$$src" -; \
|
||||
exit 1 ; \
|
||||
fi ; \
|
||||
done
|
||||
@echo "Style check passed"
|
||||
|
||||
|
||||
PHONY += style check-style
|
||||
|
||||
# Declare the contents of the .PHONY variable as phony. We keep that
|
||||
# information in a variable so we can use it in if_changed and friends.
|
||||
.PHONY: $(PHONY)
|
||||
|
||||
|
|
|
@ -17,30 +17,29 @@
|
|||
#define __ANC_WNR_H__
|
||||
|
||||
// #include "plat_types.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ANC_WNR_OPEN_MODE_STANDALONE = 0,
|
||||
ANC_WNR_OPEN_MODE_CONFIGURE,
|
||||
typedef enum {
|
||||
ANC_WNR_OPEN_MODE_STANDALONE = 0,
|
||||
ANC_WNR_OPEN_MODE_CONFIGURE,
|
||||
|
||||
ANC_WNR_OPEN_MODE_QTY
|
||||
ANC_WNR_OPEN_MODE_QTY
|
||||
} anc_wnr_open_mode_t;
|
||||
|
||||
void anc_release_gain(void);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
APP_WNR_NOTIFY_DETECT_RESULT,
|
||||
APP_WNR_REQUEST_DETECT_RESULT,
|
||||
APP_WNR_RESPONSE_DETECT_RESULT,
|
||||
APP_WNR_PROCESS_DETECT_RESULT,
|
||||
APP_WNR_SET_TRIGGER,
|
||||
APP_WNR_EXCUTE_TRIGGER,
|
||||
APP_WNR_SHARE_MODULE_INFO,
|
||||
typedef enum {
|
||||
APP_WNR_NOTIFY_DETECT_RESULT,
|
||||
APP_WNR_REQUEST_DETECT_RESULT,
|
||||
APP_WNR_RESPONSE_DETECT_RESULT,
|
||||
APP_WNR_PROCESS_DETECT_RESULT,
|
||||
APP_WNR_SET_TRIGGER,
|
||||
APP_WNR_EXCUTE_TRIGGER,
|
||||
APP_WNR_SHARE_MODULE_INFO,
|
||||
} anc_wnr_sync_ctrl_internal_event_e;
|
||||
|
||||
int32_t anc_wnr_ctrl(int32_t sample_rate, int32_t frame_len);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
*
|
||||
* Copyright 2015-2019 BES.
|
||||
|
@ -17,49 +16,43 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "anc_assist.h"
|
||||
#include "hal_trace.h"
|
||||
#include "anc_assist_algo.h"
|
||||
#include "anc_process.h"
|
||||
#include "arm_math.h"
|
||||
#include "audio_dump.h"
|
||||
#include "speech_cfg.h"
|
||||
#include "anc_process.h"
|
||||
#include "audioflinger.h"
|
||||
#include "anc_assist_algo.h"
|
||||
#include "hal_codec.h"
|
||||
#include "audioflinger.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_aud.h"
|
||||
#include "hal_codec.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "speech_cfg.h"
|
||||
#include "speech_memory.h"
|
||||
#include "speech_ssat.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hal_aud.h"
|
||||
#include "anc_process.h"
|
||||
#include "anc_assist_algo.h"
|
||||
#include "speech_memory.h"
|
||||
#include "speech_ssat.h"
|
||||
|
||||
|
||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
#include "main_classify.h"
|
||||
#endif
|
||||
|
||||
|
||||
static void _close_mic_anc_assist();
|
||||
static void _open_mic_anc_assist();
|
||||
#define _SAMPLE_RATE (16000)
|
||||
#define _SAMPLE_RATE (16000)
|
||||
|
||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
#define _FRAME_LEN (128)
|
||||
#define _FRAME_LEN (128)
|
||||
#else
|
||||
#define _FRAME_LEN (160)
|
||||
#define _FRAME_LEN (160)
|
||||
#endif
|
||||
|
||||
#define _CHANNEL_NUM_MAX (3)
|
||||
#define SAMPLE_BYTES (sizeof(ASSIST_PCM_T))
|
||||
#define AF_STREAM_BUFF_SIZE (_FRAME_LEN * SAMPLE_BYTES * _CHANNEL_NUM_MAX * 2)
|
||||
#define ANC_ADPT_STREAM_ID AUD_STREAM_ID_3
|
||||
#define _CHANNEL_NUM_MAX (3)
|
||||
#define SAMPLE_BYTES (sizeof(ASSIST_PCM_T))
|
||||
#define AF_STREAM_BUFF_SIZE (_FRAME_LEN * SAMPLE_BYTES * _CHANNEL_NUM_MAX * 2)
|
||||
#define ANC_ADPT_STREAM_ID AUD_STREAM_ID_3
|
||||
|
||||
#define _FRAME_LEN_MAX (160)
|
||||
#define _SAMPLE_BITS_MAX (32)
|
||||
#define _FRAME_LEN_MAX (160)
|
||||
#define _SAMPLE_BITS_MAX (32)
|
||||
|
||||
static uint8_t __attribute__((aligned(4))) af_stream_buff[AF_STREAM_BUFF_SIZE];
|
||||
static ASSIST_PCM_T af_stream_mic1[_FRAME_LEN_MAX * (_SAMPLE_BITS_MAX / 8)];
|
||||
|
@ -69,377 +62,322 @@ int MIC_NUM = 0;
|
|||
int MIC_MAP = 0;
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
#define _PLAY_SAMPLE_RATE (8000)
|
||||
#define _PLAY_FRAME_LEN (80)
|
||||
#define AF_PLAY_STREAM_BUFF_SIZE (_PLAY_FRAME_LEN * SAMPLE_BYTES * 1 * 2)
|
||||
static uint8_t __attribute__((aligned(4))) af_play_stream_buff[AF_PLAY_STREAM_BUFF_SIZE];
|
||||
#define _PLAY_SAMPLE_RATE (8000)
|
||||
#define _PLAY_FRAME_LEN (80)
|
||||
#define AF_PLAY_STREAM_BUFF_SIZE (_PLAY_FRAME_LEN * SAMPLE_BYTES * 1 * 2)
|
||||
static uint8_t __attribute__((aligned(4)))
|
||||
af_play_stream_buff[AF_PLAY_STREAM_BUFF_SIZE];
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
ClassifyState * NoiseClassify_st = NULL;
|
||||
ClassifyState *NoiseClassify_st = NULL;
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED) || defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED) || defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED) || defined(ANC_ASSIST_HESS_ENABLED) || \
|
||||
defined(ANC_ASSIST_PNC_ENABLED) || \
|
||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || \
|
||||
defined(ANC_ASSIST_WNR_ENABLED) || \
|
||||
defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
|
||||
extern const struct_anc_cfg * anc_coef_list_48k[1];
|
||||
void anc_assist_change_curve(int curve_id){
|
||||
TRACE(2,"[%s] change anc curve %d",__func__,curve_id);
|
||||
anc_set_cfg(anc_coef_list_48k[0],ANC_FEEDFORWARD,ANC_GAIN_NO_DELAY);
|
||||
anc_set_cfg(anc_coef_list_48k[0],ANC_FEEDBACK,ANC_GAIN_NO_DELAY);
|
||||
extern const struct_anc_cfg *anc_coef_list_48k[1];
|
||||
void anc_assist_change_curve(int curve_id) {
|
||||
TRACE(2, "[%s] change anc curve %d", __func__, curve_id);
|
||||
anc_set_cfg(anc_coef_list_48k[0], ANC_FEEDFORWARD, ANC_GAIN_NO_DELAY);
|
||||
anc_set_cfg(anc_coef_list_48k[0], ANC_FEEDBACK, ANC_GAIN_NO_DELAY);
|
||||
}
|
||||
bool audio_engine_tt_is_on(){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool audio_engine_tt_is_on() { return 1; }
|
||||
|
||||
#define _tgt_ff_gain (512)
|
||||
void anc_assist_set_anc_gain(float gain_ch_l, float gain_ch_r,enum ANC_TYPE_T anc_type){
|
||||
void anc_assist_set_anc_gain(float gain_ch_l, float gain_ch_r,
|
||||
enum ANC_TYPE_T anc_type) {
|
||||
|
||||
TRACE(2,"[%s] set anc gain %d",__func__,(int)(100*gain_ch_l));
|
||||
uint32_t tgt_ff_gain_l,tgt_ff_gain_r;
|
||||
tgt_ff_gain_l = (uint32_t)(_tgt_ff_gain*gain_ch_l);
|
||||
tgt_ff_gain_r = (uint32_t)(_tgt_ff_gain*gain_ch_r);
|
||||
anc_set_gain(tgt_ff_gain_l,tgt_ff_gain_r,anc_type);
|
||||
TRACE(2, "[%s] set anc gain %d", __func__, (int)(100 * gain_ch_l));
|
||||
uint32_t tgt_ff_gain_l, tgt_ff_gain_r;
|
||||
tgt_ff_gain_l = (uint32_t)(_tgt_ff_gain * gain_ch_l);
|
||||
tgt_ff_gain_r = (uint32_t)(_tgt_ff_gain * gain_ch_r);
|
||||
anc_set_gain(tgt_ff_gain_l, tgt_ff_gain_r, anc_type);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
static LeakageDetectionState * pilot_st = NULL;
|
||||
static LeakageDetectionState *pilot_st = NULL;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
static ANCAssistMultiState * anc_assist_multi_st = NULL;
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
static ANCAssistMultiState *anc_assist_multi_st = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
ANC_ASSIST_MODE_T g_anc_assist_mode = ANC_ASSIST_MODE_QTY;
|
||||
void anc_assist_open(ANC_ASSIST_MODE_T mode){
|
||||
g_anc_assist_mode = mode;
|
||||
void anc_assist_open(ANC_ASSIST_MODE_T mode) {
|
||||
g_anc_assist_mode = mode;
|
||||
|
||||
|
||||
//normal init
|
||||
// normal init
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
pilot_st = LeakageDetection_create(160,0);
|
||||
pilot_st = LeakageDetection_create(160, 0);
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
anc_assist_multi_st = ANCAssistMulti_create(_SAMPLE_RATE,_FRAME_LEN,128);
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
anc_assist_multi_st = ANCAssistMulti_create(_SAMPLE_RATE, _FRAME_LEN, 128);
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
NoiseClassify_st = classify_create(_SAMPLE_RATE, _FRAME_LEN);
|
||||
NoiseClassify_st = classify_create(_SAMPLE_RATE, _FRAME_LEN);
|
||||
#endif
|
||||
|
||||
// audio_dump_init(160,sizeof(short),3);
|
||||
// audio_dump_init(160,sizeof(short),3);
|
||||
|
||||
|
||||
if( mode == ANC_ASSIST_MODE_QTY){
|
||||
return;
|
||||
if (mode == ANC_ASSIST_MODE_QTY) {
|
||||
return;
|
||||
} else {
|
||||
if (mode == ANC_ASSIST_STANDALONE || mode == ANC_ASSIST_MUSIC) {
|
||||
_open_mic_anc_assist();
|
||||
}
|
||||
else{
|
||||
if(mode == ANC_ASSIST_STANDALONE || mode == ANC_ASSIST_MUSIC ){
|
||||
_open_mic_anc_assist();
|
||||
}
|
||||
if(mode == ANC_ASSIST_PHONE_8K){
|
||||
// normal init 8k
|
||||
}
|
||||
else if(mode == ANC_ASSIST_PHONE_16K){
|
||||
// normal init 16k
|
||||
}
|
||||
|
||||
if (mode == ANC_ASSIST_PHONE_8K) {
|
||||
// normal init 8k
|
||||
} else if (mode == ANC_ASSIST_PHONE_16K) {
|
||||
// normal init 16k
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void anc_assist_close(){
|
||||
void anc_assist_close() {
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
LeakageDetection_destroy(pilot_st);
|
||||
LeakageDetection_destroy(pilot_st);
|
||||
#endif
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
ANCAssistMulti_destroy(anc_assist_multi_st);
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
ANCAssistMulti_destroy(anc_assist_multi_st);
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
classify_destroy(NoiseClassify_st);
|
||||
classify_destroy(NoiseClassify_st);
|
||||
#endif
|
||||
|
||||
// ext_heap_deinit();
|
||||
// ext_heap_deinit();
|
||||
|
||||
if( g_anc_assist_mode == ANC_ASSIST_MODE_QTY){
|
||||
return;
|
||||
if (g_anc_assist_mode == ANC_ASSIST_MODE_QTY) {
|
||||
return;
|
||||
} else {
|
||||
if (g_anc_assist_mode == ANC_ASSIST_STANDALONE ||
|
||||
g_anc_assist_mode == ANC_ASSIST_MUSIC) {
|
||||
_close_mic_anc_assist();
|
||||
}
|
||||
else{
|
||||
if(g_anc_assist_mode == ANC_ASSIST_STANDALONE || g_anc_assist_mode == ANC_ASSIST_MUSIC ){
|
||||
_close_mic_anc_assist();
|
||||
}
|
||||
if(g_anc_assist_mode == ANC_ASSIST_PHONE_8K){
|
||||
// normal init 8k
|
||||
}
|
||||
else if(g_anc_assist_mode == ANC_ASSIST_PHONE_16K){
|
||||
// normal init 16k
|
||||
}
|
||||
|
||||
if (g_anc_assist_mode == ANC_ASSIST_PHONE_8K) {
|
||||
// normal init 8k
|
||||
} else if (g_anc_assist_mode == ANC_ASSIST_PHONE_16K) {
|
||||
// normal init 16k
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern ASSIST_PCM_T ref_buf_data[80];
|
||||
void anc_assist_process(uint8_t * buf, int len){
|
||||
void anc_assist_process(uint8_t *buf, int len) {
|
||||
|
||||
int32_t frame_len = len / SAMPLE_BYTES / MIC_NUM;
|
||||
ASSERT(frame_len == _FRAME_LEN, "[%s] frame len(%d) is invalid.", __func__,
|
||||
frame_len);
|
||||
ASSIST_PCM_T *pcm_buf = (ASSIST_PCM_T *)buf;
|
||||
|
||||
int32_t frame_len = len / SAMPLE_BYTES / MIC_NUM;
|
||||
ASSERT(frame_len == _FRAME_LEN, "[%s] frame len(%d) is invalid.", __func__, frame_len);
|
||||
ASSIST_PCM_T *pcm_buf = (ASSIST_PCM_T *)buf;
|
||||
ASSIST_PCM_T *mic1 = (ASSIST_PCM_T *)af_stream_mic1;
|
||||
ASSIST_PCM_T *mic2 = (ASSIST_PCM_T *)af_stream_mic2;
|
||||
ASSIST_PCM_T *mic3 = (ASSIST_PCM_T *)af_stream_mic3;
|
||||
|
||||
ASSIST_PCM_T *mic1 = (ASSIST_PCM_T *)af_stream_mic1;
|
||||
ASSIST_PCM_T *mic2 = (ASSIST_PCM_T *)af_stream_mic2;
|
||||
ASSIST_PCM_T *mic3 = (ASSIST_PCM_T *)af_stream_mic3;
|
||||
|
||||
for (int32_t i=0; i<frame_len; i++) {
|
||||
mic1[i] = pcm_buf[MIC_NUM*i + 0];
|
||||
mic2[i] = pcm_buf[MIC_NUM*i + 1];
|
||||
mic3[i] = pcm_buf[MIC_NUM*i + 2];
|
||||
}
|
||||
// audio_dump_clear_up();
|
||||
// audio_dump_add_channel_data(0,mic1,160);
|
||||
// audio_dump_add_channel_data(1,mic2,160);
|
||||
// audio_dump_add_channel_data(2,mic3,160);
|
||||
// audio_dump_run();
|
||||
// TRACE(2,"in callback");
|
||||
for (int32_t i = 0; i < frame_len; i++) {
|
||||
mic1[i] = pcm_buf[MIC_NUM * i + 0];
|
||||
mic2[i] = pcm_buf[MIC_NUM * i + 1];
|
||||
mic3[i] = pcm_buf[MIC_NUM * i + 2];
|
||||
}
|
||||
// audio_dump_clear_up();
|
||||
// audio_dump_add_channel_data(0,mic1,160);
|
||||
// audio_dump_add_channel_data(1,mic2,160);
|
||||
// audio_dump_add_channel_data(2,mic3,160);
|
||||
// audio_dump_run();
|
||||
// TRACE(2,"in callback");
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
LeakageDetection_process(pilot_st,AF_ANC_OFF,mic3,ref_buf_data,frame_len);
|
||||
LeakageDetection_process(pilot_st, AF_ANC_OFF, mic3, ref_buf_data, frame_len);
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
ANCAssistMulti_process(anc_assist_multi_st,mic1,mic2,mic3,frame_len);
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_PNC_ENABLED) || \
|
||||
defined(ANC_ASSIST_DEHOWLING_ENABLED) || defined(ANC_ASSIST_WNR_ENABLED)
|
||||
ANCAssistMulti_process(anc_assist_multi_st, mic1, mic2, mic3, frame_len);
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
static int last_classify_res = -1;
|
||||
classify_process(NoiseClassify_st, mic1, last_classify_res);
|
||||
static int last_classify_res = -1;
|
||||
classify_process(NoiseClassify_st, mic1, last_classify_res);
|
||||
#endif
|
||||
|
||||
if(g_anc_assist_mode == ANC_ASSIST_PHONE_16K){
|
||||
//down sample
|
||||
}
|
||||
if (g_anc_assist_mode == ANC_ASSIST_PHONE_16K) {
|
||||
// down sample
|
||||
}
|
||||
|
||||
//process fft
|
||||
|
||||
// wnr
|
||||
|
||||
|
||||
// pnc
|
||||
|
||||
|
||||
// hess
|
||||
|
||||
|
||||
|
||||
// pilot adpt
|
||||
// process fft
|
||||
|
||||
// wnr
|
||||
|
||||
// pnc
|
||||
|
||||
// hess
|
||||
|
||||
// pilot adpt
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static uint32_t anc_assist_callback(uint8_t *buf, uint32_t len){
|
||||
static uint32_t anc_assist_callback(uint8_t *buf, uint32_t len) {
|
||||
#ifdef TEST_MIPS
|
||||
start_ticks = hal_fast_sys_timer_get();
|
||||
start_ticks = hal_fast_sys_timer_get();
|
||||
#endif
|
||||
anc_assist_process(buf,len);
|
||||
anc_assist_process(buf, len);
|
||||
|
||||
#ifdef TEST_MIPS
|
||||
end_ticks = hal_fast_sys_timer_get();
|
||||
used_mips = (end_ticks - start_ticks) * 1000 / (start_ticks - pre_ticks);
|
||||
TRACE(2,"[%s] Usage: %d in a thousand (MIPS).", __func__, used_mips);
|
||||
//wnr_ticks = start_ticks;
|
||||
//TRACE(2,"[%s] WNR frame takes %d ms.", __func__, FAST_TICKS_TO_MS((start_ticks - pre_ticks)*100));
|
||||
pre_ticks = start_ticks;
|
||||
end_ticks = hal_fast_sys_timer_get();
|
||||
used_mips = (end_ticks - start_ticks) * 1000 / (start_ticks - pre_ticks);
|
||||
TRACE(2, "[%s] Usage: %d in a thousand (MIPS).", __func__, used_mips);
|
||||
// wnr_ticks = start_ticks;
|
||||
// TRACE(2,"[%s] WNR frame takes %d ms.", __func__,
|
||||
// FAST_TICKS_TO_MS((start_ticks - pre_ticks)*100));
|
||||
pre_ticks = start_ticks;
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
static uint32_t anc_assist_playback_callback(uint8_t *buf, uint32_t len){
|
||||
get_pilot_data(buf,len);
|
||||
// TRACE(2,"playing data %d",len);
|
||||
return 0;
|
||||
|
||||
static uint32_t anc_assist_playback_callback(uint8_t *buf, uint32_t len) {
|
||||
get_pilot_data(buf, len);
|
||||
// TRACE(2,"playing data %d",len);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _open_mic_anc_assist(void) {
|
||||
|
||||
static void _open_mic_anc_assist(void)
|
||||
{
|
||||
|
||||
int anc_assist_mic_num = 0;
|
||||
int anc_assist_mic_num = 0;
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FB_MIC;
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FB_MIC;
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC;
|
||||
#if defined(ANC_ASSIST_HESS_ENABLED) || \
|
||||
defined(ANC_ASSIST_NOISE_ADAPTIVE_ENABLED)
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC;
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_PNC_ENABLED)
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
||||
anc_assist_mic_num =
|
||||
anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_DEHOWLING_ENABLED)
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
||||
anc_assist_mic_num =
|
||||
anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FB_MIC;
|
||||
#endif
|
||||
|
||||
#if defined(ANC_ASSIST_WNR_ENABLED)
|
||||
anc_assist_mic_num = anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FF2_MIC;
|
||||
anc_assist_mic_num =
|
||||
anc_assist_mic_num | ANC_ASSIST_FF1_MIC | ANC_ASSIST_FF2_MIC;
|
||||
#endif
|
||||
|
||||
switch(anc_assist_mic_num){
|
||||
case(0):
|
||||
{
|
||||
TRACE(2,"[%s] no mic is used",__func__);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case(1):
|
||||
{
|
||||
TRACE(2,"[%s] use fb mic only",__func__);
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
|
||||
}
|
||||
break;
|
||||
case(4):
|
||||
{
|
||||
TRACE(2,"[%s] use ff mic only",__func__);
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
||||
|
||||
}
|
||||
break;
|
||||
case(5):
|
||||
{
|
||||
TRACE(2,"[%s] use ff mic and fb mic",__func__);
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
||||
|
||||
}
|
||||
break;
|
||||
case(6):
|
||||
{
|
||||
TRACE(2,"[%s] use ff1 mic and ff2 mic",__func__);
|
||||
MIC_NUM = 2;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
|
||||
}
|
||||
break;
|
||||
case(7):
|
||||
{
|
||||
TRACE(2,"[%s] use ff1 mic and ff2 mic and fb mic",__func__);
|
||||
MIC_NUM = 2;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
TRACE(2,"[%s] invalid mic order is used",__func__);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch (anc_assist_mic_num) {
|
||||
case (0): {
|
||||
TRACE(2, "[%s] no mic is used", __func__);
|
||||
return;
|
||||
} break;
|
||||
case (1): {
|
||||
TRACE(2, "[%s] use fb mic only", __func__);
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
TRACE(1,"[%s] ...", __func__);
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)MIC_NUM;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)_SAMPLE_RATE;
|
||||
stream_cfg.bits = (enum AUD_BITS_T)_SAMPLE_BITS;
|
||||
stream_cfg.vol = 12;
|
||||
stream_cfg.chan_sep_buf = false;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = (enum AUD_IO_PATH_T)MIC_MAP;
|
||||
stream_cfg.handler = anc_assist_callback;
|
||||
stream_cfg.data_size = _FRAME_LEN * SAMPLE_BYTES * 2 * MIC_NUM;
|
||||
stream_cfg.data_ptr = af_stream_buff;
|
||||
ASSERT(stream_cfg.channel_num == MIC_NUM, "[%s] channel number(%d) is invalid.", __func__, stream_cfg.channel_num);
|
||||
TRACE(2,"[%s] sample_rate:%d, data_size:%d", __func__, stream_cfg.sample_rate, stream_cfg.data_size);
|
||||
TRACE(2,"[%s] af_stream_buff = %p", __func__, af_stream_buff);
|
||||
} break;
|
||||
case (4): {
|
||||
TRACE(2, "[%s] use ff mic only", __func__);
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
||||
|
||||
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
} break;
|
||||
case (5): {
|
||||
TRACE(2, "[%s] use ff mic and fb mic", __func__);
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_ANC_WNR;
|
||||
|
||||
} break;
|
||||
case (6): {
|
||||
TRACE(2, "[%s] use ff1 mic and ff2 mic", __func__);
|
||||
MIC_NUM = 2;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
|
||||
} break;
|
||||
case (7): {
|
||||
TRACE(2, "[%s] use ff1 mic and ff2 mic and fb mic", __func__);
|
||||
MIC_NUM = 2;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
|
||||
} break;
|
||||
|
||||
default: {
|
||||
TRACE(2, "[%s] invalid mic order is used", __func__);
|
||||
} break;
|
||||
}
|
||||
|
||||
MIC_NUM = 3;
|
||||
MIC_MAP = AUD_INPUT_PATH_AF_ANC;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
TRACE(1, "[%s] ...", __func__);
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)MIC_NUM;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)_SAMPLE_RATE;
|
||||
stream_cfg.bits = (enum AUD_BITS_T)_SAMPLE_BITS;
|
||||
stream_cfg.vol = 12;
|
||||
stream_cfg.chan_sep_buf = false;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = (enum AUD_IO_PATH_T)MIC_MAP;
|
||||
stream_cfg.handler = anc_assist_callback;
|
||||
stream_cfg.data_size = _FRAME_LEN * SAMPLE_BYTES * 2 * MIC_NUM;
|
||||
stream_cfg.data_ptr = af_stream_buff;
|
||||
ASSERT(stream_cfg.channel_num == MIC_NUM,
|
||||
"[%s] channel number(%d) is invalid.", __func__,
|
||||
stream_cfg.channel_num);
|
||||
TRACE(2, "[%s] sample_rate:%d, data_size:%d", __func__,
|
||||
stream_cfg.sample_rate, stream_cfg.data_size);
|
||||
TRACE(2, "[%s] af_stream_buff = %p", __func__, af_stream_buff);
|
||||
|
||||
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
|
||||
#if defined(ANC_ASSIST_PILOT_ENABLED)
|
||||
// struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
TRACE(1,"[%s] set play ...", __func__);
|
||||
// struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
TRACE(1, "[%s] set play ...", __func__);
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
|
||||
stream_cfg.bits = (enum AUD_BITS_T)_SAMPLE_BITS;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)_PLAY_SAMPLE_RATE;
|
||||
|
||||
stream_cfg.bits = (enum AUD_BITS_T)_SAMPLE_BITS;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)_PLAY_SAMPLE_RATE;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = 15;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = 15;
|
||||
stream_cfg.handler = anc_assist_playback_callback;
|
||||
stream_cfg.data_ptr = af_play_stream_buff;
|
||||
stream_cfg.data_size = sizeof(af_play_stream_buff);
|
||||
|
||||
stream_cfg.handler = anc_assist_playback_callback;
|
||||
stream_cfg.data_ptr = af_play_stream_buff;
|
||||
stream_cfg.data_size = sizeof(af_play_stream_buff);
|
||||
|
||||
|
||||
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
af_stream_open(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(ANC_ADPT_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void _close_mic_anc_assist() {
|
||||
TRACE(1, "[%s] ...", __func__);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void _close_mic_anc_assist(){
|
||||
TRACE(1,"[%s] ...", __func__);
|
||||
|
||||
af_stream_stop(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
if(g_anc_assist_mode == ANC_ASSIST_STANDALONE || g_anc_assist_mode == ANC_ASSIST_MUSIC ){
|
||||
// close capture
|
||||
}
|
||||
// destroy
|
||||
af_stream_stop(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(ANC_ADPT_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
if (g_anc_assist_mode == ANC_ASSIST_STANDALONE ||
|
||||
g_anc_assist_mode == ANC_ASSIST_MUSIC) {
|
||||
// close capture
|
||||
}
|
||||
// destroy
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -13,8 +13,8 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "math.h"
|
||||
#include "peak_detector.h"
|
||||
#include "math.h"
|
||||
|
||||
// #define PKD_FACTOR_UP (0.6)
|
||||
// #define PKD_FACTOR_DOWN (2.0)
|
||||
|
@ -27,93 +27,93 @@ static float pkd_factor1 = 0.0f;
|
|||
static float pkd_factor2 = 0.0f;
|
||||
static float pkd_reduce_rate = 1.0f;
|
||||
|
||||
#define FABS(x) ( (x) >= 0.f ? (x) : -(x) )
|
||||
#define Max(a,b) ((a)>(b) ? (a):(b))
|
||||
#define FABS(x) ((x) >= 0.f ? (x) : -(x))
|
||||
#define Max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
// Depend on codec_dac_vol
|
||||
// const float pkd_vol_multiple[18] = {0.089125, 0.0, 0.005623, 0.007943, 0.011220, 0.015849, 0.022387, 0.031623, 0.044668, 0.063096, 0.089125, 0.125893, 0.177828, 0.251189, 0.354813, 0.501187, 0.707946, 1.000000};
|
||||
// const float pkd_vol_multiple[18] = {0.089125, 0.0, 0.005623, 0.007943,
|
||||
// 0.011220, 0.015849, 0.022387, 0.031623, 0.044668, 0.063096, 0.089125,
|
||||
// 0.125893, 0.177828, 0.251189, 0.354813, 0.501187, 0.707946, 1.000000};
|
||||
|
||||
// static uint32_t test_num = 0;
|
||||
|
||||
// int app_bt_stream_local_volume_get(void);
|
||||
|
||||
// y = 20log(x)
|
||||
static inline float convert_multiple_to_db(float multiple)
|
||||
{
|
||||
return 20*(float)log10(multiple);
|
||||
static inline float convert_multiple_to_db(float multiple) {
|
||||
return 20 * (float)log10(multiple);
|
||||
}
|
||||
|
||||
// x = 10^(y/20)
|
||||
static inline float convert_db_to_multiple(float db)
|
||||
{
|
||||
return (float)pow(10, db/20);
|
||||
static inline float convert_db_to_multiple(float db) {
|
||||
return (float)pow(10, db / 20);
|
||||
}
|
||||
|
||||
void peak_detector_init(void)
|
||||
{
|
||||
pkd_alphaR = 0.0f;
|
||||
pkd_alphaA = 0.0f;
|
||||
pkd_factor1 = 0.0f;
|
||||
pkd_factor2 = 0.0f;
|
||||
pkd_reduce_rate = 1.0f;
|
||||
// TRACE(3,"[%s] pkd_alphaR = %f, pkd_alphaA = %f", __func__, (double)pkd_alphaR, (double)pkd_alphaA);
|
||||
void peak_detector_init(void) {
|
||||
pkd_alphaR = 0.0f;
|
||||
pkd_alphaA = 0.0f;
|
||||
pkd_factor1 = 0.0f;
|
||||
pkd_factor2 = 0.0f;
|
||||
pkd_reduce_rate = 1.0f;
|
||||
// TRACE(3,"[%s] pkd_alphaR = %f, pkd_alphaA = %f", __func__,
|
||||
// (double)pkd_alphaR, (double)pkd_alphaA);
|
||||
}
|
||||
|
||||
void peak_detector_setup(PEAK_DETECTOR_CFG_T *cfg)
|
||||
{
|
||||
pkd_samp_bits = cfg->bits;
|
||||
pkd_alphaR = (float)exp(-1/(cfg->factor_down * cfg->fs));
|
||||
pkd_alphaA = (float)exp(-1/(cfg->factor_up * cfg->fs));
|
||||
pkd_reduce_rate = convert_db_to_multiple(cfg->reduce_dB);
|
||||
void peak_detector_setup(PEAK_DETECTOR_CFG_T *cfg) {
|
||||
pkd_samp_bits = cfg->bits;
|
||||
pkd_alphaR = (float)exp(-1 / (cfg->factor_down * cfg->fs));
|
||||
pkd_alphaA = (float)exp(-1 / (cfg->factor_up * cfg->fs));
|
||||
pkd_reduce_rate = convert_db_to_multiple(cfg->reduce_dB);
|
||||
}
|
||||
|
||||
static void peak_detector_run_16bits(int16_t *buf, uint32_t len, float vol_multiple)
|
||||
{
|
||||
float normal_rate = 1.0;
|
||||
float tgt_rate = 1.0;
|
||||
static void peak_detector_run_16bits(int16_t *buf, uint32_t len,
|
||||
float vol_multiple) {
|
||||
float normal_rate = 1.0;
|
||||
float tgt_rate = 1.0;
|
||||
|
||||
for(uint32_t i = 0; i < len; i++)
|
||||
{
|
||||
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
||||
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
||||
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
||||
|
||||
normal_rate = pkd_factor2/32768;
|
||||
normal_rate = pkd_factor2 / 32768;
|
||||
|
||||
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
||||
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
||||
|
||||
if(tgt_rate > 1.0)
|
||||
{
|
||||
tgt_rate = 1.0;
|
||||
}
|
||||
|
||||
// rate += (tgt_rate - rate) / 10000.0;
|
||||
|
||||
// if(pkd_factor2>)
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// normal_rate *= 1.0 - pkd_factor2/32768;
|
||||
|
||||
buf[i] = (int16_t)(buf[i] * tgt_rate);
|
||||
// buf[i] = 0;
|
||||
//
|
||||
// TRACE(2,"%d, %d", buf[i], pkd_factor2);
|
||||
if (tgt_rate > 1.0) {
|
||||
tgt_rate = 1.0;
|
||||
}
|
||||
|
||||
// if(test_num == 500)
|
||||
// rate += (tgt_rate - rate) / 10000.0;
|
||||
|
||||
// if(pkd_factor2>)
|
||||
// {
|
||||
// test_num = 0;
|
||||
// TRACE(0,"START>>>");
|
||||
// TRACE(2,"vol_level = %d, pkd_vol_multiple = %f", vol_level, pkd_vol_multiple[vol_level]);
|
||||
// TRACE(3,"buf = %d, pkd_alphaR = %f, pkd_alphaA = %f", buf[len-1], pkd_alphaR, pkd_alphaA);
|
||||
// TRACE(4,"pkd_factor1 = %f, pkd_factor2 = %f, normal_rate = %f, tgt_rate = %f", pkd_factor1, pkd_factor2, normal_rate, tgt_rate);
|
||||
// TRACE(0,"END<<<");
|
||||
// // TRACE(7,"[%s] buf = %d, pkd_alphaR = %f, pkd_alphaA = %f, pkd_factor1 = %f, pkd_factor2 = %f, normal_rate = %f", __func__, buf[len-1], pkd_alphaR, pkd_alphaA, pkd_factor1, pkd_factor2, (1.0 - pkd_factor2/32768));
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// normal_rate *= 1.0 - pkd_factor2/32768;
|
||||
|
||||
buf[i] = (int16_t)(buf[i] * tgt_rate);
|
||||
// buf[i] = 0;
|
||||
//
|
||||
// TRACE(2,"%d, %d", buf[i], pkd_factor2);
|
||||
}
|
||||
|
||||
// if(test_num == 500)
|
||||
// {
|
||||
// test_num = 0;
|
||||
// TRACE(0,"START>>>");
|
||||
// TRACE(2,"vol_level = %d, pkd_vol_multiple = %f", vol_level,
|
||||
// pkd_vol_multiple[vol_level]); TRACE(3,"buf = %d, pkd_alphaR = %f,
|
||||
// pkd_alphaA = %f", buf[len-1], pkd_alphaR, pkd_alphaA);
|
||||
// TRACE(4,"pkd_factor1 = %f, pkd_factor2 = %f, normal_rate = %f, tgt_rate =
|
||||
// %f", pkd_factor1, pkd_factor2, normal_rate, tgt_rate); TRACE(0,"END<<<");
|
||||
// // TRACE(7,"[%s] buf = %d, pkd_alphaR = %f, pkd_alphaA = %f, pkd_factor1 =
|
||||
// %f, pkd_factor2 = %f, normal_rate = %f", __func__, buf[len-1], pkd_alphaR,
|
||||
// pkd_alphaA, pkd_factor1, pkd_factor2, (1.0 - pkd_factor2/32768));
|
||||
// }
|
||||
|
||||
#if 0
|
||||
short sample;
|
||||
|
@ -139,58 +139,54 @@ static void peak_detector_run_16bits(int16_t *buf, uint32_t len, float vol_multi
|
|||
#endif
|
||||
}
|
||||
|
||||
static void peak_detector_run_24bits(int32_t *buf, uint32_t len, float vol_multiple)
|
||||
{
|
||||
float normal_rate = 1.0;
|
||||
float tgt_rate = 1.0;
|
||||
static void peak_detector_run_24bits(int32_t *buf, uint32_t len,
|
||||
float vol_multiple) {
|
||||
float normal_rate = 1.0;
|
||||
float tgt_rate = 1.0;
|
||||
|
||||
for(uint32_t i = 0; i < len; i++)
|
||||
{
|
||||
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
||||
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
pkd_factor1 = Max(buf[i], pkd_alphaR * pkd_factor1);
|
||||
pkd_factor2 = pkd_alphaA * pkd_factor2 + (1 - pkd_alphaA) * pkd_factor1;
|
||||
|
||||
normal_rate = pkd_factor2/32768;
|
||||
normal_rate = pkd_factor2 / 32768;
|
||||
|
||||
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
||||
tgt_rate = pkd_reduce_rate / normal_rate / vol_multiple;
|
||||
|
||||
if(tgt_rate > 1.0)
|
||||
{
|
||||
tgt_rate = 1.0;
|
||||
}
|
||||
|
||||
// rate += (tgt_rate - rate) / 10000.0;
|
||||
|
||||
// if(pkd_factor2>)
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// normal_rate *= 1.0 - pkd_factor2/32768;
|
||||
|
||||
buf[i] = (int32_t)(buf[i] * tgt_rate);
|
||||
// buf[i] = 0;
|
||||
//
|
||||
// TRACE(2,"%d, %d", buf[i], pkd_factor2);
|
||||
}
|
||||
}
|
||||
|
||||
void peak_detector_run(uint8_t *buf, uint32_t len, float vol_multiple)
|
||||
{
|
||||
// int vol_level = 0;
|
||||
|
||||
if (pkd_samp_bits <= AUD_BITS_16) {
|
||||
len = len / sizeof(int16_t);
|
||||
peak_detector_run_16bits((int16_t *)buf, len, vol_multiple);
|
||||
} else {
|
||||
len = len / sizeof(int32_t);
|
||||
peak_detector_run_24bits((int32_t *)buf, len, vol_multiple);
|
||||
if (tgt_rate > 1.0) {
|
||||
tgt_rate = 1.0;
|
||||
}
|
||||
|
||||
// test_num++;
|
||||
// rate += (tgt_rate - rate) / 10000.0;
|
||||
|
||||
// vol_level = app_bt_stream_local_volume_get();
|
||||
// if(pkd_factor2>)
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// normal_rate = 0.25;
|
||||
// }
|
||||
// normal_rate *= 1.0 - pkd_factor2/32768;
|
||||
|
||||
buf[i] = (int32_t)(buf[i] * tgt_rate);
|
||||
// buf[i] = 0;
|
||||
//
|
||||
// TRACE(2,"%d, %d", buf[i], pkd_factor2);
|
||||
}
|
||||
}
|
||||
|
||||
void peak_detector_run(uint8_t *buf, uint32_t len, float vol_multiple) {
|
||||
// int vol_level = 0;
|
||||
|
||||
if (pkd_samp_bits <= AUD_BITS_16) {
|
||||
len = len / sizeof(int16_t);
|
||||
peak_detector_run_16bits((int16_t *)buf, len, vol_multiple);
|
||||
} else {
|
||||
len = len / sizeof(int32_t);
|
||||
peak_detector_run_24bits((int32_t *)buf, len, vol_multiple);
|
||||
}
|
||||
|
||||
// test_num++;
|
||||
|
||||
// vol_level = app_bt_stream_local_volume_get();
|
||||
}
|
||||
|
|
|
@ -13,20 +13,20 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_thread.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_thread.h"
|
||||
|
||||
#include "hal_timer.h"
|
||||
#include "app_audtest_pattern.h"
|
||||
#include "hal_timer.h"
|
||||
|
||||
#include "hal_aud.h"
|
||||
#include "audioflinger.h"
|
||||
#include "app_utils.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "audioflinger.h"
|
||||
#include "eq_export.h"
|
||||
#include "hal_aud.h"
|
||||
#include "stdbool.h"
|
||||
#include <string.h>
|
||||
#include "eq_export.h"
|
||||
#include "app_utils.h"
|
||||
|
||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||
#include "anc_usb_app.h"
|
||||
|
@ -35,28 +35,28 @@
|
|||
//#include "dualadc_audio_app.h"
|
||||
#endif
|
||||
|
||||
#define USB_AUDIO_PLAYBACK_BUFF_SIZE (FRAME_SIZE_PLAYBACK * 4)
|
||||
#define USB_AUDIO_CAPTURE_BUFF_SIZE (FRAME_SIZE_CAPTURE * 4)
|
||||
#define USB_AUDIO_PLAYBACK_BUFF_SIZE (FRAME_SIZE_PLAYBACK * 4)
|
||||
#define USB_AUDIO_CAPTURE_BUFF_SIZE (FRAME_SIZE_CAPTURE * 4)
|
||||
|
||||
#define USB_AUDIO_RECV_BUFF_SIZE (FRAME_SIZE_RECV * 8)
|
||||
#define USB_AUDIO_SEND_BUFF_SIZE (FRAME_SIZE_SEND * 8)
|
||||
#define USB_AUDIO_RECV_BUFF_SIZE (FRAME_SIZE_RECV * 8)
|
||||
#define USB_AUDIO_SEND_BUFF_SIZE (FRAME_SIZE_SEND * 8)
|
||||
|
||||
#define APP_TEST_PLAYBACK_BUFF_SIZE (128 * 20)
|
||||
#define APP_TEST_CAPTURE_BUFF_SIZE (128 * 20)
|
||||
#define APP_TEST_PLAYBACK_BUFF_SIZE (128 * 20)
|
||||
#define APP_TEST_CAPTURE_BUFF_SIZE (128 * 20)
|
||||
|
||||
#if (USB_AUDIO_PLAYBACK_BUFF_SIZE > APP_TEST_PLAYBACK_BUFF_SIZE)
|
||||
#define REAL_PLAYBACK_BUFF_SIZE USB_AUDIO_PLAYBACK_BUFF_SIZE
|
||||
#define REAL_PLAYBACK_BUFF_SIZE USB_AUDIO_PLAYBACK_BUFF_SIZE
|
||||
#else
|
||||
#define REAL_PLAYBACK_BUFF_SIZE APP_TEST_PLAYBACK_BUFF_SIZE
|
||||
#define REAL_PLAYBACK_BUFF_SIZE APP_TEST_PLAYBACK_BUFF_SIZE
|
||||
#endif
|
||||
|
||||
#if (USB_AUDIO_CAPTURE_BUFF_SIZE > APP_TEST_CAPTURE_BUFF_SIZE)
|
||||
#define REAL_CAPTURE_BUFF_SIZE USB_AUDIO_CAPTURE_BUFF_SIZE
|
||||
#define REAL_CAPTURE_BUFF_SIZE USB_AUDIO_CAPTURE_BUFF_SIZE
|
||||
#else
|
||||
#define REAL_CAPTURE_BUFF_SIZE APP_TEST_CAPTURE_BUFF_SIZE
|
||||
#define REAL_CAPTURE_BUFF_SIZE APP_TEST_CAPTURE_BUFF_SIZE
|
||||
#endif
|
||||
|
||||
#define ALIGNED4 ALIGNED(4)
|
||||
#define ALIGNED4 ALIGNED(4)
|
||||
|
||||
static uint8_t ALIGNED4 app_test_playback_buff[REAL_PLAYBACK_BUFF_SIZE];
|
||||
static uint8_t ALIGNED4 app_test_capture_buff[REAL_CAPTURE_BUFF_SIZE];
|
||||
|
@ -66,242 +66,225 @@ static uint8_t ALIGNED4 app_test_recv_buff[USB_AUDIO_RECV_BUFF_SIZE];
|
|||
static uint8_t ALIGNED4 app_test_send_buff[USB_AUDIO_SEND_BUFF_SIZE];
|
||||
#endif
|
||||
|
||||
uint32_t pcm_1ksin_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
static uint32_t nextPbufIdx = 0;
|
||||
uint32_t remain_size = len;
|
||||
uint32_t curr_size = 0;
|
||||
static uint32_t pcm_preIrqTime = 0;;
|
||||
uint32_t stime = 0;
|
||||
uint32_t pcm_1ksin_more_data(uint8_t *buf, uint32_t len) {
|
||||
static uint32_t nextPbufIdx = 0;
|
||||
uint32_t remain_size = len;
|
||||
uint32_t curr_size = 0;
|
||||
static uint32_t pcm_preIrqTime = 0;
|
||||
;
|
||||
uint32_t stime = 0;
|
||||
|
||||
stime = hal_sys_timer_get();
|
||||
TRACE(3, "pcm_1ksin_more_data irqDur:%d readbuff:0x%08x %d\n ",
|
||||
TICKS_TO_MS(stime - pcm_preIrqTime), buf, len);
|
||||
pcm_preIrqTime = stime;
|
||||
|
||||
stime = hal_sys_timer_get();
|
||||
TRACE(3,"pcm_1ksin_more_data irqDur:%d readbuff:0x%08x %d\n ", TICKS_TO_MS(stime - pcm_preIrqTime), buf, len);
|
||||
pcm_preIrqTime = stime;
|
||||
|
||||
// TRACE(2,"[pcm_1ksin_more_data] len=%d nextBuf:%d\n", len, nextPbufIdx);
|
||||
if (remain_size > sizeof(sinwave))
|
||||
{
|
||||
do{
|
||||
if (nextPbufIdx)
|
||||
{
|
||||
curr_size = sizeof(sinwave)-nextPbufIdx;
|
||||
memcpy(buf,&sinwave[nextPbufIdx/2], curr_size);
|
||||
remain_size -= curr_size;
|
||||
nextPbufIdx = 0;
|
||||
}
|
||||
else if (remain_size>sizeof(sinwave))
|
||||
{
|
||||
memcpy(buf+curr_size,sinwave,sizeof(sinwave));
|
||||
curr_size += sizeof(sinwave);
|
||||
remain_size -= sizeof(sinwave);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(buf+curr_size,sinwave,remain_size);
|
||||
nextPbufIdx = remain_size;
|
||||
remain_size = 0;
|
||||
}
|
||||
}while(remain_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((sizeof(sinwave) - nextPbufIdx) >= len)
|
||||
{
|
||||
memcpy(buf, &sinwave[nextPbufIdx/2],len);
|
||||
nextPbufIdx += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
curr_size = sizeof(sinwave)-nextPbufIdx;
|
||||
memcpy(buf, &sinwave[nextPbufIdx/2],curr_size);
|
||||
nextPbufIdx = len - curr_size;
|
||||
memcpy(buf+curr_size,sinwave, nextPbufIdx);
|
||||
}
|
||||
// TRACE(2,"[pcm_1ksin_more_data] len=%d nextBuf:%d\n", len, nextPbufIdx);
|
||||
if (remain_size > sizeof(sinwave)) {
|
||||
do {
|
||||
if (nextPbufIdx) {
|
||||
curr_size = sizeof(sinwave) - nextPbufIdx;
|
||||
memcpy(buf, &sinwave[nextPbufIdx / 2], curr_size);
|
||||
remain_size -= curr_size;
|
||||
nextPbufIdx = 0;
|
||||
} else if (remain_size > sizeof(sinwave)) {
|
||||
memcpy(buf + curr_size, sinwave, sizeof(sinwave));
|
||||
curr_size += sizeof(sinwave);
|
||||
remain_size -= sizeof(sinwave);
|
||||
} else {
|
||||
memcpy(buf + curr_size, sinwave, remain_size);
|
||||
nextPbufIdx = remain_size;
|
||||
remain_size = 0;
|
||||
}
|
||||
} while (remain_size);
|
||||
} else {
|
||||
if ((sizeof(sinwave) - nextPbufIdx) >= len) {
|
||||
memcpy(buf, &sinwave[nextPbufIdx / 2], len);
|
||||
nextPbufIdx += len;
|
||||
} else {
|
||||
curr_size = sizeof(sinwave) - nextPbufIdx;
|
||||
memcpy(buf, &sinwave[nextPbufIdx / 2], curr_size);
|
||||
nextPbufIdx = len - curr_size;
|
||||
memcpy(buf + curr_size, sinwave, nextPbufIdx);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t pcm_mute_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
memset(buf, 0 , len);
|
||||
return 0;
|
||||
uint32_t pcm_mute_more_data(uint8_t *buf, uint32_t len) {
|
||||
memset(buf, 0, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void da_output_sin1k(bool on)
|
||||
{
|
||||
static bool isRun = false;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
void da_output_sin1k(bool on) {
|
||||
static bool isRun = false;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
|
||||
if (isRun==on)
|
||||
return;
|
||||
else
|
||||
isRun=on;
|
||||
TRACE(2,"%s %d\n", __func__, on);
|
||||
if (isRun == on)
|
||||
return;
|
||||
else
|
||||
isRun = on;
|
||||
TRACE(2, "%s %d\n", __func__, on);
|
||||
|
||||
if (on){
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_44100;
|
||||
if (on) {
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_44100;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = 16;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = 16;
|
||||
|
||||
stream_cfg.handler = pcm_1ksin_more_data;
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}else{
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
stream_cfg.handler = pcm_1ksin_more_data;
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
} else {
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
}
|
||||
|
||||
void da_tester(uint8_t on)
|
||||
{
|
||||
da_output_sin1k(on);
|
||||
}
|
||||
void da_tester(uint8_t on) { da_output_sin1k(on); }
|
||||
|
||||
extern int voicecvsd_audio_init(void);
|
||||
extern uint32_t voicecvsd_audio_more_data(uint8_t *buf, uint32_t len);
|
||||
extern int get_voicecvsd_buffer_size(void);
|
||||
extern int store_voice_pcm2cvsd(unsigned char *buf, unsigned int len);
|
||||
|
||||
static uint32_t pcm_data_capture(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
static uint32_t pcm_data_capture(uint8_t *buf, uint32_t len) {
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
|
||||
stime = hal_sys_timer_get();
|
||||
// audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
||||
audio_buffer_set(buf, len);
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(4,"%s irqDur:%d fsSpend:%d, Len:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
stime = hal_sys_timer_get();
|
||||
// audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
||||
audio_buffer_set(buf, len);
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(4, "%s irqDur:%d fsSpend:%d, Len:%d", __func__,
|
||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t pcm_data_playback(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
stime = hal_sys_timer_get();
|
||||
// audio_buffer_get_mono2stereo_16bits(buf, len);
|
||||
audio_buffer_get(buf, len);
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(4,"%s irqDur:%d fsSpend:%d, Len:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
static uint32_t pcm_data_playback(uint8_t *buf, uint32_t len) {
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
stime = hal_sys_timer_get();
|
||||
// audio_buffer_get_mono2stereo_16bits(buf, len);
|
||||
audio_buffer_get(buf, len);
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(4, "%s irqDur:%d fsSpend:%d, Len:%d", __func__,
|
||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t pcm_cvsd_data_capture(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
uint32_t pcm_cvsd_data_capture(uint8_t *buf, uint32_t len) {
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
|
||||
//TRACE(1,"%s enter", __func__);
|
||||
stime = hal_sys_timer_get();
|
||||
len >>= 1;
|
||||
audio_stereo2mono_16bits(0, (uint16_t *)buf, (uint16_t *)buf, len);
|
||||
store_voice_pcm2cvsd(buf, len);
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(4,"%s exit irqDur:%d fsSpend:%d, add:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
// TRACE(1,"%s enter", __func__);
|
||||
stime = hal_sys_timer_get();
|
||||
len >>= 1;
|
||||
audio_stereo2mono_16bits(0, (uint16_t *)buf, (uint16_t *)buf, len);
|
||||
store_voice_pcm2cvsd(buf, len);
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(4, "%s exit irqDur:%d fsSpend:%d, add:%d", __func__,
|
||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t pcm_cvsd_data_playback(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
int n;
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
uint32_t pcm_cvsd_data_playback(uint8_t *buf, uint32_t len) {
|
||||
int n;
|
||||
uint32_t stime, etime;
|
||||
static uint32_t preIrqTime = 0;
|
||||
|
||||
//TRACE(1,"%s enter", __func__);
|
||||
stime = hal_sys_timer_get();
|
||||
pcm_1ksin_more_data(buf, len);
|
||||
voicecvsd_audio_more_data(buf, len);
|
||||
n = get_voicecvsd_buffer_size();
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(5,"%s exit irqDur:%d fsSpend:%d, get:%d remain:%d", __func__, TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len, n);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
// TRACE(1,"%s enter", __func__);
|
||||
stime = hal_sys_timer_get();
|
||||
pcm_1ksin_more_data(buf, len);
|
||||
voicecvsd_audio_more_data(buf, len);
|
||||
n = get_voicecvsd_buffer_size();
|
||||
etime = hal_sys_timer_get();
|
||||
TRACE(5, "%s exit irqDur:%d fsSpend:%d, get:%d remain:%d", __func__,
|
||||
TICKS_TO_MS(stime - preIrqTime), TICKS_TO_MS(etime - stime), len, n);
|
||||
preIrqTime = stime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void adc_looptester(bool on, enum AUD_IO_PATH_T input_path, enum AUD_SAMPRATE_T sample_rate)
|
||||
{
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
void adc_looptester(bool on, enum AUD_IO_PATH_T input_path,
|
||||
enum AUD_SAMPRATE_T sample_rate) {
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
|
||||
static bool isRun = false;
|
||||
static bool isRun = false;
|
||||
|
||||
if (isRun==on)
|
||||
return;
|
||||
else
|
||||
isRun=on;
|
||||
if (isRun == on)
|
||||
return;
|
||||
else
|
||||
isRun = on;
|
||||
|
||||
if (on){
|
||||
audio_buffer_init();
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
if (on) {
|
||||
audio_buffer_init();
|
||||
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;
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = sample_rate;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = input_path;
|
||||
stream_cfg.vol = 0x03;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = input_path;
|
||||
stream_cfg.vol = 0x03;
|
||||
|
||||
stream_cfg.handler = pcm_data_capture;
|
||||
stream_cfg.handler = pcm_data_capture;
|
||||
|
||||
stream_cfg.data_ptr = app_test_capture_buff;
|
||||
stream_cfg.data_size = APP_TEST_CAPTURE_BUFF_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
stream_cfg.data_ptr = app_test_capture_buff;
|
||||
stream_cfg.data_size = APP_TEST_CAPTURE_BUFF_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
|
||||
stream_cfg.handler = pcm_data_playback;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.handler = pcm_data_playback;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||
void app_anc_usb_init(void)
|
||||
{
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_52M);
|
||||
void app_anc_usb_init(void) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_52M);
|
||||
|
||||
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_96000, AUD_SAMPRATE_192000);
|
||||
anc_usb_app_init(AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_96000,
|
||||
AUD_SAMPRATE_192000);
|
||||
|
||||
struct USB_AUDIO_BUF_CFG cfg;
|
||||
struct USB_AUDIO_BUF_CFG cfg;
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.play_buf = app_test_playback_buff;
|
||||
cfg.play_size = USB_AUDIO_PLAYBACK_BUFF_SIZE;
|
||||
cfg.cap_buf = app_test_capture_buff;
|
||||
cfg.cap_size = USB_AUDIO_CAPTURE_BUFF_SIZE;
|
||||
cfg.recv_buf = app_test_recv_buff;
|
||||
cfg.recv_size = USB_AUDIO_RECV_BUFF_SIZE;
|
||||
cfg.send_buf = app_test_send_buff;
|
||||
cfg.send_size = USB_AUDIO_SEND_BUFF_SIZE;
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.play_buf = app_test_playback_buff;
|
||||
cfg.play_size = USB_AUDIO_PLAYBACK_BUFF_SIZE;
|
||||
cfg.cap_buf = app_test_capture_buff;
|
||||
cfg.cap_size = USB_AUDIO_CAPTURE_BUFF_SIZE;
|
||||
cfg.recv_buf = app_test_recv_buff;
|
||||
cfg.recv_size = USB_AUDIO_RECV_BUFF_SIZE;
|
||||
cfg.send_buf = app_test_send_buff;
|
||||
cfg.send_size = USB_AUDIO_SEND_BUFF_SIZE;
|
||||
|
||||
usb_audio_app_init(&cfg);
|
||||
usb_audio_app_init(&cfg);
|
||||
|
||||
//dualadc_audio_app_init(app_test_playback_buff, USB_AUDIO_PLAYBACK_BUFF_SIZE,
|
||||
//app_test_capture_buff, USB_AUDIO_CAPTURE_BUFF_SIZE);
|
||||
// dualadc_audio_app_init(app_test_playback_buff,
|
||||
// USB_AUDIO_PLAYBACK_BUFF_SIZE, app_test_capture_buff,
|
||||
// USB_AUDIO_CAPTURE_BUFF_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,11 +13,10 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "audiobuffer.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "cqueue.h"
|
||||
#include "string.h"
|
||||
#include "audiobuffer.h"
|
||||
|
||||
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
static osMutexId g_audio_queue_mutex_id = NULL;
|
||||
|
@ -25,122 +24,121 @@ osMutexDef(g_audio_queue_mutex);
|
|||
#endif
|
||||
|
||||
static CQueue audio_queue;
|
||||
static unsigned char audio_queue_buf[AUDIO_BUFFER_FRAME_SIZE*AUDIO_BUFFER_FRAME_NUM];
|
||||
static unsigned char
|
||||
audio_queue_buf[AUDIO_BUFFER_FRAME_SIZE * AUDIO_BUFFER_FRAME_NUM];
|
||||
|
||||
void audio_mono2stereo_16bits(uint16_t *dst_buf, uint16_t *src_buf, uint32_t src_len)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; ++i) {
|
||||
dst_buf[i*2 + 0] = dst_buf[i*2 + 1] = src_buf[i];
|
||||
}
|
||||
void audio_mono2stereo_16bits(uint16_t *dst_buf, uint16_t *src_buf,
|
||||
uint32_t src_len) {
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; ++i) {
|
||||
dst_buf[i * 2 + 0] = dst_buf[i * 2 + 1] = src_buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
void audio_stereo2mono_16bits(uint8_t chnlsel, uint16_t *dst_buf, uint16_t *src_buf, uint32_t src_len)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; i+=2) {
|
||||
dst_buf[i/2] = src_buf[i + chnlsel];
|
||||
}
|
||||
void audio_stereo2mono_16bits(uint8_t chnlsel, uint16_t *dst_buf,
|
||||
uint16_t *src_buf, uint32_t src_len) {
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; i += 2) {
|
||||
dst_buf[i / 2] = src_buf[i + chnlsel];
|
||||
}
|
||||
}
|
||||
|
||||
void audio_buffer_init(void)
|
||||
{
|
||||
void audio_buffer_init(void) {
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
if (g_audio_queue_mutex_id == NULL)
|
||||
g_audio_queue_mutex_id = osMutexCreate((osMutex(g_audio_queue_mutex)));
|
||||
if (g_audio_queue_mutex_id == NULL)
|
||||
g_audio_queue_mutex_id = osMutexCreate((osMutex(g_audio_queue_mutex)));
|
||||
#endif
|
||||
InitCQueue(&audio_queue, sizeof(audio_queue_buf), (unsigned char *)&audio_queue_buf);
|
||||
memset(&audio_queue_buf, 0x00, sizeof(audio_queue_buf));
|
||||
InitCQueue(&audio_queue, sizeof(audio_queue_buf),
|
||||
(unsigned char *)&audio_queue_buf);
|
||||
memset(&audio_queue_buf, 0x00, sizeof(audio_queue_buf));
|
||||
}
|
||||
|
||||
int audio_buffer_length(void)
|
||||
{
|
||||
int len;
|
||||
int audio_buffer_length(void) {
|
||||
int len;
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
#endif
|
||||
len = LengthOfCQueue(&audio_queue);
|
||||
len = LengthOfCQueue(&audio_queue);
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
#endif
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
||||
int audio_buffer_set(uint8_t *buff, uint16_t len)
|
||||
{
|
||||
int status;
|
||||
int audio_buffer_set(uint8_t *buff, uint16_t len) {
|
||||
int status;
|
||||
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
#endif
|
||||
status = EnCQueue(&audio_queue, buff, len);
|
||||
status = EnCQueue(&audio_queue, buff, len);
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
#endif
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
int audio_buffer_get(uint8_t *buff, uint16_t len)
|
||||
{
|
||||
uint8_t *e1 = NULL, *e2 = NULL;
|
||||
unsigned int len1 = 0, len2 = 0;
|
||||
int status;
|
||||
int audio_buffer_get(uint8_t *buff, uint16_t len) {
|
||||
uint8_t *e1 = NULL, *e2 = NULL;
|
||||
unsigned int len1 = 0, len2 = 0;
|
||||
int status;
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
#endif
|
||||
status = PeekCQueue(&audio_queue, len, &e1, &len1, &e2, &len2);
|
||||
if (len==(len1+len2)){
|
||||
memcpy(buff,e1,len1);
|
||||
memcpy(buff+len1,e2,len2);
|
||||
DeCQueue(&audio_queue, 0, len);
|
||||
DeCQueue(&audio_queue, 0, len2);
|
||||
}else{
|
||||
memset(buff, 0x00, len);
|
||||
status = -1;
|
||||
}
|
||||
status = PeekCQueue(&audio_queue, len, &e1, &len1, &e2, &len2);
|
||||
if (len == (len1 + len2)) {
|
||||
memcpy(buff, e1, len1);
|
||||
memcpy(buff + len1, e2, len2);
|
||||
DeCQueue(&audio_queue, 0, len);
|
||||
DeCQueue(&audio_queue, 0, len2);
|
||||
} else {
|
||||
memset(buff, 0x00, len);
|
||||
status = -1;
|
||||
}
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
#endif
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
int audio_buffer_set_stereo2mono_16bits(uint8_t *buff, uint16_t len, uint8_t chnlsel)
|
||||
{
|
||||
int status;
|
||||
int audio_buffer_set_stereo2mono_16bits(uint8_t *buff, uint16_t len,
|
||||
uint8_t chnlsel) {
|
||||
int status;
|
||||
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
#endif
|
||||
audio_stereo2mono_16bits(chnlsel, (uint16_t *)buff, (uint16_t *)buff, len>>1);
|
||||
status = EnCQueue(&audio_queue, buff, len>>1);
|
||||
audio_stereo2mono_16bits(chnlsel, (uint16_t *)buff, (uint16_t *)buff,
|
||||
len >> 1);
|
||||
status = EnCQueue(&audio_queue, buff, len >> 1);
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
#endif
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
int audio_buffer_get_mono2stereo_16bits(uint8_t *buff, uint16_t len)
|
||||
{
|
||||
uint8_t *e1 = NULL, *e2 = NULL;
|
||||
unsigned int len1 = 0, len2 = 0;
|
||||
int status;
|
||||
int audio_buffer_get_mono2stereo_16bits(uint8_t *buff, uint16_t len) {
|
||||
uint8_t *e1 = NULL, *e2 = NULL;
|
||||
unsigned int len1 = 0, len2 = 0;
|
||||
int status;
|
||||
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
osMutexWait(g_audio_queue_mutex_id, osWaitForever);
|
||||
#endif
|
||||
status = PeekCQueue(&audio_queue, len>>1, &e1, &len1, &e2, &len2);
|
||||
if (len>>1== len1+len2){
|
||||
audio_mono2stereo_16bits((uint16_t *)buff, (uint16_t *)e1, len1>>1);
|
||||
audio_mono2stereo_16bits((uint16_t *)(buff+(len1<<1)), (uint16_t *)e2, len2>>1);
|
||||
DeCQueue(&audio_queue, 0, len1);
|
||||
DeCQueue(&audio_queue, 0, len2);
|
||||
status = len;
|
||||
}else{
|
||||
memset(buff, 0x00, len);
|
||||
status = -1;
|
||||
}
|
||||
status = PeekCQueue(&audio_queue, len >> 1, &e1, &len1, &e2, &len2);
|
||||
if (len >> 1 == len1 + len2) {
|
||||
audio_mono2stereo_16bits((uint16_t *)buff, (uint16_t *)e1, len1 >> 1);
|
||||
audio_mono2stereo_16bits((uint16_t *)(buff + (len1 << 1)), (uint16_t *)e2,
|
||||
len2 >> 1);
|
||||
DeCQueue(&audio_queue, 0, len1);
|
||||
DeCQueue(&audio_queue, 0, len2);
|
||||
status = len;
|
||||
} else {
|
||||
memset(buff, 0x00, len);
|
||||
status = -1;
|
||||
}
|
||||
#ifndef _AUDIO_NO_THREAD_
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
osMutexRelease(g_audio_queue_mutex_id);
|
||||
#endif
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -14,124 +14,116 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
// Standard C Included Files
|
||||
#include "a2dp_decoder_internal.h"
|
||||
#include "cmsis.h"
|
||||
#include "hal_location.h"
|
||||
#include "heap_api.h"
|
||||
#include "plat_types.h"
|
||||
#include <string.h>
|
||||
#include "heap_api.h"
|
||||
#include "hal_location.h"
|
||||
#include "a2dp_decoder_internal.h"
|
||||
|
||||
static A2DP_AUDIO_CONTEXT_T *a2dp_audio_context_p = NULL;
|
||||
static A2DP_AUDIO_DECODER_LASTFRAME_INFO_T a2dp_audio_ldac_example_info;
|
||||
static A2DP_AUDIO_OUTPUT_CONFIG_T a2dp_audio_example_output_config;
|
||||
|
||||
typedef struct {
|
||||
uint16_t sequenceNumber;
|
||||
uint32_t timestamp;
|
||||
uint8_t *buffer;
|
||||
uint32_t buffer_len;
|
||||
uint16_t sequenceNumber;
|
||||
uint32_t timestamp;
|
||||
uint8_t *buffer;
|
||||
uint32_t buffer_len;
|
||||
} a2dp_audio_example_decoder_frame_t;
|
||||
|
||||
|
||||
int a2dp_audio_example_decode_frame(uint8_t *buffer, uint32_t buffer_bytes)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_decode_frame(uint8_t *buffer, uint32_t buffer_bytes) {
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_preparse_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_preparse_packet(btif_media_header_t *header,
|
||||
uint8_t *buffer, uint32_t buffer_bytes) {
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
static void *a2dp_audio_example_frame_malloc(uint32_t packet_len) {
|
||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p = NULL;
|
||||
uint8_t *buffer = NULL;
|
||||
|
||||
static void *a2dp_audio_example_frame_malloc(uint32_t packet_len)
|
||||
{
|
||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p = NULL;
|
||||
uint8_t *buffer = NULL;
|
||||
|
||||
buffer = (uint8_t *)a2dp_audio_heap_malloc(packet_len);
|
||||
decoder_frame_p = (a2dp_audio_example_decoder_frame_t *)a2dp_audio_heap_malloc(sizeof(a2dp_audio_example_decoder_frame_t));
|
||||
decoder_frame_p->buffer = buffer;
|
||||
decoder_frame_p->buffer_len = packet_len;
|
||||
return (void *)decoder_frame_p;
|
||||
buffer = (uint8_t *)a2dp_audio_heap_malloc(packet_len);
|
||||
decoder_frame_p =
|
||||
(a2dp_audio_example_decoder_frame_t *)a2dp_audio_heap_malloc(
|
||||
sizeof(a2dp_audio_example_decoder_frame_t));
|
||||
decoder_frame_p->buffer = buffer;
|
||||
decoder_frame_p->buffer_len = packet_len;
|
||||
return (void *)decoder_frame_p;
|
||||
}
|
||||
|
||||
void a2dp_audio_example_free(void *packet)
|
||||
{
|
||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p = (a2dp_audio_example_decoder_frame_t *)packet;
|
||||
a2dp_audio_heap_free(decoder_frame_p->buffer);
|
||||
a2dp_audio_heap_free(decoder_frame_p);
|
||||
void a2dp_audio_example_free(void *packet) {
|
||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p =
|
||||
(a2dp_audio_example_decoder_frame_t *)packet;
|
||||
a2dp_audio_heap_free(decoder_frame_p->buffer);
|
||||
a2dp_audio_heap_free(decoder_frame_p);
|
||||
}
|
||||
|
||||
int a2dp_audio_example_store_packet(btif_media_header_t * header, uint8_t *buffer, uint32_t buffer_bytes)
|
||||
{
|
||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p = (a2dp_audio_example_decoder_frame_t *)a2dp_audio_example_frame_malloc(buffer_bytes);
|
||||
int a2dp_audio_example_store_packet(btif_media_header_t *header,
|
||||
uint8_t *buffer, uint32_t buffer_bytes) {
|
||||
list_t *list = a2dp_audio_context_p->audio_datapath.input_raw_packet_list;
|
||||
a2dp_audio_example_decoder_frame_t *decoder_frame_p =
|
||||
(a2dp_audio_example_decoder_frame_t *)a2dp_audio_example_frame_malloc(
|
||||
buffer_bytes);
|
||||
|
||||
decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
||||
decoder_frame_p->timestamp = header->timestamp;
|
||||
memcpy(decoder_frame_p->buffer, buffer, buffer_bytes);
|
||||
decoder_frame_p->buffer_len = buffer_bytes;
|
||||
a2dp_audio_list_append(list, decoder_frame_p);
|
||||
decoder_frame_p->sequenceNumber = header->sequenceNumber;
|
||||
decoder_frame_p->timestamp = header->timestamp;
|
||||
memcpy(decoder_frame_p->buffer, buffer, buffer_bytes);
|
||||
decoder_frame_p->buffer_len = buffer_bytes;
|
||||
a2dp_audio_list_append(list, decoder_frame_p);
|
||||
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_discards_packet(uint32_t packets)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_discards_packet(uint32_t packets) {
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_headframe_info_get(A2DP_AUDIO_HEADFRAME_INFO_T* headframe_info)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_headframe_info_get(
|
||||
A2DP_AUDIO_HEADFRAME_INFO_T *headframe_info) {
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_info_get(void *info)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_info_get(void *info) { return A2DP_DECODER_NO_ERROR; }
|
||||
|
||||
int a2dp_audio_example_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context) {
|
||||
TRACE_A2DP_DECODER_D("%s", __func__);
|
||||
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
||||
|
||||
memset(&a2dp_audio_ldac_example_info, 0,
|
||||
sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
||||
memcpy(&a2dp_audio_example_output_config, config,
|
||||
sizeof(A2DP_AUDIO_OUTPUT_CONFIG_T));
|
||||
a2dp_audio_ldac_example_info.stream_info = &a2dp_audio_example_output_config;
|
||||
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_init(A2DP_AUDIO_OUTPUT_CONFIG_T *config, void *context)
|
||||
{
|
||||
TRACE_A2DP_DECODER_D("%s", __func__);
|
||||
a2dp_audio_context_p = (A2DP_AUDIO_CONTEXT_T *)context;
|
||||
int a2dp_audio_example_deinit(void) { return A2DP_DECODER_NO_ERROR; }
|
||||
|
||||
memset(&a2dp_audio_ldac_example_info, 0, sizeof(A2DP_AUDIO_DECODER_LASTFRAME_INFO_T));
|
||||
memcpy(&a2dp_audio_example_output_config, config, sizeof(A2DP_AUDIO_OUTPUT_CONFIG_T));
|
||||
a2dp_audio_ldac_example_info.stream_info = &a2dp_audio_example_output_config;
|
||||
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_synchronize_packet(
|
||||
A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info, uint32_t mask) {
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_deinit(void)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_synchronize_packet(A2DP_AUDIO_SYNCFRAME_INFO_T *sync_info, uint32_t mask)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
int a2dp_audio_example_synchronize_dest_packet_mut(uint16_t packet_mut)
|
||||
{
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
int a2dp_audio_example_synchronize_dest_packet_mut(uint16_t packet_mut) {
|
||||
return A2DP_DECODER_NO_ERROR;
|
||||
}
|
||||
|
||||
A2DP_AUDIO_DECODER_T a2dp_audio_example_decoder_config = {
|
||||
{44100, 2, 16},
|
||||
0,
|
||||
a2dp_audio_example_init,
|
||||
a2dp_audio_example_deinit,
|
||||
a2dp_audio_example_decode_frame,
|
||||
a2dp_audio_example_preparse_packet,
|
||||
a2dp_audio_example_store_packet,
|
||||
a2dp_audio_example_discards_packet,
|
||||
a2dp_audio_example_synchronize_packet,
|
||||
a2dp_audio_example_synchronize_dest_packet_mut,
|
||||
a2dp_audio_example_headframe_info_get,
|
||||
a2dp_audio_example_info_get,
|
||||
a2dp_audio_example_free,
|
||||
} ;
|
||||
|
||||
{44100, 2, 16},
|
||||
0,
|
||||
a2dp_audio_example_init,
|
||||
a2dp_audio_example_deinit,
|
||||
a2dp_audio_example_decode_frame,
|
||||
a2dp_audio_example_preparse_packet,
|
||||
a2dp_audio_example_store_packet,
|
||||
a2dp_audio_example_discards_packet,
|
||||
a2dp_audio_example_synchronize_packet,
|
||||
a2dp_audio_example_synchronize_dest_packet_mut,
|
||||
a2dp_audio_example_headframe_info_get,
|
||||
a2dp_audio_example_info_get,
|
||||
a2dp_audio_example_free,
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -17,14 +17,18 @@
|
|||
* Usage:
|
||||
* 1. Enable SCO_CP_ACCEL ?= 1 to enable dual core in sco
|
||||
* 2. Enable SCO_TRACE_CP_ACCEL ?= 1 to see debug log.
|
||||
* 3. Change channel number if the algo(run in cp) input is more than one channel: sco_cp_init(speech_tx_frame_len, 1);
|
||||
* 4. The code between SCO_CP_ACCEL_ALGO_START(); and SCO_CP_ACCEL_ALGO_END(); will run in CP core.
|
||||
* 5. These algorithms will work in AP. Need to move this algorithms from overlay to fast ram.
|
||||
* 3. Change channel number if the algo(run in cp) input is more than one
|
||||
*channel: sco_cp_init(speech_tx_frame_len, 1);
|
||||
* 4. The code between SCO_CP_ACCEL_ALGO_START(); and SCO_CP_ACCEL_ALGO_END();
|
||||
*will run in CP core.
|
||||
* 5. These algorithms will work in AP. Need to move this algorithms from
|
||||
*overlay to fast ram.
|
||||
*
|
||||
* NOTE:
|
||||
* 1. spx fft and hw fft will share buffer, so just one core can use these fft.
|
||||
* 2. audio_dump_add_channel_data function can not work correctly in CP core, because
|
||||
* audio_dump_add_channel_data is possible called after audio_dump_run();
|
||||
* 1. spx fft and hw fft will share buffer, so just one core can use these
|
||||
*fft.
|
||||
* 2. audio_dump_add_channel_data function can not work correctly in CP core,
|
||||
*because audio_dump_add_channel_data is possible called after audio_dump_run();
|
||||
* 3. AP and CP just can use 85%
|
||||
*
|
||||
*
|
||||
|
@ -33,30 +37,30 @@
|
|||
* 1. FFT, RAM, CODE overlay
|
||||
**/
|
||||
#if defined(SCO_CP_ACCEL)
|
||||
#include "cmsis_os.h"
|
||||
#include "cp_accel.h"
|
||||
#include "hal_location.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_timer.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "speech_cfg.h"
|
||||
#include "hal_trace.h"
|
||||
#include "math.h"
|
||||
#include "norflash_api.h"
|
||||
#include "speech_cfg.h"
|
||||
|
||||
// malloc data from pool in init function
|
||||
#define FRAME_LEN_MAX (256)
|
||||
#define CHANNEL_NUM_MAX (2)
|
||||
#define FRAME_LEN_MAX (256)
|
||||
#define CHANNEL_NUM_MAX (2)
|
||||
|
||||
enum CP_SCO_STATE_T {
|
||||
CP_SCO_STATE_NONE = 0,
|
||||
CP_SCO_STATE_IDLE,
|
||||
CP_SCO_STATE_WORKING,
|
||||
CP_SCO_STATE_NONE = 0,
|
||||
CP_SCO_STATE_IDLE,
|
||||
CP_SCO_STATE_WORKING,
|
||||
};
|
||||
|
||||
enum SCO_CP_CMD_T {
|
||||
SCO_CP_CMD_PRO = 0,
|
||||
SCO_CP_CMD_OTHER,
|
||||
SCO_CP_CMD_PRO = 0,
|
||||
SCO_CP_CMD_OTHER,
|
||||
|
||||
SCO_CP_CMD_QTY,
|
||||
SCO_CP_CMD_QTY,
|
||||
};
|
||||
|
||||
static CP_DATA_LOC enum CP_SCO_STATE_T g_cp_state = CP_SCO_STATE_NONE;
|
||||
|
@ -74,45 +78,43 @@ static CP_BSS_LOC int g_channel_num;
|
|||
static int g_require_cnt = 0;
|
||||
static int g_run_cnt = 0;
|
||||
|
||||
int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len)
|
||||
{
|
||||
int32_t pcm_len = *_pcm_len;
|
||||
uint32_t wait_cnt = 0;
|
||||
int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len) {
|
||||
int32_t pcm_len = *_pcm_len;
|
||||
uint32_t wait_cnt = 0;
|
||||
|
||||
ASSERT(g_frame_len * g_channel_num == pcm_len, "[%s] g_frame_len(%d) * g_channel_num(%d) != pcm_len(%d)", __func__, g_frame_len, g_channel_num, pcm_len);
|
||||
ASSERT(g_frame_len * g_channel_num == pcm_len,
|
||||
"[%s] g_frame_len(%d) * g_channel_num(%d) != pcm_len(%d)", __func__,
|
||||
g_frame_len, g_channel_num, pcm_len);
|
||||
|
||||
// Check CP has new data to get and can get data from buffer
|
||||
// Check CP has new data to get and can get data from buffer
|
||||
#if defined(SCO_TRACE_CP_ACCEL)
|
||||
TRACE(4,"[%s] g_require_cnt: %d, status: %d, pcm_len: %d", __func__, g_require_cnt, g_cp_state, pcm_len);
|
||||
TRACE(4, "[%s] g_require_cnt: %d, status: %d, pcm_len: %d", __func__,
|
||||
g_require_cnt, g_cp_state, pcm_len);
|
||||
#endif
|
||||
|
||||
while (g_cp_state == CP_SCO_STATE_WORKING)
|
||||
{
|
||||
hal_sys_timer_delay_us(10);
|
||||
while (g_cp_state == CP_SCO_STATE_WORKING) {
|
||||
hal_sys_timer_delay_us(10);
|
||||
|
||||
if (wait_cnt++ > 300000) { // 3s
|
||||
ASSERT(0, "cp is hung %d", g_cp_state);
|
||||
}
|
||||
if (wait_cnt++ > 300000) { // 3s
|
||||
ASSERT(0, "cp is hung %d", g_cp_state);
|
||||
}
|
||||
}
|
||||
|
||||
if (g_cp_state == CP_SCO_STATE_IDLE)
|
||||
{
|
||||
speech_copy_int16(g_in_pcm_buf, pcm_buf, pcm_len);
|
||||
if (ref_buf)
|
||||
{
|
||||
speech_copy_int16(g_in_ref_buf, ref_buf, pcm_len / g_channel_num);
|
||||
}
|
||||
speech_copy_int16(pcm_buf, g_out_pcm_buf, g_pcm_len);
|
||||
*_pcm_len = g_pcm_len;
|
||||
g_pcm_len = pcm_len;
|
||||
|
||||
g_require_cnt++;
|
||||
g_cp_state = CP_SCO_STATE_WORKING;
|
||||
cp_accel_send_event_mcu2cp(CP_BUILD_ID(CP_TASK_SCO, CP_EVENT_SCO_PROCESSING));
|
||||
if (g_cp_state == CP_SCO_STATE_IDLE) {
|
||||
speech_copy_int16(g_in_pcm_buf, pcm_buf, pcm_len);
|
||||
if (ref_buf) {
|
||||
speech_copy_int16(g_in_ref_buf, ref_buf, pcm_len / g_channel_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Multi channels to one channel
|
||||
speech_copy_int16(pcm_buf, g_out_pcm_buf, g_pcm_len);
|
||||
*_pcm_len = g_pcm_len;
|
||||
g_pcm_len = pcm_len;
|
||||
|
||||
g_require_cnt++;
|
||||
g_cp_state = CP_SCO_STATE_WORKING;
|
||||
cp_accel_send_event_mcu2cp(
|
||||
CP_BUILD_ID(CP_TASK_SCO, CP_EVENT_SCO_PROCESSING));
|
||||
} else {
|
||||
// Multi channels to one channel
|
||||
#if 0
|
||||
for (int i = 0; i < pcm_len / g_channel_num; i++)
|
||||
{
|
||||
|
@ -122,26 +124,25 @@ int sco_cp_process(short *pcm_buf, short *ref_buf, int *_pcm_len)
|
|||
*_pcm_len = pcm_len / g_channel_num;
|
||||
#endif
|
||||
|
||||
// Check abs(g_require_cnt - g_run_cnt) > threshold, reset or assert
|
||||
// Check abs(g_require_cnt - g_run_cnt) > threshold, reset or assert
|
||||
|
||||
TRACE(2,"[%s] ERROR: status = %d", __func__, g_cp_state);
|
||||
}
|
||||
TRACE(2, "[%s] ERROR: status = %d", __func__, g_cp_state);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int sco_cp_algo(short *pcm_buf, short *ref_buf, int *_pcm_len);
|
||||
|
||||
CP_TEXT_SRAM_LOC
|
||||
static unsigned int sco_cp_main(uint8_t event)
|
||||
{
|
||||
static unsigned int sco_cp_main(uint8_t event) {
|
||||
#if defined(SCO_TRACE_CP_ACCEL)
|
||||
TRACE(2,"[%s] g_run_cnt: %d", __func__, g_run_cnt);
|
||||
TRACE(2, "[%s] g_run_cnt: %d", __func__, g_run_cnt);
|
||||
#endif
|
||||
|
||||
// LOCK BUFFER
|
||||
// LOCK BUFFER
|
||||
|
||||
// process pcm
|
||||
// process pcm
|
||||
#if 0
|
||||
// speech_copy_int16(g_out_pcm_buf, g_in_pcm_buf, g_pcm_len);
|
||||
|
||||
|
@ -150,79 +151,81 @@ static unsigned int sco_cp_main(uint8_t event)
|
|||
g_out_pcm_buf[i] = (short)(sinf(2 * 3.1415926 * i / 16 ) * 10000);
|
||||
}
|
||||
#else
|
||||
sco_cp_algo(g_in_pcm_buf, g_in_ref_buf, &g_pcm_len);
|
||||
speech_copy_int16(g_out_pcm_buf, g_in_pcm_buf, g_pcm_len);
|
||||
sco_cp_algo(g_in_pcm_buf, g_in_ref_buf, &g_pcm_len);
|
||||
speech_copy_int16(g_out_pcm_buf, g_in_pcm_buf, g_pcm_len);
|
||||
#endif
|
||||
|
||||
// set status
|
||||
g_run_cnt++;
|
||||
g_cp_state = CP_SCO_STATE_IDLE;
|
||||
// set status
|
||||
g_run_cnt++;
|
||||
g_cp_state = CP_SCO_STATE_IDLE;
|
||||
|
||||
#if defined(SCO_TRACE_CP_ACCEL)
|
||||
TRACE(1,"[%s] CP_SCO_STATE_IDLE", __func__);
|
||||
TRACE(1, "[%s] CP_SCO_STATE_IDLE", __func__);
|
||||
#endif
|
||||
|
||||
// UNLOCK BUFFER
|
||||
// UNLOCK BUFFER
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct cp_task_desc TASK_DESC_SCO = {CP_ACCEL_STATE_CLOSED, sco_cp_main, NULL, NULL, NULL};
|
||||
int sco_cp_init(int frame_len, int channel_num)
|
||||
{
|
||||
TRACE(3,"[%s] frame_len: %d, channel_num: %d", __func__, frame_len, channel_num);
|
||||
ASSERT(frame_len <= FRAME_LEN_MAX, "[%s] frame_len(%d) > FRAME_LEN_MAX", __func__, frame_len);
|
||||
ASSERT(channel_num <= CHANNEL_NUM_MAX, "[%s] channel_num(%d) > CHANNEL_NUM_MAX", __func__, channel_num);
|
||||
static struct cp_task_desc TASK_DESC_SCO = {CP_ACCEL_STATE_CLOSED, sco_cp_main,
|
||||
NULL, NULL, NULL};
|
||||
int sco_cp_init(int frame_len, int channel_num) {
|
||||
TRACE(3, "[%s] frame_len: %d, channel_num: %d", __func__, frame_len,
|
||||
channel_num);
|
||||
ASSERT(frame_len <= FRAME_LEN_MAX, "[%s] frame_len(%d) > FRAME_LEN_MAX",
|
||||
__func__, frame_len);
|
||||
ASSERT(channel_num <= CHANNEL_NUM_MAX,
|
||||
"[%s] channel_num(%d) > CHANNEL_NUM_MAX", __func__, channel_num);
|
||||
|
||||
g_require_cnt = 0;
|
||||
g_run_cnt = 0;
|
||||
g_require_cnt = 0;
|
||||
g_run_cnt = 0;
|
||||
|
||||
norflash_api_flush_disable(NORFLASH_API_USER_CP,(uint32_t)cp_accel_init_done);
|
||||
cp_accel_open(CP_TASK_SCO, &TASK_DESC_SCO);
|
||||
norflash_api_flush_disable(NORFLASH_API_USER_CP,
|
||||
(uint32_t)cp_accel_init_done);
|
||||
cp_accel_open(CP_TASK_SCO, &TASK_DESC_SCO);
|
||||
|
||||
uint32_t cnt=0;
|
||||
while(cp_accel_init_done() == false) {
|
||||
hal_sys_timer_delay_us(100);
|
||||
uint32_t cnt = 0;
|
||||
while (cp_accel_init_done() == false) {
|
||||
hal_sys_timer_delay_us(100);
|
||||
|
||||
cnt++;
|
||||
if (cnt % 10 == 0) {
|
||||
if (cnt == 10 * 200) { // 200ms
|
||||
ASSERT(0, "[%s] ERROR: Can not init cp!!!", __func__);
|
||||
} else {
|
||||
TRACE(1, "[%s] Wait CP init done...%d(ms)", __func__, cnt/10);
|
||||
}
|
||||
}
|
||||
cnt++;
|
||||
if (cnt % 10 == 0) {
|
||||
if (cnt == 10 * 200) { // 200ms
|
||||
ASSERT(0, "[%s] ERROR: Can not init cp!!!", __func__);
|
||||
} else {
|
||||
TRACE(1, "[%s] Wait CP init done...%d(ms)", __func__, cnt / 10);
|
||||
}
|
||||
}
|
||||
norflash_api_flush_enable(NORFLASH_API_USER_CP);
|
||||
}
|
||||
norflash_api_flush_enable(NORFLASH_API_USER_CP);
|
||||
#if 0
|
||||
speech_heap_cp_start();
|
||||
speech_heap_add_block(g_cp_heap_buf, sizeof(g_cp_heap_buf));
|
||||
speech_heap_cp_end();
|
||||
#endif
|
||||
|
||||
g_frame_len = frame_len;
|
||||
g_channel_num = channel_num;
|
||||
g_pcm_len = frame_len; // Initialize output pcm_len
|
||||
g_frame_len = frame_len;
|
||||
g_channel_num = channel_num;
|
||||
g_pcm_len = frame_len; // Initialize output pcm_len
|
||||
|
||||
speech_set_int16(g_in_pcm_buf, 0, g_frame_len * g_channel_num);
|
||||
speech_set_int16(g_out_pcm_buf, 0, g_frame_len * g_channel_num);
|
||||
speech_set_int16(g_in_ref_buf, 0, g_frame_len);
|
||||
g_cp_state = CP_SCO_STATE_IDLE;
|
||||
speech_set_int16(g_in_pcm_buf, 0, g_frame_len * g_channel_num);
|
||||
speech_set_int16(g_out_pcm_buf, 0, g_frame_len * g_channel_num);
|
||||
speech_set_int16(g_in_ref_buf, 0, g_frame_len);
|
||||
g_cp_state = CP_SCO_STATE_IDLE;
|
||||
|
||||
TRACE(2,"[%s] status = %d", __func__, g_cp_state);
|
||||
|
||||
return 0;
|
||||
TRACE(2, "[%s] status = %d", __func__, g_cp_state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sco_cp_deinit(void)
|
||||
{
|
||||
TRACE(1,"[%s] ...", __func__);
|
||||
int sco_cp_deinit(void) {
|
||||
TRACE(1, "[%s] ...", __func__);
|
||||
|
||||
cp_accel_close(CP_TASK_SCO);
|
||||
cp_accel_close(CP_TASK_SCO);
|
||||
|
||||
g_cp_state = CP_SCO_STATE_NONE;
|
||||
g_cp_state = CP_SCO_STATE_NONE;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "audio_dump.h"
|
||||
#include "bt_sco_chain.h"
|
||||
#include "hal_trace.h"
|
||||
#include "speech_cfg.h"
|
||||
#include "speech_memory.h"
|
||||
#include "speech_utils.h"
|
||||
#include "hal_trace.h"
|
||||
#include "audio_dump.h"
|
||||
#include "speech_cfg.h"
|
||||
|
||||
#if defined(SPEECH_TX_24BIT)
|
||||
int32_t *aec_echo_buf = NULL;
|
||||
|
@ -27,129 +27,134 @@ static short *aec_echo_buf_ptr;
|
|||
SpeechDcFilterState *speech_tx_dc_filter_st = NULL;
|
||||
#endif
|
||||
|
||||
int speech_init(int tx_sample_rate, int rx_sample_rate,
|
||||
int tx_frame_ms, int rx_frame_ms,
|
||||
int sco_frame_ms,
|
||||
uint8_t *buf, int len)
|
||||
{
|
||||
// we shoule keep a minmum buffer for speech heap
|
||||
// MSBC_16K_SAMPLE_RATE = 0, 560 bytes
|
||||
// MSBC_16K_SAMPLE_RATE = 1, 2568 bytes
|
||||
speech_heap_init(buf, SPEECH_HEAP_RESERVE_SIZE);
|
||||
int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||
int rx_frame_ms, int sco_frame_ms, uint8_t *buf, int len) {
|
||||
// we shoule keep a minmum buffer for speech heap
|
||||
// MSBC_16K_SAMPLE_RATE = 0, 560 bytes
|
||||
// MSBC_16K_SAMPLE_RATE = 1, 2568 bytes
|
||||
speech_heap_init(buf, SPEECH_HEAP_RESERVE_SIZE);
|
||||
|
||||
uint8_t *free_buf = buf + SPEECH_HEAP_RESERVE_SIZE;
|
||||
int free_len = len - SPEECH_HEAP_RESERVE_SIZE;
|
||||
uint8_t *free_buf = buf + SPEECH_HEAP_RESERVE_SIZE;
|
||||
int free_len = len - SPEECH_HEAP_RESERVE_SIZE;
|
||||
|
||||
// use free_buf for your algorithm
|
||||
memset(free_buf, 0, free_len);
|
||||
// use free_buf for your algorithm
|
||||
memset(free_buf, 0, free_len);
|
||||
|
||||
int frame_len = SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, tx_frame_ms);
|
||||
int frame_len = SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, tx_frame_ms);
|
||||
|
||||
#if defined(SPEECH_TX_24BIT)
|
||||
aec_echo_buf = (int32_t *)speech_calloc(frame_len, sizeof(int32_t));
|
||||
aec_echo_buf = (int32_t *)speech_calloc(frame_len, sizeof(int32_t));
|
||||
#else
|
||||
aec_echo_buf = (short *)speech_calloc(frame_len, sizeof(short));
|
||||
aec_echo_buf = (short *)speech_calloc(frame_len, sizeof(short));
|
||||
#endif
|
||||
aec_echo_buf_ptr = aec_echo_buf;
|
||||
aec_echo_buf_ptr = aec_echo_buf;
|
||||
|
||||
#if defined(SPEECH_TX_DC_FILTER)
|
||||
int channel_num = SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
int data_separation = 0;
|
||||
int channel_num = SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
int data_separation = 0;
|
||||
|
||||
SpeechDcFilterConfig dc_filter_cfg = {
|
||||
.bypass = 0,
|
||||
.gain = 0.f,
|
||||
};
|
||||
SpeechDcFilterConfig dc_filter_cfg = {
|
||||
.bypass = 0,
|
||||
.gain = 0.f,
|
||||
};
|
||||
|
||||
speech_tx_dc_filter_st = speech_dc_filter_create(tx_sample_rate, frame_len, &dc_filter_cfg);
|
||||
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_CHANNEL_NUM, &channel_num);
|
||||
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_DATA_SEPARATION, &data_separation);
|
||||
speech_tx_dc_filter_st =
|
||||
speech_dc_filter_create(tx_sample_rate, frame_len, &dc_filter_cfg);
|
||||
speech_dc_filter_ctl(speech_tx_dc_filter_st, SPEECH_DC_FILTER_SET_CHANNEL_NUM,
|
||||
&channel_num);
|
||||
speech_dc_filter_ctl(speech_tx_dc_filter_st,
|
||||
SPEECH_DC_FILTER_SET_DATA_SEPARATION, &data_separation);
|
||||
#endif
|
||||
|
||||
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
||||
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int speech_deinit(void)
|
||||
{
|
||||
int speech_deinit(void) {
|
||||
#if defined(SPEECH_TX_DC_FILTER)
|
||||
speech_dc_filter_destroy(speech_tx_dc_filter_st);
|
||||
speech_dc_filter_destroy(speech_tx_dc_filter_st);
|
||||
#endif
|
||||
|
||||
speech_free(aec_echo_buf_ptr);
|
||||
speech_free(aec_echo_buf_ptr);
|
||||
|
||||
size_t total = 0, used = 0, max_used = 0;
|
||||
speech_memory_info(&total, &used, &max_used);
|
||||
TRACE(3,"SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total, used, max_used);
|
||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||
size_t total = 0, used = 0, max_used = 0;
|
||||
speech_memory_info(&total, &used, &max_used);
|
||||
TRACE(3, "SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total,
|
||||
used, max_used);
|
||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
extern void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
|
||||
#endif
|
||||
|
||||
int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len)
|
||||
{
|
||||
int speech_tx_process(void *_pcm_buf, void *_ref_buf, int *_pcm_len) {
|
||||
#if defined(SPEECH_TX_24BIT)
|
||||
int32_t *pcm_buf = (int32_t *)_pcm_buf;
|
||||
int32_t *ref_buf = (int32_t *)_ref_buf;
|
||||
int32_t *pcm_buf = (int32_t *)_pcm_buf;
|
||||
int32_t *ref_buf = (int32_t *)_ref_buf;
|
||||
#else
|
||||
int16_t *pcm_buf = (int16_t *)_pcm_buf;
|
||||
int16_t *ref_buf = (int16_t *)_ref_buf;
|
||||
int16_t *pcm_buf = (int16_t *)_pcm_buf;
|
||||
int16_t *ref_buf = (int16_t *)_ref_buf;
|
||||
#endif
|
||||
|
||||
int pcm_len = *_pcm_len;
|
||||
int pcm_len = *_pcm_len;
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
uint8_t *bone_buf = NULL;
|
||||
uint32_t bone_len = 0;
|
||||
bt_sco_get_tdm_buffer(&bone_buf, &bone_len);
|
||||
uint8_t *bone_buf = NULL;
|
||||
uint32_t bone_len = 0;
|
||||
bt_sco_get_tdm_buffer(&bone_buf, &bone_len);
|
||||
#endif
|
||||
|
||||
audio_dump_clear_up();
|
||||
audio_dump_add_channel_data(0, ref_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
audio_dump_add_channel_data_from_multi_channels(1, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
||||
audio_dump_add_channel_data_from_multi_channels(2, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
||||
audio_dump_clear_up();
|
||||
audio_dump_add_channel_data(0, ref_buf,
|
||||
pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
audio_dump_add_channel_data_from_multi_channels(
|
||||
1, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
||||
audio_dump_add_channel_data_from_multi_channels(
|
||||
2, pcm_buf, pcm_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
audio_dump_add_channel_data(3, bone_buf, pcm16_len/SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
audio_dump_add_channel_data(3, bone_buf,
|
||||
pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
#endif
|
||||
|
||||
audio_dump_run();
|
||||
audio_dump_run();
|
||||
|
||||
#if defined(SPEECH_TX_DC_FILTER)
|
||||
#if defined(SPEECH_TX_24BIT)
|
||||
speech_dc_filter_process_int24(speech_tx_dc_filter_st, pcm_buf, pcm_len);
|
||||
speech_dc_filter_process_int24(speech_tx_dc_filter_st, pcm_buf, pcm_len);
|
||||
#else
|
||||
speech_dc_filter_process(speech_tx_dc_filter_st, pcm_buf, pcm_len);
|
||||
speech_dc_filter_process(speech_tx_dc_filter_st, pcm_buf, pcm_len);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Add your algrithm here and disable #if macro
|
||||
// Add your algrithm here and disable #if macro
|
||||
#if 1
|
||||
for (int i = 0, j = 0; i < pcm_len; i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j++) {
|
||||
// choose main microphone data
|
||||
pcm_buf[j] = pcm_buf[i];
|
||||
// choose reference data, i.e. loopback
|
||||
//pcm16_buf[j] = ref16_buf[j];
|
||||
}
|
||||
pcm_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
for (int i = 0, j = 0; i < pcm_len;
|
||||
i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j++) {
|
||||
// choose main microphone data
|
||||
pcm_buf[j] = pcm_buf[i];
|
||||
// choose reference data, i.e. loopback
|
||||
// pcm16_buf[j] = ref16_buf[j];
|
||||
}
|
||||
pcm_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
#endif
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
memcpy(pcm_buf, bone_buf, bone_len);
|
||||
memcpy(pcm_buf, bone_buf, bone_len);
|
||||
#endif
|
||||
|
||||
*_pcm_len = pcm_len;
|
||||
*_pcm_len = pcm_len;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int speech_rx_process(void *pcm_buf, int *pcm_len)
|
||||
{
|
||||
// Add your algorithm here
|
||||
return 0;
|
||||
int speech_rx_process(void *pcm_buf, int *pcm_len) {
|
||||
// Add your algorithm here
|
||||
return 0;
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
#include "audio_dump.h"
|
||||
#include "bt_sco_chain.h"
|
||||
#include "hal_trace.h"
|
||||
#include "speech_memory.h"
|
||||
#include "speech_utils.h"
|
||||
#include "hal_trace.h"
|
||||
#include "audio_dump.h"
|
||||
#include "vcp-api.h"
|
||||
#include "spf-postapi.h"
|
||||
#include "vcp-api.h"
|
||||
|
||||
#define ALANGO_TRACE(s, ...) TRACE(1,"%s: " s, __FUNCTION__, ## __VA_ARGS__)
|
||||
#define ALANGO_TRACE(s, ...) TRACE(1, "%s: " s, __FUNCTION__, ##__VA_ARGS__)
|
||||
|
||||
short *aec_echo_buf = NULL;
|
||||
|
||||
|
@ -17,7 +17,7 @@ static void *mem;
|
|||
|
||||
extern void *voicebtpcm_get_ext_buff(int size);
|
||||
|
||||
extern char* vcp_errorv(err_t err);
|
||||
extern char *vcp_errorv(err_t err);
|
||||
|
||||
extern PROFILE_TYPE(t) alango_profile;
|
||||
|
||||
|
@ -28,121 +28,130 @@ mem_reg_t reg[NUM_MEM_REGIONS];
|
|||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||
static int16_t *deinterleaved_buf = NULL;
|
||||
|
||||
static void deinterleave_audio(int16_t *dst, int16_t *src, uint32_t len, uint32_t ch_num)
|
||||
{
|
||||
uint32_t samples_per_channel = len / ch_num;
|
||||
static void deinterleave_audio(int16_t *dst, int16_t *src, uint32_t len,
|
||||
uint32_t ch_num) {
|
||||
uint32_t samples_per_channel = len / ch_num;
|
||||
|
||||
for (uint32_t i = 0; i < samples_per_channel; i++) {
|
||||
for (uint32_t j = 0; j < ch_num; j++) {
|
||||
dst[samples_per_channel * j + i] = src[ch_num * i + j];
|
||||
}
|
||||
for (uint32_t i = 0; i < samples_per_channel; i++) {
|
||||
for (uint32_t j = 0; j < ch_num; j++) {
|
||||
dst[samples_per_channel * j + i] = src[ch_num * i + j];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int speech_init(int tx_sample_rate, int rx_sample_rate,
|
||||
int tx_frame_ms, int rx_frame_ms,
|
||||
int sco_frame_ms,
|
||||
uint8_t *buf, int len)
|
||||
{
|
||||
speech_heap_init(buf, len);
|
||||
int speech_init(int tx_sample_rate, int rx_sample_rate, int tx_frame_ms,
|
||||
int rx_frame_ms, int sco_frame_ms, uint8_t *buf, int len) {
|
||||
speech_heap_init(buf, len);
|
||||
|
||||
int frame_len = SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, tx_frame_ms);
|
||||
int frame_len = SPEECH_FRAME_MS_TO_LEN(tx_sample_rate, tx_frame_ms);
|
||||
|
||||
aec_echo_buf = (short *)speech_calloc(frame_len, sizeof(short));
|
||||
aec_echo_buf_ptr = aec_echo_buf;
|
||||
aec_echo_buf = (short *)speech_calloc(frame_len, sizeof(short));
|
||||
aec_echo_buf_ptr = aec_echo_buf;
|
||||
|
||||
// init alango
|
||||
// check profile
|
||||
curr_profile = &alango_profile;
|
||||
err_t err = vcp_check_profile(curr_profile);
|
||||
if (err.err) {
|
||||
if (err.err == ERR_INVALID_CRC)
|
||||
ALANGO_TRACE(0,"Profile error: Invalid CRC!");
|
||||
else
|
||||
ALANGO_TRACE(1,"Profile error: %d", err.err);
|
||||
}
|
||||
// init alango
|
||||
// check profile
|
||||
curr_profile = &alango_profile;
|
||||
err_t err = vcp_check_profile(curr_profile);
|
||||
if (err.err) {
|
||||
if (err.err == ERR_INVALID_CRC)
|
||||
ALANGO_TRACE(0, "Profile error: Invalid CRC!");
|
||||
else
|
||||
ALANGO_TRACE(1, "Profile error: %d", err.err);
|
||||
}
|
||||
|
||||
ASSERT(frame_len % curr_profile->p_gen->frlen == 0, "Profile error: frame_len(%d) should be divided by frlen(%d)", frame_len, curr_profile->p_gen->frlen);
|
||||
ASSERT(frame_len % curr_profile->p_gen->frlen == 0,
|
||||
"Profile error: frame_len(%d) should be divided by frlen(%d)",
|
||||
frame_len, curr_profile->p_gen->frlen);
|
||||
|
||||
unsigned int smem = vcp_get_hook_size();
|
||||
mem = speech_malloc(smem);
|
||||
unsigned int smem = vcp_get_hook_size();
|
||||
mem = speech_malloc(smem);
|
||||
|
||||
vcp_get_mem_size(curr_profile, reg, mem);
|
||||
vcp_get_mem_size(curr_profile, reg, mem);
|
||||
|
||||
ALANGO_TRACE(0,"Hello, I am VCP8!");
|
||||
ALANGO_TRACE(0, "Hello, I am VCP8!");
|
||||
|
||||
for (int i = 0; i < NUM_MEM_REGIONS; i++) {
|
||||
reg[i].mem = (void *)speech_malloc(reg[i].size);
|
||||
ALANGO_TRACE(2,"I need %d bytes of memory in memory region %d to work.\n", reg[i].size, i + 1);
|
||||
}
|
||||
for (int i = 0; i < NUM_MEM_REGIONS; i++) {
|
||||
reg[i].mem = (void *)speech_malloc(reg[i].size);
|
||||
ALANGO_TRACE(2, "I need %d bytes of memory in memory region %d to work.\n",
|
||||
reg[i].size, i + 1);
|
||||
}
|
||||
|
||||
err = vcp_init_debug(curr_profile, reg);
|
||||
if (err.err == ERR_NOT_ENOUGH_MEMORY) {
|
||||
ALANGO_TRACE(2,"%d more bytes needed in region %d!\n", -reg[err.pid].size, err.pid);
|
||||
} else if (err.err == ERR_UNKNOWN) {
|
||||
ALANGO_TRACE(0,"vcp_init_debug() returns UNKNOWN error\n!");
|
||||
} else if (err.err != ERR_NO_ERROR) {
|
||||
ALANGO_TRACE(2,"vcp_init_debug() returns error %d, pid %d!\n", err.err, err.pid);
|
||||
}
|
||||
err = vcp_init_debug(curr_profile, reg);
|
||||
if (err.err == ERR_NOT_ENOUGH_MEMORY) {
|
||||
ALANGO_TRACE(2, "%d more bytes needed in region %d!\n", -reg[err.pid].size,
|
||||
err.pid);
|
||||
} else if (err.err == ERR_UNKNOWN) {
|
||||
ALANGO_TRACE(0, "vcp_init_debug() returns UNKNOWN error\n!");
|
||||
} else if (err.err != ERR_NO_ERROR) {
|
||||
ALANGO_TRACE(2, "vcp_init_debug() returns error %d, pid %d!\n", err.err,
|
||||
err.pid);
|
||||
}
|
||||
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||
deinterleaved_buf = speech_malloc(curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM * sizeof(int16_t));
|
||||
deinterleaved_buf =
|
||||
speech_malloc(curr_profile->p_gen->frlen *
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM * sizeof(int16_t));
|
||||
#endif
|
||||
|
||||
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
||||
audio_dump_init(frame_len, sizeof(int16_t), 3);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int speech_deinit(void)
|
||||
{
|
||||
speech_free(aec_echo_buf_ptr);
|
||||
speech_free(mem);
|
||||
int speech_deinit(void) {
|
||||
speech_free(aec_echo_buf_ptr);
|
||||
speech_free(mem);
|
||||
|
||||
for (int i = 0; i < NUM_MEM_REGIONS; i++)
|
||||
speech_free(reg[i].mem);
|
||||
for (int i = 0; i < NUM_MEM_REGIONS; i++)
|
||||
speech_free(reg[i].mem);
|
||||
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||
speech_free(deinterleaved_buf);
|
||||
speech_free(deinterleaved_buf);
|
||||
#endif
|
||||
|
||||
size_t total = 0, used = 0, max_used = 0;
|
||||
speech_memory_info(&total, &used, &max_used);
|
||||
TRACE(3,"SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total, used, max_used);
|
||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||
size_t total = 0, used = 0, max_used = 0;
|
||||
speech_memory_info(&total, &used, &max_used);
|
||||
TRACE(3, "SPEECH MALLOC MEM: total - %d, used - %d, max_used - %d.", total,
|
||||
used, max_used);
|
||||
ASSERT(used == 0, "[%s] used != 0", __func__);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
extern void bt_sco_get_tdm_buffer(uint8_t **buf, uint32_t *len);
|
||||
#endif
|
||||
|
||||
int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len)
|
||||
{
|
||||
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
||||
int16_t *ref16_buf = (int16_t *)ref_buf;
|
||||
int pcm16_len = *pcm_len;
|
||||
int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len) {
|
||||
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
||||
int16_t *ref16_buf = (int16_t *)ref_buf;
|
||||
int pcm16_len = *pcm_len;
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
uint8_t *bone_buf = NULL;
|
||||
uint32_t bone_len = 0;
|
||||
bt_sco_get_tdm_buffer(&bone_buf, &bone_len);
|
||||
uint8_t *bone_buf = NULL;
|
||||
uint32_t bone_len = 0;
|
||||
bt_sco_get_tdm_buffer(&bone_buf, &bone_len);
|
||||
#endif
|
||||
|
||||
audio_dump_clear_up();
|
||||
audio_dump_add_channel_data(0, ref_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
audio_dump_add_channel_data_from_multi_channels(1, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
||||
audio_dump_add_channel_data_from_multi_channels(2, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
||||
audio_dump_clear_up();
|
||||
audio_dump_add_channel_data(0, ref_buf,
|
||||
pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
audio_dump_add_channel_data_from_multi_channels(
|
||||
1, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 0);
|
||||
audio_dump_add_channel_data_from_multi_channels(
|
||||
2, pcm16_buf, pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM, 1);
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
audio_dump_add_channel_data(3, bone_buf, pcm16_len/SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
audio_dump_add_channel_data(3, bone_buf,
|
||||
pcm16_len / SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
#endif
|
||||
|
||||
audio_dump_run();
|
||||
audio_dump_run();
|
||||
|
||||
// Add your algrithm here and disable #if macro
|
||||
// Add your algrithm here and disable #if macro
|
||||
#if 0
|
||||
for (int i = 0, j = 0; i < pcm16_len; i += SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j++) {
|
||||
// choose main microphone data
|
||||
|
@ -152,41 +161,48 @@ int speech_tx_process(void *pcm_buf, void *ref_buf, int *pcm_len)
|
|||
}
|
||||
pcm16_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
#else
|
||||
for (int i = 0, j = 0; i < pcm16_len; i += curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM, j += curr_profile->p_gen->frlen) {
|
||||
for (int i = 0, j = 0; i < pcm16_len;
|
||||
i += curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||
j += curr_profile->p_gen->frlen) {
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM >= 2
|
||||
deinterleave_audio(deinterleaved_buf, &pcm16_buf[i], curr_profile->p_gen->frlen * SPEECH_CODEC_CAPTURE_CHANNEL_NUM, SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
err_t err = vcp_process_tx(reg, deinterleaved_buf, &ref16_buf[j], &pcm16_buf[j]);
|
||||
//memcpy(&pcm16_buf[j], deinterleaved_buf, curr_profile->p_gen->frlen * sizeof(int16_t));
|
||||
deinterleave_audio(deinterleaved_buf, &pcm16_buf[i],
|
||||
curr_profile->p_gen->frlen *
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM,
|
||||
SPEECH_CODEC_CAPTURE_CHANNEL_NUM);
|
||||
err_t err =
|
||||
vcp_process_tx(reg, deinterleaved_buf, &ref16_buf[j], &pcm16_buf[j]);
|
||||
// memcpy(&pcm16_buf[j], deinterleaved_buf, curr_profile->p_gen->frlen *
|
||||
// sizeof(int16_t));
|
||||
#else
|
||||
err_t err = vcp_process_tx(reg, &pcm16_buf[i], &ref16_buf[j], &pcm16_buf[j]);
|
||||
err_t err =
|
||||
vcp_process_tx(reg, &pcm16_buf[i], &ref16_buf[j], &pcm16_buf[j]);
|
||||
#endif
|
||||
if (err.err != ERR_NO_ERROR) {
|
||||
ALANGO_TRACE(1,"vcp_process_tx error: %d", err.err);
|
||||
}
|
||||
if (err.err != ERR_NO_ERROR) {
|
||||
ALANGO_TRACE(1, "vcp_process_tx error: %d", err.err);
|
||||
}
|
||||
pcm16_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
}
|
||||
pcm16_len /= SPEECH_CODEC_CAPTURE_CHANNEL_NUM;
|
||||
#endif
|
||||
|
||||
#if defined(BONE_SENSOR_TDM)
|
||||
memcpy(pcm_buf, bone_buf, bone_len);
|
||||
memcpy(pcm_buf, bone_buf, bone_len);
|
||||
#endif
|
||||
|
||||
*pcm_len = pcm16_len;
|
||||
*pcm_len = pcm16_len;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int speech_rx_process(void *pcm_buf, int *pcm_len)
|
||||
{
|
||||
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
||||
int pcm16_len = *pcm_len;
|
||||
int speech_rx_process(void *pcm_buf, int *pcm_len) {
|
||||
int16_t *pcm16_buf = (int16_t *)pcm_buf;
|
||||
int pcm16_len = *pcm_len;
|
||||
|
||||
for (int i = 0; i < pcm16_len; i += curr_profile->p_gen->frlen) {
|
||||
err_t err = vcp_process_rx(reg, &pcm16_buf[i], &pcm16_buf[i]);
|
||||
if (err.err != ERR_NO_ERROR) {
|
||||
ALANGO_TRACE(1,"vcp_process_tx error: %d", err.err);
|
||||
}
|
||||
for (int i = 0; i < pcm16_len; i += curr_profile->p_gen->frlen) {
|
||||
err_t err = vcp_process_rx(reg, &pcm16_buf[i], &pcm16_buf[i]);
|
||||
if (err.err != ERR_NO_ERROR) {
|
||||
ALANGO_TRACE(1, "vcp_process_tx error: %d", err.err);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
|
@ -13,8 +13,8 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "bt_sco_chain_cfg.h"
|
||||
#include "aud_section.h"
|
||||
#include "bt_sco_chain_cfg.h"
|
||||
#include "hal_trace.h"
|
||||
|
||||
static bool speech_tuning_status = false;
|
||||
|
@ -23,202 +23,178 @@ extern int speech_store_config(const SpeechConfig *cfg);
|
|||
|
||||
#ifdef AUDIO_SECTION_ENABLE
|
||||
typedef struct {
|
||||
uint8_t reserved[AUDIO_SECTION_CFG_RESERVED_LEN];
|
||||
SpeechConfig cfg;
|
||||
uint8_t reserved[AUDIO_SECTION_CFG_RESERVED_LEN];
|
||||
SpeechConfig cfg;
|
||||
} AUDIO_SECTION_SPEECH_CFG_T;
|
||||
|
||||
static AUDIO_SECTION_SPEECH_CFG_T audio_section_speech_cfg;
|
||||
|
||||
int store_speech_cfg_into_audio_section(SpeechConfig *cfg)
|
||||
{
|
||||
int res = 0;
|
||||
int store_speech_cfg_into_audio_section(SpeechConfig *cfg) {
|
||||
int res = 0;
|
||||
|
||||
memcpy(&audio_section_speech_cfg.cfg, cfg, sizeof(SpeechConfig));
|
||||
memcpy(&audio_section_speech_cfg.cfg, cfg, sizeof(SpeechConfig));
|
||||
|
||||
res = audio_section_store_cfg(AUDIO_SECTION_DEVICE_SPEECH,
|
||||
res = audio_section_store_cfg(AUDIO_SECTION_DEVICE_SPEECH,
|
||||
(uint8_t *)&audio_section_speech_cfg,
|
||||
sizeof(AUDIO_SECTION_SPEECH_CFG_T));
|
||||
|
||||
if (res) {
|
||||
TRACE(2, "[%s] ERROR: res = %d", __func__, res);
|
||||
} else {
|
||||
TRACE(1, "[%s] Store speech cfg into audio section!!!", __func__);
|
||||
}
|
||||
|
||||
if(res)
|
||||
{
|
||||
TRACE(2,"[%s] ERROR: res = %d", __func__, res);
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE(1,"[%s] Store speech cfg into audio section!!!", __func__);
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
void *load_speech_cfg_from_audio_section(void)
|
||||
{
|
||||
int res = 0;
|
||||
res = audio_section_load_cfg(AUDIO_SECTION_DEVICE_SPEECH,
|
||||
(uint8_t *)&audio_section_speech_cfg,
|
||||
sizeof(AUDIO_SECTION_SPEECH_CFG_T));
|
||||
void *load_speech_cfg_from_audio_section(void) {
|
||||
int res = 0;
|
||||
res = audio_section_load_cfg(AUDIO_SECTION_DEVICE_SPEECH,
|
||||
(uint8_t *)&audio_section_speech_cfg,
|
||||
sizeof(AUDIO_SECTION_SPEECH_CFG_T));
|
||||
|
||||
void *res_ptr = NULL;
|
||||
void *res_ptr = NULL;
|
||||
|
||||
if (res)
|
||||
{
|
||||
TRACE(2,"[%s] ERROR: res = %d", __func__, res);
|
||||
res_ptr = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE(1,"[%s] Load speech cfg from audio section!!!", __func__);
|
||||
res_ptr = (void *)&audio_section_speech_cfg.cfg;
|
||||
}
|
||||
if (res) {
|
||||
TRACE(2, "[%s] ERROR: res = %d", __func__, res);
|
||||
res_ptr = NULL;
|
||||
} else {
|
||||
TRACE(1, "[%s] Load speech cfg from audio section!!!", __func__);
|
||||
res_ptr = (void *)&audio_section_speech_cfg.cfg;
|
||||
}
|
||||
|
||||
return res_ptr;
|
||||
return res_ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
int speech_tuning_set_status(bool en)
|
||||
{
|
||||
speech_tuning_status = en;
|
||||
int speech_tuning_set_status(bool en) {
|
||||
speech_tuning_status = en;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool speech_tuning_get_status(void)
|
||||
{
|
||||
return speech_tuning_status;
|
||||
bool speech_tuning_get_status(void) { return speech_tuning_status; }
|
||||
|
||||
uint32_t speech_tuning_check(unsigned char *buf, uint32_t len) {
|
||||
uint32_t res = 0;
|
||||
|
||||
// Check valid
|
||||
uint32_t config_size = sizeof(SpeechConfig);
|
||||
|
||||
if (config_size != len) {
|
||||
TRACE(2, "[speech tuning] len(%d) != config_size(%d)", len, config_size);
|
||||
res = 1;
|
||||
} else {
|
||||
TRACE(1, "[speech tuning] len(%d) is OK", len);
|
||||
// SpeechConfig POSSIBLY_UNUSED *cfg = (SpeechConfig *)buf;
|
||||
|
||||
// Test parameters
|
||||
//#if defined(SPEECH_TX_2MIC_NS2)
|
||||
// TRACE(1,"[speech tuning] TX: delay_taps(x100): %d",
|
||||
// (int)(cfg->tx_2mic_ns2.delay_taps * 100));
|
||||
//#endif
|
||||
//#if defined(SPEECH_TX_NOISE_GATE)
|
||||
// TRACE(1,"[speech tuning] TX: data_threshold: %d",
|
||||
// cfg->tx_noise_gate.data_threshold);
|
||||
//#endif
|
||||
//#if defined(SPEECH_TX_EQ)
|
||||
// TRACE(1,"[speech tuning] TX: eq num: %d", cfg->tx_eq.num);
|
||||
//#endif
|
||||
//#if defined(SPEECH_RX_EQ)
|
||||
// TRACE(1,"[speech tuning] RX: eq num: %d", cfg->rx_eq.num);
|
||||
//#endif
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t speech_tuning_check(unsigned char *buf, uint32_t len)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
uint32_t speech_tuning_rx_callback(unsigned char *buf, uint32_t len) {
|
||||
uint32_t res = 0;
|
||||
|
||||
// Check valid
|
||||
uint32_t config_size = sizeof(SpeechConfig);
|
||||
res = speech_tuning_check(buf, len);
|
||||
|
||||
if (config_size != len)
|
||||
{
|
||||
TRACE(2,"[speech tuning] len(%d) != config_size(%d)", len, config_size);
|
||||
res = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE(1,"[speech tuning] len(%d) is OK", len);
|
||||
//SpeechConfig POSSIBLY_UNUSED *cfg = (SpeechConfig *)buf;
|
||||
if (res) {
|
||||
TRACE(1, "[speech tuning] ERROR: Send check res = %d", res);
|
||||
TRACE(0, "[Speech Tuning] res : 1; info : Send len(%d) != config_size(%d);",
|
||||
len, sizeof(SpeechConfig));
|
||||
} else {
|
||||
// Save cfg
|
||||
speech_store_config((SpeechConfig *)buf);
|
||||
|
||||
// Test parameters
|
||||
//#if defined(SPEECH_TX_2MIC_NS2)
|
||||
// TRACE(1,"[speech tuning] TX: delay_taps(x100): %d", (int)(cfg->tx_2mic_ns2.delay_taps * 100));
|
||||
//#endif
|
||||
//#if defined(SPEECH_TX_NOISE_GATE)
|
||||
// TRACE(1,"[speech tuning] TX: data_threshold: %d", cfg->tx_noise_gate.data_threshold);
|
||||
//#endif
|
||||
//#if defined(SPEECH_TX_EQ)
|
||||
// TRACE(1,"[speech tuning] TX: eq num: %d", cfg->tx_eq.num);
|
||||
//#endif
|
||||
//#if defined(SPEECH_RX_EQ)
|
||||
// TRACE(1,"[speech tuning] RX: eq num: %d", cfg->rx_eq.num);
|
||||
//#endif
|
||||
}
|
||||
// Set status
|
||||
speech_tuning_set_status(true);
|
||||
|
||||
return res;
|
||||
}
|
||||
TRACE(0, "[speech tuning] OK: Send cfg");
|
||||
TRACE(0, "[Speech Tuning] res : 0;");
|
||||
}
|
||||
|
||||
uint32_t speech_tuning_rx_callback(unsigned char *buf, uint32_t len)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
|
||||
res = speech_tuning_check(buf, len);
|
||||
|
||||
if (res)
|
||||
{
|
||||
TRACE(1,"[speech tuning] ERROR: Send check res = %d", res);
|
||||
TRACE(0,"[Speech Tuning] res : 1; info : Send len(%d) != config_size(%d);", len, sizeof(SpeechConfig));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save cfg
|
||||
speech_store_config((SpeechConfig *)buf);
|
||||
|
||||
// Set status
|
||||
speech_tuning_set_status(true);
|
||||
|
||||
TRACE(0,"[speech tuning] OK: Send cfg");
|
||||
TRACE(0,"[Speech Tuning] res : 0;");
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifdef AUDIO_SECTION_ENABLE
|
||||
uint32_t speech_tuning_burn_rx_callback(unsigned char *buf, uint32_t len)
|
||||
{
|
||||
uint32_t res = 0;
|
||||
uint32_t speech_tuning_burn_rx_callback(unsigned char *buf, uint32_t len) {
|
||||
uint32_t res = 0;
|
||||
|
||||
res = speech_tuning_check(buf, len);
|
||||
res = speech_tuning_check(buf, len);
|
||||
|
||||
if (res)
|
||||
{
|
||||
TRACE(1,"[speech tuning] ERROR: Burn check res = %d", res);
|
||||
TRACE(0,"[Speech Tuning] res : 1; info : Burn len(%d) != config_size(%d);", len, sizeof(SpeechConfig));
|
||||
if (res) {
|
||||
TRACE(1, "[speech tuning] ERROR: Burn check res = %d", res);
|
||||
TRACE(0, "[Speech Tuning] res : 1; info : Burn len(%d) != config_size(%d);",
|
||||
len, sizeof(SpeechConfig));
|
||||
} else {
|
||||
res = store_speech_cfg_into_audio_section((SpeechConfig *)buf);
|
||||
|
||||
if (res) {
|
||||
TRACE(1, "[speech tuning] ERROR: Store res = %d", res);
|
||||
res += 100;
|
||||
TRACE(0, "[Speech Tuning] res : 2; info : Do not enable "
|
||||
"AUDIO_SECTION_ENABLE;");
|
||||
} else {
|
||||
TRACE(0, "[speech tuning] OK: Store cfg");
|
||||
TRACE(0, "[Speech Tuning] res : 0;");
|
||||
}
|
||||
else
|
||||
{
|
||||
res = store_speech_cfg_into_audio_section((SpeechConfig *)buf);
|
||||
}
|
||||
|
||||
if(res)
|
||||
{
|
||||
TRACE(1,"[speech tuning] ERROR: Store res = %d", res);
|
||||
res += 100;
|
||||
TRACE(0,"[Speech Tuning] res : 2; info : Do not enable AUDIO_SECTION_ENABLE;");
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE(0,"[speech tuning] OK: Store cfg");
|
||||
TRACE(0,"[Speech Tuning] res : 0;");
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
int speech_tuning_init(void)
|
||||
{
|
||||
int speech_tuning_init(void) {
|
||||
#if defined(HAL_TRACE_RX_ENABLE) && !defined(SPEECH_TX_THIRDPARTY)
|
||||
hal_trace_rx_register("Speech Tuning", (HAL_TRACE_RX_CALLBACK_T)speech_tuning_rx_callback);
|
||||
hal_trace_rx_register("Speech Tuning",
|
||||
(HAL_TRACE_RX_CALLBACK_T)speech_tuning_rx_callback);
|
||||
|
||||
#ifdef AUDIO_SECTION_ENABLE
|
||||
hal_trace_rx_register("Speech Tuning Burn", (HAL_TRACE_RX_CALLBACK_T)speech_tuning_burn_rx_callback);
|
||||
hal_trace_rx_register(
|
||||
"Speech Tuning Burn",
|
||||
(HAL_TRACE_RX_CALLBACK_T)speech_tuning_burn_rx_callback);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
speech_tuning_set_status(false);
|
||||
speech_tuning_set_status(false);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int speech_tuning_open(void)
|
||||
{
|
||||
int speech_tuning_open(void) {
|
||||
#ifdef AUDIO_SECTION_ENABLE
|
||||
SpeechConfig *speech_cfg_load = NULL;
|
||||
SpeechConfig *speech_cfg_load = NULL;
|
||||
|
||||
speech_cfg_load = (SpeechConfig *)load_speech_cfg_from_audio_section();
|
||||
speech_cfg_load = (SpeechConfig *)load_speech_cfg_from_audio_section();
|
||||
|
||||
if (speech_cfg_load)
|
||||
{
|
||||
speech_store_config(speech_cfg_load);
|
||||
}
|
||||
if (speech_cfg_load) {
|
||||
speech_store_config(speech_cfg_load);
|
||||
}
|
||||
#endif
|
||||
|
||||
speech_tuning_set_status(false);
|
||||
speech_tuning_set_status(false);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int speech_tuning_close(void)
|
||||
{
|
||||
speech_tuning_set_status(false);
|
||||
int speech_tuning_close(void) {
|
||||
speech_tuning_set_status(false);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,23 +17,22 @@
|
|||
#include "mbed.h"
|
||||
#endif
|
||||
// Standard C Included Files
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef MBED
|
||||
//#include "rtos.h"
|
||||
#endif
|
||||
#ifdef MBED
|
||||
#include "SDFileSystem.h"
|
||||
#endif
|
||||
#include "app_audio.h"
|
||||
#include "cqueue.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_audio.h"
|
||||
|
||||
#include "hal_uart.h"
|
||||
|
||||
// BT
|
||||
|
||||
|
@ -44,16 +43,15 @@ osMutexDef(g_voicecvsd_queue_mutex);
|
|||
|
||||
/* cvsd queue */
|
||||
#define VOICECVSD_TEMP_BUFFER_SIZE 128
|
||||
#define VOICECVSD_QUEUE_SIZE (VOICECVSD_TEMP_BUFFER_SIZE*20)
|
||||
#define VOICECVSD_QUEUE_SIZE (VOICECVSD_TEMP_BUFFER_SIZE * 20)
|
||||
CQueue voicecvsd_queue;
|
||||
|
||||
static enum APP_AUDIO_CACHE_T voicecvsd_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
|
||||
#define LOCK_VOICECVSD_QUEUE() \
|
||||
osMutexWait(g_voicecvsd_queue_mutex_id, osWaitForever)
|
||||
#define LOCK_VOICECVSD_QUEUE() \
|
||||
osMutexWait(g_voicecvsd_queue_mutex_id, osWaitForever)
|
||||
|
||||
#define UNLOCK_VOICECVSD_QUEUE() \
|
||||
osMutexRelease(g_voicecvsd_queue_mutex_id)
|
||||
#define UNLOCK_VOICECVSD_QUEUE() osMutexRelease(g_voicecvsd_queue_mutex_id)
|
||||
|
||||
void xLOCK_VOICECVSD_QUEUE(void)
|
||||
{
|
||||
|
|
|
@ -14,34 +14,32 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
// Standard C Included Files
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "cqueue.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_uart.h"
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
uint8_t digmic_buf[100*1024];
|
||||
uint8_t digmic_buf[100 * 1024];
|
||||
uint32_t digmic_buf_len = 0;
|
||||
|
||||
uint32_t dig_mic_audio_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
TRACE(2,"%s:%d\n", __func__, __LINE__);
|
||||
memcpy(buf, digmic_buf, len);
|
||||
uint32_t dig_mic_audio_more_data(uint8_t *buf, uint32_t len) {
|
||||
TRACE(2, "%s:%d\n", __func__, __LINE__);
|
||||
memcpy(buf, digmic_buf, len);
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
uint32_t dig_mic_audio_data_come(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
TRACE(2,"%s:%d\n", __func__, __LINE__);
|
||||
uint32_t dig_mic_audio_data_come(uint8_t *buf, uint32_t len) {
|
||||
TRACE(2, "%s:%d\n", __func__, __LINE__);
|
||||
|
||||
memcpy(digmic_buf + digmic_buf_len, buf, len);
|
||||
memcpy(digmic_buf + digmic_buf_len, buf, len);
|
||||
|
||||
#if 1
|
||||
digmic_buf_len = (digmic_buf_len + len)%(100*1024);
|
||||
digmic_buf_len = (digmic_buf_len + len) % (100 * 1024);
|
||||
#endif
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
|
|
@ -14,15 +14,15 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
// Standard C Included Files
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "cqueue.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_uart.h"
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef RTOS
|
||||
#include "cmsis_os.h"
|
||||
#endif
|
||||
|
@ -33,106 +33,102 @@ osMutexDef(g_flac_queue_mutex);
|
|||
|
||||
/* flac queue */
|
||||
#define FLAC_TEMP_BUFFER_SIZE 2048
|
||||
#define FLAC_QUEUE_SIZE (FLAC_TEMP_BUFFER_SIZE*4)
|
||||
#define FLAC_QUEUE_SIZE (FLAC_TEMP_BUFFER_SIZE * 4)
|
||||
unsigned char flac_queue_buf[FLAC_QUEUE_SIZE];
|
||||
CQueue flac_queue;
|
||||
static uint32_t ok_to_decode = 0;
|
||||
|
||||
#define LOCK_FLAC_QUEUE() \
|
||||
osMutexWait(g_flac_queue_mutex_id, osWaitForever)
|
||||
#define LOCK_FLAC_QUEUE() osMutexWait(g_flac_queue_mutex_id, osWaitForever)
|
||||
|
||||
#define UNLOCK_FLAC_QUEUE() \
|
||||
osMutexRelease(g_flac_queue_mutex_id)
|
||||
#define UNLOCK_FLAC_QUEUE() osMutexRelease(g_flac_queue_mutex_id)
|
||||
|
||||
static void copy_one_trace_to_two_track_16bits(uint16_t *src_buf, uint16_t *dst_buf, uint32_t src_len)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; ++i) {
|
||||
dst_buf[i*2 + 0] = dst_buf[i*2 + 1] = src_buf[i];
|
||||
}
|
||||
static void copy_one_trace_to_two_track_16bits(uint16_t *src_buf,
|
||||
uint16_t *dst_buf,
|
||||
uint32_t src_len) {
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; ++i) {
|
||||
dst_buf[i * 2 + 0] = dst_buf[i * 2 + 1] = src_buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
int store_flac_buffer(unsigned char *buf, unsigned int len)
|
||||
{
|
||||
LOCK_FLAC_QUEUE();
|
||||
EnCQueue(&flac_queue, buf, len);
|
||||
if (LengthOfCQueue(&flac_queue) > FLAC_TEMP_BUFFER_SIZE*2) {
|
||||
ok_to_decode = 1;
|
||||
}
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
int store_flac_buffer(unsigned char *buf, unsigned int len) {
|
||||
LOCK_FLAC_QUEUE();
|
||||
EnCQueue(&flac_queue, buf, len);
|
||||
if (LengthOfCQueue(&flac_queue) > FLAC_TEMP_BUFFER_SIZE * 2) {
|
||||
ok_to_decode = 1;
|
||||
}
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int decode_flac_frame(unsigned char *pcm_buffer, unsigned int pcm_len)
|
||||
{
|
||||
uint32_t r = 0, got_len = 0;
|
||||
unsigned char *e1 = NULL, *e2 = NULL;
|
||||
unsigned int len1 = 0, len2 = 0;
|
||||
int decode_flac_frame(unsigned char *pcm_buffer, unsigned int pcm_len) {
|
||||
uint32_t r = 0, got_len = 0;
|
||||
unsigned char *e1 = NULL, *e2 = NULL;
|
||||
unsigned int len1 = 0, len2 = 0;
|
||||
get_again:
|
||||
LOCK_FLAC_QUEUE();
|
||||
r = PeekCQueue(&flac_queue, (pcm_len - got_len)/2, &e1, &len1, &e2, &len2);
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
LOCK_FLAC_QUEUE();
|
||||
r = PeekCQueue(&flac_queue, (pcm_len - got_len) / 2, &e1, &len1, &e2, &len2);
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
|
||||
if(r == CQ_ERR || len1 == 0) {
|
||||
osDelay(2);
|
||||
goto get_again;
|
||||
}
|
||||
if (r == CQ_ERR || len1 == 0) {
|
||||
osDelay(2);
|
||||
goto get_again;
|
||||
}
|
||||
|
||||
//memcpy(pcm_buffer + got_len, e1, len1);
|
||||
copy_one_trace_to_two_track_16bits((uint16_t *)e1, (uint16_t *)(pcm_buffer + got_len), len1/2);
|
||||
// memcpy(pcm_buffer + got_len, e1, len1);
|
||||
copy_one_trace_to_two_track_16bits(
|
||||
(uint16_t *)e1, (uint16_t *)(pcm_buffer + got_len), len1 / 2);
|
||||
|
||||
LOCK_FLAC_QUEUE();
|
||||
DeCQueue(&flac_queue, 0, len1);
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
|
||||
got_len += len1 * 2;
|
||||
|
||||
if (len2 != 0) {
|
||||
// memcpy(pcm_buffer + got_len, e2, len2);
|
||||
copy_one_trace_to_two_track_16bits(
|
||||
(uint16_t *)e2, (uint16_t *)(pcm_buffer + got_len), len2 / 2);
|
||||
|
||||
LOCK_FLAC_QUEUE();
|
||||
DeCQueue(&flac_queue, 0, len1);
|
||||
DeCQueue(&flac_queue, 0, len2);
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
}
|
||||
|
||||
got_len += len1*2;
|
||||
got_len += len2 * 2;
|
||||
|
||||
if (len2 != 0) {
|
||||
//memcpy(pcm_buffer + got_len, e2, len2);
|
||||
copy_one_trace_to_two_track_16bits((uint16_t *)e2, (uint16_t *)(pcm_buffer + got_len), len2/2);
|
||||
if (got_len < pcm_len)
|
||||
goto get_again;
|
||||
|
||||
LOCK_FLAC_QUEUE();
|
||||
DeCQueue(&flac_queue, 0, len2);
|
||||
UNLOCK_FLAC_QUEUE();
|
||||
}
|
||||
|
||||
got_len += len2*2;
|
||||
|
||||
if (got_len < pcm_len)
|
||||
goto get_again;
|
||||
|
||||
return pcm_len;
|
||||
return pcm_len;
|
||||
}
|
||||
|
||||
uint32_t flac_audio_data_come(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
TRACE(1,"data come %d\n", len);
|
||||
uint32_t flac_audio_data_come(uint8_t *buf, uint32_t len) {
|
||||
TRACE(1, "data come %d\n", len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t flac_audio_more_data(uint8_t *buf, uint32_t len) {
|
||||
uint32_t l = 0;
|
||||
// uint32_t cur_ticks = 0, ticks = 0;
|
||||
|
||||
if (ok_to_decode == 0)
|
||||
return 0;
|
||||
|
||||
// ticks = hal_sys_timer_get();
|
||||
l = decode_flac_frame(buf, len);
|
||||
// cur_ticks = hal_sys_timer_get();
|
||||
// TRACE(1,"flac %d t\n", (cur_ticks-ticks));
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
uint32_t flac_audio_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t l = 0;
|
||||
//uint32_t cur_ticks = 0, ticks = 0;
|
||||
int flac_audio_init(void) {
|
||||
g_flac_queue_mutex_id = osMutexCreate((osMutex(g_flac_queue_mutex)));
|
||||
/* flac queue*/
|
||||
InitCQueue(&flac_queue, FLAC_QUEUE_SIZE, (unsigned char *)&flac_queue_buf);
|
||||
|
||||
if (ok_to_decode == 0)
|
||||
return 0;
|
||||
|
||||
//ticks = hal_sys_timer_get();
|
||||
l = decode_flac_frame(buf, len);
|
||||
//cur_ticks = hal_sys_timer_get();
|
||||
// TRACE(1,"flac %d t\n", (cur_ticks-ticks));
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
int flac_audio_init(void)
|
||||
{
|
||||
g_flac_queue_mutex_id = osMutexCreate((osMutex(g_flac_queue_mutex)));
|
||||
/* flac queue*/
|
||||
InitCQueue(&flac_queue, FLAC_QUEUE_SIZE, (unsigned char *)&flac_queue_buf);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,154 +15,151 @@
|
|||
****************************************************************************/
|
||||
#ifdef CHIP_BEST1000
|
||||
|
||||
#include "app_audio.h"
|
||||
#include "app_overlay.h"
|
||||
#include "app_utils.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cmsis.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "cqueue.h"
|
||||
#include "fmdec.h"
|
||||
#include "hal_dma.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_cmu.h"
|
||||
#include "hal_analogif.h"
|
||||
#include "hal_chipid.h"
|
||||
#include "audioflinger.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "cqueue.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_utils.h"
|
||||
#include "app_overlay.h"
|
||||
#include "string.h"
|
||||
#include "hal_cmu.h"
|
||||
#include "hal_dma.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "pmu.h"
|
||||
#include "string.h"
|
||||
|
||||
//#define FM_DEBUG 1
|
||||
|
||||
#define FM_DIGITAL_REG(a) *(volatile uint32_t *)(a)
|
||||
#define fm_read_rf_reg(reg,val) hal_analogif_reg_read(reg,val)
|
||||
#define fm_write_rf_reg(reg,val) hal_analogif_reg_write(reg,val)
|
||||
#define fm_read_rf_reg(reg, val) hal_analogif_reg_read(reg, val)
|
||||
#define fm_write_rf_reg(reg, val) hal_analogif_reg_write(reg, val)
|
||||
|
||||
#define FM_FRAME_NUM 4
|
||||
#define FM_SAMPLE_NUM NUMOFSAMPLE
|
||||
|
||||
#ifdef ATAN2_HARDWARE
|
||||
#ifdef FM_NEWMODE
|
||||
#define FM_SAMPLE_BUFFER_SIZE (FM_FRAME_NUM*FM_SAMPLE_NUM*4)
|
||||
#define FM_SAMPLE_BUFFER_SIZE (FM_FRAME_NUM * FM_SAMPLE_NUM * 4)
|
||||
#else
|
||||
#define FM_SAMPLE_BUFFER_SIZE (FM_FRAME_NUM*FM_SAMPLE_NUM/2*4)
|
||||
#define FM_SAMPLE_BUFFER_SIZE (FM_FRAME_NUM * FM_SAMPLE_NUM / 2 * 4)
|
||||
#endif
|
||||
#else
|
||||
#define FM_SAMPLE_BUFFER_SIZE (FM_FRAME_NUM*FM_SAMPLE_NUM*4)
|
||||
#define FM_SAMPLE_BUFFER_SIZE (FM_FRAME_NUM * FM_SAMPLE_NUM * 4)
|
||||
#endif
|
||||
#define FM_AUDIO_BUFFER_SIZE (4096)
|
||||
|
||||
extern int app_bt_stream_local_volume_get(void);
|
||||
static int32_t *fm_sample_buffer_p;
|
||||
|
||||
static void fm_handler(uint8_t chan, uint32_t remains, uint32_t error, struct HAL_DMA_DESC_T *lli)
|
||||
{
|
||||
static int cnt = 0;
|
||||
int16_t fm_decbuf[(FM_SAMPLE_NUM/9)];
|
||||
FmDemodulate((int16_t *)(fm_sample_buffer_p +((cnt%FM_FRAME_NUM)*FM_SAMPLE_NUM)), fm_decbuf,FM_SAMPLE_NUM);
|
||||
cnt++;
|
||||
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM/9)<<1);
|
||||
FmDemodulate((int16_t *)(fm_sample_buffer_p +((cnt%FM_FRAME_NUM)*FM_SAMPLE_NUM)), fm_decbuf,FM_SAMPLE_NUM);
|
||||
cnt++;
|
||||
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM/9)<<1);
|
||||
static void fm_handler(uint8_t chan, uint32_t remains, uint32_t error,
|
||||
struct HAL_DMA_DESC_T *lli) {
|
||||
static int cnt = 0;
|
||||
int16_t fm_decbuf[(FM_SAMPLE_NUM / 9)];
|
||||
FmDemodulate(
|
||||
(int16_t *)(fm_sample_buffer_p + ((cnt % FM_FRAME_NUM) * FM_SAMPLE_NUM)),
|
||||
fm_decbuf, FM_SAMPLE_NUM);
|
||||
cnt++;
|
||||
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM / 9) << 1);
|
||||
FmDemodulate(
|
||||
(int16_t *)(fm_sample_buffer_p + ((cnt % FM_FRAME_NUM) * FM_SAMPLE_NUM)),
|
||||
fm_decbuf, FM_SAMPLE_NUM);
|
||||
cnt++;
|
||||
app_audio_pcmbuff_put((uint8_t *)fm_decbuf, (FM_SAMPLE_NUM / 9) << 1);
|
||||
|
||||
#ifdef FM_DEBUG
|
||||
{
|
||||
static uint32_t preTicks;
|
||||
uint32_t diff_ticks = 0;
|
||||
uint32_t cur_ticks;
|
||||
{
|
||||
static uint32_t preTicks;
|
||||
uint32_t diff_ticks = 0;
|
||||
uint32_t cur_ticks;
|
||||
|
||||
cur_ticks = hal_sys_timer_get();
|
||||
if (!preTicks){
|
||||
preTicks = cur_ticks;
|
||||
}else{
|
||||
diff_ticks = TICKS_TO_MS(cur_ticks - preTicks);
|
||||
preTicks = cur_ticks;
|
||||
}
|
||||
TRACE(3,"[fm_handler] diff=%d add:%d remain:%d input", diff_ticks, (FM_SAMPLE_NUM/9)<<1, app_audio_pcmbuff_length());
|
||||
cur_ticks = hal_sys_timer_get();
|
||||
if (!preTicks) {
|
||||
preTicks = cur_ticks;
|
||||
} else {
|
||||
diff_ticks = TICKS_TO_MS(cur_ticks - preTicks);
|
||||
preTicks = cur_ticks;
|
||||
}
|
||||
TRACE(3, "[fm_handler] diff=%d add:%d remain:%d input", diff_ticks,
|
||||
(FM_SAMPLE_NUM / 9) << 1, app_audio_pcmbuff_length());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t fm_pcm_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
app_audio_pcmbuff_get(buf, len);
|
||||
uint32_t fm_pcm_more_data(uint8_t *buf, uint32_t len) {
|
||||
app_audio_pcmbuff_get(buf, len);
|
||||
#ifdef FM_DEBUG
|
||||
{
|
||||
static uint32_t preTicks;
|
||||
uint32_t diff_ticks = 0;
|
||||
uint32_t cur_ticks= hal_sys_timer_get();
|
||||
if (!preTicks){
|
||||
preTicks = cur_ticks;
|
||||
}else{
|
||||
diff_ticks = TICKS_TO_MS(cur_ticks - preTicks);
|
||||
preTicks = cur_ticks;
|
||||
}
|
||||
|
||||
TRACE(5,"[fm_pcm_more_data] diff=%d get:%d remain:%d output isr:0x%08x cnt:%d", diff_ticks, len/2, app_audio_pcmbuff_length(), FM_DIGITAL_REG(0x40160020), FM_DIGITAL_REG(0x40160028));
|
||||
{
|
||||
static uint32_t preTicks;
|
||||
uint32_t diff_ticks = 0;
|
||||
uint32_t cur_ticks = hal_sys_timer_get();
|
||||
if (!preTicks) {
|
||||
preTicks = cur_ticks;
|
||||
} else {
|
||||
diff_ticks = TICKS_TO_MS(cur_ticks - preTicks);
|
||||
preTicks = cur_ticks;
|
||||
}
|
||||
|
||||
TRACE(
|
||||
5,
|
||||
"[fm_pcm_more_data] diff=%d get:%d remain:%d output isr:0x%08x cnt:%d",
|
||||
diff_ticks, len / 2, app_audio_pcmbuff_length(),
|
||||
FM_DIGITAL_REG(0x40160020), FM_DIGITAL_REG(0x40160028));
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t fm_capture_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
fm_handler(0,0,0,NULL);
|
||||
return len;
|
||||
uint32_t fm_capture_more_data(uint8_t *buf, uint32_t len) {
|
||||
fm_handler(0, 0, 0, NULL);
|
||||
return len;
|
||||
}
|
||||
|
||||
void fm_radio_digit_init(void)
|
||||
{
|
||||
FM_DIGITAL_REG(0xd0350244) = (FM_DIGITAL_REG(0xd0350244) & ~0x01fff) | 0x20f; //-890k -> 0 if_shift, for 110.5292m adc
|
||||
|
||||
// FM_DIGITAL_REG(0x40180e0c) = 0x34;
|
||||
//FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) | 0x18000;
|
||||
|
||||
|
||||
void fm_radio_digit_init(void) {
|
||||
FM_DIGITAL_REG(0xd0350244) = (FM_DIGITAL_REG(0xd0350244) & ~0x01fff) |
|
||||
0x20f; //-890k -> 0 if_shift, for 110.5292m adc
|
||||
|
||||
// FM_DIGITAL_REG(0x40180e0c) = 0x34;
|
||||
// FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) |
|
||||
// 0x18000;
|
||||
|
||||
#ifdef ATAN2_HARDWARE
|
||||
|
||||
|
||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 17);
|
||||
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
||||
// FM_DIGITAL_REG(0x40160030) = 1;
|
||||
// FM_DIGITAL_REG(0x40160000) = 0x21;
|
||||
|
||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 17);
|
||||
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
||||
// FM_DIGITAL_REG(0x40160030) = 1;
|
||||
// FM_DIGITAL_REG(0x40160000) = 0x21;
|
||||
|
||||
#else
|
||||
|
||||
|
||||
|
||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
||||
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
||||
// FM_DIGITAL_REG(0x40160030) = 1;
|
||||
// FM_DIGITAL_REG(0x40160000) = 1;
|
||||
FM_DIGITAL_REG(0xd0330038) |= (1 << 11);
|
||||
FM_DIGITAL_REG(0xd0350248) = 0x80c00000;
|
||||
// FM_DIGITAL_REG(0x40160030) = 1;
|
||||
// FM_DIGITAL_REG(0x40160000) = 1;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef SINGLECHANLE
|
||||
//0x4000a010 bit2 写0 单channel dac
|
||||
FM_DIGITAL_REG(0x4000a010) = (1 << 5) |(1<<4);
|
||||
// 0x4000a010 bit2 写0 单channel dac
|
||||
FM_DIGITAL_REG(0x4000a010) = (1 << 5) | (1 << 4);
|
||||
#else
|
||||
|
||||
FM_DIGITAL_REG(0x4000a010) = (1 << 5) | (1 << 2)|(1<<4);
|
||||
FM_DIGITAL_REG(0x4000a010) = (1 << 5) | (1 << 2) | (1 << 4);
|
||||
#endif
|
||||
|
||||
FM_DIGITAL_REG(0x4000a020) = ~0UL;
|
||||
FM_DIGITAL_REG(0x4000a02c) = 4;
|
||||
FM_DIGITAL_REG(0x4000a030) = 4;
|
||||
|
||||
FM_DIGITAL_REG(0x4000a034) = (1 << 2) | (1 << 1) | (1 << 0);
|
||||
|
||||
FM_DIGITAL_REG(0x4000a020) = ~0UL;
|
||||
FM_DIGITAL_REG(0x4000a02c) = 4;
|
||||
FM_DIGITAL_REG(0x4000a030) = 4;
|
||||
|
||||
FM_DIGITAL_REG(0x4000a034) = (1 << 2) | (1 << 1) | (1 << 0);
|
||||
|
||||
// Start DAC
|
||||
// FM_DIGITAL_REG(0x4000a010) |= (1 << 1);
|
||||
// Start DAC
|
||||
// FM_DIGITAL_REG(0x4000a010) |= (1 << 1);
|
||||
|
||||
#if 0
|
||||
//52M
|
||||
|
@ -185,345 +182,324 @@ void fm_radio_digit_init(void)
|
|||
FM_DIGITAL_REG(0x40000064) = (FM_DIGITAL_REG(0x40000064) & ~0xFF) | 0x7A | (1 << 10) | (1<<30);
|
||||
#endif
|
||||
|
||||
FM_DIGITAL_REG(0x4000a040) = 0xc0810000;
|
||||
FM_DIGITAL_REG(0x4000a044) = 0x08040c04;
|
||||
FM_DIGITAL_REG(0x4000a048) = 0x0e01f268;
|
||||
FM_DIGITAL_REG(0x4000a04c) = 0x00005100;
|
||||
// FM_DIGITAL_REG(0x40010010) = 0;
|
||||
// FM_DIGITAL_REG(0x40010014) = 0x03a80005;
|
||||
//FM_DIGITAL_REG(0x40010018) = 0x00200019;
|
||||
FM_DIGITAL_REG(0x4000a050) = 0x24200000; //for adc_div_3_6 bypass
|
||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x780) | 0x380; // for channel 1 adc volume, bit10~7
|
||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) | 0x18000; // for dual channel adc/dac
|
||||
FM_DIGITAL_REG(0x4000a040) = 0xc0810000;
|
||||
FM_DIGITAL_REG(0x4000a044) = 0x08040c04;
|
||||
FM_DIGITAL_REG(0x4000a048) = 0x0e01f268;
|
||||
FM_DIGITAL_REG(0x4000a04c) = 0x00005100;
|
||||
// FM_DIGITAL_REG(0x40010010) = 0;
|
||||
// FM_DIGITAL_REG(0x40010014) = 0x03a80005;
|
||||
// FM_DIGITAL_REG(0x40010018) = 0x00200019;
|
||||
FM_DIGITAL_REG(0x4000a050) = 0x24200000; // for adc_div_3_6 bypass
|
||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x780) |
|
||||
0x380; // for channel 1 adc volume, bit10~7
|
||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~0x18000) |
|
||||
0x18000; // for dual channel adc/dac
|
||||
|
||||
#ifdef SINGLECHANLE
|
||||
//0x4000a050 bit16 写0 单channel dac for codec
|
||||
FM_DIGITAL_REG(0x4000a050) =(FM_DIGITAL_REG(0x4000a050) & ~ (1 << 16));
|
||||
// 0x4000a050 bit16 写0 单channel dac for codec
|
||||
FM_DIGITAL_REG(0x4000a050) = (FM_DIGITAL_REG(0x4000a050) & ~(1 << 16));
|
||||
#endif
|
||||
|
||||
FM_DIGITAL_REG(0x4000a048) = (FM_DIGITAL_REG(0x4000a048) & ~0x00000f00) |
|
||||
0x40000900; // set for sdm gain
|
||||
FM_DIGITAL_REG(0x4000a044) = (FM_DIGITAL_REG(0x4000a044) & ~0x60000000) |
|
||||
0x60000000; // for adc en, and dac en
|
||||
|
||||
FM_DIGITAL_REG(0x4000a048) = (FM_DIGITAL_REG(0x4000a048) & ~0x00000f00) | 0x40000900; //set for sdm gain
|
||||
FM_DIGITAL_REG(0x4000a044) = (FM_DIGITAL_REG(0x4000a044) & ~0x60000000) | 0x60000000; //for adc en, and dac en
|
||||
// Start DAC
|
||||
FM_DIGITAL_REG(0x4000a010) |= (1 << 1);
|
||||
|
||||
// Start DAC
|
||||
FM_DIGITAL_REG(0x4000a010) |= (1 << 1);
|
||||
|
||||
|
||||
|
||||
// Delay 2 ms
|
||||
// for (volatile int kk = 0; kk < 1000/64; kk++);
|
||||
osDelay(2);
|
||||
|
||||
//hal_sys_timer_delay(MS_TO_TICKS(2));
|
||||
// Start ADC
|
||||
// FM_DIGITAL_REG(0x4000a010) |= (1 << 0);
|
||||
// Delay 2 ms
|
||||
// for (volatile int kk = 0; kk < 1000/64; kk++);
|
||||
osDelay(2);
|
||||
|
||||
// hal_sys_timer_delay(MS_TO_TICKS(2));
|
||||
// Start ADC
|
||||
// FM_DIGITAL_REG(0x4000a010) |= (1 << 0);
|
||||
|
||||
#ifdef ATAN2_HARDWARE
|
||||
|
||||
|
||||
#ifdef FM_NEWMODE
|
||||
FM_DIGITAL_REG(0x40160030) = 1;
|
||||
FM_DIGITAL_REG(0x40160000) = 0x1;
|
||||
FM_DIGITAL_REG(0x40160030) = 1;
|
||||
FM_DIGITAL_REG(0x40160000) = 0x1;
|
||||
|
||||
#else
|
||||
FM_DIGITAL_REG(0x40160030) = 1;
|
||||
FM_DIGITAL_REG(0x40160000) = 0x21;
|
||||
FM_DIGITAL_REG(0x40160030) = 1;
|
||||
FM_DIGITAL_REG(0x40160000) = 0x21;
|
||||
#endif
|
||||
|
||||
#else
|
||||
//start FM
|
||||
FM_DIGITAL_REG(0x40160030) = 1;
|
||||
FM_DIGITAL_REG(0x40160000) =1;
|
||||
// start FM
|
||||
FM_DIGITAL_REG(0x40160030) = 1;
|
||||
FM_DIGITAL_REG(0x40160000) = 1;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int fm_radio_analog_init(void)
|
||||
int fm_radio_analog_init(void) {
|
||||
int ret;
|
||||
|
||||
/*
|
||||
|
||||
// fm initial
|
||||
rfspi_wvalue( 8'h2c , 16'b0111_0000_0101_1100 ) ; // dig_vtoi_en
|
||||
rfspi_wvalue( 8'h01 , 16'b1010_1101_1111_1111 ) ; // power on fm lna
|
||||
rfspi_wvalue( 8'h02 , 16'b1000_0000_1001_0100 ) ; // reg_fm_lna_pu_mixersw
|
||||
|
||||
rfspi_wvalue( 8'h1a , 16'b0101_0000_1011_0000 ) ; //
|
||||
reg_bt_vco_fm_buff_vctrl_dr=1
|
||||
|
||||
rfspi_wvalue( 8'h18 , 16'b0000_0110_1000_0000 ) ; // power on vco
|
||||
|
||||
rfspi_wvalue( 8'h19 , 16'b0110_0100_0100_0000 ) ; // reg_bt_vco_fm_buff_vctrl
|
||||
rfspi_wvalue( 8'h1d , 16'b0111_1000_1010_0100 ) ; // reg_bt_rfpll_pu_dr
|
||||
rfspi_wvalue( 8'h1c , 16'b0000_0000_1100_1000 ) ; // reg_bt_vco_fm_lo_en
|
||||
reg_bt_vco_fm_div_ctrl=8
|
||||
|
||||
rfspi_wvalue( 8'h0a , 16'b0001_0010_0010_1111 ) ; // reg_btfm_flt_fm_en
|
||||
|
||||
rfspi_wvalue( 8'h2d , 16'b0000_0111_1000_0010 ) ; // bb ldo on
|
||||
reg_bb_ldo_pu_vddr15a_dr rfspi_wvalue( 8'h07 , 16'b0000_0010_1011_1001 ) ; //
|
||||
reg_btfm_flt_pu_dr
|
||||
|
||||
rfspi_wvalue( 8'h2a , 16'b0001_0110_1100_0000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
||||
rfspi_wvalue( 8'h26 , 16'b0000_0000_0000_0000 ) ; // vco freq[31:16] ( 2400 +
|
||||
x )*2^25/26MHZ*N (2400+x= frf) rfspi_wvalue( 8'h25 , 16'b0000_0000_0000_0000 )
|
||||
; // vco freq[15:00] fm_freq = frf/(4*reg_bt_vco_fm_div_ctrl) rfspi_wvalue(
|
||||
8'h17 , 16'b1000_0000_0000_0000 ) ; // reg_bt_vco_calen
|
||||
|
||||
*/
|
||||
|
||||
fm_write_rf_reg(0x2c, 0b0111000001011100); // dig_vtoi_en
|
||||
fm_write_rf_reg(0x01, 0b1010110111111111); // power on fm lna
|
||||
fm_write_rf_reg(0x02, 0b1000000010010100); // reg_fm_lna_pu_mixersw
|
||||
|
||||
fm_write_rf_reg(0x1a, 0b0101000010110000); // reg_bt_vco_fm_buff_vctrl_dr=1
|
||||
|
||||
fm_write_rf_reg(0x18, 0b0000011010000000); // power on vco
|
||||
|
||||
fm_write_rf_reg(0x19, 0b0110010001000000); // reg_bt_vco_fm_buff_vctrl
|
||||
fm_write_rf_reg(0x1d, 0b0111100010100100); // reg_bt_rfpll_pu_dr
|
||||
fm_write_rf_reg(
|
||||
0x1c, 0b0000000011001000); // reg_bt_vco_fm_lo_en reg_bt_vco_fm_div_ctrl=8
|
||||
|
||||
fm_write_rf_reg(0x0a, 0b0001001000101111); // reg_btfm_flt_fm_en
|
||||
|
||||
fm_write_rf_reg(0x2d,
|
||||
0b0000011110000010); // bb ldo on reg_bb_ldo_pu_vddr15a_dr
|
||||
fm_write_rf_reg(0x07, 0b0000001010111001); // reg_btfm_flt_pu_dr
|
||||
|
||||
fm_write_rf_reg(0x2a, 0b0001011011000000); // reg_bt_rfpll_sdm_freq_dr
|
||||
fm_write_rf_reg(0x26, 0b0000000000000000); // vco freq[31:16] ( 2400 + x
|
||||
// )*2^25/26MHZ*N (2400+x= frf)
|
||||
fm_write_rf_reg(0x25, 0b0000000000000000); // vco freq[15:00] fm_freq =
|
||||
// frf/(4*reg_bt_vco_fm_div_ctrl)
|
||||
fm_write_rf_reg(0x17, 0b1000000000000000); // reg_bt_vco_calen
|
||||
|
||||
// adc也要开的话,需要配 cmu
|
||||
// 0x40000060[29] = 1 最好先读再写,否则把别的bit冲掉了。
|
||||
|
||||
//需要配置的spi寄存器:ana interface:
|
||||
|
||||
// 0x05 = 0xFCB1 // Audio Pll
|
||||
// 0x06 = 0x881C
|
||||
// 0x31 = 0x0100 // audio_freq_en
|
||||
// 0x37 = 0x1000 // codec_bbpll1_fm_adc_clk_en
|
||||
// 0x31 = 0x0130 // codec_tx_en_ldac codec_tx_en_rdac
|
||||
|
||||
ret = fm_write_rf_reg(0x05, 0xfcb1);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x06, 0x881c);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = fm_write_rf_reg(0x3a, 0xe644);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x31, 0x0100);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x37, 0x1000);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x31, 0x01f0);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// delay 32ms
|
||||
osDelay(32);
|
||||
|
||||
ret = fm_write_rf_reg(0x31, 0x0130);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//[FM_RX]
|
||||
fm_write_rf_reg(0x01, 0x91ff); // pu fm
|
||||
fm_write_rf_reg(0x2d, 0x07fa); // ldo on
|
||||
fm_write_rf_reg(0x2e, 0x6aaa); // tune fm filter IF
|
||||
fm_write_rf_reg(0x02, 0xe694);
|
||||
fm_write_rf_reg(0x03, 0xfe3a);
|
||||
fm_write_rf_reg(0x04, 0x52a8);
|
||||
fm_write_rf_reg(0x07, 0x02b9);
|
||||
fm_write_rf_reg(0x0a, 0x1a2c);
|
||||
fm_write_rf_reg(0x0b, 0x402b);
|
||||
fm_write_rf_reg(0x0c, 0x7584);
|
||||
fm_write_rf_reg(0x0e, 0x0000);
|
||||
fm_write_rf_reg(0x0f, 0x2e18);
|
||||
fm_write_rf_reg(0x10, 0x02b4);
|
||||
fm_write_rf_reg(0x13, 0x0a48);
|
||||
|
||||
//[vco init]
|
||||
fm_write_rf_reg(0x18, 0x077f);
|
||||
fm_write_rf_reg(0x19, 0x3ff8);
|
||||
fm_write_rf_reg(0x1a, 0xc090);
|
||||
fm_write_rf_reg(0x1b, 0x0f88);
|
||||
fm_write_rf_reg(0x1c, 0x04c6); //[3:0] 5,6,7,8 --> vco/2
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fm_radio_poweron(void)
|
||||
|
||||
{
|
||||
int ret;
|
||||
hal_cmu_reset_clear(HAL_CMU_MOD_BTCPU);
|
||||
osDelay(2000);
|
||||
|
||||
{
|
||||
// wakp interface
|
||||
unsigned short read_val;
|
||||
|
||||
/*
|
||||
fm_read_rf_reg(0x50, &read_val);
|
||||
}
|
||||
|
||||
// fm initial
|
||||
rfspi_wvalue( 8'h2c , 16'b0111_0000_0101_1100 ) ; // dig_vtoi_en
|
||||
rfspi_wvalue( 8'h01 , 16'b1010_1101_1111_1111 ) ; // power on fm lna
|
||||
rfspi_wvalue( 8'h02 , 16'b1000_0000_1001_0100 ) ; // reg_fm_lna_pu_mixersw
|
||||
pmu_fm_config(1);
|
||||
|
||||
rfspi_wvalue( 8'h1a , 16'b0101_0000_1011_0000 ) ; // reg_bt_vco_fm_buff_vctrl_dr=1
|
||||
fm_write_rf_reg(0x0c, 0x3584);
|
||||
if (hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_2 ||
|
||||
hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_3) ////
|
||||
{
|
||||
FM_DIGITAL_REG(0xc00003b4) = 0x00060020; // turn off bt sleep
|
||||
} else if (hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_4) {
|
||||
FM_DIGITAL_REG(0xc00003b0) = 0x00060020; // turn off bt sleep
|
||||
} else {
|
||||
FM_DIGITAL_REG(0xc00003ac) = 0x00060020; // turn off bt sleep
|
||||
}
|
||||
FM_DIGITAL_REG(0xd0330038) = 0x00008D0D;
|
||||
FM_DIGITAL_REG(0xd0340020) = 0x010E01C0; // open ana rxon for open adc clk
|
||||
// fm_write_rf_reg(0x02, 0xe694);
|
||||
}
|
||||
|
||||
rfspi_wvalue( 8'h18 , 16'b0000_0110_1000_0000 ) ; // power on vco
|
||||
void *fm_radio_get_ext_buff(int size) {
|
||||
uint8_t *pBuff = NULL;
|
||||
size = size + size % 4;
|
||||
app_audio_mempool_get_buff(&pBuff, size);
|
||||
return (void *)pBuff;
|
||||
}
|
||||
|
||||
rfspi_wvalue( 8'h19 , 16'b0110_0100_0100_0000 ) ; // reg_bt_vco_fm_buff_vctrl
|
||||
rfspi_wvalue( 8'h1d , 16'b0111_1000_1010_0100 ) ; // reg_bt_rfpll_pu_dr
|
||||
rfspi_wvalue( 8'h1c , 16'b0000_0000_1100_1000 ) ; // reg_bt_vco_fm_lo_en reg_bt_vco_fm_div_ctrl=8
|
||||
|
||||
rfspi_wvalue( 8'h0a , 16'b0001_0010_0010_1111 ) ; // reg_btfm_flt_fm_en
|
||||
|
||||
rfspi_wvalue( 8'h2d , 16'b0000_0111_1000_0010 ) ; // bb ldo on reg_bb_ldo_pu_vddr15a_dr
|
||||
rfspi_wvalue( 8'h07 , 16'b0000_0010_1011_1001 ) ; // reg_btfm_flt_pu_dr
|
||||
|
||||
rfspi_wvalue( 8'h2a , 16'b0001_0110_1100_0000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
||||
rfspi_wvalue( 8'h26 , 16'b0000_0000_0000_0000 ) ; // vco freq[31:16] ( 2400 + x )*2^25/26MHZ*N (2400+x= frf)
|
||||
rfspi_wvalue( 8'h25 , 16'b0000_0000_0000_0000 ) ; // vco freq[15:00] fm_freq = frf/(4*reg_bt_vco_fm_div_ctrl)
|
||||
rfspi_wvalue( 8'h17 , 16'b1000_0000_0000_0000 ) ; // reg_bt_vco_calen
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fm_write_rf_reg( 0x2c , 0b0111000001011100 ) ; // dig_vtoi_en
|
||||
fm_write_rf_reg( 0x01 , 0b1010110111111111 ) ; // power on fm lna
|
||||
fm_write_rf_reg( 0x02 , 0b1000000010010100 ) ; // reg_fm_lna_pu_mixersw
|
||||
|
||||
fm_write_rf_reg( 0x1a , 0b0101000010110000 ) ; // reg_bt_vco_fm_buff_vctrl_dr=1
|
||||
|
||||
fm_write_rf_reg( 0x18 , 0b0000011010000000 ) ; // power on vco
|
||||
|
||||
fm_write_rf_reg( 0x19 , 0b0110010001000000 ) ; // reg_bt_vco_fm_buff_vctrl
|
||||
fm_write_rf_reg( 0x1d , 0b0111100010100100 ) ; // reg_bt_rfpll_pu_dr
|
||||
fm_write_rf_reg( 0x1c , 0b0000000011001000 ) ; // reg_bt_vco_fm_lo_en reg_bt_vco_fm_div_ctrl=8
|
||||
|
||||
fm_write_rf_reg( 0x0a , 0b0001001000101111 ) ; // reg_btfm_flt_fm_en
|
||||
|
||||
fm_write_rf_reg( 0x2d , 0b0000011110000010 ) ; // bb ldo on reg_bb_ldo_pu_vddr15a_dr
|
||||
fm_write_rf_reg( 0x07 , 0b0000001010111001 ) ; // reg_btfm_flt_pu_dr
|
||||
|
||||
fm_write_rf_reg( 0x2a , 0b0001011011000000 ) ; // reg_bt_rfpll_sdm_freq_dr
|
||||
fm_write_rf_reg( 0x26 , 0b0000000000000000 ) ; // vco freq[31:16] ( 2400 + x )*2^25/26MHZ*N (2400+x= frf)
|
||||
fm_write_rf_reg( 0x25 , 0b0000000000000000 ) ; // vco freq[15:00] fm_freq = frf/(4*reg_bt_vco_fm_div_ctrl)
|
||||
fm_write_rf_reg( 0x17 , 0b1000000000000000 ) ; // reg_bt_vco_calen
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//adc也要开的话,需要配 cmu
|
||||
//0x40000060[29] = 1 最好先读再写,否则把别的bit冲掉了。
|
||||
|
||||
|
||||
|
||||
|
||||
//需要配置的spi寄存器:ana interface:
|
||||
|
||||
//0x05 = 0xFCB1 // Audio Pll
|
||||
//0x06 = 0x881C
|
||||
//0x31 = 0x0100 // audio_freq_en
|
||||
//0x37 = 0x1000 // codec_bbpll1_fm_adc_clk_en
|
||||
//0x31 = 0x0130 // codec_tx_en_ldac codec_tx_en_rdac
|
||||
|
||||
|
||||
ret = fm_write_rf_reg(0x05 , 0xfcb1);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x06 , 0x881c);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = fm_write_rf_reg(0x3a , 0xe644);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x31 , 0x0100);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x37 , 0x1000);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
ret = fm_write_rf_reg(0x31 , 0x01f0);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//delay 32ms
|
||||
osDelay(32);
|
||||
|
||||
|
||||
ret = fm_write_rf_reg(0x31 , 0x0130);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
//[FM_RX]
|
||||
fm_write_rf_reg(0x01,0x91ff); //pu fm
|
||||
fm_write_rf_reg(0x2d,0x07fa); //ldo on
|
||||
fm_write_rf_reg(0x2e,0x6aaa); //tune fm filter IF
|
||||
fm_write_rf_reg(0x02,0xe694);
|
||||
fm_write_rf_reg(0x03,0xfe3a);
|
||||
fm_write_rf_reg(0x04,0x52a8);
|
||||
fm_write_rf_reg(0x07,0x02b9);
|
||||
fm_write_rf_reg(0x0a,0x1a2c);
|
||||
fm_write_rf_reg(0x0b,0x402b);
|
||||
fm_write_rf_reg(0x0c,0x7584);
|
||||
fm_write_rf_reg(0x0e,0x0000);
|
||||
fm_write_rf_reg(0x0f,0x2e18);
|
||||
fm_write_rf_reg(0x10,0x02b4);
|
||||
fm_write_rf_reg(0x13,0x0a48);
|
||||
|
||||
//[vco init]
|
||||
fm_write_rf_reg(0x18,0x077f);
|
||||
fm_write_rf_reg(0x19,0x3ff8);
|
||||
fm_write_rf_reg(0x1a,0xc090);
|
||||
fm_write_rf_reg(0x1b,0x0f88);
|
||||
fm_write_rf_reg(0x1c,0x04c6); //[3:0] 5,6,7,8 --> vco/2
|
||||
int fm_radio_player(bool on) {
|
||||
static struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static bool isRun = false;
|
||||
uint8_t *buff = NULL;
|
||||
|
||||
TRACE(2, "fm_radio_player work:%d op:%d", isRun, on);
|
||||
if (isRun == on)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fm_radio_poweron(void)
|
||||
|
||||
{
|
||||
hal_cmu_reset_clear(HAL_CMU_MOD_BTCPU);
|
||||
osDelay(2000);
|
||||
|
||||
{
|
||||
//wakp interface
|
||||
unsigned short read_val;
|
||||
|
||||
fm_read_rf_reg(0x50, &read_val);
|
||||
}
|
||||
|
||||
pmu_fm_config(1);
|
||||
|
||||
fm_write_rf_reg(0x0c, 0x3584);
|
||||
if(hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_2 || hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_3) ////
|
||||
{
|
||||
FM_DIGITAL_REG(0xc00003b4)=0x00060020;//turn off bt sleep
|
||||
}
|
||||
else if(hal_get_chip_metal_id() == HAL_CHIP_METAL_ID_4)
|
||||
{
|
||||
FM_DIGITAL_REG(0xc00003b0)=0x00060020;//turn off bt sleep
|
||||
}
|
||||
else
|
||||
{
|
||||
FM_DIGITAL_REG(0xc00003ac)=0x00060020;//turn off bt sleep
|
||||
}
|
||||
FM_DIGITAL_REG(0xd0330038) = 0x00008D0D;
|
||||
FM_DIGITAL_REG(0xd0340020)=0x010E01C0;// open ana rxon for open adc clk
|
||||
//fm_write_rf_reg(0x02, 0xe694);
|
||||
}
|
||||
|
||||
void* fm_radio_get_ext_buff(int size)
|
||||
{
|
||||
uint8_t *pBuff = NULL;
|
||||
size = size+size%4;
|
||||
app_audio_mempool_get_buff(&pBuff, size);
|
||||
return (void*)pBuff;
|
||||
}
|
||||
|
||||
int fm_radio_player(bool on)
|
||||
{
|
||||
static struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static bool isRun = false;
|
||||
uint8_t *buff = NULL;
|
||||
|
||||
TRACE(2,"fm_radio_player work:%d op:%d", isRun, on);
|
||||
if (isRun==on)
|
||||
return 0;
|
||||
|
||||
if (on){
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_52M);
|
||||
app_audio_mempool_init();
|
||||
fm_radio_poweron();
|
||||
fm_radio_analog_init();
|
||||
fm_radio_digit_init();
|
||||
osDelay(200);
|
||||
buff = (uint8_t *)fm_radio_get_ext_buff(FM_AUDIO_BUFFER_SIZE*2);
|
||||
app_audio_pcmbuff_init(buff, FM_AUDIO_BUFFER_SIZE*2);
|
||||
fm_sample_buffer_p = (int32_t *)fm_radio_get_ext_buff(FM_SAMPLE_BUFFER_SIZE);
|
||||
#if FPGA==0
|
||||
app_overlay_select(APP_OVERLAY_FM);
|
||||
if (on) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_52M);
|
||||
app_audio_mempool_init();
|
||||
fm_radio_poweron();
|
||||
fm_radio_analog_init();
|
||||
fm_radio_digit_init();
|
||||
osDelay(200);
|
||||
buff = (uint8_t *)fm_radio_get_ext_buff(FM_AUDIO_BUFFER_SIZE * 2);
|
||||
app_audio_pcmbuff_init(buff, FM_AUDIO_BUFFER_SIZE * 2);
|
||||
fm_sample_buffer_p =
|
||||
(int32_t *)fm_radio_get_ext_buff(FM_SAMPLE_BUFFER_SIZE);
|
||||
#if FPGA == 0
|
||||
app_overlay_select(APP_OVERLAY_FM);
|
||||
#endif
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.vol = app_bt_stream_local_volume_get();
|
||||
stream_cfg.handler = fm_capture_more_data;
|
||||
stream_cfg.data_ptr = (uint8_t *)fm_sample_buffer_p;
|
||||
stream_cfg.data_size = FM_SAMPLE_BUFFER_SIZE;
|
||||
stream_cfg.device = AUD_STREAM_USE_DPD_RX;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.vol = app_bt_stream_local_volume_get();
|
||||
stream_cfg.handler = fm_capture_more_data;
|
||||
stream_cfg.data_ptr = (uint8_t *)fm_sample_buffer_p;
|
||||
stream_cfg.data_size = FM_SAMPLE_BUFFER_SIZE;
|
||||
stream_cfg.device = AUD_STREAM_USE_DPD_RX;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
buff = (uint8_t *)fm_radio_get_ext_buff(FM_AUDIO_BUFFER_SIZE);
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
#if FPGA==0
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
buff = (uint8_t *)fm_radio_get_ext_buff(FM_AUDIO_BUFFER_SIZE);
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
#if FPGA == 0
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
#else
|
||||
stream_cfg.device = AUD_STREAM_USE_EXT_CODEC;
|
||||
stream_cfg.device = AUD_STREAM_USE_EXT_CODEC;
|
||||
#endif
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = app_bt_stream_local_volume_get();
|
||||
stream_cfg.handler = fm_pcm_more_data;
|
||||
stream_cfg.data_ptr = buff;
|
||||
stream_cfg.data_size = FM_AUDIO_BUFFER_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = app_bt_stream_local_volume_get();
|
||||
stream_cfg.handler = fm_pcm_more_data;
|
||||
stream_cfg.data_ptr = buff;
|
||||
stream_cfg.data_size = FM_AUDIO_BUFFER_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
|
||||
}else{
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
}
|
||||
} else {
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
}
|
||||
|
||||
isRun=on;
|
||||
return 0;
|
||||
isRun = on;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fm_tune(uint32_t freqkhz)
|
||||
{
|
||||
uint32_t reg;
|
||||
unsigned long long tmp = 0;
|
||||
int fm_tune(uint32_t freqkhz) {
|
||||
uint32_t reg;
|
||||
unsigned long long tmp = 0;
|
||||
|
||||
//[rfpll_cal]
|
||||
fm_write_rf_reg(0x21, 0x3979); // ref sel 52MHz
|
||||
fm_write_rf_reg(0x22, 0x7A22); // doubler setting
|
||||
fm_write_rf_reg(0x23, 0x0380);
|
||||
fm_write_rf_reg(0x2b, 0x32a0); // sdm
|
||||
fm_write_rf_reg(0x2a, 0x12d1); // cal ini
|
||||
|
||||
//[rfpll_cal]
|
||||
fm_write_rf_reg(0x21,0x3979); // ref sel 52MHz
|
||||
fm_write_rf_reg(0x22,0x7A22); // doubler setting
|
||||
fm_write_rf_reg(0x23,0x0380);
|
||||
fm_write_rf_reg(0x2b,0x32a0); // sdm
|
||||
fm_write_rf_reg(0x2a,0x12d1); // cal ini
|
||||
//(freq(Mhz)-0.89(Mhz))*(2^28)*3/26
|
||||
tmp = freqkhz;
|
||||
reg = (((tmp - 890)) << 27) * 3 / 13 / 1000;
|
||||
|
||||
//(freq(Mhz)-0.89(Mhz))*(2^28)*3/26
|
||||
tmp = freqkhz;
|
||||
reg =(((tmp-890))<<27)*3/13/1000;
|
||||
fm_write_rf_reg(0x25, (reg & 0xffff0000) >> 16);
|
||||
fm_write_rf_reg(0x26, reg & 0x0000ffff);
|
||||
|
||||
fm_write_rf_reg(0x25, (reg&0xffff0000)>>16);
|
||||
fm_write_rf_reg(0x26, reg&0x0000ffff);
|
||||
fm_write_rf_reg(0x1d, 0x58e4); // pll_cal_en
|
||||
fm_write_rf_reg(0xf7, 0x5597); // rst and enable pll_cal clk
|
||||
fm_write_rf_reg(0xf7, 0x55d7); // rst and enable pll_cal clk
|
||||
fm_write_rf_reg(0x1d, 0x7ae4); // pll cal start
|
||||
fm_write_rf_reg(0xff, 0x0000); // wait 100us
|
||||
|
||||
fm_write_rf_reg(0x1d,0x58e4); // pll_cal_en
|
||||
fm_write_rf_reg(0xf7,0x5597); // rst and enable pll_cal clk
|
||||
fm_write_rf_reg(0xf7,0x55d7); // rst and enable pll_cal clk
|
||||
fm_write_rf_reg(0x1d,0x7ae4); // pll cal start
|
||||
fm_write_rf_reg(0xff,0x0000); // wait 100us
|
||||
osDelay(20);
|
||||
|
||||
osDelay(20);
|
||||
fm_write_rf_reg(0x1d, 0x7ac4); // close pll loop
|
||||
|
||||
|
||||
fm_write_rf_reg(0x1d,0x7ac4); // close pll loop
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fm_test_main(void)
|
||||
{
|
||||
fm_radio_player(true);
|
||||
osDelay(20);
|
||||
fm_tune(90500);
|
||||
void fm_test_main(void) {
|
||||
fm_radio_player(true);
|
||||
osDelay(20);
|
||||
fm_tune(90500);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -14,20 +14,19 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
// Standard C Included Files
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "cmsis_os.h"
|
||||
#include "cqueue.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_uart.h"
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// BT
|
||||
|
||||
|
||||
#if 0
|
||||
/* mutex */
|
||||
osMutexId g_voicemsbc_queue_mutex_id;
|
||||
|
@ -35,16 +34,15 @@ osMutexDef(g_voicemsbc_queue_mutex);
|
|||
|
||||
/* msbc queue */
|
||||
#define VOICEMSBC_TEMP_BUFFER_SIZE 128
|
||||
#define VOICEMSBC_QUEUE_SIZE (VOICEMSBC_TEMP_BUFFER_SIZE*100)
|
||||
#define VOICEMSBC_QUEUE_SIZE (VOICEMSBC_TEMP_BUFFER_SIZE * 100)
|
||||
unsigned char voicemsbc_queue_buf[VOICEMSBC_QUEUE_SIZE];
|
||||
CQueue voicemsbc_queue;
|
||||
static uint32_t ok_to_decode = 0;
|
||||
|
||||
#define LOCK_VOICEMSBC_QUEUE() \
|
||||
osMutexWait(g_voicemsbc_queue_mutex_id, osWaitForever)
|
||||
#define LOCK_VOICEMSBC_QUEUE() \
|
||||
osMutexWait(g_voicemsbc_queue_mutex_id, osWaitForever)
|
||||
|
||||
#define UNLOCK_VOICEMSBC_QUEUE() \
|
||||
osMutexRelease(g_voicemsbc_queue_mutex_id)
|
||||
#define UNLOCK_VOICEMSBC_QUEUE() osMutexRelease(g_voicemsbc_queue_mutex_id)
|
||||
|
||||
static void dump_buffer_to_psram(char *buf, unsigned int len)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "plc_utils.h"
|
||||
#include "hal_trace.h"
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
|
||||
#if defined(CHIP_BEST1400) || defined(CHIP_BEST1402) || \
|
||||
defined(CHIP_BEST2300P) || defined(CHIP_BEST2300A)
|
||||
#define MSBC_MUTE_PATTERN (0x55)
|
||||
#else
|
||||
#define MSBC_MUTE_PATTERN (0x00)
|
||||
|
@ -19,9 +20,8 @@
|
|||
//#define ENABLE_PAD_CHECK
|
||||
|
||||
/*
|
||||
* if msbc frame is filled by 10+ samples in the trail, crc maybe not detect this
|
||||
* satuation.
|
||||
* Do not check this by default
|
||||
* if msbc frame is filled by 10+ samples in the trail, crc maybe not detect
|
||||
* this satuation. Do not check this by default
|
||||
*/
|
||||
//#define ENABLE_TRAILING_ZERO_CHECK
|
||||
|
||||
|
@ -58,271 +58,256 @@ static const uint8_t sbc_crc_tbl[256] = {
|
|||
0x10, 0x0D, 0x2A, 0x37, 0x64, 0x79, 0x5E, 0x43, 0xB2, 0xAF, 0x88, 0x95,
|
||||
0xC6, 0xDB, 0xFC, 0xE1, 0x5A, 0x47, 0x60, 0x7D, 0x2E, 0x33, 0x14, 0x09,
|
||||
0x7F, 0x62, 0x45, 0x58, 0x0B, 0x16, 0x31, 0x2C, 0x97, 0x8A, 0xAD, 0xB0,
|
||||
0xE3, 0xFE, 0xD9, 0xC4
|
||||
};
|
||||
0xE3, 0xFE, 0xD9, 0xC4};
|
||||
#endif
|
||||
|
||||
static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn)
|
||||
{
|
||||
uint8_t sn1, sn2;
|
||||
static int sco_parse_synchronization_header(uint8_t *buf, uint8_t *sn) {
|
||||
uint8_t sn1, sn2;
|
||||
#ifdef ENABLE_CRC_CHECK
|
||||
uint8_t fcs = 0x0F;
|
||||
uint8_t crc = 0;
|
||||
uint8_t i, sb, bit, shift;
|
||||
uint8_t ind = 6, bitOffset = 24;
|
||||
uint8_t fcs = 0x0F;
|
||||
uint8_t crc = 0;
|
||||
uint8_t i, sb, bit, shift;
|
||||
uint8_t ind = 6, bitOffset = 24;
|
||||
#endif
|
||||
*sn = 0xff;
|
||||
*sn = 0xff;
|
||||
#if defined(MSBC_SYNC_HACKER)
|
||||
if (((buf[0] != 0x01) && (buf[0] != 0x00)) ||
|
||||
((buf[1] & 0x0f) != 0x08) ||
|
||||
(buf[2] != 0xad)) {
|
||||
return -1;
|
||||
}
|
||||
if (((buf[0] != 0x01) && (buf[0] != 0x00)) || ((buf[1] & 0x0f) != 0x08) ||
|
||||
(buf[2] != 0xad)) {
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
if ((buf[0] != 0x01) ||
|
||||
((buf[1] & 0x0f) != 0x08) ||
|
||||
(buf[2] != 0xad)) {
|
||||
return -1;
|
||||
}
|
||||
if ((buf[0] != 0x01) || ((buf[1] & 0x0f) != 0x08) || (buf[2] != 0xad)) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
sn1 = (buf[1] & 0x30) >> 4;
|
||||
sn2 = (buf[1] & 0xc0) >> 6;
|
||||
if ((sn1 != 0) && (sn1 != 0x3)) {
|
||||
return -2;
|
||||
}
|
||||
if ((sn2 != 0) && (sn2 != 0x3)) {
|
||||
return -3;
|
||||
}
|
||||
sn1 = (buf[1] & 0x30) >> 4;
|
||||
sn2 = (buf[1] & 0xc0) >> 6;
|
||||
if ((sn1 != 0) && (sn1 != 0x3)) {
|
||||
return -2;
|
||||
}
|
||||
if ((sn2 != 0) && (sn2 != 0x3)) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CRC_CHECK
|
||||
fcs = sbc_crc_tbl[fcs ^ buf[3]];
|
||||
if (buf[3] != 0x00)
|
||||
return -4;
|
||||
fcs = sbc_crc_tbl[fcs ^ buf[4]];
|
||||
if (buf[4] != 0x00)
|
||||
return -4;
|
||||
crc = buf[5];
|
||||
for (sb = 0; sb < 8; sb++) {
|
||||
if (bitOffset % 8) {
|
||||
/* Sum the whole byte */
|
||||
fcs = sbc_crc_tbl[fcs ^ buf[ind]];
|
||||
ind = ind + 1;
|
||||
}
|
||||
else {
|
||||
if (sb == 7) {
|
||||
/* Sum the next 4 bits */
|
||||
fcs = sbc_crc_tbl[fcs ^ buf[3]];
|
||||
if (buf[3] != 0x00)
|
||||
return -4;
|
||||
fcs = sbc_crc_tbl[fcs ^ buf[4]];
|
||||
if (buf[4] != 0x00)
|
||||
return -4;
|
||||
crc = buf[5];
|
||||
for (sb = 0; sb < 8; sb++) {
|
||||
if (bitOffset % 8) {
|
||||
/* Sum the whole byte */
|
||||
fcs = sbc_crc_tbl[fcs ^ buf[ind]];
|
||||
ind = ind + 1;
|
||||
} else {
|
||||
if (sb == 7) {
|
||||
/* Sum the next 4 bits */
|
||||
|
||||
/* Just sum the most significant 4 bits */
|
||||
shift = 7;
|
||||
for (i = 0; i < 4; i++) {
|
||||
bit = (uint8_t)((0x01 & (buf[ind] >> shift--)) ^ (fcs >> 7));
|
||||
if (bit) {
|
||||
fcs = (uint8_t)(((fcs << 1) | bit) ^ 0x1C);
|
||||
}
|
||||
else {
|
||||
fcs = (uint8_t)((fcs << 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Just sum the most significant 4 bits */
|
||||
shift = 7;
|
||||
for (i = 0; i < 4; i++) {
|
||||
bit = (uint8_t)((0x01 & (buf[ind] >> shift--)) ^ (fcs >> 7));
|
||||
if (bit) {
|
||||
fcs = (uint8_t)(((fcs << 1) | bit) ^ 0x1C);
|
||||
} else {
|
||||
fcs = (uint8_t)((fcs << 1));
|
||||
}
|
||||
}
|
||||
|
||||
bitOffset += 4;
|
||||
}
|
||||
}
|
||||
//TRACE(2,"msbc crc:%d fcs:%d", crc,fcs);
|
||||
if (crc != fcs)
|
||||
return -4;
|
||||
|
||||
bitOffset += 4;
|
||||
}
|
||||
// TRACE(2,"msbc crc:%d fcs:%d", crc,fcs);
|
||||
if (crc != fcs)
|
||||
return -4;
|
||||
#endif
|
||||
|
||||
*sn = (sn1 & 0x01) | (sn2 & 0x02);
|
||||
*sn = (sn1 & 0x01) | (sn2 & 0x02);
|
||||
|
||||
#ifdef ENABLE_PAD_CHECK
|
||||
// when pad error detected, we should return sn
|
||||
if (buf[MSBC_PKTSIZE - 1] != 0x0) {
|
||||
return -5;
|
||||
}
|
||||
// when pad error detected, we should return sn
|
||||
if (buf[MSBC_PKTSIZE - 1] != 0x0) {
|
||||
return -5;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
||||
static bool memcmp_U8(uint8_t *x, uint8_t *y, uint16_t size)
|
||||
{
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (x[i] != y[i])
|
||||
return true;
|
||||
}
|
||||
static bool memcmp_U8(uint8_t *x, uint8_t *y, uint16_t size) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (x[i] != y[i])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// when signal is mute, msbc data remains the same except seq num. We should check history flag,
|
||||
// otherwise a single conflict may be detected twice
|
||||
static bool update_ble_sco_conflict(PacketLossState* st, uint8_t *last_pkt, uint8_t *pkt)
|
||||
{
|
||||
// do not check padding byte as it maybe useless when msbc_offset is 1
|
||||
bool ret = (st->prev_ble_sco_conflict_flag[1] == false && memcmp_U8(last_pkt, pkt, MSBC_PKTSIZE - 1) == false);
|
||||
// when signal is mute, msbc data remains the same except seq num. We should
|
||||
// check history flag, otherwise a single conflict may be detected twice
|
||||
static bool update_ble_sco_conflict(PacketLossState *st, uint8_t *last_pkt,
|
||||
uint8_t *pkt) {
|
||||
// do not check padding byte as it maybe useless when msbc_offset is 1
|
||||
bool ret = (st->prev_ble_sco_conflict_flag[1] == false &&
|
||||
memcmp_U8(last_pkt, pkt, MSBC_PKTSIZE - 1) == false);
|
||||
|
||||
memcpy(&last_pkt[0], &last_pkt[MSBC_PKTSIZE], MSBC_PKTSIZE);
|
||||
memcpy(&last_pkt[MSBC_PKTSIZE], pkt, MSBC_PKTSIZE);
|
||||
memcpy(&last_pkt[0], &last_pkt[MSBC_PKTSIZE], MSBC_PKTSIZE);
|
||||
memcpy(&last_pkt[MSBC_PKTSIZE], pkt, MSBC_PKTSIZE);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool check_ble_sco_conflict(PacketLossState* st, bool ret)
|
||||
{
|
||||
st->prev_ble_sco_conflict_flag[1] = st->prev_ble_sco_conflict_flag[0];
|
||||
st->prev_ble_sco_conflict_flag[0] = ret;
|
||||
static bool check_ble_sco_conflict(PacketLossState *st, bool ret) {
|
||||
st->prev_ble_sco_conflict_flag[1] = st->prev_ble_sco_conflict_flag[0];
|
||||
st->prev_ble_sco_conflict_flag[0] = ret;
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool msbc_check_controller_mute_pattern(uint8_t *pkt, uint8_t pattern)
|
||||
{
|
||||
// do not check padding byte as it maybe useless when msbc_offset is 1
|
||||
for (int i = 0; i < MSBC_PKTSIZE - 1; i++)
|
||||
if (pkt[i] != pattern)
|
||||
return false;
|
||||
static bool msbc_check_controller_mute_pattern(uint8_t *pkt, uint8_t pattern) {
|
||||
// do not check padding byte as it maybe useless when msbc_offset is 1
|
||||
for (int i = 0; i < MSBC_PKTSIZE - 1; i++)
|
||||
if (pkt[i] != pattern)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_TRAILING_ZERO_CHECK
|
||||
static int msbc_check_pkt_trailing_zeros(uint8_t *pkt)
|
||||
{
|
||||
int idx = MSBC_PKTSIZE;
|
||||
static int msbc_check_pkt_trailing_zeros(uint8_t *pkt) {
|
||||
int idx = MSBC_PKTSIZE;
|
||||
|
||||
for (int i = MSBC_PKTSIZE - 1; i >= 0; i--) {
|
||||
if (pkt[i] != 0) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
for (int i = MSBC_PKTSIZE - 1; i >= 0; i--) {
|
||||
if (pkt[i] != 0) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (MSBC_PKTSIZE - 1 - idx);
|
||||
return (MSBC_PKTSIZE - 1 - idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint8_t get_next_sequence_num(uint8_t seq_num)
|
||||
{
|
||||
return (seq_num + 1 == 4) ? 0 : (seq_num + 1);
|
||||
static uint8_t get_next_sequence_num(uint8_t seq_num) {
|
||||
return (seq_num + 1 == 4) ? 0 : (seq_num + 1);
|
||||
}
|
||||
|
||||
void packet_loss_detection_init(PacketLossState *st)
|
||||
{
|
||||
void packet_loss_detection_init(PacketLossState *st) {
|
||||
st->last_seq_num = 0xff;
|
||||
|
||||
memset(st->last_pkt, 0, sizeof(st->last_pkt));
|
||||
memset(st->prev_ble_sco_conflict_flag, 0,
|
||||
sizeof(st->prev_ble_sco_conflict_flag));
|
||||
memset(st->hist, 0, sizeof(st->hist));
|
||||
}
|
||||
|
||||
plc_type_t packet_loss_detection_process(PacketLossState *st,
|
||||
uint8_t *sbc_buf) {
|
||||
plc_type_t plc_type = PLC_TYPE_PASS;
|
||||
|
||||
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
||||
bool ble_sco_conflict = update_ble_sco_conflict(st, st->last_pkt, sbc_buf);
|
||||
#endif
|
||||
|
||||
uint8_t seq_num;
|
||||
if (msbc_check_controller_mute_pattern(sbc_buf, MSBC_MUTE_PATTERN) == true) {
|
||||
plc_type = PLC_TYPE_CONTROLLER_MUTE;
|
||||
st->last_seq_num = 0xff;
|
||||
|
||||
memset(st->last_pkt, 0, sizeof(st->last_pkt));
|
||||
memset(st->prev_ble_sco_conflict_flag, 0, sizeof(st->prev_ble_sco_conflict_flag));
|
||||
memset(st->hist, 0, sizeof(st->hist));
|
||||
}
|
||||
|
||||
plc_type_t packet_loss_detection_process(PacketLossState *st, uint8_t *sbc_buf)
|
||||
{
|
||||
plc_type_t plc_type = PLC_TYPE_PASS;
|
||||
|
||||
}
|
||||
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
||||
bool ble_sco_conflict = update_ble_sco_conflict(st, st->last_pkt, sbc_buf);
|
||||
else if (check_ble_sco_conflict(st, ble_sco_conflict) == true) {
|
||||
plc_type = PLC_TYPE_BLE_CONFLICT;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t seq_num;
|
||||
if (msbc_check_controller_mute_pattern(sbc_buf, MSBC_MUTE_PATTERN) == true) {
|
||||
plc_type = PLC_TYPE_CONTROLLER_MUTE;
|
||||
st->last_seq_num = 0xff;
|
||||
else {
|
||||
int err = sco_parse_synchronization_header(sbc_buf, &seq_num);
|
||||
if (err < 0 && err >= -3) {
|
||||
plc_type = PLC_TYPE_HEADER_ERROR;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#ifdef ENABLE_BLE_CONFLICT_CHECK
|
||||
else if (check_ble_sco_conflict(st, ble_sco_conflict) == true) {
|
||||
plc_type = PLC_TYPE_BLE_CONFLICT;
|
||||
st->last_seq_num = 0xff;
|
||||
#ifdef ENABLE_CRC_CHECK
|
||||
else if (err == -4) {
|
||||
plc_type = PLC_TYPE_CRC_ERROR;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_PAD_CHECK
|
||||
else if (err == -5) {
|
||||
plc_type = PLC_TYPE_PAD_ERROR;
|
||||
st->last_seq_num = seq_num;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_TRAILING_ZERO_CHECK
|
||||
else if (msbc_check_pkt_trailing_zeros(sbc_buf) > 10) {
|
||||
plc_type = PLC_TYPE_DATA_MISSING;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
int err = sco_parse_synchronization_header(sbc_buf, &seq_num);
|
||||
if (err < 0 && err >= -3) {
|
||||
plc_type = PLC_TYPE_HEADER_ERROR;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#ifdef ENABLE_CRC_CHECK
|
||||
else if (err == -4) {
|
||||
plc_type = PLC_TYPE_CRC_ERROR;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_PAD_CHECK
|
||||
else if (err == -5) {
|
||||
plc_type = PLC_TYPE_PAD_ERROR;
|
||||
st->last_seq_num = seq_num;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_TRAILING_ZERO_CHECK
|
||||
else if (msbc_check_pkt_trailing_zeros(sbc_buf) > 10) {
|
||||
plc_type = PLC_TYPE_DATA_MISSING;
|
||||
st->last_seq_num = 0xff;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
#ifdef ENABLE_SEQ_CHECK
|
||||
if (st->last_seq_num == 0xff) {
|
||||
if (seq_num == 0xff) {
|
||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||
}
|
||||
else {
|
||||
plc_type = PLC_TYPE_PASS;
|
||||
}
|
||||
st->last_seq_num = seq_num;
|
||||
}
|
||||
else {
|
||||
if (seq_num == 0xff) {
|
||||
st->last_seq_num = 0xff;
|
||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||
}
|
||||
else if (seq_num == get_next_sequence_num(st->last_seq_num)) {
|
||||
st->last_seq_num = seq_num;
|
||||
plc_type = PLC_TYPE_PASS;
|
||||
}
|
||||
else {
|
||||
st->last_seq_num = 0xff;
|
||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
plc_type = PLC_TYPE_PASS;
|
||||
#endif
|
||||
if (st->last_seq_num == 0xff) {
|
||||
if (seq_num == 0xff) {
|
||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||
} else {
|
||||
plc_type = PLC_TYPE_PASS;
|
||||
}
|
||||
st->last_seq_num = seq_num;
|
||||
} else {
|
||||
if (seq_num == 0xff) {
|
||||
st->last_seq_num = 0xff;
|
||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||
} else if (seq_num == get_next_sequence_num(st->last_seq_num)) {
|
||||
st->last_seq_num = seq_num;
|
||||
plc_type = PLC_TYPE_PASS;
|
||||
} else {
|
||||
st->last_seq_num = 0xff;
|
||||
plc_type = PLC_TYPE_SEQUENCE_DISCONTINUE;
|
||||
}
|
||||
}
|
||||
#else
|
||||
plc_type = PLC_TYPE_PASS;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
packet_loss_detection_update_histogram(st, plc_type);
|
||||
packet_loss_detection_update_histogram(st, plc_type);
|
||||
|
||||
return plc_type;
|
||||
return plc_type;
|
||||
}
|
||||
|
||||
void packet_loss_detection_update_histogram(PacketLossState *st, plc_type_t plc_type)
|
||||
{
|
||||
if (plc_type < 0 || plc_type >= PLC_TYPE_NUM) {
|
||||
TRACE(2,"[%s] plc type %d is invalid", __FUNCTION__, plc_type);
|
||||
return;
|
||||
}
|
||||
void packet_loss_detection_update_histogram(PacketLossState *st,
|
||||
plc_type_t plc_type) {
|
||||
if (plc_type < 0 || plc_type >= PLC_TYPE_NUM) {
|
||||
TRACE(2, "[%s] plc type %d is invalid", __FUNCTION__, plc_type);
|
||||
return;
|
||||
}
|
||||
|
||||
// The packet is detected as PLC_TYPE_PASS, but causes a decoder error.
|
||||
if (plc_type == PLC_TYPE_DECODER_ERROR) {
|
||||
st->hist[0] -= 1;
|
||||
}
|
||||
// The packet is detected as PLC_TYPE_PASS, but causes a decoder error.
|
||||
if (plc_type == PLC_TYPE_DECODER_ERROR) {
|
||||
st->hist[0] -= 1;
|
||||
}
|
||||
|
||||
st->hist[plc_type] += 1;
|
||||
st->hist[plc_type] += 1;
|
||||
}
|
||||
|
||||
void packet_loss_detection_report(PacketLossState *st)
|
||||
{
|
||||
uint32_t packet_loss_num = 0;
|
||||
void packet_loss_detection_report(PacketLossState *st) {
|
||||
uint32_t packet_loss_num = 0;
|
||||
|
||||
for (uint8_t i = 1; i < PLC_TYPE_NUM; i++) {
|
||||
TRACE(3,"[%s] plc type %d occurs %d times", __FUNCTION__, i, st->hist[i]);
|
||||
packet_loss_num += st->hist[i];
|
||||
}
|
||||
for (uint8_t i = 1; i < PLC_TYPE_NUM; i++) {
|
||||
TRACE(3, "[%s] plc type %d occurs %d times", __FUNCTION__, i, st->hist[i]);
|
||||
packet_loss_num += st->hist[i];
|
||||
}
|
||||
|
||||
uint32_t packet_total_num = st->hist[0] + packet_loss_num;
|
||||
TRACE(4,"[%s] packet loss percent %d/10000(%d/%d)", __FUNCTION__,
|
||||
(int32_t)(10000.f * packet_loss_num/ packet_total_num), packet_loss_num, packet_total_num);
|
||||
uint32_t packet_total_num = st->hist[0] + packet_loss_num;
|
||||
TRACE(4, "[%s] packet loss percent %d/10000(%d/%d)", __FUNCTION__,
|
||||
(int32_t)(10000.f * packet_loss_num / packet_total_num),
|
||||
packet_loss_num, packet_total_num);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -15,28 +15,28 @@
|
|||
****************************************************************************/
|
||||
/* rbpcmbuf source */
|
||||
/* pcmbuf management & af control & mixer */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef MBED
|
||||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
#endif
|
||||
#include "audioflinger.h"
|
||||
#include "cqueue.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_utils.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cqueue.h"
|
||||
#include "hal_trace.h"
|
||||
|
||||
#include "rbplay.h"
|
||||
#include "rbpcmbuf.h"
|
||||
#include "rbplay.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define RB_PCMBUF_DMA_BUFFER_SIZE (1024*12)
|
||||
#define RB_PCMBUF_MEDIA_BUFFER_SIZE (1024*12)
|
||||
#define RB_PCMBUF_DMA_BUFFER_SIZE (1024 * 12)
|
||||
#define RB_PCMBUF_MEDIA_BUFFER_SIZE (1024 * 12)
|
||||
#define RB_DECODE_OUT_BUFFER_SIZE 1024
|
||||
|
||||
static uint8_t *rb_decode_out_buff;
|
||||
|
@ -46,95 +46,93 @@ static CQueue rb_pcmbuf_media_buf_queue;
|
|||
static osMutexId _rb_media_buf_queue_mutex_id = NULL;
|
||||
static osMutexDef(_rb_media_buf_queue_mutex);
|
||||
|
||||
#define LOCK_MEDIA_BUF_QUEUE() \
|
||||
if(osErrorISR == osMutexWait(_rb_media_buf_queue_mutex_id, osWaitForever)) {\
|
||||
error("%s LOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!!\n",__func__);\
|
||||
}\
|
||||
#define LOCK_MEDIA_BUF_QUEUE() \
|
||||
if (osErrorISR == \
|
||||
osMutexWait(_rb_media_buf_queue_mutex_id, osWaitForever)) { \
|
||||
error("%s LOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!!\n", __func__); \
|
||||
}
|
||||
|
||||
#define UNLOCK_MEDIA_BUF_QUEUE() \
|
||||
if(osErrorISR == osMutexRelease(_rb_media_buf_queue_mutex_id)){ \
|
||||
error("%s UNLOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!\n"); \
|
||||
} \
|
||||
#define UNLOCK_MEDIA_BUF_QUEUE() \
|
||||
if (osErrorISR == osMutexRelease(_rb_media_buf_queue_mutex_id)) { \
|
||||
error("%s UNLOCK_MEDIA_BUF_QUEUE from IRQ!!!!!!\n"); \
|
||||
}
|
||||
|
||||
static uint32_t rbplay_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
CQItemType *e1 = NULL;
|
||||
CQItemType *e2 = NULL;
|
||||
unsigned int len1 = 0;
|
||||
unsigned int len2 = 0;
|
||||
static uint32_t rbplay_more_data(uint8_t *buf, uint32_t len) {
|
||||
CQItemType *e1 = NULL;
|
||||
CQItemType *e2 = NULL;
|
||||
unsigned int len1 = 0;
|
||||
unsigned int len2 = 0;
|
||||
|
||||
LOCK_MEDIA_BUF_QUEUE();
|
||||
int ret = PeekCQueue(&rb_pcmbuf_media_buf_queue, len, &e1, &len1, &e2, &len2);
|
||||
UNLOCK_MEDIA_BUF_QUEUE();
|
||||
|
||||
if (ret == CQ_OK) {
|
||||
if (len1 > 0)
|
||||
memcpy(buf, e1, len1);
|
||||
if (len2 > 0)
|
||||
memcpy(buf + len1, e2, len - len1);
|
||||
LOCK_MEDIA_BUF_QUEUE();
|
||||
int ret = PeekCQueue(&rb_pcmbuf_media_buf_queue, len, &e1, &len1, &e2, &len2);
|
||||
DeCQueue(&rb_pcmbuf_media_buf_queue, 0, len);
|
||||
UNLOCK_MEDIA_BUF_QUEUE();
|
||||
} else {
|
||||
warn("RBplay cache underflow");
|
||||
}
|
||||
|
||||
if (ret == CQ_OK) {
|
||||
if (len1 > 0)
|
||||
memcpy(buf, e1, len1);
|
||||
if (len2 > 0)
|
||||
memcpy(buf + len1, e2, len - len1);
|
||||
LOCK_MEDIA_BUF_QUEUE();
|
||||
DeCQueue(&rb_pcmbuf_media_buf_queue, 0, len);
|
||||
UNLOCK_MEDIA_BUF_QUEUE();
|
||||
} else {
|
||||
warn("RBplay cache underflow");
|
||||
}
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
||||
extern uint8_t rb_ctl_get_vol(void);
|
||||
void rb_pcmbuf_init(void)
|
||||
{
|
||||
info("pcmbuff init");
|
||||
if(!_rb_media_buf_queue_mutex_id)
|
||||
_rb_media_buf_queue_mutex_id = osMutexCreate((osMutex(_rb_media_buf_queue_mutex)));
|
||||
void rb_pcmbuf_init(void) {
|
||||
info("pcmbuff init");
|
||||
if (!_rb_media_buf_queue_mutex_id)
|
||||
_rb_media_buf_queue_mutex_id =
|
||||
osMutexCreate((osMutex(_rb_media_buf_queue_mutex)));
|
||||
|
||||
app_audio_mempool_init();
|
||||
app_audio_mempool_init();
|
||||
|
||||
app_audio_mempool_get_buff(&rb_pcmbuf_media_buf, RB_PCMBUF_MEDIA_BUFFER_SIZE);
|
||||
InitCQueue(&rb_pcmbuf_media_buf_queue, RB_PCMBUF_MEDIA_BUFFER_SIZE, (unsigned char *)rb_pcmbuf_media_buf);
|
||||
app_audio_mempool_get_buff(&rb_pcmbuf_media_buf, RB_PCMBUF_MEDIA_BUFFER_SIZE);
|
||||
InitCQueue(&rb_pcmbuf_media_buf_queue, RB_PCMBUF_MEDIA_BUFFER_SIZE,
|
||||
(unsigned char *)rb_pcmbuf_media_buf);
|
||||
|
||||
app_audio_mempool_get_buff(&rbplay_dma_buffer, RB_PCMBUF_DMA_BUFFER_SIZE);
|
||||
app_audio_mempool_get_buff(&rb_decode_out_buff, RB_DECODE_OUT_BUFFER_SIZE);
|
||||
app_audio_mempool_get_buff(&rbplay_dma_buffer, RB_PCMBUF_DMA_BUFFER_SIZE);
|
||||
app_audio_mempool_get_buff(&rb_decode_out_buff, RB_DECODE_OUT_BUFFER_SIZE);
|
||||
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
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 = AUD_SAMPRATE_44100;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = rb_ctl_get_vol();
|
||||
stream_cfg.handler = rbplay_more_data;
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(rbplay_dma_buffer);
|
||||
stream_cfg.data_size = RB_PCMBUF_DMA_BUFFER_SIZE;
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_44100;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = rb_ctl_get_vol();
|
||||
stream_cfg.handler = rbplay_more_data;
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(rbplay_dma_buffer);
|
||||
stream_cfg.data_size = RB_PCMBUF_DMA_BUFFER_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
|
||||
void *rb_pcmbuf_request_buffer(int *size)
|
||||
{
|
||||
*size = RB_DECODE_OUT_BUFFER_SIZE / 4;
|
||||
return rb_decode_out_buff;
|
||||
void *rb_pcmbuf_request_buffer(int *size) {
|
||||
*size = RB_DECODE_OUT_BUFFER_SIZE / 4;
|
||||
return rb_decode_out_buff;
|
||||
}
|
||||
|
||||
void rb_pcmbuf_write(unsigned int size)
|
||||
{
|
||||
int ret ;
|
||||
do {
|
||||
LOCK_MEDIA_BUF_QUEUE();
|
||||
ret = EnCQueue(&rb_pcmbuf_media_buf_queue, (CQItemType *)rb_decode_out_buff, size*(2*2));
|
||||
UNLOCK_MEDIA_BUF_QUEUE();
|
||||
osThreadYield();
|
||||
} while (ret == CQ_ERR);
|
||||
void rb_pcmbuf_write(unsigned int size) {
|
||||
int ret;
|
||||
do {
|
||||
LOCK_MEDIA_BUF_QUEUE();
|
||||
ret = EnCQueue(&rb_pcmbuf_media_buf_queue, (CQItemType *)rb_decode_out_buff,
|
||||
size * (2 * 2));
|
||||
UNLOCK_MEDIA_BUF_QUEUE();
|
||||
osThreadYield();
|
||||
} while (ret == CQ_ERR);
|
||||
}
|
||||
|
||||
void rb_pcmbuf_stop(void)
|
||||
{
|
||||
af_stream_stop(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0,AUD_STREAM_PLAYBACK);
|
||||
void rb_pcmbuf_stop(void) {
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,34 +16,34 @@
|
|||
/* rbplay source */
|
||||
/* playback control & rockbox codec porting & codec thread */
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef MBED
|
||||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
#endif
|
||||
#include "metadata.h"
|
||||
#include "app_overlay.h"
|
||||
#include "apps.h"
|
||||
#include "audioflinger.h"
|
||||
#include "codecs.h"
|
||||
#include "eq_export.h"
|
||||
#include "hal_overlay.h"
|
||||
#include "app_overlay.h"
|
||||
#include "audioflinger.h"
|
||||
#include "hal_trace.h"
|
||||
#include "apps.h"
|
||||
#include "metadata.h"
|
||||
|
||||
#include "rbpcmbuf.h"
|
||||
#include "rbplaysd.h"
|
||||
#include "app_key.h"
|
||||
#include "app_thread.h"
|
||||
#include "app_utils.h"
|
||||
#include "app_key.h"
|
||||
#include "rbpcmbuf.h"
|
||||
#include "rbplay.h"
|
||||
#include "rbplaysd.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef __TWS__
|
||||
|
@ -51,28 +51,30 @@
|
|||
#endif
|
||||
|
||||
// TODO: remove
|
||||
#define BT_STREAM_RBCODEC 0x10 //from rockbox decoder
|
||||
#define BT_STREAM_RBCODEC 0x10 // from rockbox decoder
|
||||
|
||||
extern "C" {
|
||||
void flac_codec_main(int r);
|
||||
void flac_codec_run(void);
|
||||
void wav_codec_main(int r);
|
||||
void wav_codec_run(void);
|
||||
void mpa_codec_main(int r);
|
||||
void mpa_codec_run(void);
|
||||
void ape_codec_main(int r);
|
||||
void ape_codec_run(void);
|
||||
void sbc_codec_main(int r);
|
||||
void sbc_codec_run(void);
|
||||
void flac_codec_main(int r);
|
||||
void flac_codec_run(void);
|
||||
void wav_codec_main(int r);
|
||||
void wav_codec_run(void);
|
||||
void mpa_codec_main(int r);
|
||||
void mpa_codec_run(void);
|
||||
void ape_codec_main(int r);
|
||||
void ape_codec_run(void);
|
||||
void sbc_codec_main(int r);
|
||||
void sbc_codec_run(void);
|
||||
}
|
||||
|
||||
extern void rb_pcm_player_open(enum AUD_BITS_T bits,enum AUD_SAMPRATE_T sample_rate,enum AUD_CHANNEL_NUM_T channel_num,uint8_t vol) ;
|
||||
extern void rb_pcm_player_open(enum AUD_BITS_T bits,
|
||||
enum AUD_SAMPRATE_T sample_rate,
|
||||
enum AUD_CHANNEL_NUM_T channel_num, uint8_t vol);
|
||||
|
||||
#if defined(__TWS__)
|
||||
typedef struct _rb_tws_codec_info{
|
||||
uint8_t update_codec_info;
|
||||
int32_t sample_freq;
|
||||
uint8_t channel_num;
|
||||
typedef struct _rb_tws_codec_info {
|
||||
uint8_t update_codec_info;
|
||||
int32_t sample_freq;
|
||||
uint8_t channel_num;
|
||||
} rb_tws_codec_info;
|
||||
|
||||
rb_tws_codec_info codec_info = {1, 44100, 2};
|
||||
|
@ -82,17 +84,18 @@ static osThreadId rb_decode_tid = NULL;
|
|||
static osThreadId rb_caller_tid = NULL;
|
||||
|
||||
typedef struct {
|
||||
uint32_t evt;
|
||||
uint32_t arg;
|
||||
uint32_t evt;
|
||||
uint32_t arg;
|
||||
} RBTHREAD_MSG_BLOCK;
|
||||
|
||||
#define RBTHREAD_MAILBOX_MAX (10)
|
||||
osMailQDef (rb_decode_mailbox, RBTHREAD_MAILBOX_MAX, RBTHREAD_MSG_BLOCK);
|
||||
int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK* msg_src);
|
||||
osMailQDef(rb_decode_mailbox, RBTHREAD_MAILBOX_MAX, RBTHREAD_MSG_BLOCK);
|
||||
int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK *msg_src);
|
||||
static osMailQId rb_decode_mailbox = NULL;
|
||||
|
||||
static void rb_decode_thread(void const *argument);
|
||||
osThreadDef(rb_decode_thread, osPriorityAboveNormal, 1, 1024 * 2, "rb_decorder");
|
||||
osThreadDef(rb_decode_thread, osPriorityAboveNormal, 1, 1024 * 2,
|
||||
"rb_decorder");
|
||||
|
||||
// rbcodec info
|
||||
static int song_fd;
|
||||
|
@ -115,226 +118,203 @@ uint16_t g_rbplayer_curr_song_idx = 0;
|
|||
|
||||
extern void app_rbplay_exit(void);
|
||||
|
||||
extern void bt_change_to_iic(APP_KEY_STATUS *status, void *param);
|
||||
extern void bt_change_to_iic(APP_KEY_STATUS *status, void *param);
|
||||
|
||||
extern void rb_thread_send_switch(bool next);
|
||||
extern void rb_thread_send_status_change(void );
|
||||
extern void rb_thread_send_switch(bool next);
|
||||
extern void rb_thread_send_status_change(void);
|
||||
|
||||
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void);
|
||||
|
||||
static void rb_player_sync_close_done(void)
|
||||
{
|
||||
thread_tid_waiter = NULL;
|
||||
}
|
||||
static void rb_player_sync_close_done(void) { thread_tid_waiter = NULL; }
|
||||
|
||||
extern void rb_check_stream_reconfig(int32_t freq, uint8_t ch);
|
||||
static void f_codec_pcmbuf_insert_callback(
|
||||
const void *ch1, const void *ch2, int count)
|
||||
{
|
||||
struct dsp_buffer src;
|
||||
struct dsp_buffer dst;
|
||||
static void f_codec_pcmbuf_insert_callback(const void *ch1, const void *ch2,
|
||||
int count) {
|
||||
struct dsp_buffer src;
|
||||
struct dsp_buffer dst;
|
||||
|
||||
src.remcount = count;
|
||||
src.pin[0] = (const unsigned char *)ch1;
|
||||
src.pin[1] = (const unsigned char *)ch2;
|
||||
src.proc_mask = 0;
|
||||
src.remcount = count;
|
||||
src.pin[0] = (const unsigned char *)ch1;
|
||||
src.pin[1] = (const unsigned char *)ch2;
|
||||
src.proc_mask = 0;
|
||||
|
||||
if (rb_codec_running() == 0)
|
||||
return ;
|
||||
if (rb_codec_running() == 0)
|
||||
return;
|
||||
|
||||
#ifndef __TWS__
|
||||
while (src.remcount > 0) {
|
||||
dst.remcount = 0;
|
||||
dst.p16out = (short *)rb_pcmbuf_request_buffer(&dst.bufcount);
|
||||
while (src.remcount > 0) {
|
||||
dst.remcount = 0;
|
||||
dst.p16out = (short *)rb_pcmbuf_request_buffer(&dst.bufcount);
|
||||
|
||||
if (dst.p16out == NULL) {
|
||||
warn("No pcm buffer");
|
||||
osThreadYield();
|
||||
} else {
|
||||
dsp_process(ci->dsp, &src, &dst);
|
||||
if (dst.p16out == NULL) {
|
||||
warn("No pcm buffer");
|
||||
osThreadYield();
|
||||
} else {
|
||||
dsp_process(ci->dsp, &src, &dst);
|
||||
|
||||
if (dst.remcount > 0) {
|
||||
rb_pcmbuf_write(dst.remcount);
|
||||
}
|
||||
}
|
||||
if (dst.remcount > 0) {
|
||||
rb_pcmbuf_write(dst.remcount);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
if(codec_info.update_codec_info){
|
||||
rb_set_sbc_encoder_freq_ch(codec_info.sample_freq, codec_info.channel_num); //should call this to set trigger timer
|
||||
rb_check_stream_reconfig(codec_info.sample_freq, codec_info.channel_num);
|
||||
codec_info.update_codec_info = 0;
|
||||
if (codec_info.update_codec_info) {
|
||||
rb_set_sbc_encoder_freq_ch(
|
||||
codec_info.sample_freq,
|
||||
codec_info.channel_num); // should call this to set trigger timer
|
||||
rb_check_stream_reconfig(codec_info.sample_freq, codec_info.channel_num);
|
||||
codec_info.update_codec_info = 0;
|
||||
}
|
||||
|
||||
if (tws_local_player_need_tran_2_slave()) {
|
||||
rb_tws_start_master_player(BT_STREAM_RBCODEC);
|
||||
}
|
||||
while (1) {
|
||||
uint8_t *pcm_buff = NULL;
|
||||
dst.remcount = 0;
|
||||
dst.bufcount = MIN(src.remcount, 128); /* Arbitrary min request */
|
||||
dst.p16out = (short *)rb_pcmbuf_request_buffer(&dst.bufcount);
|
||||
pcm_buff = (uint8_t *)dst.p16out;
|
||||
ASSERT(pcm_buff, "Should request buffer");
|
||||
|
||||
dsp_process(ci->dsp, &src, &dst);
|
||||
|
||||
if (dst.remcount > 0) {
|
||||
while (rb_push_pcm_in_tws_buffer(pcm_buff, dst.remcount * 2 * 2) == 0) {
|
||||
osDelay(2);
|
||||
}
|
||||
}
|
||||
|
||||
if(tws_local_player_need_tran_2_slave()){
|
||||
rb_tws_start_master_player(BT_STREAM_RBCODEC);
|
||||
}
|
||||
while(1){
|
||||
uint8_t * pcm_buff = NULL;
|
||||
dst.remcount = 0;
|
||||
dst.bufcount = MIN(src.remcount, 128); /* Arbitrary min request */
|
||||
dst.p16out = (short *)rb_pcmbuf_request_buffer(&dst.bufcount);
|
||||
pcm_buff = (uint8_t *)dst.p16out;
|
||||
ASSERT(pcm_buff, "Should request buffer");
|
||||
|
||||
dsp_process(ci->dsp, &src, &dst);
|
||||
|
||||
if (dst.remcount > 0) {
|
||||
while(rb_push_pcm_in_tws_buffer(pcm_buff, dst.remcount*2*2) == 0){
|
||||
osDelay(2);
|
||||
}
|
||||
}
|
||||
|
||||
if (src.remcount <= 0) {
|
||||
return; /* No input remains and DSP purged */
|
||||
}
|
||||
if (src.remcount <= 0) {
|
||||
return; /* No input remains and DSP purged */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void f_audio_codec_update_elapsed(unsigned long elapsed)
|
||||
{
|
||||
//info("Update elapsed: %d", elapsed);
|
||||
return;
|
||||
static void f_audio_codec_update_elapsed(unsigned long elapsed) {
|
||||
// info("Update elapsed: %d", elapsed);
|
||||
return;
|
||||
}
|
||||
|
||||
static size_t f_codec_filebuf_callback(void *ptr, size_t size)
|
||||
{
|
||||
ssize_t ret;
|
||||
ret = read(song_fd, ptr, size);
|
||||
if(ret < 0) {
|
||||
error("File read error: %d",ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
static size_t f_codec_filebuf_callback(void *ptr, size_t size) {
|
||||
ssize_t ret;
|
||||
ret = read(song_fd, ptr, size);
|
||||
if (ret < 0) {
|
||||
error("File read error: %d", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void * f_codec_request_buffer_callback(size_t *realsize, size_t reqsize)
|
||||
{
|
||||
static void *f_codec_request_buffer_callback(size_t *realsize, size_t reqsize) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *f_codec_advance_buffer_callback(size_t amount) {
|
||||
off_t ret = lseek(song_fd, (off_t)(ci->curpos + amount), SEEK_SET);
|
||||
if (ret < 0) {
|
||||
error("File seek fail");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ci->curpos += amount;
|
||||
return (void *)ci;
|
||||
}
|
||||
|
||||
static void * f_codec_advance_buffer_callback(size_t amount)
|
||||
{
|
||||
off_t ret = lseek(song_fd, (off_t)(ci->curpos + amount), SEEK_SET);
|
||||
if(ret < 0) {
|
||||
error("File seek fail");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ci->curpos += amount;
|
||||
return (void *)ci;
|
||||
static bool f_codec_seek_buffer_callback(size_t newpos) {
|
||||
off_t ret = lseek(song_fd, (off_t)newpos, SEEK_SET);
|
||||
if (ret < 0) {
|
||||
error("File seek fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
ci->curpos = newpos;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool f_codec_seek_buffer_callback(size_t newpos)
|
||||
{
|
||||
off_t ret = lseek(song_fd, (off_t)newpos, SEEK_SET);
|
||||
if(ret < 0) {
|
||||
error("File seek fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
ci->curpos = newpos;
|
||||
return true;
|
||||
static void f_codec_seek_complete_callback(void) {
|
||||
info("Seek complete");
|
||||
dsp_configure(ci->dsp, DSP_FLUSH, 0);
|
||||
}
|
||||
|
||||
static void f_codec_seek_complete_callback(void)
|
||||
{
|
||||
info("Seek complete");
|
||||
dsp_configure(ci->dsp, DSP_FLUSH, 0);
|
||||
}
|
||||
static void f_audio_codec_update_offset(size_t offset) {}
|
||||
|
||||
static void f_audio_codec_update_offset(size_t offset)
|
||||
{
|
||||
}
|
||||
|
||||
static void f_codec_configure_callback(int setting, intptr_t value)
|
||||
{
|
||||
dsp_configure(ci->dsp, setting, value);
|
||||
static void f_codec_configure_callback(int setting, intptr_t value) {
|
||||
dsp_configure(ci->dsp, setting, value);
|
||||
#ifdef __TWS__
|
||||
if(setting == DSP_SET_FREQUENCY){
|
||||
if(codec_info.sample_freq != value)
|
||||
codec_info.update_codec_info = 1;
|
||||
codec_info.sample_freq = value;
|
||||
}
|
||||
else if(setting == DSP_SET_STEREO_MODE){
|
||||
if(codec_info.channel_num != (value == STEREO_MONO ? 1 : 2))
|
||||
codec_info.update_codec_info = 1;
|
||||
codec_info.channel_num = value == STEREO_MONO ? 1 : 2;
|
||||
}
|
||||
if (setting == DSP_SET_FREQUENCY) {
|
||||
if (codec_info.sample_freq != value)
|
||||
codec_info.update_codec_info = 1;
|
||||
codec_info.sample_freq = value;
|
||||
} else if (setting == DSP_SET_STEREO_MODE) {
|
||||
if (codec_info.channel_num != (value == STEREO_MONO ? 1 : 2))
|
||||
codec_info.update_codec_info = 1;
|
||||
codec_info.channel_num = value == STEREO_MONO ? 1 : 2;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static enum codec_command_action f_codec_get_command_callback(intptr_t *param)
|
||||
{
|
||||
if (rb_decode_halt_flag == 1)
|
||||
return CODEC_ACTION_HALT ;
|
||||
static enum codec_command_action f_codec_get_command_callback(intptr_t *param) {
|
||||
if (rb_decode_halt_flag == 1)
|
||||
return CODEC_ACTION_HALT;
|
||||
|
||||
return CODEC_ACTION_NULL;
|
||||
return CODEC_ACTION_NULL;
|
||||
}
|
||||
|
||||
static bool f_codec_loop_track_callback(void)
|
||||
{
|
||||
return false;
|
||||
static bool f_codec_loop_track_callback(void) { return false; }
|
||||
|
||||
static void init_ci_file(void) {
|
||||
ci->codec_get_buffer = 0;
|
||||
ci->pcmbuf_insert = f_codec_pcmbuf_insert_callback;
|
||||
ci->set_elapsed = f_audio_codec_update_elapsed;
|
||||
ci->read_filebuf = f_codec_filebuf_callback;
|
||||
ci->request_buffer = f_codec_request_buffer_callback;
|
||||
ci->advance_buffer = f_codec_advance_buffer_callback;
|
||||
ci->seek_buffer = f_codec_seek_buffer_callback;
|
||||
ci->seek_complete = f_codec_seek_complete_callback;
|
||||
ci->set_offset = f_audio_codec_update_offset;
|
||||
ci->configure = f_codec_configure_callback;
|
||||
ci->get_command = f_codec_get_command_callback;
|
||||
ci->loop_track = f_codec_loop_track_callback;
|
||||
}
|
||||
|
||||
static void init_ci_file(void)
|
||||
{
|
||||
ci->codec_get_buffer = 0;
|
||||
ci->pcmbuf_insert = f_codec_pcmbuf_insert_callback;
|
||||
ci->set_elapsed = f_audio_codec_update_elapsed;
|
||||
ci->read_filebuf = f_codec_filebuf_callback;
|
||||
ci->request_buffer = f_codec_request_buffer_callback;
|
||||
ci->advance_buffer = f_codec_advance_buffer_callback;
|
||||
ci->seek_buffer = f_codec_seek_buffer_callback;
|
||||
ci->seek_complete = f_codec_seek_complete_callback;
|
||||
ci->set_offset = f_audio_codec_update_offset;
|
||||
ci->configure = f_codec_configure_callback;
|
||||
ci->get_command = f_codec_get_command_callback;
|
||||
ci->loop_track = f_codec_loop_track_callback;
|
||||
}
|
||||
static void rb_play_init(void) {
|
||||
init_dsp();
|
||||
|
||||
static void rb_play_init(void)
|
||||
{
|
||||
init_dsp();
|
||||
|
||||
init_ci_file();
|
||||
init_ci_file();
|
||||
|
||||
#ifndef __TWS__
|
||||
rb_pcmbuf_init();
|
||||
rb_pcmbuf_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
void rb_play_codec_init(void)
|
||||
{
|
||||
RBTHREAD_MSG_BLOCK msg;
|
||||
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_INIT;
|
||||
msg.arg = (uint32_t)0;
|
||||
rb_decode_mailbox_put(&msg);
|
||||
void rb_play_codec_init(void) {
|
||||
RBTHREAD_MSG_BLOCK msg;
|
||||
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_INIT;
|
||||
msg.arg = (uint32_t)0;
|
||||
rb_decode_mailbox_put(&msg);
|
||||
}
|
||||
|
||||
void rb_play_codec_run(void)
|
||||
{
|
||||
RBTHREAD_MSG_BLOCK msg;
|
||||
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_RUN;
|
||||
msg.arg = (uint32_t)0;
|
||||
rb_decode_mailbox_put(&msg);
|
||||
void rb_play_codec_run(void) {
|
||||
RBTHREAD_MSG_BLOCK msg;
|
||||
msg.evt = (uint32_t)RB_CTRL_CMD_CODEC_RUN;
|
||||
msg.arg = (uint32_t)0;
|
||||
rb_decode_mailbox_put(&msg);
|
||||
}
|
||||
|
||||
static int rb_codec_init_desc(void )
|
||||
{
|
||||
info("Init decode format: %d", song_format);
|
||||
static int rb_codec_init_desc(void) {
|
||||
info("Init decode format: %d", song_format);
|
||||
|
||||
switch (song_format) {
|
||||
case AFMT_MPA_L1:
|
||||
case AFMT_MPA_L2:
|
||||
case AFMT_MPA_L3:
|
||||
app_overlay_select(APP_OVERLAY_MPA);
|
||||
mpa_codec_main(CODEC_LOAD);
|
||||
break;
|
||||
// TODO: add APP_OVERLAY_APE
|
||||
switch (song_format) {
|
||||
case AFMT_MPA_L1:
|
||||
case AFMT_MPA_L2:
|
||||
case AFMT_MPA_L3:
|
||||
app_overlay_select(APP_OVERLAY_MPA);
|
||||
mpa_codec_main(CODEC_LOAD);
|
||||
break;
|
||||
// TODO: add APP_OVERLAY_APE
|
||||
#if 0
|
||||
case AFMT_APE:
|
||||
app_overlay_select(APP_OVERLAY_APE);
|
||||
|
@ -353,26 +333,25 @@ static int rb_codec_init_desc(void )
|
|||
wav_codec_main(CODEC_LOAD);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("unkown codec type init\n");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
error("unkown codec type init\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rb_codec_loop_on(void)
|
||||
{
|
||||
static int rb_codec_loop_on(void) {
|
||||
#ifdef __TWS__
|
||||
//set start transfer to slave
|
||||
tws_local_player_set_tran_2_slave_flag(1);
|
||||
// set start transfer to slave
|
||||
tws_local_player_set_tran_2_slave_flag(1);
|
||||
#endif
|
||||
switch (song_format) {
|
||||
case AFMT_MPA_L1:
|
||||
case AFMT_MPA_L2:
|
||||
case AFMT_MPA_L3:
|
||||
mpa_codec_run();
|
||||
break;
|
||||
switch (song_format) {
|
||||
case AFMT_MPA_L1:
|
||||
case AFMT_MPA_L2:
|
||||
case AFMT_MPA_L3:
|
||||
mpa_codec_run();
|
||||
break;
|
||||
#if 0
|
||||
case AFMT_SBC:
|
||||
sbc_codec_run();
|
||||
|
@ -387,229 +366,210 @@ static int rb_codec_loop_on(void)
|
|||
ape_codec_run();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
error("unkown codec type run\n");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
error("unkown codec type run\n");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rb_thread_process_evt(RB_CTRL_CMD_T evt)
|
||||
{
|
||||
info("Decode event:%d", evt);
|
||||
static int rb_thread_process_evt(RB_CTRL_CMD_T evt) {
|
||||
info("Decode event:%d", evt);
|
||||
|
||||
switch(evt) {
|
||||
case RB_CTRL_CMD_CODEC_INIT:
|
||||
rb_decode_halt_flag = 0;
|
||||
switch (evt) {
|
||||
case RB_CTRL_CMD_CODEC_INIT:
|
||||
rb_decode_halt_flag = 0;
|
||||
|
||||
rb_play_init();
|
||||
rb_play_init();
|
||||
|
||||
/* get id3 */
|
||||
/* init ci info */
|
||||
ci->filesize = filesize(song_fd);
|
||||
ci->id3 = current_id3;
|
||||
ci->curpos = 0;
|
||||
/* get id3 */
|
||||
/* init ci info */
|
||||
ci->filesize = filesize(song_fd);
|
||||
ci->id3 = current_id3;
|
||||
ci->curpos = 0;
|
||||
|
||||
dsp_configure(ci->dsp, DSP_RESET, 0);
|
||||
dsp_configure(ci->dsp, DSP_FLUSH, 0);
|
||||
dsp_configure(ci->dsp, DSP_RESET, 0);
|
||||
dsp_configure(ci->dsp, DSP_FLUSH, 0);
|
||||
|
||||
rb_codec_init_desc();
|
||||
break;
|
||||
case RB_CTRL_CMD_CODEC_RUN:
|
||||
rbplay_loop_on = 1;
|
||||
rb_codec_init_desc();
|
||||
break;
|
||||
case RB_CTRL_CMD_CODEC_RUN:
|
||||
rbplay_loop_on = 1;
|
||||
|
||||
info("Play start");
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, rb_player_get_work_freq());
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
rb_codec_loop_on();
|
||||
info("Play start");
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, rb_player_get_work_freq());
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
rb_codec_loop_on();
|
||||
#if defined(__BTIF_AUTOPOWEROFF__)
|
||||
app_start_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
app_start_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
#endif
|
||||
song_fd = 0;
|
||||
rb_decode_halt_flag = 1;
|
||||
if(thread_tid_waiter) {
|
||||
rb_player_sync_close_done();
|
||||
} else {
|
||||
rb_thread_send_status_change();
|
||||
rb_thread_send_switch(true);
|
||||
}
|
||||
song_fd = 0;
|
||||
rb_decode_halt_flag = 1;
|
||||
if (thread_tid_waiter) {
|
||||
rb_player_sync_close_done();
|
||||
} else {
|
||||
rb_thread_send_status_change();
|
||||
rb_thread_send_switch(true);
|
||||
}
|
||||
#ifdef __TWS__
|
||||
//should update codec info after play one music
|
||||
codec_info.update_codec_info = 1;
|
||||
// should update codec info after play one music
|
||||
codec_info.update_codec_info = 1;
|
||||
#endif
|
||||
rbplay_loop_on = 0;
|
||||
info("Play end");
|
||||
break;
|
||||
default:
|
||||
error("Unkown rb cmd %d\n",evt);
|
||||
break;
|
||||
}
|
||||
rbplay_loop_on = 0;
|
||||
info("Play end");
|
||||
break;
|
||||
default:
|
||||
error("Unkown rb cmd %d\n", evt);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK* msg_src)
|
||||
{
|
||||
osStatus status;
|
||||
int rb_decode_mailbox_put(RBTHREAD_MSG_BLOCK *msg_src) {
|
||||
osStatus status;
|
||||
|
||||
RBTHREAD_MSG_BLOCK *msg_p = NULL;
|
||||
RBTHREAD_MSG_BLOCK *msg_p = NULL;
|
||||
|
||||
msg_p = (RBTHREAD_MSG_BLOCK*)osMailAlloc(rb_decode_mailbox, 0);
|
||||
if(!msg_p) {
|
||||
TRACE(3,"%s fail, evt:%d,arg=%d \n",__func__,msg_src->evt,msg_src->arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg_p->evt = msg_src->evt;
|
||||
msg_p->arg = msg_src->arg;
|
||||
|
||||
status = osMailPut(rb_decode_mailbox, msg_p);
|
||||
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
int rb_decode_mailbox_free(RBTHREAD_MSG_BLOCK* msg_p)
|
||||
{
|
||||
osStatus status;
|
||||
|
||||
status = osMailFree(rb_decode_mailbox, msg_p);
|
||||
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
int rb_decode_mailbox_get(RBTHREAD_MSG_BLOCK** msg_p)
|
||||
{
|
||||
osEvent evt;
|
||||
evt = osMailGet(rb_decode_mailbox, osWaitForever);
|
||||
if (evt.status == osEventMail) {
|
||||
*msg_p = (RBTHREAD_MSG_BLOCK *)evt.value.p;
|
||||
return 0;
|
||||
}
|
||||
msg_p = (RBTHREAD_MSG_BLOCK *)osMailAlloc(rb_decode_mailbox, 0);
|
||||
if (!msg_p) {
|
||||
TRACE(3, "%s fail, evt:%d,arg=%d \n", __func__, msg_src->evt, msg_src->arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
msg_p->evt = msg_src->evt;
|
||||
msg_p->arg = msg_src->arg;
|
||||
|
||||
status = osMailPut(rb_decode_mailbox, msg_p);
|
||||
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
static void rb_decode_thread(void const *argument)
|
||||
{
|
||||
RB_CTRL_CMD_T action;
|
||||
RBTHREAD_MSG_BLOCK* msg_p;
|
||||
int rb_decode_mailbox_free(RBTHREAD_MSG_BLOCK *msg_p) {
|
||||
osStatus status;
|
||||
|
||||
while(1) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, APP_SYSFREQ_32K);
|
||||
// evt = osSignalWait(0, osWaitForever);
|
||||
if(0 == rb_decode_mailbox_get(&msg_p)) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, APP_SYSFREQ_104M);
|
||||
status = osMailFree(rb_decode_mailbox, msg_p);
|
||||
|
||||
action = (RB_CTRL_CMD_T) msg_p->evt;
|
||||
rb_caller_tid = (osThreadId) msg_p->arg ;
|
||||
|
||||
TRACE(3,"[%s] action:%d ,tid,0x%x", __func__, action,rb_caller_tid);
|
||||
rb_thread_process_evt(action);
|
||||
|
||||
rb_decode_mailbox_free(msg_p);
|
||||
if( rb_caller_tid)
|
||||
osSignalSet(rb_decode_tid, 0x1203);
|
||||
rb_caller_tid = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
int app_rbplay_open(void)
|
||||
{
|
||||
if (rb_decode_tid != NULL) {
|
||||
warn("Decode thread reopen");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rb_decode_mailbox = osMailCreate(osMailQ(rb_decode_mailbox), NULL);
|
||||
if (rb_decode_mailbox == NULL) {
|
||||
error("Failed to Create rb_decode_mailbox");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rb_decode_tid = osThreadCreate(osThread(rb_decode_thread), NULL);
|
||||
if (rb_decode_tid == NULL) {
|
||||
error("Failed to Create rb_thread \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rb_decode_mailbox_get(RBTHREAD_MSG_BLOCK **msg_p) {
|
||||
osEvent evt;
|
||||
evt = osMailGet(rb_decode_mailbox, osWaitForever);
|
||||
if (evt.status == osEventMail) {
|
||||
*msg_p = (RBTHREAD_MSG_BLOCK *)evt.value.p;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rb_codec_running(void)
|
||||
{
|
||||
return ((rb_decode_halt_flag == 0)?1:0);
|
||||
}
|
||||
static void rb_decode_thread(void const *argument) {
|
||||
RB_CTRL_CMD_T action;
|
||||
RBTHREAD_MSG_BLOCK *msg_p;
|
||||
|
||||
void rb_codec_set_halt(int halt)
|
||||
{
|
||||
rb_decode_halt_flag = halt;
|
||||
}
|
||||
while (1) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, APP_SYSFREQ_32K);
|
||||
// evt = osSignalWait(0, osWaitForever);
|
||||
if (0 == rb_decode_mailbox_get(&msg_p)) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_PLAYER, APP_SYSFREQ_104M);
|
||||
|
||||
void rb_thread_set_decode_vars(int fd, int type ,void* id3)
|
||||
{
|
||||
song_fd =fd;
|
||||
song_format = type;
|
||||
current_id3 = (struct mp3entry *)id3;
|
||||
}
|
||||
action = (RB_CTRL_CMD_T)msg_p->evt;
|
||||
rb_caller_tid = (osThreadId)msg_p->arg;
|
||||
|
||||
void rb_player_sync_set_wait_thread(osThreadId tid)
|
||||
{
|
||||
if(rbplay_loop_on)
|
||||
thread_tid_waiter = tid;
|
||||
else
|
||||
thread_tid_waiter = NULL;
|
||||
}
|
||||
TRACE(3, "[%s] action:%d ,tid,0x%x", __func__, action, rb_caller_tid);
|
||||
rb_thread_process_evt(action);
|
||||
|
||||
void rb_player_sync_wait_close(void )
|
||||
{
|
||||
while(NULL != thread_tid_waiter) {
|
||||
osThreadYield();
|
||||
rb_decode_mailbox_free(msg_p);
|
||||
if (rb_caller_tid)
|
||||
osSignalSet(rb_decode_tid, 0x1203);
|
||||
rb_caller_tid = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void)
|
||||
{
|
||||
enum APP_SYSFREQ_FREQ_T freq;
|
||||
int app_rbplay_open(void) {
|
||||
if (rb_decode_tid != NULL) {
|
||||
warn("Decode thread reopen");
|
||||
return -1;
|
||||
}
|
||||
|
||||
hal_sysfreq_print();
|
||||
rb_decode_mailbox = osMailCreate(osMailQ(rb_decode_mailbox), NULL);
|
||||
if (rb_decode_mailbox == NULL) {
|
||||
error("Failed to Create rb_decode_mailbox");
|
||||
return -1;
|
||||
}
|
||||
|
||||
info("bitrate:%d freq:%d\n", ci->id3->bitrate, ci->id3->frequency);
|
||||
rb_decode_tid = osThreadCreate(osThread(rb_decode_thread), NULL);
|
||||
if (rb_decode_tid == NULL) {
|
||||
error("Failed to Create rb_thread \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rb_codec_running(void) { return ((rb_decode_halt_flag == 0) ? 1 : 0); }
|
||||
|
||||
void rb_codec_set_halt(int halt) { rb_decode_halt_flag = halt; }
|
||||
|
||||
void rb_thread_set_decode_vars(int fd, int type, void *id3) {
|
||||
song_fd = fd;
|
||||
song_format = type;
|
||||
current_id3 = (struct mp3entry *)id3;
|
||||
}
|
||||
|
||||
void rb_player_sync_set_wait_thread(osThreadId tid) {
|
||||
if (rbplay_loop_on)
|
||||
thread_tid_waiter = tid;
|
||||
else
|
||||
thread_tid_waiter = NULL;
|
||||
}
|
||||
|
||||
void rb_player_sync_wait_close(void) {
|
||||
while (NULL != thread_tid_waiter) {
|
||||
osThreadYield();
|
||||
}
|
||||
}
|
||||
|
||||
enum APP_SYSFREQ_FREQ_T rb_player_get_work_freq(void) {
|
||||
enum APP_SYSFREQ_FREQ_T freq;
|
||||
|
||||
hal_sysfreq_print();
|
||||
|
||||
info("bitrate:%d freq:%d\n", ci->id3->bitrate, ci->id3->frequency);
|
||||
#ifndef __TWS__
|
||||
enum AUD_SAMPRATE_T sample_rate = AUD_SAMPRATE_44100;
|
||||
sample_rate =(enum AUD_SAMPRATE_T ) ci->id3->frequency;
|
||||
if(sample_rate > AUD_SAMPRATE_48000)
|
||||
freq = APP_SYSFREQ_208M;
|
||||
else if (sample_rate > AUD_SAMPRATE_44100)
|
||||
freq = APP_SYSFREQ_104M;
|
||||
else
|
||||
freq = APP_SYSFREQ_52M;
|
||||
|
||||
if(ci->id3->bitrate > 192)
|
||||
freq = APP_SYSFREQ_208M;
|
||||
else if (ci->id3->bitrate > 128)
|
||||
freq = APP_SYSFREQ_104M;
|
||||
else
|
||||
freq = APP_SYSFREQ_52M;
|
||||
|
||||
switch( song_format ) {
|
||||
case AFMT_APE:
|
||||
freq = APP_SYSFREQ_208M;
|
||||
break;
|
||||
case AFMT_FLAC:
|
||||
freq = APP_SYSFREQ_208M;
|
||||
break;
|
||||
case AFMT_PCM_WAV:
|
||||
freq = APP_SYSFREQ_208M;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
enum AUD_SAMPRATE_T sample_rate = AUD_SAMPRATE_44100;
|
||||
sample_rate = (enum AUD_SAMPRATE_T)ci->id3->frequency;
|
||||
if (sample_rate > AUD_SAMPRATE_48000)
|
||||
freq = APP_SYSFREQ_208M;
|
||||
else if (sample_rate > AUD_SAMPRATE_44100)
|
||||
freq = APP_SYSFREQ_104M;
|
||||
else
|
||||
freq = APP_SYSFREQ_52M;
|
||||
|
||||
if (ci->id3->bitrate > 192)
|
||||
freq = APP_SYSFREQ_208M;
|
||||
else if (ci->id3->bitrate > 128)
|
||||
freq = APP_SYSFREQ_104M;
|
||||
else
|
||||
freq = APP_SYSFREQ_52M;
|
||||
|
||||
switch (song_format) {
|
||||
case AFMT_APE:
|
||||
freq = APP_SYSFREQ_208M;
|
||||
break;
|
||||
case AFMT_FLAC:
|
||||
freq = APP_SYSFREQ_208M;
|
||||
break;
|
||||
case AFMT_PCM_WAV:
|
||||
freq = APP_SYSFREQ_208M;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
freq = APP_SYSFREQ_208M;
|
||||
#endif
|
||||
info("Decode thread run at: %d", freq);
|
||||
return freq;
|
||||
info("Decode thread run at: %d", freq);
|
||||
return freq;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,18 +16,18 @@
|
|||
/* rbplay source */
|
||||
/* playback control & rockbox codec porting & codec thread */
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "SDFileSystem.h"
|
||||
#include "hal_trace.h"
|
||||
#include "metadata.h"
|
||||
#include "SDFileSystem.h"
|
||||
#include "rbplaysd.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -41,185 +41,182 @@ static playlist_item sd_curritem;
|
|||
|
||||
playlist_struct sd_playlist;
|
||||
|
||||
static void playlist_insert(playlist_item* item)
|
||||
{
|
||||
int fd;
|
||||
fd = open(PLAYLIST_PATH, O_RDWR | O_CREAT);
|
||||
if (fd <= 0) {
|
||||
error("Playlist open fail");
|
||||
return;
|
||||
}
|
||||
static void playlist_insert(playlist_item *item) {
|
||||
int fd;
|
||||
fd = open(PLAYLIST_PATH, O_RDWR | O_CREAT);
|
||||
if (fd <= 0) {
|
||||
error("Playlist open fail");
|
||||
return;
|
||||
}
|
||||
|
||||
lseek(fd, item->song_idx * sizeof(playlist_item), SEEK_SET);
|
||||
write(fd, item, sizeof(playlist_item));
|
||||
close(fd);
|
||||
lseek(fd, item->song_idx * sizeof(playlist_item), SEEK_SET);
|
||||
write(fd, item, sizeof(playlist_item));
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static bool sdcard_mount(void)
|
||||
{
|
||||
if (sdfs) {
|
||||
info("SD card already mount");
|
||||
return true;
|
||||
}
|
||||
|
||||
sdfs = new SDFileSystem(SD_LABEL);
|
||||
if (sdfs == NULL) {
|
||||
error("No memory for sd file system");
|
||||
return false;
|
||||
}
|
||||
|
||||
DIR *d;
|
||||
d = opendir("/" SD_LABEL);
|
||||
|
||||
if (!d) {
|
||||
warn("SD card mount error");
|
||||
return false;
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
static bool sdcard_mount(void) {
|
||||
if (sdfs) {
|
||||
info("SD card already mount");
|
||||
return true;
|
||||
}
|
||||
|
||||
sdfs = new SDFileSystem(SD_LABEL);
|
||||
if (sdfs == NULL) {
|
||||
error("No memory for sd file system");
|
||||
return false;
|
||||
}
|
||||
|
||||
DIR *d;
|
||||
d = opendir("/" SD_LABEL);
|
||||
|
||||
if (!d) {
|
||||
warn("SD card mount error");
|
||||
return false;
|
||||
}
|
||||
|
||||
closedir(d);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void app_rbplay_gen_playlist(playlist_struct *list)
|
||||
{
|
||||
struct dirent *p;
|
||||
DIR *d;
|
||||
uint32_t total;
|
||||
int fd = 0;
|
||||
struct mp3entry current_id3;
|
||||
playlist_item* sd_curritem_p = &sd_curritem;
|
||||
static void app_rbplay_gen_playlist(playlist_struct *list) {
|
||||
struct dirent *p;
|
||||
DIR *d;
|
||||
uint32_t total;
|
||||
int fd = 0;
|
||||
struct mp3entry current_id3;
|
||||
playlist_item *sd_curritem_p = &sd_curritem;
|
||||
|
||||
memset(list,0x0,sizeof(playlist_struct));
|
||||
memset(list, 0x0, sizeof(playlist_struct));
|
||||
|
||||
d = opendir("/" SD_LABEL);
|
||||
if (!d) {
|
||||
error("SD card open fail");
|
||||
return;
|
||||
d = opendir("/" SD_LABEL);
|
||||
if (!d) {
|
||||
error("SD card open fail");
|
||||
return;
|
||||
}
|
||||
|
||||
info("---------gen audio list---------");
|
||||
|
||||
total = 0;
|
||||
while (p = readdir(d)) {
|
||||
if (probe_file_format(p->d_name) == AFMT_UNKNOWN)
|
||||
continue;
|
||||
|
||||
memset(&sd_curritem, 0x0, sizeof(playlist_item));
|
||||
sd_curritem.song_idx = total;
|
||||
|
||||
sprintf(sd_curritem.file_path, "/" SD_LABEL "/%s", p->d_name);
|
||||
sprintf(sd_curritem.file_name, "%s", p->d_name);
|
||||
|
||||
info("Adding music: %s", sd_curritem.file_path);
|
||||
|
||||
fd = open(sd_curritem.file_path, O_RDONLY);
|
||||
|
||||
if (fd <= 0) {
|
||||
error("File %s open error", p->d_name);
|
||||
break;
|
||||
}
|
||||
|
||||
info("---------gen audio list---------");
|
||||
get_metadata(¤t_id3, fd, sd_curritem.file_path);
|
||||
close(fd);
|
||||
|
||||
total = 0;
|
||||
while (p = readdir(d)) {
|
||||
if (probe_file_format(p->d_name) == AFMT_UNKNOWN)
|
||||
continue;
|
||||
if (current_id3.bitrate == 0 || current_id3.filesize == 0 ||
|
||||
current_id3.length == 0)
|
||||
break;
|
||||
|
||||
memset(&sd_curritem,0x0,sizeof(playlist_item));
|
||||
sd_curritem.song_idx = total;
|
||||
info("bits:%d, type:%d, freq:%d", current_id3.bitrate,
|
||||
current_id3.codectype, current_id3.frequency);
|
||||
|
||||
sprintf(sd_curritem.file_path, "/" SD_LABEL "/%s", p->d_name);
|
||||
sprintf(sd_curritem.file_name, "%s", p->d_name);
|
||||
|
||||
info("Adding music: %s", sd_curritem.file_path);
|
||||
|
||||
fd = open(sd_curritem.file_path, O_RDONLY);
|
||||
|
||||
if (fd <= 0) {
|
||||
error("File %s open error", p->d_name);
|
||||
break;
|
||||
}
|
||||
|
||||
get_metadata(¤t_id3, fd, sd_curritem.file_path);
|
||||
close(fd);
|
||||
|
||||
if(current_id3.bitrate == 0 || current_id3.filesize == 0 || current_id3.length == 0)
|
||||
break;
|
||||
|
||||
info("bits:%d, type:%d, freq:%d", current_id3.bitrate,
|
||||
current_id3.codectype, current_id3.frequency);
|
||||
|
||||
sd_curritem_p->bitrate = current_id3.bitrate;
|
||||
sd_curritem_p->codectype = current_id3.codectype;
|
||||
sd_curritem_p->filesize = current_id3.filesize;
|
||||
sd_curritem_p->length = current_id3.length;
|
||||
sd_curritem_p->frequency = current_id3.frequency;
|
||||
sd_curritem_p->bitrate = current_id3.bitrate;
|
||||
sd_curritem_p->codectype = current_id3.codectype;
|
||||
sd_curritem_p->filesize = current_id3.filesize;
|
||||
sd_curritem_p->length = current_id3.length;
|
||||
sd_curritem_p->frequency = current_id3.frequency;
|
||||
|
||||
#ifdef PARSER_DETAIL
|
||||
char *str;
|
||||
str = current_id3.title;
|
||||
if(str != NULL) {
|
||||
memset(sd_curritem_p->title,0x0,MP3_TITLE_LEN);
|
||||
memcpy(sd_curritem_p->title ,str,strlen(str)>MP3_TITLE_LEN?MP3_TITLE_LEN:strlen(str));
|
||||
}
|
||||
char *str;
|
||||
str = current_id3.title;
|
||||
if (str != NULL) {
|
||||
memset(sd_curritem_p->title, 0x0, MP3_TITLE_LEN);
|
||||
memcpy(sd_curritem_p->title, str,
|
||||
strlen(str) > MP3_TITLE_LEN ? MP3_TITLE_LEN : strlen(str));
|
||||
}
|
||||
|
||||
str = current_id3.artist;
|
||||
if(str != NULL) {
|
||||
memset(sd_curritem_p->artist,0x0,MP3_ARTIST_LEN);
|
||||
memcpy(sd_curritem_p->artist ,str,strlen(str)>MP3_ARTIST_LEN?MP3_ARTIST_LEN:strlen(str));
|
||||
}
|
||||
str = current_id3.artist;
|
||||
if (str != NULL) {
|
||||
memset(sd_curritem_p->artist, 0x0, MP3_ARTIST_LEN);
|
||||
memcpy(sd_curritem_p->artist, str,
|
||||
strlen(str) > MP3_ARTIST_LEN ? MP3_ARTIST_LEN : strlen(str));
|
||||
}
|
||||
|
||||
str = current_id3.album;
|
||||
if(str != NULL) {
|
||||
memset(sd_curritem_p->album,0x0,MP3_ALBUM_LEN);
|
||||
memcpy(sd_curritem_p->album ,str,strlen(str)>MP3_ALBUM_LEN?MP3_ALBUM_LEN:strlen(str));
|
||||
}
|
||||
str = current_id3.album;
|
||||
if (str != NULL) {
|
||||
memset(sd_curritem_p->album, 0x0, MP3_ALBUM_LEN);
|
||||
memcpy(sd_curritem_p->album, str,
|
||||
strlen(str) > MP3_ALBUM_LEN ? MP3_ALBUM_LEN : strlen(str));
|
||||
}
|
||||
|
||||
str = current_id3.genre_string;
|
||||
if(str != NULL) {
|
||||
memset(sd_curritem_p->genre,0x0,MP3_GENRE_LEN);
|
||||
memcpy(sd_curritem_p->genre ,str,strlen(str)>MP3_GENRE_LEN?MP3_GENRE_LEN:strlen(str));
|
||||
}
|
||||
str = current_id3.genre_string;
|
||||
if (str != NULL) {
|
||||
memset(sd_curritem_p->genre, 0x0, MP3_GENRE_LEN);
|
||||
memcpy(sd_curritem_p->genre, str,
|
||||
strlen(str) > MP3_GENRE_LEN ? MP3_GENRE_LEN : strlen(str));
|
||||
}
|
||||
|
||||
str = current_id3.composer;
|
||||
if(str != NULL) {
|
||||
memset(sd_curritem_p->composer,0x0,MP3_COMPOSER_LEN);
|
||||
memcpy(sd_curritem_p->composer ,str,strlen(str)>MP3_COMPOSER_LEN?MP3_COMPOSER_LEN:strlen(str));
|
||||
}
|
||||
str = current_id3.composer;
|
||||
if (str != NULL) {
|
||||
memset(sd_curritem_p->composer, 0x0, MP3_COMPOSER_LEN);
|
||||
memcpy(sd_curritem_p->composer, str,
|
||||
strlen(str) > MP3_COMPOSER_LEN ? MP3_COMPOSER_LEN : strlen(str));
|
||||
}
|
||||
#endif
|
||||
playlist_insert(sd_curritem_p);
|
||||
total++;
|
||||
}
|
||||
playlist_insert(sd_curritem_p);
|
||||
total++;
|
||||
}
|
||||
|
||||
list->total_songs = total ;
|
||||
list->current_item = sd_curritem_p;
|
||||
|
||||
closedir(d);
|
||||
info("---------%d audio file searched---------" , total);
|
||||
list->total_songs = total;
|
||||
list->current_item = sd_curritem_p;
|
||||
|
||||
closedir(d);
|
||||
info("---------%d audio file searched---------", total);
|
||||
}
|
||||
|
||||
void app_rbplay_load_playlist(playlist_struct *list)
|
||||
{
|
||||
if(sdcard_mount() == false)
|
||||
return;
|
||||
void app_rbplay_load_playlist(playlist_struct *list) {
|
||||
if (sdcard_mount() == false)
|
||||
return;
|
||||
|
||||
remove(PLAYLIST_PATH);
|
||||
remove(PLAYLIST_PATH);
|
||||
|
||||
app_rbplay_gen_playlist(list);
|
||||
app_rbplay_gen_playlist(list);
|
||||
}
|
||||
|
||||
playlist_item *app_rbplay_get_playitem(const int idx)
|
||||
{
|
||||
int fd;
|
||||
if(idx >= sd_playlist.total_songs) {
|
||||
warn("Index exceed: %d / %d", idx, sd_playlist.total_songs);
|
||||
return NULL;
|
||||
}
|
||||
playlist_item *app_rbplay_get_playitem(const int idx) {
|
||||
int fd;
|
||||
if (idx >= sd_playlist.total_songs) {
|
||||
warn("Index exceed: %d / %d", idx, sd_playlist.total_songs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = open(PLAYLIST_PATH, O_RDONLY);
|
||||
fd = open(PLAYLIST_PATH, O_RDONLY);
|
||||
|
||||
if (fd <= 0) {
|
||||
warn("SD card playlist can not open");
|
||||
return NULL;
|
||||
}
|
||||
if (fd <= 0) {
|
||||
warn("SD card playlist can not open");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lseek(fd, sizeof(playlist_item) * idx, SEEK_SET);
|
||||
read(fd, sd_playlist.current_item, sizeof(playlist_item));
|
||||
info("Get playitem: %d: %s", idx, sd_playlist.current_item->file_path);
|
||||
lseek(fd, sizeof(playlist_item) * idx, SEEK_SET);
|
||||
read(fd, sd_playlist.current_item, sizeof(playlist_item));
|
||||
info("Get playitem: %d: %s", idx, sd_playlist.current_item->file_path);
|
||||
|
||||
close(fd);
|
||||
close(fd);
|
||||
|
||||
return sd_playlist.current_item;
|
||||
return sd_playlist.current_item;
|
||||
}
|
||||
|
||||
int app_ctl_remove_file(const int idx)
|
||||
{
|
||||
playlist_item *item = app_rbplay_get_playitem(idx);
|
||||
if (!item)
|
||||
return -1;
|
||||
remove(item->file_path);
|
||||
int app_ctl_remove_file(const int idx) {
|
||||
playlist_item *item = app_rbplay_get_playitem(idx);
|
||||
if (!item)
|
||||
return -1;
|
||||
remove(item->file_path);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,39 +13,37 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "cmsis_os.h"
|
||||
#include "app_utils.h"
|
||||
#include "audio_dump.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "string.h"
|
||||
#include "audio_dump.h"
|
||||
// #include "local_wav.h"
|
||||
|
||||
#define CHANNEL_NUM (2)
|
||||
#define CHANNEL_NUM (2)
|
||||
|
||||
#define CHAR_BYTES (1)
|
||||
#define SHORT_BYTES (2)
|
||||
#define INT_BYTES (4)
|
||||
#define CHAR_BYTES (1)
|
||||
#define SHORT_BYTES (2)
|
||||
#define INT_BYTES (4)
|
||||
|
||||
#define SAMPLE_BITS (16)
|
||||
#define SAMPLE_BYTES (SAMPLE_BITS / 8)
|
||||
#define SAMPLE_BITS (16)
|
||||
#define SAMPLE_BYTES (SAMPLE_BITS / 8)
|
||||
|
||||
#define TX_SAMPLE_RATE (16000)
|
||||
#define RX_SAMPLE_RATE (16000)
|
||||
|
||||
#define TX_SAMPLE_RATE (16000)
|
||||
#define RX_SAMPLE_RATE (16000)
|
||||
#define TX_FRAME_LEN (256)
|
||||
#define RX_FRAME_LEN (256)
|
||||
|
||||
|
||||
#define TX_FRAME_LEN (256)
|
||||
#define RX_FRAME_LEN (256)
|
||||
|
||||
#define TX_BUF_SIZE (TX_FRAME_LEN * CHANNEL_NUM * SAMPLE_BYTES * 2)
|
||||
#define RX_BUF_SIZE (RX_FRAME_LEN * CHANNEL_NUM * SAMPLE_BYTES * 2)
|
||||
#define TX_BUF_SIZE (TX_FRAME_LEN * CHANNEL_NUM * SAMPLE_BYTES * 2)
|
||||
#define RX_BUF_SIZE (RX_FRAME_LEN * CHANNEL_NUM * SAMPLE_BYTES * 2)
|
||||
|
||||
#if SAMPLE_BYTES == SHORT_BYTES
|
||||
typedef short VOICE_PCM_T;
|
||||
typedef short VOICE_PCM_T;
|
||||
#elif SAMPLE_BYTES == INT_BYTES
|
||||
typedef int VOICE_PCM_T;
|
||||
typedef int VOICE_PCM_T;
|
||||
#else
|
||||
#error "Invalid SAMPLE_BYTES!!!"
|
||||
#endif
|
||||
|
@ -56,130 +54,127 @@ static uint8_t POSSIBLY_UNUSED codec_playback_buf[RX_BUF_SIZE];
|
|||
static uint32_t POSSIBLY_UNUSED codec_capture_cnt = 0;
|
||||
static uint32_t POSSIBLY_UNUSED codec_playback_cnt = 0;
|
||||
|
||||
#define CODEC_STREAM_ID AUD_STREAM_ID_0
|
||||
#define CODEC_STREAM_ID AUD_STREAM_ID_0
|
||||
|
||||
static uint32_t codec_capture_callback(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
||||
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
||||
int interval_len = len * 2 / CHANNEL_NUM;
|
||||
static uint32_t codec_capture_callback(uint8_t *buf, uint32_t len) {
|
||||
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
||||
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
||||
int interval_len = len * 2 / CHANNEL_NUM;
|
||||
|
||||
for (int i=0; i<CHANNEL_NUM; i++) {
|
||||
pcm_buf[i] = (VOICE_PCM_T *)(buf + i * interval_len);
|
||||
}
|
||||
for (int i = 0; i < CHANNEL_NUM; i++) {
|
||||
pcm_buf[i] = (VOICE_PCM_T *)(buf + i * interval_len);
|
||||
}
|
||||
|
||||
// TRACE(2,"[%s] cnt = %d", __func__, codec_capture_cnt++);
|
||||
// TRACE(2,"[%s] cnt = %d", __func__, codec_capture_cnt++);
|
||||
|
||||
audio_dump_add_channel_data(0, pcm_buf[0], pcm_len);
|
||||
audio_dump_add_channel_data(1, pcm_buf[0], pcm_len);
|
||||
audio_dump_run();
|
||||
audio_dump_add_channel_data(0, pcm_buf[0], pcm_len);
|
||||
audio_dump_add_channel_data(1, pcm_buf[0], pcm_len);
|
||||
audio_dump_run();
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint32_t codec_playback_callback(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
||||
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
||||
int interval_len = len * 2 / CHANNEL_NUM;
|
||||
static uint32_t codec_playback_callback(uint8_t *buf, uint32_t len) {
|
||||
int POSSIBLY_UNUSED pcm_len = len / sizeof(VOICE_PCM_T) / CHANNEL_NUM;
|
||||
VOICE_PCM_T POSSIBLY_UNUSED *pcm_buf[CHANNEL_NUM];
|
||||
int interval_len = len * 2 / CHANNEL_NUM;
|
||||
|
||||
for (int i=0; i<CHANNEL_NUM; i++) {
|
||||
pcm_buf[i] = (VOICE_PCM_T *)(buf + i * interval_len);
|
||||
}
|
||||
for (int i = 0; i < CHANNEL_NUM; i++) {
|
||||
pcm_buf[i] = (VOICE_PCM_T *)(buf + i * interval_len);
|
||||
}
|
||||
|
||||
// TRACE(2,"[%s] cnt = %d", __func__, codec_playback_cnt++);
|
||||
// TRACE(2,"[%s] cnt = %d", __func__, codec_playback_cnt++);
|
||||
|
||||
return len;
|
||||
return len;
|
||||
}
|
||||
|
||||
static int voice_start(bool on)
|
||||
{
|
||||
int ret = 0;
|
||||
static bool isRun = false;
|
||||
enum APP_SYSFREQ_FREQ_T freq = APP_SYSFREQ_208M;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static int voice_start(bool on) {
|
||||
int ret = 0;
|
||||
static bool isRun = false;
|
||||
enum APP_SYSFREQ_FREQ_T freq = APP_SYSFREQ_208M;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
|
||||
if (isRun == on) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (on) {
|
||||
TRACE(1, "[%s]] ON", __func__);
|
||||
|
||||
af_set_priority(AF_USER_TEST, osPriorityHigh);
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||
TRACE(2, "[%s] sys freq calc : %d\n", __func__, hal_sys_timer_calc_cpu_freq(5, 0));
|
||||
|
||||
// Initialize Cqueue
|
||||
codec_capture_cnt = 0;
|
||||
codec_playback_cnt = 0;
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)CHANNEL_NUM;
|
||||
stream_cfg.data_size = TX_BUF_SIZE;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)TX_SAMPLE_RATE;
|
||||
stream_cfg.bits = (enum AUD_BITS_T)SAMPLE_BITS;
|
||||
stream_cfg.vol = 12;
|
||||
stream_cfg.chan_sep_buf = true;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.handler = codec_capture_callback;
|
||||
stream_cfg.data_ptr = codec_capture_buf;
|
||||
|
||||
TRACE(3, "[%s] codec capture sample_rate: %d, data_size: %d", __func__, stream_cfg.sample_rate, stream_cfg.data_size);
|
||||
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
ASSERT(ret == 0, "codec capture failed: %d", ret);
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)CHANNEL_NUM;
|
||||
stream_cfg.data_size = RX_BUF_SIZE;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)RX_SAMPLE_RATE;
|
||||
stream_cfg.bits = (enum AUD_BITS_T)SAMPLE_BITS;
|
||||
stream_cfg.vol = 12;
|
||||
stream_cfg.chan_sep_buf = true;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.handler = codec_playback_callback;
|
||||
stream_cfg.data_ptr = codec_playback_buf;
|
||||
|
||||
TRACE(3, "[%s] codec playback sample_rate: %d, data_size: %d", __func__, stream_cfg.sample_rate, stream_cfg.data_size);
|
||||
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
ASSERT(ret == 0, "codec playback failed: %d", ret);
|
||||
|
||||
audio_dump_init(TX_FRAME_LEN, sizeof(VOICE_PCM_T), 1);
|
||||
|
||||
// Start
|
||||
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Close stream
|
||||
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
|
||||
audio_dump_deinit();
|
||||
|
||||
af_stream_close(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
|
||||
af_set_priority(AF_USER_TEST, osPriorityAboveNormal);
|
||||
|
||||
TRACE(1, "[%s] OFF", __func__);
|
||||
}
|
||||
|
||||
isRun=on;
|
||||
if (isRun == on) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (on) {
|
||||
TRACE(1, "[%s]] ON", __func__);
|
||||
|
||||
af_set_priority(AF_USER_TEST, osPriorityHigh);
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||
TRACE(2, "[%s] sys freq calc : %d\n", __func__,
|
||||
hal_sys_timer_calc_cpu_freq(5, 0));
|
||||
|
||||
// Initialize Cqueue
|
||||
codec_capture_cnt = 0;
|
||||
codec_playback_cnt = 0;
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)CHANNEL_NUM;
|
||||
stream_cfg.data_size = TX_BUF_SIZE;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)TX_SAMPLE_RATE;
|
||||
stream_cfg.bits = (enum AUD_BITS_T)SAMPLE_BITS;
|
||||
stream_cfg.vol = 12;
|
||||
stream_cfg.chan_sep_buf = true;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.handler = codec_capture_callback;
|
||||
stream_cfg.data_ptr = codec_capture_buf;
|
||||
|
||||
TRACE(3, "[%s] codec capture sample_rate: %d, data_size: %d", __func__,
|
||||
stream_cfg.sample_rate, stream_cfg.data_size);
|
||||
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
ASSERT(ret == 0, "codec capture failed: %d", ret);
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.channel_num = (enum AUD_CHANNEL_NUM_T)CHANNEL_NUM;
|
||||
stream_cfg.data_size = RX_BUF_SIZE;
|
||||
stream_cfg.sample_rate = (enum AUD_SAMPRATE_T)RX_SAMPLE_RATE;
|
||||
stream_cfg.bits = (enum AUD_BITS_T)SAMPLE_BITS;
|
||||
stream_cfg.vol = 12;
|
||||
stream_cfg.chan_sep_buf = true;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.handler = codec_playback_callback;
|
||||
stream_cfg.data_ptr = codec_playback_buf;
|
||||
|
||||
TRACE(3, "[%s] codec playback sample_rate: %d, data_size: %d", __func__,
|
||||
stream_cfg.sample_rate, stream_cfg.data_size);
|
||||
af_stream_open(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
ASSERT(ret == 0, "codec playback failed: %d", ret);
|
||||
|
||||
audio_dump_init(TX_FRAME_LEN, sizeof(VOICE_PCM_T), 1);
|
||||
|
||||
// Start
|
||||
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
af_stream_start(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
} else {
|
||||
// Close stream
|
||||
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
af_stream_stop(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
|
||||
audio_dump_deinit();
|
||||
|
||||
af_stream_close(CODEC_STREAM_ID, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(CODEC_STREAM_ID, AUD_STREAM_CAPTURE);
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
|
||||
af_set_priority(AF_USER_TEST, osPriorityAboveNormal);
|
||||
|
||||
TRACE(1, "[%s] OFF", __func__);
|
||||
}
|
||||
|
||||
isRun = on;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool voice_test_status = true;
|
||||
void voice_test(void)
|
||||
{
|
||||
TRACE(2, "[%s] status = %d", __func__, voice_test_status);
|
||||
void voice_test(void) {
|
||||
TRACE(2, "[%s] status = %d", __func__, voice_test_status);
|
||||
|
||||
voice_start(voice_test_status);
|
||||
voice_test_status = !voice_test_status;
|
||||
voice_start(voice_test_status);
|
||||
voice_test_status = !voice_test_status;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -17,46 +17,44 @@
|
|||
#include "mbed.h"
|
||||
#endif
|
||||
// Standard C Included Files
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "hal_uart.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_uart.h"
|
||||
|
||||
/*!
|
||||
* * @brief Standard Winodws PCM wave file header length
|
||||
* */
|
||||
#define WAVE_FILE_HEADER_SIZE 0x2CU
|
||||
#define WAVE_FILE_HEADER_SIZE 0x2CU
|
||||
|
||||
typedef struct wave_header
|
||||
{
|
||||
uint8_t riff[4];
|
||||
uint32_t size;
|
||||
uint8_t waveFlag[4];
|
||||
uint8_t fmt[4];
|
||||
uint32_t fmtLen;
|
||||
uint16_t tag;
|
||||
uint16_t channels;
|
||||
uint32_t sampFreq;
|
||||
uint32_t byteRate;
|
||||
uint16_t blockAlign;
|
||||
uint16_t bitSamp;
|
||||
uint8_t dataFlag[4];
|
||||
uint32_t length;
|
||||
typedef struct wave_header {
|
||||
uint8_t riff[4];
|
||||
uint32_t size;
|
||||
uint8_t waveFlag[4];
|
||||
uint8_t fmt[4];
|
||||
uint32_t fmtLen;
|
||||
uint16_t tag;
|
||||
uint16_t channels;
|
||||
uint32_t sampFreq;
|
||||
uint32_t byteRate;
|
||||
uint16_t blockAlign;
|
||||
uint16_t bitSamp;
|
||||
uint8_t dataFlag[4];
|
||||
uint32_t length;
|
||||
} wave_header_t;
|
||||
|
||||
/*!
|
||||
* * @brief Wave file structure
|
||||
* */
|
||||
typedef struct wave_file
|
||||
{
|
||||
wave_header_t header;
|
||||
uint32_t *data;
|
||||
}wave_file_t;
|
||||
typedef struct wave_file {
|
||||
wave_header_t header;
|
||||
uint32_t *data;
|
||||
} wave_file_t;
|
||||
|
||||
/* player */
|
||||
static unsigned int g_total_play_count = 0;
|
||||
|
@ -66,188 +64,179 @@ static unsigned int g_curr_play_index = 0;
|
|||
wave_file_t g_wave_file_info;
|
||||
static char g_wav_header[WAVE_FILE_HEADER_SIZE];
|
||||
FILE *g_wave_file_handle = NULL;
|
||||
static int32_t (*wav_file_playback_callback)(int32_t ) = NULL;
|
||||
static int32_t (*wav_file_playback_callback)(int32_t) = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void wav_file_set_playeback_cb(int32_t (* cb)(int32_t))
|
||||
{
|
||||
wav_file_playback_callback = cb;
|
||||
void wav_file_set_playeback_cb(int32_t (*cb)(int32_t)) {
|
||||
wav_file_playback_callback = cb;
|
||||
}
|
||||
bool wav_file_isplaydone(void)
|
||||
{
|
||||
return (g_curr_play_index >= g_total_play_count)? true : false;
|
||||
bool wav_file_isplaydone(void) {
|
||||
return (g_curr_play_index >= g_total_play_count) ? true : false;
|
||||
}
|
||||
uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
// static uint32_t g_preIrqTime = 0;
|
||||
uint32_t reallen = 0;
|
||||
// int32_t stime,etime;
|
||||
int32_t status;
|
||||
uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len) {
|
||||
// static uint32_t g_preIrqTime = 0;
|
||||
uint32_t reallen = 0;
|
||||
// int32_t stime,etime;
|
||||
int32_t status;
|
||||
|
||||
/* play done ? */
|
||||
if(wav_file_isplaydone()) {
|
||||
memset(buf, 0, len);
|
||||
status = 0;
|
||||
if (wav_file_playback_callback)
|
||||
wav_file_playback_callback(status);
|
||||
return (len);
|
||||
}
|
||||
// stime = hal_sys_timer_get();
|
||||
/* read file */
|
||||
if (g_wave_file_handle)
|
||||
reallen = fread(buf, 1, len, g_wave_file_handle);
|
||||
// etime = hal_sys_timer_get();
|
||||
if (reallen != len){
|
||||
memset(buf, 0, len);
|
||||
status = -1;
|
||||
if (wav_file_playback_callback)
|
||||
wav_file_playback_callback(status);
|
||||
return (len);
|
||||
}
|
||||
|
||||
// TRACE(5,"wav_file_audio_more_data irqDur:%d fsSpend:%d, readbuff:0x%08x %d/%d\n ", TICKS_TO_MS(stime - g_preIrqTime),TICKS_TO_MS(etime - stime),buf,reallen,len);
|
||||
// g_preIrqTime = stime;
|
||||
|
||||
/* walk index */
|
||||
g_curr_play_index += reallen;
|
||||
|
||||
return reallen;
|
||||
}
|
||||
|
||||
uint32_t get_wav_data(wave_file_t *waveFile)
|
||||
{
|
||||
uint8_t *dataTemp = (uint8_t *)waveFile->data;
|
||||
|
||||
// check for RIFF
|
||||
memcpy(waveFile->header.riff, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if( memcmp( (uint8_t*)waveFile->header.riff, "RIFF", 4) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get size
|
||||
memcpy(&waveFile->header.size, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
TRACE(1,"WAV header size [%d]\n", waveFile->header.size);
|
||||
|
||||
// .wav file flag
|
||||
memcpy(waveFile->header.waveFlag, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if( memcmp( (uint8_t*)waveFile->header.waveFlag, "WAVE", 4) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fmt
|
||||
memcpy(waveFile->header.fmt, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if( memcmp( (uint8_t*)waveFile->header.fmt, "fmt ", 4) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fmt length
|
||||
memcpy(&waveFile->header.fmtLen, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
// Tag: PCM or not
|
||||
memcpy(&waveFile->header.tag, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
|
||||
// Channels
|
||||
memcpy(&waveFile->header.channels, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
|
||||
TRACE(1,"WAV channels [%d]\n", waveFile->header.channels);
|
||||
|
||||
// Sample Rate in Hz
|
||||
memcpy(&waveFile->header.sampFreq, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
memcpy(&waveFile->header.byteRate, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
TRACE(1,"WAV sample_rate [%d]\n", waveFile->header.sampFreq);
|
||||
TRACE(1,"WAV byteRate [%d]\n", waveFile->header.byteRate);
|
||||
|
||||
// quantize bytes for per samp point
|
||||
memcpy(&waveFile->header.blockAlign, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
memcpy(&waveFile->header.bitSamp, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
|
||||
TRACE(1,"WAV bitSamp [%d]\n", waveFile->header.bitSamp);
|
||||
|
||||
// Data
|
||||
memcpy(waveFile->header.dataFlag, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if( memcmp( (uint8_t*)waveFile->header.dataFlag, "data ", 4) )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memcpy(&waveFile->header.length, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void audio_wav_init(wave_file_t *newWav)
|
||||
{
|
||||
get_wav_data(newWav);
|
||||
|
||||
// Configure the play audio g_format
|
||||
//g_format.bits = newWav->header.bitSamp;
|
||||
//g_format.sample_rate = newWav->header.sampFreq;
|
||||
//g_format.mclk = 256 * g_format.sample_rate ;
|
||||
//g_format.mono_streo = (sai_mono_streo_t)((newWav->header.channels) - 1);
|
||||
}
|
||||
|
||||
uint32_t play_wav_file(char *file_path)
|
||||
{
|
||||
uint32_t bytesToRead = 0;
|
||||
|
||||
wave_file_t *newWav = &g_wave_file_info;
|
||||
|
||||
memset(&g_wave_file_info, 0, sizeof(g_wave_file_info));
|
||||
|
||||
g_wave_file_handle = fopen(file_path, "rb");
|
||||
|
||||
if(g_wave_file_handle == NULL) {
|
||||
TRACE(1,"WAV file %s open fail\n", file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fread(&g_wav_header, WAVE_FILE_HEADER_SIZE, 1, g_wave_file_handle);
|
||||
|
||||
newWav->data = (uint32_t *)&g_wav_header;
|
||||
|
||||
audio_wav_init(newWav);
|
||||
|
||||
// Remove header size from byte count
|
||||
// Adjust note duration by divider value, wav tables in pcm_data.h are 200ms by default
|
||||
bytesToRead = (newWav->header.length - WAVE_FILE_HEADER_SIZE);
|
||||
|
||||
g_curr_play_index = 0;
|
||||
g_total_play_count = bytesToRead;
|
||||
|
||||
return newWav->header.sampFreq;
|
||||
}
|
||||
|
||||
uint32_t stop_wav_file(void)
|
||||
{
|
||||
memset(&g_wave_file_info, 0, sizeof(g_wave_file_info));
|
||||
g_curr_play_index = 0;
|
||||
g_total_play_count = 0;
|
||||
if (g_wave_file_handle){
|
||||
fclose(g_wave_file_handle);
|
||||
g_wave_file_handle = NULL;
|
||||
}
|
||||
/* play done ? */
|
||||
if (wav_file_isplaydone()) {
|
||||
memset(buf, 0, len);
|
||||
status = 0;
|
||||
if (wav_file_playback_callback)
|
||||
wav_file_playback_callback = NULL;
|
||||
wav_file_playback_callback(status);
|
||||
return (len);
|
||||
}
|
||||
// stime = hal_sys_timer_get();
|
||||
/* read file */
|
||||
if (g_wave_file_handle)
|
||||
reallen = fread(buf, 1, len, g_wave_file_handle);
|
||||
// etime = hal_sys_timer_get();
|
||||
if (reallen != len) {
|
||||
memset(buf, 0, len);
|
||||
status = -1;
|
||||
if (wav_file_playback_callback)
|
||||
wav_file_playback_callback(status);
|
||||
return (len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
// TRACE(5,"wav_file_audio_more_data irqDur:%d fsSpend:%d, readbuff:0x%08x
|
||||
// %d/%d\n ", TICKS_TO_MS(stime - g_preIrqTime),TICKS_TO_MS(etime -
|
||||
// stime),buf,reallen,len);
|
||||
// g_preIrqTime = stime;
|
||||
|
||||
/* walk index */
|
||||
g_curr_play_index += reallen;
|
||||
|
||||
return reallen;
|
||||
}
|
||||
|
||||
uint32_t get_wav_data(wave_file_t *waveFile) {
|
||||
uint8_t *dataTemp = (uint8_t *)waveFile->data;
|
||||
|
||||
// check for RIFF
|
||||
memcpy(waveFile->header.riff, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if (memcmp((uint8_t *)waveFile->header.riff, "RIFF", 4)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get size
|
||||
memcpy(&waveFile->header.size, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
TRACE(1, "WAV header size [%d]\n", waveFile->header.size);
|
||||
|
||||
// .wav file flag
|
||||
memcpy(waveFile->header.waveFlag, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if (memcmp((uint8_t *)waveFile->header.waveFlag, "WAVE", 4)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fmt
|
||||
memcpy(waveFile->header.fmt, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if (memcmp((uint8_t *)waveFile->header.fmt, "fmt ", 4)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fmt length
|
||||
memcpy(&waveFile->header.fmtLen, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
// Tag: PCM or not
|
||||
memcpy(&waveFile->header.tag, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
|
||||
// Channels
|
||||
memcpy(&waveFile->header.channels, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
|
||||
TRACE(1, "WAV channels [%d]\n", waveFile->header.channels);
|
||||
|
||||
// Sample Rate in Hz
|
||||
memcpy(&waveFile->header.sampFreq, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
memcpy(&waveFile->header.byteRate, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
TRACE(1, "WAV sample_rate [%d]\n", waveFile->header.sampFreq);
|
||||
TRACE(1, "WAV byteRate [%d]\n", waveFile->header.byteRate);
|
||||
|
||||
// quantize bytes for per samp point
|
||||
memcpy(&waveFile->header.blockAlign, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
memcpy(&waveFile->header.bitSamp, dataTemp, 4);
|
||||
dataTemp += 2;
|
||||
|
||||
TRACE(1, "WAV bitSamp [%d]\n", waveFile->header.bitSamp);
|
||||
|
||||
// Data
|
||||
memcpy(waveFile->header.dataFlag, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
if (memcmp((uint8_t *)waveFile->header.dataFlag, "data ", 4)) {
|
||||
return 0;
|
||||
}
|
||||
memcpy(&waveFile->header.length, dataTemp, 4);
|
||||
dataTemp += 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void audio_wav_init(wave_file_t *newWav) {
|
||||
get_wav_data(newWav);
|
||||
|
||||
// Configure the play audio g_format
|
||||
// g_format.bits = newWav->header.bitSamp;
|
||||
// g_format.sample_rate = newWav->header.sampFreq;
|
||||
// g_format.mclk = 256 * g_format.sample_rate ;
|
||||
// g_format.mono_streo = (sai_mono_streo_t)((newWav->header.channels) - 1);
|
||||
}
|
||||
|
||||
uint32_t play_wav_file(char *file_path) {
|
||||
uint32_t bytesToRead = 0;
|
||||
|
||||
wave_file_t *newWav = &g_wave_file_info;
|
||||
|
||||
memset(&g_wave_file_info, 0, sizeof(g_wave_file_info));
|
||||
|
||||
g_wave_file_handle = fopen(file_path, "rb");
|
||||
|
||||
if (g_wave_file_handle == NULL) {
|
||||
TRACE(1, "WAV file %s open fail\n", file_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fread(&g_wav_header, WAVE_FILE_HEADER_SIZE, 1, g_wave_file_handle);
|
||||
|
||||
newWav->data = (uint32_t *)&g_wav_header;
|
||||
|
||||
audio_wav_init(newWav);
|
||||
|
||||
// Remove header size from byte count
|
||||
// Adjust note duration by divider value, wav tables in pcm_data.h are 200ms
|
||||
// by default
|
||||
bytesToRead = (newWav->header.length - WAVE_FILE_HEADER_SIZE);
|
||||
|
||||
g_curr_play_index = 0;
|
||||
g_total_play_count = bytesToRead;
|
||||
|
||||
return newWav->header.sampFreq;
|
||||
}
|
||||
|
||||
uint32_t stop_wav_file(void) {
|
||||
memset(&g_wave_file_info, 0, sizeof(g_wave_file_info));
|
||||
g_curr_play_index = 0;
|
||||
g_total_play_count = 0;
|
||||
if (g_wave_file_handle) {
|
||||
fclose(g_wave_file_handle);
|
||||
g_wave_file_handle = NULL;
|
||||
}
|
||||
if (wav_file_playback_callback)
|
||||
wav_file_playback_callback = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,22 +13,22 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "stdio.h"
|
||||
#include "app_audio.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_audio.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#include "a2dp_api.h"
|
||||
#include "app_bt.h"
|
||||
#include "btapp.h"
|
||||
#include "usb_audio_app.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 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);
|
||||
|
@ -38,270 +38,223 @@ 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;
|
||||
#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;
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
BT_USB_DEBUG();
|
||||
}
|
||||
// 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__);
|
||||
}
|
||||
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();
|
||||
bool btusb_is_bt_mode(void) {
|
||||
BT_USB_DEBUG();
|
||||
return btusb_mode == BTUSB_MODE_BT ? true : false;
|
||||
}
|
||||
|
||||
static void btusb_usbaudio_entry(void)
|
||||
{
|
||||
BT_USB_DEBUG();
|
||||
btusbaudio_entry();
|
||||
btusb_usb_is_on = true ;
|
||||
bool btusb_is_usb_mode(void) {
|
||||
return btusb_mode == BTUSB_MODE_USB ? true : false;
|
||||
}
|
||||
|
||||
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(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_bt(void) { btusb_switch(BTUSB_MODE_BT); }
|
||||
|
||||
void test_btusb_switch_to_usb(void)
|
||||
{
|
||||
btusb_switch(BTUSB_MODE_USB);
|
||||
}
|
||||
void test_btusb_switch_to_usb(void) { btusb_switch(BTUSB_MODE_USB); }
|
||||
#endif
|
||||
|
|
|
@ -13,127 +13,119 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "usbaudio_thread.h"
|
||||
#include "app_utils.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_utils.h"
|
||||
#include "usb_audio_app.h"
|
||||
#include "usbaudio_thread.h"
|
||||
|
||||
static void usb_thread(void const *argument);
|
||||
osThreadDef(usb_thread, osPriorityHigh, 1, 2048, "usb");
|
||||
|
||||
osMailQDef (usb_mailbox, USB_MAILBOX_MAX, USB_MESSAGE);
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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();
|
||||
}
|
||||
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;
|
||||
static void usb_enqueue_cmd(uint32_t data) {
|
||||
USB_MESSAGE usb_msg;
|
||||
|
||||
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;
|
||||
usb_msg.id = 0;
|
||||
usb_msg.param0 = 0;
|
||||
usb_msg.param1 = 0;
|
||||
usb_msg.ptr = 0;
|
||||
usb_mailbox_put(&usb_msg);
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,58 +14,52 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#ifdef __PC_CMD_UART__
|
||||
#include "cmsis_os.h"
|
||||
#include "list.h"
|
||||
#include "string.h"
|
||||
#include "app_thread.h"
|
||||
#include "app_cmd.h"
|
||||
#include "app_thread.h"
|
||||
#include "audio_process.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_cmd.h"
|
||||
#include "hal_trace.h"
|
||||
#include "audio_process.h"
|
||||
#include "list.h"
|
||||
#include "string.h"
|
||||
|
||||
#define APP_CMD_TRACE(s,...) TRACE(s, ##__VA_ARGS__)
|
||||
#define APP_CMD_TRACE(s, ...) TRACE(s, ##__VA_ARGS__)
|
||||
|
||||
void cmd_event_process(hal_cmd_rx_status_t status)
|
||||
{
|
||||
APP_CMD_TRACE(1,"%s",__func__);
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_CMD;
|
||||
msg.msg_body.message_id = status;
|
||||
msg.msg_body.message_ptr = (uint32_t)NULL;
|
||||
app_mailbox_put(&msg);
|
||||
return;
|
||||
void cmd_event_process(hal_cmd_rx_status_t status) {
|
||||
APP_CMD_TRACE(1, "%s", __func__);
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_CMD;
|
||||
msg.msg_body.message_id = status;
|
||||
msg.msg_body.message_ptr = (uint32_t)NULL;
|
||||
app_mailbox_put(&msg);
|
||||
return;
|
||||
}
|
||||
|
||||
static int app_cmd_handle_process(APP_MESSAGE_BODY *msg_body)
|
||||
{
|
||||
hal_cmd_run((hal_cmd_rx_status_t)msg_body->message_id);
|
||||
return 0;
|
||||
static int app_cmd_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||
hal_cmd_run((hal_cmd_rx_status_t)msg_body->message_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t app_cmd_flag = 0;
|
||||
|
||||
void app_cmd_open(void)
|
||||
{
|
||||
APP_CMD_TRACE(1,"%s",__func__);
|
||||
void app_cmd_open(void) {
|
||||
APP_CMD_TRACE(1, "%s", __func__);
|
||||
|
||||
app_cmd_flag = 1;
|
||||
app_cmd_flag = 1;
|
||||
|
||||
app_set_threadhandle(APP_MODUAL_CMD, app_cmd_handle_process);
|
||||
hal_cmd_set_callback(cmd_event_process);
|
||||
hal_cmd_open();
|
||||
return;
|
||||
app_set_threadhandle(APP_MODUAL_CMD, app_cmd_handle_process);
|
||||
hal_cmd_set_callback(cmd_event_process);
|
||||
hal_cmd_open();
|
||||
return;
|
||||
}
|
||||
|
||||
void app_cmd_close(void)
|
||||
{
|
||||
APP_CMD_TRACE(1,"%s",__func__);
|
||||
if(app_cmd_flag)
|
||||
{
|
||||
app_cmd_flag = 0;
|
||||
hal_cmd_close();
|
||||
app_set_threadhandle(APP_MODUAL_CMD, NULL);
|
||||
}
|
||||
return;
|
||||
void app_cmd_close(void) {
|
||||
APP_CMD_TRACE(1, "%s", __func__);
|
||||
if (app_cmd_flag) {
|
||||
app_cmd_flag = 0;
|
||||
hal_cmd_close();
|
||||
app_set_threadhandle(APP_MODUAL_CMD, NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,69 +13,66 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "cmsis_os.h"
|
||||
#include "stdint.h"
|
||||
#include "app_spec_ostimer.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
/// Create timer
|
||||
osStatus app_spec_timer_create (SPEC_TIMER_CTX_T *spec_timer_ctx, const osTimerDef_t *timer_def, os_timer_type type, void *argument)
|
||||
{
|
||||
spec_timer_ctx->type = type;
|
||||
spec_timer_ctx->argument = argument;
|
||||
spec_timer_ctx->timerid = osTimerCreate(timer_def, type, spec_timer_ctx);
|
||||
return spec_timer_ctx->timerid ? osOK: osErrorOS;
|
||||
osStatus app_spec_timer_create(SPEC_TIMER_CTX_T *spec_timer_ctx,
|
||||
const osTimerDef_t *timer_def,
|
||||
os_timer_type type, void *argument) {
|
||||
spec_timer_ctx->type = type;
|
||||
spec_timer_ctx->argument = argument;
|
||||
spec_timer_ctx->timerid = osTimerCreate(timer_def, type, spec_timer_ctx);
|
||||
return spec_timer_ctx->timerid ? osOK : osErrorOS;
|
||||
}
|
||||
|
||||
/// Start or restart timer
|
||||
osStatus app_spec_timer_start (SPEC_TIMER_CTX_T *spec_timer_ctx, uint32_t millisec)
|
||||
{
|
||||
osStatus status;
|
||||
osStatus app_spec_timer_start(SPEC_TIMER_CTX_T *spec_timer_ctx,
|
||||
uint32_t millisec) {
|
||||
osStatus status;
|
||||
|
||||
//TRACE(1,"%s", __func__);
|
||||
if (millisec > UINT16_MAX){
|
||||
spec_timer_ctx->interval = millisec;
|
||||
spec_timer_ctx->ctx = millisec;
|
||||
status = osTimerStart(spec_timer_ctx->timerid, UINT16_MAX);
|
||||
}else{
|
||||
spec_timer_ctx->interval = millisec;
|
||||
spec_timer_ctx->ctx = millisec;
|
||||
status = osTimerStart(spec_timer_ctx->timerid, (uint32_t)millisec);
|
||||
}
|
||||
// TRACE(1,"%s", __func__);
|
||||
if (millisec > UINT16_MAX) {
|
||||
spec_timer_ctx->interval = millisec;
|
||||
spec_timer_ctx->ctx = millisec;
|
||||
status = osTimerStart(spec_timer_ctx->timerid, UINT16_MAX);
|
||||
} else {
|
||||
spec_timer_ctx->interval = millisec;
|
||||
spec_timer_ctx->ctx = millisec;
|
||||
status = osTimerStart(spec_timer_ctx->timerid, (uint32_t)millisec);
|
||||
}
|
||||
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
/// Stop timer
|
||||
osStatus app_spec_timer_stop (SPEC_TIMER_CTX_T *spec_timer_ctx)
|
||||
{
|
||||
osStatus app_spec_timer_stop(SPEC_TIMER_CTX_T *spec_timer_ctx) {
|
||||
return osTimerStop(spec_timer_ctx->timerid);
|
||||
}
|
||||
|
||||
/// Delete timer
|
||||
osStatus app_spec_timer_delete (SPEC_TIMER_CTX_T *spec_timer_ctx)
|
||||
{
|
||||
osStatus app_spec_timer_delete(SPEC_TIMER_CTX_T *spec_timer_ctx) {
|
||||
return osTimerDelete(spec_timer_ctx->timerid);
|
||||
}
|
||||
|
||||
void app_spec_timer_handler(void const *para)
|
||||
{
|
||||
SPEC_TIMER_CTX_T *spec_timer_ctx = (SPEC_TIMER_CTX_T *)para;
|
||||
void app_spec_timer_handler(void const *para) {
|
||||
SPEC_TIMER_CTX_T *spec_timer_ctx = (SPEC_TIMER_CTX_T *)para;
|
||||
|
||||
if (spec_timer_ctx->ctx > UINT16_MAX){
|
||||
spec_timer_ctx->ctx -= UINT16_MAX;
|
||||
if (spec_timer_ctx->ctx > UINT16_MAX){
|
||||
osTimerStart(spec_timer_ctx->timerid, UINT16_MAX);
|
||||
}else{
|
||||
osTimerStart(spec_timer_ctx->timerid, spec_timer_ctx->ctx);
|
||||
}
|
||||
}else{
|
||||
(*spec_timer_ctx->ptimer)(spec_timer_ctx->argument);
|
||||
if (spec_timer_ctx->type == osTimerPeriodic){
|
||||
app_spec_timer_start(spec_timer_ctx, spec_timer_ctx->interval);
|
||||
}
|
||||
if (spec_timer_ctx->ctx > UINT16_MAX) {
|
||||
spec_timer_ctx->ctx -= UINT16_MAX;
|
||||
if (spec_timer_ctx->ctx > UINT16_MAX) {
|
||||
osTimerStart(spec_timer_ctx->timerid, UINT16_MAX);
|
||||
} else {
|
||||
osTimerStart(spec_timer_ctx->timerid, spec_timer_ctx->ctx);
|
||||
}
|
||||
} else {
|
||||
(*spec_timer_ctx->ptimer)(spec_timer_ctx->argument);
|
||||
if (spec_timer_ctx->type == osTimerPeriodic) {
|
||||
app_spec_timer_start(spec_timer_ctx, spec_timer_ctx->interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -13,152 +13,141 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_timer.h"
|
||||
#include "app_utils.h"
|
||||
#include "app_thread.h"
|
||||
|
||||
#include "app_utils.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
|
||||
static APP_MOD_HANDLER_T mod_handler[APP_MODUAL_NUM];
|
||||
|
||||
static void app_thread(void const *argument);
|
||||
osThreadDef(app_thread, osPriorityHigh, 1, 1024*3, "app_thread");
|
||||
osThreadDef(app_thread, osPriorityHigh, 1, 1024 * 3, "app_thread");
|
||||
|
||||
osMailQDef (app_mailbox, APP_MAILBOX_MAX, APP_MESSAGE_BLOCK);
|
||||
osMailQDef(app_mailbox, APP_MAILBOX_MAX, APP_MESSAGE_BLOCK);
|
||||
static osMailQId app_mailbox = NULL;
|
||||
static uint8_t app_mailbox_cnt = 0;
|
||||
osThreadId app_thread_tid;
|
||||
|
||||
static int app_mailbox_init(void)
|
||||
{
|
||||
app_mailbox = osMailCreate(osMailQ(app_mailbox), NULL);
|
||||
if (app_mailbox == NULL) {
|
||||
TRACE(0,"Failed to Create app_mailbox\n");
|
||||
return -1;
|
||||
}
|
||||
app_mailbox_cnt = 0;
|
||||
return 0;
|
||||
static int app_mailbox_init(void) {
|
||||
app_mailbox = osMailCreate(osMailQ(app_mailbox), NULL);
|
||||
if (app_mailbox == NULL) {
|
||||
TRACE(0, "Failed to Create app_mailbox\n");
|
||||
return -1;
|
||||
}
|
||||
app_mailbox_cnt = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_mailbox_put(APP_MESSAGE_BLOCK* msg_src)
|
||||
{
|
||||
osStatus status;
|
||||
int app_mailbox_put(APP_MESSAGE_BLOCK *msg_src) {
|
||||
osStatus status;
|
||||
|
||||
APP_MESSAGE_BLOCK *msg_p = NULL;
|
||||
|
||||
msg_p = (APP_MESSAGE_BLOCK *)osMailAlloc(app_mailbox, 0);
|
||||
|
||||
if (!msg_p) {
|
||||
osEvent evt;
|
||||
TRACE_IMM(0, "osMailAlloc error dump");
|
||||
for (uint8_t i = 0; i < APP_MAILBOX_MAX; i++) {
|
||||
evt = osMailGet(app_mailbox, 0);
|
||||
if (evt.status == osEventMail) {
|
||||
TRACE_IMM(
|
||||
9,
|
||||
"cnt:%d mod:%d src:%08x tim:%d id:%x ptr:%08x para:%08x/%08x/%08x",
|
||||
i, ((APP_MESSAGE_BLOCK *)(evt.value.p))->mod_id,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->src_thread,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->system_time,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_id,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_ptr,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_Param0,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_Param1,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_Param2);
|
||||
} else {
|
||||
TRACE_IMM(2, "cnt:%d %d", i, evt.status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
TRACE_IMM(0, "osMailAlloc error dump end");
|
||||
}
|
||||
|
||||
ASSERT(msg_p, "osMailAlloc error");
|
||||
msg_p->src_thread = (uint32_t)osThreadGetId();
|
||||
msg_p->dest_thread = (uint32_t)NULL;
|
||||
msg_p->system_time = hal_sys_timer_get();
|
||||
msg_p->mod_id = msg_src->mod_id;
|
||||
msg_p->msg_body.message_id = msg_src->msg_body.message_id;
|
||||
msg_p->msg_body.message_ptr = msg_src->msg_body.message_ptr;
|
||||
msg_p->msg_body.message_Param0 = msg_src->msg_body.message_Param0;
|
||||
msg_p->msg_body.message_Param1 = msg_src->msg_body.message_Param1;
|
||||
msg_p->msg_body.message_Param2 = msg_src->msg_body.message_Param2;
|
||||
|
||||
status = osMailPut(app_mailbox, msg_p);
|
||||
if (osOK == status)
|
||||
app_mailbox_cnt++;
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
int app_mailbox_free(APP_MESSAGE_BLOCK *msg_p) {
|
||||
osStatus status;
|
||||
|
||||
status = osMailFree(app_mailbox, msg_p);
|
||||
if (osOK == status)
|
||||
app_mailbox_cnt--;
|
||||
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
int app_mailbox_get(APP_MESSAGE_BLOCK **msg_p) {
|
||||
osEvent evt;
|
||||
evt = osMailGet(app_mailbox, osWaitForever);
|
||||
if (evt.status == osEventMail) {
|
||||
*msg_p = (APP_MESSAGE_BLOCK *)evt.value.p;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void app_thread(void const *argument) {
|
||||
while (1) {
|
||||
APP_MESSAGE_BLOCK *msg_p = NULL;
|
||||
|
||||
msg_p = (APP_MESSAGE_BLOCK*)osMailAlloc(app_mailbox, 0);
|
||||
|
||||
if (!msg_p){
|
||||
osEvent evt;
|
||||
TRACE_IMM(0,"osMailAlloc error dump");
|
||||
for (uint8_t i=0; i<APP_MAILBOX_MAX; i++){
|
||||
evt = osMailGet(app_mailbox, 0);
|
||||
if (evt.status == osEventMail) {
|
||||
TRACE_IMM(9,"cnt:%d mod:%d src:%08x tim:%d id:%x ptr:%08x para:%08x/%08x/%08x",
|
||||
i,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->mod_id,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->src_thread,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->system_time,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_id,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_ptr,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_Param0,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_Param1,
|
||||
((APP_MESSAGE_BLOCK *)(evt.value.p))->msg_body.message_Param2);
|
||||
}else{
|
||||
TRACE_IMM(2,"cnt:%d %d", i, evt.status);
|
||||
break;
|
||||
}
|
||||
if (!app_mailbox_get(&msg_p)) {
|
||||
if (msg_p->mod_id < APP_MODUAL_NUM) {
|
||||
if (mod_handler[msg_p->mod_id]) {
|
||||
int ret = mod_handler[msg_p->mod_id](&(msg_p->msg_body));
|
||||
if (ret)
|
||||
TRACE(2, "mod_handler[%d] ret=%d", msg_p->mod_id, ret);
|
||||
}
|
||||
TRACE_IMM(0,"osMailAlloc error dump end");
|
||||
}
|
||||
app_mailbox_free(msg_p);
|
||||
}
|
||||
|
||||
ASSERT(msg_p, "osMailAlloc error");
|
||||
msg_p->src_thread = (uint32_t)osThreadGetId();
|
||||
msg_p->dest_thread = (uint32_t)NULL;
|
||||
msg_p->system_time = hal_sys_timer_get();
|
||||
msg_p->mod_id = msg_src->mod_id;
|
||||
msg_p->msg_body.message_id = msg_src->msg_body.message_id;
|
||||
msg_p->msg_body.message_ptr = msg_src->msg_body.message_ptr;
|
||||
msg_p->msg_body.message_Param0 = msg_src->msg_body.message_Param0;
|
||||
msg_p->msg_body.message_Param1 = msg_src->msg_body.message_Param1;
|
||||
msg_p->msg_body.message_Param2 = msg_src->msg_body.message_Param2;
|
||||
|
||||
status = osMailPut(app_mailbox, msg_p);
|
||||
if (osOK == status)
|
||||
app_mailbox_cnt++;
|
||||
return (int)status;
|
||||
}
|
||||
}
|
||||
|
||||
int app_mailbox_free(APP_MESSAGE_BLOCK* msg_p)
|
||||
{
|
||||
osStatus status;
|
||||
|
||||
status = osMailFree(app_mailbox, msg_p);
|
||||
if (osOK == status)
|
||||
app_mailbox_cnt--;
|
||||
|
||||
return (int)status;
|
||||
}
|
||||
|
||||
int app_mailbox_get(APP_MESSAGE_BLOCK** msg_p)
|
||||
{
|
||||
osEvent evt;
|
||||
evt = osMailGet(app_mailbox, osWaitForever);
|
||||
if (evt.status == osEventMail) {
|
||||
*msg_p = (APP_MESSAGE_BLOCK *)evt.value.p;
|
||||
return 0;
|
||||
}
|
||||
int app_os_init(void) {
|
||||
if (app_mailbox_init())
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void app_thread(void const *argument)
|
||||
{
|
||||
while(1){
|
||||
APP_MESSAGE_BLOCK *msg_p = NULL;
|
||||
|
||||
if (!app_mailbox_get(&msg_p)) {
|
||||
if (msg_p->mod_id < APP_MODUAL_NUM) {
|
||||
if (mod_handler[msg_p->mod_id]) {
|
||||
int ret = mod_handler[msg_p->mod_id](&(msg_p->msg_body));
|
||||
if (ret)
|
||||
TRACE(2,"mod_handler[%d] ret=%d", msg_p->mod_id, ret);
|
||||
}
|
||||
}
|
||||
app_mailbox_free(msg_p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int app_os_init(void)
|
||||
{
|
||||
if (app_mailbox_init())
|
||||
return -1;
|
||||
|
||||
app_thread_tid = osThreadCreate(osThread(app_thread), NULL);
|
||||
if (app_thread_tid == NULL) {
|
||||
TRACE(0,"Failed to Create app_thread\n");
|
||||
return 0;
|
||||
}
|
||||
app_thread_tid = osThreadCreate(osThread(app_thread), NULL);
|
||||
if (app_thread_tid == NULL) {
|
||||
TRACE(0, "Failed to Create app_thread\n");
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id, APP_MOD_HANDLER_T handler)
|
||||
{
|
||||
if (mod_id>=APP_MODUAL_NUM)
|
||||
return -1;
|
||||
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id,
|
||||
APP_MOD_HANDLER_T handler) {
|
||||
if (mod_id >= APP_MODUAL_NUM)
|
||||
return -1;
|
||||
|
||||
mod_handler[mod_id] = handler;
|
||||
return 0;
|
||||
mod_handler[mod_id] = handler;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * app_os_tid_get(void)
|
||||
{
|
||||
return (void *)app_thread_tid;
|
||||
}
|
||||
void *app_os_tid_get(void) { return (void *)app_thread_tid; }
|
||||
|
||||
bool app_is_module_registered(enum APP_MODUAL_ID_T mod_id)
|
||||
{
|
||||
return mod_handler[mod_id];
|
||||
bool app_is_module_registered(enum APP_MODUAL_ID_T mod_id) {
|
||||
return mod_handler[mod_id];
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
****************************************************************************/
|
||||
#ifndef __APP_THREAD_H__
|
||||
#define __APP_THREAD_H__
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -23,70 +25,71 @@ extern "C" {
|
|||
#define APP_MAILBOX_MAX (20)
|
||||
|
||||
enum APP_MODUAL_ID_T {
|
||||
APP_MODUAL_KEY = 0,
|
||||
APP_MODUAL_AUDIO,
|
||||
APP_MODUAL_BATTERY,
|
||||
APP_MODUAL_BT,
|
||||
APP_MODUAL_FM,
|
||||
APP_MODUAL_SD,
|
||||
APP_MODUAL_LINEIN,
|
||||
APP_MODUAL_USBHOST,
|
||||
APP_MODUAL_USBDEVICE,
|
||||
APP_MODUAL_WATCHDOG,
|
||||
APP_MODUAL_AUDIO_MANAGE,
|
||||
APP_MODUAL_ANC,
|
||||
APP_MODUAL_SMART_MIC,
|
||||
APP_MODUAL_KEY = 0,
|
||||
APP_MODUAL_AUDIO,
|
||||
APP_MODUAL_BATTERY,
|
||||
APP_MODUAL_BT,
|
||||
APP_MODUAL_FM,
|
||||
APP_MODUAL_SD,
|
||||
APP_MODUAL_LINEIN,
|
||||
APP_MODUAL_USBHOST,
|
||||
APP_MODUAL_USBDEVICE,
|
||||
APP_MODUAL_WATCHDOG,
|
||||
APP_MODUAL_AUDIO_MANAGE,
|
||||
APP_MODUAL_ANC,
|
||||
APP_MODUAL_SMART_MIC,
|
||||
#ifdef __PC_CMD_UART__
|
||||
APP_MODUAL_CMD,
|
||||
APP_MODUAL_CMD,
|
||||
#endif
|
||||
#ifdef TILE_DATAPATH
|
||||
APP_MODUAL_TILE,
|
||||
APP_MODUAL_TILE,
|
||||
#endif
|
||||
APP_MODUAL_MIC,
|
||||
APP_MODUAL_MIC,
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
APP_MODUAL_VOICE_DETECTOR,
|
||||
APP_MODUAL_VOICE_DETECTOR,
|
||||
#endif
|
||||
APP_MODUAL_CUSTOM_FUNCTION,
|
||||
APP_MODUAL_OHTER,
|
||||
APP_MODUAL_WNR,
|
||||
APP_MODUAL_CUSTOM_FUNCTION,
|
||||
APP_MODUAL_OHTER,
|
||||
APP_MODUAL_WNR,
|
||||
|
||||
APP_MODUAL_NUM
|
||||
APP_MODUAL_NUM
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t message_id;
|
||||
uint32_t message_ptr;
|
||||
uint32_t message_Param0;
|
||||
uint32_t message_Param1;
|
||||
uint32_t message_Param2;
|
||||
uint32_t message_id;
|
||||
uint32_t message_ptr;
|
||||
uint32_t message_Param0;
|
||||
uint32_t message_Param1;
|
||||
uint32_t message_Param2;
|
||||
} APP_MESSAGE_BODY;
|
||||
|
||||
typedef struct {
|
||||
uint32_t src_thread;
|
||||
uint32_t dest_thread;
|
||||
uint32_t system_time;
|
||||
uint32_t mod_id;
|
||||
APP_MESSAGE_BODY msg_body;
|
||||
uint32_t src_thread;
|
||||
uint32_t dest_thread;
|
||||
uint32_t system_time;
|
||||
uint32_t mod_id;
|
||||
APP_MESSAGE_BODY msg_body;
|
||||
} APP_MESSAGE_BLOCK;
|
||||
|
||||
typedef int (*APP_MOD_HANDLER_T)(APP_MESSAGE_BODY *);
|
||||
|
||||
int app_mailbox_put(APP_MESSAGE_BLOCK* msg_src);
|
||||
int app_mailbox_put(APP_MESSAGE_BLOCK *msg_src);
|
||||
|
||||
int app_mailbox_free(APP_MESSAGE_BLOCK* msg_p);
|
||||
int app_mailbox_free(APP_MESSAGE_BLOCK *msg_p);
|
||||
|
||||
int app_mailbox_get(APP_MESSAGE_BLOCK** msg_p);
|
||||
int app_mailbox_get(APP_MESSAGE_BLOCK **msg_p);
|
||||
|
||||
int app_os_init(void);
|
||||
|
||||
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id, APP_MOD_HANDLER_T handler);
|
||||
int app_set_threadhandle(enum APP_MODUAL_ID_T mod_id,
|
||||
APP_MOD_HANDLER_T handler);
|
||||
|
||||
void * app_os_tid_get(void);
|
||||
void *app_os_tid_get(void);
|
||||
|
||||
bool app_is_module_registered(enum APP_MODUAL_ID_T mod_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif//__FMDEC_H__
|
||||
#endif //__FMDEC_H__
|
||||
|
|
|
@ -13,23 +13,23 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_utils.h"
|
||||
#include "analog.h"
|
||||
#include "cmsis.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_wdt.h"
|
||||
#include "pmu.h"
|
||||
#include "analog.h"
|
||||
#include "app_utils.h"
|
||||
#ifdef RTOS
|
||||
#include "cmsis_os.h"
|
||||
#endif
|
||||
|
||||
#define FREQ_FREE 0UL
|
||||
#define FREQ_26M 26UL
|
||||
#define FREQ_52M 52UL
|
||||
#define FREQ_78M 78UL
|
||||
#define FREQ_104M 104UL
|
||||
#define FREQ_208M 208UL
|
||||
#define FREQ_FREE 0UL
|
||||
#define FREQ_26M 26UL
|
||||
#define FREQ_52M 52UL
|
||||
#define FREQ_78M 78UL
|
||||
#define FREQ_104M 104UL
|
||||
#define FREQ_208M 208UL
|
||||
|
||||
/*
|
||||
* qos_users, quality of services users, this kind of user must run with the
|
||||
|
@ -41,22 +41,19 @@
|
|||
*/
|
||||
/*
|
||||
* NOTE:
|
||||
* The macro QOS_USERS works only when the APP_SYSFREQ_USER_APP_XXX is not large than
|
||||
* 32, currently this works, but if the are more user, another way needed
|
||||
* The macro QOS_USERS works only when the APP_SYSFREQ_USER_APP_XXX is not large
|
||||
* than 32, currently this works, but if the are more user, another way needed
|
||||
*/
|
||||
#define QOS_USERS ((1 << (APP_SYSFREQ_USER_AI_VOICE)) | \
|
||||
(1 << (APP_SYSFREQ_USER_BT_A2DP)))
|
||||
#define QOS_USERS \
|
||||
((1 << (APP_SYSFREQ_USER_AI_VOICE)) | (1 << (APP_SYSFREQ_USER_BT_A2DP)))
|
||||
|
||||
static const uint32_t freq_map[] = {
|
||||
[HAL_CMU_FREQ_32K] = FREQ_FREE,
|
||||
[HAL_CMU_FREQ_26M] = FREQ_26M,
|
||||
[HAL_CMU_FREQ_52M] = FREQ_52M,
|
||||
[HAL_CMU_FREQ_78M] = FREQ_78M,
|
||||
[HAL_CMU_FREQ_104M] = FREQ_104M,
|
||||
[HAL_CMU_FREQ_208M] = FREQ_208M,
|
||||
static const uint32_t freq_map[] = {
|
||||
[HAL_CMU_FREQ_32K] = FREQ_FREE, [HAL_CMU_FREQ_26M] = FREQ_26M,
|
||||
[HAL_CMU_FREQ_52M] = FREQ_52M, [HAL_CMU_FREQ_78M] = FREQ_78M,
|
||||
[HAL_CMU_FREQ_104M] = FREQ_104M, [HAL_CMU_FREQ_208M] = FREQ_208M,
|
||||
};
|
||||
|
||||
static const uint32_t user_map[] = {
|
||||
static const uint32_t user_map[] = {
|
||||
[0] = APP_SYSFREQ_USER_AI_VOICE,
|
||||
[1] = APP_SYSFREQ_USER_BT_A2DP,
|
||||
};
|
||||
|
@ -89,95 +86,97 @@ static uint32_t qos_freqs_map;
|
|||
*/
|
||||
static uint32_t qos_users_map;
|
||||
|
||||
static int app_qosfreq_req(enum APP_SYSFREQ_USER_T user, enum APP_SYSFREQ_FREQ_T freq)
|
||||
{
|
||||
int ret;
|
||||
int qos_freq_num = 0;
|
||||
uint32_t max_qos_freq = 0;
|
||||
int user_idx;
|
||||
int i;
|
||||
uint32_t lock;
|
||||
static int app_qosfreq_req(enum APP_SYSFREQ_USER_T user,
|
||||
enum APP_SYSFREQ_FREQ_T freq) {
|
||||
int ret;
|
||||
int qos_freq_num = 0;
|
||||
uint32_t max_qos_freq = 0;
|
||||
int user_idx;
|
||||
int i;
|
||||
uint32_t lock;
|
||||
|
||||
if (freq >= APP_SYSFREQ_FREQ_QTY)
|
||||
return -1;
|
||||
if (freq >= APP_SYSFREQ_FREQ_QTY)
|
||||
return -1;
|
||||
|
||||
lock = int_lock();
|
||||
for (i = 0; i < ARRAY_SIZE(user_map); i++) {
|
||||
if (user == user_map[i]) {
|
||||
break;
|
||||
}
|
||||
lock = int_lock();
|
||||
for (i = 0; i < ARRAY_SIZE(user_map); i++) {
|
||||
if (user == user_map[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= ARRAY_SIZE(user_map)) {
|
||||
int_unlock(lock);
|
||||
ASSERT(0, "can not find qos user");
|
||||
return 0;
|
||||
}
|
||||
|
||||
user_idx = i;
|
||||
if ((int)freq != (int)HAL_CMU_FREQ_32K) { // require freq
|
||||
qos_freqs_map &= ~(0xf << (4 * i));
|
||||
qos_freqs_map |= freq << (4 * i);
|
||||
qos_users_map |= 1 << user_idx;
|
||||
} else { //release freq
|
||||
qos_freqs_map &= ~(0xf << (4 * i));
|
||||
qos_users_map &= ~ (1 << user_idx);
|
||||
}
|
||||
|
||||
//scan the qos_user_map and sum every user's request freq
|
||||
for(i = 0; i < ARRAY_SIZE(user_map); i++) {
|
||||
if ((qos_users_map >> i) & 0x1) {
|
||||
uint32_t real_freq;
|
||||
int freq_num;
|
||||
|
||||
freq_num = (qos_freqs_map >> (4 * i )) & 0xf;
|
||||
real_freq = freq_map[freq_num];
|
||||
max_qos_freq += real_freq;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(freq_map); i++) {
|
||||
if (i) {
|
||||
if ((max_qos_freq > freq_map[i-1]) && (max_qos_freq <= freq_map[i])) {
|
||||
qos_freq_num = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (max_qos_freq == freq_map[i]) {
|
||||
qos_freq_num = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= ARRAY_SIZE(freq_map)) {
|
||||
qos_freq_num = (HAL_CMU_FREQ_QTY - 1);
|
||||
int_unlock(lock);
|
||||
TRACE(0, "WARNING: required sysfreq exceed");
|
||||
// ASSERT(0, "can not find actual freq");
|
||||
return 0;
|
||||
}
|
||||
|
||||
user = APP_SYSFREQ_USER_QOS;
|
||||
TRACE(2, "User %d require sysfreq %d", user, qos_freq_num);
|
||||
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user, (enum HAL_CMU_FREQ_T)qos_freq_num);
|
||||
|
||||
if (i >= ARRAY_SIZE(user_map)) {
|
||||
int_unlock(lock);
|
||||
return ret;
|
||||
ASSERT(0, "can not find qos user");
|
||||
return 0;
|
||||
}
|
||||
|
||||
user_idx = i;
|
||||
if ((int)freq != (int)HAL_CMU_FREQ_32K) { // require freq
|
||||
qos_freqs_map &= ~(0xf << (4 * i));
|
||||
qos_freqs_map |= freq << (4 * i);
|
||||
qos_users_map |= 1 << user_idx;
|
||||
} else { // release freq
|
||||
qos_freqs_map &= ~(0xf << (4 * i));
|
||||
qos_users_map &= ~(1 << user_idx);
|
||||
}
|
||||
|
||||
// scan the qos_user_map and sum every user's request freq
|
||||
for (i = 0; i < ARRAY_SIZE(user_map); i++) {
|
||||
if ((qos_users_map >> i) & 0x1) {
|
||||
uint32_t real_freq;
|
||||
int freq_num;
|
||||
|
||||
freq_num = (qos_freqs_map >> (4 * i)) & 0xf;
|
||||
real_freq = freq_map[freq_num];
|
||||
max_qos_freq += real_freq;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(freq_map); i++) {
|
||||
if (i) {
|
||||
if ((max_qos_freq > freq_map[i - 1]) && (max_qos_freq <= freq_map[i])) {
|
||||
qos_freq_num = i;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (max_qos_freq == freq_map[i]) {
|
||||
qos_freq_num = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= ARRAY_SIZE(freq_map)) {
|
||||
qos_freq_num = (HAL_CMU_FREQ_QTY - 1);
|
||||
int_unlock(lock);
|
||||
TRACE(0, "WARNING: required sysfreq exceed");
|
||||
// ASSERT(0, "can not find actual freq");
|
||||
return 0;
|
||||
}
|
||||
|
||||
user = APP_SYSFREQ_USER_QOS;
|
||||
TRACE(2, "User %d require sysfreq %d", user, qos_freq_num);
|
||||
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user,
|
||||
(enum HAL_CMU_FREQ_T)qos_freq_num);
|
||||
|
||||
int_unlock(lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int app_sysfreq_req(enum APP_SYSFREQ_USER_T user, enum APP_SYSFREQ_FREQ_T freq)
|
||||
{
|
||||
int ret;
|
||||
int app_sysfreq_req(enum APP_SYSFREQ_USER_T user,
|
||||
enum APP_SYSFREQ_FREQ_T freq) {
|
||||
int ret;
|
||||
|
||||
// if user is qos user
|
||||
if ((1 << user) & QOS_USERS) {
|
||||
ret = app_qosfreq_req(user, freq);
|
||||
} else { // if user is NOT qos user
|
||||
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user, (enum HAL_CMU_FREQ_T)freq);
|
||||
}
|
||||
// if user is qos user
|
||||
if ((1 << user) & QOS_USERS) {
|
||||
ret = app_qosfreq_req(user, freq);
|
||||
} else { // if user is NOT qos user
|
||||
ret = hal_sysfreq_req((enum HAL_SYSFREQ_USER_T)user,
|
||||
(enum HAL_CMU_FREQ_T)freq);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef RTOS
|
||||
|
@ -188,94 +187,86 @@ static osTimerId wdt_ping_timer_id;
|
|||
osTimerDef(wdt_ping_timer, watchdog_ping_handler);
|
||||
static uint32_t wdt_ping_period;
|
||||
|
||||
static void watchdog_ping(void)
|
||||
{
|
||||
hal_wdt_ping(HAL_WDT_ID_0);
|
||||
static void watchdog_ping(void) {
|
||||
hal_wdt_ping(HAL_WDT_ID_0);
|
||||
#ifndef CHIP_BEST2000
|
||||
pmu_wdt_feed();
|
||||
pmu_wdt_feed();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void app_wdt_irq_handle(enum HAL_WDT_ID_T id, uint32_t status)
|
||||
{
|
||||
analog_aud_codec_mute();
|
||||
ASSERT(0, "%s id:%d status:%d",__func__, id, status);
|
||||
static void app_wdt_irq_handle(enum HAL_WDT_ID_T id, uint32_t status) {
|
||||
analog_aud_codec_mute();
|
||||
ASSERT(0, "%s id:%d status:%d", __func__, id, status);
|
||||
}
|
||||
|
||||
static void pmu_wdt_irq_handle(void)
|
||||
{
|
||||
analog_aud_codec_mute();
|
||||
ASSERT(1, "%s", __func__);
|
||||
static void pmu_wdt_irq_handle(void) {
|
||||
analog_aud_codec_mute();
|
||||
ASSERT(1, "%s", __func__);
|
||||
}
|
||||
|
||||
static void watchdog_ping_handler(void const *unused)
|
||||
{
|
||||
int ret;
|
||||
static void watchdog_ping_handler(void const *unused) {
|
||||
int ret;
|
||||
|
||||
watchdog_ping();
|
||||
ret = rtx_task_idle_health_check();
|
||||
if (ret < 0) {
|
||||
ASSERT(0, "System soft lockup");
|
||||
}
|
||||
watchdog_ping();
|
||||
ret = rtx_task_idle_health_check();
|
||||
if (ret < 0) {
|
||||
ASSERT(0, "System soft lockup");
|
||||
}
|
||||
|
||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||
}
|
||||
|
||||
int app_wdt_open(int seconds)
|
||||
{
|
||||
uint32_t lock = int_lock();
|
||||
int app_wdt_open(int seconds) {
|
||||
uint32_t lock = int_lock();
|
||||
|
||||
hal_wdt_set_irq_callback(HAL_WDT_ID_0, app_wdt_irq_handle);
|
||||
hal_wdt_set_timeout(HAL_WDT_ID_0, seconds);
|
||||
hal_wdt_start(HAL_WDT_ID_0);
|
||||
pmu_wdt_set_irq_handler(pmu_wdt_irq_handle);
|
||||
hal_wdt_set_irq_callback(HAL_WDT_ID_0, app_wdt_irq_handle);
|
||||
hal_wdt_set_timeout(HAL_WDT_ID_0, seconds);
|
||||
hal_wdt_start(HAL_WDT_ID_0);
|
||||
pmu_wdt_set_irq_handler(pmu_wdt_irq_handle);
|
||||
#ifndef CHIP_BEST2000
|
||||
pmu_wdt_config(seconds * 1100, seconds * 1100);
|
||||
pmu_wdt_start();
|
||||
pmu_wdt_config(seconds * 1100, seconds * 1100);
|
||||
pmu_wdt_start();
|
||||
#endif
|
||||
int_unlock(lock);
|
||||
wdt_ping_timer_id = osTimerCreate(osTimer(wdt_ping_timer), osTimerOnce, NULL);
|
||||
if (!wdt_ping_timer_id) {
|
||||
TRACE(0,"Warning: can not create watchdog ping timer");
|
||||
return -1;
|
||||
}
|
||||
wdt_ping_period = seconds * 1000 / 4;
|
||||
int_unlock(lock);
|
||||
wdt_ping_timer_id = osTimerCreate(osTimer(wdt_ping_timer), osTimerOnce, NULL);
|
||||
if (!wdt_ping_timer_id) {
|
||||
TRACE(0, "Warning: can not create watchdog ping timer");
|
||||
return -1;
|
||||
}
|
||||
wdt_ping_period = seconds * 1000 / 4;
|
||||
|
||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||
return 0;
|
||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_wdt_reopen(int seconds)
|
||||
{
|
||||
uint32_t lock = int_lock();
|
||||
hal_wdt_stop(HAL_WDT_ID_0);
|
||||
hal_wdt_set_timeout(HAL_WDT_ID_0, seconds);
|
||||
hal_wdt_start(HAL_WDT_ID_0);
|
||||
int app_wdt_reopen(int seconds) {
|
||||
uint32_t lock = int_lock();
|
||||
hal_wdt_stop(HAL_WDT_ID_0);
|
||||
hal_wdt_set_timeout(HAL_WDT_ID_0, seconds);
|
||||
hal_wdt_start(HAL_WDT_ID_0);
|
||||
#ifndef CHIP_BEST2000
|
||||
pmu_wdt_config(seconds * 1000, seconds * 1000);
|
||||
pmu_wdt_start();
|
||||
pmu_wdt_config(seconds * 1000, seconds * 1000);
|
||||
pmu_wdt_start();
|
||||
#endif
|
||||
int_unlock(lock);
|
||||
int_unlock(lock);
|
||||
|
||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||
return 0;
|
||||
osTimerStart(wdt_ping_timer_id, wdt_ping_period);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_wdt_close(void)
|
||||
{
|
||||
uint32_t lock;
|
||||
int app_wdt_close(void) {
|
||||
uint32_t lock;
|
||||
|
||||
osTimerStop(wdt_ping_timer_id);
|
||||
osTimerStop(wdt_ping_timer_id);
|
||||
|
||||
lock = int_lock();
|
||||
hal_wdt_stop(HAL_WDT_ID_0);
|
||||
lock = int_lock();
|
||||
hal_wdt_stop(HAL_WDT_ID_0);
|
||||
#ifndef CHIP_BEST2000
|
||||
pmu_wdt_stop();
|
||||
pmu_wdt_stop();
|
||||
#endif
|
||||
int_unlock(lock);
|
||||
int_unlock(lock);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
#ifdef __RAND_FROM_MIC__
|
||||
#include "audioflinger.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_utils.h"
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "app_bt_stream.h"
|
||||
#include "randfrommic.h"
|
||||
#include "hal_timer.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "cmsis_gcc.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_bt_stream.h"
|
||||
#include "app_utils.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cmsis_gcc.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
|
||||
#if BT_DRV_DEBUG
|
||||
#define RAND_TRACE(n, fmt, ...) TRACE(n, fmt, ##__VA_ARGS__)
|
||||
#define RAND_DUMP(s,buff,len) DUMP8(s,buff,len)
|
||||
#define RAND_TRACE(n, fmt, ...) TRACE(n, fmt, ##__VA_ARGS__)
|
||||
#define RAND_DUMP(s, buff, len) DUMP8(s, buff, len)
|
||||
#else
|
||||
#define RAND_TRACE(n, fmt, ...)
|
||||
#define RAND_DUMP(s,buff,len)
|
||||
#define RAND_DUMP(s, buff, len)
|
||||
#endif
|
||||
|
||||
static void generateRand(bool on);
|
||||
|
@ -29,239 +29,201 @@ static uint32_t randSeed = 1;
|
|||
static bool randInitialised = false;
|
||||
|
||||
// 4 bytes aligned
|
||||
#define RAND_GRAB_BITS_PER_SAMPLE 4
|
||||
#define RAND_GRAB_BITS_MASK_PER_SAMPLE ((1 << RAND_GRAB_BITS_PER_SAMPLE)-1)
|
||||
#define RAND_GRAB_BITS_PER_SAMPLE 4
|
||||
#define RAND_GRAB_BITS_MASK_PER_SAMPLE ((1 << RAND_GRAB_BITS_PER_SAMPLE) - 1)
|
||||
|
||||
RAND_NUMBER_T randomBuffer =
|
||||
{
|
||||
RAND_NUMBER_T randomBuffer = {
|
||||
25,
|
||||
RAND_STATUS_CLOSE,
|
||||
};
|
||||
|
||||
/**
|
||||
* Description: parse mic data according to the stream cfg(bit mode and channel number)
|
||||
* only the lowest byte of each frame is taken
|
||||
* ADC format:
|
||||
* 16bit mode -> [15:0] is valid
|
||||
* 24bit mode -> [23:4] is valid
|
||||
* 32bit mode -> [31:12] is valid
|
||||
* Description: parse mic data according to the stream cfg(bit mode and channel
|
||||
* number) only the lowest byte of each frame is taken ADC format: 16bit mode ->
|
||||
* [15:0] is valid 24bit mode -> [23:4] is valid 32bit mode -> [31:12] is valid
|
||||
*
|
||||
*/
|
||||
static int randDataParse(uint8_t *buf, uint32_t len, enum AUD_BITS_T bits,
|
||||
enum AUD_CHANNEL_NUM_T ch_num)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
enum AUD_CHANNEL_NUM_T ch_num) {
|
||||
uint8_t index = 0;
|
||||
|
||||
union {
|
||||
uint32_t seedValue;
|
||||
uint8_t value[4];
|
||||
}seedData;
|
||||
union {
|
||||
uint32_t seedValue;
|
||||
uint8_t value[4];
|
||||
} seedData;
|
||||
|
||||
if ((NULL == buf) ||
|
||||
((RANDOM_CAPTURE_BUFFER_SIZE/2) > len)) // ping-pong buffer
|
||||
{
|
||||
return -1;
|
||||
if ((NULL == buf) ||
|
||||
((RANDOM_CAPTURE_BUFFER_SIZE / 2) > len)) // ping-pong buffer
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
RAND_TRACE(1, "%s", __func__);
|
||||
RAND_DUMP("%x ", buf, 16);
|
||||
|
||||
switch (bits) {
|
||||
case AUD_BITS_16: {
|
||||
uint16_t *content = (uint16_t *)buf;
|
||||
|
||||
for (index = 0; index < 4; index++) {
|
||||
seedData.value[index] =
|
||||
((*content) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||
(((*(content + ch_num)) & RAND_GRAB_BITS_MASK_PER_SAMPLE)
|
||||
<< RAND_GRAB_BITS_PER_SAMPLE);
|
||||
content += ((8 / RAND_GRAB_BITS_PER_SAMPLE) * ch_num);
|
||||
}
|
||||
|
||||
RAND_TRACE(1, "%s", __func__);
|
||||
RAND_DUMP("%x ",buf, 16);
|
||||
|
||||
switch (bits)
|
||||
{
|
||||
case AUD_BITS_16:
|
||||
{
|
||||
uint16_t* content = (uint16_t *)buf;
|
||||
|
||||
for (index = 0;index < 4; index++)
|
||||
{
|
||||
seedData.value[index] = ((*content) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||
(((*(content+ch_num)) & RAND_GRAB_BITS_MASK_PER_SAMPLE) << RAND_GRAB_BITS_PER_SAMPLE);
|
||||
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AUD_BITS_24:
|
||||
{
|
||||
uint32_t* content = (uint32_t *)buf;
|
||||
for (index = 0;index < 4; index++)
|
||||
{
|
||||
// bit 23:4 are valid
|
||||
seedData.value[index] = (((*content) >> 4) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||
((((*(content+ch_num)) >> 4)&RAND_GRAB_BITS_MASK_PER_SAMPLE) << RAND_GRAB_BITS_PER_SAMPLE);
|
||||
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AUD_BITS_32:
|
||||
{
|
||||
uint32_t* content = (uint32_t *)buf;
|
||||
for (index = 0;index < 4; index++)
|
||||
{
|
||||
// bit 31:12 are valid
|
||||
seedData.value[index] = (((*content) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||
((((*(content+ch_num)) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE) << RAND_GRAB_BITS_PER_SAMPLE);
|
||||
content += ((8/RAND_GRAB_BITS_PER_SAMPLE)*ch_num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
case AUD_BITS_24: {
|
||||
uint32_t *content = (uint32_t *)buf;
|
||||
for (index = 0; index < 4; index++) {
|
||||
// bit 23:4 are valid
|
||||
seedData.value[index] =
|
||||
(((*content) >> 4) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||
((((*(content + ch_num)) >> 4) & RAND_GRAB_BITS_MASK_PER_SAMPLE)
|
||||
<< RAND_GRAB_BITS_PER_SAMPLE);
|
||||
content += ((8 / RAND_GRAB_BITS_PER_SAMPLE) * ch_num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AUD_BITS_32: {
|
||||
uint32_t *content = (uint32_t *)buf;
|
||||
for (index = 0; index < 4; index++) {
|
||||
// bit 31:12 are valid
|
||||
seedData.value[index] =
|
||||
(((*content) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE) |
|
||||
((((*(content + ch_num)) >> 12) & RAND_GRAB_BITS_MASK_PER_SAMPLE)
|
||||
<< RAND_GRAB_BITS_PER_SAMPLE);
|
||||
content += ((8 / RAND_GRAB_BITS_PER_SAMPLE) * ch_num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return -1;
|
||||
} break;
|
||||
}
|
||||
|
||||
randSeed = seedData.seedValue;
|
||||
randSeed = seedData.seedValue;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void generateRand(bool on)
|
||||
{
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static void generateRand(bool on) {
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
|
||||
RAND_TRACE(2, "%s op:%d", __func__, on);
|
||||
RAND_TRACE(2, "%s op:%d", __func__, on);
|
||||
|
||||
if (on)
|
||||
{
|
||||
randomBuffer.skipRound = 10;
|
||||
if (on) {
|
||||
randomBuffer.skipRound = 10;
|
||||
|
||||
randomBuffer.status = random_mic_is_on(&deviceId);
|
||||
RAND_TRACE(2, "%s random status = %d", __func__, randomBuffer.status);
|
||||
randomBuffer.status = random_mic_is_on(&deviceId);
|
||||
RAND_TRACE(2, "%s random status = %d", __func__, randomBuffer.status);
|
||||
|
||||
if (RAND_STATUS_CLOSE == randomBuffer.status)
|
||||
{
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_208M);
|
||||
app_capture_audio_mempool_init();
|
||||
app_capture_audio_mempool_get_buff(&captureBuffer,
|
||||
RANDOM_CAPTURE_BUFFER_SIZE);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_8000;
|
||||
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.handler = rand_data_handle;
|
||||
if (RAND_STATUS_CLOSE == randomBuffer.status) {
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_208M);
|
||||
app_capture_audio_mempool_init();
|
||||
app_capture_audio_mempool_get_buff(&captureBuffer,
|
||||
RANDOM_CAPTURE_BUFFER_SIZE);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_8000;
|
||||
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.handler = rand_data_handle;
|
||||
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(captureBuffer);
|
||||
stream_cfg.data_size = RANDOM_CAPTURE_BUFFER_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
randomBuffer.status = RAND_STATUS_OPEN;
|
||||
}
|
||||
else if(RAND_STATUS_MIC_OPENED == randomBuffer.status)
|
||||
{
|
||||
af_stream_start(deviceId, AUD_STREAM_CAPTURE);
|
||||
}
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(captureBuffer);
|
||||
stream_cfg.data_size = RANDOM_CAPTURE_BUFFER_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
randomBuffer.status = RAND_STATUS_OPEN;
|
||||
} else if (RAND_STATUS_MIC_OPENED == randomBuffer.status) {
|
||||
af_stream_start(deviceId, AUD_STREAM_CAPTURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// release the acquired system clock
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_32K);
|
||||
if (RAND_STATUS_MIC_OPENED == randomBuffer.status)
|
||||
{
|
||||
af_stream_stop(deviceId, AUD_STREAM_CAPTURE);
|
||||
}
|
||||
else if (RAND_STATUS_OPEN == randomBuffer.status)
|
||||
{
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
}
|
||||
randomBuffer.status = RAND_STATUS_CLOSE;
|
||||
} else {
|
||||
// release the acquired system clock
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_RANDOM, APP_SYSFREQ_32K);
|
||||
if (RAND_STATUS_MIC_OPENED == randomBuffer.status) {
|
||||
af_stream_stop(deviceId, AUD_STREAM_CAPTURE);
|
||||
} else if (RAND_STATUS_OPEN == randomBuffer.status) {
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
}
|
||||
randomBuffer.status = RAND_STATUS_CLOSE;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t rand_data_handle(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (buf == NULL)
|
||||
{
|
||||
return len;
|
||||
}
|
||||
static uint32_t rand_data_handle(uint8_t *buf, uint32_t len) {
|
||||
if (buf == NULL) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if ((1 == randomBuffer.skipRound) &&
|
||||
(!randDataParse(buf, len, AUD_BITS_16, AUD_CHANNEL_NUM_1)))
|
||||
{
|
||||
if ((1 == randomBuffer.skipRound) &&
|
||||
(!randDataParse(buf, len, AUD_BITS_16, AUD_CHANNEL_NUM_1))) {
|
||||
generateRand(false);
|
||||
randomBuffer.skipRound = 0;
|
||||
} else if (1 != randomBuffer.skipRound) {
|
||||
randomBuffer.skipRound--;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void initSeed(void) {
|
||||
uint8_t count = 100; // avoid deed loop
|
||||
|
||||
RAND_TRACE(2, "%s:+++ initialised = %d", __func__, randInitialised);
|
||||
|
||||
if (randInitialised) {
|
||||
generateRand(true);
|
||||
|
||||
while ((0 != randomBuffer.skipRound) && (0 != count)) {
|
||||
osDelay(10);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
if ((0 == count) || (false == randInitialised)) {
|
||||
RAND_TRACE(1, "%s not ready", __func__);
|
||||
randSeed = (uint32_t)hal_sys_timer_get();
|
||||
generateRand(false);
|
||||
}
|
||||
|
||||
srand(randSeed);
|
||||
RAND_TRACE(2, "%s:--- count = %d", __func__, count);
|
||||
}
|
||||
|
||||
void random_status_sync(void) {
|
||||
if (RAND_STATUS_OPEN == randomBuffer.status) {
|
||||
RAND_TRACE(1, "%s random mic has already on,should be closed", __func__);
|
||||
generateRand(false);
|
||||
}
|
||||
}
|
||||
|
||||
void random_data_process(uint8_t *buf, uint32_t len, enum AUD_BITS_T bits,
|
||||
enum AUD_CHANNEL_NUM_T ch_num) {
|
||||
if (buf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((RAND_STATUS_MIC_STARTED == randomBuffer.status) ||
|
||||
(RAND_STATUS_MIC_OPENED == randomBuffer.status)) {
|
||||
if (len >= RANDOM_CAPTURE_BUFFER_SIZE / 2) {
|
||||
RAND_TRACE(4, "%s buf address = 0x%p, bits = %d, channel num = %d",
|
||||
__func__, buf, bits, ch_num);
|
||||
RAND_DUMP("%02x ", buf, 32);
|
||||
if ((1 == randomBuffer.skipRound) &&
|
||||
(!randDataParse(buf, len, bits, ch_num))) {
|
||||
generateRand(false);
|
||||
randomBuffer.skipRound = 0;
|
||||
}
|
||||
else if (1 != randomBuffer.skipRound)
|
||||
{
|
||||
} else if (1 != randomBuffer.skipRound) {
|
||||
randomBuffer.skipRound--;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
void initSeed(void)
|
||||
{
|
||||
uint8_t count = 100; // avoid deed loop
|
||||
|
||||
RAND_TRACE(2, "%s:+++ initialised = %d", __func__, randInitialised);
|
||||
|
||||
if (randInitialised)
|
||||
{
|
||||
generateRand(true);
|
||||
|
||||
while ((0 != randomBuffer.skipRound) && (0 != count))
|
||||
{
|
||||
osDelay(10);
|
||||
count --;
|
||||
}
|
||||
}
|
||||
|
||||
if ((0 == count) || (false == randInitialised))
|
||||
{
|
||||
RAND_TRACE(1, "%s not ready", __func__);
|
||||
randSeed = (uint32_t)hal_sys_timer_get();
|
||||
generateRand(false);
|
||||
}
|
||||
|
||||
srand(randSeed);
|
||||
RAND_TRACE(2, "%s:--- count = %d", __func__, count);
|
||||
}
|
||||
|
||||
void random_status_sync(void)
|
||||
{
|
||||
if (RAND_STATUS_OPEN == randomBuffer.status)
|
||||
{
|
||||
RAND_TRACE(1, "%s random mic has already on,should be closed", __func__);
|
||||
generateRand(false);
|
||||
}
|
||||
}
|
||||
|
||||
void random_data_process(uint8_t *buf, uint32_t len,enum AUD_BITS_T bits,
|
||||
enum AUD_CHANNEL_NUM_T ch_num)
|
||||
{
|
||||
if (buf == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((RAND_STATUS_MIC_STARTED == randomBuffer.status) ||
|
||||
(RAND_STATUS_MIC_OPENED == randomBuffer.status))
|
||||
{
|
||||
if (len >= RANDOM_CAPTURE_BUFFER_SIZE/2)
|
||||
{
|
||||
RAND_TRACE(4, "%s buf address = 0x%p, bits = %d, channel num = %d", __func__, buf, bits, ch_num);
|
||||
RAND_DUMP("%02x ", buf, 32);
|
||||
if ((1 == randomBuffer.skipRound) &&
|
||||
(!randDataParse(buf, len, bits, ch_num)))
|
||||
{
|
||||
generateRand(false);
|
||||
randomBuffer.skipRound = 0;
|
||||
}
|
||||
else if (1 != randomBuffer.skipRound)
|
||||
{
|
||||
randomBuffer.skipRound--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void randInit(void)
|
||||
{
|
||||
randInitialised = true;
|
||||
}
|
||||
void randInit(void) { randInitialised = true; }
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -15,8 +15,9 @@
|
|||
****************************************************************************/
|
||||
#ifndef __APP_FACTORY_H__
|
||||
#define __APP_FACTORY_H__
|
||||
|
||||
#define APP_FACTORY_TRACE(s,...) TRACE(s, ##__VA_ARGS__)
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#define APP_FACTORY_TRACE(s, ...) TRACE(s, ##__VA_ARGS__)
|
||||
|
||||
void app_factorymode_result_set(bool result);
|
||||
|
||||
|
|
|
@ -13,171 +13,159 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_bt_stream.h"
|
||||
#include "app_factory.h"
|
||||
#include "app_media_player.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "resources.h"
|
||||
#include "app_bt_stream.h"
|
||||
#include "app_media_player.h"
|
||||
#include "app_factory.h"
|
||||
#include "string.h"
|
||||
|
||||
// for audio
|
||||
#include "audioflinger.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_utils.h"
|
||||
#include "audioflinger.h"
|
||||
|
||||
#include "app_factory_audio.h"
|
||||
|
||||
|
||||
#ifdef __FACTORY_MODE_SUPPORT__
|
||||
|
||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (1024*2)
|
||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (1024 * 2)
|
||||
static enum APP_AUDIO_CACHE_T a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
static int16_t *app_audioloop_play_cache = NULL;
|
||||
|
||||
static uint32_t app_factorymode_data_come(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
DUMP16("%d,",(int*)buf,30);
|
||||
static uint32_t app_factorymode_data_come(uint8_t *buf, uint32_t len) {
|
||||
DUMP16("%d,", (int *)buf, 30);
|
||||
|
||||
app_audio_pcmbuff_put(buf, len);
|
||||
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY){
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_OK;
|
||||
}
|
||||
return len;
|
||||
app_audio_pcmbuff_put(buf, len);
|
||||
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY) {
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_OK;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint32_t app_factorymode_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (a2dp_cache_status != APP_AUDIO_CACHE_QTY){
|
||||
app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
||||
app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
|
||||
}
|
||||
return len;
|
||||
static uint32_t app_factorymode_more_data(uint8_t *buf, uint32_t len) {
|
||||
if (a2dp_cache_status != APP_AUDIO_CACHE_QTY) {
|
||||
app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len / 2);
|
||||
app_bt_stream_copy_track_one_to_two_16bits(
|
||||
(int16_t *)buf, app_audioloop_play_cache, len / 2 / 2);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq)
|
||||
{
|
||||
uint8_t *buff_play = NULL;
|
||||
uint8_t *buff_capture = NULL;
|
||||
uint8_t *buff_loop = NULL;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static bool isRun = false;
|
||||
APP_FACTORY_TRACE(3,"app_factorymode_audioloop work:%d op:%d freq:%d", isRun, on, freq);
|
||||
int app_factorymode_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||
uint8_t *buff_play = NULL;
|
||||
uint8_t *buff_capture = NULL;
|
||||
uint8_t *buff_loop = NULL;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static bool isRun = false;
|
||||
APP_FACTORY_TRACE(3, "app_factorymode_audioloop work:%d op:%d freq:%d", isRun,
|
||||
on, freq);
|
||||
|
||||
if (isRun==on)
|
||||
return 0;
|
||||
if (isRun == on)
|
||||
return 0;
|
||||
|
||||
if (on){
|
||||
if (freq < APP_SYSFREQ_52M) {
|
||||
freq = APP_SYSFREQ_52M;
|
||||
}
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||
if (on) {
|
||||
if (freq < APP_SYSFREQ_52M) {
|
||||
freq = APP_SYSFREQ_52M;
|
||||
}
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
app_audio_mempool_init();
|
||||
app_audio_mempool_get_buff(&buff_capture, BT_AUDIO_FACTORMODE_BUFF_SIZE);
|
||||
app_audio_mempool_get_buff(&buff_play, BT_AUDIO_FACTORMODE_BUFF_SIZE*2);
|
||||
app_audio_mempool_get_buff((uint8_t **)&app_audioloop_play_cache, BT_AUDIO_FACTORMODE_BUFF_SIZE*2/2/2);
|
||||
app_audio_mempool_get_buff(&buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE<<2);
|
||||
app_audio_pcmbuff_init(buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE<<2);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
//stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
app_audio_mempool_init();
|
||||
app_audio_mempool_get_buff(&buff_capture, BT_AUDIO_FACTORMODE_BUFF_SIZE);
|
||||
app_audio_mempool_get_buff(&buff_play, BT_AUDIO_FACTORMODE_BUFF_SIZE * 2);
|
||||
app_audio_mempool_get_buff((uint8_t **)&app_audioloop_play_cache,
|
||||
BT_AUDIO_FACTORMODE_BUFF_SIZE * 2 / 2 / 2);
|
||||
app_audio_mempool_get_buff(&buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE << 2);
|
||||
app_audio_pcmbuff_init(buff_loop, BT_AUDIO_FACTORMODE_BUFF_SIZE << 2);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
// stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
|
||||
#ifdef SPEECH_TX_AEC_CODEC_REF
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
#else
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
#endif
|
||||
#if defined(__AUDIO_RESAMPLE__) && defined(SW_CAPTURE_RESAMPLE)
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_8463;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_8463;
|
||||
#else
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_8000;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_8000;
|
||||
#endif
|
||||
#if FPGA==0
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
#if FPGA == 0
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
#else
|
||||
stream_cfg.device = AUD_STREAM_USE_EXT_CODEC;
|
||||
stream_cfg.device = AUD_STREAM_USE_EXT_CODEC;
|
||||
#endif
|
||||
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.handler = app_factorymode_data_come;
|
||||
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.handler = app_factorymode_data_come;
|
||||
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
|
||||
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
|
||||
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.handler = app_factorymode_more_data;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.handler = app_factorymode_more_data;
|
||||
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_play);
|
||||
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE*2;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_play);
|
||||
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE * 2;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
APP_FACTORY_TRACE(0,"app_factorymode_audioloop on");
|
||||
} 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);
|
||||
APP_FACTORY_TRACE(0,"app_factorymode_audioloop off");
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
APP_FACTORY_TRACE(0, "app_factorymode_audioloop on");
|
||||
} 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);
|
||||
APP_FACTORY_TRACE(0, "app_factorymode_audioloop off");
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
}
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
}
|
||||
|
||||
isRun=on;
|
||||
return 0;
|
||||
isRun = on;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_factorymode_output_pcmpatten(audio_test_pcmpatten_t *pcmpatten, uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t remain_size = len;
|
||||
uint32_t curr_size = 0;
|
||||
int app_factorymode_output_pcmpatten(audio_test_pcmpatten_t *pcmpatten,
|
||||
uint8_t *buf, uint32_t len) {
|
||||
uint32_t remain_size = len;
|
||||
uint32_t curr_size = 0;
|
||||
|
||||
if (remain_size > pcmpatten->len)
|
||||
{
|
||||
do{
|
||||
if (pcmpatten->cuur_buf_pos)
|
||||
{
|
||||
curr_size = pcmpatten->len-pcmpatten->cuur_buf_pos;
|
||||
memcpy(buf,&(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]), curr_size);
|
||||
remain_size -= curr_size;
|
||||
pcmpatten->cuur_buf_pos = 0;
|
||||
}
|
||||
else if (remain_size>pcmpatten->len)
|
||||
{
|
||||
memcpy(buf+curr_size, pcmpatten->buf, pcmpatten->len);
|
||||
curr_size += pcmpatten->len;
|
||||
remain_size -= pcmpatten->len;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(buf+curr_size,pcmpatten->buf, remain_size);
|
||||
pcmpatten->cuur_buf_pos = remain_size;
|
||||
remain_size = 0;
|
||||
}
|
||||
}while(remain_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pcmpatten->len - pcmpatten->cuur_buf_pos) >= len)
|
||||
{
|
||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]),len);
|
||||
pcmpatten->cuur_buf_pos += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
curr_size = pcmpatten->len-pcmpatten->cuur_buf_pos;
|
||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos/2]),curr_size);
|
||||
pcmpatten->cuur_buf_pos = len - curr_size;
|
||||
memcpy(buf+curr_size, pcmpatten->buf, pcmpatten->cuur_buf_pos);
|
||||
}
|
||||
if (remain_size > pcmpatten->len) {
|
||||
do {
|
||||
if (pcmpatten->cuur_buf_pos) {
|
||||
curr_size = pcmpatten->len - pcmpatten->cuur_buf_pos;
|
||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos / 2]), curr_size);
|
||||
remain_size -= curr_size;
|
||||
pcmpatten->cuur_buf_pos = 0;
|
||||
} else if (remain_size > pcmpatten->len) {
|
||||
memcpy(buf + curr_size, pcmpatten->buf, pcmpatten->len);
|
||||
curr_size += pcmpatten->len;
|
||||
remain_size -= pcmpatten->len;
|
||||
} else {
|
||||
memcpy(buf + curr_size, pcmpatten->buf, remain_size);
|
||||
pcmpatten->cuur_buf_pos = remain_size;
|
||||
remain_size = 0;
|
||||
}
|
||||
} while (remain_size);
|
||||
} else {
|
||||
if ((pcmpatten->len - pcmpatten->cuur_buf_pos) >= len) {
|
||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos / 2]), len);
|
||||
pcmpatten->cuur_buf_pos += len;
|
||||
} else {
|
||||
curr_size = pcmpatten->len - pcmpatten->cuur_buf_pos;
|
||||
memcpy(buf, &(pcmpatten->buf[pcmpatten->cuur_buf_pos / 2]), curr_size);
|
||||
pcmpatten->cuur_buf_pos = len - curr_size;
|
||||
memcpy(buf + curr_size, pcmpatten->buf, pcmpatten->cuur_buf_pos);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "fft128dot.h"
|
||||
|
@ -185,111 +173,118 @@ int app_factorymode_output_pcmpatten(audio_test_pcmpatten_t *pcmpatten, uint8_t
|
|||
#define N 64
|
||||
#define NFFT 128
|
||||
|
||||
struct mic_st_t{
|
||||
FftTwiddle_t w[N];
|
||||
FftTwiddle_t w128[N*2];
|
||||
FftData_t x[N*2];
|
||||
FftData_t data_odd[N];
|
||||
FftData_t data_even[N];
|
||||
FftData_t data_odd_d[N];
|
||||
FftData_t data_even_d[N];
|
||||
FftData_t data[N*2];
|
||||
signed long out[N];
|
||||
struct mic_st_t {
|
||||
FftTwiddle_t w[N];
|
||||
FftTwiddle_t w128[N * 2];
|
||||
FftData_t x[N * 2];
|
||||
FftData_t data_odd[N];
|
||||
FftData_t data_even[N];
|
||||
FftData_t data_odd_d[N];
|
||||
FftData_t data_even_d[N];
|
||||
FftData_t data[N * 2];
|
||||
signed long out[N];
|
||||
};
|
||||
|
||||
int app_factorymode_mic_cancellation_run(void * mic_st, signed short *inbuf, int sample)
|
||||
{
|
||||
struct mic_st_t *st = (struct mic_st_t *)mic_st;
|
||||
int i,k,jj,ii;
|
||||
//int dataWidth = 16; // input word format is 16 bit twos complement fractional format 1.15
|
||||
int twiddleWidth = 16; // input word format is 16 bit twos complement fractional format 2.14
|
||||
FftMode_t ifft = FFT_MODE;
|
||||
int app_factorymode_mic_cancellation_run(void *mic_st, signed short *inbuf,
|
||||
int sample) {
|
||||
struct mic_st_t *st = (struct mic_st_t *)mic_st;
|
||||
int i, k, jj, ii;
|
||||
// int dataWidth = 16; // input word format is 16 bit twos complement
|
||||
// fractional format 1.15
|
||||
int twiddleWidth =
|
||||
16; // input word format is 16 bit twos complement fractional format 2.14
|
||||
FftMode_t ifft = FFT_MODE;
|
||||
|
||||
make_symmetric_twiddles(st->w,N,twiddleWidth);
|
||||
make_symmetric_twiddles(st->w128,N*2,twiddleWidth);
|
||||
// input data
|
||||
for (i=0; i<sample; i++){
|
||||
st->x[i].re = inbuf[i];
|
||||
st->x[i].im = 0;
|
||||
make_symmetric_twiddles(st->w, N, twiddleWidth);
|
||||
make_symmetric_twiddles(st->w128, N * 2, twiddleWidth);
|
||||
// input data
|
||||
for (i = 0; i < sample; i++) {
|
||||
st->x[i].re = inbuf[i];
|
||||
st->x[i].im = 0;
|
||||
}
|
||||
|
||||
for (ii = 0; ii < 1; ii++) {
|
||||
k = 0;
|
||||
for (jj = 0; jj < N * 2; jj += 2) {
|
||||
FftData_t tmp;
|
||||
|
||||
tmp.re = st->x[jj].re;
|
||||
tmp.im = st->x[jj].im;
|
||||
|
||||
st->data_even[k].re =
|
||||
tmp.re; //(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
st->data_even[k].im =
|
||||
tmp.im; //(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
tmp.re = st->x[jj + 1].re;
|
||||
tmp.im = st->x[jj + 1].im;
|
||||
st->data_odd[k].re =
|
||||
tmp.re; //(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
st->data_odd[k].im =
|
||||
tmp.im; //(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
k++;
|
||||
}
|
||||
|
||||
for(ii = 0; ii < 1; ii++)
|
||||
{
|
||||
k = 0;
|
||||
for (jj = 0; jj < N*2; jj+=2)
|
||||
{
|
||||
FftData_t tmp;
|
||||
fftr4(NFFT / 2, st->data_even, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH,
|
||||
ifft);
|
||||
fftr4(NFFT / 2, st->data_odd, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH,
|
||||
ifft);
|
||||
|
||||
tmp.re = st->x[jj].re;
|
||||
tmp.im = st->x[jj].im;
|
||||
for (jj = 0; jj < NFFT / 2; jj++) {
|
||||
|
||||
st->data_even[k].re = tmp.re;//(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
st->data_even[k].im = tmp.im;//(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
tmp.re = st->x[jj+1].re;
|
||||
tmp.im = st->x[jj+1].im;
|
||||
st->data_odd[k].re = tmp.re;//(int) (double(tmp.re)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
st->data_odd[k].im = tmp.im;//(int) (double(tmp.im)*double(1 << FFTR4_INPUT_FORMAT_Y)) ;
|
||||
k++;
|
||||
}
|
||||
|
||||
fftr4(NFFT/2, st->data_even, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH, ifft);
|
||||
fftr4(NFFT/2, st->data_odd, st->w, FFTR4_TWIDDLE_WIDTH, FFTR4_DATA_WIDTH, ifft);
|
||||
|
||||
for (jj = 0; jj < NFFT/2; jj++)
|
||||
{
|
||||
|
||||
int idx = dibit_reverse_int(jj, NFFT/2);
|
||||
st->data_even_d[jj].re = st->data_even[idx].re;
|
||||
st->data_even_d[jj].im = st->data_even[idx].im;
|
||||
st->data_odd_d[jj].re = st->data_odd[idx].re;
|
||||
st->data_odd_d[jj].im = st->data_odd[idx].im;
|
||||
}
|
||||
for (jj=0;jj<NFFT/2;jj++)
|
||||
{
|
||||
long long mbr,mbi;
|
||||
FftData_t ta;
|
||||
FftData_t tmp;
|
||||
double a;
|
||||
mbr = (long long)(st->data_odd_d[jj].re) * st->w128[jj].re - (long long)(st->data_odd_d[jj].im) * st->w128[jj].im;
|
||||
mbi = (long long)(st->data_odd_d[jj].im) * st->w128[jj].re + (long long)(st->data_odd_d[jj].re) * st->w128[jj].im;
|
||||
ta.re = int(mbr>>(FFTR4_TWIDDLE_WIDTH-2));
|
||||
ta.im = int(mbi>>(FFTR4_TWIDDLE_WIDTH-2));
|
||||
st->data[jj].re = (st->data_even_d[jj].re + ta.re)/2;
|
||||
st->data[jj].im = (st->data_even_d[jj].im + ta.im)/2;
|
||||
//data[jj] = sat(data[jj],FFTR4_DATA_WIDTH);
|
||||
st->data[jj+NFFT/2].re = (st->data_even_d[jj].re - ta.re)/2;
|
||||
st->data[jj+NFFT/2].im = (st->data_even_d[jj].im - ta.im)/2;
|
||||
//data[jj+NFFT/2] = sat(data[jj+NFFT/2],FFTR4_DATA_WIDTH);
|
||||
|
||||
a = st->data[jj].re;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||
tmp.re = (int)a;
|
||||
a = st->data[jj].im;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||
tmp.im = (int)a;
|
||||
st->x[ii*NFFT+jj].re = (int) tmp.re;
|
||||
st->x[ii*NFFT+jj].im = (int) tmp.im;
|
||||
a = st->data[jj+NFFT/2].re;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||
tmp.re = (int)a;
|
||||
a = st->data[jj+NFFT/2].im;///double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1 << FFTR4_SCALE);
|
||||
tmp.im = (int)a;
|
||||
st->x[ii*NFFT+jj+NFFT/2].re = (int) tmp.re;
|
||||
st->x[ii*NFFT+jj+NFFT/2].im = (int) tmp.im;
|
||||
}
|
||||
int idx = dibit_reverse_int(jj, NFFT / 2);
|
||||
st->data_even_d[jj].re = st->data_even[idx].re;
|
||||
st->data_even_d[jj].im = st->data_even[idx].im;
|
||||
st->data_odd_d[jj].re = st->data_odd[idx].re;
|
||||
st->data_odd_d[jj].im = st->data_odd[idx].im;
|
||||
}
|
||||
for (jj = 0; jj < NFFT / 2; jj++) {
|
||||
long long mbr, mbi;
|
||||
FftData_t ta;
|
||||
FftData_t tmp;
|
||||
double a;
|
||||
mbr = (long long)(st->data_odd_d[jj].re) * st->w128[jj].re -
|
||||
(long long)(st->data_odd_d[jj].im) * st->w128[jj].im;
|
||||
mbi = (long long)(st->data_odd_d[jj].im) * st->w128[jj].re +
|
||||
(long long)(st->data_odd_d[jj].re) * st->w128[jj].im;
|
||||
ta.re = int(mbr >> (FFTR4_TWIDDLE_WIDTH - 2));
|
||||
ta.im = int(mbi >> (FFTR4_TWIDDLE_WIDTH - 2));
|
||||
st->data[jj].re = (st->data_even_d[jj].re + ta.re) / 2;
|
||||
st->data[jj].im = (st->data_even_d[jj].im + ta.im) / 2;
|
||||
// data[jj] = sat(data[jj],FFTR4_DATA_WIDTH);
|
||||
st->data[jj + NFFT / 2].re = (st->data_even_d[jj].re - ta.re) / 2;
|
||||
st->data[jj + NFFT / 2].im = (st->data_even_d[jj].im - ta.im) / 2;
|
||||
// data[jj+NFFT/2] = sat(data[jj+NFFT/2],FFTR4_DATA_WIDTH);
|
||||
|
||||
for (i=0; i<N; i++){
|
||||
st->out[i] = st->x[i].re * st->x[i].re + st->x[i].im * st->x[i].im;
|
||||
a = st->data[jj].re; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1
|
||||
/// << FFTR4_SCALE);
|
||||
tmp.re = (int)a;
|
||||
a = st->data[jj].im; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);// * double(1
|
||||
/// << FFTR4_SCALE);
|
||||
tmp.im = (int)a;
|
||||
st->x[ii * NFFT + jj].re = (int)tmp.re;
|
||||
st->x[ii * NFFT + jj].im = (int)tmp.im;
|
||||
a = st->data[jj + NFFT / 2].re; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);//
|
||||
/// * double(1 << FFTR4_SCALE);
|
||||
tmp.re = (int)a;
|
||||
a = st->data[jj + NFFT / 2].im; /// double(1 << FFTR4_OUTPUT_FORMAT_Y);//
|
||||
/// * double(1 << FFTR4_SCALE);
|
||||
tmp.im = (int)a;
|
||||
st->x[ii * NFFT + jj + NFFT / 2].re = (int)tmp.re;
|
||||
st->x[ii * NFFT + jj + NFFT / 2].im = (int)tmp.im;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
for (i = 0; i < N; i++) {
|
||||
st->out[i] = st->x[i].re * st->x[i].re + st->x[i].im * st->x[i].im;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *app_factorymode_mic_cancellation_init(void* (* alloc_ext)(int))
|
||||
{
|
||||
struct mic_st_t *mic_st;
|
||||
mic_st = (struct mic_st_t *)alloc_ext(sizeof(struct mic_st_t));
|
||||
return (void *)mic_st;
|
||||
void *app_factorymode_mic_cancellation_init(void *(*alloc_ext)(int)) {
|
||||
struct mic_st_t *mic_st;
|
||||
mic_st = (struct mic_st_t *)alloc_ext(sizeof(struct mic_st_t));
|
||||
return (void *)mic_st;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,128 +13,120 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_sleep.h"
|
||||
#include "bt_drv_interface.h"
|
||||
#include "intersyshci.h"
|
||||
#include "apps.h"
|
||||
#include "app_factory.h"
|
||||
#include "app_factory_bt.h"
|
||||
#include "app_battery.h"
|
||||
#include "app_factory.h"
|
||||
#include "app_utils.h"
|
||||
#include "apps.h"
|
||||
#include "bluetooth.h"
|
||||
#include "bt_drv_interface.h"
|
||||
#include "bt_drv_reg_op.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "conmgr_api.h"
|
||||
#include "hal_bootmode.h"
|
||||
#include "hal_chipid.h"
|
||||
#include "hal_sleep.h"
|
||||
#include "hal_trace.h"
|
||||
#include "intersyshci.h"
|
||||
#include "me_api.h"
|
||||
#include "nvrecord.h"
|
||||
#include "nvrecord_dev.h"
|
||||
#include "pmu.h"
|
||||
#include "tgt_hardware.h"
|
||||
#include "app_battery.h"
|
||||
#include "bt_drv_reg_op.h"
|
||||
#include "conmgr_api.h"
|
||||
#include "me_api.h"
|
||||
#include "hal_bootmode.h"
|
||||
#include "hal_chipid.h"
|
||||
|
||||
|
||||
#define APP_FACT_CPU_WAKE_LOCK HAL_CPU_WAKE_LOCK_USER_3
|
||||
#define APP_FACT_CPU_WAKE_LOCK HAL_CPU_WAKE_LOCK_USER_3
|
||||
|
||||
#ifdef __FACTORY_MODE_SUPPORT__
|
||||
static uint8_t inquiry_buff[] = {0x01, 0x72, 0x77, 0xb0, 0x18, 0x57, 0x60,\
|
||||
0x01, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00};
|
||||
|
||||
static uint8_t inquiry_buff[] = {0x01, 0x72, 0x77, 0xb0, 0x18, 0x57, 0x60, 0x01,
|
||||
0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00};
|
||||
|
||||
static btif_cmgr_handler_t *app_factorymode_cmgrHandler;
|
||||
|
||||
|
||||
static void bt_error_check_timer_handler(void const *param);
|
||||
osTimerDef(bt_error_check_timer, bt_error_check_timer_handler);
|
||||
static osTimerId bt_error_check_timer_id = NULL;
|
||||
uint8_t test_mode_type=0;
|
||||
static void bt_error_check_timer_handler(void const *param)
|
||||
{
|
||||
//dump rssi
|
||||
bt_drv_rssi_dump_handler();
|
||||
//check BT core status
|
||||
if(bt_drv_error_check_handler())
|
||||
{
|
||||
if(test_mode_type==1)
|
||||
{
|
||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE|HAL_SW_BOOTMODE_TEST_SIGNALINGMODE);
|
||||
}
|
||||
else if(test_mode_type==2)
|
||||
{
|
||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE|HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE);
|
||||
}
|
||||
hal_cmu_sys_reboot();
|
||||
uint8_t test_mode_type = 0;
|
||||
static void bt_error_check_timer_handler(void const *param) {
|
||||
// dump rssi
|
||||
bt_drv_rssi_dump_handler();
|
||||
// check BT core status
|
||||
if (bt_drv_error_check_handler()) {
|
||||
if (test_mode_type == 1) {
|
||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE |
|
||||
HAL_SW_BOOTMODE_TEST_SIGNALINGMODE);
|
||||
} else if (test_mode_type == 2) {
|
||||
hal_sw_bootmode_set(HAL_SW_BOOTMODE_TEST_MODE |
|
||||
HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE);
|
||||
}
|
||||
hal_cmu_sys_reboot();
|
||||
}
|
||||
}
|
||||
|
||||
static void app_factorymode_bt_inquiry_buff_update(void)
|
||||
{
|
||||
bt_bdaddr_t flsh_dongle_addr;
|
||||
int ret = -1;
|
||||
static void app_factorymode_bt_inquiry_buff_update(void) {
|
||||
bt_bdaddr_t flsh_dongle_addr;
|
||||
int ret = -1;
|
||||
|
||||
ret = nvrec_dev_get_dongleaddr(&flsh_dongle_addr);
|
||||
if(0 == ret) {
|
||||
memcpy((void *)&inquiry_buff[1],(void *)flsh_dongle_addr.address,BTIF_BD_ADDR_SIZE);
|
||||
DUMP8("0x%02x ", &inquiry_buff[2], BTIF_BD_ADDR_SIZE);
|
||||
}
|
||||
ret = nvrec_dev_get_dongleaddr(&flsh_dongle_addr);
|
||||
if (0 == ret) {
|
||||
memcpy((void *)&inquiry_buff[1], (void *)flsh_dongle_addr.address,
|
||||
BTIF_BD_ADDR_SIZE);
|
||||
DUMP8("0x%02x ", &inquiry_buff[2], BTIF_BD_ADDR_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
static void app_factorymode_CmgrCallback(btif_cmgr_handler_t *cHandler,
|
||||
cmgr_event_t Event,
|
||||
bt_status_t Status)
|
||||
{
|
||||
APP_FACTORY_TRACE(4,"%s cHandler:%p Event:%d status:%d", __func__, cHandler, Event, Status);
|
||||
if (Event == BTIF_CMEVENT_DATA_LINK_CON_CNF){
|
||||
if (Status == BT_STS_SUCCESS){
|
||||
APP_FACTORY_TRACE(0,"connect ok");
|
||||
app_factorymode_result_set(true);
|
||||
btif_cmgr_remove_data_link(cHandler);
|
||||
cmgr_event_t Event,
|
||||
bt_status_t Status) {
|
||||
APP_FACTORY_TRACE(4, "%s cHandler:%p Event:%d status:%d", __func__, cHandler,
|
||||
Event, Status);
|
||||
if (Event == BTIF_CMEVENT_DATA_LINK_CON_CNF) {
|
||||
if (Status == BT_STS_SUCCESS) {
|
||||
APP_FACTORY_TRACE(0, "connect ok");
|
||||
app_factorymode_result_set(true);
|
||||
btif_cmgr_remove_data_link(cHandler);
|
||||
|
||||
}else{
|
||||
APP_FACTORY_TRACE(0,"connect failed");
|
||||
app_factorymode_result_set(false);
|
||||
}
|
||||
} else {
|
||||
APP_FACTORY_TRACE(0, "connect failed");
|
||||
app_factorymode_result_set(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (Event == BTIF_CMEVENT_DATA_LINK_DIS){
|
||||
if (Status == BT_STS_SUCCESS){
|
||||
APP_FACTORY_TRACE(0,"disconnect ok");
|
||||
}else{
|
||||
APP_FACTORY_TRACE(0,"disconnect failed");
|
||||
}
|
||||
if (Event == BTIF_CMEVENT_DATA_LINK_DIS) {
|
||||
if (Status == BT_STS_SUCCESS) {
|
||||
APP_FACTORY_TRACE(0, "disconnect ok");
|
||||
} else {
|
||||
APP_FACTORY_TRACE(0, "disconnect failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void app_factorymode_bt_InquiryResult_add(void)
|
||||
{
|
||||
U8 len = 15;
|
||||
bool rssi = false, extended = false;
|
||||
U8* parm = (U8*)inquiry_buff;
|
||||
static void app_factorymode_bt_InquiryResult_add(void) {
|
||||
U8 len = 15;
|
||||
bool rssi = false, extended = false;
|
||||
U8 *parm = (U8 *)inquiry_buff;
|
||||
|
||||
/* Found one or more devices. Report to clients */
|
||||
APP_FACTORY_TRACE(4,"%s len:%d rssi:%d extended:%d", __func__, len, rssi, extended);
|
||||
DUMP8("0x%02x ", parm, len);
|
||||
btif_me_inquiry_result_setup(parm, rssi, extended);
|
||||
/* Found one or more devices. Report to clients */
|
||||
APP_FACTORY_TRACE(4, "%s len:%d rssi:%d extended:%d", __func__, len, rssi,
|
||||
extended);
|
||||
DUMP8("0x%02x ", parm, len);
|
||||
btif_me_inquiry_result_setup(parm, rssi, extended);
|
||||
}
|
||||
|
||||
void app_factorymode_bt_create_connect(void)
|
||||
{
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t *bdAddr = (bt_bdaddr_t *)(inquiry_buff+1);
|
||||
void app_factorymode_bt_create_connect(void) {
|
||||
bt_status_t status;
|
||||
bt_bdaddr_t *bdAddr = (bt_bdaddr_t *)(inquiry_buff + 1);
|
||||
|
||||
status = btif_cmgr_create_data_link(app_factorymode_cmgrHandler, bdAddr);
|
||||
APP_FACTORY_TRACE(2,"%s:%d", __func__, status);
|
||||
status = btif_cmgr_create_data_link(app_factorymode_cmgrHandler, bdAddr);
|
||||
APP_FACTORY_TRACE(2, "%s:%d", __func__, status);
|
||||
}
|
||||
|
||||
void app_factorymode_bt_init_connect(void)
|
||||
{
|
||||
app_factorymode_cmgrHandler = btif_cmgr_handler_create();
|
||||
void app_factorymode_bt_init_connect(void) {
|
||||
app_factorymode_cmgrHandler = btif_cmgr_handler_create();
|
||||
|
||||
btif_cmgr_register_handler(app_factorymode_cmgrHandler,
|
||||
app_factorymode_CmgrCallback);
|
||||
app_factorymode_bt_inquiry_buff_update();
|
||||
app_factorymode_bt_InquiryResult_add();
|
||||
btif_cmgr_register_handler(app_factorymode_cmgrHandler,
|
||||
app_factorymode_CmgrCallback);
|
||||
app_factorymode_bt_inquiry_buff_update();
|
||||
app_factorymode_bt_InquiryResult_add();
|
||||
}
|
||||
|
||||
extern osTimerId app_bt_accessmode_timer;
|
||||
|
@ -145,187 +137,187 @@ extern osTimerId app_bt_accessmode_timer;
|
|||
#define XTAL_FCAP_RANGE (0xFF)
|
||||
#endif
|
||||
|
||||
void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
dev_addr_name devinfo;
|
||||
uint32_t fcap = 0;
|
||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||
void app_factorymode_bt_xtalrangetest(APP_KEY_STATUS *status, void *param) {
|
||||
dev_addr_name devinfo;
|
||||
uint32_t fcap = 0;
|
||||
APP_FACTORY_TRACE(1, "%s", __func__);
|
||||
#ifdef __WATCHER_DOG_RESET__
|
||||
app_wdt_close();
|
||||
app_wdt_close();
|
||||
#endif
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
app_stop_10_second_timer(APP_PAIR_TIMER_ID);
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
if (app_bt_accessmode_timer){
|
||||
osTimerStop(app_bt_accessmode_timer);
|
||||
}
|
||||
if (!bt_error_check_timer_id){
|
||||
bt_error_check_timer_id = osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||
}
|
||||
if (bt_error_check_timer_id != NULL) {
|
||||
osTimerStart(bt_error_check_timer_id, 1000);
|
||||
}
|
||||
test_mode_type = 1;
|
||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE);
|
||||
pmu_sleep_en(0);
|
||||
BESHCI_Close();
|
||||
btdrv_hciopen();
|
||||
btdrv_hci_reset();
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
app_stop_10_second_timer(APP_PAIR_TIMER_ID);
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
if (app_bt_accessmode_timer) {
|
||||
osTimerStop(app_bt_accessmode_timer);
|
||||
}
|
||||
if (!bt_error_check_timer_id) {
|
||||
bt_error_check_timer_id =
|
||||
osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||
}
|
||||
if (bt_error_check_timer_id != NULL) {
|
||||
osTimerStart(bt_error_check_timer_id, 1000);
|
||||
}
|
||||
test_mode_type = 1;
|
||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE);
|
||||
pmu_sleep_en(0);
|
||||
BESHCI_Close();
|
||||
btdrv_hciopen();
|
||||
btdrv_hci_reset();
|
||||
|
||||
#ifndef BT_50_FUNCTION
|
||||
btdrv_sleep_config(0);
|
||||
osDelay(2000);
|
||||
btdrv_ins_patch_test_init();
|
||||
btdrv_feature_default();
|
||||
btdrv_sleep_config(0);
|
||||
osDelay(2000);
|
||||
btdrv_ins_patch_test_init();
|
||||
btdrv_feature_default();
|
||||
#endif
|
||||
devinfo.btd_addr = bt_addr;
|
||||
devinfo.ble_addr = ble_addr;
|
||||
devinfo.localname = BT_LOCAL_NAME;
|
||||
nvrec_dev_localname_addr_init(&devinfo);
|
||||
btdrv_write_localinfo((char *)devinfo.localname, strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||
devinfo.btd_addr = bt_addr;
|
||||
devinfo.ble_addr = ble_addr;
|
||||
devinfo.localname = BT_LOCAL_NAME;
|
||||
nvrec_dev_localname_addr_init(&devinfo);
|
||||
btdrv_write_localinfo((char *)devinfo.localname,
|
||||
strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||
|
||||
btdrv_vco_test_start(78);
|
||||
while(1){
|
||||
btdrv_rf_set_xtal_fcap(fcap%XTAL_FCAP_RANGE, 1);
|
||||
osDelay(300);
|
||||
TRACE(2,"xtal tune:%d", fcap%XTAL_FCAP_RANGE);
|
||||
fcap++;
|
||||
}
|
||||
btdrv_vco_test_start(78);
|
||||
while (1) {
|
||||
btdrv_rf_set_xtal_fcap(fcap % XTAL_FCAP_RANGE, 1);
|
||||
osDelay(300);
|
||||
TRACE(2, "xtal tune:%d", fcap % XTAL_FCAP_RANGE);
|
||||
fcap++;
|
||||
}
|
||||
}
|
||||
|
||||
void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
dev_addr_name devinfo;
|
||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||
void app_factorymode_bt_signalingtest(APP_KEY_STATUS *status, void *param) {
|
||||
dev_addr_name devinfo;
|
||||
APP_FACTORY_TRACE(1, "%s", __func__);
|
||||
#ifdef __WATCHER_DOG_RESET__
|
||||
app_wdt_close();
|
||||
app_wdt_close();
|
||||
#endif
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
app_stop_10_second_timer(APP_PAIR_TIMER_ID);
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
if (app_bt_accessmode_timer){
|
||||
osTimerStop(app_bt_accessmode_timer);
|
||||
}
|
||||
if (!bt_error_check_timer_id){
|
||||
bt_error_check_timer_id = osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||
}
|
||||
if (bt_error_check_timer_id != NULL) {
|
||||
osTimerStart(bt_error_check_timer_id, 1000);
|
||||
}
|
||||
test_mode_type = 1;
|
||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE);
|
||||
pmu_sleep_en(0);
|
||||
BESHCI_Close();
|
||||
btdrv_hciopen();
|
||||
btdrv_ins_patch_test_init();
|
||||
btdrv_hci_reset();
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
app_stop_10_second_timer(APP_PAIR_TIMER_ID);
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
if (app_bt_accessmode_timer) {
|
||||
osTimerStop(app_bt_accessmode_timer);
|
||||
}
|
||||
if (!bt_error_check_timer_id) {
|
||||
bt_error_check_timer_id =
|
||||
osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||
}
|
||||
if (bt_error_check_timer_id != NULL) {
|
||||
osTimerStart(bt_error_check_timer_id, 1000);
|
||||
}
|
||||
test_mode_type = 1;
|
||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE);
|
||||
pmu_sleep_en(0);
|
||||
BESHCI_Close();
|
||||
btdrv_hciopen();
|
||||
btdrv_ins_patch_test_init();
|
||||
btdrv_hci_reset();
|
||||
|
||||
#ifndef BT_50_FUNCTION
|
||||
btdrv_sleep_config(0);
|
||||
osDelay(2000);
|
||||
btdrv_testmode_start();
|
||||
btdrv_feature_default();
|
||||
btdrv_sleep_config(0);
|
||||
osDelay(2000);
|
||||
btdrv_testmode_start();
|
||||
btdrv_feature_default();
|
||||
#endif
|
||||
devinfo.btd_addr = bt_addr;
|
||||
devinfo.ble_addr = ble_addr;
|
||||
devinfo.localname = BT_LOCAL_NAME;
|
||||
devinfo.ble_name= BT_LOCAL_NAME;
|
||||
nvrec_dev_localname_addr_init(&devinfo);
|
||||
devinfo.btd_addr = bt_addr;
|
||||
devinfo.ble_addr = ble_addr;
|
||||
devinfo.localname = BT_LOCAL_NAME;
|
||||
devinfo.ble_name = BT_LOCAL_NAME;
|
||||
nvrec_dev_localname_addr_init(&devinfo);
|
||||
#ifdef __IBRT_IBRT_TESTMODE__
|
||||
uint8_t ibrt_address[6] = {0x11,0x22,0x33,0x44,0x55,0x66};
|
||||
memcpy(bt_addr,ibrt_address,6);
|
||||
memcpy(devinfo.btd_addr,ibrt_address,6);
|
||||
uint8_t ibrt_address[6] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
|
||||
memcpy(bt_addr, ibrt_address, 6);
|
||||
memcpy(devinfo.btd_addr, ibrt_address, 6);
|
||||
#endif
|
||||
btdrv_write_localinfo((char *)devinfo.localname, strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||
bt_drv_extra_config_after_init();
|
||||
btdrv_enable_dut();
|
||||
btdrv_write_localinfo((char *)devinfo.localname,
|
||||
strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||
bt_drv_extra_config_after_init();
|
||||
btdrv_enable_dut();
|
||||
#ifdef __IBRT_IBRT_TESTMODE__
|
||||
btdrv_enable_ibrt_test();
|
||||
btdrv_enable_ibrt_test();
|
||||
#endif
|
||||
}
|
||||
|
||||
int app_battery_stop(void);
|
||||
void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
dev_addr_name devinfo;
|
||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||
void app_factorymode_bt_nosignalingtest(APP_KEY_STATUS *status, void *param) {
|
||||
dev_addr_name devinfo;
|
||||
APP_FACTORY_TRACE(1, "%s", __func__);
|
||||
#ifdef __WATCHER_DOG_RESET__
|
||||
app_wdt_close();
|
||||
app_wdt_close();
|
||||
#endif
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
app_stop_10_second_timer(APP_PAIR_TIMER_ID);
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE1);
|
||||
osTimerStop(app_bt_accessmode_timer);
|
||||
if (!bt_error_check_timer_id){
|
||||
bt_error_check_timer_id = osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||
}
|
||||
if (bt_error_check_timer_id != NULL) {
|
||||
osTimerStart(bt_error_check_timer_id, 1000);
|
||||
}
|
||||
test_mode_type = 2;
|
||||
app_battery_stop();
|
||||
pmu_sleep_en(0);
|
||||
BESHCI_Close();
|
||||
btdrv_hciopen();
|
||||
btdrv_ins_patch_test_init();
|
||||
bt_drv_reg_op_key_gen_after_reset(false);
|
||||
btdrv_hci_reset();
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
app_stop_10_second_timer(APP_PAIR_TIMER_ID);
|
||||
app_stop_10_second_timer(APP_POWEROFF_TIMER_ID);
|
||||
app_status_indication_set(APP_STATUS_INDICATION_TESTMODE1);
|
||||
osTimerStop(app_bt_accessmode_timer);
|
||||
if (!bt_error_check_timer_id) {
|
||||
bt_error_check_timer_id =
|
||||
osTimerCreate(osTimer(bt_error_check_timer), osTimerPeriodic, NULL);
|
||||
}
|
||||
if (bt_error_check_timer_id != NULL) {
|
||||
osTimerStart(bt_error_check_timer_id, 1000);
|
||||
}
|
||||
test_mode_type = 2;
|
||||
app_battery_stop();
|
||||
pmu_sleep_en(0);
|
||||
BESHCI_Close();
|
||||
btdrv_hciopen();
|
||||
btdrv_ins_patch_test_init();
|
||||
bt_drv_reg_op_key_gen_after_reset(false);
|
||||
btdrv_hci_reset();
|
||||
#ifndef BT_50_FUNCTION
|
||||
btdrv_sleep_config(0);
|
||||
btdrv_sleep_config(0);
|
||||
#endif
|
||||
osDelay(2000);
|
||||
btdrv_testmode_start();
|
||||
osDelay(2000);
|
||||
btdrv_testmode_start();
|
||||
#ifndef BT_50_FUNCTION
|
||||
btdrv_feature_default();
|
||||
devinfo.btd_addr = bt_addr;
|
||||
devinfo.ble_addr = ble_addr;
|
||||
devinfo.localname = BT_LOCAL_NAME;
|
||||
devinfo.ble_name= BT_LOCAL_NAME;
|
||||
nvrec_dev_localname_addr_init(&devinfo);
|
||||
btdrv_write_localinfo((char *)devinfo.localname, strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||
btdrv_feature_default();
|
||||
devinfo.btd_addr = bt_addr;
|
||||
devinfo.ble_addr = ble_addr;
|
||||
devinfo.localname = BT_LOCAL_NAME;
|
||||
devinfo.ble_name = BT_LOCAL_NAME;
|
||||
nvrec_dev_localname_addr_init(&devinfo);
|
||||
btdrv_write_localinfo((char *)devinfo.localname,
|
||||
strlen(devinfo.localname) + 1, devinfo.btd_addr);
|
||||
#endif
|
||||
bt_drv_extra_config_after_init();
|
||||
btdrv_hcioff();
|
||||
bt_drv_extra_config_after_init();
|
||||
btdrv_hcioff();
|
||||
#ifdef __BT_DEBUG_TPORTS__
|
||||
{
|
||||
extern void bt_enable_tports(void);
|
||||
bt_enable_tports();
|
||||
//hal_iomux_tportopen();
|
||||
}
|
||||
{
|
||||
extern void bt_enable_tports(void);
|
||||
bt_enable_tports();
|
||||
// hal_iomux_tportopen();
|
||||
}
|
||||
#endif
|
||||
btdrv_uart_bridge_loop();
|
||||
btdrv_uart_bridge_loop();
|
||||
}
|
||||
int app_factorymode_bt_xtalcalib_proc(void)
|
||||
{
|
||||
uint32_t capval = 0x80;
|
||||
int nRet;
|
||||
int app_factorymode_bt_xtalcalib_proc(void) {
|
||||
uint32_t capval = 0x80;
|
||||
int nRet;
|
||||
|
||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
APP_FACTORY_TRACE(1,"calib default, capval:%d", capval);
|
||||
btdrv_hciopen();
|
||||
btdrv_hci_reset();
|
||||
APP_FACTORY_TRACE(1, "%s", __func__);
|
||||
hal_cpu_wake_lock(APP_FACT_CPU_WAKE_LOCK);
|
||||
APP_FACTORY_TRACE(1, "calib default, capval:%d", capval);
|
||||
btdrv_hciopen();
|
||||
btdrv_hci_reset();
|
||||
#ifndef BT_50_FUNCTION
|
||||
btdrv_ins_patch_test_init();
|
||||
btdrv_ins_patch_test_init();
|
||||
#endif
|
||||
btdrv_hcioff();
|
||||
capval = 0x80;
|
||||
bt_drv_calib_open();
|
||||
nRet = bt_drv_calib_result_porc(&capval);
|
||||
bt_drv_calib_close();
|
||||
TRACE(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!calib ret:%d, capval:%d", nRet, capval);
|
||||
if (!nRet)
|
||||
nvrec_dev_set_xtal_fcap((unsigned int)capval);
|
||||
btdrv_hcioff();
|
||||
capval = 0x80;
|
||||
bt_drv_calib_open();
|
||||
nRet = bt_drv_calib_result_porc(&capval);
|
||||
bt_drv_calib_close();
|
||||
TRACE(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!calib ret:%d, capval:%d", nRet, capval);
|
||||
if (!nRet)
|
||||
nvrec_dev_set_xtal_fcap((unsigned int)capval);
|
||||
|
||||
return nRet;
|
||||
return nRet;
|
||||
}
|
||||
|
||||
void app_factorymode_bt_xtalcalib(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
APP_FACTORY_TRACE(1,"%s",__func__);
|
||||
app_factorymode_bt_xtalcalib_proc();
|
||||
void app_factorymode_bt_xtalcalib(APP_KEY_STATUS *status, void *param) {
|
||||
APP_FACTORY_TRACE(1, "%s", __func__);
|
||||
app_factorymode_bt_xtalcalib_proc();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,179 +1,180 @@
|
|||
#ifdef __USB_COMM__
|
||||
#include "stdint.h"
|
||||
#include "stdbool.h"
|
||||
#include "plat_types.h"
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "tool_msg.h"
|
||||
#include "sys_api_cdc_comm.h"
|
||||
#include "app_factory_cdc_comm.h"
|
||||
#include "plat_types.h"
|
||||
#include "stdbool.h"
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "sys_api_cdc_comm.h"
|
||||
#include "tool_msg.h"
|
||||
|
||||
static enum PARSE_STATE parse_state;
|
||||
static struct message_t recv_msg;
|
||||
static struct message_t send_msg = { { PREFIX_CHAR, }, };
|
||||
static struct message_t send_msg = {
|
||||
{
|
||||
PREFIX_CHAR,
|
||||
},
|
||||
};
|
||||
|
||||
static unsigned char check_sum(unsigned char *buf, unsigned char len)
|
||||
{
|
||||
int i;
|
||||
unsigned char sum = 0;
|
||||
static unsigned char check_sum(unsigned char *buf, unsigned char len) {
|
||||
int i;
|
||||
unsigned char sum = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
sum += buf[i];
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
sum += buf[i];
|
||||
}
|
||||
|
||||
return sum;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int send_reply(const unsigned char *payload, unsigned int len)
|
||||
{
|
||||
int ret = 0;
|
||||
int send_reply(const unsigned char *payload, unsigned int len) {
|
||||
int ret = 0;
|
||||
|
||||
if (len + 1 > sizeof(send_msg.data)) {
|
||||
TRACE(1,"Packet length too long: %u", len);
|
||||
return -1;
|
||||
}
|
||||
if (len + 1 > sizeof(send_msg.data)) {
|
||||
TRACE(1, "Packet length too long: %u", len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
send_msg.hdr.type = recv_msg.hdr.type;
|
||||
send_msg.hdr.seq = recv_msg.hdr.seq;
|
||||
send_msg.hdr.len = len;
|
||||
memcpy(&send_msg.data[0], payload, len);
|
||||
send_msg.data[len] = ~check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
||||
send_msg.hdr.type = recv_msg.hdr.type;
|
||||
send_msg.hdr.seq = recv_msg.hdr.seq;
|
||||
send_msg.hdr.len = len;
|
||||
memcpy(&send_msg.data[0], payload, len);
|
||||
send_msg.data[len] =
|
||||
~check_sum((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg) - 1);
|
||||
|
||||
ret = send_data((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
||||
ret = send_data((unsigned char *)&send_msg, MSG_TOTAL_LEN(&send_msg));
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void reset_parse_state(unsigned char **buf, size_t *len)
|
||||
{
|
||||
parse_state = PARSE_HEADER;
|
||||
memset(&recv_msg.hdr, 0, sizeof(recv_msg.hdr));
|
||||
static void reset_parse_state(unsigned char **buf, size_t *len) {
|
||||
parse_state = PARSE_HEADER;
|
||||
memset(&recv_msg.hdr, 0, sizeof(recv_msg.hdr));
|
||||
|
||||
*buf = (unsigned char *)&recv_msg.hdr;
|
||||
*len = sizeof(recv_msg.hdr);
|
||||
*buf = (unsigned char *)&recv_msg.hdr;
|
||||
*len = sizeof(recv_msg.hdr);
|
||||
}
|
||||
|
||||
static enum ERR_CODE check_msg_hdr(void)
|
||||
{
|
||||
enum ERR_CODE errcode = ERR_NONE;
|
||||
static enum ERR_CODE check_msg_hdr(void) {
|
||||
enum ERR_CODE errcode = ERR_NONE;
|
||||
|
||||
switch (recv_msg.hdr.type) {
|
||||
case TYPE_SYS:
|
||||
if (recv_msg.hdr.len != 1 && recv_msg.hdr.len != 5) {
|
||||
//TRACE(1,"SYS msg length error: %u", recv_msg.hdr.len);
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
break;
|
||||
case TYPE_READ:
|
||||
if (recv_msg.hdr.len != 4) {
|
||||
//TRACE(1,"READ msg length error: %u", recv_msg.hdr.len);
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
break;
|
||||
case TYPE_WRITE:
|
||||
if (recv_msg.hdr.len <= 4 || recv_msg.hdr.len > 20) {
|
||||
//TRACE(1,"WRITE msg length error: %u", recv_msg.hdr.len);
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
switch (recv_msg.hdr.type) {
|
||||
case TYPE_SYS:
|
||||
if (recv_msg.hdr.len != 1 && recv_msg.hdr.len != 5) {
|
||||
// TRACE(1,"SYS msg length error: %u", recv_msg.hdr.len);
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
|
||||
if (errcode == ERR_NONE && recv_msg.hdr.len + 1 > sizeof(recv_msg.data)) {
|
||||
errcode = ERR_LEN;
|
||||
break;
|
||||
case TYPE_READ:
|
||||
if (recv_msg.hdr.len != 4) {
|
||||
// TRACE(1,"READ msg length error: %u", recv_msg.hdr.len);
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
break;
|
||||
case TYPE_WRITE:
|
||||
if (recv_msg.hdr.len <= 4 || recv_msg.hdr.len > 20) {
|
||||
// TRACE(1,"WRITE msg length error: %u", recv_msg.hdr.len);
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return errcode;
|
||||
if (errcode == ERR_NONE && recv_msg.hdr.len + 1 > sizeof(recv_msg.data)) {
|
||||
errcode = ERR_LEN;
|
||||
}
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
static enum ERR_CODE handle_sys_cmd(enum SYS_CMD_TYPE cmd, unsigned char *param, unsigned int len)
|
||||
{
|
||||
unsigned char cret[5];
|
||||
unsigned int bootmode;
|
||||
static enum ERR_CODE handle_sys_cmd(enum SYS_CMD_TYPE cmd, unsigned char *param,
|
||||
unsigned int len) {
|
||||
unsigned char cret[5];
|
||||
unsigned int bootmode;
|
||||
|
||||
cret[0] = ERR_NONE;
|
||||
cret[0] = ERR_NONE;
|
||||
|
||||
if (cmd == SYS_CMD_SET_BOOTMODE || cmd == SYS_CMD_CLR_BOOTMODE) {
|
||||
if (len != 4) {
|
||||
TRACE(2,"Invalid SYS CMD len %u for cmd: 0x%x", len, cmd);
|
||||
return ERR_DATA_LEN;
|
||||
}
|
||||
} else {
|
||||
if (len != 0) {
|
||||
TRACE(2,"Invalid SYS CMD len %u for cmd: 0x%x", len, cmd);
|
||||
return ERR_DATA_LEN;
|
||||
}
|
||||
if (cmd == SYS_CMD_SET_BOOTMODE || cmd == SYS_CMD_CLR_BOOTMODE) {
|
||||
if (len != 4) {
|
||||
TRACE(2, "Invalid SYS CMD len %u for cmd: 0x%x", len, cmd);
|
||||
return ERR_DATA_LEN;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case SYS_CMD_REBOOT: {
|
||||
TRACE(0,"--- Reboot---");
|
||||
send_reply(cret, 1);
|
||||
system_reboot();
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_SHUTDOWN: {
|
||||
TRACE(0,"--- Shutdown ---");
|
||||
send_reply(cret, 1);
|
||||
system_shutdown();
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_SET_BOOTMODE: {
|
||||
TRACE(0,"--- Set bootmode ---");
|
||||
memcpy(&bootmode, param, 4);
|
||||
system_set_bootmode(bootmode);
|
||||
send_reply(cret, 1);
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_CLR_BOOTMODE: {
|
||||
TRACE(0,"--- Clear bootmode ---");
|
||||
memcpy(&bootmode, param, 4);
|
||||
system_clear_bootmode(bootmode);
|
||||
send_reply(cret, 1);
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_GET_BOOTMODE: {
|
||||
TRACE(0,"--- Get bootmode ---");
|
||||
bootmode = system_get_bootmode();
|
||||
memcpy(&cret[1], &bootmode, 4);
|
||||
send_reply(cret, 5);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
TRACE(1,"Invalid command: 0x%x", recv_msg.data[0]);
|
||||
return ERR_SYS_CMD;
|
||||
}
|
||||
} else {
|
||||
if (len != 0) {
|
||||
TRACE(2, "Invalid SYS CMD len %u for cmd: 0x%x", len, cmd);
|
||||
return ERR_DATA_LEN;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_NONE;
|
||||
switch (cmd) {
|
||||
case SYS_CMD_REBOOT: {
|
||||
TRACE(0, "--- Reboot---");
|
||||
send_reply(cret, 1);
|
||||
system_reboot();
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_SHUTDOWN: {
|
||||
TRACE(0, "--- Shutdown ---");
|
||||
send_reply(cret, 1);
|
||||
system_shutdown();
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_SET_BOOTMODE: {
|
||||
TRACE(0, "--- Set bootmode ---");
|
||||
memcpy(&bootmode, param, 4);
|
||||
system_set_bootmode(bootmode);
|
||||
send_reply(cret, 1);
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_CLR_BOOTMODE: {
|
||||
TRACE(0, "--- Clear bootmode ---");
|
||||
memcpy(&bootmode, param, 4);
|
||||
system_clear_bootmode(bootmode);
|
||||
send_reply(cret, 1);
|
||||
break;
|
||||
}
|
||||
case SYS_CMD_GET_BOOTMODE: {
|
||||
TRACE(0, "--- Get bootmode ---");
|
||||
bootmode = system_get_bootmode();
|
||||
memcpy(&cret[1], &bootmode, 4);
|
||||
send_reply(cret, 5);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
TRACE(1, "Invalid command: 0x%x", recv_msg.data[0]);
|
||||
return ERR_SYS_CMD;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra)
|
||||
{
|
||||
enum ERR_CODE errcode = ERR_NONE;
|
||||
static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra) {
|
||||
enum ERR_CODE errcode = ERR_NONE;
|
||||
#if 0
|
||||
uint32_t rlen = 0;
|
||||
#endif
|
||||
*extra = 0;
|
||||
*extra = 0;
|
||||
|
||||
// Checksum
|
||||
if (check_sum((unsigned char *)&recv_msg, MSG_TOTAL_LEN(&recv_msg)) != 0xFF) {
|
||||
TRACE(0,"Checksum error");
|
||||
return ERR_CHECKSUM;
|
||||
// Checksum
|
||||
if (check_sum((unsigned char *)&recv_msg, MSG_TOTAL_LEN(&recv_msg)) != 0xFF) {
|
||||
TRACE(0, "Checksum error");
|
||||
return ERR_CHECKSUM;
|
||||
}
|
||||
|
||||
switch (recv_msg.hdr.type) {
|
||||
case TYPE_SYS: {
|
||||
TRACE_TIME(0, "------ SYS CMD ------");
|
||||
errcode = handle_sys_cmd((enum SYS_CMD_TYPE)recv_msg.data[0],
|
||||
&recv_msg.data[1], recv_msg.hdr.len - 1);
|
||||
if (errcode != ERR_NONE) {
|
||||
return errcode;
|
||||
}
|
||||
|
||||
switch (recv_msg.hdr.type) {
|
||||
case TYPE_SYS: {
|
||||
TRACE_TIME(0,"------ SYS CMD ------");
|
||||
errcode = handle_sys_cmd((enum SYS_CMD_TYPE)recv_msg.data[0], &recv_msg.data[1], recv_msg.hdr.len - 1);
|
||||
if (errcode != ERR_NONE) {
|
||||
return errcode;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TYPE_READ: {
|
||||
TRACE_TIME(0,"------ READ CMD ------");
|
||||
break;
|
||||
}
|
||||
case TYPE_READ: {
|
||||
TRACE_TIME(0, "------ READ CMD ------");
|
||||
#if 0
|
||||
uint32_t addr = (recv_msg.data[0] << 16) | (recv_msg.data[1] << 8) | recv_msg.data[2];
|
||||
uint8_t data[4] = {0};
|
||||
|
@ -184,10 +185,10 @@ static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra)
|
|||
send_reply(data, rlen);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case TYPE_WRITE: {
|
||||
TRACE_TIME(0,"------ WRITE CMD ------");
|
||||
break;
|
||||
}
|
||||
case TYPE_WRITE: {
|
||||
TRACE_TIME(0, "------ WRITE CMD ------");
|
||||
#if 0
|
||||
uint32_t addr = (recv_msg.data[0] << 16) | (recv_msg.data[1] << 8) | recv_msg.data[2];
|
||||
uint32_t wdata = (recv_msg.data[3] << 24) | (recv_msg.data[4] << 16) | (recv_msg.data[5] << 8) | recv_msg.data[6];
|
||||
|
@ -198,117 +199,115 @@ static enum ERR_CODE handle_data(unsigned char **buf, size_t *len, int *extra)
|
|||
else
|
||||
send_reply(data, 1);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ERR_NONE;
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
static int parse_packet(unsigned char **buf, size_t *len)
|
||||
{
|
||||
enum ERR_CODE errcode;
|
||||
int rlen = *len;
|
||||
unsigned char *data;
|
||||
int i;
|
||||
int extra;
|
||||
unsigned char cret;
|
||||
static int parse_packet(unsigned char **buf, size_t *len) {
|
||||
enum ERR_CODE errcode;
|
||||
int rlen = *len;
|
||||
unsigned char *data;
|
||||
int i;
|
||||
int extra;
|
||||
unsigned char cret;
|
||||
|
||||
switch (parse_state) {
|
||||
case PARSE_HEADER:
|
||||
ASSERT(rlen > 0 && rlen <= sizeof(recv_msg.hdr), "Invalid rlen!");
|
||||
switch (parse_state) {
|
||||
case PARSE_HEADER:
|
||||
ASSERT(rlen > 0 && rlen <= sizeof(recv_msg.hdr), "Invalid rlen!");
|
||||
|
||||
if (recv_msg.hdr.prefix == PREFIX_CHAR) {
|
||||
errcode = check_msg_hdr();
|
||||
if (errcode != ERR_NONE) {
|
||||
goto _err;
|
||||
}
|
||||
parse_state = PARSE_DATA;
|
||||
*buf = &recv_msg.data[0];
|
||||
*len = recv_msg.hdr.len + 1;
|
||||
} else {
|
||||
data = (unsigned char *)&recv_msg.hdr.prefix;
|
||||
for (i = 1; i < rlen; i++) {
|
||||
if (data[i] == PREFIX_CHAR) {
|
||||
memmove(&recv_msg.hdr.prefix, &data[i], rlen - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*buf = &data[rlen - i];
|
||||
*len = sizeof(recv_msg.hdr) + i - rlen;
|
||||
}
|
||||
break;
|
||||
case PARSE_DATA:
|
||||
errcode = handle_data(buf, len, &extra);
|
||||
if (errcode != ERR_NONE) {
|
||||
goto _err;
|
||||
}
|
||||
// Receive next message
|
||||
reset_parse_state(buf, len);
|
||||
break;
|
||||
default:
|
||||
TRACE(1,"Invalid parse_state: %d", parse_state);
|
||||
break;
|
||||
if (recv_msg.hdr.prefix == PREFIX_CHAR) {
|
||||
errcode = check_msg_hdr();
|
||||
if (errcode != ERR_NONE) {
|
||||
goto _err;
|
||||
}
|
||||
parse_state = PARSE_DATA;
|
||||
*buf = &recv_msg.data[0];
|
||||
*len = recv_msg.hdr.len + 1;
|
||||
} else {
|
||||
data = (unsigned char *)&recv_msg.hdr.prefix;
|
||||
for (i = 1; i < rlen; i++) {
|
||||
if (data[i] == PREFIX_CHAR) {
|
||||
memmove(&recv_msg.hdr.prefix, &data[i], rlen - i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*buf = &data[rlen - i];
|
||||
*len = sizeof(recv_msg.hdr) + i - rlen;
|
||||
}
|
||||
break;
|
||||
case PARSE_DATA:
|
||||
errcode = handle_data(buf, len, &extra);
|
||||
if (errcode != ERR_NONE) {
|
||||
goto _err;
|
||||
}
|
||||
// Receive next message
|
||||
reset_parse_state(buf, len);
|
||||
break;
|
||||
default:
|
||||
TRACE(1, "Invalid parse_state: %d", parse_state);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
cancel_input();
|
||||
cret = (unsigned char)errcode;
|
||||
send_reply(&cret, 1);
|
||||
cancel_input();
|
||||
cret = (unsigned char)errcode;
|
||||
send_reply(&cret, 1);
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void comm_loop(void)
|
||||
{
|
||||
int ret;
|
||||
unsigned char *buf = NULL;
|
||||
size_t len = 0;
|
||||
size_t buf_len, rlen;
|
||||
void comm_loop(void) {
|
||||
int ret;
|
||||
unsigned char *buf = NULL;
|
||||
size_t len = 0;
|
||||
size_t buf_len, rlen;
|
||||
|
||||
_sync:
|
||||
reset_transport();
|
||||
reset_parse_state(&buf, &len);
|
||||
reset_transport();
|
||||
reset_parse_state(&buf, &len);
|
||||
|
||||
while (1) {
|
||||
rlen = 0;
|
||||
if (parse_state == PARSE_HEADER) {
|
||||
set_recv_timeout(default_recv_timeout_idle);
|
||||
} else {
|
||||
set_recv_timeout(default_recv_timeout_short);
|
||||
}
|
||||
buf_len = 0;
|
||||
|
||||
ret = recv_data_ex(buf, buf_len, len, &rlen);
|
||||
if (ret) {
|
||||
TRACE(1,"Receiving data failed: %d", ret);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (len != rlen) {
|
||||
TRACE(2,"Receiving part of the data: expect=%u real=%u", len, rlen);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
ret = parse_packet(&buf, &len);
|
||||
if (ret) {
|
||||
TRACE(0,"Parsing packet failed");
|
||||
goto _err;
|
||||
}
|
||||
while (1) {
|
||||
rlen = 0;
|
||||
if (parse_state == PARSE_HEADER) {
|
||||
set_recv_timeout(default_recv_timeout_idle);
|
||||
} else {
|
||||
set_recv_timeout(default_recv_timeout_short);
|
||||
}
|
||||
buf_len = 0;
|
||||
|
||||
ret = recv_data_ex(buf, buf_len, len, &rlen);
|
||||
if (ret) {
|
||||
TRACE(1, "Receiving data failed: %d", ret);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (len != rlen) {
|
||||
TRACE(2, "Receiving part of the data: expect=%u real=%u", len, rlen);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
ret = parse_packet(&buf, &len);
|
||||
if (ret) {
|
||||
TRACE(0, "Parsing packet failed");
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
|
||||
_err:
|
||||
ret = handle_error();
|
||||
if (ret == 0) {
|
||||
TRACE(0,"retry ...");
|
||||
goto _sync;
|
||||
}
|
||||
ret = handle_error();
|
||||
if (ret == 0) {
|
||||
TRACE(0, "retry ...");
|
||||
goto _sync;
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
#include "usb_cdc.h"
|
||||
#endif
|
||||
|
||||
#define TIMEOUT_INFINITE ((uint32_t)-1)
|
||||
#define TIMEOUT_INFINITE ((uint32_t)-1)
|
||||
|
||||
const unsigned int default_recv_timeout_short = MS_TO_TICKS(500);
|
||||
const unsigned int default_recv_timeout_idle = TIMEOUT_INFINITE; //MS_TO_TICKS(10 * 60 * 1000);
|
||||
const unsigned int default_recv_timeout_idle =
|
||||
TIMEOUT_INFINITE; // MS_TO_TICKS(10 * 60 * 1000);
|
||||
const unsigned int default_recv_timeout_4k_data = MS_TO_TICKS(500);
|
||||
const unsigned int default_send_timeout = MS_TO_TICKS(500);
|
||||
|
||||
|
@ -29,201 +30,165 @@ static const struct USB_SERIAL_CFG_T cdc_cfg = {
|
|||
.mode = USB_SERIAL_API_NONBLOCKING,
|
||||
};
|
||||
|
||||
void reset_transport(void)
|
||||
{
|
||||
cancel_xfer = false;
|
||||
void reset_transport(void) {
|
||||
cancel_xfer = false;
|
||||
|
||||
if (xfer_timer) {
|
||||
hwtimer_stop(xfer_timer);
|
||||
} else {
|
||||
xfer_timer = hwtimer_alloc(NULL, NULL);
|
||||
}
|
||||
if (xfer_timer) {
|
||||
hwtimer_stop(xfer_timer);
|
||||
} else {
|
||||
xfer_timer = hwtimer_alloc(NULL, NULL);
|
||||
}
|
||||
|
||||
usb_serial_flush_recv_buffer();
|
||||
usb_serial_init_xfer();
|
||||
set_recv_timeout(default_recv_timeout_short);
|
||||
set_send_timeout(default_send_timeout);
|
||||
usb_serial_flush_recv_buffer();
|
||||
usb_serial_init_xfer();
|
||||
set_recv_timeout(default_recv_timeout_short);
|
||||
set_send_timeout(default_send_timeout);
|
||||
}
|
||||
|
||||
void set_recv_timeout(unsigned int timeout)
|
||||
{
|
||||
recv_timeout = timeout;
|
||||
void set_recv_timeout(unsigned int timeout) { recv_timeout = timeout; }
|
||||
|
||||
void set_send_timeout(unsigned int timeout) { send_timeout = timeout; }
|
||||
|
||||
static void usb_send_timeout(void *param) { usb_serial_cancel_send(); }
|
||||
|
||||
static void usb_send_timer_start(void) {
|
||||
if (send_timeout == TIMEOUT_INFINITE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xfer_timer) {
|
||||
hwtimer_update_then_start(xfer_timer, usb_send_timeout, NULL, send_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
void set_send_timeout(unsigned int timeout)
|
||||
{
|
||||
send_timeout = timeout;
|
||||
static void usb_send_timer_stop(void) {
|
||||
if (xfer_timer) {
|
||||
hwtimer_stop(xfer_timer);
|
||||
}
|
||||
}
|
||||
|
||||
static void usb_send_timeout(void *param)
|
||||
{
|
||||
usb_serial_cancel_send();
|
||||
static int usb_send_data(const unsigned char *buf, size_t len) {
|
||||
int ret;
|
||||
|
||||
usb_send_timer_start();
|
||||
ret = usb_serial_send(buf, len);
|
||||
usb_send_timer_stop();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void usb_send_timer_start(void)
|
||||
{
|
||||
if (send_timeout == TIMEOUT_INFINITE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xfer_timer) {
|
||||
hwtimer_update_then_start(xfer_timer, usb_send_timeout, NULL, send_timeout);
|
||||
}
|
||||
int send_data(const unsigned char *buf, size_t len) {
|
||||
if (cancel_xfer) {
|
||||
return -1;
|
||||
}
|
||||
return usb_send_data(buf, len);
|
||||
}
|
||||
|
||||
static void usb_send_timer_stop(void)
|
||||
{
|
||||
if (xfer_timer) {
|
||||
hwtimer_stop(xfer_timer);
|
||||
}
|
||||
static void usb_recv_timeout(void *param) { usb_serial_cancel_recv(); }
|
||||
|
||||
static void usb_recv_timer_start(void) {
|
||||
if (recv_timeout == TIMEOUT_INFINITE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xfer_timer) {
|
||||
hwtimer_update_then_start(xfer_timer, usb_recv_timeout, NULL, recv_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
static int usb_send_data(const unsigned char *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
usb_send_timer_start();
|
||||
ret = usb_serial_send(buf, len);
|
||||
usb_send_timer_stop();
|
||||
return ret;
|
||||
static void usb_recv_timer_stop(void) {
|
||||
if (xfer_timer) {
|
||||
hwtimer_stop(xfer_timer);
|
||||
}
|
||||
}
|
||||
|
||||
int send_data(const unsigned char *buf, size_t len)
|
||||
{
|
||||
if (cancel_xfer) {
|
||||
return -1;
|
||||
}
|
||||
return usb_send_data(buf, len);
|
||||
static int usb_recv_data(unsigned char *buf, size_t len, size_t *rlen) {
|
||||
int ret;
|
||||
|
||||
usb_recv_timer_start();
|
||||
ret = usb_serial_recv(buf, len);
|
||||
usb_recv_timer_stop();
|
||||
if (ret == 0) {
|
||||
*rlen = len;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void usb_recv_timeout(void *param)
|
||||
{
|
||||
usb_serial_cancel_recv();
|
||||
int recv_data_ex(unsigned char *buf, size_t len, size_t expect, size_t *rlen) {
|
||||
if (cancel_xfer) {
|
||||
return -1;
|
||||
}
|
||||
return usb_recv_data(buf, expect, rlen);
|
||||
}
|
||||
|
||||
static void usb_recv_timer_start(void)
|
||||
{
|
||||
if (recv_timeout == TIMEOUT_INFINITE) {
|
||||
return;
|
||||
}
|
||||
static int usb_handle_error(void) {
|
||||
int ret;
|
||||
|
||||
if (xfer_timer) {
|
||||
hwtimer_update_then_start(xfer_timer, usb_recv_timeout, NULL, recv_timeout);
|
||||
}
|
||||
TRACE(0, "****** Send break ******");
|
||||
|
||||
// Send break signal, to tell the peer to reset the connection
|
||||
ret = usb_serial_send_break();
|
||||
if (ret) {
|
||||
TRACE(1, "Sending break failed: %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void usb_recv_timer_stop(void)
|
||||
{
|
||||
if (xfer_timer) {
|
||||
hwtimer_stop(xfer_timer);
|
||||
}
|
||||
int handle_error(void) {
|
||||
int ret = 0;
|
||||
uint32_t err_time;
|
||||
|
||||
hal_sys_timer_delay(MS_TO_TICKS(50));
|
||||
|
||||
if (!cancel_xfer) {
|
||||
ret = usb_handle_error();
|
||||
}
|
||||
|
||||
err_time = hal_sys_timer_get();
|
||||
if (xfer_err_cnt == 0 || err_time - xfer_err_time > MS_TO_TICKS(5000)) {
|
||||
xfer_err_cnt = 0;
|
||||
xfer_err_time = err_time;
|
||||
}
|
||||
xfer_err_cnt++;
|
||||
if (xfer_err_cnt < 3) {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(100));
|
||||
} else if (xfer_err_cnt < 5) {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(500));
|
||||
} else {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(2000));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usb_recv_data(unsigned char *buf, size_t len, size_t *rlen)
|
||||
{
|
||||
int ret;
|
||||
static int usb_cancel_input(void) { return usb_serial_flush_recv_buffer(); }
|
||||
|
||||
usb_recv_timer_start();
|
||||
ret = usb_serial_recv(buf, len);
|
||||
usb_recv_timer_stop();
|
||||
if (ret == 0) {
|
||||
*rlen = len;
|
||||
}
|
||||
return ret;
|
||||
int cancel_input(void) { return usb_cancel_input(); }
|
||||
|
||||
void system_reboot(void) {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(10));
|
||||
hal_cmu_sys_reboot();
|
||||
}
|
||||
|
||||
int recv_data_ex(unsigned char *buf, size_t len, size_t expect, size_t *rlen)
|
||||
{
|
||||
if (cancel_xfer) {
|
||||
return -1;
|
||||
}
|
||||
return usb_recv_data(buf, expect, rlen);
|
||||
}
|
||||
|
||||
static int usb_handle_error(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
TRACE(0,"****** Send break ******");
|
||||
|
||||
// Send break signal, to tell the peer to reset the connection
|
||||
ret = usb_serial_send_break();
|
||||
if (ret) {
|
||||
TRACE(1,"Sending break failed: %d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int handle_error(void)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t err_time;
|
||||
|
||||
hal_sys_timer_delay(MS_TO_TICKS(50));
|
||||
|
||||
if (!cancel_xfer) {
|
||||
ret = usb_handle_error();
|
||||
}
|
||||
|
||||
err_time = hal_sys_timer_get();
|
||||
if (xfer_err_cnt == 0 || err_time - xfer_err_time > MS_TO_TICKS(5000)) {
|
||||
xfer_err_cnt = 0;
|
||||
xfer_err_time = err_time;
|
||||
}
|
||||
xfer_err_cnt++;
|
||||
if (xfer_err_cnt < 3) {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(100));
|
||||
} else if (xfer_err_cnt < 5) {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(500));
|
||||
} else {
|
||||
hal_sys_timer_delay(MS_TO_TICKS(2000));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usb_cancel_input(void)
|
||||
{
|
||||
return usb_serial_flush_recv_buffer();
|
||||
}
|
||||
|
||||
int cancel_input(void)
|
||||
{
|
||||
return usb_cancel_input();
|
||||
}
|
||||
|
||||
void system_reboot(void)
|
||||
{
|
||||
hal_sys_timer_delay(MS_TO_TICKS(10));
|
||||
hal_cmu_sys_reboot();
|
||||
}
|
||||
|
||||
void system_shutdown(void)
|
||||
{
|
||||
void system_shutdown(void) {
|
||||
#if 0
|
||||
if (dld_transport == TRANSPORT_USB) {
|
||||
// Avoid PC usb serial driver hanging
|
||||
usb_serial_close();
|
||||
}
|
||||
#endif
|
||||
hal_sys_timer_delay(MS_TO_TICKS(10));
|
||||
pmu_shutdown();
|
||||
hal_sys_timer_delay(MS_TO_TICKS(10));
|
||||
pmu_shutdown();
|
||||
}
|
||||
|
||||
void system_set_bootmode(unsigned int bootmode)
|
||||
{
|
||||
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
||||
hal_sw_bootmode_set(bootmode);
|
||||
void system_set_bootmode(unsigned int bootmode) {
|
||||
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
||||
hal_sw_bootmode_set(bootmode);
|
||||
}
|
||||
|
||||
void system_clear_bootmode(unsigned int bootmode)
|
||||
{
|
||||
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
||||
hal_sw_bootmode_clear(bootmode);
|
||||
void system_clear_bootmode(unsigned int bootmode) {
|
||||
bootmode &= ~(HAL_SW_BOOTMODE_READ_ENABLED | HAL_SW_BOOTMODE_WRITE_ENABLED);
|
||||
hal_sw_bootmode_clear(bootmode);
|
||||
}
|
||||
|
||||
unsigned int system_get_bootmode(void)
|
||||
{
|
||||
return hal_sw_bootmode_get();
|
||||
}
|
||||
unsigned int system_get_bootmode(void) { return hal_sw_bootmode_get(); }
|
||||
#endif
|
||||
|
|
|
@ -13,155 +13,145 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_key.h"
|
||||
#include "app_thread.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "list.h"
|
||||
#include "string.h"
|
||||
#include "app_thread.h"
|
||||
#include "app_key.h"
|
||||
#include "hal_trace.h"
|
||||
|
||||
#define APP_KEY_TRACE(s,...) //TRACE(s, ##__VA_ARGS__)
|
||||
#define APP_KEY_TRACE(s, ...) // TRACE(s, ##__VA_ARGS__)
|
||||
|
||||
#define KEY_EVENT_CNT_LIMIT (3)
|
||||
|
||||
typedef struct {
|
||||
list_t *key_list;
|
||||
}APP_KEY_CONFIG;
|
||||
} APP_KEY_CONFIG;
|
||||
|
||||
APP_KEY_CONFIG app_key_conifg = {
|
||||
.key_list = NULL
|
||||
};
|
||||
APP_KEY_CONFIG app_key_conifg = {.key_list = NULL};
|
||||
|
||||
osPoolDef (app_key_handle_mempool, 20, APP_KEY_HANDLE);
|
||||
osPoolId app_key_handle_mempool = NULL;
|
||||
osPoolDef(app_key_handle_mempool, 20, APP_KEY_HANDLE);
|
||||
osPoolId app_key_handle_mempool = NULL;
|
||||
static uint8_t key_event_cnt = 0;
|
||||
|
||||
static int key_event_process(uint32_t key_code, uint8_t key_event)
|
||||
{
|
||||
uint32_t app_keyevt;
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
|
||||
if (key_event_cnt>KEY_EVENT_CNT_LIMIT){
|
||||
return 0;
|
||||
}else{
|
||||
key_event_cnt++;
|
||||
}
|
||||
|
||||
msg.mod_id = APP_MODUAL_KEY;
|
||||
APP_KEY_SET_MESSAGE(app_keyevt, key_code, key_event);
|
||||
msg.msg_body.message_id = app_keyevt;
|
||||
msg.msg_body.message_ptr = (uint32_t)NULL;
|
||||
app_mailbox_put(&msg);
|
||||
static int key_event_process(uint32_t key_code, uint8_t key_event) {
|
||||
uint32_t app_keyevt;
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
|
||||
if (key_event_cnt > KEY_EVENT_CNT_LIMIT) {
|
||||
return 0;
|
||||
} else {
|
||||
key_event_cnt++;
|
||||
}
|
||||
|
||||
msg.mod_id = APP_MODUAL_KEY;
|
||||
APP_KEY_SET_MESSAGE(app_keyevt, key_code, key_event);
|
||||
msg.msg_body.message_id = app_keyevt;
|
||||
msg.msg_body.message_ptr = (uint32_t)NULL;
|
||||
app_mailbox_put(&msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event)
|
||||
{
|
||||
key_event_process(key_code, key_event);
|
||||
void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event) {
|
||||
key_event_process(key_code, key_event);
|
||||
}
|
||||
|
||||
static void app_key_handle_free(void *key_handle)
|
||||
{
|
||||
osPoolFree (app_key_handle_mempool, key_handle);
|
||||
static void app_key_handle_free(void *key_handle) {
|
||||
osPoolFree(app_key_handle_mempool, key_handle);
|
||||
}
|
||||
|
||||
static APP_KEY_HANDLE *app_key_handle_find(const APP_KEY_STATUS *key_status)
|
||||
{
|
||||
APP_KEY_HANDLE *key_handle = NULL;
|
||||
list_node_t *node = NULL;
|
||||
static APP_KEY_HANDLE *app_key_handle_find(const APP_KEY_STATUS *key_status) {
|
||||
APP_KEY_HANDLE *key_handle = NULL;
|
||||
list_node_t *node = NULL;
|
||||
|
||||
for (node = list_begin(app_key_conifg.key_list); node != list_end(app_key_conifg.key_list); node = list_next(node)) {
|
||||
key_handle = (APP_KEY_HANDLE *)list_node(node);
|
||||
if ((key_handle->key_status.code == key_status->code)&&(key_handle->key_status.event == key_status->event))
|
||||
return key_handle;
|
||||
}
|
||||
for (node = list_begin(app_key_conifg.key_list);
|
||||
node != list_end(app_key_conifg.key_list); node = list_next(node)) {
|
||||
key_handle = (APP_KEY_HANDLE *)list_node(node);
|
||||
if ((key_handle->key_status.code == key_status->code) &&
|
||||
(key_handle->key_status.event == key_status->event))
|
||||
return key_handle;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int app_key_handle_process(APP_MESSAGE_BODY *msg_body)
|
||||
{
|
||||
APP_KEY_STATUS key_status;
|
||||
APP_KEY_HANDLE *key_handle = NULL;
|
||||
static int app_key_handle_process(APP_MESSAGE_BODY *msg_body) {
|
||||
APP_KEY_STATUS key_status;
|
||||
APP_KEY_HANDLE *key_handle = NULL;
|
||||
|
||||
APP_KEY_GET_CODE(msg_body->message_id, key_status.code);
|
||||
APP_KEY_GET_EVENT(msg_body->message_id, key_status.event);
|
||||
APP_KEY_GET_CODE(msg_body->message_id, key_status.code);
|
||||
APP_KEY_GET_EVENT(msg_body->message_id, key_status.event);
|
||||
|
||||
APP_KEY_TRACE(3,"%s code:%d event:%d",__func__,key_status.code, key_status.event);
|
||||
APP_KEY_TRACE(3, "%s code:%d event:%d", __func__, key_status.code,
|
||||
key_status.event);
|
||||
|
||||
key_event_cnt--;
|
||||
key_event_cnt--;
|
||||
|
||||
key_handle = app_key_handle_find(&key_status);
|
||||
key_handle = app_key_handle_find(&key_status);
|
||||
|
||||
if (key_handle != NULL && key_handle->function!= NULL)
|
||||
((APP_KEY_HANDLE_CB_T)key_handle->function)(&key_status,key_handle->param);
|
||||
if (key_handle != NULL && key_handle->function != NULL)
|
||||
((APP_KEY_HANDLE_CB_T)key_handle->function)(&key_status, key_handle->param);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_key_handle_registration(const APP_KEY_HANDLE *key_handle)
|
||||
{
|
||||
APP_KEY_HANDLE *dest_key_handle = NULL;
|
||||
APP_KEY_TRACE(1,"%s",__func__);
|
||||
dest_key_handle = app_key_handle_find(&(key_handle->key_status));
|
||||
int app_key_handle_registration(const APP_KEY_HANDLE *key_handle) {
|
||||
APP_KEY_HANDLE *dest_key_handle = NULL;
|
||||
APP_KEY_TRACE(1, "%s", __func__);
|
||||
dest_key_handle = app_key_handle_find(&(key_handle->key_status));
|
||||
|
||||
APP_KEY_TRACE(2,"%s dest handle:0x%x",__func__,dest_key_handle);
|
||||
if (dest_key_handle == NULL){
|
||||
dest_key_handle = (APP_KEY_HANDLE *)osPoolCAlloc (app_key_handle_mempool);
|
||||
APP_KEY_TRACE(2,"%s malloc:0x%x",__func__,dest_key_handle);
|
||||
list_append(app_key_conifg.key_list, dest_key_handle);
|
||||
}
|
||||
if (dest_key_handle == NULL)
|
||||
return -1;
|
||||
APP_KEY_TRACE(5,"%s set handle:0x%x code:%d event:%d function:%x",__func__,dest_key_handle, key_handle->key_status.code, key_handle->key_status.event, key_handle->function);
|
||||
dest_key_handle->key_status.code = key_handle->key_status.code;
|
||||
dest_key_handle->key_status.event = key_handle->key_status.event;
|
||||
dest_key_handle->string = key_handle->string;
|
||||
dest_key_handle->function = key_handle->function;
|
||||
dest_key_handle->param = key_handle->param;;
|
||||
APP_KEY_TRACE(2, "%s dest handle:0x%x", __func__, dest_key_handle);
|
||||
if (dest_key_handle == NULL) {
|
||||
dest_key_handle = (APP_KEY_HANDLE *)osPoolCAlloc(app_key_handle_mempool);
|
||||
APP_KEY_TRACE(2, "%s malloc:0x%x", __func__, dest_key_handle);
|
||||
list_append(app_key_conifg.key_list, dest_key_handle);
|
||||
}
|
||||
if (dest_key_handle == NULL)
|
||||
return -1;
|
||||
APP_KEY_TRACE(5, "%s set handle:0x%x code:%d event:%d function:%x", __func__,
|
||||
dest_key_handle, key_handle->key_status.code,
|
||||
key_handle->key_status.event, key_handle->function);
|
||||
dest_key_handle->key_status.code = key_handle->key_status.code;
|
||||
dest_key_handle->key_status.event = key_handle->key_status.event;
|
||||
dest_key_handle->string = key_handle->string;
|
||||
dest_key_handle->function = key_handle->function;
|
||||
dest_key_handle->param = key_handle->param;
|
||||
;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_key_handle_clear(void)
|
||||
{
|
||||
list_clear(app_key_conifg.key_list);
|
||||
void app_key_handle_clear(void) { list_clear(app_key_conifg.key_list); }
|
||||
|
||||
int app_key_open(int checkPwrKey) {
|
||||
APP_KEY_TRACE(2, "%s %x", __func__, app_key_conifg.key_list);
|
||||
|
||||
if (app_key_conifg.key_list == NULL)
|
||||
app_key_conifg.key_list = list_new(app_key_handle_free, NULL, NULL);
|
||||
|
||||
if (app_key_handle_mempool == NULL)
|
||||
app_key_handle_mempool = osPoolCreate(osPool(app_key_handle_mempool));
|
||||
|
||||
app_set_threadhandle(APP_MODUAL_KEY, app_key_handle_process);
|
||||
|
||||
return hal_key_open(checkPwrKey, key_event_process);
|
||||
}
|
||||
|
||||
int app_key_open(int checkPwrKey)
|
||||
{
|
||||
APP_KEY_TRACE(2,"%s %x",__func__, app_key_conifg.key_list);
|
||||
|
||||
if (app_key_conifg.key_list == NULL)
|
||||
app_key_conifg.key_list = list_new(app_key_handle_free, NULL, NULL);
|
||||
|
||||
if (app_key_handle_mempool == NULL)
|
||||
app_key_handle_mempool = osPoolCreate(osPool(app_key_handle_mempool));
|
||||
|
||||
app_set_threadhandle(APP_MODUAL_KEY, app_key_handle_process);
|
||||
|
||||
return hal_key_open(checkPwrKey, key_event_process);
|
||||
int app_key_close(void) {
|
||||
hal_key_close();
|
||||
if (app_key_conifg.key_list != NULL)
|
||||
list_free(app_key_conifg.key_list);
|
||||
app_set_threadhandle(APP_MODUAL_KEY, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_key_close(void)
|
||||
{
|
||||
hal_key_close();
|
||||
if (app_key_conifg.key_list != NULL)
|
||||
list_free(app_key_conifg.key_list);
|
||||
app_set_threadhandle(APP_MODUAL_KEY, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t app_key_read_status(uint32_t code)
|
||||
{
|
||||
return (uint32_t)hal_key_read_status((enum HAL_KEY_CODE_T)code);
|
||||
uint32_t app_key_read_status(uint32_t code) {
|
||||
return (uint32_t)hal_key_read_status((enum HAL_KEY_CODE_T)code);
|
||||
}
|
||||
|
||||
#if defined(_AUTO_TEST_)
|
||||
int simul_key_event_process(uint32_t key_code, uint8_t key_event)
|
||||
{
|
||||
return key_event_process(key_code, key_event);
|
||||
int simul_key_event_process(uint32_t key_code, uint8_t key_event) {
|
||||
return key_event_process(key_code, key_event);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -13,82 +13,87 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "hal_key.h"
|
||||
|
||||
#ifndef __APP_KEY_H__
|
||||
#define __APP_KEY_H__
|
||||
|
||||
#include "hal_key.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define APP_KEY_SET_MESSAGE(appevt, code, evt) (appevt = (((uint32_t)code&0xffffff)<<8)|(evt&0xff))
|
||||
#define APP_KEY_GET_CODE(appevt, code) (code = (appevt>>8)&0xffffff)
|
||||
#define APP_KEY_GET_EVENT(appevt, evt) (evt = appevt&0xff)
|
||||
#define APP_KEY_SET_MESSAGE(appevt, code, evt) \
|
||||
(appevt = (((uint32_t)code & 0xffffff) << 8) | (evt & 0xff))
|
||||
#define APP_KEY_GET_CODE(appevt, code) (code = (appevt >> 8) & 0xffffff)
|
||||
#define APP_KEY_GET_EVENT(appevt, evt) (evt = appevt & 0xff)
|
||||
|
||||
#define APP_KEY_CODE_GOOGLE APP_KEY_CODE_FN15
|
||||
#define APP_KEY_CODE_VOICEPATH APP_KEY_CODE_FN15
|
||||
#define APP_KEY_CODE_TILE APP_KEY_CODE_FN15
|
||||
#define APP_KEY_CODE_GOOGLE APP_KEY_CODE_FN15
|
||||
#define APP_KEY_CODE_VOICEPATH APP_KEY_CODE_FN15
|
||||
#define APP_KEY_CODE_TILE APP_KEY_CODE_FN15
|
||||
|
||||
enum APP_KEY_CODE_T {
|
||||
APP_KEY_CODE_NONE = HAL_KEY_CODE_NONE,
|
||||
APP_KEY_CODE_PWR = HAL_KEY_CODE_PWR,
|
||||
APP_KEY_CODE_FN1 = HAL_KEY_CODE_FN1,
|
||||
APP_KEY_CODE_FN2 = HAL_KEY_CODE_FN2,
|
||||
APP_KEY_CODE_FN3 = HAL_KEY_CODE_FN3,
|
||||
APP_KEY_CODE_FN4 = HAL_KEY_CODE_FN4,
|
||||
APP_KEY_CODE_FN5 = HAL_KEY_CODE_FN5,
|
||||
APP_KEY_CODE_FN6 = HAL_KEY_CODE_FN6,
|
||||
APP_KEY_CODE_FN7 = HAL_KEY_CODE_FN7,
|
||||
APP_KEY_CODE_FN8 = HAL_KEY_CODE_FN8,
|
||||
APP_KEY_CODE_FN9 = HAL_KEY_CODE_FN9,
|
||||
APP_KEY_CODE_FN10 = HAL_KEY_CODE_FN10,
|
||||
APP_KEY_CODE_FN11 = HAL_KEY_CODE_FN11,
|
||||
APP_KEY_CODE_FN12 = HAL_KEY_CODE_FN12,
|
||||
APP_KEY_CODE_FN13 = HAL_KEY_CODE_FN13,
|
||||
APP_KEY_CODE_FN14 = HAL_KEY_CODE_FN14,
|
||||
APP_KEY_CODE_FN15 = HAL_KEY_CODE_FN15,
|
||||
APP_KEY_CODE_NONE = HAL_KEY_CODE_NONE,
|
||||
APP_KEY_CODE_PWR = HAL_KEY_CODE_PWR,
|
||||
APP_KEY_CODE_FN1 = HAL_KEY_CODE_FN1,
|
||||
APP_KEY_CODE_FN2 = HAL_KEY_CODE_FN2,
|
||||
APP_KEY_CODE_FN3 = HAL_KEY_CODE_FN3,
|
||||
APP_KEY_CODE_FN4 = HAL_KEY_CODE_FN4,
|
||||
APP_KEY_CODE_FN5 = HAL_KEY_CODE_FN5,
|
||||
APP_KEY_CODE_FN6 = HAL_KEY_CODE_FN6,
|
||||
APP_KEY_CODE_FN7 = HAL_KEY_CODE_FN7,
|
||||
APP_KEY_CODE_FN8 = HAL_KEY_CODE_FN8,
|
||||
APP_KEY_CODE_FN9 = HAL_KEY_CODE_FN9,
|
||||
APP_KEY_CODE_FN10 = HAL_KEY_CODE_FN10,
|
||||
APP_KEY_CODE_FN11 = HAL_KEY_CODE_FN11,
|
||||
APP_KEY_CODE_FN12 = HAL_KEY_CODE_FN12,
|
||||
APP_KEY_CODE_FN13 = HAL_KEY_CODE_FN13,
|
||||
APP_KEY_CODE_FN14 = HAL_KEY_CODE_FN14,
|
||||
APP_KEY_CODE_FN15 = HAL_KEY_CODE_FN15,
|
||||
};
|
||||
|
||||
enum APP_KEY_EVENT_T {
|
||||
APP_KEY_EVENT_NONE = HAL_KEY_EVENT_NONE,
|
||||
APP_KEY_EVENT_DOWN = HAL_KEY_EVENT_DOWN,
|
||||
APP_KEY_EVENT_FIRST_DOWN = HAL_KEY_EVENT_FIRST_DOWN,
|
||||
APP_KEY_EVENT_CONTINUED_DOWN = HAL_KEY_EVENT_CONTINUED_DOWN,
|
||||
APP_KEY_EVENT_UP = HAL_KEY_EVENT_UP,
|
||||
APP_KEY_EVENT_UP_AFTER_LONGPRESS = HAL_KEY_EVENT_UP_AFTER_LONGPRESS,
|
||||
APP_KEY_EVENT_LONGPRESS = HAL_KEY_EVENT_LONGPRESS,
|
||||
APP_KEY_EVENT_LONGLONGPRESS = HAL_KEY_EVENT_LONGLONGPRESS,
|
||||
APP_KEY_EVENT_CLICK = HAL_KEY_EVENT_CLICK,
|
||||
APP_KEY_EVENT_DOUBLECLICK = HAL_KEY_EVENT_DOUBLECLICK,
|
||||
APP_KEY_EVENT_TRIPLECLICK = HAL_KEY_EVENT_TRIPLECLICK,
|
||||
APP_KEY_EVENT_ULTRACLICK = HAL_KEY_EVENT_ULTRACLICK,
|
||||
APP_KEY_EVENT_RAMPAGECLICK = HAL_KEY_EVENT_RAMPAGECLICK,
|
||||
APP_KEY_EVENT_SIXTHCLICK = HAL_KEY_EVENT_SIXTHCLICK,
|
||||
APP_KEY_EVENT_SEVENTHCLICK = HAL_KEY_EVENT_SEVENTHCLICK,
|
||||
APP_KEY_EVENT_EIGHTHCLICK = HAL_KEY_EVENT_EIGHTHCLICK,
|
||||
APP_KEY_EVENT_NINETHCLICK = HAL_KEY_EVENT_NINETHCLICK,
|
||||
APP_KEY_EVENT_TENTHCLICK = HAL_KEY_EVENT_TENTHCLICK,
|
||||
APP_KEY_EVENT_REPEAT = HAL_KEY_EVENT_REPEAT,
|
||||
APP_KEY_EVENT_GROUPKEY_DOWN = HAL_KEY_EVENT_GROUPKEY_DOWN,
|
||||
APP_KEY_EVENT_GROUPKEY_REPEAT = HAL_KEY_EVENT_GROUPKEY_REPEAT,
|
||||
APP_KEY_EVENT_INITDOWN = HAL_KEY_EVENT_INITDOWN,
|
||||
APP_KEY_EVENT_INITUP = HAL_KEY_EVENT_INITUP,
|
||||
APP_KEY_EVENT_INITLONGPRESS = HAL_KEY_EVENT_INITLONGPRESS,
|
||||
APP_KEY_EVENT_INITLONGLONGPRESS = HAL_KEY_EVENT_INITLONGLONGPRESS,
|
||||
APP_KEY_EVENT_INITFINISHED = HAL_KEY_EVENT_INITFINISHED,
|
||||
APP_KEY_EVENT_NONE = HAL_KEY_EVENT_NONE,
|
||||
APP_KEY_EVENT_DOWN = HAL_KEY_EVENT_DOWN,
|
||||
APP_KEY_EVENT_FIRST_DOWN = HAL_KEY_EVENT_FIRST_DOWN,
|
||||
APP_KEY_EVENT_CONTINUED_DOWN = HAL_KEY_EVENT_CONTINUED_DOWN,
|
||||
APP_KEY_EVENT_UP = HAL_KEY_EVENT_UP,
|
||||
APP_KEY_EVENT_UP_AFTER_LONGPRESS = HAL_KEY_EVENT_UP_AFTER_LONGPRESS,
|
||||
APP_KEY_EVENT_LONGPRESS = HAL_KEY_EVENT_LONGPRESS,
|
||||
APP_KEY_EVENT_LONGLONGPRESS = HAL_KEY_EVENT_LONGLONGPRESS,
|
||||
APP_KEY_EVENT_CLICK = HAL_KEY_EVENT_CLICK,
|
||||
APP_KEY_EVENT_DOUBLECLICK = HAL_KEY_EVENT_DOUBLECLICK,
|
||||
APP_KEY_EVENT_TRIPLECLICK = HAL_KEY_EVENT_TRIPLECLICK,
|
||||
APP_KEY_EVENT_ULTRACLICK = HAL_KEY_EVENT_ULTRACLICK,
|
||||
APP_KEY_EVENT_RAMPAGECLICK = HAL_KEY_EVENT_RAMPAGECLICK,
|
||||
APP_KEY_EVENT_SIXTHCLICK = HAL_KEY_EVENT_SIXTHCLICK,
|
||||
APP_KEY_EVENT_SEVENTHCLICK = HAL_KEY_EVENT_SEVENTHCLICK,
|
||||
APP_KEY_EVENT_EIGHTHCLICK = HAL_KEY_EVENT_EIGHTHCLICK,
|
||||
APP_KEY_EVENT_NINETHCLICK = HAL_KEY_EVENT_NINETHCLICK,
|
||||
APP_KEY_EVENT_TENTHCLICK = HAL_KEY_EVENT_TENTHCLICK,
|
||||
APP_KEY_EVENT_REPEAT = HAL_KEY_EVENT_REPEAT,
|
||||
APP_KEY_EVENT_GROUPKEY_DOWN = HAL_KEY_EVENT_GROUPKEY_DOWN,
|
||||
APP_KEY_EVENT_GROUPKEY_REPEAT = HAL_KEY_EVENT_GROUPKEY_REPEAT,
|
||||
APP_KEY_EVENT_INITDOWN = HAL_KEY_EVENT_INITDOWN,
|
||||
APP_KEY_EVENT_INITUP = HAL_KEY_EVENT_INITUP,
|
||||
APP_KEY_EVENT_INITLONGPRESS = HAL_KEY_EVENT_INITLONGPRESS,
|
||||
APP_KEY_EVENT_INITLONGLONGPRESS = HAL_KEY_EVENT_INITLONGLONGPRESS,
|
||||
APP_KEY_EVENT_INITFINISHED = HAL_KEY_EVENT_INITFINISHED,
|
||||
|
||||
APP_KEY_EVENT_NUM = HAL_KEY_EVENT_NUM,
|
||||
APP_KEY_EVENT_NUM = HAL_KEY_EVENT_NUM,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t code;
|
||||
uint8_t event;
|
||||
}APP_KEY_STATUS;
|
||||
uint32_t code;
|
||||
uint8_t event;
|
||||
} APP_KEY_STATUS;
|
||||
|
||||
typedef void (*APP_KEY_HANDLE_CB_T)(APP_KEY_STATUS*, void *param);
|
||||
typedef void (*APP_KEY_HANDLE_CB_T)(APP_KEY_STATUS *, void *param);
|
||||
|
||||
typedef struct {
|
||||
APP_KEY_STATUS key_status;
|
||||
const char* string;
|
||||
APP_KEY_HANDLE_CB_T function;
|
||||
void *param;
|
||||
APP_KEY_STATUS key_status;
|
||||
const char *string;
|
||||
APP_KEY_HANDLE_CB_T function;
|
||||
void *param;
|
||||
} APP_KEY_HANDLE;
|
||||
|
||||
int app_key_open(int checkPwrKey);
|
||||
|
@ -106,4 +111,8 @@ void app_key_simulate_key_event(uint32_t key_code, uint8_t key_event);
|
|||
#if defined(_AUTO_TEST_)
|
||||
int simul_key_event_process(uint32_t key_code, uint8_t key_event);
|
||||
#endif
|
||||
#endif//__FMDEC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
#endif //__FMDEC_H__
|
||||
|
|
3983
apps/main/apps.cpp
3983
apps/main/apps.cpp
File diff suppressed because it is too large
Load Diff
|
@ -13,21 +13,21 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "stdio.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "hal_iomux.h"
|
||||
#include "app_key.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_iomux.h"
|
||||
#include "hal_sleep.h"
|
||||
#include "hal_trace.h"
|
||||
|
||||
#include "audioflinger.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "app_thread.h"
|
||||
#include "app_utils.h"
|
||||
#include "bt_drv_interface.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "audioflinger.h"
|
||||
#include "besbt.h"
|
||||
#include "bt_drv_interface.h"
|
||||
|
||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||
#include "anc_usb_app.h"
|
||||
|
@ -35,278 +35,299 @@
|
|||
//#include "dualadc_audio_app.h"
|
||||
#endif
|
||||
|
||||
#define APP_TESTER_CPU_WAKE_LOCK HAL_CPU_WAKE_LOCK_USER_3
|
||||
#define APP_TESTER_CPU_WAKE_LOCK HAL_CPU_WAKE_LOCK_USER_3
|
||||
|
||||
extern "C" int hal_analogif_reg_write(unsigned short reg, unsigned short val);
|
||||
extern "C" int hal_analogif_reg_write(unsigned short reg, unsigned short val);
|
||||
extern "C" void OS_NotifyEvm(void);
|
||||
extern void app_anc_usb_init(void);
|
||||
|
||||
#define REG(a) *(volatile uint32_t *)(a)
|
||||
|
||||
void bt_signaling_test(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
void bt_signaling_test(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
|
||||
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
||||
btdrv_testmode_start();
|
||||
btdrv_enable_dut();
|
||||
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
||||
btdrv_testmode_start();
|
||||
btdrv_enable_dut();
|
||||
}
|
||||
|
||||
void bt_stack_test(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
void bt_stack_test(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
|
||||
btdrv_start_bt();
|
||||
BesbtInit();
|
||||
btdrv_start_bt();
|
||||
BesbtInit();
|
||||
}
|
||||
|
||||
void bt_ble_test(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
void bt_ble_test(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
|
||||
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
||||
btdrv_testmode_start();
|
||||
hal_cpu_wake_lock(APP_TESTER_CPU_WAKE_LOCK);
|
||||
btdrv_testmode_start();
|
||||
|
||||
btdrv_hcioff();
|
||||
hal_iomux_set_uart1();
|
||||
btdrv_uart_bridge_loop();
|
||||
btdrv_hcioff();
|
||||
hal_iomux_set_uart1();
|
||||
btdrv_uart_bridge_loop();
|
||||
}
|
||||
|
||||
void bt_test_104m(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
void bt_test_104m(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
|
||||
hal_analogif_reg_write(0x35,0x0);
|
||||
hal_analogif_reg_write(0x36,0x8000);
|
||||
hal_analogif_reg_write(0x37,0x1000);
|
||||
hal_analogif_reg_write(0x31,0xfd31);
|
||||
REG(0xd0350248) = 0X80C00000;
|
||||
hal_analogif_reg_write(0xC,0x3790);
|
||||
hal_analogif_reg_write(0x35, 0x0);
|
||||
hal_analogif_reg_write(0x36, 0x8000);
|
||||
hal_analogif_reg_write(0x37, 0x1000);
|
||||
hal_analogif_reg_write(0x31, 0xfd31);
|
||||
REG(0xd0350248) = 0X80C00000;
|
||||
hal_analogif_reg_write(0xC, 0x3790);
|
||||
}
|
||||
|
||||
void bt_change_to_iic(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
void bt_change_to_iic(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
|
||||
hal_iomux_set_analog_i2c();
|
||||
hal_iomux_set_analog_i2c();
|
||||
}
|
||||
|
||||
void bt_change_to_uart0(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
void bt_change_to_uart0(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
|
||||
hal_iomux_set_uart0();
|
||||
hal_iomux_set_uart0();
|
||||
}
|
||||
|
||||
void app_switch_i2c_uart(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
static uint32_t flag = 1;
|
||||
void app_switch_i2c_uart(APP_KEY_STATUS *status, void *param) {
|
||||
static uint32_t flag = 1;
|
||||
|
||||
TRACE(2,"[%s] flag = %d",__func__, flag);
|
||||
if(flag)
|
||||
{
|
||||
bt_change_to_iic(NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
bt_change_to_uart0(NULL, NULL);
|
||||
}
|
||||
flag = !flag;
|
||||
TRACE(2, "[%s] flag = %d", __func__, flag);
|
||||
if (flag) {
|
||||
bt_change_to_iic(NULL, NULL);
|
||||
} else {
|
||||
bt_change_to_uart0(NULL, NULL);
|
||||
}
|
||||
flag = !flag;
|
||||
}
|
||||
|
||||
void test_power_off(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(0,"app_power_off\n");
|
||||
void test_power_off(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(0, "app_power_off\n");
|
||||
}
|
||||
|
||||
extern APP_KEY_STATUS bt_key;
|
||||
|
||||
void test_bt_key(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
TRACE(3,"%s %d,%d",__func__, status->code, status->event);
|
||||
if(bt_key.code == 0xff)
|
||||
{
|
||||
bt_key.code = status->code;
|
||||
bt_key.event = status->event;
|
||||
OS_NotifyEvm();
|
||||
}
|
||||
void test_bt_key(APP_KEY_STATUS *status, void *param) {
|
||||
TRACE(3, "%s %d,%d", __func__, status->code, status->event);
|
||||
if (bt_key.code == 0xff) {
|
||||
bt_key.code = status->code;
|
||||
bt_key.event = status->event;
|
||||
OS_NotifyEvm();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __APP_TEST_SDMMC__
|
||||
#include "app_sdmmc.h"
|
||||
|
||||
#define SD_BUF_SIZE (10)
|
||||
uint8_t sd_buf[SD_BUF_SIZE]={0,1,2,3,4,5,6,7,8,9};
|
||||
uint8_t sd_buf[SD_BUF_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
void test_sd_card()
|
||||
{
|
||||
sd_open();
|
||||
void test_sd_card() {
|
||||
sd_open();
|
||||
|
||||
dump_data2sd(APP_SDMMC_DUMP_OPEN, NULL , 0);
|
||||
dump_data2sd(APP_SDMMC_DUMP_WRITE,sd_buf, SD_BUF_SIZE);
|
||||
dump_data2sd(APP_SDMMC_DUMP_CLOSE, NULL, 0);
|
||||
dump_data2sd(APP_SDMMC_DUMP_OPEN, NULL, 0);
|
||||
dump_data2sd(APP_SDMMC_DUMP_WRITE, sd_buf, SD_BUF_SIZE);
|
||||
dump_data2sd(APP_SDMMC_DUMP_CLOSE, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef APP_TEST_AUDIO
|
||||
extern void adc_looptester(bool on, enum AUD_IO_PATH_T input_path, enum AUD_SAMPRATE_T sample_rate);
|
||||
void test_codec_loop(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
audio_buffer_init();
|
||||
adc_looptester(true, AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_8000);
|
||||
extern void adc_looptester(bool on, enum AUD_IO_PATH_T input_path,
|
||||
enum AUD_SAMPRATE_T sample_rate);
|
||||
void test_codec_loop(APP_KEY_STATUS *status, void *param) {
|
||||
audio_buffer_init();
|
||||
adc_looptester(true, AUD_INPUT_PATH_MAINMIC, AUD_SAMPRATE_8000);
|
||||
}
|
||||
|
||||
#ifdef ANC_APP
|
||||
void test_anc(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
anc_usb_app((bool)param);
|
||||
}
|
||||
void test_anc(APP_KEY_STATUS *status, void *param) { anc_usb_app((bool)param); }
|
||||
|
||||
void test_usb_audio(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
usb_audio_app((bool)param);
|
||||
//dualadc_audio_app((bool)param);
|
||||
void test_usb_audio(APP_KEY_STATUS *status, void *param) {
|
||||
usb_audio_app((bool)param);
|
||||
// dualadc_audio_app((bool)param);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void bt_change_to_jlink(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
hal_iomux_set_jtag();
|
||||
|
||||
hal_cmu_jtag_clock_enable();
|
||||
void bt_change_to_jlink(APP_KEY_STATUS *status, void *param) {
|
||||
hal_iomux_set_jtag();
|
||||
|
||||
hal_cmu_jtag_clock_enable();
|
||||
}
|
||||
|
||||
void bt_enable_tports(void)
|
||||
{
|
||||
hal_iomux_set_bt_tport();
|
||||
bt_drv_bt_tport_type_config();
|
||||
void bt_enable_tports(void) {
|
||||
hal_iomux_set_bt_tport();
|
||||
bt_drv_bt_tport_type_config();
|
||||
}
|
||||
|
||||
#ifdef APP_TEST_AUDIO
|
||||
extern void da_tester(uint8_t on);
|
||||
void bt_test_dsp_process(APP_KEY_STATUS *status, void *param)
|
||||
{
|
||||
da_tester(1);
|
||||
}
|
||||
void bt_test_dsp_process(APP_KEY_STATUS *status, void *param) { da_tester(1); }
|
||||
#endif
|
||||
#define MENU_TITLE_MAX_SIZE (50)
|
||||
APP_KEY_HANDLE app_testcase[] = {
|
||||
APP_KEY_HANDLE app_testcase[] = {
|
||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||
{{APP_KEY_CODE_FN2,APP_KEY_EVENT_UP},"USB AUDIO TEST OFF",test_usb_audio, (void *)0},
|
||||
{{APP_KEY_CODE_FN5,APP_KEY_EVENT_UP},"USB AUDIO TEST ON",test_usb_audio, (void *)1},
|
||||
{{APP_KEY_CODE_FN3,APP_KEY_EVENT_UP},"ANC TEST OFF",test_anc, (void *)0},
|
||||
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_UP},"ANC TEST ON",test_anc, (void *)1},
|
||||
{{APP_KEY_CODE_FN2, APP_KEY_EVENT_UP},
|
||||
"USB AUDIO TEST OFF",
|
||||
test_usb_audio,
|
||||
(void *)0},
|
||||
{{APP_KEY_CODE_FN5, APP_KEY_EVENT_UP},
|
||||
"USB AUDIO TEST ON",
|
||||
test_usb_audio,
|
||||
(void *)1},
|
||||
{{APP_KEY_CODE_FN3, APP_KEY_EVENT_UP}, "ANC TEST OFF", test_anc, (void *)0},
|
||||
{{APP_KEY_CODE_FN6, APP_KEY_EVENT_UP}, "ANC TEST ON", test_anc, (void *)1},
|
||||
#else
|
||||
#ifdef APP_TEST_AUDIO
|
||||
{{APP_KEY_CODE_FN1,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: test_codec_loop",test_codec_loop, NULL},
|
||||
{{APP_KEY_CODE_FN1, APP_KEY_EVENT_LONGPRESS},
|
||||
"LONGPRESS: test_codec_loop",
|
||||
test_codec_loop,
|
||||
NULL},
|
||||
#endif
|
||||
{{APP_KEY_CODE_FN1,APP_KEY_EVENT_UP},"bt_signaling_test",bt_signaling_test, NULL},
|
||||
{{APP_KEY_CODE_FN2,APP_KEY_EVENT_UP},"bt gogogogo" ,bt_stack_test, NULL},
|
||||
{{APP_KEY_CODE_FN3,APP_KEY_EVENT_UP},"bt change to 104m",bt_test_104m, NULL},
|
||||
{{APP_KEY_CODE_FN4,APP_KEY_EVENT_UP},"ble test mode" ,bt_ble_test, NULL},
|
||||
{{APP_KEY_CODE_FN1, APP_KEY_EVENT_UP},
|
||||
"bt_signaling_test",
|
||||
bt_signaling_test,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_FN2, APP_KEY_EVENT_UP}, "bt gogogogo", bt_stack_test, NULL},
|
||||
{{APP_KEY_CODE_FN3, APP_KEY_EVENT_UP},
|
||||
"bt change to 104m",
|
||||
bt_test_104m,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_FN4, APP_KEY_EVENT_UP}, "ble test mode", bt_ble_test, NULL},
|
||||
#ifdef APP_TEST_AUDIO
|
||||
{{APP_KEY_CODE_FN5,APP_KEY_EVENT_UP},"dsp eq test" ,bt_test_dsp_process, NULL},
|
||||
{{APP_KEY_CODE_FN5, APP_KEY_EVENT_UP},
|
||||
"dsp eq test",
|
||||
bt_test_dsp_process,
|
||||
NULL},
|
||||
#endif
|
||||
{{APP_KEY_CODE_FN5,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: bt volume up key" ,test_bt_key, NULL},
|
||||
{{APP_KEY_CODE_FN5, APP_KEY_EVENT_LONGPRESS},
|
||||
"LONGPRESS: bt volume up key",
|
||||
test_bt_key,
|
||||
NULL},
|
||||
|
||||
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_UP},"bt volume down key" ,test_bt_key, NULL},
|
||||
{{APP_KEY_CODE_FN6,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: bt volume down key" ,test_bt_key, NULL},
|
||||
{{APP_KEY_CODE_FN6, APP_KEY_EVENT_UP},
|
||||
"bt volume down key",
|
||||
test_bt_key,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_FN6, APP_KEY_EVENT_LONGPRESS},
|
||||
"LONGPRESS: bt volume down key",
|
||||
test_bt_key,
|
||||
NULL},
|
||||
|
||||
{{APP_KEY_CODE_FN7,APP_KEY_EVENT_CLICK},"bt function key" ,test_bt_key, NULL},
|
||||
{{APP_KEY_CODE_FN7,APP_KEY_EVENT_DOUBLECLICK},"DOUBLECLICK: bt function key" ,test_bt_key, NULL},
|
||||
{{APP_KEY_CODE_FN7,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: bt function key" ,test_bt_key, NULL},
|
||||
{{APP_KEY_CODE_FN7, APP_KEY_EVENT_CLICK},
|
||||
"bt function key",
|
||||
test_bt_key,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_FN7, APP_KEY_EVENT_DOUBLECLICK},
|
||||
"DOUBLECLICK: bt function key",
|
||||
test_bt_key,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_FN7, APP_KEY_EVENT_LONGPRESS},
|
||||
"LONGPRESS: bt function key",
|
||||
test_bt_key,
|
||||
NULL},
|
||||
|
||||
{{APP_KEY_CODE_FN8,APP_KEY_EVENT_UP},"open jlink" ,bt_change_to_jlink, NULL},
|
||||
{{APP_KEY_CODE_FN9,APP_KEY_EVENT_UP},"iic_map2_P3_0" ,bt_change_to_iic, NULL},
|
||||
{{APP_KEY_CODE_PWR,APP_KEY_EVENT_LONGPRESS},"LONGPRESS: power off" ,test_power_off, NULL},
|
||||
{{APP_KEY_CODE_FN8, APP_KEY_EVENT_UP},
|
||||
"open jlink",
|
||||
bt_change_to_jlink,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_FN9, APP_KEY_EVENT_UP},
|
||||
"iic_map2_P3_0",
|
||||
bt_change_to_iic,
|
||||
NULL},
|
||||
{{APP_KEY_CODE_PWR, APP_KEY_EVENT_LONGPRESS},
|
||||
"LONGPRESS: power off",
|
||||
test_power_off,
|
||||
NULL},
|
||||
#endif // !(APP_TEST_AUDIO && ANC_APP)
|
||||
{{0xff, APP_KEY_EVENT_NONE}, NULL, (uint32_t)NULL, 0},
|
||||
};
|
||||
|
||||
int app_testcase_disp_menu(APP_KEY_HANDLE* testcase, bool printall)
|
||||
{
|
||||
char buf[MENU_TITLE_MAX_SIZE+1];
|
||||
if (strlen(testcase->string)>(MENU_TITLE_MAX_SIZE-15)){
|
||||
TRACE(0,"string too long, please check again\n");
|
||||
return -1;
|
||||
}
|
||||
int app_testcase_disp_menu(APP_KEY_HANDLE *testcase, bool printall) {
|
||||
char buf[MENU_TITLE_MAX_SIZE + 1];
|
||||
if (strlen(testcase->string) > (MENU_TITLE_MAX_SIZE - 15)) {
|
||||
TRACE(0, "string too long, please check again\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (printall){
|
||||
memset(buf, '-', sizeof(buf)-3);
|
||||
buf[0] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE-3] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE-2] = '\r';
|
||||
buf[MENU_TITLE_MAX_SIZE-1] = '\n';
|
||||
buf[MENU_TITLE_MAX_SIZE] = '\0';
|
||||
TRACE(1,"%s", buf);
|
||||
osDelay(1);
|
||||
}
|
||||
if (printall) {
|
||||
memset(buf, '-', sizeof(buf) - 3);
|
||||
buf[0] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE - 3] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE - 2] = '\r';
|
||||
buf[MENU_TITLE_MAX_SIZE - 1] = '\n';
|
||||
buf[MENU_TITLE_MAX_SIZE] = '\0';
|
||||
TRACE(1, "%s", buf);
|
||||
osDelay(1);
|
||||
}
|
||||
|
||||
do{
|
||||
snprintf(buf, sizeof(buf), "| (0x%X)%s", testcase->key_status.code, testcase->string);
|
||||
memset(buf+strlen(buf), ' ', sizeof(buf)-strlen(buf)-3);
|
||||
buf[MENU_TITLE_MAX_SIZE-3] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE-2] = '\r';
|
||||
buf[MENU_TITLE_MAX_SIZE-1] = '\n';
|
||||
buf[MENU_TITLE_MAX_SIZE] = '\0';
|
||||
TRACE(1,"%s", buf);
|
||||
testcase++;
|
||||
}while(testcase->key_status.code != 0xff && printall);
|
||||
do {
|
||||
snprintf(buf, sizeof(buf), "| (0x%X)%s", testcase->key_status.code,
|
||||
testcase->string);
|
||||
memset(buf + strlen(buf), ' ', sizeof(buf) - strlen(buf) - 3);
|
||||
buf[MENU_TITLE_MAX_SIZE - 3] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE - 2] = '\r';
|
||||
buf[MENU_TITLE_MAX_SIZE - 1] = '\n';
|
||||
buf[MENU_TITLE_MAX_SIZE] = '\0';
|
||||
TRACE(1, "%s", buf);
|
||||
testcase++;
|
||||
} while (testcase->key_status.code != 0xff && printall);
|
||||
|
||||
if (printall){
|
||||
memset(buf, '-', sizeof(buf)-3);
|
||||
buf[0] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE-3] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE-2] = '\r';
|
||||
buf[MENU_TITLE_MAX_SIZE-1] = '\n';
|
||||
buf[MENU_TITLE_MAX_SIZE] = '\0';
|
||||
TRACE(1,"%s", buf);
|
||||
osDelay(1);
|
||||
}
|
||||
if (printall) {
|
||||
memset(buf, '-', sizeof(buf) - 3);
|
||||
buf[0] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE - 3] = '|';
|
||||
buf[MENU_TITLE_MAX_SIZE - 2] = '\r';
|
||||
buf[MENU_TITLE_MAX_SIZE - 1] = '\n';
|
||||
buf[MENU_TITLE_MAX_SIZE] = '\0';
|
||||
TRACE(1, "%s", buf);
|
||||
osDelay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_testcase_key_response(APP_MESSAGE_BODY *msg_body)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
APP_KEY_STATUS key_status;
|
||||
int app_testcase_key_response(APP_MESSAGE_BODY *msg_body) {
|
||||
uint8_t i = 0;
|
||||
APP_KEY_STATUS key_status;
|
||||
|
||||
APP_KEY_GET_CODE(msg_body->message_id, key_status.code);
|
||||
APP_KEY_GET_EVENT(msg_body->message_id, key_status.event);
|
||||
APP_KEY_GET_CODE(msg_body->message_id, key_status.code);
|
||||
APP_KEY_GET_EVENT(msg_body->message_id, key_status.event);
|
||||
|
||||
if ((key_status.code)>(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)))
|
||||
return -1;
|
||||
if ((key_status.code) > (sizeof(app_testcase) / sizeof(APP_KEY_HANDLE)))
|
||||
return -1;
|
||||
|
||||
for (i=0; i<(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)); i++){
|
||||
if (app_testcase[i].key_status.code == key_status.code && (app_testcase[i].key_status.event == key_status.event))
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < (sizeof(app_testcase) / sizeof(APP_KEY_HANDLE)); i++) {
|
||||
if (app_testcase[i].key_status.code == key_status.code &&
|
||||
(app_testcase[i].key_status.event == key_status.event))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i>=(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)))
|
||||
return -1;
|
||||
if (i >= (sizeof(app_testcase) / sizeof(APP_KEY_HANDLE)))
|
||||
return -1;
|
||||
|
||||
if (app_testcase[i].function != (uint32_t)NULL){
|
||||
if (app_testcase[i].string != (uint32_t)NULL)
|
||||
app_testcase_disp_menu(&app_testcase[i],0);
|
||||
((APP_KEY_HANDLE_CB_T)app_testcase[i].function)(&key_status,app_testcase[i].param);
|
||||
}
|
||||
if (app_testcase[i].function != (uint32_t)NULL) {
|
||||
if (app_testcase[i].string != (uint32_t)NULL)
|
||||
app_testcase_disp_menu(&app_testcase[i], 0);
|
||||
((APP_KEY_HANDLE_CB_T)app_testcase[i].function)(&key_status,
|
||||
app_testcase[i].param);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_test_init(void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
TRACE(1,"%s",__func__);
|
||||
for (i=0; i<(sizeof(app_testcase)/sizeof(APP_KEY_HANDLE)); i++){
|
||||
app_key_handle_registration(&app_testcase[i]);
|
||||
}
|
||||
app_testcase_disp_menu(app_testcase, 1);
|
||||
void app_test_init(void) {
|
||||
uint8_t i = 0;
|
||||
TRACE(1, "%s", __func__);
|
||||
for (i = 0; i < (sizeof(app_testcase) / sizeof(APP_KEY_HANDLE)); i++) {
|
||||
app_key_handle_registration(&app_testcase[i]);
|
||||
}
|
||||
app_testcase_disp_menu(app_testcase, 1);
|
||||
|
||||
#if defined(APP_TEST_AUDIO) && defined(ANC_APP)
|
||||
app_anc_usb_init();
|
||||
app_anc_usb_init();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -14,241 +14,212 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
//#include "mbed.h"
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cmsis_os.h"
|
||||
#include "tgt_hardware.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_timer.h"
|
||||
#include "audioflinger.h"
|
||||
#include "lockcqueue.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_cmu.h"
|
||||
#include "hal_chipid.h"
|
||||
#include "analog.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_bt_stream.h"
|
||||
#include "app_overlay.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_utils.h"
|
||||
#include "apps.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_chipid.h"
|
||||
#include "hal_cmu.h"
|
||||
#include "hal_codec.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_uart.h"
|
||||
#include "lockcqueue.h"
|
||||
#include "nvrecord.h"
|
||||
#include "nvrecord_env.h"
|
||||
#include "hal_codec.h"
|
||||
#include "apps.h"
|
||||
#include "tgt_hardware.h"
|
||||
|
||||
#include "app_ring_merge.h"
|
||||
|
||||
#include "bt_drv.h"
|
||||
#include "bt_xtal_sync.h"
|
||||
#include "besbt.h"
|
||||
#include "app_bt_func.h"
|
||||
#include "app_mic.h"
|
||||
#include "besbt.h"
|
||||
#include "bt_drv.h"
|
||||
#include "bt_xtal_sync.h"
|
||||
|
||||
|
||||
#include "app_thread.h"
|
||||
#include "cqueue.h"
|
||||
#include "btapp.h"
|
||||
#include "app_bt_media_manager.h"
|
||||
#include "string.h"
|
||||
#include "hal_location.h"
|
||||
#include "hal_codec.h"
|
||||
#include "hal_sleep.h"
|
||||
#include "app_hfp.h"
|
||||
#include "app_thread.h"
|
||||
#include "btapp.h"
|
||||
#include "cqueue.h"
|
||||
#include "hal_codec.h"
|
||||
#include "hal_location.h"
|
||||
#include "hal_sleep.h"
|
||||
#include "string.h"
|
||||
|
||||
extern bool app_hfp_siri_is_active(void);
|
||||
extern int a2dp_volume_2_level_convert(uint8_t vol);
|
||||
extern bool mic_is_already_on;
|
||||
|
||||
typedef enum {
|
||||
MIC_EVENT_START,
|
||||
MIC_EVENT_STOP,
|
||||
MIC_EVENT_CHECK,
|
||||
}MIC_EVENT_TYPE;
|
||||
MIC_EVENT_START,
|
||||
MIC_EVENT_STOP,
|
||||
MIC_EVENT_CHECK,
|
||||
} MIC_EVENT_TYPE;
|
||||
|
||||
static MIC_APP_TYPE current_mictype = MIC_APP_NONE;
|
||||
static struct AF_STREAM_CONFIG_T mic_config[MIC_APP_MAX];
|
||||
osMutexId app_mic_mutex_id = NULL;
|
||||
osMutexDef(app_mic_mutex);
|
||||
|
||||
|
||||
// flag of is first mic date, if true ,will delete to avoid POP voice
|
||||
bool first_mic_in = false;
|
||||
|
||||
static int internal_mic_start(MIC_APP_TYPE new_mictype)
|
||||
{
|
||||
TRACE(1,"MIC_EVENT_START,current_mictype=%d",current_mictype);
|
||||
assert(new_mictype != MIC_APP_NONE);
|
||||
if (current_mictype != MIC_APP_NONE) {
|
||||
TRACE(0,"MIC START ERROR################");
|
||||
return false;
|
||||
}
|
||||
if (new_mictype == MIC_APP_SOC_CALL)
|
||||
{
|
||||
if (btapp_hfp_get_call_state() || app_hfp_siri_is_active())
|
||||
{
|
||||
TRACE(2,"[%s] tws_mic_start_telephone_call: %d", __func__, mic_config[new_mictype].sample_rate);
|
||||
if (mic_config[new_mictype].data_ptr != NULL)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE(1,"[%s] Warning sco play not started",__func__);
|
||||
}
|
||||
current_mictype = MIC_APP_SOC_CALL;
|
||||
}
|
||||
}
|
||||
else if (new_mictype == MIC_APP_SPEECH_RECO)
|
||||
{
|
||||
}
|
||||
else if (new_mictype == MIC_APP_CSPOTTER)
|
||||
{
|
||||
first_mic_in = true;
|
||||
current_mictype = MIC_APP_CSPOTTER;
|
||||
}
|
||||
else if (new_mictype == MIC_APP_MICRECORD)
|
||||
{
|
||||
current_mictype = MIC_APP_MICRECORD;
|
||||
}
|
||||
else if (new_mictype == MIC_APP_OTHER)
|
||||
{
|
||||
TRACE(0,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
}
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &mic_config[new_mictype]);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
static int internal_mic_start(MIC_APP_TYPE new_mictype) {
|
||||
TRACE(1, "MIC_EVENT_START,current_mictype=%d", current_mictype);
|
||||
assert(new_mictype != MIC_APP_NONE);
|
||||
if (current_mictype != MIC_APP_NONE) {
|
||||
TRACE(0, "MIC START ERROR################");
|
||||
return false;
|
||||
}
|
||||
|
||||
static int internal_mic_stop(MIC_APP_TYPE new_mictype)
|
||||
{
|
||||
TRACE(1,"MIC_EVENT_STOP,current_mictype=%d",current_mictype);
|
||||
//assert(currentMicStauts == currentStatus);
|
||||
if (new_mictype != current_mictype) {
|
||||
TRACE(0,"MIC STOP ERROR ################");
|
||||
return false;
|
||||
}
|
||||
if (new_mictype == MIC_APP_SOC_CALL) {
|
||||
if (btapp_hfp_get_call_state() || app_hfp_siri_is_active()) {
|
||||
TRACE(2, "[%s] tws_mic_start_telephone_call: %d", __func__,
|
||||
mic_config[new_mictype].sample_rate);
|
||||
if (mic_config[new_mictype].data_ptr != NULL) {
|
||||
} else {
|
||||
TRACE(1, "[%s] Warning sco play not started", __func__);
|
||||
}
|
||||
current_mictype = MIC_APP_SOC_CALL;
|
||||
}
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
first_mic_in = false;
|
||||
current_mictype = MIC_APP_NONE;
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_3, APP_SYSFREQ_32K);
|
||||
return true;
|
||||
} else if (new_mictype == MIC_APP_SPEECH_RECO) {
|
||||
} else if (new_mictype == MIC_APP_CSPOTTER) {
|
||||
first_mic_in = true;
|
||||
current_mictype = MIC_APP_CSPOTTER;
|
||||
} else if (new_mictype == MIC_APP_MICRECORD) {
|
||||
current_mictype = MIC_APP_MICRECORD;
|
||||
} else if (new_mictype == MIC_APP_OTHER) {
|
||||
TRACE(0, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
}
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &mic_config[new_mictype]);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
return false;
|
||||
}
|
||||
|
||||
static int app_mic_process(APP_MESSAGE_BODY *msg_body)
|
||||
{
|
||||
MIC_EVENT_TYPE mic_event = (MIC_EVENT_TYPE)msg_body->message_id;
|
||||
MIC_APP_TYPE new_mictype = (MIC_APP_TYPE)msg_body->message_ptr;
|
||||
int ret = -1;
|
||||
TRACE(4,"%s mic_event:%d new_mictype:%d current_mictype:%d",__func__,mic_event, new_mictype, current_mictype);
|
||||
static int internal_mic_stop(MIC_APP_TYPE new_mictype) {
|
||||
TRACE(1, "MIC_EVENT_STOP,current_mictype=%d", current_mictype);
|
||||
// assert(currentMicStauts == currentStatus);
|
||||
if (new_mictype != current_mictype) {
|
||||
TRACE(0, "MIC STOP ERROR ################");
|
||||
return false;
|
||||
}
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
first_mic_in = false;
|
||||
current_mictype = MIC_APP_NONE;
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_3, APP_SYSFREQ_32K);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int app_mic_process(APP_MESSAGE_BODY *msg_body) {
|
||||
MIC_EVENT_TYPE mic_event = (MIC_EVENT_TYPE)msg_body->message_id;
|
||||
MIC_APP_TYPE new_mictype = (MIC_APP_TYPE)msg_body->message_ptr;
|
||||
int ret = -1;
|
||||
TRACE(4, "%s mic_event:%d new_mictype:%d current_mictype:%d", __func__,
|
||||
mic_event, new_mictype, current_mictype);
|
||||
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
if (mic_event == MIC_EVENT_START)
|
||||
ret = internal_mic_start(new_mictype);
|
||||
else if (mic_event == MIC_EVENT_STOP)
|
||||
ret = internal_mic_stop(new_mictype);
|
||||
else if (mic_event == MIC_EVENT_CHECK) {
|
||||
TRACE(1, "MIC_EVENT_CHECK,current_mictype=%d", current_mictype);
|
||||
if (current_mictype != new_mictype) {
|
||||
if (current_mictype != MIC_APP_NONE)
|
||||
internal_mic_stop(current_mictype);
|
||||
if (new_mictype != MIC_APP_CSPOTTER)
|
||||
internal_mic_start(new_mictype);
|
||||
ret = 0;
|
||||
}
|
||||
} else
|
||||
assert(0);
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void app_mic_init() {
|
||||
app_mic_mutex_id = osMutexCreate((osMutex(app_mic_mutex)));
|
||||
app_set_threadhandle(APP_MODUAL_MIC, app_mic_process);
|
||||
}
|
||||
|
||||
int app_mic_register(MIC_APP_TYPE mic_type,
|
||||
struct AF_STREAM_CONFIG_T *newStream) {
|
||||
TRACE(2, "app_mic_registration mic_type:%d,newStream=%p\n", mic_type,
|
||||
newStream);
|
||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX) {
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
if (mic_event == MIC_EVENT_START)
|
||||
ret = internal_mic_start(new_mictype);
|
||||
else if (mic_event == MIC_EVENT_STOP)
|
||||
ret = internal_mic_stop(new_mictype);
|
||||
else if (mic_event == MIC_EVENT_CHECK)
|
||||
{
|
||||
TRACE(1,"MIC_EVENT_CHECK,current_mictype=%d",current_mictype);
|
||||
if (current_mictype != new_mictype)
|
||||
{
|
||||
if (current_mictype != MIC_APP_NONE)
|
||||
internal_mic_stop(current_mictype);
|
||||
if (new_mictype != MIC_APP_CSPOTTER)
|
||||
internal_mic_start(new_mictype);
|
||||
ret = 0;
|
||||
}
|
||||
if (memcmp(&mic_config[mic_type], newStream,
|
||||
sizeof(struct AF_STREAM_CONFIG_T)) != 0) {
|
||||
TRACE(0, "app_mic_registration Warning mic stream config changed!!!");
|
||||
}
|
||||
else
|
||||
assert(0);
|
||||
memcpy(&mic_config[mic_type], newStream, sizeof(struct AF_STREAM_CONFIG_T));
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void app_mic_init()
|
||||
{
|
||||
app_mic_mutex_id = osMutexCreate((osMutex(app_mic_mutex)));
|
||||
app_set_threadhandle(APP_MODUAL_MIC, app_mic_process);
|
||||
}
|
||||
|
||||
int app_mic_register(MIC_APP_TYPE mic_type, struct AF_STREAM_CONFIG_T *newStream)
|
||||
{
|
||||
TRACE(2,"app_mic_registration mic_type:%d,newStream=%p\n",mic_type,newStream);
|
||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX)
|
||||
{
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
if (memcmp(&mic_config[mic_type],newStream,sizeof(struct AF_STREAM_CONFIG_T)) != 0)
|
||||
{
|
||||
TRACE(0,"app_mic_registration Warning mic stream config changed!!!");
|
||||
}
|
||||
memcpy(&mic_config[mic_type],newStream,sizeof(struct AF_STREAM_CONFIG_T));
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int app_mic_deregister(MIC_APP_TYPE mic_type)
|
||||
{
|
||||
TRACE(1,"app_mic_deregister mic_type:%d\n",mic_type);
|
||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX)
|
||||
{
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
memset(&mic_config[mic_type],0,sizeof(struct AF_STREAM_CONFIG_T));
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool app_mic_is_registed(MIC_APP_TYPE mic_type)
|
||||
{
|
||||
TRACE(1,"app_mic_is_registed mic_type:%d\n",mic_type);
|
||||
bool ret = false;
|
||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX)
|
||||
{
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
ret = mic_config[mic_type].data_ptr != NULL;
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool app_mic_start(MIC_APP_TYPE mic_type)
|
||||
{
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_MIC;
|
||||
msg.msg_body.message_id = MIC_EVENT_START;
|
||||
msg.msg_body.message_ptr = mic_type;
|
||||
app_mailbox_put(&msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool app_mic_stop(MIC_APP_TYPE mic_type)
|
||||
{
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_MIC;
|
||||
msg.msg_body.message_id = MIC_EVENT_STOP;
|
||||
msg.msg_body.message_ptr = mic_type;
|
||||
app_mailbox_put(&msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
void app_mic_check(MIC_APP_TYPE mic_type)
|
||||
{
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_MIC;
|
||||
msg.msg_body.message_id = MIC_EVENT_CHECK;
|
||||
msg.msg_body.message_ptr = mic_type;
|
||||
app_mailbox_put(&msg);
|
||||
}
|
||||
|
||||
MIC_APP_TYPE app_mic_status(void)
|
||||
{
|
||||
MIC_APP_TYPE ret;
|
||||
int app_mic_deregister(MIC_APP_TYPE mic_type) {
|
||||
TRACE(1, "app_mic_deregister mic_type:%d\n", mic_type);
|
||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX) {
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
ret= current_mictype;
|
||||
memset(&mic_config[mic_type], 0, sizeof(struct AF_STREAM_CONFIG_T));
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool app_mic_is_registed(MIC_APP_TYPE mic_type) {
|
||||
TRACE(1, "app_mic_is_registed mic_type:%d\n", mic_type);
|
||||
bool ret = false;
|
||||
if (mic_type > MIC_APP_NONE && mic_type < MIC_APP_MAX) {
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
ret = mic_config[mic_type].data_ptr != NULL;
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool app_mic_start(MIC_APP_TYPE mic_type) {
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_MIC;
|
||||
msg.msg_body.message_id = MIC_EVENT_START;
|
||||
msg.msg_body.message_ptr = mic_type;
|
||||
app_mailbox_put(&msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool app_mic_stop(MIC_APP_TYPE mic_type) {
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_MIC;
|
||||
msg.msg_body.message_id = MIC_EVENT_STOP;
|
||||
msg.msg_body.message_ptr = mic_type;
|
||||
app_mailbox_put(&msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
void app_mic_check(MIC_APP_TYPE mic_type) {
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
msg.mod_id = APP_MODUAL_MIC;
|
||||
msg.msg_body.message_id = MIC_EVENT_CHECK;
|
||||
msg.msg_body.message_ptr = mic_type;
|
||||
app_mailbox_put(&msg);
|
||||
}
|
||||
|
||||
MIC_APP_TYPE app_mic_status(void) {
|
||||
MIC_APP_TYPE ret;
|
||||
osMutexWait(app_mic_mutex_id, osWaitForever);
|
||||
ret = current_mictype;
|
||||
osMutexRelease(app_mic_mutex_id);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -13,18 +13,18 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_bt_stream.h"
|
||||
#include "app_media_player.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "resources.h"
|
||||
#include "app_bt_stream.h"
|
||||
#include "app_media_player.h"
|
||||
//#include "app_factory.h"
|
||||
#include "string.h"
|
||||
|
||||
// for audio
|
||||
#include "audioflinger.h"
|
||||
#include "app_audio.h"
|
||||
#include "app_utils.h"
|
||||
#include "audioflinger.h"
|
||||
#include "hal_timer.h"
|
||||
|
||||
#include "app_mic_alg.h"
|
||||
|
@ -42,26 +42,22 @@
|
|||
|
||||
#include "apps.h"
|
||||
|
||||
|
||||
#ifdef WEBRTC_AGC
|
||||
#include "agc_main.h"
|
||||
#endif
|
||||
|
||||
#ifdef WL_NSX
|
||||
#define WEBRTC_NSX_BUFF_SIZE (14000)
|
||||
#define WEBRTC_NSX_BUFF_SIZE (14000)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WL_VAD
|
||||
#include "vad_user.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef WL_DEBUG_MODE
|
||||
#include "nvrecord_env.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef REMOTE_UART
|
||||
#include "app_remoter_uart.h"
|
||||
#endif
|
||||
|
@ -75,77 +71,69 @@
|
|||
#include "app_i2c_sensor.h"
|
||||
#endif
|
||||
|
||||
static inline float clampf(float v, float min, float max){
|
||||
return v < min ? min : (v > max ? max : v);
|
||||
static inline float clampf(float v, float min, float max) {
|
||||
return v < min ? min : (v > max ? max : v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef WL_NSX_5MS
|
||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (160*2)
|
||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (160 * 2)
|
||||
#else
|
||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (6*320*16)
|
||||
#define BT_AUDIO_FACTORMODE_BUFF_SIZE (6 * 320 * 16)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define NSX_FRAME_SIZE 160
|
||||
|
||||
|
||||
static enum APP_AUDIO_CACHE_T a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
|
||||
|
||||
#if defined(WL_AEC)
|
||||
static short POSSIBLY_UNUSED aec_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED far_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED aec_out[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
static short POSSIBLY_UNUSED far_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
#endif
|
||||
|
||||
static short POSSIBLY_UNUSED out_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
static short POSSIBLY_UNUSED tmp_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
|
||||
static short POSSIBLY_UNUSED out_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED tmp_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
|
||||
//static short revert_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
//static short audio_uart_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
|
||||
// static short revert_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
// static short audio_uart_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||
|
||||
static short POSSIBLY_UNUSED one_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED two_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED one_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
static short POSSIBLY_UNUSED two_buff[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
|
||||
static short POSSIBLY_UNUSED left_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED right_out[BT_AUDIO_FACTORMODE_BUFF_SIZE>>2];
|
||||
static short POSSIBLY_UNUSED left_out[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
static short POSSIBLY_UNUSED right_out[BT_AUDIO_FACTORMODE_BUFF_SIZE >> 2];
|
||||
|
||||
static void POSSIBLY_UNUSED aaudio_div_stero_to_rmono(int16_t *dst_buf, int16_t *src_buf, uint32_t src_len)
|
||||
{
|
||||
// Copy from tail so that it works even if dst_buf == src_buf
|
||||
for (uint32_t i = 0; i < src_len>>1; i++)
|
||||
{
|
||||
dst_buf[i] = src_buf[i*2 + 1];
|
||||
}
|
||||
static void POSSIBLY_UNUSED aaudio_div_stero_to_rmono(int16_t *dst_buf,
|
||||
int16_t *src_buf,
|
||||
uint32_t src_len) {
|
||||
// Copy from tail so that it works even if dst_buf == src_buf
|
||||
for (uint32_t i = 0; i < src_len >> 1; i++) {
|
||||
dst_buf[i] = src_buf[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
static void POSSIBLY_UNUSED aaudio_div_stero_to_lmono(int16_t *dst_buf, int16_t *src_buf, uint32_t src_len)
|
||||
{
|
||||
// Copy from tail so that it works even if dst_buf == src_buf
|
||||
for (uint32_t i = 0; i < src_len>>1; i++)
|
||||
{
|
||||
dst_buf[i] = src_buf[i*2 + 0];
|
||||
}
|
||||
static void POSSIBLY_UNUSED aaudio_div_stero_to_lmono(int16_t *dst_buf,
|
||||
int16_t *src_buf,
|
||||
uint32_t src_len) {
|
||||
// Copy from tail so that it works even if dst_buf == src_buf
|
||||
for (uint32_t i = 0; i < src_len >> 1; i++) {
|
||||
dst_buf[i] = src_buf[i * 2 + 0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void POSSIBLY_UNUSED audio_mono2stereo_16bits(int16_t *dst_buf, int16_t *left_buf, int16_t *right_buf, uint32_t src_len)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; ++i) {
|
||||
dst_buf[i*2 + 0] = left_buf[i];
|
||||
dst_buf[i*2 + 1] = right_buf[i];
|
||||
}
|
||||
static void POSSIBLY_UNUSED audio_mono2stereo_16bits(int16_t *dst_buf,
|
||||
int16_t *left_buf,
|
||||
int16_t *right_buf,
|
||||
uint32_t src_len) {
|
||||
uint32_t i = 0;
|
||||
for (i = 0; i < src_len; ++i) {
|
||||
dst_buf[i * 2 + 0] = left_buf[i];
|
||||
dst_buf[i * 2 + 1] = right_buf[i];
|
||||
}
|
||||
}
|
||||
|
||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 3
|
||||
|
||||
|
||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 4
|
||||
|
||||
#endif
|
||||
|
@ -155,105 +143,93 @@ extern uint32_t transfer_factor;
|
|||
extern uint32_t diff_energy;
|
||||
extern uint32_t level_shift;
|
||||
|
||||
static inline double convert_multiple_to_db(uint32_t multiple)
|
||||
{
|
||||
return 20*log10(multiple);
|
||||
static inline double convert_multiple_to_db(uint32_t multiple) {
|
||||
return 20 * log10(multiple);
|
||||
}
|
||||
#define DUMP_FRAME_LEN 0x3C0
|
||||
static short POSSIBLY_UNUSED revert_buff[2+1*DUMP_FRAME_LEN];
|
||||
#define DUMP_FRAME_LEN 0x3C0
|
||||
static short POSSIBLY_UNUSED revert_buff[2 + 1 * DUMP_FRAME_LEN];
|
||||
int32_t tx_pcmbuf32[960];
|
||||
|
||||
|
||||
extern int app_reset(void);
|
||||
|
||||
extern void app_bt_volumeup();
|
||||
extern void app_bt_volumedown();
|
||||
|
||||
void vol_state_process(uint32_t db_val)
|
||||
{
|
||||
TRACE(2,"db value is:%d volume_is:%d ",db_val,app_bt_stream_local_volume_get());
|
||||
|
||||
if((db_val < 52) && (app_bt_stream_local_volume_get() > 10))
|
||||
{
|
||||
app_bt_volumedown();
|
||||
}
|
||||
else if((db_val > 60) && (app_bt_stream_local_volume_get() < 13))
|
||||
{
|
||||
app_bt_volumeup();
|
||||
}
|
||||
else if((db_val > 72) && (app_bt_stream_local_volume_get() < 15))
|
||||
{
|
||||
app_bt_volumeup();
|
||||
}
|
||||
void vol_state_process(uint32_t db_val) {
|
||||
TRACE(2, "db value is:%d volume_is:%d ", db_val,
|
||||
app_bt_stream_local_volume_get());
|
||||
|
||||
if ((db_val < 52) && (app_bt_stream_local_volume_get() > 10)) {
|
||||
app_bt_volumedown();
|
||||
} else if ((db_val > 60) && (app_bt_stream_local_volume_get() < 13)) {
|
||||
app_bt_volumeup();
|
||||
} else if ((db_val > 72) && (app_bt_stream_local_volume_get() < 15)) {
|
||||
app_bt_volumeup();
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
uint32_t pcm_len = len>>1;
|
||||
static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len) {
|
||||
uint32_t pcm_len = len >> 1;
|
||||
|
||||
short POSSIBLY_UNUSED *tx_pcmbuf16 = (short*)buf;
|
||||
short POSSIBLY_UNUSED *tx_pcmbuf16 = (short *)buf;
|
||||
|
||||
//DUMP16("%d, ",tx_pcmbuf16,30);
|
||||
// memcpy(tmp_buff,pcm_buff,len);
|
||||
// DUMP16("%d, ",tx_pcmbuf16,30);
|
||||
// memcpy(tmp_buff,pcm_buff,len);
|
||||
|
||||
int32_t stime = 0;
|
||||
static int32_t nsx_cnt = 0;
|
||||
static int32_t dump_cnt = 0;
|
||||
int32_t stime = 0;
|
||||
static int32_t nsx_cnt = 0;
|
||||
static int32_t dump_cnt = 0;
|
||||
|
||||
nsx_cnt++;
|
||||
dump_cnt++;
|
||||
|
||||
nsx_cnt++;
|
||||
dump_cnt++;
|
||||
|
||||
DUMP16("%d,",tx_pcmbuf16,30);
|
||||
if(false == (nsx_cnt & 0x3F))
|
||||
{
|
||||
stime = hal_sys_timer_get();
|
||||
//TRACE("aecm echo time: lens:%d g_time_cnt:%d ",len, g_time_cnt);
|
||||
}
|
||||
DUMP16("%d,", tx_pcmbuf16, 30);
|
||||
if (false == (nsx_cnt & 0x3F)) {
|
||||
stime = hal_sys_timer_get();
|
||||
// TRACE("aecm echo time: lens:%d g_time_cnt:%d ",len, g_time_cnt);
|
||||
}
|
||||
|
||||
#ifdef WL_DET
|
||||
if(nsx_cnt > 100)
|
||||
{
|
||||
static double last_sum = 0,last_avg = 0;
|
||||
if (nsx_cnt > 100) {
|
||||
static double last_sum = 0, last_avg = 0;
|
||||
|
||||
uint32_t sum_ss = 0;
|
||||
//short db_val = 0;
|
||||
double db_sum = 0;
|
||||
for (uint32_t i_cnt = 0; i_cnt < pcm_len; i_cnt++)
|
||||
{
|
||||
sum_ss += ABS(tx_pcmbuf16[i_cnt]);
|
||||
}
|
||||
|
||||
sum_ss = 1*sum_ss/pcm_len;
|
||||
|
||||
db_sum = convert_multiple_to_db(sum_ss);
|
||||
//db_val = (short)(100*db_sum);
|
||||
last_sum += db_sum;
|
||||
last_avg = last_sum/nsx_cnt;
|
||||
|
||||
db_sum = db_sum*(double)0.02 + last_avg*(double)0.98;
|
||||
|
||||
//TRACE(2,"db value is:%d sum_ss:%d ",(uint32_t)db_sum,sum_ss);
|
||||
//TRACE(2,"db value is:%d ",(uint32_t)db_sum);
|
||||
vol_state_process((uint32_t)db_sum);
|
||||
uint32_t sum_ss = 0;
|
||||
// short db_val = 0;
|
||||
double db_sum = 0;
|
||||
for (uint32_t i_cnt = 0; i_cnt < pcm_len; i_cnt++) {
|
||||
sum_ss += ABS(tx_pcmbuf16[i_cnt]);
|
||||
}
|
||||
|
||||
sum_ss = 1 * sum_ss / pcm_len;
|
||||
|
||||
db_sum = convert_multiple_to_db(sum_ss);
|
||||
// db_val = (short)(100*db_sum);
|
||||
last_sum += db_sum;
|
||||
last_avg = last_sum / nsx_cnt;
|
||||
|
||||
db_sum = db_sum * (double)0.02 + last_avg * (double)0.98;
|
||||
|
||||
// TRACE(2,"db value is:%d sum_ss:%d ",(uint32_t)db_sum,sum_ss);
|
||||
// TRACE(2,"db value is:%d ",(uint32_t)db_sum);
|
||||
vol_state_process((uint32_t)db_sum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (false == (nsx_cnt & 0x3F)) {
|
||||
// TRACE("drc 48 mic_alg 16k nsx 3 agc 15 closed speed time:%d ms and
|
||||
// pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime),
|
||||
// pcm_len,hal_sysfreq_get()); TRACE("notch 500 mic_alg 16k nsx 3 agc 15
|
||||
// closed speed time:%d ms and pcm_lens:%d freq:%d ",
|
||||
// TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||
TRACE(2, "denoise det speed time:%d ms and pcm_lens:%d freq:%d ",
|
||||
TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len, hal_sysfreq_get());
|
||||
}
|
||||
|
||||
if(false == (nsx_cnt & 0x3F))
|
||||
{
|
||||
//TRACE("drc 48 mic_alg 16k nsx 3 agc 15 closed speed time:%d ms and pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||
//TRACE("notch 500 mic_alg 16k nsx 3 agc 15 closed speed time:%d ms and pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||
TRACE(2,"denoise det speed time:%d ms and pcm_lens:%d freq:%d ", TICKS_TO_MS(hal_sys_timer_get() - stime), pcm_len,hal_sysfreq_get());
|
||||
}
|
||||
|
||||
|
||||
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY){
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_OK;
|
||||
}
|
||||
return len;
|
||||
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY) {
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_OK;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
// static uint32_t app_mic_uart_playback_data(uint8_t *buf, uint32_t len)
|
||||
|
@ -262,13 +238,14 @@ static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len)
|
|||
// #if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||
// #ifdef WL_AEC
|
||||
// app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
||||
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
|
||||
// #else
|
||||
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf,
|
||||
// app_audioloop_play_cache, len/2/2); #else
|
||||
// app_audio_pcmbuff_get((uint8_t *)buf, len);
|
||||
// #endif
|
||||
// #else
|
||||
// app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
|
||||
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
|
||||
// app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf,
|
||||
// app_audioloop_play_cache, len/2/2);
|
||||
// #endif
|
||||
// }
|
||||
// return len;
|
||||
|
@ -276,68 +253,63 @@ static uint32_t app_mic_alg_data_come(uint8_t *buf, uint32_t len)
|
|||
|
||||
static uint8_t buff_capture[BT_AUDIO_FACTORMODE_BUFF_SIZE];
|
||||
|
||||
int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq)
|
||||
{
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static bool isRun = false;
|
||||
int app_mic_alg_audioloop(bool on, enum APP_SYSFREQ_FREQ_T freq) {
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
static bool isRun = false;
|
||||
|
||||
TRACE(2,"app_mic_alg work:%d op:%d freq:%d", isRun, on, freq);
|
||||
TRACE(2, "app_mic_alg work:%d op:%d freq:%d", isRun, on, freq);
|
||||
|
||||
if (isRun==on)
|
||||
return 0;
|
||||
|
||||
if (on){
|
||||
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
|
||||
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
|
||||
stream_cfg.vol = CODEC_SADC_VOL;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_ASRMIC;
|
||||
|
||||
stream_cfg.handler = app_mic_alg_data_come;
|
||||
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
|
||||
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE*stream_cfg.channel_num;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
|
||||
// stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
// stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
// stream_cfg.handler = app_mic_uart_playback_data;
|
||||
|
||||
// stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_play);
|
||||
// stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE*2;
|
||||
// af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
|
||||
//af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
TRACE(2,"app_mic_uart ss loopback on");
|
||||
|
||||
} 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);
|
||||
TRACE(2,"app_mic_16k loopback off");
|
||||
|
||||
//app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
}
|
||||
|
||||
isRun=on;
|
||||
if (isRun == on)
|
||||
return 0;
|
||||
|
||||
if (on) {
|
||||
|
||||
app_sysfreq_req(APP_SYSFREQ_USER_APP_0, freq);
|
||||
|
||||
a2dp_cache_status = APP_AUDIO_CACHE_QTY;
|
||||
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
|
||||
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
|
||||
stream_cfg.vol = CODEC_SADC_VOL;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_ASRMIC;
|
||||
|
||||
stream_cfg.handler = app_mic_alg_data_come;
|
||||
|
||||
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
|
||||
stream_cfg.data_size =
|
||||
BT_AUDIO_FACTORMODE_BUFF_SIZE * stream_cfg.channel_num;
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
|
||||
// stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
// stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
// stream_cfg.handler = app_mic_uart_playback_data;
|
||||
|
||||
// stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_play);
|
||||
// stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE*2;
|
||||
// af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
|
||||
// af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
TRACE(2, "app_mic_uart ss loopback on");
|
||||
|
||||
} 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);
|
||||
TRACE(2, "app_mic_16k loopback off");
|
||||
|
||||
// app_sysfreq_req(APP_SYSFREQ_USER_APP_0, APP_SYSFREQ_32K);
|
||||
}
|
||||
|
||||
isRun = on;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,173 +13,179 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_pwl.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "tgt_hardware.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_iomux.h"
|
||||
#include "hal_trace.h"
|
||||
#include "pmu.h"
|
||||
#include "app_pwl.h"
|
||||
#include "string.h"
|
||||
#include "tgt_hardware.h"
|
||||
|
||||
#define APP_PWL_TRACE(s,...)
|
||||
//TRACE(s, ##__VA_ARGS__)
|
||||
#define APP_PWL_TRACE(s, ...)
|
||||
// TRACE(s, ##__VA_ARGS__)
|
||||
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
static void app_pwl_timehandler(void const *param);
|
||||
|
||||
osTimerDef (APP_PWL_TIMER0, app_pwl_timehandler); // define timers
|
||||
osTimerDef(APP_PWL_TIMER0, app_pwl_timehandler); // define timers
|
||||
#if (CFG_HW_PLW_NUM == 2)
|
||||
osTimerDef (APP_PWL_TIMER1, app_pwl_timehandler);
|
||||
osTimerDef(APP_PWL_TIMER1, app_pwl_timehandler);
|
||||
#endif
|
||||
|
||||
struct APP_PWL_T {
|
||||
enum APP_PWL_ID_T id;
|
||||
struct APP_PWL_CFG_T config;
|
||||
uint8_t partidx;
|
||||
osTimerId timer;
|
||||
enum APP_PWL_ID_T id;
|
||||
struct APP_PWL_CFG_T config;
|
||||
uint8_t partidx;
|
||||
osTimerId timer;
|
||||
};
|
||||
|
||||
static struct APP_PWL_T app_pwl[APP_PWL_ID_QTY];
|
||||
|
||||
static void app_pwl_timehandler(void const *param)
|
||||
{
|
||||
struct APP_PWL_T *pwl = (struct APP_PWL_T *)param;
|
||||
struct APP_PWL_CFG_T *cfg = &(pwl->config);
|
||||
APP_PWL_TRACE(2,"%s %x",__func__, param);
|
||||
static void app_pwl_timehandler(void const *param) {
|
||||
struct APP_PWL_T *pwl = (struct APP_PWL_T *)param;
|
||||
struct APP_PWL_CFG_T *cfg = &(pwl->config);
|
||||
APP_PWL_TRACE(2, "%s %x", __func__, param);
|
||||
|
||||
osTimerStop(pwl->timer);
|
||||
osTimerStop(pwl->timer);
|
||||
|
||||
pwl->partidx++;
|
||||
if (cfg->periodic){
|
||||
if (pwl->partidx >= cfg->parttotal){
|
||||
pwl->partidx = 0;
|
||||
}
|
||||
}else{
|
||||
if (pwl->partidx >= cfg->parttotal){
|
||||
return;
|
||||
}
|
||||
pwl->partidx++;
|
||||
if (cfg->periodic) {
|
||||
if (pwl->partidx >= cfg->parttotal) {
|
||||
pwl->partidx = 0;
|
||||
}
|
||||
|
||||
APP_PWL_TRACE(3,"idx:%d pin:%d lvl:%d", pwl->partidx, cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
||||
if(!cfg->part[pwl->partidx].level){
|
||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, true);
|
||||
#endif
|
||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
}else{
|
||||
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, false);
|
||||
#endif
|
||||
} else {
|
||||
if (pwl->partidx >= cfg->parttotal) {
|
||||
return;
|
||||
}
|
||||
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
||||
}
|
||||
|
||||
APP_PWL_TRACE(3, "idx:%d pin:%d lvl:%d", pwl->partidx,
|
||||
cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
||||
if (!cfg->part[pwl->partidx].level) {
|
||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
||||
: PMU_VIORISE_REQ_USER_PWL1,
|
||||
true);
|
||||
#endif
|
||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
} else {
|
||||
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
||||
: PMU_VIORISE_REQ_USER_PWL1,
|
||||
false);
|
||||
#endif
|
||||
}
|
||||
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
||||
}
|
||||
#endif
|
||||
|
||||
int app_pwl_open(void)
|
||||
{
|
||||
int app_pwl_open(void) {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
uint8_t i;
|
||||
APP_PWL_TRACE(1,"%s",__func__);
|
||||
for (i=0;i<APP_PWL_ID_QTY;i++){
|
||||
app_pwl[i].id = APP_PWL_ID_QTY;
|
||||
memset(&(app_pwl[i].config), 0, sizeof(struct APP_PWL_CFG_T));
|
||||
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&cfg_hw_pinmux_pwl[i], 1);
|
||||
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[i].pin, HAL_GPIO_DIR_OUT, 1);
|
||||
}
|
||||
app_pwl[APP_PWL_ID_0].timer = osTimerCreate (osTimer(APP_PWL_TIMER0), osTimerOnce, &app_pwl[APP_PWL_ID_0]);
|
||||
uint8_t i;
|
||||
APP_PWL_TRACE(1, "%s", __func__);
|
||||
for (i = 0; i < APP_PWL_ID_QTY; i++) {
|
||||
app_pwl[i].id = APP_PWL_ID_QTY;
|
||||
memset(&(app_pwl[i].config), 0, sizeof(struct APP_PWL_CFG_T));
|
||||
hal_iomux_init((struct HAL_IOMUX_PIN_FUNCTION_MAP *)&cfg_hw_pinmux_pwl[i],
|
||||
1);
|
||||
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[i].pin,
|
||||
HAL_GPIO_DIR_OUT, 1);
|
||||
}
|
||||
app_pwl[APP_PWL_ID_0].timer = osTimerCreate(
|
||||
osTimer(APP_PWL_TIMER0), osTimerOnce, &app_pwl[APP_PWL_ID_0]);
|
||||
#if (CFG_HW_PLW_NUM == 2)
|
||||
app_pwl[APP_PWL_ID_1].timer = osTimerCreate (osTimer(APP_PWL_TIMER1), osTimerOnce, &app_pwl[APP_PWL_ID_1]);
|
||||
app_pwl[APP_PWL_ID_1].timer = osTimerCreate(
|
||||
osTimer(APP_PWL_TIMER1), osTimerOnce, &app_pwl[APP_PWL_ID_1]);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_pwl_start(enum APP_PWL_ID_T id)
|
||||
{
|
||||
int app_pwl_start(enum APP_PWL_ID_T id) {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
struct APP_PWL_T *pwl = NULL;
|
||||
struct APP_PWL_CFG_T *cfg = NULL;
|
||||
struct APP_PWL_T *pwl = NULL;
|
||||
struct APP_PWL_CFG_T *cfg = NULL;
|
||||
|
||||
if (id >= APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (id >= APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
APP_PWL_TRACE(2, "%s %d", __func__, id);
|
||||
|
||||
APP_PWL_TRACE(2,"%s %d",__func__, id);
|
||||
pwl = &app_pwl[id];
|
||||
cfg = &(pwl->config);
|
||||
|
||||
pwl = &app_pwl[id];
|
||||
cfg = &(pwl->config);
|
||||
if (pwl->id == APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pwl->id == APP_PWL_ID_QTY){
|
||||
return -1;
|
||||
}
|
||||
pwl->partidx = 0;
|
||||
if (pwl->partidx >= cfg->parttotal) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pwl->partidx = 0;
|
||||
if (pwl->partidx >= cfg->parttotal){
|
||||
return -1;
|
||||
}
|
||||
osTimerStop(pwl->timer);
|
||||
|
||||
osTimerStop(pwl->timer);
|
||||
|
||||
APP_PWL_TRACE(3,"idx:%d pin:%d lvl:%d", pwl->partidx, cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
||||
if(!cfg->part[pwl->partidx].level){
|
||||
APP_PWL_TRACE(3, "idx:%d pin:%d lvl:%d", pwl->partidx,
|
||||
cfg_hw_pinmux_pwl[pwl->id].pin, cfg->part[pwl->partidx].level);
|
||||
if (!cfg->part[pwl->partidx].level) {
|
||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, false);
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
||||
: PMU_VIORISE_REQ_USER_PWL1,
|
||||
false);
|
||||
#endif
|
||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
}else{
|
||||
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
} else {
|
||||
hal_gpio_pin_clr((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[pwl->id].pin);
|
||||
#if defined(__PMU_VIO_DYNAMIC_CTRL_MODE__)
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0 : PMU_VIORISE_REQ_USER_PWL1, false);
|
||||
pmu_viorise_req(pwl->id == APP_PWL_ID_0 ? PMU_VIORISE_REQ_USER_PWL0
|
||||
: PMU_VIORISE_REQ_USER_PWL1,
|
||||
false);
|
||||
#endif
|
||||
}
|
||||
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
||||
}
|
||||
osTimerStart(pwl->timer, cfg->part[pwl->partidx].time);
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_pwl_setup(enum APP_PWL_ID_T id, struct APP_PWL_CFG_T *cfg)
|
||||
{
|
||||
int app_pwl_setup(enum APP_PWL_ID_T id, struct APP_PWL_CFG_T *cfg) {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
if (cfg == NULL || id >= APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
APP_PWL_TRACE(2,"%s %d",__func__, id);
|
||||
if (cfg == NULL || id >= APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
APP_PWL_TRACE(2, "%s %d", __func__, id);
|
||||
|
||||
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[id].pin, HAL_GPIO_DIR_OUT, cfg->startlevel?0:1);
|
||||
app_pwl[id].id = id;
|
||||
memcpy(&(app_pwl[id].config), cfg, sizeof(struct APP_PWL_CFG_T));
|
||||
hal_gpio_pin_set_dir((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[id].pin,
|
||||
HAL_GPIO_DIR_OUT, cfg->startlevel ? 0 : 1);
|
||||
app_pwl[id].id = id;
|
||||
memcpy(&(app_pwl[id].config), cfg, sizeof(struct APP_PWL_CFG_T));
|
||||
|
||||
osTimerStop(app_pwl[id].timer);
|
||||
osTimerStop(app_pwl[id].timer);
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_pwl_stop(enum APP_PWL_ID_T id)
|
||||
{
|
||||
int app_pwl_stop(enum APP_PWL_ID_T id) {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
if (id >= APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
if (id >= APP_PWL_ID_QTY) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
osTimerStop(app_pwl[id].timer);
|
||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[id].pin);
|
||||
osTimerStop(app_pwl[id].timer);
|
||||
hal_gpio_pin_set((enum HAL_GPIO_PIN_T)cfg_hw_pinmux_pwl[id].pin);
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_pwl_close(void)
|
||||
{
|
||||
int app_pwl_close(void) {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
uint8_t i;
|
||||
for (i=0;i<APP_PWL_ID_QTY;i++){
|
||||
if (app_pwl[i].id != APP_PWL_ID_QTY)
|
||||
app_pwl_stop((enum APP_PWL_ID_T)i);
|
||||
}
|
||||
uint8_t i;
|
||||
for (i = 0; i < APP_PWL_ID_QTY; i++) {
|
||||
if (app_pwl[i].id != APP_PWL_ID_QTY)
|
||||
app_pwl_stop((enum APP_PWL_ID_T)i);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -19,182 +19,168 @@
|
|||
|
||||
//#include "hal_sdmmc.h"
|
||||
#include "SDFileSystem.h"
|
||||
#include "audioflinger.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "app_sdmmc.h"
|
||||
#include "audiobuffer.h"
|
||||
#include "audioflinger.h"
|
||||
|
||||
|
||||
#define APP_TEST_PLAYBACK_BUFF_SIZE (120 * 20)
|
||||
#define APP_TEST_CAPTURE_BUFF_SIZE (120 * 20)
|
||||
extern uint8_t app_test_playback_buff[APP_TEST_PLAYBACK_BUFF_SIZE] __attribute__ ((aligned(4)));
|
||||
extern uint8_t app_test_capture_buff[APP_TEST_CAPTURE_BUFF_SIZE] __attribute__ ((aligned(4)));
|
||||
#define APP_TEST_PLAYBACK_BUFF_SIZE (120 * 20)
|
||||
#define APP_TEST_CAPTURE_BUFF_SIZE (120 * 20)
|
||||
extern uint8_t app_test_playback_buff[APP_TEST_PLAYBACK_BUFF_SIZE]
|
||||
__attribute__((aligned(4)));
|
||||
extern uint8_t app_test_capture_buff[APP_TEST_CAPTURE_BUFF_SIZE]
|
||||
__attribute__((aligned(4)));
|
||||
SDFileSystem sdfs("sd");
|
||||
|
||||
int sd_open()
|
||||
{
|
||||
DIR *d = opendir("/sd");
|
||||
if (!d)
|
||||
{
|
||||
TRACE(0,"sd file system borked\n");
|
||||
return -1;
|
||||
}
|
||||
int sd_open() {
|
||||
DIR *d = opendir("/sd");
|
||||
if (!d) {
|
||||
TRACE(0, "sd file system borked\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
TRACE(0,"---------root---------\n");
|
||||
struct dirent *p;
|
||||
while ((p = readdir(d)))
|
||||
{
|
||||
int len = sizeof( dirent);
|
||||
TRACE(2,"%s %d\n", p->d_name, len);
|
||||
}
|
||||
closedir(d);
|
||||
TRACE(0,"--------root end-------\n");
|
||||
TRACE(0, "---------root---------\n");
|
||||
struct dirent *p;
|
||||
while ((p = readdir(d))) {
|
||||
int len = sizeof(dirent);
|
||||
TRACE(2, "%s %d\n", p->d_name, len);
|
||||
}
|
||||
closedir(d);
|
||||
TRACE(0, "--------root end-------\n");
|
||||
}
|
||||
|
||||
extern uint32_t play_wav_file(char *file_path);
|
||||
extern uint32_t stop_wav_file(void);
|
||||
extern uint32_t wav_file_audio_more_data(uint8_t *buf, uint32_t len);
|
||||
|
||||
void test_wave_play(bool on)
|
||||
{
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
uint32_t reallen;
|
||||
uint32_t totalreadsize;
|
||||
uint32_t stime, etime;
|
||||
void test_wave_play(bool on) {
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
uint32_t reallen;
|
||||
uint32_t totalreadsize;
|
||||
uint32_t stime, etime;
|
||||
|
||||
char wave[] = "/sd/test_music.wav";
|
||||
char wave[] = "/sd/test_music.wav";
|
||||
|
||||
static bool isRun = false;
|
||||
|
||||
if (isRun==on)
|
||||
return;
|
||||
else
|
||||
isRun=on;
|
||||
|
||||
|
||||
TRACE(2,"%s %d\n", __func__, on);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
if (on){
|
||||
play_wav_file(wave);
|
||||
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = 0x03;
|
||||
|
||||
stream_cfg.handler = wav_file_audio_more_data;
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}else{
|
||||
stop_wav_file();
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
static bool isRun = false;
|
||||
|
||||
if (isRun == on)
|
||||
return;
|
||||
}
|
||||
else
|
||||
isRun = on;
|
||||
|
||||
TRACE(2, "%s %d\n", __func__, on);
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
if (on) {
|
||||
play_wav_file(wave);
|
||||
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
|
||||
stream_cfg.vol = 0x03;
|
||||
|
||||
stream_cfg.handler = wav_file_audio_more_data;
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
} else {
|
||||
stop_wav_file();
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FIL pcm_fil;
|
||||
FRESULT pcm_res;
|
||||
UINT pcm_num;
|
||||
uint32_t pcm_save_more_data(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
// TRACE(2,"%s\n len:%d", __func__, len);
|
||||
uint32_t pcm_save_more_data(uint8_t *buf, uint32_t len) {
|
||||
// TRACE(2,"%s\n len:%d", __func__, len);
|
||||
|
||||
audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
||||
pcm_res = f_write(&pcm_fil,(uint8_t *)buf,len>>1,&pcm_num);
|
||||
if(pcm_res != FR_OK)
|
||||
{
|
||||
TRACE(2,"[%s]:error-->res = %d", __func__, pcm_res);
|
||||
}
|
||||
return 0;
|
||||
audio_buffer_set_stereo2mono_16bits(buf, len, 1);
|
||||
pcm_res = f_write(&pcm_fil, (uint8_t *)buf, len >> 1, &pcm_num);
|
||||
if (pcm_res != FR_OK) {
|
||||
TRACE(2, "[%s]:error-->res = %d", __func__, pcm_res);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ad_tester(bool run)
|
||||
{
|
||||
char filename[] = "/sd/audio_dump.bin";
|
||||
void ad_tester(bool run) {
|
||||
char filename[] = "/sd/audio_dump.bin";
|
||||
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
struct AF_STREAM_CONFIG_T stream_cfg;
|
||||
|
||||
TRACE(2,"%s %d\n", __func__, run);
|
||||
TRACE(2, "%s %d\n", __func__, run);
|
||||
|
||||
if (run){
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
pcm_res = f_open(&pcm_fil,"test2.bin",FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (pcm_res) {
|
||||
TRACE(2,"[%s]:Cannot creat test2.bin...%d",__func__, pcm_res);
|
||||
return;
|
||||
}
|
||||
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.vol = 0x03;
|
||||
|
||||
stream_cfg.handler = pcm_save_more_data;
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
}else{
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
osDelay(1000);
|
||||
|
||||
f_close(&pcm_fil);
|
||||
if (run) {
|
||||
memset(&stream_cfg, 0, sizeof(stream_cfg));
|
||||
pcm_res = f_open(&pcm_fil, "test2.bin", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (pcm_res) {
|
||||
TRACE(2, "[%s]:Cannot creat test2.bin...%d", __func__, pcm_res);
|
||||
return;
|
||||
}
|
||||
|
||||
stream_cfg.bits = AUD_BITS_16;
|
||||
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
|
||||
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
|
||||
|
||||
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
|
||||
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
|
||||
stream_cfg.vol = 0x03;
|
||||
|
||||
stream_cfg.handler = pcm_save_more_data;
|
||||
stream_cfg.data_ptr = app_test_playback_buff;
|
||||
stream_cfg.data_size = APP_TEST_PLAYBACK_BUFF_SIZE;
|
||||
|
||||
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
|
||||
af_stream_start(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
} else {
|
||||
af_stream_stop(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
af_stream_close(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE);
|
||||
osDelay(1000);
|
||||
|
||||
f_close(&pcm_fil);
|
||||
}
|
||||
}
|
||||
|
||||
// if dump data into sd, buffer length should make sd card speed enough
|
||||
// Bench32.exe can test sd card speed in PC, then make sure bufer length, buffer length < 16k(sd driver)
|
||||
void dump_data2sd(enum APP_SDMMC_DUMP_T opt, uint8_t *buf, uint32_t len)
|
||||
{
|
||||
static FIL sd_fil;
|
||||
FRESULT res;
|
||||
// Bench32.exe can test sd card speed in PC, then make sure bufer length, buffer
|
||||
// length < 16k(sd driver)
|
||||
void dump_data2sd(enum APP_SDMMC_DUMP_T opt, uint8_t *buf, uint32_t len) {
|
||||
static FIL sd_fil;
|
||||
FRESULT res;
|
||||
|
||||
ASSERT(opt < APP_SDMMC_DUMP_NUM, "[%s] opt(%d) >= APP_SDMMC_DUMP_NUM",
|
||||
__func__, opt);
|
||||
|
||||
ASSERT(opt < APP_SDMMC_DUMP_NUM, "[%s] opt(%d) >= APP_SDMMC_DUMP_NUM", __func__, opt);
|
||||
if (opt == APP_SDMMC_DUMP_OPEN) {
|
||||
// res = f_open(&sd_fil,"dump.bin",FA_CREATE_ALWAYS | FA_WRITE);
|
||||
res = f_open(&sd_fil, "test.txt", FA_READ);
|
||||
|
||||
if(opt == APP_SDMMC_DUMP_OPEN)
|
||||
{
|
||||
// res = f_open(&sd_fil,"dump.bin",FA_CREATE_ALWAYS | FA_WRITE);
|
||||
res = f_open(&sd_fil,"test.txt",FA_READ);
|
||||
// ASSERT(pcm_res == FR_OK,"[%s]:Cannot creat dump.bin, res =
|
||||
// %d",__func__, pcm_res);
|
||||
}
|
||||
if (opt == APP_SDMMC_DUMP_READ) {
|
||||
res = f_read(&sd_fil, buf, len, &pcm_num);
|
||||
|
||||
// ASSERT(pcm_res == FR_OK,"[%s]:Cannot creat dump.bin, res = %d",__func__, pcm_res);
|
||||
}
|
||||
if(opt == APP_SDMMC_DUMP_READ)
|
||||
{
|
||||
res = f_read(&sd_fil, buf, len, &pcm_num);
|
||||
// ASSERT(pcm_res == FR_OK,"[%s]:Cannot creat dump.bin, res =
|
||||
// %d",__func__, pcm_res);
|
||||
} else if (opt == APP_SDMMC_DUMP_WRITE) {
|
||||
res = f_write(&sd_fil, buf, len, &pcm_num);
|
||||
|
||||
// ASSERT(pcm_res == FR_OK,"[%s]:Cannot creat dump.bin, res = %d",__func__, pcm_res);
|
||||
}
|
||||
else if(opt == APP_SDMMC_DUMP_WRITE)
|
||||
{
|
||||
res = f_write(&sd_fil, buf, len, &pcm_num);
|
||||
// ASSERT(pcm_res == FR_OK,"[%s]:Write dump.bin failed, res = %d",
|
||||
// __func__, pcm_res);
|
||||
} else if (opt == APP_SDMMC_DUMP_CLOSE) {
|
||||
res = f_close(&sd_fil);
|
||||
}
|
||||
|
||||
// ASSERT(pcm_res == FR_OK,"[%s]:Write dump.bin failed, res = %d", __func__, pcm_res);
|
||||
}
|
||||
else if(opt == APP_SDMMC_DUMP_CLOSE)
|
||||
{
|
||||
res = f_close(&sd_fil);
|
||||
}
|
||||
|
||||
if(res == FR_OK)
|
||||
{
|
||||
TRACE(3,"[%s] SUCESS: opt = %d, res = %d",__func__, opt, res);
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE(3,"[%s] ERROR: opt = %d, res = %d",__func__, opt, res);
|
||||
}
|
||||
if (res == FR_OK) {
|
||||
TRACE(3, "[%s] SUCESS: opt = %d, res = %d", __func__, opt, res);
|
||||
} else {
|
||||
TRACE(3, "[%s] ERROR: opt = %d, res = %d", __func__, opt, res);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,30 +13,30 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "plat_addr_map.h"
|
||||
#include "analog.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cmsis.h"
|
||||
#include "hal_cmu.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_iomux.h"
|
||||
#include "hal_dma.h"
|
||||
#include "hal_key.h"
|
||||
#include "hal_gpadc.h"
|
||||
#include "hal_iomux.h"
|
||||
#include "hal_key.h"
|
||||
#include "hal_sleep.h"
|
||||
#include "hal_sysfreq.h"
|
||||
#include "cmsis.h"
|
||||
#include "pmu.h"
|
||||
#include "analog.h"
|
||||
#include "string.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hwtimer_list.h"
|
||||
#include "audioflinger.h"
|
||||
#include "plat_addr_map.h"
|
||||
#include "pmu.h"
|
||||
#include "string.h"
|
||||
#if defined(ANC_APP)
|
||||
#include "anc_usb_app.h"
|
||||
#endif
|
||||
#include "usb_audio_app.h"
|
||||
#include "dualadc_audio_app.h"
|
||||
#include "usb_audio_frm_defs.h"
|
||||
#include "tgt_hardware.h"
|
||||
#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"
|
||||
|
@ -46,75 +46,97 @@
|
|||
#endif
|
||||
|
||||
#ifdef USB_AUDIO_SPEECH
|
||||
#define CODEC_BUFF_FRAME_NUM (2 * 16)
|
||||
#define USB_BUFF_FRAME_NUM (CODEC_BUFF_FRAME_NUM * 2)
|
||||
#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
|
||||
#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)"
|
||||
#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_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)
|
||||
#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
|
||||
#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)
|
||||
#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)
|
||||
#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_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)
|
||||
#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)
|
||||
#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)
|
||||
#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)
|
||||
#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)
|
||||
#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
|
||||
#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)
|
||||
// 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)
|
||||
#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;
|
||||
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
|
||||
|
@ -125,7 +147,8 @@ static uint8_t ALIGNED4 capture_buff[USB_AUDIO_CAPTURE_BUFF_SIZE];
|
|||
|
||||
#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];
|
||||
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__)
|
||||
|
@ -146,202 +169,195 @@ static uint8_t ALIGNED4 send_buff[USB_AUDIO_SEND_BUFF_SIZE];
|
|||
|
||||
#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},
|
||||
{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);
|
||||
extern void mic_key_open(void);
|
||||
#endif
|
||||
|
||||
static void uart_i2c_switch(void)
|
||||
{
|
||||
static int flag = 0;
|
||||
static void uart_i2c_switch(void) {
|
||||
static int flag = 0;
|
||||
|
||||
flag ^= 1;
|
||||
flag ^= 1;
|
||||
|
||||
if (flag) {
|
||||
hal_iomux_set_analog_i2c();
|
||||
} else {
|
||||
hal_iomux_set_uart0();
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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();
|
||||
}
|
||||
if (key_event == HAL_KEY_EVENT_CLICK) {
|
||||
if (key_code == HAL_KEY_CODE_FN9) {
|
||||
uart_i2c_switch();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void anc_usb_open(void)
|
||||
{
|
||||
TRACE(1,"%s", __FUNCTION__);
|
||||
void anc_usb_open(void) {
|
||||
TRACE(1, "%s", __FUNCTION__);
|
||||
|
||||
#ifdef __AUDIO_RESAMPLE__
|
||||
hal_cmu_audio_resample_enable();
|
||||
hal_cmu_audio_resample_enable();
|
||||
#endif
|
||||
|
||||
#ifdef USB_AUDIO_APP
|
||||
struct USB_AUDIO_BUF_CFG cfg;
|
||||
struct USB_AUDIO_BUF_CFG cfg;
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.play_buf = playback_buff;
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.play_buf = playback_buff;
|
||||
#ifdef AUDIO_ANC_FB_MC
|
||||
cfg.play_size = sizeof(playback_buff) / 9;
|
||||
cfg.play_size = sizeof(playback_buff) / 9;
|
||||
#else
|
||||
cfg.play_size = sizeof(playback_buff);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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();
|
||||
mic_key_open();
|
||||
#endif
|
||||
#ifdef BT_USB_AUDIO_DUAL_MODE
|
||||
return;
|
||||
return;
|
||||
#endif
|
||||
// Allow sleep
|
||||
hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_32K);
|
||||
// Allow sleep
|
||||
hal_sysfreq_req(HAL_SYSFREQ_USER_INIT, HAL_CMU_FREQ_32K);
|
||||
|
||||
while (1) {
|
||||
while (1) {
|
||||
#ifdef USB_AUDIO_APP
|
||||
usb_audio_app_loop();
|
||||
usb_audio_app_loop();
|
||||
#endif
|
||||
|
||||
#ifdef ANC_APP
|
||||
anc_usb_app_loop();
|
||||
anc_usb_app_loop();
|
||||
#endif
|
||||
|
||||
#ifdef RTOS
|
||||
// Let the task sleep
|
||||
osDelay(20);
|
||||
// Let the task sleep
|
||||
osDelay(20);
|
||||
#else // !RTOS
|
||||
|
||||
#ifdef __PC_CMD_UART__
|
||||
hal_cmd_run();
|
||||
hal_cmd_run();
|
||||
#endif
|
||||
|
||||
hal_sleep_enter_sleep();
|
||||
hal_sleep_enter_sleep();
|
||||
|
||||
#endif // !RTOS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void anc_usb_close(void)
|
||||
{
|
||||
usb_audio_app(0);
|
||||
}
|
||||
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;
|
||||
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();
|
||||
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;
|
||||
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;
|
||||
int btusbaudio_entry(void) {
|
||||
anc_usb_open();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void btusbaudio_exit(void)
|
||||
{
|
||||
anc_usb_close();
|
||||
}
|
||||
|
||||
|
||||
void btusbaudio_exit(void) { anc_usb_close(); }
|
||||
|
|
|
@ -13,9 +13,6 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "app_thread.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_thread.h"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "cmsis_os.h"
|
||||
#include "tgt_hardware.h"
|
||||
#include "audioflinger.h"
|
||||
#include "hal_trace.h"
|
||||
#include "hal_timer.h"
|
||||
#include "app_thread.h"
|
||||
#include "voice_detector.h"
|
||||
#include "app_voice_detector.h"
|
||||
#include "app_thread.h"
|
||||
#include "audioflinger.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_timer.h"
|
||||
#include "hal_trace.h"
|
||||
#include "tgt_hardware.h"
|
||||
#include "voice_detector.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define APP_VD_DEBUG
|
||||
|
||||
#ifdef APP_VD_DEBUG
|
||||
#define APP_VD_LOG(str, ...) LOG_DEBUG(LOG_MOD(AUD), str, ##__VA_ARGS__)
|
||||
#else
|
||||
#define APP_VD_LOG(...) do{}while(0)
|
||||
#define APP_VD_LOG(...) \
|
||||
do { \
|
||||
} while (0)
|
||||
#endif
|
||||
#define APP_VD_ERR(str, ...) LOG_ERROR(LOG_MOD(AUD), str, ##__VA_ARGS__)
|
||||
|
||||
|
@ -22,10 +24,8 @@ osMutexId vd_mutex_id = NULL;
|
|||
osMutexDef(vd_mutex);
|
||||
|
||||
static int cmd_arr_evt_vad_start[] = {
|
||||
VOICE_DET_CMD_AUD_CAP_STOP,
|
||||
VOICE_DET_CMD_AUD_CAP_CLOSE,
|
||||
VOICE_DET_CMD_VAD_OPEN,
|
||||
VOICE_DET_CMD_VAD_START,
|
||||
VOICE_DET_CMD_AUD_CAP_STOP, VOICE_DET_CMD_AUD_CAP_CLOSE,
|
||||
VOICE_DET_CMD_VAD_OPEN, VOICE_DET_CMD_VAD_START,
|
||||
VOICE_DET_CMD_SYS_CLK_32K,
|
||||
};
|
||||
#if 0
|
||||
|
@ -44,10 +44,8 @@ static int cmd_arr_evt_cap_start[] = {
|
|||
};
|
||||
#endif
|
||||
static int cmd_arr_evt_close[] = {
|
||||
VOICE_DET_CMD_AUD_CAP_STOP,
|
||||
VOICE_DET_CMD_AUD_CAP_CLOSE,
|
||||
VOICE_DET_CMD_VAD_STOP,
|
||||
VOICE_DET_CMD_VAD_CLOSE,
|
||||
VOICE_DET_CMD_AUD_CAP_STOP, VOICE_DET_CMD_AUD_CAP_CLOSE,
|
||||
VOICE_DET_CMD_VAD_STOP, VOICE_DET_CMD_VAD_CLOSE,
|
||||
VOICE_DET_CMD_EXIT,
|
||||
};
|
||||
#if 1
|
||||
|
@ -63,205 +61,191 @@ static int cmd_arr_evt_vad_close[] = {
|
|||
VOICE_DET_CMD_EXIT,
|
||||
};
|
||||
|
||||
static int app_voice_detector_process(APP_MESSAGE_BODY *msg_body)
|
||||
{
|
||||
enum voice_detector_id id = (enum voice_detector_id)msg_body->message_id;
|
||||
enum voice_detector_evt evt = (enum voice_detector_evt)msg_body->message_ptr;
|
||||
int ret = 0, num, *cmds;
|
||||
static int app_voice_detector_process(APP_MESSAGE_BODY *msg_body) {
|
||||
enum voice_detector_id id = (enum voice_detector_id)msg_body->message_id;
|
||||
enum voice_detector_evt evt = (enum voice_detector_evt)msg_body->message_ptr;
|
||||
int ret = 0, num, *cmds;
|
||||
|
||||
voice_detector_enhance_perform(id);// set sys clock to 104M or 208M
|
||||
voice_detector_enhance_perform(id); // set sys clock to 104M or 208M
|
||||
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
switch(evt) {
|
||||
case VOICE_DET_EVT_VAD_START:
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_CLOSE) {
|
||||
cmds = &cmd_arr_evt_vad_start[0];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_vad_start);
|
||||
} else {
|
||||
cmds = &cmd_arr_evt_vad_start[2];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_vad_start) - 2;
|
||||
}
|
||||
break;
|
||||
case VOICE_DET_EVT_AUD_CAP_START:
|
||||
cmds = cmd_arr_evt_cap_start;
|
||||
num = ARRAY_SIZE(cmd_arr_evt_cap_start);
|
||||
break;
|
||||
case VOICE_DET_EVT_CLOSE:
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_CLOSE) {
|
||||
cmds = &cmd_arr_evt_cap_close[0];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_cap_close);
|
||||
} else {
|
||||
cmds = &cmd_arr_evt_vad_close[0];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_vad_close);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cmds = cmd_arr_evt_close;
|
||||
num = ARRAY_SIZE(cmd_arr_evt_close);
|
||||
break;
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
switch (evt) {
|
||||
case VOICE_DET_EVT_VAD_START:
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_CLOSE) {
|
||||
cmds = &cmd_arr_evt_vad_start[0];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_vad_start);
|
||||
} else {
|
||||
cmds = &cmd_arr_evt_vad_start[2];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_vad_start) - 2;
|
||||
}
|
||||
ret = voice_detector_send_cmd_array(id, cmds, num);
|
||||
if (ret) {
|
||||
APP_VD_ERR("%s, send cmd error %d", __func__, ret);
|
||||
break;
|
||||
case VOICE_DET_EVT_AUD_CAP_START:
|
||||
cmds = cmd_arr_evt_cap_start;
|
||||
num = ARRAY_SIZE(cmd_arr_evt_cap_start);
|
||||
break;
|
||||
case VOICE_DET_EVT_CLOSE:
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_CLOSE) {
|
||||
cmds = &cmd_arr_evt_cap_close[0];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_cap_close);
|
||||
} else {
|
||||
cmds = &cmd_arr_evt_vad_close[0];
|
||||
num = ARRAY_SIZE(cmd_arr_evt_vad_close);
|
||||
}
|
||||
ret = voice_detector_run(id, VOICE_DET_MODE_EXEC_CMD);
|
||||
if (ret) {
|
||||
APP_VD_ERR("%s, run cmd error %d", __func__, ret);
|
||||
}
|
||||
if (evt == VOICE_DET_EVT_CLOSE) {
|
||||
voice_detector_close(id);
|
||||
}
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return ret;
|
||||
break;
|
||||
default:
|
||||
cmds = cmd_arr_evt_close;
|
||||
num = ARRAY_SIZE(cmd_arr_evt_close);
|
||||
break;
|
||||
}
|
||||
ret = voice_detector_send_cmd_array(id, cmds, num);
|
||||
if (ret) {
|
||||
APP_VD_ERR("%s, send cmd error %d", __func__, ret);
|
||||
}
|
||||
ret = voice_detector_run(id, VOICE_DET_MODE_EXEC_CMD);
|
||||
if (ret) {
|
||||
APP_VD_ERR("%s, run cmd error %d", __func__, ret);
|
||||
}
|
||||
if (evt == VOICE_DET_EVT_CLOSE) {
|
||||
voice_detector_close(id);
|
||||
}
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void voice_detector_send_msg(uint32_t id, uint32_t evt)
|
||||
{
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
static void voice_detector_send_msg(uint32_t id, uint32_t evt) {
|
||||
APP_MESSAGE_BLOCK msg;
|
||||
|
||||
msg.mod_id = APP_MODUAL_VOICE_DETECTOR;
|
||||
msg.msg_body.message_id = id;
|
||||
msg.msg_body.message_ptr = evt;
|
||||
msg.mod_id = APP_MODUAL_VOICE_DETECTOR;
|
||||
msg.msg_body.message_id = id;
|
||||
msg.msg_body.message_ptr = evt;
|
||||
|
||||
app_mailbox_put(&msg);
|
||||
app_mailbox_put(&msg);
|
||||
}
|
||||
|
||||
static void voice_detector_wakeup_system(int state, void *param)
|
||||
{
|
||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||
static void voice_detector_wakeup_system(int state, void *param) {
|
||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
||||
app_voice_detector_send_event(id, VOICE_DET_EVT_AUD_CAP_START);
|
||||
}
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
||||
app_voice_detector_send_event(id, VOICE_DET_EVT_AUD_CAP_START);
|
||||
}
|
||||
|
||||
APP_VD_LOG("%s, state=%d", __func__, state);
|
||||
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
||||
APP_VD_LOG("%s, state=%d", __func__, state);
|
||||
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
||||
}
|
||||
|
||||
static void voice_not_detector_wakeup_system(int state, void *param)
|
||||
{
|
||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||
static void voice_not_detector_wakeup_system(int state, void *param) {
|
||||
enum voice_detector_id id = VOICE_DETECTOR_ID_0;
|
||||
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
||||
app_voice_detector_send_event(id, VOICE_DET_EVT_VAD_START);
|
||||
}
|
||||
if (voice_detector_query_status(id) == VOICE_DET_STATE_VAD_START) {
|
||||
app_voice_detector_send_event(id, VOICE_DET_EVT_VAD_START);
|
||||
}
|
||||
|
||||
APP_VD_LOG("%s, state=%d", __func__, state);
|
||||
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
||||
APP_VD_LOG("%s, state=%d", __func__, state);
|
||||
// APP_VD_LOG("cpu freq=%d", hal_sys_timer_calc_cpu_freq(5,0));
|
||||
}
|
||||
|
||||
void app_voice_detector_init(void)
|
||||
{
|
||||
APP_VD_LOG("%s", __func__);
|
||||
void app_voice_detector_init(void) {
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
if(vd_mutex_id == NULL){
|
||||
vd_mutex_id = osMutexCreate((osMutex(vd_mutex)));
|
||||
app_set_threadhandle(APP_MODUAL_VOICE_DETECTOR, app_voice_detector_process);
|
||||
}
|
||||
if (vd_mutex_id == NULL) {
|
||||
vd_mutex_id = osMutexCreate((osMutex(vd_mutex)));
|
||||
app_set_threadhandle(APP_MODUAL_VOICE_DETECTOR, app_voice_detector_process);
|
||||
}
|
||||
}
|
||||
|
||||
int app_voice_detector_open(enum voice_detector_id id, enum AUD_VAD_TYPE_T vad_type)
|
||||
{
|
||||
int r;
|
||||
int app_voice_detector_open(enum voice_detector_id id,
|
||||
enum AUD_VAD_TYPE_T vad_type) {
|
||||
int r;
|
||||
|
||||
APP_VD_LOG("%s", __func__);
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_open(id, vad_type);
|
||||
if (!r) {
|
||||
voice_detector_setup_callback(id, VOICE_DET_FIND_APP,
|
||||
voice_detector_wakeup_system, NULL);
|
||||
voice_detector_setup_callback(id, VOICE_DET_NOT_FIND_APP,
|
||||
voice_not_detector_wakeup_system, NULL);
|
||||
}
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_open(id, vad_type);
|
||||
if (!r) {
|
||||
voice_detector_setup_callback(id, VOICE_DET_FIND_APP,
|
||||
voice_detector_wakeup_system, NULL);
|
||||
voice_detector_setup_callback(id, VOICE_DET_NOT_FIND_APP,
|
||||
voice_not_detector_wakeup_system, NULL);
|
||||
}
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
}
|
||||
|
||||
int app_voice_detector_setup_vad(enum voice_detector_id id,
|
||||
struct AUD_VAD_CONFIG_T *conf)
|
||||
{
|
||||
int r;
|
||||
struct AUD_VAD_CONFIG_T *conf) {
|
||||
int r;
|
||||
|
||||
APP_VD_LOG("%s", __func__);
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_setup_vad(id, conf);
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_setup_vad(id, conf);
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
}
|
||||
|
||||
int app_voice_detector_setup_stream(enum voice_detector_id id,
|
||||
enum AUD_STREAM_T stream_id,
|
||||
struct AF_STREAM_CONFIG_T *stream)
|
||||
{
|
||||
int r;
|
||||
struct AF_STREAM_CONFIG_T *stream) {
|
||||
int r;
|
||||
|
||||
APP_VD_LOG("%s", __func__);
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_setup_stream(id, stream_id, stream);
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_setup_stream(id, stream_id, stream);
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
}
|
||||
|
||||
int app_voice_detector_setup_callback(enum voice_detector_id id,
|
||||
enum voice_detector_cb_id func_id,
|
||||
voice_detector_cb_t func,
|
||||
void *param)
|
||||
{
|
||||
int r;
|
||||
voice_detector_cb_t func, void *param) {
|
||||
int r;
|
||||
|
||||
APP_VD_LOG("%s", __func__);
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_setup_callback(id, func_id, func, param);
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
if (!vd_mutex_id) {
|
||||
APP_VD_LOG("%s, mutex is null", __func__);
|
||||
return -1;
|
||||
}
|
||||
osMutexWait(vd_mutex_id, osWaitForever);
|
||||
r = voice_detector_setup_callback(id, func_id, func, param);
|
||||
osMutexRelease(vd_mutex_id);
|
||||
return r;
|
||||
}
|
||||
|
||||
int app_voice_detector_send_event(enum voice_detector_id id,
|
||||
enum voice_detector_evt evt)
|
||||
{
|
||||
APP_VD_LOG("%s, id=%d, evt=%d", __func__, id, evt);
|
||||
enum voice_detector_evt evt) {
|
||||
APP_VD_LOG("%s, id=%d, evt=%d", __func__, id, evt);
|
||||
|
||||
voice_detector_send_msg(id, evt);
|
||||
return 0;
|
||||
voice_detector_send_msg(id, evt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void app_voice_detector_close(enum voice_detector_id id)
|
||||
{
|
||||
APP_VD_LOG("%s", __func__);
|
||||
void app_voice_detector_close(enum voice_detector_id id) {
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
voice_detector_send_msg(id, VOICE_DET_EVT_CLOSE);
|
||||
voice_detector_send_msg(id, VOICE_DET_EVT_CLOSE);
|
||||
}
|
||||
|
||||
void app_voice_detector_capture_start(enum voice_detector_id id)
|
||||
{
|
||||
APP_VD_LOG("%s", __func__);
|
||||
void app_voice_detector_capture_start(enum voice_detector_id id) {
|
||||
APP_VD_LOG("%s", __func__);
|
||||
|
||||
voice_detector_send_msg(id, VOICE_DET_EVT_AUD_CAP_START);
|
||||
voice_detector_send_msg(id, VOICE_DET_EVT_AUD_CAP_START);
|
||||
}
|
||||
|
||||
void app_voice_detector_get_vad_data_info(enum voice_detector_id id,
|
||||
struct CODEC_VAD_BUF_INFO_T* vad_buf_info)
|
||||
{
|
||||
voice_detector_get_vad_data_info(id, vad_buf_info);
|
||||
void app_voice_detector_get_vad_data_info(
|
||||
enum voice_detector_id id, struct CODEC_VAD_BUF_INFO_T *vad_buf_info) {
|
||||
voice_detector_get_vad_data_info(id, vad_buf_info);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,18 +13,18 @@
|
|||
* trademark and other intellectual property rights.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include "cmsis_os.h"
|
||||
#include "stdbool.h"
|
||||
#include "hal_trace.h"
|
||||
#include "app_pwl.h"
|
||||
#include "app_status_ind.h"
|
||||
#include "app_pwl.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "hal_trace.h"
|
||||
#include "stdbool.h"
|
||||
#include "string.h"
|
||||
|
||||
static APP_STATUS_INDICATION_T app_status = APP_STATUS_INDICATION_NUM;
|
||||
static APP_STATUS_INDICATION_T app_status_ind_filter = APP_STATUS_INDICATION_NUM;
|
||||
static APP_STATUS_INDICATION_T app_status_ind_filter =
|
||||
APP_STATUS_INDICATION_NUM;
|
||||
|
||||
const char *app_status_indication_str[] =
|
||||
{
|
||||
const char *app_status_indication_str[] = {
|
||||
"[POWERON]",
|
||||
"[INITIAL]",
|
||||
"[PAGESCAN]",
|
||||
|
@ -64,239 +64,229 @@ const char *app_status_indication_str[] =
|
|||
"[TILE_FIND]",
|
||||
};
|
||||
|
||||
const char *status2str(uint16_t status) {
|
||||
const char *str = NULL;
|
||||
|
||||
const char *status2str(uint16_t status)
|
||||
{
|
||||
const char *str = NULL;
|
||||
if (status >= 0 && status < APP_STATUS_INDICATION_NUM) {
|
||||
str = app_status_indication_str[status];
|
||||
} else {
|
||||
str = "[UNKNOWN]";
|
||||
}
|
||||
|
||||
if (status >= 0 && status < APP_STATUS_INDICATION_NUM)
|
||||
{
|
||||
str = app_status_indication_str[status];
|
||||
}
|
||||
else
|
||||
{
|
||||
str = "[UNKNOWN]";
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
int app_status_indication_filter_set(APP_STATUS_INDICATION_T status)
|
||||
{
|
||||
app_status_ind_filter = status;
|
||||
int app_status_indication_filter_set(APP_STATUS_INDICATION_T status) {
|
||||
app_status_ind_filter = status;
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_STATUS_INDICATION_T app_status_indication_get(void) { return app_status; }
|
||||
|
||||
int app_status_indication_set(APP_STATUS_INDICATION_T status) {
|
||||
struct APP_PWL_CFG_T cfg0;
|
||||
struct APP_PWL_CFG_T cfg1;
|
||||
|
||||
if (app_status == status)
|
||||
return 0;
|
||||
}
|
||||
|
||||
APP_STATUS_INDICATION_T app_status_indication_get(void)
|
||||
{
|
||||
return app_status;
|
||||
}
|
||||
|
||||
int app_status_indication_set(APP_STATUS_INDICATION_T status)
|
||||
{
|
||||
struct APP_PWL_CFG_T cfg0;
|
||||
struct APP_PWL_CFG_T cfg1;
|
||||
|
||||
if (app_status == status)
|
||||
return 0;
|
||||
|
||||
if (app_status_ind_filter == status)
|
||||
return 0;
|
||||
|
||||
TRACE(2,"%s %d",__func__, status);
|
||||
|
||||
app_status = status;
|
||||
memset(&cfg0, 0, sizeof(struct APP_PWL_CFG_T));
|
||||
memset(&cfg1, 0, sizeof(struct APP_PWL_CFG_T));
|
||||
app_pwl_stop(APP_PWL_ID_0);
|
||||
app_pwl_stop(APP_PWL_ID_1);
|
||||
switch (status) {
|
||||
case APP_STATUS_INDICATION_POWERON:
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (3000);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (200);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = false;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
|
||||
break;
|
||||
case APP_STATUS_INDICATION_INITIAL:
|
||||
break;
|
||||
case APP_STATUS_INDICATION_PAGESCAN:
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (8000);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_BOTHSCAN:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 1;
|
||||
cfg0.part[1].time = (300);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (300);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (300);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CONNECTING:
|
||||
// LED's alternating Red/Blue
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (300);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (300);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (300);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CONNECTED:
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (500);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (3000);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (500);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (3000);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 0;
|
||||
cfg1.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CHARGING:
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (5000);
|
||||
cfg1.parttotal = 1;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_FULLCHARGE:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (5000);
|
||||
cfg0.parttotal = 1;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = false;
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_POWEROFF:
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (100);
|
||||
cfg1.parttotal = 1;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = false;
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (100);
|
||||
cfg0.parttotal = 1;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = false;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CHARGENEED:
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (500);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (2000);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_TESTMODE:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 1;
|
||||
cfg0.part[1].time = (300);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (300);
|
||||
cfg1.part[1].level = 1;
|
||||
cfg1.part[1].time = (300);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_TESTMODE1:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (1000);
|
||||
cfg0.part[1].level = 1;
|
||||
cfg0.part[1].time = (1000);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (1000);
|
||||
cfg1.part[1].level = 1;
|
||||
cfg1.part[1].time = (1000);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (app_status_ind_filter == status)
|
||||
return 0;
|
||||
|
||||
TRACE(2, "%s %d", __func__, status);
|
||||
|
||||
app_status = status;
|
||||
memset(&cfg0, 0, sizeof(struct APP_PWL_CFG_T));
|
||||
memset(&cfg1, 0, sizeof(struct APP_PWL_CFG_T));
|
||||
app_pwl_stop(APP_PWL_ID_0);
|
||||
app_pwl_stop(APP_PWL_ID_1);
|
||||
switch (status) {
|
||||
case APP_STATUS_INDICATION_POWERON:
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (3000);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (200);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = false;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
|
||||
break;
|
||||
case APP_STATUS_INDICATION_INITIAL:
|
||||
break;
|
||||
case APP_STATUS_INDICATION_PAGESCAN:
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (8000);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_BOTHSCAN:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 1;
|
||||
cfg0.part[1].time = (300);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (300);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (300);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CONNECTING:
|
||||
// LED's alternating Red/Blue
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (300);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (300);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (300);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CONNECTED:
|
||||
cfg0.part[0].level = 1;
|
||||
cfg0.part[0].time = (500);
|
||||
cfg0.part[1].level = 0;
|
||||
cfg0.part[1].time = (3000);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (500);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (3000);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 0;
|
||||
cfg1.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CHARGING:
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (5000);
|
||||
cfg1.parttotal = 1;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_FULLCHARGE:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (5000);
|
||||
cfg0.parttotal = 1;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = false;
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_POWEROFF:
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (100);
|
||||
cfg1.parttotal = 1;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = false;
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (100);
|
||||
cfg0.parttotal = 1;
|
||||
cfg0.startlevel = 1;
|
||||
cfg0.periodic = false;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_CHARGENEED:
|
||||
cfg1.part[0].level = 1;
|
||||
cfg1.part[0].time = (500);
|
||||
cfg1.part[1].level = 0;
|
||||
cfg1.part[1].time = (2000);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_TESTMODE:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (300);
|
||||
cfg0.part[1].level = 1;
|
||||
cfg0.part[1].time = (300);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (300);
|
||||
cfg1.part[1].level = 1;
|
||||
cfg1.part[1].time = (300);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
case APP_STATUS_INDICATION_TESTMODE1:
|
||||
cfg0.part[0].level = 0;
|
||||
cfg0.part[0].time = (1000);
|
||||
cfg0.part[1].level = 1;
|
||||
cfg0.part[1].time = (1000);
|
||||
cfg0.parttotal = 2;
|
||||
cfg0.startlevel = 0;
|
||||
cfg0.periodic = true;
|
||||
|
||||
cfg1.part[0].level = 0;
|
||||
cfg1.part[0].time = (1000);
|
||||
cfg1.part[1].level = 1;
|
||||
cfg1.part[1].time = (1000);
|
||||
cfg1.parttotal = 2;
|
||||
cfg1.startlevel = 1;
|
||||
cfg1.periodic = true;
|
||||
|
||||
app_pwl_setup(APP_PWL_ID_0, &cfg0);
|
||||
app_pwl_start(APP_PWL_ID_0);
|
||||
app_pwl_setup(APP_PWL_ID_1, &cfg1);
|
||||
app_pwl_start(APP_PWL_ID_1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,85 +15,88 @@
|
|||
****************************************************************************/
|
||||
#include "tgt_hardware.h"
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_pinmux_pwl[CFG_HW_PLW_NUM] = {
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_pinmux_pwl[CFG_HW_PLW_NUM] = {};
|
||||
|
||||
//adckey define
|
||||
// adckey define
|
||||
const uint16_t CFG_HW_ADCKEY_MAP_TABLE[CFG_HW_ADCKEY_NUMBER] = {
|
||||
HAL_KEY_CODE_FN9,HAL_KEY_CODE_FN8,HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6,HAL_KEY_CODE_FN5,HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3,HAL_KEY_CODE_FN2,HAL_KEY_CODE_FN1
|
||||
};
|
||||
HAL_KEY_CODE_FN9, HAL_KEY_CODE_FN8, HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6, HAL_KEY_CODE_FN5, HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3, HAL_KEY_CODE_FN2, HAL_KEY_CODE_FN1};
|
||||
|
||||
//gpiokey define
|
||||
const struct HAL_KEY_GPIOKEY_CFG_T cfg_hw_gpio_key_cfg[CFG_HW_GPIOKEY_NUM] = {
|
||||
};
|
||||
// gpiokey define
|
||||
const struct HAL_KEY_GPIOKEY_CFG_T cfg_hw_gpio_key_cfg[CFG_HW_GPIOKEY_NUM] = {};
|
||||
|
||||
//bt config
|
||||
// bt config
|
||||
const char *BT_LOCAL_NAME = TO_STRING(BT_DEV_NAME) "\0";
|
||||
const char *BLE_DEFAULT_NAME = "BES_BLE";
|
||||
|
||||
uint8_t ble_addr[6] = {
|
||||
#ifdef BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
#else
|
||||
0xBE,0x99,0x34,0x45,0x56,0x67
|
||||
0xBE, 0x99, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
uint8_t bt_addr[6] = {
|
||||
#ifdef BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
#else
|
||||
0x1e,0x57,0x34,0x45,0x56,0x67
|
||||
0x1e, 0x57, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
|
||||
//audio config
|
||||
//freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K], [12.5K:15K], [15K:17.5K], [17.5K:20K]}
|
||||
//gain range -12~+12
|
||||
const int8_t cfg_hw_aud_eq_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
// audio config
|
||||
// freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K],
|
||||
// [12.5K:15K], [15K:17.5K], [17.5K:20K]} gain range -12~+12
|
||||
const int8_t cfg_hw_aud_eq_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
|
||||
const struct CODEC_DAC_VOL_T codec_dac_vol[TGT_VOLUME_LEVEL_QTY] = {
|
||||
{TX_PA_GAIN,0x03,-11},
|
||||
{TX_PA_GAIN,0x03,-99},
|
||||
{TX_PA_GAIN,0x03,-45},
|
||||
{TX_PA_GAIN,0x03,-42},
|
||||
{TX_PA_GAIN,0x03,-39},
|
||||
{TX_PA_GAIN,0x03,-36},
|
||||
{TX_PA_GAIN,0x03,-33},
|
||||
{TX_PA_GAIN,0x03,-30},
|
||||
{TX_PA_GAIN,0x03,-27},
|
||||
{TX_PA_GAIN,0x03,-24},
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-18},
|
||||
{TX_PA_GAIN,0x03,-15},
|
||||
{TX_PA_GAIN,0x03,-12},
|
||||
{TX_PA_GAIN,0x03, -9},
|
||||
{TX_PA_GAIN,0x03, -6},
|
||||
{TX_PA_GAIN,0x03, -3},
|
||||
{TX_PA_GAIN,0x03, 0}, //0dBm
|
||||
{TX_PA_GAIN, 0x03, -11}, {TX_PA_GAIN, 0x03, -99},
|
||||
{TX_PA_GAIN, 0x03, -45}, {TX_PA_GAIN, 0x03, -42},
|
||||
{TX_PA_GAIN, 0x03, -39}, {TX_PA_GAIN, 0x03, -36},
|
||||
{TX_PA_GAIN, 0x03, -33}, {TX_PA_GAIN, 0x03, -30},
|
||||
{TX_PA_GAIN, 0x03, -27}, {TX_PA_GAIN, 0x03, -24},
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -18},
|
||||
{TX_PA_GAIN, 0x03, -15}, {TX_PA_GAIN, 0x03, -12},
|
||||
{TX_PA_GAIN, 0x03, -9}, {TX_PA_GAIN, 0x03, -6},
|
||||
{TX_PA_GAIN, 0x03, -3}, {TX_PA_GAIN, 0x03, 0}, // 0dBm
|
||||
};
|
||||
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
const struct AUD_IO_PATH_CFG_T cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV, },
|
||||
{ AUD_INPUT_PATH_LINEIN, CFG_HW_AUD_INPUT_PATH_LINEIN_DEV, },
|
||||
{ AUD_INPUT_PATH_VADMIC, CFG_HW_AUD_INPUT_PATH_VADMIC_DEV, },
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
const struct AUD_IO_PATH_CFG_T
|
||||
cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV,
|
||||
},
|
||||
{
|
||||
AUD_INPUT_PATH_LINEIN,
|
||||
CFG_HW_AUD_INPUT_PATH_LINEIN_DEV,
|
||||
},
|
||||
{
|
||||
AUD_INPUT_PATH_VADMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_VADMIC_DEV,
|
||||
},
|
||||
};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_enable_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_detecter_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg =
|
||||
{HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
|
|
@ -14,301 +14,317 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "tgt_hardware.h"
|
||||
#include "iir_process.h"
|
||||
#include "fir_process.h"
|
||||
#include "drc.h"
|
||||
#include "fir_process.h"
|
||||
#include "iir_process.h"
|
||||
#include "limiter.h"
|
||||
#include "spectrum_fix.h"
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_pinmux_pwl[CFG_HW_PLW_NUM] = {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __APP_USE_LED_INDICATE_IBRT_STATUS__
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_ibrt_indication_pinmux_pwl[3] = {
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __KNOWLES
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_pinmux_uart[2] = {
|
||||
{HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL},
|
||||
};
|
||||
#endif
|
||||
|
||||
//adckey define
|
||||
// adckey define
|
||||
const uint16_t CFG_HW_ADCKEY_MAP_TABLE[CFG_HW_ADCKEY_NUMBER] = {
|
||||
#if (CFG_HW_ADCKEY_NUMBER > 0)
|
||||
HAL_KEY_CODE_FN9,HAL_KEY_CODE_FN8,HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6,HAL_KEY_CODE_FN5,HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3,HAL_KEY_CODE_FN2,HAL_KEY_CODE_FN1,
|
||||
HAL_KEY_CODE_FN9, HAL_KEY_CODE_FN8, HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6, HAL_KEY_CODE_FN5, HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3, HAL_KEY_CODE_FN2, HAL_KEY_CODE_FN1,
|
||||
#endif
|
||||
};
|
||||
|
||||
//gpiokey define
|
||||
#define CFG_HW_GPIOKEY_DOWN_LEVEL (0)
|
||||
#define CFG_HW_GPIOKEY_UP_LEVEL (1)
|
||||
// gpiokey define
|
||||
#define CFG_HW_GPIOKEY_DOWN_LEVEL (0)
|
||||
#define CFG_HW_GPIOKEY_UP_LEVEL (1)
|
||||
const struct HAL_KEY_GPIOKEY_CFG_T cfg_hw_gpio_key_cfg[CFG_HW_GPIOKEY_NUM] = {
|
||||
/*
|
||||
#if (CFG_HW_GPIOKEY_NUM > 0)
|
||||
#ifdef BES_AUDIO_DEV_Main_Board_9v0
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN4,{HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN5,{HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN6,{HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#else
|
||||
#ifndef TPORTS_KEY_COEXIST
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#else
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef IS_MULTI_AI_ENABLED
|
||||
//{HAL_KEY_CODE_FN13,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN14,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
/*
|
||||
#if (CFG_HW_GPIOKEY_NUM > 0)
|
||||
#ifdef BES_AUDIO_DEV_Main_Board_9v0
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN4,{HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN5,{HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN6,{HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #else #ifndef
|
||||
TPORTS_KEY_COEXIST {HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3,
|
||||
HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}}, {HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P1_0,
|
||||
HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #else
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #endif #endif
|
||||
#ifdef IS_MULTI_AI_ENABLED
|
||||
//{HAL_KEY_CODE_FN13,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN14,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #endif #endif
|
||||
*/
|
||||
{HAL_KEY_CODE_FN1,
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
};
|
||||
|
||||
//bt config
|
||||
//const char *BT_LOCAL_NAME = TO_STRING(BT_DEV_NAME) "\0";
|
||||
// bt config
|
||||
// const char *BT_LOCAL_NAME = TO_STRING(BT_DEV_NAME) "\0";
|
||||
const char *BT_LOCAL_NAME = "PineBuds Pro";
|
||||
const char *BLE_DEFAULT_NAME = "BES_BLE";
|
||||
uint8_t ble_addr[6] = {
|
||||
#ifdef BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
#else
|
||||
0xBE,0x99,0x34,0x45,0x56,0x67
|
||||
0xBE, 0x99, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
uint8_t bt_addr[6] = {
|
||||
#ifdef BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
#else
|
||||
0x1e,0x57,0x34,0x45,0x56,0x67
|
||||
0x1e, 0x57, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
|
||||
//audio config
|
||||
//freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K], [12.5K:15K], [15K:17.5K], [17.5K:20K]}
|
||||
//gain range -12~+12
|
||||
const int8_t cfg_aud_eq_sbc_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
// audio config
|
||||
// freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K],
|
||||
// [12.5K:15K], [15K:17.5K], [17.5K:20K]} gain range -12~+12
|
||||
const int8_t cfg_aud_eq_sbc_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
|
||||
const struct CODEC_DAC_VOL_T codec_dac_vol[TGT_VOLUME_LEVEL_QTY] = {
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-99},
|
||||
{TX_PA_GAIN,0x03,-45},
|
||||
{TX_PA_GAIN,0x03,-42},
|
||||
{TX_PA_GAIN,0x03,-39},
|
||||
{TX_PA_GAIN,0x03,-36},
|
||||
{TX_PA_GAIN,0x03,-33},
|
||||
{TX_PA_GAIN,0x03,-30},
|
||||
{TX_PA_GAIN,0x03,-27},
|
||||
{TX_PA_GAIN,0x03,-24},
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-18},
|
||||
{TX_PA_GAIN,0x03,-15},
|
||||
{TX_PA_GAIN,0x03,-12},
|
||||
{TX_PA_GAIN,0x03, -9},
|
||||
{TX_PA_GAIN,0x03, -6},
|
||||
{TX_PA_GAIN,0x03, -3},
|
||||
{TX_PA_GAIN,0x03, 0}, //0dBm
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -99},
|
||||
{TX_PA_GAIN, 0x03, -45}, {TX_PA_GAIN, 0x03, -42},
|
||||
{TX_PA_GAIN, 0x03, -39}, {TX_PA_GAIN, 0x03, -36},
|
||||
{TX_PA_GAIN, 0x03, -33}, {TX_PA_GAIN, 0x03, -30},
|
||||
{TX_PA_GAIN, 0x03, -27}, {TX_PA_GAIN, 0x03, -24},
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -18},
|
||||
{TX_PA_GAIN, 0x03, -15}, {TX_PA_GAIN, 0x03, -12},
|
||||
{TX_PA_GAIN, 0x03, -9}, {TX_PA_GAIN, 0x03, -6},
|
||||
{TX_PA_GAIN, 0x03, -3}, {TX_PA_GAIN, 0x03, 0}, // 0dBm
|
||||
};
|
||||
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC2|AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC2 | \
|
||||
AUD_VMIC_MAP_VMIC3)
|
||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 3
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1 | AUD_CHANNEL_MAP_CH4 | \
|
||||
AUD_VMIC_MAP_VMIC1)
|
||||
#else
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#endif
|
||||
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#else
|
||||
#define CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#endif
|
||||
|
||||
const struct AUD_IO_PATH_CFG_T cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
const struct AUD_IO_PATH_CFG_T
|
||||
cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
#if defined(SPEECH_TX_AEC_CODEC_REF)
|
||||
// NOTE: If enable Ch5 and CH6, need to add channel_num when setup audioflinger stream
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV | AUD_CHANNEL_MAP_CH4, },
|
||||
// NOTE: If enable Ch5 and CH6, need to add channel_num when setup
|
||||
// audioflinger stream
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV | AUD_CHANNEL_MAP_CH4,
|
||||
},
|
||||
#else
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV,
|
||||
},
|
||||
#endif
|
||||
{ AUD_INPUT_PATH_LINEIN, CFG_HW_AUD_INPUT_PATH_LINEIN_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_LINEIN,
|
||||
CFG_HW_AUD_INPUT_PATH_LINEIN_DEV,
|
||||
},
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
{ AUD_INPUT_PATH_VADMIC, CFG_HW_AUD_INPUT_PATH_VADMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_VADMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_VADMIC_DEV,
|
||||
},
|
||||
#else
|
||||
{ AUD_INPUT_PATH_ASRMIC, CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_ASRMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_enable_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_detecter_cfg = {
|
||||
HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg =
|
||||
{HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
/*
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_INT ={
|
||||
HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
*/
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SDA ={
|
||||
HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SCL ={
|
||||
HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SDA = {
|
||||
HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SCL = {
|
||||
HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const IIR_CFG_T audio_eq_sw_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 5,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, .0, 200, 2},
|
||||
{IIR_TYPE_PEAK, .0, 600, 2},
|
||||
{IIR_TYPE_PEAK, .0, 2000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 6000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 12000.0, 2}
|
||||
}
|
||||
};
|
||||
.param = {{IIR_TYPE_PEAK, .0, 200, 2},
|
||||
{IIR_TYPE_PEAK, .0, 600, 2},
|
||||
{IIR_TYPE_PEAK, .0, 2000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 6000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 12000.0, 2}}};
|
||||
|
||||
const IIR_CFG_T * const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM]={
|
||||
const IIR_CFG_T *const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM] = {
|
||||
&audio_eq_sw_iir_cfg,
|
||||
};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_44p1k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_44p1k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_48k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_48k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_96k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_96k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
|
||||
const FIR_CFG_T * const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM]={
|
||||
const FIR_CFG_T *const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM] = {
|
||||
&audio_eq_hw_fir_cfg_44p1k,
|
||||
&audio_eq_hw_fir_cfg_48k,
|
||||
&audio_eq_hw_fir_cfg_96k,
|
||||
};
|
||||
|
||||
//hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_dac_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
}
|
||||
// hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_dac_iir_cfg = {.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_dac_iir_cfg,
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_dac_iir_cfg,
|
||||
};
|
||||
|
||||
//hardware dac iir eq
|
||||
// hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_adc_iir_adc_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 1,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0.0, 1000.0, 0.7},
|
||||
}
|
||||
{IIR_TYPE_PEAK, 0.0, 1000.0, 0.7},
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_adc_iir_cfg_list[EQ_HW_ADC_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_adc_iir_adc_cfg,
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_adc_iir_cfg_list[EQ_HW_ADC_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_adc_iir_adc_cfg,
|
||||
// hardware iir eq
|
||||
const IIR_CFG_T audio_eq_hw_iir_cfg = {.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, -10.1, 100.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 400.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 700.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 1000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 3000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 5000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 7000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 9000.0, 7},
|
||||
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_iir_cfg,
|
||||
};
|
||||
|
||||
|
||||
|
||||
//hardware iir eq
|
||||
const IIR_CFG_T audio_eq_hw_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, -10.1, 100.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 400.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 700.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 1000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 3000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 5000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 7000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 9000.0, 7},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_iir_cfg,
|
||||
};
|
||||
|
||||
const DrcConfig audio_drc_cfg = {
|
||||
.knee = 3,
|
||||
.filter_type = {14, -1},
|
||||
.band_num = 2,
|
||||
.look_ahead_time = 10,
|
||||
.band_settings = {
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
}
|
||||
};
|
||||
const DrcConfig audio_drc_cfg = {.knee = 3,
|
||||
.filter_type = {14, -1},
|
||||
.band_num = 2,
|
||||
.look_ahead_time = 10,
|
||||
.band_settings = {
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
}};
|
||||
|
||||
const LimiterConfig audio_drc2_cfg = {
|
||||
.knee = 2,
|
||||
|
@ -324,4 +340,3 @@ const SpectrumFixConfig audio_spectrum_cfg = {
|
|||
.freq_num = 9,
|
||||
.freq_list = {200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800},
|
||||
};
|
||||
|
||||
|
|
|
@ -14,188 +14,224 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "tgt_hardware.h"
|
||||
#include "iir_process.h"
|
||||
#include "fir_process.h"
|
||||
#include "drc.h"
|
||||
#include "fir_process.h"
|
||||
#include "iir_process.h"
|
||||
#include "limiter.h"
|
||||
#include "spectrum_fix.h"
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_pinmux_pwl[CFG_HW_PLW_NUM] = {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __APP_USE_LED_INDICATE_IBRT_STATUS__
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_ibrt_indication_pinmux_pwl[3] = {
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __KNOWLES
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_pinmux_uart[2] = {
|
||||
{HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL},
|
||||
};
|
||||
#endif
|
||||
|
||||
//adckey define
|
||||
// adckey define
|
||||
const uint16_t CFG_HW_ADCKEY_MAP_TABLE[CFG_HW_ADCKEY_NUMBER] = {
|
||||
#if (CFG_HW_ADCKEY_NUMBER > 0)
|
||||
HAL_KEY_CODE_FN9,HAL_KEY_CODE_FN8,HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6,HAL_KEY_CODE_FN5,HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3,HAL_KEY_CODE_FN2,HAL_KEY_CODE_FN1,
|
||||
HAL_KEY_CODE_FN9, HAL_KEY_CODE_FN8, HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6, HAL_KEY_CODE_FN5, HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3, HAL_KEY_CODE_FN2, HAL_KEY_CODE_FN1,
|
||||
#endif
|
||||
};
|
||||
|
||||
//gpiokey define
|
||||
#define CFG_HW_GPIOKEY_DOWN_LEVEL (0)
|
||||
#define CFG_HW_GPIOKEY_UP_LEVEL (1)
|
||||
// gpiokey define
|
||||
#define CFG_HW_GPIOKEY_DOWN_LEVEL (0)
|
||||
#define CFG_HW_GPIOKEY_UP_LEVEL (1)
|
||||
const struct HAL_KEY_GPIOKEY_CFG_T cfg_hw_gpio_key_cfg[CFG_HW_GPIOKEY_NUM] = {
|
||||
/*
|
||||
#if (CFG_HW_GPIOKEY_NUM > 0)
|
||||
#ifdef BES_AUDIO_DEV_Main_Board_9v0
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN4,{HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN5,{HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN6,{HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#else
|
||||
#ifndef TPORTS_KEY_COEXIST
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#else
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef IS_MULTI_AI_ENABLED
|
||||
//{HAL_KEY_CODE_FN13,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN14,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
/*
|
||||
#if (CFG_HW_GPIOKEY_NUM > 0)
|
||||
#ifdef BES_AUDIO_DEV_Main_Board_9v0
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN4,{HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN5,{HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN6,{HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #else #ifndef
|
||||
TPORTS_KEY_COEXIST {HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3,
|
||||
HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}}, {HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P1_0,
|
||||
HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #else
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #endif #endif
|
||||
#ifdef IS_MULTI_AI_ENABLED
|
||||
//{HAL_KEY_CODE_FN13,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN14,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #endif #endif
|
||||
*/
|
||||
{HAL_KEY_CODE_FN1,
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
};
|
||||
|
||||
//bt config
|
||||
// bt config
|
||||
const char *BT_LOCAL_NAME = TO_STRING(BT_DEV_NAME) "\0";
|
||||
const char *BLE_DEFAULT_NAME = "BES_BLE";
|
||||
uint8_t ble_addr[6] = {
|
||||
#ifdef BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
#else
|
||||
0xBE,0x99,0x34,0x45,0x56,0x67
|
||||
0xBE, 0x99, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
uint8_t bt_addr[6] = {
|
||||
#ifdef BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
#else
|
||||
0x1e,0x57,0x34,0x45,0x56,0x67
|
||||
0x1e, 0x57, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
|
||||
//audio config
|
||||
//freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K], [12.5K:15K], [15K:17.5K], [17.5K:20K]}
|
||||
//gain range -12~+12
|
||||
const int8_t cfg_aud_eq_sbc_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
// audio config
|
||||
// freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K],
|
||||
// [12.5K:15K], [15K:17.5K], [17.5K:20K]} gain range -12~+12
|
||||
const int8_t cfg_aud_eq_sbc_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
|
||||
const struct CODEC_DAC_VOL_T codec_dac_vol[TGT_VOLUME_LEVEL_QTY] = {
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-99},
|
||||
{TX_PA_GAIN,0x03,-45},
|
||||
{TX_PA_GAIN,0x03,-42},
|
||||
{TX_PA_GAIN,0x03,-39},
|
||||
{TX_PA_GAIN,0x03,-36},
|
||||
{TX_PA_GAIN,0x03,-33},
|
||||
{TX_PA_GAIN,0x03,-30},
|
||||
{TX_PA_GAIN,0x03,-27},
|
||||
{TX_PA_GAIN,0x03,-24},
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-18},
|
||||
{TX_PA_GAIN,0x03,-15},
|
||||
{TX_PA_GAIN,0x03,-12},
|
||||
{TX_PA_GAIN,0x03, -9},
|
||||
{TX_PA_GAIN,0x03, -6},
|
||||
{TX_PA_GAIN,0x03, -3},
|
||||
{TX_PA_GAIN,0x03, 0}, //0dBm
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -99},
|
||||
{TX_PA_GAIN, 0x03, -45}, {TX_PA_GAIN, 0x03, -42},
|
||||
{TX_PA_GAIN, 0x03, -39}, {TX_PA_GAIN, 0x03, -36},
|
||||
{TX_PA_GAIN, 0x03, -33}, {TX_PA_GAIN, 0x03, -30},
|
||||
{TX_PA_GAIN, 0x03, -27}, {TX_PA_GAIN, 0x03, -24},
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -18},
|
||||
{TX_PA_GAIN, 0x03, -15}, {TX_PA_GAIN, 0x03, -12},
|
||||
{TX_PA_GAIN, 0x03, -9}, {TX_PA_GAIN, 0x03, -6},
|
||||
{TX_PA_GAIN, 0x03, -3}, {TX_PA_GAIN, 0x03, 0}, // 0dBm
|
||||
};
|
||||
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC2|AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC2 | \
|
||||
AUD_VMIC_MAP_VMIC3)
|
||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 3
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1 | AUD_CHANNEL_MAP_CH4 | \
|
||||
AUD_VMIC_MAP_VMIC1)
|
||||
#else
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#endif
|
||||
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#else
|
||||
#define CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_VMIC_MAP_VMIC1)
|
||||
#endif
|
||||
|
||||
const struct AUD_IO_PATH_CFG_T cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
const struct AUD_IO_PATH_CFG_T
|
||||
cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
#if defined(SPEECH_TX_AEC_CODEC_REF)
|
||||
// NOTE: If enable Ch5 and CH6, need to add channel_num when setup audioflinger stream
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV | AUD_CHANNEL_MAP_CH4, },
|
||||
// NOTE: If enable Ch5 and CH6, need to add channel_num when setup
|
||||
// audioflinger stream
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV | AUD_CHANNEL_MAP_CH4,
|
||||
},
|
||||
#else
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV,
|
||||
},
|
||||
#endif
|
||||
{ AUD_INPUT_PATH_LINEIN, CFG_HW_AUD_INPUT_PATH_LINEIN_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_LINEIN,
|
||||
CFG_HW_AUD_INPUT_PATH_LINEIN_DEV,
|
||||
},
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
{ AUD_INPUT_PATH_VADMIC, CFG_HW_AUD_INPUT_PATH_VADMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_VADMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_VADMIC_DEV,
|
||||
},
|
||||
#else
|
||||
{ AUD_INPUT_PATH_ASRMIC, CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_ASRMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_enable_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_detecter_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg =
|
||||
{HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_tws_channel_cfg = {
|
||||
HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE//HAL_IOMUX_PIN_P1_5 500:HAL_IOMUX_PIN_P2_5
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_tws_channel_cfg = {
|
||||
HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE // HAL_IOMUX_PIN_P1_5
|
||||
// 500:HAL_IOMUX_PIN_P2_5
|
||||
};
|
||||
/*
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_INT ={
|
||||
HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
*/
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SDA ={
|
||||
HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SDA = {
|
||||
HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SCL ={
|
||||
HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
bool tgt_tws_get_channel_is_right(void)
|
||||
{
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SCL = {
|
||||
HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
bool tgt_tws_get_channel_is_right(void) {
|
||||
#ifdef __FIXED_TWS_EAR_SIDE__
|
||||
return TWS_EAR_SIDE_ROLE;
|
||||
return TWS_EAR_SIDE_ROLE;
|
||||
#else
|
||||
return hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)cfg_hw_tws_channel_cfg.pin);
|
||||
return hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)cfg_hw_tws_channel_cfg.pin);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -203,122 +239,103 @@ const IIR_CFG_T audio_eq_sw_iir_cfg = {
|
|||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 5,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, .0, 200, 2},
|
||||
{IIR_TYPE_PEAK, .0, 600, 2},
|
||||
{IIR_TYPE_PEAK, .0, 2000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 6000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 12000.0, 2}
|
||||
}
|
||||
};
|
||||
.param = {{IIR_TYPE_PEAK, .0, 200, 2},
|
||||
{IIR_TYPE_PEAK, .0, 600, 2},
|
||||
{IIR_TYPE_PEAK, .0, 2000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 6000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 12000.0, 2}}};
|
||||
|
||||
const IIR_CFG_T * const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM]={
|
||||
const IIR_CFG_T *const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM] = {
|
||||
&audio_eq_sw_iir_cfg,
|
||||
};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_44p1k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_44p1k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_48k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_48k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_96k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_96k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
|
||||
const FIR_CFG_T * const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM]={
|
||||
const FIR_CFG_T *const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM] = {
|
||||
&audio_eq_hw_fir_cfg_44p1k,
|
||||
&audio_eq_hw_fir_cfg_48k,
|
||||
&audio_eq_hw_fir_cfg_96k,
|
||||
};
|
||||
|
||||
//hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_dac_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
}
|
||||
// hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_dac_iir_cfg = {.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_dac_iir_cfg,
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_dac_iir_cfg,
|
||||
};
|
||||
|
||||
//hardware dac iir eq
|
||||
// hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_adc_iir_adc_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 1,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0.0, 1000.0, 0.7},
|
||||
}
|
||||
{IIR_TYPE_PEAK, 0.0, 1000.0, 0.7},
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_adc_iir_cfg_list[EQ_HW_ADC_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_adc_iir_adc_cfg,
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_adc_iir_cfg_list[EQ_HW_ADC_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_adc_iir_adc_cfg,
|
||||
// hardware iir eq
|
||||
const IIR_CFG_T audio_eq_hw_iir_cfg = {.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, -10.1, 100.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 400.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 700.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 1000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 3000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 5000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 7000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 9000.0, 7},
|
||||
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_iir_cfg,
|
||||
};
|
||||
|
||||
|
||||
|
||||
//hardware iir eq
|
||||
const IIR_CFG_T audio_eq_hw_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, -10.1, 100.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 400.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 700.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 1000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 3000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 5000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 7000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 9000.0, 7},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_iir_cfg,
|
||||
};
|
||||
|
||||
const DrcConfig audio_drc_cfg = {
|
||||
.knee = 3,
|
||||
.filter_type = {14, -1},
|
||||
.band_num = 2,
|
||||
.look_ahead_time = 10,
|
||||
.band_settings = {
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
}
|
||||
};
|
||||
const DrcConfig audio_drc_cfg = {.knee = 3,
|
||||
.filter_type = {14, -1},
|
||||
.band_num = 2,
|
||||
.look_ahead_time = 10,
|
||||
.band_settings = {
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
}};
|
||||
|
||||
const LimiterConfig audio_drc2_cfg = {
|
||||
.knee = 2,
|
||||
|
@ -334,4 +351,3 @@ const SpectrumFixConfig audio_spectrum_cfg = {
|
|||
.freq_num = 9,
|
||||
.freq_list = {200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800},
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,190 +14,228 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
#include "tgt_hardware.h"
|
||||
#include "iir_process.h"
|
||||
#include "fir_process.h"
|
||||
#include "drc.h"
|
||||
#include "fir_process.h"
|
||||
#include "iir_process.h"
|
||||
#include "limiter.h"
|
||||
#include "spectrum_fix.h"
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_pinmux_pwl[CFG_HW_PLW_NUM] = {
|
||||
#if (CFG_HW_PLW_NUM > 0)
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __APP_USE_LED_INDICATE_IBRT_STATUS__
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_ibrt_indication_pinmux_pwl[3] = {
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT, HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
{HAL_IOMUX_PIN_LED2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VBAT,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE},
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __KNOWLES
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_pinmux_uart[2] = {
|
||||
{HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_2, HAL_IOMUX_FUNC_UART2_RX, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL},
|
||||
{HAL_IOMUX_PIN_P2_3, HAL_IOMUX_FUNC_UART2_TX, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL},
|
||||
};
|
||||
#endif
|
||||
|
||||
//adckey define
|
||||
// adckey define
|
||||
const uint16_t CFG_HW_ADCKEY_MAP_TABLE[CFG_HW_ADCKEY_NUMBER] = {
|
||||
#if (CFG_HW_ADCKEY_NUMBER > 0)
|
||||
HAL_KEY_CODE_FN9,HAL_KEY_CODE_FN8,HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6,HAL_KEY_CODE_FN5,HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3,HAL_KEY_CODE_FN2,HAL_KEY_CODE_FN1,
|
||||
HAL_KEY_CODE_FN9, HAL_KEY_CODE_FN8, HAL_KEY_CODE_FN7,
|
||||
HAL_KEY_CODE_FN6, HAL_KEY_CODE_FN5, HAL_KEY_CODE_FN4,
|
||||
HAL_KEY_CODE_FN3, HAL_KEY_CODE_FN2, HAL_KEY_CODE_FN1,
|
||||
#endif
|
||||
};
|
||||
|
||||
//gpiokey define
|
||||
#define CFG_HW_GPIOKEY_DOWN_LEVEL (0)
|
||||
#define CFG_HW_GPIOKEY_UP_LEVEL (1)
|
||||
// gpiokey define
|
||||
#define CFG_HW_GPIOKEY_DOWN_LEVEL (0)
|
||||
#define CFG_HW_GPIOKEY_UP_LEVEL (1)
|
||||
const struct HAL_KEY_GPIOKEY_CFG_T cfg_hw_gpio_key_cfg[CFG_HW_GPIOKEY_NUM] = {
|
||||
/*
|
||||
#if (CFG_HW_GPIOKEY_NUM > 0)
|
||||
#ifdef BES_AUDIO_DEV_Main_Board_9v0
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN4,{HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN5,{HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN6,{HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#else
|
||||
#ifndef TPORTS_KEY_COEXIST
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#else
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef IS_MULTI_AI_ENABLED
|
||||
//{HAL_KEY_CODE_FN13,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN14,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
/*
|
||||
#if (CFG_HW_GPIOKEY_NUM > 0)
|
||||
#ifdef BES_AUDIO_DEV_Main_Board_9v0
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P0_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P0_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P0_1, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN4,{HAL_IOMUX_PIN_P0_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN5,{HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN6,{HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #else #ifndef
|
||||
TPORTS_KEY_COEXIST {HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3,
|
||||
HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}}, {HAL_KEY_CODE_FN2,{HAL_IOMUX_PIN_P1_0,
|
||||
HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
// {HAL_KEY_CODE_FN3,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #else
|
||||
{HAL_KEY_CODE_FN1,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
{HAL_KEY_CODE_FN15,{HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #endif #endif
|
||||
#ifdef IS_MULTI_AI_ENABLED
|
||||
//{HAL_KEY_CODE_FN13,{HAL_IOMUX_PIN_P1_3, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
//{HAL_KEY_CODE_FN14,{HAL_IOMUX_PIN_P1_2, HAL_IOMUX_FUNC_AS_GPIO,
|
||||
HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE}}, #endif #endif
|
||||
*/
|
||||
{HAL_KEY_CODE_FN1,
|
||||
{HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE}},
|
||||
};
|
||||
|
||||
//bt config
|
||||
// bt config
|
||||
const char *BT_LOCAL_NAME = TO_STRING(BT_DEV_NAME) "\0";
|
||||
const char *BLE_DEFAULT_NAME = "BES_BLE";
|
||||
uint8_t ble_addr[6] = {
|
||||
#ifdef BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
BLE_DEV_ADDR
|
||||
#else
|
||||
0xBE,0x99,0x34,0x45,0x56,0x67
|
||||
0xBE, 0x99, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
uint8_t bt_addr[6] = {
|
||||
#ifdef BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
BT_DEV_ADDR
|
||||
#else
|
||||
0x1e,0x57,0x34,0x45,0x56,0x67
|
||||
0x1e, 0x57, 0x34, 0x45,
|
||||
0x56, 0x67
|
||||
#endif
|
||||
};
|
||||
|
||||
//audio config
|
||||
//freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K], [12.5K:15K], [15K:17.5K], [17.5K:20K]}
|
||||
//gain range -12~+12
|
||||
const int8_t cfg_aud_eq_sbc_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
// audio config
|
||||
// freq bands range {[0k:2.5K], [2.5k:5K], [5k:7.5K], [7.5K:10K], [10K:12.5K],
|
||||
// [12.5K:15K], [15K:17.5K], [17.5K:20K]} gain range -12~+12
|
||||
const int8_t cfg_aud_eq_sbc_band_settings[CFG_HW_AUD_EQ_NUM_BANDS] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
#define TX_PA_GAIN CODEC_TX_PA_GAIN_DEFAULT
|
||||
|
||||
const struct CODEC_DAC_VOL_T codec_dac_vol[TGT_VOLUME_LEVEL_QTY] = {
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-99},
|
||||
{TX_PA_GAIN,0x03,-45},
|
||||
{TX_PA_GAIN,0x03,-42},
|
||||
{TX_PA_GAIN,0x03,-39},
|
||||
{TX_PA_GAIN,0x03,-36},
|
||||
{TX_PA_GAIN,0x03,-33},
|
||||
{TX_PA_GAIN,0x03,-30},
|
||||
{TX_PA_GAIN,0x03,-27},
|
||||
{TX_PA_GAIN,0x03,-24},
|
||||
{TX_PA_GAIN,0x03,-21},
|
||||
{TX_PA_GAIN,0x03,-18},
|
||||
{TX_PA_GAIN,0x03,-15},
|
||||
{TX_PA_GAIN,0x03,-12},
|
||||
{TX_PA_GAIN,0x03, -9},
|
||||
{TX_PA_GAIN,0x03, -6},
|
||||
{TX_PA_GAIN,0x03, -3},
|
||||
{TX_PA_GAIN,0x03, 0}, //0dBm
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -99},
|
||||
{TX_PA_GAIN, 0x03, -45}, {TX_PA_GAIN, 0x03, -42},
|
||||
{TX_PA_GAIN, 0x03, -39}, {TX_PA_GAIN, 0x03, -36},
|
||||
{TX_PA_GAIN, 0x03, -33}, {TX_PA_GAIN, 0x03, -30},
|
||||
{TX_PA_GAIN, 0x03, -27}, {TX_PA_GAIN, 0x03, -24},
|
||||
{TX_PA_GAIN, 0x03, -21}, {TX_PA_GAIN, 0x03, -18},
|
||||
{TX_PA_GAIN, 0x03, -15}, {TX_PA_GAIN, 0x03, -12},
|
||||
{TX_PA_GAIN, 0x03, -9}, {TX_PA_GAIN, 0x03, -6},
|
||||
{TX_PA_GAIN, 0x03, -3}, {TX_PA_GAIN, 0x03, 0}, // 0dBm
|
||||
};
|
||||
|
||||
#if SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 2
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC2|AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC2 | \
|
||||
AUD_VMIC_MAP_VMIC3)
|
||||
#elif SPEECH_CODEC_CAPTURE_CHANNEL_NUM == 3
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1 | AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1 | AUD_CHANNEL_MAP_CH4 | \
|
||||
AUD_VMIC_MAP_VMIC1)
|
||||
#else
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#endif
|
||||
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV (AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_LINEIN_DEV \
|
||||
(AUD_CHANNEL_MAP_CH0 | AUD_CHANNEL_MAP_CH1)
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#define CFG_HW_AUD_INPUT_PATH_VADMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC1)
|
||||
#else
|
||||
#define CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV (AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#define CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV \
|
||||
(AUD_CHANNEL_MAP_CH4 | AUD_VMIC_MAP_VMIC3)
|
||||
#endif
|
||||
|
||||
const struct AUD_IO_PATH_CFG_T cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
const struct AUD_IO_PATH_CFG_T
|
||||
cfg_audio_input_path_cfg[CFG_HW_AUD_INPUT_PATH_NUM] = {
|
||||
#if defined(SPEECH_TX_AEC_CODEC_REF)
|
||||
// NOTE: If enable Ch5 and CH6, need to add channel_num when setup audioflinger stream
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV | AUD_CHANNEL_MAP_CH4, },
|
||||
// NOTE: If enable Ch5 and CH6, need to add channel_num when setup
|
||||
// audioflinger stream
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV | AUD_CHANNEL_MAP_CH4,
|
||||
},
|
||||
#else
|
||||
{ AUD_INPUT_PATH_MAINMIC, CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_MAINMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_MAINMIC_DEV,
|
||||
},
|
||||
#endif
|
||||
{ AUD_INPUT_PATH_LINEIN, CFG_HW_AUD_INPUT_PATH_LINEIN_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_LINEIN,
|
||||
CFG_HW_AUD_INPUT_PATH_LINEIN_DEV,
|
||||
},
|
||||
#ifdef VOICE_DETECTOR_EN
|
||||
{ AUD_INPUT_PATH_VADMIC, CFG_HW_AUD_INPUT_PATH_VADMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_VADMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_VADMIC_DEV,
|
||||
},
|
||||
#else
|
||||
{ AUD_INPUT_PATH_ASRMIC, CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV, },
|
||||
{
|
||||
AUD_INPUT_PATH_ASRMIC,
|
||||
CFG_HW_AUD_INPUT_PATH_ASRMIC_DEV,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP MuteOutPwl ={
|
||||
HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_NOPULL
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP MuteOutPwl = {
|
||||
HAL_IOMUX_PIN_P1_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_NOPULL};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_enable_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_detecter_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg = {
|
||||
HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP app_battery_ext_charger_indicator_cfg =
|
||||
{HAL_IOMUX_PIN_NUM, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_tws_channel_cfg = {
|
||||
HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE//HAL_IOMUX_PIN_P1_5 500:HAL_IOMUX_PIN_P2_5
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP cfg_hw_tws_channel_cfg = {
|
||||
HAL_IOMUX_PIN_P1_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE // HAL_IOMUX_PIN_P1_5
|
||||
// 500:HAL_IOMUX_PIN_P2_5
|
||||
};
|
||||
/*
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_INT ={
|
||||
HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
HAL_IOMUX_PIN_P1_5, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
*/
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SDA ={
|
||||
HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SDA = {
|
||||
HAL_IOMUX_PIN_P2_1, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SCL ={
|
||||
HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO, HAL_IOMUX_PIN_PULLUP_ENABLE
|
||||
};
|
||||
bool tgt_tws_get_channel_is_right(void)
|
||||
{
|
||||
const struct HAL_IOMUX_PIN_FUNCTION_MAP TOUCH_I2C_SCL = {
|
||||
HAL_IOMUX_PIN_P2_0, HAL_IOMUX_FUNC_AS_GPIO, HAL_IOMUX_PIN_VOLTAGE_VIO,
|
||||
HAL_IOMUX_PIN_PULLUP_ENABLE};
|
||||
bool tgt_tws_get_channel_is_right(void) {
|
||||
#ifdef __FIXED_TWS_EAR_SIDE__
|
||||
return TWS_EAR_SIDE_ROLE;
|
||||
return TWS_EAR_SIDE_ROLE;
|
||||
#else
|
||||
return hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)cfg_hw_tws_channel_cfg.pin);
|
||||
return hal_gpio_pin_get_val((enum HAL_GPIO_PIN_T)cfg_hw_tws_channel_cfg.pin);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -205,122 +243,103 @@ const IIR_CFG_T audio_eq_sw_iir_cfg = {
|
|||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 5,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, .0, 200, 2},
|
||||
{IIR_TYPE_PEAK, .0, 600, 2},
|
||||
{IIR_TYPE_PEAK, .0, 2000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 6000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 12000.0, 2}
|
||||
}
|
||||
};
|
||||
.param = {{IIR_TYPE_PEAK, .0, 200, 2},
|
||||
{IIR_TYPE_PEAK, .0, 600, 2},
|
||||
{IIR_TYPE_PEAK, .0, 2000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 6000.0, 2},
|
||||
{IIR_TYPE_PEAK, .0, 12000.0, 2}}};
|
||||
|
||||
const IIR_CFG_T * const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM]={
|
||||
const IIR_CFG_T *const audio_eq_sw_iir_cfg_list[EQ_SW_IIR_LIST_NUM] = {
|
||||
&audio_eq_sw_iir_cfg,
|
||||
};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_44p1k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_44p1k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_48k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_48k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_96k = {.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef = {
|
||||
(1 << 23) - 1,
|
||||
}};
|
||||
|
||||
const FIR_CFG_T audio_eq_hw_fir_cfg_96k = {
|
||||
.gain = 0.0f,
|
||||
.len = 384,
|
||||
.coef =
|
||||
{
|
||||
(1<<23)-1,
|
||||
}
|
||||
};
|
||||
|
||||
const FIR_CFG_T * const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM]={
|
||||
const FIR_CFG_T *const audio_eq_hw_fir_cfg_list[EQ_HW_FIR_LIST_NUM] = {
|
||||
&audio_eq_hw_fir_cfg_44p1k,
|
||||
&audio_eq_hw_fir_cfg_48k,
|
||||
&audio_eq_hw_fir_cfg_96k,
|
||||
};
|
||||
|
||||
//hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_dac_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
}
|
||||
// hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_dac_iir_cfg = {.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
{IIR_TYPE_PEAK, 0, 1000.0, 0.7},
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_dac_iir_cfg,
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_dac_iir_cfg_list[EQ_HW_DAC_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_dac_iir_cfg,
|
||||
};
|
||||
|
||||
//hardware dac iir eq
|
||||
// hardware dac iir eq
|
||||
const IIR_CFG_T audio_eq_hw_adc_iir_adc_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 1,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, 0.0, 1000.0, 0.7},
|
||||
}
|
||||
{IIR_TYPE_PEAK, 0.0, 1000.0, 0.7},
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_adc_iir_cfg_list[EQ_HW_ADC_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_adc_iir_adc_cfg,
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_adc_iir_cfg_list[EQ_HW_ADC_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_adc_iir_adc_cfg,
|
||||
// hardware iir eq
|
||||
const IIR_CFG_T audio_eq_hw_iir_cfg = {.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, -10.1, 100.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 400.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 700.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 1000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 3000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 5000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 7000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 9000.0, 7},
|
||||
|
||||
}};
|
||||
|
||||
const IIR_CFG_T *const POSSIBLY_UNUSED
|
||||
audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM] = {
|
||||
&audio_eq_hw_iir_cfg,
|
||||
};
|
||||
|
||||
|
||||
|
||||
//hardware iir eq
|
||||
const IIR_CFG_T audio_eq_hw_iir_cfg = {
|
||||
.gain0 = 0,
|
||||
.gain1 = 0,
|
||||
.num = 8,
|
||||
.param = {
|
||||
{IIR_TYPE_PEAK, -10.1, 100.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 400.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 700.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 1000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 3000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 5000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 7000.0, 7},
|
||||
{IIR_TYPE_PEAK, -10.1, 9000.0, 7},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const IIR_CFG_T * const POSSIBLY_UNUSED audio_eq_hw_iir_cfg_list[EQ_HW_IIR_LIST_NUM]={
|
||||
&audio_eq_hw_iir_cfg,
|
||||
};
|
||||
|
||||
const DrcConfig audio_drc_cfg = {
|
||||
.knee = 3,
|
||||
.filter_type = {14, -1},
|
||||
.band_num = 2,
|
||||
.look_ahead_time = 10,
|
||||
.band_settings = {
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
}
|
||||
};
|
||||
const DrcConfig audio_drc_cfg = {.knee = 3,
|
||||
.filter_type = {14, -1},
|
||||
.band_num = 2,
|
||||
.look_ahead_time = 10,
|
||||
.band_settings = {
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
{-20, 0, 2, 3, 3000, 1},
|
||||
}};
|
||||
|
||||
const LimiterConfig audio_drc2_cfg = {
|
||||
.knee = 2,
|
||||
|
@ -336,4 +355,3 @@ const SpectrumFixConfig audio_spectrum_cfg = {
|
|||
.freq_num = 9,
|
||||
.freq_list = {200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800},
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -60,20 +60,15 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_abs_f32(
|
||||
const float32_t * pSrc,
|
||||
float32_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_abs_f32(const float32_t *pSrc, float32_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute and store result in destination buffer. */
|
||||
|
@ -99,8 +94,7 @@ void arm_abs_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute and store result in destination buffer. */
|
||||
|
@ -109,7 +103,6 @@ void arm_abs_f32(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,53 +46,50 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
The Q15 value -1 (0x8000) will be saturated to the maximum allowable positive value 0x7FFF.
|
||||
The Q15 value -1 (0x8000) will be saturated to the maximum
|
||||
allowable positive value 0x7FFF.
|
||||
*/
|
||||
|
||||
void arm_abs_q15(
|
||||
const q15_t * pSrc,
|
||||
q15_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q15_t in; /* Temporary input variable */
|
||||
void arm_abs_q15(const q15_t *pSrc, q15_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q15_t in; /* Temporary input variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fff) and store result in destination buffer. */
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fff) and store
|
||||
* result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q15_t)__QSUB16(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t) 0x8000) ? 0x7fff : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t)0x8000) ? 0x7fff : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q15_t)__QSUB16(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t) 0x8000) ? 0x7fff : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t)0x8000) ? 0x7fff : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q15_t)__QSUB16(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t) 0x8000) ? 0x7fff : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t)0x8000) ? 0x7fff : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q15_t)__QSUB16(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t) 0x8000) ? 0x7fff : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t)0x8000) ? 0x7fff : -in);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -109,22 +106,21 @@ void arm_abs_q15(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fff) and store result in destination buffer. */
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fff) and store
|
||||
* result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q15_t)__QSUB16(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t) 0x8000) ? 0x7fff : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q15_t)0x8000) ? 0x7fff : -in);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,50 +46,47 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
The Q31 value -1 (0x80000000) will be saturated to the maximum allowable positive value 0x7FFFFFFF.
|
||||
The Q31 value -1 (0x80000000) will be saturated to the
|
||||
maximum allowable positive value 0x7FFFFFFF.
|
||||
*/
|
||||
|
||||
void arm_abs_q31(
|
||||
const q31_t * pSrc,
|
||||
q31_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t in; /* Temporary variable */
|
||||
void arm_abs_q31(const q31_t *pSrc, q31_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t in; /* Temporary variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fffffff) and store result in destination buffer. */
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fffffff) and
|
||||
* store result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q31_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q31_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q31_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q31_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in);
|
||||
|
@ -109,13 +106,13 @@ void arm_abs_q31(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fffffff) and store result in destination buffer. */
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7fffffff) and
|
||||
* store result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q31_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == INT32_MIN) ? INT32_MAX : -in);
|
||||
|
@ -124,7 +121,6 @@ void arm_abs_q31(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,53 +48,50 @@
|
|||
Input and output buffers should be aligned by 32-bit
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
The Q7 value -1 (0x80) will be saturated to the maximum allowable positive value 0x7F.
|
||||
The Q7 value -1 (0x80) will be saturated to the maximum
|
||||
allowable positive value 0x7F.
|
||||
*/
|
||||
|
||||
void arm_abs_q7(
|
||||
const q7_t * pSrc,
|
||||
q7_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q7_t in; /* Temporary input variable */
|
||||
void arm_abs_q7(const q7_t *pSrc, q7_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q7_t in; /* Temporary input variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7f) and store result in destination buffer. */
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7f) and store
|
||||
* result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q7_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? (q7_t) 0x7f : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t)0x80) ? (q7_t)0x7f : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q7_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? (q7_t) 0x7f : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t)0x80) ? (q7_t)0x7f : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q7_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? (q7_t) 0x7f : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t)0x80) ? (q7_t)0x7f : -in);
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q7_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? (q7_t) 0x7f : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t)0x80) ? (q7_t)0x7f : -in);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -111,22 +108,21 @@ void arm_abs_q7(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = |A| */
|
||||
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7f) and store result in destination buffer. */
|
||||
/* Calculate absolute of input (if -1 then saturated to 0x7f) and store
|
||||
* result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q7_t) __QSUB(0, in);
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (in > 0) ? in : (q7_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t) 0x80) ? (q7_t) 0x7f : -in);
|
||||
*pDst++ = (in > 0) ? in : ((in == (q7_t)0x80) ? (q7_t)0x7f : -in);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,21 +58,16 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_add_f32(
|
||||
const float32_t * pSrcA,
|
||||
const float32_t * pSrcB,
|
||||
float32_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_add_f32(const float32_t *pSrcA, const float32_t *pSrcB,
|
||||
float32_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
/* Add and store result in destination buffer. */
|
||||
|
@ -95,8 +90,7 @@ void arm_add_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
/* Add and store result in destination buffer. */
|
||||
|
@ -105,7 +99,6 @@ void arm_add_f32(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,20 +47,17 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
|
||||
Results outside of the allowable Q15 range [0x8000 0x7FFF]
|
||||
are saturated.
|
||||
*/
|
||||
|
||||
void arm_add_q15(
|
||||
const q15_t * pSrcA,
|
||||
const q15_t * pSrcB,
|
||||
q15_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_add_q15(const q15_t *pSrcA, const q15_t *pSrcB, q15_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t inA1, inA2;
|
||||
q31_t inB1, inB2;
|
||||
#endif
|
||||
|
@ -68,26 +65,25 @@ void arm_add_q15(
|
|||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* read 2 times 2 samples at a time from sourceA */
|
||||
inA1 = read_q15x2_ia ((q15_t **) &pSrcA);
|
||||
inA2 = read_q15x2_ia ((q15_t **) &pSrcA);
|
||||
inA1 = read_q15x2_ia((q15_t **)&pSrcA);
|
||||
inA2 = read_q15x2_ia((q15_t **)&pSrcA);
|
||||
/* read 2 times 2 samples at a time from sourceB */
|
||||
inB1 = read_q15x2_ia ((q15_t **) &pSrcB);
|
||||
inB2 = read_q15x2_ia ((q15_t **) &pSrcB);
|
||||
inB1 = read_q15x2_ia((q15_t **)&pSrcB);
|
||||
inB2 = read_q15x2_ia((q15_t **)&pSrcB);
|
||||
|
||||
/* Add and store 2 times 2 samples at a time */
|
||||
write_q15x2_ia (&pDst, __QADD16(inA1, inB1));
|
||||
write_q15x2_ia (&pDst, __QADD16(inA2, inB2));
|
||||
write_q15x2_ia(&pDst, __QADD16(inA1, inB1));
|
||||
write_q15x2_ia(&pDst, __QADD16(inA2, inB2));
|
||||
#else
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrcA++ + *pSrcB++), 16);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -104,21 +100,19 @@ void arm_add_q15(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
/* Add and store result in destination buffer. */
|
||||
#if defined (ARM_MATH_DSP)
|
||||
*pDst++ = (q15_t) __QADD16(*pSrcA++, *pSrcB++);
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (q15_t)__QADD16(*pSrcA++, *pSrcB++);
|
||||
#else
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrcA++ + *pSrcB++), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrcA++ + *pSrcB++), 16);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,24 +47,20 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
|
||||
Results outside of the allowable Q31 range [0x80000000
|
||||
0x7FFFFFFF] are saturated.
|
||||
*/
|
||||
|
||||
void arm_add_q31(
|
||||
const q31_t * pSrcA,
|
||||
const q31_t * pSrcB,
|
||||
q31_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_add_q31(const q31_t *pSrcA, const q31_t *pSrcB, q31_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
/* Add and store result in destination buffer. */
|
||||
|
@ -90,8 +86,7 @@ void arm_add_q31(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
/* Add and store result in destination buffer. */
|
||||
|
@ -100,7 +95,6 @@ void arm_add_q31(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,34 +47,31 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
|
||||
Results outside of the allowable Q7 range [0x80 0x7F] are
|
||||
saturated.
|
||||
*/
|
||||
|
||||
void arm_add_q7(
|
||||
const q7_t * pSrcA,
|
||||
const q7_t * pSrcB,
|
||||
q7_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_add_q7(const q7_t *pSrcA, const q7_t *pSrcB, q7_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Add and store result in destination buffer (4 samples at a time). */
|
||||
write_q7x4_ia (&pDst, __QADD8 (read_q7x4_ia ((q7_t **) &pSrcA), read_q7x4_ia ((q7_t **) &pSrcB)));
|
||||
write_q7x4_ia(&pDst, __QADD8(read_q7x4_ia((q7_t **)&pSrcA),
|
||||
read_q7x4_ia((q7_t **)&pSrcB)));
|
||||
#else
|
||||
*pDst++ = (q7_t) __SSAT ((q15_t) *pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t) __SSAT ((q15_t) *pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t) __SSAT ((q15_t) *pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t) __SSAT ((q15_t) *pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t)__SSAT((q15_t)*pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t)__SSAT((q15_t)*pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t)__SSAT((q15_t)*pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t)__SSAT((q15_t)*pSrcA++ + *pSrcB++, 8);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -91,17 +88,15 @@ void arm_add_q7(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + B */
|
||||
|
||||
/* Add and store result in destination buffer. */
|
||||
*pDst++ = (q7_t) __SSAT((q15_t) *pSrcA++ + *pSrcB++, 8);
|
||||
*pDst++ = (q7_t)__SSAT((q15_t)*pSrcA++ + *pSrcB++, 8);
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
The vectors are multiplied element-by-element and then summed.
|
||||
|
||||
<pre>
|
||||
sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... + pSrcA[blockSize-1]*pSrcB[blockSize-1]
|
||||
sum = pSrcA[0]*pSrcB[0] + pSrcA[1]*pSrcB[1] + ... +
|
||||
pSrcA[blockSize-1]*pSrcB[blockSize-1]
|
||||
</pre>
|
||||
|
||||
There are separate functions for floating-point, Q7, Q15, and Q31 data types.
|
||||
|
@ -59,23 +60,19 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_dot_prod_f32(
|
||||
const float32_t * pSrcA,
|
||||
const float32_t * pSrcB,
|
||||
uint32_t blockSize,
|
||||
float32_t * result)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
float32_t sum = 0.0f; /* Temporary return variable */
|
||||
void arm_dot_prod_f32(const float32_t *pSrcA, const float32_t *pSrcB,
|
||||
uint32_t blockSize, float32_t *result) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
float32_t sum = 0.0f; /* Temporary return variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
sum += (*pSrcA++) * (*pSrcB++);
|
||||
|
@ -100,9 +97,9 @@ void arm_dot_prod_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
sum += (*pSrcA++) * (*pSrcB++);
|
||||
|
|
|
@ -46,40 +46,38 @@
|
|||
@return none
|
||||
|
||||
@par Scaling and Overflow Behavior
|
||||
The intermediate multiplications are in 1.15 x 1.15 = 2.30 format and these
|
||||
results are added to a 64-bit accumulator in 34.30 format.
|
||||
Nonsaturating additions are used and given that there are 33 guard bits in the accumulator
|
||||
there is no risk of overflow.
|
||||
The return result is in 34.30 format.
|
||||
The intermediate multiplications are in 1.15 x 1.15 = 2.30
|
||||
format and these results are added to a 64-bit accumulator in 34.30 format.
|
||||
Nonsaturating additions are used and given that there are 33
|
||||
guard bits in the accumulator there is no risk of overflow. The return result
|
||||
is in 34.30 format.
|
||||
*/
|
||||
|
||||
void arm_dot_prod_q15(
|
||||
const q15_t * pSrcA,
|
||||
const q15_t * pSrcB,
|
||||
uint32_t blockSize,
|
||||
q63_t * result)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q63_t sum = 0; /* Temporary return variable */
|
||||
void arm_dot_prod_q15(const q15_t *pSrcA, const q15_t *pSrcB,
|
||||
uint32_t blockSize, q63_t *result) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q63_t sum = 0; /* Temporary return variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
sum = __SMLALD(read_q15x2_ia ((q15_t **) &pSrcA), read_q15x2_ia ((q15_t **) &pSrcB), sum);
|
||||
sum = __SMLALD(read_q15x2_ia ((q15_t **) &pSrcA), read_q15x2_ia ((q15_t **) &pSrcB), sum);
|
||||
sum = __SMLALD(read_q15x2_ia((q15_t **)&pSrcA),
|
||||
read_q15x2_ia((q15_t **)&pSrcB), sum);
|
||||
sum = __SMLALD(read_q15x2_ia((q15_t **)&pSrcA),
|
||||
read_q15x2_ia((q15_t **)&pSrcB), sum);
|
||||
#else
|
||||
sum += (q63_t)((q31_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t)*pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t)*pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t)*pSrcA++ * *pSrcB++);
|
||||
sum += (q63_t)((q31_t)*pSrcA++ * *pSrcB++);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -96,16 +94,16 @@ void arm_dot_prod_q15(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
//#if defined (ARM_MATH_DSP)
|
||||
// sum = __SMLALD(*pSrcA++, *pSrcB++, sum);
|
||||
//#else
|
||||
sum += (q63_t)((q31_t) *pSrcA++ * *pSrcB++);
|
||||
//#endif
|
||||
//#if defined (ARM_MATH_DSP)
|
||||
// sum = __SMLALD(*pSrcA++, *pSrcB++, sum);
|
||||
//#else
|
||||
sum += (q63_t)((q31_t)*pSrcA++ * *pSrcB++);
|
||||
//#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
|
|
|
@ -46,40 +46,36 @@
|
|||
@return none
|
||||
|
||||
@par Scaling and Overflow Behavior
|
||||
The intermediate multiplications are in 1.31 x 1.31 = 2.62 format and these
|
||||
are truncated to 2.48 format by discarding the lower 14 bits.
|
||||
The 2.48 result is then added without saturation to a 64-bit accumulator in 16.48 format.
|
||||
There are 15 guard bits in the accumulator and there is no risk of overflow as long as
|
||||
the length of the vectors is less than 2^16 elements.
|
||||
The return result is in 16.48 format.
|
||||
The intermediate multiplications are in 1.31 x 1.31 = 2.62
|
||||
format and these are truncated to 2.48 format by discarding the lower 14 bits.
|
||||
The 2.48 result is then added without saturation to a 64-bit
|
||||
accumulator in 16.48 format. There are 15 guard bits in the accumulator and
|
||||
there is no risk of overflow as long as the length of the vectors is less than
|
||||
2^16 elements. The return result is in 16.48 format.
|
||||
*/
|
||||
|
||||
void arm_dot_prod_q31(
|
||||
const q31_t * pSrcA,
|
||||
const q31_t * pSrcB,
|
||||
uint32_t blockSize,
|
||||
q63_t * result)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q63_t sum = 0; /* Temporary return variable */
|
||||
void arm_dot_prod_q31(const q31_t *pSrcA, const q31_t *pSrcB,
|
||||
uint32_t blockSize, q63_t *result) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q63_t sum = 0; /* Temporary return variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
sum += ((q63_t) *pSrcA++ * *pSrcB++) >> 14U;
|
||||
sum += ((q63_t)*pSrcA++ * *pSrcB++) >> 14U;
|
||||
|
||||
sum += ((q63_t) *pSrcA++ * *pSrcB++) >> 14U;
|
||||
sum += ((q63_t)*pSrcA++ * *pSrcB++) >> 14U;
|
||||
|
||||
sum += ((q63_t) *pSrcA++ * *pSrcB++) >> 14U;
|
||||
sum += ((q63_t)*pSrcA++ * *pSrcB++) >> 14U;
|
||||
|
||||
sum += ((q63_t) *pSrcA++ * *pSrcB++) >> 14U;
|
||||
sum += ((q63_t)*pSrcA++ * *pSrcB++) >> 14U;
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
|
@ -95,12 +91,12 @@ void arm_dot_prod_q31(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
sum += ((q63_t) *pSrcA++ * *pSrcB++) >> 14U;
|
||||
sum += ((q63_t)*pSrcA++ * *pSrcB++) >> 14U;
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
|
|
|
@ -46,41 +46,37 @@
|
|||
@return none
|
||||
|
||||
@par Scaling and Overflow Behavior
|
||||
The intermediate multiplications are in 1.7 x 1.7 = 2.14 format and these
|
||||
results are added to an accumulator in 18.14 format.
|
||||
Nonsaturating additions are used and there is no danger of wrap around as long as
|
||||
the vectors are less than 2^18 elements long.
|
||||
The return result is in 18.14 format.
|
||||
The intermediate multiplications are in 1.7 x 1.7 = 2.14
|
||||
format and these results are added to an accumulator in 18.14 format.
|
||||
Nonsaturating additions are used and there is no danger of
|
||||
wrap around as long as the vectors are less than 2^18 elements long. The
|
||||
return result is in 18.14 format.
|
||||
*/
|
||||
|
||||
void arm_dot_prod_q7(
|
||||
const q7_t * pSrcA,
|
||||
const q7_t * pSrcB,
|
||||
uint32_t blockSize,
|
||||
q31_t * result)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t sum = 0; /* Temporary return variable */
|
||||
void arm_dot_prod_q7(const q7_t *pSrcA, const q7_t *pSrcB, uint32_t blockSize,
|
||||
q31_t *result) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t sum = 0; /* Temporary return variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q31_t input1, input2; /* Temporary variables */
|
||||
q31_t inA1, inA2, inB1, inB2; /* Temporary variables */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t input1, input2; /* Temporary variables */
|
||||
q31_t inA1, inA2, inB1, inB2; /* Temporary variables */
|
||||
#endif
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* read 4 samples at a time from sourceA */
|
||||
input1 = read_q7x4_ia ((q7_t **) &pSrcA);
|
||||
input1 = read_q7x4_ia((q7_t **)&pSrcA);
|
||||
/* read 4 samples at a time from sourceB */
|
||||
input2 = read_q7x4_ia ((q7_t **) &pSrcB);
|
||||
input2 = read_q7x4_ia((q7_t **)&pSrcB);
|
||||
|
||||
/* extract two q7_t samples to q15_t samples */
|
||||
inA1 = __SXTB16(__ROR(input1, 8));
|
||||
|
@ -95,10 +91,10 @@ void arm_dot_prod_q7(
|
|||
sum = __SMLAD(inA1, inB1, sum);
|
||||
sum = __SMLAD(inA2, inB2, sum);
|
||||
#else
|
||||
sum += (q31_t) ((q15_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t) ((q15_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t) ((q15_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t) ((q15_t) *pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t)((q15_t)*pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t)((q15_t)*pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t)((q15_t)*pSrcA++ * *pSrcB++);
|
||||
sum += (q31_t)((q15_t)*pSrcA++ * *pSrcB++);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -115,16 +111,16 @@ void arm_dot_prod_q7(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]* B[blockSize-1] */
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A[0]* B[0] + A[1]* B[1] + A[2]* B[2] + .....+ A[blockSize-1]*
|
||||
* B[blockSize-1] */
|
||||
|
||||
/* Calculate dot product and store result in a temporary buffer. */
|
||||
//#if defined (ARM_MATH_DSP)
|
||||
// sum = __SMLAD(*pSrcA++, *pSrcB++, sum);
|
||||
//#else
|
||||
sum += (q31_t) ((q15_t) *pSrcA++ * *pSrcB++);
|
||||
//#endif
|
||||
//#if defined (ARM_MATH_DSP)
|
||||
// sum = __SMLAD(*pSrcA++, *pSrcB++, sum);
|
||||
//#else
|
||||
sum += (q31_t)((q15_t)*pSrcA++ * *pSrcB++);
|
||||
//#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
|
|
|
@ -58,21 +58,16 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_mult_f32(
|
||||
const float32_t * pSrcA,
|
||||
const float32_t * pSrcB,
|
||||
float32_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_mult_f32(const float32_t *pSrcA, const float32_t *pSrcB,
|
||||
float32_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
/* Multiply inputs and store result in destination buffer. */
|
||||
|
@ -98,8 +93,7 @@ void arm_mult_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
/* Multiply input and store result in destination buffer. */
|
||||
|
@ -108,7 +102,6 @@ void arm_mult_f32(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,68 +47,64 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
|
||||
Results outside of the allowable Q15 range [0x8000 0x7FFF]
|
||||
are saturated.
|
||||
*/
|
||||
|
||||
void arm_mult_q15(
|
||||
const q15_t * pSrcA,
|
||||
const q15_t * pSrcB,
|
||||
q15_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_mult_q15(const q15_t *pSrcA, const q15_t *pSrcB, q15_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q31_t inA1, inA2, inB1, inB2; /* Temporary input variables */
|
||||
q15_t out1, out2, out3, out4; /* Temporary output variables */
|
||||
q31_t mul1, mul2, mul3, mul4; /* Temporary variables */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t inA1, inA2, inB1, inB2; /* Temporary input variables */
|
||||
q15_t out1, out2, out3, out4; /* Temporary output variables */
|
||||
q31_t mul1, mul2, mul3, mul4; /* Temporary variables */
|
||||
#endif
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* read 2 samples at a time from sourceA */
|
||||
inA1 = read_q15x2_ia ((q15_t **) &pSrcA);
|
||||
inA1 = read_q15x2_ia((q15_t **)&pSrcA);
|
||||
/* read 2 samples at a time from sourceB */
|
||||
inB1 = read_q15x2_ia ((q15_t **) &pSrcB);
|
||||
inB1 = read_q15x2_ia((q15_t **)&pSrcB);
|
||||
/* read 2 samples at a time from sourceA */
|
||||
inA2 = read_q15x2_ia ((q15_t **) &pSrcA);
|
||||
inA2 = read_q15x2_ia((q15_t **)&pSrcA);
|
||||
/* read 2 samples at a time from sourceB */
|
||||
inB2 = read_q15x2_ia ((q15_t **) &pSrcB);
|
||||
inB2 = read_q15x2_ia((q15_t **)&pSrcB);
|
||||
|
||||
/* multiply mul = sourceA * sourceB */
|
||||
mul1 = (q31_t) ((q15_t) (inA1 >> 16) * (q15_t) (inB1 >> 16));
|
||||
mul2 = (q31_t) ((q15_t) (inA1 ) * (q15_t) (inB1 ));
|
||||
mul3 = (q31_t) ((q15_t) (inA2 >> 16) * (q15_t) (inB2 >> 16));
|
||||
mul4 = (q31_t) ((q15_t) (inA2 ) * (q15_t) (inB2 ));
|
||||
mul1 = (q31_t)((q15_t)(inA1 >> 16) * (q15_t)(inB1 >> 16));
|
||||
mul2 = (q31_t)((q15_t)(inA1) * (q15_t)(inB1));
|
||||
mul3 = (q31_t)((q15_t)(inA2 >> 16) * (q15_t)(inB2 >> 16));
|
||||
mul4 = (q31_t)((q15_t)(inA2) * (q15_t)(inB2));
|
||||
|
||||
/* saturate result to 16 bit */
|
||||
out1 = (q15_t) __SSAT(mul1 >> 15, 16);
|
||||
out2 = (q15_t) __SSAT(mul2 >> 15, 16);
|
||||
out3 = (q15_t) __SSAT(mul3 >> 15, 16);
|
||||
out4 = (q15_t) __SSAT(mul4 >> 15, 16);
|
||||
out1 = (q15_t)__SSAT(mul1 >> 15, 16);
|
||||
out2 = (q15_t)__SSAT(mul2 >> 15, 16);
|
||||
out3 = (q15_t)__SSAT(mul3 >> 15, 16);
|
||||
out4 = (q15_t)__SSAT(mul4 >> 15, 16);
|
||||
|
||||
/* store result to destination */
|
||||
#ifndef ARM_MATH_BIG_ENDIAN
|
||||
write_q15x2_ia (&pDst, __PKHBT(out2, out1, 16));
|
||||
write_q15x2_ia (&pDst, __PKHBT(out4, out3, 16));
|
||||
write_q15x2_ia(&pDst, __PKHBT(out2, out1, 16));
|
||||
write_q15x2_ia(&pDst, __PKHBT(out4, out3, 16));
|
||||
#else
|
||||
write_q15x2_ia (&pDst, __PKHBT(out1, out2, 16));
|
||||
write_q15x2_ia (&pDst, __PKHBT(out3, out4, 16));
|
||||
write_q15x2_ia(&pDst, __PKHBT(out1, out2, 16));
|
||||
write_q15x2_ia(&pDst, __PKHBT(out3, out4, 16));
|
||||
#endif /* #ifndef ARM_MATH_BIG_ENDIAN */
|
||||
|
||||
#else
|
||||
*pDst++ = (q15_t) __SSAT((((q31_t) (*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t) __SSAT((((q31_t) (*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t) __SSAT((((q31_t) (*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t) __SSAT((((q31_t) (*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t)__SSAT((((q31_t)(*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t)__SSAT((((q31_t)(*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t)__SSAT((((q31_t)(*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t)__SSAT((((q31_t)(*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -125,17 +121,15 @@ void arm_mult_q15(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
/* Multiply inputs and store result in destination buffer. */
|
||||
*pDst++ = (q15_t) __SSAT((((q31_t) (*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
*pDst++ = (q15_t)__SSAT((((q31_t)(*pSrcA++) * (*pSrcB++)) >> 15), 16);
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,41 +47,37 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q31 range[0x80000000 0x7FFFFFFF] are saturated.
|
||||
Results outside of the allowable Q31 range[0x80000000
|
||||
0x7FFFFFFF] are saturated.
|
||||
*/
|
||||
|
||||
void arm_mult_q31(
|
||||
const q31_t * pSrcA,
|
||||
const q31_t * pSrcB,
|
||||
q31_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t out; /* Temporary output variable */
|
||||
void arm_mult_q31(const q31_t *pSrcA, const q31_t *pSrcB, q31_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t out; /* Temporary output variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
/* Multiply inputs and store result in destination buffer. */
|
||||
out = ((q63_t) *pSrcA++ * *pSrcB++) >> 32;
|
||||
out = ((q63_t)*pSrcA++ * *pSrcB++) >> 32;
|
||||
out = __SSAT(out, 31);
|
||||
*pDst++ = out << 1U;
|
||||
|
||||
out = ((q63_t) *pSrcA++ * *pSrcB++) >> 32;
|
||||
out = ((q63_t)*pSrcA++ * *pSrcB++) >> 32;
|
||||
out = __SSAT(out, 31);
|
||||
*pDst++ = out << 1U;
|
||||
|
||||
out = ((q63_t) *pSrcA++ * *pSrcB++) >> 32;
|
||||
out = ((q63_t)*pSrcA++ * *pSrcB++) >> 32;
|
||||
out = __SSAT(out, 31);
|
||||
*pDst++ = out << 1U;
|
||||
|
||||
out = ((q63_t) *pSrcA++ * *pSrcB++) >> 32;
|
||||
out = ((q63_t)*pSrcA++ * *pSrcB++) >> 32;
|
||||
out = __SSAT(out, 31);
|
||||
*pDst++ = out << 1U;
|
||||
|
||||
|
@ -99,19 +95,17 @@ void arm_mult_q31(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
/* Multiply inputs and store result in destination buffer. */
|
||||
out = ((q63_t) *pSrcA++ * *pSrcB++) >> 32;
|
||||
out = ((q63_t)*pSrcA++ * *pSrcB++) >> 32;
|
||||
out = __SSAT(out, 31);
|
||||
*pDst++ = out << 1U;
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,44 +47,40 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
|
||||
Results outside of the allowable Q7 range [0x80 0x7F] are
|
||||
saturated.
|
||||
*/
|
||||
|
||||
void arm_mult_q7(
|
||||
const q7_t * pSrcA,
|
||||
const q7_t * pSrcB,
|
||||
q7_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_mult_q7(const q7_t *pSrcA, const q7_t *pSrcB, q7_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q7_t out1, out2, out3, out4; /* Temporary output variables */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q7_t out1, out2, out3, out4; /* Temporary output variables */
|
||||
#endif
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Multiply inputs and store results in temporary variables */
|
||||
out1 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out2 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out3 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out4 = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out1 = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out2 = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out3 = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
out4 = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
|
||||
/* Pack and store result in destination buffer (in single write) */
|
||||
write_q7x4_ia (&pDst, __PACKq7(out1, out2, out3, out4));
|
||||
write_q7x4_ia(&pDst, __PACKq7(out1, out2, out3, out4));
|
||||
#else
|
||||
*pDst++ = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -101,17 +97,15 @@ void arm_mult_q7(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * B */
|
||||
|
||||
/* Multiply input and store result in destination buffer. */
|
||||
*pDst++ = (q7_t) __SSAT((((q15_t) (*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
*pDst++ = (q7_t)__SSAT((((q15_t)(*pSrcA++) * (*pSrcB++)) >> 7), 8);
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,20 +59,16 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_negate_f32(
|
||||
const float32_t * pSrc,
|
||||
float32_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_negate_f32(const float32_t *pSrc, float32_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
/* Negate and store result in destination buffer. */
|
||||
|
@ -98,8 +94,7 @@ void arm_negate_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
/* Negate and store result in destination buffer. */
|
||||
|
@ -108,7 +103,6 @@ void arm_negate_f32(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,49 +48,45 @@
|
|||
Input and output buffers should be aligned by 32-bit
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
The Q15 value -1 (0x8000) is saturated to the maximum allowable positive value 0x7FFF.
|
||||
The Q15 value -1 (0x8000) is saturated to the maximum
|
||||
allowable positive value 0x7FFF.
|
||||
*/
|
||||
|
||||
void arm_negate_q15(
|
||||
const q15_t * pSrc,
|
||||
q15_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q15_t in; /* Temporary input variable */
|
||||
void arm_negate_q15(const q15_t *pSrc, q15_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q15_t in; /* Temporary input variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q31_t in1; /* Temporary input variables */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t in1; /* Temporary input variables */
|
||||
#endif
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Negate and store result in destination buffer (2 samples at a time). */
|
||||
in1 = read_q15x2_ia ((q15_t **) &pSrc);
|
||||
write_q15x2_ia (&pDst, __QSUB16(0, in1));
|
||||
in1 = read_q15x2_ia((q15_t **)&pSrc);
|
||||
write_q15x2_ia(&pDst, __QSUB16(0, in1));
|
||||
|
||||
in1 = read_q15x2_ia ((q15_t **) &pSrc);
|
||||
write_q15x2_ia (&pDst, __QSUB16(0, in1));
|
||||
in1 = read_q15x2_ia((q15_t **)&pSrc);
|
||||
write_q15x2_ia(&pDst, __QSUB16(0, in1));
|
||||
#else
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in;
|
||||
*pDst++ = (in == (q15_t)0x8000) ? (q15_t)0x7fff : -in;
|
||||
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in;
|
||||
*pDst++ = (in == (q15_t)0x8000) ? (q15_t)0x7fff : -in;
|
||||
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in;
|
||||
*pDst++ = (in == (q15_t)0x8000) ? (q15_t)0x7fff : -in;
|
||||
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in;
|
||||
*pDst++ = (in == (q15_t)0x8000) ? (q15_t)0x7fff : -in;
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -107,18 +103,16 @@ void arm_negate_q15(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
/* Negate and store result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q15_t) 0x8000) ? (q15_t) 0x7fff : -in;
|
||||
*pDst++ = (in == (q15_t)0x8000) ? (q15_t)0x7fff : -in;
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,50 +46,46 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
The Q31 value -1 (0x80000000) is saturated to the maximum allowable positive value 0x7FFFFFFF.
|
||||
The Q31 value -1 (0x80000000) is saturated to the maximum
|
||||
allowable positive value 0x7FFFFFFF.
|
||||
*/
|
||||
|
||||
void arm_negate_q31(
|
||||
const q31_t * pSrc,
|
||||
q31_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t in; /* Temporary input variable */
|
||||
void arm_negate_q31(const q31_t *pSrc, q31_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q31_t in; /* Temporary input variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
/* Negate and store result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
|
||||
#endif
|
||||
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
|
||||
|
@ -109,13 +105,12 @@ void arm_negate_q31(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
/* Negate and store result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in == INT32_MIN) ? INT32_MAX : -in;
|
||||
|
@ -124,7 +119,6 @@ void arm_negate_q31(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,46 +46,42 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
The Q7 value -1 (0x80) is saturated to the maximum allowable positive value 0x7F.
|
||||
The Q7 value -1 (0x80) is saturated to the maximum allowable
|
||||
positive value 0x7F.
|
||||
*/
|
||||
|
||||
void arm_negate_q7(
|
||||
const q7_t * pSrc,
|
||||
q7_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q7_t in; /* Temporary input variable */
|
||||
void arm_negate_q7(const q7_t *pSrc, q7_t *pDst, uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
q7_t in; /* Temporary input variable */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q31_t in1; /* Temporary input variable */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t in1; /* Temporary input variable */
|
||||
#endif
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Negate and store result in destination buffer (4 samples at a time). */
|
||||
in1 = read_q7x4_ia ((q7_t **) &pSrc);
|
||||
write_q7x4_ia (&pDst, __QSUB8(0, in1));
|
||||
in1 = read_q7x4_ia((q7_t **)&pSrc);
|
||||
write_q7x4_ia(&pDst, __QSUB8(0, in1));
|
||||
#else
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q7_t) 0x80) ? (q7_t) 0x7f : -in;
|
||||
*pDst++ = (in == (q7_t)0x80) ? (q7_t)0x7f : -in;
|
||||
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q7_t) 0x80) ? (q7_t) 0x7f : -in;
|
||||
*pDst++ = (in == (q7_t)0x80) ? (q7_t)0x7f : -in;
|
||||
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q7_t) 0x80) ? (q7_t) 0x7f : -in;
|
||||
*pDst++ = (in == (q7_t)0x80) ? (q7_t)0x7f : -in;
|
||||
|
||||
in = *pSrc++;
|
||||
*pDst++ = (in == (q7_t) 0x80) ? (q7_t) 0x7f : -in;
|
||||
*pDst++ = (in == (q7_t)0x80) ? (q7_t)0x7f : -in;
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -102,23 +98,21 @@ void arm_negate_q7(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = -A */
|
||||
|
||||
/* Negate and store result in destination buffer. */
|
||||
in = *pSrc++;
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
*pDst++ = (q7_t) __QSUB(0, in);
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (q7_t)__QSUB(0, in);
|
||||
#else
|
||||
*pDst++ = (in == (q7_t) 0x80) ? (q7_t) 0x7f : -in;
|
||||
*pDst++ = (in == (q7_t)0x80) ? (q7_t)0x7f : -in;
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -60,21 +60,16 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_offset_f32(
|
||||
const float32_t * pSrc,
|
||||
float32_t offset,
|
||||
float32_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_offset_f32(const float32_t *pSrc, float32_t offset, float32_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
/* Add offset and store result in destination buffer. */
|
||||
|
@ -100,8 +95,7 @@ void arm_offset_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
/* Add offset and store result in destination buffer. */
|
||||
|
@ -110,7 +104,6 @@ void arm_offset_f32(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,21 +47,18 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q15 range [0x8000 0x7FFF] are saturated.
|
||||
Results outside of the allowable Q15 range [0x8000 0x7FFF]
|
||||
are saturated.
|
||||
*/
|
||||
|
||||
void arm_offset_q15(
|
||||
const q15_t * pSrc,
|
||||
q15_t offset,
|
||||
q15_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_offset_q15(const q15_t *pSrc, q15_t offset, q15_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q31_t offset_packed; /* Offset packed to 32 bit */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t offset_packed; /* Offset packed to 32 bit */
|
||||
|
||||
/* Offset is packed to 32 bit in order to use SIMD32 for addition */
|
||||
offset_packed = __PKHBT(offset, offset, 16);
|
||||
|
@ -70,19 +67,21 @@ void arm_offset_q15(
|
|||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
/* Add offset and store result in destination buffer (2 samples at a time). */
|
||||
write_q15x2_ia (&pDst, __QADD16(read_q15x2_ia ((q15_t **) &pSrc), offset_packed));
|
||||
write_q15x2_ia (&pDst, __QADD16(read_q15x2_ia ((q15_t **) &pSrc), offset_packed));
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Add offset and store result in destination buffer (2 samples at a time).
|
||||
*/
|
||||
write_q15x2_ia(&pDst,
|
||||
__QADD16(read_q15x2_ia((q15_t **)&pSrc), offset_packed));
|
||||
write_q15x2_ia(&pDst,
|
||||
__QADD16(read_q15x2_ia((q15_t **)&pSrc), offset_packed));
|
||||
#else
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrc++ + offset), 16);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -99,21 +98,19 @@ void arm_offset_q15(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
/* Add offset and store result in destination buffer. */
|
||||
#if defined (ARM_MATH_DSP)
|
||||
*pDst++ = (q15_t) __QADD16(*pSrc++, offset);
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = (q15_t)__QADD16(*pSrc++, offset);
|
||||
#else
|
||||
*pDst++ = (q15_t) __SSAT(((q31_t) *pSrc++ + offset), 16);
|
||||
*pDst++ = (q15_t)__SSAT(((q31_t)*pSrc++ + offset), 16);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,49 +47,45 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q31 range [0x80000000 0x7FFFFFFF] are saturated.
|
||||
Results outside of the allowable Q31 range [0x80000000
|
||||
0x7FFFFFFF] are saturated.
|
||||
*/
|
||||
|
||||
void arm_offset_q31(
|
||||
const q31_t * pSrc,
|
||||
q31_t offset,
|
||||
q31_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_offset_q31(const q31_t *pSrc, q31_t offset, q31_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
/* Add offset and store result in destination buffer. */
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QADD(*pSrc++, offset);
|
||||
#else
|
||||
*pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrc++ + offset);
|
||||
*pDst++ = (q31_t)clip_q63_to_q31((q63_t)*pSrc++ + offset);
|
||||
#endif
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QADD(*pSrc++, offset);
|
||||
#else
|
||||
*pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrc++ + offset);
|
||||
*pDst++ = (q31_t)clip_q63_to_q31((q63_t)*pSrc++ + offset);
|
||||
#endif
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QADD(*pSrc++, offset);
|
||||
#else
|
||||
*pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrc++ + offset);
|
||||
*pDst++ = (q31_t)clip_q63_to_q31((q63_t)*pSrc++ + offset);
|
||||
#endif
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QADD(*pSrc++, offset);
|
||||
#else
|
||||
*pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrc++ + offset);
|
||||
*pDst++ = (q31_t)clip_q63_to_q31((q63_t)*pSrc++ + offset);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -106,21 +102,19 @@ void arm_offset_q31(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
/* Add offset and store result in destination buffer. */
|
||||
#if defined (ARM_MATH_DSP)
|
||||
#if defined(ARM_MATH_DSP)
|
||||
*pDst++ = __QADD(*pSrc++, offset);
|
||||
#else
|
||||
*pDst++ = (q31_t) clip_q63_to_q31((q63_t) * pSrc++ + offset);
|
||||
*pDst++ = (q31_t)clip_q63_to_q31((q63_t)*pSrc++ + offset);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,21 +47,18 @@
|
|||
|
||||
@par Scaling and Overflow Behavior
|
||||
The function uses saturating arithmetic.
|
||||
Results outside of the allowable Q7 range [0x80 0x7F] are saturated.
|
||||
Results outside of the allowable Q7 range [0x80 0x7F] are
|
||||
saturated.
|
||||
*/
|
||||
|
||||
void arm_offset_q7(
|
||||
const q7_t * pSrc,
|
||||
q7_t offset,
|
||||
q7_t * pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_offset_q7(const q7_t *pSrc, q7_t offset, q7_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
q31_t offset_packed; /* Offset packed to 32 bit */
|
||||
#if defined(ARM_MATH_DSP)
|
||||
q31_t offset_packed; /* Offset packed to 32 bit */
|
||||
|
||||
/* Offset is packed to 32 bit in order to use SIMD32 for addition */
|
||||
offset_packed = __PACKq7(offset, offset, offset, offset);
|
||||
|
@ -70,18 +67,18 @@ void arm_offset_q7(
|
|||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
#if defined (ARM_MATH_DSP)
|
||||
/* Add offset and store result in destination buffer (4 samples at a time). */
|
||||
write_q7x4_ia (&pDst, __QADD8(read_q7x4_ia ((q7_t **) &pSrc), offset_packed));
|
||||
#if defined(ARM_MATH_DSP)
|
||||
/* Add offset and store result in destination buffer (4 samples at a time).
|
||||
*/
|
||||
write_q7x4_ia(&pDst, __QADD8(read_q7x4_ia((q7_t **)&pSrc), offset_packed));
|
||||
#else
|
||||
*pDst++ = (q7_t) __SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t) __SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t) __SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t) __SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t)__SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t)__SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t)__SSAT(*pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t)__SSAT(*pSrc++ + offset, 8);
|
||||
#endif
|
||||
|
||||
/* Decrement loop counter */
|
||||
|
@ -98,17 +95,15 @@ void arm_offset_q7(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A + offset */
|
||||
|
||||
/* Add offset and store result in destination buffer. */
|
||||
*pDst++ = (q7_t) __SSAT((q15_t) *pSrc++ + offset, 8);
|
||||
*pDst++ = (q7_t)__SSAT((q15_t)*pSrc++ + offset, 8);
|
||||
|
||||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,16 +35,17 @@
|
|||
/**
|
||||
@defgroup BasicScale Vector Scale
|
||||
|
||||
Multiply a vector by a scalar value. For floating-point data, the algorithm used is:
|
||||
Multiply a vector by a scalar value. For floating-point data, the algorithm
|
||||
used is:
|
||||
|
||||
<pre>
|
||||
pDst[n] = pSrc[n] * scale, 0 <= n < blockSize.
|
||||
</pre>
|
||||
|
||||
In the fixed-point Q7, Q15, and Q31 functions, <code>scale</code> is represented by
|
||||
a fractional multiplication <code>scaleFract</code> and an arithmetic shift <code>shift</code>.
|
||||
The shift allows the gain of the scaling operation to exceed 1.0.
|
||||
The algorithm used with fixed-point data is:
|
||||
In the fixed-point Q7, Q15, and Q31 functions, <code>scale</code> is
|
||||
represented by a fractional multiplication <code>scaleFract</code> and an
|
||||
arithmetic shift <code>shift</code>. The shift allows the gain of the scaling
|
||||
operation to exceed 1.0. The algorithm used with fixed-point data is:
|
||||
|
||||
<pre>
|
||||
pDst[n] = (pSrc[n] * scaleFract) << shift, 0 <= n < blockSize.
|
||||
|
@ -73,21 +74,16 @@
|
|||
@return none
|
||||
*/
|
||||
|
||||
void arm_scale_f32(
|
||||
const float32_t *pSrc,
|
||||
float32_t scale,
|
||||
float32_t *pDst,
|
||||
uint32_t blockSize)
|
||||
{
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
void arm_scale_f32(const float32_t *pSrc, float32_t scale, float32_t *pDst,
|
||||
uint32_t blockSize) {
|
||||
uint32_t blkCnt; /* Loop counter */
|
||||
|
||||
#if defined (ARM_MATH_LOOPUNROLL)
|
||||
#if defined(ARM_MATH_LOOPUNROLL)
|
||||
|
||||
/* Loop unrolling: Compute 4 outputs at a time */
|
||||
blkCnt = blockSize >> 2U;
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * scale */
|
||||
|
||||
/* Scale input and store result in destination buffer. */
|
||||
|
@ -113,8 +109,7 @@ void arm_scale_f32(
|
|||
|
||||
#endif /* #if defined (ARM_MATH_LOOPUNROLL) */
|
||||
|
||||
while (blkCnt > 0U)
|
||||
{
|
||||
while (blkCnt > 0U) {
|
||||
/* C = A * scale */
|
||||
|
||||
/* Scale input and store result in destination buffer. */
|
||||
|
@ -123,7 +118,6 @@ void arm_scale_f32(
|
|||
/* Decrement loop counter */
|
||||
blkCnt--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue