Fix M43 on LPC176x (#13587)

The real fix. PR #13568 was wrong.
This commit is contained in:
Bob Kuhn 2019-04-06 18:06:07 -05:00 committed by Scott Lahteine
parent 9cee81d47e
commit 9a56d90150
4 changed files with 23 additions and 12 deletions

View file

@ -52,11 +52,13 @@ int freeMemory() {
return result;
}
// scan command line for code
// return index into pin map array if found and the pin is valid.
// return dval if not found or not a valid pin.
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval) {
const uint16_t val = (uint16_t)parser.intval(code), port = val / 100, pin = val % 100;
const int16_t ind = (port < (NUM_DIGITAL_PINS >> 5) && (pin < 32))
? GET_PIN_MAP_INDEX(port << 5 | pin) : -2;
return ind > -2 ? ind : dval;
const uint16_t val = (uint16_t)parser.intval(code, -1), port = val / 100, pin = val % 100;
const int16_t ind = (port < ((NUM_DIGITAL_PINS) >> 5) && pin < 32) ? GET_PIN_MAP_INDEX((port << 5) | pin) : -2;
return ind > -1 ? ind : dval;
}
void flashFirmware(int16_t value) {

View file

@ -40,6 +40,12 @@
#define PRINT_PIN(p) do {sprintf_P(buffer, PSTR("%d.%02d"), LPC1768_PIN_PORT(p), LPC1768_PIN_PIN(p)); SERIAL_ECHO(buffer);} while (0)
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
// pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
// uses pin index
#ifndef M43_NEVER_TOUCH
#define M43_NEVER_TOUCH(Q) ((Q) == 29 || (Q) == 30 || (Q) == 73) // USB pins
#endif
// active ADC function/mode/code values for PINSEL registers
constexpr int8_t ADC_pin_mode(pin_t pin) {
return (LPC1768_PIN_PORT(pin) == 0 && LPC1768_PIN_PIN(pin) == 2 ? 2 :

View file

@ -47,13 +47,13 @@ inline void toggle_pins() {
for (uint8_t i = start; i <= end; i++) {
pin_t pin = GET_PIN_MAP_PIN(i);
//report_pin_state_extended(pin, ignore_protection, false);
if (!VALID_PIN(pin)) continue;
if (!ignore_protection && pin_is_protected(pin)) {
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) {
report_pin_state_extended(pin, ignore_protection, true, "Untouched ");
SERIAL_EOL();
}
else {
watchdog_reset();
report_pin_state_extended(pin, ignore_protection, true, "Pulsing ");
#if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
if (pin == TEENSY_E2) {
@ -77,12 +77,12 @@ inline void toggle_pins() {
{
pinMode(pin, OUTPUT);
for (int16_t j = 0; j < repeat; j++) {
extDigitalWrite(pin, 0); safe_delay(wait);
extDigitalWrite(pin, 1); safe_delay(wait);
extDigitalWrite(pin, 0); safe_delay(wait);
watchdog_reset(); extDigitalWrite(pin, 0); safe_delay(wait);
watchdog_reset(); extDigitalWrite(pin, 1); safe_delay(wait);
watchdog_reset(); extDigitalWrite(pin, 0); safe_delay(wait);
watchdog_reset();
}
}
}
SERIAL_EOL();
}
@ -277,7 +277,7 @@ void GcodeSuite::M43() {
for (uint8_t i = first_pin; i <= last_pin; i++) {
pin_t pin = GET_PIN_MAP_PIN(i);
if (!VALID_PIN(pin)) continue;
if (!ignore_protection && pin_is_protected(pin)) continue;
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
pinMode(pin, INPUT_PULLUP);
delay(1);
/*
@ -300,7 +300,7 @@ void GcodeSuite::M43() {
for (uint8_t i = first_pin; i <= last_pin; i++) {
pin_t pin = GET_PIN_MAP_PIN(i);
if (!VALID_PIN(pin)) continue;
if (!ignore_protection && pin_is_protected(pin)) continue;
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
const byte val =
/*
IS_ANALOG(pin)

View file

@ -102,6 +102,9 @@ const PinInfo pin_array[] PROGMEM = {
#include HAL_PATH(../HAL, pinsDebug.h) // get the correct support file for this CPU
#ifndef M43_NEVER_TOUCH
#define M43_NEVER_TOUCH(Q) false
#endif
static void print_input_or_output(const bool isout) {
serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = "));