Skip to content

Commit

Permalink
Merge branch 'bsp_integration' into 'main'
Browse files Browse the repository at this point in the history
Changed HAL to use BSP

See merge request app-frameworks/esp-matter!547
  • Loading branch information
chshu committed Feb 7, 2024
2 parents 1e7f0ae + 41ec0e2 commit 886aa35
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/common/app_reset/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS app_reset.cpp
INCLUDE_DIRS .
REQUIRES device esp_matter)
REQUIRES button esp_matter)
2 changes: 1 addition & 1 deletion examples/common/app_reset/app_reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

#include <esp_log.h>
#include <device.h>
#include <esp_matter.h>
#include "iot_button.h"

static const char *TAG = "app_reset";
static bool perform_factory_reset = false;
Expand Down
20 changes: 0 additions & 20 deletions examples/light/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ if(NOT DEFINED ENV{ESP_MATTER_PATH})
message(FATAL_ERROR "Please set ESP_MATTER_PATH to the path of esp-matter repo")
endif(NOT DEFINED ENV{ESP_MATTER_PATH})

if(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH})
if("${IDF_TARGET}" STREQUAL "esp32" OR "${IDF_TARGET}" STREQUAL "")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32_devkit_c)
elseif("${IDF_TARGET}" STREQUAL "esp32c3")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c3_devkit_m)
elseif("${IDF_TARGET}" STREQUAL "esp32c2")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c2_devkit_m)
elseif("${IDF_TARGET}" STREQUAL "esp32h2")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32h2_devkit_c)
elseif("${IDF_TARGET}" STREQUAL "esp32s3")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32s3_devkit_c)
elseif("${IDF_TARGET}" STREQUAL "esp32c6")
set(ENV{ESP_MATTER_DEVICE_PATH} $ENV{ESP_MATTER_PATH}/device_hal/device/esp32c6_devkit_c)
else()
message(FATAL_ERROR "Unsupported IDF_TARGET")
endif()
endif(NOT DEFINED ENV{ESP_MATTER_DEVICE_PATH})

set(PROJECT_VER "1.0")
set(PROJECT_VER_NUMBER 1)

