Skip to content

Commit

Permalink
Arduino library project conformence
Browse files Browse the repository at this point in the history
  • Loading branch information
adbancroft committed Sep 2, 2024
1 parent ccea46b commit b52f389
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 85 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/arduino_lint.yml
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions examples/example/example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
avr-fast-div example
*/
#include <Arduino.h>
#include <stdint.h>
#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);
}

39 changes: 0 additions & 39 deletions include/README

This file was deleted.

46 changes: 0 additions & 46 deletions lib/README

This file was deleted.

9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -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=*

0 comments on commit b52f389

Please sign in to comment.