Skip to content

Commit 613ff20

Browse files
committed
✨ Code updates
1 parent 4a6871a commit 613ff20

File tree

117 files changed

+1502
-719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1502
-719
lines changed

Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* Logical Pin: 28 29 30 31 32 33 34 35 20 21 22 23 24 25 26 27 10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07 08 09(46*47)36 37 18 19 38 39 40 41 42 43 44 45
2828
* Port: A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7 E0 E1 E2 E3 E4 E5 E6 E7 F0 F1 F2 F3 F4 F5 F6 F7
29-
* The logical pins 46 and 47 are not supported by Teensyduino, but are supported below as E2 and E3
29+
* Logical pins 46-47 aren't supported by Teensyduino, but are supported below as E2 and E3
3030
*/
3131

3232
#include "../fastio.h"

Marlin/src/HAL/AVR/pinsDebug.h

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@
2222
#pragma once
2323

2424
/**
25-
* PWM print routines for Atmel 8 bit AVR CPUs
25+
* Pins Debugging for Atmel 8 bit AVR CPUs
26+
*
27+
* - NUMBER_PINS_TOTAL
28+
* - MULTI_NAME_PAD
29+
* - getPinByIndex(index)
30+
* - printPinNameByIndex(index)
31+
* - getPinIsDigitalByIndex(index)
32+
* - digitalPinToAnalogIndex(pin)
33+
* - getValidPinMode(pin)
34+
* - isValidPin(pin)
35+
* - isAnalogPin(pin)
36+
* - digitalRead_mod(pin)
37+
* - pwm_status(pin)
38+
* - printPinPWM(pin)
39+
* - printPinPort(pin)
40+
* - printPinNumber(pin)
41+
* - printPinAnalog(pin)
2642
*/
2743

2844
#include "../../inc/MarlinConfig.h"
@@ -39,44 +55,44 @@
3955
#include "pinsDebug_Teensyduino.h"
4056
// Can't use the "digitalPinToPort" function from the Teensyduino type IDEs
4157
// portModeRegister takes a different argument
42-
#define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
43-
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
44-
#define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
45-
#define GET_PINMODE(pin) (*portModeRegister(pin) & digitalPinToBitMask_DEBUG(pin))
58+
#define digitalPinToTimer_DEBUG(P) digitalPinToTimer(P)
59+
#define digitalPinToBitMask_DEBUG(P) digitalPinToBitMask(P)
60+
#define digitalPinToPort_DEBUG(P) digitalPinToPort(P)
61+
#define getValidPinMode(P) (*portModeRegister(P) & digitalPinToBitMask_DEBUG(P))
4662

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

