libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy_core.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_CORE_HW_H
3#define DSY_CORE_HW_H
4#include <stdint.h>
5#include <stdlib.h>
6
7#if defined(_MSC_VER)
8#define FORCE_INLINE __forceinline
9#elif defined(__clang__)
10#define FORCE_INLINE inline __attribute__((always_inline))
11#pragma clang diagnostic ignored "-Wduplicate-decl-specifier"
12#elif defined(__GNUC__)
13#define FORCE_INLINE inline __attribute__((always_inline))
14#else
15#error unknown compiler
16#endif
17
25#define DMA_BUFFER_MEM_SECTION __attribute__((section(".sram1_bss")))
31#define DTCM_MEM_SECTION __attribute__((section(".dtcmram_bss")))
32
33#define FBIPMAX 0.999985f
34#define FBIPMIN (-FBIPMAX)
35#define U82F_SCALE 0.0078740f
36#define F2U8_SCALE 127.0f
37#define S82F_SCALE 0.0078125f
38#define F2S8_SCALE 127.0f
39#define S162F_SCALE 3.0517578125e-05f
40#define F2S16_SCALE 32767.0f
41#define F2S24_SCALE 8388608.0f
42#define S242F_SCALE 1.192092896e-07f
43#define S24SIGN 0x800000
44#define S322F_SCALE 4.6566129e-10f
45#define F2S32_SCALE 2147483647.f
50#define OUT_L out[0]
51
54#define OUT_R out[1]
55
58#define IN_L in[0]
59
62#define IN_R in[1]
63
69FORCE_INLINE float cube(float x)
70{
71 return (x * x) * x;
72}
73
79FORCE_INLINE float u82f(uint8_t x)
80{
81 return ((float)x - 127.f) * U82F_SCALE;
82}
83
87FORCE_INLINE uint8_t f2u8(float x)
88{
89 x = x <= FBIPMIN ? FBIPMIN : x;
90 x = x >= FBIPMAX ? FBIPMAX : x;
91 return (uint8_t)((x * F2U8_SCALE) + F2U8_SCALE);
92}
93
94
100FORCE_INLINE float s82f(int8_t x)
101{
102 return (float)x * S82F_SCALE;
103}
104
108FORCE_INLINE int8_t f2s8(float x)
109{
110 x = x <= FBIPMIN ? FBIPMIN : x;
111 x = x >= FBIPMAX ? FBIPMAX : x;
112 return (int32_t)(x * F2S8_SCALE);
113}
114
120FORCE_INLINE float s162f(int16_t x)
121{
122 return (float)x * S162F_SCALE;
123}
124
128FORCE_INLINE int16_t f2s16(float x)
129{
130 x = x <= FBIPMIN ? FBIPMIN : x;
131 x = x >= FBIPMAX ? FBIPMAX : x;
132 return (int32_t)(x * F2S16_SCALE);
133}
134
138FORCE_INLINE float s242f(int32_t x)
139{
140 x = (x ^ S24SIGN) - S24SIGN; //sign extend aka ((x<<8)>>8)
141 return (float)x * S242F_SCALE;
142}
146FORCE_INLINE int32_t f2s24(float x)
147{
148 x = x <= FBIPMIN ? FBIPMIN : x;
149 x = x >= FBIPMAX ? FBIPMAX : x;
150 return (int32_t)(x * F2S24_SCALE);
151}
152
156FORCE_INLINE float s322f(int32_t x)
157{
158 return (float)x * S322F_SCALE;
159}
163FORCE_INLINE int32_t f2s32(float x)
164{
165 x = x <= FBIPMIN ? FBIPMIN : x;
166 x = x >= FBIPMAX ? FBIPMAX : x;
167 return (int32_t)(x * F2S32_SCALE);
168}
169
170#ifdef __cplusplus
171
172namespace daisy
173{
190
192struct Pin
193{
195 uint8_t pin;
196
201 constexpr Pin(const GPIOPort pt, const uint8_t pn) : port(pt), pin(pn) {}
202
204 constexpr Pin() : port(PORTX), pin(255) {}
205
209 constexpr bool IsValid() const { return port != PORTX && pin < 16; }
210
212 constexpr bool operator==(const Pin &rhs) const
213 {
214 return (rhs.port == port) && (rhs.pin == pin);
215 }
216
218 constexpr bool operator!=(const Pin &rhs) const { return !operator==(rhs); }
219};
220
221
247
255[[deprecated("Use daisy::Pin instead")]] typedef struct
256{
258 uint8_t pin;
260 constexpr operator Pin() const
261 {
262 return Pin(static_cast<GPIOPort>(port), pin);
263 }
264
265} dsy_gpio_pin;
266
267} // namespace daisy
268
269#endif // __cplusplus
270
271#endif
#define F2S32_SCALE
Definition daisy_core.h:45
FORCE_INLINE float u82f(uint8_t x)
Definition daisy_core.h:79
FORCE_INLINE float s82f(int8_t x)
Definition daisy_core.h:100
FORCE_INLINE int16_t f2s16(float x)
Definition daisy_core.h:128
#define F2S16_SCALE
Definition daisy_core.h:40
#define S242F_SCALE
Definition daisy_core.h:42
#define S24SIGN
Definition daisy_core.h:43
FORCE_INLINE float s162f(int16_t x)
Definition daisy_core.h:120
FORCE_INLINE float cube(float x)
Definition daisy_core.h:69
#define F2S24_SCALE
Definition daisy_core.h:41
FORCE_INLINE float s322f(int32_t x)
Definition daisy_core.h:156
FORCE_INLINE int32_t f2s32(float x)
Definition daisy_core.h:163
FORCE_INLINE int8_t f2s8(float x)
Definition daisy_core.h:108
#define F2U8_SCALE
Definition daisy_core.h:36
#define FBIPMAX
Definition daisy_core.h:33
#define FBIPMIN
Definition daisy_core.h:34
FORCE_INLINE uint8_t f2u8(float x)
Definition daisy_core.h:87
#define F2S8_SCALE
Definition daisy_core.h:38
#define S322F_SCALE
Definition daisy_core.h:44
#define S162F_SCALE
Definition daisy_core.h:39
#define U82F_SCALE
Definition daisy_core.h:35
#define S82F_SCALE
Definition daisy_core.h:37
FORCE_INLINE int32_t f2s24(float x)
Definition daisy_core.h:146
FORCE_INLINE float s242f(int32_t x)
Definition daisy_core.h:138
Hardware defines and helpers for daisy field platform.
Definition index.h:2
GPIOPort
GPIO Port names.
Definition daisy_core.h:176
@ PORTX
Definition daisy_core.h:188
@ PORTH
Definition daisy_core.h:184
@ PORTE
Definition daisy_core.h:181
@ PORTJ
Definition daisy_core.h:186
@ PORTK
Definition daisy_core.h:187
@ PORTA
Definition daisy_core.h:177
@ PORTF
Definition daisy_core.h:182
@ PORTB
Definition daisy_core.h:178
@ PORTI
Definition daisy_core.h:185
@ PORTC
Definition daisy_core.h:179
@ PORTD
Definition daisy_core.h:180
@ PORTG
Definition daisy_core.h:183
dsy_gpio_port
Definition daisy_core.h:232
@ DSY_GPIOG
Definition daisy_core.h:239
@ DSY_GPIOF
Definition daisy_core.h:238
@ DSY_GPIOB
Definition daisy_core.h:234
@ DSY_GPIOK
Definition daisy_core.h:243
@ DSY_GPIO_LAST
Definition daisy_core.h:245
@ DSY_GPIOH
Definition daisy_core.h:240
@ DSY_GPIOJ
Definition daisy_core.h:242
@ DSY_GPIOE
Definition daisy_core.h:237
@ DSY_GPIOX
Definition daisy_core.h:244
@ DSY_GPIOC
Definition daisy_core.h:235
@ DSY_GPIOI
Definition daisy_core.h:241
@ DSY_GPIOD
Definition daisy_core.h:236
@ DSY_GPIOA
Definition daisy_core.h:233
representation of hardware port/pin combination
Definition daisy_core.h:193
GPIOPort port
Definition daisy_core.h:194
constexpr Pin()
Basic Constructor creates an invalid Pin object.
Definition daisy_core.h:204
constexpr bool operator!=(const Pin &rhs) const
comparison operator for checking inequality between Pin objects
Definition daisy_core.h:218
constexpr bool operator==(const Pin &rhs) const
comparison operator for checking equality between Pin objects
Definition daisy_core.h:212
uint8_t pin
Definition daisy_core.h:195
constexpr bool IsValid() const
checks validity of a Pin
Definition daisy_core.h:209
constexpr Pin(const GPIOPort pt, const uint8_t pn)
Constructor creates a valid pin.
Definition daisy_core.h:201
uint8_t pin
Definition daisy_core.h:258
dsy_gpio_port port
Definition daisy_core.h:257