Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Pins Debugging fix and cleanup #27494

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,5 @@ __pycache__
tags
*.logs
*.bak
.aider*
.env
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,8 @@
#define DISABLE_IDLE_E // Shut down all idle extruders

// Default Minimum Feedrates for printing and travel moves
#define DEFAULT_MINIMUMFEEDRATE 0.0 // (mm/s. °/s for rotational-only moves) Minimum feedrate. Set with M205 S.
#define DEFAULT_MINTRAVELFEEDRATE 0.0 // (mm/s. °/s for rotational-only moves) Minimum travel feedrate. Set with M205 T.
#define DEFAULT_MINIMUMFEEDRATE 0.0 // (mm/s) Minimum feedrate. Set with M205 S.
#define DEFAULT_MINTRAVELFEEDRATE 0.0 // (mm/s) Minimum travel feedrate. Set with M205 T.

// Minimum time that a segment needs to take as the buffer gets emptied
#define DEFAULT_MINSEGMENTTIME 20000 // (µs) Set with M205 B.
Expand Down
56 changes: 36 additions & 20 deletions Marlin/src/HAL/AVR/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@
#pragma once

/**
* PWM print routines for Atmel 8 bit AVR CPUs
* Pins Debugging for Atmel 8 bit AVR CPUs
*
* - NUMBER_PINS_TOTAL
* - MULTI_NAME_PAD
* - getPinByIndex(index)
* - printPinNameByIndex(index)
* - getPinIsDigitalByIndex(index)
* - digitalPinToAnalogIndex(pin)
* - getValidPinMode(pin)
* - isValidPin(pin)
* - isAnalogPin(pin)
* - digitalRead_mod(pin)
* - pwm_status(pin)
* - printPinPWM(pin)
* - printPinPort(pin)
* - printPinNumber(pin)
* - printPinAnalog(pin)
*/

#include "../../inc/MarlinConfig.h"
Expand All @@ -39,30 +55,30 @@
#include "pinsDebug_Teensyduino.h"
// Can't use the "digitalPinToPort" function from the Teensyduino type IDEs
// portModeRegister takes a different argument
#define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
#define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
#define getValidPinMode(pin) (*portModeRegister(pin) & digitalPinToBitMask_DEBUG(pin))
#define digitalPinToTimer_DEBUG(P) digitalPinToTimer(P)
#define digitalPinToBitMask_DEBUG(P) digitalPinToBitMask(P)
#define digitalPinToPort_DEBUG(P) digitalPinToPort(P)
#define getValidPinMode(P) (*portModeRegister(P) & digitalPinToBitMask_DEBUG(P))

#elif AVR_ATmega2560_FAMILY_PLUS_70 // So we can access/display all the pins on boards using more than 70

#include "pinsDebug_plus_70.h"
#define digitalPinToTimer_DEBUG(p) digitalPinToTimer_plus_70(p)
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask_plus_70(p)
#define digitalPinToPort_DEBUG(p) digitalPinToPort_plus_70(p)
#define digitalPinToTimer_DEBUG(P) digitalPinToTimer_plus_70(P)
#define digitalPinToBitMask_DEBUG(P) digitalPinToBitMask_plus_70(P)
#define digitalPinToPort_DEBUG(P) digitalPinToPort_plus_70(P)
bool getValidPinMode(pin_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }

#else

