Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/esp*: add Kconfig #13135

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cpu/esp32/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1049,10 +1049,10 @@ The following parameters are defined for ESP-NOW nodes. These parameters can be

Parameter | Default | Description
:---------|:--------|:-----------
ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type ```uint8_t[16]``` and has to be exactly 16 bytes long.
#CONFIG_ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
#CONFIG_ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
#CONFIG_ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
#CONFIG_ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type ```uint8_t[16]``` and has to be exactly 16 bytes long.

</center>

Expand Down
8 changes: 4 additions & 4 deletions cpu/esp8266/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,10 @@ be overridden by [application-specific board configurations](#esp8266_applicatio

Parameter | Default | Description
:---------|:--------|:-----------
#ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
#ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
#ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
#ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type `uint8_t[16]` and has to be exactly 16 bytes long.
#CONFIG_ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
#CONFIG_ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
#CONFIG_ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
#CONFIG_ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type `uint8_t[16]` and has to be exactly 16 bytes long.

</center>

Expand Down
41 changes: 41 additions & 0 deletions cpu/esp_common/esp-now/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2020 Gunar Schorcht
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig KCONFIG_MODULE_ESP_NOW
bool "Configure ESP-NOW netdev"
depends on MODULE_ESP_NOW
help
Configure ESP-NOW netdev when module esp_now is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only shows up when esp_now module is used, so there is no need to clarify that on the help string.


if KCONFIG_MODULE_ESP_NOW

config ESP_NOW_CHANNEL
int "WiFi channel"
default 6
help
The WiFi channel that is used as by all ESP-NOW nodes.

config ESP_NOW_SCAN_PERIOD
int "Scan period in microseconds"
default 10000000
help
Period in microseconds at which an ESP-NOW node scans for other
ESP-NOW nodes in its range.

config ESP_NOW_SOFT_AP_PASS
string "SoftAP interface passphrase"
default "ThisistheRIOTporttoESP"
help
Passphrase used for the SoftAP interface of all ESP-NOW nodes.

ESP_NOW uses the WiFi interface in Station and SoftAP mode
simultaneously to build a peer-to-peer network. A passphrase is
required for the SoftAP mode. This passphrase is used by all ESP-NOW
nodes to establish the connection between them in the peer-to-peer
network.

endif # KCONFIG_MODULE_ESP_NOW
8 changes: 4 additions & 4 deletions cpu/esp_common/esp-now/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ The following parameters are defined for ESP-NOW nodes.

Parameter | Default | Description
:---------|:--------|:-----------
ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type ```uint8_t[16]``` and has to be exactly 16 bytes long.
#CONFIG_ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
#CONFIG_ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
#CONFIG_ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
#CONFIG_ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type ```uint8_t[16]``` and has to be exactly 16 bytes long.

</center>

Expand Down
4 changes: 2 additions & 2 deletions cpu/esp_common/esp-now/esp_now_gnrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ gnrc_netif_t *gnrc_netif_esp_now_create(char *stack, int stacksize, char priorit
}

/* device thread stack */
static char _esp_now_stack[ESP_NOW_STACKSIZE];
static char _esp_now_stack[CONFIG_ESP_NOW_STACKSIZE];

void auto_init_esp_now(void)
{
Expand All @@ -213,7 +213,7 @@ void auto_init_esp_now(void)
LOG_ERROR("[auto_init_netif] error initializing esp_now\n");
} else {
gnrc_netif_esp_now_create(_esp_now_stack, sizeof(_esp_now_stack),
ESP_NOW_PRIO,
CONFIG_ESP_NOW_PRIO,
"esp-now",
&esp_now_dev->netdev);
}
Expand Down
2 changes: 1 addition & 1 deletion cpu/esp_common/esp-now/esp_now_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static uint32_t aps_size = 0;
static const wifi_scan_config_t scan_cfg = {
.ssid = NULL,
.bssid = NULL,
.channel = ESP_NOW_CHANNEL,
.channel = CONFIG_ESP_NOW_CHANNEL,
.show_hidden = true,
.scan_type = WIFI_SCAN_TYPE_ACTIVE,
.scan_time.active.min = 0,
Expand Down
90 changes: 74 additions & 16 deletions cpu/esp_common/esp-now/esp_now_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,64 @@

#if defined(MODULE_ESP_NOW) || defined(DOXYGEN)

/**
* @name Legacy definitions of default configuration parameters
* @{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the @deprecated note and a deprecation release (2020.10?)

*/

/**
* @brief Legacy definition for compatibility reasons.
* #ESP_NOW_STACKSIZE is deprecated, please use #CONFIG_ESP_NOW_STACKSIZE
* instead.
*/
#ifndef ESP_NOW_STACKSIZE
#define ESP_NOW_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#endif

/**
* @brief Legacy definition for compatibility reasons.
* #ESP_NOW_PRIO is deprecated, please use #CONFIG_ESP_NOW_PRIO instead.
*/
#ifndef ESP_NOW_PRIO
#define ESP_NOW_PRIO (GNRC_NETIF_PRIO)
#endif

/**
* @brief Legacy definition for compatibility reasons.
* #ESP_NOW_SCAN_PERIOD is deprecated, please use #CONFIG_ESP_NOW_SCAN_PERIOD
* instead.
*/
#ifndef ESP_NOW_SCAN_PERIOD
#define ESP_NOW_SCAN_PERIOD (10000000UL)
#endif

/**
* @brief Legacy definition for compatibility reasons.
* #ESP_NOW_SOFT_AP_PASS is deprecated, please use #CONFIG_ESP_NOW_SOFT_AP_PASS
* instead.
*/
#ifndef ESP_NOW_SOFT_AP_PASS
#define ESP_NOW_SOFT_AP_PASS "ThisistheRIOTporttoESP"
#endif

/**
* @brief Legacy definition for compatibility reasons.
* #ESP_NOW_CHANNEL is deprecated, please use #CONFIG_ESP_NOW_CHANNEL instead.
*/
#ifndef ESP_NOW_CHANNEL
#define ESP_NOW_CHANNEL (6)
#endif

/**
* @brief Legacy definition for compatibility reasons.
* #ESP_NOW_KEY is deprecated, please use #CONFIG_ESP_NOW_KEY instead.
*/
#ifndef ESP_NOW_KEY
#define ESP_NOW_KEY (NULL)
#endif

/** @} */

/**
* @name Set default configuration parameters for the ESP-NOW netdev driver
* @{
Expand All @@ -30,42 +88,42 @@
* @brief The size of the stack used for the ESP-NOW netdev driver thread.
* @ingroup cpu_esp_common_conf
*/
#ifndef ESP_NOW_STACKSIZE
#define ESP_NOW_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#ifndef CONFIG_ESP_NOW_STACKSIZE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This macro is not generated by Kconfig, I think it's better that we try to keep the CONFIG_ namespace for those

Copy link
Contributor Author

@gschorcht gschorcht Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to rename it for two reasons:

  1. I wished the stack size would be configurable, but I couldn't find an usable approach til now. The option has to be an int which doesn't allow a default like THREAD_STACKSIZE_DEFAULT. Maybe, I will add a combination of a bool option for using the default and an int option for specifying a different value.

  2. I wanted to avoid naming inconsistencies from the users point of view in documentations where you have tables like

    Configuration Parameter Description
    CONFIG_ESP_WIFI_SSID SSID of the AP to be used.
    CONFIG_ESP_WIFI_PASS Passphrase used for the AP as clear text
    CONFIG_ESP_WIFI_STACKSIZE Stack size used for the WiFi netdev driver

    I wanted to avoid tables like the following:

    Configuration Parameter Description
    CONFIG_ESP_WIFI_SSID SSID of the AP to be used.
    CONFIG_ESP_WIFI_PASS Passphrase used for the AP as clear text
    ESP_WIFI_STACKSIZE Stack size used for the WiFi netdev driver

Therefore, I decided to name everything that is configurable by user also at command line in same way.

#define CONFIG_ESP_NOW_STACKSIZE ESP_NOW_STACKSIZE
#endif

/**
* @brief The priority of the ESP-NOW netdev driver thread. Should not be
* changed.
* @ingroup cpu_esp_common_conf
*/
#ifndef ESP_NOW_PRIO
#define ESP_NOW_PRIO (GNRC_NETIF_PRIO)
#ifndef CONFIG_ESP_NOW_PRIO
#define CONFIG_ESP_NOW_PRIO ESP_NOW_PRIO
#endif

/**
* @brief Period in microseconds at which an ESP-NOW node scans for other
* ESP-NOW nodes in its range.
* @ingroup cpu_esp_common_conf
*/
#ifndef ESP_NOW_SCAN_PERIOD
#define ESP_NOW_SCAN_PERIOD (10000000UL)
#ifndef CONFIG_ESP_NOW_SCAN_PERIOD
#define CONFIG_ESP_NOW_SCAN_PERIOD ESP_NOW_SCAN_PERIOD
#endif

/**
* @brief Passphrase used for the SoftAP interface of for all ESP-NOW nodes.
* @ingroup cpu_esp_common_conf
*/
#ifndef ESP_NOW_SOFT_AP_PASS
#define ESP_NOW_SOFT_AP_PASS "ThisistheRIOTporttoESP"
#ifndef CONFIG_ESP_NOW_SOFT_AP_PASS
#define CONFIG_ESP_NOW_SOFT_AP_PASS ESP_NOW_SOFT_AP_PASS
#endif

/**
* @brief Channel used as broadcast medium by all ESP-NOW nodes together
* @ingroup cpu_esp_common_conf
*/
#ifndef ESP_NOW_CHANNEL
#define ESP_NOW_CHANNEL (6)
#ifndef CONFIG_ESP_NOW_CHANNEL
#define CONFIG_ESP_NOW_CHANNEL ESP_NOW_CHANNEL
#endif

/**
Expand All @@ -81,8 +139,8 @@
* communicate with each other, while in unencrypted mode, up to 20 nodes can
* communicate.
*/
#ifndef ESP_NOW_KEY
#define ESP_NOW_KEY (NULL)
#ifndef CONFIG_ESP_NOW_KEY
#define CONFIG_ESP_NOW_KEY ESP_NOW_KEY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration of the key with Kconfig is a problem. The option would have to be either 0 or a 64 character array. I have no idea how to realize it with Kconfig. I renamed it to CONFIG_ just for naming consistency.

#endif

/** @} */
Expand All @@ -91,10 +149,10 @@
* @brief Initializer for default configuration parameters.
*/
#ifndef ESP_NOW_PARAMS
#define ESP_NOW_PARAMS { .key = ESP_NOW_KEY, \
.scan_period = ESP_NOW_SCAN_PERIOD, \
.softap_pass = ESP_NOW_SOFT_AP_PASS, \
.channel = ESP_NOW_CHANNEL \
#define ESP_NOW_PARAMS { .key = CONFIG_ESP_NOW_KEY, \
.scan_period = CONFIG_ESP_NOW_SCAN_PERIOD, \
.softap_pass = CONFIG_ESP_NOW_SOFT_AP_PASS, \
.channel = CONFIG_ESP_NOW_CHANNEL \
}
#endif

Expand Down