From 090da8ddad33d3764bdaae8dff0874099b7d44ba Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 24 Jul 2011 18:43:05 +0200 Subject: [PATCH] Clean up handling PS_ON_PIN and STEPPER_ENABLE_PIN. This means moving power_on() from a macro to a function and initializing the STEPPER_ENABLE_PIN in mendel.c. --- mendel.c | 14 ++++++++++++++ pinio.c | 21 ++++++++++++++++++++- pinio.h | 13 +------------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/mendel.c b/mendel.c index 1abd082..67d6a02 100644 --- a/mendel.c +++ b/mendel.c @@ -66,6 +66,18 @@ void io_init(void) { ACSR = MASK(ACD); // setup I/O pins + + // Common Stepper Enable + #ifdef STEPPER_ENABLE_PIN + #ifdef STEPPER_ENABLE_INVERT + WRITE(STEPPER_ENABLE_PIN, 0); + #else + WRITE(STEPPER_ENABLE_PIN, 1); + #endif + SET_OUTPUT(STEPPER_ENABLE_PIN); + #endif + + // X Stepper WRITE(X_STEP_PIN, 0); SET_OUTPUT(X_STEP_PIN); WRITE(X_DIR_PIN, 0); SET_OUTPUT(X_DIR_PIN); #ifdef X_MIN_PIN @@ -88,6 +100,7 @@ void io_init(void) { WRITE(X_ENABLE_PIN, 1); SET_OUTPUT(X_ENABLE_PIN); #endif + // Y Stepper WRITE(Y_STEP_PIN, 0); SET_OUTPUT(Y_STEP_PIN); WRITE(Y_DIR_PIN, 0); SET_OUTPUT(Y_DIR_PIN); #ifdef Y_MIN_PIN @@ -110,6 +123,7 @@ void io_init(void) { WRITE(Y_ENABLE_PIN, 1); SET_OUTPUT(Y_ENABLE_PIN); #endif + // Z Stepper #if defined Z_STEP_PIN && defined Z_DIR_PIN WRITE(Z_STEP_PIN, 0); SET_OUTPUT(Z_STEP_PIN); WRITE(Z_DIR_PIN, 0); SET_OUTPUT(Z_DIR_PIN); diff --git a/pinio.c b/pinio.c index 536d15d..01c77d4 100644 --- a/pinio.c +++ b/pinio.c @@ -1,5 +1,20 @@ #include "pinio.h" +void power_on() { + + #ifdef STEPPER_ENABLE_PIN + #ifdef STEPPER_ENABLE_INVERT + WRITE(STEPPER_ENABLE_PIN, 0); + #else + WRITE(STEPPER_ENABLE_PIN, 1); + #endif + #endif + #ifdef PS_ON_PIN + WRITE(PS_ON_PIN, 0); + SET_OUTPUT(PS_ON_PIN); + #endif +} + void power_off() { x_disable(); @@ -7,7 +22,11 @@ void power_off() { z_disable(); #ifdef STEPPER_ENABLE_PIN - WRITE(STEPPER_ENABLE_PIN, STEPPER_ENABLE_INVERT ^ 1); + #ifdef STEPPER_ENABLE_INVERT + WRITE(STEPPER_ENABLE_PIN, 1); + #else + WRITE(STEPPER_ENABLE_PIN, 0); + #endif #endif #ifdef PS_ON_PIN SET_INPUT(PS_ON_PIN); diff --git a/pinio.h b/pinio.h index 909759e..c93d1ee 100644 --- a/pinio.h +++ b/pinio.h @@ -23,22 +23,11 @@ #define E_INVERT_ENABLE 0 #endif -#ifndef STEPPER_ENABLE_INVERT - #define STEPPER_ENABLE_INVERT 0 -#endif - /* Power */ -#ifdef STEPPER_ENABLE_PIN - #define power_on() do { WRITE(STEPPER_ENABLE_PIN, STEPPER_ENABLE_INVERT); SET_OUTPUT(STEPPER_ENABLE_PIN); } while (0) -#elif defined PS_ON_PIN - #define power_on() do { WRITE(PS_ON_PIN, 0); SET_OUTPUT(PS_ON_PIN); } while (0) -#else - #define power_on() do { } while (0) -#endif - +void power_on(void); void power_off(void); /*