sdk5.12 build

This commit is contained in:
Holy 2024-02-19 09:58:15 +08:00
parent 905f936721
commit f305cb1a2e
16 changed files with 3109 additions and 582 deletions

View File

@ -12,7 +12,7 @@
#include "esp_check.h" #include "esp_check.h"
#define MOTOR_CTRL_TIMER_DIVIDER (16) // Hardware timer clock divider #define MOTOR_CTRL_TIMER_DIVIDER (16) // Hardware timer clock divider
#define MOTOR_CTRL_TIMER_SCALE (TIMER_BASE_CLK / MOTOR_CTRL_TIMER_DIVIDER) // convert counter value to seconds #define MOTOR_CTRL_TIMER_SCALE (TIMER_SRC_CLK_APB / MOTOR_CTRL_TIMER_DIVIDER) // convert counter value to seconds
#define MOTOR_CONTROL_TIMER_GROUP TIMER_GROUP_0 #define MOTOR_CONTROL_TIMER_GROUP TIMER_GROUP_0
#define MOTOR_CONTROL_TIMER_ID TIMER_0 #define MOTOR_CONTROL_TIMER_ID TIMER_0

View File

@ -59,10 +59,10 @@ static uint16_t spp_mtu_size = 23;
uint16_t spp_conn_id = 0xffff; uint16_t spp_conn_id = 0xffff;
esp_gatt_if_t spp_gatts_if = 0xff; esp_gatt_if_t spp_gatts_if = 0xff;
QueueHandle_t spp_uart_queue = NULL; QueueHandle_t spp_uart_queue = NULL;
static xQueueHandle cmd_cmd_queue = NULL; static QueueHandle_t cmd_cmd_queue = NULL;
#ifdef SUPPORT_HEARTBEAT #ifdef SUPPORT_HEARTBEAT
static xQueueHandle cmd_heartbeat_queue = NULL; static QueueHandle_t cmd_heartbeat_queue = NULL;
static uint8_t heartbeat_s[9] = {'E','s','p','r','e','s','s','i','f'}; static uint8_t heartbeat_s[9] = {'E','s','p','r','e','s','s','i','f'};
static bool enable_heart_ntf = false; static bool enable_heart_ntf = false;
static uint8_t heartbeat_count_num = 0; static uint8_t heartbeat_count_num = 0;

View File

@ -101,7 +101,7 @@ static void twai_receive_task(void *arg)
{ {
index += sprintf(&msg_data_str[i], "%02x ", rx_msg.data[i]); index += sprintf(&msg_data_str[i], "%02x ", rx_msg.data[i]);
} }
ESP_LOGI(TAG, "recive msg id=%x,len=%d,data=[%s]", rx_msg.identifier, rx_msg.data_length_code, msg_data_str); ESP_LOGI(TAG, "recive msg id=%lx,len=%u,data=[%s]", rx_msg.identifier, rx_msg.data_length_code, msg_data_str);
} }
} }
} }

View File

