├── LICENSE ├── Makefile ├── README.md ├── docker ├── Dockerfile ├── build_docker.sh └── run_shell.sh ├── esp-idf-examples ├── .gitignore ├── README.md ├── app_test │ ├── .gitignore │ ├── app_test.nimble │ └── clean.sh ├── nim.cfg ├── simple_rpc │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── build-all.sh │ ├── config.nims │ ├── main │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── main.nim │ │ ├── nim.cfg │ │ ├── ota_rpc_example.nim │ │ ├── server.nim │ │ ├── setup_eth.nim │ │ ├── setup_networking.nim │ │ └── setup_wifi.nim │ ├── rpc_cli_test.nim │ ├── sdkconfig │ ├── sdkconfig.old │ └── simple_rpc.nimble ├── simpleeth │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── build-all.sh │ ├── config.nims │ ├── main │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── apps.nim │ │ ├── nim.cfg │ │ ├── ota_rpc_example.nim │ │ ├── server.nim │ │ └── wifi_example_main.nim │ ├── rpc_cli_test.nim │ ├── sdkconfig │ └── sdkconfig.old ├── simplewifi-rpc │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── build-all.sh │ ├── config.nims │ ├── main │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── apps.nim │ │ ├── nim.cfg │ │ ├── ota_rpc_example.nim │ │ ├── server.nim │ │ └── wifi_example_main.nim │ ├── rpc_cli_test.nim │ ├── sdkconfig │ └── sdkconfig.old ├── simplewifi │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── config.nims │ ├── main │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── nim.cfg │ │ ├── server.nim │ │ └── wifi_example_main.nim │ ├── sdkconfig │ └── sdkconfig.old └── untested │ ├── i2c │ ├── .gitignore │ ├── i2c_self_test │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── README.md │ │ └── main │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig.projbuild │ │ │ ├── component.mk │ │ │ └── i2c_example_main.c │ └── i2c_tools │ │ ├── CMakeLists.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── example_test.py │ │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── cmd_i2ctools.c │ │ ├── cmd_i2ctools.h │ │ ├── component.mk │ │ └── i2ctools_example_main.c │ │ ├── partitions_example.csv │ │ └── sdkconfig.defaults │ ├── nvs_rw_value │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ └── main │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ └── nvs_value_example_main.c │ ├── simpleeth │ ├── .gitignore │ ├── CMakeLists.txt │ ├── README.md │ ├── config.nims │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── component.mk │ │ ├── ethernet_example_main.c │ │ ├── main.nim │ │ ├── nim.cfg │ │ └── nimcache │ │ │ ├── @mmain.nim.c │ │ │ ├── algorithm.ndi │ │ │ ├── ansi_c.ndi │ │ │ ├── assertions.ndi │ │ │ ├── asyncdispatch.ndi │ │ │ ├── asyncfutures.ndi │ │ │ ├── asynchttpserver.ndi │ │ │ ├── asyncnet.ndi │ │ │ ├── asyncstreams.ndi │ │ │ ├── base64.ndi │ │ │ ├── bitops.ndi │ │ │ ├── compile_main.sh │ │ │ ├── cstrutils.ndi │ │ │ ├── deques.ndi │ │ │ ├── dollars.ndi │ │ │ ├── formatfloat.ndi │ │ │ ├── hashes.ndi │ │ │ ├── heapqueue.ndi │ │ │ ├── httpcore.ndi │ │ │ ├── io.ndi │ │ │ ├── iterators.ndi │ │ │ ├── macros.ndi │ │ │ ├── main.deps │ │ │ ├── main.json │ │ │ ├── main.ndi │ │ │ ├── math.ndi │ │ │ ├── memory.ndi │ │ │ ├── miscdollars.ndi │ │ │ ├── monotimes.ndi │ │ │ ├── nativesockets.ndi │ │ │ ├── net.ndi │ │ │ ├── options.ndi │ │ │ ├── os.ndi │ │ │ ├── osseps.ndi │ │ │ ├── parseutils.ndi │ │ │ ├── pathnorm.ndi │ │ │ ├── posix.ndi │ │ │ ├── repr_v2.ndi │ │ │ ├── selectors.ndi │ │ │ ├── sets.ndi │ │ │ ├── since.ndi │ │ │ ├── ssl_certs.ndi │ │ │ ├── ssl_config.ndi │ │ │ ├── stacktraces.ndi │ │ │ ├── stdlib_assertions.nim.c │ │ │ ├── stdlib_asyncdispatch.nim.c │ │ │ ├── stdlib_asyncfutures.nim.c │ │ │ ├── stdlib_asynchttpserver.nim.c │ │ │ ├── stdlib_asyncnet.nim.c │ │ │ ├── stdlib_base64.nim.c │ │ │ ├── stdlib_cstrutils.nim.c │ │ │ ├── stdlib_deques.nim.c │ │ │ ├── stdlib_dollars.nim.c │ │ │ ├── stdlib_hashes.nim.c │ │ │ ├── stdlib_heapqueue.nim.c │ │ │ ├── stdlib_httpcore.nim.c │ │ │ ├── stdlib_io.nim.c │ │ │ ├── stdlib_math.nim.c │ │ │ ├── stdlib_monotimes.nim.c │ │ │ ├── stdlib_nativesockets.nim.c │ │ │ ├── stdlib_net.nim.c │ │ │ ├── stdlib_options.nim.c │ │ │ ├── stdlib_os.nim.c │ │ │ ├── stdlib_parseutils.nim.c │ │ │ ├── stdlib_posix.nim.c │ │ │ ├── stdlib_selectors.nim.c │ │ │ ├── stdlib_strutils.nim.c │ │ │ ├── stdlib_system.nim.c │ │ │ ├── stdlib_tables.nim.c │ │ │ ├── stdlib_times.nim.c │ │ │ ├── stdlib_uri.nim.c │ │ │ ├── strutils.ndi │ │ │ ├── system.ndi │ │ │ ├── tables.ndi │ │ │ ├── times.ndi │ │ │ ├── typetraits.ndi │ │ │ ├── unicode.ndi │ │ │ ├── uri.ndi │ │ │ └── widestrs.ndi │ ├── sdkconfig │ ├── sdkconfig.ci │ └── sdkconfig.old │ └── spi_master │ ├── .gitignore │ ├── hd_eeprom │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── components │ │ └── eeprom │ │ │ ├── CMakeLists.txt │ │ │ ├── component.mk │ │ │ ├── linker.lf │ │ │ ├── spi_eeprom.c │ │ │ └── spi_eeprom.h │ └── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── component.mk │ │ └── spi_eeprom_main.c │ └── lcd │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── components │ └── tjpgd │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── include │ │ └── tjpgd.h │ │ └── src │ │ └── tjpgd.c │ └── main │ ├── CMakeLists.txt │ ├── Kconfig.projbuild │ ├── component.mk │ ├── decode_image.c │ ├── decode_image.h │ ├── image.jpg │ ├── pretty_effect.c │ ├── pretty_effect.h │ └── spi_master_example_main.c ├── example_i2cs.nim ├── nesper.nimble ├── nim.cfg ├── src ├── nesper.nim └── nesper │ ├── build_utils │ ├── tasks.nim │ └── templates │ │ ├── CMakeLists.txt │ │ ├── app_templates │ │ ├── http_server │ │ │ └── server.nim │ │ ├── rpc_json_server │ │ │ ├── rpc_cli_test.nim │ │ │ └── server.nim │ │ ├── rpc_mpack_queue_server │ │ │ ├── rpc_cli_test.nim │ │ │ └── server.nim │ │ ├── rpc_mpack_server │ │ │ ├── rpc_cli_test.nim │ │ │ └── server.nim │ │ └── tcp_echo_server │ │ │ └── server.nim │ │ └── esp32_templates │ │ └── networking │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── main.nim │ │ ├── nim.cfg │ │ ├── setup_networking.nim │ │ └── setup_wifi.nim │ ├── consts.nim │ ├── esp │ ├── FreeRTOS.nim │ ├── driver │ │ ├── adc.nim │ │ ├── adc2_wifi_internal.nim │ │ ├── dac.nim │ │ ├── gpio_driver.nim │ │ ├── i2c.nim │ │ ├── i2s.nim │ │ ├── io_mux_reg.nim │ │ ├── ledc.nim │ │ ├── mcpwm.nim │ │ ├── pcnt.nim │ │ ├── periph_ctrl.nim │ │ ├── periph_defs.nim │ │ ├── rmt.nim │ │ ├── rmt_struct.nim │ │ ├── rtc_cntl.nim │ │ ├── rtc_io.nim │ │ ├── sdio_slave.nim │ │ ├── sdmmc_defs.nim │ │ ├── sdmmc_host.nim │ │ ├── sdmmc_types.nim │ │ ├── spi.nim │ │ ├── spi_slave.nim │ │ ├── timer.nim │ │ ├── timer_group_struct.nim │ │ ├── touch_pad.nim │ │ ├── uart.nim │ │ └── uart_reg.nim │ ├── esp_event.nim │ ├── esp_event_legacy.nim │ ├── esp_intr_alloc.nim │ ├── esp_log.nim │ ├── esp_system.nim │ ├── esp_timer.nim │ ├── esp_vfs_dev.nim │ ├── esp_vfs_fat.nim │ ├── event_groups.nim │ ├── fatfs │ │ ├── ff.nim │ │ └── ffconf.nim │ ├── gpio.nim │ ├── mdns.nim │ ├── net │ │ ├── esp_eth.nim │ │ ├── esp_eth_com.nim │ │ ├── esp_eth_mac.nim │ │ ├── esp_eth_netif_glue.nim │ │ ├── esp_eth_phy.nim │ │ ├── esp_netif.nim │ │ ├── esp_netif_defaults.nim │ │ ├── esp_netif_impl.nim │ │ ├── esp_netif_ip_addr.nim │ │ ├── esp_netif_types.nim │ │ ├── esp_wifi.nim │ │ ├── esp_wifi_types.nim │ │ └── tcpip_adapter.nim │ ├── nvs.nim │ ├── nvs_flash.nim │ ├── queue.nim │ ├── storage │ │ ├── esp_app_format.nim │ │ ├── esp_flash.nim │ │ ├── esp_flash_encrypt.nim │ │ ├── esp_flash_partitions.nim │ │ ├── esp_ota_ops.nim │ │ ├── esp_partition.nim │ │ └── esp_spi_flash.nim │ └── task.nim │ ├── ethernet.nim │ ├── events.nim │ ├── general.nim │ ├── gpios.nim │ ├── i2cs.nim │ ├── net_utils.nim │ ├── nvs_utils.nim │ ├── ota_utils.nim │ ├── queues.nim │ ├── servers │ ├── rpc │ │ ├── marshal.nim │ │ ├── ota_rpc.nim │ │ ├── router.nim │ │ ├── rpc_cli_utils.nim │ │ ├── rpcserial_queue_mpack.nim │ │ ├── rpcsocket_channel_mpack.nim │ │ ├── rpcsocket_json.nim │ │ ├── rpcsocket_mpack.nim │ │ ├── rpcsocket_queue_arr_mpack.nim │ │ ├── rpcsocket_queue_mpack.nim │ │ └── rpcsocket_queue_mpackstr.nim │ ├── tcpsocket.nim │ └── udpsocket.nim │ ├── soc.nim │ ├── spis.nim │ ├── tasks.nim │ ├── timers.nim │ ├── uarts.nim │ └── wifi.nim └── tests ├── .gitignore ├── c_headers ├── consts.h ├── driver │ ├── adc.h │ ├── adc2_wifi_internal.h │ ├── can.h │ ├── dac.h │ ├── gpio.h │ ├── i2c.h │ ├── i2s.h │ ├── ledc.h │ ├── mcpwm.h │ ├── pcnt.h │ ├── periph_ctrl.h │ ├── rmt.h │ ├── rtc_cntl.h │ ├── rtc_io.h │ ├── sdio_slave.h │ ├── sdmmc_defs.h │ ├── sdmmc_host.h │ ├── sdmmc_types.h │ ├── sdspi_host.h │ ├── sigmadelta.h │ ├── spi_master.h │ ├── spi_slave.h │ ├── timer.h │ ├── touch_pad.h │ ├── uart.h │ └── uart_select.h ├── esp_app_format.h ├── esp_eth.h ├── esp_eth_com.h ├── esp_eth_mac.h ├── esp_eth_netif_glue.h ├── esp_eth_phy.h ├── esp_event.h ├── esp_event_base.h ├── esp_event_legacy.h ├── esp_flash.h ├── esp_flash_encrypt.h ├── esp_flash_partitions.h ├── esp_interface.h ├── esp_intr_alloc.h ├── esp_log.h ├── esp_netif.h ├── esp_netif_defaults.h ├── esp_netif_ip_addr.h ├── esp_netif_types.h ├── esp_ota_ops.h ├── esp_partition.h ├── esp_spi_flash.h ├── esp_system.h ├── esp_timer.h ├── esp_vfs_dev.h ├── esp_wifi.h ├── esp_wifi_types.h ├── event_groups.h ├── gpio.h ├── gpio_reg.h ├── i2c.h ├── i2c_types.h ├── i2s_adc_example.c ├── io_mux_reg.h ├── io_mux_reg.nim ├── ip4_addr.h ├── ip_addr.h ├── ledc_example_main.c ├── ledc_example_main.nim ├── list.h ├── mdns.h ├── mock │ ├── FreeRTOSConfig.h │ ├── StackMacros.h │ ├── croutine.h │ ├── deprecated_definitions.h │ ├── driver │ │ ├── driver_mocks.h │ │ ├── spi_common.h │ │ ├── spi_common_internal.h │ │ └── spi_master.h │ ├── esp32 │ │ └── rom │ │ │ └── ets_sys.h │ ├── esp_attr.h │ ├── esp_bit_defs.h │ ├── esp_err.h │ ├── esp_heap_caps.h │ ├── esp_idf_version.h │ ├── esp_log.h │ ├── esp_private │ │ └── crosscore_int.h │ ├── esp_system.h │ ├── esp_timer.h │ ├── event_groups.h │ ├── freertos │ │ └── FreeRTOS.h │ ├── list.h │ ├── mpu_wrappers.h │ ├── multi_heap.h │ ├── portable.h │ ├── portbenchmark.h │ ├── portmacro.h │ ├── porttrace.h │ ├── projdefs.h │ ├── queue.h │ ├── sdkconfig.h │ ├── semphr.h │ ├── soc │ │ ├── cpu.h │ │ └── io_mux_reg.h │ ├── sys │ │ └── reent.h │ ├── task.h │ ├── timers.h │ ├── xtensa │ │ ├── cacheasm.h │ │ ├── cacheattrasm.h │ │ ├── config │ │ │ ├── core-isa.h │ │ │ ├── core-matmap.h │ │ │ ├── core.h │ │ │ ├── defs.h │ │ │ ├── specreg.h │ │ │ ├── system.h │ │ │ ├── tie-asm.h │ │ │ └── tie.h │ │ ├── core-macros.h │ │ ├── coreasm.h │ │ ├── corebits.h │ │ ├── hal.h │ │ ├── specreg.h │ │ ├── traxreg.h │ │ ├── xdm-regs.h │ │ ├── xt_perf_consts.h │ │ ├── xtensa-libdb-macros.h │ │ ├── xtensa-versions.h │ │ ├── xtensa-xer.h │ │ ├── xtruntime-core-state.h │ │ ├── xtruntime-frames.h │ │ └── xtruntime.h │ ├── xtensa_api.h │ ├── xtensa_config.h │ ├── xtensa_context.h │ ├── xtensa_rtos.h │ └── xtensa_timer.h ├── native_ota_example.c ├── native_ota_example.nim ├── nvs.h ├── nvs_flash.h ├── other.h ├── periph_defs.h ├── phy.h ├── projdefs.h ├── replace-cint_t-to-nim-types.sh ├── rmt_struct.h ├── soc.h ├── spi_master.c ├── spi_types.h ├── task.h ├── tcpip_adapter.h ├── timer_group_struct.h └── uart.h ├── driver ├── tadc.nim ├── tadc2_wifi_internal.nim ├── tdac.nim ├── tesp_timer.nim ├── tgpio.nim ├── ti2c.nim ├── ti2s.nim ├── tledc.nim ├── tmcpwm.nim ├── tpcnt.nim ├── tperiph_ctrl.nim ├── trmt.nim ├── trtc_cntl.nim ├── trtc_io.nim ├── tsdio_slave.nim ├── tsdmmc_defs.nim ├── tspi.nim ├── tspi_slave.nim ├── ttimer.nim ├── ttouch_pad.nim ├── tuart.nim └── tuart_reg.nim ├── echosocket_test.nim ├── exec_tests ├── .gitignore ├── tgeneral_exec.nim ├── trouter_exec.nim └── tspi_exec.nim ├── nim.cfg ├── rpc_cli_test.nim ├── rpc_ota_uploader.nim ├── storage ├── tesp_app_format.nim ├── tesp_flash.nim ├── tesp_flash_encrypt.nim ├── tesp_flash_partitions.nim ├── tesp_ota_ops.nim ├── tesp_partition.nim └── tesp_spi_flash.nim ├── tconsts ├── tconsts.nim ├── test_repr.nim ├── teth_modules.nim ├── tgeneral.nim ├── tgpios.nim ├── ti2cs.nim ├── tledc.nim ├── tmdns.nim ├── tnvs.nim ├── tqueues.nim ├── tsocket_echo.nim ├── tspi.nim └── tuarts.nim /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: tests 2 | 3 | tests: 4 | nimble test 5 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | from espressif/idf:release-v4.0 2 | RUN wget https://nim-lang.org/download/nim-1.4.0-linux_x64.tar.xz 3 | RUN tar xvf nim-1.4.0-linux_x64.tar.xz 4 | ENV PATH="/nim-1.4.0/bin:${PATH}" -------------------------------------------------------------------------------- /docker/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker image rm -f esp_nim 4 | docker build -t esp_nim ./ -------------------------------------------------------------------------------- /docker/run_shell.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd ../ 3 | docker run --rm -v $PWD:/project --device=/dev/ttyUSB0 -w /project -it esp_nim 4 | popd -------------------------------------------------------------------------------- /esp-idf-examples/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /esp-idf-examples/README.md: -------------------------------------------------------------------------------- 1 | 2 | The two examples `simplewifi` and `simplewifi-rpc` are currently the only examples that have been tested on hardware. 3 | 4 | The `simplewifi` example is a simple method showing how to use async servers with Nim. However, as of Nim 1.4, there are still some challenges running async with ORC on small devices. This should get better over time and may work depending on your paramters. 5 | 6 | For production usage, it's recommended to use one of the `simplewifi-rpc` methods. Using socket `select` allows efficiently servicing RPC calls without requiring async. However, this means only *one* RPC call can be handled at a time. This could be worked around by spawning more tasks or sockets, but is sufficient for many cases. 7 | 8 | 9 | -------------------------------------------------------------------------------- /esp-idf-examples/app_test/.gitignore: -------------------------------------------------------------------------------- 1 | main/ 2 | *.txt 3 | *.nim 4 | *.cfg 5 | *.nims 6 | build/ 7 | sdkconfig 8 | -------------------------------------------------------------------------------- /esp-idf-examples/app_test/app_test.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.1.0" 4 | author = "Author Name" 5 | description = "Nesper example" 6 | license = "none" 7 | srcDir = "src" 8 | 9 | # Dependencies 10 | requires "nim >= 1.4.0" 11 | requires "nesper >= 0.5.0" 12 | # includes nimble tasks for building Nim esp-idf projects 13 | include nesper/build_utils/tasks 14 | -------------------------------------------------------------------------------- /esp-idf-examples/app_test/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -Rf *.txt ./main/ 4 | rm -Rf ./src/ 5 | 6 | rm -Rf build sdkconfig 7 | -------------------------------------------------------------------------------- /esp-idf-examples/nim.cfg: -------------------------------------------------------------------------------- 1 | --path:"../src/" 2 | 3 | 4 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | results.json 7 | main/nimble/ 8 | rpc_cli 9 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 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 | # (Not part of the boilerplate) 6 | 7 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) 8 | # set(EXTRA_COMPONENT_DIRS src) 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(simple_rpc) 12 | 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 19 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 20 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ESP_IDF_VERSION ?= ESP_IDF_V4_0 3 | # ESP_IDF_VERSION ?= ESP_IDF_V4_1 4 | 5 | NIMBLE := main/nimble 6 | # Configure any dependencies 7 | NIM_DEPENDA := msgpack4nim 8 | NIMLIB := $(shell nim dump file.json 2>&1 | grep lib | sort | head -n1 ) 9 | NIMCACHE := main/nimcache 10 | NIMFLAGS ?= 11 | 12 | $(NIMBLE): 13 | nimble install -y --nimbleDir:"$(NIMBLE)" msgpack4nim stew 14 | 15 | default: mpack_rpc_queue_server 16 | 17 | json_rpc_server: clean 18 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpJsonRpcServer $(NIMFLAGS) && idf.py reconfigure 19 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpJsonRpcServer -o:rpc_cli rpc_cli_test.nim 20 | 21 | mpack_rpc_server: clean 22 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpMpackRpcServer $(NIMFLAGS) && idf.py reconfigure 23 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpMpackRpcServer -o:rpc_cli rpc_cli_test.nim 24 | 25 | mpack_rpc_queue_server: clean 26 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpMpackRpcQueueServer $(NIMFLAGS) && idf.py reconfigure 27 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpMpackRpcQueueServer -o:rpc_cli rpc_cli_test.nim 28 | 29 | tcp_echo_server: clean 30 | nim prepare main/main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpEchoServer $(NIMFLAGS) && idf.py reconfigure 31 | 32 | build: 33 | idf.py build 34 | 35 | 36 | clean: $(NIMBLE) 37 | rm -Rf main/nimcache/ 38 | 39 | fullclean: clean 40 | rm -Rf build/ 41 | rm -Rf main/nimble/ 42 | # idf.py fullclean 43 | 44 | .PHONY: clean build 45 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/README.md: -------------------------------------------------------------------------------- 1 | # Nim ESP32 - Simple Wifi 2 | 3 | Simple example in Nim with wifi on ESP32 on FreeRTOS & LwIP. 4 | 5 | ## Building Example 6 | 7 | Install and configure [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html). Currently v4.1 is the default supported version for Nesper currently. 8 | 9 | Then: 10 | 11 | ```shell 12 | git clone https://github.com/elcritch/nesper 13 | cd esp-idf-examples/simplewifi/ 14 | . $ESP_IDF_DIR/export.sh # source esp-idf 15 | ``` 16 | 17 | Build Nim project: 18 | ```sh 19 | export WIFI_SSID="[SSID]" 20 | export WIFI_PASSWORD="[PASSWORD]" 21 | make json_rpc_server build 22 | ``` 23 | 24 | This compiles the Nim code and updates the ESP-IDF project files. This example contains several variants which can be built by changing the make target like: `make tcp_echo_server build` then following the rest of the steps. The current options are: 25 | 26 | ```sh 27 | make json_rpc_server build 28 | make mpack_rpc_server build 29 | make mpack_rpc_queue_server build 30 | make tcp_echo_server build 31 | ``` 32 | 33 | The above will all compile the nim project and then run `idf.py build` for you. 34 | 35 | Once the project is built you can use `idf.py` tools for flashing and monitoring: 36 | 37 | ```shell 38 | idf.py -p [port] flash 39 | idf.py -p [port] monitor 40 | 41 | # or together: 42 | idf.py -p [port] flash monitor 43 | ``` 44 | 45 | ## Testing Example 46 | 47 | The RPC methods use raw sockets and `selectors` library from Nim's stdlib. This allows the ESP32 code to efficiently check sockets for new messages. The makefile now builds a variant of `rpc_cli` that should work with the chosen method (e.g. mpack or json). 48 | 49 | Run it like: 50 | 51 | ```sh 52 | ./rpc_cli --ip:$IP --count:1 '{"method": "add", "params": [1,2]}' 53 | ``` 54 | 55 | ## Notes on the RPC protocol 56 | 57 | The `rpc_cli` should give an example of the RPC protocol used for the message pack RPC versions. It's roughly based on JSON-RPC, however, using raw socket require a bit more work. Sending RPC messages are sent "raw", e.g. just the message. This limits RPC calls to 1400 bytes and could be fixed in the future. 58 | 59 | For receiving the RPC responses, a very simple protocol is used based on the Erlang "ports" protocol. A 4-byte signed integer with the size of the RPC result is sent first, in network byte order. The RPC client must read these 4 bytes, then read the number of bytes sent. The `rpc_cli` provides an example of how to do this in Nim. This enables returning message that are larger than 1400 bytes. Ideally, this will be done for the incoming RPC message as well. 60 | 61 | For simplificity, the JSON version of the rpc server currently returns a "raw" response and are limited to 1400 bytes on both sending and receiving RPC messages. 62 | 63 | The 'echo' server likewise only sends raw data. You can use `netcat` to test the echo server. 64 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/build-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | echo ========= full clean ========= 6 | make fullclean 7 | 8 | echo ========= json_rpc_server build ========= 9 | make json_rpc_server build 10 | 11 | echo ========= mpack_rpc_server build ========= 12 | make mpack_rpc_server build 13 | 14 | echo m========= pack_rpc_queue_server build ========= 15 | make mpack_rpc_queue_server build 16 | 17 | echo ========= tcp_echo_server build ========= 18 | make tcp_echo_server build 19 | 20 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/config.nims: -------------------------------------------------------------------------------- 1 | import os, strutils 2 | 3 | 4 | import nesper/build_utils/tasks 5 | 6 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/.gitignore: -------------------------------------------------------------------------------- 1 | nimcache 2 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRC_DIRS "./nimcache" 3 | INCLUDE_DIRS "" 4 | REQUIRES lwip newlib nvs_flash app_update) 5 | 6 | # set(C_COMPILE_OPTIONS "${C_COMPILE_OPTIONS} -Wno-error=unused-label") 7 | # list(APPEND C_COMPILE_OPTIONS "-Wno-error=unused-label ") 8 | 9 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-label APPEND) 10 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-discarded-qualifiers APPEND) 11 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-ignored-qualifiers APPEND) 12 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 19 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Wifi Example Configuration" 2 | 3 | config EXAMPLE_WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config EXAMPLE_WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "mypassword" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | endmenu -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/main.nim: -------------------------------------------------------------------------------- 1 | import nesper 2 | import nesper/net_utils 3 | import nesper/nvs_utils 4 | import nesper/events 5 | import nesper/wifi 6 | import nesper/tasks 7 | import os 8 | 9 | import server 10 | 11 | when defined(ESP32_ETHERNET): 12 | import setup_eth 13 | else: 14 | import setup_wifi 15 | 16 | # const CONFIG_EXAMPLE_WIFI_SSID = getEnv("WIFI_SSID") 17 | # const CONFIG_EXAMPLE_WIFI_PASSWORD = getEnv("WIFI_PASSWORD") 18 | 19 | const TAG*: cstring = "main" 20 | 21 | app_main(): 22 | 23 | networkingStart() 24 | 25 | # Other startup code 26 | # ... 27 | 28 | # Connect networking 29 | onNetworking(): 30 | logi(TAG, "Connected to %s", networkConnectionName) 31 | logi(TAG, "IPv4 address: %s", $networkIpAddr) 32 | logi(TAG, "network setup!\n") 33 | run_rpc_server() 34 | 35 | assert false, "shouldn't reach here!" 36 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/nim.cfg: -------------------------------------------------------------------------------- 1 | --gc:arc 2 | --os:freertos 3 | --cpu:esp 4 | 5 | # --nimCache:"nimcache/" 6 | # --nimblePath:"nimble/" 7 | --nimble_path:"nimble/pkgs" 8 | 9 | -d:use_malloc 10 | -d:no_signal_handler 11 | 12 | --debugger:native 13 | --threads:on 14 | --tls_emulation:off 15 | --verbosity:2 16 | 17 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import nesper/events 4 | import apps 5 | import volatile 6 | import strutils 7 | import json 8 | 9 | const TAG = "server" 10 | const MaxRpcReceiveBuffer {.intdefine.}: int = 4096 11 | 12 | ## Note: 13 | ## Nim uses `when` compile time constructs 14 | ## these are like ifdef's in C and don't really have an equivalent in Python 15 | ## setting the flags can be done in the Makefile `simplewifi-rpc Makefile 16 | ## for example, to compile the example to use JSON, pass `-d:TcpJsonRpcServer` to Nim 17 | ## the makefile has several example already defined for convenience 18 | ## 19 | when defined(TcpJsonRpcServer): 20 | import nesper/servers/rpc/rpcsocket_json 21 | when defined(TcpMpackRpcQueueServer): 22 | import ota_rpc_example 23 | import nesper/servers/rpc/rpcsocket_queue_mpack 24 | elif not defined(TcpEchoServer): # This is the default 'msgpack' version -- set like this for nimsuggest 25 | import ota_rpc_example 26 | import nesper/servers/rpc/rpcsocket_mpack 27 | elif defined(TcpEchoServer): 28 | import nesper/servers/tcpsocket 29 | else: 30 | {.fatal: "Compile this program with an rpc strategy!".} 31 | 32 | 33 | when defined(TcpEchoServer): 34 | proc run_rpc_server*() = 35 | echo "starting server on port 5555" 36 | var msg = "echo: " 37 | startSocketServer[string](Port(5555), readHandler=echoReadHandler, writeHandler=nil, data=msg) 38 | 39 | else: 40 | 41 | # Setup RPC Server # 42 | proc run_rpc_server*() = 43 | 44 | # Setup an RPC router 45 | var rpcRouter: RpcRouter 46 | var rt = createRpcRouter(MaxRpcReceiveBuffer) 47 | 48 | rpc(rt, "hello") do(input: string) -> string: 49 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "hello", "params": ["world"]}' 50 | result = "Hello " & input 51 | 52 | rpc(rt, "add") do(a: int, b: int) -> int: 53 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "add", "params": [1, 2]}' 54 | result = a + b 55 | 56 | rpc(rt, "addAll") do(vals: seq[int]) -> int: 57 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "add", "params": [1, 2, 3, 4, 5]}' 58 | echo("run_rpc_server: done: " & repr(addr(vals))) 59 | result = 0 60 | for x in vals: 61 | result += x 62 | 63 | # this adds methods for Over-The-Air updates using RPC! 64 | # note, this isn't secured by default 65 | rpcRouter.addOTAMethods() 66 | 67 | echo "starting rpc server on port 5555" 68 | logi(TAG,"starting rpc server buffer size: %s", $(rt.buffer)) 69 | 70 | when defined(TcpMpackRpcQueueServer): 71 | # Starts a separate task on CPU_1 (e.g. the "App CPU") 72 | # This makes it reallly easy to add dedicated tasks to run on CPU_1 73 | startRpcQueueSocketServer(Port(5555), router=rt) 74 | else: 75 | # Starts RPC handler on the current task 76 | # Default for JSON, MsgPack, and TCP Echo 77 | startRpcSocketServer(Port(5555), router=rt) 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/main/setup_networking.nim: -------------------------------------------------------------------------------- 1 | import nesper 2 | 3 | import nesper/net_utils 4 | import nesper/nvs_utils 5 | import nesper/events 6 | import nesper/tasks 7 | 8 | const 9 | GOT_IPV4_BIT* = EventBits_t(BIT(1)) 10 | CONNECTED_BITS* = (GOT_IPV4_BIT) 11 | 12 | var networkConnectEventGroup*: EventGroupHandle_t 13 | var networkIpAddr*: IpAddress 14 | var networkConnectionName*: cstring 15 | 16 | proc networkingStart*(startNvs=true) = 17 | 18 | # Networking will generally utilize NVS for storing net info 19 | # so it's best to start it first 20 | if startNvs: 21 | initNvs() 22 | 23 | # Initialize TCP/IP network interface (should be called only once in application) 24 | when defined(ESP_IDF_V4_0): 25 | tcpip_adapter_init() 26 | else: 27 | check: esp_netif_init() 28 | 29 | # Create default event loop that runs in background 30 | check: esp_event_loop_create_default() 31 | 32 | 33 | template onNetworking*(code: untyped) = 34 | discard xEventGroupWaitBits(networkConnectEventGroup, CONNECTED_BITS, 1, 1, portMAX_DELAY) 35 | 36 | code 37 | -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/rpc_cli_test.nim: -------------------------------------------------------------------------------- 1 | ../../tests/rpc_cli_test.nim -------------------------------------------------------------------------------- /esp-idf-examples/simple_rpc/simple_rpc.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.1.0" 4 | author = "Author Name" 5 | description = "Nesper example" 6 | license = "none" 7 | srcDir = "main" 8 | 9 | # Dependencies 10 | requires "nim >= 1.4.0" 11 | requires "nesper >= 0.5.0" 12 | 13 | # nesperVersion = "ESP_IDF_V4_0" 14 | # import nesper/build_tasks 15 | 16 | # nim prepare main/main.nim --nimblePath:main/nimble/pkgs -d:ESP_IDF_V4_0 -d:TcpEchoServer && idf.py reconfigure 17 | 18 | include nesper/build_utils/tasks 19 | 20 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | results.json 7 | main/nimble/ 8 | rpc_cli 9 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/CMakeLists.txt: -------------------------------------------------------------------------------- 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 | # (Not part of the boilerplate) 6 | 7 | 8 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) 9 | # set(EXTRA_COMPONENT_DIRS src) 10 | 11 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 12 | project(simple-nim-wifi) 13 | 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 19 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 20 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 21 | 22 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ESP_IDF_VERSION ?= ESP_IDF_V4_0 3 | # ESP_IDF_VERSION ?= ESP_IDF_V4_1 4 | 5 | NIMBLE := main/nimble 6 | # Configure any dependencies 7 | NIM_DEPENDA := msgpack4nim 8 | NIMLIB := $(shell nim dump file.json 2>&1 | grep lib | sort | head -n1 ) 9 | NIMCACHE := main/nimcache 10 | NIMFLAGS ?= 11 | 12 | $(NIMBLE): 13 | nimble install -y --nimbleDir:"$(NIMBLE)" msgpack4nim stew 14 | 15 | default: mpack_rpc_queue_server 16 | 17 | json_rpc_server: clean 18 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpJsonRpcServer $(NIMFLAGS) && idf.py reconfigure 19 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpJsonRpcServer -o:rpc_cli rpc_cli_test.nim 20 | 21 | mpack_rpc_server: clean 22 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpMpackRpcServer $(NIMFLAGS) && idf.py reconfigure 23 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpMpackRpcServer -o:rpc_cli rpc_cli_test.nim 24 | 25 | mpack_rpc_queue_server: clean 26 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpMpackRpcQueueServer $(NIMFLAGS) && idf.py reconfigure 27 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpMpackRpcQueueServer -o:rpc_cli rpc_cli_test.nim 28 | 29 | tcp_echo_server: clean 30 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpEchoServer $(NIMFLAGS) && idf.py reconfigure 31 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpEchoServer -o:rpc_clirpc_cli_test.nim 32 | 33 | build: 34 | idf.py build 35 | 36 | 37 | clean: $(NIMBLE) 38 | rm -Rf main/nimcache/ 39 | 40 | fullclean: clean 41 | rm -Rf build/ 42 | rm -Rf main/nimble/ 43 | # idf.py fullclean 44 | 45 | .PHONY: clean build 46 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/README.md: -------------------------------------------------------------------------------- 1 | # Nim ESP32 - Simple Wifi 2 | 3 | Simple example in Nim with wifi on ESP32 on FreeRTOS & LwIP. 4 | 5 | ## Building Example 6 | 7 | Install and configure [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html). Currently v4.1 is the default supported version for Nesper currently. 8 | 9 | Then: 10 | 11 | ```shell 12 | git clone https://github.com/elcritch/nesper 13 | cd esp-idf-examples/simplewifi/ 14 | . $ESP_IDF_DIR/export.sh # source esp-idf 15 | ``` 16 | 17 | Build Nim project: 18 | ```sh 19 | export WIFI_SSID="[SSID]" 20 | export WIFI_PASSWORD="[PASSWORD]" 21 | make json_rpc_server build 22 | ``` 23 | 24 | This compiles the Nim code and updates the ESP-IDF project files. This example contains several variants which can be built by changing the make target like: `make tcp_echo_server build` then following the rest of the steps. The current options are: 25 | 26 | ```sh 27 | make json_rpc_server build 28 | make mpack_rpc_server build 29 | make mpack_rpc_queue_server build 30 | make tcp_echo_server build 31 | ``` 32 | 33 | The above will all compile the nim project and then run `idf.py build` for you. 34 | 35 | Once the project is built you can use `idf.py` tools for flashing and monitoring: 36 | 37 | ```shell 38 | idf.py -p [port] flash 39 | idf.py -p [port] monitor 40 | 41 | # or together: 42 | idf.py -p [port] flash monitor 43 | ``` 44 | 45 | ## Testing Example 46 | 47 | The RPC methods use raw sockets and `selectors` library from Nim's stdlib. This allows the ESP32 code to efficiently check sockets for new messages. The makefile now builds a variant of `rpc_cli` that should work with the chosen method (e.g. mpack or json). 48 | 49 | Run it like: 50 | 51 | ```sh 52 | ./rpc_cli --ip:$IP --count:1 '{"method": "add", "params": [1,2]}' 53 | ``` 54 | 55 | ## Notes on the RPC protocol 56 | 57 | The `rpc_cli` should give an example of the RPC protocol used for the message pack RPC versions. It's roughly based on JSON-RPC, however, using raw socket require a bit more work. Sending RPC messages are sent "raw", e.g. just the message. This limits RPC calls to 1400 bytes and could be fixed in the future. 58 | 59 | For receiving the RPC responses, a very simple protocol is used based on the Erlang "ports" protocol. A 4-byte signed integer with the size of the RPC result is sent first, in network byte order. The RPC client must read these 4 bytes, then read the number of bytes sent. The `rpc_cli` provides an example of how to do this in Nim. This enables returning message that are larger than 1400 bytes. Ideally, this will be done for the incoming RPC message as well. 60 | 61 | For simplificity, the JSON version of the rpc server currently returns a "raw" response and are limited to 1400 bytes on both sending and receiving RPC messages. 62 | 63 | The 'echo' server likewise only sends raw data. You can use `netcat` to test the echo server. 64 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/build-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | echo ========= full clean ========= 6 | make fullclean 7 | 8 | echo ========= json_rpc_server build ========= 9 | make json_rpc_server build 10 | 11 | echo ========= mpack_rpc_server build ========= 12 | make mpack_rpc_server build 13 | 14 | echo m========= pack_rpc_queue_server build ========= 15 | make mpack_rpc_queue_server build 16 | 17 | echo ========= tcp_echo_server build ========= 18 | make tcp_echo_server build 19 | 20 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/config.nims: -------------------------------------------------------------------------------- 1 | import os, strutils 2 | 3 | task prepare, "Compile to C code": 4 | mkDir("./main/nimcache") 5 | let nimbasepath = selfExe().splitFile.dir.parentDir / "lib" / "nimbase.h" 6 | let nimcachepath = "main" / "nimcache" 7 | cpFile(nimbasepath, nimcachepath / "nimbase.h") 8 | let params = commandLineParams() 9 | let file = params[1] 10 | let rest = params[2..high(params)].join(" ") 11 | 12 | let wifi_ssid = getEnv("WIFI_SSID") 13 | let wifi_pass = getEnv("WIFI_PASSWORD") 14 | 15 | let wifidefs = 16 | if wifi_ssid != "" and wifi_pass != "": 17 | "-d:WIFI_SSID=$1 -d:WIFI_PASSWORD=$2 " % [wifi_ssid, wifi_pass] 18 | else: 19 | "" 20 | 21 | let 22 | cmd = "nim c --os:freertos --cpu:esp --nomain --nimcache:$1 --compileOnly -d:NimAppMain $4 $3 $2 " % 23 | [nimcachepath, file, rest, wifidefs] 24 | 25 | echo("cmd: " & cmd) 26 | exec(cmd) 27 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/main/.gitignore: -------------------------------------------------------------------------------- 1 | nimcache 2 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRC_DIRS "./nimcache" 3 | INCLUDE_DIRS "" 4 | REQUIRES lwip newlib nvs_flash app_update) 5 | 6 | # set(C_COMPILE_OPTIONS "${C_COMPILE_OPTIONS} -Wno-error=unused-label") 7 | # list(APPEND C_COMPILE_OPTIONS "-Wno-error=unused-label ") 8 | 9 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-label APPEND) 10 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-discarded-qualifiers APPEND) 11 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-ignored-qualifiers APPEND) 12 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 19 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Wifi Example Configuration" 2 | 3 | config EXAMPLE_WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config EXAMPLE_WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "mypassword" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | endmenu -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/main/apps.nim: -------------------------------------------------------------------------------- 1 | import nesper 2 | import nesper/consts 3 | import nesper/general 4 | import nesper/events 5 | import nesper/tasks 6 | 7 | const APP_EVENT*: string = "APP_EVENT" 8 | 9 | type 10 | app_events_t* {.size: sizeof(cint).} = enum 11 | app_test = 0, 12 | app_add_all 13 | 14 | proc add_all*(arg: pointer; 15 | event_base: esp_event_base_t; 16 | event_id: int32; 17 | event_data: ptr seq[int] 18 | ) {.cdecl.} = 19 | echo("app: `add_all` event: " & repr(event_data)) 20 | # var data: seq[int] = cast[ptr seq[int]](event_data)[] 21 | var data: seq[int] = event_data[] 22 | echo("app: `add_all` data: " & $data) 23 | # echo("app: `add_all` event[]: " & repr(cast[ptr pointer](event_data))) 24 | echo("") 25 | 26 | # apploop.eventPost(APP_EVENT, app_add_all, addr(vals), sizeof(vals), 10000) 27 | 28 | # var pdata: ptr seq[int] = cast[ptr seq[int]](event_data) 29 | # echo("app: `add_all` event: ptr: " & repr(pdata)) 30 | # var data: seq[int] = pdata[] 31 | # echo("app: `add_all` event: data: " & $(data)) 32 | 33 | proc setup_app_task_loop*(): esp_event_loop_handle_t = 34 | var loop: esp_event_loop_handle_t 35 | var loop_args = 36 | esp_event_loop_args_t( 37 | queue_size: 10, 38 | task_name: "app loop", 39 | task_priority: 1, 40 | task_stack_size: 4096, 41 | task_core_id: 1) 42 | 43 | let ret = esp_event_loop_create(addr(loop_args), addr(loop)) 44 | if ret != ESP_OK: 45 | raise newEspError[EventError]("register: " & $esp_err_to_name(ret), ret) 46 | 47 | echo("run_app: running! Loop handle: " & repr(loop.pointer) & " ptr: " & $repr(loop)) 48 | loop.eventRegisterWith(APP_EVENT, app_add_all, add_all) 49 | 50 | return loop 51 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/main/nim.cfg: -------------------------------------------------------------------------------- 1 | --gc:arc 2 | --os:freertos 3 | --cpu:esp 4 | 5 | # --nimCache:"nimcache/" 6 | # --nimblePath:"nimble/" 7 | --nimble_path:"nimble/pkgs" 8 | 9 | -d:use_malloc 10 | -d:no_signal_handler 11 | 12 | --debugger:native 13 | --threads:on 14 | --tls_emulation:off 15 | --verbosity:2 16 | 17 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/main/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import nesper/events 4 | import apps 5 | import volatile 6 | import strutils 7 | import json 8 | 9 | const TAG = "server" 10 | const MaxRpcReceiveBuffer {.intdefine.}: int = 4096 11 | 12 | ## Note: 13 | ## Nim uses `when` compile time constructs 14 | ## these are like ifdef's in C and don't really have an equivalent in Python 15 | ## setting the flags can be done in the Makefile `simplewifi-rpc Makefile 16 | ## for example, to compile the example to use JSON, pass `-d:TcpJsonRpcServer` to Nim 17 | ## the makefile has several example already defined for convenience 18 | ## 19 | when defined(TcpJsonRpcServer): 20 | import nesper/servers/rpc/rpcsocket_json 21 | when defined(TcpMpackRpcQueueServer): 22 | import ota_rpc_example 23 | import nesper/servers/rpc/rpcsocket_queue_mpack 24 | elif not defined(TcpEchoServer): # This is the default 'msgpack' version -- set like this for nimsuggest 25 | import ota_rpc_example 26 | import nesper/servers/rpc/rpcsocket_mpack 27 | elif defined(TcpEchoServer): 28 | import nesper/servers/tcpsocket 29 | else: 30 | {.fatal: "Compile this program with an rpc strategy!".} 31 | 32 | 33 | when defined(TcpEchoServer): 34 | proc run_rpc_server*() = 35 | echo "starting server on port 5555" 36 | var msg = "echo: " 37 | startSocketServer[string](Port(5555), readHandler=echoReadHandler, writeHandler=nil, data=msg) 38 | 39 | else: 40 | 41 | # Setup RPC Server # 42 | proc run_rpc_server*() = 43 | 44 | # Setup an RPC router 45 | var rpcRouter: RpcRouter 46 | var rt = createRpcRouter(MaxRpcReceiveBuffer) 47 | 48 | rpc(rt, "hello") do(input: string) -> string: 49 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "hello", "params": ["world"]}' 50 | result = "Hello " & input 51 | 52 | rpc(rt, "add") do(a: int, b: int) -> int: 53 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "add", "params": [1, 2]}' 54 | result = a + b 55 | 56 | rpc(rt, "addAll") do(vals: seq[int]) -> int: 57 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "add", "params": [1, 2, 3, 4, 5]}' 58 | echo("run_rpc_server: done: " & repr(addr(vals))) 59 | result = 0 60 | for x in vals: 61 | result += x 62 | 63 | # this adds methods for Over-The-Air updates using RPC! 64 | # note, this isn't secured by default 65 | rpcRouter.addOTAMethods() 66 | 67 | echo "starting rpc server on port 5555" 68 | logi(TAG,"starting rpc server buffer size: %s", $(rt.buffer)) 69 | 70 | when defined(TcpMpackRpcQueueServer): 71 | # Starts a separate task on CPU_1 (e.g. the "App CPU") 72 | # This makes it reallly easy to add dedicated tasks to run on CPU_1 73 | startRpcQueueSocketServer(Port(5555), router=rt) 74 | else: 75 | # Starts RPC handler on the current task 76 | # Default for JSON, MsgPack, and TCP Echo 77 | startRpcSocketServer(Port(5555), router=rt) 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /esp-idf-examples/simpleeth/rpc_cli_test.nim: -------------------------------------------------------------------------------- 1 | ../../tests/rpc_cli_test.nim -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | results.json 7 | main/nimble/ 8 | rpc_cli 9 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/CMakeLists.txt: -------------------------------------------------------------------------------- 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 | # (Not part of the boilerplate) 6 | 7 | 8 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) 9 | # set(EXTRA_COMPONENT_DIRS src) 10 | 11 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 12 | project(simple-nim-wifi) 13 | 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 19 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 20 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ESP_IDF_VERSION ?= ESP_IDF_V4_0 3 | # ESP_IDF_VERSION ?= ESP_IDF_V4_1 4 | 5 | NIMBLE := main/nimble 6 | # Configure any dependencies 7 | NIM_DEPENDA := msgpack4nim 8 | NIMLIB := $(shell nim dump file.json 2>&1 | grep lib | sort | head -n1 ) 9 | NIMCACHE := main/nimcache 10 | NIMFLAGS ?= 11 | 12 | $(NIMBLE): 13 | nimble install -y --nimbleDir:"$(NIMBLE)" msgpack4nim stew 14 | 15 | default: mpack_rpc_queue_server 16 | 17 | json_rpc_server: clean 18 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpJsonRpcServer $(NIMFLAGS) && idf.py reconfigure 19 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpJsonRpcServer -o:rpc_cli rpc_cli_test.nim 20 | 21 | mpack_rpc_server: clean 22 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpMpackRpcServer $(NIMFLAGS) && idf.py reconfigure 23 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpMpackRpcServer -o:rpc_cli rpc_cli_test.nim 24 | 25 | mpack_rpc_queue_server: clean 26 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpMpackRpcQueueServer $(NIMFLAGS) && idf.py reconfigure 27 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpMpackRpcQueueServer -o:rpc_cli rpc_cli_test.nim 28 | 29 | tcp_echo_server: clean 30 | nim prepare main/wifi_example_main.nim --nimblePath:$(NIMBLE)/pkgs -d:$(ESP_IDF_VERSION) -d:TcpEchoServer $(NIMFLAGS) && idf.py reconfigure 31 | nim c --nimblePath:$(NIMBLE)/pkgs -d:TcpEchoServer -o:rpc_clirpc_cli_test.nim 32 | 33 | build: 34 | idf.py build 35 | 36 | 37 | clean: $(NIMBLE) 38 | rm -Rf main/nimcache/ 39 | 40 | fullclean: clean 41 | rm -Rf build/ 42 | rm -Rf main/nimble/ 43 | # idf.py fullclean 44 | 45 | .PHONY: clean build 46 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/README.md: -------------------------------------------------------------------------------- 1 | # Nim ESP32 - Simple Wifi 2 | 3 | Simple example in Nim with wifi on ESP32 on FreeRTOS & LwIP. 4 | 5 | ## Building Example 6 | 7 | Install and configure [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html). Currently v4.1 is the default supported version for Nesper currently. 8 | 9 | Then: 10 | 11 | ```shell 12 | git clone https://github.com/elcritch/nesper 13 | cd esp-idf-examples/simplewifi/ 14 | . $ESP_IDF_DIR/export.sh # source esp-idf 15 | ``` 16 | 17 | Build Nim project: 18 | ```sh 19 | export WIFI_SSID="[SSID]" 20 | export WIFI_PASSWORD="[PASSWORD]" 21 | make json_rpc_server build 22 | ``` 23 | 24 | This compiles the Nim code and updates the ESP-IDF project files. This example contains several variants which can be built by changing the make target like: `make tcp_echo_server build` then following the rest of the steps. The current options are: 25 | 26 | ```sh 27 | make json_rpc_server build 28 | make mpack_rpc_server build 29 | make mpack_rpc_queue_server build 30 | make tcp_echo_server build 31 | ``` 32 | 33 | The above will all compile the nim project and then run `idf.py build` for you. 34 | 35 | Once the project is built you can use `idf.py` tools for flashing and monitoring: 36 | 37 | ```shell 38 | idf.py -p [port] flash 39 | idf.py -p [port] monitor 40 | 41 | # or together: 42 | idf.py -p [port] flash monitor 43 | ``` 44 | 45 | ## Testing Example 46 | 47 | The RPC methods use raw sockets and `selectors` library from Nim's stdlib. This allows the ESP32 code to efficiently check sockets for new messages. The makefile now builds a variant of `rpc_cli` that should work with the chosen method (e.g. mpack or json). 48 | 49 | Run it like: 50 | 51 | ```sh 52 | ./rpc_cli --ip:$IP --count:1 '{"method": "add", "params": [1,2]}' 53 | ``` 54 | 55 | ## Notes on the RPC protocol 56 | 57 | The `rpc_cli` should give an example of the RPC protocol used for the message pack RPC versions. It's roughly based on JSON-RPC, however, using raw socket require a bit more work. Sending RPC messages are sent "raw", e.g. just the message. This limits RPC calls to 1400 bytes and could be fixed in the future. 58 | 59 | For receiving the RPC responses, a very simple protocol is used based on the Erlang "ports" protocol. A 4-byte signed integer with the size of the RPC result is sent first, in network byte order. The RPC client must read these 4 bytes, then read the number of bytes sent. The `rpc_cli` provides an example of how to do this in Nim. This enables returning message that are larger than 1400 bytes. Ideally, this will be done for the incoming RPC message as well. 60 | 61 | For simplificity, the JSON version of the rpc server currently returns a "raw" response and are limited to 1400 bytes on both sending and receiving RPC messages. 62 | 63 | The 'echo' server likewise only sends raw data. You can use `netcat` to test the echo server. 64 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/build-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | echo ========= full clean ========= 6 | make fullclean 7 | 8 | echo ========= json_rpc_server build ========= 9 | make json_rpc_server build 10 | 11 | echo ========= mpack_rpc_server build ========= 12 | make mpack_rpc_server build 13 | 14 | echo m========= pack_rpc_queue_server build ========= 15 | make mpack_rpc_queue_server build 16 | 17 | echo ========= tcp_echo_server build ========= 18 | make tcp_echo_server build 19 | 20 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/config.nims: -------------------------------------------------------------------------------- 1 | import os, strutils 2 | 3 | task prepare, "Compile to C code": 4 | mkDir("./main/nimcache") 5 | let nimbasepath = selfExe().splitFile.dir.parentDir / "lib" / "nimbase.h" 6 | let nimcachepath = "main" / "nimcache" 7 | cpFile(nimbasepath, nimcachepath / "nimbase.h") 8 | let params = commandLineParams() 9 | let file = params[1] 10 | let rest = params[2..high(params)].join(" ") 11 | 12 | let wifi_ssid = getEnv("WIFI_SSID") 13 | let wifi_pass = getEnv("WIFI_PASS") 14 | 15 | let wifidefs = 16 | if wifi_ssid != "" and wifi_pass != "": 17 | "-d:WIFI_SSID=$1 -d:WIFI_PASSWORD=$2 " % [wifi_ssid, wifi_pass] 18 | else: 19 | "" 20 | 21 | let 22 | cmd = "nim c --os:freertos --cpu:esp --nomain --nimcache:$1 --compileOnly -d:NimAppMain $4 $3 $2 " % 23 | [nimcachepath, file, rest, wifidefs] 24 | 25 | echo("cmd: " & cmd) 26 | exec(cmd) 27 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/main/.gitignore: -------------------------------------------------------------------------------- 1 | nimcache 2 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRC_DIRS "./nimcache" 3 | INCLUDE_DIRS "" 4 | REQUIRES lwip newlib nvs_flash app_update) 5 | 6 | # set(C_COMPILE_OPTIONS "${C_COMPILE_OPTIONS} -Wno-error=unused-label") 7 | # list(APPEND C_COMPILE_OPTIONS "-Wno-error=unused-label ") 8 | 9 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-label APPEND) 10 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-discarded-qualifiers APPEND) 11 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-ignored-qualifiers APPEND) 12 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 19 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Wifi Example Configuration" 2 | 3 | config EXAMPLE_WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config EXAMPLE_WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "mypassword" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | endmenu -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/main/apps.nim: -------------------------------------------------------------------------------- 1 | import nesper 2 | import nesper/consts 3 | import nesper/general 4 | import nesper/events 5 | import nesper/tasks 6 | 7 | const APP_EVENT*: string = "APP_EVENT" 8 | 9 | type 10 | app_events_t* {.size: sizeof(cint).} = enum 11 | app_test = 0, 12 | app_add_all 13 | 14 | proc add_all*(arg: pointer; 15 | event_base: esp_event_base_t; 16 | event_id: int32; 17 | event_data: ptr seq[int] 18 | ) {.cdecl.} = 19 | echo("app: `add_all` event: " & repr(event_data)) 20 | # var data: seq[int] = cast[ptr seq[int]](event_data)[] 21 | var data: seq[int] = event_data[] 22 | echo("app: `add_all` data: " & $data) 23 | # echo("app: `add_all` event[]: " & repr(cast[ptr pointer](event_data))) 24 | echo("") 25 | 26 | # apploop.eventPost(APP_EVENT, app_add_all, addr(vals), sizeof(vals), 10000) 27 | 28 | # var pdata: ptr seq[int] = cast[ptr seq[int]](event_data) 29 | # echo("app: `add_all` event: ptr: " & repr(pdata)) 30 | # var data: seq[int] = pdata[] 31 | # echo("app: `add_all` event: data: " & $(data)) 32 | 33 | proc setup_app_task_loop*(): esp_event_loop_handle_t = 34 | var loop: esp_event_loop_handle_t 35 | var loop_args = 36 | esp_event_loop_args_t( 37 | queue_size: 10, 38 | task_name: "app loop", 39 | task_priority: 1, 40 | task_stack_size: 4096, 41 | task_core_id: 1) 42 | 43 | let ret = esp_event_loop_create(addr(loop_args), addr(loop)) 44 | if ret != ESP_OK: 45 | raise newEspError[EventError]("register: " & $esp_err_to_name(ret), ret) 46 | 47 | echo("run_app: running! Loop handle: " & repr(loop.pointer) & " ptr: " & $repr(loop)) 48 | loop.eventRegisterWith(APP_EVENT, app_add_all, add_all) 49 | 50 | return loop 51 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/main/nim.cfg: -------------------------------------------------------------------------------- 1 | --gc:arc 2 | --os:freertos 3 | --cpu:esp 4 | 5 | # --nimCache:"nimcache/" 6 | # --nimblePath:"nimble/" 7 | --nimble_path:"nimble/pkgs" 8 | 9 | -d:use_malloc 10 | -d:no_signal_handler 11 | 12 | --debugger:native 13 | --threads:on 14 | --tls_emulation:off 15 | --verbosity:2 16 | 17 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/main/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import nesper/events 4 | import apps 5 | import volatile 6 | import strutils 7 | import json 8 | 9 | const TAG = "server" 10 | const MaxRpcReceiveBuffer {.intdefine.}: int = 4096 11 | 12 | ## Note: 13 | ## Nim uses `when` compile time constructs 14 | ## these are like ifdef's in C and don't really have an equivalent in Python 15 | ## setting the flags can be done in the Makefile `simplewifi-rpc Makefile 16 | ## for example, to compile the example to use JSON, pass `-d:TcpJsonRpcServer` to Nim 17 | ## the makefile has several example already defined for convenience 18 | ## 19 | when defined(TcpJsonRpcServer): 20 | import nesper/servers/rpc/rpcsocket_json 21 | when defined(TcpMpackRpcQueueServer): 22 | import ota_rpc_example 23 | import nesper/servers/rpc/rpcsocket_queue_mpack 24 | elif not defined(TcpEchoServer): # This is the default 'msgpack' version -- set like this for nimsuggest 25 | import ota_rpc_example 26 | import nesper/servers/rpc/rpcsocket_mpack 27 | elif defined(TcpEchoServer): 28 | import nesper/servers/tcpsocket 29 | else: 30 | {.fatal: "Compile this program with an rpc strategy!".} 31 | 32 | 33 | when defined(TcpEchoServer): 34 | proc run_rpc_server*() = 35 | echo "starting server on port 5555" 36 | var msg = "echo: " 37 | startSocketServer[string](Port(5555), readHandler=echoReadHandler, writeHandler=nil, data=msg) 38 | 39 | else: 40 | 41 | # Setup RPC Server # 42 | proc run_rpc_server*() = 43 | 44 | # Setup an RPC router 45 | var rpcRouter: RpcRouter 46 | var rt = createRpcRouter(MaxRpcReceiveBuffer) 47 | 48 | rpc(rt, "hello") do(input: string) -> string: 49 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "hello", "params": ["world"]}' 50 | result = "Hello " & input 51 | 52 | rpc(rt, "add") do(a: int, b: int) -> int: 53 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "add", "params": [1, 2]}' 54 | result = a + b 55 | 56 | rpc(rt, "addAll") do(vals: seq[int]) -> int: 57 | # example: ./rpc_cli --ip:$IP -c:1 '{"method": "add", "params": [1, 2, 3, 4, 5]}' 58 | echo("run_rpc_server: done: " & repr(addr(vals))) 59 | result = 0 60 | for x in vals: 61 | result += x 62 | 63 | # this adds methods for Over-The-Air updates using RPC! 64 | # note, this isn't secured by default 65 | rpcRouter.addOTAMethods() 66 | 67 | echo "starting rpc server on port 5555" 68 | logi(TAG,"starting rpc server buffer size: %s", $(rt.buffer)) 69 | 70 | when defined(TcpMpackRpcQueueServer): 71 | # Starts a separate task on CPU_1 (e.g. the "App CPU") 72 | # This makes it reallly easy to add dedicated tasks to run on CPU_1 73 | startRpcQueueSocketServer(Port(5555), router=rt) 74 | else: 75 | # Starts RPC handler on the current task 76 | # Default for JSON, MsgPack, and TCP Echo 77 | startRpcSocketServer(Port(5555), router=rt) 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi-rpc/rpc_cli_test.nim: -------------------------------------------------------------------------------- 1 | ../../tests/rpc_cli_test.nim -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/CMakeLists.txt: -------------------------------------------------------------------------------- 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 | # (Not part of the boilerplate) 6 | 7 | 8 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) 9 | # set(EXTRA_COMPONENT_DIRS src) 10 | 11 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 12 | project(simple-nim-wifi) 13 | 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 19 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 20 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ESP_IDF_VERSION ?= ESP_IDF_V4_0 3 | # ESP_IDF_VERSION ?= ESP_IDF_V4_1 4 | 5 | all: clean build 6 | 7 | esp_v40: 8 | nim prepare main/wifi_example_main.nim -d:release -d:ESP_IDF_V4_0 && idf.py reconfigure 9 | 10 | esp_v41: 11 | nim prepare main/wifi_example_main.nim -d:release -d:ESP_IDF_V4_1 && idf.py reconfigure 12 | 13 | nim: 14 | nim prepare main/wifi_example_main.nim -d:release -d:$(ESP_IDF_VERSION) && idf.py reconfigure 15 | 16 | build: clean nim 17 | idf.py build 18 | 19 | clean: 20 | rm -Rf main/nimcache/ 21 | 22 | fullclean: clean 23 | rm -Rf build/ 24 | # idf.py fullclean 25 | 26 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/README.md: -------------------------------------------------------------------------------- 1 | # Nim ESP32 - Simple Wifi 2 | 3 | Simple example in Nim with wifi on ESP32 on FreeRTOS & LwIP. 4 | 5 | ## Building Example 6 | 7 | Install and configure [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html). Currently v4.1 is the default supported version for Nesper currently. 8 | 9 | Then: 10 | 11 | ```shell 12 | git clone https://github.com/elcritch/nesper 13 | cd esp-idf-examples/simplewifi/ 14 | . $ESP_IDF_DIR/export.sh # source esp-idf 15 | ``` 16 | 17 | Build Nim project: 18 | ```sh 19 | export WIFI_SSID="[SSID]" 20 | export WIFI_PASSWORD="[PASSWORD]" 21 | make 22 | ``` 23 | 24 | This compiles the Nim code and updates the ESP-IDF project files. You can then compile the ESP-IDF build by one of: 25 | 26 | ```sh 27 | idf.py build 28 | ``` 29 | 30 | ```sh 31 | make 32 | ``` 33 | 34 | This will build the project. Next use idf.py to flash and monitor: 35 | 36 | ```shell 37 | idf.py -p [port] flash 38 | idf.py -p [port] monitor 39 | ``` 40 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/config.nims: -------------------------------------------------------------------------------- 1 | import os, strutils 2 | 3 | task prepare, "Compile to C code": 4 | mkDir("./main/nimcache") 5 | let nimbasepath = selfExe().splitFile.dir.parentDir / "lib" / "nimbase.h" 6 | let nimcachepath = "main" / "nimcache" 7 | cpFile(nimbasepath, nimcachepath / "nimbase.h") 8 | let params = commandLineParams() 9 | let file = params[1] 10 | let rest = params[2..high(params)].join(" ") 11 | 12 | let wifi_ssid = getEnv("WIFI_SSID") 13 | let wifi_pass = getEnv("WIFI_PASSWORD") 14 | 15 | let wifidefs = 16 | if wifi_ssid != "" and wifi_pass != "": 17 | "-d:WIFI_SSID=$1 -d:WIFI_PASSWORD=$2 " % [wifi_ssid, wifi_pass] 18 | else: 19 | "" 20 | 21 | let 22 | cmd = "nim c --os:freertos --cpu:esp --nomain --nimcache:$1 --compileOnly -d:NimAppMain $4 $3 $2 " % 23 | [nimcachepath, file, rest, wifidefs] 24 | 25 | echo("cmd: " & cmd) 26 | exec(cmd) 27 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/main/.gitignore: -------------------------------------------------------------------------------- 1 | nimcache 2 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRC_DIRS "./nimcache" 3 | INCLUDE_DIRS "" 4 | REQUIRES lwip newlib nvs_flash) 5 | 6 | # set(C_COMPILE_OPTIONS "${C_COMPILE_OPTIONS} -Wno-error=unused-label") 7 | # list(APPEND C_COMPILE_OPTIONS "-Wno-error=unused-label ") 8 | 9 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-label APPEND) 10 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-discarded-qualifiers APPEND) 11 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-ignored-qualifiers APPEND) 12 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 19 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Wifi Example Configuration" 2 | 3 | config EXAMPLE_WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config EXAMPLE_WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "mypassword" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | endmenu -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/main/nim.cfg: -------------------------------------------------------------------------------- 1 | --gc:orc 2 | -d:nimAdaptiveOrc # important 3 | --os:freertos 4 | --cpu:esp 5 | --nimCache:"nimcache/" 6 | 7 | -d:use_malloc 8 | -d:no_signal_handler 9 | 10 | --debugger:native 11 | --threads:on 12 | --tls_emulation:off 13 | --verbosity:2 14 | 15 | -------------------------------------------------------------------------------- /esp-idf-examples/simplewifi/main/server.nim: -------------------------------------------------------------------------------- 1 | 2 | import asynchttpserver, asyncdispatch, net 3 | 4 | var count = 0 5 | 6 | proc cb*(req: Request) {.async.} = 7 | inc count 8 | echo "req #", count 9 | await req.respond(Http200, "Hello World from nim on ESP32\n") 10 | # GC_fullCollect() 11 | 12 | proc run_http_server*() {.exportc.} = 13 | echo "starting http server on port 8181" 14 | var server = newAsyncHttpServer() 15 | 16 | waitFor server.serve(Port(8181), cb) 17 | 18 | import nesper/esp/esp_timer 19 | 20 | proc example_cb*(arg: pointer) {.cdecl.} = 21 | echo "Done!" 22 | 23 | proc timer_test*(arg: pointer) {.cdecl.} = 24 | var x = "hello" 25 | 26 | var timer_handle = esp_timer_create_args_t( 27 | callback: example_cb, 28 | arg: x.cstring, 29 | dispatch_method: ESP_TIMER_TASK, 30 | name: "timer1") 31 | 32 | var timer1: esp_timer_handle_t 33 | 34 | discard esp_timer_create(addr timer_handle, addr timer1) 35 | discard esp_timer_start_periodic(timer1, 1000.uint64) 36 | 37 | 38 | when isMainModule: 39 | echo "running server" 40 | run_http_server() 41 | timer_test() 42 | 43 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_self_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # 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 | project(i2c-example) 7 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_self_test/Makefile: -------------------------------------------------------------------------------- 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 := i2c-example 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_self_test/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "i2c_example_main.c" 2 | INCLUDE_DIRS ".") -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_self_test/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/system/console/components) 6 | 7 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 8 | project(i2c-tools) 9 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/Makefile: -------------------------------------------------------------------------------- 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 := i2c-tools 7 | 8 | EXTRA_COMPONENT_DIRS = $(IDF_PATH)/examples/system/console/components 9 | 10 | include $(IDF_PATH)/make/project.mk 11 | 12 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/example_test.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | import ttfw_idf 4 | 5 | EXPECT_TIMEOUT = 20 6 | 7 | 8 | @ttfw_idf.idf_example_test(env_tag='Example_I2C_CCS811_SENSOR') 9 | def test_i2ctools_example(env, extra_data): 10 | # Get device under test, flash and start example. "i2ctool" must be defined in EnvConfig 11 | dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools', dut_class=ttfw_idf.ESP32DUT) 12 | dut.start_app() 13 | dut.expect("i2c-tools>", timeout=EXPECT_TIMEOUT) 14 | # Get i2c address 15 | dut.write("i2cdetect") 16 | dut.expect("5b", timeout=EXPECT_TIMEOUT) 17 | # Get chip ID 18 | dut.write("i2cget -c 0x5b -r 0x20 -l 1") 19 | dut.expect("0x81", timeout=EXPECT_TIMEOUT) 20 | # Reset sensor 21 | dut.write("i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A") 22 | dut.expect("OK", timeout=EXPECT_TIMEOUT) 23 | # Get status 24 | dut.write("i2cget -c 0x5b -r 0x00 -l 1") 25 | dut.expect_any("0x10", timeout=EXPECT_TIMEOUT) 26 | # Change work mode 27 | dut.write("i2cset -c 0x5b -r 0xF4") 28 | dut.expect("OK", timeout=EXPECT_TIMEOUT) 29 | dut.write("i2cset -c 0x5b -r 0x01 0x10") 30 | dut.expect("OK", timeout=EXPECT_TIMEOUT) 31 | # Get new status 32 | dut.write("i2cget -c 0x5b -r 0x00 -l 1") 33 | dut.expect_any("0x98", "0x90", timeout=EXPECT_TIMEOUT) 34 | 35 | 36 | if __name__ == '__main__': 37 | test_i2ctools_example() 38 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "i2ctools_example_main.c" 2 | "cmd_i2ctools.c" 3 | INCLUDE_DIRS ".") -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_STORE_HISTORY 4 | bool "Store command history in flash" 5 | default y 6 | help 7 | Linenoise line editing library provides functions to save and load 8 | command history. If this option is enabled, initalizes a FAT filesystem 9 | and uses it to store command history. 10 | endmenu 11 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/main/cmd_i2ctools.h: -------------------------------------------------------------------------------- 1 | /* cmd_i2ctools.h 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #pragma once 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | void register_i2ctools(void); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/main/i2ctools_example_main.c: -------------------------------------------------------------------------------- 1 | /* i2c-tools example 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "sdkconfig.h" 13 | #include "esp_log.h" 14 | #include "esp_console.h" 15 | #include "esp_vfs_fat.h" 16 | #include "cmd_system.h" 17 | #include "cmd_i2ctools.h" 18 | 19 | static const char *TAG = "i2c-tools"; 20 | 21 | #if CONFIG_EXAMPLE_STORE_HISTORY 22 | 23 | #define MOUNT_PATH "/data" 24 | #define HISTORY_PATH MOUNT_PATH "/history.txt" 25 | 26 | static void initialize_filesystem(void) 27 | { 28 | static wl_handle_t wl_handle; 29 | const esp_vfs_fat_mount_config_t mount_config = { 30 | .max_files = 4, 31 | .format_if_mount_failed = true 32 | }; 33 | esp_err_t err = esp_vfs_fat_spiflash_mount(MOUNT_PATH, "storage", &mount_config, &wl_handle); 34 | if (err != ESP_OK) { 35 | ESP_LOGE(TAG, "Failed to mount FATFS (%s)", esp_err_to_name(err)); 36 | return; 37 | } 38 | } 39 | #endif // CONFIG_EXAMPLE_STORE_HISTORY 40 | 41 | void app_main(void) 42 | { 43 | esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); 44 | #if CONFIG_EXAMPLE_STORE_HISTORY 45 | initialize_filesystem(); 46 | repl_config.history_save_path = HISTORY_PATH; 47 | #endif 48 | repl_config.prompt = "i2c-tools>"; 49 | // initialize console REPL environment 50 | ESP_ERROR_CHECK(esp_console_repl_init(&repl_config)); 51 | 52 | register_i2ctools(); 53 | register_system(); 54 | 55 | printf("\n ==============================================================\n"); 56 | printf(" | Steps to Use i2c-tools |\n"); 57 | printf(" | |\n"); 58 | printf(" | 1. Try 'help', check all supported commands |\n"); 59 | printf(" | 2. Try 'i2cconfig' to configure your I2C bus |\n"); 60 | printf(" | 3. Try 'i2cdetect' to scan devices on the bus |\n"); 61 | printf(" | 4. Try 'i2cget' to get the content of specific register |\n"); 62 | printf(" | 5. Try 'i2cset' to set the value of specific register |\n"); 63 | printf(" | 6. Try 'i2cdump' to dump all the register (Experiment) |\n"); 64 | printf(" | |\n"); 65 | printf(" ==============================================================\n\n"); 66 | 67 | // start console REPL 68 | ESP_ERROR_CHECK(esp_console_repl_start()); 69 | } 70 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/partitions_example.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 1M, 6 | storage, data, fat, , 1M, 7 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/i2c/i2c_tools/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # Reduce bootloader log verbosity 2 | CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y 3 | CONFIG_BOOTLOADER_LOG_LEVEL=2 4 | 5 | # Increase main task stack size 6 | CONFIG_ESP_MAIN_TASK_STACK_SIZE=7168 7 | 8 | # Enable filesystem 9 | CONFIG_PARTITION_TABLE_CUSTOM=y 10 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_example.csv" 11 | CONFIG_PARTITION_TABLE_FILENAME="partitions_example.csv" 12 | 13 | # Enable FreeRTOS stats formatting functions, needed for 'tasks' command 14 | CONFIG_FREERTOS_USE_TRACE_FACILITY=y 15 | CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y 16 | 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/nvs_rw_value/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/nvs_rw_value/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # 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 | project(nvs-rw-value) 7 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/nvs_rw_value/Makefile: -------------------------------------------------------------------------------- 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 := nvs-rw-value 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/nvs_rw_value/README.md: -------------------------------------------------------------------------------- 1 | # Non-Volatile Storage (NVS) Read and Write Example 2 | 3 | (See the README.md file in the upper level 'examples' directory for more information about examples.) 4 | 5 | This example demonstrates how to read and write a single integer value using NVS. 6 | 7 | In this example, value which is saved holds the number of ESP32 module restarts. Since it is written to NVS, the value is preserved between restarts. 8 | 9 | Example also shows how to check if read / write operation was successful, or certain value is not initialized in NVS. Diagnostic is provided in plain text to help track program flow and capture any issues on the way. 10 | 11 | Detailed functional description of NVS and API is provided in [documentation](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/storage/nvs_flash.html). 12 | 13 | Check another example *storage/nvs_rw_blob*, which shows how to read and write variable length binary data (blob). 14 | 15 | ## How to use example 16 | 17 | ### Hardware required 18 | 19 | This example does not require any special hardware, and can be run on any common development board. 20 | 21 | ### Build and flash 22 | 23 | Build the project and flash it to the board, then run monitor tool to view serial output: 24 | 25 | ``` 26 | idf.py -p PORT flash monitor 27 | ``` 28 | 29 | (To exit the serial monitor, type ``Ctrl-]``.) 30 | 31 | See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. 32 | 33 | ## Example Output 34 | 35 | First run: 36 | ``` 37 | Opening Non-Volatile Storage (NVS) handle... Done 38 | Reading restart counter from NVS ... The value is not initialized yet! 39 | Updating restart counter in NVS ... Done 40 | Committing updates in NVS ... Done 41 | 42 | Restarting in 10 seconds... 43 | Restarting in 9 seconds... 44 | Restarting in 8 seconds... 45 | Restarting in 7 seconds... 46 | Restarting in 6 seconds... 47 | Restarting in 5 seconds... 48 | Restarting in 4 seconds... 49 | Restarting in 3 seconds... 50 | Restarting in 2 seconds... 51 | Restarting in 1 seconds... 52 | Restarting in 0 seconds... 53 | Restarting now. 54 | ``` 55 | 56 | Subsequent runs: 57 | 58 | ``` 59 | Opening Non-Volatile Storage (NVS) handle... Done 60 | Reading restart counter from NVS ... Done 61 | Restart counter = 1 62 | Updating restart counter in NVS ... Done 63 | Committing updates in NVS ... Done 64 | 65 | Restarting in 10 seconds... 66 | Restarting in 9 seconds... 67 | Restarting in 8 seconds... 68 | Restarting in 7 seconds... 69 | Restarting in 6 seconds... 70 | Restarting in 5 seconds... 71 | Restarting in 4 seconds... 72 | Restarting in 3 seconds... 73 | Restarting in 2 seconds... 74 | Restarting in 1 seconds... 75 | Restarting in 0 seconds... 76 | Restarting now. 77 | ``` 78 | 79 | Restart counter will increment on each run. 80 | 81 | To reset the counter, erase the contents of flash memory using `idf.py erase_flash`, then upload the program again as described above. 82 | 83 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/nvs_rw_value/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "nvs_value_example_main.c" 2 | INCLUDE_DIRS ".") -------------------------------------------------------------------------------- /esp-idf-examples/untested/nvs_rw_value/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/CMakeLists.txt: -------------------------------------------------------------------------------- 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 | # (Not part of the boilerplate) 6 | # This example uses an extra component for common functions such as Wi-Fi and Ethernet connection. 7 | set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) 8 | # set(EXTRA_COMPONENT_DIRS nim) 9 | 10 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project(simpleeth) 12 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/README.md: -------------------------------------------------------------------------------- 1 | # Nim ESP32 - Hello Network 2 | 3 | Example repo for using Nim with ESP32 on FreeRTOS & LwIP. 4 | 5 | An example using only wifi is available at [simplewifi](simplewifi/), check out 6 | [its README](simplewifi/README.md) for instruction in how to build that if your 7 | board doesn't have an ethernet chip. 8 | 9 | 10 | # Building 11 | 12 | Install a devel version of the compiler. 13 | Then goto the `nim/` folder and do a `make`. This will generate Nim C output files using a local Makefile (not part of the ESP-IDF build system). 14 | 15 | Afterwards, do a `make menuconfig` in the main folder. You don't need to run a `make menuconfig` everytime after updating Nim, but only when Nim outputs a new Nim C file (e.g. you pull in a new Nim library, etc). This could be cleaned up in the future I'm sure. 16 | 17 | Once the generated Nim sources are registered with ESP-IDF's build system, then all you need to do is the standard `idf.py build` and upload steps. 18 | 19 | # Info 20 | 21 | Here's the Nim Forum thread: https://forum.nim-lang.org/t/6345 22 | 23 | The primary branch I'm using is here: https://github.com/elcritch/Nim/tree/devel-basic-freertos-network, it was already merged into 24 | devel. 25 | 26 | Beware, only ARC works as the other GC's need another memory backend. It's easy to add, but I removed it until the main FreeRTOS options are added in upstream. 27 | 28 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/config.nims: -------------------------------------------------------------------------------- 1 | import os 2 | import strutils 3 | import options 4 | 5 | task printlib, "Printout Nim library": 6 | switch("hints", "off") 7 | let nimbasepath = selfExe().splitFile.dir.parentDir / "lib" 8 | echo(nimbasepath) 9 | 10 | task copylib, "Copy nimbase.h to nimcache/": 11 | let nimbasepath = selfExe().splitFile.dir.parentDir / "lib" / "nimbase.h" 12 | cpFile(nimbasepath, "nimcache" / "nimbase.h") 13 | 14 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${COMPONENT_DIR}/nimcache/compile_main.sh ) 3 | 4 | # execute_process(COMMAND nim dump 2>&1 | grep 'lib$' | sort | tail -n1 | head -n1 OUTPUT_VARIABLE NIMLIB) 5 | execute_process(COMMAND nim printlib OUTPUT_VARIABLE NIMLIB) 6 | 7 | execute_process( 8 | COMMAND nim printlib 9 | COMMAND nim c --nimCache:${COMPONENT_DIR}/nimcache/ --noMain --genScript --compileOnly ${COMPONENT_DIR}/main.nim 10 | WORKING_DIRECTORY ${COMPONENT_DIR} 11 | COMMAND_ECHO STDOUT 12 | ) 13 | 14 | file(GLOB nim_sources ${COMPONENT_DIR}/nimcache/*.c ) 15 | 16 | message("NIMLIB::: " ${NIMLIB} ) 17 | list(APPEND SRCS ${nim_sources}) 18 | 19 | idf_component_register(SRCS "ethernet_example_main.c" ${nim_sources} 20 | INCLUDE_DIRS "" 21 | ) 22 | 23 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 24 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 25 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 26 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 27 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 28 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 29 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 30 | 31 | target_compile_options(${COMPONENT_LIB} PRIVATE -I${NIMLIB} ) 32 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/main.nim: -------------------------------------------------------------------------------- 1 | import asynchttpserver, asyncdispatch, net 2 | 3 | var count = 0 4 | 5 | proc cb*(req: Request) {.async.} = 6 | inc count 7 | echo "req #", count 8 | await req.respond(Http200, "Hello World from nim on ESP32: " & $count) 9 | 10 | proc run_http_server*() {.exportc.} = 11 | echo "starting http server on port 8181" 12 | var server = newAsyncHttpServer() 13 | 14 | waitFor server.serve(Port(8181), cb) 15 | 16 | when isMainModule: 17 | echo "running server" 18 | run_http_server() 19 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nim.cfg: -------------------------------------------------------------------------------- 1 | --gc:orc 2 | --os:freertos 3 | --cpu:esp 4 | -d:use_malloc 5 | -d:no_signal_handler 6 | --debugger:native 7 | --threads:on 8 | --tls_emulation:off 9 | --verbosity:2 10 | -d:nimAdaptiveOrc 11 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/algorithm.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/algorithm.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/ansi_c.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/ansi_c.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/assertions.ndi: -------------------------------------------------------------------------------- 1 | failedAssertImpl failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A /Users/elcritch/.asdf/installs/nim/devel/lib/system/assertions.nim 25 5 2 | raiseAssert raiseAssert__gpGJG5CoQzE64skFd9bPG7A /Users/elcritch/.asdf/installs/nim/devel/lib/system/assertions.nim 22 5 3 | msg msg /Users/elcritch/.asdf/installs/nim/devel/lib/system/assertions.nim 22 18 4 | sysFatal sysFatal__3MqFiUWEqQBXOyOla7Oh4gassertions /Users/elcritch/.asdf/installs/nim/devel/lib/system/fatal.nim 48 7 5 | message message /Users/elcritch/.asdf/installs/nim/devel/lib/system/fatal.nim 48 35 6 | blitTmp blitTmp /Users/elcritch/.asdf/installs/nim/devel/lib/system/fatal.nim 49 29 7 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/system/fatal.nim 49 4 8 | src src /Users/elcritch/.asdf/installs/nim/devel/lib/system/fatal.nim 49 4 9 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/asyncstreams.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/asyncstreams.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/base64.ndi: -------------------------------------------------------------------------------- 1 | cb64 cb64__Yyfw6lxoVbgtswIxGnGnUQ /Users/elcritch/.asdf/installs/nim/devel/lib/pure/base64.nim 72 2 2 | cb64safe cb64safe__q0GCLBVULDDeEKBBmNHUGw /Users/elcritch/.asdf/installs/nim/devel/lib/pure/base64.nim 73 2 3 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/bitops.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/bitops.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/cstrutils.ndi: -------------------------------------------------------------------------------- 1 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 60 0 2 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 73 6 3 | j j /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 74 6 4 | aa aa /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 78 8 5 | toLowerAscii toLowerAscii__pmRDqs9aWD4OvTyTVpsA9aKgcstrutils /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 16 5 6 | c c /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 16 18 7 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 16 0 8 | bb bb /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 79 8 9 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 45 2 10 | slen slen /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 52 8 11 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 53 8 12 | j j /Users/elcritch/.asdf/installs/nim/devel/lib/pure/cstrutils.nim 54 8 13 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/system/comparisons.nim 187 11 14 | y y /Users/elcritch/.asdf/installs/nim/devel/lib/system/comparisons.nim 187 14 15 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/system/comparisons.nim 187 0 16 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/deques.ndi: -------------------------------------------------------------------------------- 1 | len len__DQsAQkVd9bSjHr0J9c6igsXgdeques /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 105 5 2 | addLast addLast__AjJTTDDB8sceZqEDAtFWRA /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 320 5 3 | expandIfNeeded expandIfNeeded__1x32uzSajoB9apwB9bmROoXg /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 285 5 4 | deq deq /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 285 23 5 | correctSize`gensym178 correctSizeX60gensym178_ /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 70 6 6 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim 175 21 7 | cap cap /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 287 6 8 | n n /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 289 8 9 | len len /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 638 16 10 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 290 8 11 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 291 8 12 | i i_2 /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 245 6 13 | c c /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 246 6 14 | i i_3 /Users/elcritch/.asdf/installs/nim/devel/lib/system/iterators_1.nim 106 8 15 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/system/seqs_v2.nim 114 20 16 | src src /Users/elcritch/.asdf/installs/nim/devel/lib/system/seqs_v2.nim 114 20 17 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/system/threads.nim 94 2 18 | src src /Users/elcritch/.asdf/installs/nim/devel/lib/system/threads.nim 94 2 19 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/system/seqs_v2.nim 114 20 20 | src src /Users/elcritch/.asdf/installs/nim/devel/lib/system/seqs_v2.nim 114 20 21 | =sink eqsink___dCzbZ5M07kKVDT8cB39bLkw /Users/elcritch/.asdf/installs/nim/devel/lib/pure/asyncdispatch.nim 1143 61 22 | initDeque initDeque__BXrhNE9b8tXeZLatBly0G2w /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 79 5 23 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 79 0 24 | correctSize`gensym6 correctSizeX60gensym6_ /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 70 6 25 | popFirst popFirst__02glLbPGryNNvp0hDMcWhQdeques /Users/elcritch/.asdf/installs/nim/devel/lib/pure/collections/deques.nim 423 5 26 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/dollars.ndi: -------------------------------------------------------------------------------- 1 | $ dollar___7AQ19bV7URzlCmoau9c79cWbw /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 144 5 2 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 144 0 3 | collectionToString collectionToString__bl0bSVWGY9awnrUbJL6olrQ /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 117 5 4 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 117 27 5 | prefix prefix /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 117 33 6 | separator separator /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 117 41 7 | suffix suffix /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 117 52 8 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 117 0 9 | firstElement firstElement /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 119 6 10 | value value /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 120 6 11 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/system/iterators.nim 199 6 12 | L L /Users/elcritch/.asdf/installs/nim/devel/lib/system/iterators.nim 200 6 13 | s s /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 19 14 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 34 15 | $ dollar___WrYXAVecSG9ckDg0dVMv4oQ /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 86 5 16 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 86 0 17 | count count /Users/elcritch/.asdf/installs/nim/devel/lib/system/dollars.nim 96 6 18 | s s /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 19 19 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 34 20 | s s /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 19 21 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 34 22 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/formatfloat.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/formatfloat.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/hashes.ndi: -------------------------------------------------------------------------------- 1 | hash hash__6PCYkKlCNhq9cnRLnqWKkwQ /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 285 5 2 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 285 0 3 | murmurHash murmurHash__CiCiZV9c7F9alrF1xV3QD1ag /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 220 5 4 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 220 16 5 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 220 0 6 | size size /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 229 4 7 | stepSize stepSize /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 230 4 8 | n n /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 231 4 9 | h1 h1 /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 233 4 10 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 234 4 11 | k1 k1 /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 238 8 12 | rotl32 rotl32__7D6LSWJ2oWPOMqrc3axXgwhashes /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 217 5 13 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 217 12 14 | r r /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 217 23 15 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 217 0 16 | k1 k1_2 /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 257 6 17 | rem rem /Users/elcritch/.asdf/installs/nim/devel/lib/pure/hashes.nim 258 6 18 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/io.ndi: -------------------------------------------------------------------------------- 1 | s s /Users/elcritch/.asdf/installs/nim/devel/lib/system/io.nim 790 10 2 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/system/iterators.nim 8 6 3 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/system/chcks.nim 22 22 4 | n n /Users/elcritch/.asdf/installs/nim/devel/lib/system/chcks.nim 22 25 5 | setInheritable setInheritable__avyDiy1HdQrfaD3Ql9b63EQ /Users/elcritch/.asdf/installs/nim/devel/lib/system/io.nim 330 7 6 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/system/io.nim 330 2 7 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/iterators.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/iterators.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/macros.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/macros.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/math.ndi: -------------------------------------------------------------------------------- 1 | nextPowerOfTwo nextPowerOfTwo__v2qC0V55wqa9bmqc7eHTz8A /Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim 175 5 2 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim 175 0 3 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/memory.ndi: -------------------------------------------------------------------------------- 1 | nimSetMem nimSetMem__JE6t4x7Z3v2iVz27Nx0MRAmemory /Users/elcritch/.asdf/installs/nim/devel/lib/system/memory.nim 22 5 2 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/miscdollars.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/miscdollars.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/monotimes.ndi: -------------------------------------------------------------------------------- 1 | getMonoTime getMonoTime__QkEugs2Q2iFK9b83sl2B6wA /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 86 5 2 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 86 0 3 | ts ts /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 103 8 4 | <= lteq___3KIZNy1Wl5YmzvX5mBokLA /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 140 5 5 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 140 0 6 | == eqeq___3KIZNy1Wl5YmzvX5mBokLA_2 /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 144 5 7 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 144 0 8 | < lt___3KIZNy1Wl5YmzvX5mBokLA_3 /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 136 5 9 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 136 0 10 | - minus___p9cBm7joedh4BwcboQ3HMVQ /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 124 5 11 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/std/monotimes.nim 124 0 12 | nanoseconds nanoseconds /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 579 19 13 | microseconds microseconds /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 579 32 14 | milliseconds milliseconds /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 579 46 15 | seconds seconds /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 580 19 16 | minutes minutes /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 580 28 17 | hours hours /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 580 37 18 | days days /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 580 44 19 | weeks weeks /Users/elcritch/.asdf/installs/nim/devel/lib/pure/times.nim 580 50 20 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/net.ndi: -------------------------------------------------------------------------------- 1 | toCInt toCInt__jdGcpZaHg8FvJJ7dgE9b75w /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 1183 5 2 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 1183 0 3 | isDisconnectionError isDisconnectionError__XxybNfLJKXhPAkMhmPhNzQ /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 193 5 4 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 193 0 5 | toOSFlags toOSFlags__o0FbRanOjUQrx1x33AiBQA /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 211 5 6 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 211 0 7 | f f /Users/elcritch/.asdf/installs/nim/devel/lib/pure/net.nim 213 6 8 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/system/iterators.nim 52 6 9 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/options.ndi: -------------------------------------------------------------------------------- 1 | some some__m1OjIFHE7x2EQs5RG5pOEAoptions /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 101 5 2 | isNone isNone__7pvN3mkdmg4OQ2gDC9bkRTwoptions /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 157 5 3 | get get__jtj67WAh54gVPnaAYB1k9bgoptions /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 170 5 4 | =destroy eqdestroy___A0WfCorq86FTzHcRt3nkKw /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 5 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 6 | =trace eqtrace___umVFJaf5SzQNp0Wwgc2bRw /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 7 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 8 | env env /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 9 | =dispose eqdispose___A0WfCorq86FTzHcRt3nkKw_2 /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 10 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/pure/options.nim 185 22 11 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/os.ndi: -------------------------------------------------------------------------------- 1 | environment environment__mlhK49b6YMgc9cgrcYkKq9a3g /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/osenv.nim 21 2 2 | envComputed envComputed__LLyFo9bsdu1ZXMDvAe8DhrQ /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/osenv.nim 20 2 3 | osLastError osLastError__9bUWNxbcGnToMWA9b79aTXLIw /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 97 5 4 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 97 0 5 | osErrorMsg osErrorMsg__33xViSVWAmDrexoKkLfMhg /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 18 5 6 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 18 0 7 | raiseOSError raiseOSError__CWyPYlyH9a6rAuZckFyVxPA /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 89 5 8 | newOSError newOSError__JXEuze9ctNbkn51HYBflQLg /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 60 5 9 | errorCode errorCode /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 61 2 10 | additionalInfo additionalInfo /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 61 26 11 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 60 0 12 | e e /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 78 6 13 | =destroy eqdestroy___UZ66vRTZhSc7gx3IAuMd6Q /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 78 6 14 | dest dest /Users/elcritch/.asdf/installs/nim/devel/lib/pure/includes/oserr.nim 78 6 15 | s s /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2581 11 16 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2581 22 17 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2581 0 18 | s s /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 19 19 | x x /Users/elcritch/.asdf/installs/nim/devel/lib/system.nim 2823 34 20 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/osseps.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/osseps.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/parseutils.ndi: -------------------------------------------------------------------------------- 1 | parseUntil parseUntil__yxs3WjxMSDtXEyiLC9aqFCAparseutils /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 317 5 2 | fastSubstr fastSubstr__a88zu6ztJ3SBDTHcnqFjsg /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 313 5 3 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 315 6 4 | i i_2 /Users/elcritch/.asdf/installs/nim/devel/lib/system/iterators_1.nim 106 8 5 | parseWhile parseWhile__aIOGZyeHx2rHC71Dcc2SCwparseutils /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 382 5 6 | skipIgnoreCase skipIgnoreCase__Z630VYBL4pZDWlOyn05K5w /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 270 5 7 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 270 0 8 | toLower toLower__eK9b2e49aPf4wAIdUwhbmZsQparseutils /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 59 5 9 | c c /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 59 13 10 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 59 0 11 | parseSaturatedNatural parseSaturatedNatural__hGWFPKYRsDcYFCjZLM9acZw /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 480 5 12 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 480 0 13 | i i /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 490 6 14 | c c /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 495 10 15 | parseUntil parseUntil__jfFErPNXs9cw9bvuw3hS0GVAparseutils /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 336 5 16 | skipWhitespace skipWhitespace__6WuCTfsk2bOGNtGSxg9cZWAparseutils /Users/elcritch/.asdf/installs/nim/devel/lib/pure/parseutils.nim 244 5 17 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/pathnorm.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/pathnorm.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/posix.ndi: -------------------------------------------------------------------------------- 1 | SOMAXCONN SOMAXCONN__0XWtgJz0atYHiEz9b9aVOcQg /Users/elcritch/.asdf/installs/nim/devel/lib/posix/posix_freertos_consts.nim 417 4 2 | MAP_POPULATE MAP_POPULATE__VA0iC4AP6fJAacff09cx89ag /Users/elcritch/.asdf/installs/nim/devel/lib/posix/posix_other.nim 600 4 3 | IN6_IS_ADDR_V4MAPPED IN6_IS_ADDR_V4MAPPED__6KWoyJxz9c9cfnUA9b5aeMx3w /Users/elcritch/.asdf/installs/nim/devel/lib/posix/posix.nim 966 7 4 | result result /Users/elcritch/.asdf/installs/nim/devel/lib/posix/posix.nim 966 2 5 | bits32 bits32 /Users/elcritch/.asdf/installs/nim/devel/lib/posix/posix.nim 967 8 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/repr_v2.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/repr_v2.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/sets.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/sets.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/since.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/since.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/ssl_certs.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/ssl_certs.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/ssl_config.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/ssl_config.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/stacktraces.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/stacktraces.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/stdlib_base64.nim.c: -------------------------------------------------------------------------------- 1 | /* Generated by Nim Compiler v1.3.7 */ 2 | /* (c) 2020 Andreas Rumpf */ 3 | /* The generated code is subject to the original license. */ 4 | #define NIM_INTBITS 32 5 | 6 | /* section: NIM_merge_HEADERS */ 7 | 8 | #include "nimbase.h" 9 | #undef LANGUAGE_C 10 | #undef MIPSEB 11 | #undef MIPSEL 12 | #undef PPC 13 | #undef R3000 14 | #undef R4000 15 | #undef i386 16 | #undef linux 17 | #undef mips 18 | #undef near 19 | #undef far 20 | #undef powerpc 21 | #undef unix 22 | 23 | /* section: NIM_merge_FRAME_DEFINES */ 24 | #define nimfr_(x, y) 25 | #define nimln_(x, y) 26 | 27 | /* section: NIM_merge_TYPES */ 28 | typedef NIM_CHAR tyArray__2cWMSJoP9cqN4yIK0ILkQaQ[64]; 29 | 30 | /* section: NIM_merge_VARS */ 31 | N_LIB_PRIVATE NIM_CONST tyArray__2cWMSJoP9cqN4yIK0ILkQaQ cb64__Yyfw6lxoVbgtswIxGnGnUQ = {65, 32 | 66, 33 | 67, 34 | 68, 35 | 69, 36 | 70, 37 | 71, 38 | 72, 39 | 73, 40 | 74, 41 | 75, 42 | 76, 43 | 77, 44 | 78, 45 | 79, 46 | 80, 47 | 81, 48 | 82, 49 | 83, 50 | 84, 51 | 85, 52 | 86, 53 | 87, 54 | 88, 55 | 89, 56 | 90, 57 | 97, 58 | 98, 59 | 99, 60 | 100, 61 | 101, 62 | 102, 63 | 103, 64 | 104, 65 | 105, 66 | 106, 67 | 107, 68 | 108, 69 | 109, 70 | 110, 71 | 111, 72 | 112, 73 | 113, 74 | 114, 75 | 115, 76 | 116, 77 | 117, 78 | 118, 79 | 119, 80 | 120, 81 | 121, 82 | 122, 83 | 48, 84 | 49, 85 | 50, 86 | 51, 87 | 52, 88 | 53, 89 | 54, 90 | 55, 91 | 56, 92 | 57, 93 | 43, 94 | 47} 95 | ; 96 | N_LIB_PRIVATE NIM_CONST tyArray__2cWMSJoP9cqN4yIK0ILkQaQ cb64safe__q0GCLBVULDDeEKBBmNHUGw = {65, 97 | 66, 98 | 67, 99 | 68, 100 | 69, 101 | 70, 102 | 71, 103 | 72, 104 | 73, 105 | 74, 106 | 75, 107 | 76, 108 | 77, 109 | 78, 110 | 79, 111 | 80, 112 | 81, 113 | 82, 114 | 83, 115 | 84, 116 | 85, 117 | 86, 118 | 87, 119 | 88, 120 | 89, 121 | 90, 122 | 97, 123 | 98, 124 | 99, 125 | 100, 126 | 101, 127 | 102, 128 | 103, 129 | 104, 130 | 105, 131 | 106, 132 | 107, 133 | 108, 134 | 109, 135 | 110, 136 | 111, 137 | 112, 138 | 113, 139 | 114, 140 | 115, 141 | 116, 142 | 117, 143 | 118, 144 | 119, 145 | 120, 146 | 121, 147 | 122, 148 | 48, 149 | 49, 150 | 50, 151 | 51, 152 | 52, 153 | 53, 154 | 54, 155 | 55, 156 | 56, 157 | 57, 158 | 45, 159 | 95} 160 | ; 161 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/stdlib_math.nim.c: -------------------------------------------------------------------------------- 1 | /* Generated by Nim Compiler v1.3.7 */ 2 | /* (c) 2020 Andreas Rumpf */ 3 | /* The generated code is subject to the original license. */ 4 | #define NIM_INTBITS 32 5 | 6 | /* section: NIM_merge_HEADERS */ 7 | 8 | #include "nimbase.h" 9 | #undef LANGUAGE_C 10 | #undef MIPSEB 11 | #undef MIPSEL 12 | #undef PPC 13 | #undef R3000 14 | #undef R4000 15 | #undef i386 16 | #undef linux 17 | #undef mips 18 | #undef near 19 | #undef far 20 | #undef powerpc 21 | #undef unix 22 | 23 | /* section: NIM_merge_FRAME_DEFINES */ 24 | #define nimfr_(x, y) 25 | #define nimln_(x, y) 26 | 27 | /* section: NIM_merge_PROCS */ 28 | 29 | #line 175 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 30 | N_LIB_PRIVATE N_NIMCALL(NI, nextPowerOfTwo__v2qC0V55wqa9bmqc7eHTz8A)(NI x) { NI result; result = (NI)0; 31 | #line 187 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 32 | 33 | #line 187 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 34 | result = (NI)(x - ((NI) 1)); 35 | #line 191 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 36 | 37 | #line 191 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 38 | 39 | #line 191 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 40 | result = (NI)(result | (NI)((NI32)(result) >> (NU32)(((NI) 16)))); 41 | #line 193 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 42 | 43 | #line 193 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 44 | 45 | #line 193 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 46 | result = (NI)(result | (NI)((NI32)(result) >> (NU32)(((NI) 8)))); 47 | #line 194 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 48 | 49 | #line 194 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 50 | 51 | #line 194 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 52 | result = (NI)(result | (NI)((NI32)(result) >> (NU32)(((NI) 4)))); 53 | #line 195 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 54 | 55 | #line 195 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 56 | 57 | #line 195 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 58 | result = (NI)(result | (NI)((NI32)(result) >> (NU32)(((NI) 2)))); 59 | #line 196 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 60 | 61 | #line 196 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 62 | 63 | #line 196 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 64 | result = (NI)(result | (NI)((NI32)(result) >> (NU32)(((NI) 1)))); 65 | #line 197 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 66 | 67 | #line 197 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 68 | 69 | #line 197 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 70 | 71 | #line 197 "/Users/elcritch/.asdf/installs/nim/devel/lib/pure/math.nim" 72 | result += (NI)(((NI) 1) + (x <= ((NI) 0))); return result;} 73 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/typetraits.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/typetraits.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/unicode.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/unicode.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/main/nimcache/widestrs.ndi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/simpleeth/main/nimcache/widestrs.ndi -------------------------------------------------------------------------------- /esp-idf-examples/untested/simpleeth/sdkconfig.ci: -------------------------------------------------------------------------------- 1 | CONFIG_MDNS_RESOLVE_TEST_SERVICES=y 2 | CONFIG_MDNS_ADD_MAC_TO_HOSTNAME=y 3 | CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y 4 | CONFIG_EXAMPLE_CONNECT_ETHERNET=y 5 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | src/nimcache/ 3 | src/server 4 | src/localnim/ 5 | .env 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # 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 | project(spi_eeprom) 7 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/Makefile: -------------------------------------------------------------------------------- 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 := spi_eeprom 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/README.md: -------------------------------------------------------------------------------- 1 | ## SPI master half duplex EEPROM example 2 | 3 | This code demonstrates how to use the SPI master half duplex mode to read/write a AT93C46D 4 | EEPROM (8-bit mode). There is also an Kconfig option `EXAMPLE_USE_SPI1_PINS` allowing use the 5 | SPI1 (bus with code Flash connected on official modules). 6 | 7 | ### Connections 8 | 9 | For different chip and host used, the connections may be different. 10 | 11 | | | ESP32 | ESP32 | ESP32S2 | 12 | | ---- | ----- | ----- | ------- | 13 | | Host | SPI1 | HSPI | FSPI | 14 | | VCC | 3.3V | 3.3V | 3.3V | 15 | | GND | GND | GND | GND | 16 | | DO | 7 | 18 | 37 | 17 | | DI | 8 | 23 | 35 | 18 | | SK | 6 | 19 | 36 | 19 | | CS | 13 | 13 | 34 | 20 | | ORG | GND | GND | GND | 21 | 22 | ### Notes 23 | 24 | If you meet timeout issues, please check your connections. -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/components/eeprom/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "spi_eeprom.c" 2 | LDFRAGMENTS "linker.lf" 3 | INCLUDE_DIRS ".") 4 | 5 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/components/eeprom/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | COMPONENT_ADD_LDFRAGMENTS += linker.lf 7 | COMPONENT_ADD_INCLUDEDIRS := . 8 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/components/eeprom/linker.lf: -------------------------------------------------------------------------------- 1 | # This example supports running on the SPI1 bus, which is shared with SPI flash accessed by the 2 | # cache. When doing transaction on SPI1 bus, data cannot be fetched from the flash, so all the data 3 | # used during this time should be put into the internal RAM. 4 | 5 | [mapping:eeprom] 6 | archive: libeeprom.a 7 | entries: 8 | * (noflash) 9 | 10 | [mapping:ext_driver] 11 | archive: libdriver.a 12 | entries: 13 | # gpio_set_level, gpio_get_level, gpio_context, _gpio_hal, etc... 14 | gpio (noflash) 15 | 16 | [mapping:ext_soc] 17 | archive: libsoc.a 18 | entries: 19 | gpio_hal (noflash) 20 | 21 | [mapping:ext_newlib] 22 | archive: libnewlib.a 23 | entries: 24 | time:usleep (noflash) -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs "spi_eeprom_main.c") 2 | 3 | idf_component_register(SRCS ${srcs} 4 | INCLUDE_DIRS ".") 5 | 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_SPI1_PINS 4 | bool "The example uses SPI1 shared pins for EEPROM connection" 5 | default n 6 | depends on SPI_FLASH_SHARE_SPI1_BUS 7 | help 8 | Enable this option will make the EEPROM use SPI1 pins, which is shared with the main 9 | flash chip. 10 | 11 | Currently this example hasn't supported SPI1 pins on other chips yet. 12 | 13 | config EXAMPLE_INTR_USED 14 | bool "Use the interrupt to detect the eeprom busy" 15 | default y 16 | depends on !EXAMPLE_USE_SPI1_PINS 17 | help 18 | Enable this option will allow the example to be blocked while the EEPROM is working 19 | in progress, and unblocked by GPIO interrupt. Otherwise the example will keep polling 20 | until the EEPROM is idle. 21 | 22 | config EXAMPLE_5V_COMMANDS 23 | bool "The EEPROM is supplied by 5V power" 24 | default n 25 | help 26 | The Erase_All and Write_All commands of EEPROM are only supported when EEPROM is 27 | supplied by 5V power. Enable this to use those two commands. 28 | 29 | But please note that ESP chips don't support 5V IO, you need to add external 30 | level-shifting circuits between ESP chip to the EEPROM. 31 | 32 | endmenu 33 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/hd_eeprom/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # 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 | project(spi_master) 7 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/Makefile: -------------------------------------------------------------------------------- 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 := spi_master 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/README.md: -------------------------------------------------------------------------------- 1 | ## SPI master example 2 | 3 | This code displays some simple graphics with varying pixel colors on the 320x240 LCD on an ESP-WROVER-KIT board. 4 | 5 | If you want to adapt this example to another type of display or pinout, check [main/spi_master_example_main.c] for comments with some implementation details. 6 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/components/tjpgd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(tjpgd_srcs "src/tjpgd.c") 2 | 3 | idf_component_register(SRCS "${tjpgd_srcs}" 4 | INCLUDE_DIRS "include") 5 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/components/tjpgd/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | 3 | COMPONENT_SRCDIRS := src 4 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs "pretty_effect.c" 2 | "spi_master_example_main.c" 3 | ) 4 | 5 | # Only ESP32 has enough memory to do jpeg decoding 6 | if(IDF_TARGET STREQUAL "esp32") 7 | list(APPEND srcs "decode_image.c") 8 | endif() 9 | 10 | idf_component_register(SRCS ${srcs} 11 | INCLUDE_DIRS "." 12 | EMBED_FILES image.jpg) 13 | 14 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | choice LCD_TYPE 4 | prompt "LCD module type" 5 | default LCD_TYPE_AUTO 6 | help 7 | The type of LCD on the evaluation board. 8 | 9 | config LCD_TYPE_AUTO 10 | bool "Auto detect" 11 | config LCD_TYPE_ST7789V 12 | bool "ST7789V (WROVER Kit v2 or v3)" 13 | config LCD_TYPE_ILI9341 14 | bool "ILI9341 (WROVER Kit v1 or DevKitJ v1)" 15 | endchoice 16 | 17 | config LCD_OVERCLOCK 18 | bool 19 | prompt "Run LCD at higher clock speed than allowed" 20 | default "n" 21 | help 22 | The ILI9341 and ST7789 specify that the maximum clock speed for the SPI interface is 10MHz. However, 23 | in practice the driver chips work fine with a higher clock rate, and using that gives a better framerate. 24 | Select this to try using the out-of-spec clock rate. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | 7 | #Compile image file into the resulting firmware binary 8 | COMPONENT_EMBED_FILES := image.jpg 9 | -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/main/decode_image.h: -------------------------------------------------------------------------------- 1 | /* 2 | This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | 4 | Unless required by applicable law or agreed to in writing, this 5 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | 9 | #pragma once 10 | #include 11 | #include "esp_err.h" 12 | 13 | /** 14 | * @brief Decode the jpeg ``image.jpg`` embedded into the program file into pixel data. 15 | * 16 | * @param pixels A pointer to a pointer for an array of rows, which themselves are an array of pixels. 17 | * Effectively, you can get the pixel data by doing ``decode_image(&myPixels); pixelval=myPixels[ypos][xpos];`` 18 | * @return - ESP_ERR_NOT_SUPPORTED if image is malformed or a progressive jpeg file 19 | * - ESP_ERR_NO_MEM if out of memory 20 | * - ESP_OK on succesful decode 21 | */ 22 | esp_err_t decode_image(uint16_t ***pixels); -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/main/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/esp-idf-examples/untested/spi_master/lcd/main/image.jpg -------------------------------------------------------------------------------- /esp-idf-examples/untested/spi_master/lcd/main/pretty_effect.h: -------------------------------------------------------------------------------- 1 | /* 2 | This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | 4 | Unless required by applicable law or agreed to in writing, this 5 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | 9 | #pragma once 10 | #include 11 | #include "esp_err.h" 12 | 13 | 14 | /** 15 | * @brief Calculate the effect for a bunch of lines. 16 | * 17 | * @param dest Destination for the pixels. Assumed to be LINECT * 320 16-bit pixel values. 18 | * @param line Starting line of the chunk of lines. 19 | * @param frame Current frame, used for animation 20 | * @param linect Amount of lines to calculate 21 | */ 22 | void pretty_effect_calc_lines(uint16_t *dest, int line, int frame, int linect); 23 | 24 | 25 | /** 26 | * @brief Initialize the effect 27 | * 28 | * @return ESP_OK on success, an error from the jpeg decoder otherwise. 29 | */ 30 | esp_err_t pretty_effect_init(void); 31 | -------------------------------------------------------------------------------- /nesper.nimble: -------------------------------------------------------------------------------- 1 | # Package 2 | 3 | version = "0.6.1" 4 | author = "Jaremy Creechley" 5 | description = "Nim wrappers for ESP-IDF (ESP32)" 6 | license = "Apache-2.0" 7 | srcDir = "src" 8 | 9 | 10 | # Dependencies 11 | requires "nim >= 1.4.0" 12 | requires "msgpack4nim >= 0.3.1" 13 | requires "stew >= 0.1.0" 14 | # requires "bytesequtils >= 1.1" 15 | # requires "nimcrypto >= 1.0" 16 | 17 | 18 | # Tasks 19 | import os, strutils 20 | 21 | proc general_tests() = 22 | # Regular tests 23 | for dtest in listFiles("tests/"): 24 | if dtest.startsWith("t") and dtest.endsWith(".nim"): 25 | echo("Testing: " & $dtest) 26 | exec "nim c --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest] 27 | 28 | proc driver_tests() = 29 | # Driver tests 30 | for dtest in listFiles("tests/driver/"): 31 | if dtest.startsWith("t") and dtest.endsWith(".nim"): 32 | exec "nim c --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest] 33 | 34 | proc storage_tests() = 35 | # Driver tests 36 | for dtest in listFiles("tests/storage/"): 37 | if dtest.startsWith("t") and dtest.endsWith(".nim"): 38 | exec "nim c --compileOnly:on --cincludes:c_headers/mock/ --os:freertos $1" % [dtest] 39 | 40 | proc exec_tests() = 41 | # Exec tests 42 | for dtest in listFiles("tests/exec_tests/"): 43 | if dtest.startsWith("t") and dtest.endsWith(".nim"): 44 | exec "nim c -r --cincludes:$2/tests/c_headers/mock/ $1" % [dtest, getCurrentDir()] 45 | 46 | task test, "Runs the test suite": 47 | general_tests() 48 | driver_tests() 49 | storage_tests() 50 | exec_tests() 51 | 52 | task test_general, "Runs the test suite": 53 | general_tests() 54 | task test_drivers, "Runs the test suite": 55 | driver_tests() 56 | task test_storage, "Runs the test suite": 57 | storage_tests() 58 | task test_execs, "Runs the test suite": 59 | exec_tests() 60 | 61 | # exec "nim c -r tests/trouter.nim" 62 | 63 | 64 | -------------------------------------------------------------------------------- /nim.cfg: -------------------------------------------------------------------------------- 1 | --gc:arc 2 | --os:freertos 3 | -d:use_malloc 4 | -d:no_signal_handler 5 | --debugger:native 6 | --threads:on 7 | --tls_emulation:off 8 | --hint:conf:off 9 | --hint:SuccessX:off 10 | 11 | -------------------------------------------------------------------------------- /src/nesper.nim: -------------------------------------------------------------------------------- 1 | # This is just an example to get you started. A typical library package 2 | # exports the main API in this file. Note that you cannot rename this file 3 | # but you can remove it if you wish. 4 | 5 | import nesper/consts 6 | import nesper/general 7 | import nesper/esp/esp_log 8 | 9 | export consts 10 | export general 11 | export esp_log 12 | 13 | #{.emit: """/*TYPESECTION*/ 14 | ##include 15 | #""".} 16 | 17 | # type 18 | # Submodule* = object 19 | # name*: string 20 | 21 | # proc initSubmodule*(): Submodule = 22 | # ## Initialises a new ``Submodule`` object. 23 | # Submodule(name: "Anonymous") 24 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/CMakeLists.txt: -------------------------------------------------------------------------------- 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 | # (Not part of the boilerplate) 6 | 7 | set(EXTRA_COMPONENT_DIRS $$ENV{IDF_PATH}/examples/common_components/protocol_examples_common) 8 | # set(EXTRA_COMPONENT_DIRS src) 9 | 10 | include($$ENV{IDF_PATH}/tools/cmake/project.cmake) 11 | project($NIMBLE_PROJ_NAME) 12 | 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 19 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 20 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/http_server/server.nim: -------------------------------------------------------------------------------- 1 | 2 | import asynchttpserver, asyncdispatch, net 3 | 4 | var count = 0 5 | 6 | proc cb*(req: Request) {.async.} = 7 | inc count 8 | echo "req #", count 9 | await req.respond(Http200, "Hello World from nim on ESP32\n") 10 | # GC_fullCollect() 11 | 12 | proc run_server*() {.exportc.} = 13 | echo "starting http server on port 8181" 14 | var server = newAsyncHttpServer() 15 | 16 | waitFor server.serve(Port(8181), cb) 17 | 18 | import nesper/esp/esp_timer 19 | 20 | proc example_cb*(arg: pointer) {.cdecl.} = 21 | echo "Done!" 22 | 23 | proc timer_test*(arg: pointer) {.cdecl.} = 24 | var x = "hello" 25 | 26 | var timer_handle = esp_timer_create_args_t( 27 | callback: example_cb, 28 | arg: x.cstring, 29 | dispatch_method: ESP_TIMER_TASK, 30 | name: "timer1") 31 | 32 | var timer1: esp_timer_handle_t 33 | 34 | discard esp_timer_create(addr timer_handle, addr timer1) 35 | discard esp_timer_start_periodic(timer1, 1000.uint64) 36 | 37 | when isMainModule: 38 | echo "running server" 39 | run_http_server() 40 | timer_test() 41 | 42 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/rpc_json_server/rpc_cli_test.nim: -------------------------------------------------------------------------------- 1 | 2 | 3 | const RpcServerType* = "json" 4 | 5 | import parseopt 6 | 7 | include nesper/servers/rpc/rpc_cli_utils 8 | 9 | var p = initOptParser() 10 | 11 | var args = p.rpcOptions() 12 | 13 | args.runRpc() 14 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/rpc_json_server/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import json 4 | 5 | const TAG = "server" 6 | const MaxRpcReceiveBuffer {.intdefine.}: int = 4096 7 | 8 | ## Note: 9 | ## Nim uses `when` compile time constructs 10 | ## these are like ifdef's in C and don't really have an equivalent in Python 11 | ## setting the flags can be done in the Makefile `simplewifi-rpc Makefile 12 | ## for example, to compile the example to use JSON, pass `-d:TcpJsonRpcServer` to Nim 13 | ## the makefile has several example already defined for convenience 14 | ## 15 | import nesper/servers/rpc/rpcsocket_json 16 | 17 | 18 | # Setup RPC Server # 19 | proc run_server*() = 20 | 21 | # Setup an RPC router 22 | var rpcRouter: RpcRouter 23 | var rt = createRpcRouter(MaxRpcReceiveBuffer) 24 | 25 | rpc(rt, "hello") do(input: string) -> string: 26 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "hello", "params": ["world"]}' 27 | result = "Hello " & input 28 | 29 | rpc(rt, "add") do(a: int, b: int) -> int: 30 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "add", "params": [1, 2]}' 31 | result = a + b 32 | 33 | rpc(rt, "addAll") do(vals: seq[int]) -> int: 34 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "add", "params": [1, 2, 3, 4, 5]}' 35 | echo("run_rpc_server: done: " & repr(addr(vals))) 36 | result = 0 37 | for x in vals: 38 | result += x 39 | 40 | echo "starting rpc server on port 5555" 41 | logi(TAG,"starting rpc server buffer size: %s", $$(rt.buffer)) 42 | 43 | startRpcSocketServer(Port(5555), router=rt) 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/rpc_mpack_queue_server/rpc_cli_test.nim: -------------------------------------------------------------------------------- 1 | const RpcServerType* = "mpack" 2 | 3 | import parseopt 4 | import msgpack4nim 5 | import msgpack4nim/msgpack2json 6 | 7 | include nesper/servers/rpc/rpc_cli_utils 8 | 9 | var p = initOptParser() 10 | 11 | var args = p.rpcOptions() 12 | 13 | args.runRpc() 14 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/rpc_mpack_queue_server/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import nesper/events 4 | import apps 5 | import volatile 6 | import strutils 7 | import json 8 | 9 | const TAG = "server" 10 | const MaxRpcReceiveBuffer {.intdefine.}: int = 4096 11 | 12 | import nesper/servers/rpc/rpcsocket_queue_mpack 13 | import nesper/servers/rpc/ota_rpc 14 | 15 | # Setup RPC Server # 16 | proc run_server*() = 17 | 18 | # Setup an RPC router 19 | var rpcRouter: RpcRouter 20 | var rt = createRpcRouter(MaxRpcReceiveBuffer) 21 | 22 | rpc(rt, "hello") do(input: string) -> string: 23 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "hello", "params": ["world"]}' 24 | result = "Hello " & input 25 | 26 | rpc(rt, "add") do(a: int, b: int) -> int: 27 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "add", "params": [1, 2]}' 28 | result = a + b 29 | 30 | rpc(rt, "addAll") do(vals: seq[int]) -> int: 31 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "add", "params": [1, 2, 3, 4, 5]}' 32 | echo("run_rpc_server: done: " & repr(addr(vals))) 33 | result = 0 34 | for x in vals: 35 | result += x 36 | 37 | # this adds methods for Over-The-Air updates using RPC! 38 | # note, this isn't secured by default 39 | rpcRouter.addOTAMethods() 40 | 41 | echo "starting rpc server on port 5555" 42 | logi(TAG,"starting rpc server buffer size: %s", $$(rt.buffer)) 43 | 44 | startRpcQueueSocketServer(Port(5555), router=rt) 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/rpc_mpack_server/rpc_cli_test.nim: -------------------------------------------------------------------------------- 1 | const RpcServerType* = "mpack" 2 | 3 | import parseopt 4 | import msgpack4nim 5 | import msgpack4nim/msgpack2json 6 | 7 | include nesper/servers/rpc/rpc_cli_utils 8 | 9 | var p = initOptParser() 10 | 11 | var args = p.rpcOptions() 12 | 13 | args.runRpc() 14 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/rpc_mpack_server/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import nesper/events 4 | import apps 5 | import volatile 6 | import strutils 7 | import json 8 | 9 | const TAG = "server" 10 | const MaxRpcReceiveBuffer {.intdefine.}: int = 4096 11 | 12 | import nesper/servers/rpc/rpcsocket_mpack 13 | 14 | # Setup RPC Server # 15 | proc run_server*() = 16 | 17 | # Setup an RPC router 18 | var rpcRouter: RpcRouter 19 | var rt = createRpcRouter(MaxRpcReceiveBuffer) 20 | 21 | rpc(rt, "hello") do(input: string) -> string: 22 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "hello", "params": ["world"]}' 23 | result = "Hello " & input 24 | 25 | rpc(rt, "add") do(a: int, b: int) -> int: 26 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "add", "params": [1, 2]}' 27 | result = a + b 28 | 29 | rpc(rt, "addAll") do(vals: seq[int]) -> int: 30 | # example: ./rpc_cli --ip:$$IP -c:1 '{"method": "add", "params": [1, 2, 3, 4, 5]}' 31 | echo("run_rpc_server: done: " & repr(addr(vals))) 32 | result = 0 33 | for x in vals: 34 | result += x 35 | 36 | # this adds methods for Over-The-Air updates using RPC! 37 | # note, this isn't secured by default 38 | rpcRouter.addOTAMethods() 39 | 40 | echo "starting rpc server on port 5555" 41 | logi(TAG,"starting rpc server buffer size: %s", $$(rt.buffer)) 42 | 43 | # Starts RPC handler on the current task 44 | # Default for JSON, MsgPack, and TCP Echo 45 | startRpcSocketServer(Port(5555), router=rt) 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/app_templates/tcp_echo_server/server.nim: -------------------------------------------------------------------------------- 1 | import nesper/consts 2 | import nesper/general 3 | import nesper/events 4 | import apps 5 | import volatile 6 | import strutils 7 | import json 8 | 9 | import nesper/servers/tcpsocket 10 | 11 | proc run_server*() = 12 | echo "starting server on port 5555" 13 | var msg = "echo: " 14 | startSocketServer[string](Port(5555), readHandler=echoReadHandler, writeHandler=nil, data=msg) 15 | 16 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/esp32_templates/networking/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRC_DIRS "$NIMBLE_NIMCACHE" 3 | INCLUDE_DIRS "" 4 | REQUIRES lwip newlib nvs_flash app_update) 5 | 6 | # set(C_COMPILE_OPTIONS "$${C_COMPILE_OPTIONS} -Wno-error=unused-label") 7 | # list(APPEND C_COMPILE_OPTIONS "-Wno-error=unused-label ") 8 | 9 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-label APPEND) 10 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-discarded-qualifiers APPEND) 11 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-ignored-qualifiers APPEND) 12 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=unused-label APPEND) 13 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=parentheses APPEND) 14 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=implicit-function-declaration APPEND) 15 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=maybe-uninitialized APPEND) 16 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=nonnull APPEND) 17 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-error=address APPEND) 18 | idf_build_set_property(C_COMPILE_OPTIONS -Wno-unused-but-set-variable APPEND) 19 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/esp32_templates/networking/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Wifi Example Configuration" 2 | 3 | config EXAMPLE_WIFI_SSID 4 | string "WiFi SSID" 5 | default "myssid" 6 | help 7 | SSID (network name) for the example to connect to. 8 | 9 | config EXAMPLE_WIFI_PASSWORD 10 | string "WiFi Password" 11 | default "mypassword" 12 | help 13 | WiFi password (WPA or WPA2) for the example to use. 14 | endmenu -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/esp32_templates/networking/main.nim: -------------------------------------------------------------------------------- 1 | import nesper 2 | import nesper/net_utils 3 | import nesper/nvs_utils 4 | import nesper/events 5 | import nesper/wifi 6 | import nesper/tasks 7 | import os 8 | 9 | import $NIMBLE_PROJ_NAME/server 10 | 11 | when defined(ESP32_ETHERNET): 12 | import setup_eth 13 | else: 14 | import setup_wifi 15 | 16 | # const CONFIG_EXAMPLE_WIFI_SSID = getEnv("WIFI_SSID") 17 | # const CONFIG_EXAMPLE_WIFI_PASSWORD = getEnv("WIFI_PASSWORD") 18 | 19 | const TAG*: cstring = "main" 20 | 21 | app_main(): 22 | 23 | networkingStart() 24 | 25 | # Other startup code 26 | # ... 27 | 28 | # Connect networking 29 | check: 30 | networkingConnect() 31 | 32 | # Connect networking 33 | onNetworking(): 34 | logi(TAG, "Connected to %s", networkConnectionName) 35 | logi(TAG, "IPv4 address: %s", $$networkIpAddr) 36 | logi(TAG, "network setup!\n") 37 | run_server() 38 | 39 | # turn off networking 40 | check: 41 | networkingDisconnect() 42 | 43 | assert false, "shouldn't reach here!" 44 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/esp32_templates/networking/nim.cfg: -------------------------------------------------------------------------------- 1 | ## Nim Options 2 | ## Run using ORC which allows using async runtime and libraries 3 | --gc:orc 4 | -d:nimAdaptiveOrc 5 | ## Run using ARC for lower overhead 6 | # --gc:arc 7 | 8 | # --verbosity:2 9 | 10 | --os:freertos 11 | --cpu:esp 12 | 13 | -d:use_malloc 14 | -d:no_signal_handler 15 | 16 | --debugger:native 17 | --threads:on 18 | --tls_emulation:off 19 | -------------------------------------------------------------------------------- /src/nesper/build_utils/templates/esp32_templates/networking/setup_networking.nim: -------------------------------------------------------------------------------- 1 | import nesper 2 | 3 | import nesper/net_utils 4 | import nesper/nvs_utils 5 | import nesper/events 6 | import nesper/tasks 7 | 8 | const 9 | GOT_IPV4_BIT* = EventBits_t(BIT(1)) 10 | CONNECTED_BITS* = (GOT_IPV4_BIT) 11 | 12 | var networkConnectEventGroup*: EventGroupHandle_t 13 | var networkIpAddr*: IpAddress 14 | var networkConnectionName*: cstring 15 | 16 | proc networkingStart*(startNvs=true) = 17 | 18 | # Networking will generally utilize NVS for storing net info 19 | # so it's best to start it first 20 | if startNvs: 21 | initNvs() 22 | 23 | # Initialize TCP/IP network interface (should be called only once in application) 24 | when defined(ESP_IDF_V4_0): 25 | tcpip_adapter_init() 26 | else: 27 | check: esp_netif_init() 28 | 29 | # Create default event loop that runs in background 30 | check: esp_event_loop_create_default() 31 | 32 | 33 | template onNetworking*(code: untyped) = 34 | discard xEventGroupWaitBits(networkConnectEventGroup, CONNECTED_BITS, 1, 1, portMAX_DELAY) 35 | 36 | code 37 | -------------------------------------------------------------------------------- /src/nesper/esp/driver/adc2_wifi_internal.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## 8 | ## Unless required by applicable law or agreed to in writing, software 9 | ## distributed under the License is distributed on an "AS IS" BASIS, 10 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | ## See the License for the specific language governing permissions and 12 | ## limitations under the License. 13 | 14 | import ../../consts 15 | 16 | ## * 17 | ## @brief For WIFI module to claim the usage of ADC2. 18 | ## 19 | ## Other tasks will be forbidden to use ADC2 between ``adc2_wifi_acquire`` and ``adc2_wifi_release``. 20 | ## The WIFI module may have to wait for a short time for the current conversion (if exist) to finish. 21 | ## 22 | ## @return 23 | ## - ESP_OK success 24 | ## - ESP_ERR_TIMEOUT reserved for future use. Currently the function will wait until success. 25 | ## 26 | 27 | proc adc2_wifi_acquire*(): esp_err_t {.importc: "adc2_wifi_acquire", 28 | header: "adc2_wifi_internal.h".} 29 | ## * 30 | ## @brief For WIFI module to let other tasks use the ADC2 when WIFI is not work. 31 | ## 32 | ## Other tasks will be forbidden to use ADC2 between ``adc2_wifi_acquire`` and ``adc2_wifi_release``. 33 | ## Call this function to release the occupation of ADC2 by WIFI. 34 | ## 35 | ## @return always return ESP_OK. 36 | ## 37 | 38 | proc adc2_wifi_release*(): esp_err_t {.importc: "adc2_wifi_release", 39 | header: "adc2_wifi_internal.h".} -------------------------------------------------------------------------------- /src/nesper/esp/driver/periph_ctrl.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## 8 | ## Unless required by applicable law or agreed to in writing, software 9 | ## distributed under the License is distributed on an "AS IS" BASIS, 10 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | ## See the License for the specific language governing permissions and 12 | ## limitations under the License. 13 | 14 | import periph_defs 15 | 16 | ## * 17 | ## @brief enable peripheral module 18 | ## 19 | ## @param[in] periph : Peripheral module name 20 | ## 21 | ## Clock for the module will be ungated, and reset de-asserted. 22 | ## 23 | ## @return NULL 24 | ## 25 | ## 26 | 27 | proc periph_module_enable*(periph: periph_module_t) {. 28 | importc: "periph_module_enable", header: "periph_ctrl.h".} 29 | ## * 30 | ## @brief disable peripheral module 31 | ## 32 | ## @param[in] periph : Peripheral module name 33 | ## 34 | ## Clock for the module will be gated, reset asserted. 35 | ## 36 | ## @return NULL 37 | ## 38 | ## 39 | 40 | proc periph_module_disable*(periph: periph_module_t) {. 41 | importc: "periph_module_disable", header: "periph_ctrl.h".} 42 | ## * 43 | ## @brief reset peripheral module 44 | ## 45 | ## @param[in] periph : Peripheral module name 46 | ## 47 | ## Reset will asserted then de-assrted for the peripheral. 48 | ## 49 | ## Calling this function does not enable or disable the clock for the module. 50 | ## 51 | ## @return NULL 52 | ## 53 | ## 54 | 55 | proc periph_module_reset*(periph: periph_module_t) {. 56 | importc: "periph_module_reset", header: "periph_ctrl.h".} -------------------------------------------------------------------------------- /src/nesper/esp/driver/periph_defs.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## 8 | ## Unless required by applicable law or agreed to in writing, software 9 | ## distributed under the License is distributed on an "AS IS" BASIS, 10 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | ## See the License for the specific language governing permissions and 12 | ## limitations under the License. 13 | 14 | type 15 | periph_module_t* {.size: sizeof(cint).} = enum 16 | PERIPH_LEDC_MODULE = 0, PERIPH_UART0_MODULE, PERIPH_UART1_MODULE, 17 | PERIPH_UART2_MODULE, PERIPH_I2C0_MODULE, PERIPH_I2C1_MODULE, 18 | PERIPH_I2S0_MODULE, PERIPH_I2S1_MODULE, PERIPH_TIMG0_MODULE, 19 | PERIPH_TIMG1_MODULE, PERIPH_PWM0_MODULE, PERIPH_PWM1_MODULE, 20 | PERIPH_PWM2_MODULE, PERIPH_PWM3_MODULE, PERIPH_UHCI0_MODULE, 21 | PERIPH_UHCI1_MODULE, PERIPH_RMT_MODULE, PERIPH_PCNT_MODULE, PERIPH_SPI_MODULE, 22 | PERIPH_HSPI_MODULE, PERIPH_VSPI_MODULE, PERIPH_SPI_DMA_MODULE, 23 | PERIPH_SDMMC_MODULE, PERIPH_SDIO_SLAVE_MODULE, PERIPH_CAN_MODULE, 24 | PERIPH_EMAC_MODULE, PERIPH_RNG_MODULE, PERIPH_WIFI_MODULE, PERIPH_BT_MODULE, 25 | PERIPH_WIFI_BT_COMMON_MODULE, PERIPH_BT_BASEBAND_MODULE, PERIPH_BT_LC_MODULE, 26 | PERIPH_AES_MODULE, PERIPH_SHA_MODULE, PERIPH_RSA_MODULE 27 | 28 | -------------------------------------------------------------------------------- /src/nesper/esp/driver/rtc_cntl.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2016-2017 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## 7 | ## http://www.apache.org/licenses/LICENSE-2.0 8 | ## 9 | ## Unless required by applicable law or agreed to in writing, software 10 | ## distributed under the License is distributed on an "AS IS" BASIS, 11 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ## See the License for the specific language governing permissions and 13 | ## limitations under the License. 14 | 15 | import ../../consts 16 | 17 | ## * 18 | ## @brief Register a handler for specific RTC_CNTL interrupts 19 | ## 20 | ## Multiple handlers can be registered using this function. Whenever an 21 | ## RTC interrupt happens, all handlers with matching rtc_intr_mask values 22 | ## will be called. 23 | ## 24 | ## @param handler handler function to call 25 | ## @param handler_arg argument to be passed to the handler 26 | ## @param rtc_intr_mask combination of RTC_CNTL_*_INT_ENA bits indicating the 27 | ## sources to call the handler for 28 | ## @return 29 | ## - ESP_OK on success 30 | ## - ESP_ERR_NO_MEM not enough memory to allocate handler structure 31 | ## - other errors returned by esp_intr_alloc 32 | ## 33 | 34 | proc rtc_isr_register*(handler: intr_handler_t; handler_arg: pointer; 35 | rtc_intr_mask: uint32): esp_err_t {. 36 | importc: "rtc_isr_register", header: "rtc_cntl.h".} 37 | ## * 38 | ## @brief Deregister the handler previously registered using rtc_isr_register 39 | ## @param handler handler function to call (as passed to rtc_isr_register) 40 | ## @param handler_arg argument of the handler (as passed to rtc_isr_register) 41 | ## @return 42 | ## - ESP_OK on success 43 | ## - ESP_ERR_INVALID_STATE if a handler matching both handler and 44 | ## handler_arg isn't registered 45 | ## 46 | 47 | proc rtc_isr_deregister*(handler: intr_handler_t; handler_arg: pointer): esp_err_t {. 48 | importc: "rtc_isr_deregister", header: "rtc_cntl.h".} -------------------------------------------------------------------------------- /src/nesper/esp/fatfs/ffconf.nim: -------------------------------------------------------------------------------- 1 | import ../queue 2 | 3 | type 4 | SemaphoreHandle_t* = QueueHandle_t 5 | FF_SYNC_t* = SemaphoreHandle_t 6 | 7 | # SD card sector size 8 | const 9 | CONFIG_WL_SECTOR_SIZE* = 4096 # From sdkconfig.h 10 | 11 | FF_SS_SDCARD* = 512 12 | # wear_levelling library sector size 13 | FF_SS_WL* = CONFIG_WL_SECTOR_SIZE 14 | 15 | FF_MIN_SS* = min(FF_SS_SDCARD, FF_SS_WL) 16 | FF_MAX_SS* = max(FF_SS_SDCARD, FF_SS_WL) 17 | 18 | # This set of options configures the range of sector size to be supported. (512, 19 | # 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and 20 | # harddisk. But a larger value may be required for on-board flash memory and some 21 | # type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured 22 | # for variable sector size mode and disk_ioctl() function needs to implement 23 | # GET_SECTOR_SIZE command. 24 | -------------------------------------------------------------------------------- /src/nesper/esp/net/esp_eth_netif_glue.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2019 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## 7 | ## http://www.apache.org/licenses/LICENSE-2.0 8 | ## 9 | ## Unless required by applicable law or agreed to in writing, software 10 | ## distributed under the License is distributed on an "AS IS" BASIS, 11 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | ## See the License for the specific language governing permissions and 13 | ## limitations under the License. 14 | 15 | import ../../consts 16 | import esp_eth 17 | 18 | ## * 19 | ## @brief Create a netif glue for Ethernet driver 20 | ## @note netif glue is used to attach io driver to TCP/IP netif 21 | ## 22 | ## @param eth_hdl Ethernet driver handle 23 | ## @return glue object, which inherits esp_netif_driver_base_t 24 | ## 25 | 26 | proc esp_eth_new_netif_glue*(eth_hdl: esp_eth_handle_t): pointer {. 27 | importc: "esp_eth_new_netif_glue", header: "esp_eth_netif_glue.h".} 28 | ## * 29 | ## @brief Delete netif glue of Ethernet driver 30 | ## 31 | ## @param glue netif glue 32 | ## @return -ESP_OK: delete netif glue successfully 33 | ## 34 | 35 | proc esp_eth_del_netif_glue*(glue: pointer): esp_err_t {. 36 | importc: "esp_eth_del_netif_glue", header: "esp_eth_netif_glue.h".} 37 | ## * 38 | ## @brief Register default IP layer handlers for Ethernet 39 | ## 40 | ## @note: Ethernet handle might not yet properly initialized when setting up these default handlers 41 | ## 42 | ## @param[in] esp_netif esp network interface handle created for Ethernet driver 43 | ## @return 44 | ## - ESP_ERR_INVALID_ARG: invalid parameter (esp_netif is NULL) 45 | ## - ESP_OK: set default IP layer handlers successfully 46 | ## - others: other failure occurred during register esp_event handler 47 | ## 48 | 49 | proc esp_eth_set_default_handlers*(esp_netif: pointer): esp_err_t {. 50 | importc: "esp_eth_set_default_handlers", header: "esp_eth_netif_glue.h".} 51 | ## * 52 | ## @brief Unregister default IP layer handlers for Ethernet 53 | ## 54 | ## @param[in] esp_netif esp network interface handle created for Ethernet driver 55 | ## @return 56 | ## - ESP_ERR_INVALID_ARG: invalid parameter (esp_netif is NULL) 57 | ## - ESP_OK: clear default IP layer handlers successfully 58 | ## - others: other failure occurred during unregister esp_event handler 59 | ## 60 | 61 | proc esp_eth_clear_default_handlers*(esp_netif: pointer): esp_err_t {. 62 | importc: "esp_eth_clear_default_handlers", header: "esp_eth_netif_glue.h".} -------------------------------------------------------------------------------- /src/nesper/esp/net/esp_netif.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2019 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## 8 | ## Unless required by applicable law or agreed to in writing, software 9 | ## distributed under the License is distributed on an "AS IS" BASIS, 10 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | ## See the License for the specific language governing permissions and 12 | ## limitations under the License. 13 | 14 | 15 | import ../../consts 16 | 17 | ## 18 | ## Note: tcpip_adapter legacy API has to be included by default to provide full compatibility 19 | ## for applications that used tcpip_adapter API without explicit inclusion of tcpip_adapter.h 20 | ## 21 | 22 | when defined(ESP_IDF_V4_0): 23 | include tcpip_adapter 24 | else: 25 | import esp_netif_ip_addr 26 | import esp_netif_types 27 | import esp_eth_netif_glue 28 | export esp_netif_ip_addr 29 | export esp_netif_types 30 | export esp_eth_netif_glue 31 | 32 | include esp_netif_impl 33 | include esp_netif_defaults 34 | -------------------------------------------------------------------------------- /src/nesper/esp/net/esp_netif_ip_addr.nim: -------------------------------------------------------------------------------- 1 | ## Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD 2 | ## 3 | ## Licensed under the Apache License, Version 2.0 (the "License"); 4 | ## you may not use this file except in compliance with the License. 5 | ## You may obtain a copy of the License at 6 | ## http://www.apache.org/licenses/LICENSE-2.0 7 | ## 8 | ## Unless required by applicable law or agreed to in writing, software 9 | ## distributed under the License is distributed on an "AS IS" BASIS, 10 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | ## See the License for the specific language governing permissions and 12 | ## limitations under the License. 13 | 14 | # proc esp_netif_htonl*(x: uint32): uint32 {.importc: "$1", header: "esp_netif_types.h".} 15 | 16 | # template esp_netif_ip4_makeu32*(a, b, c, d: untyped): untyped = 17 | 18 | ## Access address in 16-bit block 19 | 20 | const 21 | ESP_IPADDR_TYPE_V4* = 0 22 | ESP_IPADDR_TYPE_V6* = 6 23 | ESP_IPADDR_TYPE_ANY* = 46 24 | 25 | type 26 | esp_ip6_addr_t* {.importc: "esp_ip6_addr_t", header: "esp_netif_ip_addr.h", bycopy.} = object 27 | address* {.importc: "addr".}: array[4, uint32] 28 | zone* {.importc: "zone".}: uint8 29 | 30 | esp_ip4_addr_t* {.importc: "esp_ip4_addr_t", header: "esp_netif_ip_addr.h", bycopy.} = object 31 | address* {.importc: "addr".}: uint32 32 | 33 | INNER_C_UNION_esp_netif_ip_addr_97* {.header: "esp_netif_ip_addr.h", bycopy, union.} = object 34 | ip6* {.importc: "ip6".}: esp_ip6_addr_t 35 | ip4* {.importc: "ip4".}: esp_ip4_addr_t 36 | 37 | esp_ip_addr_t* {.importc: "esp_ip_addr_t", header: "esp_netif_ip_addr.h", bycopy.} = object 38 | u_addr* {.importc: "u_addr".}: INNER_C_UNION_esp_netif_ip_addr_97 39 | `type`* {.importc: "type".}: uint8 40 | 41 | -------------------------------------------------------------------------------- /src/nesper/ethernet.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/esp/net/esp_eth_com 3 | import nesper/esp/net/esp_eth_mac 4 | import nesper/esp/net/esp_eth 5 | 6 | export esp_eth_com 7 | export esp_eth_mac 8 | export esp_eth 9 | -------------------------------------------------------------------------------- /src/nesper/gpios.nim: -------------------------------------------------------------------------------- 1 | import consts 2 | import general 3 | 4 | # import esp/driver/gpio 5 | import esp/gpio 6 | 7 | export gpio 8 | 9 | type 10 | GpioError* = object of OSError 11 | code*: esp_err_t 12 | 13 | GPIO_PIN* = gpio_num_t 14 | 15 | proc configure*(pins: set[gpio_num_t], 16 | mode: gpio_mode_t, ## !< GPIO mode: set input/output mode 17 | pull_up: bool = false, ## !< GPIO pull-up 18 | pull_down: bool = false, ## !< GPIO pull-down 19 | interrupt: gpio_int_type_t = GPIO_INTR_DISABLE, ## !< GPIO interrupt type 20 | ) = 21 | var pin_mask: uint64 = 0U 22 | for pin in pins: 23 | pin_mask = pin_mask or BIT64(pin.int()) 24 | 25 | var io_conf: gpio_config_t 26 | io_conf.mode = mode 27 | io_conf.pin_bit_mask = pin_mask 28 | io_conf.pull_up_en = if pull_up: GPIO_PULLUP_ENABLE else: GPIO_PULLUP_DISABLE 29 | io_conf.pull_down_en = if pull_down: GPIO_PULLDOWN_ENABLE else: GPIO_PULLDOWN_DISABLE 30 | io_conf.intr_type = interrupt 31 | 32 | var ret: esp_err_t 33 | 34 | ret = gpio_config(addr(io_conf)) 35 | if ret != ESP_OK: 36 | raise newEspError[GpioError]("gpio config:" & $esp_err_to_name(ret), ret ) 37 | 38 | proc setLevel*(pin: gpio_num_t, value: uint32) = 39 | var ret: esp_err_t 40 | 41 | ret = gpio_setLevel(pin, value.uint32()) 42 | if ret != ESP_OK: 43 | raise newEspError[GpioError]("gpio set level:" & $esp_err_to_name(ret), ret ) 44 | 45 | proc setLevel*(pin: gpio_num_t, value: bool) = 46 | setLevel(pin, uint32(value)) 47 | proc setLevel*(pin: gpio_num_t, value: SomeInteger) = 48 | setLevel(pin, uint32(value)) 49 | 50 | proc getLevel*(pin: gpio_num_t): bool = 51 | var ret: cint = gpio_getLevel(pin) 52 | 53 | return 54 | if ret == 0: 55 | false 56 | else: 57 | true 58 | 59 | proc setLevelMulti*(pins: set[gpio_num_t], value: bool) = 60 | # Sets the given gpio pin 0-31 either high or low 61 | 62 | var pin_mask: uint32 = 0'u32 63 | for pin in pins: 64 | if pin.int > 31: 65 | raise newException(ValueError, "GPIO Pin's must be 0-31") 66 | pin_mask = pin_mask or BIT(pin.int()).uint32 67 | 68 | if value: 69 | # Set 70 | GPIO_REG_WRITE(GPIO_OUT_W1TS_REG.uint32, pin_mask) # 71 | else: 72 | # Clear 73 | GPIO_REG_WRITE(GPIO_OUT_W1TC_REG.uint32, pin_mask) # 74 | 75 | proc setLevelMultiHi*(pins: set[gpio_num_t], value: bool) = 76 | # Sets the given gpio pin 32-63 either high or low 77 | 78 | var pin_mask: uint32 = 0'u32 79 | for pin in pins: 80 | if pin.int <= 31: 81 | raise newException(ValueError, "GPIO Pin's must be 32-63") 82 | pin_mask = pin_mask or BIT(pin.int() - 32).uint32 83 | 84 | if value: 85 | # Set 86 | GPIO_REG_WRITE(GPIO_OUT1_W1TS_REG.uint32, pin_mask) # 87 | else: 88 | # Clear 89 | GPIO_REG_WRITE(GPIO_OUT2_W1TC_REG.uint32, pin_mask) # 90 | -------------------------------------------------------------------------------- /src/nesper/servers/rpc/rpcsocket_json.nim: -------------------------------------------------------------------------------- 1 | import nativesockets 2 | import net 3 | import selectors 4 | import tables 5 | import posix 6 | 7 | import ../../consts 8 | import ../../general 9 | import ../tcpsocket 10 | import router 11 | import json 12 | 13 | export tcpsocket, router 14 | 15 | const TAG = "socketrpc" 16 | 17 | proc rpcMsgPackWriteHandler*(srv: TcpServerInfo[RpcRouter], result: ReadyKey, sourceClient: Socket, rt: RpcRouter) = 18 | raise newException(OSError, "the request to the OS failed") 19 | 20 | proc rpcMsgPackReadHandler*(srv: TcpServerInfo[RpcRouter], result: ReadyKey, sourceClient: Socket, rt: RpcRouter) = 21 | 22 | try: 23 | logd(TAG, "rpc server handler: router: %x", rt.buffer) 24 | 25 | let msg = sourceClient.recv(rt.buffer, -1) 26 | 27 | if msg.len() == 0: 28 | raise newException(TcpClientDisconnected, "") 29 | else: 30 | var rcall = parseJson(msg) 31 | 32 | var res: JsonNode = rt.route( rcall ) 33 | var rmsg: string = $res 34 | 35 | logd(TAG, "sending to client: %s", $(sourceClient.getFd().int)) 36 | discard sourceClient.send(addr rmsg[0], rmsg.len) 37 | 38 | except TimeoutError: 39 | echo("control server: error: socket timeout: ", $sourceClient.getFd().int) 40 | 41 | 42 | proc startRpcSocketServer*(port: Port; router: var RpcRouter) = 43 | logi(TAG, "starting json rpc server: buffer: %s", $router.buffer) 44 | 45 | startSocketServer[RpcRouter]( 46 | port, 47 | readHandler=rpcMsgPackReadHandler, 48 | writeHandler=rpcMsgPackWriteHandler, 49 | data=router) 50 | 51 | 52 | 53 | when isMainModule: 54 | runTcpServer() -------------------------------------------------------------------------------- /src/nesper/servers/rpc/rpcsocket_mpack.nim: -------------------------------------------------------------------------------- 1 | import nativesockets, net, selectors, tables, posix 2 | 3 | import ../../general 4 | import ../../timers 5 | import ../tcpsocket 6 | 7 | import router 8 | import json 9 | import msgpack4nim/msgpack2json 10 | 11 | export tcpsocket, router 12 | 13 | const TAG = "socketrpc" 14 | 15 | proc rpcMsgPackWriteHandler*(srv: TcpServerInfo[RpcRouter], result: ReadyKey, sourceClient: Socket, rt: RpcRouter) = 16 | raise newException(OSError, "the request to the OS failed") 17 | 18 | proc rpcMsgPackReadHandler*(srv: TcpServerInfo[RpcRouter], result: ReadyKey, sourceClient: Socket, rt: RpcRouter) = 19 | # TODO: improvement 20 | # The incoming RPC call needs to be less than 1400 or the network buffer size. 21 | # This could be improved, but is a bit finicky. In my usage, I only send small 22 | # RPC calls with possibly larger responses. 23 | 24 | try: 25 | logd(TAG, "rpc server handler: router: %x", rt.buffer) 26 | 27 | var msg = sourceClient.recv(rt.buffer, -1) 28 | 29 | if msg.len() == 0: 30 | raise newException(TcpClientDisconnected, "") 31 | else: 32 | var rcall = msgpack2json.toJsonNode(move msg) 33 | 34 | var res: JsonNode = rt.route(rcall) 35 | var rmsg: string = msgpack2json.fromJsonNode(move res) 36 | 37 | logd(TAG, "sending to client: %s", $(sourceClient.getFd().int)) 38 | sourceClient.sendLength(rmsg) 39 | sourceClient.sendChunks(rmsg) 40 | 41 | except TimeoutError: 42 | echo("control server: error: socket timeout: ", $sourceClient.getFd().int) 43 | 44 | 45 | proc startRpcSocketServer*(port: Port; router: var RpcRouter) = 46 | logi(TAG, "starting mpack rpc server: buffer: %s", $router.buffer) 47 | 48 | startSocketServer[RpcRouter]( 49 | port, 50 | readHandler=rpcMsgPackReadHandler, 51 | writeHandler=rpcMsgPackWriteHandler, 52 | data=router) 53 | 54 | -------------------------------------------------------------------------------- /src/nesper/tasks.nim: -------------------------------------------------------------------------------- 1 | 2 | import esp/task 3 | 4 | export task 5 | 6 | # {.emit: """ 7 | # #include "freertos/FreeRTOS.h" 8 | # #include "freertos/task.h" 9 | # """.} 10 | -------------------------------------------------------------------------------- /src/nesper/wifi.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/esp/net/esp_wifi 3 | import nesper/esp/net/esp_wifi_types 4 | 5 | export esp_wifi 6 | export esp_wifi_types -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | tests/trouter 2 | trouter 3 | mrpc_test 4 | echosocket_test 5 | test_repr 6 | rpc_cli_test 7 | *_cache/ 8 | -------------------------------------------------------------------------------- /tests/c_headers/driver/adc2_wifi_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _DRIVER_ADC2_INTERNAL_H_ 16 | #define _DRIVER_ADC2_INTERNAL_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include "esp_err.h" 23 | 24 | /** 25 | * @brief For WIFI module to claim the usage of ADC2. 26 | * 27 | * Other tasks will be forbidden to use ADC2 between ``adc2_wifi_acquire`` and ``adc2_wifi_release``. 28 | * The WIFI module may have to wait for a short time for the current conversion (if exist) to finish. 29 | * 30 | * @return 31 | * - ESP_OK success 32 | * - ESP_ERR_TIMEOUT reserved for future use. Currently the function will wait until success. 33 | */ 34 | esp_err_t adc2_wifi_acquire(); 35 | 36 | 37 | /** 38 | * @brief For WIFI module to let other tasks use the ADC2 when WIFI is not work. 39 | * 40 | * Other tasks will be forbidden to use ADC2 between ``adc2_wifi_acquire`` and ``adc2_wifi_release``. 41 | * Call this function to release the occupation of ADC2 by WIFI. 42 | * 43 | * @return always return ESP_OK. 44 | */ 45 | esp_err_t adc2_wifi_release(); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /*_DRIVER_ADC2_INTERNAL_H_*/ 52 | 53 | -------------------------------------------------------------------------------- /tests/c_headers/driver/dac.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _DRIVER_DAC_H_ 16 | #define _DRIVER_DAC_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | #include "esp_err.h" 24 | #include "soc/dac_periph.h" 25 | 26 | typedef enum { 27 | DAC_CHANNEL_1 = 1, /*!< DAC channel 1 is GPIO25 */ 28 | DAC_CHANNEL_2, /*!< DAC channel 2 is GPIO26 */ 29 | DAC_CHANNEL_MAX, 30 | } dac_channel_t; 31 | 32 | /** 33 | * @brief Get the gpio number of a specific DAC channel. 34 | * 35 | * @param channel Channel to get the gpio number 36 | * 37 | * @param gpio_num output buffer to hold the gpio number 38 | * 39 | * @return 40 | * - ESP_OK if success 41 | * - ESP_ERR_INVALID_ARG if channal not valid 42 | */ 43 | esp_err_t dac_pad_get_io_num(dac_channel_t channel, gpio_num_t *gpio_num); 44 | 45 | /** 46 | * @brief Set DAC output voltage. 47 | * 48 | * DAC output is 8-bit. Maximum (255) corresponds to VDD. 49 | * 50 | * @note Need to configure DAC pad before calling this function. 51 | * DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26 52 | * 53 | * @param channel DAC channel 54 | * @param dac_value DAC output value 55 | * 56 | * @return 57 | * - ESP_OK success 58 | * - ESP_ERR_INVALID_ARG Parameter error 59 | */ 60 | esp_err_t dac_output_voltage(dac_channel_t channel, uint8_t dac_value); 61 | 62 | /** 63 | * @brief DAC pad output enable 64 | * 65 | * @param channel DAC channel 66 | * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26 67 | * I2S left channel will be mapped to DAC channel 2 68 | * I2S right channel will be mapped to DAC channel 1 69 | */ 70 | esp_err_t dac_output_enable(dac_channel_t channel); 71 | 72 | /** 73 | * @brief DAC pad output disable 74 | * 75 | * @param channel DAC channel 76 | * @note DAC channel 1 is attached to GPIO25, DAC channel 2 is attached to GPIO26 77 | */ 78 | esp_err_t dac_output_disable(dac_channel_t channel); 79 | 80 | /** 81 | * @brief Enable DAC output data from I2S 82 | */ 83 | esp_err_t dac_i2s_enable(); 84 | 85 | /** 86 | * @brief Disable DAC output data from I2S 87 | */ 88 | esp_err_t dac_i2s_disable(); 89 | #ifdef __cplusplus 90 | } 91 | #endif 92 | 93 | #endif /*_DRIVER_DAC_H_*/ 94 | 95 | -------------------------------------------------------------------------------- /tests/c_headers/driver/periph_ctrl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _DRIVER_PERIPH_CTRL_H_ 16 | #define _DRIVER_PERIPH_CTRL_H_ 17 | 18 | #include "soc/periph_defs.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * @brief enable peripheral module 26 | * 27 | * @param[in] periph : Peripheral module name 28 | * 29 | * Clock for the module will be ungated, and reset de-asserted. 30 | * 31 | * @return NULL 32 | * 33 | */ 34 | void periph_module_enable(periph_module_t periph); 35 | 36 | /** 37 | * @brief disable peripheral module 38 | * 39 | * @param[in] periph : Peripheral module name 40 | * 41 | * Clock for the module will be gated, reset asserted. 42 | * 43 | * @return NULL 44 | * 45 | */ 46 | void periph_module_disable(periph_module_t periph); 47 | 48 | /** 49 | * @brief reset peripheral module 50 | * 51 | * @param[in] periph : Peripheral module name 52 | * 53 | * Reset will asserted then de-assrted for the peripheral. 54 | * 55 | * Calling this function does not enable or disable the clock for the module. 56 | * 57 | * @return NULL 58 | * 59 | */ 60 | void periph_module_reset(periph_module_t periph); 61 | 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* _DRIVER_PERIPH_CTRL_H_ */ 68 | -------------------------------------------------------------------------------- /tests/c_headers/driver/rtc_cntl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016-2017 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "esp_err.h" 19 | #include "esp_intr_alloc.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * @brief Register a handler for specific RTC_CNTL interrupts 27 | * 28 | * Multiple handlers can be registered using this function. Whenever an 29 | * RTC interrupt happens, all handlers with matching rtc_intr_mask values 30 | * will be called. 31 | * 32 | * @param handler handler function to call 33 | * @param handler_arg argument to be passed to the handler 34 | * @param rtc_intr_mask combination of RTC_CNTL_*_INT_ENA bits indicating the 35 | * sources to call the handler for 36 | * @return 37 | * - ESP_OK on success 38 | * - ESP_ERR_NO_MEM not enough memory to allocate handler structure 39 | * - other errors returned by esp_intr_alloc 40 | */ 41 | esp_err_t rtc_isr_register(intr_handler_t handler, void* handler_arg, 42 | uint32_t rtc_intr_mask); 43 | /** 44 | * @brief Deregister the handler previously registered using rtc_isr_register 45 | * @param handler handler function to call (as passed to rtc_isr_register) 46 | * @param handler_arg argument of the handler (as passed to rtc_isr_register) 47 | * @return 48 | * - ESP_OK on success 49 | * - ESP_ERR_INVALID_STATE if a handler matching both handler and 50 | * handler_arg isn't registered 51 | */ 52 | esp_err_t rtc_isr_deregister(intr_handler_t handler, void* handler_arg); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /tests/c_headers/driver/uart_select.h: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2018 Espressif Systems (Shanghai) PTE LTD 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #ifndef _UART_SELECT_H_ 17 | #define _UART_SELECT_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "driver/uart.h" 24 | 25 | typedef enum { 26 | UART_SELECT_READ_NOTIF, 27 | UART_SELECT_WRITE_NOTIF, 28 | UART_SELECT_ERROR_NOTIF, 29 | } uart_select_notif_t; 30 | 31 | typedef void (*uart_select_notif_callback_t)(uart_port_t uart_num, uart_select_notif_t uart_select_notif, BaseType_t *task_woken); 32 | 33 | /** 34 | * @brief Set notification callback function for select() events 35 | * @param uart_num UART port number 36 | * @param uart_select_notif_callback callback function 37 | */ 38 | void uart_set_select_notif_callback(uart_port_t uart_num, uart_select_notif_callback_t uart_select_notif_callback); 39 | 40 | /** 41 | * @brief Get mutex guarding select() notifications 42 | */ 43 | portMUX_TYPE *uart_get_selectlock(); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif //_UART_SELECT_H_ 50 | -------------------------------------------------------------------------------- /tests/c_headers/esp_eth_netif_glue.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include "esp_eth.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * @brief Create a netif glue for Ethernet driver 24 | * @note netif glue is used to attach io driver to TCP/IP netif 25 | * 26 | * @param eth_hdl Ethernet driver handle 27 | * @return glue object, which inherits esp_netif_driver_base_t 28 | */ 29 | void *esp_eth_new_netif_glue(esp_eth_handle_t eth_hdl); 30 | 31 | /** 32 | * @brief Delete netif glue of Ethernet driver 33 | * 34 | * @param glue netif glue 35 | * @return -ESP_OK: delete netif glue successfully 36 | */ 37 | esp_err_t esp_eth_del_netif_glue(void *glue); 38 | 39 | /** 40 | * @brief Register default IP layer handlers for Ethernet 41 | * 42 | * @note: Ethernet handle might not yet properly initialized when setting up these default handlers 43 | * 44 | * @param[in] esp_netif esp network interface handle created for Ethernet driver 45 | * @return 46 | * - ESP_ERR_INVALID_ARG: invalid parameter (esp_netif is NULL) 47 | * - ESP_OK: set default IP layer handlers successfully 48 | * - others: other failure occurred during register esp_event handler 49 | */ 50 | 51 | esp_err_t esp_eth_set_default_handlers(void *esp_netif); 52 | 53 | /** 54 | * @brief Unregister default IP layer handlers for Ethernet 55 | * 56 | * @param[in] esp_netif esp network interface handle created for Ethernet driver 57 | * @return 58 | * - ESP_ERR_INVALID_ARG: invalid parameter (esp_netif is NULL) 59 | * - ESP_OK: clear default IP layer handlers successfully 60 | * - others: other failure occurred during unregister esp_event handler 61 | */ 62 | esp_err_t esp_eth_clear_default_handlers(void *esp_netif); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /tests/c_headers/esp_event_base.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef ESP_EVENT_BASE_H_ 16 | #define ESP_EVENT_BASE_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | // Defines for declaring and defining event base 23 | // #define ESP_EVENT_DECLARE_BASE(id) extern esp_event_base_t id 24 | // #define ESP_EVENT_DEFINE_BASE(id) esp_event_base_t id = #id 25 | 26 | // Event loop library types 27 | typedef const char* esp_event_base_t; /**< unique pointer to a subsystem that exposes events */ 28 | typedef void* esp_event_loop_handle_t; /**< a number that identifies an event with respect to a base */ 29 | typedef void (*esp_event_handler_t)(void* event_handler_arg, 30 | esp_event_base_t event_base, 31 | int32_t event_id, 32 | void* event_data); /**< function called when an event is posted to the queue */ 33 | 34 | 35 | // Defines for registering/unregistering event handlers 36 | #define ESP_EVENT_ANY_BASE NULL /**< register handler for any event base */ 37 | #define ESP_EVENT_ANY_ID -1 /**< register handler for any event id */ 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif // #ifndef ESP_EVENT_BASE_H_ 44 | -------------------------------------------------------------------------------- /tests/c_headers/esp_interface.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | #ifndef __ESP_INTERFACE_H__ 17 | #define __ESP_INTERFACE_H__ 18 | 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | typedef enum { 26 | ESP_IF_WIFI_STA = 0, /**< ESP32 station interface */ 27 | ESP_IF_WIFI_AP, /**< ESP32 soft-AP interface */ 28 | ESP_IF_ETH, /**< ESP32 ethernet interface */ 29 | ESP_IF_MAX 30 | } esp_interface_t; 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | 37 | #endif /* __ESP_INTERFACE_TYPES_H__ */ 38 | -------------------------------------------------------------------------------- /tests/c_headers/esp_log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "sdkconfig.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define strlcpy(a, b, c) 13 | #define strlcat(a, b, c) 14 | 15 | #define heap_caps_malloc(a, b) NULL 16 | #define MALLOC_CAP_INTERNAL 0 17 | #define MALLOC_CAP_8BIT 0 18 | 19 | #define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL 20 | 21 | typedef enum { 22 | ESP_LOG_NONE, /*!< No log output */ 23 | ESP_LOG_ERROR, /*!< Critical errors, software module can not recover on its own */ 24 | ESP_LOG_WARN, /*!< Error conditions from which recovery measures have been taken */ 25 | ESP_LOG_INFO, /*!< Information messages which describe normal flow of events */ 26 | ESP_LOG_DEBUG, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */ 27 | ESP_LOG_VERBOSE /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */ 28 | } esp_log_level_t; 29 | 30 | #define LOG_COLOR_E 31 | #define LOG_COLOR_W 32 | #define LOG_COLOR_I 33 | #define LOG_COLOR_D 34 | #define LOG_COLOR_V 35 | #define LOG_RESET_COLOR 36 | 37 | #undef _Static_assert 38 | #define _Static_assert(cond, message) 39 | 40 | uint32_t esp_log_timestamp(void); 41 | void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) {}; 42 | 43 | // #define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%d) %s: " format LOG_RESET_COLOR "\n" 44 | 45 | // #define ESP_LOGE( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 46 | 47 | // #define ESP_LOGW( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 48 | 49 | // #define ESP_LOGI( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 50 | 51 | // #define ESP_LOGD( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 52 | 53 | // #define ESP_LOGV( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } 54 | 55 | // Assume that flash encryption is not enabled. Put here since in partition.c 56 | // esp_log.h is included later than esp_flash_encrypt.h. 57 | #define esp_flash_encryption_enabled() false 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /tests/c_headers/mock/driver/driver_mocks.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #define SOC_SPI_PERIPH_NUM 3 8 | // #define esp_err_to_name(id) ("ERROR" ## id) 9 | 10 | typedef uint32_t TickType_t; 11 | typedef int esp_err_t; 12 | 13 | typedef void * spi_host_device_t; 14 | 15 | typedef void * QueueHandle_t; 16 | 17 | typedef void * spi_hal_timing_conf_t ; 18 | typedef void * spi_host_t; 19 | typedef void * SemaphoreHandle_t; 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/c_headers/mock/esp_bit_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2010-2019 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | //Register Bits{{ 18 | #define BIT31 0x80000000 19 | #define BIT30 0x40000000 20 | #define BIT29 0x20000000 21 | #define BIT28 0x10000000 22 | #define BIT27 0x08000000 23 | #define BIT26 0x04000000 24 | #define BIT25 0x02000000 25 | #define BIT24 0x01000000 26 | #define BIT23 0x00800000 27 | #define BIT22 0x00400000 28 | #define BIT21 0x00200000 29 | #define BIT20 0x00100000 30 | #define BIT19 0x00080000 31 | #define BIT18 0x00040000 32 | #define BIT17 0x00020000 33 | #define BIT16 0x00010000 34 | #define BIT15 0x00008000 35 | #define BIT14 0x00004000 36 | #define BIT13 0x00002000 37 | #define BIT12 0x00001000 38 | #define BIT11 0x00000800 39 | #define BIT10 0x00000400 40 | #define BIT9 0x00000200 41 | #define BIT8 0x00000100 42 | #define BIT7 0x00000080 43 | #define BIT6 0x00000040 44 | #define BIT5 0x00000020 45 | #define BIT4 0x00000010 46 | #define BIT3 0x00000008 47 | #define BIT2 0x00000004 48 | #define BIT1 0x00000002 49 | #define BIT0 0x00000001 50 | //}} 51 | 52 | #ifndef __ASSEMBLER__ 53 | #define BIT(nr) (1UL << (nr)) 54 | #define BIT64(nr) (1ULL << (nr)) 55 | #else 56 | #define BIT(nr) (1 << (nr)) 57 | #endif -------------------------------------------------------------------------------- /tests/c_headers/mock/esp_idf_version.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /** Major version number (X.x.x) */ 22 | #define ESP_IDF_VERSION_MAJOR 4 23 | /** Minor version number (x.X.x) */ 24 | #define ESP_IDF_VERSION_MINOR 0 25 | /** Patch version number (x.x.X) */ 26 | #define ESP_IDF_VERSION_PATCH 0 27 | 28 | /** 29 | * Macro to convert IDF version number into an integer 30 | * 31 | * To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) 32 | */ 33 | #define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) 34 | 35 | /** 36 | * Current IDF version, as an integer 37 | * 38 | * To be used in comparisons, such as ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0) 39 | */ 40 | #define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(ESP_IDF_VERSION_MAJOR, \ 41 | ESP_IDF_VERSION_MINOR, \ 42 | ESP_IDF_VERSION_PATCH) 43 | 44 | /** 45 | * Return full IDF version string, same as 'git describe' output. 46 | * 47 | * @note If you are printing the ESP-IDF version in a log file or other information, 48 | * this function provides more information than using the numerical version macros. 49 | * For example, numerical version macros don't differentiate between development, 50 | * pre-release and release versions, but the output of this function does. 51 | * 52 | * @return constant string from IDF_VER 53 | */ 54 | const char* esp_get_idf_version(void); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | -------------------------------------------------------------------------------- /tests/c_headers/mock/esp_log.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #define ESP_LOGI(fmt, args...) printf(fmt, args); 5 | 6 | // #define esp_err_to_name(id) ("ERROR" ## id) 7 | -------------------------------------------------------------------------------- /tests/c_headers/mock/esp_private/crosscore_int.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef __ESP_CROSSCORE_INT_H 15 | #define __ESP_CROSSCORE_INT_H 16 | 17 | 18 | /** 19 | * Initialize the crosscore interrupt system for this CPU. 20 | * This needs to be called once on every CPU that is used 21 | * by FreeRTOS. 22 | * 23 | * If multicore FreeRTOS support is enabled, this will be 24 | * called automatically by the startup code and should not 25 | * be called manually. 26 | */ 27 | void esp_crosscore_int_init(); 28 | 29 | 30 | /** 31 | * Send an interrupt to a CPU indicating it should yield its 32 | * currently running task in favour of a higher-priority task 33 | * that presumably just woke up. 34 | * 35 | * This is used internally by FreeRTOS in multicore mode 36 | * and should not be called by the user. 37 | * 38 | * @param core_id Core that should do the yielding 39 | */ 40 | void esp_crosscore_int_send_yield(int core_id); 41 | 42 | 43 | /** 44 | * Send an interrupt to a CPU indicating it should update its 45 | * CCOMPARE1 value due to a frequency switch. 46 | * 47 | * This is used internally when dynamic frequency switching is 48 | * enabled, and should not be called from application code. 49 | * 50 | * @param core_id Core that should update its CCOMPARE1 value 51 | */ 52 | void esp_crosscore_int_send_freq_switch(int core_id); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /tests/c_headers/mock/portbenchmark.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | // Copyright (c) 2003-2015 Cadence Design Systems, Inc. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included 13 | // in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- 23 | */ 24 | 25 | /* 26 | * This utility helps benchmarking interrupt latency and context switches. 27 | * In order to enable it, set configBENCHMARK to 1 in FreeRTOSConfig.h. 28 | * You will also need to download the FreeRTOS_trace patch that contains 29 | * portbenchmark.c and the complete version of portbenchmark.h 30 | */ 31 | 32 | #ifndef PORTBENCHMARK_H 33 | #define PORTBENCHMARK_H 34 | 35 | #if configBENCHMARK 36 | #error "You need to download the FreeRTOS_trace patch that overwrites this file" 37 | #endif 38 | 39 | #define portbenchmarkINTERRUPT_DISABLE() 40 | #define portbenchmarkINTERRUPT_RESTORE(newstate) 41 | #define portbenchmarkIntLatency() 42 | #define portbenchmarkIntWait() 43 | #define portbenchmarkReset() 44 | #define portbenchmarkPrint() 45 | 46 | #endif /* PORTBENCHMARK */ 47 | -------------------------------------------------------------------------------- /tests/c_headers/mock/porttrace.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | // Copyright (c) 2003-2015 Cadence Design Systems, Inc. 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining 5 | // a copy of this software and associated documentation files (the 6 | // "Software"), to deal in the Software without restriction, including 7 | // without limitation the rights to use, copy, modify, merge, publish, 8 | // distribute, sublicense, and/or sell copies of the Software, and to 9 | // permit persons to whom the Software is furnished to do so, subject to 10 | // the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included 13 | // in all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- 23 | 24 | /* 25 | * This utility helps tracing the entering and exiting from tasks. It maintains a circular buffer 26 | * of tasks in the order they execute, and their execution time. 27 | * In order to enable it, set configUSE_TRACE_FACILITY_2 to 1 in FreeRTOSConfig.h. 28 | * You will also need to download the FreeRTOS_trace patch that contains 29 | * porttrace.c and the complete version of porttrace.h 30 | */ 31 | 32 | #ifndef PORTTRACE_H 33 | #define PORTTRACE_H 34 | 35 | #if configUSE_TRACE_FACILITY_2 36 | #error "You need to download the FreeRTOS_trace patch that overwrites this file" 37 | #endif 38 | 39 | #define porttracePrint(nelements) 40 | #define porttraceStamp(stamp, count_incr) 41 | 42 | #endif /* PORTTRACE_H */ 43 | -------------------------------------------------------------------------------- /tests/c_headers/mock/soc/io_mux_reg.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #define IO_MUX_GPIO0_REG 0 5 | #define IO_MUX_GPIO1_REG 0 6 | #define IO_MUX_GPIO2_REG 0 7 | #define IO_MUX_GPIO3_REG 0 8 | #define IO_MUX_GPIO4_REG 0 9 | #define IO_MUX_GPIO5_REG 0 10 | #define IO_MUX_GPIO6_REG 0 11 | #define IO_MUX_GPIO7_REG 0 12 | #define IO_MUX_GPIO8_REG 0 13 | #define IO_MUX_GPIO9_REG 0 14 | #define IO_MUX_GPIO10_REG 0 15 | #define IO_MUX_GPIO11_REG 0 16 | #define IO_MUX_GPIO12_REG 0 17 | #define IO_MUX_GPIO13_REG 0 18 | #define IO_MUX_GPIO14_REG 0 19 | #define IO_MUX_GPIO15_REG 0 20 | #define IO_MUX_GPIO16_REG 0 21 | #define IO_MUX_GPIO17_REG 0 22 | #define IO_MUX_GPIO18_REG 0 23 | #define IO_MUX_GPIO19_REG 0 24 | #define IO_MUX_GPIO20_REG 0 25 | #define IO_MUX_GPIO21_REG 0 26 | #define IO_MUX_GPIO22_REG 0 27 | #define IO_MUX_GPIO23_REG 0 28 | #define IO_MUX_GPIO24_REG 0 29 | #define IO_MUX_GPIO25_REG 0 30 | #define IO_MUX_GPIO26_REG 0 31 | #define IO_MUX_GPIO27_REG 0 32 | #define IO_MUX_GPIO28_REG 0 33 | #define IO_MUX_GPIO29_REG 0 34 | #define IO_MUX_GPIO30_REG 0 35 | #define IO_MUX_GPIO31_REG 0 36 | #define IO_MUX_GPIO32_REG 0 37 | #define IO_MUX_GPIO33_REG 0 38 | #define IO_MUX_GPIO34_REG 0 39 | #define IO_MUX_GPIO35_REG 0 40 | #define IO_MUX_GPIO36_REG 0 41 | #define IO_MUX_GPIO37_REG 0 42 | #define IO_MUX_GPIO38_REG 0 43 | #define IO_MUX_GPIO39_REG 0 44 | #define IO_MUX_GPIO40_REG 0 45 | #define IO_MUX_GPIO41_REG 0 46 | #define IO_MUX_GPIO42_REG 0 47 | #define IO_MUX_GPIO43_REG 0 48 | #define IO_MUX_GPIO44_REG 0 49 | #define IO_MUX_GPIO45_REG 0 50 | #define IO_MUX_GPIO46_REG 0 51 | #define IO_MUX_GPIO47_REG 0 52 | #define IO_MUX_GPIO48_REG 0 53 | #define IO_MUX_GPIO50_REG 0 54 | 55 | -------------------------------------------------------------------------------- /tests/c_headers/mock/sys/reent.h: -------------------------------------------------------------------------------- 1 | 2 | struct _reent {}; -------------------------------------------------------------------------------- /tests/c_headers/mock/xtensa/config/defs.h: -------------------------------------------------------------------------------- 1 | /* Definitions for Xtensa instructions, types, and protos. */ 2 | 3 | /* Customer ID=11657; Build=0x5fe96; Copyright (c) 2003-2004 Tensilica Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23 | 24 | /* NOTE: This file exists only for backward compatibility with T1050 25 | and earlier Xtensa releases. It includes only a subset of the 26 | available header files. */ 27 | 28 | #ifndef _XTENSA_BASE_HEADER 29 | #define _XTENSA_BASE_HEADER 30 | 31 | #ifdef __XTENSA__ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #endif /* __XTENSA__ */ 38 | #endif /* !_XTENSA_BASE_HEADER */ 39 | -------------------------------------------------------------------------------- /tests/c_headers/other.h: -------------------------------------------------------------------------------- 1 | 2 | typedef esp_err_t (*system_event_handler_t)(system_event_t *event); 3 | -------------------------------------------------------------------------------- /tests/c_headers/periph_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef _SOC_PERIPH_DEFS_H_ 16 | #define _SOC_PERIPH_DEFS_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | typedef enum { 23 | PERIPH_LEDC_MODULE = 0, 24 | PERIPH_UART0_MODULE, 25 | PERIPH_UART1_MODULE, 26 | PERIPH_UART2_MODULE, 27 | PERIPH_I2C0_MODULE, 28 | PERIPH_I2C1_MODULE, 29 | PERIPH_I2S0_MODULE, 30 | PERIPH_I2S1_MODULE, 31 | PERIPH_TIMG0_MODULE, 32 | PERIPH_TIMG1_MODULE, 33 | PERIPH_PWM0_MODULE, 34 | PERIPH_PWM1_MODULE, 35 | PERIPH_PWM2_MODULE, 36 | PERIPH_PWM3_MODULE, 37 | PERIPH_UHCI0_MODULE, 38 | PERIPH_UHCI1_MODULE, 39 | PERIPH_RMT_MODULE, 40 | PERIPH_PCNT_MODULE, 41 | PERIPH_SPI_MODULE, 42 | PERIPH_HSPI_MODULE, 43 | PERIPH_VSPI_MODULE, 44 | PERIPH_SPI_DMA_MODULE, 45 | PERIPH_SDMMC_MODULE, 46 | PERIPH_SDIO_SLAVE_MODULE, 47 | PERIPH_CAN_MODULE, 48 | PERIPH_EMAC_MODULE, 49 | PERIPH_RNG_MODULE, 50 | PERIPH_WIFI_MODULE, 51 | PERIPH_BT_MODULE, 52 | PERIPH_WIFI_BT_COMMON_MODULE, 53 | PERIPH_BT_BASEBAND_MODULE, 54 | PERIPH_BT_LC_MODULE, 55 | PERIPH_AES_MODULE, 56 | PERIPH_SHA_MODULE, 57 | PERIPH_RSA_MODULE, 58 | } periph_module_t; 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* _SOC_PERIPH_DEFS_H_ */ 65 | -------------------------------------------------------------------------------- /tests/c_headers/phy.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | #include "esp_phy_init.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #define ESP_CAL_DATA_CHECK_FAIL 1 23 | 24 | /** 25 | * @file phy.h 26 | * @brief Declarations for functions provided by libphy.a 27 | */ 28 | 29 | /** 30 | * @brief Return ROM function pointer table from PHY library. 31 | */ 32 | void phy_get_romfunc_addr(void); 33 | 34 | /** 35 | * @brief Initialize PHY module and do RF calibration 36 | * @param[in] init_data Initialization parameters to be used by the PHY 37 | * @param[inout] cal_data As input, calibration data previously obtained. As output, will contain new calibration data. 38 | * @param[in] cal_mode RF calibration mode 39 | * @return ESP_CAL_DATA_CHECK_FAIL if calibration data checksum fails, other values are reserved for future use 40 | */ 41 | int register_chipv7_phy(const esp_phy_init_data_t* init_data, esp_phy_calibration_data_t *cal_data, esp_phy_calibration_mode_t cal_mode); 42 | 43 | /** 44 | * @brief Get the format version of calibration data used by PHY library. 45 | * @return Format version number, OR'ed with BIT(16) if PHY is in WIFI only mode. 46 | */ 47 | uint32_t phy_get_rf_cal_version(); 48 | 49 | /** 50 | * @brief Set RF/BB for only WIFI mode or coexist(WIFI & BT) mode 51 | * @param[in] true is for only WIFI mode, false is for coexist mode. default is 0. 52 | * @return NULL 53 | */ 54 | void phy_set_wifi_mode_only(bool wifi_only); 55 | 56 | /** 57 | * @brief Set BT the highest priority in coexist mode. 58 | * @return NULL 59 | */ 60 | void coex_bt_high_prio(void); 61 | 62 | /** 63 | * @brief Shutdown PHY and RF. 64 | */ 65 | void phy_close_rf(void); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | -------------------------------------------------------------------------------- /tests/c_headers/replace-cint_t-to-nim-types.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ruby -i -pe '$_.gsub!(/((?:uint|int))(\d+)_t/, "\\1\\2")' $* 4 | -------------------------------------------------------------------------------- /tests/c_headers/spi_types.h: -------------------------------------------------------------------------------- 1 | 2 | typedef enum { 3 | SPI1_HOST=0, ///< SPI1 4 | SPI2_HOST=1, ///< SPI2 5 | SPI3_HOST=2, ///< SPI3 6 | } spi_host_device_t; 7 | 8 | -------------------------------------------------------------------------------- /tests/driver/tadc.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/adc 2 | export adc 3 | 4 | -------------------------------------------------------------------------------- /tests/driver/tadc2_wifi_internal.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/adc2_wifi_internal 2 | export adc2_wifi_internal 3 | -------------------------------------------------------------------------------- /tests/driver/tdac.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/dac 2 | export dac 3 | -------------------------------------------------------------------------------- /tests/driver/tesp_timer.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/timers 3 | 4 | proc example_cb*(arg: pointer) {.cdecl.} = 5 | echo "Done!" 6 | 7 | var x = "hello" 8 | 9 | var timer1 = createTimer( 10 | callback= example_cb, 11 | arg= x.cstring, 12 | dispatch_method= ESP_TIMER_TASK, 13 | name= "timer1") 14 | 15 | discard esp_timer_start_periodic(timer1, 1000.uint64) 16 | 17 | -------------------------------------------------------------------------------- /tests/driver/tgpio.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/gpio_driver 2 | export gpio_driver 3 | -------------------------------------------------------------------------------- /tests/driver/ti2c.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/i2c 2 | export i2c 3 | -------------------------------------------------------------------------------- /tests/driver/ti2s.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/i2s 2 | export i2s 3 | -------------------------------------------------------------------------------- /tests/driver/tledc.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/ledc 2 | export ledc 3 | -------------------------------------------------------------------------------- /tests/driver/tmcpwm.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/mcpwm 2 | export mcpwm 3 | -------------------------------------------------------------------------------- /tests/driver/tpcnt.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/pcnt 2 | export pcnt 3 | -------------------------------------------------------------------------------- /tests/driver/tperiph_ctrl.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/periph_ctrl 2 | export periph_ctrl 3 | -------------------------------------------------------------------------------- /tests/driver/trmt.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/rmt 2 | export rmt 3 | -------------------------------------------------------------------------------- /tests/driver/trtc_cntl.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/rtc_cntl 2 | export rtc_cntl 3 | -------------------------------------------------------------------------------- /tests/driver/trtc_io.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/rtc_io 2 | export rtc_io 3 | -------------------------------------------------------------------------------- /tests/driver/tsdio_slave.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/sdio_slave 2 | export sdio_slave 3 | -------------------------------------------------------------------------------- /tests/driver/tsdmmc_defs.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/sdmmc_defs 2 | export sdmmc_defs 3 | 4 | export sdmmc_defs -------------------------------------------------------------------------------- /tests/driver/tspi.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/spi 2 | export spi 3 | -------------------------------------------------------------------------------- /tests/driver/tspi_slave.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/spi_slave 2 | export spi_slave 3 | -------------------------------------------------------------------------------- /tests/driver/ttimer.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/timer 2 | export timer 3 | -------------------------------------------------------------------------------- /tests/driver/ttouch_pad.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/touch_pad 2 | export touch_pad 3 | -------------------------------------------------------------------------------- /tests/driver/tuart.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/uart 2 | export uart 3 | -------------------------------------------------------------------------------- /tests/driver/tuart_reg.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/driver/uart_reg 2 | export uart_reg 3 | -------------------------------------------------------------------------------- /tests/echosocket_test.nim: -------------------------------------------------------------------------------- 1 | import json 2 | import net, os 3 | 4 | import msgpack4nim/msgpack2json 5 | 6 | 7 | # ## Test Call 1 ## 8 | # echo "\n## Call 1 ##" 9 | # var call1 = %* { 10 | # "jsonrpc": "2.0", "id": 1, 11 | # "method": "hello", "params": ["world"], 12 | # } 13 | 14 | ## Test Call 2 ## 15 | echo "\n## Call 2 ##" 16 | var call2 = %* { "jsonrpc": "2.0", "id": 1, "method": "add", "params": [1, 2] } 17 | 18 | let client: Socket = newSocket(buffered=false) 19 | client.connect("192.168.1.15", Port(5555)) 20 | echo("connected to server") 21 | os.sleep(500) 22 | 23 | let mcall2 = call2.fromJsonNode() 24 | echo("mcall2: " & repr(mcall2)) 25 | client.send( mcall2 & "\n") 26 | 27 | # var msg: string = newString(4096) 28 | # var count = client.recv(msg, 4095) 29 | var msg = client.recv(4095, timeout = -1) 30 | echo("read: " & $msg.len()) 31 | echo("read: " & repr(msg)) 32 | 33 | client.close() 34 | -------------------------------------------------------------------------------- /tests/exec_tests/.gitignore: -------------------------------------------------------------------------------- 1 | tgeneral 2 | trouter 3 | tgeneral 4 | tspi 5 | *_exec 6 | -------------------------------------------------------------------------------- /tests/exec_tests/tgeneral_exec.nim: -------------------------------------------------------------------------------- 1 | import strutils 2 | import nesper 3 | import algorithm 4 | 5 | let n1 = joinBytes32[uint32]([0x01'u8, 0x02, 0x03], 3) 6 | let n2 = joinBytes32[uint32]([0x01'u8, 0x02, 0x03], 2) 7 | let n3 = joinBytes32[uint32]([0x01'u8, 0x02, 0x03], 1) 8 | 9 | let n4 = joinBytes32[int32]([0xFF'u8, 0xFF, 0xFF, 0xFF], 4) 10 | let n5 = joinBytes32[int32]([0xFF'u8, 0xFF, 0xFF, 0xFE], 4) 11 | 12 | let n6 = joinBytes64[int64]([0xFF'u8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE], 8) 13 | 14 | let n7 = joinBytes32[uint32]([0x01'u8, 0x02, 0x03], 3, top=true) 15 | let n8 = joinBytes32[int32]([0xFF'u8, 0xFF, 0xFF], 4, top=true) 16 | 17 | let n9 = joinBytes64[int64]([0xFF'u8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE], 7, top=true) 18 | 19 | let n10 = joinBytes32[int32]([0'u8, 255, 234, 221][1..3], 3, top=true) shr 8 20 | 21 | assert n1 == 0x010203'u32, "got: " & $toHex(n1) 22 | assert n2 == 0x0102'u32, "got: " & $n2.toHex() 23 | assert n3 == 0x01'u32, "got: " & $n3.toHex() 24 | 25 | assert n4 == -1, "got: " & $n4.toHex() & " int: " & $n4 26 | assert n5 == -2, "got: " & $n5.toHex() & " int: " & $n5 27 | 28 | assert n6 == -2'i64, "got: " & $n6.toHex() & " int: " & $n6 29 | 30 | assert n7 == 0x01020300'u32, "got: " & $n7.toHex() & " int: " & $n7 31 | assert (ashr(n8 , 8)) == -1'i32, "got: " & $n8.toHex() & " int: " & $n8 32 | 33 | assert (ashr(n9 , 8)) == -2'i64, "got: " & $n9.toHex() & " int: " & $n9 34 | 35 | echo " n10 == -5411 got: " & $(n10) 36 | assert n10 == -5411, "got: " & $(n10) 37 | 38 | let o1 = splitBytes(0x12345678'u32, 3) 39 | let o2 = splitBytes(0x12345678'u32, 3, top=true) 40 | 41 | let o3 = splitBytes(0x12345678_9ABCDEFF'u64, 8) 42 | 43 | assert o1 == @[0x78'u8, 0x56'u8, 0x34'u8], "got: " & $(o1) 44 | assert o2 == @[byte 0x12, 0x34, 0x56], "got: " & $(o2) 45 | 46 | var 47 | o3t = @[byte 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF] 48 | o3r: seq[byte] = o3t.reversed() 49 | 50 | assert o3 == o3r, "got: " & $(o3) 51 | # let o3 = splitBytes(0x12345678_9ABCDEF'u64, 3) 52 | 53 | echo "GENERAL" 54 | -------------------------------------------------------------------------------- /tests/exec_tests/trouter_exec.nim: -------------------------------------------------------------------------------- 1 | import json, tables, macros, options 2 | 3 | import nesper/servers/rpc/router 4 | 5 | type 6 | MyObject = object 7 | id: int 8 | name: string 9 | 10 | # Setup RPC Server # 11 | var rt1 = createRpcRouter(4096) 12 | 13 | rt1.rpc("hello") do(input: string) -> string: 14 | result = "Hello " & input 15 | 16 | rt1.rpc("add") do(a: int, b: int) -> int: 17 | result = a + b 18 | 19 | 20 | ## Test Call 1 ## 21 | echo "\n## Call 1 ##" 22 | var call1 = %* { 23 | "jsonrpc": "2.0", "id": 1, 24 | "method": "hello", "params": ["world"], 25 | } 26 | var res1 = rt1.route( call1 ) 27 | echo "Result 1: " 28 | echo res1 29 | assert res1["result"].getStr() == "Hello world" 30 | 31 | ## Test Call 2 ## 32 | echo "\n## Call 2 ##" 33 | var call2 = %* { "jsonrpc": "2.0", "id": 1, "method": "add", "params": [1, 2], } 34 | 35 | echo "arg call2: " & $call2 36 | var res2 = rt1.route( call2 ) 37 | echo "Result 2: " 38 | echo res2 39 | assert res2["result"].getInt() == 3 40 | 41 | 42 | ## Test Call 3: incorrect arguments ## 43 | echo "\n## Call 3 ##" 44 | let err_res = %* { 45 | "jsonrpc": "2.0", 46 | "id": 1, 47 | "error": { 48 | "code": -32000, 49 | "id": 1, 50 | "message": "\"add raised an exception\"", 51 | "data": "Parameter [a] expected JInt but got JString" 52 | } 53 | } 54 | 55 | var call3 = %* { 56 | "jsonrpc": "2.0", "id": 1, 57 | "method": "add", "params": ["abc", "def"], 58 | } 59 | var res3 = rt1.route( call3 ) 60 | echo "Result 3: " 61 | echo res3 62 | 63 | delete(res3["error"], "stacktrace") 64 | assert res3 == err_res 65 | -------------------------------------------------------------------------------- /tests/nim.cfg: -------------------------------------------------------------------------------- 1 | --path:"../src/" 2 | 3 | --gc:arc 4 | --os:freertos 5 | -d:use_malloc 6 | -d:no_signal_handler 7 | --debugger:native 8 | --threads:on 9 | --tls_emulation:off 10 | 11 | -------------------------------------------------------------------------------- /tests/storage/tesp_app_format.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_app_format 2 | export esp_app_format 3 | -------------------------------------------------------------------------------- /tests/storage/tesp_flash.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_flash 2 | export esp_flash 3 | -------------------------------------------------------------------------------- /tests/storage/tesp_flash_encrypt.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_flash_encrypt 2 | export esp_flash_encrypt 3 | -------------------------------------------------------------------------------- /tests/storage/tesp_flash_partitions.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_flash_partitions 2 | export esp_flash_partitions 3 | -------------------------------------------------------------------------------- /tests/storage/tesp_ota_ops.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_ota_ops 2 | export esp_ota_ops 3 | -------------------------------------------------------------------------------- /tests/storage/tesp_partition.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_partition 2 | export esp_partition 3 | -------------------------------------------------------------------------------- /tests/storage/tesp_spi_flash.nim: -------------------------------------------------------------------------------- 1 | import nesper/esp/storage/esp_spi_flash 2 | export esp_spi_flash 3 | -------------------------------------------------------------------------------- /tests/tconsts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EmbeddedNim/nesper/f54fff8b240e94684ae8ce0ffe2485cfd425497c/tests/tconsts -------------------------------------------------------------------------------- /tests/tconsts.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper 3 | 4 | 5 | echo "ESP_OK: " & $ESP_OK 6 | 7 | echo "ESP_OK: " & $(ESP_OK) 8 | echo "ESP_FAIL: " & $(ESP_FAIL) 9 | echo "ESP_ERR_NO_MEM: " & $(ESP_ERR_NO_MEM) 10 | echo "ESP_ERR_INVALID_ARG: " & $(ESP_ERR_INVALID_ARG) 11 | echo "ESP_ERR_INVALID_STATE: " & $(ESP_ERR_INVALID_STATE) 12 | echo "ESP_ERR_INVALID_SIZE: " & $(ESP_ERR_INVALID_SIZE) 13 | echo "ESP_ERR_NOT_FOUND: " & $(ESP_ERR_NOT_FOUND) 14 | echo "ESP_ERR_NOT_SUPPORTED: " & $(ESP_ERR_NOT_SUPPORTED) 15 | echo "ESP_ERR_TIMEOUT: " & $(ESP_ERR_TIMEOUT) 16 | echo "ESP_ERR_INVALID_RESPONSE: " & $(ESP_ERR_INVALID_RESPONSE) 17 | echo "ESP_ERR_INVALID_CRC: " & $(ESP_ERR_INVALID_CRC) 18 | echo "ESP_ERR_INVALID_VERSION: " & $(ESP_ERR_INVALID_VERSION) 19 | echo "ESP_ERR_INVALID_MAC: " & $(ESP_ERR_INVALID_MAC) 20 | echo "ESP_ERR_WIFI_BASE: " & $(ESP_ERR_WIFI_BASE) 21 | echo "ESP_ERR_MESH_BASE: " & $(ESP_ERR_MESH_BASE) 22 | echo "ESP_ERR_FLASH_BASE: " & $(ESP_ERR_FLASH_BASE) 23 | -------------------------------------------------------------------------------- /tests/test_repr.nim: -------------------------------------------------------------------------------- 1 | 2 | type 3 | Example[T] = ref object 4 | a*: T 5 | id*: int 6 | 7 | 8 | proc testprint[T](a: T, obj: Example) = 9 | echo("testprint: a: " & $(repr(a))) 10 | echo("testprint: obj: " & $(repr(obj))) 11 | obj.id.inc(10) 12 | 13 | 14 | var e1 = Example[string](a: "test", id: 3) 15 | 16 | testprint("example", e1) 17 | 18 | echo("example: : " & $(e1.id)) 19 | -------------------------------------------------------------------------------- /tests/teth_modules.nim: -------------------------------------------------------------------------------- 1 | # import nesper/esp/net/esp_eth_com 2 | # import nesper/esp/net/esp_eth_mac 3 | # import nesper/esp/net/esp_eth_phy 4 | import nesper/esp/net/esp_eth 5 | 6 | 7 | export esp_eth -------------------------------------------------------------------------------- /tests/tgeneral.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper 3 | import nesper/general 4 | import nesper/timers 5 | 6 | 7 | const TAG = "main" 8 | 9 | logi(TAG, "Initializing device...") 10 | logd(TAG, "Initializing device: %d", 23) 11 | 12 | echo "ESP_OK: " & $ESP_OK 13 | echo "" 14 | 15 | var portTICK_PERIOD_MS* {.importc: "portTICK_PERIOD_MS", header: "".}: cint 16 | 17 | discard delayMillis(100) 18 | delay(Millis(100)) 19 | discard delayMicros(100) 20 | delay(Micros(100)) 21 | esp_restart() 22 | 23 | # vTaskDelete*( handle: any ) 24 | 25 | echo "ESP_ERR_FLASH_BASE: " & $esp_err_to_name(ESP_ERR_FLASH_BASE) 26 | 27 | ESP_ERROR_CHECK(ESP_OK) 28 | ESP_ERROR_CHECK(ESP_ERR_INVALID_ARG) 29 | 30 | ESP_ERROR_CHECK_WITHOUT_ABORT(ESP_OK) 31 | ESP_ERROR_CHECK_WITHOUT_ABORT(ESP_ERR_INVALID_ARG) 32 | -------------------------------------------------------------------------------- /tests/tgpios.nim: -------------------------------------------------------------------------------- 1 | import nesper/gpios 2 | 3 | {GPIO_NUM_11, GPIO_NUM_2}.configure(GPIO_MODE_OUTPUT) 4 | {GPIO_NUM_10, GPIO_NUM_3}.configure(GPIO_MODE_INPUT) 5 | {GPIO_NUM_12}.configure(GPIO_MODE_INPUT, pull_up=true) 6 | {GPIO_NUM_13}.configure(GPIO_MODE_INPUT, pull_down=true) 7 | {GPIO_NUM_13}.configure(GPIO_MODE_OUTPUT_OD, pull_down=true) 8 | {GPIO_NUM_14}.configure(GPIO_MODE_INPUT_OUTPUT, interrupt = GPIO_INTR_ANYEDGE) 9 | 10 | GPIO_NUM_14.setLevel(true) 11 | 12 | let state = GPIO_NUM_13.getLevel() 13 | echo("gpio 14: " & $state) -------------------------------------------------------------------------------- /tests/ti2cs.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper 3 | import nesper/i2cs 4 | 5 | export i2cs 6 | 7 | 8 | var 9 | port1 = newI2CMaster(port = I2C_NUM_0, 10 | sda_io_num = gpio_num_t(0), ## !< GPIO number for I2C sda signal 11 | scl_io_num = gpio_num_t(1), ## !< GPIO number for I2C scl signal 12 | clk_speed = 100_000.Hertz, 13 | sda_pullup_en = false, ## !< Internal GPIO pull mode for I2C sda signal 14 | scl_pullup_en = false, ## !< Internal GPIO pull mode for I2C scl signal 15 | intr_alloc_flags = {}) 16 | 17 | var 18 | cmd1 = port1.newCmd() 19 | 20 | cmd1.start() 21 | cmd1.writeByte(0x22) 22 | cmd1.write([0x12'u8, 0x13, 0x14]) 23 | cmd1.start() 24 | cmd1.writeByte(0x23) 25 | 26 | # var 27 | # b1 = cmd1.readByte(ACK) 28 | # b2 = cmd1.readByte(NACK) 29 | # b3 = cmd1.readByte(LAST_NACK) 30 | # b4 = cmd1.read(3, LAST_NACK) 31 | # cmd1.stop() 32 | # port1.submit(cmd1, 10.Millis) 33 | # echo("bytes: ", b1, b2, b3, b4) 34 | 35 | -------------------------------------------------------------------------------- /tests/tledc.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/esp/driver/ledc 3 | 4 | export ledc 5 | 6 | -------------------------------------------------------------------------------- /tests/tmdns.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/esp/mdns 3 | 4 | export mdns 5 | -------------------------------------------------------------------------------- /tests/tnvs.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/nvs_utils 3 | 4 | 5 | let nvs_handle = newNvs("storage", NVS_READWRITE) 6 | nvs_handle.setInt("a", 1) 7 | let a = nvs_handle.getInt("a") 8 | echo "a: " & $a 9 | 10 | nvs_handle.setStr("b", "bb") 11 | let b = nvs_handle.getStr("b") 12 | echo "b: " & $b 13 | 14 | -------------------------------------------------------------------------------- /tests/tqueues.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/queues 3 | 4 | export queues 5 | -------------------------------------------------------------------------------- /tests/tsocket_echo.nim: -------------------------------------------------------------------------------- 1 | import nativesockets 2 | import net 3 | import selectors 4 | import tables 5 | import posix 6 | 7 | type 8 | ServerInfo = ref object 9 | select: Selector[int] 10 | server: Socket 11 | clients: ref Table[SocketHandle, Socket] 12 | 13 | proc createServerInfo(server: Socket, selector: Selector[int]): ServerInfo = 14 | result = new(ServerInfo) 15 | result.server = server 16 | result.select = selector 17 | result.clients = newTable[SocketHandle, Socket]() 18 | 19 | 20 | proc handleWrites(result: ReadyKey, srv: ServerInfo) = 21 | raise newException(OSError, "the request to the OS failed") 22 | 23 | proc handleReads(selected: ReadyKey, srv: ServerInfo) = 24 | if selected.fd.SocketHandle == srv.server.getFd(): 25 | var client: Socket = new(Socket) 26 | srv.server.accept(client) 27 | 28 | client.getFd().setBlocking(false) 29 | srv.select.registerHandle(client.getFd(), {Event.Read}, -1) 30 | srv.clients[client.getFd()] = client 31 | stdout.writeLine("Server: client connected") 32 | 33 | else: 34 | var sourceClient: Socket = newSocket(selected.fd.SocketHandle) 35 | var message = sourceClient.recvLine() 36 | 37 | if message == "": 38 | 39 | var client: Socket 40 | discard srv.clients.pop(sourceClient.getFd(), client) 41 | srv.select.unregister(sourceClient.getFd()) 42 | stdout.writeLine("Server: client disconnected: " & $(sourceClient.getFd().getSockName())) 43 | 44 | else: 45 | stdout.writeLine("Server: received from client: ", message) 46 | 47 | for cfd, client in srv.clients: 48 | # if sourceClient.getFd() == cfd.getFd() : 49 | # continue 50 | client.send(message & "\r\L") 51 | 52 | proc runTcpServer*() {.exportc.} = 53 | var server: Socket = newSocket() 54 | var select: Selector[int] = newSelector[int]() 55 | 56 | server.setSockOpt(OptReuseAddr, true) 57 | server.getFd().setBlocking(false) 58 | server.bindAddr(Port(5555)) 59 | server.listen() 60 | stdout.writeLine("Server: started. Listening to new connections on port 5555...") 61 | 62 | var srv = createServerInfo(server, select) 63 | 64 | select.registerHandle(server.getFd(), {Event.Read}, -1) 65 | # var clients: seq[Socket] = @[] 66 | 67 | while true: 68 | var results: seq[ReadyKey] = select.select(-1) 69 | 70 | for result in results: 71 | if Event.Read in result.events: 72 | result.handleReads(srv) 73 | if Event.Write in result.events: 74 | result.handleWrites(srv) 75 | 76 | select.close() 77 | server.close() 78 | 79 | 80 | when isMainModule: 81 | runTcpServer() -------------------------------------------------------------------------------- /tests/tspi.nim: -------------------------------------------------------------------------------- 1 | import nesper/spis 2 | 3 | # define PIN_NUM_MISO 37 4 | # define PIN_NUM_MOSI 35 5 | # define PIN_NUM_CLK 36 6 | # define PIN_NUM_CS 34 7 | 8 | let 9 | bus = HSPI.newSpiBus(miso=gpio_num_t(9), mosi=gpio_num_t(10), sclk=gpio_num_t(12), dma_channel=2, flags={MASTER}) 10 | 11 | var 12 | dev: SpiDev = 13 | bus.addDevice(commandlen = bits(3), 14 | addresslen = bits(4), 15 | mode=1, cs_io=gpio_num_t(23), 16 | clock_speed_hz = 1_000_000, 17 | queue_size = 10, 18 | flags={HALFDUPLEX}) 19 | 20 | 21 | let tdata1 = [byte 1, 2] 22 | let trn1 = dev.fullTrans(tdata1) 23 | 24 | # read non-byte number of bits 25 | var tdata2 = [byte 1, 2, 3] 26 | var trn2 = dev.fullTrans(tdata2, rxlength=bits(20)) 27 | 28 | var trn3 = dev.fullTrans([byte 1, 2, 3, 4, 5]) 29 | 30 | var tdata4 = @[1'u8, 2, 3] 31 | var trn4 = dev.fullTrans(tdata4) 32 | 33 | var trn5 = dev.readTrans(bytes(3)) 34 | # this is an error: let trn5 = dev.readTrans(@[1'u8, 2, 3, 4, 5]) 35 | 36 | var trn6 = dev.writeTrans(@[1'u8, 2, 3, 4, 5]) 37 | 38 | echo "trn1: " & repr(trn1) 39 | echo "trn2: " & repr(trn2) 40 | echo "trn3: " & repr(trn3) 41 | echo "trn4: " & repr(trn4) 42 | echo "trn5: " & repr(trn5) 43 | echo "trn5: " & repr(trn6) 44 | 45 | # Example: spi poll fullTransmission 46 | trn1.poll() 47 | 48 | # Example spi queued fullTransaction 49 | trn2.queue() 50 | 51 | # Example aquire bus 52 | withSpiBus(dev): 53 | trn3.poll() 54 | trn4.poll() 55 | 56 | # Regular spi transmit 57 | trn5.transmit() 58 | 59 | -------------------------------------------------------------------------------- /tests/tuarts.nim: -------------------------------------------------------------------------------- 1 | 2 | import nesper/consts 3 | import nesper/uarts 4 | 5 | export uarts 6 | 7 | 8 | var cfg0 = newUartConfig(baud_rate = 9600) 9 | 10 | var urt0 = cfg0.newUart(UART_NUM_0, 11 | tx_pin = GPIO_NUM_4, 12 | rx_pin = GPIO_NUM_5, 13 | buffer = 2048.SzBytes) 14 | 15 | # urt0.read() 16 | 17 | echo "urt0: ", $urt0.port 18 | 19 | var buff = urt0.read(1023.SzBytes) 20 | 21 | urt0.write(buff) 22 | --------------------------------------------------------------------------------