HAL compatible pinsDebug & misc

Re-ARM has been tested.  AVR has not been tested.

1) moved all cpu specific items to files in the low level HAL directory
for that CPU (pinDebug_Re-ARM.h & pinsDebug_AVR_8_bit.h

2) added pinsDebug.h to the top level directory

3) modified HAL_pinsDebug.h to select the correct support file for the
selected CPU

4) Patched sanitycheck to stop throwing false errors.  A long term
solution will be done

5) misc changes & bug fixes
arduino.cpp - included macros.h to fix a missing definition
pinmap_re-arm.h - removed a duplicated line.
pinmapping.h - changed from "ENABLED" to "defined" to fix a compile
error

======================================================================

split SanityCheck up, improve pinsDebug system

======================================================================

switch to latest pins_RAMPS_RE_ARM.h
This commit is contained in:
Bob-the-Kuhn
2017-07-31 01:31:14 -05:00
committed by Scott Lahteine
parent 32e759c928
commit 84a11cfedc
17 changed files with 1157 additions and 440 deletions

View File

@ -1,215 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
bool endstop_monitor_flag = false;
#define MAX_NAME_LENGTH 35 // one place to specify the format of all the sources of names
// "-" left justify, "35" minimum width of name, pad with blanks
/**
* This routine minimizes RAM usage by creating a FLASH resident array to
* store the pin names, pin numbers and analog/digital flag.
*
* Creating the array in FLASH is a two pass process. The first pass puts the
* name strings into FLASH. The second pass actually creates the array.
*
* Both passes use the same pin list. The list contains two macro names. The
* actual macro definitions are changed depending on which pass is being done.
*
*/
// first pass - put the name strings into FLASH
#define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
#define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
#define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
#define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
#include "../../../pinsDebug_list.h"
#line 51
/////////////////////////////////////////////////////////////////////////////
// second pass - create the array
#undef _ADD_PIN_2
#undef _ADD_PIN
#undef REPORT_NAME_DIGITAL
#undef REPORT_NAME_ANALOG
#define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
#define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
#define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(NAME, COUNTER, true)
#define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
typedef struct {
const char * const name;
uint8_t pin;
bool is_digital;
} PinInfo;
const PinInfo pin_array[] PROGMEM = {
/**
* [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
* Each entry takes up 6 bytes in FLASH:
* 2 byte pointer to location of the name string
* 2 bytes containing the pin number
* analog pin numbers were convereted to digital when the array was created
* 2 bytes containing the digital/analog bool flag
*/
// manually add pins ...
#if SERIAL_PORT == 0
#endif
#include "../../../pinsDebug_list.h"
#line 102
};
#define AVR_ATmega2560_FAMILY_PLUS_70 (MOTHERBOARD == BOARD_BQ_ZUM_MEGA_3D \
|| MOTHERBOARD == BOARD_MIGHTYBOARD_REVE \
|| MOTHERBOARD == BOARD_MINIRAMBO \
|| MOTHERBOARD == BOARD_SCOOVO_X9H)
#include "pinsDebug_Re_ARM.h"
#define PWM_PRINT(V) do{ sprintf_P(buffer, PSTR("PWM: %4d"), V); SERIAL_ECHO(buffer); }while(0)
#define PWM_CASE(N,Z) \
case TIMER##N##Z: \
if (TCCR##N##A & (_BV(COM##N##Z##1) | _BV(COM##N##Z##0))) { \
PWM_PRINT(OCR##N##Z); \
return true; \
} else return false
bool PWM_ok = true;
static void print_input_or_output(const bool isout) {
serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = "));
}
// pretty report with PWM info
inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = false, const char *start_string = "") {
uint8_t temp_char;
char *name_mem_pointer, buffer[30]; // for the sprintf statements
bool found = false, multi_name_pin = false;
for (uint8_t x = 0; x < COUNT(pin_array); x++) { // scan entire array and report all instances of this pin
if (GET_ARRAY_PIN(x) == pin) {
GET_PIN_INFO(pin);
if (found) multi_name_pin = true;
found = true;
if (!multi_name_pin) { // report digitial and analog pin number only on the first time through
sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin); // digital pin number
SERIAL_ECHO(buffer);
PRINT_PORT(pin);
if (IS_ANALOG(pin)) {
sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
SERIAL_ECHO(buffer);
}
else SERIAL_ECHO_SP(8); // add padding if not an analog pin
}
else {
SERIAL_CHAR('.');
SERIAL_ECHO_SP(26 + strlen(start_string)); // add padding if not the first instance found
}
PRINT_ARRAY_NAME(x);
if (extended) {
if (pin_is_protected(pin) && !ignore)
SERIAL_ECHOPGM("protected ");
else {
//SERIAL_PROTOCOLPAIR(" GET_ARRAY_IS_DIGITAL(x) 0 = analog : ", GET_ARRAY_IS_DIGITAL(x));
if (!GET_ARRAY_IS_DIGITAL(x)) {
sprintf_P(buffer, PSTR("Analog in = %5d"), analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
SERIAL_ECHO(buffer);
}
else {
//MYSERIAL.printf(" GET_PINMODE(pin) 1 = output : %d ", GET_PINMODE(pin));
if (!GET_PINMODE(pin)) {
//pinMode(pin, INPUT_PULLUP); // make sure input isn't floating - stopped doing this
// because this could interfere with inductive/capacitive
// sensors (high impedance voltage divider) and with PT100 amplifier
print_input_or_output(false);
SERIAL_PROTOCOL(digitalRead_mod(pin));
}
#if PWM_ok
else if (pwm_status(pin)) {
// do nothing
}
#endif
else {
print_input_or_output(true);
SERIAL_PROTOCOL(digitalRead_mod(pin));
}
}
#if PWM_ok
if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
#endif
}
}
SERIAL_EOL();
} // end of IF
} // end of for loop
if (!found) {
GET_PIN_INFO(pin);
sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin);
SERIAL_ECHO(buffer);
PRINT_PORT(pin);
if (IS_ANALOG(pin)) {
sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
SERIAL_ECHO(buffer);
}
else
SERIAL_ECHO_SP(8); // add padding if not an analog pin
SERIAL_ECHOPGM("<unused/unknown>");
if (extended) {
if (GET_PINMODE(pin)) {
SERIAL_PROTOCOL_SP(MAX_NAME_LENGTH - 16);
print_input_or_output(true);
SERIAL_PROTOCOL(digitalRead_mod(pin));
}
else {
if (IS_ANALOG(pin)) {
sprintf_P(buffer, PSTR(" Analog in = %5d"), analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
SERIAL_ECHO(buffer);
SERIAL_ECHOPGM(" ");
}
else
SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin
print_input_or_output(false);
SERIAL_PROTOCOL(digitalRead_mod(pin));
}
//if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
#if PWM_ok
if (extended) pwm_details(pin); // report PWM capabilities only if doing an extended report
#endif
}
SERIAL_EOL();
}
}

