Arduino Core 3.3.0
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
|
||||
Ported to Arduino ESP32 by Evandro Copercini
|
||||
*/
|
||||
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLEScan.h>
|
||||
#include <BLEAdvertisedDevice.h>
|
||||
|
||||
int scanTime = 5; //In seconds
|
||||
BLEScan *pBLEScan;
|
||||
|
||||
class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
|
||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
|
||||
}
|
||||
};
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Scanning...");
|
||||
|
||||
BLEDevice::init("");
|
||||
pBLEScan = BLEDevice::getScan(); //create new scan
|
||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
||||
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
|
||||
pBLEScan->setInterval(100);
|
||||
pBLEScan->setWindow(99); // less or equal setInterval value
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
BLEScanResults *foundDevices = pBLEScan->start(scanTime, false);
|
||||
Serial.print("Devices found: ");
|
||||
Serial.println(foundDevices->getCount());
|
||||
Serial.println("Scan done!");
|
||||
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
|
||||
delay(2000);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode
|
||||
.dependencies.lock
|
||||
sdkconfig.esp32c6
|
||||
managed_components
|
||||
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.16.0)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(espidf-arduino-c6-ulp-blink)
|
||||
@@ -0,0 +1,9 @@
|
||||
# Arduino ULP Example for the ESP32-C6
|
||||
|
||||
This example shows how to run a C program on the ESP32-C6 ULP core with Arduino (as an component of ESP-IDF)
|
||||
|
||||
## Two programs run parallel
|
||||
|
||||
1. **Arduino on the High Power Core (HP Core):** The Arduino program blinks the onboard RGB
|
||||
2. **C Program on the Ultra-Low Power Core (ULP):** The ULP C program blinks an external LED connected to GPIO3
|
||||
|
||||
@@ -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
|
||||
@@ -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 a 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
|
||||
@@ -0,0 +1,28 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter, extra scripting
|
||||
; Upload options: custom port, speed, and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
;
|
||||
; Documentation: https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32c6]
|
||||
platform = espressif32
|
||||
framework = arduino, espidf
|
||||
board = esp32-c6-devkitc-1
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
Adafruit NeoPixel@1.12.3
|
||||
custom_component_remove =
|
||||
espressif/esp_hosted
|
||||
espressif/esp_wifi_remote
|
||||
espressif/esp-dsp
|
||||
espressif/esp32-camera
|
||||
espressif/libsodium
|
||||
espressif/esp-modbus
|
||||
espressif/qrcode
|
||||
espressif/esp_insights
|
||||
espressif/esp_diag_data_store
|
||||
espressif/esp_diagnostics
|
||||
espressif/esp_rainmaker
|
||||
espressif/rmaker_common
|
||||
@@ -0,0 +1,19 @@
|
||||
# C6 devkit has 8 MB flash
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
|
||||
# Enable ULP
|
||||
CONFIG_ULP_COPROC_ENABLED=y
|
||||
CONFIG_ULP_COPROC_TYPE_LP_CORE=y
|
||||
CONFIG_ULP_COPROC_RESERVE_MEM=8192
|
||||
|
||||
# Set log level
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=2
|
||||
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=2
|
||||
|
||||
# Arduino settings
|
||||
CONFIG_AUTOSTART_ARDUINO=y
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_MBEDTLS_PSK_MODES=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y
|
||||
@@ -0,0 +1,20 @@
|
||||
idf_component_register(SRCS "main.cpp")
|
||||
|
||||
#
|
||||
# ULP support additions to component CMakeLists.txt.
|
||||
#
|
||||
# 1. The ULP app name must be "ulp_main"
|
||||
set(ulp_app_name ulp_main)
|
||||
#
|
||||
# 2. Specify all assembly source files.
|
||||
# Paths are relative because ULP files are placed into a special directory "ulp"
|
||||
# in the root of the project
|
||||
set(ulp_s_sources "../ulp/blink.c")
|
||||
#
|
||||
# 3. List all the component source files which include automatically
|
||||
# generated ULP export file, ${ulp_app_name}.h:
|
||||
set(ulp_exp_dep_srcs "main.c")
|
||||
#
|
||||
# 4. Call function to build ULP binary and embed in project using the argument
|
||||
# values above.
|
||||
ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs})
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "ulp_lp_core.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
// Define the built-in RGB LED pin and number of LEDs
|
||||
#define LED_PIN 8
|
||||
#define NUM_LEDS 1
|
||||
|
||||
Adafruit_NeoPixel rgbLed(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// Define some colors
|
||||
struct RGB {
|
||||
uint8_t r, g, b;
|
||||
};
|
||||
|
||||
constexpr RGB COLOR_RED = {255, 0, 0};
|
||||
constexpr RGB COLOR_GREEN = {0, 255, 0};
|
||||
constexpr RGB COLOR_BLUE = {0, 0, 255};
|
||||
constexpr RGB COLOR_OFF = {0, 0, 0};
|
||||
|
||||
extern const uint8_t bin_start[] asm("_binary_ulp_main_bin_start"); //refering to app name ulp_main defined in CMakelists.txt
|
||||
extern const uint8_t bin_end[] asm("_binary_ulp_main_bin_end"); //refering to app name ulp_main defined in CMakelists.txt
|
||||
|
||||
void start_ulp_program() {
|
||||
// Change: Load the ULP binary into RTC memory
|
||||
ESP_ERROR_CHECK(ulp_lp_core_load_binary(bin_start, (bin_end - bin_start)));
|
||||
|
||||
// Change: Configure the ULP LP core wake-up source and timer
|
||||
ulp_lp_core_cfg_t cfg = {
|
||||
.wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER, // Wake up using LP timer
|
||||
.lp_timer_sleep_duration_us = 1000000, // 1-second sleep duration
|
||||
};
|
||||
|
||||
// Change: Start the ULP LP core program
|
||||
ESP_ERROR_CHECK(ulp_lp_core_run(&cfg));
|
||||
}
|
||||
|
||||
void setColor(const RGB& color) {
|
||||
rgbLed.setPixelColor(0, rgbLed.Color(color.r, color.g, color.b));
|
||||
rgbLed.show();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting ULP Program...");
|
||||
start_ulp_program();
|
||||
Serial.println("Starting RGB LED blinking...");
|
||||
rgbLed.begin(); // Initialize the NeoPixel library
|
||||
rgbLed.show(); // Turn off all LEDs initially
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Setting color to RED");
|
||||
setColor(COLOR_RED);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Setting color to GREEN");
|
||||
setColor(COLOR_GREEN);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Setting color to BLUE");
|
||||
setColor(COLOR_BLUE);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Turning off LED");
|
||||
setColor(COLOR_OFF);
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "ulp_lp_core.h"
|
||||
#include "ulp_lp_core_utils.h"
|
||||
#include "ulp_lp_core_gpio.h"
|
||||
|
||||
#define BLINK_PIN LP_IO_NUM_3 // Define the GPIO pin connected to the LED
|
||||
#define BLINK_DELAY_MS 1000 // Define the delay in milliseconds between toggles
|
||||
|
||||
// Global variables can be accessed from the main program
|
||||
volatile bool ulp_led_state;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialize the GPIO pin as output
|
||||
ulp_lp_core_gpio_init(BLINK_PIN);
|
||||
ulp_lp_core_gpio_output_enable(BLINK_PIN);
|
||||
|
||||
// Toggle the LED state
|
||||
ulp_led_state = !ulp_led_state;
|
||||
ulp_lp_core_gpio_set_level(BLINK_PIN, (int)ulp_led_state);
|
||||
|
||||
// Delay for BLINK_DELAY_MS
|
||||
ulp_lp_core_delay_us(BLINK_DELAY_MS * 1000);
|
||||
|
||||
/* ulp_lp_core_halt() is called automatically when main exits */
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user