This commit is contained in:
Cyrus Yiu
2024-12-01 20:04:09 -05:00
commit 69eeea172e
8 changed files with 394 additions and 0 deletions

19
.clang-format Normal file
View File

@@ -0,0 +1,19 @@
BasedOnStyle: LLVM
AccessModifierOffset: 2
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
BreakBeforeBraces: Attach
ContinuationIndentWidth: 2
# ColumnLimit: 0
FixNamespaceComments: false
TabWidth: 2
IndentAccessModifiers: true
IndentCaseLabels: true
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 2
NamespaceIndentation: All
PointerAlignment: Left
UseTab: Never

148
.clang-tidy Normal file
View File

@@ -0,0 +1,148 @@
# Generated from CLion Inspection settings
---
Checks: '-*,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-bad-signal-to-kill-thread,
bugprone-branch-clone,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-dynamic-static-initializers,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-no-escape,
bugprone-not-null-terminated-result,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-reserved-identifier,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-spuriously-wake-up-functions,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-string-literal-with-embedded-nul,
bugprone-suspicious-enum-usage,
bugprone-suspicious-include,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-suspicious-string-compare,
bugprone-suspicious-memory-comparison,
bugprone-suspicious-realloc-usage,
bugprone-swapped-arguments,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
cert-dcl21-cpp,
cert-dcl58-cpp,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
cert-str34-c,
cppcoreguidelines-interfaces-global-init,
cppcoreguidelines-narrowing-conversions,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-slicing,
google-default-arguments,
google-explicit-constructor,
google-runtime-operator,
hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
misc-misplaced-const,
misc-new-delete-overloads,
misc-no-recursion,
misc-non-copyable-objects,
misc-throw-by-value-catch-by-reference,
misc-unconventional-assign-operator,
misc-uniqueptr-reset-release,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-deprecated-headers,
modernize-deprecated-ios-base-aliases,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-pass-by-value,
modernize-raw-string-literal,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-disallow-copy-and-assign-macro,
modernize-replace-random-shuffle,
modernize-return-braced-init-list,
modernize-shrink-to-fit,
modernize-unary-static-assert,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-nodiscard,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
mpi-buffer-deref,
mpi-type-mismatch,
openmp-use-default-none,
performance-faster-string-find,
performance-for-range-copy,
performance-implicit-conversion-in-loop,
performance-inefficient-algorithm,
performance-inefficient-string-concatenation,
performance-inefficient-vector-operation,
performance-move-const-arg,
performance-move-constructor-init,
performance-no-automatic-move,
performance-noexcept-move-constructor,
performance-trivially-destructible,
performance-type-promotion-in-math-fn,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,
portability-simd-intrinsics,
readability-avoid-const-params-in-decls,
readability-const-return-type,
readability-container-size-empty,
readability-convert-member-functions-to-static,
readability-delete-null-pointer,
readability-deleted-default,
readability-inconsistent-declaration-parameter-name,
readability-make-member-function-const,
readability-misleading-indentation,
readability-misplaced-array-index,
readability-non-const-parameter,
readability-redundant-control-flow,
readability-redundant-declaration,
readability-redundant-function-ptr-dereference,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-redundant-string-init,
readability-simplify-subscript-expr,
readability-static-accessed-through-instance,
readability-static-definition-in-anonymous-namespace,
readability-string-compare,
readability-uniqueptr-delete-release,
readability-use-anyofallof

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.idea

39
include/README Normal file
View File

@@ -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
lib/README Normal file
View File

@@ -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

28
platformio.ini Normal file
View File

@@ -0,0 +1,28 @@
; 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:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
build_type = debug
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qio
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
board_build.partitions = default.csv
build_flags = -I include
-DARDUINO_USB_CDC_ON_BOOT=1
-DBOARD_HAS_PSRAM
board_build.filesystem = littlefs
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
lib_deps = fastled/FastLED@^3.9.4

97
src/main.cpp Normal file
View File

