Skip to content

Commit

Permalink
Make the original ESP_IDF_VERSION available, fix event loop legacy an…
Browse files Browse the repository at this point in the history
…d WiFi struct on V5.0+ (#27)
  • Loading branch information
adokitkat authored Aug 27, 2024
1 parent 71093f6 commit 1ae2fa8
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 19 deletions.
2 changes: 1 addition & 1 deletion nesper.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.7.3"
version = "0.7.4"
author = "Jaremy Creechley"
description = "Nim wrappers for ESP-IDF (ESP32)"
license = "Apache-2.0"
Expand Down
7 changes: 4 additions & 3 deletions src/nesper/build_utils/tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ task esp_compile, "Compile Nim project for esp-idf program":
echo "...cleaning esp-idf build cache"
rmDir(nopts.projdir / "build")

echo "ESP_IDF_VERSION: ", nopts.esp_idf_version
var esp_idf_version_formatted = nopts.esp_idf_version[0..2]
echo "ESP IDF VERSION: ", esp_idf_version_formatted
let
nimargs = @[
"c",
Expand All @@ -229,8 +230,8 @@ task esp_compile, "Compile Nim project for esp-idf program":
"--compileOnly",
"--nimcache:" & nopts.cachedir.quoteShell(),
"-d:NimAppMain",
"-d:ESP_IDF_V" & nopts.esp_idf_version.replace(".","_"),
"-d:ESP_IDF_VERSION=" & nopts.esp_idf_version,
"-d:ESP_IDF_V" & esp_idf_version_formatted.replace(".","_"),
"-d:ESP_IDF_VERSION=" & esp_idf_version_formatted,
].join(" ")
childargs = nopts.child_args.mapIt(it.quoteShell()).join(" ")
wifidefs = nopts.wifi_args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
set(requires lwip newlib nvs_flash app_update)

string(SUBSTRING "$${IDF_VER}" 1 3 IDF_VER_VAL_STR)
if("$${IDF_VER_VAL_STR}" VERSION_GREATER_EQUAL "5.0")
list(APPEND requires esp_netif)
endif()

idf_component_register(SRC_DIRS "$NIMBLE_NIMCACHE"
INCLUDE_DIRS ""
REQUIRES lwip newlib nvs_flash app_update)
REQUIRES $${requires})

# set(C_COMPILE_OPTIONS "$${C_COMPILE_OPTIONS} -Wno-error=unused-label")
# list(APPEND C_COMPILE_OPTIONS "-Wno-error=unused-label ")
Expand Down
34 changes: 28 additions & 6 deletions src/nesper/consts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,38 @@ import strutils
from os import getEnv
from macros import error, warning

template ESP_IDF_VERSION_VAL*(major, minor, patch: int): int = (major shl 16 or minor shl 8 or patch)

func getEspIdfVersion(): string =
var version = getEnv("ESP_IDF_VERSION", "0.0.0").toLower().replace("v","")
let dot_count = version.count(".")
if dot_count < 1:
version & ".0.0"
elif dot_count < 2:
version & ".0"
else:
version

const
ESP_IDF_VERSION* {.strdefine.} = getEnv("ESP_IDF_VERSION", "0.0").toLower().replace("v","")
ESP_IDF_MAJOR* {.intdefine.} = ESP_IDF_VERSION. split(".")[0].parseInt()
ESP_IDF_MINOR* {.intdefine.} = ESP_IDF_VERSION.split(".")[1].parseInt()
ESP_IDF_VER {.strdefine: "ESP_IDF_VERSION".} = getEspIdfVersion()
ESP_IDF_VER_SPLIT = ESP_IDF_VER.split(".")

ESP_IDF_MAJOR* {.intdefine.} = block:
when ESP_IDF_VER_SPLIT.len >= 1: (try: ESP_IDF_VER_SPLIT[0].parseInt() except ValueError: 0) else: 0
ESP_IDF_MINOR* {.intdefine.} = block:
when ESP_IDF_VER_SPLIT.len >= 2: (try: ESP_IDF_VER_SPLIT[1].parseInt() except ValueError: 0) else: 0
ESP_IDF_PATCH* {.intdefine.} = block:
when ESP_IDF_VER_SPLIT.len >= 3: (try: ESP_IDF_VER_SPLIT[2].parseInt() except ValueError: 0) else: 0

ESP_IDF_VERSION*: int = ESP_IDF_VERSION_VAL(ESP_IDF_MAJOR, ESP_IDF_MINOR, ESP_IDF_PATCH)

template ESP_IDF_VERSION_STR*: string = $ESP_IDF_MAJOR & "." & $ESP_IDF_MINOR & "." & $ESP_IDF_PATCH

static:
static:
if ESP_IDF_MAJOR notin [4, 5]:
error("Incorrect esp-idf major version: " & $ESP_IDF_MAJOR)
if ESP_IDF_VERSION == "0.0":
warning("ESP_IDF_VERSION: " & ESP_IDF_VERSION)
if ESP_IDF_VERSION == ESP_IDF_VERSION_VAL(0, 0, 0):
warning("ESP_IDF_VERSION: " & ESP_IDF_VERSION_STR)
error("Must set esp-idf version using `-d:ESP_IDF_VERSION=4.4` or using an environment variable `export ESP_IDF_VERSION=4.4`")


