mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-20 09:55:54 +08:00
添加智能灯固件代码
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "base_mac_address_example_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,46 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
choice BASE_MAC_ADDRESS_STORAGE
|
||||
prompt "Storage location of the base MAC address"
|
||||
default BASE_MAC_STORED_EFUSE_BLK0
|
||||
help
|
||||
Select the storage location of the base MAC addresses.
|
||||
1. eFuse BLK0: The "Default (Espressif factory)" selection. The
|
||||
default base MAC address is written to words 1 and 2 of eFuse block
|
||||
0 when the chip was manufactured. Call esp_efuse_mac_get_default()
|
||||
read retrieve the "eFuse BLK0" MAC address.
|
||||
2. eFuse BLK3: A custom base MAC address is burned by the user into
|
||||
eFuse word 0 of block 3. Call esp_efuse_mac_get_custom() to read
|
||||
the "eFuse BLK3" MAC address.
|
||||
3. Other External Storage: Selecting this option will cause the
|
||||
example to call external_storage_mac_get() which is defined in this
|
||||
example to simply return a MAC address preset in software. Users
|
||||
should modify this function to access their desired storage mediums
|
||||
(e.g. flash, EEPROM etc).
|
||||
|
||||
config BASE_MAC_STORED_EFUSE_BLK0
|
||||
bool "Default (Espressif factory) eFuse BLK0"
|
||||
config BASE_MAC_STORED_EFUSE_BLK3
|
||||
bool "Custom eFuse BLK3"
|
||||
config BASE_MAC_STORED_OTHER_EXTERNAL_STORAGE
|
||||
bool "Other external storage"
|
||||
endchoice
|
||||
|
||||
choice BASE_MAC_STORED_EFUSE_BLK3_ERROR_BEHAV
|
||||
prompt "Behavior when retrieving eFuse BLK3 fails"
|
||||
depends on BASE_MAC_STORED_EFUSE_BLK3
|
||||
default BASE_MAC_STORED_EFUSE_BLK3_ERROR_DEFAULT
|
||||
help
|
||||
Select the behavior when reading base MAC address "eFuse BLK3" fails
|
||||
(i.e. the retrieved result is all 0).
|
||||
- If "Abort" is selected, the ESP32 will abort.
|
||||
- If "Use the default base MAC address from BLK0 of eFuse" is
|
||||
selected, the default "eFuse BLK0" will be used instead.
|
||||
|
||||
config BASE_MAC_STORED_EFUSE_BLK3_ERROR_ABORT
|
||||
bool "Abort"
|
||||
config BASE_MAC_STORED_EFUSE_BLK3_ERROR_DEFAULT
|
||||
bool "Use the default base MAC address eFuse BLK0"
|
||||
endchoice
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,108 @@
|
||||
/* Base mac address 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#define TAG "BASE_MAC"
|
||||
|
||||
#ifdef CONFIG_BASE_MAC_STORED_OTHER_EXTERNAL_STORAGE
|
||||
|
||||
static esp_err_t external_storage_mac_get(uint8_t *mac)
|
||||
{
|
||||
/* This function simulates getting a base MAC address from external storage
|
||||
* by simply setting the base MAC to an arbitrary address. Users should
|
||||
* re-implement this function to access external storage (e.g. flash, EEPROM) */
|
||||
uint8_t external_storage_mac_addr[6] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
|
||||
if (mac == NULL) {
|
||||
ESP_LOGE(TAG, "The mac parameter is NULL");
|
||||
abort();
|
||||
}
|
||||
|
||||
memcpy(mac, external_storage_mac_addr, 6);
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif//CONFIG_BASE_MAC_STORED_OTHER_EXTERNAL_STORAGE
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
//Get the base MAC address from different sources
|
||||
uint8_t base_mac_addr[6] = {0};
|
||||
esp_err_t ret = ESP_OK;
|
||||
#ifdef CONFIG_BASE_MAC_STORED_EFUSE_BLK3
|
||||
//Get base MAC address from EFUSE BLK3
|
||||
ret = esp_efuse_mac_get_custom(base_mac_addr);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to get base MAC address from EFUSE BLK3. (%s)", esp_err_to_name(ret));
|
||||
#ifdef CONFIG_BASE_MAC_STORED_EFUSE_BLK3_ERROR_ABORT
|
||||
ESP_LOGE(TAG, "Aborting");
|
||||
abort();
|
||||
#else
|
||||
ESP_LOGI(TAG, "Defaulting to base MAC address in BLK0 of EFUSE");
|
||||
esp_efuse_mac_get_default(base_mac_addr);
|
||||
ESP_LOGI(TAG, "Base MAC Address read from EFUSE BLK0");
|
||||
#endif//CONFIG_BASE_MAC_STORED_EFUSE_BLK3_ERROR_ABORT
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Base MAC Address read from EFUSE BLK3");
|
||||
}
|
||||
#elif defined(CONFIG_BASE_MAC_STORED_OTHER_EXTERNAL_STORAGE)
|
||||
//Get base MAC address from other external storage, or set by software
|
||||
ret = external_storage_mac_get(base_mac_addr);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to get base MAC address from external storage. (%s)", esp_err_to_name(ret));
|
||||
ESP_LOGE(TAG, "Aborting");
|
||||
abort();
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Base MAC Address read from external storage");
|
||||
}
|
||||
#else
|
||||
//Get base MAC address from EFUSE BLK0(default option)
|
||||
ret = esp_efuse_mac_get_default(base_mac_addr);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to get base MAC address from EFUSE BLK0. (%s)", esp_err_to_name(ret));
|
||||
ESP_LOGE(TAG, "Aborting");
|
||||
abort();
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Base MAC Address read from EFUSE BLK0");
|
||||
}
|
||||
#endif
|
||||
|
||||
//Set the base MAC address using the retrieved MAC address
|
||||
ESP_LOGI(TAG, "Using \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" as base MAC address",
|
||||
base_mac_addr[0], base_mac_addr[1], base_mac_addr[2], base_mac_addr[3], base_mac_addr[4], base_mac_addr[5]);
|
||||
esp_base_mac_addr_set(base_mac_addr);
|
||||
|
||||
//Get the derived MAC address for each network interface
|
||||
uint8_t derived_mac_addr[6] = {0};
|
||||
//Get MAC address for WiFi Station interface
|
||||
ESP_ERROR_CHECK(esp_read_mac(derived_mac_addr, ESP_MAC_WIFI_STA));
|
||||
ESP_LOGI("WIFI_STA MAC", "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x",
|
||||
derived_mac_addr[0], derived_mac_addr[1], derived_mac_addr[2],
|
||||
derived_mac_addr[3], derived_mac_addr[4], derived_mac_addr[5]);
|
||||
|
||||
//Get MAC address for SoftAp interface
|
||||
ESP_ERROR_CHECK(esp_read_mac(derived_mac_addr, ESP_MAC_WIFI_SOFTAP));
|
||||
ESP_LOGI("SoftAP MAC", "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x",
|
||||
derived_mac_addr[0], derived_mac_addr[1], derived_mac_addr[2],
|
||||
derived_mac_addr[3], derived_mac_addr[4], derived_mac_addr[5]);
|
||||
|
||||
//Get MAC address for Bluetooth
|
||||
ESP_ERROR_CHECK(esp_read_mac(derived_mac_addr, ESP_MAC_BT));
|
||||
ESP_LOGI("BT MAC", "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x",
|
||||
derived_mac_addr[0], derived_mac_addr[1], derived_mac_addr[2],
|
||||
derived_mac_addr[3], derived_mac_addr[4], derived_mac_addr[5]);
|
||||
|
||||
//Get MAC address for Ethernet
|
||||
ESP_ERROR_CHECK(esp_read_mac(derived_mac_addr, ESP_MAC_ETH));
|
||||
ESP_LOGI("Ethernet MAC", "0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x",
|
||||
derived_mac_addr[0], derived_mac_addr[1], derived_mac_addr[2],
|
||||
derived_mac_addr[3], derived_mac_addr[4], derived_mac_addr[5]);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#
|
||||
# Main Makefile. This is basically the same as a component makefile.
|
||||
#
|
||||
Reference in New Issue
Block a user