Luigi Santivetti | 69972f9 | 2019-11-12 22:55:40 +0000 | [diff] [blame^] | 1 | /* |
| 2 | settings.h - eeprom configuration handling |
| 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 settings_h |
| 23 | #define settings_h |
| 24 | |
| 25 | #include "grbl.h" |
| 26 | |
| 27 | |
| 28 | // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl |
| 29 | // when firmware is upgraded. Always stored in byte 0 of eeprom |
| 30 | #define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version. |
| 31 | |
| 32 | // Define bit flag masks for the boolean settings in settings.flag. |
| 33 | #define BIT_REPORT_INCHES 0 |
| 34 | #define BIT_LASER_MODE 1 |
| 35 | #define BIT_INVERT_ST_ENABLE 2 |
| 36 | #define BIT_HARD_LIMIT_ENABLE 3 |
| 37 | #define BIT_HOMING_ENABLE 4 |
| 38 | #define BIT_SOFT_LIMIT_ENABLE 5 |
| 39 | #define BIT_INVERT_LIMIT_PINS 6 |
| 40 | #define BIT_INVERT_PROBE_PIN 7 |
| 41 | |
| 42 | #define BITFLAG_REPORT_INCHES bit(BIT_REPORT_INCHES) |
| 43 | #define BITFLAG_LASER_MODE bit(BIT_LASER_MODE) |
| 44 | #define BITFLAG_INVERT_ST_ENABLE bit(BIT_INVERT_ST_ENABLE) |
| 45 | #define BITFLAG_HARD_LIMIT_ENABLE bit(BIT_HARD_LIMIT_ENABLE) |
| 46 | #define BITFLAG_HOMING_ENABLE bit(BIT_HOMING_ENABLE) |
| 47 | #define BITFLAG_SOFT_LIMIT_ENABLE bit(BIT_SOFT_LIMIT_ENABLE) |
| 48 | #define BITFLAG_INVERT_LIMIT_PINS bit(BIT_INVERT_LIMIT_PINS) |
| 49 | #define BITFLAG_INVERT_PROBE_PIN bit(BIT_INVERT_PROBE_PIN) |
| 50 | |
| 51 | // Define status reporting boolean enable bit flags in settings.status_report_mask |
| 52 | #define BITFLAG_RT_STATUS_POSITION_TYPE bit(0) |
| 53 | #define BITFLAG_RT_STATUS_BUFFER_STATE bit(1) |
| 54 | |
| 55 | // Define settings restore bitflags. |
| 56 | #define SETTINGS_RESTORE_DEFAULTS bit(0) |
| 57 | #define SETTINGS_RESTORE_PARAMETERS bit(1) |
| 58 | #define SETTINGS_RESTORE_STARTUP_LINES bit(2) |
| 59 | #define SETTINGS_RESTORE_BUILD_INFO bit(3) |
| 60 | #ifndef SETTINGS_RESTORE_ALL |
| 61 | #define SETTINGS_RESTORE_ALL 0xFF // All bitflags |
| 62 | #endif |
| 63 | |
| 64 | // Define EEPROM memory address location values for Grbl settings and parameters |
| 65 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and |
| 66 | // the startup script. The lower half contains the global settings and space for future |
| 67 | // developments. |
| 68 | #define EEPROM_ADDR_GLOBAL 1U |
| 69 | #define EEPROM_ADDR_PARAMETERS 512U |
| 70 | #define EEPROM_ADDR_STARTUP_BLOCK 768U |
| 71 | #define EEPROM_ADDR_BUILD_INFO 942U |
| 72 | |
| 73 | // Define EEPROM address indexing for coordinate parameters |
| 74 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) |
| 75 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) |
| 76 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) |
| 77 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 |
| 78 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 |
| 79 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) |
| 80 | |
| 81 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. |
| 82 | #define AXIS_N_SETTINGS 4 |
| 83 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. |
| 84 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings |
| 85 | |
| 86 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) |
| 87 | typedef struct { |
| 88 | // Axis settings |
| 89 | float steps_per_mm[N_AXIS]; |
| 90 | float max_rate[N_AXIS]; |
| 91 | float acceleration[N_AXIS]; |
| 92 | float max_travel[N_AXIS]; |
| 93 | |
| 94 | // Remaining Grbl settings |
| 95 | uint8_t pulse_microseconds; |
| 96 | uint8_t step_invert_mask; |
| 97 | uint8_t dir_invert_mask; |
| 98 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. |
| 99 | uint8_t status_report_mask; // Mask to indicate desired report data. |
| 100 | float junction_deviation; |
| 101 | float arc_tolerance; |
| 102 | |
| 103 | float rpm_max; |
| 104 | float rpm_min; |
| 105 | |
| 106 | uint8_t flags; // Contains default boolean settings |
| 107 | |
| 108 | uint8_t homing_dir_mask; |
| 109 | float homing_feed_rate; |
| 110 | float homing_seek_rate; |
| 111 | uint16_t homing_debounce_delay; |
| 112 | float homing_pulloff; |
| 113 | } settings_t; |
| 114 | extern settings_t settings; |
| 115 | |
| 116 | // Initialize the configuration subsystem (load settings from EEPROM) |
| 117 | void settings_init(); |
| 118 | |
| 119 | // Helper function to clear and restore EEPROM defaults |
| 120 | void settings_restore(uint8_t restore_flag); |
| 121 | |
| 122 | // A helper method to set new settings from command line |
| 123 | uint8_t settings_store_global_setting(uint8_t parameter, float value); |
| 124 | |
| 125 | // Stores the protocol line variable as a startup line in EEPROM |
| 126 | void settings_store_startup_line(uint8_t n, char *line); |
| 127 | |
| 128 | // Reads an EEPROM startup line to the protocol line variable |
| 129 | uint8_t settings_read_startup_line(uint8_t n, char *line); |
| 130 | |
| 131 | // Stores build info user-defined string |
| 132 | void settings_store_build_info(char *line); |
| 133 | |
| 134 | // Reads build info user-defined string |
| 135 | uint8_t settings_read_build_info(char *line); |
| 136 | |
| 137 | // Writes selected coordinate data to EEPROM |
| 138 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); |
| 139 | |
| 140 | // Reads selected coordinate data from EEPROM |
| 141 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); |
| 142 | |
| 143 | // Returns the step pin mask according to Grbl's internal axis numbering |
| 144 | uint8_t get_step_pin_mask(uint8_t i); |
| 145 | |
| 146 | // Returns the direction pin mask according to Grbl's internal axis numbering |
| 147 | uint8_t get_direction_pin_mask(uint8_t i); |
| 148 | |
| 149 | // Returns the limit pin mask according to Grbl's internal axis numbering |
| 150 | uint8_t get_limit_pin_mask(uint8_t i); |
| 151 | |
| 152 | |
| 153 | #endif |