From f09aad74bbf6e1b9430ca9e038629177a982c69f Mon Sep 17 00:00:00 2001 From: Chirag Atal Date: Wed, 14 Sep 2022 12:24:49 +0530 Subject: [PATCH] es32c2: Support for esp32c2 This includes some memory optimisations. Also corresponding changes required for idf 5.0. --- .../button_driver/button/CMakeLists.txt | 4 ++ .../button_driver/button/include/button_adc.h | 9 +++- device_hal/device/esp32c2_devkit_m/device.c | 43 +++++++++++++++++++ .../esp32c2_devkit_m/esp_matter_device.cmake | 11 +++++ device_hal/led_driver/hollow_led/led_driver.c | 2 +- 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 device_hal/device/esp32c2_devkit_m/device.c create mode 100644 device_hal/device/esp32c2_devkit_m/esp_matter_device.cmake diff --git a/device_hal/button_driver/button/CMakeLists.txt b/device_hal/button_driver/button/CMakeLists.txt index a856f57ff..1c3aee617 100644 --- a/device_hal/button_driver/button/CMakeLists.txt +++ b/device_hal/button_driver/button/CMakeLists.txt @@ -3,6 +3,10 @@ include($ENV{ESP_MATTER_DEVICE_PATH}/esp_matter_device.cmake) set(src_dirs ) set(requires driver) +if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") + list(APPEND requires esp_adc) +endif() + if ("${button_type}" STREQUAL "hollow_button") list(APPEND src_dirs hollow_button) endif() diff --git a/device_hal/button_driver/button/include/button_adc.h b/device_hal/button_driver/button/include/button_adc.h index f1b004106..6e5be6ea4 100644 --- a/device_hal/button_driver/button/include/button_adc.h +++ b/device_hal/button_driver/button/include/button_adc.h @@ -15,7 +15,12 @@ #define _IOT_BUTTON_ADC_H_ #include "driver/gpio.h" +#include +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) +#include "esp_adc/adc_continuous.h" +#else #include "driver/adc.h" +#endif #ifdef __cplusplus extern "C" { @@ -30,7 +35,7 @@ extern "C" { * */ typedef struct { - adc1_channel_t adc_channel; /**< Channel of ADC */ + adc_channel_t adc_channel; /**< Channel of ADC */ uint8_t button_index; /**< button index on the channel */ uint16_t min; /**< min voltage in mv corresponding to the button */ uint16_t max; /**< max voltage in mv corresponding to the button */ @@ -59,7 +64,7 @@ esp_err_t button_adc_init(const button_adc_config_t *config); * - ESP_OK on success * - ESP_ERR_INVALID_ARG Arguments is invalid. */ -esp_err_t button_adc_deinit(adc1_channel_t channel, int button_index); +esp_err_t button_adc_deinit(adc_channel_t channel, int button_index); /** * @brief Get the adc button level diff --git a/device_hal/device/esp32c2_devkit_m/device.c b/device_hal/device/esp32c2_devkit_m/device.c new file mode 100644 index 000000000..fa8e7d1b3 --- /dev/null +++ b/device_hal/device/esp32c2_devkit_m/device.c @@ -0,0 +1,43 @@ +// Copyright 2021 Espressif Systems (Shanghai) CO LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License + +#include +#include +#include + +#define LED_GPIO_PIN GPIO_NUM_8 +#define LED_CHANNEL 0 /* RMT_CHANNEL_0 */ +#define BUTTON_GPIO_PIN GPIO_NUM_9 + +static const char *TAG = "device"; + +led_driver_config_t led_driver_get_config() +{ + led_driver_config_t config = { + .gpio = LED_GPIO_PIN, + .channel = LED_CHANNEL, + }; + return config; +} + +button_config_t button_driver_get_config() +{ + button_config_t config = { + .type = BUTTON_TYPE_GPIO, + .gpio_button_config = { + .gpio_num = BUTTON_GPIO_PIN, + .active_level = 0, + } + }; + return config; +} diff --git a/device_hal/device/esp32c2_devkit_m/esp_matter_device.cmake b/device_hal/device/esp32c2_devkit_m/esp_matter_device.cmake new file mode 100644 index 000000000..5348059d3 --- /dev/null +++ b/device_hal/device/esp32c2_devkit_m/esp_matter_device.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.5) +if (NOT ("${IDF_TARGET}" STREQUAL "esp32c2" )) + message(FATAL_ERROR "please set esp32c2 as the IDF_TARGET using 'idf.py set-target esp32c2'") +endif() + +SET(device_type esp32c2_devkit_m) +SET(led_type gpio) +SET(button_type hollow_button) + +SET(extra_components_dirs_append "$ENV{ESP_MATTER_DEVICE_PATH}/../../led_driver" + "$ENV{ESP_MATTER_DEVICE_PATH}/../../button_driver/button") diff --git a/device_hal/led_driver/hollow_led/led_driver.c b/device_hal/led_driver/hollow_led/led_driver.c index ecca5f466..1bf9921db 100644 --- a/device_hal/led_driver/hollow_led/led_driver.c +++ b/device_hal/led_driver/hollow_led/led_driver.c @@ -59,7 +59,7 @@ esp_err_t led_driver_set_saturation(led_driver_handle_t handle, uint8_t saturati esp_err_t led_driver_set_temperature(led_driver_handle_t handle, uint32_t temperature) { - ESP_LOGI(TAG, "Setting temperature to: %d", temperature); + ESP_LOGI(TAG, "Setting temperature to: %lu", temperature); /* Set the color temp here*/ return ESP_OK;