diff --git a/analog.c b/analog.c index c2b177d..bdc3b6a 100644 --- a/analog.c +++ b/analog.c @@ -2,9 +2,6 @@ #include -#include "arduino.h" -#include "machine.h" - #ifndef ANALOG_MASK #warning define ANALOG_MASK as a bitmask of all the analog channels you wish to use #error ANALOG_MASK not defined diff --git a/analog.h b/analog.h index 10e2f93..2722f50 100644 --- a/analog.h +++ b/analog.h @@ -7,12 +7,12 @@ #define REFERENCE_AVCC 64 #define REFERENCE_1V1 192 -#include "machine.h" +#include "config.h" #ifndef REFERENCE #warning define REFERENCE as one of #warning REFERENCE_AREF, REFERENCE_AVCC or REFERENCE_1V1 -#warning in your machine.h +#warning in your config.h #error REFERENCE undefined #endif diff --git a/clock.c b/clock.c index 75e0d00..ecfa572 100644 --- a/clock.c +++ b/clock.c @@ -9,8 +9,7 @@ #include #include -#include "arduino.h" -#include "pinout.h" +#include "config.h" // global clock #ifdef GLOBAL_CLOCK diff --git a/machine.h b/config.h.dist similarity index 55% rename from machine.h rename to config.h.dist index 720406c..e4e6f6d 100644 --- a/machine.h +++ b/config.h.dist @@ -1,5 +1,5 @@ -#ifndef _MACHINE_H -#define _MACHINE_H +#ifndef _CONFIG_H +#define _CONFIG_H // -------------------------------------------------------------------------- // values reflecting the gearing of your machine @@ -98,10 +98,71 @@ firmware build options ANALOG_MASK - which analog inputs we will be using, bitmask. eg; #define ANALOG_MASK MASK(AIO0_PIN) | MASK(3) for AIN0 and AIN3 */ #define REFERENCE REFERENCE_AREF + #ifndef ANALOG_MASK #define ANALOG_MASK 0 #endif +/* + Machine Pin Definitions +*/ + +#include "arduino.h" + +/* + RESERVED pins + we NEED these for communication +*/ + +#define RESERVED_RXD DIO0 +#define RESERVED_TXD DIO1 + +/* + these pins are used for the MAX6675 +*/ +#define RESERVED_SCK DIO13 +#define RESERVED_MISO DIO12 +#define RESERVED_MOSI DIO11 +#define RESERVED_SS DIO10 + +/* + user defined pins + adjust to suit your electronics, + or adjust your electronics to suit this +*/ + +#define X_STEP_PIN AIO0 +#define X_DIR_PIN AIO1 +#define X_MIN_PIN AIO2 + +#define Y_STEP_PIN AIO3 +#define Y_DIR_PIN AIO4 +#define Y_MIN_PIN AIO5 + +#define Z_STEP_PIN DIO2 +#define Z_DIR_PIN DIO3 +#define Z_MIN_PIN DIO4 + +#define E_STEP_PIN DIO7 +#define E_DIR_PIN DIO8 + +#define STEPPER_ENABLE_PIN DIO9 + +// list of PWM-able pins and corresponding timers +// timer1 is used for step timing so don't use OC1A/OC1B (DIO9/DIO10) +// OC0A DIO6 +// OC0B DIO5 +// OC1A DIO9 +// OC1B DIO10 +// OC2A DIO11 +// OC2B DIO3 + +#define HEATER_PIN DIO6 +#define HEATER_PWM OCR0A + +#define FAN_PIN DIO5 +#define FAN_PWM OCR0B + // -------------------------------------------------------------------------- // you shouldn't need to edit anything below this line @@ -117,4 +178,107 @@ firmware build options #define UM_PER_STEP_Z ((uint32_t) ((1000.0 / STEPS_PER_MM_Z) + 0.5)) #define UM_PER_STEP_E ((uint32_t) ((1000.0 / STEPS_PER_MM_E) + 0.5)) -#endif /* _MACHINE_H */ + +/* + X Stepper +*/ + +#define _x_step(st) WRITE(X_STEP_PIN, st) +#define x_step() _x_step(1); +#define x_direction(dir) WRITE(X_DIR_PIN, dir) +#define x_min() READ(X_MIN_PIN) +#ifdef X_MAX_PIN + #define x_max() READ(X_MAX_PIN) +#else + #define x_max() (0) +#endif + +/* + Y Stepper +*/ + +#define _y_step(st) WRITE(Y_STEP_PIN, st) +#define y_step() _y_step(1); +#define y_direction(dir) WRITE(Y_DIR_PIN, dir) +#define y_min() READ(Y_MIN_PIN) +#ifdef Y_MAX_PIN + #define y_max() READ(Y_MAX_PIN) +#else + #define y_max() (0) +#endif + +/* + Z Stepper +*/ + +#define _z_step(st) WRITE(Z_STEP_PIN, st) +#define z_step() _z_step(1); +#define z_direction(dir) WRITE(Z_DIR_PIN, dir) +#define z_min() READ(Z_MIN_PIN) +#ifdef Z_MAX_PIN + #define z_max() READ(Z_MAX_PIN) +#else + #define z_max() (0) +#endif + +/* + Extruder +*/ + +#define _e_step(st) WRITE(E_STEP_PIN, st) +#define e_step() _e_step(1); +#define e_direction(dir) WRITE(E_DIR_PIN, dir) + +/* + Heater +*/ + +#ifdef HEATER_PWM + #define enable_heater() do { TCCR0A |= MASK(COM0A1); } while (0) + #define disable_heater() do { TCCR0A &= ~MASK(COM0A1); } while (0) +#else + #define enable_heater() WRITE(HEATER_PIN, 1) + #define disable_heater() WRITE(HEATER_PIN, 0) +#endif + +/* + fan +*/ + +#ifdef FAN_PIN + #ifdef FAN_PWM + #define enable_fan() do { TCCR0A |= MASK(COM0B1); } while (0) + #define disable_fan() do { TCCR0A &= ~MASK(COM0B1); } while (0) + #else + #define enable_fan() WRITE(FAN_PIN, 1) + #define disable_fan() WRITE(FAN_PIN, 0); + #endif +#else + #define enable_fan() if (0) {} + #define disable_fan() if (0) {} +#endif + +/* + Stepper Enable (ATX PSU pwr_good signal?) +*/ + +#ifdef STEPPER_ENABLE_PIN + // for connection to stepper driver ENABLE pins (negative asserted) +// #define power_on() WRITE(STEPPER_ENABLE_PIN, 0) +// #define power_off() WRITE(STEPPER_ENABLE_PIN, 1) + // for connection to ATX PSU PWR_ON signal + #define power_on() do { WRITE(STEPPER_ENABLE_PIN, 0); SET_OUTPUT(STEPPER_ENABLE_PIN); } while (0) + #define power_off() SET_INPUT(STEPPER_ENABLE_PIN) +#else + #define power_on() if (0) {} + #define power_off() if (0) {} +#endif + +/* + End Step - All Steppers + (so we don't have to delay in interrupt context) +*/ + +#define unstep() do { _x_step(0); _y_step(0); _z_step(0); _e_step(0); } while (0) + +#endif /* _CONFIG_H */ diff --git a/dda.h b/dda.h index 2f84951..a7f374b 100644 --- a/dda.h +++ b/dda.h @@ -3,8 +3,7 @@ #include -#include "pinout.h" -#include "machine.h" +#include "config.h" /* enums diff --git a/dda_queue.c b/dda_queue.c index c43d12c..87af4f4 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -3,7 +3,7 @@ #include #include -#include "machine.h" // for XONXOFF +#include "config.h" // for XONXOFF #include "timer.h" #include "serial.h" #include "sermsg.h" diff --git a/gcode.c b/gcode.c index 23cefee..4f3212b 100644 --- a/gcode.c +++ b/gcode.c @@ -2,7 +2,7 @@ #include -#include "machine.h" +#include "config.h" #include "serial.h" #include "sermsg.h" #include "temp.h" diff --git a/heater.c b/heater.c index 57d92af..1f3e1e7 100644 --- a/heater.c +++ b/heater.c @@ -3,8 +3,7 @@ #include #include "sersendf.h" -#include "machine.h" -#include "pinout.h" +#include "config.h" #include "debug.h" #include "arduino.h" diff --git a/mendel.c b/mendel.c index 0ccf7f9..1154ebd 100644 --- a/mendel.c +++ b/mendel.c @@ -2,7 +2,7 @@ #include #include -#include "machine.h" +#include "config.h" #include "serial.h" #include "dda_queue.h" @@ -98,7 +98,7 @@ void init(void) { // set up default feedrate current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; - // start up analog read interrupt loop, if anything uses analog as determined by ANALOG_MASK in your machine.h + // start up analog read interrupt loop, if anything uses analog as determined by ANALOG_MASK in your config.h analog_init(); // enable interrupts diff --git a/pinout.h b/pinout.h deleted file mode 100644 index 868d6b1..0000000 --- a/pinout.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef _PINOUT_H -#define _PINOUT_H - -#include "arduino.h" - -/* - Machine Pin Definitions -*/ - -/* - RESERVED pins - we NEED these for communication -*/ - -#define RESERVED_RXD DIO0 -#define RESERVED_TXD DIO1 -#define RESERVED_SCK DIO13 -#define RESERVED_MISO DIO12 -#define RESERVED_MOSI DIO11 -#define RESERVED_SS DIO10 - -/* - user defined pins - adjust to suit your electronics, - or adjust your electronics to suit this -*/ - -#define X_STEP_PIN AIO0 -#define X_DIR_PIN AIO1 -#define X_MIN_PIN AIO2 - -#define Y_STEP_PIN AIO3 -#define Y_DIR_PIN AIO4 -#define Y_MIN_PIN AIO5 - -#define Z_STEP_PIN DIO2 -#define Z_DIR_PIN DIO3 -#define Z_MIN_PIN DIO4 - -#define E_STEP_PIN DIO7 -#define E_DIR_PIN DIO8 - -#define STEPPER_ENABLE_PIN DIO9 - -// list of PWM-able pins and corresponding timers -// timer1 is used for step timing so don't use OC1A/OC1B (DIO9/DIO10) -// OC0A DIO6 -// OC0B DIO5 -// OC1A DIO9 -// OC1B DIO10 -// OC2A DIO11 -// OC2B DIO3 - -#define HEATER_PIN DIO6 -#define HEATER_PWM OCR0A - -#define FAN_PIN DIO5 -#define FAN_PWM OCR0B - -/* - X Stepper -*/ - -#define _x_step(st) WRITE(X_STEP_PIN, st) -#define x_step() _x_step(1); -#define x_direction(dir) WRITE(X_DIR_PIN, dir) -#define x_min() READ(X_MIN_PIN) -#ifdef X_MAX_PIN - #define x_max() READ(X_MAX_PIN) -#else - #define x_max() (0) -#endif - -/* - Y Stepper -*/ - -#define _y_step(st) WRITE(Y_STEP_PIN, st) -#define y_step() _y_step(1); -#define y_direction(dir) WRITE(Y_DIR_PIN, dir) -#define y_min() READ(Y_MIN_PIN) -#ifdef Y_MAX_PIN - #define y_max() READ(Y_MAX_PIN) -#else - #define y_max() (0) -#endif - -/* - Z Stepper -*/ - -#define _z_step(st) WRITE(Z_STEP_PIN, st) -#define z_step() _z_step(1); -#define z_direction(dir) WRITE(Z_DIR_PIN, dir) -#define z_min() READ(Z_MIN_PIN) -#ifdef Z_MAX_PIN - #define z_max() READ(Z_MAX_PIN) -#else - #define z_max() (0) -#endif - -/* - Extruder -*/ - -#define _e_step(st) WRITE(E_STEP_PIN, st) -#define e_step() _e_step(1); -#define e_direction(dir) WRITE(E_DIR_PIN, dir) - -/* - Heater -*/ - -#ifdef HEATER_PWM - #define enable_heater() do { TCCR0A |= MASK(COM0A1); } while (0) - #define disable_heater() do { TCCR0A &= ~MASK(COM0A1); } while (0) -#else - #define enable_heater() WRITE(HEATER_PIN, 1) - #define disable_heater() WRITE(HEATER_PIN, 0) -#endif - -/* - fan -*/ - -#ifdef FAN_PIN - #ifdef FAN_PWM - #define enable_fan() do { TCCR0A |= MASK(COM0B1); } while (0) - #define disable_fan() do { TCCR0A &= ~MASK(COM0B1); } while (0) - #else - #define enable_fan() WRITE(FAN_PIN, 1) - #define disable_fan() WRITE(FAN_PIN, 0); - #endif -#else - #define enable_fan() if (0) {} - #define disable_fan() if (0) {} -#endif - -/* - Stepper Enable (ATX PSU pwr_good signal?) -*/ - -#ifdef STEPPER_ENABLE_PIN - // for connection to stepper driver ENABLE pins (negative asserted) -// #define power_on() WRITE(STEPPER_ENABLE_PIN, 0) -// #define power_off() WRITE(STEPPER_ENABLE_PIN, 1) - // for connection to ATX PSU PWR_ON signal - #define power_on() do { WRITE(STEPPER_ENABLE_PIN, 0); SET_OUTPUT(STEPPER_ENABLE_PIN); } while (0) - #define power_off() SET_INPUT(STEPPER_ENABLE_PIN) -#else - #define power_on() if (0) {} - #define power_off() if (0) {} -#endif - -/* - End Step - All Steppers - (so we don't have to delay in interrupt context) -*/ - -#define unstep() do { _x_step(0); _y_step(0); _z_step(0); _e_step(0); } while (0) - -#endif /* _PINOUT_H */ diff --git a/serial.h b/serial.h index 6deccf3..982ffb9 100644 --- a/serial.h +++ b/serial.h @@ -5,7 +5,7 @@ #include #include -#include "machine.h" // for XONXOFF +#include "config.h" // for XONXOFF // initialise serial subsystem void serial_init(void); diff --git a/temp.c b/temp.c index 7a4285d..517e6d1 100644 --- a/temp.c +++ b/temp.c @@ -20,8 +20,6 @@ #include -#include "machine.h" -#include "pinout.h" #include "clock.h" #include "serial.h" #include "sermsg.h" diff --git a/temp.h b/temp.h index fea61fe..02a3b07 100644 --- a/temp.h +++ b/temp.h @@ -3,7 +3,7 @@ #include -#include "machine.h" +#include "config.h" // RepRap host software isn't exactly tolerant on what it ready back. #define REPRAP_HOST_COMPATIBILITY diff --git a/timer.c b/timer.c index b04be2a..0e0ab91 100644 --- a/timer.c +++ b/timer.c @@ -2,7 +2,7 @@ #include -#include "pinout.h" +#include "config.h" #include "dda_queue.h" #include "dda.h" #include "watchdog.h"