@@ -0,0 +1,97 @@
#include <Arduino.h>
#include <FastLED.h>
const uint8_t NUM_LEDS = 1;
const gpio_num_t DATA_PIN = GPIO_NUM_48;
CRGB leds[NUM_LEDS];
void prettyPrintBytes(size_t bytes) {
if (bytes < 1024) {
Serial.printf("%d b\n", bytes);
} else if (bytes < (1024 * 1024)) {
Serial.printf("%.2f kb\n", bytes / 1024.0);
} else {
Serial.printf("%.2f mb\n", bytes / (1024.0 * 1024));
}
}
// clang-format off
void printESPInfo() {
Serial.println("ESP32-S3 info");
Serial.println("Internal RAM");
Serial.print(" getHeapSize: "); prettyPrintBytes(ESP.getHeapSize());
Serial.print(" getFreeHeap: "); prettyPrintBytes(ESP.getFreeHeap());
Serial.print(" getMinFreeHeap: "); prettyPrintBytes(ESP.getMinFreeHeap());
Serial.print(" getMaxAllocHeap: "); prettyPrintBytes(ESP.getMaxAllocHeap());
Serial.println("PSRAM");
Serial.print(" getPsramSize: "); prettyPrintBytes(ESP.getPsramSize());
Serial.print(" getFreePsram: "); prettyPrintBytes(ESP.getFreePsram());
Serial.print(" getMinFreePsram: "); prettyPrintBytes(ESP.getMinFreePsram());
Serial.print(" getMaxAllocPsram: "); prettyPrintBytes(ESP.getMaxAllocPsram());
Serial.println("Flash");
Serial.print(" getFlashChipSize: "); prettyPrintBytes(ESP.getFlashChipSize());
Serial.printf(" getFlashChipSpeed: %d MHz\n", ESP.getFlashChipSpeed() / 1000 / 1000);
Serial.print(" getFlashChipMode: ");
Serial.println("SKIPPED");
// switch (ESP.getFlashChipMode()) {
// case FM_QIO:
// Serial.println("QIO");
// break;
// case FM_QOUT:
// Serial.println("QOUT");
// break;
// case FM_DIO:
// Serial.println("DIO");
// break;
// case FM_DOUT:
// Serial.println("DOUT");
// break;
// case FM_FAST_READ:
// Serial.println("FAST_READ");
// break;
// case FM_SLOW_READ:
// Serial.println("SLOW_READ");
// break;
// case FM_UNKNOWN:
// Serial.println("UNKNOWN");
// break;
// default:
// Serial.println("???");
// break;
// }
Serial.println("CPU");
Serial.printf(" getChipRevision: %d\n", ESP.getChipRevision());
Serial.printf(" getChipModel: %s\n", ESP.getChipModel());
Serial.printf(" getChipCores: %d\n", ESP.getChipCores());
Serial.printf(" getCpuFreqMHz: %d\n", ESP.getCpuFreqMHz());
Serial.printf(" getEfuseMac: %llX\n", ESP.getEfuseMac());
Serial.println("Software");
Serial.printf(" getSdkVersion: %s\n", ESP.getSdkVersion());
Serial.print(" getSketchSize: "); prettyPrintBytes(ESP.getSketchSize());
Serial.printf(" getFreeSketchSpace: %d kb\n", ESP.getFreeSketchSpace() / 1024);
Serial.printf(" getSketchMD5: %s\n", ESP.getSketchMD5().c_str());
}
// clang-format on
void setup() {
Serial.begin(115200);
CFastLED::addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(32);
delay(1000);
printESPInfo();
while (true) {
leds[0] = CRGB::Red;
FastLED.delay(500);
leds[0] = CRGB::Green;
FastLED.delay(500);
leds[0] = CRGB::Blue;
FastLED.delay(500);
leds[0] = CRGB::Black;
FastLED.delay(500);
}
}
void loop() {}

11
test/README Normal file
View File

@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner 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 PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html