4965
#include "pinsDebug_plus_70.h"
50-
#define digitalPinToTimer_DEBUG(p) digitalPinToTimer_plus_70(p)
51-
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask_plus_70(p)
52-
#define digitalPinToPort_DEBUG(p) digitalPinToPort_plus_70(p)
53-
bool GET_PINMODE(int8_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
66+
#define digitalPinToTimer_DEBUG(P) digitalPinToTimer_plus_70(P)
67+
#define digitalPinToBitMask_DEBUG(P) digitalPinToBitMask_plus_70(P)
68+
#define digitalPinToPort_DEBUG(P) digitalPinToPort_plus_70(P)
69+
bool getValidPinMode(pin_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
5470

5571
#else
5672

57-
#define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
58-
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
59-
#define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
60-
bool GET_PINMODE(int8_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
61-
#define GET_ARRAY_PIN(p) pgm_read_byte(&pin_array[p].pin)
73+
#define digitalPinToTimer_DEBUG(P) digitalPinToTimer(P)
74+
#define digitalPinToBitMask_DEBUG(P) digitalPinToBitMask(P)
75+
#define digitalPinToPort_DEBUG(P) digitalPinToPort(P)
76+
bool getValidPinMode(pin_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
77+
#define getPinByIndex(x) pgm_read_byte(&pin_array[x].pin)
6278

6379
#endif
6480

65-
#define VALID_PIN(pin) (pin >= 0 && pin < NUM_DIGITAL_PINS ? 1 : 0)
81+
#define isValidPin(P) (P >= 0 && P < NUMBER_PINS_TOTAL)
6682
#if AVR_ATmega1284_FAMILY
67-
#define IS_ANALOG(P) WITHIN(P, analogInputToDigitalPin(7), analogInputToDigitalPin(0))
68-
#define DIGITAL_PIN_TO_ANALOG_PIN(P) int(IS_ANALOG(P) ? (P) - analogInputToDigitalPin(7) : -1)
83+
#define isAnalogPin(P) WITHIN(P, analogInputToDigitalPin(7), analogInputToDigitalPin(0))
84+
#define digitalPinToAnalogIndex(P) int(isAnalogPin(P) ? (P) - analogInputToDigitalPin(7) : -1)
6985
#else
7086
#define _ANALOG1(P) WITHIN(P, analogInputToDigitalPin(0), analogInputToDigitalPin(7))
7187
#define _ANALOG2(P) WITHIN(P, analogInputToDigitalPin(8), analogInputToDigitalPin(15))
72-
#define IS_ANALOG(P) (_ANALOG1(P) || _ANALOG2(P))
73-
#define DIGITAL_PIN_TO_ANALOG_PIN(P) int(_ANALOG1(P) ? (P) - analogInputToDigitalPin(0) : _ANALOG2(P) ? (P) - analogInputToDigitalPin(8) + 8 : -1)
88+
#define isAnalogPin(P) (_ANALOG1(P) || _ANALOG2(P))
89+
#define digitalPinToAnalogIndex(P) int(_ANALOG1(P) ? (P) - analogInputToDigitalPin(0) : _ANALOG2(P) ? (P) - analogInputToDigitalPin(8) + 8 : -1)
7490
#endif
75-
#define GET_ARRAY_PIN(p) pgm_read_byte(&pin_array[p].pin)
91+
#define getPinByIndex(x) pgm_read_byte(&pin_array[x].pin)
7692
#define MULTI_NAME_PAD 26 // space needed to be pretty if not first name assigned to a pin
7793

78-
void PRINT_ARRAY_NAME(uint8_t x) {
79-
PGM_P const name_mem_pointer = (PGM_P)pgm_read_ptr(&pin_array[x].name);
94+
void printPinNameByIndex(const uint8_t index) {
95+
PGM_P const name_mem_pointer = (PGM_P)pgm_read_ptr(&pin_array[index].name);
8096
for (uint8_t y = 0; y < MAX_NAME_LENGTH; ++y) {
8197
char temp_char = pgm_read_byte(name_mem_pointer + y);
8298
if (temp_char != 0)
@@ -88,7 +104,7 @@ void PRINT_ARRAY_NAME(uint8_t x) {
88104
}
89105
}
90106

91-
#define GET_ARRAY_IS_DIGITAL(x) pgm_read_byte(&pin_array[x].is_digital)
107+
#define getPinIsDigitalByIndex(x) pgm_read_byte(&pin_array[x].is_digital)
92108

93109
#if defined(__AVR_ATmega1284P__) // 1284 IDE extensions set this to the number of
94110
#undef NUM_DIGITAL_PINS // digital only pins while all other CPUs have it
@@ -109,7 +125,7 @@ void PRINT_ARRAY_NAME(uint8_t x) {
109125
* Print a pin's PWM status.
110126
* Return true if it's currently a PWM pin.
111127
*/
112-
bool pwm_status(uint8_t pin) {
128+
bool pwm_status(const uint8_t pin) {
113129
char buffer[20]; // for the sprintf statements
114130

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

279-
void pwm_details(uint8_t pin) {
295+
void printPinPWM(const uint8_t pin) {
280296
switch (digitalPinToTimer_DEBUG(pin)) {
281297

282298
#if ABTEST(0)
@@ -347,7 +363,7 @@ void pwm_details(uint8_t pin) {
347363
#else
348364
UNUSED(print_is_also_tied);
349365
#endif
350-
} // pwm_details
366+
} // printPinPWM
351367

352368
#ifndef digitalRead_mod // Use Teensyduino's version of digitalRead - it doesn't disable the PWMs
353369
int digitalRead_mod(const pin_t pin) { // same as digitalRead except the PWM stop section has been removed
@@ -356,7 +372,7 @@ void pwm_details(uint8_t pin) {
356372
}
357373
#endif
358374

359-
void print_port(const pin_t pin) { // print port number
375+
void printPinPort(const pin_t pin) { // print port number
360376
#ifdef digitalPinToPort_DEBUG
361377
uint8_t x;
362378
SERIAL_ECHOPGM(" Port: ");
@@ -386,7 +402,7 @@ void print_port(const pin_t pin) { // print port number
386402
#endif
387403
}
388404

389-
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
390-
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
405+
#define printPinNumber(P) do{ sprintf_P(buffer, PSTR("%3d "), P); SERIAL_ECHO(buffer); }while(0)
406+
#define printPinAnalog(P) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(P)); SERIAL_ECHO(buffer); }while(0)
391407

392408
#undef ABTEST

Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
102102

103103
// digitalPinToBitMask(pin) is OK
104104

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

108108
// portModeRegister(pin) is OK

Marlin/src/HAL/DUE/HAL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ typedef Servo hal_servo_t;
127127
#define HAL_ADC_RESOLUTION 10
128128

129129
#ifndef analogInputToDigitalPin
130-
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
130+
#define analogInputToDigitalPin(p) pin_t((p < 12U) ? (p) + 54U : -1)
131131
#endif
132132

133133
//

Marlin/src/HAL/DUE/Servo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
static Flags<_Nbr_16timers> DisablePending; // ISR should disable the timer at the next timer reset
5151

5252
// ------------------------
53-
/// Interrupt handler for the TC0 channel 1.
53+
// Interrupt handler for the TC0 channel 1.
5454
// ------------------------
5555
void Servo_Handler(const timer16_Sequence_t, Tc*, const uint8_t);
5656

Marlin/src/HAL/DUE/pinsDebug.h

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,26 @@
1919
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2020
*
2121
*/
22+
#pragma once
2223

2324
/**
24-
* Support routines for Due
25-
*/
26-
27-
/**
28-
* Translation of routines & variables used by pinsDebug.h
25+
* Pins Debugging for DUE
26+
*
27+
* - NUMBER_PINS_TOTAL
28+
* - MULTI_NAME_PAD
29+
* - getPinByIndex(index)
30+
* - printPinNameByIndex(index)
31+
* - getPinIsDigitalByIndex(index)
32+
* - digitalPinToAnalogIndex(pin)
33+
* - getValidPinMode(pin)
34+
* - isValidPin(pin)
35+
* - isAnalogPin(pin)
36+
* - digitalRead_mod(pin)
37+
* - pwm_status(pin)
38+
* - printPinPWM(pin)
39+
* - printPinPort(pin)
40+
* - printPinNumber(pin)
41+
* - printPinAnalog(pin)
2942
*/
3043

3144
#include "../shared/Marduino.h"
@@ -63,20 +76,20 @@
6376

6477
#define NUMBER_PINS_TOTAL PINS_COUNT
6578

66-
#define digitalRead_mod(p) extDigitalRead(p) // AVR digitalRead disabled PWM before it read the pin
67-
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
68-
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
69-
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
70-
#define GET_ARRAY_PIN(p) pin_array[p].pin
71-
#define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
72-
#define VALID_PIN(pin) (pin >= 0 && pin < int8_t(NUMBER_PINS_TOTAL))
73-
#define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
74-
#define IS_ANALOG(P) WITHIN(P, char(analogInputToDigitalPin(0)), char(analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
75-
#define pwm_status(pin) (((g_pinStatus[pin] & 0xF) == PIN_STATUS_PWM) && \
76-
((g_APinDescription[pin].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM))
79+
#define digitalRead_mod(P) extDigitalRead(P) // AVR digitalRead disabled PWM before it read the pin
80+
#define printPinNameByIndex(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
81+
#define printPinNumber(P) do{ sprintf_P(buffer, PSTR("%02d"), P); SERIAL_ECHO(buffer); }while(0)
82+
#define printPinAnalog(P) do{ sprintf_P(buffer, PSTR(" (A%2d) "), digitalPinToAnalogIndex(P)); SERIAL_ECHO(buffer); }while(0)
83+
#define getPinByIndex(x) pin_array[x].pin
84+
#define getPinIsDigitalByIndex(x) pin_array[x].is_digital
85+
#define isValidPin(P) (P >= 0 && P < pin_t(NUMBER_PINS_TOTAL))
86+
#define digitalPinToAnalogIndex(P) int(P - analogInputToDigitalPin(0))
87+
#define isAnalogPin(P) WITHIN(P, pin_t(analogInputToDigitalPin(0)), pin_t(analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
88+
#define pwm_status(P) (((g_pinStatus[P] & 0xF) == PIN_STATUS_PWM) && \
89+
((g_APinDescription[P].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM))
7790
#define MULTI_NAME_PAD 14 // space needed to be pretty if not first name assigned to a pin
7891

79-
bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
92+
bool getValidPinMode(const pin_t pin) { // 1: output, 0: input
8093
volatile Pio* port = g_APinDescription[pin].pPort;
8194
uint32_t mask = g_APinDescription[pin].ulPin;
8295
uint8_t pin_status = g_pinStatus[pin] & 0xF;
@@ -85,14 +98,14 @@ bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
8598
|| pwm_status(pin));
8699
}
87100

88-
void pwm_details(int32_t pin) {
101+
void printPinPWM(const int32_t pin) {
89102
if (pwm_status(pin)) {
90103
uint32_t chan = g_APinDescription[pin].ulPWMChannel;
91104
SERIAL_ECHOPGM("PWM = ", PWM_INTERFACE->PWM_CH_NUM[chan].PWM_CDTY);
92105
}
93106
}
94107

95-
void print_port(const pin_t) {}
108+
void printPinPort(const pin_t) {}
96109

97110
/**
98111
* DUE Board pin | PORT | Label

Marlin/src/HAL/DUE/usb/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# USB Files Source Documentation
2+
3+
## Source
4+
5+
We sourced the USB files in Marlin from the Atmel ASF (Advanced Software Framework). The framework provides a variety of examples which were utilized in this project.
6+
7+
Atmel doesn't provide these files in a source repository but they can be extracted from ASF, which can be downloaded from Atmel.
8+
9+
[Advanced Software Framework](https://www.microchip.com/en-us/tools-resources/develop/libraries/advanced-software-framework)
10+
11+
## Modifications
12+
13+
The files are mostly unmodified except for minor cosmetic changes but some more significant changes were needed.
14+
15+
The changes that prompted the addition of this README file are listed below. Other changes may have been made prior to this.
16+
17+
1. Modified `uotghs_device_due.c` to resolve race conditions that could leave interrupts asserted when freezing the peripheral clock, resulting in hangs and watchdog resets due to the ensuing interrupt storm.
18+
19+
## Version Information
20+
21+
We don't know the exact version of ASF used as the source. However, the copyright information in the files indicates they are from 2015.
22+
23+
## Upgrade Considerations
24+
25+
We looked at the ASF 3.52.0 files released in 2022 but saw no immediate benefits to justify an upgrade. It's important to note that the files in Marlin don't follow the same folder structure as the files in ASF, which complicates the process of comparing and applying updated files.
26+
27+
When these files are updated it's important to carefully compare them to Marlin's versions so any improvements in the Marlin sources are brought forward.
28+
29+
It would be best to make Marlin's directory structure align with ASF or at least document the source of each file to ease future updates.

Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ extern "C" {
1818
void sd_mmc_spi_mem_init() {
1919
}
2020

21+
inline bool media_ready() {
22+
return IS_SD_INSERTED() && !IS_SD_PRINTING() && !IS_SD_FILE_OPEN() && card.isMounted();
23+
}
24+
25+
bool sd_mmc_spi_unload(bool) { return true; }
26+
27+
bool sd_mmc_spi_wr_protect() { return false; }
28+
29+
bool sd_mmc_spi_removal() { return !media_ready(); }
30+
2131
Ctrl_status sd_mmc_spi_test_unit_ready() {
2232
#ifdef DISABLE_DUE_SD_MMC
2333
return CTRL_NO_PRESENT;
2434
#endif
25-
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
26-
return CTRL_NO_PRESENT;
35+
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
2736
return CTRL_GOOD;
2837
}
2938

3039
// NOTE: This function is defined as returning the address of the last block
3140
// in the card, which is cardSize() - 1
3241
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
33-
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
34-
return CTRL_NO_PRESENT;
42+
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
3543
*nb_sector = card.diskIODriver()->cardSize() - 1;
3644
return CTRL_GOOD;
3745
}
3846

39-
bool sd_mmc_spi_unload(bool) { return true; }
40-
41-
bool sd_mmc_spi_wr_protect() { return false; }
42-
43-
bool sd_mmc_spi_removal() {
44-
return (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted());
45-
}
46-
4747
#if ACCESS_USB == true
4848
/**
4949
* \name MEM <-> USB Interface
@@ -61,8 +61,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
6161
#ifdef DISABLE_DUE_SD_MMC
6262
return CTRL_NO_PRESENT;
6363
#endif
64-
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
65-
return CTRL_NO_PRESENT;
64+
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
6665

6766
#ifdef DEBUG_MMC
6867
{
@@ -101,8 +100,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
101100
#ifdef DISABLE_DUE_SD_MMC
102101
return CTRL_NO_PRESENT;
103102
#endif
104-
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
105-
return CTRL_NO_PRESENT;
103+
if (sd_mmc_spi_removal()) return CTRL_NO_PRESENT;
106104

107105
#ifdef DEBUG_MMC
108106
{

0 commit comments

Comments
 (0)