diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-12-07 13:58:46 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-12-07 13:58:46 -0700 |
commit | 546a5ccdba66dd8d8c19ce6d8486f46c84637cf2 (patch) | |
tree | 95b52da91414c1bfbad745c6b55617011012813e /include/byte_math.h | |
parent | 9182b65ae2045c5087257751d30409deecf9520a (diff) | |
download | ch573-546a5ccdba66dd8d8c19ce6d8486f46c84637cf2.tar.gz ch573-546a5ccdba66dd8d8c19ce6d8486f46c84637cf2.tar.bz2 ch573-546a5ccdba66dd8d8c19ce6d8486f46c84637cf2.zip |
Add way to toggle the default pattern and a way to switch the pattern.
Diffstat (limited to 'include/byte_math.h')
-rw-r--r-- | include/byte_math.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/byte_math.h b/include/byte_math.h index 79f93b8..9be4b67 100644 --- a/include/byte_math.h +++ b/include/byte_math.h @@ -13,3 +13,24 @@ static inline uint8_t byte_sin(uint8_t n) } uint8_t calc_w(uint8_t n); + +static inline uint8_t byte_scale(uint8_t v, uint8_t scale) +{ + uint16_t acc = v; + return (acc * scale) >> 8; +} + +static inline uint8_t clip(int x) +{ + if (x > 240) { + return 240; + } + + if (x < 0) { + return 0; + } + + return (uint8_t)x; +} + +#define AS_BYTE(n) ((n) * 256) |