es32c2: Support for esp32c2

This includes some memory optimisations.
Also corresponding changes required for idf 5.0.
This commit is contained in:
Chirag Atal
2022-09-14 12:24:49 +05:30
committed by WanqQixiang
parent c44c2177a3
commit f09aad74bb
5 changed files with 66 additions and 3 deletions
@@ -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()
@@ -15,7 +15,12 @@
#define _IOT_BUTTON_ADC_H_
#include "driver/gpio.h"
#include <esp_idf_version.h>
#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
@@ -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 <esp_log.h>
#include <iot_button.h>
#include <led_driver.h>
#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;
}
@@ -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")
@@ -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;