Sergey Pastor / grbl1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nuts_bolts.h Source File

nuts_bolts.h

00001 /*
00002   nuts_bolts.h - Header file for shared definitions, variables, and functions
00003   Part of Grbl
00004 
00005   Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
00006   Copyright (c) 2009-2011 Simen Svale Skogsrud
00007 
00008   Grbl is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   Grbl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef nuts_bolts_h
00023 #define nuts_bolts_h
00024 #ifdef STM32F103C8
00025 #include "stm32f10x_rcc.h"
00026 #endif
00027 #include "float.h"
00028 #define false 0
00029 #define true 1
00030 
00031 #define SOME_LARGE_VALUE FLT_MAX
00032 
00033 // Axis array index values. Must start with 0 and be continuous.
00034 #define N_AXIS 3 // Number of axes
00035 #define X_AXIS 0 // Axis indexing value.
00036 #define Y_AXIS 1
00037 #define Z_AXIS 2
00038 // #define A_AXIS 3
00039 
00040 // CoreXY motor assignments. DO NOT ALTER.
00041 // NOTE: If the A and B motor axis bindings are changed, this effects the CoreXY equations.
00042 #ifdef COREXY
00043  #define A_MOTOR X_AXIS // Must be X_AXIS
00044  #define B_MOTOR Y_AXIS // Must be Y_AXIS
00045 #endif
00046 
00047 // Conversions
00048 #define MM_PER_INCH (25.40f)
00049 #define INCH_PER_MM (0.0393701f)
00050 #define TICKS_PER_MICROSECOND (F_CPU/1000000)
00051 #ifdef WIN32
00052 extern LARGE_INTEGER Win32Frequency;
00053 #define F_CPU  Win32Frequency.QuadPart
00054 #endif
00055 #ifdef STM32F103C8
00056 #define F_CPU SystemCoreClock
00057 #endif
00058 #define DELAY_MODE_DWELL       0
00059 #define DELAY_MODE_SYS_SUSPEND 1
00060 
00061 // Useful macros
00062 #define clear_vector(a) memset(a, 0, sizeof(a))
00063 #define clear_vector_float(a) memset(a, 0.0, sizeof(float)*N_AXIS)
00064 // #define clear_vector_long(a) memset(a, 0.0, sizeof(long)*N_AXIS)
00065 #define max(a,b) (((a) > (b)) ? (a) : (b))
00066 #define min(a,b) (((a) < (b)) ? (a) : (b))
00067 #define isequal_position_vector(a,b) !(memcmp(a, b, sizeof(float)*N_AXIS))
00068 
00069 // Bit field and masking macros
00070 #define bit(n) (1 << n)
00071 #define bit_true(x,mask) (x) |= (mask)
00072 #define bit_false(x,mask) (x) &= ~(mask)
00073 #define bit_istrue(x,mask) ((x & mask) != 0)
00074 #define bit_isfalse(x,mask) ((x & mask) == 0)
00075 
00076 // Read a floating point value from a string. Line points to the input buffer, char_counter
00077 // is the indexer pointing to the current character of the line, while float_ptr is
00078 // a pointer to the result variable. Returns true when it succeeds
00079 uint8_t read_float(char *line, uint8_t *char_counter, float *float_ptr);
00080 
00081 // Non-blocking delay function used for general operation and suspend features.
00082 void delay_sec(float seconds, uint8_t mode);
00083 
00084 // Delays variable-defined milliseconds. Compiler compatibility fix for _delay_ms().
00085 void delay_ms(uint16_t ms);
00086 
00087 
00088 // Computes hypotenuse, avoiding avr-gcc's bloated version and the extra error checking.
00089 float hypot_f(float x, float y);
00090 
00091 float convert_delta_vector_to_unit_vector(float *vector);
00092 float limit_value_by_axis_maximum(float *max_value, float *unit_vec);
00093 
00094 #endif