View File

@ -0,0 +1,71 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Test Re-ARM specific configuration values for errors at compile-time.
*/
/**
* Require gcc 4.7 or newer (first included with Arduino 1.6.8) for C++11 features.
*/
#if ENABLED(SPINDLE_LASER_ENABLE)
#if !PIN_EXISTS(SPINDLE_LASER_ENABLE)
#error "SPINDLE_LASER_ENABLE requires SPINDLE_LASER_ENABLE_PIN."
#elif SPINDLE_DIR_CHANGE && !PIN_EXISTS(SPINDLE_DIR)
#error "SPINDLE_DIR_PIN not defined."
#elif ENABLED(SPINDLE_LASER_PWM) && PIN_EXISTS(SPINDLE_LASER_PWM)
#if !PWM_PIN(SPINDLE_LASER_PWM_PIN)
#error "SPINDLE_LASER_PWM_PIN not assigned to a PWM pin."
#elif !(SPINDLE_LASER_PWM_PIN == 4 || SPINDLE_LASER_PWM_PIN == 6 || SPINDLE_LASER_PWM_PIN == 11)
#error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
#elif SPINDLE_LASER_POWERUP_DELAY < 1
#error "SPINDLE_LASER_POWERUP_DELAY must be greater than 0."
#elif SPINDLE_LASER_POWERDOWN_DELAY < 1
#error "SPINDLE_LASER_POWERDOWN_DELAY must be greater than 0."
#elif !defined(SPINDLE_LASER_PWM_INVERT)
#error "SPINDLE_LASER_PWM_INVERT missing."
#elif !defined(SPEED_POWER_SLOPE) || !defined(SPEED_POWER_INTERCEPT) || !defined(SPEED_POWER_MIN) || !defined(SPEED_POWER_MAX)
#error "SPINDLE_LASER_PWM equation constant(s) missing."
#elif PIN_EXISTS(CASE_LIGHT) && SPINDLE_LASER_PWM_PIN == CASE_LIGHT_PIN
#error "SPINDLE_LASER_PWM_PIN is used by CASE_LIGHT_PIN."
#elif PIN_EXISTS(E0_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E0_AUTO_FAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used by E0_AUTO_FAN_PIN."
#elif PIN_EXISTS(E1_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E1_AUTO_FAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used by E1_AUTO_FAN_PIN."
#elif PIN_EXISTS(E2_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E2_AUTO_FAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used by E2_AUTO_FAN_PIN."
#elif PIN_EXISTS(E3_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E3_AUTO_FAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used by E3_AUTO_FAN_PIN."
#elif PIN_EXISTS(E4_AUTO_FAN) && SPINDLE_LASER_PWM_PIN == E4_AUTO_FAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used by E4_AUTO_FAN_PIN."
#elif PIN_EXISTS(FAN) && SPINDLE_LASER_PWM_PIN == FAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used FAN_PIN."
#elif PIN_EXISTS(FAN1) && SPINDLE_LASER_PWM_PIN == FAN1_PIN
#error "SPINDLE_LASER_PWM_PIN is used FAN1_PIN."
#elif PIN_EXISTS(FAN2) && SPINDLE_LASER_PWM_PIN == FAN2_PIN
#error "SPINDLE_LASER_PWM_PIN is used FAN2_PIN."
#elif PIN_EXISTS(CONTROLLERFAN) && SPINDLE_LASER_PWM_PIN == CONTROLLERFAN_PIN
#error "SPINDLE_LASER_PWM_PIN is used by CONTROLLERFAN_PIN."
#endif
#endif
#endif // SPINDLE_LASER_ENABLE