#define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
#define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
#define digitalPinToTimer_DEBUG(P) digitalPinToTimer(P)
#define digitalPinToBitMask_DEBUG(P) digitalPinToBitMask(P)
#define digitalPinToPort_DEBUG(P) digitalPinToPort(P)
bool getValidPinMode(pin_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
#define getPinByIndex(p) pgm_read_byte(&pin_array[p].pin)
#define getPinByIndex(x) pgm_read_byte(&pin_array[x].pin)

#endif

#define isValidPin(pin) (pin >= 0 && pin < NUM_DIGITAL_PINS ? 1 : 0)
#define isValidPin(P) (P >= 0 && P < NUMBER_PINS_TOTAL)
#if AVR_ATmega1284_FAMILY
#define isAnalogPin(P) WITHIN(P, analogInputToDigitalPin(7), analogInputToDigitalPin(0))
#define digitalPinToAnalogIndex(P) int(isAnalogPin(P) ? (P) - analogInputToDigitalPin(7) : -1)
Expand All @@ -72,11 +88,11 @@
#define isAnalogPin(P) (_ANALOG1(P) || _ANALOG2(P))
#define digitalPinToAnalogIndex(P) int(_ANALOG1(P) ? (P) - analogInputToDigitalPin(0) : _ANALOG2(P) ? (P) - analogInputToDigitalPin(8) + 8 : -1)
#endif
#define getPinByIndex(p) pgm_read_byte(&pin_array[p].pin)
#define getPinByIndex(x) pgm_read_byte(&pin_array[x].pin)
#define MULTI_NAME_PAD 26 // space needed to be pretty if not first name assigned to a pin

void printPinNameByIndex(uint8_t x) {
PGM_P const name_mem_pointer = (PGM_P)pgm_read_ptr(&pin_array[x].name);
void printPinNameByIndex(const uint8_t index) {
PGM_P const name_mem_pointer = (PGM_P)pgm_read_ptr(&pin_array[index].name);
for (uint8_t y = 0; y < MAX_NAME_LENGTH; ++y) {
char temp_char = pgm_read_byte(name_mem_pointer + y);
if (temp_char != 0)
Expand Down Expand Up @@ -109,7 +125,7 @@ void printPinNameByIndex(uint8_t x) {
* Print a pin's PWM status.
* Return true if it's currently a PWM pin.
*/
bool pwm_status(uint8_t pin) {
bool pwm_status(const uint8_t pin) {
char buffer[20]; // for the sprintf statements

switch (digitalPinToTimer_DEBUG(pin)) {
Expand Down Expand Up @@ -276,7 +292,7 @@ void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N -
if (TEST(*TMSK, TOIE)) err_prob_interrupt();
}

void printPinPWM(uint8_t pin) {
void printPinPWM(const uint8_t pin) {
switch (digitalPinToTimer_DEBUG(pin)) {

#if ABTEST(0)
Expand Down Expand Up @@ -386,7 +402,7 @@ void printPinPort(const pin_t pin) { // print port number
#endif
}

#define printPinNumber(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
#define printPinAnalog(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(pin)); SERIAL_ECHO(buffer); }while(0)
#define printPinNumber(P) do{ sprintf_P(buffer, PSTR("%3d "), P); SERIAL_ECHO(buffer); }while(0)
#define printPinAnalog(P) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(P)); SERIAL_ECHO(buffer); }while(0)

#undef ABTEST
2 changes: 1 addition & 1 deletion Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const uint8_t PROGMEM digital_pin_to_port_PGM[] = {

// digitalPinToBitMask(pin) is OK

#define digitalRead_mod(p) extDigitalRead(p) // Teensyduino's version of digitalRead doesn't
#define digitalRead_mod(P) extDigitalRead(P) // Teensyduino's version of digitalRead doesn't
// disable the PWMs so we can use it as is

// portModeRegister(pin) is OK
45 changes: 29 additions & 16 deletions Marlin/src/HAL/DUE/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

/**
* Support routines for Due
*/

/**
* Translation of routines & variables used by pinsDebug.h
* Pins Debugging for DUE
*
* - NUMBER_PINS_TOTAL
* - MULTI_NAME_PAD
* - getPinByIndex(index)
* - printPinNameByIndex(index)
* - getPinIsDigitalByIndex(index)
* - digitalPinToAnalogIndex(pin)
* - getValidPinMode(pin)
* - isValidPin(pin)
* - isAnalogPin(pin)
* - digitalRead_mod(pin)
* - pwm_status(pin)
* - printPinPWM(pin)
* - printPinPort(pin)
* - printPinNumber(pin)
* - printPinAnalog(pin)
*/

#include "../shared/Marduino.h"
Expand Down Expand Up @@ -63,20 +76,20 @@

#define NUMBER_PINS_TOTAL PINS_COUNT

#define digitalRead_mod(p) extDigitalRead(p) // AVR digitalRead disabled PWM before it read the pin
#define digitalRead_mod(P) extDigitalRead(P) // AVR digitalRead disabled PWM before it read the pin
#define printPinNameByIndex(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
#define printPinNumber(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
#define printPinAnalog(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(pin)); SERIAL_ECHO(buffer); }while(0)
#define getPinByIndex(p) pin_array[p].pin
#define getPinIsDigitalByIndex(p) pin_array[p].is_digital
#define isValidPin(pin) (pin >= 0 && pin < int8_t(NUMBER_PINS_TOTAL))
#define digitalPinToAnalogIndex(p) int(p - analogInputToDigitalPin(0))
#define printPinNumber(P) do{ sprintf_P(buffer, PSTR("%02d"), P); SERIAL_ECHO(buffer); }while(0)
#define printPinAnalog(P) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(P)); SERIAL_ECHO(buffer); }while(0)
#define getPinByIndex(x) pin_array[x].pin
#define getPinIsDigitalByIndex(x) pin_array[x].is_digital
#define isValidPin(P) (P >= 0 && P < pin_t(NUMBER_PINS_TOTAL))
#define digitalPinToAnalogIndex(P) int(P - analogInputToDigitalPin(0))
#define isAnalogPin(P) WITHIN(P, pin_t(analogInputToDigitalPin(0)), pin_t(analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
#define pwm_status(pin) (((g_pinStatus[pin] & 0xF) == PIN_STATUS_PWM) && \
((g_APinDescription[pin].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM))
#define pwm_status(P) (((g_pinStatus[P] & 0xF) == PIN_STATUS_PWM) && \
((g_APinDescription[P].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM))
#define MULTI_NAME_PAD 14 // space needed to be pretty if not first name assigned to a pin

bool getValidPinMode(int8_t pin) { // 1: output, 0: input
bool getValidPinMode(const pin_t pin) { // 1: output, 0: input
volatile Pio* port = g_APinDescription[pin].pPort;
uint32_t mask = g_APinDescription[pin].ulPin;
uint8_t pin_status = g_pinStatus[pin] & 0xF;
Expand All @@ -85,7 +98,7 @@ bool getValidPinMode(int8_t pin) { // 1: output, 0: input
|| pwm_status(pin));
}

void printPinPWM(int32_t pin) {
void printPinPWM(const int32_t pin) {
if (pwm_status(pin)) {
uint32_t chan = g_APinDescription[pin].ulPWMChannel;
SERIAL_ECHOPGM("PWM = ", PWM_INTERFACE->PWM_CH_NUM[chan].PWM_CDTY);
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/HAL/ESP32/fastio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
// Set pin as output
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT)

// TODO: Store set modes in an array and use those to get the mode
#define _IS_OUTPUT(IO) true
#define _IS_INPUT(IO) true

// Set pin as input with pullup mode
#define _PULLUP(IO, v) pinMode(IO, v ? INPUT_PULLUP : INPUT)

Expand Down Expand Up @@ -70,6 +74,9 @@
// Set pin as output and init
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)

#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
#define IS_INPUT(IO) _IS_INPUT(IO)

// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/HAL/ESP32/ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@

#ifdef ARDUINO_ARCH_ESP32

#include <WiFi.h>

#undef ENABLED
#undef DISABLED

#include "../../inc/MarlinConfigPre.h"

#if ALL(WIFISUPPORT, OTASUPPORT)

#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
Expand Down
71 changes: 71 additions & 0 deletions Marlin/src/HAL/ESP32/pinsDebug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2024 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once

#error "PINS_DEBUGGING is not yet supported for ESP32!"

/**
* Pins Debugging for ESP32
*
* - NUMBER_PINS_TOTAL
* - MULTI_NAME_PAD
* - getPinByIndex(index)
* - printPinNameByIndex(index)
* - getPinIsDigitalByIndex(index)
* - digitalPinToAnalogIndex(pin)
* - getValidPinMode(pin)
* - isValidPin(pin)
* - isAnalogPin(pin)
* - digitalRead_mod(pin)
* - pwm_status(pin)
* - printPinPWM(pin)
* - printPinPort(pin)
* - printPinNumber(pin)
* - printPinAnalog(pin)
*/

#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin

#define digitalRead_mod(P) extDigitalRead(P)
#define printPinNameByIndex(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
#define printPinNumber(P) do{ sprintf_P(buffer, PSTR("%02d"), P); SERIAL_ECHO(buffer); }while(0)
#define printPinAnalog(P) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(P)); SERIAL_ECHO(buffer); }while(0)
#define getPinByIndex(x) pin_array[x].pin
#define getPinIsDigitalByIndex(x) pin_array[x].is_digital
#define isValidPin(P) (P >= 0 && P < pin_t(NUMBER_PINS_TOTAL))
#define digitalPinToAnalogIndex(P) int(P - analogInputToDigitalPin(0))
#define isAnalogPin(P) WITHIN(P, pin_t(analogInputToDigitalPin(0)), pin_t(analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
bool pwm_status(const pin_t) { return false; }

void printPinPort(const pin_t) {}

static bool getValidPinMode(const pin_t pin) {
return isValidPin(pin) && !IS_INPUT(pin);
}

void printPinPWM(const int32_t pin) {
if (pwm_status(pin)) {
//uint32_t chan = g_APinDescription[pin].ulPWMChannel TODO when fast pwm is operative;
//SERIAL_ECHOPGM("PWM = ", duty);
}
}
Loading
Loading