2022-08-15 04:20:27 -05:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright 2015-2019 BES.
|
|
|
|
* All rights reserved. All unpublished rights reserved.
|
|
|
|
*
|
|
|
|
* No part of this work may be used or reproduced in any form or by any
|
|
|
|
* means, or stored in a database or retrieval system, without prior written
|
|
|
|
* permission of BES.
|
|
|
|
*
|
|
|
|
* Use of this work is governed by a license granted by BES.
|
|
|
|
* This work contains confidential and proprietary information of
|
|
|
|
* BES. which is protected by copyright, trade secret,
|
|
|
|
* trademark and other intellectual property rights.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "apps.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "cmsis_os.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "hal_bootmode.h"
|
|
|
|
#include "hal_cmu.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "hal_timer.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "hal_trace.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
#include "rwapp_config.h"
|
2023-02-01 14:52:54 -06:00
|
|
|
#include "stdbool.h"
|
|
|
|
#include "string.h"
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#include "app_ble_cmd_handler.h"
|
|
|
|
#include "app_ble_custom_cmd.h"
|
|
|
|
#include "retention_ram.h"
|
|
|
|
|
|
|
|
#if (BTIF_BLE_APP_DATAPATH_SERVER)
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
extern void app_datapath_server_send_data_via_notification(uint8_t *ptrData,
|
|
|
|
uint32_t length);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void BLE_dummy_handler(uint32_t funcCode, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {}
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void BLE_test_no_response_print_handler(uint32_t funcCode, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {
|
|
|
|
TRACE(1, "%s Get OP_TEST_NO_RESPONSE_PRINT command!!!", __FUNCTION__);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void BLE_test_with_response_print_handler(uint32_t funcCode, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {
|
|
|
|
TRACE(1, "%s Get OP_TEST_WITH_RESPONSE_PRINT command!!!", __FUNCTION__);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
uint32_t currentTicks = GET_CURRENT_TICKS();
|
|
|
|
BLE_send_response_to_command(funcCode, NO_ERROR, (uint8_t *)¤tTicks,
|
|
|
|
sizeof(currentTicks),
|
|
|
|
TRANSMISSION_VIA_NOTIFICATION);
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void BLE_test_with_response_print_rsp_handler(
|
|
|
|
BLE_CUSTOM_CMD_RET_STATUS_E retStatus, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {
|
|
|
|
if (NO_ERROR == retStatus) {
|
|
|
|
TRACE(1, "%s Get the response of OP_TEST_WITH_RESPONSE_PRINT command!!!",
|
|
|
|
__FUNCTION__);
|
|
|
|
} else if (TIMEOUT_WAITING_RESPONSE == retStatus) {
|
|
|
|
TRACE(1,
|
|
|
|
"%s Timeout happens, doesn't get the response of "
|
|
|
|
"OP_TEST_WITH_RESPONSE_PRINT command!!!",
|
|
|
|
__FUNCTION__);
|
|
|
|
}
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
static void app_otaMode_enter(void) {
|
|
|
|
TRACE(1, "%s", __func__);
|
|
|
|
hal_norflash_disable_protection(HAL_NORFLASH_ID_0);
|
|
|
|
hal_sw_bootmode_set(HAL_SW_BOOTMODE_ENTER_HIDE_BOOT);
|
|
|
|
/*hal_cmu_reset_set(HAL_CMU_MOD_P_GLOBAL);*/
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
void BLE_enter_OTA_mode_handler(uint32_t funcCode, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {
|
|
|
|
fillBleBdAddrForOta(ptrParam);
|
|
|
|
app_otaMode_enter();
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
int audio_config_eq_iir_via_config_structure(uint8_t *buf, uint32_t len);
|
|
|
|
void BLE_iir_eq_handler(uint32_t funcCode, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {
|
2022-08-15 04:20:27 -05:00
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
audio_config_eq_iir_via_config_structure(
|
|
|
|
BLE_custom_command_raw_data_buffer_pointer(),
|
|
|
|
BLE_custom_command_received_raw_data_size());
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern uint8_t bt_addr[6];
|
2023-02-01 14:52:54 -06:00
|
|
|
void BLE_get_bt_address_handler(uint32_t funcCode, uint8_t *ptrParam,
|
|
|
|
uint32_t paramLen) {
|
|
|
|
app_datapath_server_send_data_via_notification((uint8_t *)&bt_addr,
|
|
|
|
sizeof(bt_addr));
|
2022-08-15 04:20:27 -05:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:52:54 -06:00
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_RESPONSE_TO_CMD, BLE_get_response_handler, false, 0,
|
|
|
|
NULL);
|
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_START_RAW_DATA_XFER, BLE_raw_data_xfer_control_handler,
|
|
|
|
true, 2000, BLE_start_raw_data_xfer_control_rsp_handler);
|
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_STOP_RAW_DATA_XFER, BLE_raw_data_xfer_control_handler,
|
|
|
|
true, 2000, BLE_stop_raw_data_xfer_control_rsp_handler);
|
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_TEST_NO_RESPONSE_PRINT,
|
|
|
|
BLE_test_no_response_print_handler, false, 0, NULL);
|
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_TEST_WITH_RESPONSE_PRINT,
|
|
|
|
BLE_test_with_response_print_handler, true, 5000,
|
|
|
|
BLE_test_with_response_print_rsp_handler);
|
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_ENTER_OTA_MODE, BLE_enter_OTA_mode_handler, false, 0,
|
|
|
|
NULL);
|
2022-08-15 04:20:27 -05:00
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
2023-02-01 14:52:54 -06:00
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_SW_IIR_EQ, BLE_iir_eq_handler, false, 0, NULL);
|
2022-08-15 04:20:27 -05:00
|
|
|
#endif
|
2023-02-01 14:52:54 -06:00
|
|
|
CUSTOM_COMMAND_TO_ADD(OP_GET_BT_ADDRESS, BLE_get_bt_address_handler, false, 0,
|
|
|
|
NULL);
|
2022-08-15 04:20:27 -05:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/** \brief Instances list of BLE custom command handler, should be in the order of the
|
|
|
|
* command code definition in BLE_CUSTOM_CMD_CODE_E
|
|
|
|
*/
|
|
|
|
BLE_CUSTOM_CMD_INSTANCE_T customCommandArray[] =
|
|
|
|
{
|
|
|
|
// { command handler, wait for response or not, time out of waiting response in ms, callback when the response is received }
|
|
|
|
// non-touchable instances
|
|
|
|
{ BLE_get_response_handler, false, 0, NULL },
|
|
|
|
{ BLE_raw_data_xfer_control_handler, true, 2000, BLE_start_raw_data_xfer_control_rsp_handler },
|
|
|
|
{ BLE_raw_data_xfer_control_handler, true, 2000, BLE_stop_raw_data_xfer_control_rsp_handler },
|
|
|
|
|
|
|
|
// TO ADD: the new custom command instance
|
|
|
|
{ BLE_test_no_response_print_handler, false, 0, NULL },
|
|
|
|
{ BLE_test_with_response_print_handler, true, 5000, BLE_test_with_response_print_rsp_handler },
|
|
|
|
|
|
|
|
{ BLE_enter_OTA_mode_handler, false, 0, NULL },
|
|
|
|
|
|
|
|
#ifdef __SW_IIR_EQ_PROCESS__
|
|
|
|
{ BLE_iir_eq_handler, false, 0, NULL },
|
|
|
|
#else
|
|
|
|
{ BLE_dummy_handler, false, 0, NULL },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{ BLE_get_bt_address_handler, false, 0, NULL },
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif
|