mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
refactor(ble_mesh): remove LED hardware dependency from examples
This commit is contained in:
@@ -1,66 +1,17 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "board.h"
|
||||
#include "ble_mesh_fast_prov_common.h"
|
||||
|
||||
#define TAG "BOARD"
|
||||
|
||||
struct _led_state led_state[3] = {
|
||||
{ LED_OFF, LED_OFF, LED_R, "red" },
|
||||
{ LED_OFF, LED_OFF, LED_G, "green" },
|
||||
{ LED_OFF, LED_OFF, LED_B, "blue" },
|
||||
};
|
||||
|
||||
void board_output_number(esp_ble_mesh_output_action_t action, uint32_t number)
|
||||
{
|
||||
ESP_LOGI(TAG, "Board output number %" PRIu32, number);
|
||||
}
|
||||
|
||||
void board_prov_complete(void)
|
||||
{
|
||||
board_led_operation(LED_B, LED_OFF);
|
||||
}
|
||||
|
||||
void board_led_operation(uint8_t pin, uint8_t onoff)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (led_state[i].pin != pin) {
|
||||
continue;
|
||||
}
|
||||
if (onoff == led_state[i].previous) {
|
||||
ESP_LOGW(TAG, "led %s is already %s",
|
||||
led_state[i].name, (onoff ? "on" : "off"));
|
||||
return;
|
||||
}
|
||||
gpio_set_level(pin, onoff);
|
||||
led_state[i].previous = onoff;
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGE(TAG, "LED is not found!");
|
||||
}
|
||||
|
||||
static void board_led_init(void)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
gpio_reset_pin(led_state[i].pin);
|
||||
gpio_set_direction(led_state[i].pin, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(led_state[i].pin, LED_OFF);
|
||||
led_state[i].previous = LED_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t board_init(void)
|
||||
{
|
||||
board_led_init();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -8,52 +8,7 @@
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef CONFIG_BLE_MESH_ESP_WROOM_32
|
||||
#define LED_R GPIO_NUM_25
|
||||
#define LED_G GPIO_NUM_26
|
||||
#define LED_B GPIO_NUM_27
|
||||
#elif defined(CONFIG_BLE_MESH_ESP_WROVER)
|
||||
#define LED_R GPIO_NUM_0
|
||||
#define LED_G GPIO_NUM_2
|
||||
#define LED_B GPIO_NUM_4
|
||||
#elif defined(CONFIG_BLE_MESH_ESP32C3_DEV)
|
||||
#define LED_R GPIO_NUM_8
|
||||
#define LED_G GPIO_NUM_8
|
||||
#define LED_B GPIO_NUM_8
|
||||
#elif defined(CONFIG_BLE_MESH_ESP32S3_DEV)
|
||||
#define LED_R GPIO_NUM_47
|
||||
#define LED_G GPIO_NUM_47
|
||||
#define LED_B GPIO_NUM_47
|
||||
#elif defined(CONFIG_BLE_MESH_ESP32C6_DEV)
|
||||
#define LED_R GPIO_NUM_8
|
||||
#define LED_G GPIO_NUM_8
|
||||
#define LED_B GPIO_NUM_8
|
||||
#elif defined(CONFIG_BLE_MESH_ESP32C61_DEV)
|
||||
#define LED_R GPIO_NUM_8
|
||||
#define LED_G GPIO_NUM_8
|
||||
#define LED_B GPIO_NUM_8
|
||||
#elif defined(CONFIG_BLE_MESH_ESP32C5_DEV)
|
||||
#define LED_R GPIO_NUM_8
|
||||
#define LED_G GPIO_NUM_8
|
||||
#define LED_B GPIO_NUM_8
|
||||
#endif
|
||||
|
||||
struct _led_state {
|
||||
uint8_t current;
|
||||
uint8_t previous;
|
||||
uint8_t pin;
|
||||
char *name;
|
||||
};
|
||||
|
||||
void board_output_number(esp_ble_mesh_output_action_t action, uint32_t number);
|
||||
|
||||
void board_prov_complete(void);
|
||||
|
||||
void board_led_operation(uint8_t pin, uint8_t onoff);
|
||||
#include "esp_err.h"
|
||||
|
||||
esp_err_t board_init(void);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -43,7 +43,6 @@
|
||||
|
||||
#define TAG "EXAMPLE"
|
||||
|
||||
extern struct _led_state led_state[3];
|
||||
extern struct k_delayed_work send_self_prov_node_addr_timer;
|
||||
extern bt_mesh_atomic_t fast_prov_cli_flags;
|
||||
|
||||
@@ -168,9 +167,7 @@ static esp_ble_mesh_prov_t prov = {
|
||||
|
||||
static void example_change_led_state(uint8_t onoff)
|
||||
{
|
||||
struct _led_state *led = &led_state[1];
|
||||
|
||||
board_led_operation(led->pin, onoff);
|
||||
ESP_LOGI(TAG, "Recv GenOnOff message, state: %s", onoff ? "ON" : "OFF");
|
||||
|
||||
/* When the node receives the first Generic OnOff Get/Set/Set Unack message, it will
|
||||
* start the timer used to disable fast provisioning functionality.
|
||||
@@ -189,7 +186,7 @@ static void node_prov_complete(uint16_t net_idx, uint16_t addr, uint8_t flags, u
|
||||
{
|
||||
ESP_LOGI(TAG, "net_idx: 0x%04x, unicast_addr: 0x%04x", net_idx, addr);
|
||||
ESP_LOGI(TAG, "flags: 0x%02x, iv_index: 0x%08" PRIx32, flags, iv_index);
|
||||
board_prov_complete();
|
||||
ESP_LOGI(TAG, "Provisioning complete");
|
||||
/* Updates the net_idx used by Fast Prov Server model, and it can also
|
||||
* be updated if the Fast Prov Info Set message contains a valid one.
|
||||
*/
|
||||
@@ -225,7 +222,7 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint
|
||||
|
||||
/* Sets node info */
|
||||
err = example_store_node_info(uuid, unicast_addr, element_num, net_idx,
|
||||
fast_prov_server.app_idx, LED_OFF);
|
||||
fast_prov_server.app_idx, 0);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s: Failed to set node info", __func__);
|
||||
return;
|
||||
@@ -755,8 +752,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
|
||||
ESP_LOGI(TAG, "BLE Mesh Wi-Fi Coexist Node initialized");
|
||||
|
||||
board_led_operation(LED_B, LED_ON);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user