aboutsummaryrefslogtreecommitdiff
path: root/include/shared/math.h
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2021-10-26 00:10:06 -0600
committerJosh Rahm <joshuarahm@gmail.com>2021-10-26 00:10:06 -0600
commitf9b12f748b557994b958115c04fd1591b322248e (patch)
tree7d80680edadf5b0018944966af64f8773bfa8f1a /include/shared/math.h
parentdbbe83bd8882fe18e26f6305a1f425145bfea8db (diff)
parent90eb3a0b79bfef67c70dc545b49c48928eea05f4 (diff)
downloadstm32l4-f9b12f748b557994b958115c04fd1591b322248e.tar.gz
stm32l4-f9b12f748b557994b958115c04fd1591b322248e.tar.bz2
stm32l4-f9b12f748b557994b958115c04fd1591b322248e.zip
Merge branch 'christmas' into HEAD
Diffstat (limited to 'include/shared/math.h')
-rw-r--r--include/shared/math.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/shared/math.h b/include/shared/math.h
new file mode 100644
index 0000000..6aec0e7
--- /dev/null
+++ b/include/shared/math.h
@@ -0,0 +1,19 @@
+#ifndef _SHARED_MATH_H_
+#define _SHARED_MATH_H_
+
+#include "kern/common.h"
+
+/* Returns round(sin(2πn / 256) * 127.5 + 127.5). */
+uint8_t byte_sin(uint8_t n);
+
+static inline uint8_t byte_scale(uint8_t n, uint8_t sc) {
+ return n * sc / 255;
+}
+
+#define min(a, b) (a) < (b) ? (a) : (b)
+#define max(a, b) (a) > (b) ? (a) : (b)
+
+/* returns (in / 256)^n * 256. */
+uint8_t amp(uint8_t in, uint8_t n);
+
+#endif /* _SHARED_MATH_H_ */