🐛 Fix STM32 Pins Debugging (#22896)

This commit is contained in:
ellensp 2022-04-21 21:06:22 +12:00 committed by Scott Lahteine
parent 7ffe4de021
commit 4fd7d1b056
5 changed files with 40 additions and 30 deletions

View file

@ -86,7 +86,6 @@ bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
|| pwm_status(pin));
}
void pwm_details(int32_t pin) {
if (pwm_status(pin)) {
uint32_t chan = g_APinDescription[pin].ulPWMChannel;

View file

@ -79,7 +79,6 @@
// make a list of the Arduino pin numbers in the Port/Pin order
//
#define _PIN_ADD_2(NAME_ALPHA, ARDUINO_NUM) { {NAME_ALPHA}, ARDUINO_NUM },
#define _PIN_ADD(NAME_ALPHA, ARDUINO_NUM) { NAME_ALPHA, ARDUINO_NUM },
#define PIN_ADD(NAME) _PIN_ADD(#NAME, NAME)
@ -108,7 +107,11 @@ const XrefInfo pin_xref[] PROGMEM = {
/**
* Translation of routines & variables used by pinsDebug.h
*/
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
#if PA0 >= NUM_DIGITAL_PINS
#define HAS_HIGH_ANALOG_PINS 1
#endif
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS + TERN0(HAS_HIGH_ANALOG_PINS, NUM_ANALOG_INPUTS)
#define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
#define digitalRead_mod(Ard_num) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
#define PRINT_PIN(Q)
@ -164,17 +167,20 @@ bool GET_PINMODE(const pin_t Ard_num) {
return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT; // assume all alt definitions are PWM
}
int8_t digital_pin_to_analog_pin(pin_t Ard_num) {
Ard_num -= NUM_ANALOG_FIRST;
return (Ard_num >= 0 && Ard_num < NUM_ANALOG_INPUTS) ? Ard_num : -1;
int8_t digital_pin_to_analog_pin(const pin_t Ard_num) {
if (WITHIN(Ard_num, NUM_ANALOG_FIRST, NUM_ANALOG_FIRST + NUM_ANALOG_INPUTS - 1))
return Ard_num - NUM_ANALOG_FIRST;
const uint32_t ind = digitalPinToAnalogInput(Ard_num);
return (ind < NUM_ANALOG_INPUTS) ? ind : -1;
}
bool IS_ANALOG(const pin_t Ard_num) {
return get_pin_mode(Ard_num) == MODE_PIN_ANALOG;
}
bool is_digital(const pin_t x) {
const uint8_t pin_mode = get_pin_mode(pin_array[x].pin);
bool is_digital(const pin_t Ard_num) {
const uint8_t pin_mode = get_pin_mode(pin_array[Ard_num].pin);
return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT;
}
@ -200,10 +206,15 @@ void port_print(const pin_t Ard_num) {
SERIAL_ECHO_SP(7);
// Print number to be used with M42
sprintf_P(buffer, PSTR(" M42 P%d "), Ard_num);
SERIAL_ECHO(buffer);
if (Ard_num < 10) SERIAL_CHAR(' ');
if (Ard_num < 100) SERIAL_CHAR(' ');
int calc_p = Ard_num % (NUM_DIGITAL_PINS + 1);
if (Ard_num > NUM_DIGITAL_PINS && calc_p > 7) calc_p += 8;
SERIAL_ECHOPGM(" M42 P", calc_p);
SERIAL_CHAR(' ');
if (calc_p < 100) {
SERIAL_CHAR(' ');
if (calc_p < 10)
SERIAL_CHAR(' ');
}
}
bool pwm_status(const pin_t Ard_num) {

View file

@ -313,7 +313,7 @@ void GcodeSuite::M43() {
// 'P' Get the range of pins to test or watch
uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
last_pin = parser.seenval('P') ? first_pin : TERN(HAS_HIGH_ANALOG_PINS, NUM_DIGITAL_PINS, NUMBER_PINS_TOTAL) - 1;
if (first_pin > last_pin) return;

View file

@ -141,10 +141,10 @@ extern "C" {
#define PG15 111 //D79
// This must be a literal with the same value as PEND
#define NUM_DIGITAL_PINS 125
#define NUM_DIGITAL_PINS 112
// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
#define NUM_ANALOG_INPUTS 13
#define NUM_ANALOG_FIRST 112
#define NUM_ANALOG_FIRST NUM_DIGITAL_PINS
//#define ADC_RESOLUTION 12

View file

@ -141,10 +141,10 @@ extern "C" {
#define PG15 111 //D79
// This must be a literal with the same value as PEND
#define NUM_DIGITAL_PINS 125
#define NUM_DIGITAL_PINS 112
// This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
#define NUM_ANALOG_INPUTS 13
#define NUM_ANALOG_FIRST 112
#define NUM_ANALOG_FIRST NUM_DIGITAL_PINS
//#define ADC_RESOLUTION 12