Skip to content

Commit

Permalink
push WIP example
Browse files Browse the repository at this point in the history
This is an incomplete example
  • Loading branch information
2bndy5 committed Apr 9, 2024
1 parent 205ea24 commit 6d93a90
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 12 deletions.
12 changes: 12 additions & 0 deletions examples_esp/getting_started/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

# ESP component registry cache
managed_components/

# generated sdkconfig files
sdkconfig.*
!sdkconfig.defaults
6 changes: 6 additions & 0 deletions examples_esp/getting_started/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# include parent folder (repo root) as a component library
list(APPEND EXTRA_COMPONENT_DIRS ../../)
# in user projects (external to RF24 repo), they should use `idf_component_register()` instead
project(getting_started)
10 changes: 10 additions & 0 deletions examples_esp/getting_started/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config RF24_CE_PIN
int "The GPIO pin number used for the radio's CE pin"
help
If undefined, then the main app's code defaults to using pin 7.

config RF24_CSN_PIN
int "The GPIO pin number used for the radio's CSN pin"
help
If undefined, then the main app's code defaults to using pin 8.

21 changes: 21 additions & 0 deletions examples_esp/getting_started/dependencies.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dependencies:
espressif/esp_tinyusb:
component_hash: f151d680d6847bfcfd5d8eb6d1c3ff926c208e6b963b2e83643a141bc70baa15
source:
service_url: https://api.components.espressif.com/
type: service
version: 1.4.4
espressif/tinyusb:
component_hash: 6e128177d3fe5027750a75e1ff64c655a7b53fa64eff8c1a4a8a5a4daa7924d1
source:
service_url: https://api.components.espressif.com/
type: service
version: 0.15.0~7
idf:
component_hash: null
source:
type: idf
version: 5.2.1
manifest_hash: 65bdfdf3ce9ef7f7d3d9c4c075a17d649adf01fa2984a9b54e4b8b493274a309
target: esp32s2
version: 1.0.0
39 changes: 39 additions & 0 deletions examples_esp/getting_started/include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
46 changes: 46 additions & 0 deletions examples_esp/getting_started/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
23 changes: 23 additions & 0 deletions examples_esp/getting_started/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env]
platform = espressif32
framework = espidf

[env:adafruit_qtpy_esp32s2]
board = adafruit_qtpy_esp32s2
build_flags =
; using A1 for CE_PIN
-D CONFIG_RF24_CE_PIN=17
; using A2 for CSN_PIN
-D CONFIG_RF24_CSN_PIN=9
-D CONFIG_RF24_DEFAULT_MOSI=35
-D CONFIG_RF24_DEFAULT_MISO=37
-D CONFIG_RF24_DEFAULT_SCLK=36
1 change: 1 addition & 0 deletions examples_esp/getting_started/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_TINYUSB_CDC_ENABLED=y
19 changes: 19 additions & 0 deletions examples_esp/getting_started/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was automatically generated for projects
# without default 'CMakeLists.txt' file.

FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)

idf_component_register(SRCS ${app_sources}
REQUIRES RF24
# # for user projects (that don't belong in the RF24 repo), use the component registry
# REQUIRES nRF24/RF24
)

if(DEFINED CONFIG_RF24_CE_PIN)
target_compile_definitions(main PUBLIC CE_PIN=${CONFIG_RF24_CE_PIN})
endif()

if(DEFINED CONFIG_RF24_CSN_PIN)
target_compile_definitions(main PUBLIC CSN_PIN=${CONFIG_RF24_CSN_PIN})
endif()

4 changes: 4 additions & 0 deletions examples_esp/getting_started/src/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## IDF Component Manager Manifest File
dependencies:
espressif/esp_tinyusb: "^1"
idf: "^5.0"
92 changes: 92 additions & 0 deletions examples_esp/getting_started/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <RF24.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "tinyusb.h"
#include "tusb_cdc_acm.h"
#include "tusb_console.h"
#include "sdkconfig.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef CONFIG_RF24_CE_PIN
#define CE_PIN CONFIG_RF24_CE_PIN
#else
#define CE_PIN 7
#endif

