Permalink
Browse files

Processor-independent pin mapping feature.

- Cleaned up and organized pin mapping concept by @elmom.

- pin_map.h allows for user-supplied pin mapping and port vector
definitions in a centralized file. With more processor types, more
definitions could be added.
  • Loading branch information...
1 parent b2a69c0 commit e24e67ffe274cbce2ffae506c4f12de73606dd7b @chamnit chamnit committed Aug 19, 2013
Showing with 192 additions and 165 deletions.
  1. +10 −15 config.h
  2. +0 −70 config_default_2560.h
  3. +0 −66 config_default_328p.h
  4. +1 −0 nuts_bolts.h
  5. +181 −0 pin_map.h
  6. +0 −14 serial.h
View
@@ -2,8 +2,8 @@
config.h - compile time configuration
Part of Grbl
+ Copyright (c) 2011-2013 Sungeun K. Jeon
Copyright (c) 2009-2011 Simen Svale Skogsrud
- Copyright (c) 2011-2012 Sungeun K. Jeon
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,29 +19,24 @@
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef config_h
-#define config_h
+// This file contains compile-time configurations for Grbl's internal system. For the most part,
+// users will not need to directly modify these, but they are here for specific needs, i.e.
+// performance tuning or adjusting to non-typical machines.
// IMPORTANT: Any changes here requires a full re-compiling of the source code to propagate them.
+#ifndef config_h
+#define config_h
+
// Default settings. Used when resetting EEPROM. Change to desired name in defaults.h
#define DEFAULTS_GENERIC
// Serial baud rate
#define BAUD_RATE 9600
-// Pin mappings, pick one and comment others
-#define DEFAULT_328P
-//#define DEFAULT_2560
-//#define CUSTOM_PINS
-
-if defined(DEFAULT_328P)
- #include config_default_328p.h
-elif defined(DEFAULT_2560)
- #include config_default_2560.h
-elif defined(CUSTOM_PINS)
- #include config_custom.h // Create from the closest pre-existing config_default_*.h
-#endif
+// Default pin mappings. Grbl officially supports the Arduino Uno only. Other processor types
+// may exist from user-supplied templates or directly user-defined in pin_map.h
+#define ARDUINO_UNO
// Define runtime command special characters. These characters are 'picked-off' directly from the
// serial read data stream and are not passed to the grbl line execution parser. Select characters
View
@@ -1,70 +0,0 @@
-#ifndef config_default_2560_h
-#define config_default_2560_h
-
-// Define pin-assignments
-// NOTE: All step bit and direction pins must be on the same port.
-#define STEPPING_DDR DDRA
-#define STEPPING_PORT PORTA
-#define STEPPING_PIN PINA
-#define X_STEP_BIT 0 // MEGA2560 Digital Pin 22
-#define Y_STEP_BIT 2 // MEGA2560 Digital Pin 24
-#define Z_STEP_BIT 4 // MEGA2560 Digital Pin 26
-#define C_STEP_BIT 6 // MEGA2560 Digital Pin 28
-#define X_DIRECTION_BIT 1 // MEGA2560 Digital Pin 23
-#define Y_DIRECTION_BIT 3 // MEGA2560 Digital Pin 25
-#define Z_DIRECTION_BIT 5 // MEGA2560 Digital Pin 27
-#define C_DIRECTION_BIT 7 // MEGA2560 Digital Pin 29
-#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
-#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
-#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
-
-#define STEPPERS_DISABLE_DDR DDRC
-#define STEPPERS_DISABLE_PORT PORTC
-#define STEPPERS_DISABLE_BIT 7 // MEGA2560 Digital Pin 30
-#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
-
-// NOTE: All limit bit pins must be on the same port
-#define LIMIT_DDR DDRC
-#define LIMIT_PORT PORTC
-#define LIMIT_PIN PINC
-#define X_LIMIT_BIT 6 // MEGA2560 Digital Pin 31
-#define Y_LIMIT_BIT 5 // MEGA2560 Digital Pin 32
-#define Z_LIMIT_BIT 4 // MEGA2560 Digital Pin 33
-#define C_LIMIT_BIT 3 // MEGA2560 Digital Pin 34
-#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
-#define LIMIT_INT_vect PCINT0_vect
-#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
-#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
-
-#define SPINDLE_ENABLE_DDR DDRC
-#define SPINDLE_ENABLE_PORT PORTC
-#define SPINDLE_ENABLE_BIT 2 // MEGA2560 Digital Pin 35
-
-#define SPINDLE_DIRECTION_DDR DDRC
-#define SPINDLE_DIRECTION_PORT PORTC
-#define SPINDLE_DIRECTION_BIT 1 // MEGA2560 Digital Pin 36
-
-#define COOLANT_FLOOD_DDR DDRC
-#define COOLANT_FLOOD_PORT PORTC
-#define COOLANT_FLOOD_BIT 0 // MEGA2560 Digital Pin 37
-
-// NOTE: Uno analog pins 4 and 5 are reserved for an i2c interface, and may be installed at
-// a later date if flash and memory space allows.
-// #define ENABLE_M7 // Mist coolant disabled by default. Uncomment to enable.
-#ifdef ENABLE_M7
- #define COOLANT_MIST_DDR DDRC
- #define COOLANT_MIST_PORT PORTC
- #define COOLANT_MIST_BIT 0 // MEGA2560 Digital Pin 37
-#endif
-
-// NOTE: All pinouts pins must be on the same port
-#define PINOUT_DDR DDRC
-#define PINOUT_PIN PINC
-#define PINOUT_PORT PORTC
-#define PIN_RESET 0 // Uno Analog Pin 0
-#define PIN_FEED_HOLD 1 // Uno Analog Pin 1
-#define PIN_CYCLE_START 2 // Uno Analog Pin 2
-#define PINOUT_INT PCIE1 // Pin change interrupt enable pin
-#define PINOUT_INT_vect PCINT1_vect
-#define PINOUT_PCMSK PCMSK1 // Pin change interrupt register
-#define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
View
@@ -1,66 +0,0 @@
-#ifndef config_default_2560_h
-#define config_default_2560_h
-
-// Define pin-assignments
-// NOTE: All step bit and direction pins must be on the same port.
-#define STEPPING_DDR DDRD
-#define STEPPING_PORT PORTD
-#define X_STEP_BIT 2 // Uno Digital Pin 2
-#define Y_STEP_BIT 3 // Uno Digital Pin 3
-#define Z_STEP_BIT 4 // Uno Digital Pin 4
-#define X_DIRECTION_BIT 5 // Uno Digital Pin 5
-#define Y_DIRECTION_BIT 6 // Uno Digital Pin 6
-#define Z_DIRECTION_BIT 7 // Uno Digital Pin 7
-#define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
-#define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
-#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
-
-#define STEPPERS_DISABLE_DDR DDRB
-#define STEPPERS_DISABLE_PORT PORTB
-#define STEPPERS_DISABLE_BIT 0 // Uno Digital Pin 8
-#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
-
-// NOTE: All limit bit pins must be on the same port
-#define LIMIT_DDR DDRB
-#define LIMIT_PIN PINB
-#define LIMIT_PORT PORTB
-#define X_LIMIT_BIT 1 // Uno Digital Pin 9
-#define Y_LIMIT_BIT 2 // Uno Digital Pin 10
-#define Z_LIMIT_BIT 3 // Uno Digital Pin 11
-#define LIMIT_INT PCIE0 // Pin change interrupt enable pin
-#define LIMIT_INT_vect PCINT0_vect
-#define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
-#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
-
-#define SPINDLE_ENABLE_DDR DDRB
-#define SPINDLE_ENABLE_PORT PORTB
-#define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
-
-#define SPINDLE_DIRECTION_DDR DDRB
-#define SPINDLE_DIRECTION_PORT PORTB
-#define SPINDLE_DIRECTION_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
-
-#define COOLANT_FLOOD_DDR DDRC
-#define COOLANT_FLOOD_PORT PORTC
-#define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3
-
-// NOTE: Uno analog pins 4 and 5 are reserved for an i2c interface, and may be installed at
-// a later date if flash and memory space allows.
-// #define ENABLE_M7 // Mist coolant disabled by default. Uncomment to enable.
-#ifdef ENABLE_M7
- #define COOLANT_MIST_DDR DDRC
- #define COOLANT_MIST_PORT PORTC
- #define COOLANT_MIST_BIT 4 // Uno Analog Pin 4
-#endif
-
-// NOTE: All pinouts pins must be on the same port
-#define PINOUT_DDR DDRC
-#define PINOUT_PIN PINC
-#define PINOUT_PORT PORTC
-#define PIN_RESET 0 // Uno Analog Pin 0
-#define PIN_FEED_HOLD 1 // Uno Analog Pin 1
-#define PIN_CYCLE_START 2 // Uno Analog Pin 2
-#define PINOUT_INT PCIE1 // Pin change interrupt enable pin
-#define PINOUT_INT_vect PCINT1_vect
-#define PINOUT_PCMSK PCMSK1 // Pin change interrupt register
-#define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
View
@@ -27,6 +27,7 @@
#include <stdbool.h>
#include "config.h"
#include "defaults.h"
+#include "pin_map.h"
#define false 0
#define true 1
View
@@ -0,0 +1,181 @@
+/*
+ pin_map.h - Pin mapping configuration file
+ Part of Grbl
+
+ Copyright (c) 2013 Sungeun K. Jeon
+
+ Grbl 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.
+
+ Grbl 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 Grbl. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* The pin_map.h file serves as a central pin mapping settings file for different processor
+ types, i.e. AVR 328p or AVR Mega 2560. Grbl officially supports the Arduino Uno, but the
+ other supplied pin mappings are supplied by users, so your results may vary. */
+
+#ifndef pin_map_h
+#define pin_map_h
+
+#ifdef ARDUINO_UNO // AVR 328p, Officially supported by Grbl.
+
+ // Serial port pins
+ #define Serial_RX_vect USART_RX_vect
+ #define Serial_UDRE_vect USART_UDRE_vect
+
+ // NOTE: All step bit and direction pins must be on the same port.
+ #define STEPPING_DDR DDRD
+ #define STEPPING_PORT PORTD
+ #define X_STEP_BIT 2 // Uno Digital Pin 2
+ #define Y_STEP_BIT 3 // Uno Digital Pin 3
+ #define Z_STEP_BIT 4 // Uno Digital Pin 4
+ #define X_DIRECTION_BIT 5 // Uno Digital Pin 5
+ #define Y_DIRECTION_BIT 6 // Uno Digital Pin 6
+ #define Z_DIRECTION_BIT 7 // Uno Digital Pin 7
+ #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
+ #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
+ #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
+
+ #define STEPPERS_DISABLE_DDR DDRB
+ #define STEPPERS_DISABLE_PORT PORTB
+ #define STEPPERS_DISABLE_BIT 0 // Uno Digital Pin 8
+ #define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
+
+ // NOTE: All limit bit pins must be on the same port
+ #define LIMIT_DDR DDRB
+ #define LIMIT_PIN PINB
+ #define LIMIT_PORT PORTB
+ #define X_LIMIT_BIT 1 // Uno Digital Pin 9
+ #define Y_LIMIT_BIT 2 // Uno Digital Pin 10
+ #define Z_LIMIT_BIT 3 // Uno Digital Pin 11
+ #define LIMIT_INT PCIE0 // Pin change interrupt enable pin
+ #define LIMIT_INT_vect PCINT0_vect
+ #define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
+ #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
+
+ #define SPINDLE_ENABLE_DDR DDRB
+ #define SPINDLE_ENABLE_PORT PORTB
+ #define SPINDLE_ENABLE_BIT 4 // Uno Digital Pin 12
+
+ #define SPINDLE_DIRECTION_DDR DDRB
+ #define SPINDLE_DIRECTION_PORT PORTB
+ #define SPINDLE_DIRECTION_BIT 5 // Uno Digital Pin 13 (NOTE: D13 can't be pulled-high input due to LED.)
+
+ #define COOLANT_FLOOD_DDR DDRC
+ #define COOLANT_FLOOD_PORT PORTC
+ #define COOLANT_FLOOD_BIT 3 // Uno Analog Pin 3
+
+ // NOTE: Uno analog pins 4 and 5 are reserved for an i2c interface, and may be installed at
+ // a later date if flash and memory space allows.
+ // #define ENABLE_M7 // Mist coolant disabled by default. Uncomment to enable.
+ #ifdef ENABLE_M7
+ #define COOLANT_MIST_DDR DDRC
+ #define COOLANT_MIST_PORT PORTC
+ #define COOLANT_MIST_BIT 4 // Uno Analog Pin 4
+ #endif
+
+ // NOTE: All pinouts pins must be on the same port
+ #define PINOUT_DDR DDRC
+ #define PINOUT_PIN PINC
+ #define PINOUT_PORT PORTC
+ #define PIN_RESET 0 // Uno Analog Pin 0
+ #define PIN_FEED_HOLD 1 // Uno Analog Pin 1
+ #define PIN_CYCLE_START 2 // Uno Analog Pin 2
+ #define PINOUT_INT PCIE1 // Pin change interrupt enable pin
+ #define PINOUT_INT_vect PCINT1_vect
+ #define PINOUT_PCMSK PCMSK1 // Pin change interrupt register
+ #define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
+
+#endif
+
+
+#ifdef ARDUINO_MEGA_2560 // Unsupported. Doesn't work. Supplied by @elmom.
+
+ // Serial port pins
+ #define Serial_RX_vect USART0_RX_vect
+ #define Serial_UDRE_vect USART0_UDRE_vect
+
+ // NOTE: All step bit and direction pins must be on the same port.
+ #define STEPPING_DDR DDRA
+ #define STEPPING_PORT PORTA
+ #define STEPPING_PIN PINA
+ #define X_STEP_BIT 0 // MEGA2560 Digital Pin 22
+ #define Y_STEP_BIT 1 // MEGA2560 Digital Pin 23
+ #define Z_STEP_BIT 2 // MEGA2560 Digital Pin 24
+ // #define C_STEP_BIT 3 // MEGA2560 Digital Pin 25
+ #define X_DIRECTION_BIT 4 // MEGA2560 Digital Pin 26
+ #define Y_DIRECTION_BIT 5 // MEGA2560 Digital Pin 27
+ #define Z_DIRECTION_BIT 6 // MEGA2560 Digital Pin 28
+ // #define C_DIRECTION_BIT 7 // MEGA2560 Digital Pin 29
+ #define STEP_MASK ((1<<X_STEP_BIT)|(1<<Y_STEP_BIT)|(1<<Z_STEP_BIT)) // All step bits
+ #define DIRECTION_MASK ((1<<X_DIRECTION_BIT)|(1<<Y_DIRECTION_BIT)|(1<<Z_DIRECTION_BIT)) // All direction bits
+ #define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
+
+ #define STEPPERS_DISABLE_DDR DDRC
+ #define STEPPERS_DISABLE_PORT PORTC
+ #define STEPPERS_DISABLE_BIT 7 // MEGA2560 Digital Pin 30
+ #define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)
+
+ // NOTE: All limit bit pins must be on the same port
+ #define LIMIT_DDR DDRC
+ #define LIMIT_PORT PORTC
+ #define LIMIT_PIN PINC
+ #define X_LIMIT_BIT 6 // MEGA2560 Digital Pin 31
+ #define Y_LIMIT_BIT 5 // MEGA2560 Digital Pin 32
+ #define Z_LIMIT_BIT 4 // MEGA2560 Digital Pin 33
+ // #define C_LIMIT_BIT 3 // MEGA2560 Digital Pin 34
+ #define LIMIT_INT PCIE0 // Pin change interrupt enable pin
+ #define LIMIT_INT_vect PCINT0_vect
+ #define LIMIT_PCMSK PCMSK0 // Pin change interrupt register
+ #define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
+
+ #define SPINDLE_ENABLE_DDR DDRC
+ #define SPINDLE_ENABLE_PORT PORTC
+ #define SPINDLE_ENABLE_BIT 2 // MEGA2560 Digital Pin 35
+
+ #define SPINDLE_DIRECTION_DDR DDRC
+ #define SPINDLE_DIRECTION_PORT PORTC
+ #define SPINDLE_DIRECTION_BIT 1 // MEGA2560 Digital Pin 36
+
+ #define COOLANT_FLOOD_DDR DDRC
+ #define COOLANT_FLOOD_PORT PORTC
+ #define COOLANT_FLOOD_BIT 0 // MEGA2560 Digital Pin 37
+
+ // #define ENABLE_M7 // Mist coolant disabled by default. Uncomment to enable.
+ #ifdef ENABLE_M7
+ #define COOLANT_MIST_DDR DDRC
+ #define COOLANT_MIST_PORT PORTC
+ #define COOLANT_MIST_BIT 0 // MEGA2560 Digital Pin 37
+ #endif
+
+ // NOTE: All pinouts pins must be on the same port
+ #define PINOUT_DDR DDRC
+ #define PINOUT_PIN PINC
+ #define PINOUT_PORT PORTC
+ #define PIN_RESET 0 // Uno Analog Pin 0
+ #define PIN_FEED_HOLD 1 // Uno Analog Pin 1
+ #define PIN_CYCLE_START 2 // Uno Analog Pin 2
+ #define PINOUT_INT PCIE1 // Pin change interrupt enable pin
+ #define PINOUT_INT_vect PCINT1_vect
+ #define PINOUT_PCMSK PCMSK1 // Pin change interrupt register
+ #define PINOUT_MASK ((1<<PIN_RESET)|(1<<PIN_FEED_HOLD)|(1<<PIN_CYCLE_START))
+
+#endif
+
+/*
+#ifdef CUSTOM_PROC
+ // For a custom pin map or different processor, copy and paste one of the default pin map
+ // settings above and modify it to your needs. Then, make sure the defined name is also
+ // changed in the config.h file.
+#endif
+*/
+
+#endif
View
@@ -27,20 +27,6 @@
#include "nuts_bolts.h"
-#if defined(USART_RX_vect) // For atmega328p (Arduino Uno) etc.
-#define Serial_RX_vect USART_RX_vect
-#define Serial_UDRE_vect USART_UDRE_vect
-#elif defined(USART0_RX_vect) // For atmega644p, atmega1280 and atmega2560 (ArduinoMEGA) etc.
-#define Serial_RX_vect USART0_RX_vect
-#define Serial_UDRE_vect USART0_UDRE_vect
-#elif defined(USART_RXC_vect) // For some odd chips
-#define Serial_RX_vect USART_RXC_vect
-#define Serial_UDRE_vect USART_UDRE_vect
-#elif defined(USART1_RX_vect)// Some AVRs have 1 USB and a single USART (USART1), though the USB is often preffered for serial comms (like Arduino Leonardo etc.)
-#define Serial1_RX_vect USART1_RX_vect
-#define Serial1_UDRE_vect USART1_UDRE_vect
-#endif
-
#ifndef RX_BUFFER_SIZE
#define RX_BUFFER_SIZE 128
#endif

0 comments on commit e24e67f

Please sign in to comment.