espressif/esp-idf-cxx
uploaded 2 months ago

C++ wrapper classes around ESP IDF components

readme

# ESP-IDF-C++ This project provides C++ wrapper classes around some components of [esp-idf](https://github.com/espressif/esp-idf). It is organized as a component for the [IDF component manager](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-component-manager.html). You can find this component [in the component registry](https://components.espressif.com/components/espressif/esp-idf-cxx). ## *NOTE* This component is in a beta-release phase. Some bits that are still missing (non-exhaustive list): * MQTT C++ classes * Default pin definition on Kconfig for some examples A road map and detailed release document will be announced soon. ## Requirements * ESP-IDF and its requirements. Please follow the [ESP-IDF "Get Started" Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html) to download, install and setup esp-idf. No other special requirements are necessary. ## Usage Set up the IDF environment (i.e., `. ./export.sh` inside [esp-idf](https://github.com/espressif/esp-idf)). Then go to your project directory, use `idf.py add-dependency espressif/esp-idf-cxx^1.0.0-beta ` (should only be done once) and you should be able to use this component.

readme of esp_event_async_cxx example

# ESP-Event asynchronous example (See the README.md file in the upper level 'examples' directory for more information about examples.) ## How to use example ### Configure the project ``` idf.py menuconfig ``` * Set serial port under Serial Flasher Options. ### Build and Flash Build the project and flash it to the board, then run monitor tool to view serial output: ``` idf.py -p PORT flash monitor ``` (To exit the serial monitor, type ``Ctrl-]``.) See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. ## Example Output The object is created twice, hence the started Eventloop and finished destruction lines appear twice. ``` NORMAL TESTING... received event: test/0; data: 47 received event: test/1 TIMEOUT TESTING... received event: test/0 TIMEOUT for event: test/0 I (10419) ESP Event C++ Async: Finished example ```

readme of esp_timer_cxx example

# Example: ESPTimer C++ class (See the README.md file in the upper level 'examples' directory for more information about examples.) This example demonstrates usage of the ESPTimer c++ class in ESP-IDF. In this example, the `sdkconfig.defaults` file sets the `CONFIG_COMPILER_CXX_EXCEPTIONS` option. This enables both compile time support (`-fexceptions` compiler flag) and run-time support for C++ exception handling. This is necessary for the C++ APIs. ## How to use example ### Hardware Required Any ESP32 family development board. ### Configure the project ``` idf.py menuconfig ``` ### Build and Flash ``` idf.py -p PORT flash monitor ``` (Replace PORT with the name of the serial port.) (To exit the serial monitor, type ``Ctrl-]``.) See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. ## Example Output ``` Setting up timer to trigger in 500ms timeout Setting up timer to periodically every 200ms periodic timeout periodic timeout periodic timeout periodic timeout periodic timeout Finished ```

readme of simple_i2c_rw_example example

# Example: C++ I2C sensor read for MPU9250 (See the README.md file in the upper level 'examples' directory for more information about examples.) This example demonstrates usage of C++ exceptions in ESP-IDF. It is the C++ equivalent to the [I2C Simple Example](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/i2c/i2c_simple/) which is written in C. In this example, the `sdkconfig.defaults` file sets the `CONFIG_COMPILER_CXX_EXCEPTIONS` option. This enables both compile time support (`-fexceptions` compiler flag) and run-time support for C++ exception handling. This is necessary for the C++ I2C API. ## How to Use This Example ### Hardware Required To run this example, you should have one ESP32, ESP32-S series or ESP32-C series based development board as well as an MPU9250. MPU9250 is an inertial measurement unit, which contains an accelerometer, gyroscope as well as a magnetometer, for more information about it, you can read the [datasheet of the MPU9250 sensor](https://invensense.tdk.com/wp-content/uploads/2015/02/PS-MPU-9250A-01-v1.1.pdf). #### Pin Assignment: **Note:** The following pin assignments are used by default, you can change these in the `menuconfig` . | | SDA | SCL | | ---------------- | -------------- | -------------- | | ESP I2C Master | I2C_MASTER_SDA | I2C_MASTER_SCL | | MPU9250 Sensor | SDA | SCL | For the actual default value of `I2C_MASTER_SDA` and `I2C_MASTER_SCL`, see `Example Configuration` in `menuconfig`. **Note:** There's no need to add external pull-up resistors for SDA/SCL pins, because the driver will enable the internal pull-up resistors. ### Configure the project ``` idf.py menuconfig ``` ### Build and Flash ``` idf.py -p <PORT> flash monitor ``` Replace <PORT> with the name of the serial port. To exit the serial monitor, type ``Ctrl-]``. See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects. ## Example Output If the sensor is read correctly: ```bash I (328) i2c-simple-example: I2C initialized successfully I (338) i2c-simple-example: WHO_AM_I = 71 I (338) i2c-simple-example: I2C de-initialized successfully ``` If something went wrong: ``` I2C Exception with error: ESP_FAIL (-1) Couldn't read sensor! ```

readme of simple_spi_rw_example example

# Example: C++ SPI sensor read for MCU9250 inertial/giroscope sensor (See the README.md file in the upper level 'examples' directory for more information about examples.) This example demonstrates usage of C++ SPI classes in ESP-IDF to read the `WHO_AM_I` register of the sensor. In this example, the `sdkconfig.defaults` file sets the `CONFIG_COMPILER_CXX_EXCEPTIONS` option. This enables both compile time support (`-fexceptions` compiler flag) and run-time support for C++ exception handling. This is necessary for the C++ SPI API. ## How to use example ### Hardware Required An MCU9250 sensor and any commonly available ESP32 development board. ### Configure the project ``` idf.py menuconfig ``` ### Build and Flash ``` idf.py -p PORT flash monitor ``` (Replace PORT with the name of the serial port.) (To exit the serial monitor, type ``Ctrl-]``.) See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. ## Example Output If the sensor is read correctly: ``` ... I (0) cpu_start: Starting scheduler on APP CPU. Result of WHO_AM_I register: 0x71 I (437) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (447) gpio: GPIO[25]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (457) gpio: GPIO[26]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (467) gpio: GPIO[27]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 Done ``` If there's an error with the SPI peripheral: ``` ... I (0) cpu_start: Starting scheduler on APP CPU. E (434) spi: spicommon_bus_initialize_io(429): mosi not valid Couldn't read SPI! ``` If the SPI pins are not connected properly, the resulting read may just return 0, this error can not be detected: ``` ... I (0) cpu_start: Starting scheduler on APP CPU. Result of WHO_AM_I register: 0x00 I (437) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (447) gpio: GPIO[25]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (457) gpio: GPIO[26]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (467) gpio: GPIO[27]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 ```

Links

Supports all targets

License: Apache-2.0

To add this component to your project, run:

idf.py add-dependency "espressif/esp-idf-cxx^1.0.2-beta"

or download archive

Dependencies

  • ESP-IDF >=5.0
  • Examples:

    blink_cxx

    more details

    esp_event_async_cxx

    more details

    esp_timer_cxx

    more details

    simple_i2c_rw_example

    more details

    simple_spi_rw_example

    more details

    Stats

    • Downloaded in total
      Downloaded in total 2.9k times
    • Downloaded this version
      This version: 557 times

    Badge

    espressif/esp-idf-cxx version: 1.0.2-beta |