Skip to content

Commit

Permalink
Misc. cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 11, 2022
1 parent c2e8e39 commit 523f979
Show file tree
Hide file tree
Showing 33 changed files with 156 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2739,7 +2739,7 @@

//
// ReprapWorld Graphical LCD
// https://reprapworld.com/?products_details&products_id/1218
// https://reprapworld.com/electronics/3d-printer-modules/autonomous-printing/graphical-lcd-screen-v1-0/
//
//#define REPRAPWORLD_GRAPHICAL_LCD

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/NATIVE_SIM/u8g/u8g_com_st7920_sw_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ uint8_t u8g_com_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
#endif

#endif // IS_U8GLIB_ST7920
#endif // TARGET_LPC1768
#endif // __PLAT_NATIVE_SIM__
36 changes: 18 additions & 18 deletions Marlin/src/HAL/SAMD21/HAL.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -21,8 +21,8 @@
*/

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/
#ifdef __SAMD21__

Expand Down Expand Up @@ -68,7 +68,7 @@
GCLK_GENCTRL_IDC | // Set the duty cycle to 50/50 HIGH/LOW
GCLK_GENCTRL_GENEN | // Enable GCLK2
GCLK_GENCTRL_SRC_OSCULP32K | // Set the clock source to the ultra low power oscillator (OSCULP32K)
GCLK_GENCTRL_ID(2); // Select GCLK2
GCLK_GENCTRL_ID(2); // Select GCLK2
while (GCLK->STATUS.bit.SYNCBUSY); // Wait for synchronization

// Feed GCLK2 to WDT (Watchdog Timer)
Expand All @@ -86,7 +86,7 @@
// Reset watchdog. MUST be called at least every 4 seconds after the
// first watchdog_init or SAMD will go into emergency procedures.
void MarlinHAL::watchdog_refresh() {
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
while (WDT->STATUS.bit.SYNCBUSY);
}

Expand Down Expand Up @@ -164,37 +164,37 @@ void MarlinHAL::adc_init() {
/* thanks to https://www.eevblog.com/forum/microcontrollers/samd21g18-adc-with-resrdy-interrupts-only-reads-once-or-twice/ */

ADC->CTRLA.bit.ENABLE = false;
while(ADC->STATUS.bit.SYNCBUSY);
while(ADC->STATUS.bit.SYNCBUSY);


// load chip corrections
uint32_t bias = (*((uint32_t *) ADC_FUSES_BIASCAL_ADDR) & ADC_FUSES_BIASCAL_Msk) >> ADC_FUSES_BIASCAL_Pos;
uint32_t linearity = (*((uint32_t *) ADC_FUSES_LINEARITY_0_ADDR) & ADC_FUSES_LINEARITY_0_Msk) >> ADC_FUSES_LINEARITY_0_Pos;
linearity |= ((*((uint32_t *) ADC_FUSES_LINEARITY_1_ADDR) & ADC_FUSES_LINEARITY_1_Msk) >> ADC_FUSES_LINEARITY_1_Pos) << 5;

/* Wait for bus synchronization. */
while (ADC->STATUS.bit.SYNCBUSY) {};

ADC->CALIB.reg = ADC_CALIB_BIAS_CAL(bias) | ADC_CALIB_LINEARITY_CAL(linearity);

/* Wait for bus synchronization. */
while (ADC->STATUS.bit.SYNCBUSY) {};


ADC->CTRLA.bit.SWRST = true;
while(ADC->STATUS.bit.SYNCBUSY);
while(ADC->STATUS.bit.SYNCBUSY);

ADC->REFCTRL.reg = ADC_REFCTRL_REFSEL_INTVCC1;
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_32| ADC_AVGCTRL_ADJRES(4);;


ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV128 |
ADC_CTRLB_RESSEL_16BIT |
ADC_CTRLB_RESSEL_16BIT |
ADC_CTRLB_FREERUN;
while(ADC->STATUS.bit.SYNCBUSY);
while(ADC->STATUS.bit.SYNCBUSY);

ADC->SAMPCTRL.bit.SAMPLEN = 0x00;
while(ADC->STATUS.bit.SYNCBUSY);
while(ADC->STATUS.bit.SYNCBUSY);



Expand All @@ -210,7 +210,7 @@ void MarlinHAL::adc_init() {
NVIC_EnableIRQ(ADC_IRQn); // enable ADC interrupts

NVIC_SetPriority(ADC_IRQn, 3);

ADC->CTRLA.bit.ENABLE = true;


Expand All @@ -232,7 +232,7 @@ void ADC_Handler() {



void MarlinHAL::adc_start(const pin_t pin) {
void MarlinHAL::adc_start(const pin_t pin) {

/* due to the way INPUTOFFSET works, the last sensor is the first position in the array
and we want the ADC_handler interrupt to be as simple possible, so we do the calculation here.
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/HAL/SAMD21/HAL.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -19,12 +19,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/
#pragma once

#define CPU_32_BIT

Expand All @@ -35,12 +35,12 @@


#ifdef __SAMD21__

// ------------------------
// Serial ports
// ------------------------
// #ifdef USBCON

#include "../../core/serial_hook.h"
typedef ForwardSerial1Class< decltype(SerialUSB) > DefaultSerial1;
extern DefaultSerial1 MSerialUSB;
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/HAL/SAMD21/HAL_SPI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -21,8 +21,8 @@
*/

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/

/**
Expand Down Expand Up @@ -55,7 +55,7 @@
#else // !SOFTWARE_SPI

#define sdSPI SPI


static SPISettings spiConfig;

Expand Down Expand Up @@ -110,14 +110,14 @@
* @return Nothing
*/
void spiRead(uint8_t *buf, uint16_t nbyte) {

if (nbyte == 0) return;
memset(buf, 0xFF, nbyte);

sdSPI.beginTransaction(spiConfig);
sdSPI.transfer(buf, nbyte);
sdSPI.endTransaction();

}

/**
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/HAL/SAMD21/MarlinSPI.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -21,8 +21,8 @@
*/

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/
#pragma once

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/HAL/SAMD21/QSPIFlash.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -21,8 +21,8 @@
*/

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/
#include "../../inc/MarlinConfig.h"

Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/HAL/SAMD21/SAMD21.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -19,12 +19,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/
#pragma once

#define SYNC(sc) while (sc) { \
asm(""); \
Expand Down Expand Up @@ -58,7 +58,7 @@
: -1)



#define A2_AIN 3
#define A3_AIN 4
#define A4_AIN 5
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/HAL/SAMD21/Servo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -21,9 +21,10 @@
*/

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/

/**
* This comes from Arduino library which at the moment is buggy and uncompilable
*/
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/HAL/SAMD21/ServoTimers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
Expand All @@ -19,12 +19,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

/**
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on the work of Giuliano Zaro (AKA GMagician)
* SAMD21 HAL developed by Bart Meijer (brupje)
* Based on SAMD51 HAL by Giuliano Zaro (AKA GMagician)
*/
#pragma once

#define _useTimer1
#define _useTimer2
Expand Down
Loading

0 comments on commit 523f979

Please sign in to comment.