@ -25,15 +25,15 @@
#include "esp_check.h" #include "esp_check.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "driver/mcpwm.h" #include "driver/mcpwm.h"
#include "driver/uart.h"
/*蓝牙相关的头文件*/ /*蓝牙相关的头文件*/
#include "esp_bt.h" #include "esp_bt.h"
#include "driver/uart.h"
#include "esp_gap_ble_api.h" #include "esp_gap_ble_api.h"
#include "esp_gatts_api.h" #include "esp_gatts_api.h"
#include "esp_bt_defs.h" #include "esp_bt_defs.h"
#include "esp_bt_main.h" #include "esp_bt_main.h"
/* The examples use WiFi configuration that you can set via project configuration menu /* The examples use WiFi configuration that you can set via project configuration menu
If you'd rather not, just change the below entries to strings with If you'd rather not, just change the below entries to strings with
@ -105,8 +105,8 @@ void app_main(void)
ESP_ERROR_CHECK(i2c_master_init()); ESP_ERROR_CHECK(i2c_master_init());
config_load(); config_load();
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
rtc_clk_apb_freq = rtc_clk_apb_freq_get(); // rtc_clk_apb_freq = rtc_clk_apb_freq_get();
ESP_LOGI(TAG, "rtc_clk_apb_freq=%d", rtc_clk_apb_freq); // ESP_LOGI(TAG, "rtc_clk_apb_freq=%u", rtc_clk_apb_freq);
wifi_init_softap();//ok wifi_init_softap();//ok
// wifi_init_sta(); // wifi_init_sta();

1960
main/sdkconfig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -92,10 +92,10 @@ static spi_device_handle_t spi2;
#define ESP_INTR_FLAG_DEFAULT 0 #define ESP_INTR_FLAG_DEFAULT 0
int ads1220_watchdog = 0; int ads1220_watchdog = 0;
extern xQueueHandle gpio_evt_queue; extern QueueHandle_t gpio_evt_queue;
xQueueHandle gpio_evt_queue = NULL; QueueHandle_t gpio_evt_queue = NULL;
uint16_t gWordVar[gWORD_SIZE]; // uint16_t gWordVar[gWORD_SIZE];
int ad_value[4]; int ad_value[4];
uint32_t ad_update_time[4]; uint32_t ad_update_time[4];
uint8_t ad_watchdog_cnt = 0; uint8_t ad_watchdog_cnt = 0;

View File

@ -25,9 +25,7 @@
extern move_t *pMoveCtx; extern move_t *pMoveCtx;
// To speed up transfers, every SPI transfer sends a bunch of lines. This define specifies how many. More means more memory use,
// but less overhead for setting up / finishing transfers. Make sure 240 is dividable by this.
#define PARALLEL_LINES 16
static spi_device_handle_t spi1; static spi_device_handle_t spi1;
static void SPI1_Init(void) static void SPI1_Init(void)
@ -40,15 +38,11 @@ static void SPI1_Init(void)
.sclk_io_num = SPI1_PIN_NUM_CLK, .sclk_io_num = SPI1_PIN_NUM_CLK,
.quadwp_io_num = -1, .quadwp_io_num = -1,
.quadhd_io_num = -1, .quadhd_io_num = -1,
.max_transfer_sz = PARALLEL_LINES * 320 * 2 + 8}; .max_transfer_sz = 128
};
spi_device_interface_config_t devcfg1 = { spi_device_interface_config_t devcfg1 = {
#ifdef CONFIG_LCD_OVERCLOCK
.clock_speed_hz = 26 * 1000 * 1000, // Clock out at 26 MHz
#else
.clock_speed_hz = 8 * 100 * 1000, // Clock out at 800kHz .clock_speed_hz = 8 * 100 * 1000, // Clock out at 800kHz
#endif
.mode = 1, // SPI mode 1 .mode = 1, // SPI mode 1
.spics_io_num = SPI1_PIN_NUM_CS, // CS pin .spics_io_num = SPI1_PIN_NUM_CS, // CS pin
.queue_size = 7, // We want to be able to queue 7 transactions at a time .queue_size = 7, // We want to be able to queue 7 transactions at a time

View File

@ -9,6 +9,7 @@
#include "esp_check.h" #include "esp_check.h"
#include "soc/rtc.h" #include "soc/rtc.h"
#include "driver/mcpwm.h" #include "driver/mcpwm.h"
#include "driver/gpio.h"
const static char *TAG = "capture"; const static char *TAG = "capture";

View File

@ -29,7 +29,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
static const char *TAG = "depth"; static const char *TAG = "depth";
typedef struct typedef struct
@ -103,22 +102,58 @@ typedef struct
// 18字节 // 18字节
#pragma pack(1) #pragma pack(1)
typedef struct { typedef struct
{
uint8_t TAG; uint8_t TAG;
int16_t speed; int16_t speed;
int16_t depth; int16_t depth;
int16_t tilt_x; int16_t flow[2];
int16_t tilt_y; uint32_t total_flow[2];
uint16_t current1; uint16_t current1;
uint16_t current2; uint16_t current2;
} send_to_bt_t1; } send_to_bt_t1;
// 16字节 // 16字节
typedef struct{ typedef struct
{
uint8_t TAG; uint8_t TAG;
int16_t flow[2]; uint8_t status;
uint32_t total_flow[2]; uint8_t LAT[5];
uint8_t LOG[5];
int16_t ALT; // 海拔高度
int16_t speed;
uint32_t UTC;
// uint16_t dir;
// uint16_t speed;
// int16_t tilt_x;
// int16_t tilt_y;
} position_t;
typedef struct
{
uint8_t TAG;
int16_t distence;
int16_t pitch;
int16_t azimuth;
int16_t tilt_x;
int16_t tilt_y;
}direction_t;
typedef struct
{
uint8_t TAG;
uint8_t status;
uint8_t LAT[5];
uint8_t LOG[5];
int16_t ALT; // 海拔高度
int16_t speed;
uint32_t UTC;
// uint16_t dir;
// uint16_t speed;
// int16_t tilt_x;
// int16_t tilt_y;
} send_to_bt_t2; } send_to_bt_t2;
#pragma pack() #pragma pack()
typedef struct typedef struct
@ -138,13 +173,11 @@ typedef struct
// uint16_t current3; // uint16_t current3;
} depth_t; } depth_t;
record_t *record = (record_t *)&gWordVar[RECORD_REG_ADDR]; record_t *record = (record_t *)&gWordVar[RECORD_REG_ADDR];
depth_t *depth_data = (depth_t *)&gWordVar[DEPTH_REG_ADDR]; depth_t *depth_data = (depth_t *)&gWordVar[DEPTH_REG_ADDR];
move_t *pMoveCtx = (move_t *)&gWordVar[MOVE_REG_ADDR]; move_t *pMoveCtx = (move_t *)&gWordVar[MOVE_REG_ADDR];
depth_config_t *depth_config = (depth_config_t *)&gWordVar[DEPTH_CONFIG_ADDR]; depth_config_t *depth_config = (depth_config_t *)&gWordVar[DEPTH_CONFIG_ADDR];
rotary_encoder_t *encoder = NULL; // 编码器测量深度参数 rotary_encoder_t *encoder = NULL; // 编码器测量深度参数
// static uint32_t cap_val_begin_of_depth = 0; // static uint32_t cap_val_begin_of_depth = 0;
@ -286,7 +319,6 @@ int abs_sub(uint32_t enc_update_time, uint32_t _enc_update_time)
} }
} }
send_to_bt_t1 send_to_bt1; send_to_bt_t1 send_to_bt1;
send_to_bt_t2 send_to_bt2; send_to_bt_t2 send_to_bt2;
extern bool is_connected; extern bool is_connected;
@ -295,73 +327,81 @@ extern uint16_t spp_conn_id;
extern esp_gatt_if_t spp_gatts_if; extern esp_gatt_if_t spp_gatts_if;
extern flow_t *pflow; extern flow_t *pflow;
/*把两个结构体中的数据通过蓝牙发送*/ /*把两个结构体中的数据通过蓝牙发送*/
void send_data_to_bt(void){ void send_data_to_bt(void)
{
#if SEND_DATA_TEST // #if SEND_DATA_TEST
send_to_bt1.TAG = 1; // send_to_bt1.TAG = 1;
send_to_bt1.speed = 2; // send_to_bt1.speed = 2;
send_to_bt1.depth = 3; // send_to_bt1.depth = 3;
send_to_bt1.tilt_x = 4; // send_to_bt1.tilt_x = 4;
send_to_bt1.tilt_y = 5; // send_to_bt1.tilt_y = 5;
send_to_bt1.current1 = 6; // send_to_bt1.current1 = 6;
send_to_bt1.current2 = 7; // send_to_bt1.current2 = 7;
send_to_bt2.TAG = 2; // send_to_bt2.TAG = 2;
send_to_bt2.flow[0] = 3; // send_to_bt2.flow[0] = 3;
send_to_bt2.flow[1] = 4; // send_to_bt2.flow[1] = 4;
send_to_bt2.total_flow[0] = 5; // send_to_bt2.total_flow[0] = 5;
send_to_bt2.total_flow[1] = 6; // send_to_bt2.total_flow[1] = 6;
ESP_LOGI(TAG, "set text data that send to bt\n"); // ESP_LOGI(TAG, "set text data that send to bt\n");
#else // #else
ESP_LOGI(TAG, "use real time data that send to bt\n"); // ESP_LOGI(TAG, "use real time data that send to bt\n");
send_to_bt1.TAG = 1; // send_to_bt1.TAG = 1;
send_to_bt1.tilt_x = (short)gWordVar[TILT_SENSER_ADDR]; // send_to_bt1.tilt_x = (short)gWordVar[TILT_SENSER_ADDR];
send_to_bt1.tilt_y = (short)gWordVar[TILT_SENSER_ADDR + 1]; // send_to_bt1.tilt_y = (short)gWordVar[TILT_SENSER_ADDR + 1];
send_to_bt1.speed = depth_data->speed; // send_to_bt1.speed = depth_data->speed;
send_to_bt1.depth = depth_data->depth; // send_to_bt1.depth = depth_data->depth;
if (depth_config->move_current_channel == 2){ // if (depth_config->move_current_channel == 2)
send_to_bt1.current1 = gWordVar[AC_CURRENT_REG_ADDR]; // {
send_to_bt1.current2 = gWordVar[AC_CURRENT_REG_ADDR + 1]; // send_to_bt1.current1 = gWordVar[AC_CURRENT_REG_ADDR];
} // send_to_bt1.current2 = gWordVar[AC_CURRENT_REG_ADDR + 1];
else if (depth_config->move_current_channel == 1){ // }
send_to_bt1.current1 = gWordVar[AC_CURRENT_REG_ADDR]; // else if (depth_config->move_current_channel == 1)
send_to_bt1.current2 = gWordVar[AC_CURRENT_REG_ADDR + 2]; // {
} // send_to_bt1.current1 = gWordVar[AC_CURRENT_REG_ADDR];
else{ // send_to_bt1.current2 = gWordVar[AC_CURRENT_REG_ADDR + 2];
send_to_bt1.current1 = gWordVar[AC_CURRENT_REG_ADDR + 1]; // }
send_to_bt1.current2 = gWordVar[AC_CURRENT_REG_ADDR + 2]; // else
} // {
send_to_bt2.TAG = 2; // send_to_bt1.current1 = gWordVar[AC_CURRENT_REG_ADDR + 1];
send_to_bt2.flow[0] = pflow[0].flow; // send_to_bt1.current2 = gWordVar[AC_CURRENT_REG_ADDR + 2];
send_to_bt2.flow[1] = pflow[1].flow; // }
send_to_bt2.total_flow[0] = pflow[0].total_flow; // send_to_bt2.TAG = 2;
send_to_bt2.total_flow[1] = pflow[1].total_flow; // send_to_bt2.flow[0] = pflow[0].flow;
#endif // send_to_bt2.flow[1] = pflow[1].flow;
ESP_LOGI(TAG, "flow 1 :%d\n",send_to_bt2.flow[0]); // send_to_bt2.total_flow[0] = pflow[0].total_flow;
ESP_LOGI(TAG, "flow 2 :%d\n",send_to_bt2.flow[1]); // send_to_bt2.total_flow[1] = pflow[1].total_flow;
ESP_LOGI(TAG, "total_flow 1 :%d\n",send_to_bt2.total_flow[0]); // #endif
ESP_LOGI(TAG, "total_flow 2 :%d\n",send_to_bt2.total_flow[1]); // ESP_LOGI(TAG, "flow 1 :%d\n", send_to_bt2.flow[0]);
if(is_connected == true){ // ESP_LOGI(TAG, "flow 2 :%d\n", send_to_bt2.flow[1]);
ESP_LOGI(TAG, "is connected\n"); // ESP_LOGI(TAG, "total_flow 1 :%d\n", send_to_bt2.total_flow[0]);
esp_err_t err = esp_ble_gatts_send_indicate(spp_gatts_if, // ESP_LOGI(TAG, "total_flow 2 :%d\n", send_to_bt2.total_flow[1]);
spp_conn_id, // if (is_connected == true)
spp_handle_table[4], // {
sizeof(send_to_bt1), // ESP_LOGI(TAG, "is connected\n");
(uint8*)&send_to_bt1, // esp_err_t err = esp_ble_gatts_send_indicate(spp_gatts_if,
false); // spp_conn_id,
if(err == ESP_OK) ESP_LOGI(TAG, "send data to bt 1 sucessfully\n"); // spp_handle_table[4],
else ESP_LOGI(TAG, "send data to bt 1 failed\n"); // sizeof(send_to_bt1),
// (uint8 *)&send_to_bt1,
err = esp_ble_gatts_send_indicate(spp_gatts_if, // false);
spp_conn_id, // if (err == ESP_OK)
spp_handle_table[4], // ESP_LOGI(TAG, "send data to bt 1 sucessfully\n");
sizeof(send_to_bt2), // else
(uint8*)&send_to_bt2, // ESP_LOGI(TAG, "send data to bt 1 failed\n");
false);
if(err == ESP_OK) ESP_LOGI(TAG, "send data to bt 2 sucessfully\n");
else ESP_LOGI(TAG, "send data to bt 2 failed\n");
}
// err = esp_ble_gatts_send_indicate(spp_gatts_if,
// spp_conn_id,
// spp_handle_table[4],
// sizeof(send_to_bt2),
// (uint8 *)&send_to_bt2,
// false);
// if (err == ESP_OK)
// ESP_LOGI(TAG, "send data to bt 2 sucessfully\n");
// else
// ESP_LOGI(TAG, "send data to bt 2 failed\n");
// }
} }
void depth_task(void *arg) void depth_task(void *arg)
@ -520,7 +560,6 @@ void depth_task(void *arg)
depth_data->sample_count++; depth_data->sample_count++;
add_recod_item(); add_recod_item();
target_sample_depth -= depth_config->sample_depth; target_sample_depth -= depth_config->sample_depth;
} }
} }
} }
@ -551,7 +590,8 @@ void depth_task(void *arg)
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// 每隔500ms向蓝牙发送一次数据 // 每隔500ms向蓝牙发送一次数据
if(bt_time_count++ > 50){ if (bt_time_count++ > 50)
{
ESP_LOGI(TAG, "bt_time_count++ > 50\n"); ESP_LOGI(TAG, "bt_time_count++ > 50\n");
bt_time_count = 0; bt_time_count = 0;
send_data_to_bt(); send_data_to_bt();
@ -641,5 +681,3 @@ void DEPTH_init()
capture_depth_init(); capture_depth_init();
xTaskCreate(depth_task, "depth_task", 4096, NULL, 10, NULL); xTaskCreate(depth_task, "depth_task", 4096, NULL, 10, NULL);
} }

