Commit dd48d7df authored by 时昊's avatar 时昊

feat:首次上传,基于钱江代码

parents
build/
sdkconfig.old
/.vscode
*.o
*.s
*.log
*.lst
*.d
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
# (Not part of the boilerplate)
# This example uses an extra component for common functions such as Wi-Fi and Ethernet connection.
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(QJ500-7C)
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, , 0x4000,
otadata, data, ota, , 0x2000,
phy_init, data, phy, , 0x1000,
ota_0, app, ota_0, , 0x800K,
ota_1, app, ota_1, , 0x800K,
\ No newline at end of file
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- |
# ESP-IDF Gatt Server Service Table Example
This example shows how to create a GATT service with an attribute table defined in one place. Provided API releases the user from adding attributes one by one as implemented in BLUEDROID. A demo of the other method to create the attribute table is presented in [gatt_server_demo](../gatt_server).
Please, check this [tutorial](tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md) for more information about this example.
## How to Use Example
Before project configuration and build, be sure to set the correct chip target using:
```bash
idf.py set-target <chip_name>
```
### Hardware Required
* A development board with ESP32/ESP32-C3/ESP32-H2/ESP32-C2/ESP32-S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
* A USB cable for Power supply and programming
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
### Build and Flash
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
(To exit the serial monitor, type ``Ctrl-]``.)
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
## Example Output
```
I (0) cpu_start: Starting scheduler on APP CPU.
I (512) BTDM_INIT: BT controller compile version [1342a48]
I (522) system_api: Base MAC address is not set
I (522) system_api: read default base MAC address from EFUSE
I (522) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
I (942) GATTS_TABLE_DEMO: create attribute table successfully, the number handle = 8
I (942) GATTS_TABLE_DEMO: SERVICE_START_EVT, status 0, service_handle 40
I (962) GATTS_TABLE_DEMO: advertising start successfully
```
## Troubleshooting
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
# Embed the server root certificate into the final binary
idf_build_get_property(project_dir PROJECT_DIR)
idf_component_register(SRCS "app_BT_User.c" "bt_app_main.c" "bt_app_hf.c" "bt_app_core.c" "gatts_table_creat_demo.c"
"simple_ota_example.c"
"Protocol_CRC16.c"
"Protocol_Lib.c"
"Protocol_User.c"
"MCU_Core_Protocol.c"
"app_Ble_User.c"
"main_user.c"
INCLUDE_DIRS "."
EMBED_TXTFILES ${project_dir}/server_certs/ca_cert.pem)
menu "Example Configuration"
config EXAMPLE_FIRMWARE_UPGRADE_URL
string "firmware upgrade url endpoint"
default "https://192.168.0.3:8070/hello_world.bin"
help
URL of server which hosts the firmware
image.
config EXAMPLE_USE_CERT_BUNDLE
bool "Enable certificate bundle"
default y
depends on MBEDTLS_CERTIFICATE_BUNDLE
help
Enable trusted root certificate bundle. This approach allows to have
OTA updates functional with any public server without requirement
to explicitly add its server certificate.
config EXAMPLE_FIRMWARE_UPGRADE_URL_FROM_STDIN
bool
default y if EXAMPLE_FIRMWARE_UPGRADE_URL = "FROM_STDIN"
config EXAMPLE_SKIP_COMMON_NAME_CHECK
bool "Skip server certificate CN fieldcheck"
default n
help
This allows you to skip the validation of OTA server certificate CN field.
config EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
bool "Support firmware upgrade bind specified interface"
default n
help
This allows you to bind specified interface in OTA example.
choice EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_TYPE
prompt "Choose OTA data bind interface"
default EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_STA
depends on EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
help
Select which interface type of OTA data go through.
config EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_STA
bool "Bind wifi station interface"
depends on EXAMPLE_CONNECT_WIFI
help
Select wifi station interface to pass the OTA data.
config EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_ETH
bool "Bind ethernet interface"
depends on EXAMPLE_CONNECT_ETHERNET
help
Select ethernet interface to pass the OTA data.
endchoice
endmenu
#include "Protocol_Lib.h"
#include "MCU_Core_Protocol.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "Protocol_User.h"
#include "gatts_table_creat_demo.h"
#include "app_Ble_User.h"
#ifndef _MCU_CORE_PROTOCOL_H_
#define _MCU_CORE_PROTOCOL_H_
#include "Protocol_Lib.h"
#endif
/**
* @file Protocol_CRC16.c
* @brief CRC16计算
* @details CRC16计算
* @author myliu
* @date 2022.05.09
* @version V1.0
* @copyright myiu
*/
#include "Protocol_CRC16.h"
static const Protocol_uint8_t CRC16_TAB_H [ 256 ] = {0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x01u, 0xC0u, 0x80u, 0x41u, 0x00u, 0xC1u, 0x81u, 0x40u};
static const Protocol_uint8_t CRC16_TAB_L [ 256 ] = {0x00u, 0xC0u, 0xC1u, 0x01u, 0xC3u, 0x03u, 0x02u, 0xC2u, 0xC6u, 0x06u, 0x07u, 0xC7u, 0x05u, 0xC5u, 0xC4u, 0x04u, 0xCCu, 0x0Cu, 0x0Du, 0xCDu, 0x0Fu, 0xCFu, 0xCEu, 0x0Eu, 0x0Au, 0xCAu, 0xCBu, 0x0Bu, 0xC9u, 0x09u, 0x08u, 0xC8u, 0xD8u, 0x18u, 0x19u, 0xD9u, 0x1Bu, 0xDBu, 0xDAu, 0x1Au, 0x1Eu, 0xDEu, 0xDFu, 0x1Fu, 0xDDu, 0x1Du, 0x1Cu, 0xDCu, 0x14u, 0xD4u, 0xD5u, 0x15u, 0xD7u, 0x17u, 0x16u, 0xD6u, 0xD2u, 0x12u, 0x13u, 0xD3u, 0x11u, 0xD1u, 0xD0u, 0x10u, 0xF0u, 0x30u, 0x31u, 0xF1u, 0x33u, 0xF3u, 0xF2u, 0x32u, 0x36u, 0xF6u, 0xF7u, 0x37u, 0xF5u, 0x35u, 0x34u, 0xF4u, 0x3Cu, 0xFCu, 0xFDu, 0x3Du, 0xFFu, 0x3Fu, 0x3Eu, 0xFEu, 0xFAu, 0x3Au, 0x3Bu, 0xFBu, 0x39u, 0xF9u, 0xF8u, 0x38u, 0x28u, 0xE8u, 0xE9u, 0x29u, 0xEBu, 0x2Bu, 0x2Au, 0xEAu, 0xEEu, 0x2Eu, 0x2Fu, 0xEFu, 0x2Du, 0xEDu, 0xECu, 0x2Cu, 0xE4u, 0x24u, 0x25u, 0xE5u, 0x27u, 0xE7u, 0xE6u, 0x26u, 0x22u, 0xE2u, 0xE3u, 0x23u, 0xE1u, 0x21u, 0x20u, 0xE0u, 0xA0u, 0x60u, 0x61u, 0xA1u, 0x63u, 0xA3u, 0xA2u, 0x62u, 0x66u, 0xA6u, 0xA7u, 0x67u, 0xA5u, 0x65u, 0x64u, 0xA4u, 0x6Cu, 0xACu, 0xADu, 0x6Du, 0xAFu, 0x6Fu, 0x6Eu, 0xAEu, 0xAAu, 0x6Au, 0x6Bu, 0xABu, 0x69u, 0xA9u, 0xA8u, 0x68u, 0x78u, 0xB8u, 0xB9u, 0x79u, 0xBBu, 0x7Bu, 0x7Au, 0xBAu, 0xBEu, 0x7Eu, 0x7Fu, 0xBFu, 0x7Du, 0xBDu, 0xBCu, 0x7Cu, 0xB4u, 0x74u, 0x75u, 0xB5u, 0x77u, 0xB7u, 0xB6u, 0x76u, 0x72u, 0xB2u, 0xB3u, 0x73u, 0xB1u, 0x71u, 0x70u, 0xB0u, 0x50u, 0x90u, 0x91u, 0x51u, 0x93u, 0x53u, 0x52u, 0x92u, 0x96u, 0x56u, 0x57u, 0x97u, 0x55u, 0x95u, 0x94u, 0x54u, 0x9Cu, 0x5Cu, 0x5Du, 0x9Du, 0x5Fu, 0x9Fu, 0x9Eu, 0x5Eu, 0x5Au, 0x9Au, 0x9Bu, 0x5Bu, 0x99u, 0x59u, 0x58u, 0x98u, 0x88u, 0x48u, 0x49u, 0x89u, 0x4Bu, 0x8Bu, 0x8Au, 0x4Au, 0x4Eu, 0x8Eu, 0x8Fu, 0x4Fu, 0x8Du, 0x4Du, 0x4Cu, 0x8Cu, 0x44u, 0x84u, 0x85u, 0x45u, 0x87u, 0x47u, 0x46u, 0x86u, 0x82u, 0x42u, 0x43u, 0x83u, 0x41u, 0x81u, 0x80u, 0x40u};
/**
* 获取CRC16校验和
*/
/**
* @brief 计算传入数据的CRC16
* @param[in] pData 计算的数据内容
* @param[in] len 计算的数据长度
*
* @return 校验和
*
* @since 1.0.0
*/
Protocol_uint16_t getCheckSum(const Protocol_uint8_t *pData, int len)
{
Protocol_uint8_t u8_crc_h = 0xFFu;
Protocol_uint8_t u8_crc_l = 0xFFu;
Protocol_uint8_t u8_index = 0u;
Protocol_uint8_t i = 0u;
Protocol_uint16_t re_value;
while ( len-- )
{
u8_index = u8_crc_h ^ (pData [ i++ ]);
u8_crc_h = u8_crc_l ^ CRC16_TAB_H [ u8_index ];
u8_crc_l = CRC16_TAB_L [ u8_index ];
}
re_value = ( Protocol_uint16_t )u8_crc_h << 8u;
re_value |= u8_crc_l;
return re_value;
}
#ifndef PROTOCOL_CRC16_H
#define PROTOCOL_CRC16_H
#include "Protocol_Lib.h"
Protocol_uint16_t getCheckSum(const Protocol_uint8_t *pData, int len);
#endif
/**
* @file Protocol_Lib.c
* @brief 串口协议解析
* @details 串口协议解析
* @author myliu
* @date 2022.05.09
* @version V1.0
* @copyright myiu
*/
#include <stdio.h>
#include <string.h>
#include "Protocol_CRC16.h"
#include "gatts_table_creat_demo.h"
static UARTOpen UARTOpen_Cbk;
static UARTSend UARTSend_Cbk;
static UARTRead UARTRead_Cbk;
static ProcParse ProcParseCbk;
static UARTClose UARTClose_Cbk;
static ProtocolSetData ProtocolSetData_Cbk;
static Protocol_uint8_t *mDataBufPtr = Protocol_NULL;
static Protocol_uint16_t mDataBufLen = 0;
static Protocol_uint32_t DataBufMaxLen = 0;
//#define DEBUG_PRO_DATA 0
/**
* @brief 初始化函数
* @param[in] pMemSpace 分配给协议库的内存空间,用来缓存串口数据
* @param[in] MemLen 分配的内存空间大小
* @param[in] pFunc 回调函数,包括串口打开、发送、读取、关闭,也包括解析后数据回传
* @param[in] ProcParseCbk 此回调函数,返回数据从FrameNo开始到CRC16之前,和ProtocolSetData_Cbk二选一
* @param[in] ProtocolSetData_Cbk 此回调函数,返回数据区分命令字、电源状态等,和ProcParseCbk二选一,详见结构体Protocol_Data_t
*
* @warning 此函数KL30和Wakeup都要调用,否则未分配内存,功能不好使,也有可能造成野指针复位
*
* @since 1.0.0
*/
void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protocol_Func_t *pFunc)
{
mDataBufPtr = pMemSpace;
DataBufMaxLen = MemLen;
UARTOpen_Cbk = pFunc->UARTOpen_Cbk;
UARTSend_Cbk = pFunc->UARTSend_Cbk;
UARTRead_Cbk = pFunc->UARTRead_Cbk;
ProcParseCbk = pFunc->ProcParseCbk;
UARTClose_Cbk = pFunc->UARTClose_Cbk;
ProtocolSetData_Cbk = pFunc->ProtocolSetData_Cbk;
if ( UARTOpen_Cbk != Protocol_NULL )
{
UARTOpen_Cbk( );
}
return;
}
/**
* @brief 串口协议服务函数,包括读取数据,解析数据,如在外部读取数据,可不调用此函数
*
* @warning 此函数可自定义周期调用,建议20ms周期调用,最大不可超过协议的最小发送周期
*
* @since 1.0.0
*/
void Protocol_Service(void)
{
int len;
Protocol_uint32_t readNum = 0;
if ( UARTRead_Cbk != Protocol_NULL )
{
readNum = UARTRead_Cbk(mDataBufPtr + mDataBufLen, 256 - mDataBufLen);
if ( readNum > 0 )
{
mDataBufLen += readNum;
// 解析协议
len = Protocol_Parse(mDataBufPtr, mDataBufLen);
if ( (len > 0) && (len < mDataBufLen) )
{
// 将未解析的数据移到头部
// Move unparsed data to the head
memcpy(mDataBufPtr, mDataBufPtr + len, mDataBufLen - len);
}
mDataBufLen -= len;
}
}
}
/**
* @brief 协议解析函数,如外部获取数据(例如中断),可直接调用此函数解析数据
* @param[in] pData 协议数据内容
* @param[in] len 需要处理的协议数据长度
*
* @return 剩余已处理的数据长度
*
* @since 1.0.0
*/
Protocol_uint32_t Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len)
{
Protocol_uint32_t remainLen = len; // 剩余数据长度 Remaining data length
Protocol_uint32_t dataLen; // 数据包长度 Packet length
Protocol_uint32_t frameLen; // 帧长度 Frame length
Protocol_uint32_t frameSum;
Protocol_Data_t ProcData;
int i = 0;
int dataBuf [ 256 ];
/**
* 以下部分需要根据协议格式进行相应的修改,解析出每一帧的数据
*/
while ( remainLen >= DATA_PACKAGE_MIN_LEN )
{
// 找到一帧数据的数据头
// Find the data header of a frame of data
while ( (remainLen >= 2) && ((pData [ 0 ] != CMD_HEAD1) || (pData [ 1 ] != CMD_HEAD2)) )
{
pData++;
remainLen--;
continue;
}
if ( remainLen < DATA_PACKAGE_MIN_LEN )
{
#ifdef DEBUG_PRO_DATA
d_printf("too short!!!!!!\n");
#endif
break;
}
dataLen = pData [ 2 ];
frameLen = dataLen + DATA_PACKAGE_FIXED_LEN;
if ( frameLen > remainLen )
{
// 数据内容不全
#ifdef DEBUG_PRO_DATA
d_printf("Incomplete data packet!!!!!!\n");
#endif
break;
}
// 打印一帧数据,需要时在CommDef.h文件中打开DEBUG_PRO_DATA宏
#ifdef DEBUG_PRO_DATA
for ( i = 0; i < frameLen; ++i )
{
d_printf("%x ", pData [ i ]);
}
d_printf("\n");
#endif
// 检测校验码 Checksum
frameSum = (pData [ frameLen - 2 ] << 8) | (pData [ frameLen - 1 ]);
if ( frameLen > 4 )
{
if ( getCheckSum(pData + 2, frameLen - 4) == frameSum )
{
// 解析一帧数据
if ( ProcParseCbk != Protocol_NULL )
{
ProcParseCbk(pData + 3, dataLen - 2);
}
if ( ProtocolSetData_Cbk != Protocol_NULL )
{
ProcData.FrameNo = pData [ 3 ];
ProcData.PowerSts = (pData [ 4 ] >> 6) & 0x03;
ProcData.CmdID = pData [ 4 ] & 0x3F;
if ( ProcData.CmdID == 0x10 )
{
#ifdef DEBUG_PRO_DATA
for ( i = 0; i < frameLen; ++i )
{
d_printf("%x ", pData [ i ]);
}
d_printf("\n");
#endif
}
if ( ProcData.CmdID == 0x12 )
{
#ifdef DEBUG_PRO_DATA
for ( i = 0; i < frameLen; ++i )
{
d_printf("%x ", pData [ i ]);
}
d_printf("\n");
#endif
}
ProcData.DataLen = dataLen - 4;
memcpy(ProcData.Data, pData + 5, ProcData.DataLen);
ProtocolSetData_Cbk(&ProcData);
}
}
else
{
for ( i = 0; i < frameLen; ++i )
{
dataBuf [ i ] = pData [ i ];
}
i = 0;
#ifdef DEBUG_PRO_DATA
d_printf("CheckSum error: new = %x, old = %x!!!!!!\n", getCheckSum(pData + 2, frameLen - 4), frameSum);
#endif
}
}
pData += frameLen;
remainLen -= frameLen;
}
return len - remainLen;
}
/**
* 根据协议格式进行拼接
*/
/**
* @brief 串口协议数据拼接,如初始化发送函数,调用此函数后,数据已通过串口发送
* @param[in] cmdID 命令字
* @param[in] pData 协议数据内容(不包括协议头、长度、帧序号、命令字、校验和,从数据域算起)
* @param[in] len 数据域长度
*
* @return 已发送的数据长度
*
* @since 1.0.0
*/
Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_uint8_t *pData, Protocol_uint8_t len)
{
int i = 0;
Protocol_uint16_t checksum = 0;
Protocol_uint8_t dataBuf [ 256 ];
Protocol_uint32_t frameLen;
if ( len + DATA_PACKAGE_MIN_LEN > 256 )
{
// printf("sendProtocol data is too len !!!\n");
return 0;
}
dataBuf [ 0 ] = CMD_HEAD1;
dataBuf [ 1 ] = CMD_HEAD2; // 同步帧头 Sync frame header
dataBuf [ 2 ] = len + 4;
dataBuf [ 3 ] = len; // 命令字节 Command byte
dataBuf [ 4 ] = ( Protocol_uint8_t )cmdID;
frameLen = 5;
// 数据 Data
for ( i = 0; i < len; ++i )
{
dataBuf [ frameLen ] = pData [ i ];
frameLen++;
}
// 校验码 Checksum
checksum = getCheckSum(dataBuf + 2, frameLen - 2);
dataBuf [ frameLen ] = (checksum >> 8) & 0x00FF;
frameLen++;
dataBuf [ frameLen ] = checksum & 0x00FF;
frameLen++;
if ( UARTSend_Cbk != Protocol_NULL )
{
return UARTSend_Cbk(dataBuf, frameLen);
}
else
{
return 0;
}
}
#ifndef PROTOCOL_LIB_H
#define PROTOCOL_LIB_H
/*
Platform_32Bit
Platform_16Bit
*/
#ifdef Platform_16Bit
#define Protocol_uint8_t unsigned char
#define Protocol_uint16_t unsigned int
#define Protocol_uint32_t unsigned long
#else
#define Protocol_uint8_t unsigned char
#define Protocol_uint16_t unsigned short
#define Protocol_uint32_t unsigned int
#define Protocol_uint64_t unsigned long long
#endif
#ifndef Protocol_NULL
#define Protocol_NULL ( void * )0u
#endif /* NULL */
/**<0xEB 0x90 长度 帧序号 命令字 DATA0-DATAN CRC16_1 CRC16_2*/
#define DATA_PACKAGE_MIN_LEN 7 /**< 0xEB 0x90 + 长度 + 数据包序号 + CMDID + CRC16_1 + CRC16_2 */
#define DATA_PACKAGE_FIXED_LEN 3 /**< 未计算在长度内的数据 0xEB 0x90 + 长度位 */
#define CMD_HEAD1 0xEB
#define CMD_HEAD2 0x90
/**@struct Protocol_Data_t
* @brief 解析后的协议数据
*/
typedef struct
{
Protocol_uint8_t FrameNo; /**< 帧序号 */
Protocol_uint8_t PowerSts; /**< 电源状态 */
Protocol_uint8_t CmdID; /**< 命令字 */
Protocol_uint8_t DataLen; /**< 有效数据长度 DATA0-DATAN*/
Protocol_uint8_t Data [ 256 ]; /**< 有效数据内容 DATA0-DATAN*/
} Protocol_Data_t;
typedef Protocol_uint8_t (*UARTOpen)(void);
typedef Protocol_uint32_t (*UARTSend)(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
typedef Protocol_uint32_t (*UARTRead)(Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
typedef void (*ProtocolSetData)(const Protocol_Data_t *pData);
typedef void (*ProcParse)(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
typedef void (*UARTClose)(void);
/**@struct Protocol_Func_t
* @brief 协议解析回调函数
*/
typedef struct
{
UARTOpen UARTOpen_Cbk; /**< 串口打开回调 */
UARTSend UARTSend_Cbk; /**< 串口发送回调 */
UARTRead UARTRead_Cbk; /**< 串口读取回调 */
UARTClose UARTClose_Cbk; /**< 串口关闭回调 */
ProcParse ProcParseCbk; /**< 解析后的数据, 处理了数据包序号,命令字和电源状态,和ProcParse二选一 */
ProtocolSetData ProtocolSetData_Cbk; /**< 不包含 0xEB 0x90 + 长度 + CRC16_1 + CRC16_2,和ProtocolSetData二选一 */
} Protocol_Func_t;
void Protocol_Init(Protocol_uint8_t *pMemSpace, Protocol_uint32_t MemLen, Protocol_Func_t *pFunc);
void Protocol_Service(void);
Protocol_uint32_t Protocol_Parse(const Protocol_uint8_t *pData, Protocol_uint32_t len);
Protocol_uint32_t Protocol_Send(const Protocol_uint16_t cmdID, const Protocol_uint8_t *pData, Protocol_uint8_t len);
#endif
#include <stdint.h>
#include "Protocol_User.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_bt.h"
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_bt_main.h"
#include "gatts_table_creat_demo.h"
#include "esp_gatt_common_api.h"
#include "esp_mac.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "string.h"
#include "driver/gpio.h"
#include "MCU_Core_Protocol.h"
#include "Protocol_Lib.h"
#include "app_Ble_User.h"
#include "app_BT_User.h"
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#define TAG "Prot_User"
Protocol_User_Ctrl_Struct Prot_User;
#define UART_TX_MAX_DEPTH 1024UL //(2 * 1024UL) // 4K
#define UART_RX_MAX_DEPTH (2 * 1024UL) // 4K
#define UART_DATA_BUF_LEN (2 * 1024UL) // 4K
//extern void OTA_IC_To_Master( uint8_t len);
typedef struct
{
Protocol_uint32_t read_pos;
Protocol_uint32_t write_pos;
Protocol_uint8_t Rx_Buffer [ UART_RX_MAX_DEPTH ];
} UARTRxBuf_t;
typedef struct
{
Protocol_uint32_t read_pos;
Protocol_uint32_t write_pos;
Protocol_uint8_t Tx_Buffer [ UART_TX_MAX_DEPTH ];
} UARTTxBuf_t;
static UARTRxBuf_t UARTRxBuf;
static UARTTxBuf_t UARTTxBuf;
static Protocol_uint8_t UsartDataBuf [ 256 ];
static Protocol_uint8_t mDataBufPtr [ UART_DATA_BUF_LEN ];
static Protocol_uint8_t Protocol_OpenUart(void);
static Protocol_uint32_t Protocol_UartRead(Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
static Protocol_uint32_t Protocol_UartSend(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len);
static void Protocol_UartHandle(const Protocol_Data_t *pData);
void Protocol_KL30_Wakeup_Init(void)
{
Protocol_Func_t pFunc;
pFunc.UARTOpen_Cbk = Protocol_OpenUart;
pFunc.UARTSend_Cbk = Protocol_UartSend;
pFunc.UARTRead_Cbk = Protocol_UartRead;
pFunc.UARTClose_Cbk = Protocol_NULL;
pFunc.ProcParseCbk = Protocol_NULL;
pFunc.ProtocolSetData_Cbk = Protocol_UartHandle;
UARTTxBuf.read_pos = 0;
UARTTxBuf.write_pos = 0;
UARTRxBuf.read_pos = 0;
UARTRxBuf.write_pos = 0;
Protocol_Init(mDataBufPtr, UART_DATA_BUF_LEN, &pFunc);
}
void Protocol_Send_Service(void)
{
Protocol_uint32_t i = 0u;
Protocol_uint32_t DataLen = 0u;
Protocol_uint32_t SendLen = 0u;
if ( UARTTxBuf.write_pos == UARTTxBuf.read_pos )
{
return;
}
if ( UARTTxBuf.write_pos > UARTTxBuf.read_pos )
{
DataLen = UARTTxBuf.write_pos - UARTTxBuf.read_pos;
}
else
{
DataLen = UART_TX_MAX_DEPTH - (UARTTxBuf.read_pos - UARTTxBuf.write_pos);
}
if ( DataLen > 255 )
{
SendLen = 255;
}
else
{
SendLen = DataLen;
}
for ( i = 0u; i < SendLen; i++ )
{
UsartDataBuf [ i ] = UARTTxBuf.Tx_Buffer [ UARTTxBuf.read_pos ];
UARTTxBuf.read_pos = (UARTTxBuf.read_pos + 1) % UART_TX_MAX_DEPTH;
}
bsp_Uart_Send_Data(UsartDataBuf, SendLen);
}
static Protocol_uint8_t Protocol_OpenUart(void)
{
#if 0
UART_Channel_Config_st_t loc_config;
loc_config.u32UARTChEn = 1;
loc_config.u32UARTbps = 115200;
loc_config.pfnUARTConfirmCallBack = Protocol_NULL;
loc_config.pfnUARTReadMsgCallBack = UART_Put;
UART_Init(UART_RLIN31, &loc_config);
#endif
return 1;
}
static Protocol_uint32_t Protocol_UartRead(Protocol_uint8_t *pData, Protocol_uint32_t len)
{
Protocol_uint32_t i = 0;
Protocol_uint32_t DataLen = 0u;
Protocol_uint32_t ReadLen = 0u;
if ( UARTRxBuf.write_pos == UARTRxBuf.read_pos )
{
return 0; //队列空
}
if ( UARTRxBuf.write_pos > UARTRxBuf.read_pos )
{
DataLen = UARTRxBuf.write_pos - UARTRxBuf.read_pos;
}
else
{
DataLen = UART_RX_MAX_DEPTH - (UARTRxBuf.read_pos - UARTRxBuf.write_pos);
}
if ( len > DataLen )
{
ReadLen = DataLen;
}
else
{
ReadLen = len;
}
for ( i = 0u; i < ReadLen; i++ )
{
pData [ i ] = UARTRxBuf.Rx_Buffer [ UARTRxBuf.read_pos ];
UARTRxBuf.read_pos = (UARTRxBuf.read_pos + 1) % UART_RX_MAX_DEPTH;
}
return ReadLen;
}
static Protocol_uint32_t Protocol_UartSend(const Protocol_uint8_t *pData, Protocol_uint32_t u32Len)
{
Protocol_uint32_t i = 0;
Protocol_uint32_t RemainLen = 0u;
if ( UARTTxBuf.write_pos >= UARTTxBuf.read_pos )
{
RemainLen = UART_TX_MAX_DEPTH - (UARTTxBuf.write_pos - UARTTxBuf.read_pos);
}
else
{
RemainLen = UARTTxBuf.read_pos - UARTTxBuf.write_pos;
}
if ( u32Len > RemainLen )
{
return 1; //队列已满,无法插入队列
}
for ( i = 0; i < u32Len; i++ )
{
UARTTxBuf.Tx_Buffer [ UARTTxBuf.write_pos ] = pData [ i ];
UARTTxBuf.write_pos = (UARTTxBuf.write_pos + 1) % UART_TX_MAX_DEPTH;
}
return 0;
}
static void Protocol_UartHandle(const Protocol_Data_t *pData)
{
if ( pData->CmdID == 0x20 )
{
//printf("0x20 is get\r\n");
if(Prot_User.State < Prot_Start)
{
Prot_User.State = Prot_Start;
printf("Prot_Start \r\n");
}
}
else if(pData->CmdID == 0x03 )
{
//printf("0x03 is get\r\n");
if(Prot_User.State < Prot_Normal)
{
Prot_User.State = Prot_Normal;
printf("Prot_Normal \r\n");
}
if(Prot_User.State >= Prot_Start)
{
// if(pData->DataLen == 33)
{
if(BT_User.HF_Ctrl != pData->Data[0])
{
BT_User.HF_Ctrl = pData->Data[0];
}
if(strncmp((const char *) ble_uerid, (const char *)&(pData->Data[1]), 32) != 0)
{
memcpy(( uint8_t * )ble_uerid, (uint8_t *)&(pData->Data[1]), 32);
}
// esp_log_buffer_hex(TAG, ble_uerid, 32);
// esp_log_buffer_hex(TAG, &(pData->Data[1]), 32);
if(Ble_User.UseridUpdate == 0)
{
bsp_Ble_Init();
printf("get uuid and init ble!!! \r\n");
}
Ble_User.UseridUpdate = 0xAA;
}
}
}
else if(pData->CmdID == 0x21 )
{
//printf("Wifi_OTA_Request is %d\r\n",Wifi_OTA_Request);
if(pData->Data[0] == 1)
{
// if((pData->CmdID & 0xC0) == 0X40)
// {
if(Wifi_OTA_Request == 0)
{
Wifi_OTA_Request = 1;
printf("get ota req! \r\n");
}
// }
}
}
else
{
}
}
void UART_Put(Protocol_uint16_t Data)
{
Protocol_uint32_t nextPos = 0u;
nextPos = (UARTRxBuf.write_pos + 1) % UART_RX_MAX_DEPTH;
if ( nextPos == UARTRxBuf.read_pos )
{
//队列已满,无法插入队列
}
else
{
UARTRxBuf.Rx_Buffer [ UARTRxBuf.write_pos ] = Data;
UARTRxBuf.write_pos = (UARTRxBuf.write_pos + 1) % UART_RX_MAX_DEPTH;
}
//printf("into UARTRxBuf!!!!\r\n");
return;
}
/**
* @brief Protocol协议应用层数据赋值和发送
*/
void Protocol_User_Ctrl_Init(void )
{
Prot_User.State = Prot_Idle;
Prot_User.TimeDelay = 0;
}
void Uart_Send_Id10_Pro(void )
{
uint8_t wtemp[1] = {0};
wtemp[0] = 1;
Protocol_Send(0x10, wtemp, 1);
}
void Uart_Send_Id12_Pro(void )
{
uint8_t ID12[15] = {0};
ID12[0] |= (uint8_t)(BT_User.BT_Sts << 4);
ID12[0] |= Ble_User.Ble_Sts;
unsigned int i = 0;
for(i = 0;i < 14;i++)
{
ID12[ i + 1 ] = BT_Device_Name[ i ];
}
Protocol_Send(0x12, ID12, 15);
}
void Uart_Send_Id01_Pro(void)
{
uint8_t ID01[6] = {0x00,0x00,0x00,0x00,0x00,0x00};
if(Ble_User.Navi_Updat)
{
ID01[0] = Ble_Navi_Data.Navi_Sts;
ID01[1] = Ble_Navi_Data.Navi_Turn;
ID01[2] = Ble_Navi_Data.Navi_Dte[0];
ID01[3] = Ble_Navi_Data.Navi_Dte[1];
ID01[4] = Ble_Navi_Data.Navi_Dte[2];
ID01[5] = Ble_Navi_Data.Navi_Dte[3];
//printf("转向编码:%d\r\n",Ble_Navi_Data.Navi_Turn);
}
Protocol_Send(0x01,ID01,6);
}
void Uart_Send_Id02_Pro(void)
{
uint8_t ID02[1] = {0x00};
ID02[0] = BT_User.Call_Sts;
Protocol_Send(0x02, ID02, 1);
}
void Prot_Send_Msg_Process(void )
{
if(Prot_User.State < Prot_Start)
{
Uart_Send_Id10_Pro();
// printf("send 0x10 \r\n");
}
if(Prot_User.State >= Prot_Start)
{
if(Prot_User.TimeDelay == 0)
{
Uart_Send_Id12_Pro();
Prot_User.TimeDelay++;
// printf("send 0x12 \r\n");
}
else
{
Uart_Send_Id01_Pro();
Uart_Send_Id02_Pro();
Prot_User.TimeDelay = 0;
//printf("send 0x01 0x02 \r\n");
}
}
}
#ifndef PROTOCOL_USER_H
#define PROTOCOL_USER_H
#include "Protocol_Lib.h"
#define BLE_START_STA 0x10
#define MCU_REPLY 0x20
#define BLE_NAVIGATION 0x01
#define BLE_WEATHER 0x02
#define BLE_LOCATION 0x03
#define BLE_STA 0x12
#define MCU_TO_BLE_INFO 0x21
void Protocol_KL30_Wakeup_Init(void);
void Protocol_Send_Service(void); // 10ms任务调用
void UART_Put(Protocol_uint16_t Data);
typedef enum
{
Prot_Idle = 0,
Prot_Starting,
Prot_Start,
Prot_Normal,
}Prot_User_State_Enum;
typedef struct
{
uint8_t State;
uint16_t TimeDelay;
}Protocol_User_Ctrl_Struct;
extern Protocol_User_Ctrl_Struct Prot_User;
void Protocol_User_Ctrl_Init(void );
void Prot_Send_Msg_Process(void );
#endif
#include "app_BT_User.h"
#include <stdio.h>
#include "bt_app_hf.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "bt_app_main.h"
extern esp_bd_addr_t peer_addr;
#define TAG "APP_BLE_USER"
BT_User_Control_Struct BT_User;
#define BT_ReConn_T 3000
void BT_User_Init(void )
{
BT_User.BT_Sts = BT_Idle;
BT_User.Call_Sts = Call_Idle;
BT_User.ReconnTime = BT_ReConn_T - 500;
BT_User.HF_Ctrl = HF_Idle;
}
void BT_Connect_Event_Pro(void )
{
BT_User.BT_Sts = BT_Conn;
BT_User.Call_Sts = Call_Idle;
BT_User.ReconnTime = BT_ReConn_T - 500;
BT_User.HF_Ctrl = HF_Idle;
printf("TB CONN\r\n");
}
void BT_DisConnect_Event_Pro(void )
{
BT_User.BT_Sts = BT_Idle;
BT_User.Call_Sts = Call_Idle;
BT_User.ReconnTime = BT_ReConn_T - 500;
BT_User.HF_Ctrl = HF_Idle;
printf("TB DISCONN\r\n");
}
void BT_User_Process(void )
{
switch(BT_User.Call_Sts)
{
case Call_OutCalling:
{
if(BT_User.HF_Ctrl == HF_Reject)
{
hf_reject_handler();
}
break;
}
case Call_IncomeCalling:
{
if(BT_User.HF_Ctrl == HF_Reject)
{
hf_reject_handler();
}
else if(BT_User.HF_Ctrl == HF_Answer)
{
hf_answer_handler();
}
break;
}
case Call_InProcess:
{
if(BT_User.HF_Ctrl == HF_Reject)
{
hf_reject_handler();
}
break;
}
case Call_Idle:
{
break;
}
}
BT_User.HF_Ctrl = HF_Idle;
if(BT_User.BT_Sts == BT_Idle)
{
BT_User.ReconnTime++;
if(BT_User.ReconnTime >= BT_ReConn_T)
{
printf("Connect Start.................\n");
if(app_BT_Get_BondDev() == 1)
{
esp_hf_client_connect(peer_addr);
}
printf("Connect Over\n");
BT_User.ReconnTime = 0;
}
}
else
{
}
}
#ifndef _APP_BT_USER_H_
#define _APP_BT_USER_H_
#include <stdlib.h>
typedef enum
{
BT_Idle = 0,
BT_Conn,
}BT_Sts_Enum;
typedef enum
{
Call_Idle = 0,
Call_IncomeCalling,
Call_OutCalling,
Call_InProcess,
}Call_Sts_Enum;
typedef enum
{
HF_Idle = 0,
HF_Answer,
HF_Reject,
}Call_HF_Ctrl_Enum;
typedef struct
{
uint8_t BT_Sts;
uint8_t Call_Sts;
uint16_t ReconnTime;
uint8_t HF_Ctrl;
}BT_User_Control_Struct;
extern BT_User_Control_Struct BT_User;
void BT_Connect_Event_Pro(void );
void BT_DisConnect_Event_Pro(void );
void BT_User_Process(void );
void BT_User_Init(void );
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include "freertos/xtensa_api.h"
#include "freertos/FreeRTOSConfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "bt_app_core.h"
static void bt_app_task_handler(void *arg);
static bool bt_app_send_msg(bt_app_msg_t *msg);
static void bt_app_work_dispatched(bt_app_msg_t *msg);
static QueueHandle_t bt_app_task_queue = NULL;
static TaskHandle_t bt_app_task_handle = NULL;
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
{
ESP_LOGD(BT_APP_CORE_TAG, "%s event 0x%x, param len %d", __func__, event, param_len);
bt_app_msg_t msg;
memset(&msg, 0, sizeof(bt_app_msg_t));
msg.sig = BT_APP_SIG_WORK_DISPATCH;
msg.event = event;
msg.cb = p_cback;
if (param_len == 0) {
return bt_app_send_msg(&msg);
} else if (p_params && param_len > 0) {
if ((msg.param = malloc(param_len)) != NULL) {
memcpy(msg.param, p_params, param_len);
/* check if caller has provided a copy callback to do the deep copy */
if (p_copy_cback) {
p_copy_cback(&msg, msg.param, p_params);
}
return bt_app_send_msg(&msg);
}
}
return false;
}
static bool bt_app_send_msg(bt_app_msg_t *msg)
{
if (msg == NULL) {
return false;
}
if (xQueueSend(bt_app_task_queue, msg, 10 / portTICK_PERIOD_MS) != pdTRUE) {
ESP_LOGE(BT_APP_CORE_TAG, "%s xQueue send failed", __func__);
return false;
}
return true;
}
static void bt_app_work_dispatched(bt_app_msg_t *msg)
{
if (msg->cb) {
msg->cb(msg->event, msg->param);
}
}
static void bt_app_task_handler(void *arg)
{
bt_app_msg_t msg;
for (;;) {
if (pdTRUE == xQueueReceive(bt_app_task_queue, &msg, (TickType_t)portMAX_DELAY)) {
ESP_LOGD(BT_APP_CORE_TAG, "%s, sig 0x%x, 0x%x", __func__, msg.sig, msg.event);
switch (msg.sig) {
case BT_APP_SIG_WORK_DISPATCH:
{
bt_app_work_dispatched(&msg);
break;
}
default:
ESP_LOGW(BT_APP_CORE_TAG, "%s, unhandled sig: %d", __func__, msg.sig);
break;
} // switch (msg.sig)
if (msg.param) {
free(msg.param);
}
}
}
}
void bt_app_task_start_up(void)
{
bt_app_task_queue = xQueueCreate(10, sizeof(bt_app_msg_t));
xTaskCreate(bt_app_task_handler, "BtAppT", 2048, NULL, configMAX_PRIORITIES - 3, &bt_app_task_handle);
return;
}
void bt_app_task_shut_down(void)
{
if (bt_app_task_handle) {
vTaskDelete(bt_app_task_handle);
bt_app_task_handle = NULL;
}
if (bt_app_task_queue) {
vQueueDelete(bt_app_task_queue);
bt_app_task_queue = NULL;
}
}
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef __BT_APP_CORE_H__
#define __BT_APP_CORE_H__
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#define BT_APP_CORE_TAG "BT_APP_CORE"
#define BT_APP_SIG_WORK_DISPATCH (0x01)
/**
* @brief handler for the dispatched work
*/
typedef void (* bt_app_cb_t) (uint16_t event, void *param);
/* message to be sent */
typedef struct {
uint16_t sig; /*!< signal to bt_app_task */
uint16_t event; /*!< message event id */
bt_app_cb_t cb; /*!< context switch callback */
void *param; /*!< parameter area needs to be the last */
} bt_app_msg_t;
/**
* @brief parameter deep-copy function to be customized
*/
typedef void (* bt_app_copy_cb_t) (bt_app_msg_t *msg, void *p_dest, void *p_src);
/**
* @brief work dispatcher for the application task
*/
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback);
void bt_app_task_start_up(void);
void bt_app_task_shut_down(void);
#endif /* __BT_APP_CORE_H__ */
This diff is collapsed.
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef __BT_APP_HF_H__
#define __BT_APP_HF_H__
#include <stdint.h>
#include "esp_hf_client_api.h"
#define BT_HF_TAG "BT_HF"
/**
* @brief callback function for HF client
*/
void bt_app_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_t *param);
int hf_conn_handler(void );
int hf_disc_handler(void );
int hf_conn_audio_handler(void );
int hf_disc_audio_handler(void );
int hf_query_op_handler(void );
int hf_answer_handler(void );
int hf_reject_handler(void );
int hf_dial_handler(void );
int hf_redial_handler(void );
int hf_dial_mem_handler(void );
int hf_start_vr_handler(void );
int hf_stop_vr_handler(void );
#endif /* __BT_APP_HF_H__*/
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "esp_system.h"
#include "esp_log.h"
#include "esp_bt.h"
#include "bt_app_core.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "esp_gap_bt_api.h"
#include "esp_hf_client_api.h"
#include "bt_app_hf.h"
// #include "gpio_pcm_config.h"
#include "esp_console.h"
// #include "app_hf_msg_set.h"
#include "app_BT_User.h"
#include "gatts_table_creat_demo.h"
esp_bd_addr_t peer_addr = {0};
static char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
static uint8_t peer_bdname_len;
int bond_dev_num;
int last_bond_dev_num = -1;
// esp_bt_gap_remove_bond_device
uint8_t app_BT_Get_BondDev(void )
{
uint8_t ret = 0;
bond_dev_num = esp_bt_gap_get_bond_device_num();
if(bond_dev_num)
{
esp_bd_addr_t *dev_list = (esp_bd_addr_t *)malloc(sizeof(esp_bd_addr_t) * bond_dev_num);
esp_bt_gap_get_bond_device_list(&bond_dev_num, dev_list);
memcpy(peer_addr, dev_list[0], 6);
if(bond_dev_num > 1)
{
for(int i=1; i<bond_dev_num; i++)
{
esp_bt_gap_remove_bond_device(dev_list[i]);
}
}
ret = 1;
}
else
{
memset(peer_addr, 0, 6);
ret = 0;
}
return ret;
}
void BT_Remove_Other_BondDev(void )
{
}
// static const char remote_device_name[] = "ESP_HFP_AG";
static bool get_name_from_eir(uint8_t *eir, char *bdname, uint8_t *bdname_len)
{
uint8_t *rmt_bdname = NULL;
uint8_t rmt_bdname_len = 0;
if (!eir) {
return false;
}
rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_CMPL_LOCAL_NAME, &rmt_bdname_len);
if (!rmt_bdname) {
rmt_bdname = esp_bt_gap_resolve_eir_data(eir, ESP_BT_EIR_TYPE_SHORT_LOCAL_NAME, &rmt_bdname_len);
}
if (rmt_bdname) {
if (rmt_bdname_len > ESP_BT_GAP_MAX_BDNAME_LEN) {
rmt_bdname_len = ESP_BT_GAP_MAX_BDNAME_LEN;
}
if (bdname) {
memcpy(bdname, rmt_bdname, rmt_bdname_len);
bdname[rmt_bdname_len] = '\0';
}
if (bdname_len) {
*bdname_len = rmt_bdname_len;
}
return true;
}
return false;
}
void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch (event) {
case ESP_BT_GAP_DISC_RES_EVT: {
// esp_hf_client_connect(peer_addr);
// esp_bt_gap_cancel_discovery();
// printf("event state %d\n", event);
break;
}
case ESP_BT_GAP_DISC_STATE_CHANGED_EVT:
ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_DISC_STATE_CHANGED_EVT");
case ESP_BT_GAP_RMT_SRVCS_EVT:
case ESP_BT_GAP_RMT_SRVC_REC_EVT:
// printf("event state %d\n", event);
break;
case ESP_BT_GAP_AUTH_CMPL_EVT: {
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
ESP_LOGI(BT_HF_TAG, "authentication success: %s", param->auth_cmpl.device_name);
esp_log_buffer_hex(BT_HF_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
} else {
ESP_LOGE(BT_HF_TAG, "authentication failed, status:%d", param->auth_cmpl.stat);
}
// printf("event state %d\n", event);
break;
}
case ESP_BT_GAP_PIN_REQ_EVT: {
ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_PIN_REQ_EVT min_16_digit:%d", param->pin_req.min_16_digit);
if (param->pin_req.min_16_digit) {
ESP_LOGI(BT_HF_TAG, "Input pin code: 0000 0000 0000 0000");
esp_bt_pin_code_t pin_code = {0};
esp_bt_gap_pin_reply(param->pin_req.bda, true, 16, pin_code);
} else {
ESP_LOGI(BT_HF_TAG, "Input pin code: 1234");
esp_bt_pin_code_t pin_code;
pin_code[0] = '1';
pin_code[1] = '2';
pin_code[2] = '3';
pin_code[3] = '4';
esp_bt_gap_pin_reply(param->pin_req.bda, true, 4, pin_code);
}
// printf("event state %d\n", event);
break;
}
#if (CONFIG_BT_SSP_ENABLED == true)
case ESP_BT_GAP_CFM_REQ_EVT:
ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: %"PRIu32, param->cfm_req.num_val);
esp_bt_gap_ssp_confirm_reply(param->cfm_req.bda, true);
// printf("event state %d\n", event);
break;
case ESP_BT_GAP_KEY_NOTIF_EVT:
ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_KEY_NOTIF_EVT passkey:%"PRIu32, param->key_notif.passkey);
// printf("event state %d\n", event);
break;
case ESP_BT_GAP_KEY_REQ_EVT:
ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_KEY_REQ_EVT Please enter passkey!");
// printf("event state %d\n", event);
break;
#endif
case ESP_BT_GAP_MODE_CHG_EVT:
ESP_LOGI(BT_HF_TAG, "ESP_BT_GAP_MODE_CHG_EVT mode:%d", param->mode_chg.mode);
// printf("event state %d\n", event);
break;
default: {
ESP_LOGI(BT_HF_TAG, "event: %d", event);
// printf("event state %d\n", event);
break;
}
}
return;
}
/* event for handler "bt_av_hdl_stack_up */
enum {
BT_APP_EVT_STACK_UP = 0,
};
/* handler for bluetooth stack enabled events */
static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param);
void bsp_BT_Init(void)
{
/* Initialize NVS — it is used to store PHY calibration data */
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
// ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));
esp_err_t err;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
if ((err = esp_bt_controller_init(&bt_cfg)) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
if ((err = esp_bt_controller_enable(ESP_BT_MODE_BTDM)) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
if ((err = esp_bluedroid_init()) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
if ((err = esp_bluedroid_enable()) != ESP_OK) {
ESP_LOGE(BT_HF_TAG, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
/* create application task */
bt_app_task_start_up();
/* Bluetooth device name, connection mode and profile set up */
bt_app_work_dispatch(bt_hf_client_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
#if CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM
/* configure the PCM interface and PINs used */
// app_gpio_pcm_io_cfg();
#endif
/* configure externel chip for acoustic echo cancellation */
#if ACOUSTIC_ECHO_CANCELLATION_ENABLE
// app_gpio_aec_io_cfg();
#endif /* ACOUSTIC_ECHO_CANCELLATION_ENABLE */
// esp_console_repl_t *repl = NULL;
// esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
// esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
// repl_config.prompt = "hfp_hf>";
// // init console REPL environment
// ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
/* Register commands */
// register_hfp_hf();
// printf("\n ==================================================\n");
// printf(" | Steps to test hfp_hf |\n");
// printf(" | |\n");
// printf(" | 1. Print 'help' to gain overview of commands |\n");
// printf(" | 2. Setup a service level connection |\n");
// printf(" | 3. Run hfp_hf to test |\n");
// printf(" | |\n");
// printf(" =================================================\n\n");
// start console REPL
// ESP_ERROR_CHECK(esp_console_start_repl(repl));
}
static void bt_hf_client_hdl_stack_evt(uint16_t event, void *p_param)
{
ESP_LOGD(BT_HF_TAG, "%s evt %d", __func__, event);
switch (event) {
case BT_APP_EVT_STACK_UP: {
/* set up device name */
char *dev_name = "ESP_HFP_HF";
esp_bt_dev_set_device_name((char *)BT_Device_Name);
/* register GAP callback function */
esp_bt_gap_register_callback(esp_bt_gap_cb);
esp_hf_client_register_callback(bt_app_hf_client_cb);
esp_hf_client_init();
esp_bt_pin_type_t pin_type = ESP_BT_PIN_TYPE_FIXED;
esp_bt_pin_code_t pin_code;
pin_code[0] = '0';
pin_code[1] = '0';
pin_code[2] = '0';
pin_code[3] = '0';
esp_bt_gap_set_pin(pin_type, 4, pin_code);
/* set discoverable and connectable mode, wait to be connected */
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
/* start device discovery */
ESP_LOGI(BT_HF_TAG, "Starting device discovery...");
esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, 10, 0);
break;
}
default:
ESP_LOGE(BT_HF_TAG, "%s unhandled evt %d", __func__, event);
break;
}
}
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef BT_APP_MAN_H
#define BT_APP_MAN_H
void bsp_BT_Init(void);
uint8_t app_BT_Get_BondDev(void );
#endif
\ No newline at end of file
This diff is collapsed.
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#ifndef GATTS_TABLE_CREAT_DEMO_H
#define GATTS_TABLE_CREAT_DEMO_H
/* Attributes State Machine */
enum
{
IDX_SVC,
IDX_CHAR_2A29,
IDX_CHAR_VAL_2A29,
IDX_CHAR_CFG_2A29,
IDX_CHAR_2A24,
IDX_CHAR_VAL_2A24,
IDX_CHAR_CFG_2A24,
IDX_CHAR_2A25,
IDX_CHAR_VAL_2A25,
IDX_CHAR_CFG_2A25,
IDX_CHAR_2A27,
IDX_CHAR_VAL_2A27,
IDX_CHAR_CFG_2A27,
IDX_CHAR_2A26,
IDX_CHAR_VAL_2A26,
IDX_CHAR_CFG_2A26,
IDX_CHAR_2A28,
IDX_CHAR_VAL_2A28,
IDX_CHAR_CFG_2A28,
IDX_CHAR_2A23,
IDX_CHAR_VAL_2A23,
IDX_CHAR_CFG_2A23,
IDX_CHAR_2A2A,
IDX_CHAR_VAL_2A2A,
IDX_CHAR_CFG_2A2A,
IDX_CHAR_2A50,
IDX_CHAR_VAL_2A50,
IDX_CHAR_CFG_2A50,
HRS_IDX_NB,
};
enum
{
IDX_SVC2,
IDX_CHAR_A2,
IDX_CHAR_VAL_A2,
IDX_CHAR_CFG_A2,
HRS_IDX_NB2,
};
void bsp_Ble_Init(void);
void bsp_Uart_Init(void );
int bsp_Ble_Gatts_Send_Indicate(uint8_t len, uint8_t *data);
void simple_ota_service(void);
extern uint8_t BT_Device_Name[14];
void Get_Mac_Init(void );
extern int bsp_Uart_Send_Data(uint8_t * data , unsigned int len);
extern uint8_t BT_Device_Name[14];
#endif
\ No newline at end of file
#include "app_Ble_User.h"
#include "gatts_table_creat_demo.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "gatts_table_creat_demo.h"
#include "main_user.h"
#include "Protocol_CRC16.h"
#include "Protocol_User.h"
#include "bt_app_main.h"
#include "app_BT_User.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "string.h"
#include "driver/gpio.h"
#include "MCU_Core_Protocol.h"
#include "Protocol_Lib.h"
#include "app_Ble_User.h"
#include "app_BT_User.h"
#include "bt_app_hf.h"
#define TAG "MAIN_USER"
extern esp_bd_addr_t peer_addr;
uint32_t Sys_1ms_Cnt;
#define SYS_RUN_TASK_1MS (1)
#define SYS_RUN_TASK_10MS (Sys_1ms_Cnt % 10 == 1)
#define SYS_RUN_TASK_20MS (Sys_1ms_Cnt % 20 == 2)
#define SYS_RUN_TASK_50MS (Sys_1ms_Cnt % 50 == 3)
#define SYS_RUN_TASK_100MS (Sys_1ms_Cnt % 100 == 4)
#define SYS_RUN_TASK_1000MS (Sys_1ms_Cnt % 1000 == 5)
uint32_t testcnt;
static void Sys_Run_Tasks(void *arg)
{
uint8_t i = 0;
while(1)
{
if(Sys_1ms_Cnt < 499)
{
Sys_1ms_Cnt ++ ;
}
else
{
Sys_1ms_Cnt = 0;
}
if(SYS_RUN_TASK_10MS)
{
Protocol_Send_Service();
Protocol_Service();
BT_User_Process();
}
if(SYS_RUN_TASK_20MS)
{
}
if(SYS_RUN_TASK_50MS)
{
Prot_Send_Msg_Process();
}
if(SYS_RUN_TASK_100MS)
{
Ble_MsgRec_Navi_Timeout();
}
if(SYS_RUN_TASK_1000MS)
{
simple_ota_service();
testcnt++;
if(testcnt >= 10)
{
testcnt = 0;
printf("BT_User.BT_Sts = %d\r\n", BT_User.BT_Sts);
printf("Ble_User.Ble_Sts = %d\r\n", Ble_User.Ble_Sts);
// esp_log_buffer_hex(TAG, peer_addr, 6);
// printf("Ble_User.Navi_Updat = %d\r\n", Ble_User.Navi_Updat);
// printf("RecCtrl.Sts = %d\r\n", RecCtrl.Sts);
// Ble_Msg_RequestNavi_RLY();
// if(Prot_User.State < Prot_Normal)
// {
// Prot_User.State = Prot_Normal;
// printf("Prot_Normal \r\n");
// }
}
}
vTaskDelay(1);
}
vTaskDelete(NULL);
}
void app_main(void)
{
Protocol_User_Ctrl_Init();
BT_User_Init();
Ble_User_Init();
Get_Mac_Init();
bsp_BT_Init();
// bsp_Ble_Init();
bsp_Uart_Init();
printf("KL30 INIT OVER~~~~~~\r\n");
xTaskCreatePinnedToCore(Sys_Run_Tasks, "Sys_Run_Tasks", 4096, NULL, 3, NULL, 1);
}
#ifndef _MAIN_USER_H_
#define _MAIN_USER_H_
#endif
\ No newline at end of file
/* OTA example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_http_client.h"
#include "esp_https_ota.h"
#include "protocol_examples_common.h"
#include "string.h"
#ifdef CONFIG_EXAMPLE_USE_CERT_BUNDLE
#include "esp_crt_bundle.h"
#endif
#include "nvs.h"
#include "nvs_flash.h"
#include "protocol_examples_common.h"
#include <sys/socket.h>
#if CONFIG_EXAMPLE_CONNECT_WIFI
#include "esp_wifi.h"
#endif
#define HASH_LEN 32
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
/* The interface name value can refer to if_desc in esp_netif_defaults.h */
#if CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_ETH
static const char *bind_interface_name = EXAMPLE_NETIF_DESC_ETH;
#elif CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF_STA
static const char *bind_interface_name = EXAMPLE_NETIF_DESC_STA;
#endif
#endif
static const char *TAG = "simple_ota_example";
extern const uint8_t server_cert_pem_start[] asm("_binary_ca_cert_pem_start");
extern const uint8_t server_cert_pem_end[] asm("_binary_ca_cert_pem_end");
#define OTA_URL_SIZE 256
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
{
switch (evt->event_id) {
case HTTP_EVENT_ERROR:
ESP_LOGD(TAG, "HTTP_EVENT_ERROR");
break;
case HTTP_EVENT_ON_CONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_ON_CONNECTED");
break;
case HTTP_EVENT_HEADER_SENT:
ESP_LOGD(TAG, "HTTP_EVENT_HEADER_SENT");
break;
case HTTP_EVENT_ON_HEADER:
ESP_LOGD(TAG, "HTTP_EVENT_ON_HEADER, key=%s, value=%s", evt->header_key, evt->header_value);
break;
case HTTP_EVENT_ON_DATA:
ESP_LOGD(TAG, "HTTP_EVENT_ON_DATA, len=%d", evt->data_len);
break;
case HTTP_EVENT_ON_FINISH:
ESP_LOGD(TAG, "HTTP_EVENT_ON_FINISH");
break;
case HTTP_EVENT_DISCONNECTED:
ESP_LOGD(TAG, "HTTP_EVENT_DISCONNECTED");
break;
case HTTP_EVENT_REDIRECT:
ESP_LOGD(TAG, "HTTP_EVENT_REDIRECT");
break;
}
return ESP_OK;
}
void simple_ota_example_task(void *pvParameter)
{
int i = 0;
ESP_LOGI(TAG, "Starting OTA example task");
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
esp_netif_t *netif = get_example_netif_from_desc(bind_interface_name);
if (netif == NULL) {
ESP_LOGE(TAG, "Can't find netif from interface description");
abort();
}
struct ifreq ifr;
esp_netif_get_netif_impl_name(netif, ifr.ifr_name);
ESP_LOGI(TAG, "Bind interface name is %s", ifr.ifr_name);
#endif
esp_http_client_config_t config = {
.url = CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL,
#ifdef CONFIG_EXAMPLE_USE_CERT_BUNDLE
.crt_bundle_attach = esp_crt_bundle_attach,
#else
.cert_pem = (char *)server_cert_pem_start,
#endif /* CONFIG_EXAMPLE_USE_CERT_BUNDLE */
.event_handler = _http_event_handler,
.keep_alive_enable = true,
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
.if_name = &ifr,
#endif
};
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL_FROM_STDIN
char url_buf[OTA_URL_SIZE];
if (strcmp(config.url, "FROM_STDIN") == 0) {
example_configure_stdin_stdout();
fgets(url_buf, OTA_URL_SIZE, stdin);
int len = strlen(url_buf);
url_buf[len - 1] = '\0';
config.url = url_buf;
} else {
ESP_LOGE(TAG, "Configuration mismatch: wrong firmware upgrade image url");
abort();
}
#endif
#ifdef CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK
config.skip_cert_common_name_check = true;
#endif
esp_https_ota_config_t ota_config = {
.http_config = &config,
};
ESP_LOGI(TAG, "Attempting to download update from %s", config.url);
esp_err_t ret = esp_https_ota(&ota_config);
if (ret == ESP_OK) {
ESP_LOGI(TAG, "OTA Succeed");
printf("\n");
printf("==========================================================\n");
for(i = 5; i > 0; i--)
{
printf("============ System will restart in %d second. ============\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("============ System rebooting... ============\n");
printf("==========================================================\n");
printf("\n");
esp_restart();
} else {
ESP_LOGE(TAG, "Firmware upgrade failed");
}
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
static void print_sha256(const uint8_t *image_hash, const char *label)
{
char hash_print[HASH_LEN * 2 + 1];
hash_print[HASH_LEN * 2] = 0;
for (int i = 0; i < HASH_LEN; ++i) {
sprintf(&hash_print[i * 2], "%02x", image_hash[i]);
}
ESP_LOGI(TAG, "%s %s", label, hash_print);
}
static void get_sha256_of_partitions(void)
{
uint8_t sha_256[HASH_LEN] = { 0 };
esp_partition_t partition;
// get sha256 digest for bootloader
partition.address = ESP_BOOTLOADER_OFFSET;
partition.size = ESP_PARTITION_TABLE_OFFSET;
partition.type = ESP_PARTITION_TYPE_APP;
esp_partition_get_sha256(&partition, sha_256);
print_sha256(sha_256, "SHA-256 for bootloader: ");
// get sha256 digest for running partition
esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256);
print_sha256(sha_256, "SHA-256 for current firmware: ");
}
void simple_ota_main(void)
{
ESP_LOGI(TAG, "OTA example app_main start");
// Initialize NVS.
// esp_err_t err = nvs_flash_init();
// if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
// 1.OTA app partition table has a smaller NVS partition size than the non-OTA
// partition table. This size mismatch may cause NVS initialization to fail.
// 2.NVS partition contains data in new format and cannot be recognized by this version of code.
// If this happens, we erase NVS partition and initialize NVS again.
// ESP_ERROR_CHECK(nvs_flash_erase());
// err = nvs_flash_init();
// }
// ESP_ERROR_CHECK(err);
get_sha256_of_partitions();
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
/* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig.
* Read "Establishing Wi-Fi or Ethernet Connection" section in
* examples/protocols/README.md for more information about this function.
*/
ESP_ERROR_CHECK(example_connect());
#if CONFIG_EXAMPLE_CONNECT_WIFI
/* Ensure to disable any WiFi power save mode, this allows best throughput
* and hence timings for overall OTA operation.
*/
esp_wifi_set_ps(WIFI_PS_NONE);
#endif // CONFIG_EXAMPLE_CONNECT_WIFI
xTaskCreate(&simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);
}
This diff is collapsed.
This diff is collapsed.
CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF=y
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_EXAMPLE_CONNECT_IPV6=n
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_SECURE_FLASH_ENC_ENABLED=y
CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT=y
CONFIG_SECURE_BOOT_ALLOW_ROM_BASIC=y
CONFIG_SECURE_BOOT_ALLOW_JTAG=y
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC=y
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC=y
CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE=y
CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED=y
CONFIG_PARTITION_TABLE_OFFSET=0x9000
CONFIG_EXAMPLE_CONNECT_ETHERNET=n
CONFIG_EXAMPLE_CONNECT_WIFI=y
CONFIG_EXAMPLE_WIFI_SSID_PWD_FROM_STDIN=y
# This is required for nvs encryption (which is enabled by default with flash encryption)
CONFIG_PARTITION_TABLE_TWO_OTA_ENCRYPTED_NVS=y
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_EXAMPLE_CONNECT_IPV6=n
# ECDSA is available only in ESP32
CONFIG_IDF_TARGET="esp32"
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_PARTITION_TABLE_OFFSET=0xC000
CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT=y
CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT=y
CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME=y
CONFIG_SECURE_BOOT_SIGNING_KEY="test/secure_boot_signing_key_ecdsa.pem"
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
CONFIG_EXAMPLE_CONNECT_WIFI=n
CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y
CONFIG_EXAMPLE_ETH_PHY_IP101=y
CONFIG_EXAMPLE_ETH_MDC_GPIO=23
CONFIG_EXAMPLE_ETH_MDIO_GPIO=18
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
CONFIG_EXAMPLE_CONNECT_IPV6=y
# ESP32 supports SIGNED_APPS_RSA_SCHEME only in ECO3
CONFIG_ESP32_REV_MIN_3=y
CONFIG_ESP32_REV_MIN=3
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_PARTITION_TABLE_OFFSET=0xC000
CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT=y
CONFIG_SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT=y
CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME=y
CONFIG_SECURE_BOOT_SIGNING_KEY="test/secure_boot_signing_key.pem"
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
CONFIG_EXAMPLE_CONNECT_WIFI=n
CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y
CONFIG_EXAMPLE_ETH_PHY_IP101=y
CONFIG_EXAMPLE_ETH_MDC_GPIO=23
CONFIG_EXAMPLE_ETH_MDIO_GPIO=18
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_EXAMPLE_CONNECT_IPV6=n
CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN"
CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y
CONFIG_SPIRAM=y
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
CONFIG_EXAMPLE_CONNECT_WIFI=n
CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y
CONFIG_EXAMPLE_ETH_PHY_IP101=y
CONFIG_EXAMPLE_ETH_MDC_GPIO=23
CONFIG_EXAMPLE_ETH_MDIO_GPIO=18
CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=5
CONFIG_EXAMPLE_ETH_PHY_ADDR=1
CONFIG_EXAMPLE_CONNECT_IPV6=y
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_BT_ENABLED=y
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
CONFIG_IDF_TARGET="esp32c2"
CONFIG_BT_ENABLED=y
# CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
# CONFIG_BT_LE_50_FEATURE_SUPPORT is not set
CONFIG_BT_LE_HCI_EVT_BUF_SIZE=257
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment