Cleanup following Pins Debug update
This commit is contained in:
parent
c7a8f7970b
commit
d4ce839351
2 changed files with 65 additions and 87 deletions
|
@ -5317,25 +5317,17 @@ inline void gcode_M42() {
|
||||||
#include "pinsDebug.h"
|
#include "pinsDebug.h"
|
||||||
|
|
||||||
inline void toggle_pins() {
|
inline void toggle_pins() {
|
||||||
int pin, j, start = 0, I_flag = 0, end = NUM_DIGITAL_PINS - 1, wait = 500, repeat = 1;
|
int pin, j;
|
||||||
|
|
||||||
if (code_seen('R'))
|
bool I_flag = code_seen('I') ? code_value_bool() : false;
|
||||||
repeat = code_value_int();
|
|
||||||
|
|
||||||
if (code_seen('S'))
|
int repeat = code_seen('R') ? code_value_int() : 1,
|
||||||
start = code_value_int();
|
start = code_seen('S') ? code_value_int() : 0,
|
||||||
|
end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
|
||||||
if (code_seen('E'))
|
wait = code_seen('W') ? code_value_int() : 500;
|
||||||
end = code_value_int();
|
|
||||||
|
|
||||||
if (code_seen('I') )
|
|
||||||
I_flag++;
|
|
||||||
|
|
||||||
if (code_seen('W'))
|
|
||||||
wait = code_value_int();
|
|
||||||
|
|
||||||
for (pin = start; pin <= end; pin++) {
|
for (pin = start; pin <= end; pin++) {
|
||||||
if ( I_flag == 0 && pin_is_protected(pin)) {
|
if (!I_flag && pin_is_protected(pin)) {
|
||||||
SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
|
SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
|
||||||
SERIAL_ECHOPGM(" untouched.\n");
|
SERIAL_ECHOPGM(" untouched.\n");
|
||||||
}
|
}
|
||||||
|
@ -5344,22 +5336,17 @@ inline void gcode_M42() {
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
for(j = 0; j < repeat; j++) {
|
for(j = 0; j < repeat; j++) {
|
||||||
digitalWrite(pin, 0);
|
digitalWrite(pin, 0);
|
||||||
idle();
|
safe_delay(wait);
|
||||||
delay(wait);
|
|
||||||
digitalWrite(pin, 1);
|
digitalWrite(pin, 1);
|
||||||
idle();
|
safe_delay(wait);
|
||||||
delay(wait);
|
|
||||||
digitalWrite(pin, 0);
|
digitalWrite(pin, 0);
|
||||||
idle();
|
safe_delay(wait);
|
||||||
delay(wait);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SERIAL_ECHOPGM("\n");
|
SERIAL_ECHOPGM("\n");
|
||||||
}
|
}
|
||||||
SERIAL_ECHOPGM("Done\n");
|
SERIAL_ECHOPGM("Done\n");
|
||||||
return;
|
} // toggle_pins
|
||||||
} // toggle pin(s)
|
|
||||||
|
|
||||||
|
|
||||||
inline void servo_probe_test(){
|
inline void servo_probe_test(){
|
||||||
#if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
|
#if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
|
||||||
|
@ -5505,10 +5492,10 @@ inline void gcode_M42() {
|
||||||
if (first_pin > NUM_DIGITAL_PINS - 1) return;
|
if (first_pin > NUM_DIGITAL_PINS - 1) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ignore_protection = code_seen('I');
|
bool ignore_protection = code_seen('I') ? code_value_bool() : false;
|
||||||
|
|
||||||
// Watch until click, M108, or reset
|
// Watch until click, M108, or reset
|
||||||
if (code_seen('W')) { // watch digital pins
|
if (code_seen('W') && code_value_bool()) { // watch digital pins
|
||||||
SERIAL_PROTOCOLLNPGM("Watching pins");
|
SERIAL_PROTOCOLLNPGM("Watching pins");
|
||||||
byte pin_state[last_pin - first_pin + 1];
|
byte pin_state[last_pin - first_pin + 1];
|
||||||
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
for (int8_t pin = first_pin; pin <= last_pin; pin++) {
|
||||||
|
|
|
@ -109,7 +109,8 @@ const char* const pin_array[][3] PROGMEM = {
|
||||||
|
|
||||||
#define n_array (sizeof (pin_array) / sizeof (const char *))/3
|
#define n_array (sizeof (pin_array) / sizeof (const char *))/3
|
||||||
|
|
||||||
#if !defined(TIMER1B) // working with Teensyduino extension so need to re-define some things
|
#ifndef TIMER1B
|
||||||
|
// working with Teensyduino extension so need to re-define some things
|
||||||
#include "pinsDebug_Teensyduino.h"
|
#include "pinsDebug_Teensyduino.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ static bool pwm_status(uint8_t pin) {
|
||||||
switch(digitalPinToTimer(pin)) {
|
switch(digitalPinToTimer(pin)) {
|
||||||
|
|
||||||
#if defined(TCCR0A) && defined(COM0A1)
|
#if defined(TCCR0A) && defined(COM0A1)
|
||||||
#if defined (TIMER0A)
|
#ifdef TIMER0A
|
||||||
PWM_CASE(0,A);
|
PWM_CASE(0,A);
|
||||||
#endif
|
#endif
|
||||||
PWM_CASE(0,B);
|
PWM_CASE(0,B);
|
||||||
|
@ -200,7 +201,7 @@ const uint8_t* const PWM_other[][3] PROGMEM = {
|
||||||
|
|
||||||
const uint8_t* const PWM_OCR[][3] PROGMEM = {
|
const uint8_t* const PWM_OCR[][3] PROGMEM = {
|
||||||
|
|
||||||
#if defined (TIMER0A)
|
#ifdef TIMER0A
|
||||||
{&OCR0A,&OCR0B,0},
|
{&OCR0A,&OCR0B,0},
|
||||||
#else
|
#else
|
||||||
{0,&OCR0B,0},
|
{0,&OCR0B,0},
|
||||||
|
@ -217,7 +218,7 @@ const uint8_t* const PWM_OCR[][3] PROGMEM = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(TCCR3A) && defined(COM3A1)
|
#if defined(TCCR3A) && defined(COM3A1)
|
||||||
#if defined(COM3C1)
|
#ifdef COM3C1
|
||||||
{ (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B, (const uint8_t*) &OCR3C},
|
{ (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B, (const uint8_t*) &OCR3C},
|
||||||
#else
|
#else
|
||||||
{ (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B,0},
|
{ (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B,0},
|
||||||
|
@ -323,18 +324,15 @@ void timer_prefix(uint8_t T, char L, uint8_t N){ // T - timer L - pwm n - W
|
||||||
if (TEST(*TMSK, TOIE)) err_prob_interrupt();
|
if (TEST(*TMSK, TOIE)) err_prob_interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void pwm_details(uint8_t pin) {
|
static void pwm_details(uint8_t pin) {
|
||||||
char buffer[20]; // for the sprintf statements
|
char buffer[20]; // for the sprintf statements
|
||||||
uint8_t WGM;
|
uint8_t WGM;
|
||||||
|
|
||||||
switch(digitalPinToTimer(pin)) {
|
switch(digitalPinToTimer(pin)) {
|
||||||
|
|
||||||
|
|
||||||
#if defined(TCCR0A) && defined(COM0A1)
|
#if defined(TCCR0A) && defined(COM0A1)
|
||||||
|
|
||||||
#if defined (TIMER0A)
|
#ifdef TIMER0A
|
||||||
case TIMER0A:
|
case TIMER0A:
|
||||||
timer_prefix(0,'A',3);
|
timer_prefix(0,'A',3);
|
||||||
break;
|
break;
|
||||||
|
@ -374,7 +372,7 @@ static void pwm_details(uint8_t pin) {
|
||||||
case TIMER3B:
|
case TIMER3B:
|
||||||
timer_prefix(3,'B',4);
|
timer_prefix(3,'B',4);
|
||||||
break;
|
break;
|
||||||
#if defined(COM3C1)
|
#ifdef COM3C1
|
||||||
case TIMER3C:
|
case TIMER3C:
|
||||||
timer_prefix(3,'C',4);
|
timer_prefix(3,'C',4);
|
||||||
break;
|
break;
|
||||||
|
@ -414,13 +412,11 @@ static void pwm_details(uint8_t pin) {
|
||||||
#if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
|
#if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
|
||||||
// looking for port B7 - PWMs 0A and 1C
|
// looking for port B7 - PWMs 0A and 1C
|
||||||
if ( ('B' == digitalPinToPort(pin) + 64) && (0x80 == digitalPinToBitMask(pin))) {
|
if ( ('B' == digitalPinToPort(pin) + 64) && (0x80 == digitalPinToBitMask(pin))) {
|
||||||
#if !defined(TEENSYDUINO_IDE)
|
#ifndef TEENSYDUINO_IDE
|
||||||
SERIAL_EOL;
|
SERIAL_PROTOCOLPGM("\n . TIMER1C is also tied to this pin ");
|
||||||
SERIAL_PROTOCOLPGM (" . TIMER1C is also tied to this pin ");
|
|
||||||
timer_prefix(1,'C',4);
|
timer_prefix(1,'C',4);
|
||||||
#else
|
#else
|
||||||
SERIAL_EOL;
|
SERIAL_PROTOCOLPGM("\n . TIMER0A is also tied to this pin ");
|
||||||
SERIAL_PROTOCOLPGM (" . TIMER0A is also tied to this pin ");
|
|
||||||
timer_prefix(0,'A',3);
|
timer_prefix(0,'A',3);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -429,7 +425,7 @@ static void pwm_details(uint8_t pin) {
|
||||||
|
|
||||||
bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) & digitalPinToBitMask(pin); }
|
bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) & digitalPinToBitMask(pin); }
|
||||||
|
|
||||||
#if !defined(digitalRead_mod) // use Teensyduino's version of digitalRead - it doesn't disable the PWMs
|
#ifndef digitalRead_mod // use Teensyduino's version of digitalRead - it doesn't disable the PWMs
|
||||||
int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
|
int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
|
||||||
uint8_t port = digitalPinToPort(pin);
|
uint8_t port = digitalPinToPort(pin);
|
||||||
return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
|
return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
|
||||||
|
@ -437,33 +433,30 @@ bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) &
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void print_port(int8_t pin) { // print port number
|
void print_port(int8_t pin) { // print port number
|
||||||
#if defined(digitalPinToPort)
|
#ifdef digitalPinToPort
|
||||||
SERIAL_PROTOCOLPGM(" Port: ");
|
SERIAL_PROTOCOLPGM(" Port: ");
|
||||||
uint8_t x = digitalPinToPort(pin) + 64;
|
uint8_t x = digitalPinToPort(pin) + 64;
|
||||||
SERIAL_CHAR(x);
|
SERIAL_CHAR(x);
|
||||||
uint8_t temp = digitalPinToBitMask(pin);
|
uint8_t temp = digitalPinToBitMask(pin);
|
||||||
for (x = '0'; (x < '9' && !(temp == 1)); x++){
|
for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
|
||||||
temp = temp >> 1;
|
|
||||||
}
|
|
||||||
SERIAL_CHAR(x);
|
SERIAL_CHAR(x);
|
||||||
#else
|
#else
|
||||||
SERIAL_PROTOCOLPGM(" ")
|
SERIAL_PROTOCOLPGM(" ");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// pretty report with PWM info
|
// pretty report with PWM info
|
||||||
inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = true) {
|
inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = true) {
|
||||||
uint8_t temp_char;
|
uint8_t temp_char;
|
||||||
char *name_mem_pointer;
|
char *name_mem_pointer;
|
||||||
char buffer[30]; // for the sprintf statements
|
char buffer[30]; // for the sprintf statements
|
||||||
bool found = false;
|
bool found = false,
|
||||||
bool multi_name_pin = false;
|
multi_name_pin = false;
|
||||||
for (uint8_t x = 0; x < n_array; x++) { // scan entire array and report all instances of this pin
|
for (uint8_t x = 0; x < n_array; x++) { // scan entire array and report all instances of this pin
|
||||||
if (pgm_read_byte(&pin_array[x][1]) == pin) {
|
if (pgm_read_byte(&pin_array[x][1]) == pin) {
|
||||||
if (found == true) multi_name_pin = true;
|
if (found) multi_name_pin = true;
|
||||||
found = true;
|
found = true;
|
||||||
if (multi_name_pin == false) { // report digitial and analog pin number only on the first time through
|
if (!multi_name_pin) { // report digitial and analog pin number only on the first time through
|
||||||
sprintf(buffer, "PIN: %3d ", pin); // digital pin number
|
sprintf(buffer, "PIN: %3d ", pin); // digital pin number
|
||||||
SERIAL_ECHO(buffer);
|
SERIAL_ECHO(buffer);
|
||||||
print_port(pin);
|
print_port(pin);
|
||||||
|
@ -479,7 +472,7 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
|
||||||
temp_char = pgm_read_byte(name_mem_pointer + y);
|
temp_char = pgm_read_byte(name_mem_pointer + y);
|
||||||
if (temp_char != 0) MYSERIAL.write(temp_char);
|
if (temp_char != 0) MYSERIAL.write(temp_char);
|
||||||
else {
|
else {
|
||||||
for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(" ");
|
for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(' ');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,13 +495,13 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
|
||||||
}
|
}
|
||||||
else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
|
else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
|
||||||
}
|
}
|
||||||
if (multi_name_pin == false && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
|
if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
|
||||||
}
|
}
|
||||||
SERIAL_EOL;
|
SERIAL_EOL;
|
||||||
} // end of IF
|
} // end of IF
|
||||||
} // end of for loop
|
} // end of for loop
|
||||||
|
|
||||||
if (found == false) {
|
if (!found) {
|
||||||
sprintf(buffer, "PIN: %3d ", pin);
|
sprintf(buffer, "PIN: %3d ", pin);
|
||||||
SERIAL_ECHO(buffer);
|
SERIAL_ECHO(buffer);
|
||||||
print_port(pin);
|
print_port(pin);
|
||||||
|
@ -516,29 +509,27 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
|
||||||
sprintf(buffer, " (A%2d) ", int(pin - analogInputToDigitalPin(0))); // analog pin number
|
sprintf(buffer, " (A%2d) ", int(pin - analogInputToDigitalPin(0))); // analog pin number
|
||||||
SERIAL_ECHO(buffer);
|
SERIAL_ECHO(buffer);
|
||||||
}
|
}
|
||||||
else SERIAL_ECHOPGM(" "); // add padding if not an analog pin
|
else
|
||||||
|
SERIAL_ECHOPGM(" "); // add padding if not an analog pin
|
||||||
SERIAL_ECHOPGM("<unused/unknown>");
|
SERIAL_ECHOPGM("<unused/unknown>");
|
||||||
if (get_pinMode(pin)) {
|
if (get_pinMode(pin))
|
||||||
SERIAL_PROTOCOLPAIR(" Output = ", digitalRead_mod(pin));
|
SERIAL_PROTOCOLPAIR(" Output = ", digitalRead_mod(pin));
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (IS_ANALOG(pin)) {
|
if (IS_ANALOG(pin)) {
|
||||||
sprintf(buffer, " Analog in = %5d", analogRead(pin - analogInputToDigitalPin(0)));
|
sprintf(buffer, " Analog in = %5d", analogRead(pin - analogInputToDigitalPin(0)));
|
||||||
SERIAL_ECHO(buffer);
|
SERIAL_ECHO(buffer);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
SERIAL_ECHOPGM(" "); // add padding if not an analog pin
|
SERIAL_ECHOPGM(" "); // add padding if not an analog pin
|
||||||
}
|
|
||||||
SERIAL_PROTOCOLPAIR(" Input = ", digitalRead_mod(pin));
|
SERIAL_PROTOCOLPAIR(" Input = ", digitalRead_mod(pin));
|
||||||
}
|
}
|
||||||
// if (!pwm_status(pin)) SERIAL_ECHOPGM(" "); // add padding if it's not a PWM pin
|
//if (!pwm_status(pin)) SERIAL_ECHOCHAR(' '); // add padding if it's not a PWM pin
|
||||||
if (extended) pwm_details(pin); // report PWM capabilities only if doing an extended report
|
if (extended) pwm_details(pin); // report PWM capabilities only if doing an extended report
|
||||||
SERIAL_EOL;
|
SERIAL_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void report_pin_state(int8_t pin) {
|
inline void report_pin_state(int8_t pin) {
|
||||||
|
|
||||||
report_pin_state_extended(pin, false, false);
|
report_pin_state_extended(pin, false, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue