Skip to content

Commit

Permalink
Adafruit Grand Central M4 fixes (#16812)
Browse files Browse the repository at this point in the history
  • Loading branch information
GMagician authored Feb 9, 2020
1 parent 84b6e11 commit 90e2c42
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions Marlin/src/HAL/HAL_SAMD51/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/HAL/HAL_SAMD51/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/HAL/HAL_SAMD51/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/HAL/HAL_SAMD51/fastio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/HAL/HAL_SAMD51/pinsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/
4 changes: 2 additions & 2 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 90e2c42

Please sign in to comment.