feat: add ESP-RainMaker and ESP-Matter frameworks and update existing framework metadata in frameworks.json
This commit is contained in:
1 parent
07dac4f6de
commit
d71dc8df3c
19 files changed
+2458
-282
No files matched your search
+45
-14
@@ -1,25 +1,56 @@
|
||||
/*
|
||||
* Exemplo ESP-IDF v5.x+ para ESP32
|
||||
* Demonstração de inicialização do sistema, gerenciamento de tarefas FreeRTOS e log unificado
|
||||
*
|
||||
* Gerenciamento de componentes (main/idf_component.yml):
|
||||
* dependencies:
|
||||
* espressif/led_strip: "^2.5.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_chip_info.h"
|
||||
|
||||
#define LED_PIN GPIO_NUM_2 // LED onboard (ajuste conforme sua placa)
|
||||
static const char *TAG = "main_app";
|
||||
|
||||
#define BLINK_GPIO GPIO_NUM_2 // Ajuste conforme o pino do LED da sua placa
|
||||
|
||||
static void blink_task(void *pvParameters)
|
||||
{
|
||||
// Configura o pino GPIO com a nova API do ESP-IDF
|
||||
gpio_reset_pin(BLINK_GPIO);
|
||||
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||
|
||||
bool led_state = false;
|
||||
|
||||
while (1) {
|
||||
led_state = !led_state;
|
||||
gpio_set_level(BLINK_GPIO, led_state);
|
||||
|
||||
ESP_LOGI(TAG, "LED %s | Heap livre: %lu bytes",
|
||||
led_state ? "LIGADO" : "DESLIGADO",
|
||||
(unsigned long)esp_get_free_heap_size());
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Configura o pino do LED como saída
|
||||
gpio_reset_pin(LED_PIN);
|
||||
gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT);
|
||||
// Informações do chip SoC
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
|
||||
while (1) {
|
||||
// Liga o LED
|
||||
gpio_set_level(LED_PIN, 1);
|
||||
printf("LED ON\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000)); // Espera 1 segundo
|
||||
ESP_LOGI(TAG, "===========================================");
|
||||
ESP_LOGI(TAG, " Iniciando ESP-IDF v5.x Modern Application ");
|
||||
ESP_LOGI(TAG, " Modelo do Chip: %d | Núcleos: %d | Rev: %d",
|
||||
chip_info.model, chip_info.cores, chip_info.revision);
|
||||
ESP_LOGI(TAG, "===========================================");
|
||||
|
||||
// Desliga o LED
|
||||
gpio_set_level(LED_PIN, 0);
|
||||
printf("LED OFF\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000)); // Espera 1 segundo
|
||||
}
|
||||
// Cria uma tarefa FreeRTOS dedicada
|
||||
xTaskCreate(blink_task, "blink_task", 3072, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Exemplo ESP-IoT-Solution para ESP32
|
||||
* Inicialização de Botão Inteligente com Callbacks e Driver de Display/Sensores
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/button: "^3.3.0"
|
||||
* espressif/led_indicator: "^1.2.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "iot_button.h"
|
||||
#include "led_indicator.h"
|
||||
|
||||
static const char *TAG = "iot_solution_app";
|
||||
|
||||
#define BUTTON_GPIO_NUM 0 // Botão BOOT nativo
|
||||
#define LED_INDICATOR_GPIO 2 // LED indicador
|
||||
|
||||
static led_indicator_handle_t led_handle = NULL;
|
||||
|
||||
/* Callback para clique único do botão */
|
||||
static void button_single_click_cb(void *arg, void *data)
|
||||
{
|
||||
ESP_LOGI(TAG, "Evento: Clique Único detectado!");
|
||||
led_indicator_start(led_handle, BLINK_DOUBLE_FAST);
|
||||
}
|
||||
|
||||
/* Callback para clique longo (> 3 segundos) */
|
||||
static void button_long_press_cb(void *arg, void *data)
|
||||
{
|
||||
ESP_LOGW(TAG, "Evento: Pressionamento Longo! Acionando modo de reset de fábrica.");
|
||||
led_indicator_start(led_handle, BLINK_BREATHE_FAST);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando ESP-IoT-Solution Component Suite");
|
||||
|
||||
// 1. Configuração do LED Indicator
|
||||
led_indicator_gpio_config_t led_cfg = {
|
||||
.is_active_level_high = true,
|
||||
.gpio_num = LED_INDICATOR_GPIO,
|
||||
};
|
||||
led_handle = led_indicator_create(&led_cfg);
|
||||
|
||||
// 2. Configuração do Botão com debounce de hardware/software automático
|
||||
button_config_t btn_cfg = {
|
||||
.type = BUTTON_TYPE_GPIO,
|
||||
.long_press_time = 3000,
|
||||
.short_press_time = 180,
|
||||
.gpio_button_config = {
|
||||
.gpio_num = BUTTON_GPIO_NUM,
|
||||
.active_level = 0,
|
||||
},
|
||||
};
|
||||
|
||||
button_handle_t btn_handle = iot_button_create(&btn_cfg);
|
||||
assert(btn_handle != NULL);
|
||||
|
||||
// Registra callbacks para diferentes gestos
|
||||
iot_button_register_cb(btn_handle, BUTTON_SINGLE_CLICK, button_single_click_cb, NULL);
|
||||
iot_button_register_cb(btn_handle, BUTTON_LONG_PRESS_START, button_long_press_cb, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "Drivers inicializados com sucesso! Pressione o botão GPIO 0.");
|
||||
|
||||
while (1) {
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Exemplo ESP-NOW para ESP32
|
||||
* Comunicação Sem Fio Ponto-a-Ponto e Broadcast sem roteador Wi-Fi
|
||||
*
|
||||
* Protocolo nativo integrado no ESP-IDF
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_now.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
static const char *TAG = "esp_now_demo";
|
||||
|
||||
// Estrutura de dados enviada no pacote
|
||||
typedef struct {
|
||||
uint32_t sensor_id;
|
||||
float temperatura;
|
||||
float umidade;
|
||||
uint32_t tempo_ms;
|
||||
} __attribute__((packed)) dados_pacote_t;
|
||||
|
||||
// Endereço MAC de Broadcast (envia para todos os nós ESP-NOW por perto)
|
||||
static const uint8_t broadcast_mac[ESP_NOW_ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
|
||||
/* Callback executado ao enviar um pacote */
|
||||
static void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status)
|
||||
{
|
||||
ESP_LOGI(TAG, "Envio concluído: %s", status == ESP_NOW_SEND_SUCCESS ? "SUCESSO (ACK)" : "FALHA");
|
||||
}
|
||||
|
||||
/* Callback executado ao receber um pacote de outro ESP32 */
|
||||
static void on_data_recv(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len)
|
||||
{
|
||||
if (len == sizeof(dados_pacote_t)) {
|
||||
dados_pacote_t *pct = (dados_pacote_t *)data;
|
||||
ESP_LOGI(TAG, "Pacote recebido de [%02X:%02X:%02X:%02X:%02X:%02X]: Sensor #%ld | Temp: %.1f C | Umid: %.1f %%",
|
||||
recv_info->src_addr[0], recv_info->src_addr[1], recv_info->src_addr[2],
|
||||
recv_info->src_addr[3], recv_info->src_addr[4], recv_info->src_addr[5],
|
||||
pct->sensor_id, pct->temperatura, pct->umidade);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicializa NVS e Wi-Fi em modo Station
|
||||
nvs_flash_init();
|
||||
esp_netif_init();
|
||||
esp_event_loop_create_default();
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
esp_wifi_init(&cfg);
|
||||
esp_wifi_set_mode(WIFI_MODE_STA);
|
||||
esp_wifi_start();
|
||||
|
||||
// Inicializa o protocolo ESP-NOW
|
||||
ESP_ERROR_CHECK(esp_now_init());
|
||||
esp_now_register_send_cb(on_data_sent);
|
||||
esp_now_register_recv_cb(on_data_recv);
|
||||
|
||||
// Registra o peer de Broadcast
|
||||
esp_now_peer_info_t peer_info = {
|
||||
.channel = 1,
|
||||
.ifidx = WIFI_IF_STA,
|
||||
.encrypt = false,
|
||||
};
|
||||
memcpy(peer_info.peer_addr, broadcast_mac, ESP_NOW_ETH_ALEN);
|
||||
ESP_ERROR_CHECK(esp_now_add_peer(&peer_info));
|
||||
|
||||
ESP_LOGI(TAG, "ESP-NOW pronto! Enviando telemetria a cada 3 segundos...");
|
||||
|
||||
dados_pacote_t telemetria = {
|
||||
.sensor_id = 101,
|
||||
.temperatura = 24.8f,
|
||||
.umidade = 58.2f,
|
||||
};
|
||||
|
||||
while (1) {
|
||||
telemetria.tempo_ms = esp_log_timestamp();
|
||||
telemetria.temperatura += ((float)(rand() % 10) - 5.0f) / 10.0f;
|
||||
|
||||
esp_err_t res = esp_now_send(broadcast_mac, (uint8_t *)&telemetria, sizeof(telemetria));
|
||||
if (res != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Erro ao disparar envio ESP-NOW: %d", res);
|
||||
}
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Exemplo ESP-RainMaker para ESP32
|
||||
* Dispositivo: Interruptor Inteligente com controle via App e Nuvem
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp_rainmaker: "^1.4.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_devices.h>
|
||||
#include <app_wifi.h>
|
||||
|
||||
static const char *TAG = "app_rainmaker";
|
||||
static esp_rmaker_device_t *switch_device;
|
||||
|
||||
/* Callback acionado quando o usuário altera o estado no App móvel */
|
||||
static esp_err_t write_cb(const esp_rmaker_device_t *dev, const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
ESP_LOGI(TAG, "Comando recebido via %s", esp_rmaker_device_cb_src_to_str(ctx->src));
|
||||
}
|
||||
|
||||
bool state = val.val.b;
|
||||
ESP_LOGI(TAG, "Estado do interruptor alterado para: %s", state ? "LIGADO" : "DESLIGADO");
|
||||
|
||||
// Atualiza o parâmetro na nuvem e no aplicativo
|
||||
esp_rmaker_param_update_and_report(priv_data, val);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Inicialização da memória não-volátil (NVS)
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
|
||||
// Inicializa o provisionamento Wi-Fi
|
||||
app_wifi_init();
|
||||
|
||||
// Configura o nó RainMaker
|
||||
esp_rmaker_config_t rainmaker_cfg = {
|
||||
.enable_time_sync = true,
|
||||
};
|
||||
esp_rmaker_node_t *node = esp_rmaker_node_init(&rainmaker_cfg, "ESP32_SmartSwitch", "Switch");
|
||||
|
||||
// Cria o dispositivo padrão 'Switch'
|
||||
switch_device = esp_rmaker_switch_device_create("Luz Sala", NULL, true);
|
||||
|
||||
// Registra callback de escrita
|
||||
esp_rmaker_device_add_cb(switch_device, write_cb, NULL);
|
||||
esp_rmaker_node_add_device(node, switch_device);
|
||||
|
||||
// Habilita serviços adicionais (OTA e Timezone)
|
||||
esp_rmaker_ota_enable_default();
|
||||
esp_rmaker_timezone_service_enable();
|
||||
|
||||
// Inicia o agente RainMaker
|
||||
esp_rmaker_start();
|
||||
|
||||
// Inicia o provisionamento Wi-Fi via BLE (abre no app oficial RainMaker)
|
||||
app_wifi_start(POP_TYPE_RANDOM);
|
||||
|
||||
ESP_LOGI(TAG, "Nó RainMaker pronto! Escaneie o QR Code no app ESP RainMaker.");
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Exemplo ESP-SR para ESP32-S3 / ESP32-P4
|
||||
* Reconhecimento de Fala Local Offline (WakeNet + MultiNet)
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp-sr: "^1.5.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wn_iface.h"
|
||||
#include "esp_wn_models.h"
|
||||
#include "esp_mn_iface.h"
|
||||
#include "esp_mn_models.h"
|
||||
#include "esp_afe_sr_iface.h"
|
||||
#include "esp_afe_sr_models.h"
|
||||
|
||||
static const char *TAG = "app_voice_sr";
|
||||
|
||||
void feed_audio_task(void *arg)
|
||||
{
|
||||
esp_afe_sr_data_t *afe_data = (esp_afe_sr_data_t *)arg;
|
||||
int audio_chunksize = afe_handle->get_feed_chunksize(afe_data);
|
||||
int16_t *feed_buff = (int16_t *)malloc(audio_chunksize * sizeof(int16_t) * 2);
|
||||
|
||||
while (1) {
|
||||
// Leitura de áudio I2S dos microfones da placa
|
||||
// i2s_read(I2S_NUM_0, feed_buff, ...);
|
||||
|
||||
afe_handle->feed(afe_data, feed_buff);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
free(feed_buff);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void speech_recognition_task(void *arg)
|
||||
{
|
||||
esp_afe_sr_data_t *afe_data = (esp_afe_sr_data_t *)arg;
|
||||
const esp_afe_sr_iface_t *afe_handle = &ESP_AFE_SR_HANDLE;
|
||||
|
||||
// Inicializa o modelo de comandos de fala (MultiNet)
|
||||
const esp_mn_iface_t *multinet = &ESP_MN_HANDLE;
|
||||
model_iface_data_t *model_data = multinet->create(&MULTINET_MODEL, 6000);
|
||||
|
||||
ESP_LOGI(TAG, "Aguardando palavra-chave de ativação (ex: 'Hi, ESP')...");
|
||||
|
||||
while (1) {
|
||||
afe_fetch_result_t *res = afe_handle->fetch(afe_data);
|
||||
if (!res || res->ret_value == ESP_FAIL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1. Verificação de Wake Word (Palavra de ativação)
|
||||
if (res->wake_word_detected == WAKENET_DETECTED) {
|
||||
ESP_LOGW(TAG, ">>> PALAVRA-CHAVE DETECTADA! Canal de escuta aberto.");
|
||||
}
|
||||
|
||||
// 2. Reconhecimento de comando local
|
||||
if (res->raw_data_size > 0) {
|
||||
esp_mn_state_t mn_state = multinet->detect(model_data, res->data);
|
||||
|
||||
if (mn_state == ESP_MN_STATE_DETECTED) {
|
||||
esp_mn_results_t *mn_res = multinet->get_results(model_data);
|
||||
ESP_LOGI(TAG, ">>> COMANDO RECONHECIDO: ID #%d (Frase correspondente)", mn_res->command_id[0]);
|
||||
|
||||
// Exemplo de ação
|
||||
if (mn_res->command_id[0] == 1) {
|
||||
ESP_LOGI(TAG, "Ação: Ligar Luz da Sala");
|
||||
} else if (mn_res->command_id[0] == 2) {
|
||||
ESP_LOGI(TAG, "Ação: Desligar Luz da Sala");
|
||||
}
|
||||
} else if (mn_state == ESP_MN_STATE_TIMEOUT) {
|
||||
ESP_LOGI(TAG, "Tempo esgotado. Retornando ao modo de escuta de Wake Word.");
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "Iniciando ESP-SR Speech Recognition Engine");
|
||||
|
||||
// Configura o pipeline de Audio Front-End (AEC, BSS, VAD, WakeNet)
|
||||
afe_config_t afe_config = AFE_CONFIG_DEFAULT();
|
||||
afe_config.wakenet_init = true;
|
||||
afe_config.voice_communication_init = false;
|
||||
|
||||
esp_afe_sr_data_t *afe_data = ESP_AFE_SR_HANDLE.create_from_config(&afe_config);
|
||||
|
||||
// Cria as tarefas de alimentação de áudio e reconhecimento
|
||||
xTaskCreatePinnedToCore(feed_audio_task, "feed_task", 4096, afe_data, 5, NULL, 0);
|
||||
xTaskCreatePinnedToCore(speech_recognition_task, "sr_task", 8192, afe_data, 5, NULL, 1);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Exemplo ESP-Zigbee-SDK para ESP32-H2 e ESP32-C6 (IEEE 802.15.4)
|
||||
* Dispositivo: Lâmpada Inteligente Zigbee 3.0 (Home Automation End Device)
|
||||
*
|
||||
* Dependência (idf_component.yml):
|
||||
* espressif/esp-zigbee-lib: "^1.6.0"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_zigbee_core.h"
|
||||
|
||||
static const char *TAG = "zigbee_light_device";
|
||||
|
||||
#define HA_ESP_LIGHT_ENDPOINT 1
|
||||
#define ESP_ZB_PRIMARY_CHANNEL_MASK (1l << 15) // Canal 15 padrão Zigbee
|
||||
|
||||
/* Callback de escrita em atributos Zigbee (ex: Liga/Desliga via Home Assistant) */
|
||||
static esp_err_t zb_attribute_handler(const esp_zb_zcl_set_attr_value_message_t *message)
|
||||
{
|
||||
if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_ON_OFF) {
|
||||
if (message->attribute.id == ESP_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID &&
|
||||
message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_BOOL) {
|
||||
bool on_off_state = message->attribute.data.value ? *(bool *)message->attribute.data.value : false;
|
||||
ESP_LOGW(TAG, ">>> COMANDO ZIGBEE RECEBIDO: Lâmpada %s", on_off_state ? "LIGADA" : "DESLIGADA");
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Callback de eventos da pilha Zigbee */
|
||||
void esp_zb_app_signal_handler(esp_zb_app_signal_msg_t *signal_msg)
|
||||
{
|
||||
uint32_t *p_sg_p = signal_msg->p_app_signal;
|
||||
esp_err_t err_status = signal_msg->esp_err_status;
|
||||
esp_zb_app_signal_type_t sig_type = *p_sg_p;
|
||||
|
||||
switch (sig_type) {
|
||||
case ESP_ZB_ZDO_SIGNAL_SKIP_STARTUP:
|
||||
ESP_LOGI(TAG, "Iniciando comissionamento na rede Zigbee...");
|
||||
esp_zb_bdb_start_top_level_commissioning(ESP_ZB_BDB_MODE_NETWORK_STEERING);
|
||||
break;
|
||||
case ESP_ZB_BDB_SIGNAL_STEERING:
|
||||
if (err_status == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Conectado com sucesso à rede Zigbee 3.0!");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Buscando coordenador Zigbee novamente...");
|
||||
esp_zb_scheduler_alarm((esp_zb_callback_t)esp_zb_bdb_start_top_level_commissioning, ESP_ZB_BDB_MODE_NETWORK_STEERING, 1000);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void esp_zb_task(void *pvParameters)
|
||||
{
|
||||
// Configura nó Zigbee como End Device
|
||||
esp_zb_cfg_t zb_nwk_cfg = {
|
||||
.esp_zb_role = ESP_ZB_DEVICE_TYPE_ED,
|
||||
.install_code_policy = false,
|
||||
.nwk_cfg.zed_cfg = {
|
||||
.ed_timeout = ESP_ZB_ED_0_5_MIN,
|
||||
.keep_alive = 3000,
|
||||
},
|
||||
};
|
||||
esp_zb_init(&zb_nwk_cfg);
|
||||
|
||||
// Cria o cluster de On/Off de iluminação residencial
|
||||
esp_zb_on_off_light_cfg_t light_cfg = ESP_ZB_DEFAULT_ON_OFF_LIGHT_CONFIG();
|
||||
esp_zb_ep_list_t *ep_list = esp_zb_on_off_light_ep_create(HA_ESP_LIGHT_ENDPOINT, &light_cfg);
|
||||
|
||||
// Registra endpoint e manipulador de atributos
|
||||
esp_zb_device_register(ep_list);
|
||||
esp_zb_core_action_handler_register(zb_attribute_handler);
|
||||
|
||||
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
|
||||
ESP_ERROR_CHECK(esp_zb_start(false));
|
||||
esp_zb_main_loop_iteration();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
|
||||
// Inicializa a pilha de rádio IEEE 802.15.4
|
||||
esp_zb_platform_config_t config = {
|
||||
.radio_config = { .radio_mode = ZB_RADIO_MODE_NATIVE },
|
||||
.host_config = { .host_connection_mode = ZB_HOST_CONNECTION_MODE_NONE },
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_zb_platform_config(&config));
|
||||
|
||||
xTaskCreate(esp_zb_task, "Zigbee_main", 4096, NULL, 5, NULL);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//! Exemplo Rust no ESP32 usando `esp-hal` (Modo Bare-Metal / no_std)
|
||||
//! Pisca um LED e envia mensagens via UART Serial com segurança de memória garantida.
|
||||
//!
|
||||
//! Cargo.toml:
|
||||
//! esp-hal = { version = "0.22", features = ["esp32s3"] }
|
||||
//! esp-println = { version = "0.12", features = ["esp32s3", "log"] }
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{
|
||||
clock::ClockControl,
|
||||
gpio::{Io, Level, Output},
|
||||
peripherals::Peripherals,
|
||||
system::SystemControl,
|
||||
timer::timg::TimerGroup,
|
||||
delay::Delay,
|
||||
prelude::*,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
// Inicializa periféricos do SoC com verificação em tempo de compilação
|
||||
let peripherals = Peripherals::take();
|
||||
let system = SystemControl::new(peripherals.SYSTEM);
|
||||
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
||||
|
||||
// Configura os pinos de E/S
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut led = Output::new(io.pins.gpio2, Level::Low);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
|
||||
println!("🦀 Firmware Rust Bare-Metal inicializado no ESP32!");
|
||||
|
||||
let mut counter: u32 = 0;
|
||||
|
||||
loop {
|
||||
// Inverte estado do LED com garantia de exclusão mútua
|
||||
led.toggle();
|
||||
counter += 1;
|
||||
|
||||
println!("Ciclo Rust #{}: LED está {:?}", counter, led.is_set_high());
|
||||
delay.delay_millis(500);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user