Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复编译问题 #239

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,12 @@ static esp_err_t req_get_ap_config_handler (CtrlMsg *req,
}

snprintf((char *)credentials.bssid,BSSID_LENGTH,MACSTR,MAC2STR(ap_info->bssid));

if (strlen((char *)ap_info->ssid)) {
strncpy((char *)credentials.ssid, (char *)ap_info->ssid,
min(sizeof(credentials.ssid), strlen((char *)ap_info->ssid)+1));
}

credentials.rssi = ap_info->rssi;
credentials.chnl = ap_info->primary;
credentials.ecn = ap_info->authmode;
Expand Down Expand Up @@ -803,6 +805,7 @@ static esp_err_t req_get_softap_config_handler (CtrlMsg *req,
strncpy((char *)credentials.pwd,(char *)&get_conf.ap.password,
min(sizeof(credentials.pwd), strlen((char *)&get_conf.ap.password)+1));
}

credentials.chnl = get_conf.ap.channel;
credentials.max_conn = get_conf.ap.max_connection;
credentials.ecn = get_conf.ap.authmode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(COMPONENT_SRCS "app_main.c" "slave_bt.c" "cmd.c" "stats.c")
set(COMPONENT_SRCS "app_main.c" "slave_bt.c" "cmd.c" "stats.c" "spi_lcd_touch.c" "lvgl_demo_ui.c" "adc_read.c")
set(COMPONENT_ADD_INCLUDEDIRS "./include")

if(CONFIG_ESP_SDIO_HOST_INTERFACE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,36 @@ menu "Example Configuration"
help
UART Baudrate for HCI over ESP32C3. Please use standard baudrate.

choice EXAMPLE_LCD_CONTROLLER
prompt "LCD controller model"
default EXAMPLE_LCD_CONTROLLER_ILI9341
help
Select LCD controller model

config EXAMPLE_LCD_CONTROLLER_ILI9341
bool "ILI9341"

config EXAMPLE_LCD_CONTROLLER_GC9A01
bool "GC9A01"
endchoice

config EXAMPLE_LCD_TOUCH_ENABLED
bool "Enable LCD touch"
default n
help
Enable this option if you wish to use display touch. You can select from touch controllers.

choice EXAMPLE_LCD_TOUCH_CONTROLLER
prompt "LCD touch controller model"
depends on EXAMPLE_LCD_TOUCH_ENABLED
default EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
help
Select LCD touch controller model

config EXAMPLE_LCD_TOUCH_CONTROLLER_STMPE610
bool "STMPE610"
help
Touch controller STMPE610 connected via SPI.
endchoice

endmenu
151 changes: 151 additions & 0 deletions esp_hosted_ng/esp/esp_driver/network_adapter/main/adc_read.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <string.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp_adc/adc_continuous.h"
#include "adc_read.h"

#define EXAMPLE_ADC_UNIT ADC_UNIT_1
#define _EXAMPLE_ADC_UNIT_STR(unit) #unit
#define EXAMPLE_ADC_UNIT_STR(unit) _EXAMPLE_ADC_UNIT_STR(unit)
#define EXAMPLE_ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_0
#define EXAMPLE_ADC_BIT_WIDTH SOC_ADC_DIGI_MAX_BITWIDTH

#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
#define EXAMPLE_ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
#define EXAMPLE_ADC_GET_CHANNEL(p_data) ((p_data)->type1.channel)
#define EXAMPLE_ADC_GET_DATA(p_data) ((p_data)->type1.data)
#else
#define EXAMPLE_ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
#define EXAMPLE_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
#define EXAMPLE_ADC_GET_DATA(p_data) ((p_data)->type2.data)
#endif

#define EXAMPLE_READ_LEN 256

#if CONFIG_IDF_TARGET_ESP32
static adc_channel_t channel[2] = {ADC_CHANNEL_6, ADC_CHANNEL_7};
#else
static adc_channel_t channel[5] = {ADC_CHANNEL_0, ADC_CHANNEL_3, ADC_CHANNEL_4, ADC_CHANNEL_6, ADC_CHANNEL_7};
#endif

static TaskHandle_t s_task_handle;
static const char *TAG = "EXAMPLE";


static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)
{
BaseType_t mustYield = pdFALSE;
//Notify that ADC continuous driver has done enough number of conversions
vTaskNotifyGiveFromISR(s_task_handle, &mustYield);

return (mustYield == pdTRUE);
}