#ifdef CONFIG_RF24_CSN_PIN
#define CSN_PIN CONFIG_RF24_CSN_PIN
#else
#define CSN_PIN 8
#endif

RF24 radio = RF24(CE_PIN, CSN_PIN);

static const char* TAG = "RF24/examples_esp/getting_started";

void setupSerialUSB(); // See definition below

void app_main(void)
{
setupSerialUSB();

SPIClass spi;
spi.begin();
fprintf(stdout, "SPI bus configured\n");

// if (!radio.begin(&spi)) {
// while (true) {
// fprintf(stdout, "radio hardware not responding!\n");
// }
// }
while (true) {
fprintf(stdout, "radio is ready to configure.\n");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

/** Setup TinyUSB for CDC serial communication */
void setupSerialUSB()
{
ESP_LOGI(TAG, "USB initialization");
const tinyusb_config_t tusb_cfg = {
.device_descriptor = NULL, // Use the default device descriptor specified in Menuconfig
.string_descriptor = NULL, // Use the default string descriptors specified in Menuconfig
.string_descriptor_count = 0,
.external_phy = false, // Use internal USB PHY (in most cases)
#if (TUD_OPT_HIGH_SPEED)
.fs_configuration_descriptor = NULL, // Use the default full-speed configuration descriptor according to settings in Menuconfig
.hs_configuration_descriptor = NULL, // Use the default high-speed configuration descriptor according to settings in Menuconfig
.qualifier_descriptor = NULL, // Use the default qualifier descriptor, with values from default device descriptor
#else
.configuration_descriptor = NULL, // Use the default configuration descriptor according to settings in Menuconfig
#endif // TUD_OPT_HIGH_SPEED
.self_powered = false,
.vbus_monitor_io = 0,
};
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));

const tinyusb_config_cdcacm_t acm_cfg = {
.usb_dev = TINYUSB_USBDEV_0,
.cdc_port = TINYUSB_CDC_ACM_0,
.rx_unread_buf_sz = 64,
.callback_rx = NULL,
.callback_rx_wanted_char = NULL,
.callback_line_state_changed = NULL,
.callback_line_coding_changed = NULL};
ESP_ERROR_CHECK(tusb_cdc_acm_init(&acm_cfg));

ESP_LOGI(TAG, "USB initialization DONE");
esp_tusb_init_console(TINYUSB_CDC_ACM_0); // log to usb

// the delay here isn't needed, but any `abort()` called immediately after this function would
// prevent the OS from seeing the USB port enumerated as a CDC Serial device
vTaskDelay(1000 / portTICK_PERIOD_MS); // remove this when lib is working properly
}

#ifdef __cplusplus
}
#endif
12 changes: 0 additions & 12 deletions utility/esp_idf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Include this file if you want to use the RF24 library
## in YOUR (ESP-IDF) project.
## See examples_esp/CMakeLists.txt to see how it could be done

cmake_minimum_required(VERSION 3.16.0)

Expand All @@ -14,14 +13,3 @@ idf_component_register(
INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/../../"
REQUIRES driver esp_timer # esp_driver_gpio esp_driver_spi
)

# add_library(RF24 STATIC
# ${CMAKE_CURRENT_LIST_DIR}/../../RF24.cpp
# ${CMAKE_CURRENT_LIST_DIR}/compatibility.cpp
# ${CMAKE_CURRENT_LIST_DIR}/gpio.cpp
# ${CMAKE_CURRENT_LIST_DIR}/spi.cpp
# )

# target_include_directories(RF24 PUBLIC
# ${CMAKE_CURRENT_LIST_DIR}/../../
# )

0 comments on commit 6d93a90

Please sign in to comment.