View File

@ -22,8 +22,8 @@
#ifdef TARGET_LPC1768
#include <lpc17xx_pinsel.h>
#include "../../../macros.h"
#include "HAL.h"
#include "../../macros.h"
// Interrupts
void cli(void) { __disable_irq(); } // Disable

View File

@ -63,7 +63,6 @@ const adc_pin_data adc_pin_map[] = {
#define VALID_PIN(r) (r < 0 ? 0 :\
r == 7 ? 0 :\
r == 17 ? 0 :\
r == 17 ? 0 :\
r == 22 ? 0 :\
r == 23 ? 0 :\
r == 25 ? 0 :\
@ -82,6 +81,20 @@ const adc_pin_data adc_pin_map[] = {
r == 66 ? 0 :\
r >= NUM_DIGITAL_PINS ? 0 : 1)
#define PWM_PIN(r) (r < 0 ? 0 :\
r == 3 ? 1 :\
r == 4 ? 1 :\
r == 6 ? 1 :\
r == 9 ? 1 :\
r == 10 ? 1 :\
r == 11 ? 1 :\
r == 14 ? 1 :\
r == 26 ? 1 :\
r == 46 ? 1 :\
r == 53 ? 1 :\
r == 54 ? 1 :\
r == 60 ? 1 : 0)
const pin_data pin_map[] = { // pin map for variable pin function
{0,3}, // DIO0 RXD0 A6 J4-4 AUX-1
{0,2}, // DIO1 TXD0 A7 J4-5 AUX-1

View File

@ -27,7 +27,7 @@
struct pin_data { uint8_t port, pin; };
struct adc_pin_data { uint8_t port, pin, adc; };
#if ENABLED(IS_REARM)
#if defined(IS_REARM)
#include "pinmap_re_arm.h"
#else
#error "HAL: LPC1768: No defined pin-mapping"

View File

@ -1,5 +1,5 @@
/**
* Marlin 3D Printer Firmware
* Marlin 3D Printer Firmware
* Copyright (C) 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
@ -19,68 +19,60 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Support routines for Re-ARM board
*/
*/
bool pin_Re_ARM_output;
bool pin_Re_ARM_analog;
int8_t pin_Re_ARM_pin;
typedef struct {
int8_t pin;
bool output;
bool analog;
uint8_t resistors;
bool open_drain;
char function_string[15];
} pin_info;
pin_info pin_Re_ARM;
void get_pin_info(int8_t pin) {
pin_Re_ARM.analog = 0;
pin_Re_ARM.pin = pin;
if (pin == 7) return;
pin_Re_ARM_analog = 0;
pin_Re_ARM_pin = pin;
int8_t pin_port = pin_map[pin].port;
int8_t pin_port_pin = pin_map[pin].pin;
// active ADC function/mode/code values for PINSEL registers
int8_t ADC_pin_mode = pin_port == 0 && pin_port_pin == 2 ? 2 :
pin_port == 0 && pin_port_pin == 3 ? 2 :
pin_port == 0 && pin_port_pin == 23 ? 1 :
pin_port == 0 && pin_port_pin == 23 ? 1 :
pin_port == 0 && pin_port_pin == 24 ? 1 :
pin_port == 0 && pin_port_pin == 25 ? 1 :
pin_port == 0 && pin_port_pin == 26 ? 1 :
pin_port == 1 && pin_port_pin == 30 ? 3 :
pin_port == 1 && pin_port_pin == 31 ? 3 : -1;
//get appropriate PINSEL register
pin_port == 1 && pin_port_pin == 31 ? 3 : -1;
//get appropriate PINSEL register
volatile uint32_t * pinsel_reg = (pin_port == 0 && pin_port_pin <= 15) ? &LPC_PINCON->PINSEL0 :
(pin_port == 0) ? &LPC_PINCON->PINSEL1 :
(pin_port == 1 && pin_port_pin <= 15) ? &LPC_PINCON->PINSEL2 :
pin_port == 1 ? &LPC_PINCON->PINSEL3 :
pin_port == 2 ? &LPC_PINCON->PINSEL4 :
pin_port == 3 ? &LPC_PINCON->PINSEL7 : &LPC_PINCON->PINSEL9;
pin_port == 3 ? &LPC_PINCON->PINSEL7 : &LPC_PINCON->PINSEL9;
uint8_t pinsel_start_bit = pin_port_pin > 15 ? 2 * (pin_port_pin - 16) : 2 * pin_port_pin;
uint8_t pin_mode = (uint8_t) ((*pinsel_reg >> pinsel_start_bit) & 0x3);
uint32_t * FIO_reg[5] PROGMEM = {(uint32_t*) 0x2009C000,(uint32_t*) 0x2009C020,(uint32_t*) 0x2009C040,(uint32_t*) 0x2009C060,(uint32_t*) 0x2009C080};
pin_Re_ARM.output = (*FIO_reg[pin_map[pin].port] >> pin_map[pin].pin) & 1; //input/output state except if active ADC
pin_Re_ARM_output = (*FIO_reg[pin_map[pin].port] >> pin_map[pin].pin) & 1; //input/output state except if active ADC
if (pin_mode) { // if function/mode/code value not 0 then could be an active analog channel
if (ADC_pin_mode == pin_mode) { // found an active analog pin
pin_Re_ARM.output = 0;
pin_Re_ARM.analog = 1;
}
pin_Re_ARM_output = 0;
pin_Re_ARM_analog = 1;
}
}
}
/**
* translation of routines & variables used by pinsDebug.h
*/
#define pwm_details(pin) pin = pin // do nothing // print PWM details
#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
#define GET_PIN_INFO(pin) get_pin_info(pin)
#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
#define GET_PINMODE(pin) pin_Re_ARM.output
#define GET_PINMODE(pin) pin_Re_ARM_output
#define digitalRead_mod(p) digitalRead(p)
#define digitalPinToPort_DEBUG(p) 0
#define digitalPinToBitMask_DEBUG(pin) 0
@ -89,4 +81,4 @@ void get_pin_info(int8_t pin) {
#define NAME_FORMAT(p) PSTR("%-##p##s")
// #define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, NAME_FORMAT(MAX_NAME_LENGTH) , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
#define PRINT_ARRAY_NAME(x) do {sprintf_P(buffer, PSTR("%-35s") , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
#define GET_ARRAY_IS_DIGITAL(x) !pin_Re_ARM.analog
#define GET_ARRAY_IS_DIGITAL(x) !pin_Re_ARM_analog