static void continuous_adc_init(adc_channel_t *channel, uint8_t channel_num, adc_continuous_handle_t *out_handle)
{
adc_continuous_handle_t handle = NULL;

adc_continuous_handle_cfg_t adc_config = {
.max_store_buf_size = 1024,
.conv_frame_size = EXAMPLE_READ_LEN,
};
ESP_ERROR_CHECK(adc_continuous_new_handle(&adc_config, &handle));

adc_continuous_config_t dig_cfg = {
.sample_freq_hz = 20 * 1000,
.conv_mode = EXAMPLE_ADC_CONV_MODE,
.format = EXAMPLE_ADC_OUTPUT_TYPE,
};

adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
dig_cfg.pattern_num = channel_num;
for (int i = 0; i < channel_num; i++) {
adc_pattern[i].atten = EXAMPLE_ADC_ATTEN;
adc_pattern[i].channel = channel[i] & 0x7;
adc_pattern[i].unit = EXAMPLE_ADC_UNIT;
adc_pattern[i].bit_width = EXAMPLE_ADC_BIT_WIDTH;

ESP_LOGI(TAG, "adc_pattern[%d].atten is :%"PRIx8, i, adc_pattern[i].atten);
ESP_LOGI(TAG, "adc_pattern[%d].channel is :%"PRIx8, i, adc_pattern[i].channel);
ESP_LOGI(TAG, "adc_pattern[%d].unit is :%"PRIx8, i, adc_pattern[i].unit);
}
dig_cfg.adc_pattern = adc_pattern;
ESP_ERROR_CHECK(adc_continuous_config(handle, &dig_cfg));

*out_handle = handle;
}

void adc_init(void)
{
esp_err_t ret;
uint32_t ret_num = 0;
uint8_t result[EXAMPLE_READ_LEN] = {0};
memset(result, 0xcc, EXAMPLE_READ_LEN);

s_task_handle = xTaskGetCurrentTaskHandle();

adc_continuous_handle_t handle = NULL;
continuous_adc_init(channel, sizeof(channel) / sizeof(adc_channel_t), &handle);

adc_continuous_evt_cbs_t cbs = {
.on_conv_done = s_conv_done_cb,
};
ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(handle, &cbs, NULL));
ESP_ERROR_CHECK(adc_continuous_start(handle));

while(1) {

/**
* This is to show you the way to use the ADC continuous mode driver event callback.
* This `ulTaskNotifyTake` will block when the data processing in the task is fast.
* However in this example, the data processing (print) is slow, so you barely block here.
*
* Without using this event callback (to notify this task), you can still just call
* `adc_continuous_read()` here in a loop, with/without a certain block timeout.
*/
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

char unit[] = EXAMPLE_ADC_UNIT_STR(EXAMPLE_ADC_UNIT);

while (1) {
ret = adc_continuous_read(handle, result, EXAMPLE_READ_LEN, &ret_num, 0);
if (ret == ESP_OK) {
ESP_LOGI("TASK", "ret is %x, ret_num is %"PRIu32" bytes", ret, ret_num);
for (int i = 0; i < ret_num; i += SOC_ADC_DIGI_RESULT_BYTES) {
adc_digi_output_data_t *p = (adc_digi_output_data_t*)&result[i];
uint32_t chan_num = EXAMPLE_ADC_GET_CHANNEL(p);
uint32_t data = EXAMPLE_ADC_GET_DATA(p);
/* Check the channel number validation, the data is invalid if the channel num exceed the maximum channel */
if (chan_num < SOC_ADC_CHANNEL_NUM(EXAMPLE_ADC_UNIT)) {
ESP_LOGI(TAG, "Unit: %s, Channel: %"PRIu32", Value: %"PRIx32, unit, chan_num, data);
} else {
ESP_LOGW(TAG, "Invalid data [%s_%"PRIu32"_%"PRIx32"]", unit, chan_num, data);
}
}
/**
* Because printing is slow, so every time you call `ulTaskNotifyTake`, it will immediately return.
* To avoid a task watchdog timeout, add a delay here. When you replace the way you process the data,
* usually you don't need this delay (as this task will block for a while).
*/
vTaskDelay(1);
} else if (ret == ESP_ERR_TIMEOUT) {
//We try to read `EXAMPLE_READ_LEN` until API returns timeout, which means there's no available data
break;
}
}
}

ESP_ERROR_CHECK(adc_continuous_stop(handle));
ESP_ERROR_CHECK(adc_continuous_deinit(handle));
}
7 changes: 6 additions & 1 deletion esp_hosted_ng/esp/esp_driver/network_adapter/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "app_main.h"
#include "esp_wifi.h"
#include "cmd.h"
#include <esp_mac.h>

#include "freertos/task.h"
#include "freertos/queue.h"
Expand All @@ -47,6 +48,8 @@
#include "driver/periph_ctrl.h"
#include "slave_bt.c"
#include "stats.h"
#include "display.h"
#include "adc_read.h"

static const char TAG[] = "FW_MAIN";

Expand Down Expand Up @@ -619,6 +622,8 @@ void app_main()
}
ESP_ERROR_CHECK( ret );

// spi_touch_tftf_init();

ret = initialise_wifi();
ESP_ERROR_CHECK( ret );

Expand Down Expand Up @@ -675,7 +680,7 @@ void app_main()
/*send capabilities to host*/
send_bootup_event_to_host(capa);

