From b52f389a82b418105eb94ec24bc26bb8cc9b504a Mon Sep 17 00:00:00 2001 From: tx_haggis <13982343+adbancroft@users.noreply.github.com> Date: Mon, 2 Sep 2024 15:13:43 -0500 Subject: [PATCH] Arduino library project conformence --- .github/workflows/arduino_lint.yml | 13 +++++++ examples/example/example.ino | 58 ++++++++++++++++++++++++++++++ include/README | 39 -------------------- lib/README | 46 ------------------------ library.properties | 9 +++++ 5 files changed, 80 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/arduino_lint.yml create mode 100644 examples/example/example.ino delete mode 100644 include/README delete mode 100644 lib/README create mode 100644 library.properties diff --git a/.github/workflows/arduino_lint.yml b/.github/workflows/arduino_lint.yml new file mode 100644 index 0000000..a61b59a --- /dev/null +++ b/.github/workflows/arduino_lint.yml @@ -0,0 +1,13 @@ +name: Arduino-lint + +on: [push, pull_request] +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - uses: arduino/arduino-lint-action@v1 + with: + library-manager: submit + compliance: strict \ No newline at end of file diff --git a/examples/example/example.ino b/examples/example/example.ino new file mode 100644 index 0000000..314adbf --- /dev/null +++ b/examples/example/example.ino @@ -0,0 +1,58 @@ +/* + avr-fast-div example +*/ +#include +#include +#include "avr-fast-div.h" + +void setup() { + Serial.begin(9600); //send and receive at 9600 baud + pinMode(LED_BUILTIN, OUTPUT); + + Serial.println("Beginning test..."); + + const uint32_t divisor = random(2U, UINT16_MAX/2U); + const uint32_t dividend = random((uint32_t)UINT16_MAX+1U, (uint32_t)UINT16_MAX*24U); + + constexpr uint32_t iterations = 5000; + + // Built in "/" operator + uint32_t divCheckSum = 0UL; + uint32_t divStartTime = micros(); + for (uint32_t i = 0U; i < iterations; i++) { + // We need the +i & -i to prevent the optimiser making this loop a no-op + divCheckSum += (dividend+i) / (divisor+i); + } + uint32_t divEndTime = micros(); + uint32_t divDuration = divEndTime-divStartTime; + + // fast_div() + uint32_t fastdivCheckSum = 0UL; + uint32_t fastdivStartTime = micros(); + for (uint32_t i = 0U; i < iterations; i++) { + fastdivCheckSum += fast_div((dividend+i), (divisor+i)); + } + uint32_t fastdivEndTime = micros(); + uint32_t fastdivDuration = fastdivEndTime-fastdivStartTime; + + char msg[128]; + sprintf(msg, "Dividend: %" PRIu32 ", Divisor: %" PRIu32, dividend, divisor); + Serial.println(msg); + sprintf(msg, "Div Checksum: %" PRIu32 ", FastDiv Checksum: %" PRIu32, divCheckSum, fastdivCheckSum); + Serial.println(msg); + sprintf(msg, "Div Duration: %" PRIu32 ", FastDiv Duration: %" PRIu32, divDuration, fastdivDuration); + Serial.println(msg); + uint16_t percentDelta = fastdivDuration * 100U / divDuration; + sprintf(msg, "fast_div() took %" PRIu16 "%% less time than the division operator", 100-percentDelta); + Serial.println(msg); +} + +void loop() { + + // Blink to indicate end of test + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + digitalWrite(LED_BUILTIN, LOW); + delay(250); +} + diff --git a/include/README b/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -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 diff --git a/lib/README b/lib/README deleted file mode 100644 index 2593a33..0000000 --- a/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -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 -#include - -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 diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..575c1d6 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=avr-fast-div +version=1.0.0 +author=Andrew Bancroft +maintainer=Andrew Bancroft +sentence=Optimized integer division for avr-gcc +paragraph=On AVR, runtime division is done in software. This library provides *up to* 70% improvement in run time division speed on AVR hardware. Exact speedup varies depending on data types & number ranges. +category=Data Processing +url=https://github.com/adbancroft/avr-fast-div +architectures=*