Expand All @@ -32,13 +14,11 @@ set(MATTER_SDK_PATH ${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip)

# This should be done before using the IDF_TARGET variable.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake)

set(EXTRA_COMPONENT_DIRS
"${ESP_MATTER_PATH}/examples/common"
"${MATTER_SDK_PATH}/config/esp32/components"
"${ESP_MATTER_PATH}/components"
"${ESP_MATTER_PATH}/device_hal/device"
${extra_components_dirs_append})

project(light)
Expand Down
83 changes: 62 additions & 21 deletions examples/light/main/app_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
#include <stdlib.h>
#include <string.h>

#include <device.h>
#include <esp_matter.h>
#include <led_driver.h>
#include "bsp/esp-bsp.h"

#include <app_priv.h>

Expand All @@ -23,33 +22,68 @@ static const char *TAG = "app_driver";
extern uint16_t light_endpoint_id;

/* Do any conversions/remapping for the actual value here */
static esp_err_t app_driver_light_set_power(led_driver_handle_t handle, esp_matter_attr_val_t *val)
static esp_err_t app_driver_light_set_power(led_indicator_handle_t handle, esp_matter_attr_val_t *val)
{
return led_driver_set_power(handle, val->val.b);
#if BSP_LED_NUM > 0
esp_err_t err = ESP_OK;
if (val->val.b) {
err = led_indicator_start(handle, BSP_LED_ON);
} else {
err = led_indicator_start(handle, BSP_LED_OFF);
}
return err;
#else
ESP_LOGI(TAG, "LED set power: %d", val->val.b);
return ESP_OK;
#endif
}

static esp_err_t app_driver_light_set_brightness(led_driver_handle_t handle, esp_matter_attr_val_t *val)
static esp_err_t app_driver_light_set_brightness(led_indicator_handle_t handle, esp_matter_attr_val_t *val)
{
int value = REMAP_TO_RANGE(val->val.u8, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
return led_driver_set_brightness(handle, value);
#if BSP_LED_NUM > 0
return led_indicator_set_brightness(handle, value);
#else
ESP_LOGI(TAG, "LED set brightness: %d", value);
return ESP_OK;
#endif
}

static esp_err_t app_driver_light_set_hue(led_driver_handle_t handle, esp_matter_attr_val_t *val)
static esp_err_t app_driver_light_set_hue(led_indicator_handle_t handle, esp_matter_attr_val_t *val)
{
int value = REMAP_TO_RANGE(val->val.u8, MATTER_HUE, STANDARD_HUE);
return led_driver_set_hue(handle, value);
#if BSP_LED_NUM > 0
uint32_t hsv = led_indicator_get_hsv(handle);
SET_HUE(hsv, value);
return led_indicator_set_hsv(handle, hsv);
#else
ESP_LOGI(TAG, "LED set hue: %d", value);
return ESP_OK;
#endif
}

static esp_err_t app_driver_light_set_saturation(led_driver_handle_t handle, esp_matter_attr_val_t *val)
static esp_err_t app_driver_light_set_saturation(led_indicator_handle_t handle, esp_matter_attr_val_t *val)
{
int value = REMAP_TO_RANGE(val->val.u8, MATTER_SATURATION, STANDARD_SATURATION);
return led_driver_set_saturation(handle, value);
#if BSP_LED_NUM > 0
uint32_t hsv = led_indicator_get_hsv(handle);
SET_SATURATION(hsv, value);
return led_indicator_set_hsv(handle, hsv);
#else
ESP_LOGI(TAG, "LED set saturation: %d", value);
return ESP_OK;
#endif
}

static esp_err_t app_driver_light_set_temperature(led_driver_handle_t handle, esp_matter_attr_val_t *val)
static esp_err_t app_driver_light_set_temperature(led_indicator_handle_t handle, esp_matter_attr_val_t *val)
{
uint32_t value = REMAP_TO_RANGE_INVERSE(val->val.u16, STANDARD_TEMPERATURE_FACTOR);
return led_driver_set_temperature(handle, value);
#if BSP_LED_NUM > 0
return led_indicator_set_color_temperature(handle, value);
#else
ESP_LOGI(TAG, "LED set temperature: %ld", value);
return ESP_OK;
#endif
}

static void app_driver_button_toggle_cb(void *arg, void *data)
Expand All @@ -75,7 +109,7 @@ esp_err_t app_driver_attribute_update(app_driver_handle_t driver_handle, uint16_
{
esp_err_t err = ESP_OK;
if (endpoint_id == light_endpoint_id) {
led_driver_handle_t handle = (led_driver_handle_t)driver_handle;
led_indicator_handle_t handle = (led_indicator_handle_t)driver_handle;
if (cluster_id == OnOff::Id) {
if (attribute_id == OnOff::Attributes::OnOff::Id) {
err = app_driver_light_set_power(handle, val);
Expand All @@ -101,7 +135,7 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)
{
esp_err_t err = ESP_OK;
void *priv_data = endpoint::get_priv_data(endpoint_id);
led_driver_handle_t handle = (led_driver_handle_t)priv_data;
led_indicator_handle_t handle = (led_indicator_handle_t)priv_data;
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
Expand Down Expand Up @@ -147,17 +181,24 @@ esp_err_t app_driver_light_set_defaults(uint16_t endpoint_id)

app_driver_handle_t app_driver_light_init()
{
#if BSP_LED_NUM > 0
/* Initialize led */
led_driver_config_t config = led_driver_get_config();
led_driver_handle_t handle = led_driver_init(&config);
return (app_driver_handle_t)handle;
led_indicator_handle_t leds[BSP_LED_NUM];
ESP_ERROR_CHECK(bsp_led_indicator_create(leds, NULL, BSP_LED_NUM));
led_indicator_set_hsv(leds[0], SET_HSV(DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS));

return (app_driver_handle_t)leds[0];
#else
return NULL;
#endif
}

app_driver_handle_t app_driver_button_init()
{
/* Initialize button */
button_config_t config = button_driver_get_config();
button_handle_t handle = iot_button_create(&config);
iot_button_register_cb(handle, BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL);
return (app_driver_handle_t)handle;
button_handle_t btns[BSP_BUTTON_NUM];
ESP_ERROR_CHECK(bsp_iot_button_create(btns, NULL, BSP_BUTTON_NUM));
ESP_ERROR_CHECK(iot_button_register_cb(btns[0], BUTTON_PRESS_DOWN, app_driver_button_toggle_cb, NULL));

return (app_driver_handle_t)btns[0];
}
4 changes: 2 additions & 2 deletions examples/light/main/app_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#endif

/** Standard max values (used for remapping attributes) */
#define STANDARD_BRIGHTNESS 100
#define STANDARD_BRIGHTNESS 255
#define STANDARD_HUE 360
#define STANDARD_SATURATION 100
#define STANDARD_SATURATION 255
#define STANDARD_TEMPERATURE_FACTOR 1000000

/** Matter max values (used for remapping attributes) */
Expand Down
2 changes: 2 additions & 0 deletions examples/light/main/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ dependencies:
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
esp_bsp_generic:
version: "^1.1.0"
9 changes: 9 additions & 0 deletions examples/light/sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ CONFIG_MBEDTLS_HKDF_C=y
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6

# ESP32-DevKitC Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
# LEDs
CONFIG_BSP_LEDS_NUM=0
14 changes: 14 additions & 0 deletions examples/light/sdkconfig.defaults.esp32c2
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,17 @@ CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=4
CONFIG_CU_RELINKER_ENABLE=y
CONFIG_CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES=y
CONFIG_CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH="../common/relinker/esp32c2"

# ESP32-C2-DevKitM-1 Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
# LEDs
CONFIG_BSP_LEDS_NUM=1
CONFIG_BSP_LED_TYPE_RGB_CLASSIC=y
CONFIG_BSP_LED_RGB_RED_GPIO=0
CONFIG_BSP_LED_RGB_GREEN_GPIO=1
CONFIG_BSP_LED_RGB_BLUE_GPIO=8

12 changes: 12 additions & 0 deletions examples/light/sdkconfig.defaults.esp32c6
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000
# Enable chip shell
CONFIG_ENABLE_CHIP_SHELL=y

# ESP32-C6-DevKitM-1 Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
# LEDs
CONFIG_BSP_LEDS_NUM=1
CONFIG_BSP_LED_TYPE_RGB=y
CONFIG_BSP_LED_RGB_GPIO=8
CONFIG_BSP_LED_RGB_BACKEND_RMT=y

12 changes: 12 additions & 0 deletions examples/light/sdkconfig.defaults.esp32h2
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@ CONFIG_ENABLE_CHIP_SHELL=y

# Enable DS Peripheral
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=y

# ESP32-H2-DevKitM-1 Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
# LEDs
CONFIG_BSP_LEDS_NUM=1
CONFIG_BSP_LED_TYPE_RGB=y
CONFIG_BSP_LED_RGB_GPIO=8
CONFIG_BSP_LED_RGB_BACKEND_RMT=y
12 changes: 12 additions & 0 deletions examples/light/sdkconfig.defaults.esp32s2
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000

# Disable BLE
CONFIG_ENABLE_CHIPOBLE=n

# ESP32-S2-DevKitM-1 Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
# LEDs
CONFIG_BSP_LEDS_NUM=1
CONFIG_BSP_LED_TYPE_RGB=y
CONFIG_BSP_LED_RGB_GPIO=18
CONFIG_BSP_LED_RGB_BACKEND_RMT=y
53 changes: 53 additions & 0 deletions examples/light/sdkconfig.defaults.esp32s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#enable BT
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y

#disable BT connection reattempt
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n

#enable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=y

# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0xC000

# Enable chip shell
CONFIG_ENABLE_CHIP_SHELL=y

#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y

# Button
CONFIG_BUTTON_PERIOD_TIME_MS=20
CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000

# disable softap by default
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n

# Disable DS Peripheral
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n

# Use compact attribute storage mode
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y

# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y

# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6

# ESP32-S3-DevKitC-1 Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
# LEDs
CONFIG_BSP_LEDS_NUM=1
CONFIG_BSP_LED_TYPE_RGB=y
CONFIG_BSP_LED_RGB_GPIO=48
CONFIG_BSP_LED_RGB_BACKEND_RMT=y

0 comments on commit 886aa35

Please sign in to comment.