Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
grbl/settings.h@0:9dcf85d9b2f3, 2017-09-04 (annotated)
- Committer:
- Sergunb
- Date:
- Mon Sep 04 12:05:05 2017 +0000
- Revision:
- 0:9dcf85d9b2f3
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:9dcf85d9b2f3 | 1 | /* |
Sergunb | 0:9dcf85d9b2f3 | 2 | settings.h - eeprom configuration handling |
Sergunb | 0:9dcf85d9b2f3 | 3 | Part of Grbl |
Sergunb | 0:9dcf85d9b2f3 | 4 | |
Sergunb | 0:9dcf85d9b2f3 | 5 | Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC |
Sergunb | 0:9dcf85d9b2f3 | 6 | Copyright (c) 2009-2011 Simen Svale Skogsrud |
Sergunb | 0:9dcf85d9b2f3 | 7 | |
Sergunb | 0:9dcf85d9b2f3 | 8 | Grbl is free software: you can redistribute it and/or modify |
Sergunb | 0:9dcf85d9b2f3 | 9 | it under the terms of the GNU General Public License as published by |
Sergunb | 0:9dcf85d9b2f3 | 10 | the Free Software Foundation, either version 3 of the License, or |
Sergunb | 0:9dcf85d9b2f3 | 11 | (at your option) any later version. |
Sergunb | 0:9dcf85d9b2f3 | 12 | |
Sergunb | 0:9dcf85d9b2f3 | 13 | Grbl is distributed in the hope that it will be useful, |
Sergunb | 0:9dcf85d9b2f3 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:9dcf85d9b2f3 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:9dcf85d9b2f3 | 16 | GNU General Public License for more details. |
Sergunb | 0:9dcf85d9b2f3 | 17 | |
Sergunb | 0:9dcf85d9b2f3 | 18 | You should have received a copy of the GNU General Public License |
Sergunb | 0:9dcf85d9b2f3 | 19 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
Sergunb | 0:9dcf85d9b2f3 | 20 | */ |
Sergunb | 0:9dcf85d9b2f3 | 21 | |
Sergunb | 0:9dcf85d9b2f3 | 22 | #ifndef settings_h |
Sergunb | 0:9dcf85d9b2f3 | 23 | #define settings_h |
Sergunb | 0:9dcf85d9b2f3 | 24 | |
Sergunb | 0:9dcf85d9b2f3 | 25 | #include "grbl.h" |
Sergunb | 0:9dcf85d9b2f3 | 26 | |
Sergunb | 0:9dcf85d9b2f3 | 27 | |
Sergunb | 0:9dcf85d9b2f3 | 28 | // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl |
Sergunb | 0:9dcf85d9b2f3 | 29 | // when firmware is upgraded. Always stored in byte 0 of eeprom |
Sergunb | 0:9dcf85d9b2f3 | 30 | #define SETTINGS_VERSION 10 // NOTE: Check settings_reset() when moving to next version. |
Sergunb | 0:9dcf85d9b2f3 | 31 | |
Sergunb | 0:9dcf85d9b2f3 | 32 | // Define bit flag masks for the boolean settings in settings.flag. |
Sergunb | 0:9dcf85d9b2f3 | 33 | #define BITFLAG_REPORT_INCHES bit(0) |
Sergunb | 0:9dcf85d9b2f3 | 34 | #define BITFLAG_LASER_MODE bit(1) |
Sergunb | 0:9dcf85d9b2f3 | 35 | #define BITFLAG_INVERT_ST_ENABLE bit(2) |
Sergunb | 0:9dcf85d9b2f3 | 36 | #define BITFLAG_HARD_LIMIT_ENABLE bit(3) |
Sergunb | 0:9dcf85d9b2f3 | 37 | #define BITFLAG_HOMING_ENABLE bit(4) |
Sergunb | 0:9dcf85d9b2f3 | 38 | #define BITFLAG_SOFT_LIMIT_ENABLE bit(5) |
Sergunb | 0:9dcf85d9b2f3 | 39 | #define BITFLAG_INVERT_LIMIT_PINS bit(6) |
Sergunb | 0:9dcf85d9b2f3 | 40 | #define BITFLAG_INVERT_PROBE_PIN bit(7) |
Sergunb | 0:9dcf85d9b2f3 | 41 | |
Sergunb | 0:9dcf85d9b2f3 | 42 | // Define status reporting boolean enable bit flags in settings.status_report_mask |
Sergunb | 0:9dcf85d9b2f3 | 43 | #define BITFLAG_RT_STATUS_POSITION_TYPE bit(0) |
Sergunb | 0:9dcf85d9b2f3 | 44 | #define BITFLAG_RT_STATUS_BUFFER_STATE bit(1) |
Sergunb | 0:9dcf85d9b2f3 | 45 | |
Sergunb | 0:9dcf85d9b2f3 | 46 | // Define settings restore bitflags. |
Sergunb | 0:9dcf85d9b2f3 | 47 | #define SETTINGS_RESTORE_DEFAULTS bit(0) |
Sergunb | 0:9dcf85d9b2f3 | 48 | #define SETTINGS_RESTORE_PARAMETERS bit(1) |
Sergunb | 0:9dcf85d9b2f3 | 49 | #define SETTINGS_RESTORE_STARTUP_LINES bit(2) |
Sergunb | 0:9dcf85d9b2f3 | 50 | #define SETTINGS_RESTORE_BUILD_INFO bit(3) |
Sergunb | 0:9dcf85d9b2f3 | 51 | #ifndef SETTINGS_RESTORE_ALL |
Sergunb | 0:9dcf85d9b2f3 | 52 | #define SETTINGS_RESTORE_ALL 0xFF // All bitflags |
Sergunb | 0:9dcf85d9b2f3 | 53 | #endif |
Sergunb | 0:9dcf85d9b2f3 | 54 | |
Sergunb | 0:9dcf85d9b2f3 | 55 | // Define EEPROM memory address location values for Grbl settings and parameters |
Sergunb | 0:9dcf85d9b2f3 | 56 | // NOTE: The Atmega328p has 1KB EEPROM. The upper half is reserved for parameters and |
Sergunb | 0:9dcf85d9b2f3 | 57 | // the startup script. The lower half contains the global settings and space for future |
Sergunb | 0:9dcf85d9b2f3 | 58 | // developments. |
Sergunb | 0:9dcf85d9b2f3 | 59 | #define EEPROM_ADDR_GLOBAL 1U |
Sergunb | 0:9dcf85d9b2f3 | 60 | #define EEPROM_ADDR_PARAMETERS 512U |
Sergunb | 0:9dcf85d9b2f3 | 61 | #define EEPROM_ADDR_STARTUP_BLOCK 768U |
Sergunb | 0:9dcf85d9b2f3 | 62 | #define EEPROM_ADDR_BUILD_INFO 942U |
Sergunb | 0:9dcf85d9b2f3 | 63 | |
Sergunb | 0:9dcf85d9b2f3 | 64 | // Define EEPROM address indexing for coordinate parameters |
Sergunb | 0:9dcf85d9b2f3 | 65 | #define N_COORDINATE_SYSTEM 6 // Number of supported work coordinate systems (from index 1) |
Sergunb | 0:9dcf85d9b2f3 | 66 | #define SETTING_INDEX_NCOORD N_COORDINATE_SYSTEM+1 // Total number of system stored (from index 0) |
Sergunb | 0:9dcf85d9b2f3 | 67 | // NOTE: Work coordinate indices are (0=G54, 1=G55, ... , 6=G59) |
Sergunb | 0:9dcf85d9b2f3 | 68 | #define SETTING_INDEX_G28 N_COORDINATE_SYSTEM // Home position 1 |
Sergunb | 0:9dcf85d9b2f3 | 69 | #define SETTING_INDEX_G30 N_COORDINATE_SYSTEM+1 // Home position 2 |
Sergunb | 0:9dcf85d9b2f3 | 70 | // #define SETTING_INDEX_G92 N_COORDINATE_SYSTEM+2 // Coordinate offset (G92.2,G92.3 not supported) |
Sergunb | 0:9dcf85d9b2f3 | 71 | |
Sergunb | 0:9dcf85d9b2f3 | 72 | // Define Grbl axis settings numbering scheme. Starts at START_VAL, every INCREMENT, over N_SETTINGS. |
Sergunb | 0:9dcf85d9b2f3 | 73 | #define AXIS_N_SETTINGS 4 |
Sergunb | 0:9dcf85d9b2f3 | 74 | #define AXIS_SETTINGS_START_VAL 100 // NOTE: Reserving settings values >= 100 for axis settings. Up to 255. |
Sergunb | 0:9dcf85d9b2f3 | 75 | #define AXIS_SETTINGS_INCREMENT 10 // Must be greater than the number of axis settings |
Sergunb | 0:9dcf85d9b2f3 | 76 | |
Sergunb | 0:9dcf85d9b2f3 | 77 | // Global persistent settings (Stored from byte EEPROM_ADDR_GLOBAL onwards) |
Sergunb | 0:9dcf85d9b2f3 | 78 | typedef struct { |
Sergunb | 0:9dcf85d9b2f3 | 79 | // Axis settings |
Sergunb | 0:9dcf85d9b2f3 | 80 | float steps_per_mm[N_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 81 | float max_rate[N_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 82 | float acceleration[N_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 83 | float max_travel[N_AXIS]; |
Sergunb | 0:9dcf85d9b2f3 | 84 | |
Sergunb | 0:9dcf85d9b2f3 | 85 | // Remaining Grbl settings |
Sergunb | 0:9dcf85d9b2f3 | 86 | uint8_t pulse_microseconds; |
Sergunb | 0:9dcf85d9b2f3 | 87 | uint8_t step_invert_mask; |
Sergunb | 0:9dcf85d9b2f3 | 88 | uint8_t dir_invert_mask; |
Sergunb | 0:9dcf85d9b2f3 | 89 | uint8_t stepper_idle_lock_time; // If max value 255, steppers do not disable. |
Sergunb | 0:9dcf85d9b2f3 | 90 | uint8_t status_report_mask; // Mask to indicate desired report data. |
Sergunb | 0:9dcf85d9b2f3 | 91 | float junction_deviation; |
Sergunb | 0:9dcf85d9b2f3 | 92 | float arc_tolerance; |
Sergunb | 0:9dcf85d9b2f3 | 93 | |
Sergunb | 0:9dcf85d9b2f3 | 94 | float rpm_max; |
Sergunb | 0:9dcf85d9b2f3 | 95 | float rpm_min; |
Sergunb | 0:9dcf85d9b2f3 | 96 | |
Sergunb | 0:9dcf85d9b2f3 | 97 | uint8_t flags; // Contains default boolean settings |
Sergunb | 0:9dcf85d9b2f3 | 98 | |
Sergunb | 0:9dcf85d9b2f3 | 99 | uint8_t homing_dir_mask; |
Sergunb | 0:9dcf85d9b2f3 | 100 | float homing_feed_rate; |
Sergunb | 0:9dcf85d9b2f3 | 101 | float homing_seek_rate; |
Sergunb | 0:9dcf85d9b2f3 | 102 | uint16_t homing_debounce_delay; |
Sergunb | 0:9dcf85d9b2f3 | 103 | float homing_pulloff; |
Sergunb | 0:9dcf85d9b2f3 | 104 | } settings_t; |
Sergunb | 0:9dcf85d9b2f3 | 105 | extern settings_t settings; |
Sergunb | 0:9dcf85d9b2f3 | 106 | |
Sergunb | 0:9dcf85d9b2f3 | 107 | // Initialize the configuration subsystem (load settings from EEPROM) |
Sergunb | 0:9dcf85d9b2f3 | 108 | void settings_init(); |
Sergunb | 0:9dcf85d9b2f3 | 109 | |
Sergunb | 0:9dcf85d9b2f3 | 110 | // Helper function to clear and restore EEPROM defaults |
Sergunb | 0:9dcf85d9b2f3 | 111 | void settings_restore(uint8_t restore_flag); |
Sergunb | 0:9dcf85d9b2f3 | 112 | |
Sergunb | 0:9dcf85d9b2f3 | 113 | // A helper method to set new settings from command line |
Sergunb | 0:9dcf85d9b2f3 | 114 | uint8_t settings_store_global_setting(uint8_t parameter, float value); |
Sergunb | 0:9dcf85d9b2f3 | 115 | |
Sergunb | 0:9dcf85d9b2f3 | 116 | // Stores the protocol line variable as a startup line in EEPROM |
Sergunb | 0:9dcf85d9b2f3 | 117 | void settings_store_startup_line(uint8_t n, char *line); |
Sergunb | 0:9dcf85d9b2f3 | 118 | |
Sergunb | 0:9dcf85d9b2f3 | 119 | // Reads an EEPROM startup line to the protocol line variable |
Sergunb | 0:9dcf85d9b2f3 | 120 | uint8_t settings_read_startup_line(uint8_t n, char *line); |
Sergunb | 0:9dcf85d9b2f3 | 121 | |
Sergunb | 0:9dcf85d9b2f3 | 122 | // Stores build info user-defined string |
Sergunb | 0:9dcf85d9b2f3 | 123 | void settings_store_build_info(char *line); |
Sergunb | 0:9dcf85d9b2f3 | 124 | |
Sergunb | 0:9dcf85d9b2f3 | 125 | // Reads build info user-defined string |
Sergunb | 0:9dcf85d9b2f3 | 126 | uint8_t settings_read_build_info(char *line); |
Sergunb | 0:9dcf85d9b2f3 | 127 | |
Sergunb | 0:9dcf85d9b2f3 | 128 | // Writes selected coordinate data to EEPROM |
Sergunb | 0:9dcf85d9b2f3 | 129 | void settings_write_coord_data(uint8_t coord_select, float *coord_data); |
Sergunb | 0:9dcf85d9b2f3 | 130 | |
Sergunb | 0:9dcf85d9b2f3 | 131 | // Reads selected coordinate data from EEPROM |
Sergunb | 0:9dcf85d9b2f3 | 132 | uint8_t settings_read_coord_data(uint8_t coord_select, float *coord_data); |
Sergunb | 0:9dcf85d9b2f3 | 133 | |
Sergunb | 0:9dcf85d9b2f3 | 134 | #endif |