-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4eb924
commit a60b4cb
Showing
8 changed files
with
186 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Marlin 3D Printer Firmware | ||
* Copyright (c) 2023 MarlinFirmware [https:/MarlinFirmware/Marlin] | ||
* | ||
* Based on Sprinter and grbl. | ||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include <math.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
typedef void (*voidFunc_t)(); | ||
|
||
// | ||
// Conditional type assignment magic. For example... | ||
// | ||
// typename IF<(MYOPT==12), int, float>::type myvar; | ||
// | ||
template <bool, class L, class R> struct IF { typedef R type; }; | ||
template <class L, class R> struct IF<true, L, R> { typedef L type; }; | ||
|
||
// Define types based on largest bit width stored value required | ||
#define bits_t(W) typename IF<((W)> 16), uint32_t, typename IF<((W)> 8), uint16_t, uint8_t>::type>::type | ||
#define uvalue_t(V) typename IF<((V)>65535), uint32_t, typename IF<((V)>255), uint16_t, uint8_t>::type>::type | ||
#define value_t(V) typename IF<((V)>32767), int32_t, typename IF<((V)>127), int16_t, int8_t>::type>::type | ||
|
||
// General Flags for some number of states | ||
template<size_t N> | ||
struct Flags { | ||
typedef value_t(N) flagbits_t; | ||
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1; } N8; | ||
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1; } N16; | ||
typedef struct { bool b0:1, b1:1, b2:1, b3:1, b4:1, b5:1, b6:1, b7:1, b8:1, b9:1, b10:1, b11:1, b12:1, b13:1, b14:1, b15:1, | ||
b16:1, b17:1, b18:1, b19:1, b20:1, b21:1, b22:1, b23:1, b24:1, b25:1, b26:1, b27:1, b28:1, b29:1, b30:1, b31:1; } N32; | ||
union { | ||
flagbits_t b; | ||
typename IF<(N>16), N32, typename IF<(N>8), N16, N8>::type>::type flag; | ||
}; | ||
FI void reset() { b = 0; } | ||
FI void set(const int n, const bool onoff) { onoff ? set(n) : clear(n); } | ||
FI void set(const int n) { b |= (flagbits_t)_BV(n); } | ||
FI void clear(const int n) { b &= ~(flagbits_t)_BV(n); } | ||
FI bool test(const int n) const { return TEST(b, n); } | ||
FI bool operator[](const int n) { return test(n); } | ||
FI bool operator[](const int n) const { return test(n); } | ||
FI int size() const { return sizeof(b); } | ||
FI operator bool() const { return b; } | ||
}; | ||
|
||
// Specialization for a single bool flag | ||
template<> | ||
struct Flags<1> { | ||
bool b; | ||
FI void reset() { b = false; } | ||
FI void set(const int n, const bool onoff) { onoff ? set(n) : clear(n); } | ||
FI void set(const int) { b = true; } | ||
FI void clear(const int) { b = false; } | ||
FI bool test(const int) const { return b; } | ||
FI bool& operator[](const int) { return b; } | ||
FI bool operator[](const int) const { return b; } | ||
FI int size() const { return sizeof(b); } | ||
FI operator bool() const { return b; } | ||
}; | ||
|
||
typedef Flags<8> flags_8_t; | ||
typedef Flags<16> flags_16_t; | ||
|
||
// | ||
// feedRate_t is just a humble float | ||
// | ||
typedef float feedRate_t; | ||
|
||
// | ||
// celsius_t is the native unit of temperature. Signed to handle a disconnected thermistor value (-14). | ||
// For more resolition (e.g., for a chocolate printer) this may later be changed to Celsius x 100 | ||
// | ||
typedef uint16_t raw_adc_t; | ||
typedef int16_t celsius_t; | ||
typedef float celsius_float_t; | ||
|
||
// | ||
// On AVR pointers are only 2 bytes so use 'const float &' for 'const float' | ||
// | ||
#ifdef __AVR__ | ||
typedef const float & const_float_t; | ||
#else | ||
typedef const float const_float_t; | ||
#endif | ||
typedef const_float_t const_feedRate_t; | ||
typedef const_float_t const_celsius_float_t; | ||
|
||
// Conversion macros | ||
#define MMM_TO_MMS(MM_M) feedRate_t(static_cast<float>(MM_M) / 60.0f) | ||
#define MMS_TO_MMM(MM_S) (static_cast<float>(MM_S) * 60.0f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.