初始化提交
This commit is contained in:
0
arduino-cli/libraries/Fast/.gitignore
vendored
Normal file
0
arduino-cli/libraries/Fast/.gitignore
vendored
Normal file
143
arduino-cli/libraries/Fast/Fast.cpp
Normal file
143
arduino-cli/libraries/Fast/Fast.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
|
||||
///
|
||||
/// Created for personal use, use it at your own risk and benefit.
|
||||
/// https://github.com/GitMoDu/Fast
|
||||
///
|
||||
|
||||
#include "Fast.h"
|
||||
|
||||
bool FastShifter::Setup(const uint8_t pin, const bool startValue)
|
||||
{
|
||||
return FastOut::Setup(pin, startValue);
|
||||
}
|
||||
|
||||
void FastShifter::PulseHigh()
|
||||
{
|
||||
Set(HIGH);
|
||||
Set(LOW);
|
||||
}
|
||||
|
||||
void FastShifter::PulseLow()
|
||||
{
|
||||
Set(LOW);
|
||||
Set(HIGH);
|
||||
}
|
||||
|
||||
void FastShifter::PulseHigh(const int16_t pulseIntervalMicros)
|
||||
{
|
||||
Set(HIGH);
|
||||
delayMicroseconds(pulseIntervalMicros);
|
||||
Set(LOW);
|
||||
}
|
||||
|
||||
void FastShifter::PulseLow(const uint16_t pulseIntervalMicros)
|
||||
{
|
||||
Set(LOW);
|
||||
delayMicroseconds(pulseIntervalMicros);
|
||||
Set(HIGH);
|
||||
}
|
||||
|
||||
FastOut::FastOut(const uint8_t pin, const bool startValue)
|
||||
{
|
||||
Setup(pin, startValue);
|
||||
}
|
||||
|
||||
bool FastOut::Setup(const uint8_t pin, const bool startValue)
|
||||
{
|
||||
if (Fast::Setup(pin))
|
||||
{
|
||||
Set(startValue);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool FastOutCached::Setup(const uint8_t pin, const bool startValue)
|
||||
{
|
||||
return FastOut::Setup(pin, startValue);
|
||||
}
|
||||
|
||||
void FastOut::Toggle()
|
||||
{
|
||||
if (Get())
|
||||
{
|
||||
*OutPin &= PinAddressMaskOff;
|
||||
}
|
||||
else
|
||||
{
|
||||
*OutPin |= PinAddressMaskOn;
|
||||
}
|
||||
}
|
||||
|
||||
void FastOut::Set(const bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
*OutPin |= PinAddressMaskOn;
|
||||
}
|
||||
else
|
||||
{
|
||||
*OutPin &= PinAddressMaskOff;
|
||||
}
|
||||
}
|
||||
|
||||
FastOutCached::FastOutCached(const uint8_t pin, const bool startValue)
|
||||
{
|
||||
Setup(pin, startValue);
|
||||
}
|
||||
|
||||
void FastOutCached::Toggle()
|
||||
{
|
||||
if (LastValueCache)
|
||||
{
|
||||
Set(LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
Set(HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
inline void FastOutCached::Set(const bool value)
|
||||
{
|
||||
LastValueCache = value;
|
||||
if (LastValueCache)
|
||||
{
|
||||
*OutPin |= PinAddressMaskOn;
|
||||
}
|
||||
else
|
||||
{
|
||||
*OutPin &= PinAddressMaskOff;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Fast::Fast(const uint8_t pin)
|
||||
{
|
||||
if (pin != INVALID_PIN)
|
||||
{
|
||||
Setup(pin);
|
||||
}
|
||||
}
|
||||
|
||||
bool Fast::Setup(const uint8_t pin)
|
||||
{
|
||||
PinAddressMaskOn = digitalPinToBitMask(pin);
|
||||
PinAddressMaskOff = ~PinAddressMaskOn;
|
||||
Mode = portModeRegister(digitalPinToPort(pin));
|
||||
OutPin = portOutputRegister(digitalPinToPort(pin));
|
||||
InPin = portInputRegister(digitalPinToPort(pin));
|
||||
|
||||
*Mode |= PinAddressMaskOn;//TODO, ensure input compatibility
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Fast::Get()
|
||||
{
|
||||
return *InPin & PinAddressMaskOn;
|
||||
}
|
||||
86
arduino-cli/libraries/Fast/Fast.h
Normal file
86
arduino-cli/libraries/Fast/Fast.h
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
///
|
||||
/// Fast and simple IO library for Arduino compatible boards.
|
||||
/// Not the fastest, but simplest to use (for me at least).
|
||||
/// Created for personal use, use it at your own risk and benefit.
|
||||
/// https://github.com/GitMoDu/Fast
|
||||
///
|
||||
|
||||
#ifndef _FAST_h
|
||||
#define _FAST_h
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class Fast
|
||||
{
|
||||
|
||||
protected:
|
||||
#define INVALID_PIN 254
|
||||
uint8_t *Mode;
|
||||
volatile uint8_t *OutPin;
|
||||
volatile uint8_t *InPin;
|
||||
uint8_t PinAddressMaskOn, PinAddressMaskOff;
|
||||
|
||||
bool Get();
|
||||
|
||||
public:
|
||||
Fast(const uint8_t pin = INVALID_PIN);
|
||||
bool virtual Setup(const uint8_t pin);
|
||||
};
|
||||
|
||||
class FastOut : public Fast
|
||||
{
|
||||
public:
|
||||
FastOut(const uint8_t pin = INVALID_PIN, const bool startValue = false);
|
||||
FastOut& operator = (boolean value)
|
||||
{
|
||||
Set(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Setup(const uint8_t pin, const bool startValue);
|
||||
void Set(const bool value);
|
||||
void Toggle();
|
||||
};
|
||||
|
||||
class FastOutCached : public FastOut
|
||||
{
|
||||
private:
|
||||
bool LastValueCache = false;
|
||||
|
||||
public:
|
||||
FastOutCached(const uint8_t pin = INVALID_PIN, const bool startValue = false);
|
||||
FastOutCached& operator = (boolean value)
|
||||
{
|
||||
Set(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Setup(const uint8_t pin, const bool startValue = false);
|
||||
void Set(const bool value);
|
||||
void Toggle();
|
||||
};
|
||||
|
||||
class FastIn : public Fast
|
||||
{
|
||||
public:
|
||||
FastIn(const uint8_t pin = INVALID_PIN, const bool startValue = false);
|
||||
|
||||
operator bool() {
|
||||
return Get();
|
||||
}
|
||||
};
|
||||
|
||||
class FastShifter : public FastOut
|
||||
{
|
||||
public:
|
||||
virtual bool Setup(const uint8_t pin, const bool startValue = false);
|
||||
void PulseLow();
|
||||
void PulseHigh();
|
||||
void PulseLow(const uint16_t pulseIntervalMicros);
|
||||
void PulseHigh(const int16_t pulseIntervalMicros);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
21
arduino-cli/libraries/Fast/LICENSE
Normal file
21
arduino-cli/libraries/Fast/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 André
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
35
arduino-cli/libraries/Fast/README.md
Normal file
35
arduino-cli/libraries/Fast/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Fast (Arduino Compatible)
|
||||
|
||||
Fast and simple IO for Arduino, easy to use for library making.
|
||||
|
||||
Tested in: ATmega328p, ATTiny85.
|
||||
|
||||
Results in ATmega328p @ 16 MHz
|
||||
|
||||
|
||||
|
||||
Benchmarking 100000 toggles
|
||||
|
||||
Digital Write Manual Toggle took 472 ms - 211.9 kHz
|
||||
|
||||
Fast Manual Toggle took 254 ms - 393.7 kHz
|
||||
|
||||
Fast Auto Toggle took 329 ms - 304.0 kHz
|
||||
|
||||
Fast Pointer Manual Toggle took 249 ms - 401.6 kHz
|
||||
|
||||
Fast Pointer Auto Toggle took 349 ms - 286.5 kHz
|
||||
|
||||
Fast Cached Pointer Manual Toggle took 147 ms - 680.3 kHz
|
||||
|
||||
Fast Cached Pointer Auto Toggle took 155 ms - 645.2 kHz
|
||||
|
||||
DirectIO Manual Toggle took 274 ms - 365.0 kHz
|
||||
|
||||
DirectIO Auto Toggle took 356 ms - 280.9 kHz
|
||||
|
||||
DirectIO Pointer Manual Toggle took 267 ms - 374.5 kHz
|
||||
|
||||
DirectIO Pointer Auto Toggle took 355 ms - 281.7 kHz
|
||||
|
||||
Benchmark complete.
|
||||
49
arduino-cli/libraries/Fast/examples/Blink/Blink.ino
Normal file
49
arduino-cli/libraries/Fast/examples/Blink/Blink.ino
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Blink, Fast version
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
|
||||
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
|
||||
the correct LED pin independent of which board is used.
|
||||
If you want to know what pin the on-board LED is connected to on your Arduino model, check
|
||||
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 May 2014
|
||||
by Scott Fitzgerald
|
||||
|
||||
modified 2 Sep 2016
|
||||
by Arturo Guadalupi
|
||||
|
||||
modified 8 Sep 2016
|
||||
by Colby Newman
|
||||
|
||||
modified 20 Jul 2017
|
||||
by MoDu
|
||||
*/
|
||||
|
||||
#include <Fast.h>
|
||||
|
||||
FastShifter shifterPin;
|
||||
FastOut ledPin;
|
||||
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup() {
|
||||
// initialize digital pin LED_BUILTIN as an output with shifting capabilities.
|
||||
ledPin.Setup(LED_BUILTIN);
|
||||
|
||||
// initialize digital pin shifter pin 5 as an output.
|
||||
shifterPin.Setup(5);
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
ledPin.Set(HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
shifterPin.PulseHigh();//Pulse the shifter pin
|
||||
delay(1000); // wait for a second
|
||||
|
||||
ledPin.Set(LOW); // turn the LED off by making the voltage LOW
|
||||
shifterPin.PulseHigh();//Pulse the shifter pin
|
||||
delay(1000); // wait for a second
|
||||
}
|
||||
207
arduino-cli/libraries/Fast/examples/IOBenchmark/IOBenchmark.ino
Normal file
207
arduino-cli/libraries/Fast/examples/IOBenchmark/IOBenchmark.ino
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
Benchmark program to test speed of IO.
|
||||
Intended only for testing and optimization in real world scenarios, not for synthetic testing or comparison.
|
||||
|
||||
Created for personal use, use it at your own risk and benefit.
|
||||
https://github.com/GitMoDu/Fast
|
||||
|
||||
modified 5 Aug 2017
|
||||
by MoDu
|
||||
*/
|
||||
|
||||
#include <Fast.h>
|
||||
#include <DirectIO.h>
|
||||
|
||||
#define BENCHMARK_SIZE 100000
|
||||
#define BENCHMARK_STEP_DELAY 300
|
||||
#define BENCHMARK_PIN 9
|
||||
|
||||
FastOut ledPin;
|
||||
FastOut *ledPinPointer;
|
||||
FastOutCached *ledPinCachedPointer;
|
||||
OutputPin DirectPin(BENCHMARK_PIN);
|
||||
OutputPin *DirectPinPointer;
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
Benchmark();
|
||||
}
|
||||
|
||||
void Benchmark()
|
||||
{
|
||||
Serial.print(F("Benchmarking "));
|
||||
Serial.print(BENCHMARK_SIZE);
|
||||
Serial.println(F(" toggles "));
|
||||
|
||||
uint32_t Start, Duration;
|
||||
bool ManualToggle = false;
|
||||
|
||||
pinMode(BENCHMARK_PIN, OUTPUT);
|
||||
ManualToggle = LOW;
|
||||
digitalWrite(BENCHMARK_PIN, ManualToggle);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
digitalWrite(BENCHMARK_PIN, ManualToggle);
|
||||
ManualToggle = !ManualToggle;
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
digitalWrite(BENCHMARK_PIN, ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "Digital Write Manual Toggle");
|
||||
|
||||
|
||||
ledPin.Setup(BENCHMARK_PIN, ManualToggle);
|
||||
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
//ledPin = ManualToggle;
|
||||
ledPin.Set(ManualToggle);
|
||||
ManualToggle = !ManualToggle;
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
ledPin = ManualToggle;
|
||||
PrintBenchmarkResults(Duration, "Fast Manual Toggle");
|
||||
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
ledPin.Toggle();
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
ledPin = ManualToggle;
|
||||
PrintBenchmarkResults(Duration, "Fast Auto Toggle");
|
||||
|
||||
|
||||
ledPinPointer = new FastOut(BENCHMARK_PIN, ManualToggle);
|
||||
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
ledPinPointer->Set(ManualToggle);
|
||||
ManualToggle = !ManualToggle;
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
ledPinPointer->Set(ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "Fast Pointer Manual Toggle");
|
||||
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
ledPinPointer->Toggle();
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
ledPinPointer->Set(ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "Fast Pointer Auto Toggle");
|
||||
|
||||
ledPinCachedPointer = new FastOutCached(BENCHMARK_PIN, ManualToggle);
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
ledPinCachedPointer->Set(ManualToggle);
|
||||
ManualToggle = !ManualToggle;
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
ledPinCachedPointer->Set(ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "Fast Cached Pointer Manual Toggle");
|
||||
|
||||
//ledPinCachedPointer = new FastOutCached(BENCHMARK_PIN, ManualToggle);
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
ledPinCachedPointer->Toggle();
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
ledPinCachedPointer->Set(ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "Fast Cached Pointer Auto Toggle");
|
||||
|
||||
DirectPin = ManualToggle;
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
|
||||
DirectPin = ManualToggle;
|
||||
ManualToggle = !ManualToggle;
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
DirectPin = ManualToggle;
|
||||
PrintBenchmarkResults(Duration, "DirectIO Manual Toggle");
|
||||
|
||||
DirectPin = ManualToggle;
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
DirectPin.toggle();
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
DirectPin = ManualToggle;
|
||||
PrintBenchmarkResults(Duration, "DirectIO Auto Toggle");
|
||||
|
||||
DirectPinPointer = new OutputPin(BENCHMARK_PIN);
|
||||
DirectPinPointer->write(ManualToggle);
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
|
||||
DirectPinPointer->write(ManualToggle);
|
||||
ManualToggle = !ManualToggle;
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
DirectPinPointer->write(ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "DirectIO Pointer Manual Toggle");
|
||||
|
||||
DirectPinPointer = new OutputPin(BENCHMARK_PIN);
|
||||
DirectPinPointer->write(ManualToggle);
|
||||
delay(BENCHMARK_STEP_DELAY);
|
||||
Start = millis();
|
||||
for (uint32_t counter = 0; counter < BENCHMARK_SIZE; counter++)
|
||||
{
|
||||
DirectPin.toggle();
|
||||
}
|
||||
Duration = millis() - Start;
|
||||
ManualToggle = LOW;
|
||||
DirectPinPointer->write(ManualToggle);
|
||||
PrintBenchmarkResults(Duration, "DirectIO Pointer Auto Toggle");
|
||||
|
||||
|
||||
digitalWrite(BENCHMARK_PIN, HIGH);
|
||||
Serial.println(F("Benchmark complete."));
|
||||
delay(BENCHMARK_STEP_DELAY * 3);
|
||||
digitalWrite(BENCHMARK_PIN, LOW);
|
||||
|
||||
}
|
||||
|
||||
void PrintBenchmarkResults(uint32_t duration, char* benchmarkType)
|
||||
{
|
||||
Serial.print(benchmarkType);
|
||||
Serial.print(F(" took "));
|
||||
Serial.print(duration);
|
||||
Serial.print(F(" ms - "));
|
||||
|
||||
double FrequencyKHz = ((double)BENCHMARK_SIZE) / ((double)duration);
|
||||
Serial.print(FrequencyKHz,1);
|
||||
Serial.println(F(" kHz"));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
26
arduino-cli/libraries/Fast/keywords.txt
Normal file
26
arduino-cli/libraries/Fast/keywords.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Fast
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
FastOut KEYWORD2
|
||||
Fast KEYWORD2
|
||||
FastShifter KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
Fast KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
9
arduino-cli/libraries/Fast/library.properties
Normal file
9
arduino-cli/libraries/Fast/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=Fast
|
||||
version=1.0
|
||||
author=GitMoDu <batatas@gmail.com>
|
||||
maintainer=GitMoDu <batatas@gmail.com>
|
||||
sentence=Fast and simple IO for Arduino, easy to use for library making.
|
||||
paragraph=
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/GitMoDu/Fast
|
||||
architectures=avr
|
||||
Reference in New Issue
Block a user