From 90e2c420312675521ce10def0a8c16a2d4b2c6bf Mon Sep 17 00:00:00 2001 From: Giuliano Zaro <3684609+GMagician@users.noreply.github.com> Date: Sun, 9 Feb 2020 16:57:22 +0100 Subject: [PATCH] Adafruit Grand Central M4 fixes (#16812) --- Marlin/src/HAL/HAL_SAMD51/HAL.cpp | 9 ++++----- Marlin/src/HAL/HAL_SAMD51/HAL.h | 6 +++--- Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp | 3 --- Marlin/src/HAL/HAL_SAMD51/fastio.h | 1 + Marlin/src/HAL/HAL_SAMD51/pinsDebug.h | 1 + Marlin/src/inc/Conditionals_post.h | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL.cpp b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp index 2b8da883dc..4828c40ff7 100644 --- a/Marlin/src/HAL/HAL_SAMD51/HAL.cpp +++ b/Marlin/src/HAL/HAL_SAMD51/HAL.cpp @@ -427,7 +427,6 @@ void HAL_init() { dma_init(); #endif #if ENABLED(SDSUPPORT) - // SD_DETECT_PIN may be removed if NO_SD_HOST_DRIVE is not defined in Configuration_adv.h #if SD_CONNECTION_IS(ONBOARD) && PIN_EXISTS(SD_DETECT) SET_INPUT_PULLUP(SD_DETECT_PIN); #endif @@ -496,14 +495,14 @@ void HAL_adc_init() { // Preloaded data (fixed for all ADC instances hence not loaded by DMA) adc->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val; // VRefA pin SYNC(adc->SYNCBUSY.bit.REFCTRL); - adc->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_12BIT_Val; + adc->CTRLB.bit.RESSEL = ADC_CTRLB_RESSEL_10BIT_Val; // ... ADC_CTRLB_RESSEL_16BIT_Val SYNC(adc->SYNCBUSY.bit.CTRLB); adc->SAMPCTRL.bit.SAMPLEN = (6 - 1); // Sampling clocks - adc->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_16 | ADC_AVGCTRL_ADJRES(4); // 16 Accumulated conversions and shift 4 to get oversampled 12 bits result - SYNC(adc->SYNCBUSY.bit.AVGCTRL); + //adc->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_16 | ADC_AVGCTRL_ADJRES(4); // 16 Accumulated conversions and shift 4 to get oversampled 12 bits result + //SYNC(adc->SYNCBUSY.bit.AVGCTRL); + // Registers loaded by DMA adc->DSEQCTRL.bit.INPUTCTRL = true; - adc->DSEQCTRL.bit.AUTOSTART = true; // Start conversion after DMA sequence adc->CTRLA.bit.ENABLE = true; // Enable ADC diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL.h b/Marlin/src/HAL/HAL_SAMD51/HAL.h index 2eaa40f302..209514a704 100644 --- a/Marlin/src/HAL/HAL_SAMD51/HAL.h +++ b/Marlin/src/HAL/HAL_SAMD51/HAL.h @@ -122,14 +122,14 @@ uint8_t eeprom_read_byte(uint8_t *pos); // // ADC // -extern uint16_t HAL_adc_result; // result of last ADC conversion +extern uint16_t HAL_adc_result; // Most recent ADC conversion #define HAL_ANALOG_SELECT(pin) void HAL_adc_init(); -#define HAL_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL -#define HAL_ADC_RESOLUTION 12 +//#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values. +#define HAL_ADC_RESOLUTION 10 // ... 12 #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin) #define HAL_READ_ADC() HAL_adc_result #define HAL_ADC_READY() true diff --git a/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp b/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp index 4fe4c85b69..83226daa48 100644 --- a/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp +++ b/Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp @@ -46,9 +46,6 @@ // ------------------------ #error "Software SPI not supported for SAMD51. Use Hardware SPI." - #if SD_CONNECTION_IS(ONBOARD) - #endif - #else // !SOFTWARE_SPI #ifdef ADAFRUIT_GRAND_CENTRAL_M4 diff --git a/Marlin/src/HAL/HAL_SAMD51/fastio.h b/Marlin/src/HAL/HAL_SAMD51/fastio.h index b5045e47bb..c91965e19e 100644 --- a/Marlin/src/HAL/HAL_SAMD51/fastio.h +++ b/Marlin/src/HAL/HAL_SAMD51/fastio.h @@ -245,6 +245,7 @@ #define DIO17_PIN PIN_PC23 #define DIO88_PIN PIN_PC24 // NEOPIXEL // PORTD + #define DIO53_PIN PIN_PD10 #define DIO22_PIN PIN_PD12 #define DIO6_PIN PIN_PD20 #define DIO7_PIN PIN_PD21 diff --git a/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h b/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h index 07964fb1b3..15b6473382 100644 --- a/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h +++ b/Marlin/src/HAL/HAL_SAMD51/pinsDebug.h @@ -149,5 +149,6 @@ void pwm_details(int32_t pin) { * 92 | PA9 | QSPI: IO1 * 93 | PA10 | QSPI: IO2 * 94 | PA11 | QSPI: IO3 + * 95 | PB31 | SD: DETECT * */ diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index ef7df41a1c..624de26a0b 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -300,7 +300,7 @@ /** * Override here because this is set in Configuration_adv.h */ -#if HAS_LCD_MENU && DISABLED(ELB_FULL_GRAPHIC_CONTROLLER) +#if HAS_LCD_MENU && DISABLED(ELB_FULL_GRAPHIC_CONTROLLER) && !(defined(ARDUINO_GRAND_CENTRAL_M4) && SD_CONNECTION_IS(ONBOARD)) #undef SD_DETECT_INVERTED #endif @@ -2218,7 +2218,7 @@ #endif #if ENABLED(SDSUPPORT) - #if SD_CONNECTION_IS(ONBOARD) && DISABLED(NO_SD_HOST_DRIVE) + #if SD_CONNECTION_IS(ONBOARD) && DISABLED(NO_SD_HOST_DRIVE) && !defined(ARDUINO_GRAND_CENTRAL_M4) // // The external SD card is not used. Hardware SPI is used to access the card. // When sharing the SD card with a PC we want the menu options to