mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
refactor(ble_mesh): remove LED hardware dependency from examples
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
#define TAG "BOARD"
|
||||
|
||||
#define BUTTON_IO_NUM 0
|
||||
#define BUTTON_IO_NUM CONFIG_BUTTON_IO_NUM
|
||||
#define BUTTON_ACTIVE_LEVEL 0
|
||||
|
||||
extern void example_ble_mesh_send_sensor_message(uint32_t opcode);
|
||||
|
||||
@@ -2,54 +2,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 "driver/gpio.h"
|
||||
#include "esp_log.h"
|
||||
#include "board.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_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;
|
||||
}
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
board_led_init();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -14,54 +14,6 @@
|
||||
extern "C" {
|
||||
#endif /**< __cplusplus */
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#if defined(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_ESP32H2_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
|
||||
|
||||
#define LED_ON 1
|
||||
#define LED_OFF 0
|
||||
|
||||
struct _led_state {
|
||||
uint8_t current;
|
||||
uint8_t previous;
|
||||
uint8_t pin;
|
||||
char *name;
|
||||
};
|
||||
|
||||
void board_led_operation(uint8_t pin, uint8_t onoff);
|
||||
|
||||
void board_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -164,8 +164,6 @@ static void prov_complete(uint16_t net_idx, uint16_t addr, uint8_t flags, uint32
|
||||
{
|
||||
ESP_LOGI(TAG, "net_idx 0x%03x, addr 0x%04x", net_idx, addr);
|
||||
ESP_LOGI(TAG, "flags 0x%02x, iv_index 0x%08" PRIx32, flags, iv_index);
|
||||
board_led_operation(LED_G, LED_OFF);
|
||||
|
||||
/* Initialize the indoor and outdoor temperatures for each sensor. */
|
||||
net_buf_simple_add_u8(&sensor_data_0, indoor_temp);
|
||||
net_buf_simple_add_u8(&sensor_data_1, outdoor_temp);
|
||||
@@ -617,8 +615,6 @@ static esp_err_t ble_mesh_init(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
board_led_operation(LED_G, LED_ON);
|
||||
|
||||
ESP_LOGI(TAG, "BLE Mesh sensor server initialized");
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
Reference in New Issue
Block a user