Initial commit.
Some checks failed
Sync remain PRs to Jira / Sync PRs to Jira (push) Has been cancelled
Some checks failed
Sync remain PRs to Jira / Sync PRs to Jira (push) Has been cancelled
This commit is contained in:
2
examples/gpio/main/CMakeLists.txt
Normal file
2
examples/gpio/main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS ./app_driver.c ./app_main.c
|
||||
INCLUDE_DIRS ".")
|
||||
29
examples/gpio/main/Kconfig.projbuild
Normal file
29
examples/gpio/main/Kconfig.projbuild
Normal file
@@ -0,0 +1,29 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_BOARD_BUTTON_GPIO
|
||||
int "Boot Button GPIO"
|
||||
default 9 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
|
||||
default 0
|
||||
help
|
||||
GPIO number on which the "Boot" button is connected. This is generally used
|
||||
by the application for custom operations like toggling states, resetting to defaults, etc.
|
||||
|
||||
config EXAMPLE_OUTPUT_GPIO_RED
|
||||
int "Red GPIO"
|
||||
default 2
|
||||
help
|
||||
Control digital RGB LEDs. Need to connect this GPIO to the red pin of the LED.
|
||||
|
||||
config EXAMPLE_OUTPUT_GPIO_GREEN
|
||||
int "Green GPIO"
|
||||
default 4
|
||||
help
|
||||
Control digital RGB LEDs. Need to connect this GPIO to the green pin of the LED.
|
||||
|
||||
config EXAMPLE_OUTPUT_GPIO_BLUE
|
||||
int "Blue GPIO"
|
||||
default 5
|
||||
help
|
||||
Control digital RGB LEDs. Need to connect this GPIO to the blue pin of the LED.
|
||||
|
||||
endmenu
|
||||
61
examples/gpio/main/app_driver.c
Normal file
61
examples/gpio/main/app_driver.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* Simple GPIO Demo
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <sdkconfig.h>
|
||||
#include <string.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#include <app_reset.h>
|
||||
#include "app_priv.h"
|
||||
|
||||
#define RMT_TX_CHANNEL RMT_CHANNEL_0
|
||||
/* This is the button that is used for toggling the power */
|
||||
#define BUTTON_GPIO CONFIG_EXAMPLE_BOARD_BUTTON_GPIO
|
||||
#define BUTTON_ACTIVE_LEVEL 0
|
||||
/* This is the GPIO on which the power will be set */
|
||||
|
||||
#define OUTPUT_GPIO_RED CONFIG_EXAMPLE_OUTPUT_GPIO_RED
|
||||
#define OUTPUT_GPIO_GREEN CONFIG_EXAMPLE_OUTPUT_GPIO_GREEN
|
||||
#define OUTPUT_GPIO_BLUE CONFIG_EXAMPLE_OUTPUT_GPIO_BLUE
|
||||
|
||||
#define WIFI_RESET_BUTTON_TIMEOUT 3
|
||||
#define FACTORY_RESET_BUTTON_TIMEOUT 10
|
||||
|
||||
esp_err_t app_driver_set_gpio(const char *name, bool state)
|
||||
{
|
||||
if (strcmp(name, "Red") == 0) {
|
||||
gpio_set_level(OUTPUT_GPIO_RED, state);
|
||||
} else if (strcmp(name, "Green") == 0) {
|
||||
gpio_set_level(OUTPUT_GPIO_GREEN, state);
|
||||
} else if (strcmp(name, "Blue") == 0) {
|
||||
gpio_set_level(OUTPUT_GPIO_BLUE, state);
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void app_driver_init()
|
||||
{
|
||||
app_reset_button_register(app_reset_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL),
|
||||
WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
|
||||
/* Configure power */
|
||||
gpio_config_t io_conf = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = 1,
|
||||
};
|
||||
uint64_t pin_mask = (((uint64_t)1 << OUTPUT_GPIO_RED ) | ((uint64_t)1 << OUTPUT_GPIO_GREEN ) | ((uint64_t)1 << OUTPUT_GPIO_BLUE ));
|
||||
io_conf.pin_bit_mask = pin_mask;
|
||||
/* Configure the GPIO */
|
||||
gpio_config(&io_conf);
|
||||
gpio_set_level(OUTPUT_GPIO_RED, false);
|
||||
gpio_set_level(OUTPUT_GPIO_GREEN, false);
|
||||
gpio_set_level(OUTPUT_GPIO_BLUE, false);
|
||||
}
|
||||
109
examples/gpio/main/app_main.c
Normal file
109
examples/gpio/main/app_main.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/* GPIO Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include <nvs_flash.h>
|
||||
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
|
||||
#include <app_network.h>
|
||||
#include <app_insights.h>
|
||||
|
||||
#include "app_priv.h"
|
||||
|
||||
static const char *TAG = "app_main";
|
||||
|
||||
/* Callback to handle commands received from the RainMaker cloud */
|
||||
static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
|
||||
const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
ESP_LOGI(TAG, "Received write request via : %s", esp_rmaker_device_cb_src_to_str(ctx->src));
|
||||
}
|
||||
if (app_driver_set_gpio(esp_rmaker_param_get_name(param), val.val.b) == ESP_OK) {
|
||||
esp_rmaker_param_update(param, val);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
/* Initialize Application specific hardware drivers and
|
||||
* set initial state.
|
||||
*/
|
||||
app_driver_init();
|
||||
|
||||
/* Initialize NVS. */
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK( err );
|
||||
|
||||
/* Initialize Wi-Fi. Note that, this should be called before esp_rmaker_node_init()
|
||||
*/
|
||||
app_network_init();
|
||||
|
||||
/* Initialize the ESP RainMaker Agent.
|
||||
* Note that this should be called after app_network_init() but before app_network_start()
|
||||
* */
|
||||
esp_rmaker_config_t rainmaker_cfg = {
|
||||
.enable_time_sync = false,
|
||||
};
|
||||
esp_rmaker_node_t *node = esp_rmaker_node_init(&rainmaker_cfg, "ESP RainMaker Device", "GPIO-Device");
|
||||
if (!node) {
|
||||
ESP_LOGE(TAG, "Could not initialise node. Aborting!!!");
|
||||
vTaskDelay(5000/portTICK_PERIOD_MS);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Create a device and add the relevant parameters to it */
|
||||
esp_rmaker_device_t *gpio_device = esp_rmaker_device_create("GPIO-Device", NULL, NULL);
|
||||
esp_rmaker_device_add_cb(gpio_device, write_cb, NULL);
|
||||
|
||||
esp_rmaker_param_t *red_param = esp_rmaker_param_create("Red", NULL, esp_rmaker_bool(false), PROP_FLAG_READ | PROP_FLAG_WRITE);
|
||||
esp_rmaker_param_add_ui_type(red_param, ESP_RMAKER_UI_TOGGLE);
|
||||
esp_rmaker_device_add_param(gpio_device, red_param);
|
||||
|
||||
esp_rmaker_param_t *green_param = esp_rmaker_param_create("Green", NULL, esp_rmaker_bool(false), PROP_FLAG_READ | PROP_FLAG_WRITE);
|
||||
esp_rmaker_param_add_ui_type(green_param, ESP_RMAKER_UI_TOGGLE);
|
||||
esp_rmaker_device_add_param(gpio_device, green_param);
|
||||
|
||||
esp_rmaker_param_t *blue_param = esp_rmaker_param_create("Blue", NULL, esp_rmaker_bool(false), PROP_FLAG_READ | PROP_FLAG_WRITE);
|
||||
esp_rmaker_param_add_ui_type(blue_param, ESP_RMAKER_UI_TOGGLE);
|
||||
esp_rmaker_device_add_param(gpio_device, blue_param);
|
||||
|
||||
esp_rmaker_node_add_device(node, gpio_device);
|
||||
|
||||
/* Enable OTA */
|
||||
esp_rmaker_ota_enable_default();
|
||||
|
||||
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
|
||||
app_insights_enable();
|
||||
|
||||
/* Start the ESP RainMaker Agent */
|
||||
esp_rmaker_start();
|
||||
|
||||
/* Start the Wi-Fi.
|
||||
* If the node is provisioned, it will start connection attempts,
|
||||
* else, it will start Wi-Fi provisioning. The function will return
|
||||
* after a connection has been successfully established
|
||||
*/
|
||||
err = app_network_start(POP_TYPE_RANDOM);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Could not start Wifi. Aborting!!!");
|
||||
vTaskDelay(5000/portTICK_PERIOD_MS);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
14
examples/gpio/main/app_priv.h
Normal file
14
examples/gpio/main/app_priv.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
|
||||
void app_driver_init(void);
|
||||
esp_err_t app_driver_set_gpio(const char *name, bool state);
|
||||
4
examples/gpio/main/component.mk
Normal file
4
examples/gpio/main/component.mk
Normal file
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
8
examples/gpio/main/idf_component.yml
Normal file
8
examples/gpio/main/idf_component.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: ">=5.0.0"
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
||||
Reference in New Issue
Block a user