diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e49f21e --- /dev/null +++ b/.clang-format @@ -0,0 +1,117 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: true +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 100 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 2 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +RawStringFormats: + - Language: TextProto + Delimiters: + - 'pb' + - 'proto' + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... + diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..99fd921 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,21 @@ +name: Build + +on: [pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Build Examples + uses: espressif/esp-idf-ci-action@v1 + with: + esp_idf_version: release-v5.2 + target: esp32s3 + path: '.' diff --git a/.github/workflows/package_main.yml b/.github/workflows/package_main.yml new file mode 100644 index 0000000..04683d9 --- /dev/null +++ b/.github/workflows/package_main.yml @@ -0,0 +1,48 @@ +name: Build and Package Main + +on: + push: + branches: [main] + release: + types: [published] + +jobs: + build: + + runs-on: ubuntu-latest + continue-on-error: false + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Build Main Code + uses: espressif/esp-idf-ci-action@v1 + with: + esp_idf_version: release-v5.2 + target: esp32s3 + path: '.' + command: 'idf.py build' + + - name: Upload Build Outputs + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: | + build/bootloader/bootloader.bin + build/partition_table/partition-table.bin + build/*.bin + build/flash_args + + - name: Attach files to release + uses: softprops/action-gh-release@v1 + if: ${{ github.event.release && github.event.action == 'published' }} + with: + files: | + build/*.bin + build/bootloader/bootloader.bin + build/partition_table/partition-table.bin + build/flash_args + diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml new file mode 100644 index 0000000..8840f50 --- /dev/null +++ b/.github/workflows/static_analysis.yml @@ -0,0 +1,25 @@ +name: Static analysis + +on: [pull_request] + +jobs: + static_analysis: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Run static analysis + uses: esp-cpp/StaticAnalysis@master + with: + # Do not build the project and do not use cmake to generate compile_commands.json + use_cmake: false + + # Use the 5.2 release version since it's what we build with + esp_idf_version: release/v5.2 + + # (Optional) cppcheck args + cppcheck_args: -i$GITHUB_WORKSPACE/components/espp -i$GITHUB_WORKSPACE/components/esp-protocols --force --enable=all --inline-suppr --inconclusive --platform=mips32 --std=c++17 --suppressions-list=$GITHUB_WORKSPACE/suppressions.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..5b45aee --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +repos: +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v14.0.6 + hooks: + - id: clang-format + exclude: | + (?x)( + ^components/esp-dsp/| + ^components/esp_littlefs/| + ^components/lvgl/| + ^components/state_machine/include/magic_enum.hpp| + ^external/alpaca/| + ^external/cli/| + ^external/csv2/| + ^external/fmt/ + ) + types_or: [c++, c] diff --git a/components/esp-protocols b/components/esp-protocols index 12bacdc..38a3631 160000 --- a/components/esp-protocols +++ b/components/esp-protocols @@ -1 +1 @@ -Subproject commit 12bacdc3a01121ca97eeb3988e2faf38c7563472 +Subproject commit 38a3631a27f71f25109f1d6e28d3c2ba309f292d diff --git a/components/espp b/components/espp index c07e2fd..761b524 160000 --- a/components/espp +++ b/components/espp @@ -1 +1 @@ -Subproject commit c07e2fdb344856dc7b1c01234a2e16bd8d3ea0d7 +Subproject commit 761b52412c903319f06e66f66696e5ac29ded285 diff --git a/components/gui/include/graph_window.hpp b/components/gui/include/graph_window.hpp index 9a0ad79..ee00fbe 100644 --- a/components/gui/include/graph_window.hpp +++ b/components/gui/include/graph_window.hpp @@ -1,29 +1,31 @@ #pragma once -#include #include +#include #include #include "window.hpp" class GraphWindow : public Window { public: + GraphWindow() = default; + void init(lv_obj_t *parent, size_t width, size_t height) override; void update() override; - void clear_plots ( void ); - void add_data ( const std::string& plot_name, int new_data ); - void remove_plot ( const std::string& plot_name ); + void clear_plots(void); + void add_data(const std::string &plot_name, int new_data); + void remove_plot(const std::string &plot_name); protected: - lv_chart_series_t* create_plot ( const std::string& plotName ); - lv_chart_series_t* get_plot ( const std::string& plotName ); + lv_chart_series_t *create_plot(const std::string &plotName); + lv_chart_series_t *get_plot(const std::string &plotName); - void update_ticks ( void ); + void update_ticks(void); private: - lv_obj_t *chart_; - lv_obj_t *legend_; - std::string y_ticks_; - std::unordered_map plot_map_; + lv_obj_t *chart_{nullptr}; + lv_obj_t *legend_{nullptr}; + std::string y_ticks_{""}; + std::unordered_map plot_map_{}; }; diff --git a/components/gui/include/gui.hpp b/components/gui/include/gui.hpp index 53ff7dd..4e2f15d 100644 --- a/components/gui/include/gui.hpp +++ b/components/gui/include/gui.hpp @@ -9,14 +9,14 @@ #include "converter.hpp" #include "display.hpp" -#include "task.hpp" +#include "graph_window.hpp" #include "logger.hpp" +#include "task.hpp" #include "text_window.hpp" -#include "graph_window.hpp" class Gui { public: - const std::string delimeter_data = "::"; ///< Delimeter indicating this contains plottable data + const std::string delimeter_data = "::"; ///< Delimeter indicating this contains plottable data const std::string delimeter_command = "+++"; ///< Delimeter indicating this contains a command const std::string command_remove_plot = "RP:"; ///< Command: remove plot const std::string command_clear_plots = "CP"; ///< Command: clear plots @@ -27,17 +27,15 @@ class Gui { espp::Logger::Verbosity log_level{espp::Logger::Verbosity::WARN}; }; - explicit Gui(const Config& config) - : display_(config.display) - , logger_({.tag = "Gui", .level = config.log_level}) { + explicit Gui(const Config &config) + : display_(config.display) + , logger_({.tag = "Gui", .level = config.log_level}) { init_ui(); // now start the gui updater task using namespace std::placeholders; - task_ = espp::Task::make_unique({ - .name = "Gui Task", - .callback = std::bind(&Gui::update, this, _1, _2), - .stack_size_bytes = 6 * 1024 - }); + task_ = espp::Task::make_unique({.name = "Gui Task", + .callback = std::bind(&Gui::update, this, _1, _2), + .stack_size_bytes = 6 * 1024}); task_->start(); } @@ -48,11 +46,11 @@ class Gui { void switch_tab(); - void push_data(const std::string& data); + void push_data(const std::string &data); std::string pop_data(); void clear_info(); - void add_info(const std::string& info); + void add_info(const std::string &info); bool handle_data(); @@ -60,7 +58,7 @@ class Gui { void init_ui(); void deinit_ui(); - bool update(std::mutex& m, std::condition_variable& cv) { + bool update(std::mutex &m, std::condition_variable &cv) { { std::lock_guard lk(mutex_); lv_task_handler(); @@ -77,7 +75,7 @@ class Gui { static void event_callback(lv_event_t *e) { lv_event_code_t event_code = lv_event_get_code(e); auto user_data = lv_event_get_user_data(e); - auto gui = static_cast(user_data); + auto gui = static_cast(user_data); if (!gui) { return; } diff --git a/components/gui/include/text_window.hpp b/components/gui/include/text_window.hpp index 5e1ebfc..264cb68 100644 --- a/components/gui/include/text_window.hpp +++ b/components/gui/include/text_window.hpp @@ -7,13 +7,14 @@ class TextWindow : public Window { public: + TextWindow() = default; - void init ( lv_obj_t *parent, size_t width, size_t height ) override; + void init(lv_obj_t *parent, size_t width, size_t height) override; - void clear_logs( void ); - void add_log ( const std::string& log_text ); + void clear_logs(void); + void add_log(const std::string &log_text); private: - std::string log_text_; - lv_obj_t *log_container_; + std::string log_text_{""}; + lv_obj_t *log_container_{nullptr}; }; diff --git a/components/gui/include/window.hpp b/components/gui/include/window.hpp index 3c90cca..aa650b1 100644 --- a/components/gui/include/window.hpp +++ b/components/gui/include/window.hpp @@ -4,16 +4,18 @@ class Window { public: - virtual void init ( lv_obj_t *parent, size_t width, size_t height ) { + Window() = default; + + virtual void init(lv_obj_t *parent, size_t width, size_t height) { parent_ = parent; width_ = width; height_ = height; } - virtual void clear ( void ) { } - virtual void update ( void ) { } + virtual void clear(void) {} + virtual void update(void) {} protected: - size_t width_; - size_t height_; - lv_obj_t* parent_; + size_t width_{0}; + size_t height_{0}; + lv_obj_t *parent_{nullptr}; }; diff --git a/components/gui/src/converter.cpp b/components/gui/src/converter.cpp index 38318b3..6d93c29 100644 --- a/components/gui/src/converter.cpp +++ b/components/gui/src/converter.cpp @@ -2,7 +2,7 @@ Converter::Status Converter::str2int(int &i, char const *s, int base) { char *end; - long l; + long l; errno = 0; l = strtol(s, &end, base); if ((errno == ERANGE && l == LONG_MAX) || l > INT_MAX) { diff --git a/components/gui/src/graph_window.cpp b/components/gui/src/graph_window.cpp index 8013dfa..df0ef82 100644 --- a/components/gui/src/graph_window.cpp +++ b/components/gui/src/graph_window.cpp @@ -16,7 +16,7 @@ void GraphWindow::init(lv_obj_t *parent, size_t width, size_t height) { // Show lines and points too lv_chart_set_type(chart_, LV_CHART_TYPE_LINE); - + // update the tick values size_t major_tick_length = 5; size_t minor_tick_length = 2; @@ -24,17 +24,12 @@ void GraphWindow::init(lv_obj_t *parent, size_t width, size_t height) { size_t minor_tick_count = 2; bool label_enabled = true; size_t draw_size = 50; - lv_chart_set_axis_tick(chart_, LV_CHART_AXIS_PRIMARY_Y, - major_tick_length, - minor_tick_length, - major_tick_count, - minor_tick_count, - label_enabled, - draw_size); + lv_chart_set_axis_tick(chart_, LV_CHART_AXIS_PRIMARY_Y, major_tick_length, minor_tick_length, + major_tick_count, minor_tick_count, label_enabled, draw_size); // create the legend legend_ = lv_label_create(chart_); - lv_obj_align(legend_, LV_ALIGN_TOP_RIGHT, - 7, 5); + lv_obj_align(legend_, LV_ALIGN_TOP_RIGHT, -7, 5); lv_label_set_text(legend_, ""); // create a style for the chart @@ -50,14 +45,16 @@ void GraphWindow::init(lv_obj_t *parent, size_t width, size_t height) { void GraphWindow::update_ticks() { // get the minimum and maximum - lv_coord_t min=0, max=0; + lv_coord_t min = 0, max = 0; auto num_points = lv_chart_get_point_count(chart_); for (auto e : plot_map_) { auto series = e.second; - for (size_t i=0; i < num_points; i++) { + for (size_t i = 0; i < num_points; i++) { auto point = series->y_points[i]; - if (point < min) min = point; - if (point > max) max = point; + if (point < min) + min = point; + if (point > max) + max = point; } } @@ -73,7 +70,7 @@ void GraphWindow::update() { lv_chart_refresh(chart_); } -void GraphWindow::clear_plots( void ) { +void GraphWindow::clear_plots(void) { // remove all the series from the chart for (auto e : plot_map_) { lv_chart_remove_series(chart_, e.second); @@ -84,16 +81,16 @@ void GraphWindow::clear_plots( void ) { lv_label_set_text(legend_, ""); } -void GraphWindow::add_data( const std::string& plotName, int newData ) { - auto plot = get_plot( plotName ); +void GraphWindow::add_data(const std::string &plotName, int newData) { + auto plot = get_plot(plotName); // couldn't find the plot so create a new one - if ( plot == nullptr ) - plot = create_plot( plotName ); + if (plot == nullptr) + plot = create_plot(plotName); // now add the data lv_chart_set_next_value(chart_, plot, newData); } -lv_chart_series_t* GraphWindow::create_plot( const std::string& plotName ) { +lv_chart_series_t *GraphWindow::create_plot(const std::string &plotName) { // make a random color uint8_t red = rand() % 256; uint8_t green = rand() % 256; @@ -102,8 +99,8 @@ lv_chart_series_t* GraphWindow::create_plot( const std::string& plotName ) { // now make the plot auto plot = lv_chart_add_series(chart_, color, LV_CHART_AXIS_PRIMARY_Y); - //Add text to legend, #XXX # will be a colored string, if we set the - //recolor property to true on the label + // Add text to legend, #XXX # will be a colored string, if we set the + // recolor property to true on the label char label_buf[50]; sprintf(label_buf, "#%02X%02X%02X - %s#\n", red, green, blue, plotName.c_str()); char *current_legend = lv_label_get_text(legend_); @@ -118,7 +115,7 @@ lv_chart_series_t* GraphWindow::create_plot( const std::string& plotName ) { return plot; } -void GraphWindow::remove_plot( const std::string& plotName ) { +void GraphWindow::remove_plot(const std::string &plotName) { auto plot = get_plot(plotName); if (plot != nullptr) { // we should remove it from the display @@ -128,8 +125,8 @@ void GraphWindow::remove_plot( const std::string& plotName ) { } } -lv_chart_series_t* GraphWindow::get_plot( const std::string& plotName ) { - lv_chart_series_t* plot = nullptr; +lv_chart_series_t *GraphWindow::get_plot(const std::string &plotName) { + lv_chart_series_t *plot = nullptr; auto search = plot_map_.find(plotName); if (search != plot_map_.end()) { // set the plot to be the value of the element diff --git a/components/gui/src/gui.cpp b/components/gui/src/gui.cpp index 2c2e05b..6e8a42e 100644 --- a/components/gui/src/gui.cpp +++ b/components/gui/src/gui.cpp @@ -3,9 +3,7 @@ using namespace espp; using namespace std::chrono_literals; -void Gui::deinit_ui() { - lv_obj_del(tabview_); -} +void Gui::deinit_ui() { lv_obj_del(tabview_); } void Gui::init_ui() { // Initialize the GUI @@ -29,19 +27,20 @@ void Gui::init_ui() { info_window_.init(info_tab, display_->width(), display_->height()); // rom screen navigation - // lv_obj_add_event_cb(ui_settingsbutton, &Gui::event_callback, LV_EVENT_PRESSED, static_cast(this)); - // lv_obj_add_event_cb(ui_playbutton, &Gui::event_callback, LV_EVENT_PRESSED, static_cast(this)); + // lv_obj_add_event_cb(ui_settingsbutton, &Gui::event_callback, LV_EVENT_PRESSED, + // static_cast(this)); lv_obj_add_event_cb(ui_playbutton, &Gui::event_callback, + // LV_EVENT_PRESSED, static_cast(this)); } void Gui::switch_tab() { std::lock_guard lk{mutex_}; - auto num_tabs = ((lv_tabview_t*)tabview_)->tab_cnt; + auto num_tabs = ((lv_tabview_t *)tabview_)->tab_cnt; auto active_tab = lv_tabview_get_tab_act(tabview_); auto next_tab = (active_tab + 1) % num_tabs; lv_tabview_set_act(tabview_, next_tab, LV_ANIM_ON); } -void Gui::push_data(const std::string& data) { +void Gui::push_data(const std::string &data) { std::unique_lock lock{data_queue_mutex_}; data_queue_.push(data); } @@ -61,7 +60,7 @@ void Gui::clear_info() { info_window_.clear_logs(); } -void Gui::add_info(const std::string& info) { +void Gui::add_info(const std::string &info) { std::lock_guard lk{mutex_}; info_window_.add_log(info); } @@ -70,12 +69,12 @@ bool Gui::handle_data() { // lock the display std::lock_guard lk{mutex_}; - bool hasNewPlotData = false; - bool hasNewTextData = false; + bool hasNewPlotData = false; + bool hasNewTextData = false; std::string newData = pop_data(); int len = newData.length(); - if(len > 0) { + if (len > 0) { size_t num_lines = 0; // logger_.info("parsing input '{}'", newData); // have data, parse here @@ -85,7 +84,7 @@ bool Gui::handle_data() { num_lines++; size_t pos = 0; // parse for commands - if ( (pos = line.find(delimeter_command)) != std::string::npos) { + if ((pos = line.find(delimeter_command)) != std::string::npos) { std::string command; std::string plotName; command = line.substr(pos + delimeter_command.length(), line.length()); @@ -93,52 +92,46 @@ bool Gui::handle_data() { log_window_.clear_logs(); // make sure we transition to the next state hasNewTextData = true; - } - else if (command == command_clear_plots) { + } else if (command == command_clear_plots) { plot_window_.clear_plots(); // make sure we transition to the next state hasNewPlotData = true; - } - else if ( (pos = line.find(command_remove_plot)) != std::string::npos) { + } else if ((pos = line.find(command_remove_plot)) != std::string::npos) { plotName = line.substr(pos + command_remove_plot.length(), line.length()); - plot_window_.remove_plot( plotName ); + plot_window_.remove_plot(plotName); // make sure we transition to the next state hasNewPlotData = true; } - } - else { + } else { // parse for data - if ( (pos = line.find(delimeter_data)) != std::string::npos) { + if ((pos = line.find(delimeter_data)) != std::string::npos) { // found "::" so we have a plot data std::string plotName; - std::string value; plotName = line.substr(0, pos); pos = pos + delimeter_data.length(); - if ( pos < line.length() ) { + if (pos < line.length()) { int iValue; - value = line.substr(pos, line.length()); + auto value = line.substr(pos, line.length()); if (Converter::str2int(iValue, value.c_str()) == Converter::Status::Success) { // make sure we transition to the next state - plot_window_.add_data( plotName, iValue ); + plot_window_.add_data(plotName, iValue); hasNewPlotData = true; } else { logger_.warn("has '::', but could not convert to number, adding log '{}'", line); // couldn't find that, so we just have text data - log_window_.add_log( line ); + log_window_.add_log(line); // make sure we transition to the next state hasNewTextData = true; } - } - else { + } else { // couldn't find that, so we just have text data - log_window_.add_log( line ); + log_window_.add_log(line); // make sure we transition to the next state hasNewTextData = true; } - } - else { + } else { // couldn't find that, so we just have text data - log_window_.add_log( line ); + log_window_.add_log(line); // make sure we transition to the next state hasNewTextData = true; } @@ -153,6 +146,6 @@ bool Gui::handle_data() { } void Gui::on_pressed(lv_event_t *e) { - lv_obj_t * target = lv_event_get_target(e); + lv_obj_t *target = lv_event_get_target(e); logger_.info("PRESSED: {}", fmt::ptr(target)); } diff --git a/components/gui/src/text_window.cpp b/components/gui/src/text_window.cpp index 04e1115..4767fcd 100644 --- a/components/gui/src/text_window.cpp +++ b/components/gui/src/text_window.cpp @@ -1,6 +1,6 @@ #include "text_window.hpp" -void TextWindow::init( lv_obj_t *parent, size_t width, size_t height ) { +void TextWindow::init(lv_obj_t *parent, size_t width, size_t height) { Window::init(parent, width, height); log_container_ = lv_label_create(parent_); lv_label_set_recolor(log_container_, true); @@ -13,14 +13,14 @@ void TextWindow::init( lv_obj_t *parent, size_t width, size_t height ) { lv_obj_set_height(log_container_, lv_pct(100)); } -void TextWindow::clear_logs( void ) { +void TextWindow::clear_logs(void) { // clear all the logs off the page lv_obj_clean(log_container_); // now empty the string log_text_.clear(); } -void TextWindow::add_log( const std::string& log_text ) { +void TextWindow::add_log(const std::string &log_text) { // now add to our string for storage log_text_ += "\n" + log_text; // set the string to the display diff --git a/main/box_3.hpp b/main/box_3.hpp index bed0d32..2d3e827 100644 --- a/main/box_3.hpp +++ b/main/box_3.hpp @@ -1,10 +1,10 @@ #pragma once +#include "gt911.hpp" #include "i2c.hpp" #include "ili9341.hpp" #include "st7789.hpp" #include "touchpad_input.hpp" -#include "gt911.hpp" #include "tt21100.hpp" static constexpr int DC_PIN_NUM = 4; diff --git a/main/main.cpp b/main/main.cpp index e66ee7a..344390b 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -24,9 +24,9 @@ #error "Misconfigured hardware!" #endif +#include "gui.hpp" #include "logger.hpp" #include "task.hpp" -#include "gui.hpp" #include "tcp_socket.hpp" #include "udp_socket.hpp" #include "wifi_sta.hpp" @@ -217,40 +217,35 @@ extern "C" void app_main(void) { ret = spi_bus_add_device(spi_num, &devcfg, &spi); ESP_ERROR_CHECK(ret); // initialize the controller - DisplayDriver::initialize(espp::display_drivers::Config{.lcd_write = lcd_write, - .lcd_send_lines = lcd_send_lines, - .reset_pin = reset, - .data_command_pin = dc_pin, - .backlight_pin = backlight, - .backlight_on_value = backlight_value, - .reset_value = reset_value, - .invert_colors = invert_colors, - .mirror_x = mirror_x, - .mirror_y = mirror_y, - }); + DisplayDriver::initialize(espp::display_drivers::Config{ + .lcd_write = lcd_write, + .lcd_send_lines = lcd_send_lines, + .reset_pin = reset, + .data_command_pin = dc_pin, + .reset_value = reset_value, + .invert_colors = invert_colors, + .mirror_x = mirror_x, + .mirror_y = mirror_y, + }); // initialize the display / lvgl auto display = std::make_shared( - espp::Display::AllocatingConfig{.width = width, - .height = height, - .pixel_buffer_size = pixel_buffer_size, - .flush_callback = DisplayDriver::flush, - .rotation = rotation, - .software_rotation_enabled = true}); + espp::Display::AllocatingConfig{.width = width, + .height = height, + .pixel_buffer_size = pixel_buffer_size, + .flush_callback = DisplayDriver::flush, + .backlight_pin = backlight, + .backlight_on_value = backlight_value, + .rotation = rotation, + .software_rotation_enabled = true}); // create the gui - Gui gui({ - .display = display, - .log_level = espp::Logger::Verbosity::DEBUG - }); + Gui gui({.display = display, .log_level = espp::Logger::Verbosity::DEBUG}); // initialize the input system #if CONFIG_HARDWARE_WROVER_KIT espp::Button button({ .gpio_num = GPIO_NUM_0, - .callback = - [&](const espp::Button::Event &event) { - gui.switch_tab(); - }, + .callback = [&](const espp::Button::Event &event) { gui.switch_tab(); }, .active_level = espp::Button::ActiveLevel::LOW, .interrupt_type = espp::Button::InterruptType::RISING_EDGE, .pullup_enabled = false, @@ -267,7 +262,7 @@ extern "C" void app_main(void) { .sda_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE, .clk_speed = 400 * 1000, - }); + }); // probe for the touch devices: // tt21100, gt911 @@ -279,23 +274,20 @@ extern "C" void app_main(void) { #if CONFIG_HARDWARE_BOX logger.info("Initializing Tt21100"); - espp::Tt21100 touch({ - .read = std::bind(&espp::I2c::read, &i2c, std::placeholders::_1, std::placeholders::_2, - std::placeholders::_3), - }); + using TouchDriver = espp::Tt21100; #endif #if CONFIG_HARDWARE_TDECK || CONFIG_HARDWARE_BOX_3 logger.info("Initializing GT911"); + using TouchDriver = espp::Gt911; // implement GT911 - espp::Gt911 touch({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3), - .write_read = std::bind(&espp::I2c::write_read, &i2c, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5)}); - #endif + TouchDriver touch({.write = std::bind(&espp::I2c::write, &i2c, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3), + .read = std::bind(&espp::I2c::read, &i2c, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3)}); - auto touchpad_read = [&touch](uint8_t* num_touch_points, uint16_t* x, uint16_t* y, uint8_t* btn_state) { + auto touchpad_read = [&touch](uint8_t *num_touch_points, uint16_t *x, uint16_t *y, + uint8_t *btn_state) { std::error_code ec; *num_touch_points = 0; // get the latest data from the device @@ -305,29 +297,27 @@ extern "C" void app_main(void) { *btn_state = touch.get_home_button_state(); }; logger.info("Initializing touchpad"); - auto touchpad = espp::TouchpadInput(espp::TouchpadInput::Config{ - .touchpad_read = touchpad_read, - .swap_xy = touch_swap_xy, - .invert_x = touch_invert_x, - .invert_y = touch_invert_y, - .log_level = espp::Logger::Verbosity::WARN - }); + auto touchpad = + espp::TouchpadInput(espp::TouchpadInput::Config{.touchpad_read = touchpad_read, + .swap_xy = touch_swap_xy, + .invert_x = touch_invert_x, + .invert_y = touch_invert_y, + .log_level = espp::Logger::Verbosity::WARN}); #endif // initialize WiFi logger.info("Initializing WiFi"); std::string server_address; - espp::WifiSta wifi_sta({ - .ssid = CONFIG_ESP_WIFI_SSID, - .password = CONFIG_ESP_WIFI_PASSWORD, - .num_connect_retries = CONFIG_ESP_MAXIMUM_RETRY, - .on_connected = nullptr, - .on_disconnected = nullptr, - .on_got_ip = [&server_address, &logger](ip_event_got_ip_t* eventdata) { - server_address = fmt::format("{}.{}.{}.{}", IP2STR(&eventdata->ip_info.ip)); - logger.info("got IP: {}.{}.{}.{}", IP2STR(&eventdata->ip_info.ip)); - } - }); + espp::WifiSta wifi_sta({.ssid = CONFIG_ESP_WIFI_SSID, + .password = CONFIG_ESP_WIFI_PASSWORD, + .num_connect_retries = CONFIG_ESP_MAXIMUM_RETRY, + .on_connected = nullptr, + .on_disconnected = nullptr, + .on_got_ip = [&server_address, &logger](ip_event_got_ip_t *eventdata) { + server_address = + fmt::format("{}.{}.{}.{}", IP2STR(&eventdata->ip_info.ip)); + logger.info("got IP: {}.{}.{}.{}", IP2STR(&eventdata->ip_info.ip)); + }}); // wait for network while (!wifi_sta.is_connected()) { @@ -341,67 +331,64 @@ extern "C" void app_main(void) { // create the socket espp::UdpSocket server_socket({.log_level = espp::Logger::Verbosity::WARN}); auto server_task_config = espp::Task::Config{ - .name = "UdpServer", - .callback = nullptr, - .stack_size_bytes = 6 * 1024, + .name = "UdpServer", + .callback = nullptr, + .stack_size_bytes = 6 * 1024, }; auto server_config = espp::UdpSocket::ReceiveConfig{ - .port = server_port, - .buffer_size = 1024, - .on_receive_callback = - [&gui](auto &data, auto &source) -> auto { - // turn the vector into a string - std::string data_str(data.begin(), data.end()); - fmt::print("Server received: '{}'\n" - " from source: {}\n", - data_str, source); - gui.push_data(data_str); - gui.handle_data(); - return std::nullopt; - } - }; - server_socket.start_receiving(server_task_config, server_config); - - // initialize mDNS, so that other embedded devices on the network can find us - // without having to be hardcoded / configured with our IP address and port - logger.info("Initializing mDNS"); - auto err = mdns_init(); - if (err != ESP_OK) { - logger.error("Could not initialize mDNS: {}", err); - return; - } + .port = server_port, + .buffer_size = 1024, + .on_receive_callback = [&gui]( + auto &data, auto &source) -> auto{// turn the vector into a string + std::string data_str(data.begin(), data.end()); + fmt::print("Server received: '{}'\n" + " from source: {}\n", + data_str, source); + gui.push_data(data_str); + gui.handle_data(); + return std::nullopt; +} +} +; +server_socket.start_receiving(server_task_config, server_config); + +// initialize mDNS, so that other embedded devices on the network can find us +// without having to be hardcoded / configured with our IP address and port +logger.info("Initializing mDNS"); +auto err = mdns_init(); +if (err != ESP_OK) { + logger.error("Could not initialize mDNS: {}", err); + return; +} - uint8_t mac[6]; - esp_read_mac(mac, ESP_MAC_WIFI_STA); - std::string hostname = fmt::format("wireless-debug-display-{:x}{:x}{:x}", mac[3], mac[4], mac[5]); - err = mdns_hostname_set(hostname.c_str()); - if (err != ESP_OK) { - logger.error("Could not set mDNS hostname: {}", err); - return; - } - logger.info("mDNS hostname set to '{}'", hostname); - err = mdns_instance_name_set("Wireless Debug Display"); - if (err != ESP_OK) { - logger.error("Could not set mDNS instance name: {}", err); - return; - } - err = mdns_service_add("Wireless Debug Display", "_debugdisplay", "_udp", server_port, NULL, 0); - if (err != ESP_OK) { - logger.error("Could not add mDNS service: {}", err); - return; - } - logger.info("mDNS initialized"); - - // update the info page - gui.clear_info(); - gui.add_info(std::string("#FF0000 WiFi: #") + - CONFIG_ESP_WIFI_SSID); - gui.add_info(std::string("#00FF00 IP: #") + - server_address + ":" + - std::to_string(server_port)); - - // loop forever - while (true) { - std::this_thread::sleep_for(1s); - } +uint8_t mac[6]; +esp_read_mac(mac, ESP_MAC_WIFI_STA); +std::string hostname = fmt::format("wireless-debug-display-{:x}{:x}{:x}", mac[3], mac[4], mac[5]); +err = mdns_hostname_set(hostname.c_str()); +if (err != ESP_OK) { + logger.error("Could not set mDNS hostname: {}", err); + return; +} +logger.info("mDNS hostname set to '{}'", hostname); +err = mdns_instance_name_set("Wireless Debug Display"); +if (err != ESP_OK) { + logger.error("Could not set mDNS instance name: {}", err); + return; +} +err = mdns_service_add("Wireless Debug Display", "_debugdisplay", "_udp", server_port, NULL, 0); +if (err != ESP_OK) { + logger.error("Could not add mDNS service: {}", err); + return; +} +logger.info("mDNS initialized"); + +// update the info page +gui.clear_info(); +gui.add_info(std::string("#FF0000 WiFi: #") + CONFIG_ESP_WIFI_SSID); +gui.add_info(std::string("#00FF00 IP: #") + server_address + ":" + std::to_string(server_port)); + +// loop forever +while (true) { + std::this_thread::sleep_for(1s); +} } diff --git a/main/tdeck.hpp b/main/tdeck.hpp index dc9782d..739c97f 100644 --- a/main/tdeck.hpp +++ b/main/tdeck.hpp @@ -1,9 +1,9 @@ #pragma once +#include "gt911.hpp" #include "i2c.hpp" #include "st7789.hpp" #include "touchpad_input.hpp" -#include "gt911.hpp" static constexpr int DC_PIN_NUM = 11; static constexpr std::string_view dev_kit = "LILYGO T-DECK"; @@ -15,7 +15,8 @@ static constexpr auto spi_num = SPI2_HOST; static constexpr gpio_num_t mosi = GPIO_NUM_41; static constexpr gpio_num_t sclk = GPIO_NUM_40; static constexpr gpio_num_t spics = GPIO_NUM_12; -static constexpr gpio_num_t reset = GPIO_NUM_NC; // not connected according to Setup210_LilyGo_T_Deck.h +static constexpr gpio_num_t reset = + GPIO_NUM_NC; // not connected according to Setup210_LilyGo_T_Deck.h static constexpr gpio_num_t dc_pin = (gpio_num_t)DC_PIN_NUM; static constexpr gpio_num_t backlight = GPIO_NUM_42; static constexpr size_t width = 320; diff --git a/main/wrover_kit.hpp b/main/wrover_kit.hpp index 29d93dc..324082e 100644 --- a/main/wrover_kit.hpp +++ b/main/wrover_kit.hpp @@ -1,7 +1,7 @@ #pragma once -#include "ili9341.hpp" #include "button.hpp" +#include "ili9341.hpp" static constexpr int DC_PIN_NUM = 21; static constexpr std::string_view dev_kit = "ESP-WROVER-DevKit"; diff --git a/suppressions.txt b/suppressions.txt new file mode 100644 index 0000000..7466731 --- /dev/null +++ b/suppressions.txt @@ -0,0 +1,11 @@ +// category of errors to suppress, e.g. unusedFunction +missingInclude +missingIncludeSystem +unusedFunction +unusedStructMember +functionStatic +cstyleCast + +// Specific suppressions of the form: +// [error id]:[filename]:[line] +*:components/espp/*