Skip to content

Commit 4e1bfc4

Browse files
committed
🎨 Misc. tweaks to HALs
1 parent 5859ff0 commit 4e1bfc4

File tree

14 files changed

+101
-119
lines changed

14 files changed

+101
-119
lines changed

Marlin/src/HAL/AVR/pinsDebug.h

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void PRINT_ARRAY_NAME(uint8_t x) {
109109
* Print a pin's PWM status.
110110
* Return true if it's currently a PWM pin.
111111
*/
112-
static bool pwm_status(uint8_t pin) {
112+
bool pwm_status(uint8_t pin) {
113113
char buffer[20]; // for the sprintf statements
114114

115115
switch (digitalPinToTimer_DEBUG(pin)) {
@@ -232,12 +232,12 @@ const volatile uint8_t* const PWM_OCR[][3] PROGMEM = {
232232

233233
#define OCR_VAL(T, L) pgm_read_word(&PWM_OCR[T][L])
234234

235-
static void err_is_counter() { SERIAL_ECHOPGM(" non-standard PWM mode"); }
236-
static void err_is_interrupt() { SERIAL_ECHOPGM(" compare interrupt enabled"); }
237-
static void err_prob_interrupt() { SERIAL_ECHOPGM(" overflow interrupt enabled"); }
238-
static void print_is_also_tied() { SERIAL_ECHOPGM(" is also tied to this pin"); SERIAL_ECHO_SP(14); }
235+
void err_is_counter() { SERIAL_ECHOPGM(" non-standard PWM mode"); }
236+
void err_is_interrupt() { SERIAL_ECHOPGM(" compare interrupt enabled"); }
237+
void err_prob_interrupt() { SERIAL_ECHOPGM(" overflow interrupt enabled"); }
238+
void print_is_also_tied() { SERIAL_ECHOPGM(" is also tied to this pin"); SERIAL_ECHO_SP(14); }
239239

240-
inline void com_print(const uint8_t N, const uint8_t Z) {
240+
void com_print(const uint8_t N, const uint8_t Z) {
241241
const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
242242
SERIAL_ECHOPGM(" COM", AS_DIGIT(N));
243243
SERIAL_CHAR(Z);
@@ -279,7 +279,7 @@ void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N -
279279
if (TEST(*TMSK, TOIE)) err_prob_interrupt();
280280
}
281281

282-
static void pwm_details(uint8_t pin) {
282+
void pwm_details(uint8_t pin) {
283283
switch (digitalPinToTimer_DEBUG(pin)) {
284284

285285
#if ABTEST(0)
@@ -353,47 +353,41 @@ static void pwm_details(uint8_t pin) {
353353
} // pwm_details
354354

355355
#ifndef digitalRead_mod // Use Teensyduino's version of digitalRead - it doesn't disable the PWMs
356-
int digitalRead_mod(const int8_t pin) { // same as digitalRead except the PWM stop section has been removed
356+
int digitalRead_mod(const pin_t pin) { // same as digitalRead except the PWM stop section has been removed
357357
const uint8_t port = digitalPinToPort_DEBUG(pin);
358358
return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask_DEBUG(pin)) ? HIGH : LOW;
359359
}
360360
#endif
361361

362-
#ifndef PRINT_PORT
363-
364-
void print_port(int8_t pin) { // print port number
365-
#ifdef digitalPinToPort_DEBUG
366-
uint8_t x;
367-
SERIAL_ECHOPGM(" Port: ");
368-
#if AVR_AT90USB1286_FAMILY
369-
x = (pin == 46 || pin == 47) ? 'E' : digitalPinToPort_DEBUG(pin) + 64;
370-
#else
371-
x = digitalPinToPort_DEBUG(pin) + 64;
372-
#endif
373-
SERIAL_CHAR(x);
374-
375-
#if AVR_AT90USB1286_FAMILY
376-
if (pin == 46)
377-
x = '2';
378-
else if (pin == 47)
379-
x = '3';
380-
else {
381-
uint8_t temp = digitalPinToBitMask_DEBUG(pin);
382-
for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
383-
}
384-
#else
362+
void print_port(const pin_t pin) { // print port number
363+
#ifdef digitalPinToPort_DEBUG
364+
uint8_t x;
365+
SERIAL_ECHOPGM(" Port: ");
366+
#if AVR_AT90USB1286_FAMILY
367+
x = (pin == 46 || pin == 47) ? 'E' : digitalPinToPort_DEBUG(pin) + 64;
368+
#else
369+
x = digitalPinToPort_DEBUG(pin) + 64;
370+
#endif
371+
SERIAL_CHAR(x);
372+
373+
#if AVR_AT90USB1286_FAMILY
374+
if (pin == 46)
375+
x = '2';
376+
else if (pin == 47)
377+
x = '3';
378+
else {
385379
uint8_t temp = digitalPinToBitMask_DEBUG(pin);
386380
for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
387-
#endif
388-
SERIAL_CHAR(x);
381+
}
389382
#else
390-
SERIAL_ECHO_SP(10);
383+
uint8_t temp = digitalPinToBitMask_DEBUG(pin);
384+
for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
391385
#endif
392-
}
393-
394-
#define PRINT_PORT(p) print_port(p)
395-
396-
#endif
386+
SERIAL_CHAR(x);
387+
#else
388+
SERIAL_ECHO_SP(10);
389+
#endif
390+
}
397391

398392
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
399393
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)

Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
#pragma once
2323

2424
//
25-
// some of the pin mapping functions of the Teensduino extension to the Arduino IDE
26-
// do not function the same as the other Arduino extensions
25+
// Some of the pin mapping functions of the Arduino IDE Teensduino extension
26+
// function differently from other Arduino extensions.
2727
//
2828

29-
3029
#define TEENSYDUINO_IDE
3130

3231
//digitalPinToTimer(pin) function works like Arduino but Timers are not defined
@@ -48,8 +47,6 @@
4847
#define PE 5
4948
#define PF 6
5049

51-
#undef digitalPinToPort
52-
5350
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
5451
PD, // 0 - PD0 - INT0 - PWM
5552
PD, // 1 - PD1 - INT1 - PWM
@@ -101,7 +98,7 @@ const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
10198
PE, // 47 - PE3 (not defined in teensyduino)
10299
};
103100

104-
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
101+
#define digitalPinToPort(P) pgm_read_byte(digital_pin_to_port_PGM[P])
105102

106103
// digitalPinToBitMask(pin) is OK
107104

Marlin/src/HAL/DUE/pinsDebug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#define NUMBER_PINS_TOTAL PINS_COUNT
6565

6666
#define digitalRead_mod(p) extDigitalRead(p) // AVR digitalRead disabled PWM before it read the pin
67-
#define PRINT_PORT(p)
6867
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
6968
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
7069
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
@@ -93,6 +92,8 @@ void pwm_details(int32_t pin) {
9392
}
9493
}
9594

95+
void print_port(const pin_t) {}
96+
9697
/**
9798
* DUE Board pin | PORT | Label
9899
* ----------------+--------+-------

Marlin/src/HAL/LINUX/HAL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ uint8_t MarlinHAL::active_ch = 0;
5252
uint16_t MarlinHAL::adc_value() {
5353
const pin_t pin = analogInputToDigitalPin(active_ch);
5454
if (!VALID_PIN(pin)) return 0;
55-
const uint16_t data = ((Gpio::get(pin) >> 2) & 0x3FF);
56-
return data; // return 10bit value as Marlin expects
55+
return uint16_t((Gpio::get(pin) >> 2) & 0x3FF); // return 10bit value as Marlin expects
5756
}
5857

5958
void MarlinHAL::reboot() { /* Reset the application state and GPIO */ }

Marlin/src/HAL/LINUX/pinsDebug.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,33 @@
2828
* Translation of routines & variables used by pinsDebug.h
2929
*/
3030

31-
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
32-
#define pwm_details(pin) NOOP // (do nothing)
33-
#define pwm_status(pin) false // Print a pin's PWM status. Return true if it's currently a PWM pin.
31+
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
3432
#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
3533
#define digitalRead_mod(p) digitalRead(p)
36-
#define PRINT_PORT(p)
3734
#define GET_ARRAY_PIN(p) pin_array[p].pin
3835
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
3936
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
4037
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
41-
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
38+
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
4239

4340
// active ADC function/mode/code values for PINSEL registers
44-
constexpr int8_t ADC_pin_mode(pin_t pin) {
45-
return (-1);
46-
}
41+
constexpr int8_t ADC_pin_mode(pin_t pin) { return -1; }
4742

48-
int8_t get_pin_mode(pin_t pin) {
49-
if (!VALID_PIN(pin)) return -1;
50-
return 0;
51-
}
43+
int8_t get_pin_mode(const pin_t pin) { return VALID_PIN(pin) ? 0 : -1; }
5244

53-
bool GET_PINMODE(pin_t pin) {
54-
int8_t pin_mode = get_pin_mode(pin);
55-
if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
45+
bool GET_PINMODE(const pin_t pin) {
46+
const int8_t pin_mode = get_pin_mode(pin);
47+
if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // Invalid pin or active analog pin
5648
return false;
5749

58-
return (Gpio::getMode(pin) != 0); //input/output state
50+
return (Gpio::getMode(pin) != 0); // Input/output state
5951
}
6052

61-
bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
53+
bool GET_ARRAY_IS_DIGITAL(const pin_t pin) {
6254
return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
6355
}
56+
57+
void pwm_details(const pin_t pin) {}
58+
bool pwm_status(const pin_t) { return false; }
59+
60+
void print_port(const pin_t) {}

Marlin/src/HAL/LPC1768/pinsDebug.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
*/
3030

3131
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
32-
#define pwm_details(pin) pin = pin // do nothing // print PWM details
33-
#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
3432
#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
3533
#define digitalRead_mod(p) extDigitalRead(p)
36-
#define PRINT_PORT(p)
3734
#define GET_ARRAY_PIN(p) pin_array[p].pin
3835
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
3936
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("P%d_%02d"), LPC176x::pin_port(p), LPC176x::pin_bit(p)); SERIAL_ECHO(buffer); }while(0)
@@ -46,10 +43,14 @@
4643
#endif
4744

4845
bool GET_PINMODE(const pin_t pin) {
49-
if (!LPC176x::pin_is_valid(pin) || LPC176x::pin_adc_enabled(pin)) // found an invalid pin or active analog pin
46+
if (!LPC176x::pin_is_valid(pin) || LPC176x::pin_adc_enabled(pin)) // Invalid pin or active analog pin
5047
return false;
5148

5249
return LPC176x::gpio_direction(pin);
5350
}
5451

5552
#define GET_ARRAY_IS_DIGITAL(x) ((bool) pin_array[x].is_digital)
53+
54+
void print_port(const pin_t) {}
55+
void pwm_details(const pin_t) {}
56+
bool pwm_status(const pin_t) { return false; }

Marlin/src/HAL/NATIVE_SIM/pinsDebug.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,31 @@
2727
*/
2828

2929
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
30-
#define pwm_details(pin) pin = pin // do nothing // print PWM details
31-
#define pwm_status(pin) false //Print a pin's PWM status. Return true if it's currently a PWM pin.
3230
#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
3331
#define digitalRead_mod(p) digitalRead(p)
34-
#define PRINT_PORT(p)
3532
#define GET_ARRAY_PIN(p) pin_array[p].pin
3633
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
3734
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
3835
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
3936
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
4037

41-
// active ADC function/mode/code values for PINSEL registers
42-
inline constexpr int8_t ADC_pin_mode(pin_t pin) {
43-
return (-1);
44-
}
38+
// Active ADC function/mode/code values for PINSEL registers
39+
constexpr int8_t ADC_pin_mode(pin_t pin) { return -1; }
4540

46-
inline int8_t get_pin_mode(pin_t pin) {
47-
if (!VALID_PIN(pin)) return -1;
48-
return 0;
49-
}
41+
int8_t get_pin_mode(const pin_t pin) { return VALID_PIN(pin) 0 : -1; }
5042

51-
inline bool GET_PINMODE(pin_t pin) {
52-
int8_t pin_mode = get_pin_mode(pin);
53-
if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // found an invalid pin or active analog pin
43+
bool GET_PINMODE(const pin_t pin) {
44+
const int8_t pin_mode = get_pin_mode(pin);
45+
if (pin_mode == -1 || pin_mode == ADC_pin_mode(pin)) // Invalid pin or active analog pin
5446
return false;
5547

56-
return (Gpio::getMode(pin) != 0); //input/output state
48+
return (Gpio::getMode(pin) != 0); // Input/output state
5749
}
5850

59-
inline bool GET_ARRAY_IS_DIGITAL(pin_t pin) {
60-
return (!IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin));
51+
bool GET_ARRAY_IS_DIGITAL(const pin_t pin) {
52+
return !IS_ANALOG(pin) || get_pin_mode(pin) != ADC_pin_mode(pin);
6153
}
54+
55+
void print_port(const pin_t) {}
56+
void pwm_details(const pin_t) {}
57+
bool pwm_status(const pin_t) { return false; }

Marlin/src/HAL/STM32/pinsDebug.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ const XrefInfo pin_xref[] PROGMEM = {
119119
#define digitalRead_mod(Ard_num) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
120120
#define PRINT_PIN(Q)
121121
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
122-
#define PRINT_PORT(ANUM) port_print(ANUM)
123122
#define DIGITAL_PIN_TO_ANALOG_PIN(ANUM) -1 // will report analog pin number in the print port routine
124123

125124
// x is a variable used to search pin_array
@@ -187,7 +186,7 @@ bool is_digital(const pin_t Ard_num) {
187186
return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT;
188187
}
189188

190-
void port_print(const pin_t Ard_num) {
189+
void print_port(const pin_t Ard_num) {
191190
char buffer[16];
192191
pin_t Index;
193192
for (Index = 0; Index < NUMBER_PINS_TOTAL; Index++)

Marlin/src/HAL/STM32F1/pinsDebug.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
4141
#define NUMBER_PINS_TOTAL BOARD_NR_GPIO_PINS
4242
#define VALID_PIN(pin) (pin >= 0 && pin < BOARD_NR_GPIO_PINS)
4343
#define GET_ARRAY_PIN(p) pin_t(pin_array[p].pin)
44-
#define pwm_status(pin) PWM_PIN(pin)
4544
#define digitalRead_mod(p) extDigitalRead(p)
4645
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3hd "), int16_t(p)); SERIAL_ECHO(buffer); }while(0)
4746
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
48-
#define PRINT_PORT(p) print_port(p)
4947
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
5048
#define MULTI_NAME_PAD 21 // space needed to be pretty if not first name assigned to a pin
5149

@@ -54,20 +52,18 @@ extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
5452
#define M43_NEVER_TOUCH(Q) (Q >= 9 && Q <= 12) // SERIAL/USB pins PA9(TX) PA10(RX)
5553
#endif
5654

57-
static int8_t get_pin_mode(pin_t pin) {
58-
return VALID_PIN(pin) ? _GET_MODE(pin) : -1;
59-
}
55+
int8_t get_pin_mode(const pin_t pin) { return VALID_PIN(pin) ? _GET_MODE(pin) : -1; }
6056

61-
static pin_t DIGITAL_PIN_TO_ANALOG_PIN(pin_t pin) {
57+
pin_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t pin) {
6258
if (!VALID_PIN(pin)) return -1;
63-
int8_t adc_channel = int8_t(PIN_MAP[pin].adc_channel);
59+
pin_t adc_channel = pin_t(PIN_MAP[pin].adc_channel);
6460
#ifdef NUM_ANALOG_INPUTS
65-
if (adc_channel >= NUM_ANALOG_INPUTS) adc_channel = ADCx;
61+
if (adc_channel >= NUM_ANALOG_INPUTS) adc_channel = (pin_t)ADCx;
6662
#endif
67-
return pin_t(adc_channel);
63+
return adc_channel;
6864
}
6965

70-
static bool IS_ANALOG(pin_t pin) {
66+
bool IS_ANALOG(const pin_t pin) {
7167
if (!VALID_PIN(pin)) return false;
7268
if (PIN_MAP[pin].adc_channel != ADCx) {
7369
#ifdef NUM_ANALOG_INPUTS
@@ -78,11 +74,11 @@ static bool IS_ANALOG(pin_t pin) {
7874
return false;
7975
}
8076

81-
static bool GET_PINMODE(const pin_t pin) {
77+
bool GET_PINMODE(const pin_t pin) {
8278
return VALID_PIN(pin) && !IS_INPUT(pin);
8379
}
8480

85-
static bool GET_ARRAY_IS_DIGITAL(const int16_t array_pin) {
81+
bool GET_ARRAY_IS_DIGITAL(const int16_t array_pin) {
8682
const pin_t pin = GET_ARRAY_PIN(array_pin);
8783
return (!IS_ANALOG(pin)
8884
#ifdef NUM_ANALOG_INPUTS
@@ -93,7 +89,7 @@ static bool GET_ARRAY_IS_DIGITAL(const int16_t array_pin) {
9389

9490
#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
9591

96-
static void pwm_details(const pin_t pin) {
92+
void pwm_details(const pin_t pin) {
9793
if (PWM_PIN(pin)) {
9894
timer_dev * const tdev = PIN_MAP[pin].timer_device;
9995
const uint8_t channel = PIN_MAP[pin].timer_channel;
@@ -113,7 +109,9 @@ static void pwm_details(const pin_t pin) {
113109
}
114110
}
115111

116-
static void print_port(pin_t pin) {
112+
bool pwm_status(const pin_t pin) { return PWM_PIN(pin); }
113+
114+
void print_port(const pin_t pin) {
117115
const char port = 'A' + char(pin >> 4); // pin div 16
118116
const int16_t gbit = PIN_MAP[pin].gpio_bit;
119117
char buffer[8];

0 commit comments

Comments
 (0)