Umstrukuriert/windows-app hinzugefügt
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
file(GLOB_RECURSE SRC_FILES "*.c")
|
||||
|
||||
idf_component_register(SRCS ${SRC_FILES}
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES "esp_lcd" "driver" "esp_adc" "esp_lcd_jd9853" "esp_lcd_touch_axs5106" "fatfs" "nvs_flash" "lwip" "esp_wifi")
|
||||
@@ -0,0 +1,115 @@
|
||||
#include "bsp_battery.h"
|
||||
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_adc/adc_cali.h"
|
||||
#include "esp_adc/adc_cali_scheme.h"
|
||||
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
static char *TAG = "bsp_battery";
|
||||
|
||||
|
||||
static adc_oneshot_unit_handle_t adc1_handle;
|
||||
static adc_cali_handle_t adc1_cali_chan0_handle = NULL;
|
||||
static bool do_calibration1_chan0;
|
||||
|
||||
|
||||
static bool example_adc_calibration_init(adc_unit_t unit, adc_channel_t channel, adc_atten_t atten, adc_cali_handle_t *out_handle)
|
||||
{
|
||||
adc_cali_handle_t handle = NULL;
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
bool calibrated = false;
|
||||
|
||||
#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
|
||||
if (!calibrated)
|
||||
{
|
||||
ESP_LOGI(TAG, "calibration scheme version is %s", "Curve Fitting");
|
||||
adc_cali_curve_fitting_config_t cali_config = {
|
||||
.unit_id = unit,
|
||||
.chan = channel,
|
||||
.atten = atten,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
ret = adc_cali_create_scheme_curve_fitting(&cali_config, &handle);
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
calibrated = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ADC_CALI_SCHEME_LINE_FITTING_SUPPORTED
|
||||
if (!calibrated)
|
||||
{
|
||||
ESP_LOGI(TAG, "calibration scheme version is %s", "Line Fitting");
|
||||
adc_cali_line_fitting_config_t cali_config = {
|
||||
.unit_id = unit,
|
||||
.atten = atten,
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
};
|
||||
ret = adc_cali_create_scheme_line_fitting(&cali_config, &handle);
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
calibrated = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
*out_handle = handle;
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
ESP_LOGI(TAG, "Calibration Success");
|
||||
}
|
||||
else if (ret == ESP_ERR_NOT_SUPPORTED || !calibrated)
|
||||
{
|
||||
ESP_LOGW(TAG, "eFuse not burnt, skip software calibration");
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Invalid arg or no memory");
|
||||
}
|
||||
|
||||
return calibrated;
|
||||
}
|
||||
|
||||
|
||||
void bsp_battery_init(void)
|
||||
{
|
||||
|
||||
adc_oneshot_unit_init_cfg_t init_config1 = {
|
||||
.unit_id = EXAMPLE_ADC_UNIT,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle));
|
||||
//-------------ADC1 Config---------------//
|
||||
adc_oneshot_chan_cfg_t config = {
|
||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||
.atten = EXAMPLE_ADC_ATTEN,
|
||||
};
|
||||
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, EXAMPLE_BATTERY_ADC_CHANNEL, &config));
|
||||
|
||||
//-------------ADC1 Calibration Init---------------//
|
||||
|
||||
do_calibration1_chan0 = example_adc_calibration_init(EXAMPLE_ADC_UNIT, EXAMPLE_BATTERY_ADC_CHANNEL, EXAMPLE_ADC_ATTEN, &adc1_cali_chan0_handle);
|
||||
}
|
||||
|
||||
|
||||
void bsp_battery_get_voltage(float *voltage, uint16_t *adc_value)
|
||||
{
|
||||
int adc_raw;
|
||||
int voltage_int;
|
||||
|
||||
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle, EXAMPLE_BATTERY_ADC_CHANNEL, &adc_raw));
|
||||
|
||||
// ESP_LOGI(TAG, "ADC%d Channel[%d] Raw Data: %d", ADC_UNIT_1 + 1, EXAMPLE_BATTERY_ADC_CHANNEL, adc_raw);
|
||||
if (do_calibration1_chan0)
|
||||
{
|
||||
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_chan0_handle, adc_raw, &voltage_int));
|
||||
*voltage = (voltage_int / 1000.0f) * 3.0;
|
||||
|
||||
if (adc_value)
|
||||
{
|
||||
*adc_value = adc_raw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef __BSP_BATTERY_H__
|
||||
#define __BSP_BATTERY_H__
|
||||
#include <stdio.h>
|
||||
|
||||
#define EXAMPLE_ADC_UNIT ADC_UNIT_1
|
||||
#define EXAMPLE_BATTERY_ADC_CHANNEL ADC_CHANNEL_0
|
||||
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_12
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bsp_battery_init(void);
|
||||
void bsp_battery_get_voltage(float *voltage, uint16_t *adc_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
#include "bsp_display.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/ledc.h"
|
||||
|
||||
#include "esp_lcd_jd9853.h"
|
||||
|
||||
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
|
||||
|
||||
#include "bsp_spi.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "bsp_display";
|
||||
|
||||
static uint8_t g_brightness = 0;
|
||||
|
||||
|
||||
void bsp_display_init(esp_lcd_panel_io_handle_t *io_handle, esp_lcd_panel_handle_t *panel_handle, size_t max_transfer_sz)
|
||||
{
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
|
||||
// esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
|
||||
esp_lcd_panel_io_spi_config_t io_config = JD9853_PANEL_IO_SPI_CONFIG(EXAMPLE_PIN_LCD_CS, EXAMPLE_PIN_LCD_DC, NULL, NULL);
|
||||
io_config.pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ;
|
||||
// Attach the LCD to the SPI bus
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)EXAMPLE_SPI_HOST, &io_config, io_handle));
|
||||
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = EXAMPLE_PIN_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
.bits_per_pixel = 16,
|
||||
};
|
||||
esp_lcd_new_panel_jd9853(*io_handle, &panel_config, panel_handle);
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(*panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(*panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(*panel_handle, true));
|
||||
// ESP_ERROR_CHECK(esp_lcd_panel_set_gap(*panel_handle, 0, 34));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(*panel_handle, false, false));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(*panel_handle, true));
|
||||
}
|
||||
|
||||
|
||||
void bsp_display_brightness_init(void)
|
||||
{
|
||||
// Prepare and then apply the LEDC PWM timer configuration
|
||||
ledc_timer_config_t ledc_timer = {};
|
||||
ledc_timer.speed_mode = LCD_BL_LEDC_MODE,
|
||||
ledc_timer.timer_num = LCD_BL_LEDC_TIMER;
|
||||
ledc_timer.duty_resolution = LCD_BL_LEDC_DUTY_RES;
|
||||
ledc_timer.freq_hz = LCD_BL_LEDC_FREQUENCY; // Set output frequency at 5 kHz
|
||||
ledc_timer.clk_cfg = LEDC_AUTO_CLK;
|
||||
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
|
||||
|
||||
// Prepare and then apply the LEDC PWM channel configuration
|
||||
ledc_channel_config_t ledc_channel = {};
|
||||
ledc_channel.speed_mode = LCD_BL_LEDC_MODE;
|
||||
ledc_channel.channel = LCD_BL_LEDC_CHANNEL;
|
||||
ledc_channel.timer_sel = LCD_BL_LEDC_TIMER;
|
||||
ledc_channel.intr_type = LEDC_INTR_DISABLE;
|
||||
ledc_channel.gpio_num = EXAMPLE_PIN_LCD_BL;
|
||||
ledc_channel.duty = 0, // Set duty to 0%
|
||||
ledc_channel.hpoint = 0;
|
||||
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
|
||||
}
|
||||
|
||||
void bsp_display_set_brightness(uint8_t brightness)
|
||||
{
|
||||
if (brightness > 100)
|
||||
{
|
||||
brightness = 100;
|
||||
ESP_LOGE(TAG, "Brightness value out of range");
|
||||
}
|
||||
|
||||
g_brightness = brightness;
|
||||
uint32_t duty = (brightness * (LCD_BL_LEDC_DUTY - 1)) / 100;
|
||||
|
||||
ESP_ERROR_CHECK(ledc_set_duty(LCD_BL_LEDC_MODE, LCD_BL_LEDC_CHANNEL, duty));
|
||||
ESP_ERROR_CHECK(ledc_update_duty(LCD_BL_LEDC_MODE, LCD_BL_LEDC_CHANNEL));
|
||||
|
||||
ESP_LOGI(TAG, "LCD brightness set to %d%%", brightness);
|
||||
}
|
||||
|
||||
uint8_t bsp_display_get_brightness(void)
|
||||
{
|
||||
return g_brightness;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef __BSP_DISPLAY_H__
|
||||
#define __BSP_DISPLAY_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_touch_axs5106.h"
|
||||
|
||||
#define EXAMPLE_LCD_PIXEL_CLOCK_HZ (80 * 1000 * 1000)
|
||||
|
||||
#define EXAMPLE_PIN_LCD_CS GPIO_NUM_14
|
||||
#define EXAMPLE_PIN_LCD_DC GPIO_NUM_15
|
||||
#define EXAMPLE_PIN_LCD_RST GPIO_NUM_22
|
||||
#define EXAMPLE_PIN_LCD_BL GPIO_NUM_23
|
||||
|
||||
#define LCD_BL_LEDC_TIMER LEDC_TIMER_0
|
||||
#define LCD_BL_LEDC_MODE LEDC_LOW_SPEED_MODE
|
||||
#define LCD_BL_LEDC_CHANNEL LEDC_CHANNEL_0
|
||||
#define LCD_BL_LEDC_DUTY_RES LEDC_TIMER_10_BIT // Set duty resolution to 13 bits
|
||||
#define LCD_BL_LEDC_DUTY (1024) // Set duty to 50%. 1024 * 50% = 4096
|
||||
#define LCD_BL_LEDC_FREQUENCY (5000) // Frequency in Hertz. Set frequency at 5 kHz
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bsp_display_init(esp_lcd_panel_io_handle_t *io_handle, esp_lcd_panel_handle_t *panel_handle, size_t max_transfer_sz);
|
||||
void bsp_display_brightness_init(void);
|
||||
void bsp_display_set_brightness(uint8_t brightness);
|
||||
uint8_t bsp_display_get_brightness(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "bsp_i2c.h"
|
||||
|
||||
|
||||
|
||||
i2c_master_bus_handle_t bsp_i2c_init(void)
|
||||
{
|
||||
i2c_master_bus_handle_t i2c_bus_handle;
|
||||
i2c_master_bus_config_t i2c_mst_config = {};
|
||||
i2c_mst_config.clk_source = I2C_CLK_SRC_DEFAULT;
|
||||
i2c_mst_config.i2c_port = (i2c_port_num_t)I2C_PORT_NUM;
|
||||
i2c_mst_config.scl_io_num = EXAMPLE_PIN_I2C_SCL;
|
||||
i2c_mst_config.sda_io_num = EXAMPLE_PIN_I2C_SDA;
|
||||
i2c_mst_config.glitch_ignore_cnt = 7;
|
||||
i2c_mst_config.flags.enable_internal_pullup = 1;
|
||||
|
||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &i2c_bus_handle));
|
||||
return i2c_bus_handle;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef __BSP_I2C_H__
|
||||
#define __BSP_I2C_H__
|
||||
|
||||
#include "driver/i2c_master.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#define EXAMPLE_PIN_I2C_SDA GPIO_NUM_18
|
||||
#define EXAMPLE_PIN_I2C_SCL GPIO_NUM_19
|
||||
#define I2C_PORT_NUM 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
i2c_master_bus_handle_t bsp_i2c_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif //__BSP_I2C_H__
|
||||
@@ -0,0 +1,106 @@
|
||||
#include "bsp_qmi8658.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "bsp_i2c.h"
|
||||
|
||||
static const char *TAG = "bsp_qmi8658";
|
||||
#define ACC_SENSITIVITY (4 / 32768.0f) // 每LSB对应的加速度(单位为g)
|
||||
|
||||
static i2c_master_dev_handle_t dev_handle;
|
||||
|
||||
|
||||
// 读取QMI8658寄存器的值
|
||||
static esp_err_t bsp_qmi8658_reg_read(uint8_t reg_addr, uint8_t *data, size_t len)
|
||||
{
|
||||
//return bsp_i2c_reg8_read(QMI8658_SENSOR_ADDR, reg_addr, data, len);
|
||||
return i2c_master_transmit_receive(dev_handle, ®_addr, 1, data, len, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
// 给QMI8658的寄存器写值
|
||||
static esp_err_t bsp_qmi8658_reg_write_byte(uint8_t reg_addr, uint8_t *data, size_t len)
|
||||
{
|
||||
uint8_t buf[len + 1];
|
||||
buf[0] = reg_addr;
|
||||
memcpy(buf + 1, data, len);
|
||||
//return bsp_i2c_reg8_write(QMI8658_SENSOR_ADDR, reg_addr, data, len);
|
||||
return i2c_master_transmit(dev_handle, buf, len + 1, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
|
||||
bool bsp_qmi8658_read_data(qmi8658_data_t *data)
|
||||
{
|
||||
uint8_t status;
|
||||
float mask;
|
||||
uint16_t buf[6];
|
||||
bsp_qmi8658_reg_read(QMI8658_STATUS0, &status, 1); // 读状态寄存器
|
||||
if (status & 0x03)
|
||||
{
|
||||
bsp_qmi8658_reg_read(QMI8658_AX_L, (uint8_t *)buf, 12); // 读加速度和陀螺仪值
|
||||
data->acc_x = buf[0];
|
||||
data->acc_y = buf[1];
|
||||
data->acc_z = buf[2];
|
||||
data->gyr_x = buf[3];
|
||||
data->gyr_y = buf[4];
|
||||
data->gyr_z = buf[5];
|
||||
// ESP_LOGI(TAG, "QMI8658 read data success!");
|
||||
|
||||
mask = (float)data->acc_x / sqrt(((float)data->acc_y * (float)data->acc_y + (float)data->acc_z * (float)data->acc_z));
|
||||
data->AngleX = atan(mask) * 57.29578f; // 180/π=57.29578
|
||||
mask = (float)data->acc_y / sqrt(((float)data->acc_x * (float)data->acc_x + (float)data->acc_z * (float)data->acc_z));
|
||||
data->AngleY = atan(mask) * 57.29578f; // 180/π=57.29578
|
||||
mask = sqrt(((float)data->acc_x * (float)data->acc_x + (float)data->acc_y * (float)data->acc_y)) / (float)data->acc_z;
|
||||
data->AngleZ = atan(mask) * 57.29578f; // 180/π=57.29578
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void bsp_qmi8658_init(i2c_master_bus_handle_t bus_handle)
|
||||
{
|
||||
uint8_t id = 0;
|
||||
ESP_LOGI(TAG, "QMI8658 Initialize");
|
||||
|
||||
i2c_device_config_t dev_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = QMI8658_SENSOR_ADDR,
|
||||
.scl_speed_hz = 400000,
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||
|
||||
ESP_ERROR_CHECK(bsp_qmi8658_reg_read(QMI8658_WHO_AM_I, &id, 1));
|
||||
|
||||
if (0x05 != id)
|
||||
{
|
||||
ESP_LOGI(TAG, "QMI8658 not found");
|
||||
}
|
||||
ESP_LOGI(TAG, "Find QMI8658");
|
||||
bsp_qmi8658_reg_write_byte(QMI8658_RESET, (uint8_t[]){0xb0}, 1); // 复位
|
||||
vTaskDelay(pdMS_TO_TICKS(10)); // 延时10ms
|
||||
bsp_qmi8658_reg_write_byte(QMI8658_CTRL1, (uint8_t[]){0x40}, 1); // CTRL1 设置地址自动增加
|
||||
bsp_qmi8658_reg_write_byte(QMI8658_CTRL7, (uint8_t[]){0x03}, 1); // CTRL7 允许加速度和陀螺仪
|
||||
bsp_qmi8658_reg_write_byte(QMI8658_CTRL2, (uint8_t[]){0x95}, 1); // CTRL2 设置ACC 4g 250Hz
|
||||
bsp_qmi8658_reg_write_byte(QMI8658_CTRL3, (uint8_t[]){0xd5}, 1); // CTRL3 设置GRY 512dps 250Hz
|
||||
}
|
||||
|
||||
static void qmi8658_test_task(void *arg)
|
||||
{
|
||||
qmi8658_data_t data;
|
||||
while (1)
|
||||
{
|
||||
bsp_qmi8658_read_data(&data);
|
||||
// printf("Acc: %.2f %.2f %.2f-----Gyr: %04d %04d %04d\n", data.acc_x * ACC_SENSITIVITY * 9.8f, data.acc_y * ACC_SENSITIVITY * 9.8f, data.acc_z * ACC_SENSITIVITY * 9.8f, data.gyr_x, data.gyr_y, data.gyr_z);
|
||||
// printf("-------------------------------------------------------------------------\n");
|
||||
// printf("Angle: %.2f %.2f %.2f\n", data.AngleX, data.AngleY, data.AngleZ);
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
}
|
||||
}
|
||||
|
||||
void bsp_qmi8658_test(void)
|
||||
{
|
||||
xTaskCreate(qmi8658_test_task, "qmi8658_test", 4096, NULL, 0, NULL);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include "driver/i2c_master.h"
|
||||
|
||||
#define QMI8658_SENSOR_ADDR 0x6B
|
||||
|
||||
typedef enum
|
||||
{
|
||||
QMI8658_WHO_AM_I,
|
||||
QMI8658_REVISION_ID,
|
||||
QMI8658_CTRL1,
|
||||
QMI8658_CTRL2,
|
||||
QMI8658_CTRL3,
|
||||
QMI8658_CTRL4,
|
||||
QMI8658_CTRL5,
|
||||
QMI8658_CTRL6,
|
||||
QMI8658_CTRL7,
|
||||
QMI8658_CTRL8,
|
||||
QMI8658_CTRL9,
|
||||
QMI8658_CATL1_L,
|
||||
QMI8658_CATL1_H,
|
||||
QMI8658_CATL2_L,
|
||||
QMI8658_CATL2_H,
|
||||
QMI8658_CATL3_L,
|
||||
QMI8658_CATL3_H,
|
||||
QMI8658_CATL4_L,
|
||||
QMI8658_CATL4_H,
|
||||
QMI8658_FIFO_WTM_TH,
|
||||
QMI8658_FIFO_CTRL,
|
||||
QMI8658_FIFO_SMPL_CNT,
|
||||
QMI8658_FIFO_STATUS,
|
||||
QMI8658_FIFO_DATA,
|
||||
QMI8658_STATUSINT = 45,
|
||||
QMI8658_STATUS0,
|
||||
QMI8658_STATUS1,
|
||||
QMI8658_TIMESTAMP_LOW,
|
||||
QMI8658_TIMESTAMP_MID,
|
||||
QMI8658_TIMESTAMP_HIGH,
|
||||
QMI8658_TEMP_L,
|
||||
QMI8658_TEMP_H,
|
||||
QMI8658_AX_L,
|
||||
QMI8658_AX_H,
|
||||
QMI8658_AY_L,
|
||||
QMI8658_AY_H,
|
||||
QMI8658_AZ_L,
|
||||
QMI8658_AZ_H,
|
||||
QMI8658_GX_L,
|
||||
QMI8658_GX_H,
|
||||
QMI8658_GY_L,
|
||||
QMI8658_GY_H,
|
||||
QMI8658_GZ_L,
|
||||
QMI8658_GZ_H,
|
||||
QMI8658_COD_STATUS = 70,
|
||||
QMI8658_dQW_L = 73,
|
||||
QMI8658_dQW_H,
|
||||
QMI8658_dQX_L,
|
||||
QMI8658_dQX_H,
|
||||
QMI8658_dQY_L,
|
||||
QMI8658_dQY_H,
|
||||
QMI8658_dQZ_L,
|
||||
QMI8658_dQZ_H,
|
||||
QMI8658_dVX_L,
|
||||
QMI8658_dVX_H,
|
||||
QMI8658_dVY_L,
|
||||
QMI8658_dVY_H,
|
||||
QMI8658_dVZ_L,
|
||||
QMI8658_dVZ_H,
|
||||
QMI8658_TAP_STATUS = 89,
|
||||
QMI8658_STEP_CNT_LOW,
|
||||
QMI8658_STEP_CNT_MIDL,
|
||||
QMI8658_STEP_CNT_HIGH,
|
||||
QMI8658_RESET = 96
|
||||
} qmi8658_reg_t;
|
||||
|
||||
// 倾角结构体
|
||||
typedef struct{
|
||||
int16_t acc_x;
|
||||
int16_t acc_y;
|
||||
int16_t acc_z;
|
||||
int16_t gyr_x;
|
||||
int16_t gyr_y;
|
||||
int16_t gyr_z;
|
||||
float AngleX;
|
||||
float AngleY;
|
||||
float AngleZ;
|
||||
float temp;
|
||||
}qmi8658_data_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void bsp_qmi8658_init(i2c_master_bus_handle_t bus_handle);
|
||||
void bsp_qmi8658_test(void);
|
||||
bool bsp_qmi8658_read_data(qmi8658_data_t *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,147 @@
|
||||
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "esp_check.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "bsp_sdcard.h"
|
||||
#include "bsp_spi.h"
|
||||
|
||||
sdmmc_card_t *card = NULL;
|
||||
|
||||
static const char *TAG = "bsp_sdcard";
|
||||
|
||||
uint64_t bsp_sdcard_get_size(void)
|
||||
{
|
||||
uint64_t sdcard_size = 0;
|
||||
if (card != NULL)
|
||||
{
|
||||
sdcard_size = ((uint64_t)card->csd.capacity) * card->csd.sector_size;
|
||||
}
|
||||
return sdcard_size;
|
||||
}
|
||||
|
||||
|
||||
void bsp_sdcard_init(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
const char mount_point[] = "/sdcard";
|
||||
|
||||
ESP_LOGI(TAG, "Initialize SPI SD Card");
|
||||
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
#ifdef CONFIG_EXAMPLE_FORMAT_IF_MOUNT_FAILED
|
||||
.format_if_mount_failed = true,
|
||||
#else
|
||||
.format_if_mount_failed = false,
|
||||
#endif // EXAMPLE_FORMAT_IF_MOUNT_FAILED
|
||||
.max_files = 5,
|
||||
.allocation_unit_size = 16 * 1024};
|
||||
// sdmmc_card_t *card;
|
||||
|
||||
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
|
||||
host.slot = EXAMPLE_SPI_HOST;
|
||||
|
||||
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
|
||||
slot_config.gpio_cs = EXAMPLE_PIN_SD_CS;
|
||||
slot_config.host_id = host.slot;
|
||||
|
||||
ESP_LOGI(TAG, "Mounting filesystem");
|
||||
ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
|
||||
if (ret != ESP_OK)
|
||||
{
|
||||
if (ret == ESP_FAIL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to mount filesystem. "
|
||||
"If you want the card to be formatted, set the CONFIG_EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to initialize the card (%s). "
|
||||
"Make sure SD card lines have pull-up resistors in place.",
|
||||
esp_err_to_name(ret));
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "Filesystem mounted");
|
||||
// Card has been initialized, print its properties
|
||||
sdmmc_card_print_info(stdout, card);
|
||||
}
|
||||
}
|
||||
|
||||
// void bsp_sdcard_init(void)
|
||||
// {
|
||||
// esp_err_t ret;
|
||||
|
||||
// // Options for mounting the filesystem.
|
||||
// // If format_if_mount_failed is set to true, SD card will be partitioned and
|
||||
// // formatted in case when mounting fails.
|
||||
// esp_vfs_fat_sdmmc_mount_config_t mount_config = {
|
||||
// .format_if_mount_failed = false,
|
||||
// .max_files = 5,
|
||||
// .allocation_unit_size = 16 * 1024};
|
||||
// const char mount_point[] = "/sdcard";
|
||||
// ESP_LOGI(TAG, "Initializing SD card");
|
||||
|
||||
// // Use settings defined above to initialize SD card and mount FAT filesystem.
|
||||
// // Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions.
|
||||
// // Please check its source code and implement error recovery when developing
|
||||
// // production applications.
|
||||
|
||||
// ESP_LOGI(TAG, "Using SDMMC peripheral");
|
||||
|
||||
// // By default, SD card frequency is initialized to SDMMC_FREQ_DEFAULT (20MHz)
|
||||
// // For setting a specific frequency, use host.max_freq_khz (range 400kHz - 40MHz for SDMMC)
|
||||
// // Example: for fixed frequency of 10MHz, use host.max_freq_khz = 10000;
|
||||
// sdmmc_host_t host = SDMMC_HOST_DEFAULT();
|
||||
|
||||
// sdmmc_slot_config_t slot_config = {};
|
||||
|
||||
// // On chips where the GPIOs used for SD card can be configured, set them in
|
||||
// // the slot_config structure:
|
||||
// slot_config.width = 4;
|
||||
// slot_config.cd = SDMMC_SLOT_NO_CD;
|
||||
// slot_config.wp = SDMMC_SLOT_NO_WP;
|
||||
// slot_config.width = SDMMC_SLOT_WIDTH_DEFAULT;
|
||||
// slot_config.flags = 0;
|
||||
// slot_config.clk = EXAMPLE_PIN_SD_CLK;
|
||||
// slot_config.cmd = EXAMPLE_PIN_SD_CMD;
|
||||
// slot_config.d0 = EXAMPLE_PIN_SD_D0;
|
||||
// slot_config.d1 = EXAMPLE_PIN_SD_D1;
|
||||
// slot_config.d2 = EXAMPLE_PIN_SD_D2;
|
||||
// slot_config.d3 = EXAMPLE_PIN_SD_D3;
|
||||
|
||||
// // Enable internal pullups on enabled pins. The internal pullups
|
||||
// // are insufficient however, please make sure 10k external pullups are
|
||||
// // connected on the bus. This is for debug / example purpose only.
|
||||
// slot_config.flags |= SDMMC_SLOT_FLAG_INTERNAL_PULLUP;
|
||||
|
||||
// ESP_LOGI(TAG, "Mounting filesystem");
|
||||
// ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
|
||||
|
||||
// if (ret != ESP_OK)
|
||||
// {
|
||||
// if (ret == ESP_FAIL)
|
||||
// {
|
||||
// ESP_LOGE(TAG, "Failed to mount filesystem. "
|
||||
// "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ESP_LOGE(TAG, "Failed to initialize the card (%s). "
|
||||
// "Make sure SD card lines have pull-up resistors in place.",
|
||||
// esp_err_to_name(ret));
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// ESP_LOGI(TAG, "Filesystem mounted");
|
||||
|
||||
// // Card has been initialized, print its properties
|
||||
// sdmmc_card_print_info(stdout, card);
|
||||
// }
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef __BSP_SDCARD_H_
|
||||
#define __BSP_SDCARD_H_
|
||||
#include "esp_err.h"
|
||||
#include "esp_vfs_fat.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
#include "driver/sdmmc_defs.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define EXAMPLE_PIN_SD_CS GPIO_NUM_4
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bsp_sdcard_init(void);
|
||||
uint64_t bsp_sdcard_get_size(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "bsp_spi.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "bsp_spi";
|
||||
|
||||
void bsp_spi_init(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "SPI BUS init");
|
||||
spi_bus_config_t buscfg = {};
|
||||
buscfg.sclk_io_num = EXAMPLE_PIN_SCLK;
|
||||
buscfg.mosi_io_num = EXAMPLE_PIN_MOSI;
|
||||
buscfg.miso_io_num = EXAMPLE_PIN_MISO;
|
||||
buscfg.quadwp_io_num = -1;
|
||||
buscfg.quadhd_io_num = -1;
|
||||
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(EXAMPLE_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef __BSP_SPI_H__
|
||||
#define __BSP_SPI_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/spi_master.h"
|
||||
|
||||
#define EXAMPLE_SPI_HOST SPI2_HOST
|
||||
|
||||
#define EXAMPLE_PIN_MISO GPIO_NUM_3
|
||||
#define EXAMPLE_PIN_MOSI GPIO_NUM_2
|
||||
#define EXAMPLE_PIN_SCLK GPIO_NUM_1
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bsp_spi_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
|
||||
#include "esp_lcd_touch_axs5106.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "bsp_touch.h"
|
||||
|
||||
void bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_t bus_handle, uint16_t xmax, uint16_t ymax, uint16_t rotation)
|
||||
{
|
||||
static i2c_master_dev_handle_t dev_handle;
|
||||
i2c_device_config_t dev_cfg = {
|
||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||
.device_address = ESP_LCD_TOUCH_IO_I2C_AXS5106_ADDRESS,
|
||||
.scl_speed_hz = 400000,
|
||||
};
|
||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
|
||||
|
||||
esp_lcd_touch_config_t tp_cfg = {};
|
||||
tp_cfg.x_max = xmax < ymax ? xmax : ymax;
|
||||
tp_cfg.y_max = xmax < ymax ? ymax : xmax;;
|
||||
tp_cfg.rst_gpio_num = EXAMPLE_PIN_TP_RST;
|
||||
tp_cfg.int_gpio_num = EXAMPLE_PIN_TP_INT;
|
||||
|
||||
if (90 == rotation)
|
||||
{
|
||||
tp_cfg.flags.swap_xy = 1;
|
||||
tp_cfg.flags.mirror_x = 0;
|
||||
tp_cfg.flags.mirror_y = 0;
|
||||
}
|
||||
else if (180 == rotation)
|
||||
{
|
||||
tp_cfg.flags.swap_xy = 0;
|
||||
tp_cfg.flags.mirror_x = 0;
|
||||
tp_cfg.flags.mirror_y = 1;
|
||||
}
|
||||
else if (270 == rotation)
|
||||
{
|
||||
tp_cfg.flags.swap_xy = 1;
|
||||
tp_cfg.flags.mirror_x = 1;
|
||||
tp_cfg.flags.mirror_y = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tp_cfg.flags.swap_xy = 0;
|
||||
tp_cfg.flags.mirror_x = 1;
|
||||
tp_cfg.flags.mirror_y = 0;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_axs5106(dev_handle, &tp_cfg, touch_handle));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef __BSP_TOUCH_H__
|
||||
#define __BSP_TOUCH_H__
|
||||
|
||||
#include "driver/i2c_master.h"
|
||||
#include "esp_lcd_touch_axs5106.h"
|
||||
|
||||
|
||||
#define EXAMPLE_PIN_TP_INT GPIO_NUM_21
|
||||
#define EXAMPLE_PIN_TP_RST GPIO_NUM_20
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bsp_touch_init(esp_lcd_touch_handle_t *touch_handle, i2c_master_bus_handle_t bus_handle, uint16_t xmax, uint16_t ymax, uint16_t rotation);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
#include "bsp_wifi.h"
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sys.h"
|
||||
|
||||
/* 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
|
||||
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
||||
*/
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
|
||||
|
||||
#define DEFAULT_SCAN_LIST_SIZE 10
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
SemaphoreHandle_t wifi_scan_Semaphore = NULL;
|
||||
SemaphoreHandle_t wifi_connect_Semaphore = NULL;
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
static const char *TAG = "wifi station";
|
||||
|
||||
static int s_retry_num = 0;
|
||||
|
||||
static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
|
||||
{
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
|
||||
{
|
||||
// esp_wifi_connect();
|
||||
// s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
}
|
||||
else
|
||||
{
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG, "connect to the AP fail");
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE)
|
||||
{
|
||||
ESP_LOGI(TAG, "WiFi scan done!!!!!");
|
||||
// 释放信号量
|
||||
xSemaphoreGive(wifi_scan_Semaphore);
|
||||
}
|
||||
|
||||
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
|
||||
{
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data;
|
||||
ESP_LOGI(TAG, "Got IP:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
// 释放信号量
|
||||
xSemaphoreGive(wifi_connect_Semaphore);
|
||||
wifi_ap_record_t ap_info;
|
||||
esp_err_t err = esp_wifi_sta_get_ap_info(&ap_info);
|
||||
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
// Print the SSID
|
||||
ESP_LOGI(TAG, "Connected SSID: %s", ap_info.ssid);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to get AP info");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize Wi-Fi as sta and set scan method */
|
||||
bool bsp_wifi_scan(wifi_ap_record_t *ap_info, uint16_t *scan_number, uint16_t scan_max_num)
|
||||
{
|
||||
// uint16_t number = DEFAULT_SCAN_LIST_SIZE;
|
||||
// wifi_ap_record_t ap_info[scan_max_num];
|
||||
esp_err_t ret = ESP_OK;
|
||||
// memset(ap_info, 0, sizeof(ap_info));
|
||||
|
||||
ret = esp_wifi_scan_start(NULL, false);
|
||||
if (ESP_OK != ret)
|
||||
goto scan_err;
|
||||
|
||||
// ESP_LOGI(TAG, "Max AP number ap_info can hold = %u", number);
|
||||
|
||||
if (xSemaphoreTake(wifi_scan_Semaphore, pdMS_TO_TICKS(5000)))
|
||||
{
|
||||
esp_wifi_scan_stop();
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(scan_number));
|
||||
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&scan_max_num, ap_info));
|
||||
ESP_LOGI(TAG, "Total APs scanned = %u, actual AP number ap_info holds = %u", *scan_number, scan_max_num);
|
||||
for (int i = 0; i < scan_max_num && i < *scan_number; i++)
|
||||
{
|
||||
ESP_LOGI(TAG, "SSID \t\t%s", ap_info[i].ssid);
|
||||
// memcpy(infos[i].name, ap_info[i].ssid, strlen((char *)ap_info[i].ssid));
|
||||
ESP_LOGI(TAG, "RSSI \t\t%d", ap_info[i].rssi);
|
||||
// infos[i].rssi = ap_info[i].rssi;
|
||||
}
|
||||
if (*scan_number > scan_max_num)
|
||||
{
|
||||
*scan_number = scan_max_num;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
scan_err:
|
||||
*scan_number = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
// esp_err_t bsp_wifi_disconnect(void)
|
||||
// {
|
||||
// return esp_wifi_disconnect();
|
||||
// }
|
||||
|
||||
// esp_err_t bsp_wifi_connect(void)
|
||||
// {
|
||||
// return esp_wifi_connect();
|
||||
// }
|
||||
|
||||
esp_err_t bsp_wifi_sta_connect(const char *ssid, const char *password)
|
||||
{
|
||||
esp_wifi_disconnect();
|
||||
// esp_wifi_stop();
|
||||
wifi_config_t wifi_config = {};
|
||||
wifi_config.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
|
||||
|
||||
memcpy(wifi_config.sta.ssid, ssid, strlen(ssid));
|
||||
memcpy(wifi_config.sta.password, password, strlen(password));
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||
|
||||
esp_wifi_connect();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
return ESP_OK;
|
||||
|
||||
// if (xSemaphoreTake(wifi_connect_Semaphore, pdMS_TO_TICKS(5000)))
|
||||
// return ESP_OK;
|
||||
// else
|
||||
// return ESP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
void bsp_wifi_get_ip(char *ip)
|
||||
{
|
||||
esp_netif_ip_info_t ip_info;
|
||||
esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &ip_info);
|
||||
sprintf(ip, "%d.%d.%d.%d", IP2STR(&ip_info.ip));
|
||||
}
|
||||
|
||||
void bsp_wifi_init(const char *ssid, const char *pass)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
|
||||
assert(sta_netif);
|
||||
|
||||
esp_netif_t *ap_netif = esp_netif_create_default_wifi_ap();
|
||||
assert(ap_netif);
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
wifi_scan_Semaphore = xSemaphoreCreateBinary();
|
||||
wifi_connect_Semaphore = xSemaphoreCreateBinary();
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
if (ssid != NULL && pass != NULL)
|
||||
{
|
||||
bsp_wifi_sta_connect(ssid, pass);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __BSP_WIFI_H__
|
||||
#define __BSP_WIFI_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_wifi.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void bsp_wifi_init(const char *ssid, const char *pass);
|
||||
void bsp_wifi_get_ip(char *ip);
|
||||
esp_err_t bsp_wifi_sta_connect(const char *ssid, const char *password);
|
||||
bool bsp_wifi_scan(wifi_ap_record_t *ap_info, uint16_t *scan_number, uint16_t scan_max_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user