tcpip_adapter_init();
esp_netif_init();

ESP_LOGI(TAG,"Initial set up done");
}
20 changes: 10 additions & 10 deletions esp_hosted_ng/esp/esp_driver/network_adapter/main/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int sta_connection(uint8_t *bssid)
return ESP_FAIL;
}
memcpy(ap_bssid, bssid, MAC_ADDR_LEN);
esp_wifi_connect_internal(ap_bssid);
// esp_wifi_connect_internal(ap_bssid);

return ESP_OK;
}
Expand All @@ -137,7 +137,7 @@ int station_rx_eapol(uint8_t *src_addr, uint8_t *buf, uint32_t len)
u8 own_mac[MAC_ADDR_LEN] = {0};

if (!src_addr || !buf || !len) {
ESP_LOGI(TAG, "eapol err - src_addr: %p buf: %p len: %u\n",
ESP_LOGI(TAG, "eapol err - src_addr: %p buf: %p len: %lu\n",
src_addr, buf, len);
//TODO : free buf using esp_wifi_internal_free_rx_buffer?
return ESP_FAIL;
Expand Down Expand Up @@ -416,7 +416,7 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
esp_err_t result;

if (event_base != WIFI_EVENT) {
ESP_LOGI(TAG, "Received unregistered event %s[%d]\n", event_base, event_id);
ESP_LOGI(TAG, "Received unregistered event %s[%ld]\n", event_base, event_id);
return;
}

Expand Down Expand Up @@ -459,7 +459,7 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
break;

default:
ESP_LOGI(TAG, "Unregistered event: %d\n", event_id);
ESP_LOGI(TAG, "Unregistered event: %ld\n", event_id);
}
}

Expand Down Expand Up @@ -1101,12 +1101,12 @@ int process_auth_request(uint8_t if_type, uint8_t *payload, uint16_t payload_len

/* WPA3 specific */
ESP_LOGI(TAG, "AUTH Confirm\n");
esp_wifi_issue_auth_internal(0);
// esp_wifi_issue_auth_internal(0);

} else {
wifi_scan_config_t params = {0};

if (cmd_auth->bssid) {
{
params.bssid = malloc(sizeof(cmd_auth->bssid));
assert(params.bssid);

Expand Down Expand Up @@ -1245,7 +1245,7 @@ int process_assoc_request(uint8_t if_type, uint8_t *payload, uint16_t payload_le
cmd_assoc->assoc_ie_len, 0);
}

esp_wifi_issue_assoc_internal(0);
// esp_wifi_issue_assoc_internal(0);

buf_handle.if_type = if_type;
buf_handle.if_num = 0;
Expand Down Expand Up @@ -1309,7 +1309,7 @@ int process_sta_connect(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
wifi_config.sta.channel = cmd_connect->channel;
ESP_LOGI(TAG, "%s, channel: %u", cmd_connect->ssid, cmd_connect->channel);

if (cmd_connect->assoc_ie && cmd_connect->assoc_ie_len) {
if (cmd_connect->assoc_ie_len) {
esp_wifi_unset_appie_internal(WIFI_APPIE_ASSOC_REQ);
esp_wifi_set_appie_internal(WIFI_APPIE_ASSOC_REQ, cmd_connect->assoc_ie,
cmd_connect->assoc_ie_len, 0);
Expand Down Expand Up @@ -1812,15 +1812,15 @@ int process_add_key(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
if (key->algo == WIFI_WPA_ALG_IGTK) {
wifi_wpa_igtk_t igtk = {0};

ESP_LOGI(TAG, "Setting iGTK [%d]\n", key->index);
ESP_LOGI(TAG, "Setting iGTK [%ld]\n", key->index);

memcpy(igtk.igtk, key->data, key->len);
memcpy(igtk.pn, key->seq, key->seq_len);
WPA_PUT_LE16(igtk.keyid, key->index);
ret = esp_wifi_set_igtk_internal(0, &igtk);
} else {
/* GTK */
ESP_LOGI(TAG, "Setting GTK [%d]\n", key->index);
ESP_LOGI(TAG, "Setting GTK [%ld]\n", key->index);
ret = esp_wifi_set_sta_key_internal(key->algo, key->mac_addr, key->index,
0, key->seq, key->seq_len, key->data, key->len,
KEY_FLAG_GROUP | KEY_FLAG_RX);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
idf: ">=4.4"
lvgl/lvgl: "~8.3.0"
esp_lcd_ili9341: "^1.0"
esp_lcd_gc9a01: "^1.0"
esp_lcd_touch_stmpe610: "^1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __ESP_ADC_REMOTE_H
#define __ESP_ADC_REMOTE_H

void adc_init(void);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __ESP_SPI_TOUCH_TFT_H
#define __ESP_SPI_TOUCH_TFT_H

void spi_touch_tftf_init(void);

#endif
Loading