Luigi Santivetti | 69972f9 | 2019-11-12 22:55:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | nuts_bolts.h - Header file for shared definitions, variables, and functions |
| 3 | Part of Grbl |
| 4 | |
| 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC |
| 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud |
| 7 | |
| 8 | Grbl is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | Grbl is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef nuts_bolts_h |
| 23 | #define nuts_bolts_h |
| 24 | |
| 25 | #define false 0 |
| 26 | #define true 1 |
| 27 | |
| 28 | #define SOME_LARGE_VALUE 1.0E+38 |
| 29 | |
| 30 | // Axis array index values. Must start with 0 and be continuous. |
| 31 | #define N_AXIS 3 // Number of axes |
| 32 | #define X_AXIS 0 // Axis indexing value. |
| 33 | #define Y_AXIS 1 |
| 34 | #define Z_AXIS 2 |
| 35 | // #define A_AXIS 3 |
| 36 | |
| 37 | // CoreXY motor assignments. DO NOT ALTER. |
| 38 | // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations. |
| 39 | #ifdef COREXY |
| 40 | #define A_MOTOR X_AXIS // Must be X_AXIS |
| 41 | #define B_MOTOR Y_AXIS // Must be Y_AXIS |
| 42 | #endif |
| 43 | |
| 44 | // Conversions |
| 45 | #define MM_PER_INCH (25.40) |
| 46 | #define INCH_PER_MM (0.0393701) |
| 47 | #define TICKS_PER_MICROSECOND (F_CPU/1000000) |
| 48 | |
| 49 | #define DELAY_MODE_DWELL 0 |
| 50 | #define DELAY_MODE_SYS_SUSPEND 1 |
| 51 | |
| 52 | // Useful macros |
| 53 | #define clear_vector(a) memset(a, 0, sizeof(a)) |
| 54 | #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS) |
| 55 | // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS) |
| 56 | #define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 57 | #define min(a,b) (((a) < (b)) ? (a) : (b)) |
| 58 | #define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS)) |
| 59 | |
| 60 | // Bit field and masking macros |
| 61 | #define bit(n) (1 << n) |
| 62 | #define bit_true(x,mask) (x) |= (mask) |
| 63 | #define bit_false(x,mask) (x) &= ~(mask) |
| 64 | #define bit_istrue(x,mask) ((x & mask) != 0) |
| 65 | #define bit_isfalse(x,mask) ((x & mask) == 0) |
| 66 | |
| 67 | // Read a floating point value from a string. Line points to the input buffer, char_counter |
| 68 | // is the indexer pointing to the current character of the line, while float_ptr is |
| 69 | // a pointer to the result variable. Returns true when it succeeds |
| 70 | uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr); |
| 71 | |
| 72 | // Non-blocking delay function used for general operation and suspend features. |
| 73 | void delay_sec(float seconds, uint8_t mode); |
| 74 | |
| 75 | // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms(). |
| 76 | void delay_ms(uint16_t ms); |
| 77 | |
| 78 | // Delays variable-defined microseconds. Compiler compatibility fix for _delay_us(). |
| 79 | void delay_us(uint32_t us); |
| 80 | |
| 81 | // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking. |
| 82 | float hypot_f(float x, float y); |
| 83 | |
| 84 | float convert_delta_vector_to_unit_vector(float *vector); |
| 85 | float limit_value_by_axis_maximum(float *max_value, float *unit_vec); |
| 86 | |
| 87 | #endif |