Skip to content

Commit 4ddfa85

Browse files
Add apps,tools and patches for esp32c3
Signed-off-by: hong.ye <52810083+hongye-samsung@users.noreply.github.com>
1 parent 42d32b4 commit 4ddfa85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+6764
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Basically, this release builds on the environments of chipset vendor's SDKs.
7575
ex) python setup.py esp8266
7676
ex) python setup.py esp32
7777
ex) python setup.py esp32s2
78+
ex) python setup.py esp32c2
7879
```
7980

8081
2. Check the build configuration of a sample device application. If you want to use specific build options, you can directly modify the build configuration file(e.g. sdkconfig, sdkconfig.h) at the root directory of a sample device application. On the Espressif chipset, you can additionally use the `menuconfig` option to configure them.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
7+
project(light_example)
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := light_example
7+
8+
EXTRA_COMPONENT_DIRS := ${IDF_PATH}/../../iot-core
9+
10+
include $(IDF_PATH)/make/project.mk
11+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SmartThings SDK for Direct Connected Devices for C - Light Example
2+
3+
## Introduction
4+
5+
SmartThings direct-connected device is Wi-Fi enabled device that uses the SmartThings cloud as its primary cloud infrastructure. And this device will use the MQTT protocol for communication.
6+
7+
## Getting started
8+
9+
For information on detailed workflow, please refer to the [Getting Started](../../../doc/getting_started.md)
10+
11+
## Components and Capabilities
12+
13+
SmartThings Device is defined using components and capabilities. Capabilities define the features of the device, and capabilities are grouped into components.
14+
Components and Capabilities are contained in device profile. You can create a device profile in Developer Workspace and associate it with an integration.
15+
16+
This example assumes the following components and capabilities are used. :
17+
18+
`main` component
19+
- `healthCheck` capability
20+
- `switch` capability
21+
- `switchLevel` capability
22+
- `colorTemperature` capability
23+
- `activityLightingMode` capability
24+
25+
`monitor` component
26+
- `dustSensor` capability
27+
28+
(`healthCheck` capability is automatically added by Developer Workspace. It doesn't need handler at device side)
29+
30+
## SmartThings SDK for Direct Connected Devices - Config
31+
If you want to use specific SmartThings Device SDK build options, you can directly modify the build configuration file. For this example, SmartThings Device SDK config is saved in 'sdkconfig' file. If you want to change this, please execute the following :
32+
```sh
33+
# python build.py {app_path} {option}
34+
$ cd ~/st-device-sdk-c-ref/
35+
$ python build.py apps/esp32c3/light_example menuconfig
36+
```
37+
38+
## Test device schematics
39+
This example uses ESP32C3 GPIO like below.
40+
Please refer below picture for __ESP32C3-DevKitC-02__.
41+
> Note: If your device's schematics doesn't match with belows.
42+
> Please modify GPIO defines for your device at [device_control.h](main/device_control.h)
43+
> ```c
44+
> #define GPIO_INPUT_BUTTON 9
45+
>
46+
> #define GPIO_OUTPUT_COLORLED_R 3
47+
> #define GPIO_OUTPUT_COLORLED_G 2
48+
> #define GPIO_OUTPUT_COLORLED_B 1
49+
> #define GPIO_OUTPUT_COLORLED_0 0
50+
> ```
51+
52+
### ESP32-C3-DevKitC-02
53+
| ESP32-C3-DevKitC-02 |
54+
|-----------------------------------------------------------------------------|
55+
|![ESP32C3_DEVKITC_02](../../../doc/res/Light_Example_ESP32C3_DEVKITC_02.png) |
56+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Log output
3+
#
4+
CONFIG_LOG_DEFAULT_LEVEL_NONE=
5+
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
6+
CONFIG_LOG_DEFAULT_LEVEL_WARN=
7+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
8+
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
9+
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
10+
CONFIG_LOG_DEFAULT_LEVEL=3
11+
CONFIG_LOG_COLORS=y
12+
CONFIG_LOG_SET_LEVEL=
13+
14+
CONFIG_STDK_DEBUG_MEMORY_CHECK=y
15+
16+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_ERROR=y
17+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_WARN=y
18+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_INFO=y
19+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_DEBUG=
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
idf_component_register(SRCS "main.c"
2+
"device_control.c"
3+
"iot_cli_cmd.c"
4+
"iot_uart_cli.c"
5+
"caps_activityLightingMode.c"
6+
"caps_colorTemperature.c"
7+
"caps_dustSensor.c"
8+
"caps_switch.c"
9+
"caps_switchLevel.c"
10+
EMBED_FILES "device_info.json"
11+
"onboarding_config.json"
12+
)
13+
14+
set(STDK_IOT_CORE_USE_DEFINED_CONFIG "y")
15+
16+
set(STDK_LINK_LIBRARY
17+
__idf_libsodium
18+
__idf_json
19+
)
20+
21+
set(STDK_INCLUDE_PATH
22+
"$ENV{IDF_PATH}/components/freertos/include/freertos"
23+
"$ENV{IDF_PATH}/components/nvs_flash/include"
24+
"$ENV{IDF_PATH}/components/spi_flash/include"
25+
"$ENV{IDF_PATH}/components/bootloader_support/include"
26+
)
27+
28+
add_subdirectory($ENV{STDK_CORE_PATH} iotcore)
29+
target_link_libraries(${COMPONENT_LIB} PUBLIC iotcore)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
menu "Example Configuration"
2+
3+
config WIFI_SSID
4+
string "WiFi SSID"
5+
default "myssid"
6+
help
7+
SSID (network name) for the example to connect to.
8+
9+
config WIFI_PASSWORD
10+
string "WiFi Password"
11+
default "mypassword"
12+
help
13+
WiFi password (WPA or WPA2) for the example to use.
14+
Can be left blank if the network has no security set.
15+
16+
config MQTT_BROKER
17+
string "MQTT broker"
18+
default "mosquitto.org"
19+
help
20+
MQTT broker which you want to login, either IP address or domain name is OK.
21+
22+
config MQTT_PORT
23+
int "Default MQTT port"
24+
default 1883
25+
help
26+
MQTT port.
27+
28+
config MQTT_SUB_TOPIC
29+
string "MQTT subscribe topic"
30+
default "/espressif/sub"
31+
help
32+
MQTT subscribe topic to MQTT broker.
33+
34+
choice MQTT_SUB_QOS
35+
prompt "MQTT Subscribe QoS"
36+
default SUB_QOS1
37+
help
38+
MQTT subcribe QoS level.
39+
40+
config SUB_QOS0
41+
bool "QOS0"
42+
config SUB_QOS1
43+
bool "QOS1"
44+
config SUB_QOS2
45+
bool "QOS2"
46+
endchoice
47+
48+
config DEFAULT_MQTT_SUB_QOS
49+
int
50+
default 0 if SUB_QOS0
51+
default 1 if SUB_QOS1
52+
default 2 if SUB_QOS2
53+
54+
config MQTT_PUB_TOPIC
55+
string "MQTT publish topic"
56+
default "/espressif/pub"
57+
help
58+
MQTT publish topic to MQTT broker.
59+
60+
choice MQTT_PUB_QOS
61+
prompt "MQTT publish QoS"
62+
default PUB_QOS1
63+
help
64+
MQTT publish QoS level.
65+
66+
config PUB_QOS0
67+
bool "QOS0"
68+
config PUB_QOS1
69+
bool "QOS1"
70+
config PUB_QOS2
71+
bool "QOS2"
72+
endchoice
73+
74+
config DEFAULT_MQTT_PUB_QOS
75+
int
76+
default 0 if PUB_QOS0
77+
default 1 if PUB_QOS1
78+
default 2 if PUB_QOS2
79+
80+
config MQTT_PUBLISH_INTERVAL
81+
int "MQTT publish interval(ms)"
82+
default 0
83+
help
84+
Default MQTT publish message interval.
85+
86+
config MQTT_PAYLOAD_BUFFER
87+
int "MQTT payload size(Bytes)"
88+
default 1460
89+
help
90+
1460~2048 is recommended.
91+
MQTT payload size.
92+
93+
endmenu
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* ***************************************************************************
2+
*
3+
* Copyright 2021 Samsung Electronics All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
* either express or implied. See the License for the specific
15+
* language governing permissions and limitations under the License.
16+
*
17+
****************************************************************************/
18+
19+
#include <string.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
23+
#include "st_dev.h"
24+
#include "caps_activityLightingMode.h"
25+
26+
static int caps_activityLightingMode_attr_lightingMode_str2idx(const char *value)
27+
{
28+
int index;
29+
30+
for (index = 0; index < CAP_ENUM_ACTIVITYLIGHTINGMODE_LIGHTINGMODE_VALUE_MAX; index++) {
31+
if (!strcmp(value, caps_helper_activityLightingMode.attr_lightingMode.values[index])) {
32+
return index;
33+
}
34+
}
35+
return -1;
36+
}
37+
38+
static const char *caps_activityLightingMode_get_lightingMode_value(caps_activityLightingMode_data_t *caps_data)
39+
{
40+
if (!caps_data) {
41+
printf("caps_data is NULL\n");
42+
return NULL;
43+
}
44+
return caps_data->lightingMode_value;
45+
}
46+
47+
static void caps_activityLightingMode_set_lightingMode_value(caps_activityLightingMode_data_t *caps_data, const char *value)
48+
{
49+
if (!caps_data) {
50+
printf("caps_data is NULL\n");
51+
return;
52+
}
53+
if (caps_data->lightingMode_value) {
54+
free(caps_data->lightingMode_value);
55+
}
56+
caps_data->lightingMode_value = strdup(value);
57+
}
58+
59+
static void caps_activityLightingMode_attr_lightingMode_send(caps_activityLightingMode_data_t *caps_data)
60+
{
61+
int sequence_no = -1;
62+
63+
if (!caps_data || !caps_data->handle) {
64+
printf("fail to get handle\n");
65+
return;
66+
}
67+
if (!caps_data->lightingMode_value) {
68+
printf("value is NULL\n");
69+
return;
70+
}
71+
72+
ST_CAP_SEND_ATTR_STRING(caps_data->handle,
73+
(char *)caps_helper_activityLightingMode.attr_lightingMode.name,
74+
caps_data->lightingMode_value,
75+
NULL,
76+
NULL,
77+
sequence_no);
78+
79+
if (sequence_no < 0)
80+
printf("fail to send lightingMode value\n");
81+
else
82+
printf("Sequence number return : %d\n", sequence_no);
83+
84+
}
85+
86+
87+
static void caps_activityLightingMode_cmd_setLightingMode_cb(IOT_CAP_HANDLE *handle, iot_cap_cmd_data_t *cmd_data, void *usr_data)
88+
{
89+
caps_activityLightingMode_data_t *caps_data = (caps_activityLightingMode_data_t *)usr_data;
90+
char *value;
91+
int index;
92+
93+
printf("called [%s] func with num_args:%u\n", __func__, cmd_data->num_args);
94+
95+
index = caps_activityLightingMode_attr_lightingMode_str2idx(cmd_data->cmd_data[0].string);
96+
if (index < 0) {
97+
printf("%s is not supported value for setLightingMode\n", cmd_data->cmd_data[0].string);
98+
return;
99+
}
100+
value = (char *)caps_helper_activityLightingMode.attr_lightingMode.values[index];
101+
102+
caps_activityLightingMode_set_lightingMode_value(caps_data, value);
103+
if (caps_data && caps_data->cmd_setLightingMode_usr_cb)
104+
caps_data->cmd_setLightingMode_usr_cb(caps_data);
105+
caps_activityLightingMode_attr_lightingMode_send(caps_data);
106+
}
107+
108+
static void caps_activityLightingMode_init_cb(IOT_CAP_HANDLE *handle, void *usr_data)
109+
{
110+
caps_activityLightingMode_data_t *caps_data = usr_data;
111+
if (caps_data && caps_data->init_usr_cb)
112+
caps_data->init_usr_cb(caps_data);
113+
caps_activityLightingMode_attr_lightingMode_send(caps_data);
114+
}
115+
116+
caps_activityLightingMode_data_t *caps_activityLightingMode_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data)
117+
{
118+
caps_activityLightingMode_data_t *caps_data = NULL;
119+
int err;
120+
121+
caps_data = malloc(sizeof(caps_activityLightingMode_data_t));
122+
if (!caps_data) {
123+
printf("fail to malloc for caps_activityLightingMode_data\n");
124+
return NULL;
125+
}
126+
127+
memset(caps_data, 0, sizeof(caps_activityLightingMode_data_t));
128+
129+
caps_data->init_usr_cb = init_usr_cb;
130+
caps_data->usr_data = usr_data;
131+
132+
caps_data->get_lightingMode_value = caps_activityLightingMode_get_lightingMode_value;
133+
caps_data->set_lightingMode_value = caps_activityLightingMode_set_lightingMode_value;
134+
caps_data->attr_lightingMode_str2idx = caps_activityLightingMode_attr_lightingMode_str2idx;
135+
caps_data->attr_lightingMode_send = caps_activityLightingMode_attr_lightingMode_send;
136+
if (ctx) {
137+
caps_data->handle = st_cap_handle_init(ctx, component, caps_helper_activityLightingMode.id, caps_activityLightingMode_init_cb, caps_data);
138+
}
139+
if (caps_data->handle) {
140+
err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_activityLightingMode.cmd_setLightingMode.name, caps_activityLightingMode_cmd_setLightingMode_cb, caps_data);
141+
if (err) {
142+
printf("fail to set cmd_cb for setLightingMode of activityLightingMode\n");
143+
}
144+
} else {
145+
printf("fail to init activityLightingMode handle\n");
146+
}
147+
148+
return caps_data;
149+
}

0 commit comments

Comments
 (0)