Bump
This commit is contained in:
@@ -100,11 +100,13 @@
|
||||
* respectfully request that you retain the unmodified Marlin boot screen.
|
||||
*/
|
||||
|
||||
#if ENABLED(GRAPHICSLCD)
|
||||
// Enable to show the bitmap in Marlin/_Bootscreen.h on startup.
|
||||
//#define SHOW_CUSTOM_BOOTSCREEN
|
||||
#define SHOW_CUSTOM_BOOTSCREEN
|
||||
|
||||
// Enable to show the bitmap in Marlin/_Statusscreen.h on the status screen.
|
||||
//#define CUSTOM_STATUS_SCREEN_IMAGE
|
||||
#define CUSTOM_STATUS_SCREEN_IMAGE
|
||||
#endif
|
||||
|
||||
// @section machine
|
||||
|
||||
|
||||
@@ -1055,7 +1055,7 @@
|
||||
*
|
||||
* :[ 'LCD', 'ONBOARD', 'CUSTOM_CABLE' ]
|
||||
*/
|
||||
//#define SDCARD_CONNECTION LCD
|
||||
#define SDCARD_CONNECTION LCD
|
||||
#endif
|
||||
|
||||
#endif // SDSUPPORT
|
||||
|
||||
+1
-27
@@ -21,32 +21,6 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifdef __AVR__
|
||||
#define HAL_PLATFORM HAL_AVR
|
||||
#elif defined(ARDUINO_ARCH_SAM)
|
||||
#define HAL_PLATFORM HAL_DUE
|
||||
#elif defined(__MK20DX256__)
|
||||
#define HAL_PLATFORM HAL_TEENSY31_32
|
||||
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
#define HAL_PLATFORM HAL_TEENSY35_36
|
||||
#elif defined(TARGET_LPC1768)
|
||||
#define HAL_PLATFORM HAL_LPC1768
|
||||
#elif defined(__STM32F1__) || defined(TARGET_STM32F1)
|
||||
#define HAL_PLATFORM HAL_STM32F1
|
||||
#elif defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
|
||||
#define HAL_PLATFORM HAL_STM32_F4_F7
|
||||
#elif defined(ARDUINO_ARCH_STM32)
|
||||
#define HAL_PLATFORM HAL_STM32
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
#define HAL_PLATFORM HAL_ESP32
|
||||
#elif defined(__PLAT_LINUX__)
|
||||
#define HAL_PLATFORM HAL_LINUX
|
||||
#else
|
||||
#error "Unsupported Platform!"
|
||||
#endif
|
||||
|
||||
#define XSTR_(M) #M
|
||||
#define XSTR(M) XSTR_(M)
|
||||
#define HAL_PATH(PATH, NAME) XSTR(PATH/HAL_PLATFORM/NAME)
|
||||
#include "platforms.h"
|
||||
|
||||
#include HAL_PATH(.,HAL.h)
|
||||
|
||||
@@ -37,17 +37,18 @@
|
||||
|
||||
void HAL_init(void) {
|
||||
// Init Servo Pins
|
||||
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
|
||||
#if HAS_SERVO_0
|
||||
OUT_WRITE(SERVO0_PIN, LOW);
|
||||
INIT_SERVO(0);
|
||||
#endif
|
||||
#if HAS_SERVO_1
|
||||
OUT_WRITE(SERVO1_PIN, LOW);
|
||||
INIT_SERVO(1);
|
||||
#endif
|
||||
#if HAS_SERVO_2
|
||||
OUT_WRITE(SERVO2_PIN, LOW);
|
||||
INIT_SERVO(2);
|
||||
#endif
|
||||
#if HAS_SERVO_3
|
||||
OUT_WRITE(SERVO3_PIN, LOW);
|
||||
INIT_SERVO(3);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -53,9 +53,9 @@ void spiBegin(void) {
|
||||
|
||||
#if NONE(SOFTWARE_SPI, FORCE_SOFT_SPI)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ------------------------
|
||||
// Hardware SPI
|
||||
//------------------------------------------------------------------------------
|
||||
// ------------------------
|
||||
|
||||
// make sure SPCR rate is in expected bits
|
||||
#if (SPR0 != 0 || SPR1 != 1)
|
||||
@@ -177,9 +177,9 @@ void spiBegin(void) {
|
||||
|
||||
#else // SOFTWARE_SPI || FORCE_SOFT_SPI
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ------------------------
|
||||
// Software SPI
|
||||
//------------------------------------------------------------------------------
|
||||
// ------------------------
|
||||
|
||||
// nop to tune soft SPI timing
|
||||
#define nop asm volatile ("\tnop\n")
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
* Logical Pin : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 78 79 80 xx xx 84 85 71 70 xx xx xx xx xx 81 82 83 xx xx 72 72 75 76 77 74 xx xx xx xx xx
|
||||
*/
|
||||
|
||||
#include "fastio_AVR.h"
|
||||
#include "../fastio_AVR.h"
|
||||
|
||||
// change for your board
|
||||
#define DEBUG_LED DIO21
|
||||
@@ -28,7 +28,7 @@
|
||||
* 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 G0 G1 G2 G3 G4 G5
|
||||
*/
|
||||
|
||||
#include "fastio_AVR.h"
|
||||
#include "../fastio_AVR.h"
|
||||
|
||||
// change for your board
|
||||
#define DEBUG_LED DIO46
|
||||
@@ -28,7 +28,7 @@
|
||||
* Port: B0 B1 B2 B3 B4 B5 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7
|
||||
*/
|
||||
|
||||
#include "fastio_AVR.h"
|
||||
#include "../fastio_AVR.h"
|
||||
|
||||
#define DEBUG_LED AIO5
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
* +--------+
|
||||
*/
|
||||
|
||||
#include "fastio_AVR.h"
|
||||
#include "../fastio_AVR.h"
|
||||
|
||||
#define DEBUG_LED DIO0
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
* The logical pins 46 and 47 are not supported by Teensyduino, but are supported below as E2 and E3
|
||||
*/
|
||||
|
||||
#include "fastio_AVR.h"
|
||||
#include "../fastio_AVR.h"
|
||||
|
||||
// change for your board
|
||||
#define DEBUG_LED DIO31 /* led D5 red */
|
||||
@@ -27,8 +27,6 @@
|
||||
* Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
|
||||
*/
|
||||
|
||||
#include "../../core/macros.h"
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__))
|
||||
@@ -41,15 +39,15 @@
|
||||
* Include Ports and Functions
|
||||
*/
|
||||
#if AVR_ATmega328_FAMILY
|
||||
#include "fastio_168.h"
|
||||
#include "fastio/fastio_168.h"
|
||||
#elif AVR_ATmega1284_FAMILY
|
||||
#include "fastio_644.h"
|
||||
#include "fastio/fastio_644.h"
|
||||
#elif AVR_ATmega2560_FAMILY
|
||||
#include "fastio_1280.h"
|
||||
#include "fastio/fastio_1280.h"
|
||||
#elif AVR_AT90USB1286_FAMILY
|
||||
#include "fastio_AT90USB.h"
|
||||
#include "fastio/fastio_AT90USB.h"
|
||||
#elif AVR_ATmega2561_FAMILY
|
||||
#include "fastio_1281.h"
|
||||
#include "fastio/fastio_1281.h"
|
||||
#else
|
||||
#error "No FastIO definition for the selected AVR Board."
|
||||
#endif
|
||||
@@ -274,6 +272,8 @@ enum ClockSource2 : char {
|
||||
#define SET_FOCB(T,V) SET_FOC(T,B,V)
|
||||
#define SET_FOCC(T,V) SET_FOC(T,C,V)
|
||||
|
||||
#if 0
|
||||
|
||||
/**
|
||||
* PWM availability macros
|
||||
*/
|
||||
@@ -337,6 +337,8 @@ enum ClockSource2 : char {
|
||||
|
||||
#define PWM_CHK(P) (PWM_CHK_HEATER(P) || PWM_CHK_SERVO(P) || PWM_CHK_MOTOR_CURRENT(P) || PWM_CHK_FAN_A(P) || PWM_CHK_FAN_B(P))
|
||||
|
||||
#endif // PWM_CHK is not used in Marlin
|
||||
|
||||
// define which hardware PWMs are available for the current CPU
|
||||
// all timer 1 PWMS deleted from this list because they are never available
|
||||
#if AVR_ATmega2560_FAMILY
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -353,6 +353,8 @@ static void pwm_details(uint8_t pin) {
|
||||
timer_prefix(0, 'A', 3);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
UNUSED(print_is_also_tied);
|
||||
#endif
|
||||
} // pwm_details
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@
|
||||
|
||||
static volatile int8_t Channel[_Nbr_16timers]; // counter for the servo being pulsed for each timer (or -1 if refresh interval)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// ------------------------
|
||||
/// Interrupt handler for the TC0 channel 1.
|
||||
//------------------------------------------------------------------------------
|
||||
// ------------------------
|
||||
void Servo_Handler(timer16_Sequence_t timer, Tc *pTc, uint8_t channel);
|
||||
|
||||
#ifdef _useTimer1
|
||||
@@ -137,7 +137,7 @@ void initISR(timer16_Sequence_t timer) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void finISR(timer16_Sequence_t timer) {
|
||||
void finISR(timer16_Sequence_t) {
|
||||
#ifdef _useTimer1
|
||||
TC_Stop(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1);
|
||||
#endif
|
||||
|
||||
+37
-38
@@ -21,58 +21,57 @@
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
based on u8g_com_msp430_hw_spi.c
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2012, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/**
|
||||
* Based on u8g_com_msp430_hw_spi.c
|
||||
*
|
||||
* Universal 8bit Graphics Library
|
||||
*
|
||||
* Copyright (c) 2012, olikraus@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SAM3X8E__
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
|
||||
#include <U8glib.h>
|
||||
|
||||
#include "../../Marlin.h"
|
||||
#include "../../../Marlin.h"
|
||||
|
||||
void spiBegin();
|
||||
void spiInit(uint8_t spiRate);
|
||||
void spiSend(uint8_t b);
|
||||
void spiSend(const uint8_t* buf, size_t n);
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "fastio_Due.h"
|
||||
#include "../../shared/Marduino.h"
|
||||
#include "../fastio_Due.h"
|
||||
|
||||
void u8g_SetPIOutput_DUE_hw_spi(u8g_t *u8g, uint8_t pin_index) {
|
||||
PIO_Configure(g_APinDescription[u8g->pin_list[pin_index]].pPort, PIO_OUTPUT_1,
|
||||
+4
-4
@@ -55,11 +55,11 @@
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(U8GLIB_ST7920)
|
||||
|
||||
#include "../shared/Delay.h"
|
||||
#include "../../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
|
||||
@@ -145,8 +145,8 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
}
|
||||
|
||||
#if ENABLED(LIGHTWEIGHT_UI)
|
||||
#include "../../lcd/ultralcd.h"
|
||||
#include "../shared/HAL_ST7920.h"
|
||||
#include "../../../lcd/ultralcd.h"
|
||||
#include "../../shared/HAL_ST7920.h"
|
||||
|
||||
#define ST7920_CS_PIN LCD_PINS_RS
|
||||
|
||||
+3
-3
@@ -55,7 +55,7 @@
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
|
||||
|
||||
@@ -64,8 +64,8 @@
|
||||
|
||||
#include "u8g_com_HAL_DUE_sw_spi_shared.h"
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/Delay.h"
|
||||
#include "../../shared/Marduino.h"
|
||||
#include "../../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
|
||||
+2
-2
@@ -55,11 +55,11 @@
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
|
||||
#include "../shared/Delay.h"
|
||||
#include "../../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
#include "../../shared/Marduino.h"
|
||||
|
||||
void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index);
|
||||
void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level);
|
||||
@@ -40,7 +40,7 @@
|
||||
* Some jitter in the Vref signal is OK so the interrupt priority is left at its default value.
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if MB(PRINTRBOARD_G2)
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
* PR #7500. It is hardwired for the PRINTRBOARD_G2 Motor Current needs.
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../module/stepper.h"
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
#include "../../../module/stepper.h"
|
||||
//C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\module\stepper.h
|
||||
//C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\HAL\HAL_DUE\G2_PWM.h
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
|
||||
#if MB(PRINTRBOARD_G2)
|
||||
|
||||
#include "G2_pins.h"
|
||||
#include "fastio/G2_pins.h"
|
||||
|
||||
// Set pin as input
|
||||
#define _SET_INPUT(IO) do{ \
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -62,7 +62,6 @@
|
||||
|
||||
#define digitalRead_mod(p) extDigitalRead(p) // AVR digitalRead disabled PWM before it read the pin
|
||||
#define PRINT_PORT(p)
|
||||
#define NAME_FORMAT(p) PSTR("%-##p##s")
|
||||
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
|
||||
#define GET_ARRAY_PIN(p) pin_array[p].pin
|
||||
|
||||
@@ -458,7 +458,7 @@ void udi_cdc_data_sof_notify(void)
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// ------------------------
|
||||
//------- Internal routines to control serial line
|
||||
|
||||
static uint8_t udi_cdc_setup_to_port(void)
|
||||
@@ -579,7 +579,7 @@ static void udi_cdc_serial_state_msg_sent(udd_ep_status_t status, iram_size_t n,
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// ------------------------
|
||||
//------- Internal routines to process data transfer
|
||||
|
||||
|
||||
@@ -781,7 +781,7 @@ static void udi_cdc_tx_send(uint8_t port)
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// ------------------------
|
||||
//------- Application interface
|
||||
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@ uint8_t udi_msc_getsetting(void)
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// ------------------------
|
||||
//------- Routines to process CBW packet
|
||||
|
||||
static void udi_msc_cbw_invalid(void)
|
||||
@@ -613,7 +613,7 @@ static bool udi_msc_cbw_validate(uint32_t alloc_len, uint8_t dir_flag)
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// ------------------------
|
||||
//------- Routines to process small data packet
|
||||
|
||||
static void udi_msc_data_send(uint8_t * buffer, uint8_t buf_size)
|
||||
@@ -645,7 +645,7 @@ static void udi_msc_data_sent(udd_ep_status_t status, iram_size_t nb_sent,
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// ------------------------
|
||||
//------- Routines to process CSW packet
|
||||
|
||||
static void udi_msc_csw_process(void)
|
||||
@@ -691,7 +691,7 @@ static void udi_msc_csw_sent(udd_ep_status_t status, iram_size_t nb_sent,
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// ------------------------
|
||||
//------- Routines manage sense data
|
||||
|
||||
static void udi_msc_clear_sense(void)
|
||||
@@ -757,7 +757,7 @@ static void udi_msc_sense_command_invalid(void)
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// ------------------------
|
||||
//------- Routines manage SCSI Commands
|
||||
|
||||
static void udi_msc_spc_requestsense(void)
|
||||
|
||||
@@ -506,7 +506,7 @@ static bool udd_ep_interrupt(void);
|
||||
//@}
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// ------------------------
|
||||
//--- INTERNAL ROUTINES TO MANAGED GLOBAL EVENTS
|
||||
|
||||
/**
|
||||
@@ -1307,7 +1307,7 @@ void udd_test_mode_packet(void)
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// ------------------------
|
||||
//--- INTERNAL ROUTINES TO MANAGED THE CONTROL ENDPOINT
|
||||
|
||||
static void udd_reset_ep_ctrl(void)
|
||||
@@ -1729,7 +1729,7 @@ static bool udd_ctrl_interrupt(void)
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
// ------------------------
|
||||
//--- INTERNAL ROUTINES TO MANAGED THE BULK/INTERRUPT/ISOCHRONOUS ENDPOINTS
|
||||
|
||||
#if (0 != USB_DEVICE_MAX_EP)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
#include "HAL.h"
|
||||
#include "HAL_timers_ESP32.h"
|
||||
#include <rom/rtc.h>
|
||||
#include <driver/adc.h>
|
||||
#include <esp_adc_cal.h>
|
||||
@@ -45,7 +46,7 @@
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
// Externals
|
||||
// Externs
|
||||
// ------------------------
|
||||
|
||||
portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
@@ -66,7 +67,12 @@ uint16_t HAL_adc_result;
|
||||
// Private Variables
|
||||
// ------------------------
|
||||
|
||||
esp_adc_cal_characteristics_t characteristics;
|
||||
esp_adc_cal_characteristics_t characteristics[ADC_ATTEN_MAX];
|
||||
adc_atten_t attenuations[ADC1_CHANNEL_MAX] = {};
|
||||
uint32_t thresholds[ADC_ATTEN_MAX];
|
||||
volatile int numPWMUsed = 0,
|
||||
pwmPins[MAX_PWM_PINS],
|
||||
pwmValues[MAX_PWM_PINS];
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
@@ -125,68 +131,132 @@ adc1_channel_t get_channel(int pin) {
|
||||
return ADC1_CHANNEL_MAX;
|
||||
}
|
||||
|
||||
void adc1_set_attenuation(adc1_channel_t chan, adc_atten_t atten) {
|
||||
if (attenuations[chan] != atten) {
|
||||
adc1_config_channel_atten(chan, atten);
|
||||
attenuations[chan] = atten;
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_adc_init() {
|
||||
// Configure ADC
|
||||
adc1_config_width(ADC_WIDTH_12Bit);
|
||||
|
||||
// Configure channels only if used as (re-)configuring a pin for ADC that is used elsewhere might have adverse effects
|
||||
#if HAS_TEMP_ADC_0
|
||||
adc1_config_channel_atten(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_1
|
||||
adc1_config_channel_atten(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_2
|
||||
adc1_config_channel_atten(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_3
|
||||
adc1_config_channel_atten(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_4
|
||||
adc1_config_channel_atten(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_5
|
||||
adc1_config_channel_atten(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
adc1_config_channel_atten(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if HAS_TEMP_CHAMBER
|
||||
adc1_config_channel_atten(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
||||
adc1_config_channel_atten(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
|
||||
adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
|
||||
#endif
|
||||
|
||||
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.
|
||||
// That's why we're not setting it up here.
|
||||
|
||||
// Calculate ADC characteristics i.e. gain and offset factors
|
||||
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, V_REF, &characteristics);
|
||||
// Calculate ADC characteristics (i.e., gain and offset factors for each attenuation level)
|
||||
for (int i = 0; i < ADC_ATTEN_MAX; i++) {
|
||||
esp_adc_cal_characterize(ADC_UNIT_1, (adc_atten_t)i, ADC_WIDTH_BIT_12, V_REF, &characteristics[i]);
|
||||
|
||||
// Change attenuation 100mV below the calibrated threshold
|
||||
thresholds[i] = esp_adc_cal_raw_to_voltage(4095, &characteristics[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_adc_start_conversion(uint8_t adc_pin) {
|
||||
const adc1_channel_t chan = get_channel(adc_pin);
|
||||
uint32_t mv;
|
||||
esp_adc_cal_get_voltage((adc_channel_t)get_channel(adc_pin), &characteristics, &mv);
|
||||
esp_adc_cal_get_voltage((adc_channel_t)chan, &characteristics[attenuations[chan]], &mv);
|
||||
|
||||
HAL_adc_result = mv*1023.0/3300.0;
|
||||
// Change the attenuation level based on the new reading
|
||||
adc_atten_t atten;
|
||||
if (mv < thresholds[ADC_ATTEN_DB_0] - 100)
|
||||
adc1_set_attenuation(chan, ADC_ATTEN_DB_0);
|
||||
else if (mv > thresholds[ADC_ATTEN_DB_0] - 50 && mv < thresholds[ADC_ATTEN_DB_2_5] - 100)
|
||||
adc1_set_attenuation(chan, ADC_ATTEN_DB_2_5);
|
||||
else if (mv > thresholds[ADC_ATTEN_DB_2_5] - 50 && mv < thresholds[ADC_ATTEN_DB_6] - 100)
|
||||
adc1_set_attenuation(chan, ADC_ATTEN_DB_6);
|
||||
else if (mv > thresholds[ADC_ATTEN_DB_6] - 50)
|
||||
adc1_set_attenuation(chan, ADC_ATTEN_DB_11);
|
||||
|
||||
HAL_adc_result = mv * 1023.0 / 3300.0;
|
||||
}
|
||||
|
||||
void analogWrite(pin_t pin, int value) {
|
||||
|
||||
if (!PWM_PIN(pin)) return;
|
||||
|
||||
static int cnt_channel = 1,
|
||||
pin_to_channel[40] = {};
|
||||
if (pin_to_channel[pin] == 0) {
|
||||
ledcAttachPin(pin, cnt_channel);
|
||||
ledcSetup(cnt_channel, 490, 8);
|
||||
ledcWrite(cnt_channel, value);
|
||||
|
||||
pin_to_channel[pin] = cnt_channel++;
|
||||
// Use ledc hardware for internal pins
|
||||
if (pin < 34) {
|
||||
static int cnt_channel = 1, pin_to_channel[40] = { 0 };
|
||||
if (pin_to_channel[pin] == 0) {
|
||||
ledcAttachPin(pin, cnt_channel);
|
||||
ledcSetup(cnt_channel, 490, 8);
|
||||
ledcWrite(cnt_channel, value);
|
||||
pin_to_channel[pin] = cnt_channel++;
|
||||
}
|
||||
ledcWrite(pin_to_channel[pin], value);
|
||||
return;
|
||||
}
|
||||
|
||||
ledcWrite(pin_to_channel[pin], value);
|
||||
int idx = -1;
|
||||
|
||||
// Search Pin
|
||||
for (int i = 0; i < numPWMUsed; ++i)
|
||||
if (pwmPins[i] == pin) { idx = i; break; }
|
||||
|
||||
// not found ?
|
||||
if (idx < 0) {
|
||||
// No slots remaining
|
||||
if (numPWMUsed >= MAX_PWM_PINS) return;
|
||||
|
||||
// Take new slot for pin
|
||||
idx = numPWMUsed;
|
||||
pwmPins[idx] = pin;
|
||||
// Start timer on first use
|
||||
if (idx == 0) HAL_timer_start(PWM_TIMER_NUM, PWM_TIMER_FREQUENCY);
|
||||
|
||||
++numPWMUsed;
|
||||
}
|
||||
|
||||
// Use 7bit internal value - add 1 to have 100% high at 255
|
||||
pwmValues[idx] = (value + 1) / 2;
|
||||
}
|
||||
|
||||
// Handle PWM timer interrupt
|
||||
HAL_PWM_TIMER_ISR() {
|
||||
HAL_timer_isr_prologue(PWM_TIMER_NUM);
|
||||
|
||||
static uint8_t count = 0;
|
||||
|
||||
for (int i = 0; i < numPWMUsed; ++i) {
|
||||
if (count == 0) // Start of interval
|
||||
WRITE(pwmPins[i], pwmValues[i] ? HIGH : LOW);
|
||||
else if (pwmValues[i] == count) // End of duration
|
||||
WRITE(pwmPins[i], LOW);
|
||||
}
|
||||
|
||||
// 128 for 7 Bit resolution
|
||||
count = (count + 1) & 0x7F;
|
||||
|
||||
HAL_timer_isr_epilogue(PWM_TIMER_NUM);
|
||||
}
|
||||
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
@@ -47,7 +47,7 @@ static timg_dev_t *TG[2] = {&TIMERG0, &TIMERG1};
|
||||
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
|
||||
{ TIMER_GROUP_0, TIMER_0, STEPPER_TIMER_PRESCALE, stepTC_Handler }, // 0 - Stepper
|
||||
{ TIMER_GROUP_0, TIMER_1, TEMP_TIMER_PRESCALE, tempTC_Handler }, // 1 - Temperature
|
||||
{ TIMER_GROUP_1, TIMER_0, 1, nullptr }, // 2
|
||||
{ TIMER_GROUP_1, TIMER_0, PWM_TIMER_PRESCALE, pwmTC_Handler }, // 2 - PWM
|
||||
{ TIMER_GROUP_1, TIMER_1, 1, nullptr }, // 3
|
||||
};
|
||||
|
||||
@@ -55,28 +55,28 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
void IRAM_ATTR timer_group0_isr(void *para) {
|
||||
const int timer_idx = (int)para;
|
||||
void IRAM_ATTR timer_isr(void *para) {
|
||||
const tTimerConfig& timer = TimerConfig[(int)para];
|
||||
|
||||
// Retrieve the interrupt status and the counter value
|
||||
// from the timer that reported the interrupt
|
||||
uint32_t intr_status = TIMERG0.int_st_timers.val;
|
||||
TIMERG0.hw_timer[timer_idx].update = 1;
|
||||
uint32_t intr_status = TG[timer.group]->int_st_timers.val;
|
||||
TG[timer.group]->hw_timer[timer.idx].update = 1;
|
||||
|
||||
// Clear the interrupt
|
||||
if (intr_status & BIT(timer_idx)) {
|
||||
switch (timer_idx) {
|
||||
case TIMER_0: TIMERG0.int_clr_timers.t0 = 1; break;
|
||||
case TIMER_1: TIMERG0.int_clr_timers.t1 = 1; break;
|
||||
if (intr_status & BIT(timer.idx)) {
|
||||
switch (timer.idx) {
|
||||
case TIMER_0: TG[timer.group]->int_clr_timers.t0 = 1; break;
|
||||
case TIMER_1: TG[timer.group]->int_clr_timers.t1 = 1; break;
|
||||
case TIMER_MAX: break;
|
||||
}
|
||||
}
|
||||
|
||||
const tTimerConfig timer = TimerConfig[timer_idx];
|
||||
timer.fn();
|
||||
|
||||
// After the alarm has been triggered
|
||||
// Enable it again so it gets triggered the next time
|
||||
TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
|
||||
TG[timer.group]->hw_timer[timer.idx].config.alarm_en = TIMER_ALARM_EN;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,8 +106,7 @@ void HAL_timer_start(const uint8_t timer_num, uint32_t frequency) {
|
||||
|
||||
timer_enable_intr(timer.group, timer.idx);
|
||||
|
||||
// TODO need to deal with timer_group1_isr
|
||||
timer_isr_register(timer.group, timer.idx, timer_group0_isr, (void*)timer.idx, 0, nullptr);
|
||||
timer_isr_register(timer.group, timer.idx, timer_isr, (void*)timer_num, 0, nullptr);
|
||||
|
||||
timer_start(timer.group, timer.idx);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ typedef uint64_t hal_timer_t;
|
||||
|
||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper
|
||||
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
|
||||
#define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
|
||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||
|
||||
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
|
||||
@@ -59,6 +60,14 @@ typedef uint64_t hal_timer_t;
|
||||
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||
|
||||
#define PWM_TIMER_PRESCALE 10
|
||||
#if ENABLED(FAST_PWM_FAN)
|
||||
#define PWM_TIMER_FREQUENCY FAST_PWM_FAN_FREQUENCY
|
||||
#else
|
||||
#define PWM_TIMER_FREQUENCY (50*128) // 50Hz and 7bit resolution
|
||||
#endif
|
||||
#define MAX_PWM_PINS 32 // Number of PWM pin-slots
|
||||
|
||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
||||
@@ -72,10 +81,11 @@ typedef uint64_t hal_timer_t;
|
||||
|
||||
#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler(void)
|
||||
#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler(void)
|
||||
#define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler(void)
|
||||
|
||||
extern "C" void tempTC_Handler(void);
|
||||
extern "C" void stepTC_Handler(void);
|
||||
|
||||
extern "C" void pwmTC_Handler(void);
|
||||
|
||||
// ------------------------
|
||||
// Types
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|
||||
|
||||
// PWM outputs
|
||||
#define PWM_PIN(P) (P < 34) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
|
||||
#define PWM_PIN(P) (P < 34 || P > 127) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
|
||||
|
||||
// Toggle pin value
|
||||
#define TOGGLE(IO) WRITE(IO, !READ(IO))
|
||||
|
||||
@@ -56,7 +56,7 @@ static i2s_dev_t* I2S[I2S_NUM_MAX] = {&I2S0, &I2S1};
|
||||
static i2s_dma_t dma;
|
||||
|
||||
// output value
|
||||
uint32_t i2s_port_data;
|
||||
uint32_t i2s_port_data = 0;
|
||||
|
||||
#define I2S_ENTER_CRITICAL() portENTER_CRITICAL(&i2s_spinlock[i2s_num])
|
||||
#define I2S_EXIT_CRITICAL() portEXIT_CRITICAL(&i2s_spinlock[i2s_num])
|
||||
@@ -140,13 +140,13 @@ static void IRAM_ATTR i2s_intr_handler_default(void *arg) {
|
||||
}
|
||||
|
||||
void stepperTask(void* parameter) {
|
||||
uint32_t i, remaining = 0;
|
||||
uint32_t remaining = 0;
|
||||
|
||||
while (1) {
|
||||
xQueueReceive(dma.queue, &dma.current, portMAX_DELAY);
|
||||
dma.rw_pos = 0;
|
||||
|
||||
for (i = 0; i < DMA_SAMPLE_COUNT; i++) {
|
||||
while (dma.rw_pos < DMA_SAMPLE_COUNT) {
|
||||
// Fill with the port data post pulse_phase until the next step
|
||||
if (remaining) {
|
||||
i2s_push_sample();
|
||||
@@ -254,7 +254,13 @@ int i2s_init() {
|
||||
|
||||
I2S0.fifo_conf.dscr_en = 0;
|
||||
|
||||
I2S0.conf_chan.tx_chan_mod = 0;
|
||||
I2S0.conf_chan.tx_chan_mod = (
|
||||
#if ENABLED(I2S_STEPPER_SPLIT_STREAM)
|
||||
4
|
||||
#else
|
||||
0
|
||||
#endif
|
||||
);
|
||||
I2S0.fifo_conf.tx_fifo_mod = 0;
|
||||
I2S0.conf.tx_mono = 0;
|
||||
|
||||
@@ -314,10 +320,19 @@ int i2s_init() {
|
||||
}
|
||||
|
||||
void i2s_write(uint8_t pin, uint8_t val) {
|
||||
#if ENABLED(I2S_STEPPER_SPLIT_STREAM)
|
||||
if (pin >= 16) {
|
||||
SET_BIT_TO(I2S0.conf_single_data, pin, val);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
SET_BIT_TO(i2s_port_data, pin, val);
|
||||
}
|
||||
|
||||
uint8_t i2s_state(uint8_t pin) {
|
||||
#if ENABLED(I2S_STEPPER_SPLIT_STREAM)
|
||||
if (pin >= 16) return TEST(I2S0.conf_single_data, pin);
|
||||
#endif
|
||||
return TEST(i2s_port_data, pin);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -83,8 +83,9 @@ public:
|
||||
|
||||
HalSerial() { host_connected = true; }
|
||||
|
||||
void begin(int32_t baud) {
|
||||
}
|
||||
void begin(int32_t baud) { }
|
||||
|
||||
void end() { }
|
||||
|
||||
int peek() {
|
||||
uint8_t value;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define digitalRead_mod(p) digitalRead(p)
|
||||
#define PRINT_PORT(p)
|
||||
#define GET_ARRAY_PIN(p) pin_array[p].pin
|
||||
#define NAME_FORMAT(p) PSTR("%-##p##s")
|
||||
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
|
||||
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include "../../core/macros.h"
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if BOTH(SDSUPPORT, DOGLCD) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
|
||||
#if HAS_GRAPHICAL_LCD && ENABLED(SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
|
||||
#define LPC_SOFTWARE_SPI // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
|
||||
// needed due to the speed and mode requred for communicating with each device being different.
|
||||
// needed due to the speed and mode required for communicating with each device being different.
|
||||
// This requirement can be removed if the SPI access to these devices is updated to use
|
||||
// spiBeginTransaction.
|
||||
#endif
|
||||
|
||||
@@ -133,7 +133,7 @@ uint8_t spiRec(uint32_t chan);
|
||||
// Memory usage per ADC channel (bytes): (6 * ADC_MEDIAN_FILTER_SIZE) + 16
|
||||
// 8 * ((6 * 23) + 16 ) = 1232 Bytes for 8 channels
|
||||
|
||||
#define ADC_LOWPASS_K_VALUE (6) // Higher values increase rise time
|
||||
#define ADC_LOWPASS_K_VALUE (2) // Higher values increase rise time
|
||||
// Rise time sample delays for 100% signal convergence on full range step
|
||||
// (1 : 13, 2 : 32, 3 : 67, 4 : 139, 5 : 281, 6 : 565, 7 : 1135, 8 : 2273)
|
||||
// K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
|
||||
@@ -147,7 +147,9 @@ using FilteredADC = LPC176x::ADC<ADC_LOWPASS_K_VALUE, ADC_MEDIAN_FILTER_SIZE>;
|
||||
#define HAL_ADC_READY() FilteredADC::finished_conversion()
|
||||
|
||||
// A grace period to allow ADC readings to stabilize, preventing false alarms
|
||||
#define THERMAL_PROTECTION_GRACE_PERIOD 1000
|
||||
#ifndef THERMAL_PROTECTION_GRACE_PERIOD
|
||||
#define THERMAL_PROTECTION_GRACE_PERIOD 1000
|
||||
#endif
|
||||
|
||||
// Parse a G-code word into a pin index
|
||||
int16_t PARSED_PIN_INDEX(const char code, const int16_t dval);
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void end() { }
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
bool recv_callback(const char c) override {
|
||||
emergency_parser.update(emergency_state, c);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -73,17 +73,18 @@ void HAL_init(void) {
|
||||
#endif
|
||||
|
||||
// Init Servo Pins
|
||||
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
|
||||
#if HAS_SERVO_0
|
||||
OUT_WRITE(SERVO0_PIN, LOW);
|
||||
INIT_SERVO(0);
|
||||
#endif
|
||||
#if HAS_SERVO_1
|
||||
OUT_WRITE(SERVO1_PIN, LOW);
|
||||
INIT_SERVO(1);
|
||||
#endif
|
||||
#if HAS_SERVO_2
|
||||
OUT_WRITE(SERVO2_PIN, LOW);
|
||||
INIT_SERVO(2);
|
||||
#endif
|
||||
#if HAS_SERVO_3
|
||||
OUT_WRITE(SERVO3_PIN, LOW);
|
||||
INIT_SERVO(3);
|
||||
#endif
|
||||
|
||||
//debug_frmwrk_init();
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define digitalRead_mod(p) extDigitalRead(p)
|
||||
#define PRINT_PORT(p)
|
||||
#define GET_ARRAY_PIN(p) pin_array[p].pin
|
||||
#define NAME_FORMAT(p) PSTR("%-##p##s")
|
||||
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%d.%02d"), LPC1768_PIN_PORT(p), LPC1768_PIN_PIN(p)); SERIAL_ECHO(buffer); }while(0)
|
||||
#define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#if ENABLED(SDSUPPORT) && HAS_GRAPHICAL_LCD && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
|
||||
#define LPC_SOFTWARE_SPI // If the SD card and LCD adapter share the same SPI pins, then software SPI is currently
|
||||
// needed due to the speed and mode requred for communicating with each device being different.
|
||||
// needed due to the speed and mode required for communicating with each device being different.
|
||||
// This requirement can be removed if the SPI access to these devices is updated to use
|
||||
// spiBeginTransaction.
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,475 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SAMD51__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "Adafruit_ZeroDMA.h"
|
||||
#include "wiring_private.h"
|
||||
|
||||
// ------------------------
|
||||
// Local defines
|
||||
// ------------------------
|
||||
|
||||
#if HAS_TEMP_ADC_0
|
||||
#define GET_TEMP_0_ADC() PIN_TO_ADC(TEMP_0_PIN)
|
||||
#else
|
||||
#define GET_TEMP_0_ADC() -1
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_1
|
||||
#define GET_TEMP_1_ADC() PIN_TO_ADC(TEMP_1_PIN)
|
||||
#else
|
||||
#define GET_TEMP_1_ADC() -1
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_2
|
||||
#define GET_TEMP_2_ADC() PIN_TO_ADC(TEMP_2_PIN)
|
||||
#else
|
||||
#define GET_TEMP_2_ADC() -1
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_3
|
||||
#define GET_TEMP_3_ADC() PIN_TO_ADC(TEMP_3_PIN)
|
||||
#else
|
||||
#define GET_TEMP_3_ADC() -1
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_4
|
||||
#define GET_TEMP_4_ADC() PIN_TO_ADC(TEMP_4_PIN)
|
||||
#else
|
||||
#define GET_TEMP_4_ADC() -1
|
||||
#endif
|
||||
#if HAS_TEMP_ADC_5
|
||||
#define GET_TEMP_5_ADC() PIN_TO_ADC(TEMP_5_PIN)
|
||||
#else
|
||||
#define GET_TEMP_5_ADC() -1
|
||||
#endif
|
||||
#if HAS_HEATED_BED
|
||||
#define GET_BED_ADC() PIN_TO_ADC(TEMP_BED_PIN)
|
||||
#else
|
||||
#define GET_BED_ADC() -1
|
||||
#endif
|
||||
#if HAS_HEATED_CHAMBER
|
||||
#define GET_CHAMBER_ADC() PIN_TO_ADC(TEMP_CHAMBER_PIN)
|
||||
#else
|
||||
#define GET_CHAMBER_ADC() -1
|
||||
#endif
|
||||
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
||||
#define GET_FILAMENT_WIDTH_ADC() PIN_TO_ADC(FILWIDTH_PIN)
|
||||
#else
|
||||
#define GET_FILAMENT_WIDTH_ADC() -1
|
||||
#endif
|
||||
#if HAS_ADC_BUTTONS
|
||||
#define GET_BUTTONS_ADC() PIN_TO_ADC(ADC_KEYPAD_PIN)
|
||||
#else
|
||||
#define GET_BUTTONS_ADC() -1
|
||||
#endif
|
||||
|
||||
#define IS_ADC_REQUIRED(n) (GET_TEMP_0_ADC() == n || GET_TEMP_1_ADC() == n || GET_TEMP_2_ADC() == n \
|
||||
|| GET_TEMP_3_ADC() == n || GET_TEMP_4_ADC() == n || GET_TEMP_5_ADC() == n \
|
||||
|| GET_BED_ADC() == n \
|
||||
|| GET_CHAMBER_ADC() == n \
|
||||
|| GET_FILAMENT_WIDTH_ADC() == n \
|
||||
|| GET_BUTTONS_ADC() == n)
|
||||
|
||||
#define ADC0_IS_REQUIRED IS_ADC_REQUIRED(0)
|
||||
#define ADC1_IS_REQUIRED IS_ADC_REQUIRED(1)
|
||||
#define ADC_IS_REQUIRED (ADC0_IS_REQUIRED || ADC1_IS_REQUIRED)
|
||||
#if ADC0_IS_REQUIRED
|
||||
#define FIRST_ADC 0
|
||||
#else
|
||||
#define FIRST_ADC 1
|
||||
#endif
|
||||
#if ADC1_IS_REQUIRED
|
||||
#define LAST_ADC 1
|
||||
#else
|
||||
#define LAST_ADC 0
|
||||
#endif
|
||||
|
||||
#define DMA_IS_REQUIRED ADC_IS_REQUIRED
|
||||
|
||||
// ------------------------
|
||||
// Types
|
||||
// ------------------------
|
||||
|
||||
#if DMA_IS_REQUIRED
|
||||
|
||||
// Struct must be 32 bits aligned because of DMA accesses but fields needs to be 8 bits packed
|
||||
typedef struct __attribute__((aligned(4), packed)) {
|
||||
ADC_INPUTCTRL_Type INPUTCTRL;
|
||||
} HAL_DMA_DAC_Registers; // DMA transfered registers
|
||||
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
// Private Variables
|
||||
// ------------------------
|
||||
|
||||
uint16_t HAL_adc_result;
|
||||
|
||||
#if ADC_IS_REQUIRED
|
||||
|
||||
// Pins used by ADC inputs. Order must be ADC0 inputs first then ADC1
|
||||
const uint8_t adc_pins[] = {
|
||||
// ADC0 pins
|
||||
#if GET_TEMP_0_ADC() == 0
|
||||
TEMP_0_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_1_ADC() == 0
|
||||
TEMP_1_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_2_ADC() == 0
|
||||
TEMP_2_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_3_ADC() == 0
|
||||
TEMP_3_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_4_ADC() == 0
|
||||
TEMP_4_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_5_ADC() == 0
|
||||
TEMP_5_PIN,
|
||||
#endif
|
||||
#if GET_BED_ADC() == 0
|
||||
TEMP_BED_PIN,
|
||||
#endif
|
||||
#if GET_CHAMBER_ADC() == 0
|
||||
TEMP_CHAMBER_PIN,
|
||||
#endif
|
||||
#if GET_FILAMENT_WIDTH_ADC() == 0
|
||||
FILWIDTH_PIN,
|
||||
#endif
|
||||
#if GET_BUTTONS_ADC() == 0
|
||||
ADC_KEYPAD_PIN,
|
||||
#endif
|
||||
// ADC1 pins
|
||||
#if GET_TEMP_0_ADC() == 1
|
||||
TEMP_0_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_1_ADC() == 1
|
||||
TEMP_1_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_2_ADC() == 1
|
||||
TEMP_2_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_3_ADC() == 1
|
||||
TEMP_3_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_4_ADC() == 1
|
||||
TEMP_4_PIN,
|
||||
#endif
|
||||
#if GET_TEMP_5_ADC() == 1
|
||||
TEMP_5_PIN,
|
||||
#endif
|
||||
#if GET_BED_ADC() == 1
|
||||
TEMP_BED_PIN,
|
||||
#endif
|
||||
#if GET_CHAMBER_ADC() == 1
|
||||
TEMP_CHAMBER_PIN,
|
||||
#endif
|
||||
#if GET_FILAMENT_WIDTH_ADC() == 1
|
||||
FILWIDTH_PIN,
|
||||
#endif
|
||||
#if GET_BUTTONS_ADC() == 1
|
||||
ADC_KEYPAD_PIN,
|
||||
#endif
|
||||
};
|
||||
|
||||
uint16_t HAL_adc_results[COUNT(adc_pins)];
|
||||
|
||||
#if ADC0_IS_REQUIRED
|
||||
Adafruit_ZeroDMA adc0ProgramDMA,
|
||||
adc0ReadDMA;
|
||||
|
||||
const HAL_DMA_DAC_Registers adc0_dma_regs_list[] = {
|
||||
#if GET_TEMP_0_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_0_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_1_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_1_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_2_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_2_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_3_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_3_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_4_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_4_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_5_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_5_PIN) },
|
||||
#endif
|
||||
#if GET_BED_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_BED_PIN) },
|
||||
#endif
|
||||
#if GET_CHAMBER_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
|
||||
#endif
|
||||
#if GET_FILAMENT_WIDTH_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
|
||||
#endif
|
||||
#if GET_BUTTONS_ADC() == 0
|
||||
{ PIN_TO_INPUTCTRL(ADC_KEYPAD_PIN) },
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ADC0_AINCOUNT COUNT(adc0_dma_regs_list)
|
||||
#endif // ADC0_IS_REQUIRED
|
||||
|
||||
#if ADC1_IS_REQUIRED
|
||||
Adafruit_ZeroDMA adc1ProgramDMA,
|
||||
adc1ReadDMA;
|
||||
|
||||
const HAL_DMA_DAC_Registers adc1_dma_regs_list[] = {
|
||||
#if GET_TEMP_0_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_0_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_1_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_1_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_2_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_2_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_3_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_3_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_4_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_4_PIN) },
|
||||
#endif
|
||||
#if GET_TEMP_5_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_5_PIN) },
|
||||
#endif
|
||||
#if GET_BED_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_BED_PIN) },
|
||||
#endif
|
||||
#if GET_CHAMBER_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(TEMP_CHAMBER_PIN) },
|
||||
#endif
|
||||
#if GET_FILAMENT_WIDTH_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(FILWIDTH_PIN) },
|
||||
#endif
|
||||
#if GET_BUTTONS_ADC() == 1
|
||||
{ PIN_TO_INPUTCTRL(ADC_KEYPAD_PIN) },
|
||||
#endif
|
||||
};
|
||||
|
||||
#define ADC1_AINCOUNT COUNT(adc1_dma_regs_list)
|
||||
#endif // ADC1_IS_REQUIRED
|
||||
|
||||
#endif // ADC_IS_REQUIRED
|
||||
|
||||
// ------------------------
|
||||
// Private functions
|
||||
// ------------------------
|
||||
|
||||
#if DMA_IS_REQUIRED
|
||||
|
||||
void dma_init() {
|
||||
DmacDescriptor *descriptor;
|
||||
|
||||
#if ADC0_IS_REQUIRED
|
||||
adc0ProgramDMA.setTrigger(ADC0_DMAC_ID_SEQ);
|
||||
adc0ProgramDMA.setAction(DMA_TRIGGER_ACTON_BEAT);
|
||||
adc0ProgramDMA.loop(true);
|
||||
if (adc0ProgramDMA.allocate() == DMA_STATUS_OK) {
|
||||
descriptor = adc0ProgramDMA.addDescriptor(
|
||||
(void *)adc0_dma_regs_list, // SRC
|
||||
(void *)&ADC0->DSEQDATA.reg, // DEST
|
||||
sizeof(adc0_dma_regs_list) / 4, // CNT
|
||||
DMA_BEAT_SIZE_WORD,
|
||||
true, // SRCINC
|
||||
false, // DSTINC
|
||||
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
|
||||
DMA_STEPSEL_SRC // STEPSEL
|
||||
);
|
||||
if (descriptor != nullptr)
|
||||
descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
|
||||
adc0ProgramDMA.startJob();
|
||||
}
|
||||
|
||||
adc0ReadDMA.setTrigger(ADC0_DMAC_ID_RESRDY);
|
||||
adc0ReadDMA.setAction(DMA_TRIGGER_ACTON_BEAT);
|
||||
adc0ReadDMA.loop(true);
|
||||
if (adc0ReadDMA.allocate() == DMA_STATUS_OK) {
|
||||
adc0ReadDMA.addDescriptor(
|
||||
(void *)&ADC0->RESULT.reg, // SRC
|
||||
&HAL_adc_results, // DEST
|
||||
ADC0_AINCOUNT, // CNT
|
||||
DMA_BEAT_SIZE_HWORD,
|
||||
false, // SRCINC
|
||||
true, // DSTINC
|
||||
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
|
||||
DMA_STEPSEL_DST // STEPSEL
|
||||
);
|
||||
adc0ReadDMA.startJob();
|
||||
}
|
||||
#endif
|
||||
#if ADC1_IS_REQUIRED
|
||||
adc1ProgramDMA.setTrigger(ADC1_DMAC_ID_SEQ);
|
||||
adc1ProgramDMA.setAction(DMA_TRIGGER_ACTON_BEAT);
|
||||
adc1ProgramDMA.loop(true);
|
||||
if (adc1ProgramDMA.allocate() == DMA_STATUS_OK) {
|
||||
descriptor = adc1ProgramDMA.addDescriptor(
|
||||
(void *)adc1_dma_regs_list, // SRC
|
||||
(void *)&ADC1->DSEQDATA.reg, // DEST
|
||||
sizeof(adc1_dma_regs_list) / 4, // CNT
|
||||
DMA_BEAT_SIZE_WORD,
|
||||
true, // SRCINC
|
||||
false, // DSTINC
|
||||
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
|
||||
DMA_STEPSEL_SRC // STEPSEL
|
||||
);
|
||||
if (descriptor != nullptr)
|
||||
descriptor->BTCTRL.bit.EVOSEL = DMA_EVENT_OUTPUT_BEAT;
|
||||
adc1ProgramDMA.startJob();
|
||||
}
|
||||
|
||||
adc1ReadDMA.setTrigger(ADC1_DMAC_ID_RESRDY);
|
||||
adc1ReadDMA.setAction(DMA_TRIGGER_ACTON_BEAT);
|
||||
adc1ReadDMA.loop(true);
|
||||
if (adc1ReadDMA.allocate() == DMA_STATUS_OK) {
|
||||
adc1ReadDMA.addDescriptor(
|
||||
(void *)&ADC1->RESULT.reg, // SRC
|
||||
&HAL_adc_results[ADC0_AINCOUNT], // DEST
|
||||
ADC1_AINCOUNT, // CNT
|
||||
DMA_BEAT_SIZE_HWORD,
|
||||
false, // SRCINC
|
||||
true, // DSTINC
|
||||
DMA_ADDRESS_INCREMENT_STEP_SIZE_1, // STEPSIZE
|
||||
DMA_STEPSEL_DST // STEPSEL
|
||||
);
|
||||
adc1ReadDMA.startJob();
|
||||
}
|
||||
#endif
|
||||
|
||||
DMAC->PRICTRL0.bit.RRLVLEN0 = true; // Activate round robin for DMA channels used by ADCs
|
||||
}
|
||||
|
||||
#endif // DMA_IS_REQUIRED
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
// HAL initialization task
|
||||
void HAL_init(void) {
|
||||
#if DMA_IS_REQUIRED
|
||||
dma_init();
|
||||
#endif
|
||||
#if ENABLED(SDSUPPORT)
|
||||
#if SD_CONNECTION_IS(ONBOARD) && PIN_EXISTS(SD_DETECT) // SD_DETECT_PIN may be remove when NO_SD_HOST_DRIVE is not defined in configuration_adv
|
||||
SET_INPUT_PULLUP(SD_DETECT_PIN);
|
||||
#endif
|
||||
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
|
||||
#endif
|
||||
}
|
||||
|
||||
// HAL idle task
|
||||
/*
|
||||
void HAL_idletask(void) {
|
||||
}
|
||||
*/
|
||||
|
||||
void HAL_clear_reset_source(void) { }
|
||||
|
||||
#pragma push_macro("WDT")
|
||||
#undef WDT // Required to be able to use '.bit.WDT'. Compiler wrongly replace struct field with WDT define
|
||||
uint8_t HAL_get_reset_source(void) {
|
||||
RSTC_RCAUSE_Type resetCause;
|
||||
|
||||
resetCause.reg = REG_RSTC_RCAUSE;
|
||||
if (resetCause.bit.POR) return RST_POWER_ON;
|
||||
else if (resetCause.bit.EXT) return RST_EXTERNAL;
|
||||
else if (resetCause.bit.BODCORE || resetCause.bit.BODVDD) return RST_BROWN_OUT;
|
||||
else if (resetCause.bit.WDT) return RST_WATCHDOG;
|
||||
else if (resetCause.bit.SYST || resetCause.bit.NVM) return RST_SOFTWARE;
|
||||
else if (resetCause.bit.BACKUP) return RST_BACKUP;
|
||||
return 0;
|
||||
}
|
||||
#pragma pop_macro("WDT")
|
||||
|
||||
extern "C" {
|
||||
void * _sbrk(int incr);
|
||||
|
||||
extern unsigned int __bss_end__; // end of bss section
|
||||
}
|
||||
|
||||
// Return free memory between end of heap (or end bss) and whatever is current
|
||||
int freeMemory() {
|
||||
int free_memory, heap_end = (int)_sbrk(0);
|
||||
return (int)&free_memory - (heap_end ? heap_end : (int)&__bss_end__);
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// ADC
|
||||
// ------------------------
|
||||
|
||||
void HAL_adc_init(void) {
|
||||
#if ADC_IS_REQUIRED
|
||||
memset(HAL_adc_results, 0xFF, sizeof(HAL_adc_results)); // Fill result with invalid values
|
||||
|
||||
for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi)
|
||||
pinPeripheral(adc_pins[pi], PIO_ANALOG);
|
||||
|
||||
for (uint8_t ai = FIRST_ADC; ai <= LAST_ADC; ++ai) {
|
||||
Adc* adc = ((Adc*[])ADC_INSTS)[ai];
|
||||
|
||||
// ADC clock setup
|
||||
GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN = false;
|
||||
SYNC(GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN);
|
||||
GCLK->PCHCTRL[ADC0_GCLK_ID + ai].reg = GCLK_PCHCTRL_GEN_GCLK1 | GCLK_PCHCTRL_CHEN; // 48MHz startup code programmed
|
||||
SYNC(!GCLK->PCHCTRL[ADC0_GCLK_ID + ai].bit.CHEN);
|
||||
adc->CTRLA.bit.PRESCALER = ADC_CTRLA_PRESCALER_DIV32_Val; // 1.5MHZ adc clock
|
||||
|
||||
// ADC setup
|
||||
// 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_10BIT_Val;
|
||||
SYNC(adc->SYNCBUSY.bit.CTRLB);
|
||||
adc->SAMPCTRL.bit.SAMPLEN = (6 - 1); // Sampling clocks
|
||||
// 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
|
||||
SYNC(adc->SYNCBUSY.bit.ENABLE);
|
||||
}
|
||||
#endif // ADC_IS_REQUIRED
|
||||
}
|
||||
|
||||
void HAL_adc_start_conversion(const uint8_t adc_pin) {
|
||||
#if ADC_IS_REQUIRED
|
||||
for (uint8_t pi = 0; pi < COUNT(adc_pins); ++pi) {
|
||||
if (adc_pin == adc_pins[pi]) {
|
||||
HAL_adc_result = HAL_adc_results[pi];
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
HAL_adc_result = 0xFFFF;
|
||||
}
|
||||
|
||||
uint16_t HAL_adc_get_result(void) {
|
||||
return HAL_adc_result;
|
||||
}
|
||||
|
||||
#endif // __SAMD51__
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define CPU_32_BIT
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/math_32bit.h"
|
||||
#include "../shared/HAL_SPI.h"
|
||||
#include "fastio_SAMD51.h"
|
||||
#include "watchdog_SAMD51.h"
|
||||
#include "HAL_timers_SAMD51.h"
|
||||
|
||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||
#include "MarlinSerial_AGCM4.h"
|
||||
|
||||
// Serial ports
|
||||
#if !WITHIN(SERIAL_PORT, -1, 3)
|
||||
#error "SERIAL_PORT must be from -1 to 3"
|
||||
#endif
|
||||
|
||||
// MYSERIAL0 required before MarlinSerial includes!
|
||||
#if SERIAL_PORT == -1
|
||||
#define MYSERIAL0 Serial
|
||||
#elif SERIAL_PORT == 0
|
||||
#define MYSERIAL0 Serial1
|
||||
#elif SERIAL_PORT == 1
|
||||
#define MYSERIAL0 Serial2
|
||||
#elif SERIAL_PORT == 2
|
||||
#define MYSERIAL0 Serial3
|
||||
#else
|
||||
#define MYSERIAL0 Serial4
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_PORT_2
|
||||
#if !WITHIN(SERIAL_PORT_2, -1, 3)
|
||||
#error "SERIAL_PORT_2 must be from -1 to 3"
|
||||
#elif SERIAL_PORT_2 == SERIAL_PORT
|
||||
#error "SERIAL_PORT_2 must be different than SERIAL_PORT"
|
||||
#endif
|
||||
#define NUM_SERIAL 2
|
||||
#if SERIAL_PORT_2 == -1
|
||||
#define MYSERIAL1 Serial
|
||||
#elif SERIAL_PORT_2 == 0
|
||||
#define MYSERIAL1 Serial1
|
||||
#elif SERIAL_PORT_2 == 1
|
||||
#define MYSERIAL1 Serial2
|
||||
#elif SERIAL_PORT_2 == 2
|
||||
#define MYSERIAL1 Serial3
|
||||
#else
|
||||
#define MYSERIAL1 Serial4
|
||||
#endif
|
||||
#else
|
||||
#define NUM_SERIAL 1
|
||||
#endif
|
||||
|
||||
#endif // ADAFRUIT_GRAND_CENTRAL_M4
|
||||
|
||||
typedef int8_t pin_t;
|
||||
|
||||
//#define HAL_SERVO_LIB Servo
|
||||
|
||||
//
|
||||
// Interrupts
|
||||
//
|
||||
#define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||
#define CRITICAL_SECTION_END if (!primask) __enable_irq()
|
||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||
#define ENABLE_ISRS() __enable_irq()
|
||||
#define DISABLE_ISRS() __disable_irq()
|
||||
|
||||
#define cli() __disable_irq() // Disable interrupts
|
||||
#define sei() __enable_irq() // Enable interrupts
|
||||
|
||||
void HAL_clear_reset_source(void); // clear reset reason
|
||||
uint8_t HAL_get_reset_source(void); // get reset reason
|
||||
|
||||
//
|
||||
// EEPROM
|
||||
//
|
||||
void eeprom_write_byte(uint8_t *pos, unsigned char value);
|
||||
uint8_t eeprom_read_byte(uint8_t *pos);
|
||||
|
||||
//
|
||||
// ADC
|
||||
//
|
||||
extern uint16_t HAL_adc_result; // result of last ADC conversion
|
||||
|
||||
#define HAL_ANALOG_SELECT(pin)
|
||||
|
||||
void HAL_adc_init(void);
|
||||
|
||||
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
void HAL_adc_start_conversion(const uint8_t adc_pin);
|
||||
uint16_t HAL_adc_get_result(void);
|
||||
|
||||
//
|
||||
// Pin Map
|
||||
//
|
||||
#define GET_PIN_MAP_PIN(index) index
|
||||
#define GET_PIN_MAP_INDEX(pin) pin
|
||||
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
|
||||
|
||||
//
|
||||
// Tone
|
||||
//
|
||||
void toneInit();
|
||||
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
|
||||
void noTone(const pin_t _pin);
|
||||
|
||||
// Enable hooks into idle and setup for HAL
|
||||
void HAL_init(void);
|
||||
/*#define HAL_IDLETASK 1
|
||||
void HAL_idletask(void);*/
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
|
||||
int freeMemory(void);
|
||||
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hardware and software SPI implementations are included in this file.
|
||||
*
|
||||
* Control of the slave select pin(s) is handled by the calling routines and
|
||||
* SAMD51 let hardware SPI handling to remove SS from its logic.
|
||||
*/
|
||||
|
||||
#ifdef __SAMD51__
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include <SPI.h>
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#if EITHER(SOFTWARE_SPI, FORCE_SOFT_SPI)
|
||||
|
||||
// ------------------------
|
||||
// Software SPI
|
||||
// ------------------------
|
||||
#error "Software SPI not supported for SAMD51. Use Hardware SPI."
|
||||
|
||||
#if SD_CONNECTION_IS(ONBOARD)
|
||||
#endif
|
||||
|
||||
#else // !SOFTWARE_SPI
|
||||
|
||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||
#if SD_CONNECTION_IS(ONBOARD)
|
||||
#define sdSPI SDCARD_SPI
|
||||
#else
|
||||
#define sdSPI SPI
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static SPISettings spiConfig;
|
||||
|
||||
// ------------------------
|
||||
// Hardware SPI
|
||||
// ------------------------
|
||||
void spiBegin(void) {
|
||||
spiInit(SPI_HALF_SPEED);
|
||||
}
|
||||
|
||||
void spiInit(uint8_t spiRate) {
|
||||
// Use datarates Marlin uses
|
||||
uint32_t clock;
|
||||
switch (spiRate) {
|
||||
case SPI_FULL_SPEED: clock = 8000000; break;
|
||||
case SPI_HALF_SPEED: clock = 4000000; break;
|
||||
case SPI_QUARTER_SPEED: clock = 2000000; break;
|
||||
case SPI_EIGHTH_SPEED: clock = 1000000; break;
|
||||
case SPI_SIXTEENTH_SPEED: clock = 500000; break;
|
||||
case SPI_SPEED_5: clock = 250000; break;
|
||||
case SPI_SPEED_6: clock = 125000; break;
|
||||
default: clock = 4000000; break; // Default from the SPI library
|
||||
}
|
||||
spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
|
||||
sdSPI.begin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receives a single byte from the SPI port.
|
||||
*
|
||||
* @return Byte received
|
||||
*
|
||||
* @details
|
||||
*/
|
||||
uint8_t spiRec(void) {
|
||||
sdSPI.beginTransaction(spiConfig);
|
||||
uint8_t returnByte = sdSPI.transfer(0xFF);
|
||||
sdSPI.endTransaction();
|
||||
return returnByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receives a number of bytes from the SPI port to a buffer
|
||||
*
|
||||
* @param buf Pointer to starting address of buffer to write to.
|
||||
* @param nbyte Number of bytes to receive.
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sends a single byte on SPI port
|
||||
*
|
||||
* @param b Byte to send
|
||||
*
|
||||
* @details
|
||||
*/
|
||||
void spiSend(uint8_t b) {
|
||||
sdSPI.beginTransaction(spiConfig);
|
||||
sdSPI.transfer(b);
|
||||
sdSPI.endTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write token and then write from 512 byte buffer to SPI (for SD card)
|
||||
*
|
||||
* @param buf Pointer with buffer start address
|
||||
* @return Nothing
|
||||
*
|
||||
* @details Uses DMA
|
||||
*/
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
sdSPI.beginTransaction(spiConfig);
|
||||
sdSPI.transfer(token);
|
||||
sdSPI.transfer((uint8_t*)buf, nullptr, 512);
|
||||
sdSPI.endTransaction();
|
||||
}
|
||||
|
||||
void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
|
||||
spiConfig = SPISettings(spiClock, (BitOrder)bitOrder, dataMode);
|
||||
sdSPI.beginTransaction(spiConfig);
|
||||
}
|
||||
#endif // !SOFTWARE_SPI
|
||||
|
||||
#endif // __SAMD51__
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SAMD51__
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Includes
|
||||
// --------------------------------------------------------------------------
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL_timers_SAMD51.h"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Local defines
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#define NUM_HARDWARE_TIMERS 8
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Private Variables
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
const tTimerConfig TimerConfig[NUM_HARDWARE_TIMERS] = {
|
||||
{ TC0, TC0_IRQn, TC_PRIORITY(0) },
|
||||
{ TC1, TC1_IRQn, TC_PRIORITY(1) },
|
||||
{ TC2, TC2_IRQn, TC_PRIORITY(2) },
|
||||
{ TC3, TC3_IRQn, TC_PRIORITY(3) },
|
||||
{ TC4, TC4_IRQn, TC_PRIORITY(4) },
|
||||
{ TC5, TC5_IRQn, TC_PRIORITY(5) },
|
||||
{ TC6, TC6_IRQn, TC_PRIORITY(6) },
|
||||
{ TC7, TC7_IRQn, TC_PRIORITY(7) }
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Private functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
FORCE_INLINE void Disable_Irq(IRQn_Type irq) {
|
||||
NVIC_DisableIRQ(irq);
|
||||
|
||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
Tc * const tc = TimerConfig[timer_num].pTimer;
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
|
||||
// Disable interrupt, just in case it was already enabled
|
||||
Disable_Irq(irq);
|
||||
|
||||
// Disable timer interrupt
|
||||
tc->COUNT32.INTENCLR.reg = TC_INTENCLR_OVF; // disable overflow interrupt
|
||||
|
||||
// TCn clock setup
|
||||
const uint8_t clockID = GCLK_CLKCTRL_IDs[TCC_INST_NUM + timer_num];
|
||||
GCLK->PCHCTRL[clockID].bit.CHEN = false;
|
||||
SYNC(GCLK->PCHCTRL[clockID].bit.CHEN);
|
||||
GCLK->PCHCTRL[clockID].reg = GCLK_PCHCTRL_GEN_GCLK0 | GCLK_PCHCTRL_CHEN; // 120MHz startup code programmed
|
||||
SYNC(!GCLK->PCHCTRL[clockID].bit.CHEN);
|
||||
|
||||
// Stop timer, just in case, to be able to reconfigure it
|
||||
tc->COUNT32.CTRLA.bit.ENABLE = false;
|
||||
SYNC(tc->COUNT32.SYNCBUSY.bit.ENABLE);
|
||||
|
||||
// Reset timer
|
||||
tc->COUNT32.CTRLA.bit.SWRST = true;
|
||||
SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
|
||||
|
||||
NVIC_SetPriority(irq, TimerConfig[timer_num].priority);
|
||||
|
||||
// Wave mode, reset counter on overflow on 0 (I use count down to prevent double buffer use)
|
||||
tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
|
||||
tc->COUNT32.CTRLA.reg = TC_CTRLA_MODE_COUNT32 | TC_CTRLA_PRESCALER_DIV1;
|
||||
tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_DIR;
|
||||
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
|
||||
|
||||
// Set compare value
|
||||
tc->COUNT32.COUNT.reg = tc->COUNT32.CC[0].reg = HAL_TIMER_RATE / frequency;
|
||||
|
||||
// And start timer
|
||||
tc->COUNT32.CTRLA.bit.ENABLE = true;
|
||||
SYNC(tc->COUNT32.SYNCBUSY.bit.ENABLE);
|
||||
|
||||
// Enable interrupt on RC compare
|
||||
tc->COUNT32.INTENSET.reg = TC_INTENCLR_OVF; // enable overflow interrupt
|
||||
|
||||
// Finally, enable IRQ
|
||||
NVIC_EnableIRQ(irq);
|
||||
}
|
||||
|
||||
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
NVIC_EnableIRQ(irq);
|
||||
}
|
||||
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
Disable_Irq(irq);
|
||||
}
|
||||
|
||||
// missing from CMSIS: Check if interrupt is enabled or not
|
||||
static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
|
||||
return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0;
|
||||
}
|
||||
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
return NVIC_GetEnabledIRQ(irq);
|
||||
}
|
||||
|
||||
#endif // __SAMD51__
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Defines
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
typedef uint32_t hal_timer_t;
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
|
||||
|
||||
#define HAL_TIMER_RATE SystemCoreClock // frequency of timers peripherals
|
||||
|
||||
#define STEP_TIMER_NUM 0 // index of timer to use for stepper (also +1 for 32bits counter)
|
||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||
#define TONE_TIMER_NUM 2 // index of timer to use for beeper tones (also +1 for 32bits counter)
|
||||
#define TEMP_TIMER_NUM 4 // index of timer to use for temperature (also +1 for 32bits counter)
|
||||
|
||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||
|
||||
#define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
||||
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
||||
#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
|
||||
|
||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
||||
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
|
||||
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
|
||||
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||
|
||||
#define TC_PRIORITY(t) (t == STEP_TIMER_NUM || t == PULSE_TIMER_NUM) ? 2 \
|
||||
: (t == TEMP_TIMER_NUM) ? 6 \
|
||||
: (t == TONE_TIMER_NUM) ? 5 : 7
|
||||
#define _TC_HANDLER(t) void TC##t##_Handler()
|
||||
#define TC_HANDLER(t) _TC_HANDLER(t)
|
||||
#define HAL_STEP_TIMER_ISR() TC_HANDLER(STEP_TIMER_NUM)
|
||||
#if STEP_TIMER_NUM != PULSE_TIMER_NUM
|
||||
#define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
|
||||
#endif
|
||||
#define HAL_TEMP_TIMER_ISR() TC_HANDLER(TEMP_TIMER_NUM)
|
||||
#define HAL_TONE_TIMER_ISR() TC_HANDLER(TONE_TIMER_NUM)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Types
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
typedef struct {
|
||||
Tc *pTimer;
|
||||
IRQn_Type IRQ_Id;
|
||||
uint8_t priority;
|
||||
} tTimerConfig;
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public Variables
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
extern const tTimerConfig TimerConfig[];
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Public functions
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
|
||||
|
||||
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
|
||||
Tc * const tc = TimerConfig[timer_num].pTimer;
|
||||
tc->COUNT32.CC[0].reg = HAL_TIMER_TYPE_MAX - compare;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
Tc * const tc = TimerConfig[timer_num].pTimer;
|
||||
return (hal_timer_t)(HAL_TIMER_TYPE_MAX - tc->COUNT32.CC[0].reg);
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
Tc * const tc = TimerConfig[timer_num].pTimer;
|
||||
tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
|
||||
SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
|
||||
return HAL_TIMER_TYPE_MAX - tc->COUNT32.COUNT.reg;
|
||||
}
|
||||
|
||||
void HAL_timer_enable_interrupt(const uint8_t timer_num);
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num);
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
|
||||
|
||||
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
||||
Tc * const tc = TimerConfig[timer_num].pTimer;
|
||||
// Clear interrupt flag
|
||||
tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF;
|
||||
}
|
||||
|
||||
#define HAL_timer_isr_epilogue(timer_num)
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||
|
||||
/**
|
||||
* Framework doesn't define some serial to save sercom resources
|
||||
* hence if these are used I need to define them
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if SERIAL_PORT == 1 || SERIAL_PORT_2 == 1
|
||||
Uart Serial2(&sercom4, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
|
||||
void SERCOM4_0_Handler() { Serial2.IrqHandler(); }
|
||||
void SERCOM4_1_Handler() { Serial2.IrqHandler(); }
|
||||
void SERCOM4_2_Handler() { Serial2.IrqHandler(); }
|
||||
void SERCOM4_3_Handler() { Serial2.IrqHandler(); }
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 2 || SERIAL_PORT_2 == 2
|
||||
Uart Serial3(&sercom1, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);
|
||||
void SERCOM1_0_Handler() { Serial3.IrqHandler(); }
|
||||
void SERCOM1_1_Handler() { Serial3.IrqHandler(); }
|
||||
void SERCOM1_2_Handler() { Serial3.IrqHandler(); }
|
||||
void SERCOM1_3_Handler() { Serial3.IrqHandler(); }
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT == 3 || SERIAL_PORT_2 == 3
|
||||
Uart Serial4(&sercom5, PIN_SERIAL4_RX, PIN_SERIAL4_TX, PAD_SERIAL4_RX, PAD_SERIAL4_TX);
|
||||
void SERCOM5_0_Handler() { Serial4.IrqHandler(); }
|
||||
void SERCOM5_1_Handler() { Serial4.IrqHandler(); }
|
||||
void SERCOM5_2_Handler() { Serial4.IrqHandler(); }
|
||||
void SERCOM5_3_Handler() { Serial4.IrqHandler(); }
|
||||
#endif
|
||||
|
||||
#endif // ADAFRUIT_GRAND_CENTRAL_M4
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
extern Uart Serial2;
|
||||
extern Uart Serial3;
|
||||
extern Uart Serial4;
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define SYNC(sc) while (sc) { \
|
||||
asm(""); \
|
||||
}
|
||||
|
||||
// Get SAMD port/pin from specified arduino pin
|
||||
#define GET_SAMD_PORT(P) _GET_SAMD_PORT(PIN_TO_SAMD_PIN(P))
|
||||
#define GET_SAMD_PIN(P) _GET_SAMD_PIN(PIN_TO_SAMD_PIN(P))
|
||||
|
||||
// Get external interrupt line associated to specified arduino pin
|
||||
#define PIN_TO_EILINE(P) _SAMDPORTPIN_TO_EILINE(GET_SAMD_PORT(P), GET_SAMD_PIN(P))
|
||||
|
||||
// Get adc/ain associated to specified arduino pin
|
||||
#define PIN_TO_ADC(P) (ANAPIN_TO_ADCAIN(P) >> 8)
|
||||
#define PIN_TO_AIN(P) (ANAPIN_TO_ADCAIN(P) & 0xFF)
|
||||
|
||||
// Private defines
|
||||
#define PIN_TO_SAMD_PIN(P) DIO##P##_PIN
|
||||
|
||||
#define _GET_SAMD_PORT(P) ((P) >> 5)
|
||||
#define _GET_SAMD_PIN(P) ((P) & 0x1F)
|
||||
|
||||
// Get external interrupt line
|
||||
#define _SAMDPORTPIN_TO_EILINE(P,B) ((P == 0 && WITHIN(B, 0, 31) && B != 8 && B != 26 && B != 28 && B != 29) ? (B) & 0xF \
|
||||
: (P == 1 && (WITHIN(B, 0, 25) || WITHIN(B, 30, 31))) ? (B) & 0xF \
|
||||
: (P == 1 && WITHIN(B, 26, 29)) ? 12 + (B) - 26 \
|
||||
: (P == 2 && (WITHIN(B, 0, 6) || WITHIN(B, 10, 31)) && B != 29) ? (B) & 0xF \
|
||||
: (P == 2 && B == 7) ? 9 \
|
||||
: (P == 3 && WITHIN(B, 0, 1)) ? (B) \
|
||||
: (P == 3 && WITHIN(B, 8, 12)) ? 3 + (B) - 8 \
|
||||
: (P == 3 && WITHIN(B, 20, 21)) ? 10 + (B) - 20 \
|
||||
: -1)
|
||||
|
||||
// Get adc/ain
|
||||
#define ANAPIN_TO_ADCAIN(P) _PIN_TO_ADCAIN(ANAPIN_TO_SAMDPIN(P))
|
||||
#define _PIN_TO_ADCAIN(P) _SAMDPORTPIN_TO_ADCAIN(_GET_SAMD_PORT(P), _GET_SAMD_PIN(P))
|
||||
|
||||
#define _SAMDPORTPIN_TO_ADCAIN(P,B) ((P == 0 && WITHIN(B, 2, 3)) ? 0x000 + (B) - 2 \
|
||||
: (P == 0 && WITHIN(B, 4, 7)) ? 0x000 + (B) \
|
||||
: (P == 0 && WITHIN(B, 8, 9)) ? 0x100 + 2 + (B) - 8 \
|
||||
: (P == 0 && WITHIN(B, 10, 11)) ? 0x000 + (B) \
|
||||
: (P == 1 && WITHIN(B, 0, 3)) ? 0x000 + 12 + (B) \
|
||||
: (P == 1 && WITHIN(B, 4, 7)) ? 0x100 + 6 + (B) - 4 \
|
||||
: (P == 1 && WITHIN(B, 8, 9)) ? 0x100 + (B) - 8 \
|
||||
: (P == 2 && WITHIN(B, 0, 1)) ? 0x100 + 10 + (B) \
|
||||
: (P == 2 && WITHIN(B, 2, 3)) ? 0x100 + 4 + (B) - 2 \
|
||||
: (P == 2 && WITHIN(B, 30, 31)) ? 0x100 + 12 + (B) - 30 \
|
||||
: (P == 3 && WITHIN(B, 0, 1)) ? 0x100 + 14 + (B) \
|
||||
: -1)
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: Tone function for Arduino Due and compatible (SAM3X8E)
|
||||
* Derived from http://forum.arduino.cc/index.php?topic=136500.msg2903012#msg2903012
|
||||
*/
|
||||
|
||||
#ifdef __SAMD51__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL_timers_SAMD51.h"
|
||||
|
||||
static pin_t tone_pin;
|
||||
volatile static int32_t toggles;
|
||||
|
||||
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration) {
|
||||
tone_pin = _pin;
|
||||
toggles = 2 * frequency * duration / 1000;
|
||||
HAL_timer_start(TONE_TIMER_NUM, 2 * frequency);
|
||||
}
|
||||
|
||||
void noTone(const pin_t _pin) {
|
||||
HAL_timer_disable_interrupt(TONE_TIMER_NUM);
|
||||
extDigitalWrite(_pin, LOW);
|
||||
}
|
||||
|
||||
HAL_TONE_TIMER_ISR() {
|
||||
static bool pin_state = false;
|
||||
HAL_timer_isr_prologue(TONE_TIMER_NUM);
|
||||
|
||||
if (toggles) {
|
||||
toggles--;
|
||||
extDigitalWrite(tone_pin, (pin_state = !pin_state));
|
||||
}
|
||||
else noTone(tone_pin); // turn off interrupt
|
||||
|
||||
HAL_timer_isr_epilogue(TONE_TIMER_NUM);
|
||||
}
|
||||
|
||||
#endif // __SAMD51__
|
||||
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Endstop interrupts for ATMEL SAMD51 based targets.
|
||||
*
|
||||
* On SAMD51, all pins support external interrupt capability.
|
||||
* Any pin can be used for external interrupts, but there are some restrictions.
|
||||
* At most 16 different external interrupts can be used at one time.
|
||||
* Further, you can’t just pick any 16 pins to use. This is because every pin on the SAMD51
|
||||
* connects to what is called an EXTINT line, and only one pin per EXTINT line can be used for external
|
||||
* interrupts at a time
|
||||
*/
|
||||
|
||||
/**
|
||||
* Endstop Interrupts
|
||||
*
|
||||
* Without endstop interrupts the endstop pins must be polled continually in
|
||||
* the temperature-ISR via endstops.update(), most of the time finding no change.
|
||||
* With this feature endstops.update() is called only when we know that at
|
||||
* least one endstop has changed state, saving valuable CPU cycles.
|
||||
*
|
||||
* This feature only works when all used endstop pins can generate an 'external interrupt'.
|
||||
*
|
||||
* Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
|
||||
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
|
||||
*/
|
||||
|
||||
#include "../../module/endstops.h"
|
||||
|
||||
#define MATCH_EILINE(P1,P2) (P1 != P2 && PIN_TO_EILINE(P1) == PIN_TO_EILINE(P2))
|
||||
#if HAS_X_MAX
|
||||
#define MATCH_X_MAX_EILINE(P) MATCH_EILINE(P, X_MAX_PIN)
|
||||
#else
|
||||
#define MATCH_X_MAX_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_X_MIN
|
||||
#define MATCH_X_MIN_EILINE(P) MATCH_EILINE(P, X_MIN_PIN)
|
||||
#else
|
||||
#define MATCH_X_MIN_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Y_MAX
|
||||
#define MATCH_Y_MAX_EILINE(P) MATCH_EILINE(P, Y_MAX_PIN)
|
||||
#else
|
||||
#define MATCH_Y_MAX_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Y_MIN
|
||||
#define MATCH_Y_MIN_EILINE(P) MATCH_EILINE(P, Y_MIN_PIN)
|
||||
#else
|
||||
#define MATCH_Y_MIN_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z_MAX
|
||||
#define MATCH_Z_MAX_EILINE(P) MATCH_EILINE(P, Z_MAX_PIN)
|
||||
#else
|
||||
#define MATCH_Z_MAX_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z_MIN
|
||||
#define MATCH_Z_MIN_EILINE(P) MATCH_EILINE(P, Z_MIN_PIN)
|
||||
#else
|
||||
#define MATCH_Z_MIN_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z2_MAX
|
||||
#define MATCH_Z2_MAX_EILINE(P) MATCH_EILINE(P, Z2_MAX_PIN)
|
||||
#else
|
||||
#define MATCH_Z2_MAX_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z2_MIN
|
||||
#define MATCH_Z2_MIN_EILINE(P) MATCH_EILINE(P, Z2_MIN_PIN)
|
||||
#else
|
||||
#define MATCH_Z2_MIN_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z3_MAX
|
||||
#define MATCH_Z3_MAX_EILINE(P) MATCH_EILINE(P, Z3_MAX_PIN)
|
||||
#else
|
||||
#define MATCH_Z3_MAX_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z3_MIN
|
||||
#define MATCH_Z3_MIN_EILINE(P) MATCH_EILINE(P, Z3_MIN_PIN)
|
||||
#else
|
||||
#define MATCH_Z3_MIN_EILINE(P) false
|
||||
#endif
|
||||
#if HAS_Z_MIN_PROBE_PIN
|
||||
#define MATCH_Z_MIN_PROBE_EILINE(P) MATCH_EILINE(P, Z_MIN_PROBE_PIN)
|
||||
#else
|
||||
#define MATCH_Z_MIN_PROBE_EILINE(P) false
|
||||
#endif
|
||||
#define AVAILABLE_EILINE(P) (PIN_TO_EILINE(P) != -1 \
|
||||
&& !MATCH_X_MAX_EILINE(P) && !MATCH_X_MIN_EILINE(P) \
|
||||
&& !MATCH_Y_MAX_EILINE(P) && !MATCH_Y_MIN_EILINE(P) \
|
||||
&& !MATCH_Z_MAX_EILINE(P) && !MATCH_Z_MIN_EILINE(P) \
|
||||
&& !MATCH_Z2_MAX_EILINE(P) && !MATCH_Z2_MIN_EILINE(P) \
|
||||
&& !MATCH_Z3_MAX_EILINE(P) && !MATCH_Z3_MIN_EILINE(P) \
|
||||
&& !MATCH_Z_MIN_PROBE_EILINE(P))
|
||||
|
||||
// One ISR for all EXT-Interrupts
|
||||
void endstop_ISR(void) { endstops.update(); }
|
||||
|
||||
void setup_endstop_interrupts(void) {
|
||||
#if HAS_X_MAX
|
||||
#if !AVAILABLE_EILINE(X_MAX_PIN)
|
||||
static_assert(false, "X_MAX_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_X_MIN
|
||||
#if !AVAILABLE_EILINE(X_MIN_PIN)
|
||||
static_assert(false, "X_MIN_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Y_MAX
|
||||
#if !AVAILABLE_EILINE(Y_MAX_PIN)
|
||||
static_assert(false, "Y_MAX_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Y_MIN
|
||||
#if !AVAILABLE_EILINE(Y_MIN_PIN)
|
||||
static_assert(false, "Y_MIN_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z_MAX
|
||||
#if !AVAILABLE_EILINE(Z_MAX_PIN)
|
||||
static_assert(false, "Z_MAX_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z_MIN
|
||||
#if !AVAILABLE_EILINE(Z_MIN_PIN)
|
||||
static_assert(false, "Z_MIN_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z2_MAX
|
||||
#if !AVAILABLE_EILINE(Z2_MAX_PIN)
|
||||
static_assert(false, "Z2_MAX_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z2_MIN
|
||||
#if !AVAILABLE_EILINE(Z2_MIN_PIN)
|
||||
static_assert(false, "Z2_MIN_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z3_MAX
|
||||
#if !AVAILABLE_EILINE(Z3_MAX_PIN)
|
||||
static_assert(false, "Z3_MAX_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z3_MIN
|
||||
#if !AVAILABLE_EILINE(Z3_MIN_PIN)
|
||||
static_assert(false, "Z3_MIN_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
#if HAS_Z_MIN_PROBE_PIN
|
||||
#if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
|
||||
static_assert(false, "Z_MIN_PROBE_PIN has no EXTINT line available.");
|
||||
#endif
|
||||
attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Fast IO functions for SAMD51
|
||||
*/
|
||||
|
||||
#include "SAMD51.h"
|
||||
|
||||
/**
|
||||
* Utility functions
|
||||
*/
|
||||
|
||||
#ifndef MASK
|
||||
#define MASK(PIN) (1 << PIN)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Magic I/O routines
|
||||
*
|
||||
* Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
|
||||
*/
|
||||
|
||||
// Read a pin
|
||||
#define READ(IO) ((PORT->Group[(EPortType)GET_SAMD_PORT(IO)].IN.reg & MASK(GET_SAMD_PIN(IO))) != 0)
|
||||
|
||||
// Write to a pin
|
||||
#define WRITE(IO,V) do{ \
|
||||
const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
|
||||
const uint32_t mask = MASK(GET_SAMD_PIN(IO)); \
|
||||
\
|
||||
if (V) PORT->Group[port].OUTSET.reg = mask; \
|
||||
else PORT->Group[port].OUTCLR.reg = mask; \
|
||||
}while(0)
|
||||
|
||||
// Toggle a pin
|
||||
#define TOGGLE(IO) PORT->Group[(EPortType)GET_SAMD_PORT(IO)].OUTTGL.reg = MASK(GET_SAMD_PIN(IO));
|
||||
|
||||
// Set pin as input
|
||||
#define SET_INPUT(IO) do{ \
|
||||
const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
|
||||
const uint32_t pin = GET_SAMD_PIN(IO); \
|
||||
\
|
||||
PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN); \
|
||||
PORT->Group[port].DIRCLR.reg = MASK(pin); \
|
||||
}while(0)
|
||||
// Set pin as input with pullup
|
||||
#define SET_INPUT_PULLUP(IO) do{ \
|
||||
const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
|
||||
const uint32_t pin = GET_SAMD_PIN(IO); \
|
||||
const uint32_t mask = MASK(pin); \
|
||||
\
|
||||
PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN | PORT_PINCFG_PULLEN); \
|
||||
PORT->Group[port].DIRCLR.reg = mask; \
|
||||
PORT->Group[port].OUTSET.reg = mask; \
|
||||
}while(0)
|
||||
// Set pin as input with pulldown
|
||||
#define SET_INPUT_PULLDOWN(IO) do{ \
|
||||
const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
|
||||
const uint32_t pin = GET_SAMD_PIN(IO); \
|
||||
const uint32_t mask = MASK(pin); \
|
||||
\
|
||||
PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN | PORT_PINCFG_PULLEN); \
|
||||
PORT->Group[port].DIRCLR.reg = mask; \
|
||||
PORT->Group[port].OUTCLR.reg = mask; \
|
||||
}while(0)
|
||||
// Set pin as output (push pull)
|
||||
#define SET_OUTPUT(IO) do{ \
|
||||
const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
|
||||
const uint32_t pin = GET_SAMD_PIN(IO); \
|
||||
\
|
||||
PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_INEN); \
|
||||
PORT->Group[port].DIRSET.reg = MASK(pin); \
|
||||
}while(0)
|
||||
// Set pin as output (open drain)
|
||||
#define SET_OUTPUT_OD(IO) do{ \
|
||||
const EPortType port = (EPortType)GET_SAMD_PORT(IO); \
|
||||
const uint32_t pin = GET_SAMD_PIN(IO); \
|
||||
\
|
||||
PORT->Group[port].PINCFG[pin].reg = (uint8_t)(PORT_PINCFG_PULLEN); \
|
||||
PORT->Group[port].DIRCLR.reg = MASK(pin); \
|
||||
}while(0)
|
||||
// Set pin as PWM (push pull)
|
||||
#define SET_PWM(IO) SET_OUTPUT(IO)
|
||||
// Set pin as PWM (open drain)
|
||||
#define SET_PWM_OD(IO) SET_OUTPUT_OD(IO)
|
||||
|
||||
// check if pin is an output
|
||||
#define IS_OUTPUT(IO) ((PORT->Group[(EPortType)GET_SAMD_PORT(IO)].DIR.reg & MASK(GET_SAMD_PIN(IO))) \
|
||||
|| (PORT->Group[(EPortType)GET_SAMD_PORT(IO)].PINCFG[GET_SAMD_PIN(IO)].reg & (PORT_PINCFG_INEN | PORT_PINCFG_PULLEN)) == PORT_PINCFG_PULLEN)
|
||||
// check if pin is an input
|
||||
#define IS_INPUT(IO) !IS_OUTPUT(IO)
|
||||
|
||||
// Shorthand
|
||||
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
||||
#define OUT_WRITE_OD(IO,V) do{ SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0)
|
||||
|
||||
// digitalRead/Write wrappers
|
||||
#define extDigitalRead(IO) digitalRead(IO)
|
||||
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|
||||
|
||||
/**
|
||||
* Ports and functions
|
||||
* Added as necessary or if I feel like it- not a comprehensive list!
|
||||
*/
|
||||
|
||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||
|
||||
/*
|
||||
* Adafruit Grand Central M4 has a lot of PWMs the availables are listed here.
|
||||
* Some of these share the same source and so can't be used in the same time
|
||||
*/
|
||||
#define PWM_PIN(P) (WITHIN(P, 2, 13) || WITHIN(P, 22, 23) || WITHIN(P, 44, 45) || P == 48)
|
||||
|
||||
// Return fullfilled ADCx->INPUTCTRL.reg
|
||||
#define PIN_TO_INPUTCTRL(P) ( (PIN_TO_AIN(P) == 0) ? ADC_INPUTCTRL_MUXPOS_AIN0 \
|
||||
: (PIN_TO_AIN(P) == 1) ? ADC_INPUTCTRL_MUXPOS_AIN1 \
|
||||
: (PIN_TO_AIN(P) == 2) ? ADC_INPUTCTRL_MUXPOS_AIN2 \
|
||||
: (PIN_TO_AIN(P) == 3) ? ADC_INPUTCTRL_MUXPOS_AIN3 \
|
||||
: (PIN_TO_AIN(P) == 4) ? ADC_INPUTCTRL_MUXPOS_AIN4 \
|
||||
: (PIN_TO_AIN(P) == 5) ? ADC_INPUTCTRL_MUXPOS_AIN5 \
|
||||
: (PIN_TO_AIN(P) == 6) ? ADC_INPUTCTRL_MUXPOS_AIN6 \
|
||||
: (PIN_TO_AIN(P) == 7) ? ADC_INPUTCTRL_MUXPOS_AIN7 \
|
||||
: (PIN_TO_AIN(P) == 8) ? ADC_INPUTCTRL_MUXPOS_AIN8 \
|
||||
: (PIN_TO_AIN(P) == 9) ? ADC_INPUTCTRL_MUXPOS_AIN9 \
|
||||
: (PIN_TO_AIN(P) == 10) ? ADC_INPUTCTRL_MUXPOS_AIN10 \
|
||||
: (PIN_TO_AIN(P) == 11) ? ADC_INPUTCTRL_MUXPOS_AIN11 \
|
||||
: (PIN_TO_AIN(P) == 12) ? ADC_INPUTCTRL_MUXPOS_AIN12 \
|
||||
: (PIN_TO_AIN(P) == 13) ? ADC_INPUTCTRL_MUXPOS_AIN13 \
|
||||
: (PIN_TO_AIN(P) == 14) ? ADC_INPUTCTRL_MUXPOS_AIN14 \
|
||||
: ADC_INPUTCTRL_MUXPOS_AIN15)
|
||||
|
||||
#define ANAPIN_TO_SAMDPIN(P) ( (P == 0) ? PIN_TO_SAMD_PIN(67) \
|
||||
: (P == 1) ? PIN_TO_SAMD_PIN(68) \
|
||||
: (P == 2) ? PIN_TO_SAMD_PIN(69) \
|
||||
: (P == 3) ? PIN_TO_SAMD_PIN(70) \
|
||||
: (P == 4) ? PIN_TO_SAMD_PIN(71) \
|
||||
: (P == 5) ? PIN_TO_SAMD_PIN(72) \
|
||||
: (P == 6) ? PIN_TO_SAMD_PIN(73) \
|
||||
: (P == 7) ? PIN_TO_SAMD_PIN(74) \
|
||||
: (P == 8) ? PIN_TO_SAMD_PIN(54) \
|
||||
: (P == 9) ? PIN_TO_SAMD_PIN(55) \
|
||||
: (P == 10) ? PIN_TO_SAMD_PIN(56) \
|
||||
: (P == 11) ? PIN_TO_SAMD_PIN(57) \
|
||||
: (P == 12) ? PIN_TO_SAMD_PIN(58) \
|
||||
: (P == 13) ? PIN_TO_SAMD_PIN(59) \
|
||||
: (P == 14) ? PIN_TO_SAMD_PIN(60) \
|
||||
: (P == 15) ? PIN_TO_SAMD_PIN(61) \
|
||||
: (P == 16) ? PIN_TO_SAMD_PIN(12) \
|
||||
: (P == 17) ? PIN_TO_SAMD_PIN(13) \
|
||||
: PIN_TO_SAMD_PIN(9))
|
||||
|
||||
#define digitalPinToAnalogInput(P) (WITHIN(P, 67, 74) ? (P) - 67 : WITHIN(P, 54, 61) ? 8 + (P) - 54 : WITHIN(P, 12, 13) ? 16 + (P) - 12 : P == 9 ? 18 : -1)
|
||||
|
||||
/*
|
||||
* pins
|
||||
*/
|
||||
|
||||
// PORTA
|
||||
#define DIO67_PIN PIN_PA02 // A0
|
||||
#define DIO59_PIN PIN_PA04 // A13
|
||||
#define DIO68_PIN PIN_PA05 // A1
|
||||
#define DIO60_PIN PIN_PA06 // A14
|
||||
#define DIO61_PIN PIN_PA07 // A15
|
||||
#define DIO26_PIN PIN_PA12
|
||||
#define DIO27_PIN PIN_PA13
|
||||
#define DIO28_PIN PIN_PA14
|
||||
#define DIO23_PIN PIN_PA15
|
||||
#define DIO37_PIN PIN_PA16
|
||||
#define DIO36_PIN PIN_PA17
|
||||
#define DIO35_PIN PIN_PA18
|
||||
#define DIO34_PIN PIN_PA19
|
||||
#define DIO33_PIN PIN_PA20
|
||||
#define DIO32_PIN PIN_PA21
|
||||
#define DIO31_PIN PIN_PA22
|
||||
#define DIO30_PIN PIN_PA23
|
||||
// PORTB
|
||||
#define DIO12_PIN PIN_PB00 // A16
|
||||
#define DIO13_PIN PIN_PB01 // A17
|
||||
#define DIO9_PIN PIN_PB02 // A18
|
||||
#define DIO69_PIN PIN_PB03 // A2
|
||||
#define DIO74_PIN PIN_PB04 // A7
|
||||
#define DIO54_PIN PIN_PB05 // A8
|
||||
#define DIO55_PIN PIN_PB06 // A9
|
||||
#define DIO56_PIN PIN_PB07 // A10
|
||||
#define DIO57_PIN PIN_PB08 // A11
|
||||
#define DIO58_PIN PIN_PB09 // A12
|
||||
#define DIO18_PIN PIN_PB12
|
||||
#define DIO19_PIN PIN_PB13
|
||||
#define DIO39_PIN PIN_PB14
|
||||
#define DIO38_PIN PIN_PB15
|
||||
#define DIO14_PIN PIN_PB16
|
||||
#define DIO15_PIN PIN_PB17
|
||||
#define DIO8_PIN PIN_PB18
|
||||
#define DIO29_PIN PIN_PB19
|
||||
#define DIO20_PIN PIN_PB20
|
||||
#define DIO21_PIN PIN_PB21
|
||||
#define DIO10_PIN PIN_PB22
|
||||
#define DIO11_PIN PIN_PB23
|
||||
#define DIO1_PIN PIN_PB24
|
||||
#define DIO0_PIN PIN_PB25
|
||||
#define DIO83_PIN PIN_PB28 // SD_CS
|
||||
#define DIO95_PIN PIN_PB31 // SD_CD
|
||||
// PORTC
|
||||
#define DIO70_PIN PIN_PC00 // A3
|
||||
#define DIO71_PIN PIN_PC01 // A4
|
||||
#define DIO72_PIN PIN_PC02 // A5
|
||||
#define DIO73_PIN PIN_PC03 // A6
|
||||
#define DIO48_PIN PIN_PC04
|
||||
#define DIO49_PIN PIN_PC05
|
||||
#define DIO46_PIN PIN_PC06
|
||||
#define DIO47_PIN PIN_PC07
|
||||
#define DIO45_PIN PIN_PC10
|
||||
#define DIO44_PIN PIN_PC11
|
||||
#define DIO41_PIN PIN_PC12
|
||||
#define DIO40_PIN PIN_PC13
|
||||
#define DIO43_PIN PIN_PC14
|
||||
#define DIO42_PIN PIN_PC15
|
||||
#define DIO25_PIN PIN_PC16
|
||||
#define DIO24_PIN PIN_PC17
|
||||
#define DIO2_PIN PIN_PC18
|
||||
#define DIO3_PIN PIN_PC19
|
||||
#define DIO4_PIN PIN_PC20
|
||||
#define DIO5_PIN PIN_PC21
|
||||
#define DIO16_PIN PIN_PC22
|
||||
#define DIO17_PIN PIN_PC23
|
||||
// PORTD
|
||||
#define DIO22_PIN PIN_PD12
|
||||
#define DIO6_PIN PIN_PD20
|
||||
#define DIO7_PIN PIN_PD21
|
||||
|
||||
#endif // ADAFRUIT_GRAND_CENTRAL_M4
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test SAMD51 specific configuration values for errors at compile-time.
|
||||
*/
|
||||
|
||||
#if defined(ADAFRUIT_GRAND_CENTRAL_M4) && SD_CONNECTION_IS(CUSTOM_CABLE)
|
||||
#error "No custom SD drive cable defined for this board."
|
||||
#endif
|
||||
|
||||
#if defined(MAX6675_SCK_PIN) && defined(MAX6675_DO_PIN) && (MAX6675_SCK_PIN == SCK1 || MAX6675_DO_PIN == MISO1)
|
||||
#error "OnBoard SPI BUS can't be shared with other devices."
|
||||
#endif
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
#error "EMERGENCY_PARSER is not yet implemented for STM32F4. Disable EMERGENCY_PARSER to continue."
|
||||
#endif
|
||||
|
||||
#if ENABLED(SDIO_SUPPORT)
|
||||
#error "SDIO_SUPPORT is not supported."
|
||||
#endif
|
||||
|
||||
#if ENABLED(FAST_PWM_FAN)
|
||||
#error "FAST_PWM_FAN is not yet implemented for this platform."
|
||||
#endif
|
||||
|
||||
#if ENABLED(EEPROM_SETTINGS) && NONE(SPI_EEPROM, I2C_EEPROM)
|
||||
#warning "Did you activate the SmartEEPROM? See https://github.com/GMagician/SAMD51-SmartEEprom-Activator"
|
||||
#endif
|
||||
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SAMD51__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(EEPROM_SETTINGS)
|
||||
|
||||
#include "../shared/persistent_store_api.h"
|
||||
|
||||
#if NONE(SPI_EEPROM, I2C_EEPROM)
|
||||
#define NVMCTRL_CMD(c) do{ \
|
||||
SYNC(!NVMCTRL->STATUS.bit.READY); \
|
||||
NVMCTRL->INTFLAG.bit.DONE = true; \
|
||||
NVMCTRL->CTRLB.reg = c | NVMCTRL_CTRLB_CMDEX_KEY; \
|
||||
SYNC(NVMCTRL->INTFLAG.bit.DONE); \
|
||||
}while(0)
|
||||
#define NVMCTRL_FLUSH() do{ \
|
||||
if (NVMCTRL->SEESTAT.bit.LOAD) \
|
||||
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_SEEFLUSH); \
|
||||
}while(0)
|
||||
#endif
|
||||
|
||||
bool PersistentStore::access_start() {
|
||||
#if NONE(SPI_EEPROM, I2C_EEPROM)
|
||||
NVMCTRL->SEECFG.reg = NVMCTRL_SEECFG_WMODE_BUFFERED; // Buffered mode and segment reallocation active
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PersistentStore::access_finish() {
|
||||
#if NONE(SPI_EEPROM, I2C_EEPROM)
|
||||
NVMCTRL_FLUSH();
|
||||
if (!NVMCTRL->SEESTAT.bit.LOCK)
|
||||
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_LSEE); // Lock E2P data write access
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||
#if NONE(SPI_EEPROM, I2C_EEPROM)
|
||||
if (NVMCTRL->SEESTAT.bit.RLOCK)
|
||||
NVMCTRL_CMD(NVMCTRL_CTRLB_CMD_USEE); // Unlock E2P data write access
|
||||
#endif
|
||||
|
||||
while (size--) {
|
||||
const uint8_t v = *value;
|
||||
#if ANY(SPI_EEPROM, I2C_EEPROM)
|
||||
uint8_t * const p = (uint8_t * const)pos;
|
||||
if (v != eeprom_read_byte(p)) {
|
||||
eeprom_write_byte(p, v);
|
||||
delay(2);
|
||||
if (eeprom_read_byte(p) != v) {
|
||||
SERIAL_ECHO_MSG(MSG_ERR_EEPROM_WRITE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
SYNC(NVMCTRL->SEESTAT.bit.BUSY);
|
||||
if (NVMCTRL->INTFLAG.bit.SEESFULL)
|
||||
NVMCTRL_FLUSH(); // Next write will trigger a sector reallocation. I need to flush 'pagebuffer'
|
||||
((volatile uint8_t *)SEEPROM_ADDR)[pos] = v;
|
||||
SYNC(!NVMCTRL->INTFLAG.bit.SEEWRC);
|
||||
#endif
|
||||
crc16(crc, &v, 1);
|
||||
pos++;
|
||||
value++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
while (size--) {
|
||||
uint8_t c;
|
||||
#if ANY(SPI_EEPROM, I2C_EEPROM)
|
||||
c = eeprom_read_byte((uint8_t*)pos);
|
||||
#else
|
||||
SYNC(NVMCTRL->SEESTAT.bit.BUSY);
|
||||
c = ((volatile uint8_t *)SEEPROM_ADDR)[pos];
|
||||
#endif
|
||||
if (writing) *value = c;
|
||||
crc16(crc, &c, 1);
|
||||
pos++;
|
||||
value++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t PersistentStore::capacity() {
|
||||
#if ANY(SPI_EEPROM, I2C_EEPROM)
|
||||
return E2END + 1;
|
||||
#else
|
||||
const uint8_t psz = NVMCTRL->SEESTAT.bit.PSZ,
|
||||
sblk = NVMCTRL->SEESTAT.bit.SBLK;
|
||||
|
||||
if (!psz && !sblk) return 0;
|
||||
else if (psz <= 2) return (0x200 << psz);
|
||||
else if (sblk == 1 || psz == 3) return 4096;
|
||||
else if (sblk == 2 || psz == 4) return 8192;
|
||||
else if (sblk <= 4 || psz == 5) return 16384;
|
||||
else if (sblk >= 9 && psz == 7) return 65536;
|
||||
else return 32768;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // EEPROM_SETTINGS
|
||||
|
||||
#endif // __SAMD51__
|
||||
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define NUMBER_PINS_TOTAL PINS_COUNT
|
||||
|
||||
#define digitalRead_mod(p) extDigitalRead(p)
|
||||
#define PRINT_PORT(p) do{ SERIAL_ECHOPGM(" Port: "); sprintf_P(buffer, PSTR("%c%02ld"), 'A' + g_APinDescription[p].ulPort, g_APinDescription[p].ulPin); SERIAL_ECHO(buffer); }while (0)
|
||||
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
|
||||
#define GET_ARRAY_PIN(p) pin_array[p].pin
|
||||
#define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
|
||||
#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL)
|
||||
#define DIGITAL_PIN_TO_ANALOG_PIN(p) digitalPinToAnalogInput(p)
|
||||
#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P)!=-1)
|
||||
#define pwm_status(pin) digitalPinHasPWM(pin)
|
||||
#define MULTI_NAME_PAD 27 // space needed to be pretty if not first name assigned to a pin
|
||||
|
||||
// pins that will cause hang/reset/disconnect in M43 Toggle and Watch utilities
|
||||
// uses pin index
|
||||
#define M43_NEVER_TOUCH(Q) ((Q) >= 75)
|
||||
|
||||
bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
|
||||
const EPortType samdport = g_APinDescription[pin].ulPort;
|
||||
const uint32_t samdpin = g_APinDescription[pin].ulPin;
|
||||
return PORT->Group[samdport].DIR.reg & MASK(samdpin) || (PORT->Group[samdport].PINCFG[samdpin].reg & (PORT_PINCFG_INEN | PORT_PINCFG_PULLEN)) == PORT_PINCFG_PULLEN;
|
||||
}
|
||||
|
||||
void pwm_details(int32_t pin) {
|
||||
if (pwm_status(pin)) {
|
||||
//uint32_t chan = g_APinDescription[pin].ulPWMChannel TODO when fast pwm is operative;
|
||||
//SERIAL_ECHOPAIR("PWM = ", duty);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AGCM4 Board pin | PORT | Label
|
||||
* ----------------+--------+-------
|
||||
* 0 | PB25 | "RX0"
|
||||
* 1 | PB24 | "TX0"
|
||||
* 2 | PC18 |
|
||||
* 3 | PC19 |
|
||||
* 4 | PC20 |
|
||||
* 5 | PC21 |
|
||||
* 6 | PD20 |
|
||||
* 7 | PD21 |
|
||||
* 8 | PB18 |
|
||||
* 9 | PB2 |
|
||||
* 10 | PB22 |
|
||||
* 11 | PB23 |
|
||||
* 12 | PB0 | "A16"
|
||||
* 13 | PB1 | LED AMBER "L" / "A17"
|
||||
* 14 | PB16 | "TX3"
|
||||
* 15 | PB17 | "RX3"
|
||||
* 16 | PC22 | "TX2"
|
||||
* 17 | PC23 | "RX2"
|
||||
* 18 | PB12 | "TX1" / "A18"
|
||||
* 19 | PB13 | "RX1"
|
||||
* 20 | PB20 | "SDA"
|
||||
* 21 | PB21 | "SCL"
|
||||
* 22 | PD12 |
|
||||
* 23 | PA15 |
|
||||
* 24 | PC17 |
|
||||
* 25 | PC16 |
|
||||
* 26 | PA12 |
|
||||
* 27 | PA13 |
|
||||
* 28 | PA14 |
|
||||
* 29 | PB19 |
|
||||
* 30 | PA23 |
|
||||
* 31 | PA22 |
|
||||
* 32 | PA21 |
|
||||
* 33 | PA20 |
|
||||
* 34 | PA19 |
|
||||
* 35 | PA18 |
|
||||
* 36 | PA17 |
|
||||
* 37 | PA16 |
|
||||
* 38 | PB15 |
|
||||
* 39 | PB14 |
|
||||
* 40 | PC13 |
|
||||
* 41 | PC12 |
|
||||
* 42 | PC15 |
|
||||
* 43 | PC14 |
|
||||
* 44 | PC11 |
|
||||
* 45 | PC10 |
|
||||
* 46 | PC6 |
|
||||
* 47 | PC7 |
|
||||
* 48 | PC4 |
|
||||
* 49 | PC5 |
|
||||
* 50 | PD11 |
|
||||
* 51 | PD8 |
|
||||
* 52 | PD9 |
|
||||
* 53 | PD10 |
|
||||
* 54 | PB5 | "A8"
|
||||
* 55 | PB6 | "A9"
|
||||
* 56 | PB7 | "A10"
|
||||
* 57 | PB8 | "A11"
|
||||
* 58 | PB9 | "A12"
|
||||
* 69 | PA4 | "A13"
|
||||
* 60 | PA6 | "A14"
|
||||
* 61 | PA7 | "A15"
|
||||
* 62 | PB17 |
|
||||
* 63 | PB20 |
|
||||
* 64 | PD11 |
|
||||
* 65 | PD8 |
|
||||
* 66 | PD9 |
|
||||
* 67 | PA2 | "A0" / "DAC0"
|
||||
* 68 | PA5 | "A1" / "DAC1"
|
||||
* 69 | PB3 | "A2"
|
||||
* 70 | PC0 | "A3"
|
||||
* 71 | PC1 | "A4"
|
||||
* 72 | PC2 | "A5"
|
||||
* 73 | PC3 | "A6"
|
||||
* 74 | PB4 | "A7"
|
||||
* 75 | PC31 | LED GREEN "RX"
|
||||
* 76 | PC30 | LED GREEN "TX"
|
||||
* 77 | PA27 | USB: Host enable
|
||||
* 78 | PA24 | USB: D-
|
||||
* 79 | PA25 | USB: D+
|
||||
* 80 | PB29 | SD: MISO
|
||||
* 81 | PB27 | SD: SCK
|
||||
* 82 | PB26 | SD: MOSI
|
||||
* 83 | PB28 | SD: CS
|
||||
* 84 | PA3 | AREF
|
||||
* 85 | PA2 | DAC0 (Duplicate)
|
||||
* 86 | PA5 | DAC1 (Duplicate)
|
||||
* 87 | PB1 | LED AMBER "L" (Duplicate)
|
||||
* 88 | PC24 | NeoPixel
|
||||
* 89 | PB10 | QSPI: SCK
|
||||
* 90 | PB11 | QSPI: CS
|
||||
* 91 | PA8 | QSPI: IO0
|
||||
* 92 | PA9 | QSPI: IO1
|
||||
* 93 | PA10 | QSPI: IO2
|
||||
* 94 | PA11 | QSPI: IO3
|
||||
*
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||
|
||||
/*
|
||||
* AGCM4 Default SPI Pins
|
||||
*
|
||||
* SS SCK MISO MOSI
|
||||
* +-------------------------+
|
||||
* SPI | 53 52 50 51 |
|
||||
* SPI1 | 83 81 80 82 |
|
||||
* +-------------------------+
|
||||
* Any pin can be used for Chip Select (SS_PIN)
|
||||
*/
|
||||
#ifndef SCK_PIN
|
||||
#define SCK_PIN 52
|
||||
#endif
|
||||
#ifndef MISO_PIN
|
||||
#define MISO_PIN 50
|
||||
#endif
|
||||
#ifndef MOSI_PIN
|
||||
#define MOSI_PIN 51
|
||||
#endif
|
||||
#ifndef SDSS
|
||||
#define SDSS 53
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#error "Unsupported board!"
|
||||
|
||||
#endif
|
||||
|
||||
#define SS_PIN SDSS
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SAMD51__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
|
||||
#include "watchdog_SAMD51.h"
|
||||
|
||||
void watchdog_init(void) {
|
||||
// The low-power oscillator used by the WDT runs at 32,768 Hz with
|
||||
// a 1:32 prescale, thus 1024 Hz, though probably not super precise.
|
||||
|
||||
// Setup WDT clocks
|
||||
MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
|
||||
MCLK->APBAMASK.bit.WDT_ = true;
|
||||
OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
|
||||
|
||||
WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config
|
||||
SYNC(WDT->SYNCBUSY.bit.ENABLE);
|
||||
|
||||
WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt
|
||||
WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096; // Set at least 4s period for chip reset
|
||||
|
||||
watchdog_reset();
|
||||
|
||||
WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode
|
||||
SYNC(WDT->SYNCBUSY.bit.ENABLE);
|
||||
}
|
||||
|
||||
#endif // USE_WATCHDOG
|
||||
|
||||
#endif // __SAMD51__
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
*
|
||||
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// Initialize watchdog with a 4 second interrupt time
|
||||
void watchdog_init();
|
||||
|
||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||
// first watchdog_init or SAMD will go into emergency procedures.
|
||||
inline void watchdog_reset() {
|
||||
SYNC(WDT->SYNCBUSY.bit.CLEAR); // Test first if previous is 'ongoing' to save time waiting for command execution
|
||||
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ void FastIO_init(); // Must be called before using fast io macros
|
||||
|
||||
#define _BV32(b) (1UL << (b))
|
||||
|
||||
#if !defined(PWM)
|
||||
#ifndef PWM
|
||||
#define PWM OUTPUT
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -42,7 +42,6 @@ extern const stm32_pin_info PIN_MAP[BOARD_NR_GPIO_PINS];
|
||||
#define GET_ARRAY_PIN(p) pin_t(pin_array[p].pin)
|
||||
#define pwm_status(pin) PWM_PIN(pin)
|
||||
#define digitalRead_mod(p) extDigitalRead(p)
|
||||
#define NAME_FORMAT(p) PSTR("%-##p##s")
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3hd "), int16_t(p)); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PORT(p) print_port(p)
|
||||
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
|
||||
@@ -90,6 +89,8 @@ static inline bool GET_ARRAY_IS_DIGITAL(const int16_t array_pin) {
|
||||
);
|
||||
}
|
||||
|
||||
#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
|
||||
|
||||
static inline void pwm_details(const pin_t pin) {
|
||||
if (PWM_PIN(pin)) {
|
||||
timer_dev * const tdev = PIN_MAP[pin].timer_device;
|
||||
|
||||
@@ -107,7 +107,6 @@ const XrefInfo pin_xref[] PROGMEM = {
|
||||
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
|
||||
#define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
|
||||
#define digitalRead_mod(Ard_num) extDigitalRead(Ard_num) // must use Arduino pin numbers when doing reads
|
||||
#define NAME_FORMAT(p) PSTR("%-##p##s")
|
||||
#define PRINT_PIN(Q)
|
||||
#define PRINT_PORT(ANUM) port_print(ANUM)
|
||||
#define DIGITAL_PIN_TO_ANALOG_PIN(ANUM) -1 // will report analog pin number in the print port routine
|
||||
|
||||
@@ -201,6 +201,11 @@ void HAL_init(void) {
|
||||
#if PIN_EXISTS(LED)
|
||||
OUT_WRITE(LED_PIN, LOW);
|
||||
#endif
|
||||
#if PIN_EXISTS(USB_CONNECT)
|
||||
OUT_WRITE(USB_CONNECT_PIN, !USB_CONNECT_INVERTING); // USB clear connection
|
||||
delay(1000); // Give OS time to notice
|
||||
OUT_WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* VGPV Done with defines
|
||||
@@ -260,7 +265,11 @@ extern "C" {
|
||||
void HAL_adc_init(void) {
|
||||
// configure the ADC
|
||||
adc.calibrate();
|
||||
adc.setSampleRate(ADC_SMPR_41_5); // ?
|
||||
#if F_CPU > 72000000
|
||||
adc.setSampleRate(ADC_SMPR_71_5); // 71.5 ADC cycles
|
||||
#else
|
||||
adc.setSampleRate(ADC_SMPR_41_5); // 41.5 ADC cycles
|
||||
#endif
|
||||
adc.setPins(adc_pins, ADC_PIN_COUNT);
|
||||
adc.setDMA(HAL_adc_results, (uint16_t)ADC_PIN_COUNT, (uint32_t)(DMA_MINC_MODE | DMA_CIRC_MODE), nullptr);
|
||||
adc.setScanMode();
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include <libmaple/stm32.h>
|
||||
|
||||
#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to set density
|
||||
|
||||
#if defined(STM32_HIGH_DENSITY) || defined(STM32_XL_DENSITY)
|
||||
|
||||
#include "HAL_sdio_STM32F1.h"
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
|
||||
#include "libmaple/sdio.h"
|
||||
#include "libmaple/dma.h"
|
||||
#include <libmaple/sdio.h>
|
||||
#include <libmaple/dma.h>
|
||||
|
||||
// ------------------------
|
||||
// Defines
|
||||
|
||||
@@ -79,15 +79,25 @@ void spiBegin() {
|
||||
* @details
|
||||
*/
|
||||
void spiInit(uint8_t spiRate) {
|
||||
/**
|
||||
* STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
|
||||
* STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
|
||||
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
|
||||
*/
|
||||
#if SPI_DEVICE == 1
|
||||
#define SPI_CLOCK_MAX SPI_CLOCK_DIV4
|
||||
#else
|
||||
#define SPI_CLOCK_MAX SPI_CLOCK_DIV2
|
||||
#endif
|
||||
uint8_t clock;
|
||||
switch (spiRate) {
|
||||
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV2 ; break;
|
||||
case SPI_FULL_SPEED: clock = SPI_CLOCK_MAX ; break;
|
||||
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4 ; break;
|
||||
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
|
||||
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
|
||||
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
|
||||
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
||||
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
||||
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
||||
}
|
||||
SPI.setModule(SPI_DEVICE);
|
||||
SPI.begin();
|
||||
@@ -104,7 +114,7 @@ void spiInit(uint8_t spiRate) {
|
||||
* @details
|
||||
*/
|
||||
uint8_t spiRec(void) {
|
||||
uint8_t returnByte = SPI.transfer(0xFF);
|
||||
uint8_t returnByte = SPI.transfer(ff);
|
||||
return returnByte;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
case 3: irq_num = NVIC_TIMER3; break;
|
||||
case 4: irq_num = NVIC_TIMER4; break;
|
||||
case 5: irq_num = NVIC_TIMER5; break;
|
||||
#ifdef STM32_HIGH_DENSITY
|
||||
#if ENABLED(STM32_HIGH_DENSITY)
|
||||
// 6 & 7 are basic timers, avoid them
|
||||
case 8: irq_num = NVIC_TIMER8_CC; break;
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,6 @@ import sys
|
||||
#dynamic build flags for generic compile options
|
||||
if __name__ == "__main__":
|
||||
args = " ".join([ "-std=gnu11",
|
||||
"-std=gnu++11",
|
||||
"-Os",
|
||||
"-mcpu=cortex-m3",
|
||||
"-mthumb",
|
||||
|
||||
+72
-23
@@ -26,18 +26,21 @@
|
||||
* Communication interface for FSMC
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs
|
||||
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
|
||||
#include "U8glib.h"
|
||||
#include "libmaple/fsmc.h"
|
||||
#include "libmaple/gpio.h"
|
||||
#include "boards.h"
|
||||
#include <U8glib.h>
|
||||
#include <libmaple/fsmc.h>
|
||||
#include <libmaple/gpio.h>
|
||||
#include <libmaple/dma.h>
|
||||
#include <boards.h>
|
||||
|
||||
#define LCD_READ_ID 0x04 /* Read display identification information */
|
||||
#ifndef LCD_READ_ID
|
||||
#define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
|
||||
#endif
|
||||
|
||||
/* Timing configuration */
|
||||
#define FSMC_ADDRESS_SETUP_TIME 15 // AddressSetupTime
|
||||
@@ -47,6 +50,10 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs);
|
||||
void LCD_IO_WriteData(uint16_t RegValue);
|
||||
void LCD_IO_WriteReg(uint16_t Reg);
|
||||
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize);
|
||||
#ifdef LCD_USE_DMA_FSMC
|
||||
void LCD_IO_WriteMultiple(uint16_t data, uint32_t count);
|
||||
void LCD_IO_WriteSequence(uint16_t *data, uint16_t length);
|
||||
#endif
|
||||
|
||||
static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
|
||||
|
||||
@@ -59,21 +66,25 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
|
||||
static uint8_t isCommand;
|
||||
|
||||
switch (msg) {
|
||||
case U8G_COM_MSG_STOP:
|
||||
break;
|
||||
case U8G_COM_MSG_STOP: break;
|
||||
case U8G_COM_MSG_INIT:
|
||||
u8g_SetPIOutput(u8g, U8G_PI_RESET);
|
||||
|
||||
#ifdef LCD_USE_DMA_FSMC
|
||||
dma_init(FSMC_DMA_DEV);
|
||||
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
dma_set_priority(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, DMA_PRIORITY_MEDIUM);
|
||||
#endif
|
||||
|
||||
LCD_IO_Init(u8g->pin_list[U8G_PI_CS], u8g->pin_list[U8G_PI_A0]);
|
||||
u8g_Delay(100);
|
||||
u8g_Delay(50);
|
||||
|
||||
if (arg_ptr != nullptr)
|
||||
if (arg_ptr)
|
||||
*((uint32_t *)arg_ptr) = LCD_IO_ReadData(LCD_READ_ID, 3);
|
||||
|
||||
isCommand = 0;
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
|
||||
case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
|
||||
isCommand = arg_val == 0 ? 1 : 0;
|
||||
break;
|
||||
|
||||
@@ -89,7 +100,6 @@ uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, voi
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_WRITE_SEQ:
|
||||
|
||||
for (uint8_t i = 0; i < arg_val; i += 2)
|
||||
LCD_IO_WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
|
||||
break;
|
||||
@@ -107,9 +117,9 @@ __attribute__((always_inline)) __STATIC_INLINE void __DSB(void) {
|
||||
__ASM volatile ("dsb 0xF":::"memory");
|
||||
}
|
||||
|
||||
#define FSMC_CS_NE1 PD7
|
||||
#define FSMC_CS_NE1 PD7
|
||||
|
||||
#ifdef STM32_XL_DENSITY
|
||||
#if ENABLED(STM32_XL_DENSITY)
|
||||
#define FSMC_CS_NE2 PG9
|
||||
#define FSMC_CS_NE3 PG10
|
||||
#define FSMC_CS_NE4 PG12
|
||||
@@ -141,7 +151,7 @@ __attribute__((always_inline)) __STATIC_INLINE void __DSB(void) {
|
||||
#define FSMC_RS_A22 PE6
|
||||
#define FSMC_RS_A23 PE2
|
||||
|
||||
#ifdef STM32_XL_DENSITY
|
||||
#if ENABLED(STM32_XL_DENSITY)
|
||||
#define FSMC_RS_A24 PG13
|
||||
#define FSMC_RS_A25 PG14
|
||||
#endif
|
||||
@@ -163,7 +173,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
|
||||
|
||||
switch (cs) {
|
||||
case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; break;
|
||||
#ifdef STM32_XL_DENSITY
|
||||
#if ENABLED(STM32_XL_DENSITY)
|
||||
case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; break;
|
||||
case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; break;
|
||||
case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; break;
|
||||
@@ -174,7 +184,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
|
||||
#define _ORADDR(N) controllerAddress |= (_BV32(N) - 2)
|
||||
|
||||
switch (rs) {
|
||||
#ifdef STM32_XL_DENSITY
|
||||
#if ENABLED(STM32_XL_DENSITY)
|
||||
case FSMC_RS_A0: _ORADDR( 1); break;
|
||||
case FSMC_RS_A1: _ORADDR( 2); break;
|
||||
case FSMC_RS_A2: _ORADDR( 3); break;
|
||||
@@ -200,7 +210,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
|
||||
case FSMC_RS_A21: _ORADDR(22); break;
|
||||
case FSMC_RS_A22: _ORADDR(23); break;
|
||||
case FSMC_RS_A23: _ORADDR(24); break;
|
||||
#ifdef STM32_XL_DENSITY
|
||||
#if ENABLED(STM32_XL_DENSITY)
|
||||
case FSMC_RS_A24: _ORADDR(25); break;
|
||||
case FSMC_RS_A25: _ORADDR(26); break;
|
||||
#endif
|
||||
@@ -232,7 +242,7 @@ void LCD_IO_Init(uint8_t cs, uint8_t rs) {
|
||||
gpio_set_mode(PIN_MAP[cs].gpio_device, PIN_MAP[cs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_CS_NEx
|
||||
gpio_set_mode(PIN_MAP[rs].gpio_device, PIN_MAP[rs].gpio_bit, GPIO_AF_OUTPUT_PP); //FSMC_RS_Ax
|
||||
|
||||
#ifdef STM32_XL_DENSITY
|
||||
#if ENABLED(STM32_XL_DENSITY)
|
||||
FSMC_NOR_PSRAM4_BASE->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
|
||||
FSMC_NOR_PSRAM4_BASE->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
|
||||
#else // PSRAM1 for STM32F103V (high density)
|
||||
@@ -257,7 +267,7 @@ void LCD_IO_WriteReg(uint16_t Reg) {
|
||||
|
||||
uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
|
||||
volatile uint32_t data;
|
||||
LCD->REG = (uint16_t)RegValue;
|
||||
LCD->REG = RegValue;
|
||||
__DSB();
|
||||
|
||||
data = LCD->RAM; // dummy read
|
||||
@@ -267,9 +277,48 @@ uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
|
||||
data <<= 8;
|
||||
data |= (LCD->RAM & 0x00FF);
|
||||
}
|
||||
return (uint32_t)data;
|
||||
return uint32_t(data);
|
||||
}
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD
|
||||
#if ENABLED(LCD_USE_DMA_FSMC)
|
||||
|
||||
void LCD_IO_WriteMultiple(uint16_t color, uint32_t count) {
|
||||
while (count > 0) {
|
||||
dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, &color, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM);
|
||||
dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, count > 65535 ? 65535 : count);
|
||||
dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
|
||||
while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
|
||||
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
|
||||
count = count > 65535 ? count - 65535 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_IO_WriteSequence(uint16_t *data, uint16_t length) {
|
||||
dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
|
||||
dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
|
||||
dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
|
||||
while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
|
||||
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
}
|
||||
|
||||
void LCD_IO_WriteSequence_Async(uint16_t *data, uint16_t length) {
|
||||
dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | DMA_PINC_MODE);
|
||||
dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, length);
|
||||
dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
}
|
||||
|
||||
void LCD_IO_WaitSequence_Async() {
|
||||
while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
|
||||
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
|
||||
}
|
||||
|
||||
#endif // LCD_USE_DMA_FSMC
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD
|
||||
#endif // ARDUINO_ARCH_STM32F1 && FSMC_CS_PIN
|
||||
+2
-2
@@ -18,11 +18,11 @@
|
||||
*/
|
||||
#ifdef __STM32F1__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD && ENABLED(FORCE_SOFT_SPI)
|
||||
|
||||
#include "HAL.h"
|
||||
#include "../HAL.h"
|
||||
#include <U8glib.h>
|
||||
|
||||
#undef SPI_SPEED
|
||||
@@ -56,3 +56,130 @@
|
||||
#define extDigitalRead(IO) digitalRead(IO)
|
||||
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
|
||||
|
||||
//
|
||||
// Pins Definitions
|
||||
//
|
||||
#define PA0 0x00
|
||||
#define PA1 0x01
|
||||
#define PA2 0x02
|
||||
#define PA3 0x03
|
||||
#define PA4 0x04
|
||||
#define PA5 0x05
|
||||
#define PA6 0x06
|
||||
#define PA7 0x07
|
||||
#define PA8 0x08
|
||||
#define PA9 0x09
|
||||
#define PA10 0x0A
|
||||
#define PA11 0x0B
|
||||
#define PA12 0x0C
|
||||
#define PA13 0x0D
|
||||
#define PA14 0x0E
|
||||
#define PA15 0x0F
|
||||
|
||||
#define PB0 0x10
|
||||
#define PB1 0x11
|
||||
#define PB2 0x12
|
||||
#define PB3 0x13
|
||||
#define PB4 0x14
|
||||
#define PB5 0x15
|
||||
#define PB6 0x16
|
||||
#define PB7 0x17 // 36 pins (F103T)
|
||||
#define PB8 0x18
|
||||
#define PB9 0x19
|
||||
#define PB10 0x1A
|
||||
#define PB11 0x1B
|
||||
#define PB12 0x1C
|
||||
#define PB13 0x1D
|
||||
#define PB14 0x1E
|
||||
#define PB15 0x1F
|
||||
|
||||
#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
|
||||
#define PC13 0x20
|
||||
#define PC14 0x21
|
||||
#define PC15 0x22
|
||||
#else
|
||||
#define PC0 0x20
|
||||
#define PC1 0x21
|
||||
#define PC2 0x22
|
||||
#define PC3 0x23
|
||||
#define PC4 0x24
|
||||
#define PC5 0x25
|
||||
#define PC6 0x26
|
||||
#define PC7 0x27
|
||||
#define PC8 0x28
|
||||
#define PC9 0x29
|
||||
#define PC10 0x2A
|
||||
#define PC11 0x2B
|
||||
#define PC12 0x2C
|
||||
#define PC13 0x2D
|
||||
#define PC14 0x2E
|
||||
#define PC15 0x2F
|
||||
#endif
|
||||
|
||||
#define PD0 0x30
|
||||
#define PD1 0x31
|
||||
#define PD2 0x32 // 64 pins (F103R)
|
||||
#define PD3 0x33
|
||||
#define PD4 0x34
|
||||
#define PD5 0x35
|
||||
#define PD6 0x36
|
||||
#define PD7 0x37
|
||||
#define PD8 0x38
|
||||
#define PD9 0x39
|
||||
#define PD10 0x3A
|
||||
#define PD11 0x3B
|
||||
#define PD12 0x3C
|
||||
#define PD13 0x3D
|
||||
#define PD14 0x3E
|
||||
#define PD15 0x3F
|
||||
|
||||
#define PE0 0x40
|
||||
#define PE1 0x41
|
||||
#define PE2 0x42
|
||||
#define PE3 0x43
|
||||
#define PE4 0x44
|
||||
#define PE5 0x45
|
||||
#define PE6 0x46
|
||||
#define PE7 0x47
|
||||
#define PE8 0x48
|
||||
#define PE9 0x49
|
||||
#define PE10 0x4A
|
||||
#define PE11 0x4B
|
||||
#define PE12 0x4C
|
||||
#define PE13 0x4D
|
||||
#define PE14 0x4E
|
||||
#define PE15 0x4F // 100 pins (F103V)
|
||||
|
||||
#define PF0 0x50
|
||||
#define PF1 0x51
|
||||
#define PF2 0x52
|
||||
#define PF3 0x53
|
||||
#define PF4 0x54
|
||||
#define PF5 0x55
|
||||
#define PF6 0x56
|
||||
#define PF7 0x57
|
||||
#define PF8 0x58
|
||||
#define PF9 0x59
|
||||
#define PF10 0x5A
|
||||
#define PF11 0x5B
|
||||
#define PF12 0x5C
|
||||
#define PF13 0x5D
|
||||
#define PF14 0x5E
|
||||
#define PF15 0x5F
|
||||
|
||||
#define PG0 0x60
|
||||
#define PG1 0x61
|
||||
#define PG2 0x62
|
||||
#define PG3 0x63
|
||||
#define PG4 0x64
|
||||
#define PG5 0x65
|
||||
#define PG6 0x66
|
||||
#define PG7 0x67
|
||||
#define PG8 0x68
|
||||
#define PG9 0x69
|
||||
#define PG10 0x6A
|
||||
#define PG11 0x6B
|
||||
#define PG12 0x6C
|
||||
#define PG13 0x6D
|
||||
#define PG14 0x6E
|
||||
#define PG15 0x6F // 144 pins (F103Z)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user