View File

@ -200,8 +200,8 @@ void flow_task(void *arg)
ccr = ccr / (rtc_clk_apb_freq / 1000000); ccr = ccr / (rtc_clk_apb_freq / 1000000);
// __enable_irq(); // __enable_irq();
time_diff = ccr - last_ccr[ch]; time_diff = ccr - last_ccr[ch];
ESP_LOGI(TAG, "(type2) t15_ccr_times[%d]: %u %u time_diff: %u", ch, ccr, ccr_times, time_diff); ESP_LOGI(TAG, "(type2) t15_ccr_times[%d]: %lu %d time_diff: %d", ch, ccr, ccr_times, time_diff);
printf("rtc_clk_apb_freq : %u\n", rtc_clk_apb_freq); ESP_LOGI(TAG,"rtc_clk_apb_freq : %lu\n", rtc_clk_apb_freq);
if (time_diff != 0) if (time_diff != 0)
{ {
int t_flow; int t_flow;

View File

@ -8,6 +8,7 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_system.h" #include "esp_system.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "driver/gpio.h"
static const char *TAG = "i2c-simple-example"; static const char *TAG = "i2c-simple-example";
@ -86,7 +87,7 @@ int fram_write(uint16_t addr, void * buf,uint32_t len)
i2c_master_write(cmd, &low_addr, 1, ACK_CHECK_EN); i2c_master_write(cmd, &low_addr, 1, ACK_CHECK_EN);
i2c_master_write(cmd, buf, len, ACK_CHECK_EN); i2c_master_write(cmd, buf, len, ACK_CHECK_EN);
i2c_master_stop(cmd); i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS); ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_PERIOD_MS);
if (ret != ESP_OK) { if (ret != ESP_OK) {
printf("esp_err : %s \n", esp_err_to_name(ret)); printf("esp_err : %s \n", esp_err_to_name(ret));
return ret; return ret;

View File

@ -20,7 +20,7 @@ static const char *TAG = "UART0";
#define BAUD_RATE (115200) #define BAUD_RATE (115200)
#define UART_PORT_NUM (0) #define UART_PORT_NUM (0)
#define BUF_SIZE (256) #define BUF_SIZE (256)
#define UART_READ_TOUT (50 / portTICK_RATE_MS) #define UART_READ_TOUT (50 / portTICK_PERIOD_MS)
#define LED1_GPIO_PIN 9 #define LED1_GPIO_PIN 9

View File

@ -40,9 +40,9 @@ int GetCompileDateTime(uint16_t *DateTime)
return 0; return 0;
} }
unsigned int TickDiff(unsigned int comptime) uint32_t TickDiff(uint32_t comptime)
{ {
unsigned int nowtime = xTaskGetTickCount(); uint32_t nowtime = xTaskGetTickCount();
if(nowtime >= comptime) if(nowtime >= comptime)
return (nowtime - comptime); return (nowtime - comptime);
else else

View File

@ -2,5 +2,5 @@
#ifndef _UTILS_H_ #ifndef _UTILS_H_
#define _UTILS_H_ #define _UTILS_H_
int GetCompileDateTime(uint16_t *DateTime); int GetCompileDateTime(uint16_t *DateTime);
extern unsigned int TickDiff(unsigned int comptime); extern uint32_t TickDiff(uint32_t comptime);
#endif #endif

View File

@ -45,20 +45,17 @@ static const char *TAG = "wifi softAP";
static void wifi_event_handler(void *arg, esp_event_base_t event_base, static void wifi_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data) int32_t event_id, void *event_data)
{ {
if (event_id == WIFI_EVENT_AP_STACONNECTED) // if (event_id == WIFI_EVENT_AP_STACONNECTED) {
{ // wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t *)event_data; // ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
ESP_LOGI(TAG, "station " MACSTR " join, AID=%d", // MAC2STR(event->mac), event->aid);
MAC2STR(event->mac), event->aid); // } else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
// wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
// ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d",
// MAC2STR(event->mac), event->aid);
// }
} }
else if (event_id == WIFI_EVENT_AP_STADISCONNECTED)
{
wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t *)event_data;
ESP_LOGI(TAG, "station " MACSTR " leave, AID=%d",
MAC2STR(event->mac), event->aid);
}
}
extern void ModBusTCPSlave_init(void);
void wifi_init_softap(void) void wifi_init_softap(void)
{ {
ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_netif_init());

1388
sdkconfig

File diff suppressed because it is too large Load Diff