Expand Down
6 changes: 4 additions & 2 deletions src/nesper/esp/esp_event.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
## limitations under the License.

import ../consts
import esp_event_legacy

export esp_event_legacy
when ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0):
import esp_event_legacy

export esp_event_legacy


## / Configuration for creating event loops
Expand Down
3 changes: 2 additions & 1 deletion src/nesper/esp/mdns.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

import ../consts
import ../net_utils
import ../esp/esp_event_legacy

import ../esp/esp_event

import ../esp/net/esp_netif

Expand Down
2 changes: 0 additions & 2 deletions src/nesper/esp/net/esp_eth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export esp_eth_com
export esp_eth_mac
export esp_eth_phy

# import ../esp_event_legacy

## *
## @brief Handle of Ethernet driver
##
Expand Down
26 changes: 23 additions & 3 deletions src/nesper/esp/net/esp_wifi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

import ../../consts
import ../../general
import ../esp_event_legacy
import ../esp_event
import ../../net_utils
import esp_wifi_types

Expand Down Expand Up @@ -90,25 +90,45 @@ const

type
wifi_init_config_t* {.importc: "wifi_init_config_t", header: "esp_wifi.h".} = object
event_handler* {.importc: "event_handler".}: system_event_handler_t ## *< WiFi event handler
when ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0):
event_handler* {.importc: "event_handler".}: system_event_handler_t ## *< WiFi event handler

osi_funcs* {.importc: "osi_funcs".}: ptr wifi_osi_funcs_t ## *< WiFi OS functions
wpa_crypto_funcs* {.importc: "wpa_crypto_funcs".}: wpa_crypto_funcs_t ## *< WiFi station crypto functions when connect
static_rx_buf_num* {.importc: "static_rx_buf_num".}: cint ## *< WiFi static RX buffer number
dynamic_rx_buf_num* {.importc: "dynamic_rx_buf_num".}: cint ## *< WiFi dynamic RX buffer number
tx_buf_type* {.importc: "tx_buf_type".}: cint ## *< WiFi TX buffer type
static_tx_buf_num* {.importc: "static_tx_buf_num".}: cint ## *< WiFi static TX buffer number
dynamic_tx_buf_num* {.importc: "dynamic_tx_buf_num".}: cint ## *< WiFi dynamic TX buffer number

when ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0):
rx_mgmt_buf_type* {.importc: "rx_mgmt_buf_type".}: cint ## *< WiFi RX MGMT buffer type
rx_mgmt_buf_num* {.importc: "rx_mgmt_buf_num".}: cint ## *< WiFi RX MGMT buffer number
cache_tx_buf_num* {.importc: "cache_tx_buf_num".}: cint ## *< WiFi TX cache buffer number

csi_enable* {.importc: "csi_enable".}: cint ## *< WiFi channel state information enable flag
ampdu_rx_enable* {.importc: "ampdu_rx_enable".}: cint ## *< WiFi AMPDU RX feature enable flag
ampdu_tx_enable* {.importc: "ampdu_tx_enable".}: cint ## *< WiFi AMPDU TX feature enable flag
nvs_enable* {.importc: "nvs_enable".}: cint ## *< WiFi NVS flash enable flag
nano_enable* {.importc: "nano_enable".}: cint ## *< Nano option for printf/scan family enable flag
tx_ba_win* {.importc: "tx_ba_win".}: cint ## *< WiFi Block Ack TX window size

when ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0):
tx_ba_win* {.importc: "tx_ba_win".}: cint ## *< WiFi Block Ack TX window size

rx_ba_win* {.importc: "rx_ba_win".}: cint ## *< WiFi Block Ack RX window size
wifi_task_core_id* {.importc: "wifi_task_core_id".}: cint ## *< WiFi Task Core ID
beacon_max_len* {.importc: "beacon_max_len".}: cint ## *< WiFi softAP maximum length of the beacon
mgmt_sbuf_num* {.importc: "mgmt_sbuf_num".}: cint ## *< WiFi management short buffer number, the minimum value is 6, the maximum value is 32
feature_caps* {.importc: "feature_caps".}: uint64 ## *< Enables additional WiFi features and capabilities

when ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0):
sta_disconnected_pm* {.importc: "sta_disconnected_pm".}: bool ## *< WiFi Power Management for station at disconnected status
espnow_max_encrypt_num* {.importc: "espnow_max_encrypt_num".}: cint ## *< Maximum encrypt number of peers supported by espnow

when ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0):
tx_hetb_queue_num* {.importc: "tx_hetb_queue_num".}: cint ## *< WiFi TX HE TB QUEUE number for STA HE TB PPDU transmission */
dump_hesigb_enable* {.importc: "dump_hesigb_enable".}: bool ## *< enable dump sigb field */

magic* {.importc: "magic".}: cint ## *< WiFi init magic number, it should be the last field


Expand Down

0 comments on commit 1ae2fa8

Please sign in to comment.