Speeduino
|
Go to the source code of this file.
Macros | |
#define | DIV_ROUND_DOWN -1 |
Rounding behavior: always round down. | |
#define | DIV_ROUND_UP 1 |
Rounding behavior: always round up. | |
#define | DIV_ROUND_NEAREST 0 |
Rounding behavior: round to nearest. | |
#define | DIV_ROUND_BEHAVIOR DIV_ROUND_NEAREST |
Integer division rounding behavior. | |
#define | DIV_ROUND_CORRECT(d, t) ((t)(((d)>>1U)+(t)DIV_ROUND_BEHAVIOR)) |
Computes the denominator correction for rounding division based on our rounding behavior. | |
#define | DIV_ROUND_CLOSEST(n, d, t) |
Rounded integer division. | |
#define | UDIV_ROUND_CLOSEST(n, d, t) ((t)((n) + DIV_ROUND_CORRECT(d, t))/(t)(d)) |
Rounded unsigned integer division. | |
#define | IS_INTEGER(d) ((d) == (int32_t)(d)) |
Test whether the parameter is an integer or not. | |
Functions | |
uint8_t | random1to100 (void) |
static uint32_t | div360 (uint32_t n) |
Optimised integer division by 360. | |
static uint32_t | percentage (uint8_t percent, uint32_t value) |
Integer based percentage calculation. | |
static uint16_t | halfPercentage (uint8_t percent, uint16_t value) |
Integer based half-percentage calculation. | |
static int16_t | nudge (int16_t min, int16_t max, int16_t value, int16_t nudgeAmount) |
Make one pass at correcting the value into the range [min, max) | |
static uint16_t | udiv_32_16 (uint32_t dividend, uint16_t divisor) |
Optimised division: uint32_t/uint16_t => uint16_t. | |
static uint16_t | udiv_32_16_closest (uint32_t dividend, uint16_t divisor) |
Same as udiv_32_16(), except this will round to nearest integer instead of truncating. | |
template<class T > | |
constexpr const T & | clamp (const T &v, const T &lo, const T &hi) |
clamps a given value between the minimum and maximum thresholds. | |
static uint16_t | LOW_PASS_FILTER (uint16_t input, uint8_t alpha, uint16_t prior) |
Simple low pass IIR filter 16-bit values. | |
static int16_t | LOW_PASS_FILTER (int16_t input, uint8_t alpha, int16_t prior) |
Simple low pass IIR filter for S16 values. | |
static uint16_t | div100 (uint16_t n) |
Performance optimised integer division by 100. I.e. same as n/100. | |
static int16_t | div100 (int16_t n) |
Performance optimised integer division by 100. I.e. same as n/100. | |
static uint32_t | div100 (uint32_t n) |
Performance optimised integer division by 100. I.e. same as n/100. | |
static int32_t | div100 (int32_t n) |
Performance optimised integer division by 100. I.e. same as n/100. | |
clamps a given value between the minimum and maximum thresholds.
Uses operator< to compare the values.
T | Any type that supports operator< |
v | The value to clamp |
lo | The minimum threshold |
hi | The maximum threshold |
Performance optimised integer division by 100. I.e. same as n/100.
Uses the rounding behaviour controlled by DIV_ROUND_BEHAVIOR
n | Dividend to divide by 100 |
Performance optimised integer division by 100. I.e. same as n/100.
Uses the rounding behaviour controlled by DIV_ROUND_BEHAVIOR
n | Dividend to divide by 100 |
Performance optimised integer division by 100. I.e. same as n/100.
Uses the rounding behaviour controlled by DIV_ROUND_BEHAVIOR
n | Dividend to divide by 100 |
Performance optimised integer division by 100. I.e. same as n/100.
Uses the rounding behaviour controlled by DIV_ROUND_BEHAVIOR
n | Dividend to divide by 100 |
Optimised integer division by 360.
n | The numerator (dividee) (an integer) |
Integer based half-percentage calculation.
percent | The percent to calculate ([0, 100]) |
value | The value to operate on |
Simple low pass IIR filter for S16 values.
Simple low pass IIR filter 16-bit values.
This is effectively implementing the smooth filter from playground.arduino.cc/Main/Smooth But removes the use of floats and uses 8 bits of fixed precision.
input | incoming unfiltered value |
alpha | filter factor. 0=off, 255=full smoothing (0.00 to 0.99 in float, 0-99%) |
prior | previous filtered value. |
Make one pass at correcting the value into the range [min, max)
min | Minimum value (inclusive) |
max | Maximum value (exclusive) |
value | Value to nudge |
nudgeAmount | Amount to change value by |
Integer based percentage calculation.
percent | The percent to calculate ([0, 100]) |
value | The value to operate on |
Optimised division: uint32_t/uint16_t => uint16_t.
Optimised division of unsigned 32-bit by unsigned 16-bit when it is known that the result fits into unsigned 16-bit.
~60% quicker than raw 32/32 => 32 division on ATMega
dividend | The dividend (numerator) |
divisor | The divisor (denominator) |
Same as udiv_32_16(), except this will round to nearest integer instead of truncating.
Minor performance drop compared to non-rounding version.