diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
index 70734d4972..a973242932 100644
--- a/.github/FUNDING.yml
+++ b/.github/FUNDING.yml
@@ -1,3 +1,3 @@
github: [thinkyhead]
patreon: thinkyhead
-custom: ["http://www.thinkyhead.com/donate-to-marlin"]
+custom: ["https://www.thinkyhead.com/donate-to-marlin"]
diff --git a/.github/contributing.md b/.github/contributing.md
index 808c87bb04..6bc7b5a005 100644
--- a/.github/contributing.md
+++ b/.github/contributing.md
@@ -34,16 +34,15 @@ This project and everyone participating in it is governed by the [Marlin Code of
We have a Message Board and a Facebook group where our knowledgable user community can provide helpful advice if you have questions.
-* [Marlin RepRap forum](http://forums.reprap.org/list.php?415)
+* [Marlin RepRap forum](https://reprap.org/forum/list.php?415)
* [MarlinFirmware on Facebook](https://www.facebook.com/groups/1049718498464482/)
-If chat is more your speed, you can join the MarlinFirmware Slack team:
+If chat is more your speed, you can join the MarlinFirmware Discord server:
-* Join the Marlin Slack Team
- * To obtain group access, please [send a request](http://www.thinkyhead.com/contact/9) to @thinkyhead.
- * Even though Slack is a chat service, sometimes it takes several hours for community members to respond — please be patient!
- * Use the `#general` channel for general questions or discussion about Marlin.
- * Other channels exist for certain topics. Check the channel list.
+* Use the link https://discord.gg/n5NJ59y to join up as a General User.
+* Even though our Discord is pretty active, it may take a while for community members to respond — please be patient!
+* Use the `#general` channel for general questions or discussion about Marlin.
+* Other channels exist for certain topics or are limited to Patrons. Check the channel list.
## How Can I Contribute?
@@ -93,7 +92,7 @@ Before creating a suggestion, please check [this list](#before-submitting-a-sugg
#### Before Submitting a Feature Request
-* **Check the [Marlin website](http://marlinfw.org/)** for tips — you might discover that the feature is already included. Most importantly, check if you're using [the latest version of Marlin](https://github.com/MarlinFirmware/Marlin/releases) and if you can get the desired behavior by changing [Marlin's config settings](http://marlinfw.org/docs/configuration/configuration.html).
+* **Check the [Marlin website](https://marlinfw.org/)** for tips — you might discover that the feature is already included. Most importantly, check if you're using [the latest version of Marlin](https://github.com/MarlinFirmware/Marlin/releases) and if you can get the desired behavior by changing [Marlin's config settings](https://marlinfw.org/docs/configuration/configuration.html).
* **Perform a [cursory search](https://github.com/MarlinFirmware/Marlin/issues?q=is%3Aissue)** to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
#### How Do I Submit A (Good) Feature Request?
@@ -117,12 +116,12 @@ Unsure where to begin contributing to Marlin? You can start by looking through t
### Pull Requests
-Pull Requests should always be targeted to working branches (e.g., `bugfix-1.1.x` and/or `bugfix-2.0.x`) and never to release branches (e.g., `1.1.x`). If this is your first Pull Request, please read our [Guide to Pull Requests](http://marlinfw.org/docs/development/getting_started_pull_requests.html) and Github's [Pull Request](https://help.github.com/articles/creating-a-pull-request/) documentation.
+Pull Requests should always be targeted to working branches (e.g., `bugfix-1.1.x` and/or `bugfix-2.0.x`) and never to release branches (e.g., `1.1.x`). If this is your first Pull Request, please read our [Guide to Pull Requests](https://marlinfw.org/docs/development/getting_started_pull_requests.html) and Github's [Pull Request](https://help.github.com/articles/creating-a-pull-request/) documentation.
* Fill in [the required template](pull_request_template.md).
* Don't include issue numbers in the PR title.
* Include pictures, diagrams, and links to videos in your Pull Request to demonstrate your changes, if needed.
-* Follow the [Coding Standards](http://marlinfw.org/docs/development/coding_standards.html) posted on our website.
+* Follow the [Coding Standards](https://marlinfw.org/docs/development/coding_standards.html) posted on our website.
* Document new code with clear and concise comments.
* End all files with a newline.
@@ -137,7 +136,7 @@ Pull Requests should always be targeted to working branches (e.g., `bugfix-1.1.x
### C++ Coding Standards
-* Please read and follow the [Coding Standards](http://marlinfw.org/docs/development/coding_standards.html) posted on our website. Failure to follow these guidelines will delay evaluation and acceptance of Pull Requests.
+* Please read and follow the [Coding Standards](https://marlinfw.org/docs/development/coding_standards.html) posted on our website. Failure to follow these guidelines will delay evaluation and acceptance of Pull Requests.
### Documentation
diff --git a/.github/issue_template.md b/.github/issue_template.md
index f45bd71d09..a211ca5e27 100644
--- a/.github/issue_template.md
+++ b/.github/issue_template.md
@@ -1,16 +1,11 @@
# NO SUPPORT REQUESTS PLEASE
-Support Requests posted here will be automatically closed!
+Do you want to ask a question? Are you looking for support? Please don't post here. Support Requests posted here will be automatically closed!
-This Issue Queue is for Marlin bug reports and development-related issues, and we prefer not to handle user-support questions here. See https://github.com/MarlinFirmware/Marlin/blob/1.1.x/.github/contributing.md#i-dont-want-to-read-this-whole-thing-i-just-have-a-question.
+Instead use one of the following options:
-For best results getting help with configuration and troubleshooting, please use the following resources:
+- The Marlin Firmware forum at https://reprap.org/forum/list.php?415
+- The MarlinFirmware Facebook Group at https://www.facebook.com/groups/1049718498464482/
+- The MarlinFirmware Discord Server at https://discord.gg/n5NJ59y.
-- RepRap.org Marlin Forum http://forums.reprap.org/list.php?415
-- Tom's 3D Forums https://discuss.toms3d.org/
-- Facebook Group "Marlin Firmware" https://www.facebook.com/groups/1049718498464482/
-- Facebook Group "Marlin Firmware for 3D Printers" https://www.facebook.com/groups/3Dtechtalk/
-- Marlin Configuration https://www.youtube.com/results?search_query=marlin+configuration on YouTube
-- Marlin Discord server. Join link: https://discord.gg/n5NJ59y
-
-After seeking help from the community, if the consensus points to to a bug in Marlin, then you should post a Bug Report at https://github.com/MarlinFirmware/Marlin/issues/new/choose).
+Before filing an issue be sure to test the latest "bugfix" branch to see whether the issue is already addressed.
diff --git a/.github/lock.yml b/.github/lock.yml
new file mode 100644
index 0000000000..c5ceff66b0
--- /dev/null
+++ b/.github/lock.yml
@@ -0,0 +1,40 @@
+#
+# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app
+#
+
+# Number of days of inactivity before a closed issue or pull request is locked
+daysUntilLock: 60
+
+# Skip issues and pull requests created before a given timestamp. Timestamp must
+# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
+skipCreatedBefore: false
+
+# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
+exemptLabels: [ 'no-locking' ]
+
+# Label to add before locking, such as `outdated`. Set to `false` to disable
+lockLabel: false
+
+# Comment to post before locking. Set to `false` to disable
+lockComment: >
+ This thread has been automatically locked since there has not been
+ any recent activity after it was closed. Please open a new issue for
+ related bugs.
+
+# Assign `resolved` as the reason for locking. Set to `false` to disable
+setLockReason: true
+
+# Limit to only `issues` or `pulls`
+# only: issues
+
+# Optionally, specify configuration settings just for `issues` or `pulls`
+# issues:
+# exemptLabels:
+# - help-wanted
+# lockLabel: outdated
+
+# pulls:
+# daysUntilLock: 30
+
+# Repository to extend settings from
+# _extends: repo
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 9298b2b96d..d82fb0f9e3 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -14,6 +14,10 @@ We must be able to understand your proposed change from this description. If we
+### Configurations
+
+
+
### Related Issues
diff --git a/.github/workflows/bad-target.md b/.github/workflows/bad-target.md
deleted file mode 100644
index 048e56cfd1..0000000000
--- a/.github/workflows/bad-target.md
+++ /dev/null
@@ -1,7 +0,0 @@
-Thanks for your contribution! Unfortunately we can't accept PRs directed at release branches. We make patches to the bugfix branches and only later do we push them out as releases.
-
-Please redo this PR starting with the `bugfix-2.0.x` branch and be careful to target `bugfix-2.0.x` when resubmitting the PR.
-
-It may help to set your fork's default branch to `bugfix-2.0.x`.
-
-See [this page](http://marlinfw.org/docs/development/getting_started_pull_requests.html) for full instructions.
diff --git a/.github/workflows/bump-date.yml b/.github/workflows/bump-date.yml
index ecf4a4f0ec..54902da8c9 100644
--- a/.github/workflows/bump-date.yml
+++ b/.github/workflows/bump-date.yml
@@ -11,6 +11,8 @@ on:
jobs:
bump_date:
+ name: Bump Distribution Date
+ if: github.repository == 'MarlinFirmware/Marlin'
runs-on: ubuntu-latest
@@ -24,7 +26,6 @@ jobs:
- name: Bump Distribution Date
run: |
# Inline Bump Script
- [[ "$GITHUB_REPOSITORY" == "MarlinFirmware/Marlin" ]] || exit 0
DIST=$( date +"%Y-%m-%d" )
eval "sed -E -i 's/(#define +STRING_DISTRIBUTION_DATE) .*$/\1 \"$DIST\"/g' Marlin/src/inc/Version.h" && \
git config user.name "${GITHUB_ACTOR}" && \
diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml
index a6246a3786..aa4a2c59c9 100644
--- a/.github/workflows/check-pr.yml
+++ b/.github/workflows/check-pr.yml
@@ -1,6 +1,6 @@
#
-# comment-pr.yml
-# Add a comment to any PR directed to a release branch
+# check-pr.yml
+# Close PRs directed at release branches
#
name: PR Bad Target
@@ -14,14 +14,20 @@ on:
jobs:
bad_target:
-
name: PR Bad Target
+ if: github.repository == 'MarlinFirmware/Marlin'
+
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v1
- - uses: harupy/comment-on-pr@master
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- filename: bad-target.md
+ - uses: peter-evans/close-pull@v1
+ with:
+ delete-branch: false
+ comment: >
+ Thanks for your contribution! Unfortunately we can't accept PRs directed at release branches. We make patches to the bugfix branches and only later do we push them out as releases.
+
+ Please redo this PR starting with the `bugfix-2.0.x` branch and be careful to target `bugfix-2.0.x` when resubmitting the PR.
+
+ It may help to set your fork's default branch to `bugfix-2.0.x`.
+
+ See [this page](http://marlinfw.org/docs/development/getting_started_pull_requests.html) for full instructions.
diff --git a/.github/workflows/close-stale.yml b/.github/workflows/close-stale.yml
new file mode 100644
index 0000000000..083e844e90
--- /dev/null
+++ b/.github/workflows/close-stale.yml
@@ -0,0 +1,27 @@
+#
+# close-stale.yml
+# Close open issues after a period of inactivity
+#
+
+name: Close Stale Issues
+
+on:
+ schedule:
+ - cron: "22 1 * * *"
+
+jobs:
+ stale:
+ name: Close Stale Issues
+ if: github.repository == 'MarlinFirmware/Marlin'
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/stale@v3
+ with:
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
+ stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label / comment or this will be closed in 5 days.'
+ days-before-stale: 30
+ days-before-close: 5
+ stale-issue-label: 'stale-closing-soon'
+ exempt-issue-labels: 'T: Feature Request'
diff --git a/.github/workflows/lock-closed.yml b/.github/workflows/lock-closed.yml
new file mode 100644
index 0000000000..8cdcd7a836
--- /dev/null
+++ b/.github/workflows/lock-closed.yml
@@ -0,0 +1,32 @@
+#
+# lock-closed.yml
+# Lock closed issues after a period of inactivity
+#
+
+name: Lock Closed Issues
+
+on:
+ schedule:
+ - cron: '0 1/13 * * *'
+
+jobs:
+ lock:
+ name: Lock Closed Issues
+ if: github.repository == 'MarlinFirmware/Marlin'
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: dessant/lock-threads@v2
+ with:
+ github-token: ${{ github.token }}
+ process-only: 'issues'
+ issue-lock-inactive-days: '60'
+ issue-exclude-created-before: ''
+ issue-exclude-labels: 'no-locking'
+ issue-lock-labels: ''
+ issue-lock-comment: >
+ This issue has been automatically locked since there
+ has not been any recent activity after it was closed.
+ Please open a new issue for related bugs.
+ issue-lock-reason: ''
diff --git a/.github/workflows/test-builds.yml b/.github/workflows/test-builds.yml
index b92b015287..fdb81fbdc9 100644
--- a/.github/workflows/test-builds.yml
+++ b/.github/workflows/test-builds.yml
@@ -9,7 +9,14 @@ on:
pull_request:
branches:
- bugfix-2.0.x
- - dev-2.1.x
+ paths-ignore:
+ - config/**
+ - data/**
+ - docs/**
+ - '**/*.md'
+ push:
+ branches:
+ - bugfix-2.0.x
paths-ignore:
- config/**
- data/**
@@ -18,6 +25,8 @@ on:
jobs:
test_builds:
+ name: Run All Tests
+ if: github.repository == 'MarlinFirmware/Marlin'
runs-on: ubuntu-latest
@@ -49,14 +58,27 @@ jobs:
- STM32F103RE_btt
- STM32F103RE_btt_USB
- STM32F103RC_fysetc
+ - STM32F103RC_meeb
- jgaurora_a5s_a1
- STM32F103VE_longer
- STM32F407VE_black
+ - STM32F401VE_STEVAL
+ - BIGTREE_BTT002
- BIGTREE_SKR_PRO
- BIGTREE_GTR_V1_0
- mks_robin
+ - mks_robin_stm32
- ARMED
- FYSETC_S6
+ - STM32F070RB_malyan
+ - malyan_M300
+ - mks_robin_lite
+ - FLYF407ZG
+ - rumba32
+ - mks_robin_pro
+ - STM32F103RET6_creality
+ - LERDGEX
+ - mks_robin_nano35
# Put lengthy tests last
@@ -69,14 +91,10 @@ jobs:
#- STM32F7
# Non-working environment tests
-
- #- BIGTREE_BTT002
#- at90usb1286_cdc
#- at90usb1286_dfu
#- STM32F103CB_malyan
- #- mks_robin_lite
#- mks_robin_mini
- #- mks_robin_nano
steps:
@@ -88,7 +106,7 @@ jobs:
- name: Install PlatformIO
run: |
- pip install -U https://github.com/platformio/platformio-core/archive/master.zip
+ pip install -U https://github.com/platformio/platformio-core/archive/develop.zip
platformio update
- name: Check out the PR
@@ -97,8 +115,7 @@ jobs:
- name: Run ${{ matrix.test-platform }} Tests
run: |
# Inline tests script
- [[ "$GITHUB_REPOSITORY" == "MarlinFirmware/Marlin" ]] || exit 0
chmod +x buildroot/bin/*
- chmod +x buildroot/share/tests/*
- export PATH=./buildroot/bin/:./buildroot/share/tests/:${PATH}
+ chmod +x buildroot/tests/*
+ export PATH=./buildroot/bin/:./buildroot/tests/:${PATH}
run_tests . ${{ matrix.test-platform }}
diff --git a/.github/workflows/unlock-reopened.yml b/.github/workflows/unlock-reopened.yml
new file mode 100644
index 0000000000..614ef3fab2
--- /dev/null
+++ b/.github/workflows/unlock-reopened.yml
@@ -0,0 +1,22 @@
+#
+# unlock-reopened.yml
+# Unlock an issue whenever it is re-opened
+#
+
+name: "Unlock reopened issue"
+
+on:
+ issues:
+ types: [reopened]
+
+jobs:
+ unlock:
+ name: Unlock Reopened
+ if: github.repository == 'MarlinFirmware/Marlin'
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: OSDKDev/unlock-issues@v1.1
+ with:
+ repo-token: "${{ secrets.GITHUB_TOKEN }}"
diff --git a/.gitignore b/.gitignore
index 80c76ee1e4..c163d339df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,7 +16,7 @@
# 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 .
+# along with this program. If not, see .
#
# Our automatic versioning scheme generates the following file
diff --git a/LICENSE b/LICENSE
index 7d917cf3d8..6c0e10f3b8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -3,7 +3,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
- Copyright (c) 2007 Free Software Foundation, Inc.
+ Copyright (c) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@@ -647,7 +647,7 @@ the "copyright" line and a pointer to where the full notice is found.
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 .
+ along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
@@ -666,12 +666,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
-.
+.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
-.
-
+.
diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 99bf3e336c..7a6b0d373b 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -36,7 +36,7 @@
* Advanced settings can be found in Configuration_adv.h
*
*/
-#define CONFIGURATION_H_VERSION 020005
+#define CONFIGURATION_H_VERSION 020006
//===========================================================================
//============================= Getting Started =============================
@@ -45,13 +45,13 @@
/**
* Here are some standard links for getting your machine calibrated:
*
- * http://reprap.org/wiki/Calibration
- * http://youtu.be/wAL9d7FgInk
+ * https://reprap.org/wiki/Calibration
+ * https://youtu.be/wAL9d7FgInk
* http://calculator.josefprusa.cz
- * http://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide
- * http://www.thingiverse.com/thing:5573
+ * https://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide
+ * https://www.thingiverse.com/thing:5573
* https://sites.google.com/site/repraplogphase/calibration-of-your-reprap
- * http://www.thingiverse.com/thing:298812
+ * https://www.thingiverse.com/thing:298812
*/
//===========================================================================
@@ -140,13 +140,13 @@
#define CUSTOM_MACHINE_NAME "SKR i3"
// Printer's unique ID, used by some programs to differentiate between machines.
-// Choose your own or use a service like http://www.uuidgenerator.net/version4
+// Choose your own or use a service like https://www.uuidgenerator.net/version4
//#define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
// @section extruder
// This defines the number of extruders
-// :[1, 2, 3, 4, 5, 6, 7, 8]
+// :[0, 1, 2, 3, 4, 5, 6, 7, 8]
#define EXTRUDERS 1
// Generally expected filament diameter (1.75, 2.85, 3.0, ...). Used for Volumetric, Filament Width Sensor, etc.
@@ -155,6 +155,13 @@
// For Cyclops or any "multi-extruder" that shares a single nozzle.
//#define SINGLENOZZLE
+// Save and restore temperature and fan speed on tool-change.
+// Set standby for the unselected tool with M104/106/109 T...
+#if ENABLED(SINGLENOZZLE)
+ //#define SINGLENOZZLE_STANDBY_TEMP
+ //#define SINGLENOZZLE_STANDBY_FAN
+#endif
+
/**
* Průša MK2 Single Nozzle Multi-Material Multiplexer, and variants.
*
@@ -175,7 +182,7 @@
#endif
/**
- * Prusa Multi-Material Unit v2
+ * Průša Multi-Material Unit v2
*
* Requires NOZZLE_PARK_FEATURE to park print head in case MMU unit fails.
* Requires EXTRUDERS = 5
@@ -233,8 +240,8 @@
#elif ENABLED(MAGNETIC_PARKING_EXTRUDER)
- #define MPE_FAST_SPEED 9000 // (mm/m) Speed for travel before last distance point
- #define MPE_SLOW_SPEED 4500 // (mm/m) Speed for last distance travel to park and couple
+ #define MPE_FAST_SPEED 9000 // (mm/min) Speed for travel before last distance point
+ #define MPE_SLOW_SPEED 4500 // (mm/min) Speed for last distance travel to park and couple
#define MPE_TRAVEL_DISTANCE 10 // (mm) Last distance point
#define MPE_COMPENSATION 0 // Offset Compensation -1 , 0 , 1 (multiplier) only for coupling
@@ -282,8 +289,8 @@
#if ENABLED(PRIME_BEFORE_REMOVE)
#define SWITCHING_TOOLHEAD_PRIME_MM 20 // (mm) Extruder prime length
#define SWITCHING_TOOLHEAD_RETRACT_MM 10 // (mm) Retract after priming length
- #define SWITCHING_TOOLHEAD_PRIME_FEEDRATE 300 // (mm/m) Extruder prime feedrate
- #define SWITCHING_TOOLHEAD_RETRACT_FEEDRATE 2400 // (mm/m) Extruder retract feedrate
+ #define SWITCHING_TOOLHEAD_PRIME_FEEDRATE 300 // (mm/min) Extruder prime feedrate
+ #define SWITCHING_TOOLHEAD_RETRACT_FEEDRATE 2400 // (mm/min) Extruder retract feedrate
#endif
#elif ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
#define SWITCHING_TOOLHEAD_Z_HOP 2 // (mm) Z raise for switching
@@ -328,10 +335,10 @@
//#define PSU_NAME "Power Supply"
#if ENABLED(PSU_CONTROL)
- #define PSU_ACTIVE_HIGH false // Set 'false' for ATX, 'true' for X-Box
+ #define PSU_ACTIVE_STATE LOW // Set 'LOW' for ATX, 'HIGH' for X-Box
//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
- //#define PSU_POWERUP_DELAY 100 // (ms) Delay for the PSU to warm up to full power
+ //#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
//#define AUTO_POWER_CONTROL // Enable automatic control of the PS_ON pin
#if ENABLED(AUTO_POWER_CONTROL)
@@ -369,8 +376,9 @@
* 202 : 200k thermistor - Copymaster 3D
* 3 : Mendel-parts thermistor (4.7k pullup)
* 4 : 10k thermistor !! do not use it for a hotend. It gives bad resolution at high temp. !!
- * 5 : 100K thermistor - ATC Semitec 104GT-2/104NT-4-R025H42G (Used in ParCan & J-Head) (4.7k pullup)
+ * 5 : 100K thermistor - ATC Semitec 104GT-2/104NT-4-R025H42G (Used in ParCan, J-Head, and E3D) (4.7k pullup)
* 501 : 100K Zonestar (Tronxy X3A) Thermistor
+ * 502 : 100K Zonestar Thermistor used by hot bed in Zonestar Průša P802M
* 512 : 100k RPW-Ultra hotend thermistor (4.7k pullup)
* 6 : 100k EPCOS - Not as accurate as table 1 (created using a fluke thermocouple) (4.7k pullup)
* 7 : 100k Honeywell thermistor 135-104LAG-J01 (4.7k pullup)
@@ -378,13 +386,15 @@
* 8 : 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup)
* 9 : 100k GE Sensing AL03006-58.2K-97-G1 (4.7k pullup)
* 10 : 100k RS thermistor 198-961 (4.7k pullup)
- * 11 : 100k beta 3950 1% thermistor (4.7k pullup)
+ * 11 : 100k beta 3950 1% thermistor (Used in Keenovo AC silicone mats and most Wanhao i3 machines) (4.7k pullup)
* 12 : 100k 0603 SMD Vishay NTCS0603E3104FXT (4.7k pullup) (calibrated for Makibox hot bed)
* 13 : 100k Hisens 3950 1% up to 300°C for hotend "Simple ONE " & "Hotend "All In ONE"
* 15 : 100k thermistor calibration for JGAurora A5 hotend
* 18 : ATC Semitec 204GT-2 (4.7k pullup) Dagoma.Fr - MKS_Base_DKU001327
* 20 : Pt100 with circuit in the Ultimainboard V2.x with 5v excitation (AVR)
* 21 : Pt100 with circuit in the Ultimainboard V2.x with 3.3v excitation (STM32 \ LPC176x....)
+ * 22 : 100k (hotend) with 4.7k pullup to 3.3V and 220R to analog input (as in GTM32 Pro vB)
+ * 23 : 100k (bed) with 4.7k pullup to 3.3v and 220R to analog input (as in GTM32 Pro vB)
* 201 : Pt100 with circuit in Overlord, similar to Ultimainboard V2.x
* 60 : 100k Maker's Tool Works Kapton Bed Thermistor beta=3950
* 61 : 100k Formbot / Vivedino 3950 350C thermistor 4.7k pullup
@@ -400,7 +410,7 @@
* 52 : 200k thermistor - ATC Semitec 204GT-2 (1k pullup)
* 55 : 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan & J-Head) (1k pullup)
*
- * 1047 : Pt1000 with 4k7 pullup
+ * 1047 : Pt1000 with 4k7 pullup (E3D)
* 1010 : Pt1000 with 1k pullup (non standard)
* 147 : Pt100 with 4k7 pullup
* 110 : Pt100 with 1k pullup (non standard)
@@ -468,23 +478,19 @@
//===========================================================================
//============================= PID Settings ================================
//===========================================================================
-// PID Tuning Guide here: http://reprap.org/wiki/PID_Tuning
+// PID Tuning Guide here: https://reprap.org/wiki/PID_Tuning
// Comment the following line to disable PID and enable bang-bang.
#define PIDTEMP
#define BANG_MAX 255 // Limits current to nozzle while in bang-bang mode; 255=full current
#define PID_MAX BANG_MAX // Limits current to nozzle while PID is active (see PID_FUNCTIONAL_RANGE below); 255=full current
#define PID_K1 0.95 // Smoothing factor within any PID loop
+
#if ENABLED(PIDTEMP)
//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of PROGMEM)
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of PROGMEM)
- //#define PID_DEBUG // Sends debug data to the serial port. Use 'M303 D' to toggle activation.
- //#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
- //#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
//#define PID_PARAMS_PER_HOTEND // Uses separate PID parameters for each extruder (useful for mismatched extruders)
// Set/get with gcode: M301 E[extruder number, 0-2]
- #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
- // is more than PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
// If you are using a pre-configured hotend then you can use one of the value sets by uncommenting it
@@ -583,6 +589,14 @@
// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
#endif // PIDTEMPBED
+#if EITHER(PIDTEMP, PIDTEMPBED)
+ //#define PID_DEBUG // Sends debug data to the serial port. Use 'M303 D' to toggle activation.
+ //#define PID_OPENLOOP // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
+ //#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
+ #define PID_FUNCTIONAL_RANGE 10 // If the temperature difference between the target temperature and the actual temperature
+ // is more than PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
+#endif
+
// @section extruder
/**
@@ -732,7 +746,7 @@
* Enable if your probe or endstops falsely trigger due to noise.
*
* - Higher values may affect repeatability or accuracy of some bed probes.
- * - To fix noise install a 100nF ceramic capacitor inline with the switch.
+ * - To fix noise install a 100nF ceramic capacitor in parallel with the switch.
* - This feature is not required for common micro-switches mounted on PCBs
* based on the Makerbot design, which already have the 100nF capacitor.
*
@@ -740,6 +754,9 @@
*/
//#define ENDSTOP_NOISE_THRESHOLD 2
+// Check for stuck or disconnected endstops during homing moves.
+//#define DETECT_BROKEN_ENDSTOP
+
//=============================================================================
//============================== Movement Settings ============================
//=============================================================================
@@ -833,10 +850,12 @@
*
* See:
* https://reprap.org/forum/read.php?1,739819
- * http://blog.kyneticcnc.com/2018/10/computing-junction-deviation-for-marlin.html
+ * https://blog.kyneticcnc.com/2018/10/computing-junction-deviation-for-marlin.html
*/
#if DISABLED(CLASSIC_JERK)
- #define JUNCTION_DEVIATION_MM 0.02 // (mm) Distance from real junction edge
+ #define JUNCTION_DEVIATION_MM 0.013 // (mm) Distance from real junction edge
+ #define JD_HANDLE_SMALL_SEGMENTS // Use curvature estimation instead of just the junction angle
+ // for small segments (< 1mm) with large junction angles (> 135°).
#endif
/**
@@ -855,16 +874,19 @@
// @section probes
//
-// See http://marlinfw.org/docs/configuration/probes.html
+// See https://marlinfw.org/docs/configuration/probes.html
//
/**
- * Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
- *
- * Enable this option for a probe connected to the Z Min endstop pin.
+ * Enable this option for a probe connected to the Z-MIN pin.
+ * The probe replaces the Z-MIN endstop and is used for Z homing.
+ * (Automatically enables USE_PROBE_FOR_Z_HOMING.)
*/
#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
+// Force the use of the probe for Z-axis homing
+//#define USE_PROBE_FOR_Z_HOMING
+
/**
* Z_MIN_PROBE_PIN
*
@@ -921,6 +943,11 @@
*/
#define BLTOUCH
+/**
+ * Pressure sensor with a BLTouch-like interface
+ */
+//#define CREALITY_TOUCH
+
/**
* Touch-MI Probe by hotends.fr
*
@@ -972,38 +999,48 @@
//
/**
- * Z Probe to nozzle (X,Y) offset, relative to (0, 0).
+ * Nozzle-to-Probe offsets { X, Y, Z }
*
- * In the following example the X and Y offsets are both positive:
+ * - Use a caliper or ruler to measure the distance from the tip of
+ * the Nozzle to the center-point of the Probe in the X and Y axes.
+ * - For the Z offset use your best known value and adjust at runtime.
+ * - Probe Offsets can be tuned at runtime with 'M851', LCD menus, babystepping, etc.
*
- * #define NOZZLE_TO_PROBE_OFFSET { 10, 10, 0 }
+ * Assuming the typical work area orientation:
+ * - Probe to RIGHT of the Nozzle has a Positive X offset
+ * - Probe to LEFT of the Nozzle has a Negative X offset
+ * - Probe in BACK of the Nozzle has a Positive Y offset
+ * - Probe in FRONT of the Nozzle has a Negative Y offset
+ *
+ * Some examples:
+ * #define NOZZLE_TO_PROBE_OFFSET { 10, 10, -1 } // Example "1"
+ * #define NOZZLE_TO_PROBE_OFFSET {-10, 5, -1 } // Example "2"
+ * #define NOZZLE_TO_PROBE_OFFSET { 5, -5, -1 } // Example "3"
+ * #define NOZZLE_TO_PROBE_OFFSET {-15,-10, -1 } // Example "4"
*
* +-- BACK ---+
- * | |
- * L | (+) P | R <-- probe (20,20)
- * E | | I
- * F | (-) N (+) | G <-- nozzle (10,10)
- * T | | H
- * | (-) | T
- * | |
+ * | [+] |
+ * L | 1 | R <-- Example "1" (right+, back+)
+ * E | 2 | I <-- Example "2" ( left-, back+)
+ * F |[-] N [+]| G <-- Nozzle
+ * T | 3 | H <-- Example "3" (right+, front-)
+ * | 4 | T <-- Example "4" ( left-, front-)
+ * | [-] |
* O-- FRONT --+
- * (0,0)
- *
- * Specify a Probe position as { X, Y, Z }
*/
#define NOZZLE_TO_PROBE_OFFSET { -33, -37, -1 }
// Most probes should stay away from the edges of the bed, but
// with NOZZLE_AS_PROBE this can be negative for a wider probing area.
-#define MIN_PROBE_EDGE 10
+#define PROBING_MARGIN 10
-// X and Y axis travel speed (mm/m) between probes
-#define XY_PROBE_SPEED 8000
+// X and Y axis travel speed (mm/min) between probes
+#define XY_PROBE_SPEED (133*60)
-// Feedrate (mm/m) for the first approach when double-probing (MULTIPLE_PROBING == 2)
+// Feedrate (mm/min) for the first approach when double-probing (MULTIPLE_PROBING == 2)
#define Z_PROBE_SPEED_FAST HOMING_FEEDRATE_Z
-// Feedrate (mm/m) for the "accurate" probe of each point
+// Feedrate (mm/min) for the "accurate" probe of each point
#define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2)
/**
@@ -1074,18 +1111,18 @@
#define Z_ENABLE_ON 0
#define E_ENABLE_ON 0 // For all extruders
-// Disables axis stepper immediately when it's not being used.
+// Disable axis steppers immediately when they're not being stepped.
// WARNING: When motors turn off there is a chance of losing position accuracy!
#define DISABLE_X false
#define DISABLE_Y false
#define DISABLE_Z false
-// Warn on display about possibly reduced accuracy
+// Turn off the display blinking that warns about possible accuracy reduction
//#define DISABLE_REDUCED_ACCURACY_WARNING
// @section extruder
-#define DISABLE_E false // For all extruders
+#define DISABLE_E false // Disable the extruder when not stepping
#define DISABLE_INACTIVE_EXTRUDER // Keep only the active extruder enabled
// @section machine
@@ -1173,14 +1210,14 @@
*
* RAMPS-based boards use SERVO3_PIN for the first runout sensor.
* For other boards you may need to define FIL_RUNOUT_PIN, FIL_RUNOUT2_PIN, etc.
- * By default the firmware assumes HIGH=FILAMENT PRESENT.
*/
//#define FILAMENT_RUNOUT_SENSOR
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
- #define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
- #define FIL_RUNOUT_INVERTING false // Set to true to invert the logic of the sensor.
- #define FIL_RUNOUT_PULLUP // Use internal pullup for filament runout pins.
- //#define FIL_RUNOUT_PULLDOWN // Use internal pulldown for filament runout pins.
+ #define FIL_RUNOUT_ENABLED_DEFAULT true // Enable the sensor on startup. Override with M412 followed by M500.
+ #define NUM_RUNOUT_SENSORS 1 // Number of sensors, up to one per extruder. Define a FIL_RUNOUT#_PIN for each.
+ #define FIL_RUNOUT_STATE LOW // Pin state indicating that filament is NOT present.
+ #define FIL_RUNOUT_PULLUP // Use internal pullup for filament runout pins.
+ //#define FIL_RUNOUT_PULLDOWN // Use internal pulldown for filament runout pins.
// Set one or more commands to execute on filament runout.
// (After 'M412 H' Marlin will ask the host to handle the process.)
@@ -1370,7 +1407,6 @@
*/
//#define Z_PROBE_END_SCRIPT "G1 Z10 F12000\nG1 X15 Y330\nG1 Z0.5\nG1 Z10"
-
// @section homing
// The center of the bed is at (X=0, Y=0)
@@ -1388,17 +1424,17 @@
//
// - Allow Z homing only after X and Y homing AND stepper drivers still enabled.
// - If stepper drivers time out, it will need X and Y homing again before Z homing.
-// - Move the Z probe (or nozzle) to a defined XY point before Z Homing when homing all axes (G28).
+// - Move the Z probe (or nozzle) to a defined XY point before Z Homing.
// - Prevent Z homing when the Z probe is outside bed area.
//
#define Z_SAFE_HOMING
#if ENABLED(Z_SAFE_HOMING)
- #define Z_SAFE_HOMING_X_POINT ((X_BED_SIZE) / 2) // X point for Z homing when homing all axes (G28).
- #define Z_SAFE_HOMING_Y_POINT ((Y_BED_SIZE) / 2) // Y point for Z homing when homing all axes (G28).
+ #define Z_SAFE_HOMING_X_POINT X_CENTER // X point for Z homing
+ #define Z_SAFE_HOMING_Y_POINT Y_CENTER // Y point for Z homing
#endif
-// Homing speeds (mm/m)
+// Homing speeds (mm/min)
#define HOMING_FEEDRATE_XY (50*60)
#define HOMING_FEEDRATE_Z (4*60)
@@ -1533,8 +1569,11 @@
#if ENABLED(NOZZLE_PARK_FEATURE)
// Specify a park position as { X, Y, Z_raise }
#define NOZZLE_PARK_POINT { (X_MIN_POS + 10), (Y_MAX_POS - 10), 20 }
- #define NOZZLE_PARK_XY_FEEDRATE 80 // (mm/s) X and Y axes feedrate (also used for delta Z axis)
- #define NOZZLE_PARK_Z_FEEDRATE 5 // (mm/s) Z axis feedrate (not used for delta printers)
+ //#define NOZZLE_PARK_X_ONLY // X move only is required to park
+ //#define NOZZLE_PARK_Y_ONLY // Y move only is required to park
+ #define NOZZLE_PARK_Z_RAISE_MIN 2 // (mm) Always raise Z by at least this distance
+ #define NOZZLE_PARK_XY_FEEDRATE 80 // (mm/s) X and Y axes feedrate (also used for delta Z axis)
+ #define NOZZLE_PARK_Z_FEEDRATE 5 // (mm/s) Z axis feedrate (not used for delta printers)
#endif
/**
@@ -1599,8 +1638,15 @@
// Move the nozzle to the initial position after cleaning
#define NOZZLE_CLEAN_GOBACK
- // Enable for a purge/clean station that's always at the gantry height (thus no Z move)
+ // For a purge/clean station that's always at the gantry height (thus no Z move)
//#define NOZZLE_CLEAN_NO_Z
+
+ // For a purge/clean station mounted on the X axis
+ //#define NOZZLE_CLEAN_NO_Y
+
+ // Explicit wipe G-code script applies to a G12 with no arguments.
+ //#define WIPE_SEQUENCE_COMMANDS "G1 X-17 Y25 Z10 F4000\nG1 Z1\nM114\nG1 X-17 Y25\nG1 X-17 Y95\nG1 X-17 Y25\nG1 X-17 Y95\nG1 X-17 Y25\nG1 X-17 Y95\nG1 X-17 Y25\nG1 X-17 Y95\nG1 X-17 Y25\nG1 X-17 Y95\nG1 X-17 Y25\nG1 X-17 Y95\nG1 Z15\nM400\nG0 X-10.0 Y-9.0"
+
#endif
/**
@@ -1634,6 +1680,37 @@
*/
#define PRINTCOUNTER
+/**
+ * Password
+ *
+ * Set a numerical password for the printer which can be requested:
+ *
+ * - When the printer boots up
+ * - Upon opening the 'Print from Media' Menu
+ * - When SD printing is completed or aborted
+ *
+ * The following G-codes can be used:
+ *
+ * M510 - Lock Printer. Blocks all commands except M511.
+ * M511 - Unlock Printer.
+ * M512 - Set, Change and Remove Password.
+ *
+ * If you forget the password and get locked out you'll need to re-flash
+ * the firmware with the feature disabled, reset EEPROM, and (optionally)
+ * re-flash the firmware again with this feature enabled.
+ */
+//#define PASSWORD_FEATURE
+#if ENABLED(PASSWORD_FEATURE)
+ #define PASSWORD_LENGTH 4 // (#) Number of digits (1-9). 3 or 4 is recommended
+ #define PASSWORD_ON_STARTUP
+ #define PASSWORD_UNLOCK_GCODE // Unlock with the M511 P command. Disable to prevent brute-force attack.
+ #define PASSWORD_CHANGE_GCODE // Change the password with M512 P S.
+ //#define PASSWORD_ON_SD_PRINT_MENU // This does not prevent gcodes from running
+ //#define PASSWORD_AFTER_SD_PRINT_END
+ //#define PASSWORD_AFTER_SD_PRINT_ABORT
+ //#include "Configuration_Secure.h" // External file with PASSWORD_DEFAULT_VALUE
+#endif
+
//=============================================================================
//============================= LCD and SD support ============================
//=============================================================================
@@ -1645,10 +1722,10 @@
*
* Select the language to display on the LCD. These languages are available:
*
- * en, an, bg, ca, cz, da, de, el, el_gr, es, eu, fi, fr, gl, hr, it, jp_kana,
- * ko_KR, nl, pl, pt, pt_br, ru, sk, tr, uk, vi, zh_CN, zh_TW, test
+ * en, an, bg, ca, cz, da, de, el, el_gr, es, eu, fi, fr, gl, hr, hu, it,
+ * jp_kana, ko_KR, nl, pl, pt, pt_br, ro, ru, sk, tr, uk, vi, zh_CN, zh_TW, test
*
- * :{ 'en':'English', 'an':'Aragonese', 'bg':'Bulgarian', 'ca':'Catalan', 'cz':'Czech', 'da':'Danish', 'de':'German', 'el':'Greek', 'el_gr':'Greek (Greece)', 'es':'Spanish', 'eu':'Basque-Euskera', 'fi':'Finnish', 'fr':'French', 'gl':'Galician', 'hr':'Croatian', 'it':'Italian', 'jp_kana':'Japanese', 'ko_KR':'Korean (South Korea)', 'nl':'Dutch', 'pl':'Polish', 'pt':'Portuguese', 'pt_br':'Portuguese (Brazilian)', 'ru':'Russian', 'sk':'Slovak', 'tr':'Turkish', 'uk':'Ukrainian', 'vi':'Vietnamese', 'zh_CN':'Chinese (Simplified)', 'zh_TW':'Chinese (Traditional)', 'test':'TEST' }
+ * :{ 'en':'English', 'an':'Aragonese', 'bg':'Bulgarian', 'ca':'Catalan', 'cz':'Czech', 'da':'Danish', 'de':'German', 'el':'Greek', 'el_gr':'Greek (Greece)', 'es':'Spanish', 'eu':'Basque-Euskera', 'fi':'Finnish', 'fr':'French', 'gl':'Galician', 'hr':'Croatian', 'hu':'Hungarian', 'it':'Italian', 'jp_kana':'Japanese', 'ko_KR':'Korean (South Korea)', 'nl':'Dutch', 'pl':'Polish', 'pt':'Portuguese', 'pt_br':'Portuguese (Brazilian)', 'ro':'Romanian', 'ru':'Russian', 'sk':'Slovak', 'tr':'Turkish', 'uk':'Ukrainian', 'vi':'Vietnamese', 'zh_CN':'Chinese (Simplified)', 'zh_TW':'Chinese (Traditional)', 'test':'TEST' }
*/
#define LCD_LANGUAGE en
@@ -1670,16 +1747,16 @@
* - Click the controller to view the LCD menu
* - The LCD will display Japanese, Western, or Cyrillic text
*
- * See http://marlinfw.org/docs/development/lcd_language.html
+ * See https://marlinfw.org/docs/development/lcd_language.html
*
* :['JAPANESE', 'WESTERN', 'CYRILLIC']
*/
#define DISPLAY_CHARSET_HD44780 JAPANESE
/**
- * Info Screen Style (0:Classic, 1:Prusa)
+ * Info Screen Style (0:Classic, 1:Průša)
*
- * :[0:'Classic', 1:'Prusa']
+ * :[0:'Classic', 1:'Průša']
*/
#define LCD_INFO_SCREEN_STYLE 0
@@ -1797,7 +1874,7 @@
//
// RepRapDiscount Smart Controller.
-// http://reprap.org/wiki/RepRapDiscount_Smart_Controller
+// https://reprap.org/wiki/RepRapDiscount_Smart_Controller
//
// Note: Usually sold with a white PCB.
//
@@ -1821,13 +1898,13 @@
//
// PanelOne from T3P3 (via RAMPS 1.4 AUX2/AUX3)
-// http://reprap.org/wiki/PanelOne
+// https://reprap.org/wiki/PanelOne
//
//#define PANEL_ONE
//
// GADGETS3D G3D LCD/SD Controller
-// http://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel
+// https://reprap.org/wiki/RAMPS_1.3/1.4_GADGETS3D_Shield_with_Panel
//
// Note: Usually sold with a blue PCB.
//
@@ -1914,7 +1991,7 @@
//
// 2-wire Non-latching LCD SR from https://goo.gl/aJJ4sH
-// LCD configuration: http://reprap.org/wiki/SAV_3D_LCD
+// LCD configuration: https://reprap.org/wiki/SAV_3D_LCD
//
//#define SAV_3DLCD
@@ -1936,10 +2013,12 @@
// IMPORTANT: The U8glib library is required for Graphical Display!
// https://github.com/olikraus/U8glib_Arduino
//
+// NOTE: If the LCD is unresponsive you may need to reverse the plugs.
+//
//
// RepRapDiscount FULL GRAPHIC Smart Controller
-// http://reprap.org/wiki/RepRapDiscount_Full_Graphic_Smart_Controller
+// https://reprap.org/wiki/RepRapDiscount_Full_Graphic_Smart_Controller
//
#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
@@ -1952,20 +2031,20 @@
//
// Activate one of these if you have a Panucatt Devices
// Viki 2.0 or mini Viki with Graphic LCD
-// http://panucatt.com
+// https://www.panucatt.com
//
//#define VIKI2
//#define miniVIKI
//
// MakerLab Mini Panel with graphic
-// controller and SD support - http://reprap.org/wiki/Mini_panel
+// controller and SD support - https://reprap.org/wiki/Mini_panel
//
//#define MINIPANEL
//
// MaKr3d Makr-Panel with graphic controller and SD support.
-// http://reprap.org/wiki/MaKr3d_MaKrPanel
+// https://reprap.org/wiki/MaKr3d_MaKrPanel
//
//#define MAKRPANEL
@@ -2008,6 +2087,12 @@
//
//#define MKS_MINI_12864
+//
+// MKS LCD12864A/B with graphic controller and SD support. Follows MKS_MINI_12864 pinout.
+// https://www.aliexpress.com/item/33018110072.html
+//
+//#define MKS_LCD12864
+
//
// FYSETC variant of the MINI12864 graphic controller with SD support
// https://wiki.fysetc.com/Mini12864_Panel/
@@ -2015,7 +2100,7 @@
//#define FYSETC_MINI_12864_X_X // Type C/D/E/F. No tunable RGB Backlight by default
//#define FYSETC_MINI_12864_1_2 // Type C/D/E/F. Simple RGB Backlight (always on)
//#define FYSETC_MINI_12864_2_0 // Type A/B. Discreet RGB Backlight
-//#define FYSETC_MINI_12864_2_1 // Type A/B. Neopixel RGB Backlight
+//#define FYSETC_MINI_12864_2_1 // Type A/B. NeoPixel RGB Backlight
//#define FYSETC_GENERIC_12864_1_1 // Larger display with basic ON/OFF backlight.
//
@@ -2049,7 +2134,7 @@
//
// Silvergate GLCD controller
-// http://github.com/android444/Silvergate
+// https://github.com/android444/Silvergate
//
//#define SILVER_GATE_GLCD_CONTROLLER
@@ -2077,14 +2162,21 @@
//#define OLED_PANEL_TINYBOY2
//
-// MKS OLED 1.3" 128 × 64 FULL GRAPHICS CONTROLLER
-// http://reprap.org/wiki/MKS_12864OLED
+// MKS OLED 1.3" 128×64 FULL GRAPHICS CONTROLLER
+// https://reprap.org/wiki/MKS_12864OLED
//
// Tiny, but very sharp OLED display
//
//#define MKS_12864OLED // Uses the SH1106 controller (default)
//#define MKS_12864OLED_SSD1306 // Uses the SSD1306 controller
+//
+// Zonestar OLED 128×64 FULL GRAPHICS CONTROLLER
+//
+//#define ZONESTAR_12864LCD // Graphical (DOGM) with ST7920 controller
+//#define ZONESTAR_12864OLED // 1.3" OLED with SH1106 controller (default)
+//#define ZONESTAR_12864OLED_SSD1306 // 0.96" OLED with SSD1306 controller
+
//
// Einstart S OLED SSD1306
//
@@ -2095,19 +2187,26 @@
//
//#define OVERLORD_OLED
+//
+// FYSETC OLED 2.42" 128×64 FULL GRAPHICS CONTROLLER with WS2812 RGB
+// Where to find : https://www.aliexpress.com/item/4000345255731.html
+//#define FYSETC_242_OLED_12864 // Uses the SSD1309 controller
+
//=============================================================================
//========================== Extensible UI Displays ===========================
//=============================================================================
//
// DGUS Touch Display with DWIN OS. (Choose one.)
+// ORIGIN : https://www.aliexpress.com/item/32993409517.html
+// FYSETC : https://www.aliexpress.com/item/32961471929.html
//
//#define DGUS_LCD_UI_ORIGIN
//#define DGUS_LCD_UI_FYSETC
//#define DGUS_LCD_UI_HIPRECY
//
-// Touch-screen LCD for Malyan M200 printers
+// Touch-screen LCD for Malyan M200/M300 printers
//
//#define MALYAN_LCD
@@ -2117,42 +2216,96 @@
//
//#define TOUCH_UI_FTDI_EVE
+//
+// Touch-screen LCD for Anycubic printers
+//
+//#define ANYCUBIC_LCD_I3MEGA
+//#define ANYCUBIC_LCD_CHIRON
+#if EITHER(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON)
+ #define ANYCUBIC_LCD_SERIAL_PORT 3
+ //#define ANYCUBIC_LCD_DEBUG
+#endif
+
//
// Third-party or vendor-customized controller interfaces.
// Sources should be installed in 'src/lcd/extensible_ui'.
//
//#define EXTENSIBLE_UI
+#if ENABLED(EXTENSIBLE_UI)
+ //#define EXTUI_LOCAL_BEEPER // Enables use of local Beeper pin with external display
+#endif
+
//=============================================================================
//=============================== Graphical TFTs ==============================
//=============================================================================
+//
+// TFT display with optional touch screen
+// Color Marlin UI with standard menu system
+//
+//#define TFT_320x240
+//#define TFT_320x240_SPI
+//#define TFT_480x320
+//#define TFT_480x320_SPI
+
+//
+// Skip autodetect and force specific TFT driver
+// Mandatory for SPI screens with no MISO line
+// Available drivers are: ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488
+//
+//#define TFT_DRIVER AUTO
+
+//
+// SPI display (MKS Robin Nano V2.0, MKS Gen L V2.0)
+// Upscaled 128x64 Marlin UI
+//
+//#define SPI_GRAPHICAL_TFT
+
//
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.)
+// Upscaled 128x64 Marlin UI
//
//#define FSMC_GRAPHICAL_TFT
+//
+// TFT LVGL UI
+//
+// Using default MKS icons and fonts from: https://git.io/JJvzK
+// Just copy the 'assets' folder from the build directory to the
+// root of your SD card, together with the compiled firmware.
+//
+//#define TFT_LVGL_UI_FSMC // Robin nano v1.2 uses FSMC
+//#define TFT_LVGL_UI_SPI // Robin nano v2.0 uses SPI
+
//=============================================================================
//============================ Other Controllers ============================
//=============================================================================
+//
+// Ender-3 v2 OEM display. A DWIN display with Rotary Encoder.
+//
+//#define DWIN_CREALITY_LCD
+
//
// ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
//
-//#define TOUCH_BUTTONS
-#if ENABLED(TOUCH_BUTTONS)
+//#define TOUCH_SCREEN
+#if ENABLED(TOUCH_SCREEN)
#define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
- #define XPT2046_X_CALIBRATION 12316
- #define XPT2046_Y_CALIBRATION -8981
- #define XPT2046_X_OFFSET -43
- #define XPT2046_Y_OFFSET 257
+ #define TOUCH_SCREEN_CALIBRATION
+
+ //#define XPT2046_X_CALIBRATION 12316
+ //#define XPT2046_Y_CALIBRATION -8981
+ //#define XPT2046_X_OFFSET -43
+ //#define XPT2046_Y_OFFSET 257
#endif
//
// RepRapWorld REPRAPWORLD_KEYPAD v1.1
-// http://reprapworld.com/?products_details&products_id=202&cPath=1591_1626
+// https://reprapworld.com/products/electronics/ramps/keypad_v1_0_fully_assembled/
//
//#define REPRAPWORLD_KEYPAD
//#define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 // (mm) Distance to move per key-press
@@ -2163,6 +2316,10 @@
// @section extras
+// Set number of user-controlled fans. Disable to use all board-defined fans.
+// :[1,2,3,4,5,6,7,8]
+//#define NUM_M106_FANS 1
+
// Increase the FAN PWM frequency. Removes the PWM noise but increases heating in the FET/Arduino
//#define FAST_PWM_FAN
@@ -2189,7 +2346,7 @@
// then the BLUE led is on. Otherwise the RED led is on. (1C hysteresis)
//#define TEMP_STAT_LEDS
-// SkeinForge sends the wrong arc g-codes when using Arc Point as fillet procedure
+// SkeinForge sends the wrong arc G-codes when using Arc Point as fillet procedure
//#define SF_ARC_FIX
// Support for the BariCUDA Paste Extruder
@@ -2202,7 +2359,6 @@
//#define PCA9632
// Support for PCA9533 PWM LED driver
-// https://github.com/mikeshub/SailfishRGB_LED
//#define PCA9533
/**
@@ -2214,13 +2370,13 @@
* Adds the M150 command to set the LED (or LED strip) color.
* If pins are PWM capable (e.g., 4, 5, 6, 11) then a range of
* luminance values can be set from 0 to 255.
- * For Neopixel LED an overall brightness parameter is also available.
+ * For NeoPixel LED an overall brightness parameter is also available.
*
* *** CAUTION ***
* LED Strips require a MOSFET Chip between PWM lines and LEDs,
* as the Arduino cannot handle the current the LEDs will require.
* Failure to follow this precaution can destroy your Arduino!
- * NOTE: A separate 5V power supply is required! The Neopixel LED needs
+ * NOTE: A separate 5V power supply is required! The NeoPixel LED needs
* more current than the Arduino 5V linear regulator can produce.
* *** CAUTION ***
*
@@ -2237,19 +2393,29 @@
//#define RGB_LED_W_PIN -1
#endif
-// Support for Adafruit Neopixel LED driver
+// Support for Adafruit NeoPixel LED driver
//#define NEOPIXEL_LED
#if ENABLED(NEOPIXEL_LED)
#define NEOPIXEL_TYPE NEO_GRBW // NEO_GRBW / NEO_GRB - four/three channel driver type (defined in Adafruit_NeoPixel.h)
#define NEOPIXEL_PIN 4 // LED driving pin
//#define NEOPIXEL2_TYPE NEOPIXEL_TYPE
//#define NEOPIXEL2_PIN 5
- #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip, larger of 2 strips if 2 neopixel strips are used
+ #define NEOPIXEL_PIXELS 30 // Number of LEDs in the strip. (Longest strip when NEOPIXEL2_SEPARATE is disabled.)
#define NEOPIXEL_IS_SEQUENTIAL // Sequential display for temperature change - LED by LED. Disable to change all LEDs at once.
#define NEOPIXEL_BRIGHTNESS 127 // Initial brightness (0-255)
//#define NEOPIXEL_STARTUP_TEST // Cycle through colors at startup
- // Use a single Neopixel LED for static (background) lighting
+ // Support for second Adafruit NeoPixel LED driver controlled with M150 S1 ...
+ //#define NEOPIXEL2_SEPARATE
+ #if ENABLED(NEOPIXEL2_SEPARATE)
+ #define NEOPIXEL2_PIXELS 15 // Number of LEDs in the second strip
+ #define NEOPIXEL2_BRIGHTNESS 127 // Initial brightness (0-255)
+ #define NEOPIXEL2_STARTUP_TEST // Cycle through colors at startup
+ #else
+ //#define NEOPIXEL2_INSERIES // Default behavior is NeoPixel 2 in parallel
+ #endif
+
+ // Use a single NeoPixel LED for static (background) lighting
//#define NEOPIXEL_BKGD_LED_INDEX 0 // Index of the LED to use
//#define NEOPIXEL_BKGD_COLOR { 255, 255, 255, 0 } // R, G, B, W
#endif
diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index 47e6edd857..ff84139221 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -31,14 +31,27 @@
* Basic settings can be found in Configuration.h
*
*/
-#define CONFIGURATION_ADV_H_VERSION 020005
+#define CONFIGURATION_ADV_H_VERSION 020006
// @section temperature
//===========================================================================
-//=============================Thermal Settings ============================
+//============================= Thermal Settings ============================
//===========================================================================
+/**
+ * Thermocouple sensors are quite sensitive to noise. Any noise induced in
+ * the sensor wires, such as by stepper motor wires run in parallel to them,
+ * may result in the thermocouple sensor reporting spurious errors. This
+ * value is the number of errors which can occur in a row before the error
+ * is reported. This allows us to ignore intermittent error conditions while
+ * still detecting an actual failure, which should result in a continuous
+ * stream of errors from the sensor.
+ *
+ * Set this value to 0 to fail on the first error to occur.
+ */
+#define THERMOCOUPLE_MAX_ERRORS 15
+
//
// Custom Thermistor 1000 parameters
//
@@ -206,7 +219,7 @@
// A well-chosen Kc value should add just enough power to melt the increased material volume.
//#define PID_EXTRUSION_SCALING
#if ENABLED(PID_EXTRUSION_SCALING)
- #define DEFAULT_Kc (100) //heating power=Kc*(e_speed)
+ #define DEFAULT_Kc (100) // heating power = Kc * e_speed
#define LPQ_MAX_LEN 50
#endif
@@ -262,25 +275,30 @@
#endif
/**
- * Automatic Temperature:
- * The hotend target temperature is calculated by all the buffered lines of gcode.
- * The maximum buffered steps/sec of the extruder motor is called "se".
- * Start autotemp mode with M109 S B F
- * The target temperature is set to mintemp+factor*se[steps/sec] and is limited by
- * mintemp and maxtemp. Turn this off by executing M109 without F*
- * Also, if the temperature is set to a value below mintemp, it will not be changed by autotemp.
- * On an Ultimaker, some initial testing worked with M109 S215 B260 F1 in the start.gcode
+ * Automatic Temperature Mode
+ *
+ * Dynamically adjust the hotend target temperature based on planned E moves.
+ *
+ * (Contrast with PID_EXTRUSION_SCALING, which tracks E movement and adjusts PID
+ * behavior using an additional kC value.)
+ *
+ * Autotemp is calculated by (mintemp + factor * mm_per_sec), capped to maxtemp.
+ *
+ * Enable Autotemp Mode with M104/M109 F S B.
+ * Disable by sending M104/M109 with no F parameter (or F0 with AUTOTEMP_PROPORTIONAL).
*/
#define AUTOTEMP
#if ENABLED(AUTOTEMP)
- #define AUTOTEMP_OLDWEIGHT 0.98
+ #define AUTOTEMP_OLDWEIGHT 0.98
+ // Turn on AUTOTEMP on M104/M109 by default using proportions set here
+ //#define AUTOTEMP_PROPORTIONAL
+ #if ENABLED(AUTOTEMP_PROPORTIONAL)
+ #define AUTOTEMP_MIN_P 0 // (°C) Added to the target temperature
+ #define AUTOTEMP_MAX_P 5 // (°C) Added to the target temperature
+ #define AUTOTEMP_FACTOR_P 1 // Apply this F parameter by default (overridden by M104/M109 F)
+ #endif
#endif
-// Extra options for the M114 "Current Position" report
-//#define M114_DETAIL // Use 'M114` for details to check planner calculations
-//#define M114_REALTIME // Real current position based on forward kinematics
-//#define M114_LEGACY // M114 used to synchronize on every call. Enable if needed.
-
// Show Temperature ADC value
// Enable for M105 to include ADC values read from temperature sensors.
//#define SHOW_TEMP_ADC_VALUES
@@ -321,10 +339,22 @@
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
#define EXTRUDER_RUNOUT_MINTEMP 190
#define EXTRUDER_RUNOUT_SECONDS 30
- #define EXTRUDER_RUNOUT_SPEED 1500 // (mm/m)
+ #define EXTRUDER_RUNOUT_SPEED 1500 // (mm/min)
#define EXTRUDER_RUNOUT_EXTRUDE 5 // (mm)
#endif
+/**
+ * Hotend Idle Timeout
+ * Prevent filament in the nozzle from charring and causing a critical jam.
+ */
+//#define HOTEND_IDLE_TIMEOUT
+#if ENABLED(HOTEND_IDLE_TIMEOUT)
+ #define HOTEND_IDLE_TIMEOUT_SEC (5*60) // (seconds) Time without extruder movement to trigger protection
+ #define HOTEND_IDLE_MIN_TRIGGER 180 // (°C) Minimum temperature to enable hotend protection
+ #define HOTEND_IDLE_NOZZLE_TARGET 0 // (°C) Safe temperature for the nozzle after timeout
+ #define HOTEND_IDLE_BED_TARGET 0 // (°C) Safe temperature for the bed after timeout
+#endif
+
// @section temperature
// Calibration for AD595 / AD8495 sensor to adjust temperature measurements.
@@ -340,12 +370,12 @@
*
* The fan turns on automatically whenever any driver is enabled and turns
* off (or reduces to idle speed) shortly after drivers are turned off.
- *
*/
//#define USE_CONTROLLER_FAN
#if ENABLED(USE_CONTROLLER_FAN)
//#define CONTROLLER_FAN_PIN -1 // Set a custom pin for the controller fan
//#define CONTROLLER_FAN_USE_Z_ONLY // With this option only the Z axis is considered
+ //#define CONTROLLER_FAN_IGNORE_Z // Ignore Z stepper. Useful when stepper timeout is disabled.
#define CONTROLLERFAN_SPEED_MIN 0 // (0-255) Minimum speed. (If set below this value the fan is turned off.)
#define CONTROLLERFAN_SPEED_ACTIVE 255 // (0-255) Active speed, used when any motor is enabled
#define CONTROLLERFAN_SPEED_IDLE 0 // (0-255) Idle speed, used when motors are disabled
@@ -426,6 +456,8 @@
#define E3_AUTO_FAN_PIN -1
#define E4_AUTO_FAN_PIN -1
#define E5_AUTO_FAN_PIN -1
+#define E6_AUTO_FAN_PIN -1
+#define E7_AUTO_FAN_PIN -1
#define CHAMBER_AUTO_FAN_PIN -1
#define EXTRUDER_AUTO_FAN_TEMPERATURE 50
@@ -456,7 +488,7 @@
//#define CASE_LIGHT_MAX_PWM 128 // Limit pwm
//#define CASE_LIGHT_MENU // Add Case Light options to the LCD menu
//#define CASE_LIGHT_NO_BRIGHTNESS // Disable brightness control. Enable for non-PWM lighting.
- //#define CASE_LIGHT_USE_NEOPIXEL // Use Neopixel LED as case light, requires NEOPIXEL_LED.
+ //#define CASE_LIGHT_USE_NEOPIXEL // Use NeoPixel LED as case light, requires NEOPIXEL_LED.
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
#define CASE_LIGHT_NEOPIXEL_COLOR { 255, 255, 255, 255 } // { Red, Green, Blue, White }
#endif
@@ -581,8 +613,7 @@
// Default x offset in duplication mode (typically set to half print bed width)
#define DEFAULT_DUPLICATION_X_OFFSET 100
-
-#endif // DUAL_X_CARRIAGE
+#endif
// Activate a solenoid on the active extruder with M380. Disable all with M381.
// Define SOL0_PIN, SOL1_PIN, etc., for each extruder that has a solenoid.
@@ -590,19 +621,24 @@
// @section homing
-// Homing hits each endstop, retracts by these distances, then does a slower bump.
-#define X_HOME_BUMP_MM 5
-#define Y_HOME_BUMP_MM 5
-#define Z_HOME_BUMP_MM 2
-#define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate)
-//#define QUICK_HOME // If homing includes X and Y, do a diagonal move initially
-//#define HOMING_BACKOFF_MM { 2, 2, 2 } // (mm) Move away from the endstops after homing
+/**
+ * Homing Procedure
+ * Homing (G28) does an indefinite move towards the endstops to establish
+ * the position of the toolhead relative to the workspace.
+ */
-// When G28 is called, this option will make Y home before X
-//#define HOME_Y_BEFORE_X
+//#define SENSORLESS_BACKOFF_MM { 2, 2 } // (mm) Backoff from endstops before sensorless homing
-// Enable this if X or Y can't home without homing the other axis first.
-//#define CODEPENDENT_XY_HOMING
+#define HOMING_BUMP_MM { 5, 5, 2 } // (mm) Backoff from endstops after first bump
+#define HOMING_BUMP_DIVISOR { 2, 2, 4 } // Re-Bump Speed Divisor (Divides the Homing Feedrate)
+
+//#define HOMING_BACKOFF_POST_MM { 2, 2, 2 } // (mm) Backoff from endstops after homing
+
+//#define QUICK_HOME // If G28 contains XY do a diagonal move first
+//#define HOME_Y_BEFORE_X // If G28 contains XY home Y before X
+//#define CODEPENDENT_XY_HOMING // If X/Y can't home without homing Y/X first
+
+// @section bltouch
#if ENABLED(BLTOUCH)
/**
@@ -610,8 +646,8 @@
* Do not activate settings that the probe might not understand. Clones might misunderstand
* advanced commands.
*
- * Note: If the probe is not deploying, check a "Cmd: Reset" and "Cmd: Self-Test" and then
- * check the wiring of the BROWN, RED and ORANGE wires.
+ * Note: If the probe is not deploying, do a "Reset" and "Self-Test" and then check the
+ * wiring of the BROWN, RED and ORANGE wires.
*
* Note: If the trigger signal of your probe is not being recognized, it has been very often
* because the BLACK and WHITE wires needed to be swapped. They are not "interchangeable"
@@ -644,7 +680,7 @@
* Danger: Don't activate 5V mode unless attached to a 5V-tolerant controller!
* V3.0 or 3.1: Set default mode to 5V mode at Marlin startup.
* If disabled, OD mode is the hard-coded default on 3.0
- * On startup, Marlin will compare its eeprom to this vale. If the selected mode
+ * On startup, Marlin will compare its eeprom to this value. If the selected mode
* differs, a mode set eeprom write will be completed at initialization.
* Use the option below to force an eeprom write to a V3.1 probe regardless.
*/
@@ -671,6 +707,8 @@
#endif // BLTOUCH
+// @section extras
+
/**
* Z Steppers Auto-Alignment
* Add the G34 command to align multiple Z steppers using a bed probe.
@@ -730,6 +768,34 @@
#define HOME_AFTER_G34
#endif
+//
+// Add the G35 command to read bed corners to help adjust screws. Requires a bed probe.
+//
+//#define ASSISTED_TRAMMING
+#if ENABLED(ASSISTED_TRAMMING)
+
+ // Define positions for probing points, use the hotend as reference not the sensor.
+ #define TRAMMING_POINT_XY { { 20, 20 }, { 200, 20 }, { 200, 200 }, { 20, 200 } }
+
+ // Define positions names for probing points.
+ #define TRAMMING_POINT_NAME_1 "Front-Left"
+ #define TRAMMING_POINT_NAME_2 "Front-Right"
+ #define TRAMMING_POINT_NAME_3 "Back-Right"
+ #define TRAMMING_POINT_NAME_4 "Back-Left"
+
+ // Enable to restore leveling setup after operation
+ #define RESTORE_LEVELING_AFTER_G35
+
+ /**
+ * Screw thread:
+ * M3: 30 = Clockwise, 31 = Counter-Clockwise
+ * M4: 40 = Clockwise, 41 = Counter-Clockwise
+ * M5: 50 = Clockwise, 51 = Counter-Clockwise
+ */
+ #define TRAMMING_SCREW_THREAD 30
+
+#endif
+
// @section motion
#define AXIS_RELATIVE_MODES { false, false, false, false }
@@ -743,35 +809,46 @@
#define INVERT_Z_STEP_PIN false
#define INVERT_E_STEP_PIN false
-// Default stepper release if idle. Set to 0 to deactivate.
-// Steppers will shut down DEFAULT_STEPPER_DEACTIVE_TIME seconds after the last move when DISABLE_INACTIVE_? is true.
-// Time can be set by M18 and M84.
+/**
+ * Idle Stepper Shutdown
+ * Set DISABLE_INACTIVE_? 'true' to shut down axis steppers after an idle period.
+ * The Deactive Time can be overridden with M18 and M84. Set to 0 for No Timeout.
+ */
#define DEFAULT_STEPPER_DEACTIVE_TIME 120
#define DISABLE_INACTIVE_X true
#define DISABLE_INACTIVE_Y true
-#define DISABLE_INACTIVE_Z true // Set to false if the nozzle will fall down on your printed part when print has finished.
+#define DISABLE_INACTIVE_Z true // Set 'false' if the nozzle could fall onto your printed part!
#define DISABLE_INACTIVE_E true
-#define DEFAULT_MINIMUMFEEDRATE 0.0 // minimum feedrate
-#define DEFAULT_MINTRAVELFEEDRATE 0.0
+// If the Nozzle or Bed falls when the Z stepper is disabled, set its resting position here.
+//#define Z_AFTER_DEACTIVATE Z_HOME_POS
//#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated
-// Minimum time that a segment needs to take if the buffer is emptied
-#define DEFAULT_MINSEGMENTTIME 20000 // (ms)
+// Default Minimum Feedrates for printing and travel moves
+#define DEFAULT_MINIMUMFEEDRATE 0.0 // (mm/s) Minimum feedrate. Set with M205 S.
+#define DEFAULT_MINTRAVELFEEDRATE 0.0 // (mm/s) Minimum travel feedrate. Set with M205 T.
-// If defined the movements slow down when the look ahead buffer is only half full
-// Slow down the machine if the look ahead buffer is (by default) half full.
+// Minimum time that a segment needs to take as the buffer gets emptied
+#define DEFAULT_MINSEGMENTTIME 20000 // (µs) Set with M205 B.
+
+// Slow down the machine if the lookahead buffer is (by default) half full.
// Increase the slowdown divisor for larger buffer sizes.
#define SLOWDOWN
#if ENABLED(SLOWDOWN)
#define SLOWDOWN_DIVISOR 2
#endif
-// Frequency limit
-// See nophead's blog for more info
-// Not working O
-//#define XY_FREQUENCY_LIMIT 15
+/**
+ * XY Frequency limit
+ * Reduce resonance by limiting the frequency of small zigzag infill moves.
+ * See https://hydraraptor.blogspot.com/2010/12/frequency-limit.html
+ * Use M201 F G to change limits at runtime.
+ */
+//#define XY_FREQUENCY_LIMIT 10 // (Hz) Maximum frequency of small zigzag infill moves. Set with M201 F.
+#ifdef XY_FREQUENCY_LIMIT
+ #define XY_FREQUENCY_MIN_PERCENT 5 // (percent) Minimum FR percentage to apply. Set with M201 G.
+#endif
// Minimum planner junction speed. Sets the default minimum speed the planner plans for at the end
// of the buffer and all stops. This should not be much greater than zero and should only be changed
@@ -806,7 +883,7 @@
// increments while checking for the contact to be broken.
#define BACKLASH_MEASUREMENT_LIMIT 0.5 // (mm)
#define BACKLASH_MEASUREMENT_RESOLUTION 0.005 // (mm)
- #define BACKLASH_MEASUREMENT_FEEDRATE Z_PROBE_SPEED_SLOW // (mm/m)
+ #define BACKLASH_MEASUREMENT_FEEDRATE Z_PROBE_SPEED_SLOW // (mm/min)
#endif
#endif
#endif
@@ -827,11 +904,14 @@
//#define CALIBRATION_GCODE
#if ENABLED(CALIBRATION_GCODE)
+ //#define CALIBRATION_SCRIPT_PRE "M117 Starting Auto-Calibration\nT0\nG28\nG12\nM117 Calibrating..."
+ //#define CALIBRATION_SCRIPT_POST "M500\nM117 Calibration data saved"
+
#define CALIBRATION_MEASUREMENT_RESOLUTION 0.01 // mm
- #define CALIBRATION_FEEDRATE_SLOW 60 // mm/m
- #define CALIBRATION_FEEDRATE_FAST 1200 // mm/m
- #define CALIBRATION_FEEDRATE_TRAVEL 3000 // mm/m
+ #define CALIBRATION_FEEDRATE_SLOW 60 // mm/min
+ #define CALIBRATION_FEEDRATE_FAST 1200 // mm/min
+ #define CALIBRATION_FEEDRATE_TRAVEL 3000 // mm/min
// The following parameters refer to the conical section of the nozzle tip.
#define CALIBRATION_NOZZLE_TIP_HEIGHT 1.0 // mm
@@ -883,7 +963,7 @@
//#define MICROSTEP16 LOW,LOW,HIGH
//#define MICROSTEP32 HIGH,LOW,HIGH
-// Microstep setting (Only functional when stepper driver microstep pins are connected to MCU.
+// Microstep settings (Requires a board with pins named X_MS1, X_MS2, etc.)
#define MICROSTEP_MODES { 16, 16, 16, 16, 16, 16 } // [1,2,4,8,16]
/**
@@ -910,9 +990,20 @@
//#define DIGIPOT_MOTOR_CURRENT { 135,135,135,135,135 } // Values 0-255 (RAMBO 135 = ~0.75A, 185 = ~1A)
//#define DAC_MOTOR_CURRENT_DEFAULT { 70, 80, 90, 80 } // Default drive percent - X, Y, Z, E axis
-// Use an I2C based DIGIPOT (e.g., Azteeg X3 Pro)
-//#define DIGIPOT_I2C
-#if ENABLED(DIGIPOT_I2C) && !defined(DIGIPOT_I2C_ADDRESS_A)
+/**
+ * I2C-based DIGIPOTs (e.g., Azteeg X3 Pro)
+ */
+//#define DIGIPOT_MCP4018 // Requires https://github.com/stawel/SlowSoftI2CMaster
+//#define DIGIPOT_MCP4451
+#if EITHER(DIGIPOT_MCP4018, DIGIPOT_MCP4451)
+ #define DIGIPOT_I2C_NUM_CHANNELS 8 // 5DPRINT:4 AZTEEG_X3_PRO:8 MKS_SBASE:5 MIGHTYBOARD_REVE:5
+
+ // Actual motor currents in Amps. The number of entries must match DIGIPOT_I2C_NUM_CHANNELS.
+ // These correspond to the physical drivers, so be mindful if the order is changed.
+ #define DIGIPOT_I2C_MOTOR_CURRENTS { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 } // AZTEEG_X3_PRO
+
+ //#define DIGIPOT_USE_RAW_VALUES // Use DIGIPOT_MOTOR_CURRENT raw wiper values (instead of A4988 motor currents)
+
/**
* Common slave addresses:
*
@@ -923,16 +1014,10 @@
* AZTEEG_X5_MINI_WIFI 0x58 0x5C MCP4451
* MIGHTYBOARD_REVE 0x2F (0x5E) MCP4018
*/
- #define DIGIPOT_I2C_ADDRESS_A 0x2C // unshifted slave address for first DIGIPOT
- #define DIGIPOT_I2C_ADDRESS_B 0x2D // unshifted slave address for second DIGIPOT
+ //#define DIGIPOT_I2C_ADDRESS_A 0x2C // Unshifted slave address for first DIGIPOT
+ //#define DIGIPOT_I2C_ADDRESS_B 0x2D // Unshifted slave address for second DIGIPOT
#endif
-//#define DIGIPOT_MCP4018 // Requires library from https://github.com/stawel/SlowSoftI2CMaster
-#define DIGIPOT_I2C_NUM_CHANNELS 8 // 5DPRINT: 4 AZTEEG_X3_PRO: 8 MKS SBASE: 5
-// Actual motor currents in Amps. The number of entries must match DIGIPOT_I2C_NUM_CHANNELS.
-// These correspond to the physical drivers, so be mindful if the order is changed.
-#define DIGIPOT_I2C_MOTOR_CURRENTS { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 } // AZTEEG_X3_PRO
-
//===========================================================================
//=============================Additional Features===========================
//===========================================================================
@@ -940,7 +1025,7 @@
// @section lcd
#if EITHER(ULTIPANEL, EXTENSIBLE_UI)
- #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 60 } // Feedrates for manual moves along X, Y, Z, E from panel
+ #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // (mm/min) Feedrates for manual moves along X, Y, Z, E from panel
#define SHORT_MANUAL_Z_MOVE 0.025 // (mm) Smallest manual Z move (< 0.1mm)
#if ENABLED(ULTIPANEL)
#define MANUAL_E_MOVES_RELATIVE // Display extruder move distance rather than "position"
@@ -980,6 +1065,7 @@
//#define LED_CONTROL_MENU
#if ENABLED(LED_CONTROL_MENU)
#define LED_COLOR_PRESETS // Enable the Preset Color menu option
+ //#define NEO2_COLOR_PRESETS // Enable a second NeoPixel Preset Color menu option
#if ENABLED(LED_COLOR_PRESETS)
#define LED_USER_PRESET_RED 255 // User defined RED value
#define LED_USER_PRESET_GREEN 128 // User defined GREEN value
@@ -988,6 +1074,14 @@
#define LED_USER_PRESET_BRIGHTNESS 255 // User defined intensity
//#define LED_USER_PRESET_STARTUP // Have the printer display the user preset color on startup
#endif
+ #if ENABLED(NEO2_COLOR_PRESETS)
+ #define NEO2_USER_PRESET_RED 255 // User defined RED value
+ #define NEO2_USER_PRESET_GREEN 128 // User defined GREEN value
+ #define NEO2_USER_PRESET_BLUE 0 // User defined BLUE value
+ #define NEO2_USER_PRESET_WHITE 255 // User defined WHITE value
+ #define NEO2_USER_PRESET_BRIGHTNESS 255 // User defined intensity
+ //#define NEO2_USER_PRESET_STARTUP // Have the printer display the user preset color on startup for the second strip
+ #endif
#endif
#endif // HAS_LCD_MENU
@@ -1037,8 +1131,12 @@
// Enable this option and set to HIGH if your SD cards are incorrectly detected.
//#define SD_DETECT_STATE HIGH
- #define SD_FINISHED_STEPPERRELEASE true // Disable steppers when SD Print is finished
- #define SD_FINISHED_RELEASECOMMAND "M84 X Y Z E" // You might want to keep the Z enabled so your bed stays in place.
+ //#define SDCARD_READONLY // Read-only SD card (to save over 2K of flash)
+
+ #define SD_PROCEDURE_DEPTH 1 // Increase if you need more nested M32 calls
+
+ #define SD_FINISHED_STEPPERRELEASE true // Disable steppers when SD Print is finished
+ #define SD_FINISHED_RELEASECOMMAND "M84" // Use "M84XYE" to keep Z enabled so your bed stays in place
// Reverse SD sort to show "more recent" files first, according to the card's FAT.
// Since the FAT gets out of order with usage, SDCARD_SORT_ALPHA is recommended.
@@ -1048,7 +1146,7 @@
//#define MENU_ADDAUTOSTART // Add a menu option to run auto#.g files
- #define EVENT_GCODE_SD_STOP "G28XY" // G-code to run on Stop Print (e.g., "G28XY" or "G27")
+ #define EVENT_GCODE_SD_ABORT "G28XY" // G-code to run on SD Abort Print (e.g., "G28XY" or "G27")
#if ENABLED(PRINTER_EVENT_LEDS)
#define PE_LEDS_COMPLETED_TIME (30*60) // (seconds) Time to keep the LED "done" color before restoring normal illumination
@@ -1061,9 +1159,6 @@
* during SD printing. If the recovery file is found at boot time, present
* an option on the LCD screen to continue the print from the last-known
* point in the file.
- *
- * If the machine reboots when resuming a print you may need to replace or
- * reformat the SD card. (Bad sectors delay startup triggering the watchdog.)
*/
//#define POWER_LOSS_RECOVERY
#if ENABLED(POWER_LOSS_RECOVERY)
@@ -1110,7 +1205,7 @@
#if ENABLED(SDCARD_SORT_ALPHA)
#define SDSORT_LIMIT 40 // Maximum number of sorted items (10-256). Costs 27 bytes each.
#define FOLDER_SORTING -1 // -1=above 0=none 1=below
- #define SDSORT_GCODE false // Allow turning sorting on/off with LCD and M34 g-code.
+ #define SDSORT_GCODE false // Allow turning sorting on/off with LCD and M34 G-code.
#define SDSORT_USES_RAM false // Pre-allocate a static array for faster pre-sorting.
#define SDSORT_USES_STACK false // Prefer the stack for pre-sorting to give back some SRAM. (Negated by next 2 options.)
#define SDSORT_CACHE_NAMES false // Keep sorted items in RAM longer for speedy performance. Most expensive option.
@@ -1233,7 +1328,8 @@
// Show SD percentage next to the progress bar
//#define DOGM_SD_PERCENT
- // Enable to save many cycles by drawing a hollow frame on the Info Screen
+ // Save many cycles by drawing a hollow frame or no frame on the Info Screen
+ //#define XYZ_NO_FRAME
#define XYZ_HOLLOW_FRAME
// Enable to save many cycles by drawing a hollow frame on Menu Screens
@@ -1347,6 +1443,7 @@
//#define LCD_HAOYU_FT800CB // Haoyu with 4.3" or 5" (480x272)
//#define LCD_HAOYU_FT810CB // Haoyu with 5" (800x480)
//#define LCD_ALEPHOBJECTS_CLCD_UI // Aleph Objects Color LCD UI
+ //#define LCD_FYSETC_TFT81050 // FYSETC with 5" (800x480)
// Correct the resolution if not using the stock TFT panel.
//#define TOUCH_UI_320x240
@@ -1354,10 +1451,11 @@
//#define TOUCH_UI_800x480
// Mappings for boards with a standard RepRapDiscount Display connector
- //#define AO_EXP1_PINMAP // AlephObjects CLCD UI EXP1 mapping
- //#define AO_EXP2_PINMAP // AlephObjects CLCD UI EXP2 mapping
- //#define CR10_TFT_PINMAP // Rudolph Riedel's CR10 pin mapping
- //#define S6_TFT_PINMAP // FYSETC S6 pin mapping
+ //#define AO_EXP1_PINMAP // AlephObjects CLCD UI EXP1 mapping
+ //#define AO_EXP2_PINMAP // AlephObjects CLCD UI EXP2 mapping
+ //#define CR10_TFT_PINMAP // Rudolph Riedel's CR10 pin mapping
+ //#define S6_TFT_PINMAP // FYSETC S6 pin mapping
+ //#define F6_TFT_PINMAP // FYSETC F6 pin mapping
//#define OTHER_PIN_LAYOUT // Define pins manually below
#if ENABLED(OTHER_PIN_LAYOUT)
@@ -1426,9 +1524,10 @@
#endif
//
-// FSMC Graphical TFT
+// FSMC / SPI Graphical TFT
//
-#if ENABLED(FSMC_GRAPHICAL_TFT)
+#if TFT_SCALED_DOGLCD
+ //#define GRAPHICAL_TFT_ROTATE_180
//#define TFT_MARLINUI_COLOR 0xFFFF // White
//#define TFT_MARLINBG_COLOR 0x0000 // Black
//#define TFT_DISABLED_COLOR 0x0003 // Almost black
@@ -1441,7 +1540,7 @@
// ADC Button Debounce
//
#if HAS_ADC_BUTTONS
- #define ADC_BUTTON_DEBOUNCE_DELAY 16 // (ms) Increase if buttons bounce or repeat too fast
+ #define ADC_BUTTON_DEBOUNCE_DELAY 16 // Increase if buttons bounce or repeat too fast
#endif
// @section safety
@@ -1475,8 +1574,9 @@
//#define BABYSTEP_WITHOUT_HOMING
//#define BABYSTEP_XY // Also enable X/Y Babystepping. Not supported on DELTA!
#define BABYSTEP_INVERT_Z false // Change if Z babysteps should go the other way
- #define BABYSTEP_MULTIPLICATOR_Z 1 // Babysteps are very small. Increase for faster motion.
- #define BABYSTEP_MULTIPLICATOR_XY 1
+ //#define BABYSTEP_MILLIMETER_UNITS // Specify BABYSTEP_MULTIPLICATOR_(XY|Z) in mm instead of micro-steps
+ #define BABYSTEP_MULTIPLICATOR_Z 1 // (steps or mm) Steps or millimeter distance for each Z babystep
+ #define BABYSTEP_MULTIPLICATOR_XY 1 // (steps or mm) Steps or millimeter distance for each XY babystep
//#define DOUBLECLICK_FOR_Z_BABYSTEPPING // Double-click on the Status Screen for Z Babystepping.
#if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING)
@@ -1513,14 +1613,14 @@
* If this algorithm produces a higher speed offset than the extruder can handle (compared to E jerk)
* print acceleration will be reduced during the affected moves to keep within the limit.
*
- * See http://marlinfw.org/docs/features/lin_advance.html for full instructions.
- * Mention @Sebastianv650 on GitHub to alert the author of any issues.
+ * See https://marlinfw.org/docs/features/lin_advance.html for full instructions.
*/
//#define LIN_ADVANCE
#if ENABLED(LIN_ADVANCE)
//#define EXTRA_LIN_ADVANCE_K // Enable for second linear advance constants
#define LIN_ADVANCE_K 0.22 // Unit: mm compression per 1mm/s extruder speed
//#define LA_DEBUG // If enabled, this will generate debug information output over USB.
+ //#define EXPERIMENTAL_SCURVE // Enable this option to permit S-Curve Acceleration
#endif
// @section leveling
@@ -1539,7 +1639,9 @@
#endif
/**
- * Override MIN_PROBE_EDGE for each side of the build plate
+ * Probing Margins
+ *
+ * Override PROBING_MARGIN for each side of the build plate
* Useful to get probe points to exact positions on targets or
* to allow leveling to avoid plate clamps on only specific
* sides of the bed. With NOZZLE_AS_PROBE negative values are
@@ -1556,10 +1658,10 @@
* the probe to be unable to reach any points.
*/
#if PROBE_SELECTED && !IS_KINEMATIC
- //#define MIN_PROBE_EDGE_LEFT MIN_PROBE_EDGE
- //#define MIN_PROBE_EDGE_RIGHT MIN_PROBE_EDGE
- //#define MIN_PROBE_EDGE_FRONT MIN_PROBE_EDGE
- //#define MIN_PROBE_EDGE_BACK MIN_PROBE_EDGE
+ //#define PROBING_MARGIN_LEFT PROBING_MARGIN
+ //#define PROBING_MARGIN_RIGHT PROBING_MARGIN
+ //#define PROBING_MARGIN_FRONT PROBING_MARGIN
+ //#define PROBING_MARGIN_BACK PROBING_MARGIN
#endif
#if EITHER(MESH_BED_LEVELING, AUTO_BED_LEVELING_UBL)
@@ -1601,22 +1703,46 @@
// Add additional compensation depending on hotend temperature
// Note: this values cannot be calibrated and have to be set manually
#if ENABLED(PROBE_TEMP_COMPENSATION)
- // Max temperature that can be reached by heated bed.
- // This is required only for the calibration process.
- #define PTC_MAX_BED_TEMP BED_MAXTEMP
-
// Park position to wait for probe cooldown
- #define PTC_PARK_POS_X 0.0F
- #define PTC_PARK_POS_Y 0.0F
- #define PTC_PARK_POS_Z 100.0F
+ #define PTC_PARK_POS { 0, 0, 100 }
// Probe position to probe and wait for probe to reach target temperature
- #define PTC_PROBE_POS_X 90.0F
- #define PTC_PROBE_POS_Y 100.0F
+ #define PTC_PROBE_POS { 90, 100 }
// Enable additional compensation using hotend temperature
// Note: this values cannot be calibrated automatically but have to be set manually
//#define USE_TEMP_EXT_COMPENSATION
+
+ // Probe temperature calibration generates a table of values starting at PTC_SAMPLE_START
+ // (e.g. 30), in steps of PTC_SAMPLE_RES (e.g. 5) with PTC_SAMPLE_COUNT (e.g. 10) samples.
+
+ //#define PTC_SAMPLE_START 30.0f
+ //#define PTC_SAMPLE_RES 5.0f
+ //#define PTC_SAMPLE_COUNT 10U
+
+ // Bed temperature calibration builds a similar table.
+
+ //#define BTC_SAMPLE_START 60.0f
+ //#define BTC_SAMPLE_RES 5.0f
+ //#define BTC_SAMPLE_COUNT 10U
+
+ // The temperature the probe should be at while taking measurements during bed temperature
+ // calibration.
+ //#define BTC_PROBE_TEMP 30.0f
+
+ // Height above Z=0.0f to raise the nozzle. Lowering this can help the probe to heat faster.
+ // Note: the Z=0.0f offset is determined by the probe offset which can be set using M851.
+ //#define PTC_PROBE_HEATING_OFFSET 0.5f
+
+ // Height to raise the Z-probe between heating and taking the next measurement. Some probes
+ // may fail to untrigger if they have been triggered for a long time, which can be solved by
+ // increasing the height the probe is raised to.
+ //#define PTC_PROBE_RAISE 15U
+
+ // If the probe is outside of the defined range, use linear extrapolation using the closest
+ // point and the PTC_LINEAR_EXTRAPOLATION'th next point. E.g. if set to 4 it will use data[0]
+ // and data[4] to perform linear extrapolation for values below PTC_SAMPLE_START.
+ //#define PTC_LINEAR_EXTRAPOLATION 4
#endif
#endif
@@ -1644,6 +1770,16 @@
// Support for G5 with XYZE destination and IJPQ offsets. Requires ~2666 bytes.
//#define BEZIER_CURVE_SUPPORT
+/**
+ * Direct Stepping
+ *
+ * Comparable to the method used by Klipper, G6 direct stepping significantly
+ * reduces motion calculations, increases top printing speeds, and results in
+ * less step aliasing by calculating all motions in advance.
+ * Preparing your G-code: https://github.com/colinrgodsey/step-daemon
+ */
+//#define DIRECT_STEPPING
+
/**
* G38 Probe Target
*
@@ -1712,14 +1848,16 @@
//================================= Buffers =================================
//===========================================================================
-// @section hidden
+// @section motion
-// The number of linear motions that can be in the plan at any give time.
-// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2 (e.g. 8, 16, 32) because shifts and ors are used to do the ring-buffering.
-#if ENABLED(SDSUPPORT)
- #define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller
+// The number of linear moves that can be in the planner at once.
+// The value of BLOCK_BUFFER_SIZE must be a power of 2 (e.g. 8, 16, 32)
+#if BOTH(SDSUPPORT, DIRECT_STEPPING)
+ #define BLOCK_BUFFER_SIZE 8
+#elif ENABLED(SDSUPPORT)
+ #define BLOCK_BUFFER_SIZE 16
#else
- #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
+ #define BLOCK_BUFFER_SIZE 16
#endif
// @section serial
@@ -1762,10 +1900,14 @@
//#define SERIAL_STATS_DROPPED_RX
#endif
-// Enable an emergency-command parser to intercept certain commands as they
-// enter the serial receive buffer, so they cannot be blocked.
-// Currently handles M108, M112, M410
-// Does not work on boards using AT90USB (USBCON) processors!
+/**
+ * Emergency Command Parser
+ *
+ * Add a low-level parser to intercept certain commands as they
+ * enter the serial receive buffer, so they cannot be blocked.
+ * Currently handles M108, M112, M410, M876
+ * NOTE: Not yet implemented for all platforms.
+ */
//#define EMERGENCY_PARSER
// Bad Serial-connections can miss a received command by sending an 'ok'
@@ -1781,6 +1923,9 @@
// This option inserts short delays between lines of serial output.
#define SERIAL_OVERRUN_PROTECTION
+// For serial echo, the number of digits after the decimal point
+//#define SERIAL_FLOAT_PRECISION 4
+
// @section extras
/**
@@ -1833,19 +1978,55 @@
*/
#if EXTRUDERS > 1
// Z raise distance for tool-change, as needed for some extruders
- #define TOOLCHANGE_ZRAISE 2 // (mm)
- //#define TOOLCHANGE_NO_RETURN // Never return to the previous position on tool-change
+ #define TOOLCHANGE_ZRAISE 2 // (mm)
+ //#define TOOLCHANGE_ZRAISE_BEFORE_RETRACT // Apply raise before swap retraction (if enabled)
+ //#define TOOLCHANGE_NO_RETURN // Never return to previous position on tool-change
#if ENABLED(TOOLCHANGE_NO_RETURN)
- //#define EVENT_GCODE_AFTER_TOOLCHANGE "G12X" // G-code to run after tool-change is complete
+ //#define EVENT_GCODE_AFTER_TOOLCHANGE "G12X" // Extra G-code to run after tool-change
#endif
- // Retract and prime filament on tool-change
+ /**
+ * Retract and prime filament on tool-change to reduce
+ * ooze and stringing and to get cleaner transitions.
+ */
//#define TOOLCHANGE_FILAMENT_SWAP
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
- #define TOOLCHANGE_FIL_SWAP_LENGTH 12 // (mm)
- #define TOOLCHANGE_FIL_EXTRA_PRIME 2 // (mm)
- #define TOOLCHANGE_FIL_SWAP_RETRACT_SPEED 3600 // (mm/m)
- #define TOOLCHANGE_FIL_SWAP_PRIME_SPEED 3600 // (mm/m)
+ // Load / Unload
+ #define TOOLCHANGE_FS_LENGTH 12 // (mm) Load / Unload length
+ #define TOOLCHANGE_FS_EXTRA_RESUME_LENGTH 0 // (mm) Extra length for better restart, fine tune by LCD/Gcode)
+ #define TOOLCHANGE_FS_RETRACT_SPEED (50*60) // (mm/min) (Unloading)
+ #define TOOLCHANGE_FS_UNRETRACT_SPEED (25*60) // (mm/min) (On SINGLENOZZLE or Bowden loading must be slowed down)
+
+ // Longer prime to clean out a SINGLENOZZLE
+ #define TOOLCHANGE_FS_EXTRA_PRIME 0 // (mm) Extra priming length
+ #define TOOLCHANGE_FS_PRIME_SPEED (4.6*60) // (mm/min) Extra priming feedrate
+ #define TOOLCHANGE_FS_WIPE_RETRACT 0 // (mm/min) Retract before cooling for less stringing, better wipe, etc.
+
+ // Cool after prime to reduce stringing
+ #define TOOLCHANGE_FS_FAN -1 // Fan index or -1 to skip
+ #define TOOLCHANGE_FS_FAN_SPEED 255 // 0-255
+ #define TOOLCHANGE_FS_FAN_TIME 10 // (seconds)
+
+ // Swap uninitialized extruder with TOOLCHANGE_FS_PRIME_SPEED for all lengths (recover + prime)
+ // (May break filament if not retracted beforehand.)
+ //#define TOOLCHANGE_FS_INIT_BEFORE_SWAP
+
+ // Prime on the first T0 (If other, TOOLCHANGE_FS_INIT_BEFORE_SWAP applied)
+ // Enable it (M217 V[0/1]) before printing, to avoid unwanted priming on host connect
+ //#define TOOLCHANGE_FS_PRIME_FIRST_USED
+
+ /**
+ * Tool Change Migration
+ * This feature provides G-code and LCD options to switch tools mid-print.
+ * All applicable tool properties are migrated so the print can continue.
+ * Tools must be closely matching and other restrictions may apply.
+ * Useful to:
+ * - Change filament color without interruption
+ * - Switch spools automatically on filament runout
+ * - Switch to a different nozzle on an extruder jam
+ */
+ #define TOOLCHANGE_MIGRATION_FEATURE
+
#endif
/**
@@ -1855,9 +2036,11 @@
//#define TOOLCHANGE_PARK
#if ENABLED(TOOLCHANGE_PARK)
#define TOOLCHANGE_PARK_XY { X_MIN_POS + 10, Y_MIN_POS + 10 }
- #define TOOLCHANGE_PARK_XY_FEEDRATE 6000 // (mm/m)
+ #define TOOLCHANGE_PARK_XY_FEEDRATE 6000 // (mm/min)
+ //#define TOOLCHANGE_PARK_X_ONLY // X axis only move
+ //#define TOOLCHANGE_PARK_Y_ONLY // Y axis only move
#endif
-#endif
+#endif // EXTRUDERS > 1
/**
* Advanced Pause
@@ -1908,7 +2091,7 @@
#define PAUSE_PARK_NO_STEPPER_TIMEOUT // Enable for XYZ steppers to stay powered on during filament change.
//#define PARK_HEAD_ON_PAUSE // Park the nozzle during pause and filament change.
- //#define HOME_BEFORE_FILAMENT_CHANGE // Ensure homing has been completed prior to parking for filament change
+ //#define HOME_BEFORE_FILAMENT_CHANGE // If needed, home before parking for filament change
//#define FILAMENT_LOAD_UNLOAD_GCODES // Add M701/M702 Load/Unload G-codes, plus Load/Unload in the LCD Prepare menu.
//#define FILAMENT_UNLOAD_ALL_EXTRUDERS // Allow M702 to unload all extruders above a minimum target temp (as set by M302)
@@ -2249,7 +2432,8 @@
* CHOPPER_DEFAULT_19V
* CHOPPER_DEFAULT_24V
* CHOPPER_DEFAULT_36V
- * CHOPPER_PRUSAMK3_24V // Imported parameters from the official Prusa firmware for MK3 (24V)
+ * CHOPPER_09STEP_24V // 0.9 degree steppers (24V)
+ * CHOPPER_PRUSAMK3_24V // Imported parameters from the official Průša firmware for MK3 (24V)
* CHOPPER_MARLIN_119 // Old defaults from Marlin v1.1.9
*
* Define you own with
@@ -2258,11 +2442,11 @@
#define CHOPPER_TIMING CHOPPER_DEFAULT_12V
/**
- * Monitor Trinamic drivers for error conditions,
- * like overtemperature and short to ground.
- * In the case of overtemperature Marlin can decrease the driver current until error condition clears.
+ * Monitor Trinamic drivers
+ * for error conditions like overtemperature and short to ground.
+ * To manage over-temp Marlin can decrease the driver current until the error condition clears.
* Other detected conditions can be used to stop the current print.
- * Relevant g-codes:
+ * Relevant G-codes:
* M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given.
* M911 - Report stepper driver overtemperature pre-warn condition.
* M912 - Clear stepper driver overtemperature pre-warn condition flag.
@@ -2316,7 +2500,7 @@
* HIGHEST 255 -64 (Too sensitive => False positive)
* LOWEST 0 63 (Too insensitive => No trigger)
*
- * It is recommended to set [XYZ]_HOME_BUMP_MM to 0.
+ * It is recommended to set HOMING_BUMP_MM to { 0, 0, 0 }.
*
* SPI_ENDSTOPS *** Beta feature! *** TMC2130 Only ***
* Poll the driver through SPI to determine load when homing.
@@ -2332,11 +2516,27 @@
#define X_STALL_SENSITIVITY 20
#define X2_STALL_SENSITIVITY X_STALL_SENSITIVITY
#define Y_STALL_SENSITIVITY 20
+ #define Y2_STALL_SENSITIVITY Y_STALL_SENSITIVITY
//#define Z_STALL_SENSITIVITY 8
+ //#define Z2_STALL_SENSITIVITY Z_STALL_SENSITIVITY
+ //#define Z3_STALL_SENSITIVITY Z_STALL_SENSITIVITY
+ //#define Z4_STALL_SENSITIVITY Z_STALL_SENSITIVITY
//#define SPI_ENDSTOPS // TMC2130 only
#define IMPROVE_HOMING_RELIABILITY
#endif
+ /**
+ * TMC Homing stepper phase.
+ *
+ * Improve homing repeatability by homing to stepper coil's nearest absolute
+ * phase position. Trinamic drivers use a stepper phase table with 1024 values
+ * spanning 4 full steps with 256 positions each (ergo, 1024 positions).
+ * Full step positions (128, 384, 640, 896) have the highest holding torque.
+ *
+ * Values from 0..1023, -1 to disable homing phase for that axis.
+ */
+ //#define TMC_HOME_PHASE { 896, 896, 896 }
+
/**
* Beta feature!
* Create a 50/50 square wave step pulse optimal for stepper drivers.
@@ -2537,7 +2737,7 @@
* Monitor L6470 drivers for error conditions like over temperature and over current.
* In the case of over temperature Marlin can decrease the drive until the error condition clears.
* Other detected conditions can be used to stop the current print.
- * Relevant g-codes:
+ * Relevant G-codes:
* M906 - I1/2/3/4/5 Set or get motor drive level using axis codes X, Y, Z, E. Report values if no axis codes given.
* I not present or I0 or I1 - X, Y, Z or E0
* I2 - X2, Y2, Z2 or E1
@@ -2614,11 +2814,11 @@
//#define PHOTO_RETRACT_MM 6.5 // (mm) E retract/recover for the photo move (M240 R S)
// Canon RC-1 or homebrew digital camera trigger
- // Data from: http://www.doc-diy.net/photo/rc-1_hacked/
+ // Data from: https://www.doc-diy.net/photo/rc-1_hacked/
//#define PHOTOGRAPH_PIN 23
// Canon Hack Development Kit
- // http://captain-slow.dk/2014/03/09/3d-printing-timelapses/
+ // https://captain-slow.dk/2014/03/09/3d-printing-timelapses/
//#define CHDK_PIN 4
// Optional second move with delay to trigger the camera shutter
@@ -2655,39 +2855,138 @@
* You'll need to select a pin for the ON/OFF function and optionally choose a 0-5V
* hardware PWM pin for the speed control and a pin for the rotation direction.
*
- * See http://marlinfw.org/docs/configuration/laser_spindle.html for more config details.
+ * See https://marlinfw.org/docs/configuration/laser_spindle.html for more config details.
*/
//#define SPINDLE_FEATURE
//#define LASER_FEATURE
#if EITHER(SPINDLE_FEATURE, LASER_FEATURE)
- #define SPINDLE_LASER_ACTIVE_HIGH false // Set to "true" if the on/off function is active HIGH
+ #define SPINDLE_LASER_ACTIVE_STATE LOW // Set to "HIGH" if the on/off function is active HIGH
#define SPINDLE_LASER_PWM true // Set to "true" if your controller supports setting the speed/power
- #define SPINDLE_LASER_PWM_INVERT true // Set to "true" if the speed/power goes up when you want it to go slower
- #define SPINDLE_LASER_POWERUP_DELAY 5000 // (ms) Delay to allow the spindle/laser to come up to speed/power
- #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop
+ #define SPINDLE_LASER_PWM_INVERT false // Set to "true" if the speed/power goes up when you want it to go slower
+
+ #define SPINDLE_LASER_FREQUENCY 2500 // (Hz) Spindle/laser frequency (only on supported HALs: AVR and LPC)
+
+ /**
+ * Speed / Power can be set ('M3 S') and displayed in terms of:
+ * - PWM255 (S0 - S255)
+ * - PERCENT (S0 - S100)
+ * - RPM (S0 - S50000) Best for use with a spindle
+ */
+ #define CUTTER_POWER_UNIT PWM255
+
+ /**
+ * Relative Cutter Power
+ * Normally, 'M3 O' sets
+ * OCR power is relative to the range SPEED_POWER_MIN...SPEED_POWER_MAX.
+ * so input powers of 0...255 correspond to SPEED_POWER_MIN...SPEED_POWER_MAX
+ * instead of normal range (0 to SPEED_POWER_MAX).
+ * Best used with (e.g.) SuperPID router controller: S0 = 5,000 RPM and S255 = 30,000 RPM
+ */
+ //#define CUTTER_POWER_RELATIVE // Set speed proportional to [SPEED_POWER_MIN...SPEED_POWER_MAX]
#if ENABLED(SPINDLE_FEATURE)
//#define SPINDLE_CHANGE_DIR // Enable if your spindle controller can change spindle direction
#define SPINDLE_CHANGE_DIR_STOP // Enable if the spindle should stop before changing spin direction
#define SPINDLE_INVERT_DIR false // Set to "true" if the spin direction is reversed
+ #define SPINDLE_LASER_POWERUP_DELAY 5000 // (ms) Delay to allow the spindle/laser to come up to speed/power
+ #define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop
+
/**
- * The M3 & M4 commands use the following equation to convert PWM duty cycle to speed/power
+ * M3/M4 Power Equation
*
- * SPEED/POWER = PWM duty cycle * SPEED_POWER_SLOPE + SPEED_POWER_INTERCEPT
- * where PWM duty cycle varies from 0 to 255
+ * Each tool uses different value ranges for speed / power control.
+ * These parameters are used to convert between tool power units and PWM.
*
- * set the following for your controller (ALL MUST BE SET)
+ * Speed/Power = (PWMDC / 255 * 100 - SPEED_POWER_INTERCEPT) / SPEED_POWER_SLOPE
+ * PWMDC = (spdpwr - SPEED_POWER_MIN) / (SPEED_POWER_MAX - SPEED_POWER_MIN) / SPEED_POWER_SLOPE
*/
- #define SPEED_POWER_SLOPE 118.4
- #define SPEED_POWER_INTERCEPT 0
- #define SPEED_POWER_MIN 5000
- #define SPEED_POWER_MAX 30000 // SuperPID router controller 0 - 30,000 RPM
+ #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage
+ #define SPEED_POWER_MIN 5000 // (RPM)
+ #define SPEED_POWER_MAX 30000 // (RPM) SuperPID router controller 0 - 30,000 RPM
+ #define SPEED_POWER_STARTUP 25000 // (RPM) M3/M4 speed/power default (with no arguments)
+
#else
- #define SPEED_POWER_SLOPE 0.3922
- #define SPEED_POWER_INTERCEPT 0
- #define SPEED_POWER_MIN 10
- #define SPEED_POWER_MAX 100 // 0-100%
+
+ #define SPEED_POWER_INTERCEPT 0 // (%) 0-100 i.e., Minimum power percentage
+ #define SPEED_POWER_MIN 0 // (%) 0-100
+ #define SPEED_POWER_MAX 100 // (%) 0-100
+ #define SPEED_POWER_STARTUP 80 // (%) M3/M4 speed/power default (with no arguments)
+
+ /**
+ * Enable inline laser power to be handled in the planner / stepper routines.
+ * Inline power is specified by the I (inline) flag in an M3 command (e.g., M3 S20 I)
+ * or by the 'S' parameter in G0/G1/G2/G3 moves (see LASER_MOVE_POWER).
+ *
+ * This allows the laser to keep in perfect sync with the planner and removes
+ * the powerup/down delay since lasers require negligible time.
+ */
+ #define LASER_POWER_INLINE
+
+ #if ENABLED(LASER_POWER_INLINE)
+ /**
+ * Scale the laser's power in proportion to the movement rate.
+ *
+ * - Sets the entry power proportional to the entry speed over the nominal speed.
+ * - Ramps the power up every N steps to approximate the speed trapezoid.
+ * - Due to the limited power resolution this is only approximate.
+ */
+ #define LASER_POWER_INLINE_TRAPEZOID
+
+ /**
+ * Continuously calculate the current power (nominal_power * current_rate / nominal_rate).
+ * Required for accurate power with non-trapezoidal acceleration (e.g., S_CURVE_ACCELERATION).
+ * This is a costly calculation so this option is discouraged on 8-bit AVR boards.
+ *
+ * LASER_POWER_INLINE_TRAPEZOID_CONT_PER defines how many step cycles there are between power updates. If your
+ * board isn't able to generate steps fast enough (and you are using LASER_POWER_INLINE_TRAPEZOID_CONT), increase this.
+ * Note that when this is zero it means it occurs every cycle; 1 means a delay wait one cycle then run, etc.
+ */
+ //#define LASER_POWER_INLINE_TRAPEZOID_CONT
+
+ /**
+ * Stepper iterations between power updates. Increase this value if the board
+ * can't keep up with the processing demands of LASER_POWER_INLINE_TRAPEZOID_CONT.
+ * Disable (or set to 0) to recalculate power on every stepper iteration.
+ */
+ //#define LASER_POWER_INLINE_TRAPEZOID_CONT_PER 10
+
+ /**
+ * Include laser power in G0/G1/G2/G3/G5 commands with the 'S' parameter
+ */
+ //#define LASER_MOVE_POWER
+
+ #if ENABLED(LASER_MOVE_POWER)
+ // Turn off the laser on G0 moves with no power parameter.
+ // If a power parameter is provided, use that instead.
+ //#define LASER_MOVE_G0_OFF
+
+ // Turn off the laser on G28 homing.
+ //#define LASER_MOVE_G28_OFF
+ #endif
+
+ /**
+ * Inline flag inverted
+ *
+ * WARNING: M5 will NOT turn off the laser unless another move
+ * is done (so G-code files must end with 'M5 I').
+ */
+ //#define LASER_POWER_INLINE_INVERT
+
+ /**
+ * Continuously apply inline power. ('M3 S3' == 'G1 S3' == 'M3 S3 I')
+ *
+ * The laser might do some weird things, so only enable this
+ * feature if you understand the implications.
+ */
+ //#define LASER_POWER_INLINE_CONTINUOUS
+
+ #else
+
+ #define SPINDLE_LASER_POWERUP_DELAY 50 // (ms) Delay to allow the spindle/laser to come up to speed/power
+ #define SPINDLE_LASER_POWERDOWN_DELAY 50 // (ms) Delay to allow the spindle to stop
+
+ #endif
#endif
#endif
@@ -2739,6 +3038,24 @@
//#define FILAMENT_LCD_DISPLAY
#endif
+/**
+ * Power Monitor
+ * Monitor voltage (V) and/or current (A), and -when possible- power (W)
+ *
+ * Read and configure with M430
+ *
+ * The current sensor feeds DC voltage (relative to the measured current) to an analog pin
+ * The voltage sensor feeds DC voltage (relative to the measured voltage) to an analog pin
+ */
+//#define POWER_MONITOR_CURRENT // Monitor the system current
+//#define POWER_MONITOR_VOLTAGE // Monitor the system voltage
+#if EITHER(POWER_MONITOR_CURRENT, POWER_MONITOR_VOLTAGE)
+ #define POWER_MONITOR_VOLTS_PER_AMP 0.05000 // Input voltage to the MCU analog pin per amp - DO NOT apply more than ADC_VREF!
+ #define POWER_MONITOR_CURRENT_OFFSET -1 // Offset value for current sensors with linear function output
+ #define POWER_MONITOR_VOLTS_PER_VOLT 0.11786 // Input voltage to the MCU analog pin per volt - DO NOT apply more than ADC_VREF!
+ #define POWER_MONITOR_FIXED_VOLTAGE 13.6 // Voltage for a current sensor with no voltage sensor (for power display)
+#endif
+
/**
* CNC Coordinate Systems
*
@@ -2756,6 +3073,9 @@
* Include capabilities in M115 output
*/
#define EXTENDED_CAPABILITIES_REPORT
+#if ENABLED(EXTENDED_CAPABILITIES_REPORT)
+ //#define M115_GEOMETRY_REPORT
+#endif
/**
* Expected Printer Check
@@ -2775,9 +3095,21 @@
* Activate to make volumetric extrusion the default method,
* with DEFAULT_NOMINAL_FILAMENT_DIA as the default diameter.
*
- * M200 D0 to disable, M200 Dn to set a new diameter.
+ * M200 D0 to disable, M200 Dn to set a new diameter (and enable volumetric).
+ * M200 S0/S1 to disable/enable volumetric extrusion.
*/
//#define VOLUMETRIC_DEFAULT_ON
+
+ //#define VOLUMETRIC_EXTRUDER_LIMIT
+ #if ENABLED(VOLUMETRIC_EXTRUDER_LIMIT)
+ /**
+ * Default volumetric extrusion limit in cubic mm per second (mm^3/sec).
+ * This factory setting applies to all extruders.
+ * Use 'M200 [T] L' to override and 'M502' to reset.
+ * A non-zero value activates Volume-based Extrusion Limiting.
+ */
+ #define DEFAULT_VOLUMETRIC_EXTRUDER_LIMIT 0.00 // (mm^3/sec)
+ #endif
#endif
/**
@@ -2789,6 +3121,13 @@
*/
//#define NO_WORKSPACE_OFFSETS
+// Extra options for the M114 "Current Position" report
+//#define M114_DETAIL // Use 'M114` for details to check planner calculations
+//#define M114_REALTIME // Real current position based on forward kinematics
+//#define M114_LEGACY // M114 used to synchronize on every call. Enable if needed.
+
+//#define REPORT_FAN_CHANGE // Report the new fan speed when changed by M106 (and others)
+
/**
* Set the number of proportional font spaces required to fill up a typical character space.
* This can help to better align the output of commands like `G29 O` Mesh Output.
@@ -2809,6 +3148,8 @@
//#define GCODE_CASE_INSENSITIVE // Accept G-code sent to the firmware in lowercase
+//#define REPETIER_GCODE_M360 // Add commands originally from Repetier FW
+
/**
* CNC G-code options
* Support CNC-style G-code dialects used by laser cutters, drawing machine cams, etc.
@@ -2819,7 +3160,7 @@
//#define GCODE_MOTION_MODES // Remember the motion mode (G0 G1 G2 G3 G5 G38.X) and apply for X Y Z E F, etc.
// Enable and set a (default) feedrate for all G0 moves
-//#define G0_FEEDRATE 3000 // (mm/m)
+//#define G0_FEEDRATE 3000 // (mm/min)
#ifdef G0_FEEDRATE
//#define VARIABLE_G0_FEEDRATE // The G0 feedrate is set by F in G0 motion mode
#endif
@@ -2899,11 +3240,11 @@
* I2C position encoders for closed loop control.
* Developed by Chris Barr at Aus3D.
*
- * Wiki: http://wiki.aus3d.com.au/Magnetic_Encoder
+ * Wiki: https://wiki.aus3d.com.au/Magnetic_Encoder
* Github: https://github.com/Aus3D/MagneticEncoder
*
- * Supplier: http://aus3d.com.au/magnetic-encoder-module
- * Alternative Supplier: http://reliabuild3d.com/
+ * Supplier: https://aus3d.com.au/magnetic-encoder-module
+ * Alternative Supplier: https://reliabuild3d.com/
*
* Reliabuild encoders have been modified to improve reliability.
*/
@@ -3064,7 +3405,7 @@
#endif
/**
- * Prusa Multi-Material Unit v2
+ * Průša Multi-Material Unit v2
* Enable in Configuration.h
*/
#if ENABLED(PRUSA_MMU2)
@@ -3088,10 +3429,10 @@
//#define MMU2_MENUS
#if ENABLED(MMU2_MENUS)
// Settings for filament load / unload from the LCD menu.
- // This is for Prusa MK3-style extruders. Customize for your hardware.
+ // This is for Průša MK3-style extruders. Customize for your hardware.
#define MMU2_FILAMENTCHANGE_EJECT_FEED 80.0
#define MMU2_LOAD_TO_NOZZLE_SEQUENCE \
- { 7.2, 562 }, \
+ { 7.2, 1145 }, \
{ 14.4, 871 }, \
{ 36.0, 1393 }, \
{ 14.4, 871 }, \
@@ -3109,6 +3450,45 @@
{ 10.0, 700 }, \
{ -10.0, 400 }, \
{ -50.0, 2000 }
+ #endif
+
+ /**
+ * MMU Extruder Sensor
+ *
+ * Support for a Průša (or other) IR Sensor to detect filament near the extruder
+ * and make loading more reliable. Suitable for an extruder equipped with a filament
+ * sensor less than 38mm from the gears.
+ *
+ * During loading the extruder will stop when the sensor is triggered, then do a last
+ * move up to the gears. If no filament is detected, the MMU2 can make some more attempts.
+ * If all attempts fail, a filament runout will be triggered.
+ */
+ //#define MMU_EXTRUDER_SENSOR
+ #if ENABLED(MMU_EXTRUDER_SENSOR)
+ #define MMU_LOADING_ATTEMPTS_NR 5 //max. number of attempts to load filament if first load fail
+ #endif
+
+ /**
+ * Using a sensor like the MMU2S
+ * This mode requires a MK3S extruder with a sensor at the extruder idler, like the MMU2S.
+ * See https://help.prusa3d.com/en/guide/3b-mk3s-mk2-5s-extruder-upgrade_41560, step 11
+ */
+ //#define PRUSA_MMU2_S_MODE
+ #if ENABLED(PRUSA_MMU2_S_MODE)
+ #define MMU2_C0_RETRY 5 // Number of retries (total time = timeout*retries)
+
+ #define MMU2_CAN_LOAD_FEEDRATE 800 // (mm/min)
+ #define MMU2_CAN_LOAD_SEQUENCE \
+ { 0.1, MMU2_CAN_LOAD_FEEDRATE }, \
+ { 60.0, MMU2_CAN_LOAD_FEEDRATE }, \
+ { -52.0, MMU2_CAN_LOAD_FEEDRATE }
+
+ #define MMU2_CAN_LOAD_RETRACT 6.0 // (mm) Keep under the distance between Load Sequence values
+ #define MMU2_CAN_LOAD_DEVIATION 0.8 // (mm) Acceptable deviation
+
+ #define MMU2_CAN_LOAD_INCREMENT 0.2 // (mm) To reuse within MMU2 module
+ #define MMU2_CAN_LOAD_INCREMENT_SEQUENCE \
+ { -MMU2_CAN_LOAD_INCREMENT, MMU2_CAN_LOAD_FEEDRATE }
#endif
diff --git a/Marlin/Makefile b/Marlin/Makefile
index 0a9b3a45d7..95135ab594 100644
--- a/Marlin/Makefile
+++ b/Marlin/Makefile
@@ -14,7 +14,7 @@
# Detailed instructions for using the makefile:
#
# 1. Modify the line containing "ARDUINO_INSTALL_DIR" to point to the directory that
-# contains the Arduino installation (for example, under Mac OS X, this
+# contains the Arduino installation (for example, under macOS, this
# might be /Applications/Arduino.app/Contents/Resources/Java).
#
# 2. Modify the line containing "UPLOAD_PORT" to refer to the filename
@@ -98,7 +98,7 @@ NEOPIXEL ?= 0
############
# Try to automatically determine whether RELOC_WORKAROUND is needed based
# on GCC versions:
-# http://www.avrfreaks.net/comment/1789106#comment-1789106
+# https://www.avrfreaks.net/comment/1789106#comment-1789106
CC_MAJ:=$(shell $(CC) -dM -E - < /dev/null | grep __GNUC__ | cut -f3 -d\ )
CC_MIN:=$(shell $(CC) -dM -E - < /dev/null | grep __GNUC_MINOR__ | cut -f3 -d\ )
@@ -170,105 +170,110 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1100)
else ifeq ($(HARDWARE_MOTHERBOARD),1101)
# Velleman K8400 Controller (derived from 3Drag Controller)
else ifeq ($(HARDWARE_MOTHERBOARD),1102)
-# 2PrintBeta BAM&DICE with STK drivers
+# Velleman K8600 Controller (derived from 3Drag Controller)
else ifeq ($(HARDWARE_MOTHERBOARD),1103)
-# 2PrintBeta BAM&DICE Due with STK drivers
+# 2PrintBeta BAM&DICE with STK drivers
else ifeq ($(HARDWARE_MOTHERBOARD),1104)
-# MKS BASE v1.0
+# 2PrintBeta BAM&DICE Due with STK drivers
else ifeq ($(HARDWARE_MOTHERBOARD),1105)
-# MKS v1.4 with A4982 stepper drivers
+# MKS BASE v1.0
else ifeq ($(HARDWARE_MOTHERBOARD),1106)
-# MKS v1.5 with Allegro A4982 stepper drivers
+# MKS v1.4 with A4982 stepper drivers
else ifeq ($(HARDWARE_MOTHERBOARD),1107)
-# MKS v1.6 with Allegro A4982 stepper drivers
+# MKS v1.5 with Allegro A4982 stepper drivers
else ifeq ($(HARDWARE_MOTHERBOARD),1108)
-
-# MKS BASE 1.0 with Heroic HR4982 stepper drivers
+# MKS v1.6 with Allegro A4982 stepper drivers
else ifeq ($(HARDWARE_MOTHERBOARD),1109)
-# MKS GEN v1.3 or 1.4
+# MKS BASE 1.0 with Heroic HR4982 stepper drivers
else ifeq ($(HARDWARE_MOTHERBOARD),1110)
-# MKS GEN L
+# MKS GEN v1.3 or 1.4
else ifeq ($(HARDWARE_MOTHERBOARD),1111)
-# zrib V2.0 control board (Chinese knock off RAMPS replica)
+# MKS GEN L
else ifeq ($(HARDWARE_MOTHERBOARD),1112)
-# BigTreeTech or BIQU KFB2.0
+# zrib V2.0 control board (Chinese knock off RAMPS replica)
else ifeq ($(HARDWARE_MOTHERBOARD),1113)
-# Felix 2.0+ Electronics Board (RAMPS like)
+# BigTreeTech or BIQU KFB2.0
else ifeq ($(HARDWARE_MOTHERBOARD),1114)
-# Invent-A-Part RigidBoard
+# Felix 2.0+ Electronics Board (RAMPS like)
else ifeq ($(HARDWARE_MOTHERBOARD),1115)
-# Invent-A-Part RigidBoard V2
+# Invent-A-Part RigidBoard
else ifeq ($(HARDWARE_MOTHERBOARD),1116)
-# Sainsmart 2-in-1 board
+# Invent-A-Part RigidBoard V2
else ifeq ($(HARDWARE_MOTHERBOARD),1117)
-# Ultimaker
+# Sainsmart 2-in-1 board
else ifeq ($(HARDWARE_MOTHERBOARD),1118)
-# Ultimaker (Older electronics. Pre 1.5.4. This is rare)
+# Ultimaker
else ifeq ($(HARDWARE_MOTHERBOARD),1119)
+# Ultimaker (Older electronics. Pre 1.5.4. This is rare)
+else ifeq ($(HARDWARE_MOTHERBOARD),1120)
MCU ?= atmega1280
# Azteeg X3
-else ifeq ($(HARDWARE_MOTHERBOARD),1120)
-# Azteeg X3 Pro
else ifeq ($(HARDWARE_MOTHERBOARD),1121)
-# Ultimainboard 2.x (Uses TEMP_SENSOR 20)
+# Azteeg X3 Pro
else ifeq ($(HARDWARE_MOTHERBOARD),1122)
-# Rumba
+# Ultimainboard 2.x (Uses TEMP_SENSOR 20)
else ifeq ($(HARDWARE_MOTHERBOARD),1123)
-# Raise3D Rumba
+# Rumba
else ifeq ($(HARDWARE_MOTHERBOARD),1124)
-# Rapide Lite RL200 Rumba
+# Raise3D Rumba
else ifeq ($(HARDWARE_MOTHERBOARD),1125)
-# Formbot T-Rex 2 Plus
+# Rapide Lite RL200 Rumba
else ifeq ($(HARDWARE_MOTHERBOARD),1126)
-# Formbot T-Rex 3
+# Formbot T-Rex 2 Plus
else ifeq ($(HARDWARE_MOTHERBOARD),1127)
-# Formbot Raptor
+# Formbot T-Rex 3
else ifeq ($(HARDWARE_MOTHERBOARD),1128)
-# Formbot Raptor 2
+# Formbot Raptor
else ifeq ($(HARDWARE_MOTHERBOARD),1129)
-# bq ZUM Mega 3D
+# Formbot Raptor 2
else ifeq ($(HARDWARE_MOTHERBOARD),1130)
-# MakeBoard Mini v2.1.2 is a control board sold by MicroMake
+# bq ZUM Mega 3D
else ifeq ($(HARDWARE_MOTHERBOARD),1131)
-# TriGorilla Anycubic version 1.3 based on RAMPS EFB
+# MakeBoard Mini v2.1.2 is a control board sold by MicroMake
else ifeq ($(HARDWARE_MOTHERBOARD),1132)
-# TriGorilla Anycubic version 1.4 based on RAMPS EFB
+# TriGorilla Anycubic version 1.3 based on RAMPS EFB
else ifeq ($(HARDWARE_MOTHERBOARD),1133)
-# TriGorilla Anycubic version 1.4 Rev 1.1
+# TriGorilla Anycubic version 1.4 based on RAMPS EFB
else ifeq ($(HARDWARE_MOTHERBOARD),1134)
-# Creality: Ender-4, CR-8
+# TriGorilla Anycubic version 1.4 Rev 1.1
else ifeq ($(HARDWARE_MOTHERBOARD),1135)
-# Creality: CR10S, CR20, CR-X
+# Creality: Ender-4, CR-8
else ifeq ($(HARDWARE_MOTHERBOARD),1136)
-# Dagoma F5
+# Creality: CR10S, CR20, CR-X
else ifeq ($(HARDWARE_MOTHERBOARD),1137)
-# FYSETC F6 1.3
+# Dagoma F5
else ifeq ($(HARDWARE_MOTHERBOARD),1138)
-# FYSETC F6 1.5
+# FYSETC F6 1.3
else ifeq ($(HARDWARE_MOTHERBOARD),1139)
-# Duplicator i3 Plus
+# FYSETC F6 1.5
else ifeq ($(HARDWARE_MOTHERBOARD),1140)
-# VORON
+# Duplicator i3 Plus
else ifeq ($(HARDWARE_MOTHERBOARD),1141)
-# TRONXY V3 1.0
+# VORON
else ifeq ($(HARDWARE_MOTHERBOARD),1142)
-# Z-Bolt X Series
+# TRONXY V3 1.0
else ifeq ($(HARDWARE_MOTHERBOARD),1143)
-# TT OSCAR
+# Z-Bolt X Series
else ifeq ($(HARDWARE_MOTHERBOARD),1144)
-# Overlord/Overlord Pro
+# TT OSCAR
else ifeq ($(HARDWARE_MOTHERBOARD),1145)
-# ADIMLab Gantry v1
+# Overlord/Overlord Pro
else ifeq ($(HARDWARE_MOTHERBOARD),1146)
-# ADIMLab Gantry v2
+# ADIMLab Gantry v1
else ifeq ($(HARDWARE_MOTHERBOARD),1147)
-# BIQU Tango V1
+# ADIMLab Gantry v2
else ifeq ($(HARDWARE_MOTHERBOARD),1148)
-# MKS GEN L V2
+# BIQU Tango V1
else ifeq ($(HARDWARE_MOTHERBOARD),1149)
-# Copymaster 3D
+# MKS GEN L V2
else ifeq ($(HARDWARE_MOTHERBOARD),1150)
+# Copymaster 3D
+else ifeq ($(HARDWARE_MOTHERBOARD),1151)
+# Ortur 4
+else ifeq ($(HARDWARE_MOTHERBOARD),1152)
+# Tenlog D3 Hero
+else ifeq ($(HARDWARE_MOTHERBOARD),1153)
#
# RAMBo and derivatives
@@ -361,34 +366,38 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1501)
else ifeq ($(HARDWARE_MOTHERBOARD),1502)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega644p
-# Melzi with ATmega1284 (MaKr3d version)
+# Melzi V2.0
else ifeq ($(HARDWARE_MOTHERBOARD),1503)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
-# Melzi Creality3D board (for CR-10 etc)
+# Melzi with ATmega1284 (MaKr3d version)
else ifeq ($(HARDWARE_MOTHERBOARD),1504)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
-# Melzi Malyan M150 board
+# Melzi Creality3D board (for CR-10 etc)
else ifeq ($(HARDWARE_MOTHERBOARD),1505)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
-# Tronxy X5S
+# Melzi Malyan M150 board
else ifeq ($(HARDWARE_MOTHERBOARD),1506)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
-# STB V1.1
+# Tronxy X5S
else ifeq ($(HARDWARE_MOTHERBOARD),1507)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
-# Azteeg X1
+# STB V1.1
else ifeq ($(HARDWARE_MOTHERBOARD),1508)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
-# Anet 1.0 (Melzi clone)
+# Azteeg X1
else ifeq ($(HARDWARE_MOTHERBOARD),1509)
HARDWARE_VARIANT ?= Sanguino
MCU ?= atmega1284p
+# Anet 1.0 (Melzi clone)
+else ifeq ($(HARDWARE_MOTHERBOARD),1510)
+ HARDWARE_VARIANT ?= Sanguino
+ MCU ?= atmega1284p
#
# Other ATmega644P, ATmega644, ATmega1284P
@@ -686,7 +695,7 @@ ifeq ($(HARDWARE_VARIANT), Teensy)
else ifeq ($(HARDWARE_VARIANT), archim)
CDEFS += -DARDUINO_SAM_ARCHIM -DARDUINO_ARCH_SAM -D__SAM3X8E__ -DUSB_VID=0x27b1 -DUSB_PID=0x0001 -DUSBCON '-DUSB_MANUFACTURER="UltiMachine"' '-DUSB_PRODUCT="Archim"'
- LIB_CXXSRC += variant.cpp IPAddress.cpp Reset.cpp RingBuffer.cpp Stream.cpp UARTClass.cpp USARTClass.cpp abi.cpp new.cpp watchdog.cpp CDC.cpp PluggableUSB.cpp USBCore.cpp
+ LIB_CXXSRC += variant.cpp IPAddress.cpp Reset.cpp RingBuffer.cpp Stream.cpp UARTClass.cpp USARTClass.cpp abi.cpp new.cpp watchdog.cpp CDC.cpp PluggableUSB.cpp USBCore.cpp
LIB_SRC += cortex_handlers.c iar_calls_sam3.c syscalls_sam3.c dtostrf.c itoa.c
ifeq ($(U8GLIB), 1)
diff --git a/Marlin/Marlin.ino b/Marlin/Marlin.ino
index ae5bca1dfe..57c825445f 100644
--- a/Marlin/Marlin.ino
+++ b/Marlin/Marlin.ino
@@ -1,9 +1,8 @@
-/*
-================================================================================
+/*==============================================================================
Marlin Firmware
- (c) 2011-2019 MarlinFirmware
+ (c) 2011-2020 MarlinFirmware
Portions of Marlin are (c) by their respective authors.
All code complies with GPLv2 and/or GPLv3
@@ -12,30 +11,33 @@
Greetings! Thank you for choosing Marlin 2 as your 3D printer firmware.
To configure Marlin you must edit Configuration.h and Configuration_adv.h
-located in the root 'Marlin' folder. Check the config/examples folder to see if
-there's a more suitable starting-point for your specific hardware.
+located in the root 'Marlin' folder. Check our Configurations repository to
+see if there's a more suitable starting-point for your specific hardware.
Before diving in, we recommend the following essential links:
Marlin Firmware Official Website
- - http://marlinfw.org/
+ - https://marlinfw.org/
The official Marlin Firmware website contains the most up-to-date
documentation. Contributions are always welcome!
Configuration
+ - https://github.com/MarlinFirmware/Configurations
+ Example configurations for several printer models.
+
- https://www.youtube.com/watch?v=3gwWVFtdg-4
A good 20-minute overview of Marlin configuration by Tom Sanladerer.
(Applies to Marlin 1.0.x, so Jerk and Acceleration should be halved.)
Also... https://www.google.com/search?tbs=vid%3A1&q=configure+marlin
- - http://marlinfw.org/docs/configuration/configuration.html
+ - https://marlinfw.org/docs/configuration/configuration.html
Marlin's configuration options are explained in more detail here.
Getting Help
- - http://forums.reprap.org/list.php?415
+ - https://reprap.org/forum/list.php?415
The Marlin Discussion Forum is a great place to get help from other Marlin
users who may have experienced similar issues to your own.
@@ -45,9 +47,11 @@ Getting Help
Contributing
- - http://marlinfw.org/docs/development/contributing.html
+ - https://marlinfw.org/docs/development/contributing.html
If you'd like to contribute to Marlin, read this first!
- - http://marlinfw.org/docs/development/coding_standards.html
+ - https://marlinfw.org/docs/development/coding_standards.html
Before submitting code get to know the Coding Standards.
-*/
+
+
+------------------------------------------------------------------------------*/
diff --git a/Marlin/Version.h b/Marlin/Version.h
index b4e51841b3..5ce04b2903 100644
--- a/Marlin/Version.h
+++ b/Marlin/Version.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -28,20 +28,20 @@
/**
* Marlin release version identifier
*/
-//#define SHORT_BUILD_VERSION "2.0.5.3"
+//#define SHORT_BUILD_VERSION "2.0.6.1"
/**
* Verbose version identifier which should contain a reference to the location
* from where the binary was downloaded or the source code was compiled.
*/
-//#define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION " (Github)"
+//#define DETAILED_BUILD_VERSION SHORT_BUILD_VERSION
/**
* The STRING_DISTRIBUTION_DATE represents when the binary file was built,
* here we define this default string as the date where the latest release
* version was tagged.
*/
-//#define STRING_DISTRIBUTION_DATE "2020-01-31"
+//#define STRING_DISTRIBUTION_DATE "2020-07-09"
/**
* Defines a generic printer name to be output to the LCD after booting Marlin.
@@ -65,12 +65,12 @@
* The WEBSITE_URL is the location where users can get more information such as
* documentation about a specific Marlin release.
*/
-//#define WEBSITE_URL "http://marlinfw.org"
+//#define WEBSITE_URL "https://marlinfw.org"
/**
* Set the vendor info the serial USB interface, if changable
* Currently only supported by DUE platform
*/
-//#define USB_DEVICE_VENDOR_ID 0x0000
-//#define USB_DEVICE_PRODUCT_ID 0x0000
-//#define USB_DEVICE_MANUFACTURE_NAME WEBSITE_URL
+//#define USB_DEVICE_VENDOR_ID 0x0000
+//#define USB_DEVICE_PRODUCT_ID 0x0000
+//#define USB_DEVICE_MANUFACTURE_NAME WEBSITE_URL
diff --git a/Marlin/lib/readme.txt b/Marlin/lib/readme.txt
index dbadc3d630..5ec60aa858 100644
--- a/Marlin/lib/readme.txt
+++ b/Marlin/lib/readme.txt
@@ -33,4 +33,4 @@ PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
-- http://docs.platformio.org/page/librarymanager/ldf.html
+- https://docs.platformio.org/page/librarymanager/ldf.html
diff --git a/Marlin/src/HAL/AVR/HAL.cpp b/Marlin/src/HAL/AVR/HAL.cpp
index 317d13a540..58d57c8ee5 100644
--- a/Marlin/src/HAL/AVR/HAL.cpp
+++ b/Marlin/src/HAL/AVR/HAL.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __AVR__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/AVR/HAL.h b/Marlin/src/HAL/AVR/HAL.h
index 0255169819..609375e386 100644
--- a/Marlin/src/HAL/AVR/HAL.h
+++ b/Marlin/src/HAL/AVR/HAL.h
@@ -14,7 +14,7 @@
* 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 .
+ * along with this program. If not, see .
*/
#pragma once
@@ -50,7 +50,11 @@
// Defines
// ------------------------
-//#define analogInputToDigitalPin(IO) IO
+// AVR PROGMEM extension for sprintf_P
+#define S_FMT "%S"
+
+// AVR PROGMEM extension for string define
+#define PGMSTR(NAM,STR) const char NAM[] PROGMEM = STR
#ifndef CRITICAL_SECTION_START
#define CRITICAL_SECTION_START() unsigned char _sreg = SREG; cli()
@@ -60,16 +64,10 @@
#define ENABLE_ISRS() sei()
#define DISABLE_ISRS() cli()
-// On AVR this is in math.h?
-//#define square(x) ((x)*(x))
-
// ------------------------
// Types
// ------------------------
-typedef uint16_t hal_timer_t;
-#define HAL_TIMER_TYPE_MAX 0xFFFF
-
typedef int8_t pin_t;
#define SHARED_SERVOS HAS_SERVOS
@@ -122,6 +120,17 @@ typedef int8_t pin_t;
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
#endif
+#ifdef ANYCUBIC_LCD_SERIAL_PORT
+ #if !WITHIN(ANYCUBIC_LCD_SERIAL_PORT, -1, 3)
+ #error "ANYCUBIC_LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
+ #elif ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT
+ #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
+ #elif defined(SERIAL_PORT_2) && ANYCUBIC_LCD_SERIAL_PORT == SERIAL_PORT_2
+ #error "ANYCUBIC_LCD_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
+ #endif
+ #define ANYCUBIC_LCD_SERIAL anycubicLcdSerial
+#endif
+
// ------------------------
// Public functions
// ------------------------
@@ -142,220 +151,6 @@ extern "C" {
}
#pragma GCC diagnostic pop
-// timers
-#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
-
-#define STEP_TIMER_NUM 1
-#define TEMP_TIMER_NUM 0
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
-
-#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
-
-#define STEPPER_TIMER_RATE HAL_TIMER_RATE
-#define STEPPER_TIMER_PRESCALE 8
-#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
-
-#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
-
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
-#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
-#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
-
-#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
-#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
-#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
-
-FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
- switch (timer_num) {
- case STEP_TIMER_NUM:
- // waveform generation = 0100 = CTC
- SET_WGM(1, CTC_OCRnA);
-
- // output mode = 00 (disconnected)
- SET_COMA(1, NORMAL);
-
- // Set the timer pre-scaler
- // Generally we use a divider of 8, resulting in a 2MHz timer
- // frequency on a 16MHz MCU. If you are going to change this, be
- // sure to regenerate speed_lookuptable.h with
- // create_speed_lookuptable.py
- SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
-
- // Init Stepper ISR to 122 Hz for quick starting
- // (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
- OCR1A = 0x4000;
- TCNT1 = 0;
- break;
-
- case TEMP_TIMER_NUM:
- // Use timer0 for temperature measurement
- // Interleave temperature interrupt with millies interrupt
- OCR0B = 128;
- break;
- }
-}
-
-#define TIMER_OCR_1 OCR1A
-#define TIMER_COUNTER_1 TCNT1
-
-#define TIMER_OCR_0 OCR0A
-#define TIMER_COUNTER_0 TCNT0
-
-#define _CAT(a,V...) a##V
-#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
-#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
-#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
-
-/**
- * On AVR there is no hardware prioritization and preemption of
- * interrupts, so this emulates it. The UART has first priority
- * (otherwise, characters will be lost due to UART overflow).
- * Then: Stepper, Endstops, Temperature, and -finally- all others.
- */
-#define HAL_timer_isr_prologue(TIMER_NUM)
-#define HAL_timer_isr_epilogue(TIMER_NUM)
-
-/* 18 cycles maximum latency */
-#define HAL_STEP_TIMER_ISR() \
-extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal, naked, used, externally_visible)); \
-extern "C" void TIMER1_COMPA_vect_bottom() asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
-void TIMER1_COMPA_vect() { \
- __asm__ __volatile__ ( \
- A("push r16") /* 2 Save R16 */ \
- A("in r16, __SREG__") /* 1 Get SREG */ \
- A("push r16") /* 2 Save SREG into stack */ \
- A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
- A("push r16") /* 2 Save TIMSK0 into the stack */ \
- A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
- A("sts %[timsk0], r16") /* 2 And set the new value */ \
- A("lds r16, %[timsk1]") /* 2 Load into R0 the stepper timer Interrupt mask register [TIMSK1] */ \
- A("andi r16,~%[msk1]") /* 1 Disable the stepper ISR */ \
- A("sts %[timsk1], r16") /* 2 And set the new value */ \
- A("push r16") /* 2 Save TIMSK1 into stack */ \
- A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
- A("push r16") /* 2 Save RAMPZ into stack */ \
- A("in r16, 0x3C") /* 1 Get EIND register */ \
- A("push r0") /* C runtime can modify all the following registers without restoring them */ \
- A("push r1") \
- A("push r18") \
- A("push r19") \
- A("push r20") \
- A("push r21") \
- A("push r22") \
- A("push r23") \
- A("push r24") \
- A("push r25") \
- A("push r26") \
- A("push r27") \
- A("push r30") \
- A("push r31") \
- A("clr r1") /* C runtime expects this register to be 0 */ \
- A("call TIMER1_COMPA_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
- A("pop r31") \
- A("pop r30") \
- A("pop r27") \
- A("pop r26") \
- A("pop r25") \
- A("pop r24") \
- A("pop r23") \
- A("pop r22") \
- A("pop r21") \
- A("pop r20") \
- A("pop r19") \
- A("pop r18") \
- A("pop r1") \
- A("pop r0") \
- A("out 0x3C, r16") /* 1 Restore EIND register */ \
- A("pop r16") /* 2 Get the original RAMPZ register value */ \
- A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
- A("pop r16") /* 2 Get the original TIMSK1 value but with stepper ISR disabled */ \
- A("ori r16,%[msk1]") /* 1 Reenable the stepper ISR */ \
- A("cli") /* 1 Disable global interrupts - Reenabling Stepper ISR can reenter amd temperature can reenter, and we want that, if it happens, after this ISR has ended */ \
- A("sts %[timsk1], r16") /* 2 And restore the old value - This reenables the stepper ISR */ \
- A("pop r16") /* 2 Get the temperature timer Interrupt mask register [TIMSK0] */ \
- A("sts %[timsk0], r16") /* 2 And restore the old value - This reenables the temperature ISR */ \
- A("pop r16") /* 2 Get the old SREG value */ \
- A("out __SREG__, r16") /* 1 And restore the SREG value */ \
- A("pop r16") /* 2 Restore R16 value */ \
- A("reti") /* 4 Return from interrupt */ \
- : \
- : [timsk0] "i" ((uint16_t)&TIMSK0), \
- [timsk1] "i" ((uint16_t)&TIMSK1), \
- [msk0] "M" ((uint8_t)(1<.
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp
index 350d0f302d..3d44a3f59f 100644
--- a/Marlin/src/HAL/AVR/MarlinSerial.cpp
+++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -43,6 +43,10 @@
#include "MarlinSerial.h"
#include "../../MarlinCore.h"
+ #if ENABLED(DIRECT_STEPPING)
+ #include "../../feature/direct_stepping.h"
+ #endif
+
template typename MarlinSerial::ring_buffer_r MarlinSerial::rx_buffer = { 0, 0, { 0 } };
template typename MarlinSerial::ring_buffer_t MarlinSerial::tx_buffer = { 0 };
template bool MarlinSerial::_written = false;
@@ -131,6 +135,18 @@
static EmergencyParser::State emergency_state; // = EP_RESET
+ // This must read the R_UCSRA register before reading the received byte to detect error causes
+ if (Cfg::DROPPED_RX && B_DOR && !++rx_dropped_bytes) --rx_dropped_bytes;
+ if (Cfg::RX_OVERRUNS && B_DOR && !++rx_buffer_overruns) --rx_buffer_overruns;
+ if (Cfg::RX_FRAMING_ERRORS && B_FE && !++rx_framing_errors) --rx_framing_errors;
+
+ // Read the character from the USART
+ uint8_t c = R_UDR;
+
+ #if ENABLED(DIRECT_STEPPING)
+ if (page_manager.maybe_store_rxd_char(c)) return;
+ #endif
+
// Get the tail - Nothing can alter its value while this ISR is executing, but there's
// a chance that this ISR interrupted the main process while it was updating the index.
// The backup mechanism ensures the correct value is always returned.
@@ -142,14 +158,6 @@
// Get the next element
ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(Cfg::RX_SIZE - 1);
- // This must read the R_UCSRA register before reading the received byte to detect error causes
- if (Cfg::DROPPED_RX && B_DOR && !++rx_dropped_bytes) --rx_dropped_bytes;
- if (Cfg::RX_OVERRUNS && B_DOR && !++rx_buffer_overruns) --rx_buffer_overruns;
- if (Cfg::RX_FRAMING_ERRORS && B_FE && !++rx_framing_errors) --rx_framing_errors;
-
- // Read the character from the USART
- uint8_t c = R_UDR;
-
if (Cfg::EMERGENCYPARSER) emergency_parser.update(emergency_state, c);
// If the character is to be stored at the index just before the tail
@@ -784,6 +792,24 @@
#endif
+#ifdef ANYCUBIC_LCD_SERIAL_PORT
+
+ ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_RX_vect)) {
+ MarlinSerial>::store_rxd_char();
+ }
+
+ ISR(SERIAL_REGNAME(USART,ANYCUBIC_LCD_SERIAL_PORT,_UDRE_vect)) {
+ MarlinSerial>::_tx_udr_empty_irq();
+ }
+
+ // Preinstantiate
+ template class MarlinSerial>;
+
+ // Instantiate
+ MarlinSerial> anycubicLcdSerial;
+
+#endif
+
// For AT90USB targets use the UART for BT interfacing
#if defined(USBCON) && ENABLED(BLUETOOTH)
HardwareSerial bluetoothSerial;
diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h
index cd7aad90a9..e8bfc5583a 100644
--- a/Marlin/src/HAL/AVR/MarlinSerial.h
+++ b/Marlin/src/HAL/AVR/MarlinSerial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -299,12 +299,12 @@
template
struct MarlinInternalSerialCfg {
static constexpr int PORT = serial;
- static constexpr unsigned int RX_SIZE = 128;
- static constexpr unsigned int TX_SIZE = 48;
+ static constexpr unsigned int RX_SIZE = DGUS_RX_BUFFER_SIZE;
+ static constexpr unsigned int TX_SIZE = DGUS_TX_BUFFER_SIZE;
static constexpr bool XONOFF = false;
static constexpr bool EMERGENCYPARSER = false;
static constexpr bool DROPPED_RX = false;
- static constexpr bool RX_OVERRUNS = HAS_DGUS_LCD && ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
+ static constexpr bool RX_OVERRUNS = BOTH(HAS_DGUS_LCD, DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS);
static constexpr bool RX_FRAMING_ERRORS = false;
static constexpr bool MAX_RX_QUEUED = false;
};
@@ -312,6 +312,23 @@
extern MarlinSerial> internalDgusSerial;
#endif
+#ifdef ANYCUBIC_LCD_SERIAL_PORT
+ template
+ struct AnycubicLcdSerialCfg {
+ static constexpr int PORT = serial;
+ static constexpr unsigned int RX_SIZE = 64;
+ static constexpr unsigned int TX_SIZE = 128;
+ static constexpr bool XONOFF = false;
+ static constexpr bool EMERGENCYPARSER = false;
+ static constexpr bool DROPPED_RX = false;
+ static constexpr bool RX_OVERRUNS = false;
+ static constexpr bool RX_FRAMING_ERRORS = false;
+ static constexpr bool MAX_RX_QUEUED = false;
+ };
+
+ extern MarlinSerial> anycubicLcdSerial;
+#endif
+
// Use the UART for Bluetooth in AT90USB configurations
#if defined(USBCON) && ENABLED(BLUETOOTH)
extern HardwareSerial bluetoothSerial;
diff --git a/Marlin/src/HAL/AVR/Servo.cpp b/Marlin/src/HAL/AVR/Servo.cpp
index 02c131bd44..66ed993c6f 100644
--- a/Marlin/src/HAL/AVR/Servo.cpp
+++ b/Marlin/src/HAL/AVR/Servo.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -59,7 +59,6 @@
#include
-#include "../shared/Marduino.h"
#include "../shared/servo.h"
#include "../shared/servo_private.h"
diff --git a/Marlin/src/HAL/AVR/ServoTimers.h b/Marlin/src/HAL/AVR/ServoTimers.h
index 86007fd102..436b28141f 100644
--- a/Marlin/src/HAL/AVR/ServoTimers.h
+++ b/Marlin/src/HAL/AVR/ServoTimers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -59,10 +59,12 @@
// Say which 16 bit timers can be used and in what order
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
//#define _useTimer1
- #define _useTimer3
#define _useTimer4
- #if !HAS_MOTOR_CURRENT_PWM
- #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
+ #if NUM_SERVOS > SERVOS_PER_TIMER
+ #define _useTimer3
+ #if !HAS_MOTOR_CURRENT_PWM && SERVOS > 2 * SERVOS_PER_TIMER
+ #define _useTimer5 // Timer 5 is used for motor current PWM and can't be used for servos.
+ #endif
#endif
#elif defined(__AVR_ATmega32U4__)
#define _useTimer3
diff --git a/Marlin/src/HAL/AVR/eeprom.cpp b/Marlin/src/HAL/AVR/eeprom.cpp
index ee416b7a12..c7906985eb 100644
--- a/Marlin/src/HAL/AVR/eeprom.cpp
+++ b/Marlin/src/HAL/AVR/eeprom.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __AVR__
@@ -25,9 +25,18 @@
#if EITHER(EEPROM_SETTINGS, SD_FIRMWARE_UPDATE)
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with implementations supplied by the framework.
+ */
+
#include "../shared/eeprom_api.h"
-bool PersistentStore::access_start() { return true; }
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
@@ -46,7 +55,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
crc16(crc, &v, 1);
pos++;
value++;
- };
+ }
return false;
}
@@ -61,7 +70,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false; // always assume success for AVR's
}
-size_t PersistentStore::capacity() { return E2END + 1; }
-
#endif // EEPROM_SETTINGS || SD_FIRMWARE_UPDATE
#endif // __AVR__
diff --git a/Marlin/src/HAL/AVR/endstop_interrupts.h b/Marlin/src/HAL/AVR/endstop_interrupts.h
index 8f89c69baf..ae9a605acc 100644
--- a/Marlin/src/HAL/AVR/endstop_interrupts.h
+++ b/Marlin/src/HAL/AVR/endstop_interrupts.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/fast_pwm.cpp b/Marlin/src/HAL/AVR/fast_pwm.cpp
index 42e7cc3f10..29866bccf9 100644
--- a/Marlin/src/HAL/AVR/fast_pwm.cpp
+++ b/Marlin/src/HAL/AVR/fast_pwm.cpp
@@ -16,14 +16,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __AVR__
#include "../../inc/MarlinConfigPre.h"
-#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
+#if NEEDS_HARDWARE_PWM // Specific meta-flag for features that mandate PWM
#include "HAL.h"
@@ -274,9 +274,9 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
else
top = *timer.ICRn; // top = ICRn
- _SET_OCRnQ(timer.OCRnQ, timer.q, v * float(top / v_size)); // Scale 8/16-bit v to top value
+ _SET_OCRnQ(timer.OCRnQ, timer.q, v * float(top) / float(v_size)); // Scale 8/16-bit v to top value
}
}
-#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
+#endif // NEEDS_HARDWARE_PWM
#endif // __AVR__
diff --git a/Marlin/src/HAL/AVR/fastio.cpp b/Marlin/src/HAL/AVR/fastio.cpp
index 9f70b50f71..b51d7f9768 100644
--- a/Marlin/src/HAL/AVR/fastio.cpp
+++ b/Marlin/src/HAL/AVR/fastio.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -234,5 +234,55 @@ uint8_t extDigitalRead(const int8_t pin) {
}
}
+#if 0
+/**
+ * Set Timer 5 PWM frequency in Hz, from 3.8Hz up to ~16MHz
+ * with a minimum resolution of 100 steps.
+ *
+ * DC values -1.0 to 1.0. Negative duty cycle inverts the pulse.
+ */
+uint16_t set_pwm_frequency_hz(const float &hz, const float dca, const float dcb, const float dcc) {
+ float count = 0;
+ if (hz > 0 && (dca || dcb || dcc)) {
+ count = float(F_CPU) / hz; // 1x prescaler, TOP for 16MHz base freq.
+ uint16_t prescaler; // Range of 30.5Hz (65535) 64.5KHz (>31)
+
+ if (count >= 255. * 256.) { prescaler = 1024; SET_CS(5, PRESCALER_1024); }
+ else if (count >= 255. * 64.) { prescaler = 256; SET_CS(5, PRESCALER_256); }
+ else if (count >= 255. * 8.) { prescaler = 64; SET_CS(5, PRESCALER_64); }
+ else if (count >= 255.) { prescaler = 8; SET_CS(5, PRESCALER_8); }
+ else { prescaler = 1; SET_CS(5, PRESCALER_1); }
+
+ count /= float(prescaler);
+ const float pwm_top = round(count); // Get the rounded count
+
+ ICR5 = (uint16_t)pwm_top - 1; // Subtract 1 for TOP
+ OCR5A = pwm_top * ABS(dca); // Update and scale DCs
+ OCR5B = pwm_top * ABS(dcb);
+ OCR5C = pwm_top * ABS(dcc);
+ _SET_COM(5, A, dca ? (dca < 0 ? COM_SET_CLEAR : COM_CLEAR_SET) : COM_NORMAL); // Set compare modes
+ _SET_COM(5, B, dcb ? (dcb < 0 ? COM_SET_CLEAR : COM_CLEAR_SET) : COM_NORMAL);
+ _SET_COM(5, C, dcc ? (dcc < 0 ? COM_SET_CLEAR : COM_CLEAR_SET) : COM_NORMAL);
+
+ SET_WGM(5, FAST_PWM_ICRn); // Fast PWM with ICR5 as TOP
+
+ //SERIAL_ECHOLNPGM("Timer 5 Settings:");
+ //SERIAL_ECHOLNPAIR(" Prescaler=", prescaler);
+ //SERIAL_ECHOLNPAIR(" TOP=", ICR5);
+ //SERIAL_ECHOLNPAIR(" OCR5A=", OCR5A);
+ //SERIAL_ECHOLNPAIR(" OCR5B=", OCR5B);
+ //SERIAL_ECHOLNPAIR(" OCR5C=", OCR5C);
+ }
+ else {
+ // Restore the default for Timer 5
+ SET_WGM(5, PWM_PC_8); // PWM 8-bit (Phase Correct)
+ SET_COMS(5, NORMAL, NORMAL, NORMAL); // Do nothing
+ SET_CS(5, PRESCALER_64); // 16MHz / 64 = 250KHz
+ OCR5A = OCR5B = OCR5C = 0;
+ }
+ return round(count);
+}
+#endif
+
#endif // FASTIO_EXT_START
#endif // __AVR__
diff --git a/Marlin/src/HAL/AVR/fastio.h b/Marlin/src/HAL/AVR/fastio.h
index a45e0f2beb..bd6935aaf0 100644
--- a/Marlin/src/HAL/AVR/fastio.h
+++ b/Marlin/src/HAL/AVR/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -57,7 +57,7 @@
*
* Now you can simply SET_OUTPUT(PIN); WRITE(PIN, HIGH); WRITE(PIN, LOW);
*
- * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
+ * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/cpp/Stringification.html
*/
#define _READ(IO) TEST(DIO ## IO ## _RPORT, DIO ## IO ## _PIN)
diff --git a/Marlin/src/HAL/AVR/fastio/fastio_1280.h b/Marlin/src/HAL/AVR/fastio/fastio_1280.h
index b62156caa7..f482f823e8 100644
--- a/Marlin/src/HAL/AVR/fastio/fastio_1280.h
+++ b/Marlin/src/HAL/AVR/fastio/fastio_1280.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/fastio/fastio_1281.h b/Marlin/src/HAL/AVR/fastio/fastio_1281.h
index 7552540ffe..e0bc5e2995 100644
--- a/Marlin/src/HAL/AVR/fastio/fastio_1281.h
+++ b/Marlin/src/HAL/AVR/fastio/fastio_1281.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/fastio/fastio_168.h b/Marlin/src/HAL/AVR/fastio/fastio_168.h
index 549e0246d5..8cfdd1e8f8 100644
--- a/Marlin/src/HAL/AVR/fastio/fastio_168.h
+++ b/Marlin/src/HAL/AVR/fastio/fastio_168.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/fastio/fastio_644.h b/Marlin/src/HAL/AVR/fastio/fastio_644.h
index 3a48c109e9..f4a9427e0a 100644
--- a/Marlin/src/HAL/AVR/fastio/fastio_644.h
+++ b/Marlin/src/HAL/AVR/fastio/fastio_644.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h b/Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h
index 23d16a20e5..51d400b705 100644
--- a/Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h
+++ b/Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h b/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h
index 0285c52ee3..a611ccd7c4 100644
--- a/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/AVR."
+#endif
diff --git a/Marlin/src/HAL/AVR/inc/Conditionals_adv.h b/Marlin/src/HAL/AVR/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/AVR/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/AVR/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/inc/Conditionals_post.h b/Marlin/src/HAL/AVR/inc/Conditionals_post.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/AVR/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/AVR/inc/Conditionals_post.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h
index 1c7c68f216..731cf92865 100644
--- a/Marlin/src/HAL/AVR/inc/SanityCheck.h
+++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -25,16 +25,6 @@
* Test AVR-specific configuration values for errors at compile-time.
*/
-/**
- * Digipot requirement
- */
- #if ENABLED(DIGIPOT_MCP4018)
- #if !defined(DIGIPOTS_I2C_SDA_X) || !defined(DIGIPOTS_I2C_SDA_Y) || !defined(DIGIPOTS_I2C_SDA_Z) \
- || !defined(DIGIPOTS_I2C_SDA_E0) || !defined(DIGIPOTS_I2C_SDA_E1)
- #error "DIGIPOT_MCP4018 requires DIGIPOTS_I2C_SDA_* pins to be defined."
- #endif
-#endif
-
/**
* Checks for FAST PWM
*/
@@ -46,20 +36,23 @@
* Sanity checks for Spindle / Laser PWM
*/
#if ENABLED(SPINDLE_LASER_PWM)
+ #include "../ServoTimers.h" // Needed to check timer availability (_useTimer3)
#if SPINDLE_LASER_PWM_PIN == 4 || WITHIN(SPINDLE_LASER_PWM_PIN, 11, 13)
#error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by a system interrupt."
- #elif NUM_SERVOS > 0 && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5)
+ #elif NUM_SERVOS > 0 && defined(_useTimer3) && (WITHIN(SPINDLE_LASER_PWM_PIN, 2, 3) || SPINDLE_LASER_PWM_PIN == 5)
#error "Counter/Timer for SPINDLE_LASER_PWM_PIN is used by the servo system."
#endif
+#elif defined(SPINDLE_LASER_FREQUENCY)
+ #error "SPINDLE_LASER_FREQUENCY requires SPINDLE_LASER_PWM."
#endif
/**
* The Trinamic library includes SoftwareSerial.h, leading to a compile error.
*/
-#if HAS_TRINAMIC_CONFIG && ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+#if BOTH(HAS_TRINAMIC_CONFIG, ENDSTOP_INTERRUPTS_FEATURE)
#error "TMCStepper includes SoftwareSerial.h which is incompatible with ENDSTOP_INTERRUPTS_FEATURE. Disable ENDSTOP_INTERRUPTS_FEATURE to continue."
#endif
-#if HAS_TMC_SW_SERIAL && ENABLED(MONITOR_DRIVER_STATUS)
+#if BOTH(HAS_TMC_SW_SERIAL, MONITOR_DRIVER_STATUS)
#error "MONITOR_DRIVER_STATUS causes performance issues when used with SoftwareSerial-connected drivers. Disable MONITOR_DRIVER_STATUS or use hardware serial to continue."
#endif
diff --git a/Marlin/src/HAL/AVR/math.h b/Marlin/src/HAL/AVR/math.h
index e8be0a04bc..7ede4accc0 100644
--- a/Marlin/src/HAL/AVR/math.h
+++ b/Marlin/src/HAL/AVR/math.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/pinsDebug.h b/Marlin/src/HAL/AVR/pinsDebug.h
index fbd2e084fa..d73f520d14 100644
--- a/Marlin/src/HAL/AVR/pinsDebug.h
+++ b/Marlin/src/HAL/AVR/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h b/Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h
index f6da077743..051972a861 100644
--- a/Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h
+++ b/Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/pinsDebug_plus_70.h b/Marlin/src/HAL/AVR/pinsDebug_plus_70.h
index 6e7b8fbaa9..46c03088d2 100644
--- a/Marlin/src/HAL/AVR/pinsDebug_plus_70.h
+++ b/Marlin/src/HAL/AVR/pinsDebug_plus_70.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/spi_pins.h b/Marlin/src/HAL/AVR/spi_pins.h
index daaebb76d7..f3fa78e2bf 100644
--- a/Marlin/src/HAL/AVR/spi_pins.h
+++ b/Marlin/src/HAL/AVR/spi_pins.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/AVR/timers.h b/Marlin/src/HAL/AVR/timers.h
new file mode 100644
index 0000000000..6c40d32209
--- /dev/null
+++ b/Marlin/src/HAL/AVR/timers.h
@@ -0,0 +1,259 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ *
+ * 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 .
+ */
+#pragma once
+
+#include
+
+// ------------------------
+// Types
+// ------------------------
+
+typedef uint16_t hal_timer_t;
+#define HAL_TIMER_TYPE_MAX 0xFFFF
+
+// ------------------------
+// Defines
+// ------------------------
+
+#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
+
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 1
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 0
+#endif
+
+#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
+
+#define STEPPER_TIMER_RATE HAL_TIMER_RATE
+#define STEPPER_TIMER_PRESCALE 8
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
+
+#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
+
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
+#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
+
+#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
+#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
+#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
+
+FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
+ switch (timer_num) {
+ case STEP_TIMER_NUM:
+ // waveform generation = 0100 = CTC
+ SET_WGM(1, CTC_OCRnA);
+
+ // output mode = 00 (disconnected)
+ SET_COMA(1, NORMAL);
+
+ // Set the timer pre-scaler
+ // Generally we use a divider of 8, resulting in a 2MHz timer
+ // frequency on a 16MHz MCU. If you are going to change this, be
+ // sure to regenerate speed_lookuptable.h with
+ // create_speed_lookuptable.py
+ SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
+
+ // Init Stepper ISR to 122 Hz for quick starting
+ // (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
+ OCR1A = 0x4000;
+ TCNT1 = 0;
+ break;
+
+ case TEMP_TIMER_NUM:
+ // Use timer0 for temperature measurement
+ // Interleave temperature interrupt with millies interrupt
+ OCR0B = 128;
+ break;
+ }
+}
+
+#define TIMER_OCR_1 OCR1A
+#define TIMER_COUNTER_1 TCNT1
+
+#define TIMER_OCR_0 OCR0A
+#define TIMER_COUNTER_0 TCNT0
+
+#define _CAT(a,V...) a##V
+#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
+#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
+#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
+
+/**
+ * On AVR there is no hardware prioritization and preemption of
+ * interrupts, so this emulates it. The UART has first priority
+ * (otherwise, characters will be lost due to UART overflow).
+ * Then: Stepper, Endstops, Temperature, and -finally- all others.
+ */
+#define HAL_timer_isr_prologue(TIMER_NUM)
+#define HAL_timer_isr_epilogue(TIMER_NUM)
+
+/* 18 cycles maximum latency */
+#ifndef HAL_STEP_TIMER_ISR
+
+#define HAL_STEP_TIMER_ISR() \
+extern "C" void TIMER1_COMPA_vect() __attribute__ ((signal, naked, used, externally_visible)); \
+extern "C" void TIMER1_COMPA_vect_bottom() asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
+void TIMER1_COMPA_vect() { \
+ __asm__ __volatile__ ( \
+ A("push r16") /* 2 Save R16 */ \
+ A("in r16, __SREG__") /* 1 Get SREG */ \
+ A("push r16") /* 2 Save SREG into stack */ \
+ A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
+ A("push r16") /* 2 Save TIMSK0 into the stack */ \
+ A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
+ A("sts %[timsk0], r16") /* 2 And set the new value */ \
+ A("lds r16, %[timsk1]") /* 2 Load into R0 the stepper timer Interrupt mask register [TIMSK1] */ \
+ A("andi r16,~%[msk1]") /* 1 Disable the stepper ISR */ \
+ A("sts %[timsk1], r16") /* 2 And set the new value */ \
+ A("push r16") /* 2 Save TIMSK1 into stack */ \
+ A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
+ A("push r16") /* 2 Save RAMPZ into stack */ \
+ A("in r16, 0x3C") /* 1 Get EIND register */ \
+ A("push r0") /* C runtime can modify all the following registers without restoring them */ \
+ A("push r1") \
+ A("push r18") \
+ A("push r19") \
+ A("push r20") \
+ A("push r21") \
+ A("push r22") \
+ A("push r23") \
+ A("push r24") \
+ A("push r25") \
+ A("push r26") \
+ A("push r27") \
+ A("push r30") \
+ A("push r31") \
+ A("clr r1") /* C runtime expects this register to be 0 */ \
+ A("call TIMER1_COMPA_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
+ A("pop r31") \
+ A("pop r30") \
+ A("pop r27") \
+ A("pop r26") \
+ A("pop r25") \
+ A("pop r24") \
+ A("pop r23") \
+ A("pop r22") \
+ A("pop r21") \
+ A("pop r20") \
+ A("pop r19") \
+ A("pop r18") \
+ A("pop r1") \
+ A("pop r0") \
+ A("out 0x3C, r16") /* 1 Restore EIND register */ \
+ A("pop r16") /* 2 Get the original RAMPZ register value */ \
+ A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
+ A("pop r16") /* 2 Get the original TIMSK1 value but with stepper ISR disabled */ \
+ A("ori r16,%[msk1]") /* 1 Reenable the stepper ISR */ \
+ A("cli") /* 1 Disable global interrupts - Reenabling Stepper ISR can reenter amd temperature can reenter, and we want that, if it happens, after this ISR has ended */ \
+ A("sts %[timsk1], r16") /* 2 And restore the old value - This reenables the stepper ISR */ \
+ A("pop r16") /* 2 Get the temperature timer Interrupt mask register [TIMSK0] */ \
+ A("sts %[timsk0], r16") /* 2 And restore the old value - This reenables the temperature ISR */ \
+ A("pop r16") /* 2 Get the old SREG value */ \
+ A("out __SREG__, r16") /* 1 And restore the SREG value */ \
+ A("pop r16") /* 2 Restore R16 value */ \
+ A("reti") /* 4 Return from interrupt */ \
+ : \
+ : [timsk0] "i" ((uint16_t)&TIMSK0), \
+ [timsk1] "i" ((uint16_t)&TIMSK1), \
+ [msk0] "M" ((uint8_t)(1<.
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/AVR/watchdog.cpp b/Marlin/src/HAL/AVR/watchdog.cpp
index e35a70f2cc..3f10c4adff 100644
--- a/Marlin/src/HAL/AVR/watchdog.cpp
+++ b/Marlin/src/HAL/AVR/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __AVR__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/AVR/watchdog.h b/Marlin/src/HAL/AVR/watchdog.h
index 57dfcfc0bf..a16c88b35e 100644
--- a/Marlin/src/HAL/AVR/watchdog.h
+++ b/Marlin/src/HAL/AVR/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/DebugMonitor.cpp b/Marlin/src/HAL/DUE/DebugMonitor.cpp
index 3ed9873e66..79759151d8 100644
--- a/Marlin/src/HAL/DUE/DebugMonitor.cpp
+++ b/Marlin/src/HAL/DUE/DebugMonitor.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_SAM
#include "../../core/macros.h"
diff --git a/Marlin/src/HAL/DUE/HAL.cpp b/Marlin/src/HAL/DUE/HAL.cpp
index cb381ff4bb..4b9260c359 100644
--- a/Marlin/src/HAL/DUE/HAL.cpp
+++ b/Marlin/src/HAL/DUE/HAL.cpp
@@ -14,7 +14,8 @@
* 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 .
+ * along with this program. If not, see .
+ *
*/
/**
diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h
index 42f6f175fb..31409c76dd 100644
--- a/Marlin/src/HAL/DUE/HAL.h
+++ b/Marlin/src/HAL/DUE/HAL.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -30,11 +30,11 @@
#define CPU_32_BIT
#include "../shared/Marduino.h"
+#include "../shared/eeprom_if.h"
#include "../shared/math_32bit.h"
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
#include
@@ -130,14 +130,6 @@ void sei(); // Enable interrupts
void HAL_clear_reset_source(); // clear reset reason
uint8_t HAL_get_reset_source(); // get reset reason
-//
-// EEPROM
-//
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
-
//
// ADC
//
@@ -151,8 +143,9 @@ extern uint16_t HAL_adc_result; // result of last ADC conversion
inline void HAL_adc_init() {}//todo
-#define HAL_START_ADC(ch) HAL_adc_start_conversion(ch)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(ch) HAL_adc_start_conversion(ch)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
diff --git a/Marlin/src/HAL/DUE/HAL_SPI.cpp b/Marlin/src/HAL/DUE/HAL_SPI.cpp
index 97a6fa05a1..6d8f7ef819 100644
--- a/Marlin/src/HAL/DUE/HAL_SPI.cpp
+++ b/Marlin/src/HAL/DUE/HAL_SPI.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/InterruptVectors.cpp b/Marlin/src/HAL/DUE/InterruptVectors.cpp
index 7964f2d1f6..e4e0ce99f2 100644
--- a/Marlin/src/HAL/DUE/InterruptVectors.cpp
+++ b/Marlin/src/HAL/DUE/InterruptVectors.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/InterruptVectors.h b/Marlin/src/HAL/DUE/InterruptVectors.h
index 534cd17f42..6faeb34b7a 100644
--- a/Marlin/src/HAL/DUE/InterruptVectors.h
+++ b/Marlin/src/HAL/DUE/InterruptVectors.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/MarlinSerial.cpp b/Marlin/src/HAL/DUE/MarlinSerial.cpp
index d114c75989..c9a372eeb1 100644
--- a/Marlin/src/HAL/DUE/MarlinSerial.cpp
+++ b/Marlin/src/HAL/DUE/MarlinSerial.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/MarlinSerial.h b/Marlin/src/HAL/DUE/MarlinSerial.h
index fa6a2c7d15..dfafa15141 100644
--- a/Marlin/src/HAL/DUE/MarlinSerial.h
+++ b/Marlin/src/HAL/DUE/MarlinSerial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp b/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
index 7a020bbaf0..a41dbfeb7a 100644
--- a/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
+++ b/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -73,9 +73,7 @@ int MarlinSerialUSB::peek() {
pending_char = udi_cdc_getc();
- #if ENABLED(EMERGENCY_PARSER)
- emergency_parser.update(emergency_state, (char)pending_char);
- #endif
+ TERN_(EMERGENCY_PARSER, emergency_parser.update(emergency_state, (char)pending_char));
return pending_char;
}
@@ -97,9 +95,7 @@ int MarlinSerialUSB::read() {
int c = udi_cdc_getc();
- #if ENABLED(EMERGENCY_PARSER)
- emergency_parser.update(emergency_state, (char)c);
- #endif
+ TERN_(EMERGENCY_PARSER, emergency_parser.update(emergency_state, (char)c));
return c;
}
diff --git a/Marlin/src/HAL/DUE/MarlinSerialUSB.h b/Marlin/src/HAL/DUE/MarlinSerialUSB.h
index 9aece901b1..2e3622e553 100644
--- a/Marlin/src/HAL/DUE/MarlinSerialUSB.h
+++ b/Marlin/src/HAL/DUE/MarlinSerialUSB.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/Servo.cpp b/Marlin/src/HAL/DUE/Servo.cpp
index 266158bbc6..5524aa9cef 100644
--- a/Marlin/src/HAL/DUE/Servo.cpp
+++ b/Marlin/src/HAL/DUE/Servo.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -44,7 +44,6 @@
#if HAS_SERVOS
-#include "../shared/Marduino.h"
#include "../shared/servo.h"
#include "../shared/servo_private.h"
diff --git a/Marlin/src/HAL/DUE/Tone.cpp b/Marlin/src/HAL/DUE/Tone.cpp
index 9b580b8b4c..9beb602223 100644
--- a/Marlin/src/HAL/DUE/Tone.cpp
+++ b/Marlin/src/HAL/DUE/Tone.cpp
@@ -18,20 +18,19 @@
* 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 .
+ * along with this program. If not, see .
*
*/
/**
* Description: Tone function for Arduino Due and compatible (SAM3X8E)
- * Derived from http://forum.arduino.cc/index.php?topic=136500.msg2903012#msg2903012
+ * Derived from https://forum.arduino.cc/index.php?topic=136500.msg2903012#msg2903012
*/
#ifdef ARDUINO_ARCH_SAM
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "timers.h"
static pin_t tone_pin;
volatile static int32_t toggles;
diff --git a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
index 0fb8a782e5..2ef7011b1c 100644
--- a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
+++ b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
index 01320ba9b9..47060d6a5b 100644
--- a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
+++ b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
index c4816c3db5..54c244d4f6 100644
--- a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
+++ b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
index 96b7a1f61e..960df1bd86 100644
--- a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
+++ b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
index e0f15bfd81..f076c503ca 100644
--- a/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
+++ b/Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/EepromEmulation.cpp b/Marlin/src/HAL/DUE/eeprom_flash.cpp
similarity index 88%
rename from Marlin/src/HAL/DUE/EepromEmulation.cpp
rename to Marlin/src/HAL/DUE/eeprom_flash.cpp
index 66af50cfd2..d98f06039f 100644
--- a/Marlin/src/HAL/DUE/EepromEmulation.cpp
+++ b/Marlin/src/HAL/DUE/eeprom_flash.cpp
@@ -1,9 +1,10 @@
/**
* Marlin 3D Printer Firmware
- * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
- * Based on Sprinter and grbl.
- * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
*
* 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
@@ -16,9 +17,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
+#ifdef ARDUINO_ARCH_SAM
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(FLASH_EEPROM_EMULATION)
/* EEPROM emulation over flash with reduced wear
*
@@ -50,14 +56,7 @@
*
*/
-#ifdef ARDUINO_ARCH_SAM
-
-#include "../../inc/MarlinConfig.h"
-
-#if ENABLED(FLASH_EEPROM_EMULATION)
-
-#include "../shared/Marduino.h"
-#include "../shared/eeprom_api.h"
+//#define EE_EMU_DEBUG
#define EEPROMSize 4096
#define PagesPerGroup 128
@@ -134,15 +133,18 @@ static uint8_t buffer[256] = {0}, // The RAM buffer to accumulate writes
curPage = 0, // Current FLASH page inside the group
curGroup = 0xFF; // Current FLASH group
-//#define EE_EMU_DEBUG
-#ifdef EE_EMU_DEBUG
- static void ee_Dump(int page,const void* data) {
+#define DEBUG_OUT ENABLED(EE_EMU_DEBUG)
+#include "../../core/debug_out.h"
+
+static void ee_Dump(const int page, const void* data) {
+
+ #ifdef EE_EMU_DEBUG
const uint8_t* c = (const uint8_t*) data;
char buffer[80];
sprintf_P(buffer, PSTR("Page: %d (0x%04x)\n"), page, page);
- SERIAL_ECHO(buffer);
+ DEBUG_ECHO(buffer);
char* p = &buffer[0];
for (int i = 0; i< PageSize; ++i) {
@@ -152,12 +154,16 @@ static uint8_t buffer[256] = {0}, // The RAM buffer to accumulate writes
if ((i & 0xF) == 0xF) {
*p++ = '\n';
*p = 0;
- SERIAL_ECHO(buffer);
+ DEBUG_ECHO(buffer);
p = &buffer[0];
}
}
- }
-#endif
+
+ #else
+ UNUSED(page);
+ UNUSED(data);
+ #endif
+}
/* Flash Writing Protection Key */
#define FWP_KEY 0x5Au
@@ -170,17 +176,16 @@ static uint8_t buffer[256] = {0}, // The RAM buffer to accumulate writes
#define EEFC_ERROR_FLAGS (EEFC_FSR_FLOCKE | EEFC_FSR_FCMDE)
#endif
-
/**
* Writes the contents of the specified page (no previous erase)
* @param page (page #)
* @param data (pointer to the data buffer)
*/
__attribute__ ((long_call, section (".ramfunc")))
-static bool ee_PageWrite(uint16_t page,const void* data) {
+static bool ee_PageWrite(uint16_t page, const void* data) {
uint16_t i;
- uint32_t addrflash = ((uint32_t)getFlashStorage(page));
+ uint32_t addrflash = uint32_t(getFlashStorage(page));
// Read the flash contents
uint32_t pageContents[PageSize>>2];
@@ -195,13 +200,11 @@ static bool ee_PageWrite(uint16_t page,const void* data) {
for (i = 0; i > 2; i++)
pageContents[i] = (((uint32_t*)data)[i]) | (~(pageContents[i] ^ ((uint32_t*)data)[i]));
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM PageWrite ", page);
- SERIAL_ECHOLNPAIR(" in FLASH address ", (uint32_t)addrflash);
- SERIAL_ECHOLNPAIR(" base address ", (uint32_t)getFlashStorage(0));
- SERIAL_FLUSH();
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM PageWrite ", page);
+ DEBUG_ECHOLNPAIR(" in FLASH address ", (uint32_t)addrflash);
+ DEBUG_ECHOLNPAIR(" base address ", (uint32_t)getFlashStorage(0));
+ DEBUG_FLUSH();
// Get the page relative to the start of the EFC controller, and the EFC controller to use
Efc *efc;
@@ -243,10 +246,8 @@ static bool ee_PageWrite(uint16_t page,const void* data) {
// Reenable interrupts
__enable_irq();
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Unlock failure for page ", page);
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Unlock failure for page ", page);
return false;
}
@@ -270,10 +271,9 @@ static bool ee_PageWrite(uint16_t page,const void* data) {
// Reenable interrupts
__enable_irq();
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Write failure for page ", page);
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Write failure for page ", page);
+
return false;
}
@@ -287,11 +287,11 @@ static bool ee_PageWrite(uint16_t page,const void* data) {
if (memcmp(getFlashStorage(page),data,PageSize)) {
#ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Verify Write failure for page ", page);
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Verify Write failure for page ", page);
- ee_Dump( page,(uint32_t *) addrflash);
- ee_Dump(-page,data);
+ ee_Dump( page, (uint32_t *)addrflash);
+ ee_Dump(-page, data);
// Calculate count of changed bits
uint32_t* p1 = (uint32_t*)addrflash;
@@ -307,7 +307,7 @@ static bool ee_PageWrite(uint16_t page,const void* data) {
}
}
}
- SERIAL_ECHOLNPAIR("--> Differing bits: ", count);
+ DEBUG_ECHOLNPAIR("--> Differing bits: ", count);
#endif
return false;
@@ -324,15 +324,13 @@ __attribute__ ((long_call, section (".ramfunc")))
static bool ee_PageErase(uint16_t page) {
uint16_t i;
- uint32_t addrflash = ((uint32_t)getFlashStorage(page));
+ uint32_t addrflash = uint32_t(getFlashStorage(page));
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM PageErase ", page);
- SERIAL_ECHOLNPAIR(" in FLASH address ", (uint32_t)addrflash);
- SERIAL_ECHOLNPAIR(" base address ", (uint32_t)getFlashStorage(0));
- SERIAL_FLUSH();
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM PageErase ", page);
+ DEBUG_ECHOLNPAIR(" in FLASH address ", (uint32_t)addrflash);
+ DEBUG_ECHOLNPAIR(" base address ", (uint32_t)getFlashStorage(0));
+ DEBUG_FLUSH();
// Get the page relative to the start of the EFC controller, and the EFC controller to use
Efc *efc;
@@ -373,10 +371,9 @@ static bool ee_PageErase(uint16_t page) {
// Reenable interrupts
__enable_irq();
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Unlock failure for page ",page);
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Unlock failure for page ",page);
+
return false;
}
@@ -398,10 +395,9 @@ static bool ee_PageErase(uint16_t page) {
// Reenable interrupts
__enable_irq();
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Erase failure for page ",page);
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Erase failure for page ",page);
+
return false;
}
@@ -415,20 +411,17 @@ static bool ee_PageErase(uint16_t page) {
uint32_t * aligned_src = (uint32_t *) addrflash;
for (i = 0; i < PageSize >> 2; i++) {
if (*aligned_src++ != 0xFFFFFFFF) {
-
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Verify Erase failure for page ",page);
-
- ee_Dump( page,(uint32_t *) addrflash);
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Verify Erase failure for page ",page);
+ ee_Dump(page, (uint32_t *)addrflash);
return false;
}
}
return true;
}
-static uint8_t ee_Read(uint32_t address, bool excludeRAMBuffer = false) {
+
+static uint8_t ee_Read(uint32_t address, bool excludeRAMBuffer=false) {
uint32_t baddr;
uint32_t blen;
@@ -511,7 +504,7 @@ static uint8_t ee_Read(uint32_t address, bool excludeRAMBuffer = false) {
return 0xFF;
}
-static uint32_t ee_GetAddrRange(uint32_t address, bool excludeRAMBuffer = false) {
+static uint32_t ee_GetAddrRange(uint32_t address, bool excludeRAMBuffer=false) {
uint32_t baddr,
blen,
nextAddr = 0xFFFF,
@@ -603,7 +596,7 @@ static bool ee_IsPageClean(int page) {
return true;
}
-static bool ee_Flush(uint32_t overrideAddress = 0xFFFFFFFF, uint8_t overrideData = 0xFF) {
+static bool ee_Flush(uint32_t overrideAddress = 0xFFFFFFFF, uint8_t overrideData=0xFF) {
// Check if RAM buffer has something to be written
bool isEmpty = true;
@@ -929,11 +922,9 @@ static void ee_Init() {
// If all groups seem to be used, default to first group
if (curGroup >= GroupCount) curGroup = 0;
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Current Group: ",curGroup);
- SERIAL_FLUSH();
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Current Group: ",curGroup);
+ DEBUG_FLUSH();
// Now, validate that all the other group pages are empty
for (int grp = 0; grp < GroupCount; grp++) {
@@ -941,11 +932,9 @@ static void ee_Init() {
for (int page = 0; page < PagesPerGroup; page++) {
if (!ee_IsPageClean(grp * PagesPerGroup + page)) {
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Page ", page, " not clean on group ", grp);
- SERIAL_FLUSH();
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Page ", page, " not clean on group ", grp);
+ DEBUG_FLUSH();
ee_PageErase(grp * PagesPerGroup + page);
}
}
@@ -955,66 +944,69 @@ static void ee_Init() {
// and also validate that all the other ones are clean
for (curPage = 0; curPage < PagesPerGroup; curPage++) {
if (ee_IsPageClean(curGroup * PagesPerGroup + curPage)) {
- #ifdef EE_EMU_DEBUG
- ee_Dump(curGroup * PagesPerGroup + curPage, getFlashStorage(curGroup * PagesPerGroup + curPage));
- #endif
+ ee_Dump(curGroup * PagesPerGroup + curPage, getFlashStorage(curGroup * PagesPerGroup + curPage));
break;
}
}
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Active page: ", curPage);
- SERIAL_FLUSH();
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Active page: ", curPage);
+ DEBUG_FLUSH();
// Make sure the pages following the first clean one are also clean
for (int page = curPage + 1; page < PagesPerGroup; page++) {
if (!ee_IsPageClean(curGroup * PagesPerGroup + page)) {
- #ifdef EE_EMU_DEBUG
- SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR("EEPROM Page ", page, " not clean on active group ", curGroup);
- SERIAL_FLUSH();
- ee_Dump(curGroup * PagesPerGroup + page, getFlashStorage(curGroup * PagesPerGroup + page));
- #endif
+ DEBUG_ECHO_START();
+ DEBUG_ECHOLNPAIR("EEPROM Page ", page, " not clean on active group ", curGroup);
+ DEBUG_FLUSH();
+ ee_Dump(curGroup * PagesPerGroup + page, getFlashStorage(curGroup * PagesPerGroup + page));
ee_PageErase(curGroup * PagesPerGroup + page);
}
}
}
-uint8_t eeprom_read_byte(uint8_t* addr) {
- ee_Init();
- return ee_Read((uint32_t)addr);
-}
+/* PersistentStore -----------------------------------------------------------*/
-void eeprom_write_byte(uint8_t* addr, uint8_t value) {
- ee_Init();
- ee_Write((uint32_t)addr, value);
-}
+#include "../shared/eeprom_api.h"
-void eeprom_update_block(const void* __src, void* __dst, size_t __n) {
- uint8_t* dst = (uint8_t*)__dst;
- const uint8_t* src = (const uint8_t*)__src;
- while (__n--) {
- eeprom_write_byte(dst, *src);
- ++dst;
- ++src;
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+bool PersistentStore::access_start() { ee_Init(); return true; }
+bool PersistentStore::access_finish() { ee_Flush(); return true; }
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ while (size--) {
+ uint8_t * const p = (uint8_t * const)pos;
+ uint8_t v = *value;
+ // EEPROM has only ~100,000 write cycles,
+ // so only write bytes that have changed!
+ if (v != ee_Read(uint32_t(p))) {
+ ee_Write(uint32_t(p), v);
+ delay(2);
+ if (ee_Read(uint32_t(p)) != v) {
+ SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
+ return true;
+ }
+ }
+ crc16(crc, &v, 1);
+ pos++;
+ value++;
}
+ return false;
}
-void eeprom_read_block(void* __dst, const void* __src, size_t __n) {
- uint8_t* dst = (uint8_t*)__dst;
- uint8_t* src = (uint8_t*)__src;
- while (__n--) {
- *dst = eeprom_read_byte(src);
- ++dst;
- ++src;
- }
-}
-
-void eeprom_flush() {
- ee_Flush();
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
+ do {
+ uint8_t c = ee_Read(uint32_t(pos));
+ if (writing) *value = c;
+ crc16(crc, &c, 1);
+ pos++;
+ value++;
+ } while (--size);
+ return false;
}
#endif // FLASH_EEPROM_EMULATION
-#endif // ARDUINO_ARCH_AVR
+#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/eeprom.cpp b/Marlin/src/HAL/DUE/eeprom_wired.cpp
similarity index 76%
rename from Marlin/src/HAL/DUE/eeprom.cpp
rename to Marlin/src/HAL/DUE/eeprom_wired.cpp
index ec9ef51ffc..4599d6a7cd 100644
--- a/Marlin/src/HAL/DUE/eeprom.cpp
+++ b/Marlin/src/HAL/DUE/eeprom_wired.cpp
@@ -17,32 +17,29 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef ARDUINO_ARCH_SAM
-#include "../../inc/MarlinConfigPre.h"
-
-#if ENABLED(EEPROM_SETTINGS)
-
#include "../../inc/MarlinConfig.h"
+
+#if USE_WIRED_EEPROM
+
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with simple implementations supplied by Marlin.
+ */
+
+#include "../shared/eeprom_if.h"
#include "../shared/eeprom_api.h"
-#if !defined(E2END) && ENABLED(FLASH_EEPROM_EMULATION)
- #define E2END 0xFFF // Default to Flash emulated EEPROM size (EepromEmulation_Due.cpp)
+#ifndef MARLIN_EEPROM_SIZE
+ #error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
#endif
-
-extern void eeprom_flush();
-
-bool PersistentStore::access_start() { return true; }
-
-bool PersistentStore::access_finish() {
- #if ENABLED(FLASH_EEPROM_EMULATION)
- eeprom_flush();
- #endif
- return true;
-}
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+bool PersistentStore::access_start() { eeprom_init(); return true; }
+bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
@@ -61,7 +58,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
crc16(crc, &v, 1);
pos++;
value++;
- };
+ }
return false;
}
@@ -76,7 +73,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() { return E2END + 1; }
-
-#endif // EEPROM_SETTINGS
+#endif // USE_WIRED_EEPROM
#endif // ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/endstop_interrupts.h b/Marlin/src/HAL/DUE/endstop_interrupts.h
index f81d9055d5..999ada5127 100644
--- a/Marlin/src/HAL/DUE/endstop_interrupts.h
+++ b/Marlin/src/HAL/DUE/endstop_interrupts.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -47,43 +47,21 @@ void endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
#define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
- #if HAS_X_MAX
- _ATTACH(X_MAX_PIN);
- #endif
- #if HAS_X_MIN
- _ATTACH(X_MIN_PIN);
- #endif
- #if HAS_Y_MAX
- _ATTACH(Y_MAX_PIN);
- #endif
- #if HAS_Y_MIN
- _ATTACH(Y_MIN_PIN);
- #endif
- #if HAS_Z_MAX
- _ATTACH(Z_MAX_PIN);
- #endif
- #if HAS_Z_MIN
- _ATTACH(Z_MIN_PIN);
- #endif
- #if HAS_Z2_MAX
- _ATTACH(Z2_MAX_PIN);
- #endif
- #if HAS_Z2_MIN
- _ATTACH(Z2_MIN_PIN);
- #endif
- #if HAS_Z3_MAX
- _ATTACH(Z3_MAX_PIN);
- #endif
- #if HAS_Z3_MIN
- _ATTACH(Z3_MIN_PIN);
- #endif
- #if HAS_Z4_MAX
- _ATTACH(Z4_MAX_PIN);
- #endif
- #if HAS_Z4_MIN
- _ATTACH(Z4_MIN_PIN);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- _ATTACH(Z_MIN_PROBE_PIN);
- #endif
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/DUE/fastio.h b/Marlin/src/HAL/DUE/fastio.h
index 01abd82049..286319302d 100644
--- a/Marlin/src/HAL/DUE/fastio.h
+++ b/Marlin/src/HAL/DUE/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -58,7 +58,7 @@
*
* Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
*
- * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
+ * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/cpp/Stringification.html
*/
// Read a pin
@@ -174,7 +174,7 @@
#define IS_OUTPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) != 0)
// Shorthand
-#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
+#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
diff --git a/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp b/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
index 672932f56c..1682faea66 100644
--- a/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
+++ b/Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/fastio/G2_PWM.h b/Marlin/src/HAL/DUE/fastio/G2_PWM.h
index a94c1c5276..dc4edffff8 100644
--- a/Marlin/src/HAL/DUE/fastio/G2_PWM.h
+++ b/Marlin/src/HAL/DUE/fastio/G2_PWM.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/fastio/G2_pins.h b/Marlin/src/HAL/DUE/fastio/G2_pins.h
index 44b9cb35ee..80c87bd392 100644
--- a/Marlin/src/HAL/DUE/fastio/G2_pins.h
+++ b/Marlin/src/HAL/DUE/fastio/G2_pins.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/inc/Conditionals_LCD.h b/Marlin/src/HAL/DUE/inc/Conditionals_LCD.h
index 0285c52ee3..5867414447 100644
--- a/Marlin/src/HAL/DUE/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/DUE/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/DUE."
+#endif
diff --git a/Marlin/src/HAL/DUE/inc/Conditionals_adv.h b/Marlin/src/HAL/DUE/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/DUE/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/DUE/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/inc/Conditionals_post.h b/Marlin/src/HAL/DUE/inc/Conditionals_post.h
index 8a305009ce..ce6d3fdde2 100644
--- a/Marlin/src/HAL/DUE/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/DUE/inc/Conditionals_post.h
@@ -16,13 +16,13 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
#if USE_FALLBACK_EEPROM
- #undef SRAM_EEPROM_EMULATION
- #undef SDCARD_EEPROM_EMULATION
#define FLASH_EEPROM_EMULATION
+#elif EITHER(I2C_EEPROM, SPI_EEPROM)
+ #define USE_SHARED_EEPROM 1
#endif
diff --git a/Marlin/src/HAL/DUE/inc/SanityCheck.h b/Marlin/src/HAL/DUE/inc/SanityCheck.h
index 0f7be7955f..6880696506 100644
--- a/Marlin/src/HAL/DUE/inc/SanityCheck.h
+++ b/Marlin/src/HAL/DUE/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -52,8 +52,8 @@
#endif
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on DUE."
#endif
#if HAS_TMC_SW_SERIAL
diff --git a/Marlin/src/HAL/DUE/pinsDebug.h b/Marlin/src/HAL/DUE/pinsDebug.h
index 448c2391d3..28687ff267 100644
--- a/Marlin/src/HAL/DUE/pinsDebug.h
+++ b/Marlin/src/HAL/DUE/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/DUE/spi_pins.h b/Marlin/src/HAL/DUE/spi_pins.h
index a205540bcd..e28eaf8270 100644
--- a/Marlin/src/HAL/DUE/spi_pins.h
+++ b/Marlin/src/HAL/DUE/spi_pins.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/DUE/timers.cpp b/Marlin/src/HAL/DUE/timers.cpp
index 74ae882843..795cdad66a 100644
--- a/Marlin/src/HAL/DUE/timers.cpp
+++ b/Marlin/src/HAL/DUE/timers.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -34,8 +34,6 @@
#include "../../inc/MarlinConfig.h"
#include "HAL.h"
-#include "timers.h"
-
// ------------------------
// Local defines
// ------------------------
diff --git a/Marlin/src/HAL/DUE/timers.h b/Marlin/src/HAL/DUE/timers.h
index 5144660116..9defe39a0a 100644
--- a/Marlin/src/HAL/DUE/timers.h
+++ b/Marlin/src/HAL/DUE/timers.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -40,11 +40,17 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
#ifndef STEP_TIMER_NUM
-#define STEP_TIMER_NUM 2 // index of timer to use for stepper
+ #define STEP_TIMER_NUM 2 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 4 // Timer Index for Temperature
+#endif
+#ifndef TONE_TIMER_NUM
+ #define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
#endif
-#define TEMP_TIMER_NUM 4 // index of timer to use for temperature
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
-#define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -66,8 +72,12 @@ typedef uint32_t hal_timer_t;
#ifndef HAL_STEP_TIMER_ISR
#define HAL_STEP_TIMER_ISR() void TC2_Handler()
#endif
-#define HAL_TEMP_TIMER_ISR() void TC4_Handler()
-#define HAL_TONE_TIMER_ISR() void TC6_Handler()
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() void TC4_Handler()
+#endif
+#ifndef HAL_TONE_TIMER_ISR
+ #define HAL_TONE_TIMER_ISR() void TC6_Handler()
+#endif
// ------------------------
// Types
diff --git a/Marlin/src/HAL/DUE/upload_extra_script.py b/Marlin/src/HAL/DUE/upload_extra_script.py
new file mode 100644
index 0000000000..06c2b914f5
--- /dev/null
+++ b/Marlin/src/HAL/DUE/upload_extra_script.py
@@ -0,0 +1,18 @@
+#
+# Set upload_command
+#
+# Windows: bossac.exe
+# Other: leave unchanged
+#
+
+import platform
+current_OS = platform.system()
+
+if current_OS == 'Windows':
+
+ Import("env")
+
+ # Use bossac.exe on Windows
+ env.Replace(
+ UPLOADCMD="bossac --info --unlock --write --verify --reset --erase -U false --boot"
+ )
diff --git a/Marlin/src/HAL/DUE/usb/arduino_due_x.h b/Marlin/src/HAL/DUE/usb/arduino_due_x.h
index 7355f74f6d..d3b333fb34 100644
--- a/Marlin/src/HAL/DUE/usb/arduino_due_x.h
+++ b/Marlin/src/HAL/DUE/usb/arduino_due_x.h
@@ -43,7 +43,7 @@
#pragma once
/**
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
/**
@@ -93,5 +93,5 @@
#define USB_VBOF_GPIO (PIO_PB10_IDX)
#define USB_VBOF_FLAGS (PIO_PERIPH_A | PIO_DEFAULT)
/*! Active level of the USB_VBOF output pin. */
-#define USB_VBOF_ACTIVE_LEVEL LOW
+#define USB_VBOF_ACTIVE_STATE LOW
/* ------------------------------------------------------------------------ */
diff --git a/Marlin/src/HAL/DUE/usb/compiler.h b/Marlin/src/HAL/DUE/usb/compiler.h
index 33df080e2f..7b746543c4 100644
--- a/Marlin/src/HAL/DUE/usb/compiler.h
+++ b/Marlin/src/HAL/DUE/usb/compiler.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef UTILS_COMPILER_H
diff --git a/Marlin/src/HAL/DUE/usb/conf_access.h b/Marlin/src/HAL/DUE/usb/conf_access.h
index fdac1ab7e8..f401685223 100644
--- a/Marlin/src/HAL/DUE/usb/conf_access.h
+++ b/Marlin/src/HAL/DUE/usb/conf_access.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _CONF_ACCESS_H_
diff --git a/Marlin/src/HAL/DUE/usb/conf_clock.h b/Marlin/src/HAL/DUE/usb/conf_clock.h
index d0f68500ad..97e70e99a5 100644
--- a/Marlin/src/HAL/DUE/usb/conf_clock.h
+++ b/Marlin/src/HAL/DUE/usb/conf_clock.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef CONF_CLOCK_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/conf_usb.h b/Marlin/src/HAL/DUE/usb/conf_usb.h
index 8d5924d375..4de9e347e2 100644
--- a/Marlin/src/HAL/DUE/usb/conf_usb.h
+++ b/Marlin/src/HAL/DUE/usb/conf_usb.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _CONF_USB_H_
@@ -78,10 +78,6 @@
//! To define a Full speed device
//#define USB_DEVICE_FULL_SPEED
-#if MB(ARCHIM1)
- #define USB_DEVICE_FULL_SPEED
-#endif
-
//! To authorize the High speed
#ifndef USB_DEVICE_FULL_SPEED
#if (UC3A3||UC3A4)
diff --git a/Marlin/src/HAL/DUE/usb/ctrl_access.c b/Marlin/src/HAL/DUE/usb/ctrl_access.c
index 0ec14e0b8f..99f97f62cb 100644
--- a/Marlin/src/HAL/DUE/usb/ctrl_access.c
+++ b/Marlin/src/HAL/DUE/usb/ctrl_access.c
@@ -53,7 +53,7 @@
*
******************************************************************************/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/ctrl_access.h b/Marlin/src/HAL/DUE/usb/ctrl_access.h
index af6c8ceb96..b33839076e 100644
--- a/Marlin/src/HAL/DUE/usb/ctrl_access.h
+++ b/Marlin/src/HAL/DUE/usb/ctrl_access.h
@@ -53,7 +53,7 @@
*
******************************************************************************/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
diff --git a/Marlin/src/HAL/DUE/usb/genclk.h b/Marlin/src/HAL/DUE/usb/genclk.h
index 895aba0352..cde03bc0d1 100644
--- a/Marlin/src/HAL/DUE/usb/genclk.h
+++ b/Marlin/src/HAL/DUE/usb/genclk.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef CHIP_GENCLK_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/mrepeat.h b/Marlin/src/HAL/DUE/usb/mrepeat.h
index 5a2017be99..8363d9cde3 100644
--- a/Marlin/src/HAL/DUE/usb/mrepeat.h
+++ b/Marlin/src/HAL/DUE/usb/mrepeat.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _MREPEAT_H_
diff --git a/Marlin/src/HAL/DUE/usb/osc.h b/Marlin/src/HAL/DUE/usb/osc.h
index 3a9543507b..953bcbbed1 100644
--- a/Marlin/src/HAL/DUE/usb/osc.h
+++ b/Marlin/src/HAL/DUE/usb/osc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef CHIP_OSC_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/pll.h b/Marlin/src/HAL/DUE/usb/pll.h
index d3d2174870..8eaf27672b 100644
--- a/Marlin/src/HAL/DUE/usb/pll.h
+++ b/Marlin/src/HAL/DUE/usb/pll.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef CHIP_PLL_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/preprocessor.h b/Marlin/src/HAL/DUE/usb/preprocessor.h
index 184c03ae71..c12d01cb64 100644
--- a/Marlin/src/HAL/DUE/usb/preprocessor.h
+++ b/Marlin/src/HAL/DUE/usb/preprocessor.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _PREPROCESSOR_H_
diff --git a/Marlin/src/HAL/DUE/usb/sbc_protocol.h b/Marlin/src/HAL/DUE/usb/sbc_protocol.h
index 082b735fa6..ab845739fd 100644
--- a/Marlin/src/HAL/DUE/usb/sbc_protocol.h
+++ b/Marlin/src/HAL/DUE/usb/sbc_protocol.h
@@ -52,7 +52,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _SBC_PROTOCOL_H_
#define _SBC_PROTOCOL_H_
diff --git a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.h b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.h
index 6df82c146b..d77e4f9523 100644
--- a/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.h
+++ b/Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.h
@@ -42,7 +42,7 @@
*
******************************************************************************/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
diff --git a/Marlin/src/HAL/DUE/usb/spc_protocol.h b/Marlin/src/HAL/DUE/usb/spc_protocol.h
index 6fadb9f36c..d67cc5c788 100644
--- a/Marlin/src/HAL/DUE/usb/spc_protocol.h
+++ b/Marlin/src/HAL/DUE/usb/spc_protocol.h
@@ -45,7 +45,7 @@
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _SPC_PROTOCOL_H_
#define _SPC_PROTOCOL_H_
diff --git a/Marlin/src/HAL/DUE/usb/stringz.h b/Marlin/src/HAL/DUE/usb/stringz.h
index b914b73489..fc9aaf38a4 100644
--- a/Marlin/src/HAL/DUE/usb/stringz.h
+++ b/Marlin/src/HAL/DUE/usb/stringz.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _STRINGZ_H_
diff --git a/Marlin/src/HAL/DUE/usb/sysclk.c b/Marlin/src/HAL/DUE/usb/sysclk.c
index 899244dd88..cbb4e2c9ef 100644
--- a/Marlin/src/HAL/DUE/usb/sysclk.c
+++ b/Marlin/src/HAL/DUE/usb/sysclk.c
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/sysclk.h b/Marlin/src/HAL/DUE/usb/sysclk.h
index 48c99de298..16db8c86d3 100644
--- a/Marlin/src/HAL/DUE/usb/sysclk.h
+++ b/Marlin/src/HAL/DUE/usb/sysclk.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef CHIP_SYSCLK_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/tpaste.h b/Marlin/src/HAL/DUE/usb/tpaste.h
index f8ec44a41d..2ad3f2758e 100644
--- a/Marlin/src/HAL/DUE/usb/tpaste.h
+++ b/Marlin/src/HAL/DUE/usb/tpaste.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _TPASTE_H_
diff --git a/Marlin/src/HAL/DUE/usb/udc.c b/Marlin/src/HAL/DUE/usb/udc.c
index 048a902d3b..60bf0cfff3 100644
--- a/Marlin/src/HAL/DUE/usb/udc.c
+++ b/Marlin/src/HAL/DUE/usb/udc.c
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/udc.h b/Marlin/src/HAL/DUE/usb/udc.h
index 885bdf04d6..8d92eb5c03 100644
--- a/Marlin/src/HAL/DUE/usb/udc.h
+++ b/Marlin/src/HAL/DUE/usb/udc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDC_H_
diff --git a/Marlin/src/HAL/DUE/usb/udc_desc.h b/Marlin/src/HAL/DUE/usb/udc_desc.h
index 88ed08a961..052ca08eca 100644
--- a/Marlin/src/HAL/DUE/usb/udc_desc.h
+++ b/Marlin/src/HAL/DUE/usb/udc_desc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDC_DESC_H_
diff --git a/Marlin/src/HAL/DUE/usb/udd.h b/Marlin/src/HAL/DUE/usb/udd.h
index c87763de23..7ec8c03dee 100644
--- a/Marlin/src/HAL/DUE/usb/udd.h
+++ b/Marlin/src/HAL/DUE/usb/udd.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDD_H_
diff --git a/Marlin/src/HAL/DUE/usb/udi.h b/Marlin/src/HAL/DUE/usb/udi.h
index 709908cad9..febf03b718 100644
--- a/Marlin/src/HAL/DUE/usb/udi.h
+++ b/Marlin/src/HAL/DUE/usb/udi.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDI_H_
diff --git a/Marlin/src/HAL/DUE/usb/udi_cdc.c b/Marlin/src/HAL/DUE/usb/udi_cdc.c
index 60c9546ce2..cbe23dbb68 100644
--- a/Marlin/src/HAL/DUE/usb/udi_cdc.c
+++ b/Marlin/src/HAL/DUE/usb/udi_cdc.c
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/udi_cdc.h b/Marlin/src/HAL/DUE/usb/udi_cdc.h
index 526419c860..0ecf7bb00e 100644
--- a/Marlin/src/HAL/DUE/usb/udi_cdc.h
+++ b/Marlin/src/HAL/DUE/usb/udi_cdc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDI_CDC_H_
@@ -701,7 +701,7 @@ iram_size_t udi_cdc_multi_write_buf(uint8_t port, const void* buf, iram_size_t s
* another "Composite Device" module, like "USB HID Mouse (Composite Device)".
*
* Also, you can refer to application note
- *
+ *
* AVR4902 ASF - USB Composite Device.
*
* \section udi_cdc_use_case_composite_setup Setup steps
diff --git a/Marlin/src/HAL/DUE/usb/udi_cdc_conf.h b/Marlin/src/HAL/DUE/usb/udi_cdc_conf.h
index cbd3eb00ae..d406a87743 100644
--- a/Marlin/src/HAL/DUE/usb/udi_cdc_conf.h
+++ b/Marlin/src/HAL/DUE/usb/udi_cdc_conf.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDI_CDC_CONF_H_
diff --git a/Marlin/src/HAL/DUE/usb/udi_cdc_desc.c b/Marlin/src/HAL/DUE/usb/udi_cdc_desc.c
index 8f730ba823..97c334e2a8 100644
--- a/Marlin/src/HAL/DUE/usb/udi_cdc_desc.c
+++ b/Marlin/src/HAL/DUE/usb/udi_cdc_desc.c
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/udi_composite_desc.c b/Marlin/src/HAL/DUE/usb/udi_composite_desc.c
index 07bdd1b9d6..da74fbe60d 100644
--- a/Marlin/src/HAL/DUE/usb/udi_composite_desc.c
+++ b/Marlin/src/HAL/DUE/usb/udi_composite_desc.c
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/udi_msc.c b/Marlin/src/HAL/DUE/usb/udi_msc.c
index 627bca0d4f..b7c3bb5ea0 100644
--- a/Marlin/src/HAL/DUE/usb/udi_msc.c
+++ b/Marlin/src/HAL/DUE/usb/udi_msc.c
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/udi_msc.h b/Marlin/src/HAL/DUE/usb/udi_msc.h
index c632ee4aac..730dbc8eec 100644
--- a/Marlin/src/HAL/DUE/usb/udi_msc.h
+++ b/Marlin/src/HAL/DUE/usb/udi_msc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _UDI_MSC_H_
@@ -290,7 +290,7 @@ bool udi_msc_trans_block(bool b_read, uint8_t * block, iram_size_t block_size,
* another "Composite Device" module, like "USB HID Mouse (Composite Device)".
*
* Also, you can refer to application note
- *
+ *
* AVR4902 ASF - USB Composite Device.
*
* \section udi_msc_use_case_composite_setup Setup steps
diff --git a/Marlin/src/HAL/DUE/usb/uotghs_device_due.c b/Marlin/src/HAL/DUE/usb/uotghs_device_due.c
index 2a10190c7e..e13232a39c 100644
--- a/Marlin/src/HAL/DUE/usb/uotghs_device_due.c
+++ b/Marlin/src/HAL/DUE/usb/uotghs_device_due.c
@@ -42,7 +42,7 @@
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/uotghs_device_due.h b/Marlin/src/HAL/DUE/usb/uotghs_device_due.h
index 97877994bf..6df26d63df 100644
--- a/Marlin/src/HAL/DUE/usb/uotghs_device_due.h
+++ b/Marlin/src/HAL/DUE/usb/uotghs_device_due.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef UOTGHS_DEVICE_DUE_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/uotghs_otg.h b/Marlin/src/HAL/DUE/usb/uotghs_otg.h
index 86c903b2c1..eca5e938bb 100644
--- a/Marlin/src/HAL/DUE/usb/uotghs_otg.h
+++ b/Marlin/src/HAL/DUE/usb/uotghs_otg.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef UOTGHS_OTG_H_INCLUDED
diff --git a/Marlin/src/HAL/DUE/usb/usb_protocol.h b/Marlin/src/HAL/DUE/usb/usb_protocol.h
index 31c783f974..ea51a86896 100644
--- a/Marlin/src/HAL/DUE/usb/usb_protocol.h
+++ b/Marlin/src/HAL/DUE/usb/usb_protocol.h
@@ -44,7 +44,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _USB_PROTOCOL_H_
diff --git a/Marlin/src/HAL/DUE/usb/usb_protocol_cdc.h b/Marlin/src/HAL/DUE/usb/usb_protocol_cdc.h
index 49fc7387ef..d594db52e3 100644
--- a/Marlin/src/HAL/DUE/usb/usb_protocol_cdc.h
+++ b/Marlin/src/HAL/DUE/usb/usb_protocol_cdc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _USB_PROTOCOL_CDC_H_
#define _USB_PROTOCOL_CDC_H_
diff --git a/Marlin/src/HAL/DUE/usb/usb_protocol_msc.h b/Marlin/src/HAL/DUE/usb/usb_protocol_msc.h
index db8f9cafd0..0fef308046 100644
--- a/Marlin/src/HAL/DUE/usb/usb_protocol_msc.h
+++ b/Marlin/src/HAL/DUE/usb/usb_protocol_msc.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _USB_PROTOCOL_MSC_H_
diff --git a/Marlin/src/HAL/DUE/usb/usb_task.c b/Marlin/src/HAL/DUE/usb/usb_task.c
index 29d02faef7..66bdb265d8 100644
--- a/Marlin/src/HAL/DUE/usb/usb_task.c
+++ b/Marlin/src/HAL/DUE/usb/usb_task.c
@@ -41,7 +41,7 @@
*
*/
-// Support and FAQ: visit Atmel Support
+// Support and FAQ: visit Atmel Support
#ifdef ARDUINO_ARCH_SAM
diff --git a/Marlin/src/HAL/DUE/usb/usb_task.h b/Marlin/src/HAL/DUE/usb/usb_task.h
index fad62fda50..e9831ae062 100644
--- a/Marlin/src/HAL/DUE/usb/usb_task.h
+++ b/Marlin/src/HAL/DUE/usb/usb_task.h
@@ -41,7 +41,7 @@
*
*/
/*
- * Support and FAQ: visit Atmel Support
+ * Support and FAQ: visit Atmel Support
*/
#ifndef _USB_TASK_H_
diff --git a/Marlin/src/HAL/DUE/watchdog.cpp b/Marlin/src/HAL/DUE/watchdog.cpp
index c245633d76..0f46971830 100644
--- a/Marlin/src/HAL/DUE/watchdog.cpp
+++ b/Marlin/src/HAL/DUE/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_SAM
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/DUE/watchdog.h b/Marlin/src/HAL/DUE/watchdog.h
index 7d9665f20e..5725a10007 100644
--- a/Marlin/src/HAL/DUE/watchdog.h
+++ b/Marlin/src/HAL/DUE/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/FlushableHardwareSerial.cpp b/Marlin/src/HAL/ESP32/FlushableHardwareSerial.cpp
index 4d70d34edb..d4b2f42c53 100644
--- a/Marlin/src/HAL/ESP32/FlushableHardwareSerial.cpp
+++ b/Marlin/src/HAL/ESP32/FlushableHardwareSerial.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/ESP32/FlushableHardwareSerial.h b/Marlin/src/HAL/ESP32/FlushableHardwareSerial.h
index 703bcbeb73..b43caea13c 100644
--- a/Marlin/src/HAL/ESP32/FlushableHardwareSerial.h
+++ b/Marlin/src/HAL/ESP32/FlushableHardwareSerial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/HAL.cpp b/Marlin/src/HAL/ESP32/HAL.cpp
index d9afa13ab8..1e00df5177 100644
--- a/Marlin/src/HAL/ESP32/HAL.cpp
+++ b/Marlin/src/HAL/ESP32/HAL.cpp
@@ -16,21 +16,18 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
-#include "HAL.h"
-#include "timers.h"
+#include "../../inc/MarlinConfig.h"
+
#include
#include
#include
#include
-#include "../../inc/MarlinConfigPre.h"
-
#if ENABLED(WIFISUPPORT)
#include
#include "wifi.h"
@@ -97,9 +94,7 @@ void HAL_init_board() {
esp3dlib.init();
#elif ENABLED(WIFISUPPORT)
wifi_init();
- #if ENABLED(OTASUPPORT)
- OTA_init();
- #endif
+ TERN_(OTASUPPORT, OTA_init());
#if ENABLED(WEBSUPPORT)
spiffs_init();
web_init();
@@ -133,9 +128,7 @@ void HAL_idletask() {
#if BOTH(WIFISUPPORT, OTASUPPORT)
OTA_handle();
#endif
- #if ENABLED(ESP3D_WIFISUPPORT)
- esp3dlib.idletask();
- #endif
+ TERN_(ESP3D_WIFISUPPORT, esp3dlib.idletask());
}
void HAL_clear_reset_source() { }
@@ -176,39 +169,17 @@ void HAL_adc_init() {
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_set_attenuation(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_1
- adc1_set_attenuation(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_2
- adc1_set_attenuation(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_3
- adc1_set_attenuation(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_4
- adc1_set_attenuation(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_5
- adc1_set_attenuation(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_6
- adc2_set_attenuation(get_channel(TEMP_6_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_ADC_7
- adc3_set_attenuation(get_channel(TEMP_7_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_HEATED_BED
- adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
- #endif
- #if HAS_TEMP_CHAMBER
- adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
- #endif
- #if ENABLED(FILAMENT_WIDTH_SENSOR)
- adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
- #endif
+ TERN_(HAS_TEMP_ADC_0, adc1_set_attenuation(get_channel(TEMP_0_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_1, adc1_set_attenuation(get_channel(TEMP_1_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_2, adc1_set_attenuation(get_channel(TEMP_2_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_3, adc1_set_attenuation(get_channel(TEMP_3_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_4, adc1_set_attenuation(get_channel(TEMP_4_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_5, adc1_set_attenuation(get_channel(TEMP_5_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_6, adc2_set_attenuation(get_channel(TEMP_6_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_ADC_7, adc3_set_attenuation(get_channel(TEMP_7_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_HEATED_BED, adc1_set_attenuation(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db));
+ TERN_(HAS_TEMP_CHAMBER, adc1_set_attenuation(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db));
+ TERN_(FILAMENT_WIDTH_SENSOR, adc1_set_attenuation(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db));
// 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.
diff --git a/Marlin/src/HAL/ESP32/HAL.h b/Marlin/src/HAL/ESP32/HAL.h
index a04343b69e..c91f9efff0 100644
--- a/Marlin/src/HAL/ESP32/HAL.h
+++ b/Marlin/src/HAL/ESP32/HAL.h
@@ -14,7 +14,7 @@
* 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 .
+ * along with this program. If not, see .
*/
#pragma once
@@ -34,8 +34,6 @@
#include "watchdog.h"
#include "i2s.h"
-#include "timers.h"
-
#if ENABLED(WIFISUPPORT)
#include "WebSocketSerial.h"
#endif
@@ -109,19 +107,14 @@ int freeMemory();
void analogWrite(pin_t pin, int value);
-// EEPROM
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
-
// ADC
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_init();
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
diff --git a/Marlin/src/HAL/ESP32/HAL_SPI.cpp b/Marlin/src/HAL/ESP32/HAL_SPI.cpp
index 981d9b49c1..8e5875fc38 100644
--- a/Marlin/src/HAL/ESP32/HAL_SPI.cpp
+++ b/Marlin/src/HAL/ESP32/HAL_SPI.cpp
@@ -17,19 +17,17 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
-#include "HAL.h"
-#include "../shared/HAL_SPI.h"
-#include
-#include "spi_pins.h"
-#include
+#include "../../inc/MarlinConfig.h"
-#include "../../core/macros.h"
+#include "../shared/HAL_SPI.h"
+
+#include
+#include
// ------------------------
// Public Variables
diff --git a/Marlin/src/HAL/ESP32/Servo.cpp b/Marlin/src/HAL/ESP32/Servo.cpp
index 68ee3d9098..fcf5848581 100644
--- a/Marlin/src/HAL/ESP32/Servo.cpp
+++ b/Marlin/src/HAL/ESP32/Servo.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef ARDUINO_ARCH_ESP32
@@ -61,9 +61,7 @@ void Servo::move(const int value) {
if (attach(0) >= 0) {
write(value);
safe_delay(servo_delay[channel]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
#endif // HAS_SERVOS
diff --git a/Marlin/src/HAL/ESP32/Servo.h b/Marlin/src/HAL/ESP32/Servo.h
index 3f575150eb..b0d9294527 100644
--- a/Marlin/src/HAL/ESP32/Servo.h
+++ b/Marlin/src/HAL/ESP32/Servo.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/WebSocketSerial.cpp b/Marlin/src/HAL/ESP32/WebSocketSerial.cpp
index c7ee6951e1..533f873e4f 100644
--- a/Marlin/src/HAL/ESP32/WebSocketSerial.cpp
+++ b/Marlin/src/HAL/ESP32/WebSocketSerial.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/ESP32/WebSocketSerial.h b/Marlin/src/HAL/ESP32/WebSocketSerial.h
index e76a2bc68e..7a25c6dc5e 100644
--- a/Marlin/src/HAL/ESP32/WebSocketSerial.h
+++ b/Marlin/src/HAL/ESP32/WebSocketSerial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/eeprom_impl.cpp b/Marlin/src/HAL/ESP32/eeprom.cpp
similarity index 77%
rename from Marlin/src/HAL/ESP32/eeprom_impl.cpp
rename to Marlin/src/HAL/ESP32/eeprom.cpp
index dbfee14055..1bf687c6fe 100644
--- a/Marlin/src/HAL/ESP32/eeprom_impl.cpp
+++ b/Marlin/src/HAL/ESP32/eeprom.cpp
@@ -16,29 +16,25 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
+#if ENABLED(EEPROM_SETTINGS)
#include "../shared/eeprom_api.h"
-#include "EEPROM.h"
+#include
-#define EEPROM_SIZE 4096
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
-bool PersistentStore::access_start() {
- return EEPROM.begin(EEPROM_SIZE);
-}
-
-bool PersistentStore::access_finish() {
- EEPROM.end();
- return true;
-}
+bool PersistentStore::access_start() { return EEPROM.begin(MARLIN_EEPROM_SIZE); }
+bool PersistentStore::access_finish() { EEPROM.end(); return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
for (size_t i = 0; i < size; i++) {
@@ -57,7 +53,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() { return EEPROM_SIZE; }
-
#endif // EEPROM_SETTINGS
#endif // ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/ESP32/endstop_interrupts.h b/Marlin/src/HAL/ESP32/endstop_interrupts.h
index 2da1cc7477..743ccd99c9 100644
--- a/Marlin/src/HAL/ESP32/endstop_interrupts.h
+++ b/Marlin/src/HAL/ESP32/endstop_interrupts.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -42,43 +42,21 @@ void ICACHE_RAM_ATTR endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
#define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
- #if HAS_X_MAX
- _ATTACH(X_MAX_PIN);
- #endif
- #if HAS_X_MIN
- _ATTACH(X_MIN_PIN);
- #endif
- #if HAS_Y_MAX
- _ATTACH(Y_MAX_PIN);
- #endif
- #if HAS_Y_MIN
- _ATTACH(Y_MIN_PIN);
- #endif
- #if HAS_Z_MAX
- _ATTACH(Z_MAX_PIN);
- #endif
- #if HAS_Z_MIN
- _ATTACH(Z_MIN_PIN);
- #endif
- #if HAS_Z2_MAX
- _ATTACH(Z2_MAX_PIN);
- #endif
- #if HAS_Z2_MIN
- _ATTACH(Z2_MIN_PIN);
- #endif
- #if HAS_Z3_MAX
- _ATTACH(Z3_MAX_PIN);
- #endif
- #if HAS_Z3_MIN
- _ATTACH(Z3_MIN_PIN);
- #endif
- #if HAS_Z4_MAX
- _ATTACH(Z4_MAX_PIN);
- #endif
- #if HAS_Z4_MIN
- _ATTACH(Z4_MIN_PIN);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- _ATTACH(Z_MIN_PROBE_PIN);
- #endif
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/ESP32/fastio.h b/Marlin/src/HAL/ESP32/fastio.h
index 09930194d6..2ded3a5f62 100644
--- a/Marlin/src/HAL/ESP32/fastio.h
+++ b/Marlin/src/HAL/ESP32/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/i2s.cpp b/Marlin/src/HAL/ESP32/i2s.cpp
index d80c3c24e1..99b2f755e5 100644
--- a/Marlin/src/HAL/ESP32/i2s.cpp
+++ b/Marlin/src/HAL/ESP32/i2s.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/ESP32/i2s.h b/Marlin/src/HAL/ESP32/i2s.h
index 63a579a184..573b983837 100644
--- a/Marlin/src/HAL/ESP32/i2s.h
+++ b/Marlin/src/HAL/ESP32/i2s.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/inc/Conditionals_LCD.h b/Marlin/src/HAL/ESP32/inc/Conditionals_LCD.h
index 0285c52ee3..4da600179d 100644
--- a/Marlin/src/HAL/ESP32/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/ESP32/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/ESP32."
+#endif
diff --git a/Marlin/src/HAL/ESP32/inc/Conditionals_adv.h b/Marlin/src/HAL/ESP32/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/ESP32/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/ESP32/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/inc/Conditionals_post.h b/Marlin/src/HAL/ESP32/inc/Conditionals_post.h
index 11603c9ef4..5f1c4b1601 100644
--- a/Marlin/src/HAL/ESP32/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/ESP32/inc/Conditionals_post.h
@@ -16,12 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-
-// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
-#if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
- #define SDCARD_EEPROM_EMULATION
-#endif
diff --git a/Marlin/src/HAL/ESP32/inc/SanityCheck.h b/Marlin/src/HAL/ESP32/inc/SanityCheck.h
index b6ad7a3c4b..f57a6c5910 100644
--- a/Marlin/src/HAL/ESP32/inc/SanityCheck.h
+++ b/Marlin/src/HAL/ESP32/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -25,8 +25,8 @@
#error "EMERGENCY_PARSER is not yet implemented for ESP32. Disable EMERGENCY_PARSER to continue."
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on ESP32."
#endif
#if HAS_TMC_SW_SERIAL
diff --git a/Marlin/src/HAL/ESP32/ota.cpp b/Marlin/src/HAL/ESP32/ota.cpp
index 34a2482c9b..69a3e25e56 100644
--- a/Marlin/src/HAL/ESP32/ota.cpp
+++ b/Marlin/src/HAL/ESP32/ota.cpp
@@ -14,7 +14,8 @@
* 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 .
+ * along with this program. If not, see .
+ *
*/
#ifdef ARDUINO_ARCH_ESP32
diff --git a/Marlin/src/HAL/ESP32/ota.h b/Marlin/src/HAL/ESP32/ota.h
index 1780fb32c1..7f9b237aa6 100644
--- a/Marlin/src/HAL/ESP32/ota.h
+++ b/Marlin/src/HAL/ESP32/ota.h
@@ -14,7 +14,7 @@
* 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 .
+ * along with this program. If not, see .
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/servotimers.h b/Marlin/src/HAL/ESP32/servotimers.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/ESP32/servotimers.h
+++ b/Marlin/src/HAL/ESP32/servotimers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/spi_pins.h b/Marlin/src/HAL/ESP32/spi_pins.h
index 0e67615a2b..15f8f2ab6b 100644
--- a/Marlin/src/HAL/ESP32/spi_pins.h
+++ b/Marlin/src/HAL/ESP32/spi_pins.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/spiffs.cpp b/Marlin/src/HAL/ESP32/spiffs.cpp
index 0013dd6093..a0e713bff0 100644
--- a/Marlin/src/HAL/ESP32/spiffs.cpp
+++ b/Marlin/src/HAL/ESP32/spiffs.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
#include "../../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/HAL/ESP32/spiffs.h b/Marlin/src/HAL/ESP32/spiffs.h
index b9cbb23bda..64ec7dd11e 100644
--- a/Marlin/src/HAL/ESP32/spiffs.h
+++ b/Marlin/src/HAL/ESP32/spiffs.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/timers.cpp b/Marlin/src/HAL/ESP32/timers.cpp
index ef181a438c..3300aea8a8 100644
--- a/Marlin/src/HAL/ESP32/timers.cpp
+++ b/Marlin/src/HAL/ESP32/timers.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
#include
@@ -28,9 +27,7 @@
#include
#include
-#include "HAL.h"
-
-#include "timers.h"
+#include "../../inc/MarlinConfig.h"
// ------------------------
// Local defines
diff --git a/Marlin/src/HAL/ESP32/timers.h b/Marlin/src/HAL/ESP32/timers.h
index bc4306be20..d722670f33 100644
--- a/Marlin/src/HAL/ESP32/timers.h
+++ b/Marlin/src/HAL/ESP32/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -38,10 +38,18 @@
typedef uint64_t hal_timer_t;
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
-#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
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
+#ifndef PWM_TIMER_NUM
+ #define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
+#endif
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
@@ -79,9 +87,15 @@ typedef uint64_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
-#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
-#define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
+#endif
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
+#endif
+#ifndef HAL_PWM_TIMER_ISR
+ #define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
+#endif
extern "C" void tempTC_Handler();
extern "C" void stepTC_Handler();
diff --git a/Marlin/src/HAL/ESP32/watchdog.cpp b/Marlin/src/HAL/ESP32/watchdog.cpp
index 9f681e6095..f6fcfa3182 100644
--- a/Marlin/src/HAL/ESP32/watchdog.cpp
+++ b/Marlin/src/HAL/ESP32/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/ESP32/watchdog.h b/Marlin/src/HAL/ESP32/watchdog.h
index 7e07990865..b6c169e347 100644
--- a/Marlin/src/HAL/ESP32/watchdog.h
+++ b/Marlin/src/HAL/ESP32/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/web.cpp b/Marlin/src/HAL/ESP32/web.cpp
index b795efe3c5..7a27707a3e 100644
--- a/Marlin/src/HAL/ESP32/web.cpp
+++ b/Marlin/src/HAL/ESP32/web.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
#include "../../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/HAL/ESP32/web.h b/Marlin/src/HAL/ESP32/web.h
index 8dbefd8eef..60023ac636 100644
--- a/Marlin/src/HAL/ESP32/web.h
+++ b/Marlin/src/HAL/ESP32/web.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/ESP32/wifi.cpp b/Marlin/src/HAL/ESP32/wifi.cpp
index 9203dd62e7..f4cf5a606a 100644
--- a/Marlin/src/HAL/ESP32/wifi.cpp
+++ b/Marlin/src/HAL/ESP32/wifi.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_ESP32
#include "../../core/serial.h"
diff --git a/Marlin/src/HAL/ESP32/wifi.h b/Marlin/src/HAL/ESP32/wifi.h
index 580c6c87f4..759a73b252 100644
--- a/Marlin/src/HAL/ESP32/wifi.h
+++ b/Marlin/src/HAL/ESP32/wifi.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/HAL.h b/Marlin/src/HAL/HAL.h
index fa2782cfcb..c7b7531442 100644
--- a/Marlin/src/HAL/HAL.h
+++ b/Marlin/src/HAL/HAL.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -27,8 +27,20 @@
#define HAL_ADC_RANGE _BV(HAL_ADC_RESOLUTION)
+#ifndef I2C_ADDRESS
+ #define I2C_ADDRESS(A) (A)
+#endif
+
+// Needed for AVR sprintf_P PROGMEM extension
+#ifndef S_FMT
+ #define S_FMT "%s"
+#endif
+
+// String helper
+#ifndef PGMSTR
+ #define PGMSTR(NAM,STR) const char NAM[] = STR
+#endif
+
inline void watchdog_refresh() {
- #if ENABLED(USE_WATCHDOG)
- HAL_watchdog_refresh();
- #endif
+ TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
}
diff --git a/Marlin/src/HAL/LINUX/HAL.cpp b/Marlin/src/HAL/LINUX/HAL.cpp
index d38644f1a5..d7d7c2d2b4 100644
--- a/Marlin/src/HAL/LINUX/HAL.cpp
+++ b/Marlin/src/HAL/LINUX/HAL.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/LINUX/HAL.h b/Marlin/src/HAL/LINUX/HAL.h
index 0475c953c3..96e121d915 100644
--- a/Marlin/src/HAL/LINUX/HAL.h
+++ b/Marlin/src/HAL/LINUX/HAL.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -56,7 +56,6 @@ uint8_t _getc();
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
#include "serial.h"
#define SHARED_SERVOS HAS_SERVOS
@@ -87,9 +86,10 @@ int freeMemory();
#pragma GCC diagnostic pop
// ADC
+#define HAL_ADC_VREF 5.0
+#define HAL_ADC_RESOLUTION 10
#define HAL_ANALOG_SELECT(ch) HAL_adc_enable_channel(ch)
#define HAL_START_ADC(ch) HAL_adc_start_conversion(ch)
-#define HAL_ADC_RESOLUTION 10
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
@@ -106,3 +106,8 @@ inline uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
FORCE_INLINE static void DELAY_CYCLES(uint64_t x) {
Clock::delayCycles(x);
}
+
+// Add strcmp_P if missing
+#ifndef strcmp_P
+ #define strcmp_P(a, b) strcmp((a), (b))
+#endif
diff --git a/Marlin/src/HAL/LINUX/arduino.cpp b/Marlin/src/HAL/LINUX/arduino.cpp
index 008db15592..4b56d02a38 100644
--- a/Marlin/src/HAL/LINUX/arduino.cpp
+++ b/Marlin/src/HAL/LINUX/arduino.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include
@@ -76,20 +75,6 @@ uint16_t analogRead(pin_t adc_pin) {
return Gpio::get(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin));
}
-// **************************
-// Persistent Config Storage
-// **************************
-
-void eeprom_write_byte(unsigned char *pos, unsigned char value) {
-
-}
-
-unsigned char eeprom_read_byte(uint8_t * pos) { return '\0'; }
-
-void eeprom_read_block(void *__dst, const void *__src, size_t __n) { }
-
-void eeprom_update_block(const void *__src, void *__dst, size_t __n) { }
-
char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s) {
char format_string[20];
snprintf(format_string, 20, "%%%d.%df", __width, __prec);
diff --git a/Marlin/src/HAL/LINUX/eeprom_impl.cpp b/Marlin/src/HAL/LINUX/eeprom.cpp
similarity index 86%
rename from Marlin/src/HAL/LINUX/eeprom_impl.cpp
rename to Marlin/src/HAL/LINUX/eeprom.cpp
index 4745f05673..967ca851ab 100644
--- a/Marlin/src/HAL/LINUX/eeprom_impl.cpp
+++ b/Marlin/src/HAL/LINUX/eeprom.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "../../inc/MarlinConfig.h"
@@ -29,10 +28,15 @@
#include "../shared/eeprom_api.h"
#include
-#define LINUX_EEPROM_SIZE (E2END + 1)
-uint8_t buffer[LINUX_EEPROM_SIZE];
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB of Emulated EEPROM
+#endif
+
+uint8_t buffer[MARLIN_EEPROM_SIZE];
char filename[] = "eeprom.dat";
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
bool PersistentStore::access_start() {
const char eeprom_erase_value = 0xFF;
FILE * eeprom_file = fopen(filename, "rb");
@@ -41,8 +45,8 @@ bool PersistentStore::access_start() {
fseek(eeprom_file, 0L, SEEK_END);
std::size_t file_size = ftell(eeprom_file);
- if (file_size < LINUX_EEPROM_SIZE) {
- memset(buffer + file_size, eeprom_erase_value, LINUX_EEPROM_SIZE - file_size);
+ if (file_size < MARLIN_EEPROM_SIZE) {
+ memset(buffer + file_size, eeprom_erase_value, MARLIN_EEPROM_SIZE - file_size);
}
else {
fseek(eeprom_file, 0L, SEEK_SET);
@@ -96,7 +100,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return bytes_read != size; // return true for any error
}
-size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
-
#endif // EEPROM_SETTINGS
#endif // __PLAT_LINUX__
diff --git a/Marlin/src/HAL/LINUX/fastio.h b/Marlin/src/HAL/LINUX/fastio.h
index 8b0526710d..4567c62a51 100644
--- a/Marlin/src/HAL/LINUX/fastio.h
+++ b/Marlin/src/HAL/LINUX/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -44,7 +44,7 @@
*
* Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
*
- * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
+ * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html
*/
/// Read a pin
diff --git a/Marlin/src/HAL/LINUX/hardware/Clock.cpp b/Marlin/src/HAL/LINUX/hardware/Clock.cpp
index 8265fedbf0..1984a4a44e 100644
--- a/Marlin/src/HAL/LINUX/hardware/Clock.cpp
+++ b/Marlin/src/HAL/LINUX/hardware/Clock.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "../../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/LINUX/hardware/Clock.h b/Marlin/src/HAL/LINUX/hardware/Clock.h
index 17c2fd9501..072eacfd73 100644
--- a/Marlin/src/HAL/LINUX/hardware/Clock.h
+++ b/Marlin/src/HAL/LINUX/hardware/Clock.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/hardware/Gpio.cpp b/Marlin/src/HAL/LINUX/hardware/Gpio.cpp
index e49fb13754..61a7be7da9 100644
--- a/Marlin/src/HAL/LINUX/hardware/Gpio.cpp
+++ b/Marlin/src/HAL/LINUX/hardware/Gpio.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "Gpio.h"
diff --git a/Marlin/src/HAL/LINUX/hardware/Gpio.h b/Marlin/src/HAL/LINUX/hardware/Gpio.h
index 33eea77731..9255ec1dfc 100644
--- a/Marlin/src/HAL/LINUX/hardware/Gpio.h
+++ b/Marlin/src/HAL/LINUX/hardware/Gpio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/hardware/Heater.cpp b/Marlin/src/HAL/LINUX/hardware/Heater.cpp
index 7c9bfaf80f..70df816182 100644
--- a/Marlin/src/HAL/LINUX/hardware/Heater.cpp
+++ b/Marlin/src/HAL/LINUX/hardware/Heater.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "Clock.h"
diff --git a/Marlin/src/HAL/LINUX/hardware/Heater.h b/Marlin/src/HAL/LINUX/hardware/Heater.h
index bb759da090..b17078d0b7 100644
--- a/Marlin/src/HAL/LINUX/hardware/Heater.h
+++ b/Marlin/src/HAL/LINUX/hardware/Heater.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.cpp b/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.cpp
index a79f14f6f5..c11fd1f55c 100644
--- a/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.cpp
+++ b/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "IOLoggerCSV.h"
diff --git a/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.h b/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.h
index f8bca83e30..d8fe7383bd 100644
--- a/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.h
+++ b/Marlin/src/HAL/LINUX/hardware/IOLoggerCSV.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/hardware/LinearAxis.cpp b/Marlin/src/HAL/LINUX/hardware/LinearAxis.cpp
index ec58fe77e5..c5b3ccc986 100644
--- a/Marlin/src/HAL/LINUX/hardware/LinearAxis.cpp
+++ b/Marlin/src/HAL/LINUX/hardware/LinearAxis.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include
diff --git a/Marlin/src/HAL/LINUX/hardware/LinearAxis.h b/Marlin/src/HAL/LINUX/hardware/LinearAxis.h
index 04a5f3d0f7..34541e79a1 100644
--- a/Marlin/src/HAL/LINUX/hardware/LinearAxis.h
+++ b/Marlin/src/HAL/LINUX/hardware/LinearAxis.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/hardware/Timer.cpp b/Marlin/src/HAL/LINUX/hardware/Timer.cpp
index e7136bbdef..9f0d6a8f3a 100644
--- a/Marlin/src/HAL/LINUX/hardware/Timer.cpp
+++ b/Marlin/src/HAL/LINUX/hardware/Timer.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "Timer.h"
diff --git a/Marlin/src/HAL/LINUX/hardware/Timer.h b/Marlin/src/HAL/LINUX/hardware/Timer.h
index ebfe8e8b9b..757efdcdbd 100644
--- a/Marlin/src/HAL/LINUX/hardware/Timer.h
+++ b/Marlin/src/HAL/LINUX/hardware/Timer.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/inc/Conditionals_LCD.h b/Marlin/src/HAL/LINUX/inc/Conditionals_LCD.h
index 0285c52ee3..99a6fc2753 100644
--- a/Marlin/src/HAL/LINUX/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/LINUX/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/LINUX."
+#endif
diff --git a/Marlin/src/HAL/LINUX/inc/Conditionals_adv.h b/Marlin/src/HAL/LINUX/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/LINUX/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/LINUX/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/inc/Conditionals_post.h b/Marlin/src/HAL/LINUX/inc/Conditionals_post.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/LINUX/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/LINUX/inc/Conditionals_post.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/inc/SanityCheck.h b/Marlin/src/HAL/LINUX/inc/SanityCheck.h
index a3238b088b..84167c97a1 100644
--- a/Marlin/src/HAL/LINUX/inc/SanityCheck.h
+++ b/Marlin/src/HAL/LINUX/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -30,8 +30,8 @@
#error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on LINUX."
#endif
#if HAS_TMC_SW_SERIAL
diff --git a/Marlin/src/HAL/LINUX/include/Arduino.h b/Marlin/src/HAL/LINUX/include/Arduino.h
index 55bf0f95ee..e28b474ede 100644
--- a/Marlin/src/HAL/LINUX/include/Arduino.h
+++ b/Marlin/src/HAL/LINUX/include/Arduino.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -106,12 +106,6 @@ bool digitalRead(pin_t);
void analogWrite(pin_t, int);
uint16_t analogRead(pin_t);
-// EEPROM
-void eeprom_write_byte(unsigned char *pos, unsigned char value);
-unsigned char eeprom_read_byte(unsigned char *pos);
-void eeprom_read_block(void *__dst, const void *__src, size_t __n);
-void eeprom_update_block(const void *__src, void *__dst, size_t __n);
-
int32_t random(int32_t);
int32_t random(int32_t, int32_t);
void randomSeed(uint32_t);
diff --git a/Marlin/src/HAL/LINUX/include/pinmapping.cpp b/Marlin/src/HAL/LINUX/include/pinmapping.cpp
index 0340e681fe..870ab3a96e 100644
--- a/Marlin/src/HAL/LINUX/include/pinmapping.cpp
+++ b/Marlin/src/HAL/LINUX/include/pinmapping.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include
diff --git a/Marlin/src/HAL/LINUX/include/pinmapping.h b/Marlin/src/HAL/LINUX/include/pinmapping.h
index 0d99a38116..98f4b812e8 100644
--- a/Marlin/src/HAL/LINUX/include/pinmapping.h
+++ b/Marlin/src/HAL/LINUX/include/pinmapping.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/include/serial.h b/Marlin/src/HAL/LINUX/include/serial.h
index c881d5dbda..154e95aec2 100644
--- a/Marlin/src/HAL/LINUX/include/serial.h
+++ b/Marlin/src/HAL/LINUX/include/serial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/main.cpp b/Marlin/src/HAL/LINUX/main.cpp
index 1155f2a873..4eeef318e7 100644
--- a/Marlin/src/HAL/LINUX/main.cpp
+++ b/Marlin/src/HAL/LINUX/main.cpp
@@ -14,10 +14,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
extern void setup();
diff --git a/Marlin/src/HAL/LINUX/pinsDebug.h b/Marlin/src/HAL/LINUX/pinsDebug.h
index e373d37067..a93ceddc61 100644
--- a/Marlin/src/HAL/LINUX/pinsDebug.h
+++ b/Marlin/src/HAL/LINUX/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LINUX/servo_private.h b/Marlin/src/HAL/LINUX/servo_private.h
index d576ff9266..122cfef3ea 100644
--- a/Marlin/src/HAL/LINUX/servo_private.h
+++ b/Marlin/src/HAL/LINUX/servo_private.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LINUX/spi_pins.h b/Marlin/src/HAL/LINUX/spi_pins.h
index 8abeb312f4..a444196f04 100644
--- a/Marlin/src/HAL/LINUX/spi_pins.h
+++ b/Marlin/src/HAL/LINUX/spi_pins.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -24,7 +24,7 @@
#include "../../core/macros.h"
#include "../../inc/MarlinConfigPre.h"
-#if HAS_GRAPHICAL_LCD && ENABLED(SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
+#if BOTH(HAS_GRAPHICAL_LCD, 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 required for communicating with each device being different.
// This requirement can be removed if the SPI access to these devices is updated to use
diff --git a/Marlin/src/HAL/LINUX/timers.cpp b/Marlin/src/HAL/LINUX/timers.cpp
index ebfb950595..66d80f2518 100644
--- a/Marlin/src/HAL/LINUX/timers.cpp
+++ b/Marlin/src/HAL/LINUX/timers.cpp
@@ -16,16 +16,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "hardware/Timer.h"
#include "../../inc/MarlinConfig.h"
-#include "timers.h"
/**
* Use POSIX signals to attempt to emulate Interrupts
diff --git a/Marlin/src/HAL/LINUX/timers.h b/Marlin/src/HAL/LINUX/timers.h
index b657584922..1beaea95ab 100644
--- a/Marlin/src/HAL/LINUX/timers.h
+++ b/Marlin/src/HAL/LINUX/timers.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -37,9 +37,15 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE ((SystemCoreClock) / 4) // frequency of timers peripherals
-#define STEP_TIMER_NUM 0 // Timer Index for Stepper
-#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
#define TEMP_TIMER_RATE 1000000
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -59,8 +65,12 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler()
-#define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler()
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() extern "C" void TIMER0_IRQHandler()
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() extern "C" void TIMER1_IRQHandler()
+#endif
// PWM timer
#define HAL_PWM_TIMER
diff --git a/Marlin/src/HAL/LINUX/watchdog.cpp b/Marlin/src/HAL/LINUX/watchdog.cpp
index 5ffe860f05..c15b0e311c 100644
--- a/Marlin/src/HAL/LINUX/watchdog.cpp
+++ b/Marlin/src/HAL/LINUX/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __PLAT_LINUX__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/LINUX/watchdog.h b/Marlin/src/HAL/LINUX/watchdog.h
index 4771426a0b..472624cc78 100644
--- a/Marlin/src/HAL/LINUX/watchdog.h
+++ b/Marlin/src/HAL/LINUX/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/DebugMonitor.cpp b/Marlin/src/HAL/LPC1768/DebugMonitor.cpp
index 2a39e56168..783b10cfac 100644
--- a/Marlin/src/HAL/LPC1768/DebugMonitor.cpp
+++ b/Marlin/src/HAL/LPC1768/DebugMonitor.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef TARGET_LPC1768
#include "../../core/macros.h"
@@ -211,11 +210,7 @@ void HardFault_HandlerC(unsigned long *sp, unsigned long lr, unsigned long cause
// Nothing below here is compiled because NVIC_SystemReset loops forever
- for (;;) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_init();
- #endif
- }
+ for (;;) { TERN_(USE_WATCHDOG, watchdog_init()); }
}
extern "C" {
diff --git a/Marlin/src/HAL/LPC1768/HAL.cpp b/Marlin/src/HAL/LPC1768/HAL.cpp
index f206ce7adb..939f1e8a94 100644
--- a/Marlin/src/HAL/LPC1768/HAL.cpp
+++ b/Marlin/src/HAL/LPC1768/HAL.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
@@ -70,9 +69,7 @@ int16_t PARSED_PIN_INDEX(const char code, const int16_t dval) {
void flashFirmware(const int16_t) { NVIC_SystemReset(); }
void HAL_clear_reset_source(void) {
- #if ENABLED(USE_WATCHDOG)
- watchdog_clear_timeout_flag();
- #endif
+ TERN_(USE_WATCHDOG, watchdog_clear_timeout_flag());
}
uint8_t HAL_get_reset_source(void) {
diff --git a/Marlin/src/HAL/LPC1768/HAL.h b/Marlin/src/HAL/LPC1768/HAL.h
index f5ea629f16..0153bacf42 100644
--- a/Marlin/src/HAL/LPC1768/HAL.h
+++ b/Marlin/src/HAL/LPC1768/HAL.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -41,13 +41,15 @@ extern "C" volatile uint32_t _millis;
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
#include "MarlinSerial.h"
#include
#include
#include
+// i2c uses 8-bit shifted address
+#define I2C_ADDRESS(A) uint8_t((A) << 1)
+
//
// Default graphical display delays
//
@@ -148,6 +150,8 @@ int freeMemory();
// K = 6, 565 samples, 500Hz sample rate, 1.13s convergence on full range step
// Memory usage per ADC channel (bytes): 4 (32 Bytes for 8 channels)
+#define HAL_ADC_VREF 3.3 // ADC voltage reference
+
#define HAL_ADC_RESOLUTION 12 // 15 bit maximum, raw temperature is stored as int16_t
#define HAL_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL
@@ -197,6 +201,8 @@ void HAL_idletask();
#define PLATFORM_M997_SUPPORT
void flashFirmware(const int16_t);
+#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment
+
/**
* set_pwm_frequency
* Set the frequency of the timer corresponding to the provided pin
@@ -216,3 +222,8 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255,
// Reset source
void HAL_clear_reset_source(void);
uint8_t HAL_get_reset_source(void);
+
+// Add strcmp_P if missing
+#ifndef strcmp_P
+ #define strcmp_P(a, b) strcmp((a), (b))
+#endif
diff --git a/Marlin/src/HAL/LPC1768/HAL_SPI.cpp b/Marlin/src/HAL/LPC1768/HAL_SPI.cpp
index 1c20e7f652..00b4310d1d 100644
--- a/Marlin/src/HAL/LPC1768/HAL_SPI.cpp
+++ b/Marlin/src/HAL/LPC1768/HAL_SPI.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -30,7 +30,7 @@
*/
/**
- * Hardware SPI and a software SPI implementations are included in this file.
+ * Hardware SPI and Software SPI implementations are included in this file.
* The hardware SPI runs faster and has higher throughput but is not compatible
* with some LCD interfaces/adapters.
*
@@ -51,6 +51,10 @@
#include "../../inc/MarlinConfig.h"
#include
+// Hardware SPI and SPIClass
+#include
+#include
+
// ------------------------
// Public functions
// ------------------------
@@ -96,12 +100,6 @@
#else
- // Hardware SPI
-
- #include
- #include
- #include
-
// decide which HW SPI device to use
#ifndef LPC_HW_SPI_DEV
#if (SCK_PIN == P0_07 && MISO_PIN == P0_08 && MOSI_PIN == P0_09)
@@ -114,7 +112,7 @@
#endif
#endif
#endif
- #if (LPC_HW_SPI_DEV == 0)
+ #if LPC_HW_SPI_DEV == 0
#define LPC_SSPn LPC_SSP0
#else
#define LPC_SSPn LPC_SSP1
@@ -192,7 +190,7 @@
for (uint16_t i = 0; i < nbyte; i++) buf[i] = doio(0xFF);
}
- static uint8_t spiTransfer(uint8_t b) {
+ uint8_t spiTransfer(uint8_t b) {
return doio(b);
}
@@ -209,32 +207,238 @@
}
-#endif // ENABLED(LPC_SOFTWARE_SPI)
+#endif // LPC_SOFTWARE_SPI
-void SPIClass::begin() { spiBegin(); }
-
-void SPIClass::beginTransaction(SPISettings cfg) {
- uint8_t spiRate;
- switch (cfg.spiRate()) {
- case 8000000: spiRate = 0; break;
- case 4000000: spiRate = 1; break;
- case 2000000: spiRate = 2; break;
- case 1000000: spiRate = 3; break;
- case 500000: spiRate = 4; break;
- case 250000: spiRate = 5; break;
- case 125000: spiRate = 6; break;
- default: spiRate = 2; break;
- }
- spiInit(spiRate);
+/**
+ * @brief Wait until TXE (tx empty) flag is set and BSY (busy) flag unset.
+ */
+static inline void waitSpiTxEnd(LPC_SSP_TypeDef *spi_d) {
+ while (SSP_GetStatus(spi_d, SSP_STAT_TXFIFO_EMPTY) == RESET) { /* nada */ } // wait until TXE=1
+ while (SSP_GetStatus(spi_d, SSP_STAT_BUSY) == SET) { /* nada */ } // wait until BSY=0
}
-uint8_t SPIClass::transfer(const uint8_t B) { return spiTransfer(B); }
+SPIClass::SPIClass(uint8_t device) {
+ // Init things specific to each SPI device
+ // clock divider setup is a bit of hack, and needs to be improved at a later date.
+
+ PINSEL_CFG_Type PinCfg; // data structure to hold init values
+ #if BOARD_NR_SPI >= 1
+ _settings[0].spi_d = LPC_SSP0;
+ // _settings[0].clockDivider = determine_baud_rate(_settings[0].spi_d, _settings[0].clock);
+ PinCfg.Funcnum = 2;
+ PinCfg.OpenDrain = 0;
+ PinCfg.Pinmode = 0;
+ PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI1_SCK_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI1_SCK_PIN);
+ PINSEL_ConfigPin(&PinCfg);
+ SET_OUTPUT(BOARD_SPI1_SCK_PIN);
+
+ PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI1_MISO_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI1_MISO_PIN);
+ PINSEL_ConfigPin(&PinCfg);
+ SET_INPUT(BOARD_SPI1_MISO_PIN);
+
+ PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI1_MOSI_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI1_MOSI_PIN);
+ PINSEL_ConfigPin(&PinCfg);
+ SET_OUTPUT(BOARD_SPI1_MOSI_PIN);
+ #endif
+
+ #if BOARD_NR_SPI >= 2
+ _settings[1].spi_d = LPC_SSP1;
+ // _settings[1].clockDivider = determine_baud_rate(_settings[1].spi_d, _settings[1].clock);
+ PinCfg.Funcnum = 2;
+ PinCfg.OpenDrain = 0;
+ PinCfg.Pinmode = 0;
+ PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI2_SCK_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI2_SCK_PIN);
+ PINSEL_ConfigPin(&PinCfg);
+ SET_OUTPUT(BOARD_SPI2_SCK_PIN);
+
+ PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI2_MISO_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI2_MISO_PIN);
+ PINSEL_ConfigPin(&PinCfg);
+ SET_INPUT(BOARD_SPI2_MISO_PIN);
+
+ PinCfg.Pinnum = LPC176x::pin_bit(BOARD_SPI2_MOSI_PIN);
+ PinCfg.Portnum = LPC176x::pin_port(BOARD_SPI2_MOSI_PIN);
+ PINSEL_ConfigPin(&PinCfg);
+ SET_OUTPUT(BOARD_SPI2_MOSI_PIN);
+ #endif
+
+ setModule(device);
+
+ /* Initialize GPDMA controller */
+ //TODO: call once in the constructor? or each time?
+ GPDMA_Init();
+}
+
+void SPIClass::begin() {
+ updateSettings();
+ SSP_Cmd(_currentSetting->spi_d, ENABLE); // start SSP running
+}
+
+void SPIClass::beginTransaction(const SPISettings &cfg) {
+ setBitOrder(cfg.bitOrder);
+ setDataMode(cfg.dataMode);
+ setDataSize(cfg.dataSize);
+ //setClockDivider(determine_baud_rate(_currentSetting->spi_d, settings.clock));
+ begin();
+}
+
+uint8_t SPIClass::transfer(const uint16_t b) {
+ /* send and receive a single byte */
+ SSP_ReceiveData(_currentSetting->spi_d); // read any previous data
+ SSP_SendData(_currentSetting->spi_d, b);
+ waitSpiTxEnd(_currentSetting->spi_d); // wait for it to finish
+ return SSP_ReceiveData(_currentSetting->spi_d);
+}
uint16_t SPIClass::transfer16(const uint16_t data) {
return (transfer((data >> 8) & 0xFF) << 8)
| (transfer(data & 0xFF) & 0xFF);
}
-SPIClass SPI;
+void SPIClass::end() {
+ // SSP_Cmd(_currentSetting->spi_d, DISABLE); // stop device or SSP_DeInit?
+ SSP_DeInit(_currentSetting->spi_d);
+}
+
+void SPIClass::send(uint8_t data) {
+ SSP_SendData(_currentSetting->spi_d, data);
+}
+
+void SPIClass::dmaSend(void *buf, uint16_t length, bool minc) {
+ //TODO: LPC dma can only write 0xFFF bytes at once.
+ GPDMA_Channel_CFG_Type GPDMACfg;
+
+ /* Configure GPDMA channel 0 -------------------------------------------------------------*/
+ /* DMA Channel 0 */
+ GPDMACfg.ChannelNum = 0;
+ // Source memory
+ GPDMACfg.SrcMemAddr = (uint32_t)buf;
+ // Destination memory - Not used
+ GPDMACfg.DstMemAddr = 0;
+ // Transfer size
+ GPDMACfg.TransferSize = (minc ? length : 1);
+ // Transfer width
+ GPDMACfg.TransferWidth = (_currentSetting->dataSize == DATA_SIZE_16BIT) ? GPDMA_WIDTH_HALFWORD : GPDMA_WIDTH_BYTE;
+ // Transfer type
+ GPDMACfg.TransferType = GPDMA_TRANSFERTYPE_M2P;
+ // Source connection - unused
+ GPDMACfg.SrcConn = 0;
+ // Destination connection
+ GPDMACfg.DstConn = (_currentSetting->spi_d == LPC_SSP0) ? GPDMA_CONN_SSP0_Tx : GPDMA_CONN_SSP1_Tx;
+
+ GPDMACfg.DMALLI = 0;
+
+ // Enable dma on SPI
+ SSP_DMACmd(_currentSetting->spi_d, SSP_DMA_TX, ENABLE);
+
+ // if minc=false, I'm repeating the same byte 'length' times, as I could not find yet how do GPDMA without memory increment
+ do {
+ // Setup channel with given parameter
+ GPDMA_Setup(&GPDMACfg);
+
+ // enabled dma
+ GPDMA_ChannelCmd(0, ENABLE);
+
+ // wait data transfer
+ while (!GPDMA_IntGetStatus(GPDMA_STAT_INTTC, 0) && !GPDMA_IntGetStatus(GPDMA_STAT_INTERR, 0)) { }
+
+ // clear err and int
+ GPDMA_ClearIntPending (GPDMA_STATCLR_INTTC, 0);
+ GPDMA_ClearIntPending (GPDMA_STATCLR_INTERR, 0);
+
+ // dma disable
+ GPDMA_ChannelCmd(0, DISABLE);
+
+ --length;
+ } while (!minc && length > 0);
+
+ waitSpiTxEnd(_currentSetting->spi_d);
+
+ SSP_DMACmd(_currentSetting->spi_d, SSP_DMA_TX, DISABLE);
+}
+
+uint16_t SPIClass::read() {
+ return SSP_ReceiveData(_currentSetting->spi_d);
+}
+
+void SPIClass::read(uint8_t *buf, uint32_t len) {
+ for (uint16_t i = 0; i < len; i++) buf[i] = transfer(0xFF);
+}
+
+void SPIClass::setClock(uint32_t clock) {
+ _currentSetting->clock = clock;
+}
+
+void SPIClass::setModule(uint8_t device) {
+ _currentSetting = &_settings[device - 1];// SPI channels are called 1 2 and 3 but the array is zero indexed
+}
+
+void SPIClass::setBitOrder(uint8_t bitOrder) {
+ _currentSetting->bitOrder = bitOrder;
+}
+
+void SPIClass::setDataMode(uint8_t dataMode) {
+ _currentSetting->dataSize = dataMode;
+}
+
+void SPIClass::setDataSize(uint32_t ds) {
+ _currentSetting->dataSize = ds;
+}
+
+/**
+ * Set up/tear down
+ */
+void SPIClass::updateSettings() {
+ //SSP_DeInit(_currentSetting->spi_d); //todo: need force de init?!
+
+ // divide PCLK by 2 for SSP0
+ CLKPWR_SetPCLKDiv(_currentSetting->spi_d == LPC_SSP0 ? CLKPWR_PCLKSEL_SSP0 : CLKPWR_PCLKSEL_SSP1, CLKPWR_PCLKSEL_CCLK_DIV_2);
+
+ SSP_CFG_Type HW_SPI_init; // data structure to hold init values
+ SSP_ConfigStructInit(&HW_SPI_init); // set values for SPI mode
+ HW_SPI_init.ClockRate = _currentSetting->clock;
+ HW_SPI_init.Databit = _currentSetting->dataSize;
+
+ /**
+ * SPI Mode CPOL CPHA Shift SCK-edge Capture SCK-edge
+ * 0 0 0 Falling Rising
+ * 1 0 1 Rising Falling
+ * 2 1 0 Rising Falling
+ * 3 1 1 Falling Rising
+ */
+ switch (_currentSetting->dataMode) {
+ case SPI_MODE0:
+ HW_SPI_init.CPHA = SSP_CPHA_FIRST;
+ HW_SPI_init.CPOL = SSP_CPOL_HI;
+ break;
+ case SPI_MODE1:
+ HW_SPI_init.CPHA = SSP_CPHA_SECOND;
+ HW_SPI_init.CPOL = SSP_CPOL_HI;
+ break;
+ case SPI_MODE2:
+ HW_SPI_init.CPHA = SSP_CPHA_FIRST;
+ HW_SPI_init.CPOL = SSP_CPOL_LO;
+ break;
+ case SPI_MODE3:
+ HW_SPI_init.CPHA = SSP_CPHA_SECOND;
+ HW_SPI_init.CPOL = SSP_CPOL_LO;
+ break;
+ default:
+ break;
+ }
+
+ // TODO: handle bitOrder
+ SSP_Init(_currentSetting->spi_d, &HW_SPI_init); // puts the values into the proper bits in the SSP0 registers
+}
+
+#if MISO_PIN == BOARD_SPI1_MISO_PIN
+ SPIClass SPI(1);
+#elif MISO_PIN == BOARD_SPI2_MISO_PIN
+ SPIClass SPI(2);
+#endif
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp
index 1b80b211fb..c3fb3bd0e4 100644
--- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp
+++ b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h
index b6bbf8e453..98ce73d377 100644
--- a/Marlin/src/HAL/LPC1768/MarlinSerial.h
+++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -44,10 +44,9 @@ public:
MarlinSerial(LPC_UART_TypeDef *UARTx) :
HardwareSerial(UARTx)
#if ENABLED(EMERGENCY_PARSER)
- , emergency_state(EmergencyParser::State::EP_RESET)
+ , emergency_state(EmergencyParser::State::EP_RESET)
#endif
- {
- }
+ { }
void end() {}
diff --git a/Marlin/src/HAL/LPC1768/Servo.h b/Marlin/src/HAL/LPC1768/Servo.h
index 71e2bb5695..e953cb9204 100644
--- a/Marlin/src/HAL/LPC1768/Servo.h
+++ b/Marlin/src/HAL/LPC1768/Servo.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -60,9 +60,7 @@ class libServo: public Servo {
if (attach(servo_info[servoIndex].Pin.nbr) >= 0) { // try to reattach
write(value);
safe_delay(servo_delay[servoIndex]); // delay to allow servo to reach position
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
diff --git a/Marlin/src/HAL/LPC1768/eeprom_flash.cpp b/Marlin/src/HAL/LPC1768/eeprom_flash.cpp
index 9225807480..2558486375 100644
--- a/Marlin/src/HAL/LPC1768/eeprom_flash.cpp
+++ b/Marlin/src/HAL/LPC1768/eeprom_flash.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef TARGET_LPC1768
@@ -40,24 +40,29 @@
#if ENABLED(FLASH_EEPROM_EMULATION)
-#include "eeprom_api.h"
+#include "../shared/eeprom_api.h"
extern "C" {
#include
}
-#define SECTOR_START(sector) ((sector < 16) ? (sector * 0x1000) : ((sector - 14) * 0x8000))
-#define EEPROM_SECTOR 29
-#define EEPROM_SIZE (4096)
-#define SECTOR_SIZE (32768)
-#define EEPROM_SLOTS (SECTOR_SIZE/EEPROM_SIZE)
-#define EEPROM_ERASE (0xFF)
-#define SLOT_ADDRESS(sector, slot) (((uint8_t *)SECTOR_START(sector)) + slot * EEPROM_SIZE)
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
+#endif
-static uint8_t ram_eeprom[EEPROM_SIZE] __attribute__((aligned(4))) = {0};
+#define SECTOR_START(sector) ((sector < 16) ? (sector << 12) : ((sector - 14) << 15))
+#define EEPROM_SECTOR 29
+#define SECTOR_SIZE 32768
+#define EEPROM_SLOTS ((SECTOR_SIZE)/(MARLIN_EEPROM_SIZE))
+#define EEPROM_ERASE 0xFF
+#define SLOT_ADDRESS(sector, slot) (((uint8_t *)SECTOR_START(sector)) + slot * (MARLIN_EEPROM_SIZE))
+
+static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
static bool eeprom_dirty = false;
static int current_slot = 0;
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
bool PersistentStore::access_start() {
uint32_t first_nblank_loc, first_nblank_val;
IAP_STATUS_CODE status;
@@ -69,15 +74,15 @@ bool PersistentStore::access_start() {
if (status == CMD_SUCCESS) {
// sector is blank so nothing stored yet
- for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = EEPROM_ERASE;
+ for (int i = 0; i < MARLIN_EEPROM_SIZE; i++) ram_eeprom[i] = EEPROM_ERASE;
current_slot = EEPROM_SLOTS;
}
else {
// current slot is the first non blank one
- current_slot = first_nblank_loc / EEPROM_SIZE;
+ current_slot = first_nblank_loc / (MARLIN_EEPROM_SIZE);
uint8_t *eeprom_data = SLOT_ADDRESS(EEPROM_SECTOR, current_slot);
// load current settings
- for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = eeprom_data[i];
+ for (int i = 0; i < MARLIN_EEPROM_SIZE; i++) ram_eeprom[i] = eeprom_data[i];
}
eeprom_dirty = false;
@@ -122,7 +127,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false; // return true for any error
}
-size_t PersistentStore::capacity() { return EEPROM_SIZE; }
-
#endif // FLASH_EEPROM_EMULATION
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp b/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp
index d982bd6268..9f2475f490 100644
--- a/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp
+++ b/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef TARGET_LPC1768
@@ -26,7 +26,7 @@
#if ENABLED(SDCARD_EEPROM_EMULATION)
-#include "eeprom_api.h"
+#include "../shared/eeprom_api.h"
#include
#include
@@ -38,6 +38,11 @@ FATFS fat_fs;
FIL eeprom_file;
bool eeprom_file_open = false;
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE size_t(0x1000) // 4KiB of Emulated EEPROM
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
bool PersistentStore::access_start() {
const char eeprom_erase_value = 0xFF;
MSC_Aquire_Lock();
@@ -79,21 +84,16 @@ static void debug_rw(const bool write, int &pos, const uint8_t *value, const siz
PGM_P const rw_str = write ? PSTR("write") : PSTR("read");
SERIAL_CHAR(' ');
serialprintPGM(rw_str);
- SERIAL_ECHOPAIR("_data(", pos);
- SERIAL_ECHOPAIR(",", (int)value);
- SERIAL_ECHOPAIR(",", (int)size);
- SERIAL_ECHOLNPGM(", ...)");
+ SERIAL_ECHOLNPAIR("_data(", pos, ",", int(value), ",", int(size), ", ...)");
if (total) {
SERIAL_ECHOPGM(" f_");
serialprintPGM(rw_str);
- SERIAL_ECHOPAIR("()=", (int)s);
- SERIAL_ECHOPAIR("\n size=", size);
- SERIAL_ECHOPGM("\n bytes_");
+ SERIAL_ECHOPAIR("()=", int(s), "\n size=", int(size), "\n bytes_");
serialprintPGM(write ? PSTR("written=") : PSTR("read="));
SERIAL_ECHOLN(total);
}
else
- SERIAL_ECHOLNPAIR(" f_lseek()=", (int)s);
+ SERIAL_ECHOLNPAIR(" f_lseek()=", int(s));
}
// File function return codes for type FRESULT. This goes away soon, but
@@ -173,7 +173,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return bytes_read != size; // return true for any error
}
-size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
-
#endif // SDCARD_EEPROM_EMULATION
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/LPC1768/eeprom_wired.cpp b/Marlin/src/HAL/LPC1768/eeprom_wired.cpp
new file mode 100644
index 0000000000..16c15eaf00
--- /dev/null
+++ b/Marlin/src/HAL/LPC1768/eeprom_wired.cpp
@@ -0,0 +1,81 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#ifdef TARGET_LPC1768
+
+#include "../../inc/MarlinConfig.h"
+
+#if USE_WIRED_EEPROM
+
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with implementations supplied by the framework.
+ */
+
+#include "../shared/eeprom_if.h"
+#include "../shared/eeprom_api.h"
+
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x8000 // 32KB
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_start() { eeprom_init(); return true; }
+bool PersistentStore::access_finish() { return true; }
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ while (size--) {
+ uint8_t v = *value;
+
+ // EEPROM has only ~100,000 write cycles,
+ // so only write bytes that have changed!
+ uint8_t * const p = (uint8_t * const)pos;
+ if (v != eeprom_read_byte(p)) {
+ eeprom_write_byte(p, v);
+ if (eeprom_read_byte(p) != v) {
+ SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
+ return true;
+ }
+ }
+
+ 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*/) {
+ do {
+ // Read from external EEPROM
+ const uint8_t c = eeprom_read_byte((uint8_t*)pos);
+
+ if (writing) *value = c;
+ crc16(crc, &c, 1);
+ pos++;
+ value++;
+ } while (--size);
+ return false;
+}
+
+#endif // USE_WIRED_EEPROM
+#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/LPC1768/endstop_interrupts.h b/Marlin/src/HAL/LPC1768/endstop_interrupts.h
index 4c4e9bd3f0..b0d0c0ec5c 100644
--- a/Marlin/src/HAL/LPC1768/endstop_interrupts.h
+++ b/Marlin/src/HAL/LPC1768/endstop_interrupts.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/fast_pwm.cpp b/Marlin/src/HAL/LPC1768/fast_pwm.cpp
index a1feb25903..dd440b5e77 100644
--- a/Marlin/src/HAL/LPC1768/fast_pwm.cpp
+++ b/Marlin/src/HAL/LPC1768/fast_pwm.cpp
@@ -16,15 +16,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfigPre.h"
-#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
+#if NEEDS_HARDWARE_PWM // Specific meta-flag for features that mandate PWM
#include
@@ -36,5 +35,5 @@ void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255
LPC176x::pwm_write_ratio(pin, invert ? 1.0f - (float)v / v_size : (float)v / v_size);
}
-#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
+#endif // NEEDS_HARDWARE_PWM
#endif // TARGET_LPC1768
diff --git a/Marlin/src/HAL/LPC1768/fastio.h b/Marlin/src/HAL/LPC1768/fastio.h
index 8e8e66db72..c553ffb182 100644
--- a/Marlin/src/HAL/LPC1768/fastio.h
+++ b/Marlin/src/HAL/LPC1768/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -56,7 +56,7 @@
*
* Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
*
- * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
+ * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html
*/
/// Read a pin
diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h
index 0285c52ee3..b9bc0bf82e 100644
--- a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h
@@ -16,7 +16,18 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_FSMC_TFT
+ #error "Sorry! FSMC TFT displays are not current available for HAL/LPC1768."
+#endif
+
+// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
+#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT
+ #undef TOUCH_SCREEN
+ #undef TOUCH_SCREEN_CALIBRATION
+ #define HAS_TOUCH_XPT2046 1
+#endif
diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
index 490cfd50e8..ce6d3fdde2 100644
--- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h
@@ -16,11 +16,13 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-#if USE_FALLBACK_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
+#if USE_FALLBACK_EEPROM
#define FLASH_EEPROM_EMULATION
+#elif EITHER(I2C_EEPROM, SPI_EEPROM)
+ #define USE_SHARED_EEPROM 1
#endif
diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h
index 949c7f4899..0a4e59c6c4 100644
--- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h
+++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -59,6 +59,10 @@
*/
static_assert(!(NUM_SERVOS && ENABLED(FAST_PWM_FAN)), "BLTOUCH and Servos are incompatible with FAST_PWM_FAN on LPC176x boards.");
+#if SPINDLE_LASER_FREQUENCY
+ static_assert(!NUM_SERVOS, "BLTOUCH and Servos are incompatible with SPINDLE_LASER_FREQUENCY on LPC176x boards.");
+#endif
+
/**
* Test LPC176x-specific configuration values for errors at compile-time.
*/
@@ -174,7 +178,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
//
// Flag any i2c pin conflicts
//
-#if ANY(DIGIPOT_I2C, DIGIPOT_MCP4018, DAC_STEPPER_CURRENT, EXPERIMENTAL_I2CBUS, I2C_POSITION_ENCODERS, PCA9632, I2C_EEPROM)
+#if ANY(HAS_I2C_DIGIPOT, DAC_STEPPER_CURRENT, EXPERIMENTAL_I2CBUS, I2C_POSITION_ENCODERS, PCA9632, I2C_EEPROM)
#define USEDI2CDEV_M 1 // /Wire.cpp
#if USEDI2CDEV_M == 0 // P0_27 [D57] (AUX-1) .......... P0_28 [D58] (AUX-1)
@@ -251,3 +255,9 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o
#undef USEDI2CDEV_M
#endif
+
+#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
+ #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on this platform."
+#elif ENABLED(SERIAL_STATS_DROPPED_RX)
+ #error "SERIAL_STATS_DROPPED_RX is not supported on this platform."
+#endif
diff --git a/Marlin/src/HAL/LPC1768/include/SPI.h b/Marlin/src/HAL/LPC1768/include/SPI.h
index af085f29a9..e2645b9290 100644
--- a/Marlin/src/HAL/LPC1768/include/SPI.h
+++ b/Marlin/src/HAL/LPC1768/include/SPI.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -24,25 +24,139 @@
#include "../../shared/HAL_SPI.h"
#include
+#include
+#include
-#define MSBFIRST 1
-#define SPI_MODE3 0
+//#define MSBFIRST 1
+
+#define SPI_MODE0 0
+#define SPI_MODE1 1
+#define SPI_MODE2 2
+#define SPI_MODE3 3
+
+#define DATA_SIZE_8BIT SSP_DATABIT_8
+#define DATA_SIZE_16BIT SSP_DATABIT_16
+
+#define SPI_CLOCK_DIV2 8333333 //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED
+#define SPI_CLOCK_DIV4 4166667 //(SCR: 5) desired: 4,000,000 actual: 4,166,667 +4.2% SPI_HALF_SPEED
+#define SPI_CLOCK_DIV8 2083333 //(SCR: 11) desired: 2,000,000 actual: 2,083,333 +4.2% SPI_QUARTER_SPEED
+#define SPI_CLOCK_DIV16 1000000 //(SCR: 24) desired: 1,000,000 actual: 1,000,000 SPI_EIGHTH_SPEED
+#define SPI_CLOCK_DIV32 500000 //(SCR: 49) desired: 500,000 actual: 500,000 SPI_SPEED_5
+#define SPI_CLOCK_DIV64 250000 //(SCR: 99) desired: 250,000 actual: 250,000 SPI_SPEED_6
+#define SPI_CLOCK_DIV128 125000 //(SCR:199) desired: 125,000 actual: 125,000 Default from HAL.h
+
+#define SPI_CLOCK_MAX SPI_CLOCK_DIV2
+
+#define BOARD_NR_SPI 2
+
+//#define BOARD_SPI1_NSS_PIN PA4 ?!
+#define BOARD_SPI1_SCK_PIN P0_15
+#define BOARD_SPI1_MISO_PIN P0_17
+#define BOARD_SPI1_MOSI_PIN P0_18
+
+//#define BOARD_SPI2_NSS_PIN PB12 ?!
+#define BOARD_SPI2_SCK_PIN P0_07
+#define BOARD_SPI2_MISO_PIN P0_08
+#define BOARD_SPI2_MOSI_PIN P0_09
class SPISettings {
- public:
- SPISettings(uint32_t speed, int, int) : spi_speed(speed) {};
- uint32_t spiRate() { return spi_speed; }
- private:
- uint32_t spi_speed;
+public:
+ SPISettings(uint32_t speed, int, int) : spi_speed(speed) {};
+ SPISettings(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
+ if (__builtin_constant_p(inClock))
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
+ else
+ init_MightInline(inClock, inBitOrder, inDataMode, inDataSize);
+ }
+ SPISettings() {
+ init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT);
+ }
+
+ uint32_t spiRate() const { return spi_speed; }
+
+private:
+ void init_MightInline(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) {
+ init_AlwaysInline(inClock, inBitOrder, inDataMode, inDataSize);
+ }
+ void init_AlwaysInline(uint32_t inClock, uint8_t inBitOrder, uint8_t inDataMode, uint32_t inDataSize) __attribute__((__always_inline__)) {
+ clock = inClock;
+ bitOrder = inBitOrder;
+ dataMode = inDataMode;
+ dataSize = inDataSize;
+ }
+
+ uint32_t spi_speed;
+ uint32_t clock;
+ uint32_t dataSize;
+ //uint32_t clockDivider;
+ uint8_t bitOrder;
+ uint8_t dataMode;
+ LPC_SSP_TypeDef *spi_d;
+
+ friend class SPIClass;
};
+/**
+ * @brief Wirish SPI interface.
+ *
+ * This is the same interface is available across HAL
+ *
+ * This implementation uses software slave management, so the caller
+ * is responsible for controlling the slave select line.
+ */
class SPIClass {
- public:
- void begin();
- void beginTransaction(SPISettings);
- void endTransaction() {};
- uint8_t transfer(uint8_t data);
- uint16_t transfer16(uint16_t data);
+public:
+ /**
+ * @param spiPortNumber Number of the SPI port to manage.
+ */
+ SPIClass(uint8_t spiPortNumber);
+
+ /**
+ * Select and configure the current selected SPI device to use
+ */
+ void begin();
+
+ /**
+ * Disable the current SPI device
+ */
+ void end();
+
+ void beginTransaction(const SPISettings&);
+ void endTransaction() {};
+
+ // Transfer using 1 "Data Size"
+ uint8_t transfer(uint16_t data);
+ // Transfer 2 bytes in 8 bit mode
+ uint16_t transfer16(uint16_t data);
+
+ void send(uint8_t data);
+
+ uint16_t read();
+ void read(uint8_t *buf, uint32_t len);
+
+ void dmaSend(void *buf, uint16_t length, bool minc);
+
+ /**
+ * @brief Sets the number of the SPI peripheral to be used by
+ * this HardwareSPI instance.
+ *
+ * @param spi_num Number of the SPI port. 1-2 in low density devices
+ * or 1-3 in high density devices.
+ */
+ void setModule(uint8_t device);
+
+ void setClock(uint32_t clock);
+ void setBitOrder(uint8_t bitOrder);
+ void setDataMode(uint8_t dataMode);
+ void setDataSize(uint32_t ds);
+
+ inline uint32_t getDataSize() { return _currentSetting->dataSize; }
+
+private:
+ SPISettings _settings[BOARD_NR_SPI];
+ SPISettings *_currentSetting;
+
+ void updateSettings();
};
extern SPIClass SPI;
diff --git a/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.c b/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.c
index 1e53be5f62..f442ab71c0 100644
--- a/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.c
+++ b/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.c
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.h b/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.h
index 6e9ad6f179..9b6c62b052 100644
--- a/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.h
+++ b/Marlin/src/HAL/LPC1768/include/digipot_mcp4451_I2C_routines.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/include/i2c_util.c b/Marlin/src/HAL/LPC1768/include/i2c_util.c
index b92f3f0453..e52fb7c4de 100644
--- a/Marlin/src/HAL/LPC1768/include/i2c_util.c
+++ b/Marlin/src/HAL/LPC1768/include/i2c_util.c
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/include/i2c_util.h b/Marlin/src/HAL/LPC1768/include/i2c_util.h
index eae275e0f9..a57f68a407 100644
--- a/Marlin/src/HAL/LPC1768/include/i2c_util.h
+++ b/Marlin/src/HAL/LPC1768/include/i2c_util.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/main.cpp b/Marlin/src/HAL/LPC1768/main.cpp
index d7b05dce9d..0b4045cb99 100644
--- a/Marlin/src/HAL/LPC1768/main.cpp
+++ b/Marlin/src/HAL/LPC1768/main.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef TARGET_LPC1768
@@ -38,8 +38,6 @@ extern "C" {
#include "../../sd/cardreader.h"
#include "../../inc/MarlinConfig.h"
#include "../../core/millis_t.h"
-#include "HAL.h"
-#include "timers.h"
extern uint32_t MSC_SD_Init(uint8_t pdrv);
extern "C" int isLPC1769();
@@ -124,7 +122,7 @@ void HAL_init() {
delay(1000); // Give OS time to notice
USB_Connect(TRUE);
- #if !BOTH(SHARED_SD_CARD, INIT_SDCARD_ON_BOOT) && DISABLED(NO_SD_HOST_DRIVE)
+ #if DISABLED(NO_SD_HOST_DRIVE)
MSC_SD_Init(0); // Enable USB SD card access
#endif
@@ -142,7 +140,7 @@ void HAL_init() {
// HAL idle task
void HAL_idletask() {
- #if ENABLED(SHARED_SD_CARD)
+ #if HAS_SHARED_MEDIA
// If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
diff --git a/Marlin/src/HAL/LPC1768/pinsDebug.h b/Marlin/src/HAL/LPC1768/pinsDebug.h
index 6cc824afa3..f80551604f 100644
--- a/Marlin/src/HAL/LPC1768/pinsDebug.h
+++ b/Marlin/src/HAL/LPC1768/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/spi_pins.h b/Marlin/src/HAL/LPC1768/spi_pins.h
index 9b983428bd..2e6749bf57 100644
--- a/Marlin/src/HAL/LPC1768/spi_pins.h
+++ b/Marlin/src/HAL/LPC1768/spi_pins.h
@@ -16,14 +16,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
#include "../../core/macros.h"
-#if ENABLED(SDSUPPORT) && HAS_GRAPHICAL_LCD && (LCD_PINS_D4 == SCK_PIN || LCD_PINS_ENABLE == MOSI_PIN || DOGLCD_SCK == SCK_PIN || DOGLCD_MOSI == MOSI_PIN)
+#if BOTH(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 required for communicating with each device being different.
// This requirement can be removed if the SPI access to these devices is updated to use
diff --git a/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp b/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp
new file mode 100644
index 0000000000..84907acd07
--- /dev/null
+++ b/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp
@@ -0,0 +1,153 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_SPI_TFT
+
+#include "tft_spi.h"
+
+//TFT_SPI tft;
+
+SPIClass TFT_SPI::SPIx(1);
+
+#define TFT_CS_H WRITE(TFT_CS_PIN, HIGH)
+#define TFT_CS_L WRITE(TFT_CS_PIN, LOW)
+
+#define TFT_DC_H WRITE(TFT_DC_PIN, HIGH)
+#define TFT_DC_L WRITE(TFT_DC_PIN, LOW)
+
+#define TFT_RST_H WRITE(TFT_RESET_PIN, HIGH)
+#define TFT_RST_L WRITE(TFT_RESET_PIN, LOW)
+
+#define TFT_BLK_H WRITE(TFT_BACKLIGHT_PIN, HIGH)
+#define TFT_BLK_L WRITE(TFT_BACKLIGHT_PIN, LOW)
+
+void TFT_SPI::Init() {
+ #if PIN_EXISTS(TFT_RESET)
+ SET_OUTPUT(TFT_RESET_PIN);
+ TFT_RST_H;
+ delay(100);
+ #endif
+
+ #if PIN_EXISTS(TFT_BACKLIGHT)
+ SET_OUTPUT(TFT_BACKLIGHT_PIN);
+ TFT_BLK_H;
+ #endif
+
+ SET_OUTPUT(TFT_DC_PIN);
+ SET_OUTPUT(TFT_CS_PIN);
+
+ TFT_DC_H;
+ TFT_CS_H;
+
+ /**
+ * 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 0
+ #if SPI_DEVICE == 1
+ #define SPI_CLOCK_MAX SPI_CLOCK_DIV4
+ #else
+ #define SPI_CLOCK_MAX SPI_CLOCK_DIV2
+ #endif
+ uint8_t clock;
+ uint8_t spiRate = SPI_FULL_SPEED;
+ switch (spiRate) {
+ 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
+ }
+ #endif
+
+ #if TFT_MISO_PIN == BOARD_SPI1_MISO_PIN
+ SPIx.setModule(1);
+ #elif TFT_MISO_PIN == BOARD_SPI2_MISO_PIN
+ SPIx.setModule(2);
+ #endif
+ SPIx.setClock(SPI_CLOCK_MAX);
+ SPIx.setBitOrder(MSBFIRST);
+ SPIx.setDataMode(SPI_MODE0);
+}
+
+void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
+ SPIx.setDataSize(DataSize);
+ SPIx.begin();
+ TFT_CS_L;
+}
+
+uint32_t TFT_SPI::GetID() {
+ uint32_t id;
+ id = ReadID(LCD_READ_ID);
+ if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
+ id = ReadID(LCD_READ_ID4);
+ return id;
+}
+
+uint32_t TFT_SPI::ReadID(uint16_t Reg) {
+ uint32_t data = 0;
+
+ #if PIN_EXISTS(TFT_MISO)
+ uint8_t d = 0;
+ SPIx.setDataSize(DATASIZE_8BIT);
+ SPIx.setClock(SPI_CLOCK_DIV64);
+ SPIx.begin();
+ TFT_CS_L;
+ WriteReg(Reg);
+
+ LOOP_L_N(i, 4) {
+ SPIx.read((uint8_t*)&d, 1);
+ data = (data << 8) | d;
+ }
+
+ DataTransferEnd();
+ SPIx.setClock(SPI_CLOCK_MAX);
+ #endif
+
+ return data >> 7;
+}
+
+bool TFT_SPI::isBusy() {
+ return false;
+}
+
+void TFT_SPI::Abort() {
+ DataTransferEnd();
+}
+
+void TFT_SPI::Transmit(uint16_t Data) {
+ SPIx.transfer(Data);
+}
+
+void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
+ DataTransferBegin(DATASIZE_16BIT); //16
+ TFT_DC_H;
+ SPIx.dmaSend(Data, Count, MemoryIncrease);
+ DataTransferEnd();
+}
+
+#endif // HAS_SPI_TFT
diff --git a/Marlin/src/HAL/LPC1768/tft/tft_spi.h b/Marlin/src/HAL/LPC1768/tft/tft_spi.h
new file mode 100644
index 0000000000..8d3e3127bb
--- /dev/null
+++ b/Marlin/src/HAL/LPC1768/tft/tft_spi.h
@@ -0,0 +1,77 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "../../../inc/MarlinConfig.h"
+
+#include
+#include
+// #include
+
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
+#ifndef LCD_READ_ID4
+ #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
+#endif
+
+#define DATASIZE_8BIT SSP_DATABIT_8
+#define DATASIZE_16BIT SSP_DATABIT_16
+#define TFT_IO TFT_SPI
+
+#define DMA_MINC_ENABLE 1
+#define DMA_MINC_DISABLE 0
+
+class TFT_SPI {
+private:
+ static uint32_t ReadID(uint16_t Reg);
+ static void Transmit(uint16_t Data);
+ static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
+
+public:
+ static SPIClass SPIx;
+
+ static void Init();
+ static uint32_t GetID();
+ static bool isBusy();
+ static void Abort();
+
+ static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT);
+ static void DataTransferEnd() { OUT_WRITE(TFT_CS_PIN, HIGH); SPIx.end(); };
+ static void DataTransferAbort();
+
+ static void WriteData(uint16_t Data) { Transmit(Data); }
+ static void WriteReg(uint16_t Reg) { OUT_WRITE(TFT_A0_PIN, LOW); Transmit(Reg); OUT_WRITE(TFT_A0_PIN, HIGH); }
+
+ static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
+ // static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint32_t Count) {
+ static uint16_t Data; Data = Color;
+ //LPC dma can only write 0xFFF bytes at once.
+ #define MAX_DMA_SIZE (0xFFF - 1)
+ while (Count > 0) {
+ TransmitDMA(DMA_MINC_DISABLE, &Data, Count > MAX_DMA_SIZE ? MAX_DMA_SIZE : Count);
+ Count = Count > MAX_DMA_SIZE ? Count - MAX_DMA_SIZE : 0;
+ }
+ #undef MAX_DMA_SIZE
+ }
+};
diff --git a/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp b/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp
new file mode 100644
index 0000000000..c72e5f0eac
--- /dev/null
+++ b/Marlin/src/HAL/LPC1768/tft/xpt2046.cpp
@@ -0,0 +1,129 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046
+
+#include "xpt2046.h"
+#include
+
+uint16_t delta(uint16_t a, uint16_t b) { return a > b ? a - b : b - a; }
+
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ #include
+
+ SPIClass XPT2046::SPIx(TOUCH_BUTTONS_HW_SPI_DEVICE);
+
+ static void touch_spi_init(uint8_t spiRate) {
+ XPT2046::SPIx.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
+ XPT2046::SPIx.setClock(SPI_CLOCK_DIV128);
+ XPT2046::SPIx.setBitOrder(MSBFIRST);
+ XPT2046::SPIx.setDataMode(SPI_MODE0);
+ XPT2046::SPIx.setDataSize(DATA_SIZE_8BIT);
+ }
+#endif
+
+void XPT2046::Init() {
+ SET_INPUT(TOUCH_MISO_PIN);
+ SET_OUTPUT(TOUCH_MOSI_PIN);
+ SET_OUTPUT(TOUCH_SCK_PIN);
+ OUT_WRITE(TOUCH_CS_PIN, HIGH);
+
+ #if PIN_EXISTS(TOUCH_INT)
+ // Optional Pendrive interrupt pin
+ SET_INPUT(TOUCH_INT_PIN);
+ #endif
+
+ TERN_(TOUCH_BUTTONS_HW_SPI, touch_spi_init(SPI_SPEED_6));
+
+ // Read once to enable pendrive status pin
+ getRawData(XPT2046_X);
+}
+
+bool XPT2046::isTouched() {
+ return isBusy() ? false : (
+ #if PIN_EXISTS(TOUCH_INT)
+ READ(TOUCH_INT_PIN) != HIGH
+ #else
+ getRawData(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
+ #endif
+ );
+}
+
+bool XPT2046::getRawPoint(int16_t *x, int16_t *y) {
+ if (isBusy()) return false;
+ if (!isTouched()) return false;
+ *x = getRawData(XPT2046_X);
+ *y = getRawData(XPT2046_Y);
+ SERIAL_ECHOLNPAIR("X: ", *x, ", Y: ", *y);
+ return isTouched();
+}
+
+uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) {
+ uint16_t data[3];
+
+ DataTransferBegin();
+ TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.begin());
+
+ for (uint16_t i = 0; i < 3 ; i++) {
+ IO(coordinate);
+ data[i] = (IO() << 4) | (IO() >> 4);
+ }
+
+ TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.end());
+ DataTransferEnd();
+
+ uint16_t delta01 = delta(data[0], data[1]),
+ delta02 = delta(data[0], data[2]),
+ delta12 = delta(data[1], data[2]);
+
+ if (delta01 > delta02 || delta01 > delta12)
+ data[delta02 > delta12 ? 0 : 1] = data[2];
+
+ return (data[0] + data[1]) >> 1;
+}
+
+uint16_t XPT2046::IO(uint16_t data) {
+ return TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data);
+}
+
+extern uint8_t spiTransfer(uint8_t b);
+
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ uint16_t XPT2046::HardwareIO(uint16_t data) {
+ return SPIx.transfer(data & 0xFF);
+ }
+#endif
+
+uint16_t XPT2046::SoftwareIO(uint16_t data) {
+ uint16_t result = 0;
+
+ for (uint8_t j = 0x80; j; j >>= 1) {
+ WRITE(TOUCH_SCK_PIN, LOW);
+ WRITE(TOUCH_MOSI_PIN, data & j ? HIGH : LOW);
+ if (READ(TOUCH_MISO_PIN)) result |= j;
+ WRITE(TOUCH_SCK_PIN, HIGH);
+ }
+ WRITE(TOUCH_SCK_PIN, LOW);
+
+ return result;
+}
+
+#endif // HAS_TFT_XPT2046
diff --git a/Marlin/src/HAL/LPC1768/tft/xpt2046.h b/Marlin/src/HAL/LPC1768/tft/xpt2046.h
new file mode 100644
index 0000000000..019f75efce
--- /dev/null
+++ b/Marlin/src/HAL/LPC1768/tft/xpt2046.h
@@ -0,0 +1,80 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ #include
+#endif
+
+#ifndef TOUCH_MISO_PIN
+ #define TOUCH_MISO_PIN MISO_PIN
+#endif
+#ifndef TOUCH_MOSI_PIN
+ #define TOUCH_MOSI_PIN MOSI_PIN
+#endif
+#ifndef TOUCH_SCK_PIN
+ #define TOUCH_SCK_PIN SCK_PIN
+#endif
+#ifndef TOUCH_CS_PIN
+ #define TOUCH_CS_PIN CS_PIN
+#endif
+#ifndef TOUCH_INT_PIN
+ #define TOUCH_INT_PIN -1
+#endif
+
+#define XPT2046_DFR_MODE 0x00
+#define XPT2046_SER_MODE 0x04
+#define XPT2046_CONTROL 0x80
+
+enum XPTCoordinate : uint8_t {
+ XPT2046_X = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Y = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+};
+
+#if !defined(XPT2046_Z1_THRESHOLD)
+ #define XPT2046_Z1_THRESHOLD 10
+#endif
+
+class XPT2046 {
+private:
+ static bool isBusy() { return false; }
+
+ static uint16_t getRawData(const XPTCoordinate coordinate);
+ static bool isTouched();
+
+ static inline void DataTransferBegin() { WRITE(TOUCH_CS_PIN, LOW); };
+ static inline void DataTransferEnd() { WRITE(TOUCH_CS_PIN, HIGH); };
+ #if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ static uint16_t HardwareIO(uint16_t data);
+ #endif
+ static uint16_t SoftwareIO(uint16_t data);
+ static uint16_t IO(uint16_t data = 0);
+
+public:
+ #if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ static SPIClass SPIx;
+ #endif
+
+ static void Init();
+ static bool getRawPoint(int16_t *x, int16_t *y);
+};
diff --git a/Marlin/src/HAL/LPC1768/timers.cpp b/Marlin/src/HAL/LPC1768/timers.cpp
index 686b251c69..a7a40584da 100644
--- a/Marlin/src/HAL/LPC1768/timers.cpp
+++ b/Marlin/src/HAL/LPC1768/timers.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -29,7 +29,6 @@
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
-#include "timers.h"
void HAL_timer_init() {
SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
diff --git a/Marlin/src/HAL/LPC1768/timers.h b/Marlin/src/HAL/LPC1768/timers.h
index 30da933521..23dc20e2eb 100644
--- a/Marlin/src/HAL/LPC1768/timers.h
+++ b/Marlin/src/HAL/LPC1768/timers.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -61,10 +61,18 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE ((F_CPU) / 4) // frequency of timers peripherals
-#define STEP_TIMER_NUM 0 // Timer Index for Stepper
-#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
-#define PWM_TIMER_NUM 3 // Timer Index for PWM
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
+#ifndef PWM_TIMER_NUM
+ #define PWM_TIMER_NUM 3 // Timer Index for PWM
+#endif
#define TEMP_TIMER_RATE 1000000
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -84,12 +92,16 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() _HAL_TIMER_ISR(STEP_TIMER_NUM)
-#define HAL_TEMP_TIMER_ISR() _HAL_TIMER_ISR(TEMP_TIMER_NUM)
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() _HAL_TIMER_ISR(STEP_TIMER_NUM)
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() _HAL_TIMER_ISR(TEMP_TIMER_NUM)
+#endif
// Timer references by index
-#define STEP_TIMER _HAL_TIMER(STEP_TIMER_NUM)
-#define TEMP_TIMER _HAL_TIMER(TEMP_TIMER_NUM)
+#define STEP_TIMER_PTR _HAL_TIMER(STEP_TIMER_NUM)
+#define TEMP_TIMER_PTR _HAL_TIMER(TEMP_TIMER_NUM)
// ------------------------
// Public functions
@@ -99,23 +111,23 @@ 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) {
switch (timer_num) {
- case 0: STEP_TIMER->MR0 = compare; break; // Stepper Timer Match Register 0
- case 1: TEMP_TIMER->MR0 = compare; break; // Temp Timer Match Register 0
+ case 0: STEP_TIMER_PTR->MR0 = compare; break; // Stepper Timer Match Register 0
+ case 1: TEMP_TIMER_PTR->MR0 = compare; break; // Temp Timer Match Register 0
}
}
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
switch (timer_num) {
- case 0: return STEP_TIMER->MR0; // Stepper Timer Match Register 0
- case 1: return TEMP_TIMER->MR0; // Temp Timer Match Register 0
+ case 0: return STEP_TIMER_PTR->MR0; // Stepper Timer Match Register 0
+ case 1: return TEMP_TIMER_PTR->MR0; // Temp Timer Match Register 0
}
return 0;
}
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
switch (timer_num) {
- case 0: return STEP_TIMER->TC; // Stepper Timer Count
- case 1: return TEMP_TIMER->TC; // Temp Timer Count
+ case 0: return STEP_TIMER_PTR->TC; // Stepper Timer Count
+ case 1: return TEMP_TIMER_PTR->TC; // Temp Timer Count
}
return 0;
}
@@ -154,8 +166,8 @@ FORCE_INLINE static bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
switch (timer_num) {
- case 0: SBI(STEP_TIMER->IR, SBIT_CNTEN); break;
- case 1: SBI(TEMP_TIMER->IR, SBIT_CNTEN); break;
+ case 0: SBI(STEP_TIMER_PTR->IR, SBIT_CNTEN); break;
+ case 1: SBI(TEMP_TIMER_PTR->IR, SBIT_CNTEN); break;
}
}
diff --git a/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.cpp b/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.cpp
index 6d643f5bf6..a48a820dc4 100644
--- a/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.cpp
+++ b/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.h b/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.h
index 9de3e93274..2d976c92d2 100644
--- a/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.h
+++ b/Marlin/src/HAL/LPC1768/u8g/LCD_I2C_routines.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/u8g/LCD_defines.h b/Marlin/src/HAL/LPC1768/u8g/LCD_defines.h
index e7518d698a..d2260037b6 100644
--- a/Marlin/src/HAL/LPC1768/u8g/LCD_defines.h
+++ b/Marlin/src/HAL/LPC1768/u8g/LCD_defines.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/u8g/LCD_delay.h b/Marlin/src/HAL/LPC1768/u8g/LCD_delay.h
index 0d9b8d3dcc..0b9e2b4fd0 100644
--- a/Marlin/src/HAL/LPC1768/u8g/LCD_delay.h
+++ b/Marlin/src/HAL/LPC1768/u8g/LCD_delay.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.c b/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.c
index 67e78f36f0..466fc80203 100644
--- a/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.c
+++ b/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.c
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.h b/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.h
index 8a73b69ded..d60d93dadd 100644
--- a/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.h
+++ b/Marlin/src/HAL/LPC1768/u8g/LCD_pin_routines.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
index c0105bc129..befc348fab 100644
--- a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
+++ b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_hw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
index b99abb6867..f03be9ab34 100644
--- a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
+++ b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_ssd_hw_i2c.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
index 5f3da457aa..1500c22a0d 100644
--- a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
+++ b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_hw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
index a1f8097e52..10d8494162 100644
--- a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
+++ b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_st7920_sw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
index 6eac5daf24..4f52f7dd01 100644
--- a/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
+++ b/Marlin/src/HAL/LPC1768/u8g/u8g_com_HAL_LPC1768_sw_spi.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/LPC1768/usb_serial.cpp b/Marlin/src/HAL/LPC1768/usb_serial.cpp
index ddb31da20f..63a570efdf 100644
--- a/Marlin/src/HAL/LPC1768/usb_serial.cpp
+++ b/Marlin/src/HAL/LPC1768/usb_serial.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/HAL/LPC1768/watchdog.cpp b/Marlin/src/HAL/LPC1768/watchdog.cpp
index 73563a6baa..3cd22d6651 100644
--- a/Marlin/src/HAL/LPC1768/watchdog.cpp
+++ b/Marlin/src/HAL/LPC1768/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef TARGET_LPC1768
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/LPC1768/watchdog.h b/Marlin/src/HAL/LPC1768/watchdog.h
index e9e25e4f2a..cc170881f3 100644
--- a/Marlin/src/HAL/LPC1768/watchdog.h
+++ b/Marlin/src/HAL/LPC1768/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp
index b3a741fe13..9f24d30071 100644
--- a/Marlin/src/HAL/SAMD51/HAL.cpp
+++ b/Marlin/src/HAL/SAMD51/HAL.cpp
@@ -15,10 +15,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
@@ -29,71 +28,19 @@
// 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_TEMP_ADC_6
- #define GET_TEMP_6_ADC() PIN_TO_ADC(TEMP_6_PIN)
-#else
- #define GET_TEMP_6_ADC() -1
-#endif
-#if HAS_TEMP_ADC_7
- #define GET_TEMP_7_ADC() PIN_TO_ADC(TEMP_7_PIN)
-#else
- #define GET_TEMP_7_ADC() -1
-#endif
-#if HAS_TEMP_PROBE
- #define GET_PROBE_ADC() PIN_TO_ADC(TEMP_PROBE_PIN)
-#else
- #define GET_PROBE_ADC() -1
-#endif
-#if HAS_TEMP_ADC_BED
- #define GET_BED_ADC() PIN_TO_ADC(TEMP_BED_PIN)
-#else
- #define GET_BED_ADC() -1
-#endif
-#if HAS_TEMP_ADC_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 GET_TEMP_0_ADC() TERN(HAS_TEMP_ADC_0, PIN_TO_ADC(TEMP_0_PIN), -1)
+#define GET_TEMP_1_ADC() TERN(HAS_TEMP_ADC_1, PIN_TO_ADC(TEMP_1_PIN), -1)
+#define GET_TEMP_2_ADC() TERN(HAS_TEMP_ADC_2, PIN_TO_ADC(TEMP_2_PIN), -1)
+#define GET_TEMP_3_ADC() TERN(HAS_TEMP_ADC_3, PIN_TO_ADC(TEMP_3_PIN), -1)
+#define GET_TEMP_4_ADC() TERN(HAS_TEMP_ADC_4, PIN_TO_ADC(TEMP_4_PIN), -1)
+#define GET_TEMP_5_ADC() TERN(HAS_TEMP_ADC_5, PIN_TO_ADC(TEMP_5_PIN), -1)
+#define GET_TEMP_6_ADC() TERN(HAS_TEMP_ADC_6, PIN_TO_ADC(TEMP_6_PIN), -1)
+#define GET_TEMP_7_ADC() TERN(HAS_TEMP_ADC_7, PIN_TO_ADC(TEMP_7_PIN), -1)
+#define GET_PROBE_ADC() TERN(HAS_TEMP_PROBE, PIN_TO_ADC(TEMP_PROBE_PIN), -1)
+#define GET_BED_ADC() TERN(HAS_TEMP_ADC_BED, PIN_TO_ADC(TEMP_BED_PIN), -1)
+#define GET_CHAMBER_ADC() TERN(HAS_TEMP_ADC_CHAMBER, PIN_TO_ADC(TEMP_CHAMBER_PIN), -1)
+#define GET_FILAMENT_WIDTH_ADC() TERN(FILAMENT_WIDTH_SENSOR, PIN_TO_ADC(FILWIDTH_PIN), -1)
+#define GET_BUTTONS_ADC() TERN(HAS_ADC_BUTTONS, PIN_TO_ADC(ADC_KEYPAD_PIN), -1)
#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 \
@@ -105,21 +52,22 @@
|| 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
+#if IS_ADC_REQUIRED(0)
+ #define ADC0_IS_REQUIRED 1
#define FIRST_ADC 0
#else
#define FIRST_ADC 1
#endif
-#if ADC1_IS_REQUIRED
+#if IS_ADC_REQUIRED(1)
+ #define ADC1_IS_REQUIRED 1
#define LAST_ADC 1
#else
#define LAST_ADC 0
#endif
-
-#define DMA_IS_REQUIRED ADC_IS_REQUIRED
+#if ADC0_IS_REQUIRED || ADC1_IS_REQUIRED
+ #define ADC_IS_REQUIRED 1
+ #define DMA_IS_REQUIRED 1
+#endif
// ------------------------
// Types
@@ -423,9 +371,7 @@ uint16_t HAL_adc_result;
// HAL initialization task
void HAL_init() {
- #if DMA_IS_REQUIRED
- dma_init();
- #endif
+ TERN_(DMA_IS_REQUIRED, dma_init());
#if ENABLED(SDSUPPORT)
#if SD_CONNECTION_IS(ONBOARD) && PIN_EXISTS(SD_DETECT)
SET_INPUT_PULLUP(SD_DETECT_PIN);
diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h
index f2ee02a22f..ea0f694cdc 100644
--- a/Marlin/src/HAL/SAMD51/HAL.h
+++ b/Marlin/src/HAL/SAMD51/HAL.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -27,7 +27,6 @@
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
#include "MarlinSerial_AGCM4.h"
@@ -113,12 +112,6 @@ typedef int8_t pin_t;
void HAL_clear_reset_source(); // clear reset reason
uint8_t HAL_get_reset_source(); // get reset reason
-//
-// EEPROM
-//
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-
//
// ADC
//
@@ -129,13 +122,13 @@ extern uint16_t HAL_adc_result; // Most recent ADC conversion
void HAL_adc_init();
//#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values.
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10 // ... 12
#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
-inline uint16_t HAL_adc_get_result() { return HAL_adc_result; }
//
// Pin Map
diff --git a/Marlin/src/HAL/SAMD51/HAL_SPI.cpp b/Marlin/src/HAL/SAMD51/HAL_SPI.cpp
index 83226daa48..c3acd38237 100644
--- a/Marlin/src/HAL/SAMD51/HAL_SPI.cpp
+++ b/Marlin/src/HAL/SAMD51/HAL_SPI.cpp
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp b/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp
index f13b29555a..abc5f3acbf 100644
--- a/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp
+++ b/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.cpp
@@ -15,10 +15,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
/**
diff --git a/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.h b/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.h
index a9eb0470a2..f3821d8d5a 100644
--- a/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.h
+++ b/Marlin/src/HAL/SAMD51/MarlinSerial_AGCM4.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/QSPIFlash.cpp b/Marlin/src/HAL/SAMD51/QSPIFlash.cpp
index 76a3329707..161c04084f 100644
--- a/Marlin/src/HAL/SAMD51/QSPIFlash.cpp
+++ b/Marlin/src/HAL/SAMD51/QSPIFlash.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/SAMD51/QSPIFlash.h b/Marlin/src/HAL/SAMD51/QSPIFlash.h
index 7f75286ebf..b6f22769ff 100644
--- a/Marlin/src/HAL/SAMD51/QSPIFlash.h
+++ b/Marlin/src/HAL/SAMD51/QSPIFlash.h
@@ -29,7 +29,7 @@
#pragma once
-#include "Adafruit_SPIFlashBase.h"
+#include
// This class extends Adafruit_SPIFlashBase by adding caching support.
//
diff --git a/Marlin/src/HAL/SAMD51/SAMD51.h b/Marlin/src/HAL/SAMD51/SAMD51.h
index ef84a20820..783956140d 100644
--- a/Marlin/src/HAL/SAMD51/SAMD51.h
+++ b/Marlin/src/HAL/SAMD51/SAMD51.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/Servo.cpp b/Marlin/src/HAL/SAMD51/Servo.cpp
index b39869ef32..9bab8e89be 100644
--- a/Marlin/src/HAL/SAMD51/Servo.cpp
+++ b/Marlin/src/HAL/SAMD51/Servo.cpp
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -29,11 +29,9 @@
#if HAS_SERVOS
-#include "../shared/Marduino.h"
#include "../shared/servo.h"
#include "../shared/servo_private.h"
#include "SAMD51.h"
-#include "timers.h"
#define __TC_GCLK_ID(t) TC##t##_GCLK_ID
#define _TC_GCLK_ID(t) __TC_GCLK_ID(t)
@@ -55,7 +53,7 @@
static volatile int8_t currentServoIndex[_Nbr_16timers]; // index for the servo being pulsed for each timer (or -1 if refresh interval)
FORCE_INLINE static uint16_t getTimerCount() {
- Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ Tc * const tc = TimerConfig[SERVO_TC].pTc;
tc->COUNT16.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
SYNC(tc->COUNT16.SYNCBUSY.bit.CTRLB || tc->COUNT16.SYNCBUSY.bit.COUNT);
@@ -67,7 +65,7 @@ FORCE_INLINE static uint16_t getTimerCount() {
// Interrupt handler for the TC
// ----------------------------
HAL_SERVO_TIMER_ISR() {
- Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ Tc * const tc = TimerConfig[SERVO_TC].pTc;
const timer16_Sequence_t timer =
#ifndef _useTimer1
_timer2
@@ -127,7 +125,7 @@ HAL_SERVO_TIMER_ISR() {
}
void initISR(timer16_Sequence_t timer) {
- Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ Tc * const tc = TimerConfig[SERVO_TC].pTc;
const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
static bool initialized = false; // Servo TC has been initialized
@@ -204,7 +202,7 @@ void initISR(timer16_Sequence_t timer) {
}
void finISR(timer16_Sequence_t timer) {
- Tc * const tc = TimerConfig[SERVO_TC].pTimer;
+ Tc * const tc = TimerConfig[SERVO_TC].pTc;
const uint8_t tcChannel = TIMER_TCCHANNEL(timer);
// Disable the match channel interrupt request
diff --git a/Marlin/src/HAL/SAMD51/ServoTimers.h b/Marlin/src/HAL/SAMD51/ServoTimers.h
index 3572c608d2..948d515356 100644
--- a/Marlin/src/HAL/SAMD51/ServoTimers.h
+++ b/Marlin/src/HAL/SAMD51/ServoTimers.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/eeprom_flash.cpp b/Marlin/src/HAL/SAMD51/eeprom_flash.cpp
index fd8973369a..429ef1c2d4 100644
--- a/Marlin/src/HAL/SAMD51/eeprom_flash.cpp
+++ b/Marlin/src/HAL/SAMD51/eeprom_flash.cpp
@@ -15,10 +15,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/SAMD51/eeprom_qspi.cpp b/Marlin/src/HAL/SAMD51/eeprom_qspi.cpp
index c6aa383f9f..b403f7939f 100644
--- a/Marlin/src/HAL/SAMD51/eeprom_qspi.cpp
+++ b/Marlin/src/HAL/SAMD51/eeprom_qspi.cpp
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __SAMD51__
diff --git a/Marlin/src/HAL/SAMD51/eeprom.cpp b/Marlin/src/HAL/SAMD51/eeprom_wired.cpp
similarity index 76%
rename from Marlin/src/HAL/SAMD51/eeprom.cpp
rename to Marlin/src/HAL/SAMD51/eeprom_wired.cpp
index e167515bff..3283195897 100644
--- a/Marlin/src/HAL/SAMD51/eeprom.cpp
+++ b/Marlin/src/HAL/SAMD51/eeprom_wired.cpp
@@ -15,21 +15,29 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS) && NONE(QSPI_EEPROM, FLASH_EEPROM_EMULATION)
+#if USE_WIRED_EEPROM
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with simple implementations supplied by Marlin.
+ */
+
+#include "../shared/eeprom_if.h"
#include "../shared/eeprom_api.h"
-size_t PersistentStore::capacity() { return E2END + 1; }
+#ifndef MARLIN_EEPROM_SIZE
+ #error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
-bool PersistentStore::access_start() { return true; }
+bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
@@ -62,5 +70,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-#endif // EEPROM_SETTINGS && !(QSPI_EEPROM || FLASH_EEPROM_EMULATION)
+#endif // USE_WIRED_EEPROM
#endif // __SAMD51__
diff --git a/Marlin/src/HAL/SAMD51/endstop_interrupts.h b/Marlin/src/HAL/SAMD51/endstop_interrupts.h
index 4c8f441ce2..daac773387 100644
--- a/Marlin/src/HAL/SAMD51/endstop_interrupts.h
+++ b/Marlin/src/HAL/SAMD51/endstop_interrupts.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -126,82 +126,83 @@
void endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
+ #define _ATTACH(P) attachInterrupt(P, endstop_ISR, CHANGE)
#if HAS_X_MAX
#if !AVAILABLE_EILINE(X_MAX_PIN)
#error "X_MAX_PIN has no EXTINT line available."
#endif
- attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
+ _ATTACH(X_MAX_PIN);
#endif
#if HAS_X_MIN
#if !AVAILABLE_EILINE(X_MIN_PIN)
#error "X_MIN_PIN has no EXTINT line available."
#endif
- attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
+ _ATTACH(X_MIN_PIN);
#endif
#if HAS_Y_MAX
#if !AVAILABLE_EILINE(Y_MAX_PIN)
#error "Y_MAX_PIN has no EXTINT line available."
#endif
- attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Y_MAX_PIN);
#endif
#if HAS_Y_MIN
#if !AVAILABLE_EILINE(Y_MIN_PIN)
#error "Y_MIN_PIN has no EXTINT line available."
#endif
- attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Y_MIN_PIN);
#endif
#if HAS_Z_MAX
#if !AVAILABLE_EILINE(Z_MAX_PIN)
#error "Z_MAX_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z_MAX_PIN);
#endif
#if HAS_Z_MIN
#if !AVAILABLE_EILINE(Z_MIN_PIN)
#error "Z_MIN_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PIN);
#endif
#if HAS_Z2_MAX
#if !AVAILABLE_EILINE(Z2_MAX_PIN)
#error "Z2_MAX_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z2_MAX_PIN);
#endif
#if HAS_Z2_MIN
#if !AVAILABLE_EILINE(Z2_MIN_PIN)
#error "Z2_MIN_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z2_MIN_PIN);
#endif
#if HAS_Z3_MAX
#if !AVAILABLE_EILINE(Z3_MAX_PIN)
#error "Z3_MAX_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z3_MAX_PIN);
#endif
#if HAS_Z3_MIN
#if !AVAILABLE_EILINE(Z3_MIN_PIN)
#error "Z3_MIN_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z3_MIN_PIN);
#endif
#if HAS_Z4_MAX
#if !AVAILABLE_EILINE(Z4_MAX_PIN)
#error "Z4_MAX_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z4_MAX_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z4_MAX_PIN);
#endif
#if HAS_Z4_MIN
#if !AVAILABLE_EILINE(Z4_MIN_PIN)
#error "Z4_MIN_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z4_MIN_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z4_MIN_PIN);
#endif
#if HAS_Z_MIN_PROBE_PIN
#if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
#error "Z_MIN_PROBE_PIN has no EXTINT line available."
#endif
- attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
+ _ATTACH(Z_MIN_PROBE_PIN);
#endif
}
diff --git a/Marlin/src/HAL/SAMD51/fastio.h b/Marlin/src/HAL/SAMD51/fastio.h
index d3b3dc1f63..c456dfce30 100644
--- a/Marlin/src/HAL/SAMD51/fastio.h
+++ b/Marlin/src/HAL/SAMD51/fastio.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/inc/Conditionals_LCD.h b/Marlin/src/HAL/SAMD51/inc/Conditionals_LCD.h
index 0285c52ee3..932348c52f 100644
--- a/Marlin/src/HAL/SAMD51/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/SAMD51/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/SAMD51."
+#endif
diff --git a/Marlin/src/HAL/SAMD51/inc/Conditionals_adv.h b/Marlin/src/HAL/SAMD51/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/SAMD51/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/SAMD51/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h b/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h
index 490cfd50e8..ce6d3fdde2 100644
--- a/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/SAMD51/inc/Conditionals_post.h
@@ -16,11 +16,13 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-#if USE_FALLBACK_EEPROM && NONE(SDCARD_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
+#if USE_FALLBACK_EEPROM
#define FLASH_EEPROM_EMULATION
+#elif EITHER(I2C_EEPROM, SPI_EEPROM)
+ #define USE_SHARED_EEPROM 1
#endif
diff --git a/Marlin/src/HAL/SAMD51/inc/SanityCheck.h b/Marlin/src/HAL/SAMD51/inc/SanityCheck.h
index cc7a10e7a6..5d610acac8 100644
--- a/Marlin/src/HAL/SAMD51/inc/SanityCheck.h
+++ b/Marlin/src/HAL/SAMD51/inc/SanityCheck.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -35,6 +35,10 @@
#error "OnBoard SPI BUS can't be shared with other devices."
#endif
+#if SERVO_TC == RTC_TIMER_NUM
+ #error "Servos can't use RTC timer"
+#endif
+
#if ENABLED(EMERGENCY_PARSER)
#error "EMERGENCY_PARSER is not yet implemented for SAMD51. Disable EMERGENCY_PARSER to continue."
#endif
@@ -43,6 +47,6 @@
#error "SDIO_SUPPORT is not supported on SAMD51."
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on SAMD51."
#endif
diff --git a/Marlin/src/HAL/SAMD51/pinsDebug.h b/Marlin/src/HAL/SAMD51/pinsDebug.h
index 15b6473382..c28937d6c6 100644
--- a/Marlin/src/HAL/SAMD51/pinsDebug.h
+++ b/Marlin/src/HAL/SAMD51/pinsDebug.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/spi_pins.h b/Marlin/src/HAL/SAMD51/spi_pins.h
index 049aacb57a..5a9b1275ef 100644
--- a/Marlin/src/HAL/SAMD51/spi_pins.h
+++ b/Marlin/src/HAL/SAMD51/spi_pins.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/SAMD51/timers.cpp b/Marlin/src/HAL/SAMD51/timers.cpp
index 3eb021c25b..a68af2e074 100644
--- a/Marlin/src/HAL/SAMD51/timers.cpp
+++ b/Marlin/src/HAL/SAMD51/timers.cpp
@@ -15,17 +15,17 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __SAMD51__
// --------------------------------------------------------------------------
// Includes
// --------------------------------------------------------------------------
+
#include "../../inc/MarlinConfig.h"
-#include "timers.h"
+#include "ServoTimers.h" // for SERVO_TC
// --------------------------------------------------------------------------
// Local defines
@@ -38,15 +38,15 @@
// --------------------------------------------------------------------------
const tTimerConfig TimerConfig[NUM_HARDWARE_TIMERS+1] = {
- { {.pTc=TC0}, TC0_IRQn, TC_PRIORITY(0) }, // 0 - stepper
+ { {.pTc=TC0}, TC0_IRQn, TC_PRIORITY(0) }, // 0 - stepper (assigned priority 2)
{ {.pTc=TC1}, TC1_IRQn, TC_PRIORITY(1) }, // 1 - stepper (needed by 32 bit timers)
- { {.pTc=TC2}, TC2_IRQn, TC_PRIORITY(2) }, // 2 - tone (framework)
- { {.pTc=TC3}, TC3_IRQn, TC_PRIORITY(3) }, // 3 - servo
- { {.pTc=TC4}, TC4_IRQn, TC_PRIORITY(4) }, // 4 - software serial
+ { {.pTc=TC2}, TC2_IRQn, 5 }, // 2 - tone (reserved by framework and fixed assigned priority 5)
+ { {.pTc=TC3}, TC3_IRQn, TC_PRIORITY(3) }, // 3 - servo (assigned priority 1)
+ { {.pTc=TC4}, TC4_IRQn, TC_PRIORITY(4) }, // 4 - software serial (no interrupts used)
{ {.pTc=TC5}, TC5_IRQn, TC_PRIORITY(5) },
{ {.pTc=TC6}, TC6_IRQn, TC_PRIORITY(6) },
{ {.pTc=TC7}, TC7_IRQn, TC_PRIORITY(7) },
- { {.pRtc=RTC}, RTC_IRQn, TC_PRIORITY(8) } // 8 - temperature
+ { {.pRtc=RTC}, RTC_IRQn, TC_PRIORITY(8) } // 8 - temperature (assigned priority 6)
};
// --------------------------------------------------------------------------
@@ -121,14 +121,15 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
tc->COUNT32.CTRLA.bit.SWRST = true;
SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
- // Wave mode, reset counter on overflow on 0 (I use count down to prevent double buffer use)
+ // Wave mode, reset counter on compare match
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;
+ tc->COUNT32.CTRLBCLR.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;
+ tc->COUNT32.CC[0].reg = (HAL_TIMER_RATE) / frequency;
+ tc->COUNT32.COUNT.reg = 0;
// Enable interrupt on compare
tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF; // reset pending interrupt
diff --git a/Marlin/src/HAL/SAMD51/timers.h b/Marlin/src/HAL/SAMD51/timers.h
index 4b21e47162..dc6e38b730 100644
--- a/Marlin/src/HAL/SAMD51/timers.h
+++ b/Marlin/src/HAL/SAMD51/timers.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -32,9 +32,15 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE F_CPU // 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 TEMP_TIMER_NUM RTC_TIMER_NUM // index of timer to use for temperature
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM RTC_TIMER_NUM // Timer Index for Temperature
+#endif
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -53,20 +59,23 @@ typedef uint32_t hal_timer_t;
#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 \
+#define TC_PRIORITY(t) t == SERVO_TC ? 1 \
+ : (t == STEP_TIMER_NUM || t == PULSE_TIMER_NUM) ? 2 \
+ : (t == TEMP_TIMER_NUM) ? 6 \
: 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)
+#define _TC_HANDLER(t) void TC##t##_Handler()
+#define TC_HANDLER(t) _TC_HANDLER(t)
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() TC_HANDLER(STEP_TIMER_NUM)
+#endif
#if STEP_TIMER_NUM != PULSE_TIMER_NUM
- #define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
+ #define HAL_PULSE_TIMER_ISR() TC_HANDLER(PULSE_TIMER_NUM)
#endif
#if TEMP_TIMER_NUM == RTC_TIMER_NUM
- #define HAL_TEMP_TIMER_ISR() void RTC_Handler()
+ #define HAL_TEMP_TIMER_ISR() void RTC_Handler()
#else
- #define HAL_TEMP_TIMER_ISR() TC_HANDLER(TEMP_TIMER_NUM)
+ #define HAL_TEMP_TIMER_ISR() TC_HANDLER(TEMP_TIMER_NUM)
#endif
// --------------------------------------------------------------------------
@@ -97,13 +106,13 @@ 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) {
// Should never be called with timer RTC_TIMER_NUM
Tc * const tc = TimerConfig[timer_num].pTc;
- tc->COUNT32.CC[0].reg = HAL_TIMER_TYPE_MAX - compare;
+ tc->COUNT32.CC[0].reg = compare;
}
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
// Should never be called with timer RTC_TIMER_NUM
Tc * const tc = TimerConfig[timer_num].pTc;
- return (hal_timer_t)(HAL_TIMER_TYPE_MAX - tc->COUNT32.CC[0].reg);
+ return (hal_timer_t)tc->COUNT32.CC[0].reg;
}
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
@@ -111,7 +120,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
Tc * const tc = TimerConfig[timer_num].pTc;
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;
+ return tc->COUNT32.COUNT.reg;
}
void HAL_timer_enable_interrupt(const uint8_t timer_num);
diff --git a/Marlin/src/HAL/SAMD51/watchdog.cpp b/Marlin/src/HAL/SAMD51/watchdog.cpp
index 13539b4d70..ebc8dffe13 100644
--- a/Marlin/src/HAL/SAMD51/watchdog.cpp
+++ b/Marlin/src/HAL/SAMD51/watchdog.cpp
@@ -15,10 +15,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __SAMD51__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/SAMD51/watchdog.h b/Marlin/src/HAL/SAMD51/watchdog.h
index aa8ef35371..2cd4788229 100644
--- a/Marlin/src/HAL/SAMD51/watchdog.h
+++ b/Marlin/src/HAL/SAMD51/watchdog.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/HAL.cpp b/Marlin/src/HAL/STM32/HAL.cpp
index 77f8d27640..b1b727ce19 100644
--- a/Marlin/src/HAL/STM32/HAL.cpp
+++ b/Marlin/src/HAL/STM32/HAL.cpp
@@ -17,21 +17,17 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "HAL.h"
+#include "usb_serial.h"
#include "../../inc/MarlinConfig.h"
#include "../shared/Delay.h"
-#if HAS_TMC_SW_SERIAL
- #include "SoftwareSerial.h"
-#endif
-
#if ENABLED(SRAM_EEPROM_EMULATION)
#if STM32F7xx
#include
@@ -67,7 +63,7 @@ uint16_t HAL_adc_result;
void HAL_init() {
FastIO_init();
- #if ENABLED(SDSUPPORT)
+ #if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT)
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
#endif
@@ -76,20 +72,16 @@ void HAL_init() {
#endif
#if ENABLED(SRAM_EEPROM_EMULATION)
- // Enable access to backup SRAM
- __HAL_RCC_PWR_CLK_ENABLE();
- HAL_PWR_EnableBkUpAccess();
- __HAL_RCC_BKPSRAM_CLK_ENABLE();
-
- // Enable backup regulator
- LL_PWR_EnableBkUpRegulator();
- // Wait until backup regulator is initialized
- while (!LL_PWR_IsActiveFlag_BRR());
- #endif // EEPROM_EMULATED_SRAM
-
- #if HAS_TMC_SW_SERIAL
- SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0);
+ __HAL_RCC_PWR_CLK_ENABLE();
+ HAL_PWR_EnableBkUpAccess(); // Enable access to backup SRAM
+ __HAL_RCC_BKPSRAM_CLK_ENABLE();
+ LL_PWR_EnableBkUpRegulator(); // Enable backup regulator
+ while (!LL_PWR_IsActiveFlag_BRR()); // Wait until backup regulator is initialized
#endif
+
+ SetTimerInterruptPriorities();
+
+ TERN_(EMERGENCY_PARSER, USB_Hook_init());
}
void HAL_clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
diff --git a/Marlin/src/HAL/STM32/HAL.h b/Marlin/src/HAL/STM32/HAL.h
index c310cca74e..08081331b7 100644
--- a/Marlin/src/HAL/STM32/HAL.h
+++ b/Marlin/src/HAL/STM32/HAL.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -30,6 +30,7 @@
#include "../shared/HAL_SPI.h"
#include "fastio.h"
#include "watchdog.h"
+#include "MarlinSerial.h"
#include "../../inc/MarlinConfigPre.h"
@@ -48,17 +49,17 @@
#elif SERIAL_PORT == -1
#define MYSERIAL0 SerialUSB
#elif SERIAL_PORT == 1
- #define MYSERIAL0 Serial1
+ #define MYSERIAL0 MSerial1
#elif SERIAL_PORT == 2
- #define MYSERIAL0 Serial2
+ #define MYSERIAL0 MSerial2
#elif SERIAL_PORT == 3
- #define MYSERIAL0 Serial3
+ #define MYSERIAL0 MSerial3
#elif SERIAL_PORT == 4
- #define MYSERIAL0 Serial4
+ #define MYSERIAL0 MSerial4
#elif SERIAL_PORT == 5
- #define MYSERIAL0 Serial5
+ #define MYSERIAL0 MSerial5
#elif SERIAL_PORT == 6
- #define MYSERIAL0 Serial6
+ #define MYSERIAL0 MSerial6
#else
#error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
#endif
@@ -72,17 +73,17 @@
#elif SERIAL_PORT_2 == -1
#define MYSERIAL1 SerialUSB
#elif SERIAL_PORT_2 == 1
- #define MYSERIAL1 Serial1
+ #define MYSERIAL1 MSerial1
#elif SERIAL_PORT_2 == 2
- #define MYSERIAL1 Serial2
+ #define MYSERIAL1 MSerial2
#elif SERIAL_PORT_2 == 3
- #define MYSERIAL1 Serial3
+ #define MYSERIAL1 MSerial3
#elif SERIAL_PORT_2 == 4
- #define MYSERIAL1 Serial4
+ #define MYSERIAL1 MSerial4
#elif SERIAL_PORT_2 == 5
- #define MYSERIAL1 Serial5
+ #define MYSERIAL1 MSerial5
#elif SERIAL_PORT_2 == 6
- #define MYSERIAL1 Serial6
+ #define MYSERIAL1 MSerial6
#else
#error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
#endif
@@ -100,17 +101,17 @@
#elif DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL SerialUSB
#elif DGUS_SERIAL_PORT == 1
- #define DGUS_SERIAL Serial1
+ #define DGUS_SERIAL MSerial1
#elif DGUS_SERIAL_PORT == 2
- #define DGUS_SERIAL Serial2
+ #define DGUS_SERIAL MSerial2
#elif DGUS_SERIAL_PORT == 3
- #define DGUS_SERIAL Serial3
+ #define DGUS_SERIAL MSerial3
#elif DGUS_SERIAL_PORT == 4
- #define DGUS_SERIAL Serial4
+ #define DGUS_SERIAL MSerial4
#elif DGUS_SERIAL_PORT == 5
- #define DGUS_SERIAL Serial5
+ #define DGUS_SERIAL MSerial5
#elif DGUS_SERIAL_PORT == 6
- #define DGUS_SERIAL Serial6
+ #define DGUS_SERIAL MSerial6
#else
#error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
#endif
@@ -118,7 +119,6 @@
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
#endif
-#include "timers.h"
/**
* TODO: review this to return 1 for pins that are not analog input
@@ -191,16 +191,6 @@ static inline int freeMemory() {
#pragma GCC diagnostic pop
-//
-// EEPROM
-//
-
-// Wire library should work for i2c EEPROMs
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block(void *__dst, const void *__src, size_t __n);
-void eeprom_update_block(const void *__src, void *__dst, size_t __n);
-
//
// ADC
//
@@ -209,8 +199,9 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
inline void HAL_adc_init() {}
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
@@ -222,5 +213,10 @@ uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+#ifdef STM32F1xx
+ #define JTAG_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
+ #define JTAGSWD_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_DISABLE)
+#endif
+
#define PLATFORM_M997_SUPPORT
void flashFirmware(const int16_t);
diff --git a/Marlin/src/HAL/STM32/HAL_SPI.cpp b/Marlin/src/HAL/STM32/HAL_SPI.cpp
index 7b37fff9c2..202442a71b 100644
--- a/Marlin/src/HAL/STM32/HAL_SPI.cpp
+++ b/Marlin/src/HAL/STM32/HAL_SPI.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
diff --git a/Marlin/src/HAL/STM32/MarlinSerial.cpp b/Marlin/src/HAL/STM32/MarlinSerial.cpp
new file mode 100644
index 0000000000..8d99ab7855
--- /dev/null
+++ b/Marlin/src/HAL/STM32/MarlinSerial.cpp
@@ -0,0 +1,88 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+
+#include "../../inc/MarlinConfig.h"
+#include "MarlinSerial.h"
+
+#if ENABLED(EMERGENCY_PARSER)
+ #include "../../feature/e_parser.h"
+#endif
+
+#ifndef USART4
+ #define USART4 UART4
+#endif
+
+#ifndef USART5
+ #define USART5 UART5
+#endif
+
+#define DECLARE_SERIAL_PORT(ser_num) \
+ void _rx_complete_irq_ ## ser_num (serial_t * obj); \
+ MarlinSerial MSerial ## ser_num (USART ## ser_num, &_rx_complete_irq_ ## ser_num); \
+ void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); }
+
+#define DECLARE_SERIAL_PORT_EXP(ser_num) DECLARE_SERIAL_PORT(ser_num)
+
+#if defined(SERIAL_PORT) && SERIAL_PORT >= 0
+ DECLARE_SERIAL_PORT_EXP(SERIAL_PORT)
+#endif
+
+#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
+ DECLARE_SERIAL_PORT_EXP(SERIAL_PORT_2)
+#endif
+
+#if defined(DGUS_SERIAL_PORT) && DGUS_SERIAL_PORT >= 0
+ DECLARE_SERIAL_PORT_EXP(DGUS_SERIAL_PORT)
+#endif
+
+void MarlinSerial::begin(unsigned long baud, uint8_t config) {
+ HardwareSerial::begin(baud, config);
+ // replace the IRQ callback with the one we have defined
+ #if ENABLED(EMERGENCY_PARSER)
+ _serial.rx_callback = _rx_callback;
+ #endif
+}
+
+// This function is Copyright (c) 2006 Nicholas Zambetti.
+void MarlinSerial::_rx_complete_irq(serial_t *obj) {
+ // No Parity error, read byte and store it in the buffer if there is room
+ unsigned char c;
+
+ if (uart_getc(obj, &c) == 0) {
+
+ rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % SERIAL_RX_BUFFER_SIZE;
+
+ // if we should be storing the received character into the location
+ // just before the tail (meaning that the head would advance to the
+ // current location of the tail), we're about to overflow the buffer
+ // and so we don't write the character or advance the head.
+ if (i != obj->rx_tail) {
+ obj->rx_buff[obj->rx_head] = c;
+ obj->rx_head = i;
+ }
+
+ #if ENABLED(EMERGENCY_PARSER)
+ emergency_parser.update(emergency_state, c);
+ #endif
+ }
+}
+
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/MarlinSerial.h b/Marlin/src/HAL/STM32/MarlinSerial.h
new file mode 100644
index 0000000000..5ab97ff3a9
--- /dev/null
+++ b/Marlin/src/HAL/STM32/MarlinSerial.h
@@ -0,0 +1,60 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if ENABLED(EMERGENCY_PARSER)
+ #include "../../feature/e_parser.h"
+#endif
+
+typedef void (*usart_rx_callback_t)(serial_t * obj);
+
+class MarlinSerial : public HardwareSerial {
+public:
+ MarlinSerial(void* peripheral, usart_rx_callback_t rx_callback) :
+ HardwareSerial(peripheral), _rx_callback(rx_callback)
+ #if ENABLED(EMERGENCY_PARSER)
+ , emergency_state(EmergencyParser::State::EP_RESET)
+ #endif
+ { }
+
+ void begin(unsigned long baud, uint8_t config);
+ inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
+
+ void _rx_complete_irq(serial_t* obj);
+
+protected:
+ usart_rx_callback_t _rx_callback;
+ #if ENABLED(EMERGENCY_PARSER)
+ EmergencyParser::State emergency_state;
+ #endif
+};
+
+extern MarlinSerial MSerial1;
+extern MarlinSerial MSerial2;
+extern MarlinSerial MSerial3;
+extern MarlinSerial MSerial4;
+extern MarlinSerial MSerial5;
+extern MarlinSerial MSerial6;
+extern MarlinSerial MSerial7;
+extern MarlinSerial MSerial8;
+extern MarlinSerial MSerial9;
+extern MarlinSerial MSerial10;
+extern MarlinSerial MSerialLP1;
diff --git a/Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp b/Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp
index ebe15f9391..6e73e87c21 100644
--- a/Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp
+++ b/Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -27,248 +27,295 @@
#include
#include
-//#include "SdMscDriver.h"
-
-//#include "usbd_msc_bot.h"
-//#include "usbd_msc_scsi.h"
-//#include "usbd_msc_composite.h"
-//#include "usbd_msc_cdc_composite.h"
-
-//#include "usbd_msc_data.h"
-
-#if defined(STM32F103xE) || defined(STM32F103xG)
- #include
- #include
-#elif defined(STM32F4xx)
- #include
- #include
- #include
- #include
-#elif defined(STM32F7xx)
- #include
- #include
- #include
- #include
-#else
+#if NONE(STM32F103xE, STM32F103xG, STM32F4xx, STM32F7xx)
#error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
#endif
-SD_HandleTypeDef hsd; // create SDIO structure
+#ifdef USBD_USE_CDC_COMPOSITE
-#define TRANSFER_CLOCK_DIV ((uint8_t)SDIO_INIT_CLK_DIV/40)
+ // use USB drivers
-#ifndef USBD_OK
- #define USBD_OK 0
-#endif
+ extern "C" { int8_t SD_MSC_Read(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
+ int8_t SD_MSC_Write(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
+ extern SD_HandleTypeDef hsd;
+ }
-void go_to_transfer_speed() {
+ bool SDIO_Init() {
+ return hsd.State == HAL_SD_STATE_READY; // return pass/fail status
+ }
- SD_InitTypeDef Init;
+ bool SDIO_ReadBlock(uint32_t block, uint8_t *src) {
+ int8_t status = SD_MSC_Read(0, (uint8_t*)src, block, 1); // read one 512 byte block
+ return (bool) status;
+ }
- /* Default SDIO peripheral configuration for SD card initialization */
- Init.ClockEdge = hsd.Init.ClockEdge;
- Init.ClockBypass = hsd.Init.ClockBypass;
- Init.ClockPowerSave = hsd.Init.ClockPowerSave;
- Init.BusWide = hsd.Init.BusWide;
- Init.HardwareFlowControl = hsd.Init.HardwareFlowControl;
- Init.ClockDiv = TRANSFER_CLOCK_DIV;
+ bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) {
+ int8_t status = SD_MSC_Write(0, (uint8_t*)src, block, 1); // write one 512 byte block
+ return (bool) status;
+ }
- /* Initialize SDIO peripheral interface with default configuration */
- SDIO_Init(hsd.Instance, Init);
-}
+#else // !USBD_USE_CDC_COMPOSITE
-void SD_LowLevel_Init(void) {
+ // use local drivers
+ #if defined(STM32F103xE) || defined(STM32F103xG)
+ #include
+ #include
+ #elif defined(STM32F4xx)
+ #include
+ #include
+ #include
+ #include
+ #elif defined(STM32F7xx)
+ #include
+ #include
+ #include
+ #include
+ #else
+ #error "ERROR - Only STM32F103xE, STM32F103xG, STM32F4xx or STM32F7xx CPUs supported"
+ #endif
- uint32_t tempreg;
+ SD_HandleTypeDef hsd; // create SDIO structure
- GPIO_InitTypeDef GPIO_InitStruct;
+ /*
+ SDIO_INIT_CLK_DIV is 118
+ SDIO clock frequency is 48MHz / (TRANSFER_CLOCK_DIV + 2)
+ SDIO init clock frequency should not exceed 400KHz = 48MHz / (118 + 2)
- __HAL_RCC_GPIOC_CLK_ENABLE(); //enable GPIO clocks
- __HAL_RCC_GPIOD_CLK_ENABLE(); //enable GPIO clocks
+ Default TRANSFER_CLOCK_DIV is 2 (118 / 40)
+ Default SDIO clock frequency is 48MHz / (2 + 2) = 12 MHz
+ This might be too fast for stable SDIO operations
- GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_12; // D0 & SCK
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = 1; //GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+ MKS Robin board seems to have stable SDIO with BusWide 1bit and ClockDiv 8 i.e. 4.8MHz SDIO clock frequency
+ Additional testing is required as there are clearly some 4bit initialization problems
+
+ Add -DTRANSFER_CLOCK_DIV=8 to build parameters to improve SDIO stability
+ */
+
+ #ifndef TRANSFER_CLOCK_DIV
+ #define TRANSFER_CLOCK_DIV (uint8_t(SDIO_INIT_CLK_DIV) / 40)
+ #endif
+
+ #ifndef USBD_OK
+ #define USBD_OK 0
+ #endif
+
+ void go_to_transfer_speed() {
+ SD_InitTypeDef Init;
+
+ /* Default SDIO peripheral configuration for SD card initialization */
+ Init.ClockEdge = hsd.Init.ClockEdge;
+ Init.ClockBypass = hsd.Init.ClockBypass;
+ Init.ClockPowerSave = hsd.Init.ClockPowerSave;
+ Init.BusWide = hsd.Init.BusWide;
+ Init.HardwareFlowControl = hsd.Init.HardwareFlowControl;
+ Init.ClockDiv = TRANSFER_CLOCK_DIV;
+
+ /* Initialize SDIO peripheral interface with default configuration */
+ SDIO_Init(hsd.Instance, Init);
+ }
+
+ void SD_LowLevel_Init(void) {
+ uint32_t tempreg;
+
+ __HAL_RCC_SDIO_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE(); //enable GPIO clocks
+ __HAL_RCC_GPIOD_CLK_ENABLE(); //enable GPIO clocks
+
+ GPIO_InitTypeDef GPIO_InitStruct;
- #if defined(SDIO_D1_PIN) && defined(SDIO_D2_PIN) && defined(SDIO_D3_PIN) // define D1-D3 only if have a four bit wide SDIO bus
- GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11; // D1-D3
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = 1; //GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
+
+ #if DISABLED(STM32F1xx)
+ GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
+ #endif
+
+ GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_12; // D0 & SCK
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- #endif
- // Configure PD.02 CMD line
- GPIO_InitStruct.Pin = GPIO_PIN_2;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+ #if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // define D1-D3 only if have a four bit wide SDIO bus
+ GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11; // D1-D3
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+ #endif
- RCC->APB2RSTR &= ~RCC_APB2RSTR_SDIORST_Msk; // take SDIO out of reset
- RCC->APB2ENR |= RCC_APB2RSTR_SDIORST_Msk; // enable SDIO clock
-
- // Enable the DMA2 Clock
-
- //Initialize the SDIO (with initial <400Khz Clock)
- tempreg = 0; //Reset value
- tempreg |= SDIO_CLKCR_CLKEN; //Clock is enabled
- tempreg |= (uint32_t)0x76; //Clock Divider. Clock = 48000/(118+2) = 400Khz
- //Keep the rest at 0 => HW_Flow Disabled, Rising Clock Edge, Disable CLK ByPass, Bus Width = 0, Power save Disable
- SDIO->CLKCR = tempreg;
-
- //Power up the SDIO
- SDIO->POWER = 0x03;
-}
+ // Configure PD.02 CMD line
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
-void HAL_SD_MspInit(SD_HandleTypeDef *hsd) { // application specific init
- UNUSED(hsd); /* Prevent unused argument(s) compilation warning */
- __HAL_RCC_SDIO_CLK_ENABLE(); // turn on SDIO clock
-}
+ #if DISABLED(STM32F1xx)
+ // TODO: use __HAL_RCC_SDIO_RELEASE_RESET() and __HAL_RCC_SDIO_CLK_ENABLE();
+ RCC->APB2RSTR &= ~RCC_APB2RSTR_SDIORST_Msk; // take SDIO out of reset
+ RCC->APB2ENR |= RCC_APB2RSTR_SDIORST_Msk; // enable SDIO clock
+ // Enable the DMA2 Clock
+ #endif
-constexpr uint8_t SD_RETRY_COUNT = (1
- #if ENABLED(SD_CHECK_AND_RETRY)
- + 2
- #endif
-);
+ //Initialize the SDIO (with initial <400Khz Clock)
+ tempreg = 0; //Reset value
+ tempreg |= SDIO_CLKCR_CLKEN; // Clock enabled
+ tempreg |= (uint32_t)0x76; // Clock Divider. Clock = 48000 / (118 + 2) = 400Khz
+ // Keep the rest at 0 => HW_Flow Disabled, Rising Clock Edge, Disable CLK ByPass, Bus Width = 0, Power save Disable
+ SDIO->CLKCR = tempreg;
-bool SDIO_Init() {
- //init SDIO and get SD card info
-
- uint8_t retryCnt = SD_RETRY_COUNT;
-
- bool status;
- hsd.Instance = SDIO;
- hsd.State = (HAL_SD_StateTypeDef) 0; // HAL_SD_STATE_RESET
- SD_LowLevel_Init();
-
- uint8_t retry_Cnt = retryCnt;
- for (;;) {
- status = (bool) HAL_SD_Init(&hsd);
- if (!status) break;
- if (!--retry_Cnt) return false; // return failing status if retries are exhausted
+ // Power up the SDIO
+ SDIO->POWER = 0x03;
}
- go_to_transfer_speed();
+ void HAL_SD_MspInit(SD_HandleTypeDef *hsd) { // application specific init
+ UNUSED(hsd); /* Prevent unused argument(s) compilation warning */
+ __HAL_RCC_SDIO_CLK_ENABLE(); // turn on SDIO clock
+ }
- #if defined(SDIO_D1_PIN) && defined(SDIO_D2_PIN) && defined(SDIO_D3_PIN) // go to 4 bit wide mode if pins are defined
- retry_Cnt = retryCnt;
+ constexpr uint8_t SD_RETRY_COUNT = TERN(SD_CHECK_AND_RETRY, 3, 1);
+
+ bool SDIO_Init() {
+ //init SDIO and get SD card info
+
+ uint8_t retryCnt = SD_RETRY_COUNT;
+
+ bool status;
+ hsd.Instance = SDIO;
+ hsd.State = (HAL_SD_StateTypeDef) 0; // HAL_SD_STATE_RESET
+
+ /*
+ hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
+ hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
+ hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
+ hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
+ hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
+ hsd.Init.ClockDiv = 8;
+ */
+
+ SD_LowLevel_Init();
+
+ uint8_t retry_Cnt = retryCnt;
for (;;) {
- if (!HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B)) break; // some cards are only 1 bit wide so a pass here is not required
- if (!--retry_Cnt) break;
+ TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
+ status = (bool) HAL_SD_Init(&hsd);
+ if (!status) break;
+ if (!--retry_Cnt) return false; // return failing status if retries are exhausted
}
- if (!retry_Cnt) { // wide bus failed, go back to one bit wide mode
- hsd.State = (HAL_SD_StateTypeDef) 0; // HAL_SD_STATE_RESET
- SD_LowLevel_Init();
+
+ go_to_transfer_speed();
+
+ #if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // go to 4 bit wide mode if pins are defined
retry_Cnt = retryCnt;
for (;;) {
- status = (bool) HAL_SD_Init(&hsd);
- if (!status) break;
- if (!--retry_Cnt) return false; // return failing status if retries are exhausted
+ TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
+ if (!HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B)) break; // some cards are only 1 bit wide so a pass here is not required
+ if (!--retry_Cnt) break;
}
- }
- #endif
+ if (!retry_Cnt) { // wide bus failed, go back to one bit wide mode
+ hsd.State = (HAL_SD_StateTypeDef) 0; // HAL_SD_STATE_RESET
+ SD_LowLevel_Init();
+ retry_Cnt = retryCnt;
+ for (;;) {
+ TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
+ status = (bool) HAL_SD_Init(&hsd);
+ if (!status) break;
+ if (!--retry_Cnt) return false; // return failing status if retries are exhausted
+ }
+ }
+ #endif
- return true;
-}
-
-void init_SDIO_pins(void) {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
-
- /**SDIO GPIO Configuration
- PC8 ------> SDIO_D0
- PC12 ------> SDIO_CK
- PD2 ------> SDIO_CMD
- */
- GPIO_InitStruct.Pin = GPIO_PIN_8;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = GPIO_PIN_12;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
- HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
-
- GPIO_InitStruct.Pin = GPIO_PIN_2;
- GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
-}
-
-//bool SDIO_init() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
-//bool SDIO_Init_C() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
-
-bool SDIO_ReadBlock(uint32_t block, uint8_t *dst) {
- bool status;
-
- hsd.Instance = SDIO;
-
- uint8_t retryCnt = SD_RETRY_COUNT;
-
- for (;;) {
- bool status = (bool) HAL_SD_ReadBlocks(&hsd, (uint8_t*)dst, block, 1, 1000); // read one 512 byte block with 500mS timeout
- status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK
- if (!status) return false; // return passing status
- if (!--retryCnt) return true; // return failing status if retries are exhausted
+ return true;
}
-
/*
- return (bool) ((status_read | status_card) ? 1 : 0);
+ void init_SDIO_pins(void) {
+ GPIO_InitTypeDef GPIO_InitStruct = {0};
- if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
- if (blockAddress >= SdCard.LogBlockNbr) return false;
- if ((0x03 & (uint32_t)data)) return false; // misaligned data
+ // SDIO GPIO Configuration
+ // PC8 ------> SDIO_D0
+ // PC12 ------> SDIO_CK
+ // PD2 ------> SDIO_CMD
- if (SdCard.CardType != CARD_SDHC_SDXC) { blockAddress *= 512U; }
+ GPIO_InitStruct.Pin = GPIO_PIN_8;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- if (!SDIO_CmdReadSingleBlock(blockAddress)) {
- SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS);
- dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
- return false;
+ GPIO_InitStruct.Pin = GPIO_PIN_12;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
-
- while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) {}
-
- dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
-
- if (SDIO->STA & SDIO_STA_RXDAVL) {
- while (SDIO->STA & SDIO_STA_RXDAVL) (void)SDIO->FIFO;
- SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
- return false;
- }
-
- if (SDIO_GET_FLAG(SDIO_STA_TRX_ERROR_FLAGS)) {
- SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
- return false;
- }
- SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
*/
+ //bool SDIO_init() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
+ //bool SDIO_Init_C() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
- return true;
-}
+ bool SDIO_ReadBlock(uint32_t block, uint8_t *dst) {
+ hsd.Instance = SDIO;
+ uint8_t retryCnt = SD_RETRY_COUNT;
-bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) {
- bool status;
+ bool status;
+ for (;;) {
+ TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
+ status = (bool) HAL_SD_ReadBlocks(&hsd, (uint8_t*)dst, block, 1, 1000); // read one 512 byte block with 500mS timeout
+ status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK
+ if (!status) break; // return passing status
+ if (!--retryCnt) break; // return failing status if retries are exhausted
+ }
+ return status;
- hsd.Instance = SDIO;
+ /*
+ return (bool) ((status_read | status_card) ? 1 : 0);
- uint8_t retryCnt = SD_RETRY_COUNT;
+ if (SDIO_GetCardState() != SDIO_CARD_TRANSFER) return false;
+ if (blockAddress >= SdCard.LogBlockNbr) return false;
+ if ((0x03 & (uint32_t)data)) return false; // misaligned data
- for (;;) {
- status = (bool) HAL_SD_WriteBlocks(&hsd, (uint8_t*)src, block, 1, 500); // write one 512 byte block with 500mS timeout
- status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK
- if (!status) return (bool) status; // return passing status
- if (!--retryCnt) return (bool) status; // return failing status if retries are exhausted
+ if (SdCard.CardType != CARD_SDHC_SDXC) { blockAddress *= 512U; }
+
+ if (!SDIO_CmdReadSingleBlock(blockAddress)) {
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS);
+ dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
+ return false;
+ }
+
+ while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) {}
+
+ dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
+
+ if (SDIO->STA & SDIO_STA_RXDAVL) {
+ while (SDIO->STA & SDIO_STA_RXDAVL) (void)SDIO->FIFO;
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
+ return false;
+ }
+
+ if (SDIO_GET_FLAG(SDIO_STA_TRX_ERROR_FLAGS)) {
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
+ return false;
+ }
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
+ */
+
+ return true;
}
-}
+ bool SDIO_WriteBlock(uint32_t block, const uint8_t *src) {
+ hsd.Instance = SDIO;
+ uint8_t retryCnt = SD_RETRY_COUNT;
+ bool status;
+ for (;;) {
+ status = (bool) HAL_SD_WriteBlocks(&hsd, (uint8_t*)src, block, 1, 500); // write one 512 byte block with 500mS timeout
+ status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK
+ if (!status) break; // return passing status
+ if (!--retryCnt) break; // return failing status if retries are exhausted
+ }
+ return status;
+ }
+
+#endif // !USBD_USE_CDC_COMPOSITE
#endif // SDIO_SUPPORT
diff --git a/Marlin/src/HAL/STM32/Servo.cpp b/Marlin/src/HAL/STM32/Servo.cpp
index 2dcadb8876..1cf117a056 100644
--- a/Marlin/src/HAL/STM32/Servo.cpp
+++ b/Marlin/src/HAL/STM32/Servo.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
@@ -29,34 +29,82 @@
#include "Servo.h"
static uint_fast8_t servoCount = 0;
+static libServo *servos[NUM_SERVOS] = {0};
constexpr millis_t servoDelay[] = SERVO_DELAY;
static_assert(COUNT(servoDelay) == NUM_SERVOS, "SERVO_DELAY must be an array NUM_SERVOS long.");
+// Initialize to the default timer priority. This will be overridden by a call from timers.cpp.
+// This allows all timer interrupt priorities to be managed from a single location in the HAL.
+static uint32_t servo_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), TIM_IRQ_PRIO, TIM_IRQ_SUBPRIO);
+
+// This must be called after the STM32 Servo class has intialized the timer.
+// It may only be needed after the first call to attach(), but it is possible
+// that is is necessary after every detach() call. To be safe this is currently
+// called after every call to attach().
+static void fixServoTimerInterruptPriority() {
+ NVIC_SetPriority(getTimerUpIrq(TIMER_SERVO), servo_interrupt_priority);
+}
+
libServo::libServo()
-: delay(servoDelay[servoCount++])
-{}
+: delay(servoDelay[servoCount]),
+ was_attached_before_pause(false),
+ value_before_pause(0)
+{
+ servos[servoCount++] = this;
+}
int8_t libServo::attach(const int pin) {
if (servoCount >= MAX_SERVOS) return -1;
if (pin > 0) servo_pin = pin;
- return super::attach(servo_pin);
+ auto result = stm32_servo.attach(servo_pin);
+ fixServoTimerInterruptPriority();
+ return result;
}
int8_t libServo::attach(const int pin, const int min, const int max) {
if (servoCount >= MAX_SERVOS) return -1;
if (pin > 0) servo_pin = pin;
- return super::attach(servo_pin, min, max);
+ auto result = stm32_servo.attach(servo_pin, min, max);
+ fixServoTimerInterruptPriority();
+ return result;
}
void libServo::move(const int value) {
if (attach(0) >= 0) {
- write(value);
+ stm32_servo.write(value);
safe_delay(delay);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
-#endif // HAS_SERVOS
+void libServo::pause() {
+ was_attached_before_pause = stm32_servo.attached();
+ if (was_attached_before_pause) {
+ value_before_pause = stm32_servo.read();
+ stm32_servo.detach();
+ }
+}
+
+void libServo::resume() {
+ if (was_attached_before_pause) {
+ attach();
+ move(value_before_pause);
+ }
+}
+
+void libServo::pause_all_servos() {
+ for (auto& servo : servos)
+ if (servo) servo->pause();
+}
+
+void libServo::resume_all_servos() {
+ for (auto& servo : servos)
+ if (servo) servo->resume();
+}
+
+void libServo::setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority) {
+ servo_interrupt_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preemptPriority, subPriority);
+}
+
+#endif // HAS_SERVOS
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/Servo.h b/Marlin/src/HAL/STM32/Servo.h
index e8b3c4b100..1527e753b6 100644
--- a/Marlin/src/HAL/STM32/Servo.h
+++ b/Marlin/src/HAL/STM32/Servo.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -27,15 +27,28 @@
#include "../../core/millis_t.h"
// Inherit and expand on the official library
-class libServo : public Servo {
+class libServo {
public:
libServo();
- int8_t attach(const int pin);
+ int8_t attach(const int pin = 0); // pin == 0 uses value from previous call
int8_t attach(const int pin, const int min, const int max);
+ void detach() { stm32_servo.detach(); }
+ int read() { return stm32_servo.read(); }
void move(const int value);
+
+ void pause();
+ void resume();
+
+ static void pause_all_servos();
+ static void resume_all_servos();
+ static void setInterruptPriority(uint32_t preemptPriority, uint32_t subPriority);
+
private:
- typedef Servo super;
+ Servo stm32_servo;
int servo_pin = 0;
millis_t delay = 0;
+
+ bool was_attached_before_pause;
+ int value_before_pause;
};
diff --git a/Marlin/src/HAL/STM32/SoftwareSerial.cpp b/Marlin/src/HAL/STM32/SoftwareSerial.cpp
index f6363aa1cf..2228a177be 100644
--- a/Marlin/src/HAL/STM32/SoftwareSerial.cpp
+++ b/Marlin/src/HAL/STM32/SoftwareSerial.cpp
@@ -3,14 +3,14 @@
*
* Multi-instance software serial library for Arduino/Wiring
* -- Interrupt-driven receive and other improvements by ladyada
- * (http://ladyada.net)
+ *
* -- Tuning, circular buffer, derivation from class Print/Stream,
* multi-instance support, porting to 8MHz processors,
* various optimizations, PROGMEM delay tables, inverse logic and
- * direct port writing by Mikal Hart (http://www.arduiniana.org)
- * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
- * -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
- * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
+ * direct port writing by Mikal Hart
+ * -- Pin change interrupt macros by Paul Stoffregen
+ * -- 20MHz processor support by Garrett Mace
+ * -- ATmega1280/2560 support by Brett Hagman
* -- STM32 support by Armin van der Togt
*
* This library is free software; you can redistribute it and/or
@@ -36,8 +36,9 @@
//
#if defined(PLATFORMIO) && defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+#include "../../inc/MarlinConfig.h"
+
#include "SoftwareSerial.h"
-#include "timers.h"
#define OVERSAMPLE 3 // in RX, Timer will generate interruption OVERSAMPLE time during a bit. Thus OVERSAMPLE ticks in a bit. (interrupt not synchonized with edge).
@@ -47,49 +48,49 @@
// The order is based on (lack of) features and compare channels, we choose the simplest available
// because we only need an update interrupt
#if !defined(TIMER_SERIAL)
-#if defined (TIM18_BASE)
+#if defined(TIM18_BASE)
#define TIMER_SERIAL TIM18
-#elif defined (TIM7_BASE)
+#elif defined(TIM7_BASE)
#define TIMER_SERIAL TIM7
-#elif defined (TIM6_BASE)
+#elif defined(TIM6_BASE)
#define TIMER_SERIAL TIM6
-#elif defined (TIM22_BASE)
+#elif defined(TIM22_BASE)
#define TIMER_SERIAL TIM22
-#elif defined (TIM21_BASE)
+#elif defined(TIM21_BASE)
#define TIMER_SERIAL TIM21
-#elif defined (TIM17_BASE)
+#elif defined(TIM17_BASE)
#define TIMER_SERIAL TIM17
-#elif defined (TIM16_BASE)
+#elif defined(TIM16_BASE)
#define TIMER_SERIAL TIM16
-#elif defined (TIM15_BASE)
+#elif defined(TIM15_BASE)
#define TIMER_SERIAL TIM15
-#elif defined (TIM14_BASE)
+#elif defined(TIM14_BASE)
#define TIMER_SERIAL TIM14
-#elif defined (TIM13_BASE)
+#elif defined(TIM13_BASE)
#define TIMER_SERIAL TIM13
-#elif defined (TIM11_BASE)
+#elif defined(TIM11_BASE)
#define TIMER_SERIAL TIM11
-#elif defined (TIM10_BASE)
+#elif defined(TIM10_BASE)
#define TIMER_SERIAL TIM10
-#elif defined (TIM12_BASE)
+#elif defined(TIM12_BASE)
#define TIMER_SERIAL TIM12
-#elif defined (TIM19_BASE)
+#elif defined(TIM19_BASE)
#define TIMER_SERIAL TIM19
-#elif defined (TIM9_BASE)
+#elif defined(TIM9_BASE)
#define TIMER_SERIAL TIM9
-#elif defined (TIM5_BASE)
+#elif defined(TIM5_BASE)
#define TIMER_SERIAL TIM5
-#elif defined (TIM4_BASE)
+#elif defined(TIM4_BASE)
#define TIMER_SERIAL TIM4
-#elif defined (TIM3_BASE)
+#elif defined(TIM3_BASE)
#define TIMER_SERIAL TIM3
-#elif defined (TIM2_BASE)
+#elif defined(TIM2_BASE)
#define TIMER_SERIAL TIM2
-#elif defined (TIM20_BASE)
+#elif defined(TIM20_BASE)
#define TIMER_SERIAL TIM20
-#elif defined (TIM8_BASE)
+#elif defined(TIM8_BASE)
#define TIMER_SERIAL TIM8
-#elif defined (TIM1_BASE)
+#elif defined(TIM1_BASE)
#define TIMER_SERIAL TIM1
#else
#error No suitable timer found for SoftwareSerial, define TIMER_SERIAL in variant.h
diff --git a/Marlin/src/HAL/STM32/SoftwareSerial.h b/Marlin/src/HAL/STM32/SoftwareSerial.h
index 504bd6979b..1a4f742c32 100644
--- a/Marlin/src/HAL/STM32/SoftwareSerial.h
+++ b/Marlin/src/HAL/STM32/SoftwareSerial.h
@@ -3,14 +3,14 @@
*
* Multi-instance software serial library for Arduino/Wiring
* -- Interrupt-driven receive and other improvements by ladyada
- * (http://ladyada.net)
+ * (https://ladyada.net)
* -- Tuning, circular buffer, derivation from class Print/Stream,
* multi-instance support, porting to 8MHz processors,
* various optimizations, PROGMEM delay tables, inverse logic and
* direct port writing by Mikal Hart (http://www.arduiniana.org)
- * -- Pin change interrupt macros by Paul Stoffregen (http://www.pjrc.com)
+ * -- Pin change interrupt macros by Paul Stoffregen (https://www.pjrc.com)
* -- 20MHz processor support by Garrett Mace (http://www.macetech.com)
- * -- ATmega1280/2560 support by Brett Hagman (http://www.roguerobotics.com/)
+ * -- ATmega1280/2560 support by Brett Hagman (https://www.roguerobotics.com/)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp
index 39012f8205..0933b9f4e8 100644
--- a/Marlin/src/HAL/STM32/eeprom_flash.cpp
+++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp
@@ -17,22 +17,24 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "../../inc/MarlinConfig.h"
-#if BOTH(EEPROM_SETTINGS, FLASH_EEPROM_EMULATION)
+#if ENABLED(FLASH_EEPROM_EMULATION)
#include "../shared/eeprom_api.h"
-
-// Only STM32F4 can support wear leveling at this time
-#ifndef STM32F4xx
- #undef FLASH_EEPROM_LEVELING
+#if HAS_SERVOS
+ #include "Servo.h"
+ #define PAUSE_SERVO_OUTPUT() libServo::pause_all_servos()
+ #define RESUME_SERVO_OUTPUT() libServo::resume_all_servos()
+#else
+ #define PAUSE_SERVO_OUTPUT()
+ #define RESUME_SERVO_OUTPUT()
#endif
/**
@@ -57,8 +59,8 @@
#define DEBUG_OUT ENABLED(EEPROM_CHITCHAT)
#include "src/core/debug_out.h"
- #ifndef EEPROM_SIZE
- #define EEPROM_SIZE 0x1000 // 4kB
+ #ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
#endif
#ifndef FLASH_SECTOR
@@ -68,11 +70,11 @@
#define FLASH_UNIT_SIZE 0x20000 // 128kB
#endif
- #define FLASH_ADDRESS_START (FLASH_END - ((FLASH_SECTOR_TOTAL - FLASH_SECTOR) * FLASH_UNIT_SIZE) + 1)
+ #define FLASH_ADDRESS_START (FLASH_END - ((FLASH_SECTOR_TOTAL - (FLASH_SECTOR)) * (FLASH_UNIT_SIZE)) + 1)
#define FLASH_ADDRESS_END (FLASH_ADDRESS_START + FLASH_UNIT_SIZE - 1)
- #define EEPROM_SLOTS (FLASH_UNIT_SIZE/EEPROM_SIZE)
- #define SLOT_ADDRESS(slot) (FLASH_ADDRESS_START + (slot * EEPROM_SIZE))
+ #define EEPROM_SLOTS ((FLASH_UNIT_SIZE) / (MARLIN_EEPROM_SIZE))
+ #define SLOT_ADDRESS(slot) (FLASH_ADDRESS_START + (slot * (MARLIN_EEPROM_SIZE)))
#define UNLOCK_FLASH() if (!flash_unlocked) { \
HAL_FLASH_Unlock(); \
@@ -85,12 +87,12 @@
#define EMPTY_UINT32 ((uint32_t)-1)
#define EMPTY_UINT8 ((uint8_t)-1)
- static uint8_t ram_eeprom[EEPROM_SIZE] __attribute__((aligned(4))) = {0};
+ static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
static int current_slot = -1;
- static_assert(0 == EEPROM_SIZE % 4, "EEPROM_SIZE must be a multiple of 4"); // Ensure copying as uint32_t is safe
- static_assert(0 == FLASH_UNIT_SIZE % EEPROM_SIZE, "EEPROM_SIZE must divide evenly into your FLASH_UNIT_SIZE");
- static_assert(FLASH_UNIT_SIZE >= EEPROM_SIZE, "FLASH_UNIT_SIZE must be greater than or equal to your EEPROM_SIZE");
+ static_assert(0 == MARLIN_EEPROM_SIZE % 4, "MARLIN_EEPROM_SIZE must be a multiple of 4"); // Ensure copying as uint32_t is safe
+ static_assert(0 == FLASH_UNIT_SIZE % MARLIN_EEPROM_SIZE, "MARLIN_EEPROM_SIZE must divide evenly into your FLASH_UNIT_SIZE");
+ static_assert(FLASH_UNIT_SIZE >= MARLIN_EEPROM_SIZE, "FLASH_UNIT_SIZE must be greater than or equal to your MARLIN_EEPROM_SIZE");
static_assert(IS_FLASH_SECTOR(FLASH_SECTOR), "FLASH_SECTOR is invalid");
static_assert(IS_POWER_OF_2(FLASH_UNIT_SIZE), "FLASH_UNIT_SIZE should be a power of 2, please check your chip's spec sheet");
@@ -98,6 +100,11 @@
static bool eeprom_data_written = false;
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
bool PersistentStore::access_start() {
#if ENABLED(FLASH_EEPROM_LEVELING)
@@ -111,20 +118,20 @@ bool PersistentStore::access_start() {
while (address <= FLASH_ADDRESS_END) {
uint32_t address_value = (*(__IO uint32_t*)address);
if (address_value != EMPTY_UINT32) {
- current_slot = (address - FLASH_ADDRESS_START) / EEPROM_SIZE;
+ current_slot = (address - (FLASH_ADDRESS_START)) / (MARLIN_EEPROM_SIZE);
break;
}
address += sizeof(uint32_t);
}
if (current_slot == -1) {
// We didn't find anything, so we'll just intialize to empty
- for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = EMPTY_UINT8;
+ for (int i = 0; i < MARLIN_EEPROM_SIZE; i++) ram_eeprom[i] = EMPTY_UINT8;
current_slot = EEPROM_SLOTS;
}
else {
// load current settings
uint8_t *eeprom_data = (uint8_t *)SLOT_ADDRESS(current_slot);
- for (int i = 0; i < EEPROM_SIZE; i++) ram_eeprom[i] = eeprom_data[i];
+ for (int i = 0; i < MARLIN_EEPROM_SIZE; i++) ram_eeprom[i] = eeprom_data[i];
DEBUG_ECHOLNPAIR("EEPROM loaded from slot ", current_slot, ".");
}
eeprom_data_written = false;
@@ -140,6 +147,11 @@ bool PersistentStore::access_start() {
bool PersistentStore::access_finish() {
if (eeprom_data_written) {
+ #ifdef STM32F4xx
+ // MCU may come up with flash error bits which prevent some flash operations.
+ // Clear flags prior to flash operations to prevent errors.
+ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
+ #endif
#if ENABLED(FLASH_EEPROM_LEVELING)
@@ -160,7 +172,11 @@ bool PersistentStore::access_finish() {
current_slot = EEPROM_SLOTS - 1;
UNLOCK_FLASH();
+ PAUSE_SERVO_OUTPUT();
+ DISABLE_ISRS();
status = HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError);
+ ENABLE_ISRS();
+ RESUME_SERVO_OUTPUT();
if (status != HAL_OK) {
DEBUG_ECHOLNPAIR("HAL_FLASHEx_Erase=", status);
DEBUG_ECHOLNPAIR("GetError=", HAL_FLASH_GetError());
@@ -174,7 +190,7 @@ bool PersistentStore::access_finish() {
uint32_t offset = 0;
uint32_t address = SLOT_ADDRESS(current_slot);
- uint32_t address_end = address + EEPROM_SIZE;
+ uint32_t address_end = address + MARLIN_EEPROM_SIZE;
uint32_t data = 0;
bool success = true;
@@ -205,7 +221,18 @@ bool PersistentStore::access_finish() {
return success;
#else
+ // The following was written for the STM32F4 but may work with other MCUs as well.
+ // Most STM32F4 flash does not allow reading from flash during erase operations.
+ // This takes about a second on a STM32F407 with a 128kB sector used as EEPROM.
+ // Interrupts during this time can have unpredictable results, such as killing Servo
+ // output. Servo output still glitches with interrupts disabled, but recovers after the
+ // erase.
+ PAUSE_SERVO_OUTPUT();
+ DISABLE_ISRS();
eeprom_buffer_flush();
+ ENABLE_ISRS();
+ RESUME_SERVO_OUTPUT();
+
eeprom_data_written = false;
#endif
}
@@ -236,13 +263,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
- const uint8_t c = (
- #if ENABLED(FLASH_EEPROM_LEVELING)
- ram_eeprom[pos]
- #else
- eeprom_buffered_read_byte(pos)
- #endif
- );
+ const uint8_t c = TERN(FLASH_EEPROM_LEVELING, ram_eeprom[pos], eeprom_buffered_read_byte(pos));
if (writing) *value = c;
crc16(crc, &c, 1);
pos++;
@@ -251,15 +272,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() {
- return (
- #if ENABLED(FLASH_EEPROM_LEVELING)
- EEPROM_SIZE
- #else
- E2END + 1
- #endif
- );
-}
-
-#endif // EEPROM_SETTINGS && FLASH_EEPROM_EMULATION
+#endif // FLASH_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/eeprom_sdcard.cpp b/Marlin/src/HAL/STM32/eeprom_sdcard.cpp
index 2b89c21b89..711a83ed5b 100644
--- a/Marlin/src/HAL/STM32/eeprom_sdcard.cpp
+++ b/Marlin/src/HAL/STM32/eeprom_sdcard.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -31,53 +31,44 @@
#if ENABLED(SDCARD_EEPROM_EMULATION)
#include "../shared/eeprom_api.h"
+#include "../../sd/cardreader.h"
-#ifndef E2END
- #define E2END 0xFFF // 4KB
+#define EEPROM_FILENAME "eeprom.dat"
+
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
#endif
-#define HAL_EEPROM_SIZE int(E2END + 1)
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
#define _ALIGN(x) __attribute__ ((aligned(x)))
-static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
+static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
-#if ENABLED(SDSUPPORT)
+bool PersistentStore::access_start() {
+ if (!card.isMounted()) return false;
- #include "../../sd/cardreader.h"
-
- #define EEPROM_FILENAME "eeprom.dat"
-
- bool PersistentStore::access_start() {
- if (!card.isMounted()) return false;
-
- SdFile file, root = card.getroot();
- if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
- return true;
-
- int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
- if (bytes_read < 0) return false;
- for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
- HAL_eeprom_data[bytes_read] = 0xFF;
- file.close();
+ SdFile file, root = card.getroot();
+ if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
return true;
+
+ int bytes_read = file.read(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
+ if (bytes_read < 0) return false;
+ for (; bytes_read < MARLIN_EEPROM_SIZE; bytes_read++)
+ HAL_eeprom_data[bytes_read] = 0xFF;
+ file.close();
+ return true;
+}
+
+bool PersistentStore::access_finish() {
+ if (!card.isMounted()) return false;
+
+ SdFile file, root = card.getroot();
+ int bytes_written = 0;
+ if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
+ bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
+ file.close();
}
-
- bool PersistentStore::access_finish() {
- if (!card.isMounted()) return false;
-
- SdFile file, root = card.getroot();
- int bytes_written = 0;
- if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
- bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
- file.close();
- }
- return (bytes_written == HAL_EEPROM_SIZE);
- }
-
-#else // !SDSUPPORT
-
- #error "Please define an EEPROM, a SDCARD or disable EEPROM_SETTINGS."
-
-#endif // !SDSUPPORT
+ return (bytes_written == MARLIN_EEPROM_SIZE);
+}
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
for (size_t i = 0; i < size; i++)
@@ -97,7 +88,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return false;
}
-size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
-
#endif // SDCARD_EEPROM_EMULATION
#endif // STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/eeprom_impl.cpp b/Marlin/src/HAL/STM32/eeprom_sram.cpp
similarity index 58%
rename from Marlin/src/HAL/STM32/eeprom_impl.cpp
rename to Marlin/src/HAL/STM32/eeprom_sram.cpp
index cd0f93e8d8..5f6f26f9c6 100644
--- a/Marlin/src/HAL/STM32/eeprom_impl.cpp
+++ b/Marlin/src/HAL/STM32/eeprom_sram.cpp
@@ -17,44 +17,32 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "../../inc/MarlinConfig.h"
-#if EITHER(USE_WIRED_EEPROM, SRAM_EEPROM_EMULATION)
+#if ENABLED(SRAM_EEPROM_EMULATION)
+#include "../shared/eeprom_if.h"
#include "../shared/eeprom_api.h"
-bool PersistentStore::access_start() {
- return true;
-}
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
-bool PersistentStore::access_finish() {
- return true;
-}
+bool PersistentStore::access_start() { return true; }
+bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
uint8_t v = *value;
- // Save to either external EEPROM, program flash or Backup SRAM
- #if USE_WIRED_EEPROM
- // EEPROM has only ~100,000 write cycles,
- // so only write bytes that have changed!
- uint8_t * const p = (uint8_t * const)pos;
- if (v != eeprom_read_byte(p)) {
- eeprom_write_byte(p, v);
- if (eeprom_read_byte(p) != v) {
- SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
- return true;
- }
- }
- #else
- *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
- #endif
+ // Save to Backup SRAM
+ *(__IO uint8_t *)(BKPSRAM_BASE + (uint8_t * const)pos) = v;
crc16(crc, &v, 1);
pos++;
@@ -67,14 +55,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
do {
// Read from either external EEPROM, program flash or Backup SRAM
- const uint8_t c = (
- #if USE_WIRED_EEPROM
- eeprom_read_byte((uint8_t*)pos)
- #else
- (*(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)))
- #endif
- );
-
+ const uint8_t c = ( *(__IO uint8_t *)(BKPSRAM_BASE + ((uint8_t*)pos)) );
if (writing) *value = c;
crc16(crc, &c, 1);
pos++;
@@ -83,15 +64,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() {
- return (
- #if USE_WIRED_EEPROM
- E2END + 1
- #else
- 4096 // 4kB
- #endif
- );
-}
-
-#endif // USE_WIRED_EEPROM || SRAM_EEPROM_EMULATION
+#endif // SRAM_EEPROM_EMULATION
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/eeprom_wired.cpp b/Marlin/src/HAL/STM32/eeprom_wired.cpp
new file mode 100644
index 0000000000..8c46e45f03
--- /dev/null
+++ b/Marlin/src/HAL/STM32/eeprom_wired.cpp
@@ -0,0 +1,81 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
+ *
+ * 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 .
+ *
+ */
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+
+#include "../../inc/MarlinConfig.h"
+
+#if USE_WIRED_EEPROM
+
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with simple implementations supplied by Marlin.
+ */
+
+#include "../shared/eeprom_if.h"
+#include "../shared/eeprom_api.h"
+
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_start() { eeprom_init(); return true; }
+bool PersistentStore::access_finish() { return true; }
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ while (size--) {
+ uint8_t v = *value;
+
+ // EEPROM has only ~100,000 write cycles,
+ // so only write bytes that have changed!
+ uint8_t * const p = (uint8_t * const)pos;
+ if (v != eeprom_read_byte(p)) {
+ eeprom_write_byte(p, v);
+ if (eeprom_read_byte(p) != v) {
+ SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
+ return true;
+ }
+ }
+
+ 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*/) {
+ do {
+ // Read from either external EEPROM, program flash or Backup SRAM
+ const uint8_t c = eeprom_read_byte((uint8_t*)pos);
+ if (writing) *value = c;
+ crc16(crc, &c, 1);
+ pos++;
+ value++;
+ } while (--size);
+ return false;
+}
+
+#endif // USE_WIRED_EEPROM
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/endstop_interrupts.h b/Marlin/src/HAL/STM32/endstop_interrupts.h
index 0b97c3c774..fdff8cc644 100644
--- a/Marlin/src/HAL/STM32/endstop_interrupts.h
+++ b/Marlin/src/HAL/STM32/endstop_interrupts.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -28,43 +28,22 @@
void endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
- #if HAS_X_MAX
- attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_X_MIN
- attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MAX
- attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MIN
- attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MAX
- attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN
- attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MAX
- attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MIN
- attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MAX
- attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MIN
- attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z4_MAX
- attachInterrupt(Z4_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z4_MIN
- attachInterrupt(Z4_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
- #endif
+ #define _ATTACH(P) attachInterrupt(P, endstop_ISR, CHANGE)
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/STM32/fastio.cpp b/Marlin/src/HAL/STM32/fastio.cpp
index c51effaa04..0d55579d88 100644
--- a/Marlin/src/HAL/STM32/fastio.cpp
+++ b/Marlin/src/HAL/STM32/fastio.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h
index c17901fa99..d90b2fbeb0 100644
--- a/Marlin/src/HAL/STM32/fastio.h
+++ b/Marlin/src/HAL/STM32/fastio.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -64,12 +64,14 @@ void FastIO_init(); // Must be called before using fast io macros
#define _GET_MODE(IO)
#define _SET_MODE(IO,M) pinMode(IO, M)
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
+#define _SET_OUTPUT_OD(IO) pinMode(IO, OUTPUT_OPEN_DRAIN)
#define WRITE(IO,V) _WRITE(IO,V)
#define READ(IO) _READ(IO)
#define TOGGLE(IO) _TOGGLE(IO)
#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)
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */
@@ -81,6 +83,7 @@ void FastIO_init(); // Must be called before using fast io macros
#define IS_OUTPUT(IO)
#define PWM_PIN(P) digitalPinHasPWM(P)
+#define NO_COMPILE_TIME_PWM
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
diff --git a/Marlin/src/HAL/STM32/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32/inc/Conditionals_LCD.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/STM32/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/STM32/inc/Conditionals_LCD.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/inc/Conditionals_adv.h b/Marlin/src/HAL/STM32/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/STM32/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/STM32/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/inc/Conditionals_post.h b/Marlin/src/HAL/STM32/inc/Conditionals_post.h
index 11603c9ef4..18826e11d2 100644
--- a/Marlin/src/HAL/STM32/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/STM32/inc/Conditionals_post.h
@@ -16,12 +16,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
-#if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
+// If no real or emulated EEPROM selected, fall back to SD emulation
+#if USE_FALLBACK_EEPROM
#define SDCARD_EEPROM_EMULATION
+#elif EITHER(I2C_EEPROM, SPI_EEPROM)
+ #define USE_SHARED_EEPROM 1
#endif
diff --git a/Marlin/src/HAL/STM32/inc/SanityCheck.h b/Marlin/src/HAL/STM32/inc/SanityCheck.h
index b1d0029ba9..30d0750d90 100644
--- a/Marlin/src/HAL/STM32/inc/SanityCheck.h
+++ b/Marlin/src/HAL/STM32/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -28,10 +28,29 @@
// #error "SPINDLE_LASER_PWM_PIN must use SERVO0, SERVO1 or SERVO3 connector"
//#endif
-#if ENABLED(EMERGENCY_PARSER)
- #error "EMERGENCY_PARSER is not yet implemented for STM32. Disable EMERGENCY_PARSER to continue."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32."
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(SDCARD_EEPROM_EMULATION) && DISABLED(SDSUPPORT)
+ #undef SDCARD_EEPROM_EMULATION // Avoid additional error noise
+ #if USE_FALLBACK_EEPROM
+ #warning "EEPROM type not specified. Fallback is SDCARD_EEPROM_EMULATION."
+ #endif
+ #error "SDCARD_EEPROM_EMULATION requires SDSUPPORT. Enable SDSUPPORT or choose another EEPROM emulation."
+#endif
+
+#if defined(STM32F4xx) && BOTH(PRINTCOUNTER, FLASH_EEPROM_EMULATION)
+ #warning "FLASH_EEPROM_EMULATION may cause long delays when writing and should not be used while printing."
+ #error "Disable PRINTCOUNTER or choose another EEPROM emulation."
+#endif
+
+#if !defined(STM32F4xx) && ENABLED(FLASH_EEPROM_LEVELING)
+ #error "FLASH_EEPROM_LEVELING is currently only supported on STM32F4 hardware."
+#endif
+
+#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
+ #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on this platform."
+#elif ENABLED(SERIAL_STATS_DROPPED_RX)
+ #error "SERIAL_STATS_DROPPED_RX is not supported on this platform."
#endif
diff --git a/Marlin/src/HAL/STM32/pinsDebug.h b/Marlin/src/HAL/STM32/pinsDebug.h
index 8c5d1ec2b6..ec08e3fd75 100644
--- a/Marlin/src/HAL/STM32/pinsDebug.h
+++ b/Marlin/src/HAL/STM32/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h
index e3d28aed07..5ff40debea 100644
--- a/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h
+++ b/Marlin/src/HAL/STM32/pinsDebug_STM32GENERIC.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h b/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h
index 58b8c32cc7..09f2bb54e6 100644
--- a/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h
+++ b/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/pins_Xref.h b/Marlin/src/HAL/STM32/pins_Xref.h
index 7e88ec76ba..890e561860 100644
--- a/Marlin/src/HAL/STM32/pins_Xref.h
+++ b/Marlin/src/HAL/STM32/pins_Xref.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/STM32/spi_pins.h b/Marlin/src/HAL/STM32/spi_pins.h
index 8f46ca12c5..176e2a7b20 100644
--- a/Marlin/src/HAL/STM32/spi_pins.h
+++ b/Marlin/src/HAL/STM32/spi_pins.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp b/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
new file mode 100644
index 0000000000..f11fab39db
--- /dev/null
+++ b/Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
@@ -0,0 +1,180 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_FSMC_TFT
+
+#include "tft_fsmc.h"
+#include "pinconfig.h"
+
+SRAM_HandleTypeDef TFT_FSMC::SRAMx;
+DMA_HandleTypeDef TFT_FSMC::DMAtx;
+LCD_CONTROLLER_TypeDef *TFT_FSMC::LCD;
+
+void TFT_FSMC::Init() {
+ uint32_t controllerAddress;
+
+ #if PIN_EXISTS(TFT_RESET)
+ OUT_WRITE(TFT_RESET_PIN, HIGH);
+ HAL_Delay(100);
+ #endif
+
+ #if PIN_EXISTS(TFT_BACKLIGHT)
+ OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
+ #endif
+
+ FSMC_NORSRAM_TimingTypeDef Timing, ExtTiming;
+
+ uint32_t NSBank = (uint32_t)pinmap_peripheral(digitalPinToPinName(TFT_CS_PIN), PinMap_FSMC_CS);
+
+ SRAMx.Instance = FSMC_NORSRAM_DEVICE;
+ SRAMx.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
+ /* SRAMx.Init */
+ SRAMx.Init.NSBank = NSBank;
+ SRAMx.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
+ SRAMx.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
+ SRAMx.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
+ SRAMx.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
+ SRAMx.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
+ SRAMx.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
+ SRAMx.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
+ SRAMx.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
+ SRAMx.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
+ SRAMx.Init.ExtendedMode = FSMC_EXTENDED_MODE_ENABLE;
+ SRAMx.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
+ SRAMx.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
+ #ifdef STM32F4xx
+ SRAMx.Init.PageSize = FSMC_PAGE_SIZE_NONE;
+ #endif
+ /* Read Timing - relatively slow to ensure ID information is correctly read from TFT controller */
+ /* Can be decreases from 15-15-24 to 4-4-8 with risk of stability loss */
+ Timing.AddressSetupTime = 15;
+ Timing.AddressHoldTime = 15;
+ Timing.DataSetupTime = 24;
+ Timing.BusTurnAroundDuration = 0;
+ Timing.CLKDivision = 16;
+ Timing.DataLatency = 17;
+ Timing.AccessMode = FSMC_ACCESS_MODE_A;
+ /* Write Timing */
+ /* Can be decreases from 8-15-8 to 0-0-1 with risk of stability loss */
+ ExtTiming.AddressSetupTime = 8;
+ ExtTiming.AddressHoldTime = 15;
+ ExtTiming.DataSetupTime = 8;
+ ExtTiming.BusTurnAroundDuration = 0;
+ ExtTiming.CLKDivision = 16;
+ ExtTiming.DataLatency = 17;
+ ExtTiming.AccessMode = FSMC_ACCESS_MODE_A;
+
+ __HAL_RCC_FSMC_CLK_ENABLE();
+
+ for(uint16_t i = 0; PinMap_FSMC[i].pin != NC; i++)
+ pinmap_pinout(PinMap_FSMC[i].pin, PinMap_FSMC);
+ pinmap_pinout(digitalPinToPinName(TFT_CS_PIN), PinMap_FSMC_CS);
+ pinmap_pinout(digitalPinToPinName(TFT_RS_PIN), PinMap_FSMC_RS);
+
+ controllerAddress = FSMC_BANK1_1;
+ #ifdef PF0
+ switch (NSBank) {
+ case FSMC_NORSRAM_BANK2: controllerAddress = FSMC_BANK1_2 ; break;
+ case FSMC_NORSRAM_BANK3: controllerAddress = FSMC_BANK1_3 ; break;
+ case FSMC_NORSRAM_BANK4: controllerAddress = FSMC_BANK1_4 ; break;
+ }
+ #endif
+
+ controllerAddress |= (uint32_t)pinmap_peripheral(digitalPinToPinName(TFT_RS_PIN), PinMap_FSMC_RS);
+
+ HAL_SRAM_Init(&SRAMx, &Timing, &ExtTiming);
+
+ __HAL_RCC_DMA2_CLK_ENABLE();
+
+ #ifdef STM32F1xx
+ DMAtx.Instance = DMA2_Channel1;
+ #elif defined(STM32F4xx)
+ DMAtx.Instance = DMA2_Stream0;
+ DMAtx.Init.Channel = DMA_CHANNEL_0;
+ DMAtx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
+ DMAtx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
+ DMAtx.Init.MemBurst = DMA_MBURST_SINGLE;
+ DMAtx.Init.PeriphBurst = DMA_PBURST_SINGLE;
+ #endif
+
+ DMAtx.Init.Direction = DMA_MEMORY_TO_MEMORY;
+ DMAtx.Init.MemInc = DMA_MINC_DISABLE;
+ DMAtx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
+ DMAtx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
+ DMAtx.Init.Mode = DMA_NORMAL;
+ DMAtx.Init.Priority = DMA_PRIORITY_HIGH;
+
+ LCD = (LCD_CONTROLLER_TypeDef *)controllerAddress;
+}
+
+uint32_t TFT_FSMC::GetID() {
+ uint32_t id;
+ WriteReg(0x0000);
+ id = LCD->RAM;
+
+ if (id == 0)
+ id = ReadID(LCD_READ_ID);
+ if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
+ id = ReadID(LCD_READ_ID4);
+ return id;
+}
+
+ uint32_t TFT_FSMC::ReadID(uint16_t Reg) {
+ uint32_t id;
+ WriteReg(Reg);
+ id = LCD->RAM; // dummy read
+ id = Reg << 24;
+ id |= (LCD->RAM & 0x00FF) << 16;
+ id |= (LCD->RAM & 0x00FF) << 8;
+ id |= LCD->RAM & 0x00FF;
+ return id;
+ }
+
+bool TFT_FSMC::isBusy() {
+ if (__IS_DMA_ENABLED(&DMAtx))
+ if (__HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TC_FLAG_INDEX(&DMAtx)) != 0 || __HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TE_FLAG_INDEX(&DMAtx)) != 0)
+ Abort();
+ return __IS_DMA_ENABLED(&DMAtx);
+}
+
+void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
+ DMAtx.Init.PeriphInc = MemoryIncrease;
+ HAL_DMA_Init(&DMAtx);
+
+ __HAL_DMA_CLEAR_FLAG(&DMAtx, __HAL_DMA_GET_TC_FLAG_INDEX(&DMAtx));
+ __HAL_DMA_CLEAR_FLAG(&DMAtx, __HAL_DMA_GET_TE_FLAG_INDEX(&DMAtx));
+
+ #ifdef STM32F1xx
+ DMAtx.Instance->CNDTR = Count;
+ DMAtx.Instance->CPAR = (uint32_t)Data;
+ DMAtx.Instance->CMAR = (uint32_t)&(LCD->RAM);
+ #elif defined(STM32F4xx)
+ DMAtx.Instance->NDTR = Count;
+ DMAtx.Instance->PAR = (uint32_t)Data;
+ DMAtx.Instance->M0AR = (uint32_t)&(LCD->RAM);
+ #endif
+ __HAL_DMA_ENABLE(&DMAtx);
+}
+
+#endif // HAS_FSMC_TFT
diff --git a/Marlin/src/HAL/STM32/tft/tft_fsmc.h b/Marlin/src/HAL/STM32/tft/tft_fsmc.h
new file mode 100644
index 0000000000..8500fee113
--- /dev/null
+++ b/Marlin/src/HAL/STM32/tft/tft_fsmc.h
@@ -0,0 +1,160 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#ifdef STM32F1xx
+ #include "stm32f1xx_hal.h"
+#elif defined(STM32F4xx)
+ #include "stm32f4xx_hal.h"
+#else
+ #error FSMC TFT is currently only supported on STM32F1 and STM32F4 hardware.
+#endif
+
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
+#ifndef LCD_READ_ID4
+ #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
+#endif
+
+#define DATASIZE_8BIT SPI_DATASIZE_8BIT
+#define DATASIZE_16BIT SPI_DATASIZE_16BIT
+#define TFT_IO TFT_FSMC
+
+#ifdef STM32F1xx
+ #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN)
+#elif defined(STM32F4xx)
+ #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN)
+#endif
+
+typedef struct {
+ __IO uint16_t REG;
+ __IO uint16_t RAM;
+} LCD_CONTROLLER_TypeDef;
+
+class TFT_FSMC {
+ private:
+ static SRAM_HandleTypeDef SRAMx;
+ static DMA_HandleTypeDef DMAtx;
+
+ static LCD_CONTROLLER_TypeDef *LCD;
+
+ static uint32_t ReadID(uint16_t Reg);
+ static void Transmit(uint16_t Data) { LCD->RAM = Data; __DSB(); }
+ static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
+
+ public:
+ static void Init();
+ static uint32_t GetID();
+ static bool isBusy();
+ static void Abort() { __HAL_DMA_DISABLE(&DMAtx); }
+
+ static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) {}
+ static void DataTransferEnd() {};
+
+ static void WriteData(uint16_t Data) { Transmit(Data); }
+ static void WriteReg(uint16_t Reg) { LCD->REG = Reg; __DSB(); }
+
+ static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_ENABLE, Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_PINC_DISABLE, &Data, Count); }
+};
+
+
+#ifdef STM32F1xx
+ #define FSMC_PIN_DATA STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, AFIO_NONE)
+#elif defined(STM32F4xx)
+ #define FSMC_PIN_DATA STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_FSMC)
+ #define FSMC_BANK1_1 0x60000000U
+ #define FSMC_BANK1_2 0x64000000U
+ #define FSMC_BANK1_3 0x68000000U
+ #define FSMC_BANK1_4 0x6C000000U
+#else
+ #error No configuration for this MCU
+#endif
+
+const PinMap PinMap_FSMC[] = {
+ {PD_14, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D00
+ {PD_15, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D01
+ {PD_0, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D02
+ {PD_1, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D03
+ {PE_7, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D04
+ {PE_8, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D05
+ {PE_9, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D06
+ {PE_10, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D07
+ {PE_11, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D08
+ {PE_12, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D09
+ {PE_13, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D10
+ {PE_14, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D11
+ {PE_15, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D12
+ {PD_8, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D13
+ {PD_9, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D14
+ {PD_10, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D15
+ {PD_4, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_NOE
+ {PD_5, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_NWE
+ {NC, NP, 0}
+};
+
+const PinMap PinMap_FSMC_CS[] = {
+ {PD_7, (void *)FSMC_NORSRAM_BANK1, FSMC_PIN_DATA}, // FSMC_NE1
+ #ifdef PF0
+ {PG_9, (void *)FSMC_NORSRAM_BANK2, FSMC_PIN_DATA}, // FSMC_NE2
+ {PG_10, (void *)FSMC_NORSRAM_BANK3, FSMC_PIN_DATA}, // FSMC_NE3
+ {PG_12, (void *)FSMC_NORSRAM_BANK4, FSMC_PIN_DATA}, // FSMC_NE4
+ #endif
+ {NC, NP, 0}
+};
+
+#define FSMC_RS(A) (void *)((2 << A) - 2)
+
+const PinMap PinMap_FSMC_RS[] = {
+ #ifdef PF0
+ {PF_0, FSMC_RS( 0), FSMC_PIN_DATA}, // FSMC_A0
+ {PF_1, FSMC_RS( 1), FSMC_PIN_DATA}, // FSMC_A1
+ {PF_2, FSMC_RS( 2), FSMC_PIN_DATA}, // FSMC_A2
+ {PF_3, FSMC_RS( 3), FSMC_PIN_DATA}, // FSMC_A3
+ {PF_4, FSMC_RS( 4), FSMC_PIN_DATA}, // FSMC_A4
+ {PF_5, FSMC_RS( 5), FSMC_PIN_DATA}, // FSMC_A5
+ {PF_12, FSMC_RS( 6), FSMC_PIN_DATA}, // FSMC_A6
+ {PF_13, FSMC_RS( 7), FSMC_PIN_DATA}, // FSMC_A7
+ {PF_14, FSMC_RS( 8), FSMC_PIN_DATA}, // FSMC_A8
+ {PF_15, FSMC_RS( 9), FSMC_PIN_DATA}, // FSMC_A9
+ {PG_0, FSMC_RS(10), FSMC_PIN_DATA}, // FSMC_A10
+ {PG_1, FSMC_RS(11), FSMC_PIN_DATA}, // FSMC_A11
+ {PG_2, FSMC_RS(12), FSMC_PIN_DATA}, // FSMC_A12
+ {PG_3, FSMC_RS(13), FSMC_PIN_DATA}, // FSMC_A13
+ {PG_4, FSMC_RS(14), FSMC_PIN_DATA}, // FSMC_A14
+ {PG_5, FSMC_RS(15), FSMC_PIN_DATA}, // FSMC_A15
+ #endif
+ {PD_11, FSMC_RS(16), FSMC_PIN_DATA}, // FSMC_A16
+ {PD_12, FSMC_RS(17), FSMC_PIN_DATA}, // FSMC_A17
+ {PD_13, FSMC_RS(18), FSMC_PIN_DATA}, // FSMC_A18
+ {PE_3, FSMC_RS(19), FSMC_PIN_DATA}, // FSMC_A19
+ {PE_4, FSMC_RS(20), FSMC_PIN_DATA}, // FSMC_A20
+ {PE_5, FSMC_RS(21), FSMC_PIN_DATA}, // FSMC_A21
+ {PE_6, FSMC_RS(22), FSMC_PIN_DATA}, // FSMC_A22
+ {PE_2, FSMC_RS(23), FSMC_PIN_DATA}, // FSMC_A23
+ #ifdef PF0
+ {PG_13, FSMC_RS(24), FSMC_PIN_DATA}, // FSMC_A24
+ {PG_14, FSMC_RS(25), FSMC_PIN_DATA}, // FSMC_A25
+ #endif
+ {NC, NP, 0}
+};
diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.cpp b/Marlin/src/HAL/STM32/tft/tft_spi.cpp
new file mode 100644
index 0000000000..d3eb4ba8db
--- /dev/null
+++ b/Marlin/src/HAL/STM32/tft/tft_spi.cpp
@@ -0,0 +1,212 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_SPI_TFT
+
+#include "tft_spi.h"
+#include "pinconfig.h"
+
+SPI_HandleTypeDef TFT_SPI::SPIx;
+DMA_HandleTypeDef TFT_SPI::DMAtx;
+
+void TFT_SPI::Init() {
+ SPI_TypeDef *spiInstance;
+
+ #if PIN_EXISTS(TFT_RESET)
+ OUT_WRITE(TFT_RESET_PIN, HIGH);
+ HAL_Delay(100);
+ #endif
+
+ #if PIN_EXISTS(TFT_BACKLIGHT)
+ OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
+ #endif
+
+ OUT_WRITE(TFT_A0_PIN, HIGH);
+ OUT_WRITE(TFT_CS_PIN, HIGH);
+
+ if ((spiInstance = (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK)) == NP) return;
+ if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI)) return;
+
+ #if PIN_EXISTS(TFT_MISO) && (TFT_MISO_PIN != TFT_MOSI_PIN)
+ if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO)) return;
+ #endif
+
+ SPIx.Instance = spiInstance;
+ SPIx.State = HAL_SPI_STATE_RESET;
+ SPIx.Init.NSS = SPI_NSS_SOFT;
+ SPIx.Init.Mode = SPI_MODE_MASTER;
+ SPIx.Init.Direction =
+ #if TFT_MISO_PIN == TFT_MOSI_PIN
+ SPI_DIRECTION_1LINE;
+ #else
+ SPI_DIRECTION_2LINES;
+ #endif
+ SPIx.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
+ SPIx.Init.CLKPhase = SPI_PHASE_1EDGE;
+ SPIx.Init.CLKPolarity = SPI_POLARITY_LOW;
+ SPIx.Init.DataSize = SPI_DATASIZE_8BIT;
+ SPIx.Init.FirstBit = SPI_FIRSTBIT_MSB;
+ SPIx.Init.TIMode = SPI_TIMODE_DISABLE;
+ SPIx.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
+ SPIx.Init.CRCPolynomial = 10;
+
+ pinmap_pinout(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK);
+ pinmap_pinout(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI);
+ #if PIN_EXISTS(TFT_MISO) && (TFT_MISO_PIN != TFT_MOSI_PIN)
+ pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
+ #endif
+ pin_PullConfig(get_GPIO_Port(STM_PORT(digitalPinToPinName(TFT_SCK_PIN))), STM_LL_GPIO_PIN(digitalPinToPinName(TFT_SCK_PIN)), GPIO_PULLDOWN);
+
+ #ifdef SPI1_BASE
+ if (SPIx.Instance == SPI1) {
+ __HAL_RCC_SPI1_CLK_ENABLE();
+ __HAL_RCC_DMA1_CLK_ENABLE();
+ SPIx.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
+ DMAtx.Instance = DMA1_Channel3;
+ }
+ #endif
+ #ifdef SPI2_BASE
+ if (SPIx.Instance == SPI2) {
+ __HAL_RCC_SPI2_CLK_ENABLE();
+ __HAL_RCC_DMA1_CLK_ENABLE();
+ DMAtx.Instance = DMA1_Channel5;
+ }
+ #endif
+ #ifdef SPI3_BASE
+ if (SPIx.Instance == SPI3) {
+ __HAL_RCC_SPI3_CLK_ENABLE();
+ __HAL_RCC_DMA2_CLK_ENABLE();
+ DMAtx.Instance = DMA2_Channel2;
+ }
+ #endif
+
+ HAL_SPI_Init(&SPIx);
+
+ DMAtx.Init.Direction = DMA_MEMORY_TO_PERIPH;
+ DMAtx.Init.PeriphInc = DMA_PINC_DISABLE;
+ DMAtx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
+ DMAtx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
+ DMAtx.Init.Mode = DMA_NORMAL;
+ DMAtx.Init.Priority = DMA_PRIORITY_LOW;
+}
+
+void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
+ SPIx.Init.DataSize = DataSize == DATASIZE_8BIT ? SPI_DATASIZE_8BIT : SPI_DATASIZE_16BIT;
+ HAL_SPI_Init(&SPIx);
+ WRITE(TFT_CS_PIN, LOW);
+}
+
+uint32_t TFT_SPI::GetID() {
+ uint32_t id;
+ id = ReadID(LCD_READ_ID);
+
+ if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
+ id = ReadID(LCD_READ_ID4);
+ return id;
+}
+
+uint32_t TFT_SPI::ReadID(uint16_t Reg) {
+ #if !PIN_EXISTS(TFT_MISO)
+ return 0;
+ #else
+ uint32_t BaudRatePrescaler = SPIx.Init.BaudRatePrescaler;
+ uint32_t i, Data = 0;
+
+ SPIx.Init.BaudRatePrescaler = SPIx.Instance == SPI1 ? SPI_BAUDRATEPRESCALER_8 : SPI_BAUDRATEPRESCALER_4;
+ DataTransferBegin(DATASIZE_8BIT);
+ WriteReg(Reg);
+
+ if (SPIx.Init.Direction == SPI_DIRECTION_1LINE) SPI_1LINE_RX(&SPIx);
+ __HAL_SPI_ENABLE(&SPIx);
+
+ for (i = 0; i < 4; i++) {
+ #if TFT_MISO_PIN != TFT_MOSI_PIN
+ //if (hspi->Init.Direction == SPI_DIRECTION_2LINES) {
+ while ((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
+ SPIx.Instance->DR = 0;
+ //}
+ #endif
+ while ((SPIx.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE) {}
+ Data = (Data << 8) | SPIx.Instance->DR;
+ }
+
+ __HAL_SPI_DISABLE(&SPIx);
+ DataTransferEnd();
+
+ SPIx.Init.BaudRatePrescaler = BaudRatePrescaler;
+
+ return Data >> 7;
+ #endif
+}
+
+bool TFT_SPI::isBusy() {
+ if (DMAtx.Instance->CCR & DMA_CCR_EN)
+ if (__HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TC_FLAG_INDEX(&DMAtx)) != 0 || __HAL_DMA_GET_FLAG(&DMAtx, __HAL_DMA_GET_TE_FLAG_INDEX(&DMAtx)) != 0)
+ Abort();
+ return DMAtx.Instance->CCR & DMA_CCR_EN;
+}
+
+void TFT_SPI::Abort() {
+ __HAL_DMA_DISABLE(&DMAtx);
+ DataTransferEnd();
+}
+
+void TFT_SPI::Transmit(uint16_t Data) {
+ #if TFT_MISO_PIN == TFT_MOSI_PIN
+ SPI_1LINE_TX(&SPIx);
+ #endif
+
+ __HAL_SPI_ENABLE(&SPIx);
+
+ SPIx.Instance->DR = Data;
+
+ while ((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
+ while ((SPIx.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY) {}
+
+ #if TFT_MISO_PIN != TFT_MOSI_PIN
+ __HAL_SPI_CLEAR_OVRFLAG(&SPIx); /* Clear overrun flag in 2 Lines communication mode because received is not read */
+ #endif
+}
+
+void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
+ DMAtx.Init.MemInc = MemoryIncrease;
+ HAL_DMA_Init(&DMAtx);
+
+ DataTransferBegin();
+
+ #if TFT_MISO_PIN == TFT_MOSI_PIN
+ SPI_1LINE_TX(&SPIx);
+ #endif
+
+ DMAtx.DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << DMAtx.ChannelIndex);
+ DMAtx.Instance->CNDTR = Count;
+ DMAtx.Instance->CPAR = (uint32_t)&(SPIx.Instance->DR);
+ DMAtx.Instance->CMAR = (uint32_t)Data;
+ __HAL_DMA_ENABLE(&DMAtx);
+ __HAL_SPI_ENABLE(&SPIx);
+
+ SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); /* Enable Tx DMA Request */
+}
+
+#endif // HAS_SPI_TFT
diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.h b/Marlin/src/HAL/STM32/tft/tft_spi.h
new file mode 100644
index 0000000000..1eed45a709
--- /dev/null
+++ b/Marlin/src/HAL/STM32/tft/tft_spi.h
@@ -0,0 +1,67 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#ifdef STM32F1xx
+ #include "stm32f1xx_hal.h"
+#elif defined(STM32F4xx)
+ #include "stm32f4xx_hal.h"
+#else
+ #error SPI TFT is currently only supported on STM32F1 and STM32F4 hardware.
+#endif
+
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
+#ifndef LCD_READ_ID4
+ #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
+#endif
+
+#define DATASIZE_8BIT SPI_DATASIZE_8BIT
+#define DATASIZE_16BIT SPI_DATASIZE_16BIT
+#define TFT_IO TFT_SPI
+
+class TFT_SPI {
+private:
+ static SPI_HandleTypeDef SPIx;
+ static DMA_HandleTypeDef DMAtx;
+
+ static uint32_t ReadID(uint16_t Reg);
+ static void Transmit(uint16_t Data);
+ static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
+
+public:
+ static void Init();
+ static uint32_t GetID();
+ static bool isBusy();
+ static void Abort();
+
+ static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT);
+ static void DataTransferEnd() { WRITE(TFT_CS_PIN, HIGH); };
+ static void DataTransferAbort();
+
+ static void WriteData(uint16_t Data) { Transmit(Data); }
+ static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); }
+
+ static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
+};
diff --git a/Marlin/src/HAL/STM32/tft/xpt2046.cpp b/Marlin/src/HAL/STM32/tft/xpt2046.cpp
new file mode 100644
index 0000000000..49e64da6a1
--- /dev/null
+++ b/Marlin/src/HAL/STM32/tft/xpt2046.cpp
@@ -0,0 +1,185 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_TFT_XPT2046
+
+#include "xpt2046.h"
+#include "pinconfig.h"
+
+uint16_t delta(uint16_t a, uint16_t b) { return a > b ? a - b : b - a; }
+
+SPI_HandleTypeDef XPT2046::SPIx;
+DMA_HandleTypeDef XPT2046::DMAtx;
+
+void XPT2046::Init() {
+ SPI_TypeDef *spiInstance;
+
+ OUT_WRITE(TOUCH_CS_PIN, HIGH);
+
+ #if PIN_EXISTS(TOUCH_INT)
+ // Optional Pendrive interrupt pin
+ SET_INPUT(TOUCH_INT_PIN);
+ #endif
+
+ spiInstance = (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TOUCH_SCK_PIN), PinMap_SPI_SCLK);
+ if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TOUCH_MOSI_PIN), PinMap_SPI_MOSI)) spiInstance = NP;
+ if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TOUCH_MISO_PIN), PinMap_SPI_MISO)) spiInstance = NP;
+
+ SPIx.Instance = spiInstance;
+
+ if (SPIx.Instance) {
+ SPIx.State = HAL_SPI_STATE_RESET;
+ SPIx.Init.NSS = SPI_NSS_SOFT;
+ SPIx.Init.Mode = SPI_MODE_MASTER;
+ SPIx.Init.Direction = SPI_DIRECTION_2LINES;
+ SPIx.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
+ SPIx.Init.CLKPhase = SPI_PHASE_2EDGE;
+ SPIx.Init.CLKPolarity = SPI_POLARITY_HIGH;
+ SPIx.Init.DataSize = SPI_DATASIZE_8BIT;
+ SPIx.Init.FirstBit = SPI_FIRSTBIT_MSB;
+ SPIx.Init.TIMode = SPI_TIMODE_DISABLE;
+ SPIx.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
+ SPIx.Init.CRCPolynomial = 10;
+
+ pinmap_pinout(digitalPinToPinName(TOUCH_SCK_PIN), PinMap_SPI_SCLK);
+ pinmap_pinout(digitalPinToPinName(TOUCH_MOSI_PIN), PinMap_SPI_MOSI);
+ pinmap_pinout(digitalPinToPinName(TOUCH_MISO_PIN), PinMap_SPI_MISO);
+
+ #ifdef SPI1_BASE
+ if (SPIx.Instance == SPI1) {
+ __HAL_RCC_SPI1_CLK_ENABLE();
+ SPIx.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
+ #ifdef STM32F1xx
+ DMAtx.Instance = DMA1_Channel3;
+ #elif defined(STM32F4xx)
+ DMAtx.Instance = DMA2_Stream3; // DMA2_Stream5
+ #endif
+ //SERIAL_ECHO_MSG(" Touch Screen on SPI1");
+ }
+ #endif
+ #ifdef SPI2_BASE
+ if (SPIx.Instance == SPI2) {
+ __HAL_RCC_SPI2_CLK_ENABLE();
+ #ifdef STM32F1xx
+ DMAtx.Instance = DMA1_Channel5;
+ #elif defined(STM32F4xx)
+ DMAtx.Instance = DMA1_Stream4;
+ #endif
+ //SERIAL_ECHO_MSG(" Touch Screen on SPI2");
+ }
+ #endif
+ #ifdef SPI3_BASE
+ if (SPIx.Instance == SPI3) {
+ __HAL_RCC_SPI3_CLK_ENABLE();
+ #ifdef STM32F1xx
+ DMAtx.Instance = DMA2_Channel2;
+ #elif defined(STM32F4xx)
+ DMAtx.Instance = DMA1_Stream5; // DMA1_Stream7
+ #endif
+ //SERIAL_ECHO_MSG(" Touch Screen on SPI3");
+ }
+ #endif
+ }
+ else {
+ SPIx.Instance = NULL;
+ SET_INPUT(TOUCH_MISO_PIN);
+ SET_OUTPUT(TOUCH_MOSI_PIN);
+ SET_OUTPUT(TOUCH_SCK_PIN);
+ //SERIAL_ECHO_MSG(" Touch Screen on Software SPI");
+ }
+
+ getRawData(XPT2046_Z1);
+}
+
+bool XPT2046::isTouched() {
+ return isBusy() ? false : (
+ #if PIN_EXISTS(TOUCH_INT)
+ READ(TOUCH_INT_PIN) != HIGH
+ #else
+ getRawData(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
+ #endif
+ );
+}
+
+bool XPT2046::getRawPoint(int16_t *x, int16_t *y) {
+ if (isBusy()) return false;
+ if (!isTouched()) return false;
+ *x = getRawData(XPT2046_X);
+ *y = getRawData(XPT2046_Y);
+ return isTouched();
+}
+
+uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) {
+ uint16_t data[3];
+
+ DataTransferBegin();
+
+ for (uint16_t i = 0; i < 3 ; i++) {
+ IO(coordinate);
+ data[i] = (IO() << 4) | (IO() >> 4);
+ }
+
+ DataTransferEnd();
+
+ uint16_t delta01 = delta(data[0], data[1]);
+ uint16_t delta02 = delta(data[0], data[2]);
+ uint16_t delta12 = delta(data[1], data[2]);
+
+ if (delta01 > delta02 || delta01 > delta12) {
+ if (delta02 > delta12)
+ data[0] = data[2];
+ else
+ data[1] = data[2];
+ }
+
+ return (data[0] + data[1]) >> 1;
+}
+
+uint16_t XPT2046::HardwareIO(uint16_t data) {
+ __HAL_SPI_ENABLE(&SPIx);
+ while((SPIx.Instance->SR & SPI_FLAG_TXE) != SPI_FLAG_TXE) {}
+ SPIx.Instance->DR = data;
+ while((SPIx.Instance->SR & SPI_FLAG_RXNE) != SPI_FLAG_RXNE) {}
+ __HAL_SPI_DISABLE(&SPIx);
+
+ return SPIx.Instance->DR;
+}
+
+uint16_t XPT2046::SoftwareIO(uint16_t data) {
+ uint16_t result = 0;
+
+ for (uint8_t j = 0x80; j > 0; j >>= 1) {
+ WRITE(TOUCH_SCK_PIN, LOW);
+ __DSB();
+ WRITE(TOUCH_MOSI_PIN, data & j ? HIGH : LOW);
+ __DSB();
+ if (READ(TOUCH_MISO_PIN)) result |= j;
+ __DSB();
+ WRITE(TOUCH_SCK_PIN, HIGH);
+ __DSB();
+ }
+ WRITE(TOUCH_SCK_PIN, LOW);
+ __DSB();
+
+ return result;
+}
+
+#endif // HAS_TFT_XPT2046
diff --git a/Marlin/src/HAL/STM32/tft/xpt2046.h b/Marlin/src/HAL/STM32/tft/xpt2046.h
new file mode 100644
index 0000000000..7a6d8439c5
--- /dev/null
+++ b/Marlin/src/HAL/STM32/tft/xpt2046.h
@@ -0,0 +1,86 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+#ifdef STM32F1xx
+ #include
+#elif defined(STM32F4xx)
+ #include
+#endif
+
+#include "../../../inc/MarlinConfig.h"
+
+// Not using regular SPI interface by default to avoid SPI mode conflicts with other SPI devices
+
+#if !PIN_EXISTS(TOUCH_MISO)
+ #error "TOUCH_MISO_PIN is not defined."
+#elif !PIN_EXISTS(TOUCH_MOSI)
+ #error "TOUCH_MOSI_PIN is not defined."
+#elif !PIN_EXISTS(TOUCH_SCK)
+ #error "TOUCH_SCK_PIN is not defined."
+#elif !PIN_EXISTS(TOUCH_CS)
+ #error "TOUCH_CS_PIN is not defined."
+#endif
+
+#ifndef TOUCH_INT_PIN
+ #define TOUCH_INT_PIN -1
+#endif
+
+#define XPT2046_DFR_MODE 0x00
+#define XPT2046_SER_MODE 0x04
+#define XPT2046_CONTROL 0x80
+
+enum XPTCoordinate : uint8_t {
+ XPT2046_X = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Y = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+};
+
+#if !defined(XPT2046_Z1_THRESHOLD)
+ #define XPT2046_Z1_THRESHOLD 10
+#endif
+
+#ifdef STM32F1xx
+ #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN)
+#elif defined(STM32F4xx)
+ #define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN)
+#endif
+
+
+class XPT2046 {
+private:
+ static SPI_HandleTypeDef SPIx;
+ static DMA_HandleTypeDef DMAtx;
+
+ static bool isBusy() { return SPIx.Instance ? __IS_DMA_ENABLED(&DMAtx) : false; }
+
+ static uint16_t getRawData(const XPTCoordinate coordinate);
+ static bool isTouched();
+
+ static inline void DataTransferBegin() { if (SPIx.Instance) { HAL_SPI_Init(&SPIx); } WRITE(TOUCH_CS_PIN, LOW); };
+ static inline void DataTransferEnd() { WRITE(TOUCH_CS_PIN, HIGH); };
+ static uint16_t HardwareIO(uint16_t data);
+ static uint16_t SoftwareIO(uint16_t data);
+ static uint16_t IO(uint16_t data = 0) { return SPIx.Instance ? HardwareIO(data) : SoftwareIO(data); }
+
+public:
+ static void Init();
+ static bool getRawPoint(int16_t *x, int16_t *y);
+};
diff --git a/Marlin/src/HAL/STM32/timers.cpp b/Marlin/src/HAL/STM32/timers.cpp
index b7b65f714e..1196731448 100644
--- a/Marlin/src/HAL/STM32/timers.cpp
+++ b/Marlin/src/HAL/STM32/timers.cpp
@@ -16,15 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
-#include "HAL.h"
-
-#include "timers.h"
+#include "../../inc/MarlinConfig.h"
// ------------------------
// Local defines
@@ -32,11 +29,82 @@
#define NUM_HARDWARE_TIMERS 2
+// Default timer priorities. Override by specifying alternate priorities in the board pins file.
+// The TONE timer is not present here, as it currently cannot be set programmatically. It is set
+// by defining TIM_IRQ_PRIO in the variant.h or platformio.ini file, which adjusts the default
+// priority for STM32 HardwareTimer objects.
+#define SWSERIAL_TIMER_IRQ_PRIO_DEFAULT 1 // Requires tight bit timing to communicate reliably with TMC drivers
+#define SERVO_TIMER_IRQ_PRIO_DEFAULT 1 // Requires tight PWM timing to control a BLTouch reliably
+#define STEP_TIMER_IRQ_PRIO_DEFAULT 2
+#define TEMP_TIMER_IRQ_PRIO_DEFAULT 14 // Low priority avoids interference with other hardware and timers
+
+#ifndef STEP_TIMER_IRQ_PRIO
+ #define STEP_TIMER_IRQ_PRIO STEP_TIMER_IRQ_PRIO_DEFAULT
+#endif
+#ifndef TEMP_TIMER_IRQ_PRIO
+ #define TEMP_TIMER_IRQ_PRIO TEMP_TIMER_IRQ_PRIO_DEFAULT
+#endif
+#if HAS_TMC_SW_SERIAL
+ #include
+ #ifndef SWSERIAL_TIMER_IRQ_PRIO
+ #define SWSERIAL_TIMER_IRQ_PRIO SWSERIAL_TIMER_IRQ_PRIO_DEFAULT
+ #endif
+#endif
+#if HAS_SERVOS
+ #include "Servo.h"
+ #ifndef SERVO_TIMER_IRQ_PRIO
+ #define SERVO_TIMER_IRQ_PRIO SERVO_TIMER_IRQ_PRIO_DEFAULT
+ #endif
+#endif
+#if ENABLED(SPEAKER)
+ // Ensure the default timer priority is somewhere between the STEP and TEMP priorities.
+ // The STM32 framework defaults to interrupt 14 for all timers. This should be increased so that
+ // timing-sensitive operations such as speaker output are not impacted by the long-running
+ // temperature ISR. This must be defined in the platformio.ini file or the board's variant.h,
+ // so that it will be consumed by framework code.
+ #if !(TIM_IRQ_PRIO > STEP_TIMER_IRQ_PRIO && TIM_IRQ_PRIO < TEMP_TIMER_IRQ_PRIO)
+ #error "Default timer interrupt priority is unspecified or set to a value which may degrade performance."
+ #endif
+#endif
+
+#ifdef STM32F0xx
+ #define MCU_TIMER_RATE (F_CPU) // Frequency of timer peripherals
+ #define MCU_STEP_TIMER 16
+ #define MCU_TEMP_TIMER 17
+#elif defined(STM32F1xx)
+ #define MCU_TIMER_RATE (F_CPU)
+ #define MCU_STEP_TIMER 4
+ #define MCU_TEMP_TIMER 2
+#elif defined(STM32F401xC) || defined(STM32F401xE)
+ #define MCU_TIMER_RATE (F_CPU / 2)
+ #define MCU_STEP_TIMER 9
+ #define MCU_TEMP_TIMER 10
+#elif defined(STM32F4xx) || defined(STM32F7xx)
+ #define MCU_TIMER_RATE (F_CPU / 2)
+ #define MCU_STEP_TIMER 6 // STM32F401 has no TIM6, TIM7, or TIM8
+ #define MCU_TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used.
+#endif
+
+#ifndef HAL_TIMER_RATE
+ #define HAL_TIMER_RATE MCU_TIMER_RATE
+#endif
+#ifndef STEP_TIMER
+ #define STEP_TIMER MCU_STEP_TIMER
+#endif
+#ifndef TEMP_TIMER
+ #define TEMP_TIMER MCU_TEMP_TIMER
+#endif
+
#define __TIMER_DEV(X) TIM##X
#define _TIMER_DEV(X) __TIMER_DEV(X)
#define STEP_TIMER_DEV _TIMER_DEV(STEP_TIMER)
#define TEMP_TIMER_DEV _TIMER_DEV(TEMP_TIMER)
+#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn
+#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X)
+#define STEP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(STEP_TIMER)
+#define TEMP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(TEMP_TIMER)
+
// ------------------------
// Private Variables
// ------------------------
@@ -136,4 +204,9 @@ TIM_TypeDef * HAL_timer_device(const uint8_t timer_num) {
return nullptr;
}
+void SetTimerInterruptPriorities() {
+ TERN_(HAS_TMC_SW_SERIAL, SoftwareSerial::setInterruptPriority(SWSERIAL_TIMER_IRQ_PRIO, 0));
+ TERN_(HAS_SERVOS, libServo::setInterruptPriority(SERVO_TIMER_IRQ_PRIO, 0));
+}
+
#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/timers.h b/Marlin/src/HAL/STM32/timers.h
index 8a0950a4d7..000f86043b 100644
--- a/Marlin/src/HAL/STM32/timers.h
+++ b/Marlin/src/HAL/STM32/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -33,84 +33,16 @@
#define hal_timer_t uint32_t
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF // Timers can be 16 or 32 bit
-#ifdef STM32F0xx
-
- #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals
-
- #ifndef STEP_TIMER
- #define STEP_TIMER 16
- #endif
-
- #ifndef TEMP_TIMER
- #define TEMP_TIMER 17
- #endif
-
-#elif defined(STM32F1xx)
-
- #define HAL_TIMER_RATE (F_CPU) // frequency of timer peripherals
-
- #ifndef STEP_TIMER
- #define STEP_TIMER 4
- #endif
-
- #ifndef TEMP_TIMER
- #define TEMP_TIMER 2
- #endif
-
-#elif defined(STM32F401xC) || defined(STM32F401xE)
-
- #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals
-
- #ifndef STEP_TIMER
- #define STEP_TIMER 9
- #endif
-
- #ifndef TEMP_TIMER
- #define TEMP_TIMER 10
- #endif
-
-#elif defined(STM32F4xx)
-
- #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals
-
- #ifndef STEP_TIMER
- #define STEP_TIMER 6 // STM32F401 has no TIM6, TIM7, or TIM8
- #endif
-
- #ifndef TEMP_TIMER
- #define TEMP_TIMER 14 // TIM7 is consumed by Software Serial if used.
- #endif
-
-#elif defined(STM32F7xx)
-
- #define HAL_TIMER_RATE (F_CPU / 2) // frequency of timer peripherals
-
- #ifndef STEP_TIMER
- #define STEP_TIMER 6 // the RIGHT timer!
- #endif
-
- #ifndef TEMP_TIMER
- #define TEMP_TIMER 14
- #endif
-
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
#endif
-
-#ifndef SWSERIAL_TIMER_IRQ_PRIO
- #define SWSERIAL_TIMER_IRQ_PRIO 1
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
#endif
-
-#ifndef STEP_TIMER_IRQ_PRIO
- #define STEP_TIMER_IRQ_PRIO 2
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
#endif
-#ifndef TEMP_TIMER_IRQ_PRIO
- #define TEMP_TIMER_IRQ_PRIO 14 // 14 = after hardware ISRs
-#endif
-
-#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 PULSE_TIMER_NUM STEP_TIMER_NUM
-
#define TEMP_TIMER_FREQUENCY 1000 // Temperature::isr() is expected to be called at around 1kHz
// TODO: get rid of manual rate/prescale/ticks/cycles taken for procedures in stepper.cpp
@@ -122,12 +54,6 @@
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
-#define __TIMER_IRQ_NAME(X) TIM##X##_IRQn
-#define _TIMER_IRQ_NAME(X) __TIMER_IRQ_NAME(X)
-
-#define STEP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(STEP_TIMER)
-#define TEMP_TIMER_IRQ_NAME _TIMER_IRQ_NAME(TEMP_TIMER)
-
#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)
@@ -137,8 +63,13 @@
extern void Step_Handler(HardwareTimer *htim);
extern void Temp_Handler(HardwareTimer *htim);
-#define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim)
-#define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim)
+
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() void Step_Handler(HardwareTimer *htim)
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() void Temp_Handler(HardwareTimer *htim)
+#endif
// ------------------------
// Public Variables
@@ -155,6 +86,10 @@ 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);
+// Configure timer priorities for peripherals such as Software Serial or Servos.
+// Exposed here to allow all timer priority information to reside in timers.cpp
+void SetTimerInterruptPriorities();
+
//TIM_TypeDef* HAL_timer_device(const uint8_t timer_num); no need to be public for now. not public = not used externally
// FORCE_INLINE because these are used in performance-critical situations
diff --git a/Marlin/src/HAL/STM32/usb_serial.cpp b/Marlin/src/HAL/STM32/usb_serial.cpp
new file mode 100644
index 0000000000..2dd1bef12c
--- /dev/null
+++ b/Marlin/src/HAL/STM32/usb_serial.cpp
@@ -0,0 +1,55 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if ENABLED(EMERGENCY_PARSER)
+
+#include "usb_serial.h"
+#include "../../feature/e_parser.h"
+
+EmergencyParser::State emergency_state = EmergencyParser::State::EP_RESET;
+
+int8_t (*USBD_CDC_Receive_original) (uint8_t *Buf, uint32_t *Len) = nullptr;
+
+static int8_t USBD_CDC_Receive_hook(uint8_t *Buf, uint32_t *Len) {
+ for (uint32_t i = 0; i < *Len; i++)
+ emergency_parser.update(emergency_state, Buf[i]);
+ return USBD_CDC_Receive_original(Buf, Len);
+}
+
+typedef struct _USBD_CDC_Itf {
+ int8_t (* Init)(void);
+ int8_t (* DeInit)(void);
+ int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
+ int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
+ int8_t (* Transferred)(void);
+} USBD_CDC_ItfTypeDef;
+
+extern USBD_CDC_ItfTypeDef USBD_CDC_fops;
+
+void USB_Hook_init() {
+ USBD_CDC_Receive_original = USBD_CDC_fops.Receive;
+ USBD_CDC_fops.Receive = USBD_CDC_Receive_hook;
+}
+
+#endif // EMERGENCY_PARSER
+#endif // ARDUINO_ARCH_STM32 && !STM32GENERIC
diff --git a/Marlin/src/HAL/STM32/usb_serial.h b/Marlin/src/HAL/STM32/usb_serial.h
new file mode 100644
index 0000000000..ca61b9ed23
--- /dev/null
+++ b/Marlin/src/HAL/STM32/usb_serial.h
@@ -0,0 +1,21 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+void USB_Hook_init();
diff --git a/Marlin/src/HAL/STM32/watchdog.cpp b/Marlin/src/HAL/STM32/watchdog.cpp
index 2c6b583e83..37e5638b05 100644
--- a/Marlin/src/HAL/STM32/watchdog.cpp
+++ b/Marlin/src/HAL/STM32/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
#include "../../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/HAL/STM32/watchdog.h b/Marlin/src/HAL/STM32/watchdog.h
index efa7d2b3d0..49a0d9c631 100644
--- a/Marlin/src/HAL/STM32/watchdog.h
+++ b/Marlin/src/HAL/STM32/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/HAL.cpp b/Marlin/src/HAL/STM32F1/HAL.cpp
index 01fd2c8fc3..d7f9264be6 100644
--- a/Marlin/src/HAL/STM32F1/HAL.cpp
+++ b/Marlin/src/HAL/STM32F1/HAL.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -100,7 +100,7 @@ const uint8_t adc_pins[] = {
#if HAS_HEATED_BED
TEMP_BED_PIN,
#endif
- #if HAS_HEATED_CHAMBER
+ #if HAS_TEMP_CHAMBER
TEMP_CHAMBER_PIN,
#endif
#if HAS_TEMP_ADC_1
@@ -139,16 +139,22 @@ const uint8_t adc_pins[] = {
#if HAS_JOY_ADC_Z
JOY_Z_PIN,
#endif
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ POWER_MONITOR_CURRENT_PIN,
+ #endif
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ POWER_MONITOR_VOLTAGE_PIN,
+ #endif
};
-enum TEMP_PINS : char {
+enum TempPinIndex : char {
#if HAS_TEMP_ADC_0
TEMP_0,
#endif
#if HAS_HEATED_BED
TEMP_BED,
#endif
- #if HAS_HEATED_CHAMBER
+ #if HAS_TEMP_CHAMBER
TEMP_CHAMBER,
#endif
#if HAS_TEMP_ADC_1
@@ -187,6 +193,12 @@ enum TEMP_PINS : char {
#if HAS_JOY_ADC_Z
JOY_Z,
#endif
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ POWERMON_CURRENT,
+ #endif
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ POWERMON_VOLTS,
+ #endif
ADC_PIN_COUNT
};
@@ -246,7 +258,7 @@ void HAL_init() {
// HAL idle task
void HAL_idletask() {
#ifdef USE_USB_COMPOSITE
- #if ENABLED(SHARED_SD_CARD)
+ #if HAS_SHARED_MEDIA
// If Marlin is using the SD card we need to lock it to prevent access from
// a PC via USB.
// Other HALs use IS_SD_PRINTING() and IS_SD_FILE_OPEN() to check for access but
@@ -254,7 +266,7 @@ void HAL_idletask() {
// the disk if Marlin has it mounted. Unfortunately there is currently no way
// to unmount the disk from the LCD menu.
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
- /* copy from lpc1768 framework, should be fixed later for process SHARED_SD_CARD*/
+ /* copy from lpc1768 framework, should be fixed later for process HAS_SHARED_MEDIA*/
#endif
// process USB mass storage device class loop
MarlinMSC.loop();
@@ -265,9 +277,8 @@ void HAL_clear_reset_source() { }
/**
* TODO: Check this and change or remove.
- * currently returns 1 that's equal to poweron reset.
*/
-uint8_t HAL_get_reset_source() { return 1; }
+uint8_t HAL_get_reset_source() { return RST_POWER_ON; }
void _delay_ms(const int delay_ms) { delay(delay_ms); }
@@ -323,7 +334,8 @@ void HAL_adc_init() {
}
void HAL_adc_start_conversion(const uint8_t adc_pin) {
- TEMP_PINS pin_index;
+ //TEMP_PINS pin_index;
+ TempPinIndex pin_index;
switch (adc_pin) {
default: return;
#if HAS_TEMP_ADC_0
@@ -332,7 +344,7 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
#if HAS_HEATED_BED
case TEMP_BED_PIN: pin_index = TEMP_BED; break;
#endif
- #if HAS_HEATED_CHAMBER
+ #if HAS_TEMP_CHAMBER
case TEMP_CHAMBER_PIN: pin_index = TEMP_CHAMBER; break;
#endif
#if HAS_TEMP_ADC_1
@@ -371,6 +383,12 @@ void HAL_adc_start_conversion(const uint8_t adc_pin) {
#if ENABLED(ADC_KEYPAD)
case ADC_KEYPAD_PIN: pin_index = ADC_KEY; break;
#endif
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ case POWER_MONITOR_CURRENT_PIN: pin_index = POWERMON_CURRENT; break;
+ #endif
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ case POWER_MONITOR_VOLTAGE_PIN: pin_index = POWERMON_VOLTS; break;
+ #endif
}
HAL_adc_result = (HAL_adc_results[(int)pin_index] >> 2) & 0x3FF; // shift to get 10 bits only.
}
diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h
index ff42beb92a..5a0b046009 100644
--- a/Marlin/src/HAL/STM32F1/HAL.h
+++ b/Marlin/src/HAL/STM32F1/HAL.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -36,7 +36,6 @@
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
#include
#include
@@ -52,7 +51,7 @@
// ------------------------
#ifndef STM32_FLASH_SIZE
- #ifdef MCU_STM32F103RE
+ #if defined(MCU_STM32F103RE) || defined(MCU_STM32F103VE)
#define STM32_FLASH_SIZE 512
#else
#define STM32_FLASH_SIZE 256
@@ -248,19 +247,6 @@ static int freeMemory() {
#pragma GCC diagnostic pop
-//
-// EEPROM
-//
-
-/**
- * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
- * Wire library should work for i2c EEPROMs.
- */
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block(void *__dst, const void *__src, size_t __n);
-void eeprom_update_block(const void *__src, void *__dst, size_t __n);
-
//
// ADC
//
@@ -269,8 +255,9 @@ void eeprom_update_block(const void *__src, void *__dst, size_t __n);
void HAL_adc_init();
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
diff --git a/Marlin/src/HAL/STM32F1/HAL_SPI.cpp b/Marlin/src/HAL/STM32F1/HAL_SPI.cpp
index bfbdf6af40..4d72473e7f 100644
--- a/Marlin/src/HAL/STM32F1/HAL_SPI.cpp
+++ b/Marlin/src/HAL/STM32F1/HAL_SPI.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/STM32F1/SPI.cpp b/Marlin/src/HAL/STM32F1/SPI.cpp
index 8eb8f9aa88..423772dbc9 100644
--- a/Marlin/src/HAL/STM32F1/SPI.cpp
+++ b/Marlin/src/HAL/STM32F1/SPI.cpp
@@ -216,7 +216,7 @@ void SPIClass::setDataMode(uint8_t dataMode) {
/**
* Notes:
* As far as we know the AVR numbers for dataMode match the numbers required by the STM32.
- * From the AVR doc http://www.atmel.com/images/doc2585.pdf section 2.4
+ * From the AVR doc https://www.atmel.com/images/doc2585.pdf section 2.4
*
* SPI Mode CPOL CPHA Shift SCK-edge Capture SCK-edge
* 0 0 0 Falling Rising
@@ -243,7 +243,7 @@ void SPIClass::setDataMode(uint8_t dataMode) {
_currentSetting->spi_d->regs->CR1 = cr1 | (dataMode & (SPI_CR1_CPOL|SPI_CR1_CPHA));
}
-void SPIClass::beginTransaction(uint8_t pin, SPISettings settings) {
+void SPIClass::beginTransaction(uint8_t pin, const SPISettings &settings) {
setBitOrder(settings.bitOrder);
setDataMode(settings.dataMode);
setDataSize(settings.dataSize);
@@ -251,7 +251,7 @@ void SPIClass::beginTransaction(uint8_t pin, SPISettings settings) {
begin();
}
-void SPIClass::beginTransactionSlave(SPISettings settings) {
+void SPIClass::beginTransactionSlave(const SPISettings &settings) {
setBitOrder(settings.bitOrder);
setDataMode(settings.dataMode);
setDataSize(settings.dataSize);
@@ -266,7 +266,7 @@ void SPIClass::endTransaction() { }
uint16_t SPIClass::read() {
while (!spi_is_rx_nonempty(_currentSetting->spi_d)) { /* nada */ }
- return (uint16)spi_rx_reg(_currentSetting->spi_d);
+ return (uint16_t)spi_rx_reg(_currentSetting->spi_d);
}
void SPIClass::read(uint8_t *buf, uint32_t len) {
@@ -277,7 +277,7 @@ void SPIClass::read(uint8_t *buf, uint32_t len) {
regs->DR = 0x00FF; // write the first byte
// main loop
while (--len) {
- while(!(regs->SR & SPI_SR_TXE)) { /* nada */ } // wait for TXE flag
+ while (!(regs->SR & SPI_SR_TXE)) { /* nada */ } // wait for TXE flag
noInterrupts(); // go atomic level - avoid interrupts to surely get the previously received data
regs->DR = 0x00FF; // write the next data item to be transmitted into the SPI_DR register. This clears the TXE flag.
while (!(regs->SR & SPI_SR_RXNE)) { /* nada */ } // wait till data is available in the DR register
diff --git a/Marlin/src/HAL/STM32F1/SPI.h b/Marlin/src/HAL/STM32F1/SPI.h
index 0162ac13bb..0d20a46577 100644
--- a/Marlin/src/HAL/STM32F1/SPI.h
+++ b/Marlin/src/HAL/STM32F1/SPI.h
@@ -126,6 +126,7 @@ private:
bitOrder = inBitOrder;
dataMode = inDataMode;
dataSize = inDataSize;
+ //state = SPI_STATE_IDLE;
}
uint32_t clock;
uint32_t dataSize;
@@ -187,11 +188,11 @@ public:
*/
void end();
- void beginTransaction(SPISettings settings) { beginTransaction(BOARD_SPI_DEFAULT_SS, settings); }
- void beginTransaction(uint8_t pin, SPISettings settings);
+ void beginTransaction(const SPISettings &settings) { beginTransaction(BOARD_SPI_DEFAULT_SS, settings); }
+ void beginTransaction(uint8_t pin, const SPISettings &settings);
void endTransaction();
- void beginTransactionSlave(SPISettings settings);
+ void beginTransactionSlave(const SPISettings &settings);
void setClockDivider(uint32_t clockDivider);
void setBitOrder(BitOrder bitOrder);
@@ -207,6 +208,8 @@ public:
*/
void setDataSize(uint32_t ds);
+ uint32_t getDataSize() { return _currentSetting->dataSize; }
+
/* Victor Perez 2017. Added to set and clear callback functions for callback
* on DMA transfer completion.
* onReceive used to set the callback in case of dmaTransfer (tx/rx), once rx is completed
diff --git a/Marlin/src/HAL/STM32F1/Servo.cpp b/Marlin/src/HAL/STM32F1/Servo.cpp
index 06abb2c2b9..e1ee831493 100644
--- a/Marlin/src/HAL/STM32F1/Servo.cpp
+++ b/Marlin/src/HAL/STM32F1/Servo.cpp
@@ -17,10 +17,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
@@ -30,7 +29,6 @@
uint8_t ServoCount = 0;
#include "Servo.h"
-#include "timers.h"
//#include "Servo.h"
@@ -76,6 +74,7 @@ void libServo::servoWrite(uint8_t inPin, uint16_t duty_cycle) {
libServo::libServo() {
servoIndex = ServoCount < MAX_SERVOS ? ServoCount++ : INVALID_SERVO;
+ timer_set_interrupt_priority(SERVO0_TIMER_NUM, SERVO0_TIMER_IRQ_PRIO);
}
bool libServo::attach(const int32_t inPin, const int32_t inMinAngle, const int32_t inMaxAngle) {
@@ -138,9 +137,7 @@ void libServo::move(const int32_t value) {
angle = constrain(value, minAngle, maxAngle);
servoWrite(pin, US_TO_COMPARE(ANGLE_TO_US(angle)));
safe_delay(servo_delay[servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
diff --git a/Marlin/src/HAL/STM32F1/Servo.h b/Marlin/src/HAL/STM32F1/Servo.h
index b3ca09f238..b6143de81d 100644
--- a/Marlin/src/HAL/STM32F1/Servo.h
+++ b/Marlin/src/HAL/STM32F1/Servo.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/SoftwareSerial.cpp b/Marlin/src/HAL/STM32F1/SoftwareSerial.cpp
index e9e4a162a5..3641c9fdf0 100644
--- a/Marlin/src/HAL/STM32F1/SoftwareSerial.cpp
+++ b/Marlin/src/HAL/STM32F1/SoftwareSerial.cpp
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(__STM32F1__) && !defined(HAVE_SW_SERIAL)
diff --git a/Marlin/src/HAL/STM32F1/SoftwareSerial.h b/Marlin/src/HAL/STM32F1/SoftwareSerial.h
index 1899a2ae0b..1c8058665a 100644
--- a/Marlin/src/HAL/STM32F1/SoftwareSerial.h
+++ b/Marlin/src/HAL/STM32F1/SoftwareSerial.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
index 2e9d11f97e..894abb882a 100644
--- a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
+++ b/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_swspi.cpp
@@ -13,14 +13,14 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __STM32F1__
#include "../../../inc/MarlinConfig.h"
-#if HAS_GRAPHICAL_LCD && ENABLED(FORCE_SOFT_SPI)
+#if BOTH(HAS_GRAPHICAL_LCD, FORCE_SOFT_SPI)
#include "../HAL.h"
#include
diff --git a/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp b/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp
new file mode 100644
index 0000000000..f77306a88a
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp
@@ -0,0 +1,81 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with simple implementations supplied by Marlin.
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(IIC_BL24CXX_EEPROM)
+
+#include "../shared/eeprom_if.h"
+#include "../shared/eeprom_api.h"
+
+//
+// PersistentStore
+//
+
+#ifndef MARLIN_EEPROM_SIZE
+ #error "MARLIN_EEPROM_SIZE is required for IIC_BL24CXX_EEPROM."
+#endif
+
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_start() { eeprom_init(); return true; }
+bool PersistentStore::access_finish() { return true; }
+
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ while (size--) {
+ uint8_t v = *value;
+ uint8_t * const p = (uint8_t * const)pos;
+ // EEPROM has only ~100,000 write cycles,
+ // so only write bytes that have changed!
+ if (v != eeprom_read_byte(p)) {
+ eeprom_write_byte(p, v);
+ delay(2);
+ if (eeprom_read_byte(p) != v) {
+ SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
+ return true;
+ }
+ }
+ 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*/) {
+ do {
+ uint8_t * const p = (uint8_t * const)pos;
+ uint8_t c = eeprom_read_byte(p);
+ if (writing) *value = c;
+ crc16(crc, &c, 1);
+ pos++;
+ value++;
+ } while (--size);
+ return false;
+}
+
+#endif // IIC_BL24CXX_EEPROM
diff --git a/Marlin/src/HAL/STM32F1/eeprom_flash.cpp b/Marlin/src/HAL/STM32F1/eeprom_flash.cpp
index 9c81730465..8db8c8638b 100644
--- a/Marlin/src/HAL/STM32F1/eeprom_flash.cpp
+++ b/Marlin/src/HAL/STM32F1/eeprom_flash.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -39,18 +39,20 @@
#include
// Store settings in the last two pages
-#define EEPROM_SIZE (EEPROM_PAGE_SIZE * 2)
-#define ACCESS_FINISHED(TF) do{ FLASH_Lock(); eeprom_dirty = false; return TF; }while(0)
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE ((EEPROM_PAGE_SIZE) * 2)
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
-static uint8_t ram_eeprom[EEPROM_SIZE] __attribute__((aligned(4))) = {0};
+static uint8_t ram_eeprom[MARLIN_EEPROM_SIZE] __attribute__((aligned(4))) = {0};
static bool eeprom_dirty = false;
bool PersistentStore::access_start() {
const uint32_t* source = reinterpret_cast(EEPROM_PAGE0_BASE);
uint32_t* destination = reinterpret_cast(ram_eeprom);
- static_assert(0 == EEPROM_SIZE % 4, "EEPROM_SIZE is corrupted. (Must be a multiple of 4.)"); // Ensure copying as uint32_t is safe
- constexpr size_t eeprom_size_u32 = EEPROM_SIZE / 4;
+ static_assert(0 == (MARLIN_EEPROM_SIZE) % 4, "MARLIN_EEPROM_SIZE is corrupted. (Must be a multiple of 4.)"); // Ensure copying as uint32_t is safe
+ constexpr size_t eeprom_size_u32 = (MARLIN_EEPROM_SIZE) / 4;
for (size_t i = 0; i < eeprom_size_u32; ++i, ++destination, ++source)
*destination = *source;
@@ -72,13 +74,15 @@ bool PersistentStore::access_finish() {
// page changes...either way, something to look at later.
FLASH_Unlock();
+ #define ACCESS_FINISHED(TF) { FLASH_Lock(); eeprom_dirty = false; return TF; }
+
status = FLASH_ErasePage(EEPROM_PAGE0_BASE);
if (status != FLASH_COMPLETE) ACCESS_FINISHED(true);
status = FLASH_ErasePage(EEPROM_PAGE1_BASE);
if (status != FLASH_COMPLETE) ACCESS_FINISHED(true);
const uint16_t *source = reinterpret_cast(ram_eeprom);
- for (size_t i = 0; i < EEPROM_SIZE; i += 2, ++source) {
+ for (size_t i = 0; i < MARLIN_EEPROM_SIZE; i += 2, ++source) {
if (FLASH_ProgramHalfWord(EEPROM_PAGE0_BASE + i, *source) != FLASH_COMPLETE)
ACCESS_FINISHED(false);
}
@@ -105,7 +109,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return false; // return true for any error
}
-size_t PersistentStore::capacity() { return EEPROM_SIZE; }
-
#endif // FLASH_EEPROM_EMULATION
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/STM32F1/eeprom_if_iic.cpp b/Marlin/src/HAL/STM32F1/eeprom_if_iic.cpp
new file mode 100644
index 0000000000..33dd277add
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/eeprom_if_iic.cpp
@@ -0,0 +1,51 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+/**
+ * Platform-independent Arduino functions for I2C EEPROM.
+ * Enable USE_SHARED_EEPROM if not supplied by the framework.
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(IIC_BL24CXX_EEPROM)
+
+#include "../../libs/BL24CXX.h"
+#include "../shared/eeprom_if.h"
+
+void eeprom_init() { BL24CXX::init(); }
+
+// ------------------------
+// Public functions
+// ------------------------
+
+void eeprom_write_byte(uint8_t *pos, unsigned char value) {
+ const unsigned eeprom_address = (unsigned)pos;
+ return BL24CXX::writeOneByte(eeprom_address, value);
+}
+
+uint8_t eeprom_read_byte(uint8_t *pos) {
+ const unsigned eeprom_address = (unsigned)pos;
+ return BL24CXX::readOneByte(eeprom_address);
+}
+
+#endif // IIC_BL24CXX_EEPROM
diff --git a/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp b/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp
index 7894e69787..11959191f6 100644
--- a/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp
+++ b/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -32,53 +32,44 @@
#if ENABLED(SDCARD_EEPROM_EMULATION)
#include "../shared/eeprom_api.h"
+#include "../../sd/cardreader.h"
-#ifndef E2END
- #define E2END 0xFFF // 4KB
+#define EEPROM_FILENAME "eeprom.dat"
+
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE 0x1000 // 4KB
#endif
-#define HAL_EEPROM_SIZE (E2END + 1)
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
#define _ALIGN(x) __attribute__ ((aligned(x))) // SDIO uint32_t* compat.
-static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
+static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE];
-#if ENABLED(SDSUPPORT)
+bool PersistentStore::access_start() {
+ if (!card.isMounted()) return false;
- #include "../../sd/cardreader.h"
+ SdFile file, root = card.getroot();
+ if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
+ return true; // false aborts the save
- #define EEPROM_FILENAME "eeprom.dat"
+ int bytes_read = file.read(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
+ if (bytes_read < 0) return false;
+ for (; bytes_read < MARLIN_EEPROM_SIZE; bytes_read++)
+ HAL_eeprom_data[bytes_read] = 0xFF;
+ file.close();
+ return true;
+}
- bool PersistentStore::access_start() {
- if (!card.isMounted()) return false;
+bool PersistentStore::access_finish() {
+ if (!card.isMounted()) return false;
- SdFile file, root = card.getroot();
- if (!file.open(&root, EEPROM_FILENAME, O_RDONLY))
- return true; // false aborts the save
-
- int bytes_read = file.read(HAL_eeprom_data, HAL_EEPROM_SIZE);
- if (bytes_read < 0) return false;
- for (; bytes_read < HAL_EEPROM_SIZE; bytes_read++)
- HAL_eeprom_data[bytes_read] = 0xFF;
+ SdFile file, root = card.getroot();
+ int bytes_written = 0;
+ if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
+ bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE);
file.close();
- return true;
}
-
- bool PersistentStore::access_finish() {
- if (!card.isMounted()) return false;
-
- SdFile file, root = card.getroot();
- int bytes_written = 0;
- if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) {
- bytes_written = file.write(HAL_eeprom_data, HAL_EEPROM_SIZE);
- file.close();
- }
- return (bytes_written == HAL_EEPROM_SIZE);
- }
-
-#else // !SDSUPPORT
-
- #error "Please define SPI_EEPROM (in Configuration.h) or disable EEPROM_SETTINGS."
-
-#endif // !SDSUPPORT
+ return (bytes_written == MARLIN_EEPROM_SIZE);
+}
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
for (size_t i = 0; i < size; i++)
@@ -98,7 +89,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
return false;
}
-size_t PersistentStore::capacity() { return HAL_EEPROM_SIZE; }
-
#endif // SDCARD_EEPROM_EMULATION
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/STM32F1/eeprom.cpp b/Marlin/src/HAL/STM32F1/eeprom_wired.cpp
similarity index 83%
rename from Marlin/src/HAL/STM32F1/eeprom.cpp
rename to Marlin/src/HAL/STM32F1/eeprom_wired.cpp
index ed5d50cbde..b4699d00dc 100644
--- a/Marlin/src/HAL/STM32F1/eeprom.cpp
+++ b/Marlin/src/HAL/STM32F1/eeprom_wired.cpp
@@ -14,19 +14,32 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
#if USE_WIRED_EEPROM
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with simple implementations supplied by Marlin.
+ */
+
+#include "../shared/eeprom_if.h"
#include "../shared/eeprom_api.h"
+#ifndef MARLIN_EEPROM_SIZE
+ #error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_finish() { return true; }
+
bool PersistentStore::access_start() {
+ eeprom_init();
#if ENABLED(SPI_EEPROM)
#if SPI_CHAN_EEPROM1 == 1
SET_OUTPUT(BOARD_SPI1_SCK_PIN);
@@ -38,7 +51,6 @@ bool PersistentStore::access_start() {
#endif
return true;
}
-bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
while (size--) {
@@ -56,7 +68,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
crc16(crc, &v, 1);
pos++;
value++;
- };
+ }
return false;
}
@@ -71,7 +83,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() { return E2END + 1; }
-
#endif // USE_WIRED_EEPROM
#endif // __STM32F1__
diff --git a/Marlin/src/HAL/STM32F1/endstop_interrupts.h b/Marlin/src/HAL/STM32F1/endstop_interrupts.h
index 246e292983..bcb07d991d 100644
--- a/Marlin/src/HAL/STM32F1/endstop_interrupts.h
+++ b/Marlin/src/HAL/STM32F1/endstop_interrupts.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -53,43 +53,22 @@
void endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
- #if HAS_X_MAX
- attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE); // assign it
- #endif
- #if HAS_X_MIN
- attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MAX
- attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MIN
- attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MAX
- attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN
- attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MAX
- attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MIN
- attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MAX
- attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MIN
- attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z4_MAX
- attachInterrupt(Z4_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z4_MIN
- attachInterrupt(Z4_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
- #endif
+ #define _ATTACH(P) attachInterrupt(P, endstop_ISR, CHANGE)
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/STM32F1/fastio.h b/Marlin/src/HAL/STM32F1/fastio.h
index 9bf78d4254..e0e2e03a1c 100644
--- a/Marlin/src/HAL/STM32F1/fastio.h
+++ b/Marlin/src/HAL/STM32F1/fastio.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h
index 0285c52ee3..25110d7c80 100644
--- a/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h
@@ -16,7 +16,19 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if ENABLED(USE_USB_COMPOSITE)
+ //#warning "SD_CHECK_AND_RETRY isn't needed with USE_USB_COMPOSITE."
+ #undef SD_CHECK_AND_RETRY
+#endif
+
+// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
+#if ENABLED(TOUCH_SCREEN) && !HAS_GRAPHICAL_TFT
+ #undef TOUCH_SCREEN
+ #undef TOUCH_SCREEN_CALIBRATION
+ #define HAS_TOUCH_XPT2046 1
+#endif
diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_adv.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/STM32F1/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h b/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h
index 0285c52ee3..656fbe1ce2 100644
--- a/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/STM32F1/inc/Conditionals_post.h
@@ -16,7 +16,19 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
+#if USE_FALLBACK_EEPROM
+ #define SDCARD_EEPROM_EMULATION
+#elif EITHER(I2C_EEPROM, SPI_EEPROM)
+ #define USE_SHARED_EEPROM 1
+#endif
+
+// Allow SDSUPPORT to be disabled
+#if DISABLED(SDSUPPORT)
+ #undef SDIO_SUPPORT
+#endif
diff --git a/Marlin/src/HAL/STM32F1/inc/SanityCheck.h b/Marlin/src/HAL/STM32F1/inc/SanityCheck.h
index b8ebc446d6..c0cb486952 100644
--- a/Marlin/src/HAL/STM32F1/inc/SanityCheck.h
+++ b/Marlin/src/HAL/STM32F1/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -29,15 +29,29 @@
#error "EMERGENCY_PARSER is not yet implemented for STM32F1. Disable EMERGENCY_PARSER to continue."
#endif
-#if ENABLED(SDIO_SUPPORT) && DISABLED(SDSUPPORT)
- #error "SDIO_SUPPORT requires SDSUPPORT. Enable SDSUPPORT to continue."
-#endif
-
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32F1."
#endif
#if !defined(HAVE_SW_SERIAL) && HAS_TMC_SW_SERIAL
#warning "With TMC2208/9 consider using SoftwareSerialM with HAVE_SW_SERIAL and appropriate SS_TIMER."
#error "Missing SoftwareSerial implementation."
#endif
+
+#if ENABLED(SDCARD_EEPROM_EMULATION) && DISABLED(SDSUPPORT)
+ #undef SDCARD_EEPROM_EMULATION // Avoid additional error noise
+ #if USE_FALLBACK_EEPROM
+ #warning "EEPROM type not specified. Fallback is SDCARD_EEPROM_EMULATION."
+ #endif
+ #error "SDCARD_EEPROM_EMULATION requires SDSUPPORT. Enable SDSUPPORT or choose another EEPROM emulation."
+#endif
+
+#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
+ #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on this platform."
+#elif ENABLED(SERIAL_STATS_DROPPED_RX)
+ #error "SERIAL_STATS_DROPPED_RX is not supported on this platform."
+#endif
+
+#if ENABLED(NEOPIXEL_LED)
+ #error "NEOPIXEL_LED (Adafruit NeoPixel) is not supported for HAL/STM32F1. Comment out this line to proceed at your own risk!"
+#endif
diff --git a/Marlin/src/HAL/STM32F1/msc_sd.cpp b/Marlin/src/HAL/STM32F1/msc_sd.cpp
index a086b82bc3..ab5530174e 100644
--- a/Marlin/src/HAL/STM32F1/msc_sd.cpp
+++ b/Marlin/src/HAL/STM32F1/msc_sd.cpp
@@ -10,7 +10,7 @@
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
+ * along with this program. If not, see .
*
*/
#ifdef USE_USB_COMPOSITE
@@ -25,7 +25,7 @@ USBCompositeSerial MarlinCompositeSerial;
#include "../../inc/MarlinConfig.h"
-#ifdef HAS_ONBOARD_SD
+#if SD_CONNECTION_IS(ONBOARD)
#include "onboard_sd.h"
@@ -47,7 +47,7 @@ void MSC_SD_init() {
USBComposite.end();
USBComposite.clear();
// Set api and register mass storage
- #ifdef HAS_ONBOARD_SD
+ #if SD_CONNECTION_IS(ONBOARD)
uint32_t cardSize;
if (disk_initialize(0) == RES_OK) {
if (disk_ioctl(0, GET_SECTOR_COUNT, (void *)(&cardSize)) == RES_OK) {
diff --git a/Marlin/src/HAL/STM32F1/msc_sd.h b/Marlin/src/HAL/STM32F1/msc_sd.h
index 125ba36466..8715888f47 100644
--- a/Marlin/src/HAL/STM32F1/msc_sd.h
+++ b/Marlin/src/HAL/STM32F1/msc_sd.h
@@ -10,7 +10,7 @@
* (at your option) any later version.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/onboard_sd.cpp b/Marlin/src/HAL/STM32F1/onboard_sd.cpp
index 0fd94a9199..099e2a0686 100644
--- a/Marlin/src/HAL/STM32F1/onboard_sd.cpp
+++ b/Marlin/src/HAL/STM32F1/onboard_sd.cpp
@@ -14,13 +14,13 @@
#include "../../inc/MarlinConfig.h"
-#ifdef HAS_ONBOARD_SD
+#if SD_CONNECTION_IS(ONBOARD)
#include "onboard_sd.h"
#include "SPI.h"
#include "fastio.h"
-#ifdef SHARED_SD_CARD
+#if HAS_SHARED_MEDIA
#ifndef ON_BOARD_SPI_DEVICE
#define ON_BOARD_SPI_DEVICE SPI_DEVICE
#endif
@@ -553,4 +553,4 @@ DRESULT disk_read (
#endif // _DISKIO_IOCTL
-#endif // HAS_ONBOARD_SD
+#endif // SD_CONNECTION_IS(ONBOARD)
diff --git a/Marlin/src/HAL/STM32F1/pinsDebug.h b/Marlin/src/HAL/STM32F1/pinsDebug.h
index 913cb62afc..2d63ebd770 100644
--- a/Marlin/src/HAL/STM32F1/pinsDebug.h
+++ b/Marlin/src/HAL/STM32F1/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/sdio.cpp b/Marlin/src/HAL/STM32F1/sdio.cpp
index da6beda85c..0e8a745810 100644
--- a/Marlin/src/HAL/STM32F1/sdio.cpp
+++ b/Marlin/src/HAL/STM32F1/sdio.cpp
@@ -17,10 +17,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef ARDUINO_ARCH_STM32F1
#include
@@ -102,7 +101,23 @@ bool SDIO_ReadBlock_DMA(uint32_t blockAddress, uint8_t *data) {
return false;
}
- while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) {}
+ while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) { /* wait */ }
+
+ //If there were SDIO errors, do not wait DMA.
+ if (SDIO->STA & SDIO_STA_TRX_ERROR_FLAGS) {
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
+ dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
+ return false;
+ }
+
+ //Wait for DMA transaction to complete
+ while ((DMA2_BASE->ISR & (DMA_ISR_TEIF4|DMA_ISR_TCIF4)) == 0 ) { /* wait */ }
+
+ if (DMA2_BASE->ISR & DMA_ISR_TEIF4) {
+ dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
+ SDIO_CLEAR_FLAG(SDIO_ICR_CMD_FLAGS | SDIO_ICR_DATA_FLAGS);
+ return false;
+ }
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
@@ -121,7 +136,7 @@ bool SDIO_ReadBlock_DMA(uint32_t blockAddress, uint8_t *data) {
}
bool SDIO_ReadBlock(uint32_t blockAddress, uint8_t *data) {
- uint32_t retries = 3;
+ uint32_t retries = SDIO_READ_RETRIES;
while (retries--) if (SDIO_ReadBlock_DMA(blockAddress, data)) return true;
return false;
}
@@ -147,7 +162,7 @@ bool SDIO_WriteBlock(uint32_t blockAddress, const uint8_t *data) {
sdio_setup_transfer(SDIO_DATA_TIMEOUT * (F_CPU / 1000U), 512U, SDIO_BLOCKSIZE_512 | SDIO_DCTRL_DMAEN | SDIO_DCTRL_DTEN);
- while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) {}
+ while (!SDIO_GET_FLAG(SDIO_STA_DATAEND | SDIO_STA_TRX_ERROR_FLAGS)) { /* wait */ }
dma_disable(SDIO_DMA_DEV, SDIO_DMA_CHANNEL);
diff --git a/Marlin/src/HAL/STM32F1/sdio.h b/Marlin/src/HAL/STM32F1/sdio.h
index f51ba6d0a6..8777299f01 100644
--- a/Marlin/src/HAL/STM32F1/sdio.h
+++ b/Marlin/src/HAL/STM32F1/sdio.h
@@ -16,12 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-#include "../shared/Marduino.h"
+#include "../../inc/MarlinConfig.h" // Allow pins/pins.h to override SDIO clock / retries
#include
#include
@@ -100,7 +100,13 @@
#define SDIO_DATA_TIMEOUT 100U /* Read data transfer timeout */
#define SDIO_WRITE_TIMEOUT 200U /* Write data transfer timeout */
-#define SDIO_CLOCK 18000000 /* 18 MHz */
+#ifndef SDIO_CLOCK
+ #define SDIO_CLOCK 18000000 /* 18 MHz */
+#endif
+
+#ifndef SDIO_READ_RETRIES
+ #define SDIO_READ_RETRIES 3
+#endif
// ------------------------
// Types
diff --git a/Marlin/src/HAL/STM32F1/spi_pins.h b/Marlin/src/HAL/STM32F1/spi_pins.h
index e8e4cbba11..8f2b324f64 100644
--- a/Marlin/src/HAL/STM32F1/spi_pins.h
+++ b/Marlin/src/HAL/STM32F1/spi_pins.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
similarity index 52%
rename from Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
rename to Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
index cc26a003d1..bc1b012dc7 100644
--- a/Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_fsmc.cpp
+++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
@@ -16,100 +16,20 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-/**
- * u8g_com_stm32duino_fsmc.cpp
- *
- * Communication interface for FSMC
- */
-
#include "../../../inc/MarlinConfig.h"
-#if defined(ARDUINO_ARCH_STM32F1) && PIN_EXISTS(FSMC_CS) // FSMC on 100/144 pins SoCs
+#if HAS_FSMC_TFT
-#if HAS_GRAPHICAL_LCD
-
-#include
+#include "tft_fsmc.h"
#include
#include
#include
-#include
-#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
-#define FSMC_DATA_SETUP_TIME 15 // DataSetupTime
-
-void LCD_IO_Init(uint8_t cs, uint8_t rs);
-void LCD_IO_WriteData(uint16_t RegValue);
-void LCD_IO_WriteReg(uint16_t Reg);
-uint16_t LCD_IO_ReadData(uint16_t RegValue);
-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
-
-uint8_t u8g_com_stm32duino_fsmc_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
- if (msgInitCount) {
- if (msg == U8G_COM_MSG_INIT) msgInitCount--;
- if (msgInitCount) return -1;
- }
-
- static uint8_t isCommand;
-
- switch (msg) {
- 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(50);
-
- if (arg_ptr) {
- *((uint32_t *)arg_ptr) = LCD_IO_ReadData(0x0000);
- if (*((uint32_t *)arg_ptr) == 0)
- *((uint32_t *)arg_ptr) = (LCD_READ_ID << 24) | 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)
- isCommand = arg_val == 0 ? 1 : 0;
- break;
-
- case U8G_COM_MSG_RESET:
- u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
- break;
-
- case U8G_COM_MSG_WRITE_BYTE:
- if (isCommand)
- LCD_IO_WriteReg(arg_val);
- else
- LCD_IO_WriteData((uint16_t)arg_val);
- 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;
- }
- return 1;
-}
+LCD_CONTROLLER_TypeDef *TFT_FSMC::LCD;
/**
* FSMC LCD IO
@@ -160,27 +80,35 @@ __attribute__((always_inline)) __STATIC_INLINE void __DSB() {
#define FSMC_RS_A25 PG14
#endif
+/* Timing configuration */
+#define FSMC_ADDRESS_SETUP_TIME 15 // AddressSetupTime
+#define FSMC_DATA_SETUP_TIME 15 // DataSetupTime
+
static uint8_t fsmcInit = 0;
-
-typedef struct {
- __IO uint16_t REG;
- __IO uint16_t RAM;
-} LCD_CONTROLLER_TypeDef;
-
-LCD_CONTROLLER_TypeDef *LCD;
-
-void LCD_IO_Init(uint8_t cs, uint8_t rs) {
+void TFT_FSMC::Init() {
+ uint8_t cs = FSMC_CS_PIN, rs = FSMC_RS_PIN;
uint32_t controllerAddress;
+ #if PIN_EXISTS(TFT_RESET)
+ OUT_WRITE(TFT_RESET_PIN, HIGH);
+ delay(100);
+ #endif
+
+ #if PIN_EXISTS(TFT_BACKLIGHT)
+ OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
+ #endif
+
+ struct fsmc_nor_psram_reg_map* fsmcPsramRegion;
+
if (fsmcInit) return;
fsmcInit = 1;
switch (cs) {
- case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; break;
+ case FSMC_CS_NE1: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION1; fsmcPsramRegion = FSMC_NOR_PSRAM1_BASE; break;
#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;
+ case FSMC_CS_NE2: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION2; fsmcPsramRegion = FSMC_NOR_PSRAM2_BASE; break;
+ case FSMC_CS_NE3: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION3; fsmcPsramRegion = FSMC_NOR_PSRAM3_BASE; break;
+ case FSMC_CS_NE4: controllerAddress = (uint32_t)FSMC_NOR_PSRAM_REGION4; fsmcPsramRegion = FSMC_NOR_PSRAM4_BASE; break;
#endif
default: return;
}
@@ -246,90 +174,65 @@ 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
- #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)
- FSMC_NOR_PSRAM1_BASE->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
- FSMC_NOR_PSRAM1_BASE->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
- #endif
+ fsmcPsramRegion->BCR = FSMC_BCR_WREN | FSMC_BCR_MTYP_SRAM | FSMC_BCR_MWID_16BITS | FSMC_BCR_MBKEN;
+ fsmcPsramRegion->BTR = (FSMC_DATA_SETUP_TIME << 8) | FSMC_ADDRESS_SETUP_TIME;
afio_remap(AFIO_REMAP_FSMC_NADV);
LCD = (LCD_CONTROLLER_TypeDef*)controllerAddress;
}
-void LCD_IO_WriteData(uint16_t RegValue) {
- LCD->RAM = RegValue;
+void TFT_FSMC::Transmit(uint16_t Data) {
+ LCD->RAM = Data;
__DSB();
}
-void LCD_IO_WriteReg(uint16_t Reg) {
+void TFT_FSMC::WriteReg(uint16_t Reg) {
LCD->REG = Reg;
__DSB();
}
-uint16_t LCD_IO_ReadData(uint16_t RegValue) {
- LCD->REG = RegValue;
- __DSB();
+uint32_t TFT_FSMC::GetID() {
+ uint32_t id;
+ WriteReg(0x0000);
+ id = LCD->RAM;
- return LCD->RAM;
+ if (id == 0)
+ id = ReadID(LCD_READ_ID);
+ if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
+ id = ReadID(LCD_READ_ID4);
+ return id;
}
-uint32_t LCD_IO_ReadData(uint16_t RegValue, uint8_t ReadSize) {
- volatile uint32_t data;
- LCD->REG = RegValue;
- __DSB();
+ uint32_t TFT_FSMC::ReadID(uint16_t Reg) {
+ uint32_t id;
+ WriteReg(Reg);
+ id = LCD->RAM; // dummy read
+ id = Reg << 24;
+ id |= (LCD->RAM & 0x00FF) << 16;
+ id |= (LCD->RAM & 0x00FF) << 8;
+ id |= LCD->RAM & 0x00FF;
+ return id;
+ }
- data = LCD->RAM; // dummy read
- data = LCD->RAM & 0x00FF;
-
- while (--ReadSize) {
- data <<= 8;
- data |= (LCD->RAM & 0x00FF);
- }
- return uint32_t(data);
+bool TFT_FSMC::isBusy() {
+ return false;
}
-#if ENABLED(LCD_USE_DMA_FSMC)
+void TFT_FSMC::Abort() {
-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);
+}
+
+void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
+ #if defined(FSMC_DMA_DEV) && defined(FSMC_DMA_CHANNEL)
+ dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease);
+ dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, 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;
- }
+ #endif
}
-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
+#endif // HAS_FSMC_TFT
diff --git a/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h
new file mode 100644
index 0000000000..6fcfea8a11
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/tft/tft_fsmc.h
@@ -0,0 +1,71 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
+#ifndef LCD_READ_ID4
+ #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
+#endif
+
+#include
+
+#define DATASIZE_8BIT DMA_SIZE_8BITS
+#define DATASIZE_16BIT DMA_SIZE_16BITS
+#define TFT_IO TFT_FSMC
+
+typedef struct {
+ __IO uint16_t REG;
+ __IO uint16_t RAM;
+} LCD_CONTROLLER_TypeDef;
+
+class TFT_FSMC {
+ private:
+ static LCD_CONTROLLER_TypeDef *LCD;
+
+ static uint32_t ReadID(uint16_t Reg);
+ static void Transmit(uint16_t Data);
+ static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
+
+ public:
+ static void Init();
+ static uint32_t GetID();
+ static bool isBusy();
+ static void Abort();
+
+ static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) {};
+ static void DataTransferEnd() {};
+
+ static void WriteData(uint16_t Data) { Transmit(Data); }
+ static void WriteReg(uint16_t Reg);
+
+ static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_MODE, Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_CIRC_MODE, &Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint32_t Count) {
+ static uint16_t Data; Data = Color;
+ while (Count > 0) {
+ TransmitDMA(DMA_CIRC_MODE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
+ Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
+ }
+ }
+};
diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp
new file mode 100644
index 0000000000..1095389946
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.cpp
@@ -0,0 +1,149 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_SPI_TFT
+
+#include "tft_spi.h"
+
+// TFT_SPI tft;
+
+SPIClass TFT_SPI::SPIx(1);
+
+#define TFT_CS_H OUT_WRITE(TFT_CS_PIN, HIGH)
+#define TFT_CS_L OUT_WRITE(TFT_CS_PIN, LOW)
+
+#define TFT_DC_H OUT_WRITE(TFT_DC_PIN, HIGH)
+#define TFT_DC_L OUT_WRITE(TFT_DC_PIN, LOW)
+
+#define TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH)
+#define TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW)
+
+#define TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH)
+#define TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW)
+
+void TFT_SPI::Init() {
+ #if PIN_EXISTS(TFT_RESET)
+ // OUT_WRITE(TFT_RESET_PIN, HIGH);
+ TFT_RST_H;
+ delay(100);
+ #endif
+
+ #if PIN_EXISTS(TFT_BACKLIGHT)
+ // OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
+ TFT_BLK_H;
+ #endif
+
+ TFT_DC_H;
+ TFT_CS_H;
+
+ /**
+ * 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;
+ uint8_t spiRate = SPI_FULL_SPEED;
+ switch (spiRate) {
+ 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
+ }
+ SPIx.setModule(1);
+ SPIx.setClockDivider(clock);
+ SPIx.setBitOrder(MSBFIRST);
+ SPIx.setDataMode(SPI_MODE0);
+}
+
+void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
+ SPIx.setDataSize(DataSize);
+ SPIx.begin();
+ TFT_CS_L;
+}
+
+uint32_t TFT_SPI::GetID() {
+ uint32_t id;
+ id = ReadID(LCD_READ_ID);
+
+ if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF)
+ id = ReadID(LCD_READ_ID4);
+ return id;
+}
+
+uint32_t TFT_SPI::ReadID(uint16_t Reg) {
+ #if !PIN_EXISTS(TFT_MISO)
+ return 0;
+ #else
+ uint8_t d = 0;
+ uint32_t data = 0;
+ SPIx.setClockDivider(SPI_CLOCK_DIV16);
+ DataTransferBegin(DATASIZE_8BIT);
+ WriteReg(Reg);
+
+ LOOP_L_N(i, 4) {
+ SPIx.read((uint8_t*)&d, 1);
+ data = (data << 8) | d;
+ }
+
+ DataTransferEnd();
+ SPIx.setClockDivider(SPI_CLOCK_MAX);
+
+ return data >> 7;
+ #endif
+}
+
+bool TFT_SPI::isBusy() {
+ return false;
+}
+
+void TFT_SPI::Abort() {
+ DataTransferEnd();
+}
+
+void TFT_SPI::Transmit(uint16_t Data) {
+ SPIx.send(Data);
+}
+
+void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
+ DataTransferBegin();
+ TFT_DC_H;
+ if (MemoryIncrease == DMA_MINC_ENABLE) {
+ SPIx.dmaSend(Data, Count, true);
+ }
+ else {
+ SPIx.dmaSend(Data, Count, false);
+ }
+
+ DataTransferEnd();
+}
+
+#endif // HAS_SPI_TFT
diff --git a/Marlin/src/HAL/STM32F1/tft/tft_spi.h b/Marlin/src/HAL/STM32F1/tft/tft_spi.h
new file mode 100644
index 0000000000..bb26fc21b6
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/tft/tft_spi.h
@@ -0,0 +1,72 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "../../../inc/MarlinConfig.h"
+
+#include
+
+#ifndef LCD_READ_ID
+ #define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
+#endif
+#ifndef LCD_READ_ID4
+ #define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
+#endif
+
+#define DATASIZE_8BIT DATA_SIZE_8BIT
+#define DATASIZE_16BIT DATA_SIZE_16BIT
+#define TFT_IO TFT_SPI
+
+#define DMA_MINC_ENABLE 1
+#define DMA_MINC_DISABLE 0
+
+class TFT_SPI {
+private:
+ static uint32_t ReadID(uint16_t Reg);
+ static void Transmit(uint16_t Data);
+ static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);
+
+public:
+ static SPIClass SPIx;
+
+ static void Init();
+ static uint32_t GetID();
+ static bool isBusy();
+ static void Abort();
+
+ static void DataTransferBegin(uint16_t DataWidth = DATA_SIZE_16BIT);
+ static void DataTransferEnd() { WRITE(TFT_CS_PIN, HIGH); SPIx.end(); };
+ static void DataTransferAbort();
+
+ static void WriteData(uint16_t Data) { Transmit(Data); }
+ static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); }
+
+ static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
+ static void WriteMultiple(uint16_t Color, uint32_t Count) {
+ static uint16_t Data; Data = Color;
+ while (Count > 0) {
+ TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
+ Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
+ }
+ }
+};
diff --git a/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp
new file mode 100644
index 0000000000..616d05fead
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/tft/xpt2046.cpp
@@ -0,0 +1,141 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+
+#include "../../../inc/MarlinConfig.h"
+
+#if HAS_TFT_XPT2046 || HAS_TOUCH_XPT2046
+
+#include "xpt2046.h"
+#include
+
+uint16_t delta(uint16_t a, uint16_t b) { return a > b ? a - b : b - a; }
+
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ #include
+
+ SPIClass XPT2046::SPIx(TOUCH_BUTTONS_HW_SPI_DEVICE);
+
+ static void touch_spi_init(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
+ */
+ uint8_t clock;
+ switch (spiRate) {
+ case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV4; 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
+ }
+ XPT2046::SPIx.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
+ XPT2046::SPIx.setClockDivider(clock);
+ XPT2046::SPIx.setBitOrder(MSBFIRST);
+ XPT2046::SPIx.setDataMode(SPI_MODE0);
+ }
+#endif // TOUCH_BUTTONS_HW_SPI
+
+void XPT2046::Init() {
+ SET_INPUT(TOUCH_MISO_PIN);
+ SET_OUTPUT(TOUCH_MOSI_PIN);
+ SET_OUTPUT(TOUCH_SCK_PIN);
+ OUT_WRITE(TOUCH_CS_PIN, HIGH);
+
+ #if PIN_EXISTS(TOUCH_INT)
+ // Optional Pendrive interrupt pin
+ SET_INPUT(TOUCH_INT_PIN);
+ #endif
+
+ TERN_(TOUCH_BUTTONS_HW_SPI, touch_spi_init(SPI_SPEED_6));
+
+ // Read once to enable pendrive status pin
+ getRawData(XPT2046_X);
+}
+
+bool XPT2046::isTouched() {
+ return isBusy() ? false : (
+ #if PIN_EXISTS(TOUCH_INT)
+ READ(TOUCH_INT_PIN) != HIGH
+ #else
+ getRawData(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
+ #endif
+ );
+}
+
+bool XPT2046::getRawPoint(int16_t *x, int16_t *y) {
+ if (isBusy()) return false;
+ if (!isTouched()) return false;
+ *x = getRawData(XPT2046_X);
+ *y = getRawData(XPT2046_Y);
+ return isTouched();
+}
+
+uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) {
+ uint16_t data[3];
+
+ DataTransferBegin();
+ TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.begin());
+
+ for (uint16_t i = 0; i < 3 ; i++) {
+ IO(coordinate);
+ data[i] = (IO() << 4) | (IO() >> 4);
+ }
+
+ TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.end());
+ DataTransferEnd();
+
+ uint16_t delta01 = delta(data[0], data[1]),
+ delta02 = delta(data[0], data[2]),
+ delta12 = delta(data[1], data[2]);
+
+ if (delta01 > delta02 || delta01 > delta12)
+ data[delta02 > delta12 ? 0 : 1] = data[2];
+
+ return (data[0] + data[1]) >> 1;
+}
+
+uint16_t XPT2046::IO(uint16_t data) {
+ return TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data);
+}
+
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ uint16_t XPT2046::HardwareIO(uint16_t data) {
+ uint16_t result = SPIx.transfer(data);
+ return result;
+ }
+#endif
+
+uint16_t XPT2046::SoftwareIO(uint16_t data) {
+ uint16_t result = 0;
+
+ for (uint8_t j = 0x80; j; j >>= 1) {
+ WRITE(TOUCH_SCK_PIN, LOW);
+ WRITE(TOUCH_MOSI_PIN, data & j ? HIGH : LOW);
+ if (READ(TOUCH_MISO_PIN)) result |= j;
+ WRITE(TOUCH_SCK_PIN, HIGH);
+ }
+ WRITE(TOUCH_SCK_PIN, LOW);
+
+ return result;
+}
+
+#endif // HAS_TFT_XPT2046
diff --git a/Marlin/src/HAL/STM32F1/tft/xpt2046.h b/Marlin/src/HAL/STM32F1/tft/xpt2046.h
new file mode 100644
index 0000000000..019f75efce
--- /dev/null
+++ b/Marlin/src/HAL/STM32F1/tft/xpt2046.h
@@ -0,0 +1,80 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+#include "../../../inc/MarlinConfig.h"
+
+#if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ #include
+#endif
+
+#ifndef TOUCH_MISO_PIN
+ #define TOUCH_MISO_PIN MISO_PIN
+#endif
+#ifndef TOUCH_MOSI_PIN
+ #define TOUCH_MOSI_PIN MOSI_PIN
+#endif
+#ifndef TOUCH_SCK_PIN
+ #define TOUCH_SCK_PIN SCK_PIN
+#endif
+#ifndef TOUCH_CS_PIN
+ #define TOUCH_CS_PIN CS_PIN
+#endif
+#ifndef TOUCH_INT_PIN
+ #define TOUCH_INT_PIN -1
+#endif
+
+#define XPT2046_DFR_MODE 0x00
+#define XPT2046_SER_MODE 0x04
+#define XPT2046_CONTROL 0x80
+
+enum XPTCoordinate : uint8_t {
+ XPT2046_X = 0x10 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Y = 0x50 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Z1 = 0x30 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+ XPT2046_Z2 = 0x40 | XPT2046_CONTROL | XPT2046_DFR_MODE,
+};
+
+#if !defined(XPT2046_Z1_THRESHOLD)
+ #define XPT2046_Z1_THRESHOLD 10
+#endif
+
+class XPT2046 {
+private:
+ static bool isBusy() { return false; }
+
+ static uint16_t getRawData(const XPTCoordinate coordinate);
+ static bool isTouched();
+
+ static inline void DataTransferBegin() { WRITE(TOUCH_CS_PIN, LOW); };
+ static inline void DataTransferEnd() { WRITE(TOUCH_CS_PIN, HIGH); };
+ #if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ static uint16_t HardwareIO(uint16_t data);
+ #endif
+ static uint16_t SoftwareIO(uint16_t data);
+ static uint16_t IO(uint16_t data = 0);
+
+public:
+ #if ENABLED(TOUCH_BUTTONS_HW_SPI)
+ static SPIClass SPIx;
+ #endif
+
+ static void Init();
+ static bool getRawPoint(int16_t *x, int16_t *y);
+};
diff --git a/Marlin/src/HAL/STM32F1/timers.cpp b/Marlin/src/HAL/STM32F1/timers.cpp
index 720bd37ba4..8c2df1e216 100644
--- a/Marlin/src/HAL/STM32F1/timers.cpp
+++ b/Marlin/src/HAL/STM32F1/timers.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -27,8 +27,6 @@
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
-#include "HAL.h"
-#include "timers.h"
// ------------------------
// Local defines
@@ -49,7 +47,10 @@
* TODO: Calculate Timer prescale value, so we get the 32bit to adjust
*/
-void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
+
+
+
+void timer_set_interrupt_priority(uint_fast8_t timer_num, uint_fast8_t priority) {
nvic_irq_num irq_num;
switch (timer_num) {
case 1: irq_num = NVIC_TIMER1_CC; break;
@@ -66,9 +67,14 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
* This should never happen. Add a Sanitycheck for timer number.
* Should be a general timer since basic timers have no CC channels.
*/
- break;
+ return;
}
+ nvic_irq_set_priority(irq_num, priority);
+}
+
+
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
/**
* Give the Stepper ISR a higher priority (lower number)
* so it automatically preempts the Temperature ISR.
@@ -85,7 +91,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (STEPPER_TIMER_RATE) / frequency));
timer_no_ARR_preload_ARPE(STEP_TIMER_DEV); // Need to be sure no preload on ARR register
timer_attach_interrupt(STEP_TIMER_DEV, STEP_TIMER_CHAN, stepTC_Handler);
- nvic_irq_set_priority(irq_num, STEP_TIMER_IRQ_PRIO);
+ timer_set_interrupt_priority(STEP_TIMER_NUM, STEP_TIMER_IRQ_PRIO);
timer_generate_update(STEP_TIMER_DEV);
timer_resume(STEP_TIMER_DEV);
break;
@@ -97,7 +103,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
timer_set_reload(TEMP_TIMER_DEV, 0xFFFF);
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, _MIN(hal_timer_t(HAL_TIMER_TYPE_MAX), (F_CPU) / (TEMP_TIMER_PRESCALE) / frequency));
timer_attach_interrupt(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, tempTC_Handler);
- nvic_irq_set_priority(irq_num, TEMP_TIMER_IRQ_PRIO);
+ timer_set_interrupt_priority(TEMP_TIMER_NUM, TEMP_TIMER_IRQ_PRIO);
timer_generate_update(TEMP_TIMER_DEV);
timer_resume(TEMP_TIMER_DEV);
break;
diff --git a/Marlin/src/HAL/STM32F1/timers.h b/Marlin/src/HAL/STM32F1/timers.h
index e5733cc563..6f360f6bfc 100644
--- a/Marlin/src/HAL/STM32F1/timers.h
+++ b/Marlin/src/HAL/STM32F1/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -44,8 +44,12 @@ typedef uint16_t hal_timer_t;
#define HAL_TIMER_RATE uint32_t(F_CPU) // frequency of timers peripherals
-#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
-#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
+#ifndef STEP_TIMER_CHAN
+ #define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
+#endif
+#ifndef TEMP_TIMER_CHAN
+ #define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
+#endif
/**
* Note: Timers may be used by platforms and libraries
@@ -61,14 +65,20 @@ typedef uint16_t hal_timer_t;
* - Otherwise it uses Timer 8 on boards with STM32_HIGH_DENSITY
* or Timer 4 on other boards.
*/
-#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
- #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
-#else
- #define STEP_TIMER_NUM 5 // for other boards, five is fine.
+#ifndef STEP_TIMER_NUM
+ #if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
+ #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
+ #else
+ #define STEP_TIMER_NUM 5 // for other boards, five is fine.
+ #endif
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 2 // Timer Index for Temperature
+ //#define TEMP_TIMER_NUM 4 // 2->4, Timer 2 for Stepper Current PWM
#endif
-#define TEMP_TIMER_NUM 2 // index of timer to use for temperature
-//#define TEMP_TIMER_NUM 4 // 2->4, Timer 2 for Stepper Current PWM
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
#if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_E3_DIP, BTT_SKR_MINI_E3_V1_2, MKS_ROBIN_LITE)
// SKR Mini E3 boards use PA8 as FAN_PIN, so TIMER 1 is used for Fan PWM.
@@ -81,8 +91,9 @@ typedef uint16_t hal_timer_t;
#define SERVO0_TIMER_NUM 1 // SERVO0 or BLTOUCH
#endif
-#define STEP_TIMER_IRQ_PRIO 1
-#define TEMP_TIMER_IRQ_PRIO 2
+#define STEP_TIMER_IRQ_PRIO 2
+#define TEMP_TIMER_IRQ_PRIO 3
+#define SERVO0_TIMER_IRQ_PRIO 1
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -111,8 +122,12 @@ timer_dev* get_timer_dev(int number);
// TODO change this
-#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
-#define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
+#endif
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
+#endif
extern "C" void tempTC_Handler();
extern "C" void stepTC_Handler();
@@ -179,4 +194,6 @@ FORCE_INLINE static void timer_no_ARR_preload_ARPE(timer_dev *dev) {
bb_peri_set_bit(&(dev->regs).gen->CR1, TIMER_CR1_ARPE_BIT, 0);
}
+void timer_set_interrupt_priority(uint_fast8_t timer_num, uint_fast8_t priority);
+
#define TIMER_OC_NO_PRELOAD 0 // Need to disable preload also on compare registers.
diff --git a/Marlin/src/HAL/STM32F1/watchdog.cpp b/Marlin/src/HAL/STM32F1/watchdog.cpp
index 9556d1fa66..4123bc3ef0 100644
--- a/Marlin/src/HAL/STM32F1/watchdog.cpp
+++ b/Marlin/src/HAL/STM32F1/watchdog.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/STM32F1/watchdog.h b/Marlin/src/HAL/STM32F1/watchdog.h
index 7218b1a720..7185d69775 100644
--- a/Marlin/src/HAL/STM32F1/watchdog.h
+++ b/Marlin/src/HAL/STM32F1/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.cpp b/Marlin/src/HAL/STM32_F4_F7/HAL.cpp
index 5acda8af41..b4629d2afd 100644
--- a/Marlin/src/HAL/STM32_F4_F7/HAL.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/HAL.cpp
@@ -17,10 +17,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "HAL.h"
diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL.h b/Marlin/src/HAL/STM32_F4_F7/HAL.h
index b5d8ac29cf..5601400c5a 100644
--- a/Marlin/src/HAL/STM32_F4_F7/HAL.h
+++ b/Marlin/src/HAL/STM32_F4_F7/HAL.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -31,7 +31,6 @@
#include "../shared/HAL_SPI.h"
#include "fastio.h"
-#include "timers.h"
#include "watchdog.h"
#include
@@ -51,6 +50,8 @@
#error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
#elif SERIAL_PORT == -1
#define MYSERIAL0 SerialUSB
+#elif SERIAL_PORT == 0
+ #define MYSERIAL0 Serial1
#elif SERIAL_PORT == 1
#define MYSERIAL0 SerialUART1
#elif SERIAL_PORT == 2
@@ -74,6 +75,8 @@
#error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
#elif SERIAL_PORT_2 == -1
#define MYSERIAL1 SerialUSB
+ #elif SERIAL_PORT_2 == 0
+ #define MYSERIAL1 Serial1
#elif SERIAL_PORT_2 == 1
#define MYSERIAL1 SerialUART1
#elif SERIAL_PORT_2 == 2
@@ -103,6 +106,8 @@
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
#elif DGUS_SERIAL_PORT == -1
#define DGUS_SERIAL SerialUSB
+ #elif DGUS_SERIAL_PORT == 0
+ #define DGUS_SERIAL Serial1
#elif DGUS_SERIAL_PORT == 1
#define DGUS_SERIAL SerialUART1
#elif DGUS_SERIAL_PORT == 2
@@ -206,19 +211,6 @@ static inline int freeMemory() {
#pragma GCC diagnostic pop
-//
-// EEPROM
-//
-
-/**
- * TODO: Write all this EEPROM stuff. Can emulate EEPROM in flash as last resort.
- * Wire library should work for i2c EEPROMs.
- */
-void eeprom_write_byte(uint8_t *pos, unsigned char value);
-uint8_t eeprom_read_byte(uint8_t *pos);
-void eeprom_read_block (void *__dst, const void *__src, size_t __n);
-void eeprom_update_block (const void *__src, void *__dst, size_t __n);
-
//
// ADC
//
@@ -227,8 +219,9 @@ void eeprom_update_block (const void *__src, void *__dst, size_t __n);
inline void HAL_adc_init() {}
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_result
#define HAL_ADC_READY() true
diff --git a/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp b/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp
index deb14f2cfe..6fe81819ab 100644
--- a/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/HAL_SPI.cpp
@@ -17,9 +17,10 @@
* 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 .
+ * along with this program. If not, see .
*
*/
+#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
/**
* Software SPI functions originally from Arduino Sd2Card Library
@@ -30,8 +31,6 @@
* Adapted to the Marlin STM32F4/7 HAL
*/
-#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
-
#include "../../inc/MarlinConfig.h"
#include
@@ -121,7 +120,7 @@ uint8_t spiRec() {
*/
void spiRead(uint8_t* buf, uint16_t nbyte) {
SPI.beginTransaction(spiConfig);
- #ifdef STM32GENERIC
+ #ifndef STM32GENERIC
SPI.dmaTransfer(0, const_cast(buf), nbyte);
#else
SPI.transfer((uint8_t*)buf, nbyte);
@@ -153,7 +152,7 @@ void spiSend(uint8_t b) {
void spiSendBlock(uint8_t token, const uint8_t* buf) {
SPI.beginTransaction(spiConfig);
SPI.transfer(token);
- #ifdef STM32GENERIC
+ #ifndef STM32GENERIC
SPI.dmaSend(const_cast(buf), 512);
#else
SPI.transfer((uint8_t*)buf, nullptr, 512);
diff --git a/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.cpp b/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.cpp
index ffd46dae60..dc41f89131 100644
--- a/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.cpp
@@ -16,14 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && defined(STM32F4)
-#include "../HAL.h"
-#include "timers.h"
+#include "../../../inc/MarlinConfig.h"
// ------------------------
// Local defines
diff --git a/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.h b/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.h
index c52f5ea21c..a4a7ad82cc 100644
--- a/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.h
+++ b/Marlin/src/HAL/STM32_F4_F7/STM32F4/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -34,9 +34,15 @@
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
-#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 PULSE_TIMER_NUM STEP_TIMER_NUM
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
@@ -59,17 +65,19 @@
// TODO change this
#ifdef STM32GENERIC
- extern void TC5_Handler();
- extern void TC7_Handler();
- #define HAL_STEP_TIMER_ISR() void TC5_Handler()
- #define HAL_TEMP_TIMER_ISR() void TC7_Handler()
+ #define TC_TIMER_ARGS
#else
- extern void TC5_Handler(stimer_t *htim);
- extern void TC7_Handler(stimer_t *htim);
- #define HAL_STEP_TIMER_ISR() void TC5_Handler(stimer_t *htim)
- #define HAL_TEMP_TIMER_ISR() void TC7_Handler(stimer_t *htim)
+ #define TC_TIMER_ARGS stimer_t *htim
#endif
+extern void TC5_Handler(TC_TIMER_ARGS);
+extern void TC7_Handler(TC_TIMER_ARGS);
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() void TC5_Handler(TC_TIMER_ARGS)
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() void TC7_Handler(TC_TIMER_ARGS)
+#endif
// ------------------------
// Types
diff --git a/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp b/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
index b030459029..4d116f440b 100644
--- a/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/STM32F7/TMC2660.cpp
@@ -40,7 +40,7 @@
#include "../../../module/stepper/indirection.h"
#include "../../../module/printcounter.h"
#include "../../../libs/duration_t.h"
-#include "../../../libs/hex_print_routines.h"
+#include "../../../libs/hex_print.h"
//some default values used in initialization
#define DEFAULT_MICROSTEPPING_VALUE 32
diff --git a/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.cpp b/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.cpp
index d90f22e03a..f7ded7454d 100644
--- a/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.cpp
@@ -16,14 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && defined(STM32F7)
-#include "../HAL.h"
-#include "timers.h"
+#include "../../../inc/MarlinConfig.h"
// ------------------------
// Local defines
diff --git a/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.h b/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.h
index 00428c54f1..d2f78259d6 100644
--- a/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.h
+++ b/Marlin/src/HAL/STM32_F4_F7/STM32F7/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -34,9 +34,15 @@
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq() / 2) // frequency of timer peripherals
-#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 PULSE_TIMER_NUM STEP_TIMER_NUM
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
@@ -62,8 +68,12 @@
extern void TC5_Handler();
extern void TC7_Handler();
-#define HAL_STEP_TIMER_ISR() void TC5_Handler()
-#define HAL_TEMP_TIMER_ISR() void TC7_Handler()
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() void TC5_Handler()
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() void TC7_Handler()
+#endif
// ------------------------
// Types
diff --git a/Marlin/src/HAL/STM32_F4_F7/Servo.cpp b/Marlin/src/HAL/STM32_F4_F7/Servo.cpp
index e7fb15e6b1..7185468f50 100644
--- a/Marlin/src/HAL/STM32_F4_F7/Servo.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/Servo.cpp
@@ -17,10 +17,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfig.h"
@@ -44,9 +43,7 @@ void libServo::move(const int value) {
if (attach(0) >= 0) {
write(value);
safe_delay(servo_delay[servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
diff --git a/Marlin/src/HAL/STM32_F4_F7/Servo.h b/Marlin/src/HAL/STM32_F4_F7/Servo.h
index 076a547bb2..e42cc60840 100644
--- a/Marlin/src/HAL/STM32_F4_F7/Servo.h
+++ b/Marlin/src/HAL/STM32_F4_F7/Servo.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp b/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp
index 3358fa3df7..e0726c7cd5 100644
--- a/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.cpp
@@ -1,6 +1,6 @@
/**
******************************************************************************
- * @file EEPROM/EEPROM_Emulation/src/eeprom.c
+ * @file eeprom_emul.cpp
* @author MCD Application Team
* @version V1.2.6
* @date 04-November-2016
@@ -49,6 +49,10 @@
*/
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(FLASH_EEPROM_EMULATION)
+
/* Includes ------------------------------------------------------------------*/
#include "eeprom_emul.h"
@@ -61,7 +65,7 @@ uint16_t DataVar = 0;
uint16_t VirtAddVarTab[NB_OF_VAR];
/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
+
static HAL_StatusTypeDef EE_Format();
static uint16_t EE_FindValidPage(uint8_t Operation);
static uint16_t EE_VerifyPageFullWriteVariable(uint16_t VirtAddress, uint16_t Data);
@@ -75,6 +79,9 @@ static uint16_t EE_VerifyPageFullyErased(uint32_t Address);
* @retval - Flash error code: on write Flash error
* - FLASH_COMPLETE: on success
*/
+
+/* Private functions ---------------------------------------------------------*/
+
uint16_t EE_Initialize() {
/* Get Page0 and Page1 status */
uint16_t PageStatus0 = (*(__IO uint16_t*)PAGE0_BASE_ADDRESS),
@@ -329,7 +336,7 @@ uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data) {
* @brief Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE
* @param None
* @retval Status of the last operation (Flash write or erase) done during
- * EEPROM formating
+ * EEPROM formatting
*/
static HAL_StatusTypeDef EE_Format() {
FLASH_EraseInitTypeDef pEraseInit;
@@ -518,6 +525,7 @@ static uint16_t EE_PageTransfer(uint16_t VirtAddress, uint16_t Data) {
return HAL_FLASH_Program(TYPEPROGRAM_HALFWORD, NewPageAddress, VALID_PAGE);
}
+#endif // FLASH_EEPROM_EMULATION
#endif // STM32GENERIC && (STM32F4 || STM32F7)
/**
diff --git a/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.h b/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.h
index e4094f8e13..84c4c6e3d2 100644
--- a/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.h
+++ b/Marlin/src/HAL/STM32_F4_F7/eeprom_emul.h
@@ -50,7 +50,6 @@
// ------------------------
#include "../../inc/MarlinConfig.h"
-#include "HAL.h"
/* Exported constants --------------------------------------------------------*/
/* EEPROM emulation firmware error codes */
diff --git a/Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp b/Marlin/src/HAL/STM32_F4_F7/eeprom_flash.cpp
similarity index 57%
rename from Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp
rename to Marlin/src/HAL/STM32_F4_F7/eeprom_flash.cpp
index cc1a1bb01e..00b808fd48 100644
--- a/Marlin/src/HAL/STM32_F4_F7/EmulatedEeprom.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/eeprom_flash.cpp
@@ -13,33 +13,18 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
-/**
- * Description: Functions for a Flash emulated EEPROM
- * Not platform dependent.
- */
-
-// Include configs and pins to get all EEPROM flags
#include "../../inc/MarlinConfig.h"
#if ENABLED(FLASH_EEPROM_EMULATION)
-// ------------------------
-// Includes
-// ------------------------
-
-#include "HAL.h"
+#include "../shared/eeprom_api.h"
#include "eeprom_emul.h"
-// ------------------------
-// Local defines
-// ------------------------
-
// FLASH_FLAG_PGSERR (Programming Sequence Error) was renamed to
// FLASH_FLAG_ERSERR (Erasing Sequence Error) in STM32F4/7
@@ -49,18 +34,34 @@
//#define FLASH_FLAG_PGSERR FLASH_FLAG_ERSERR
#endif
-// ------------------------
-// Private Variables
-// ------------------------
+void ee_write_byte(uint8_t *pos, unsigned char value) {
+ HAL_FLASH_Unlock();
+ __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
-static bool eeprom_initialized = false;
+ const unsigned eeprom_address = (unsigned)pos;
+ if (EE_WriteVariable(eeprom_address, uint16_t(value)) != EE_OK)
+ for (;;) HAL_Delay(1); // Spin forever until watchdog reset
-// ------------------------
-// Public functions
-// ------------------------
+ HAL_FLASH_Lock();
+}
-void eeprom_init() {
- if (!eeprom_initialized) {
+uint8_t ee_read_byte(uint8_t *pos) {
+ uint16_t data = 0xFF;
+ const unsigned eeprom_address = (unsigned)pos;
+ (void)EE_ReadVariable(eeprom_address, &data); // Data unchanged on error
+ return uint8_t(data);
+}
+
+#ifndef MARLIN_EEPROM_SIZE
+ #error "MARLIN_EEPROM_SIZE is required for Flash-based EEPROM."
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_finish() { return true; }
+
+bool PersistentStore::access_start() {
+ static bool ee_initialized = false;
+ if (!ee_initialized) {
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
@@ -70,46 +71,40 @@ void eeprom_init() {
for (;;) HAL_Delay(1); // Spin forever until watchdog reset
HAL_FLASH_Lock();
- eeprom_initialized = true;
+ ee_initialized = true;
}
+ return true;
}
-void eeprom_write_byte(uint8_t *pos, unsigned char value) {
- eeprom_init();
-
- HAL_FLASH_Unlock();
- __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
-
- uint16_t eeprom_address = unsigned(pos);
- if (EE_WriteVariable(eeprom_address, uint16_t(value)) != EE_OK)
- for (;;) HAL_Delay(1); // Spin forever until watchdog reset
-
- HAL_FLASH_Lock();
-}
-
-uint8_t eeprom_read_byte(uint8_t *pos) {
- eeprom_init();
-
- uint16_t data = 0xFF;
- uint16_t eeprom_address = unsigned(pos);
- (void)EE_ReadVariable(eeprom_address, &data); // Data unchanged on error
-
- return uint8_t(data);
-}
-
-void eeprom_read_block(void *__dst, const void *__src, size_t __n) {
- eeprom_init();
-
- uint16_t data = 0xFF;
- uint16_t eeprom_address = unsigned(__src);
- LOOP_L_N(c, __n) {
- EE_ReadVariable(eeprom_address+c, &data);
- *((uint8_t*)__dst + c) = data;
+bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
+ while (size--) {
+ uint8_t * const p = (uint8_t * const)pos;
+ uint8_t v = *value;
+ // EEPROM has only ~100,000 write cycles,
+ // so only write bytes that have changed!
+ if (v != ee_read_byte(p)) {
+ ee_write_byte(p, v);
+ if (ee_read_byte(p) != v) {
+ SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
+ return true;
+ }
+ }
+ crc16(crc, &v, 1);
+ pos++;
+ value++;
}
+ return false;
}
-void eeprom_update_block(const void *__src, void *__dst, size_t __n) {
-
+bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
+ do {
+ uint8_t c = ee_read_byte((uint8_t*)pos);
+ if (writing) *value = c;
+ crc16(crc, &c, 1);
+ pos++;
+ value++;
+ } while (--size);
+ return false;
}
#endif // FLASH_EEPROM_EMULATION
diff --git a/Marlin/src/HAL/STM32_F4_F7/eeprom.cpp b/Marlin/src/HAL/STM32_F4_F7/eeprom_wired.cpp
similarity index 77%
rename from Marlin/src/HAL/STM32_F4_F7/eeprom.cpp
rename to Marlin/src/HAL/STM32_F4_F7/eeprom_wired.cpp
index b957aae6a8..c0d82dbd07 100644
--- a/Marlin/src/HAL/STM32_F4_F7/eeprom.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/eeprom_wired.cpp
@@ -17,19 +17,29 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
-#include "../../inc/MarlinConfigPre.h"
+#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS)
+#if USE_WIRED_EEPROM
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with simple implementations supplied by Marlin.
+ */
+
+#include "../shared/eeprom_if.h"
#include "../shared/eeprom_api.h"
-bool PersistentStore::access_start() { return true; }
+#ifndef MARLIN_EEPROM_SIZE
+ #error "MARLIN_EEPROM_SIZE is required for I2C / SPI EEPROM."
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_start() { eeprom_init(); return true; }
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
@@ -48,7 +58,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
crc16(crc, &v, 1);
pos++;
value++;
- };
+ }
return false;
}
@@ -63,7 +73,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() { return E2END + 1; }
-
-#endif // EEPROM_SETTINGS
+#endif // USE_WIRED_EEPROM
#endif // STM32GENERIC && (STM32F4 || STM32F7)
diff --git a/Marlin/src/HAL/STM32_F4_F7/endstop_interrupts.h b/Marlin/src/HAL/STM32_F4_F7/endstop_interrupts.h
index 0b97c3c774..fdff8cc644 100644
--- a/Marlin/src/HAL/STM32_F4_F7/endstop_interrupts.h
+++ b/Marlin/src/HAL/STM32_F4_F7/endstop_interrupts.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -28,43 +28,22 @@
void endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
- #if HAS_X_MAX
- attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_X_MIN
- attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MAX
- attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Y_MIN
- attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MAX
- attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN
- attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MAX
- attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z2_MIN
- attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MAX
- attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z3_MIN
- attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z4_MAX
- attachInterrupt(Z4_MAX_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z4_MIN
- attachInterrupt(Z4_MIN_PIN, endstop_ISR, CHANGE);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
- #endif
+ #define _ATTACH(P) attachInterrupt(P, endstop_ISR, CHANGE)
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/STM32_F4_F7/fastio.h b/Marlin/src/HAL/STM32_F4_F7/fastio.h
index ee64ca833d..f42be58354 100644
--- a/Marlin/src/HAL/STM32_F4_F7/fastio.h
+++ b/Marlin/src/HAL/STM32_F4_F7/fastio.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_LCD.h b/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_LCD.h
index 0285c52ee3..a9f1b58222 100644
--- a/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/STM32F4_F7."
+#endif
diff --git a/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_adv.h b/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_post.h b/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_post.h
index d21624955e..b5d808e21a 100644
--- a/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/STM32_F4_F7/inc/Conditionals_post.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/inc/SanityCheck.h b/Marlin/src/HAL/STM32_F4_F7/inc/SanityCheck.h
index e04258fa07..9bb36f3bbb 100644
--- a/Marlin/src/HAL/STM32_F4_F7/inc/SanityCheck.h
+++ b/Marlin/src/HAL/STM32_F4_F7/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -32,8 +32,8 @@
#error "EMERGENCY_PARSER is not yet implemented for STM32F4/7. Disable EMERGENCY_PARSER to continue."
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on STM32F4/F7."
#endif
#if HAS_TMC_SW_SERIAL
diff --git a/Marlin/src/HAL/STM32_F4_F7/pinsDebug.h b/Marlin/src/HAL/STM32_F4_F7/pinsDebug.h
index 208a3524f7..973abb1b01 100644
--- a/Marlin/src/HAL/STM32_F4_F7/pinsDebug.h
+++ b/Marlin/src/HAL/STM32_F4_F7/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/spi_pins.h b/Marlin/src/HAL/STM32_F4_F7/spi_pins.h
index f120e7178b..75a6a2b250 100644
--- a/Marlin/src/HAL/STM32_F4_F7/spi_pins.h
+++ b/Marlin/src/HAL/STM32_F4_F7/spi_pins.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/timers.h b/Marlin/src/HAL/STM32_F4_F7/timers.h
index 632c05a5ad..4e8c81783e 100644
--- a/Marlin/src/HAL/STM32_F4_F7/timers.h
+++ b/Marlin/src/HAL/STM32_F4_F7/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/STM32_F4_F7/watchdog.cpp b/Marlin/src/HAL/STM32_F4_F7/watchdog.cpp
index 347edcd49d..cb12ec7aac 100644
--- a/Marlin/src/HAL/STM32_F4_F7/watchdog.cpp
+++ b/Marlin/src/HAL/STM32_F4_F7/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(STM32GENERIC) && (defined(STM32F4) || defined(STM32F7))
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/STM32_F4_F7/watchdog.h b/Marlin/src/HAL/STM32_F4_F7/watchdog.h
index ece6ef0162..3dbc2d08c1 100644
--- a/Marlin/src/HAL/STM32_F4_F7/watchdog.h
+++ b/Marlin/src/HAL/STM32_F4_F7/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.cpp b/Marlin/src/HAL/TEENSY31_32/HAL.cpp
index f226a4a90e..d276a4c880 100644
--- a/Marlin/src/HAL/TEENSY31_32/HAL.cpp
+++ b/Marlin/src/HAL/TEENSY31_32/HAL.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/TEENSY31_32/HAL.h b/Marlin/src/HAL/TEENSY31_32/HAL.h
index 15e9ab71bb..890930f7f8 100644
--- a/Marlin/src/HAL/TEENSY31_32/HAL.h
+++ b/Marlin/src/HAL/TEENSY31_32/HAL.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -34,7 +34,6 @@
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
#include
@@ -108,8 +107,9 @@ extern "C" {
void HAL_adc_init();
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
diff --git a/Marlin/src/HAL/TEENSY31_32/HAL_SPI.cpp b/Marlin/src/HAL/TEENSY31_32/HAL_SPI.cpp
index 83d4d00bf2..cdb3f4701c 100644
--- a/Marlin/src/HAL/TEENSY31_32/HAL_SPI.cpp
+++ b/Marlin/src/HAL/TEENSY31_32/HAL_SPI.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __MK20DX256__
diff --git a/Marlin/src/HAL/TEENSY31_32/Servo.cpp b/Marlin/src/HAL/TEENSY31_32/Servo.cpp
index 2b01d3d875..544892cb7d 100644
--- a/Marlin/src/HAL/TEENSY31_32/Servo.cpp
+++ b/Marlin/src/HAL/TEENSY31_32/Servo.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __MK20DX256__
@@ -46,9 +46,7 @@ void libServo::move(const int value) {
if (attach(0) >= 0) {
write(value);
safe_delay(servo_delay[servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
diff --git a/Marlin/src/HAL/TEENSY31_32/Servo.h b/Marlin/src/HAL/TEENSY31_32/Servo.h
index 9243291e43..82b601d956 100644
--- a/Marlin/src/HAL/TEENSY31_32/Servo.h
+++ b/Marlin/src/HAL/TEENSY31_32/Servo.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY31_32/eeprom_impl.cpp b/Marlin/src/HAL/TEENSY31_32/eeprom.cpp
similarity index 78%
rename from Marlin/src/HAL/TEENSY31_32/eeprom_impl.cpp
rename to Marlin/src/HAL/TEENSY31_32/eeprom.cpp
index 96499d4f19..f663132255 100644
--- a/Marlin/src/HAL/TEENSY31_32/eeprom_impl.cpp
+++ b/Marlin/src/HAL/TEENSY31_32/eeprom.cpp
@@ -13,18 +13,29 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#ifdef __MK20DX256__
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS)
+#if USE_WIRED_EEPROM
+
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with implementations supplied by the framework.
+ */
#include "../shared/eeprom_api.h"
+#include
-bool PersistentStore::access_start() { return true; }
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
@@ -43,7 +54,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
crc16(crc, &v, 1);
pos++;
value++;
- };
+ }
return false;
}
@@ -58,5 +69,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-#endif // EEPROM_SETTINGS
+#endif // USE_WIRED_EEPROM
#endif // __MK20DX256__
diff --git a/Marlin/src/HAL/TEENSY31_32/endstop_interrupts.h b/Marlin/src/HAL/TEENSY31_32/endstop_interrupts.h
index 21fea5bd01..999ada5127 100644
--- a/Marlin/src/HAL/TEENSY31_32/endstop_interrupts.h
+++ b/Marlin/src/HAL/TEENSY31_32/endstop_interrupts.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -47,31 +47,21 @@ void endstop_ISR() { endstops.update(); }
void setup_endstop_interrupts() {
#define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
- #if HAS_X_MAX
- _ATTACH(X_MAX_PIN);
- #endif
- #if HAS_X_MIN
- _ATTACH(X_MIN_PIN);
- #endif
- #if HAS_Y_MAX
- _ATTACH(Y_MAX_PIN);
- #endif
- #if HAS_Y_MIN
- _ATTACH(Y_MIN_PIN);
- #endif
- #if HAS_Z_MAX
- _ATTACH(Z_MAX_PIN);
- #endif
- #if HAS_Z_MIN
- _ATTACH(Z_MIN_PIN);
- #endif
- #if HAS_Z2_MAX
- _ATTACH(Z2_MAX_PIN);
- #endif
- #if HAS_Z2_MIN
- _ATTACH(Z2_MIN_PIN);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- _ATTACH(Z_MIN_PROBE_PIN);
- #endif
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/TEENSY31_32/fastio.h b/Marlin/src/HAL/TEENSY31_32/fastio.h
index e74920d493..9a299de9c7 100644
--- a/Marlin/src/HAL/TEENSY31_32/fastio.h
+++ b/Marlin/src/HAL/TEENSY31_32/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -39,7 +39,7 @@
*
* Now you can simply SET_OUTPUT(PIN); WRITE(PIN, HIGH); WRITE(PIN, LOW);
*
- * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
+ * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html
*/
#define _READ(P) bool(CORE_PIN ## P ## _PINREG & CORE_PIN ## P ## _BITMASK)
diff --git a/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_LCD.h b/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_LCD.h
index 0285c52ee3..54ec166643 100644
--- a/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/TEENSY31_32."
+#endif
diff --git a/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_adv.h b/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_post.h b/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_post.h
index 11603c9ef4..998f1dcc0d 100644
--- a/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/TEENSY31_32/inc/Conditionals_post.h
@@ -16,12 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-// If no real EEPROM, Flash emulation, or SRAM emulation is available fall back to SD emulation
-#if ENABLED(EEPROM_SETTINGS) && NONE(USE_WIRED_EEPROM, FLASH_EEPROM_EMULATION, SRAM_EEPROM_EMULATION)
- #define SDCARD_EEPROM_EMULATION
+#if USE_FALLBACK_EEPROM
+ #define USE_WIRED_EEPROM 1
#endif
diff --git a/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h b/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h
index 9268868596..3932ee6a76 100644
--- a/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h
+++ b/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -29,8 +29,8 @@
#error "EMERGENCY_PARSER is not yet implemented for Teensy 3.1/3.2. Disable EMERGENCY_PARSER to continue."
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on Teensy 3.1/3.2."
#endif
#if HAS_TMC_SW_SERIAL
diff --git a/Marlin/src/HAL/TEENSY31_32/spi_pins.h b/Marlin/src/HAL/TEENSY31_32/spi_pins.h
index 79230f3d44..5754fbfeed 100644
--- a/Marlin/src/HAL/TEENSY31_32/spi_pins.h
+++ b/Marlin/src/HAL/TEENSY31_32/spi_pins.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY31_32/timers.cpp b/Marlin/src/HAL/TEENSY31_32/timers.cpp
index 92641742f9..bf756af8a1 100644
--- a/Marlin/src/HAL/TEENSY31_32/timers.cpp
+++ b/Marlin/src/HAL/TEENSY31_32/timers.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -26,8 +26,7 @@
#ifdef __MK20DX256__
-#include "HAL.h"
-#include "timers.h"
+#include "../../inc/MarlinConfig.h"
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
diff --git a/Marlin/src/HAL/TEENSY31_32/timers.h b/Marlin/src/HAL/TEENSY31_32/timers.h
index 00f9f0740d..4f004ef751 100644
--- a/Marlin/src/HAL/TEENSY31_32/timers.h
+++ b/Marlin/src/HAL/TEENSY31_32/timers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -47,9 +47,15 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
-#define STEP_TIMER_NUM 0
-#define TEMP_TIMER_NUM 1
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
#define TEMP_TIMER_FREQUENCY 1000
@@ -68,8 +74,12 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
-#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
+#endif
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
diff --git a/Marlin/src/HAL/TEENSY31_32/watchdog.cpp b/Marlin/src/HAL/TEENSY31_32/watchdog.cpp
index 618294591b..9f7b70d9f9 100644
--- a/Marlin/src/HAL/TEENSY31_32/watchdog.cpp
+++ b/Marlin/src/HAL/TEENSY31_32/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#ifdef __MK20DX256__
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/TEENSY31_32/watchdog.h b/Marlin/src/HAL/TEENSY31_32/watchdog.h
index cb881f8595..b8b46a4030 100644
--- a/Marlin/src/HAL/TEENSY31_32/watchdog.h
+++ b/Marlin/src/HAL/TEENSY31_32/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.cpp b/Marlin/src/HAL/TEENSY35_36/HAL.cpp
index 86ba40870f..bcbee1d4c5 100644
--- a/Marlin/src/HAL/TEENSY35_36/HAL.cpp
+++ b/Marlin/src/HAL/TEENSY35_36/HAL.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/TEENSY35_36/HAL.h b/Marlin/src/HAL/TEENSY35_36/HAL.h
index 7e5be1081c..5442ae2d3b 100644
--- a/Marlin/src/HAL/TEENSY35_36/HAL.h
+++ b/Marlin/src/HAL/TEENSY35_36/HAL.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -34,8 +34,6 @@
#include "fastio.h"
#include "watchdog.h"
-#include "timers.h"
-
#include
#include
@@ -114,8 +112,9 @@ extern "C" {
void HAL_adc_init();
-#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
+#define HAL_ADC_VREF 3.3
#define HAL_ADC_RESOLUTION 10
+#define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
diff --git a/Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp b/Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp
index b35533aa94..0b1ae4afa4 100644
--- a/Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp
+++ b/Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
diff --git a/Marlin/src/HAL/TEENSY35_36/Servo.cpp b/Marlin/src/HAL/TEENSY35_36/Servo.cpp
index f2fd5fe7ff..d1390187a7 100644
--- a/Marlin/src/HAL/TEENSY35_36/Servo.cpp
+++ b/Marlin/src/HAL/TEENSY35_36/Servo.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
@@ -46,9 +46,7 @@ void libServo::move(const int value) {
if (attach(0) >= 0) {
write(value);
safe_delay(servo_delay[servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
diff --git a/Marlin/src/HAL/TEENSY35_36/Servo.h b/Marlin/src/HAL/TEENSY35_36/Servo.h
index 4962105d79..ae904f0e2e 100644
--- a/Marlin/src/HAL/TEENSY35_36/Servo.h
+++ b/Marlin/src/HAL/TEENSY35_36/Servo.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY35_36/eeprom.cpp b/Marlin/src/HAL/TEENSY35_36/eeprom.cpp
index c66a45e2a5..d2d7324cdd 100644
--- a/Marlin/src/HAL/TEENSY35_36/eeprom.cpp
+++ b/Marlin/src/HAL/TEENSY35_36/eeprom.cpp
@@ -17,20 +17,29 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../../inc/MarlinConfig.h"
-#if ENABLED(EEPROM_SETTINGS)
+#if USE_WIRED_EEPROM
+
+/**
+ * PersistentStore for Arduino-style EEPROM interface
+ * with implementations supplied by the framework.
+ */
#include "../shared/eeprom_api.h"
#include
-bool PersistentStore::access_start() { return true; }
+#ifndef MARLIN_EEPROM_SIZE
+ #define MARLIN_EEPROM_SIZE size_t(E2END + 1)
+#endif
+size_t PersistentStore::capacity() { return MARLIN_EEPROM_SIZE; }
+
+bool PersistentStore::access_start() { return true; }
bool PersistentStore::access_finish() { return true; }
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
@@ -49,7 +58,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
crc16(crc, &v, 1);
pos++;
value++;
- };
+ }
return false;
}
@@ -64,7 +73,5 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
return false;
}
-size_t PersistentStore::capacity() { return E2END + 1; }
-
-#endif // EEPROM_SETTINGS
+#endif // USE_WIRED_EEPROM
#endif // __MK64FX512__ || __MK66FX1M0__
diff --git a/Marlin/src/HAL/TEENSY35_36/endstop_interrupts.h b/Marlin/src/HAL/TEENSY35_36/endstop_interrupts.h
index eaaf297ea2..92e22efc0f 100644
--- a/Marlin/src/HAL/TEENSY35_36/endstop_interrupts.h
+++ b/Marlin/src/HAL/TEENSY35_36/endstop_interrupts.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -46,43 +46,21 @@ void endstop_ISR() { endstops.update(); }
*/
void setup_endstop_interrupts() {
#define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
- #if HAS_X_MAX
- _ATTACH(X_MAX_PIN);
- #endif
- #if HAS_X_MIN
- _ATTACH(X_MIN_PIN);
- #endif
- #if HAS_Y_MAX
- _ATTACH(Y_MAX_PIN);
- #endif
- #if HAS_Y_MIN
- _ATTACH(Y_MIN_PIN);
- #endif
- #if HAS_Z_MAX
- _ATTACH(Z_MAX_PIN);
- #endif
- #if HAS_Z_MIN
- _ATTACH(Z_MIN_PIN);
- #endif
- #if HAS_Z2_MAX
- _ATTACH(Z2_MAX_PIN);
- #endif
- #if HAS_Z2_MIN
- _ATTACH(Z2_MIN_PIN);
- #endif
- #if HAS_Z3_MAX
- _ATTACH(Z3_MAX_PIN);
- #endif
- #if HAS_Z3_MIN
- _ATTACH(Z3_MIN_PIN);
- #endif
- #if HAS_Z4_MAX
- _ATTACH(Z4_MAX_PIN);
- #endif
- #if HAS_Z4_MIN
- _ATTACH(Z4_MIN_PIN);
- #endif
- #if HAS_Z_MIN_PROBE_PIN
- _ATTACH(Z_MIN_PROBE_PIN);
- #endif
+ TERN_(HAS_X_MAX, _ATTACH(X_MAX_PIN));
+ TERN_(HAS_X_MIN, _ATTACH(X_MIN_PIN));
+ TERN_(HAS_Y_MAX, _ATTACH(Y_MAX_PIN));
+ TERN_(HAS_Y_MIN, _ATTACH(Y_MIN_PIN));
+ TERN_(HAS_Z_MAX, _ATTACH(Z_MAX_PIN));
+ TERN_(HAS_Z_MIN, _ATTACH(Z_MIN_PIN));
+ TERN_(HAS_X2_MAX, _ATTACH(X2_MAX_PIN));
+ TERN_(HAS_X2_MIN, _ATTACH(X2_MIN_PIN));
+ TERN_(HAS_Y2_MAX, _ATTACH(Y2_MAX_PIN));
+ TERN_(HAS_Y2_MIN, _ATTACH(Y2_MIN_PIN));
+ TERN_(HAS_Z2_MAX, _ATTACH(Z2_MAX_PIN));
+ TERN_(HAS_Z2_MIN, _ATTACH(Z2_MIN_PIN));
+ TERN_(HAS_Z3_MAX, _ATTACH(Z3_MAX_PIN));
+ TERN_(HAS_Z3_MIN, _ATTACH(Z3_MIN_PIN));
+ TERN_(HAS_Z4_MAX, _ATTACH(Z4_MAX_PIN));
+ TERN_(HAS_Z4_MIN, _ATTACH(Z4_MIN_PIN));
+ TERN_(HAS_Z_MIN_PROBE_PIN, _ATTACH(Z_MIN_PROBE_PIN));
}
diff --git a/Marlin/src/HAL/TEENSY35_36/fastio.h b/Marlin/src/HAL/TEENSY35_36/fastio.h
index e74920d493..9a299de9c7 100644
--- a/Marlin/src/HAL/TEENSY35_36/fastio.h
+++ b/Marlin/src/HAL/TEENSY35_36/fastio.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -39,7 +39,7 @@
*
* Now you can simply SET_OUTPUT(PIN); WRITE(PIN, HIGH); WRITE(PIN, LOW);
*
- * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
+ * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html
*/
#define _READ(P) bool(CORE_PIN ## P ## _PINREG & CORE_PIN ## P ## _BITMASK)
diff --git a/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_LCD.h b/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_LCD.h
index 0285c52ee3..632ee533ac 100644
--- a/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_LCD.h
+++ b/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_LCD.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if HAS_SPI_TFT || HAS_FSMC_TFT
+ #error "Sorry! TFT displays are not available for HAL/TEENSY35_36."
+#endif
diff --git a/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_adv.h b/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_adv.h
index 0285c52ee3..5f1c4b1601 100644
--- a/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_adv.h
+++ b/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_adv.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_post.h b/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_post.h
index 0285c52ee3..998f1dcc0d 100644
--- a/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_post.h
+++ b/Marlin/src/HAL/TEENSY35_36/inc/Conditionals_post.h
@@ -16,7 +16,11 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
+
+#if USE_FALLBACK_EEPROM
+ #define USE_WIRED_EEPROM 1
+#endif
diff --git a/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h b/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h
index f42bd63b17..ee80e42696 100644
--- a/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h
+++ b/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -29,8 +29,8 @@
#error "EMERGENCY_PARSER is not yet implemented for Teensy 3.5/3.6. Disable EMERGENCY_PARSER to continue."
#endif
-#if ENABLED(FAST_PWM_FAN)
- #error "FAST_PWM_FAN is not yet implemented for this platform."
+#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY
+ #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on Teensy 3.5/3.6."
#endif
#if HAS_TMC_SW_SERIAL
diff --git a/Marlin/src/HAL/TEENSY35_36/pinsDebug.h b/Marlin/src/HAL/TEENSY35_36/pinsDebug.h
index 61a54f15ed..e57c73c595 100644
--- a/Marlin/src/HAL/TEENSY35_36/pinsDebug.h
+++ b/Marlin/src/HAL/TEENSY35_36/pinsDebug.h
@@ -13,7 +13,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY35_36/spi_pins.h b/Marlin/src/HAL/TEENSY35_36/spi_pins.h
index b29a9346a1..276d4f456a 100644
--- a/Marlin/src/HAL/TEENSY35_36/spi_pins.h
+++ b/Marlin/src/HAL/TEENSY35_36/spi_pins.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/TEENSY35_36/timers.cpp b/Marlin/src/HAL/TEENSY35_36/timers.cpp
index 81e23e4d17..5725e83a85 100644
--- a/Marlin/src/HAL/TEENSY35_36/timers.cpp
+++ b/Marlin/src/HAL/TEENSY35_36/timers.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -27,8 +27,7 @@
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
-#include "HAL.h"
-#include "timers.h"
+#include "../../inc/MarlinConfig.h"
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
diff --git a/Marlin/src/HAL/TEENSY35_36/timers.h b/Marlin/src/HAL/TEENSY35_36/timers.h
index 6dc26a9665..68060d0e1c 100644
--- a/Marlin/src/HAL/TEENSY35_36/timers.h
+++ b/Marlin/src/HAL/TEENSY35_36/timers.h
@@ -15,7 +15,7 @@
* 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 .
+ * along with this program. If not, see .
*/
#pragma once
@@ -46,9 +46,15 @@ typedef uint32_t hal_timer_t;
#define HAL_TIMER_RATE (FTM0_TIMER_RATE)
-#define STEP_TIMER_NUM 0
-#define TEMP_TIMER_NUM 1
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
+#ifndef STEP_TIMER_NUM
+ #define STEP_TIMER_NUM 0 // Timer Index for Stepper
+#endif
+#ifndef PULSE_TIMER_NUM
+ #define PULSE_TIMER_NUM STEP_TIMER_NUM
+#endif
+#ifndef TEMP_TIMER_NUM
+ #define TEMP_TIMER_NUM 1 // Timer Index for Temperature
+#endif
#define TEMP_TIMER_FREQUENCY 1000
@@ -67,8 +73,12 @@ typedef uint32_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
-#define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
-#define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
+#ifndef HAL_STEP_TIMER_ISR
+ #define HAL_STEP_TIMER_ISR() extern "C" void ftm0_isr() //void TC3_Handler()
+#endif
+#ifndef HAL_TEMP_TIMER_ISR
+ #define HAL_TEMP_TIMER_ISR() extern "C" void ftm1_isr() //void TC4_Handler()
+#endif
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
diff --git a/Marlin/src/HAL/TEENSY35_36/watchdog.cpp b/Marlin/src/HAL/TEENSY35_36/watchdog.cpp
index 69afa04a54..e735ee7923 100644
--- a/Marlin/src/HAL/TEENSY35_36/watchdog.cpp
+++ b/Marlin/src/HAL/TEENSY35_36/watchdog.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#include "../../inc/MarlinConfig.h"
diff --git a/Marlin/src/HAL/TEENSY35_36/watchdog.h b/Marlin/src/HAL/TEENSY35_36/watchdog.h
index ec3f18f094..981b1f0bd2 100644
--- a/Marlin/src/HAL/TEENSY35_36/watchdog.h
+++ b/Marlin/src/HAL/TEENSY35_36/watchdog.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/platforms.h b/Marlin/src/HAL/platforms.h
index cc462f37c5..d4cec64267 100644
--- a/Marlin/src/HAL/platforms.h
+++ b/Marlin/src/HAL/platforms.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h
index 5cb68b1503..d98e960848 100644
--- a/Marlin/src/HAL/shared/Delay.h
+++ b/Marlin/src/HAL/shared/Delay.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -36,7 +36,7 @@
#if __CORTEX_M == 7
// Cortex-M3 through M7 can use the cycle counter of the DWT unit
- // http://www.anthonyvh.com/2017/05/18/cortex_m-cycle_counter/
+ // https://www.anthonyvh.com/2017/05/18/cortex_m-cycle_counter/
FORCE_INLINE static void enableCycleCounter() {
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
diff --git a/Marlin/src/HAL/shared/HAL_SPI.h b/Marlin/src/HAL/shared/HAL_SPI.h
index 0410d70c93..59af554806 100644
--- a/Marlin/src/HAL/shared/HAL_SPI.h
+++ b/Marlin/src/HAL/shared/HAL_SPI.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/shared/HAL_ST7920.h b/Marlin/src/HAL/shared/HAL_ST7920.h
index 69c1d741ae..05e8a1f2c5 100644
--- a/Marlin/src/HAL/shared/HAL_ST7920.h
+++ b/Marlin/src/HAL/shared/HAL_ST7920.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -27,7 +27,7 @@
* (bypassing U8G), it will allow the LIGHTWEIGHT_UI to operate.
*/
-#if HAS_GRAPHICAL_LCD && ENABLED(LIGHTWEIGHT_UI)
+#if BOTH(HAS_GRAPHICAL_LCD, LIGHTWEIGHT_UI)
void ST7920_cs();
void ST7920_ncs();
void ST7920_set_cmd();
diff --git a/Marlin/src/HAL/shared/HAL_spi_L6470.cpp b/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
index 46e7b71f88..bd85dbe7bd 100644
--- a/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
+++ b/Marlin/src/HAL/shared/HAL_spi_L6470.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/HAL/shared/Marduino.h b/Marlin/src/HAL/shared/Marduino.h
index c022fc72ed..3003f3cc28 100644
--- a/Marlin/src/HAL/shared/Marduino.h
+++ b/Marlin/src/HAL/shared/Marduino.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.cpp b/Marlin/src/HAL/shared/backtrace/backtrace.cpp
index 7264969c74..6cf5e055e1 100644
--- a/Marlin/src/HAL/shared/backtrace/backtrace.cpp
+++ b/Marlin/src/HAL/shared/backtrace/backtrace.cpp
@@ -16,10 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
-
#if defined(__arm__) || defined(__thumb__)
#include "backtrace.h"
diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.h b/Marlin/src/HAL/shared/backtrace/backtrace.h
index 636eb09a71..fccadedaa5 100644
--- a/Marlin/src/HAL/shared/backtrace/backtrace.h
+++ b/Marlin/src/HAL/shared/backtrace/backtrace.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/shared/backtrace/unwarm_thumb.cpp b/Marlin/src/HAL/shared/backtrace/unwarm_thumb.cpp
index d5449f863e..26ca8b2604 100644
--- a/Marlin/src/HAL/shared/backtrace/unwarm_thumb.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwarm_thumb.cpp
@@ -807,7 +807,7 @@ UnwResult UnwStartThumb(UnwState * const state) {
case 2: /* MOV */
UnwPrintd5("MOV r%d, r%d\t; r%d %s", rhd, rhs, rhd, M_Origin2Str(state->regData[rhs].o));
state->regData[rhd].v = state->regData[rhs].v;
- state->regData[rhd].o = state->regData[rhd].o;
+ state->regData[rhd].o = state->regData[rhs].o;
break;
case 3: /* BX */
diff --git a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
index 207cd56aa8..bfc062af20 100644
--- a/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
+++ b/Marlin/src/HAL/shared/backtrace/unwarmbytab.cpp
@@ -4,7 +4,7 @@
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ * file, You can obtain one at https://www.mozilla.org/en-US/MPL/2.0/
*
* This library was modified, some bugs fixed, stack address validated
* and adapted to be used in Marlin 3D printer firmware as backtracer
diff --git a/Marlin/src/HAL/shared/eeprom_api.cpp b/Marlin/src/HAL/shared/eeprom_api.cpp
index d8839e3d9d..47cfa5a2db 100644
--- a/Marlin/src/HAL/shared/eeprom_api.cpp
+++ b/Marlin/src/HAL/shared/eeprom_api.cpp
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/HAL/shared/eeprom_api.h b/Marlin/src/HAL/shared/eeprom_api.h
index d7bee8a5f3..6445f7a4aa 100644
--- a/Marlin/src/HAL/shared/eeprom_api.h
+++ b/Marlin/src/HAL/shared/eeprom_api.h
@@ -17,7 +17,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -29,20 +29,38 @@
class PersistentStore {
public:
- static bool access_start();
- static bool access_finish();
- static bool write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc);
- static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
+
+ // Total available persistent storage space (in bytes)
static size_t capacity();
+ // Prepare to read or write
+ static bool access_start();
+
+ // Housecleaning after read or write
+ static bool access_finish();
+
+ // Write one or more bytes of data and update the CRC
+ // Return 'true' on write error
+ static bool write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc);
+
+ // Read one or more bytes of data and update the CRC
+ // Return 'true' on read error
+ static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
+
+ // Write one or more bytes of data
+ // Return 'true' on write error
static inline bool write_data(const int pos, const uint8_t* value, const size_t size=sizeof(uint8_t)) {
int data_pos = pos;
uint16_t crc = 0;
return write_data(data_pos, value, size, &crc);
}
+ // Write a single byte of data
+ // Return 'true' on write error
static inline bool write_data(const int pos, const uint8_t value) { return write_data(pos, &value); }
+ // Read one or more bytes of data
+ // Return 'true' on read error
static inline bool read_data(const int pos, uint8_t* value, const size_t size=1) {
int data_pos = pos;
uint16_t crc = 0;
diff --git a/Marlin/src/HAL/shared/eeprom_i2c.cpp b/Marlin/src/HAL/shared/eeprom_i2c.cpp
deleted file mode 100644
index 3eb72194ac..0000000000
--- a/Marlin/src/HAL/shared/eeprom_i2c.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * Marlin 3D Printer Firmware
- * Copyright (c) 2020 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 .
- *
- */
-
-/**
- * Description: functions for I2C connected external EEPROM.
- * Not platform dependent.
- *
- * TODO: Some platform Arduino libraries define these functions
- * so Marlin needs to add a glue layer to prevent the conflict.
- */
-
-#include "../../inc/MarlinConfig.h"
-
-#if ENABLED(I2C_EEPROM)
-
-#include "../HAL.h"
-#include
-
-// ------------------------
-// Private Variables
-// ------------------------
-
-static uint8_t eeprom_device_address = 0x50;
-
-// ------------------------
-// Public functions
-// ------------------------
-
-static void eeprom_init() {
- Wire.begin();
-}
-
-void eeprom_write_byte(uint8_t *pos, unsigned char value) {
- unsigned eeprom_address = (unsigned) pos;
-
- eeprom_init();
-
- Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
- Wire.write((int)(eeprom_address >> 8)); // MSB
- Wire.write((int)(eeprom_address & 0xFF)); // LSB
- Wire.write(value);
- Wire.endTransmission();
-
- // wait for write cycle to complete
- // this could be done more efficiently with "acknowledge polling"
- delay(5);
-}
-
-// WARNING: address is a page address, 6-bit end will wrap around
-// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
-void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
- eeprom_init();
-
- Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
- Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
- Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
- Wire.endTransmission();
-
- uint8_t *ptr = (uint8_t*)pos;
- uint8_t flag = 0;
- Wire.requestFrom(eeprom_device_address, (byte)n);
- for (byte c = 0; c < n && Wire.available(); c++)
- flag |= Wire.read() ^ ptr[c];
-
- if (flag) {
- Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
- Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
- Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
- Wire.write((uint8_t*)pos, n);
- Wire.endTransmission();
-
- // wait for write cycle to complete
- // this could be done more efficiently with "acknowledge polling"
- delay(5);
- }
-}
-
-uint8_t eeprom_read_byte(uint8_t *pos) {
- unsigned eeprom_address = (unsigned)pos;
-
- eeprom_init();
-
- Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
- Wire.write((int)(eeprom_address >> 8)); // MSB
- Wire.write((int)(eeprom_address & 0xFF)); // LSB
- Wire.endTransmission();
- Wire.requestFrom(eeprom_device_address, (byte)1);
- return Wire.available() ? Wire.read() : 0xFF;
-}
-
-// Don't read more than 30..32 bytes at a time!
-void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
- eeprom_init();
-
- Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
- Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
- Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
- Wire.endTransmission();
- Wire.requestFrom(eeprom_device_address, (byte)n);
- for (byte c = 0; c < n; c++ )
- if (Wire.available()) *((uint8_t*)pos + c) = Wire.read();
-}
-
-#endif // I2C_EEPROM
diff --git a/Marlin/src/HAL/shared/eeprom_if.h b/Marlin/src/HAL/shared/eeprom_if.h
new file mode 100644
index 0000000000..e44da801df
--- /dev/null
+++ b/Marlin/src/HAL/shared/eeprom_if.h
@@ -0,0 +1,29 @@
+/**
+ * Marlin 3D Printer Firmware
+ *
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
+ *
+ * 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 .
+ *
+ */
+#pragma once
+
+//
+// EEPROM
+//
+void eeprom_init();
+void eeprom_write_byte(uint8_t *pos, unsigned char value);
+uint8_t eeprom_read_byte(uint8_t *pos);
diff --git a/Marlin/src/HAL/shared/eeprom_if_i2c.cpp b/Marlin/src/HAL/shared/eeprom_if_i2c.cpp
new file mode 100644
index 0000000000..cc22bf7d98
--- /dev/null
+++ b/Marlin/src/HAL/shared/eeprom_if_i2c.cpp
@@ -0,0 +1,78 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+/**
+ * Platform-independent Arduino functions for I2C EEPROM.
+ * Enable USE_SHARED_EEPROM if not supplied by the framework.
+ */
+
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(I2C_EEPROM)
+
+#include "eeprom_if.h"
+#include
+
+void eeprom_init() { Wire.begin(); }
+
+#if ENABLED(USE_SHARED_EEPROM)
+
+#ifndef EEPROM_WRITE_DELAY
+ #define EEPROM_WRITE_DELAY 5
+#endif
+#ifndef EEPROM_DEVICE_ADDRESS
+ #define EEPROM_DEVICE_ADDRESS 0x50
+#endif
+
+static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(EEPROM_DEVICE_ADDRESS);
+
+// ------------------------
+// Public functions
+// ------------------------
+
+void eeprom_write_byte(uint8_t *pos, unsigned char value) {
+ const unsigned eeprom_address = (unsigned)pos;
+
+ Wire.beginTransmission(eeprom_device_address);
+ Wire.write(int(eeprom_address >> 8)); // MSB
+ Wire.write(int(eeprom_address & 0xFF)); // LSB
+ Wire.write(value);
+ Wire.endTransmission();
+
+ // wait for write cycle to complete
+ // this could be done more efficiently with "acknowledge polling"
+ delay(EEPROM_WRITE_DELAY);
+}
+
+uint8_t eeprom_read_byte(uint8_t *pos) {
+ const unsigned eeprom_address = (unsigned)pos;
+
+ Wire.beginTransmission(eeprom_device_address);
+ Wire.write(int(eeprom_address >> 8)); // MSB
+ Wire.write(int(eeprom_address & 0xFF)); // LSB
+ Wire.endTransmission();
+ Wire.requestFrom(eeprom_device_address, (byte)1);
+ return Wire.available() ? Wire.read() : 0xFF;
+}
+
+#endif // USE_SHARED_EEPROM
+#endif // I2C_EEPROM
diff --git a/Marlin/src/HAL/shared/eeprom_spi.cpp b/Marlin/src/HAL/shared/eeprom_if_spi.cpp
similarity index 57%
rename from Marlin/src/HAL/shared/eeprom_spi.cpp
rename to Marlin/src/HAL/shared/eeprom_if_spi.cpp
index ce7479aedb..a341fef9de 100644
--- a/Marlin/src/HAL/shared/eeprom_spi.cpp
+++ b/Marlin/src/HAL/shared/eeprom_if_spi.cpp
@@ -16,25 +16,33 @@
* 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 .
+ * along with this program. If not, see .
*
*/
/**
- * Description: functions for SPI connected external EEPROM.
- * Not platform dependent.
+ * Platform-independent Arduino functions for SPI EEPROM.
+ * Enable USE_SHARED_EEPROM if not supplied by the framework.
*/
#include "../../inc/MarlinConfig.h"
#if ENABLED(SPI_EEPROM)
-#include "../HAL.h"
+#include "eeprom_if.h"
+
+void eeprom_init() {}
+
+#if ENABLED(USE_SHARED_EEPROM)
#define CMD_WREN 6 // WREN
#define CMD_READ 2 // WRITE
#define CMD_WRITE 2 // WRITE
+#ifndef EEPROM_WRITE_DELAY
+ #define EEPROM_WRITE_DELAY 7
+#endif
+
uint8_t eeprom_read_byte(uint8_t* pos) {
uint8_t v;
uint8_t eeprom_temp[3];
@@ -53,24 +61,6 @@ uint8_t eeprom_read_byte(uint8_t* pos) {
return v;
}
-void eeprom_read_block(void* dest, const void* eeprom_address, size_t n) {
- uint8_t eeprom_temp[3];
-
- // set read location
- // begin transmission from device
- eeprom_temp[0] = CMD_READ;
- eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; // addr High
- eeprom_temp[2] = (unsigned)eeprom_address& 0xFF; // addr Low
- WRITE(SPI_EEPROM1_CS, HIGH);
- WRITE(SPI_EEPROM1_CS, LOW);
- spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
-
- uint8_t *p_dest = (uint8_t *)dest;
- while (n--)
- *p_dest++ = spiRec(SPI_CHAN_EEPROM1);
- WRITE(SPI_EEPROM1_CS, HIGH);
-}
-
void eeprom_write_byte(uint8_t* pos, uint8_t value) {
uint8_t eeprom_temp[3];
@@ -90,29 +80,8 @@ void eeprom_write_byte(uint8_t* pos, uint8_t value) {
spiSend(SPI_CHAN_EEPROM1, value);
WRITE(SPI_EEPROM1_CS, HIGH);
- delay(7); // wait for page write to complete
+ delay(EEPROM_WRITE_DELAY); // wait for page write to complete
}
-void eeprom_update_block(const void* src, void* eeprom_address, size_t n) {
- uint8_t eeprom_temp[3];
-
- /*write enable*/
- eeprom_temp[0] = CMD_WREN;
- WRITE(SPI_EEPROM1_CS, LOW);
- spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 1);
- WRITE(SPI_EEPROM1_CS, HIGH);
- delay(1);
-
- /*write addr*/
- eeprom_temp[0] = CMD_WRITE;
- eeprom_temp[1] = ((unsigned)eeprom_address>>8) & 0xFF; //addr High
- eeprom_temp[2] = (unsigned)eeprom_address & 0xFF; //addr Low
- WRITE(SPI_EEPROM1_CS, LOW);
- spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
-
- spiSend(SPI_CHAN_EEPROM1, (const uint8_t*)src, n);
- WRITE(SPI_EEPROM1_CS, HIGH);
- delay(7); // wait for page write to complete
-}
-
-#endif // SPI_EEPROM
+#endif // USE_SHARED_EEPROM
+#endif // I2C_EEPROM
diff --git a/Marlin/src/HAL/shared/esp_wifi.cpp b/Marlin/src/HAL/shared/esp_wifi.cpp
new file mode 100644
index 0000000000..a55f5ca39f
--- /dev/null
+++ b/Marlin/src/HAL/shared/esp_wifi.cpp
@@ -0,0 +1,43 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfig.h"
+#include "Delay.h"
+
+void esp_wifi_init(void) { // init ESP01 WIFI module pins
+ #if PIN_EXISTS(ESP_WIFI_MODULE_GPIO0)
+ OUT_WRITE(ESP_WIFI_MODULE_GPIO0_PIN, HIGH);
+ #endif
+ #if PIN_EXISTS(ESP_WIFI_MODULE_GPIO2)
+ OUT_WRITE(ESP_WIFI_MODULE_GPIO2_PIN, HIGH);
+ #endif
+ #if PIN_EXISTS(ESP_WIFI_MODULE_RESET)
+ delay(1); // power up delay (0.1mS minimum)
+ OUT_WRITE(ESP_WIFI_MODULE_RESET_PIN, LOW);
+ delay(1);
+ OUT_WRITE(ESP_WIFI_MODULE_RESET_PIN, HIGH);
+ #endif
+ #if PIN_EXISTS(ESP_WIFI_MODULE_ENABLE)
+ delay(1); // delay after reset released (0.1mS minimum)
+ OUT_WRITE(ESP_WIFI_MODULE_ENABLE_PIN, HIGH);
+ #endif
+}
diff --git a/Marlin/src/HAL/LPC1768/eeprom_api.h b/Marlin/src/HAL/shared/esp_wifi.h
similarity index 85%
rename from Marlin/src/HAL/LPC1768/eeprom_api.h
rename to Marlin/src/HAL/shared/esp_wifi.h
index f874eac58a..84a50a941d 100644
--- a/Marlin/src/HAL/LPC1768/eeprom_api.h
+++ b/Marlin/src/HAL/shared/esp_wifi.h
@@ -16,11 +16,9 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-#include "../shared/eeprom_api.h"
-
-#define FLASH_EEPROM_EMULATION
+void esp_wifi_init();
diff --git a/Marlin/src/HAL/shared/math_32bit.h b/Marlin/src/HAL/shared/math_32bit.h
index d93ab9caf6..87e9e6406e 100644
--- a/Marlin/src/HAL/shared/math_32bit.h
+++ b/Marlin/src/HAL/shared/math_32bit.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/shared/servo.cpp b/Marlin/src/HAL/shared/servo.cpp
index 2c3d7bb7d3..d69cf2fe2c 100644
--- a/Marlin/src/HAL/shared/servo.cpp
+++ b/Marlin/src/HAL/shared/servo.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -150,9 +150,7 @@ void Servo::move(const int value) {
if (attach(0) >= 0) {
write(value);
safe_delay(servo_delay[servoIndex]);
- #if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
- detach();
- #endif
+ TERN_(DEACTIVATE_SERVOS_AFTER_MOVE, detach());
}
}
diff --git a/Marlin/src/HAL/shared/servo.h b/Marlin/src/HAL/shared/servo.h
index b582221b86..f9c4784118 100644
--- a/Marlin/src/HAL/shared/servo.h
+++ b/Marlin/src/HAL/shared/servo.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/HAL/shared/servo_private.h b/Marlin/src/HAL/shared/servo_private.h
index 58e455b124..d85d8da8ba 100644
--- a/Marlin/src/HAL/shared/servo_private.h
+++ b/Marlin/src/HAL/shared/servo_private.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp
index 8130affe30..e703eaf8d9 100644
--- a/Marlin/src/MarlinCore.cpp
+++ b/Marlin/src/MarlinCore.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -30,35 +30,59 @@
#include "MarlinCore.h"
-#include "core/utility.h"
-#include "lcd/ultralcd.h"
-#include "module/motion.h"
-#include "module/planner.h"
-#include "module/stepper.h"
-#include "module/endstops.h"
-#include "module/probe.h"
-#include "module/temperature.h"
-#include "sd/cardreader.h"
-#include "module/configuration_store.h"
-#include "module/printcounter.h" // PrintCounter or Stopwatch
-#include "feature/closedloop.h"
+#if ENABLED(MARLIN_DEV_MODE)
+ #warning "WARNING! Disable MARLIN_DEV_MODE for the final build!"
+#endif
#include "HAL/shared/Delay.h"
-
-#include "module/stepper/indirection.h"
+#include "HAL/shared/esp_wifi.h"
#ifdef ARDUINO
#include
#endif
#include
-#include "libs/nozzle.h"
+
+#include "core/utility.h"
+#include "module/motion.h"
+#include "module/planner.h"
+#include "module/endstops.h"
+#include "module/temperature.h"
+#include "module/settings.h"
+#include "module/printcounter.h" // PrintCounter or Stopwatch
+
+#include "module/stepper.h"
+#include "module/stepper/indirection.h"
#include "gcode/gcode.h"
#include "gcode/parser.h"
#include "gcode/queue.h"
-#if ENABLED(TOUCH_BUTTONS)
- #include "feature/touch/xpt2046.h"
+#include "sd/cardreader.h"
+
+#include "lcd/ultralcd.h"
+#if HAS_TOUCH_XPT2046
+ #include "lcd/touch/touch_buttons.h"
+#endif
+
+#if HAS_TFT_LVGL_UI
+ #include "lcd/extui/lib/mks_ui/tft_lvgl_configuration.h"
+ #include "lcd/extui/lib/mks_ui/draw_ui.h"
+ #include "lcd/extui/lib/mks_ui/mks_hardware_test.h"
+ #include
+#endif
+
+#if ENABLED(DWIN_CREALITY_LCD)
+ #include "lcd/dwin/dwin.h"
+ #include "lcd/dwin/dwin_lcd.h"
+ #include "lcd/dwin/rotary_encoder.h"
+#endif
+
+#if ENABLED(IIC_BL24CXX_EEPROM)
+ #include "libs/BL24CXX.h"
+#endif
+
+#if ENABLED(DIRECT_STEPPING)
+ #include "feature/direct_stepping.h"
#endif
#if ENABLED(HOST_ACTION_COMMANDS)
@@ -69,7 +93,11 @@
#include "libs/buzzer.h"
#endif
-#if ENABLED(DIGIPOT_I2C)
+#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
+ #include "feature/closedloop.h"
+#endif
+
+#if HAS_I2C_DIGIPOT
#include "feature/digipot/digipot.h"
#endif
@@ -153,11 +181,19 @@
#include "feature/runout.h"
#endif
+#if HAS_Z_SERVO_PROBE
+ #include "module/probe.h"
+#endif
+
+#if ENABLED(HOTEND_IDLE_TIMEOUT)
+ #include "feature/hotend_idle.h"
+#endif
+
#if ENABLED(TEMP_STAT_LEDS)
#include "feature/leds/tempstat.h"
#endif
-#if HAS_CASE_LIGHT
+#if ENABLED(CASE_LIGHT_ENABLE)
#include "feature/caselight.h"
#endif
@@ -181,26 +217,22 @@
#include "libs/L64XX/L64XX_Marlin.h"
#endif
-const char NUL_STR[] PROGMEM = "",
- M112_KILL_STR[] PROGMEM = "M112 Shutdown",
- G28_STR[] PROGMEM = "G28",
- M21_STR[] PROGMEM = "M21",
- M23_STR[] PROGMEM = "M23 %s",
- M24_STR[] PROGMEM = "M24",
- SP_P_STR[] PROGMEM = " P",
- SP_T_STR[] PROGMEM = " T",
- SP_X_STR[] PROGMEM = " X",
- SP_Y_STR[] PROGMEM = " Y",
- SP_Z_STR[] PROGMEM = " Z",
- SP_E_STR[] PROGMEM = " E",
- X_LBL[] PROGMEM = "X:",
- Y_LBL[] PROGMEM = "Y:",
- Z_LBL[] PROGMEM = "Z:",
- E_LBL[] PROGMEM = "E:",
- SP_X_LBL[] PROGMEM = " X:",
- SP_Y_LBL[] PROGMEM = " Y:",
- SP_Z_LBL[] PROGMEM = " Z:",
- SP_E_LBL[] PROGMEM = " E:";
+#if ENABLED(PASSWORD_FEATURE)
+ #include "feature/password/password.h"
+#endif
+
+PGMSTR(NUL_STR, "");
+PGMSTR(M112_KILL_STR, "M112 Shutdown");
+PGMSTR(G28_STR, "G28");
+PGMSTR(M21_STR, "M21");
+PGMSTR(M23_STR, "M23 %s");
+PGMSTR(M24_STR, "M24");
+PGMSTR(SP_P_STR, " P"); PGMSTR(SP_T_STR, " T");
+PGMSTR(X_STR, "X"); PGMSTR(Y_STR, "Y"); PGMSTR(Z_STR, "Z"); PGMSTR(E_STR, "E");
+PGMSTR(X_LBL, "X:"); PGMSTR(Y_LBL, "Y:"); PGMSTR(Z_LBL, "Z:"); PGMSTR(E_LBL, "E:");
+PGMSTR(SP_A_STR, " A"); PGMSTR(SP_B_STR, " B"); PGMSTR(SP_C_STR, " C");
+PGMSTR(SP_X_STR, " X"); PGMSTR(SP_Y_STR, " Y"); PGMSTR(SP_Z_STR, " Z"); PGMSTR(SP_E_STR, " E");
+PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMSTR(SP_E_LBL, " E:");
MarlinState marlin_state = MF_INITIALIZING;
@@ -212,28 +244,17 @@ bool wait_for_heatup = true;
bool wait_for_user; // = false;
void wait_for_user_response(millis_t ms/*=0*/, const bool no_sleep/*=false*/) {
- #if DISABLED(ADVANCED_PAUSE_FEATURE)
- UNUSED(no_sleep);
- #endif
+ TERN(ADVANCED_PAUSE_FEATURE,,UNUSED(no_sleep));
KEEPALIVE_STATE(PAUSED_FOR_USER);
wait_for_user = true;
if (ms) ms += millis(); // expire time
- while (wait_for_user && !(ms && ELAPSED(millis(), ms))) {
- idle(
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- no_sleep
- #endif
- );
- }
+ while (wait_for_user && !(ms && ELAPSED(millis(), ms)))
+ idle(TERN_(ADVANCED_PAUSE_FEATURE, no_sleep));
wait_for_user = false;
}
#endif
-// Inactivity shutdown
-millis_t max_inactive_time, // = 0
- stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
-
#if PIN_EXISTS(CHDK)
extern millis_t chdk_timeout;
#endif
@@ -250,7 +271,11 @@ millis_t max_inactive_time, // = 0
void setup_killpin() {
#if HAS_KILL
- SET_INPUT_PULLUP(KILL_PIN);
+ #if KILL_PIN_STATE
+ SET_INPUT_PULLDOWN(KILL_PIN);
+ #else
+ SET_INPUT_PULLUP(KILL_PIN);
+ #endif
#endif
}
@@ -290,6 +315,9 @@ void setup_powerhold() {
#include "pins/sensitive_pins.h"
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnarrowing"
+
bool pin_is_protected(const pin_t pin) {
static const pin_t sensitive_pins[] PROGMEM = SENSITIVE_PINS;
LOOP_L_N(i, COUNT(sensitive_pins)) {
@@ -300,6 +328,8 @@ bool pin_is_protected(const pin_t pin) {
return false;
}
+#pragma GCC diagnostic pop
+
void protected_pin_err() {
SERIAL_ERROR_MSG(STR_ERR_PROTECTED_PIN);
}
@@ -317,9 +347,7 @@ void enable_e_steppers() {
}
void enable_all_steppers() {
- #if ENABLED(AUTO_POWER_CONTROL)
- powerManager.power_on();
- #endif
+ TERN_(AUTO_POWER_CONTROL, powerManager.power_on());
ENABLE_AXIS_X();
ENABLE_AXIS_Y();
ENABLE_AXIS_Z();
@@ -363,9 +391,7 @@ void disable_all_steppers() {
}
void event_probe_recover() {
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"), DISMISS_STR);
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"), DISMISS_STR));
#ifdef ACTION_ON_G29_RECOVER
host_action(PSTR(ACTION_ON_G29_RECOVER));
#endif
@@ -382,6 +408,13 @@ void disable_all_steppers() {
constexpr bool did_pause_print = false;
#endif
+/**
+ * A Print Job exists when the timer is running or SD printing
+ */
+bool printJobOngoing() {
+ return print_job_timer.isRunning() || IS_SD_PRINTING();
+}
+
/**
* Printing is active when the print job timer is running
*/
@@ -398,12 +431,8 @@ bool printingIsPaused() {
void startOrResumeJob() {
if (!printingIsPaused()) {
- #if ENABLED(CANCEL_OBJECTS)
- cancelable.reset();
- #endif
- #if ENABLED(LCD_SHOW_E_TOTAL)
- e_move_accumulator = 0;
- #endif
+ TERN_(CANCEL_OBJECTS, cancelable.reset());
+ TERN_(LCD_SHOW_E_TOTAL, e_move_accumulator = 0);
#if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
ui.reset_remaining_time();
#endif
@@ -414,37 +443,38 @@ void startOrResumeJob() {
#if ENABLED(SDSUPPORT)
inline void abortSDPrinting() {
- card.endFilePrint(
- #if SD_RESORT
- true
- #endif
- );
+ card.endFilePrint(TERN_(SD_RESORT, true));
queue.clear();
quickstop_stepper();
print_job_timer.stop();
#if DISABLED(SD_ABORT_NO_COOLDOWN)
thermalManager.disable_all_heaters();
#endif
- thermalManager.zero_fan_speeds();
+ #if !HAS_CUTTER
+ thermalManager.zero_fan_speeds();
+ #else
+ cutter.kill(); // Full cutter shutdown including ISR control
+ #endif
wait_for_heatup = false;
- #if ENABLED(POWER_LOSS_RECOVERY)
- recovery.purge();
- #endif
- #ifdef EVENT_GCODE_SD_STOP
- queue.inject_P(PSTR(EVENT_GCODE_SD_STOP));
+ TERN_(POWER_LOSS_RECOVERY, recovery.purge());
+ #ifdef EVENT_GCODE_SD_ABORT
+ queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT));
#endif
+
+ TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine());
}
inline void finishSDPrinting() {
- if (queue.enqueue_one_P(PSTR("M1001")))
+ if (queue.enqueue_one_P(PSTR("M1001"))) {
marlin_state = MF_RUNNING;
+ TERN_(PASSWORD_AFTER_SD_PRINT_END, password.lock_machine());
+ }
}
#endif // SDSUPPORT
/**
* Minimal management of Marlin's core activities:
- * - Check for Filament Runout
* - Keep the command buffer full
* - Check for maximum inactive time between commands
* - Check for maximum inactive time between stepper commands
@@ -455,43 +485,46 @@ void startOrResumeJob() {
* - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT)
* - Pulse FET_SAFETY_PIN if it exists
*/
-
inline void manage_inactivity(const bool ignore_stepper_queue=false) {
- #if HAS_FILAMENT_SENSOR
- runout.run();
- #endif
-
if (queue.length < BUFSIZE) queue.get_available_commands();
const millis_t ms = millis();
- if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) {
+ // Prevent steppers timing-out in the middle of M600
+ // unless PAUSE_PARK_NO_STEPPER_TIMEOUT is disabled
+ const bool parked_or_ignoring = ignore_stepper_queue ||
+ (BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) && did_pause_print);
+
+ // Reset both the M18/M84 activity timeout and the M85 max 'kill' timeout
+ if (parked_or_ignoring) gcode.reset_stepper_timeout(ms);
+
+ if (gcode.stepper_max_timed_out(ms)) {
SERIAL_ERROR_START();
SERIAL_ECHOLNPAIR(STR_KILL_INACTIVE_TIME, parser.command_ptr);
kill();
}
- // Prevent steppers timing-out in the middle of M600
- #define STAY_TEST (BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT) && did_pause_print)
+ // M18 / M94 : Handle steppers inactive time timeout
+ if (gcode.stepper_inactive_time) {
- if (stepper_inactive_time) {
static bool already_shutdown_steppers; // = false
+
+ // Any moves in the planner? Resets both the M18/M84
+ // activity timeout and the M85 max 'kill' timeout
if (planner.has_blocks_queued())
- gcode.reset_stepper_timeout();
- else if (!STAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) {
+ gcode.reset_stepper_timeout(ms);
+ else if (!parked_or_ignoring && gcode.stepper_inactive_timeout()) {
if (!already_shutdown_steppers) {
already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this
+
+ // Individual axes will be disabled if configured
if (ENABLED(DISABLE_INACTIVE_X)) DISABLE_AXIS_X();
if (ENABLED(DISABLE_INACTIVE_Y)) DISABLE_AXIS_Y();
if (ENABLED(DISABLE_INACTIVE_Z)) DISABLE_AXIS_Z();
if (ENABLED(DISABLE_INACTIVE_E)) disable_e_steppers();
- #if HAS_LCD_MENU && ENABLED(AUTO_BED_LEVELING_UBL)
- if (ubl.lcd_map_control) {
- ubl.lcd_map_control = false;
- ui.defer_status_screen(false);
- }
- #endif
+
+ TERN_(AUTO_BED_LEVELING_UBL, ubl.steppers_were_disabled());
}
}
else
@@ -512,7 +545,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
// -------------------------------------------------------------------------------
static int killCount = 0; // make the inactivity button a bit less responsive
const int KILL_DELAY = 750;
- if (!READ(KILL_PIN))
+ if (kill_state())
killCount++;
else if (killCount > 0)
killCount--;
@@ -540,17 +573,15 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
#endif
- #if ENABLED(USE_CONTROLLER_FAN)
- controllerFan.update(); // Check if fan should be turned on to cool stepper drivers down
- #endif
+ TERN_(USE_CONTROLLER_FAN, controllerFan.update()); // Check if fan should be turned on to cool stepper drivers down
- #if ENABLED(AUTO_POWER_CONTROL)
- powerManager.check();
- #endif
+ TERN_(AUTO_POWER_CONTROL, powerManager.check());
+
+ TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check());
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
- && ELAPSED(ms, gcode.previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
+ && ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
&& !planner.has_blocks_queued()
) {
#if ENABLED(SWITCHING_EXTRUDER)
@@ -600,7 +631,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
#endif // !SWITCHING_EXTRUDER
- gcode.reset_stepper_timeout();
+ gcode.reset_stepper_timeout(ms);
}
#endif // EXTRUDER_RUNOUT_PREVENT
@@ -614,17 +645,11 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
#endif
- #if ENABLED(TEMP_STAT_LEDS)
- handle_status_leds();
- #endif
+ TERN_(TEMP_STAT_LEDS, handle_status_leds());
- #if ENABLED(MONITOR_DRIVER_STATUS)
- monitor_tmc_drivers();
- #endif
+ TERN_(MONITOR_DRIVER_STATUS, monitor_tmc_drivers());
- #if ENABLED(MONITOR_L6470_DRIVER_STATUS)
- L64xxManager.monitor_driver();
- #endif
+ TERN_(MONITOR_L6470_DRIVER_STATUS, L64xxManager.monitor_driver());
// Limit check_axes_activity frequency to 10Hz
static millis_t next_check_axes_ms = 0;
@@ -645,54 +670,81 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
}
/**
- * Standard idle routine keeps the machine alive
+ * Standard idle routine keeps the machine alive:
+ * - Core Marlin activities
+ * - Manage heaters (and Watchdog)
+ * - Max7219 heartbeat, animation, etc.
+ *
+ * Only after setup() is complete:
+ * - Handle filament runout sensors
+ * - Run HAL idle tasks
+ * - Handle Power-Loss Recovery
+ * - Run StallGuard endstop checks
+ * - Handle SD Card insert / remove
+ * - Handle USB Flash Drive insert / remove
+ * - Announce Host Keepalive state (if any)
+ * - Update the Print Job Timer state
+ * - Update the Beeper queue
+ * - Read Buttons and Update the LCD
+ * - Run i2c Position Encoders
+ * - Auto-report Temperatures / SD Status
+ * - Update the Průša MMU2
+ * - Handle Joystick jogging
*/
-void idle(
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- bool no_stepper_sleep/*=false*/
- #endif
-) {
- #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
- recovery.outage();
- #endif
+void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
- #if ENABLED(SPI_ENDSTOPS)
- if (endstops.tmc_spi_homing.any
- #if ENABLED(IMPROVE_HOMING_RELIABILITY)
- && ELAPSED(millis(), sg_guard_period)
- #endif
- ) {
- for (uint8_t i = 4; i--;) // Read SGT 4 times per idle loop
- if (endstops.tmc_spi_homing_check()) break;
- }
- #endif
-
- #if ENABLED(MAX7219_DEBUG)
- max7219.idle_tasks();
- #endif
-
- ui.update();
-
- #if ENABLED(HOST_KEEPALIVE_FEATURE)
- gcode.host_keepalive();
- #endif
-
- manage_inactivity(
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- no_stepper_sleep
- #endif
- );
+ // Core Marlin activities
+ manage_inactivity(TERN_(ADVANCED_PAUSE_FEATURE, no_stepper_sleep));
+ // Manage Heaters (and Watchdog)
thermalManager.manage_heater();
- #if ENABLED(PRINTCOUNTER)
- print_job_timer.tick();
+ // Max7219 heartbeat, animation, etc
+ TERN_(MAX7219_DEBUG, max7219.idle_tasks());
+
+ // Return if setup() isn't completed
+ if (marlin_state == MF_INITIALIZING) return;
+
+ // Handle filament runout sensors
+ TERN_(HAS_FILAMENT_SENSOR, runout.run());
+
+ // Run HAL idle tasks
+ #ifdef HAL_IDLETASK
+ HAL_idletask();
#endif
- #if USE_BEEPER
- buzzer.tick();
+ // Handle Power-Loss Recovery
+ #if ENABLED(POWER_LOSS_RECOVERY) && PIN_EXISTS(POWER_LOSS)
+ if (printJobOngoing()) recovery.outage();
#endif
+ // Run StallGuard endstop checks
+ #if ENABLED(SPI_ENDSTOPS)
+ if (endstops.tmc_spi_homing.any
+ && TERN1(IMPROVE_HOMING_RELIABILITY, ELAPSED(millis(), sg_guard_period))
+ ) LOOP_L_N(i, 4) // Read SGT 4 times per idle loop
+ if (endstops.tmc_spi_homing_check()) break;
+ #endif
+
+ // Handle SD Card insert / remove
+ TERN_(SDSUPPORT, card.manage_media());
+
+ // Handle USB Flash Drive insert / remove
+ TERN_(USB_FLASH_DRIVE_SUPPORT, Sd2Card::idle());
+
+ // Announce Host Keepalive state (if any)
+ TERN_(HOST_KEEPALIVE_FEATURE, gcode.host_keepalive());
+
+ // Update the Print Job Timer state
+ TERN_(PRINTCOUNTER, print_job_timer.tick());
+
+ // Update the Beeper queue
+ TERN_(USE_BEEPER, buzzer.tick());
+
+ // Handle UI input / draw events
+ TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update());
+
+ // Run i2c Position Encoders
#if ENABLED(I2C_POSITION_ENCODERS)
static millis_t i2cpem_next_update_ms;
if (planner.has_blocks_queued()) {
@@ -704,31 +756,25 @@ void idle(
}
#endif
- #ifdef HAL_IDLETASK
- HAL_idletask();
- #endif
-
+ // Auto-report Temperatures / SD Status
#if HAS_AUTO_REPORTING
if (!gcode.autoreport_paused) {
- #if ENABLED(AUTO_REPORT_TEMPERATURES)
- thermalManager.auto_report_temperatures();
- #endif
- #if ENABLED(AUTO_REPORT_SD_STATUS)
- card.auto_report_sd_status();
- #endif
+ TERN_(AUTO_REPORT_TEMPERATURES, thermalManager.auto_report_temperatures());
+ TERN_(AUTO_REPORT_SD_STATUS, card.auto_report_sd_status());
}
#endif
- #if ENABLED(USB_FLASH_DRIVE_SUPPORT)
- Sd2Card::idle();
- #endif
+ // Update the Průša MMU2
+ TERN_(PRUSA_MMU2, mmu2.mmu_loop());
- #if ENABLED(PRUSA_MMU2)
- mmu2.mmu_loop();
- #endif
+ // Handle Joystick jogging
+ TERN_(POLL_JOG, joystick.inject_jog_moves());
- #if ENABLED(POLL_JOG)
- joystick.inject_jog_moves();
+ // Direct Stepping
+ TERN_(DIRECT_STEPPING, page_manager.write_responses());
+
+ #if HAS_TFT_LVGL_UI
+ LV_TASK_HANDLER();
#endif
}
@@ -739,6 +785,8 @@ void idle(
void kill(PGM_P const lcd_error/*=nullptr*/, PGM_P const lcd_component/*=nullptr*/, const bool steppers_off/*=false*/) {
thermalManager.disable_all_heaters();
+ TERN_(HAS_CUTTER, cutter.kill()); // Full cutter shutdown including ISR control
+
SERIAL_ERROR_MSG(STR_ERR_KILLED);
#if HAS_DISPLAY
@@ -768,33 +816,31 @@ void minkill(const bool steppers_off/*=false*/) {
// Reiterate heaters off
thermalManager.disable_all_heaters();
+ TERN_(HAS_CUTTER, cutter.kill()); // Reiterate cutter shutdown
+
// Power off all steppers (for M112) or just the E steppers
steppers_off ? disable_all_steppers() : disable_e_steppers();
- #if ENABLED(PSU_CONTROL)
- PSU_OFF();
- #endif
+ TERN_(PSU_CONTROL, PSU_OFF());
- #if HAS_SUICIDE
- suicide();
- #endif
+ TERN_(HAS_SUICIDE, suicide());
#if HAS_KILL
// Wait for kill to be released
- while (!READ(KILL_PIN)) watchdog_refresh();
+ while (kill_state()) watchdog_refresh();
// Wait for kill to be pressed
- while (READ(KILL_PIN)) watchdog_refresh();
+ while (!kill_state()) watchdog_refresh();
- void (*resetFunc)() = 0; // Declare resetFunc() at address 0
+ void (*resetFunc)() = 0; // Declare resetFunc() at address 0
resetFunc(); // Jump to address 0
- #else // !HAS_KILL
+ #else
- for (;;) watchdog_refresh(); // Wait for reset
+ for (;;) watchdog_refresh(); // Wait for reset
- #endif // !HAS_KILL
+ #endif
}
/**
@@ -838,86 +884,93 @@ void stop() {
*/
void setup() {
- HAL_init();
-
- #if HAS_L64XX
- L64xxManager.init(); // Set up SPI, init drivers
+ #if ENABLED(MARLIN_DEV_MODE)
+ auto log_current_ms = [&](PGM_P const msg) {
+ SERIAL_ECHO_START();
+ SERIAL_CHAR('['); SERIAL_ECHO(millis()); SERIAL_ECHOPGM("] ");
+ serialprintPGM(msg);
+ SERIAL_EOL();
+ };
+ #define SETUP_LOG(M) log_current_ms(PSTR(M))
+ #else
+ #define SETUP_LOG(...) NOOP
#endif
+ #define SETUP_RUN(C) do{ SETUP_LOG(STRINGIFY(C)); C; }while(0)
- #if ENABLED(SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
- OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Put Smart Effector into NORMAL mode
- #endif
-
- #if ENABLED(DISABLE_DEBUG)
+ #if EITHER(DISABLE_DEBUG, DISABLE_JTAG)
// Disable any hardware debug to free up pins for IO
- #ifdef JTAGSWD_DISABLE
+ #if ENABLED(DISABLE_DEBUG) && defined(JTAGSWD_DISABLE)
JTAGSWD_DISABLE();
#elif defined(JTAG_DISABLE)
JTAG_DISABLE();
#else
- #error "DISABLE_DEBUG is not supported for the selected MCU/Board"
+ #error "DISABLE_(DEBUG|JTAG) is not supported for the selected MCU/Board."
#endif
- #elif ENABLED(DISABLE_JTAG)
- // Disable JTAG to free up pins for IO
- #ifdef JTAG_DISABLE
- JTAG_DISABLE();
- #else
- #error "DISABLE_JTAG is not supported for the selected MCU/Board"
- #endif
- #endif
-
- #if HAS_FILAMENT_SENSOR
- runout.setup();
- #endif
-
- #if ENABLED(POWER_LOSS_RECOVERY)
- recovery.setup();
- #endif
-
- setup_killpin();
-
- #if HAS_TMC220x
- tmc_serial_begin();
- #endif
-
- setup_powerhold();
-
- #if HAS_STEPPER_RESET
- disableStepperDrivers();
#endif
#if NUM_SERIAL > 0
MYSERIAL0.begin(BAUDRATE);
uint32_t serial_connect_timeout = millis() + 1000UL;
while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
- #if NUM_SERIAL > 1
+ #if HAS_MULTI_SERIAL
MYSERIAL1.begin(BAUDRATE);
serial_connect_timeout = millis() + 1000UL;
while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
#endif
+ SERIAL_ECHO_MSG("start");
#endif
- SERIAL_ECHOLNPGM("start");
- SERIAL_ECHO_START();
+ SETUP_RUN(HAL_init());
+
+ #if HAS_L64XX
+ SETUP_RUN(L64xxManager.init()); // Set up SPI, init drivers
+ #endif
+
+ #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD)
+ OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Put Smart Effector into NORMAL mode
+ #endif
+
+ #if HAS_FILAMENT_SENSOR
+ SETUP_RUN(runout.setup());
+ #endif
+
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ SETUP_RUN(recovery.setup());
+ #endif
+
+ SETUP_RUN(setup_killpin());
+
+ #if HAS_TMC220x
+ SETUP_RUN(tmc_serial_begin());
+ #endif
+
+ SETUP_RUN(setup_powerhold());
+
+ #if HAS_STEPPER_RESET
+ SETUP_RUN(disableStepperDrivers());
+ #endif
#if HAS_TMC_SPI
#if DISABLED(TMC_USE_SW_SPI)
- SPI.begin();
+ SETUP_RUN(SPI.begin());
#endif
- tmc_init_cs_pins();
+ SETUP_RUN(tmc_init_cs_pins());
#endif
#ifdef BOARD_INIT
+ SETUP_LOG("BOARD_INIT");
BOARD_INIT();
#endif
+ SETUP_RUN(esp_wifi_init());
+
// Check startup - does nothing if bootloader sets MCUSR to 0
- byte mcu = HAL_get_reset_source();
- if (mcu & 1) SERIAL_ECHOLNPGM(STR_POWERUP);
- if (mcu & 2) SERIAL_ECHOLNPGM(STR_EXTERNAL_RESET);
- if (mcu & 4) SERIAL_ECHOLNPGM(STR_BROWNOUT_RESET);
- if (mcu & 8) SERIAL_ECHOLNPGM(STR_WATCHDOG_RESET);
- if (mcu & 32) SERIAL_ECHOLNPGM(STR_SOFTWARE_RESET);
+ const byte mcu = HAL_get_reset_source();
+ if (mcu & RST_POWER_ON) SERIAL_ECHOLNPGM(STR_POWERUP);
+ if (mcu & RST_EXTERNAL) SERIAL_ECHOLNPGM(STR_EXTERNAL_RESET);
+ if (mcu & RST_BROWN_OUT) SERIAL_ECHOLNPGM(STR_BROWNOUT_RESET);
+ if (mcu & RST_WATCHDOG) SERIAL_ECHOLNPGM(STR_WATCHDOG_RESET);
+ if (mcu & RST_SOFTWARE) SERIAL_ECHOLNPGM(STR_SOFTWARE_RESET);
HAL_clear_reset_source();
serialprintPGM(GET_TEXT(MSG_MARLIN));
@@ -937,56 +990,48 @@ void setup() {
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(STR_FREE_MEMORY, freeMemory(), STR_PLANNER_BUFFER_BYTES, (int)sizeof(block_t) * (BLOCK_BUFFER_SIZE));
- // UI must be initialized before EEPROM
- // (because EEPROM code calls the UI).
-
- #if ENABLED(MARLIN_DEV_MODE)
- auto log_current_ms = [&](PGM_P const msg) {
- SERIAL_ECHO_START();
- SERIAL_CHAR('['); SERIAL_ECHO(millis()); SERIAL_ECHO("] ");
- serialprintPGM(msg);
- SERIAL_EOL();
- };
- #define SETUP_LOG(M) log_current_ms(PSTR(M))
- #else
- #define SETUP_LOG(...) NOOP
- #endif
- #define SETUP_RUN(C) do{ SETUP_LOG(STRINGIFY(C)); C; }while(0)
-
// Set up LEDs early
#if HAS_COLOR_LEDS
SETUP_RUN(leds.setup());
#endif
+ #if ENABLED(NEOPIXEL2_SEPARATE)
+ SETUP_RUN(leds2.setup());
+ #endif
+
#if ENABLED(USE_CONTROLLER_FAN) // Set up fan controller to initialize also the default configurations.
SETUP_RUN(controllerFan.setup());
#endif
- SETUP_RUN(ui.init());
- SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)
+ // UI must be initialized before EEPROM
+ // (because EEPROM code calls the UI).
- #if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN)
- SETUP_RUN(ui.show_bootscreen());
+ #if ENABLED(DWIN_CREALITY_LCD)
+ delay(800); // Required delay (since boot?)
+ SERIAL_ECHOPGM("\nDWIN handshake ");
+ if (DWIN_Handshake()) SERIAL_ECHOLNPGM("ok."); else SERIAL_ECHOLNPGM("error.");
+ DWIN_Frame_SetDir(1); // Orientation 90°
+ DWIN_UpdateLCD(); // Show bootscreen (first image)
+ #else
+ SETUP_RUN(ui.init());
+ #if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN)
+ SETUP_RUN(ui.show_bootscreen());
+ #endif
+ SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)
#endif
- #if ENABLED(SDSUPPORT) && defined(SDCARD_CONNECTION) && !SD_CONNECTION_IS(LCD)
- SETUP_RUN(card.mount()); // Mount onboard / custom SD card before settings.first_load
+ #if BOTH(SDSUPPORT, SDCARD_EEPROM_EMULATION)
+ SETUP_RUN(card.mount()); // Mount media with settings before first_load
#endif
SETUP_RUN(settings.first_load()); // Load data from EEPROM if available (or use defaults)
// This also updates variables in the planner, elsewhere
- #if HAS_SERVICE_INTERVALS
- SETUP_RUN(ui.reset_status(true)); // Show service messages or keep current status
- #endif
-
- #if ENABLED(TOUCH_BUTTONS)
+ #if HAS_TOUCH_XPT2046
SETUP_RUN(touch.init());
#endif
- #if HAS_M206_COMMAND
- current_position += home_offset; // Init current position based on home_offset
- #endif
+ TERN_(HAS_M206_COMMAND, current_position += home_offset); // Init current position based on home_offset
sync_plan_position(); // Vital to init stepper/planner equivalent for current_position
@@ -1029,7 +1074,7 @@ void setup() {
SETUP_RUN(enableStepperDrivers());
#endif
- #if ENABLED(DIGIPOT_I2C)
+ #if HAS_I2C_DIGIPOT
SETUP_RUN(digipot_i2c_init());
#endif
@@ -1053,11 +1098,11 @@ void setup() {
OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // OFF
#endif
- #if HAS_CASE_LIGHT
+ #if ENABLED(CASE_LIGHT_ENABLE)
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
#endif
- SETUP_RUN(update_case_light());
+ SETUP_RUN(caselight.update_brightness());
#endif
#if ENABLED(MK2_MULTIPLEXER)
@@ -1113,23 +1158,19 @@ void setup() {
#endif
#if ENABLED(SWITCHING_TOOLHEAD)
- swt_init();
+ SETUP_RUN(swt_init());
#endif
#if ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
SETUP_RUN(est_init());
#endif
- #if ENABLED(POWER_LOSS_RECOVERY)
- SETUP_RUN(recovery.check());
- #endif
-
#if ENABLED(USE_WATCHDOG)
SETUP_RUN(watchdog_init()); // Reinit watchdog after HAL_get_reset_source call
#endif
#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
- SETUP_RUN(init_closedloop());
+ SETUP_RUN(closedloop.init());
#endif
#ifdef STARTUP_COMMANDS
@@ -1137,10 +1178,6 @@ void setup() {
queue.inject_P(PSTR(STARTUP_COMMANDS));
#endif
- #if ENABLED(INIT_SDCARD_ON_BOOT) && !HAS_SPI_LCD
- SETUP_RUN(card.beginautostart());
- #endif
-
#if ENABLED(HOST_PROMPT_SUPPORT)
SETUP_RUN(host_action_prompt_end());
#endif
@@ -1153,10 +1190,41 @@ void setup() {
SETUP_RUN(mmu2.init());
#endif
+ #if ENABLED(IIC_BL24CXX_EEPROM)
+ BL24CXX::init();
+ const uint8_t err = BL24CXX::check();
+ SERIAL_ECHO_TERNARY(err, "BL24CXX Check ", "failed", "succeeded", "!\n");
+ #endif
+
+ #if ENABLED(DWIN_CREALITY_LCD)
+ Encoder_Configuration();
+ HMI_Init();
+ HMI_StartFrame(true);
+ #endif
+
+ #if HAS_SERVICE_INTERVALS && DISABLED(DWIN_CREALITY_LCD)
+ ui.reset_status(true); // Show service messages or keep current status
+ #endif
+
#if ENABLED(MAX7219_DEBUG)
SETUP_RUN(max7219.init());
#endif
+ #if ENABLED(DIRECT_STEPPING)
+ SETUP_RUN(page_manager.init());
+ #endif
+
+ #if HAS_TFT_LVGL_UI
+ #if ENABLED(SDSUPPORT)
+ if (!card.isMounted()) SETUP_RUN(card.mount()); // Mount SD to load graphics and fonts
+ #endif
+ SETUP_RUN(tft_lvgl_init());
+ #endif
+
+ #if ENABLED(PASSWORD_ON_STARTUP)
+ SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided
+ #endif
+
marlin_state = MF_RUNNING;
SETUP_LOG("setup() completed.");
@@ -1189,5 +1257,7 @@ void loop() {
endstops.event_handler();
+ TERN_(HAS_TFT_LVGL_UI, printer_state_polling());
+
} while (ENABLED(__AVR__)); // Loop forever on slower (AVR) boards
}
diff --git a/Marlin/src/MarlinCore.h b/Marlin/src/MarlinCore.h
index e6678c5b18..69afc7f30e 100644
--- a/Marlin/src/MarlinCore.h
+++ b/Marlin/src/MarlinCore.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -31,26 +31,11 @@
#include
#include
-#if HAS_L64XX
- #include "libs/L64XX/L64XX_Marlin.h"
- extern uint8_t axis_known_position;
-#endif
-
void stop();
-void idle(
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- bool no_stepper_sleep=false // Pass true to keep steppers from timing out
- #endif
-);
-
-inline void idle_no_sleep() {
- idle(
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- true
- #endif
- );
-}
+// Pass true to keep steppers from timing out
+void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep=false));
+inline void idle_no_sleep() { idle(TERN_(ADVANCED_PAUSE_FEATURE, true)); }
#if ENABLED(EXPERIMENTAL_I2CBUS)
#include "feature/twibus.h"
@@ -102,17 +87,10 @@ extern bool wait_for_heatup;
void wait_for_user_response(millis_t ms=0, const bool no_sleep=false);
#endif
-// Inactivity shutdown timer
-extern millis_t max_inactive_time, stepper_inactive_time;
-
-#if ENABLED(USE_CONTROLLER_FAN)
- extern uint8_t controllerfan_speed;
-#endif
-
#if ENABLED(PSU_CONTROL)
extern bool powersupply_on;
- #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_HIGH); powersupply_on = true; }while(0)
- #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_HIGH); powersupply_on = false; }while(0)
+ #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); powersupply_on = true; }while(0)
+ #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); powersupply_on = false; }while(0)
#if ENABLED(AUTO_POWER_CONTROL)
#define PSU_ON() powerManager.power_on()
#define PSU_OFF() powerManager.power_off()
@@ -129,12 +107,19 @@ void protected_pin_err();
inline void suicide() { OUT_WRITE(SUICIDE_PIN, SUICIDE_PIN_INVERTING); }
#endif
+#if HAS_KILL
+ #ifndef KILL_PIN_STATE
+ #define KILL_PIN_STATE LOW
+ #endif
+ inline bool kill_state() { return READ(KILL_PIN) == KILL_PIN_STATE; }
+#endif
+
#if ENABLED(G29_RETRY_AND_RECOVER)
void event_probe_recover();
void event_probe_failure();
#endif
extern const char NUL_STR[], M112_KILL_STR[], G28_STR[], M21_STR[], M23_STR[], M24_STR[],
+ SP_A_STR[], SP_B_STR[], SP_C_STR[],
SP_P_STR[], SP_T_STR[], SP_X_STR[], SP_Y_STR[], SP_Z_STR[], SP_E_STR[],
X_LBL[], Y_LBL[], Z_LBL[], E_LBL[], SP_X_LBL[], SP_Y_LBL[], SP_Z_LBL[], SP_E_LBL[];
-
diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h
index 30c2d3eb87..c880b3d325 100644
--- a/Marlin/src/core/boards.h
+++ b/Marlin/src/core/boards.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -56,54 +56,57 @@
#define BOARD_3DRAG 1100 // 3Drag Controller
#define BOARD_K8200 1101 // Velleman K8200 Controller (derived from 3Drag Controller)
#define BOARD_K8400 1102 // Velleman K8400 Controller (derived from 3Drag Controller)
-#define BOARD_BAM_DICE 1103 // 2PrintBeta BAM&DICE with STK drivers
-#define BOARD_BAM_DICE_DUE 1104 // 2PrintBeta BAM&DICE Due with STK drivers
-#define BOARD_MKS_BASE 1105 // MKS BASE v1.0
-#define BOARD_MKS_BASE_14 1106 // MKS BASE v1.4 with Allegro A4982 stepper drivers
-#define BOARD_MKS_BASE_15 1107 // MKS BASE v1.5 with Allegro A4982 stepper drivers
-#define BOARD_MKS_BASE_16 1108 // MKS BASE v1.6 with Allegro A4982 stepper drivers
-#define BOARD_MKS_BASE_HEROIC 1109 // MKS BASE 1.0 with Heroic HR4982 stepper drivers
-#define BOARD_MKS_GEN_13 1110 // MKS GEN v1.3 or 1.4
-#define BOARD_MKS_GEN_L 1111 // MKS GEN L
-#define BOARD_KFB_2 1112 // BigTreeTech or BIQU KFB2.0
-#define BOARD_ZRIB_V20 1113 // zrib V2.0 control board (Chinese knock off RAMPS replica)
-#define BOARD_FELIX2 1114 // Felix 2.0+ Electronics Board (RAMPS like)
-#define BOARD_RIGIDBOARD 1115 // Invent-A-Part RigidBoard
-#define BOARD_RIGIDBOARD_V2 1116 // Invent-A-Part RigidBoard V2
-#define BOARD_SAINSMART_2IN1 1117 // Sainsmart 2-in-1 board
-#define BOARD_ULTIMAKER 1118 // Ultimaker
-#define BOARD_ULTIMAKER_OLD 1119 // Ultimaker (Older electronics. Pre 1.5.4. This is rare)
-#define BOARD_AZTEEG_X3 1120 // Azteeg X3
-#define BOARD_AZTEEG_X3_PRO 1121 // Azteeg X3 Pro
-#define BOARD_ULTIMAIN_2 1122 // Ultimainboard 2.x (Uses TEMP_SENSOR 20)
-#define BOARD_RUMBA 1123 // Rumba
-#define BOARD_RUMBA_RAISE3D 1124 // Raise3D N series Rumba derivative
-#define BOARD_RL200 1125 // Rapide Lite 200 (v1, low-cost RUMBA clone with drv)
-#define BOARD_FORMBOT_TREX2PLUS 1126 // Formbot T-Rex 2 Plus
-#define BOARD_FORMBOT_TREX3 1127 // Formbot T-Rex 3
-#define BOARD_FORMBOT_RAPTOR 1128 // Formbot Raptor
-#define BOARD_FORMBOT_RAPTOR2 1129 // Formbot Raptor 2
-#define BOARD_BQ_ZUM_MEGA_3D 1130 // bq ZUM Mega 3D
-#define BOARD_MAKEBOARD_MINI 1131 // MakeBoard Mini v2.1.2 is a control board sold by MicroMake
-#define BOARD_TRIGORILLA_13 1132 // TriGorilla Anycubic version 1.3-based on RAMPS EFB
-#define BOARD_TRIGORILLA_14 1133 // ... Ver 1.4
-#define BOARD_TRIGORILLA_14_11 1134 // ... Rev 1.1 (new servo pin order)
-#define BOARD_RAMPS_ENDER_4 1135 // Creality: Ender-4, CR-8
-#define BOARD_RAMPS_CREALITY 1136 // Creality: CR10S, CR20, CR-X
-#define BOARD_RAMPS_DAGOMA 1137 // Dagoma F5
-#define BOARD_FYSETC_F6_13 1138 // FYSETC F6 1.3
-#define BOARD_FYSETC_F6_14 1139 // FYSETC F6 1.4
-#define BOARD_DUPLICATOR_I3_PLUS 1140 // Wanhao Duplicator i3 Plus
-#define BOARD_VORON 1141 // VORON Design
-#define BOARD_TRONXY_V3_1_0 1142 // Tronxy TRONXY-V3-1.0
-#define BOARD_Z_BOLT_X_SERIES 1143 // Z-Bolt X Series
-#define BOARD_TT_OSCAR 1144 // TT OSCAR
-#define BOARD_OVERLORD 1145 // Overlord/Overlord Pro
-#define BOARD_HJC2560C_REV1 1146 // ADIMLab Gantry v1
-#define BOARD_HJC2560C_REV2 1147 // ADIMLab Gantry v2
-#define BOARD_TANGO 1148 // BIQU Tango V1
-#define BOARD_MKS_GEN_L_V2 1149 // MKS GEN L V2
-#define BOARD_COPYMASTER_3D 1150 // Copymaster 3D
+#define BOARD_K8600 1103 // Velleman K8600 Controller (Vertex Nano)
+#define BOARD_BAM_DICE 1104 // 2PrintBeta BAM&DICE with STK drivers
+#define BOARD_BAM_DICE_DUE 1105 // 2PrintBeta BAM&DICE Due with STK drivers
+#define BOARD_MKS_BASE 1106 // MKS BASE v1.0
+#define BOARD_MKS_BASE_14 1107 // MKS BASE v1.4 with Allegro A4982 stepper drivers
+#define BOARD_MKS_BASE_15 1108 // MKS BASE v1.5 with Allegro A4982 stepper drivers
+#define BOARD_MKS_BASE_16 1109 // MKS BASE v1.6 with Allegro A4982 stepper drivers
+#define BOARD_MKS_BASE_HEROIC 1110 // MKS BASE 1.0 with Heroic HR4982 stepper drivers
+#define BOARD_MKS_GEN_13 1111 // MKS GEN v1.3 or 1.4
+#define BOARD_MKS_GEN_L 1112 // MKS GEN L
+#define BOARD_KFB_2 1113 // BigTreeTech or BIQU KFB2.0
+#define BOARD_ZRIB_V20 1114 // zrib V2.0 control board (Chinese knock off RAMPS replica)
+#define BOARD_FELIX2 1115 // Felix 2.0+ Electronics Board (RAMPS like)
+#define BOARD_RIGIDBOARD 1116 // Invent-A-Part RigidBoard
+#define BOARD_RIGIDBOARD_V2 1117 // Invent-A-Part RigidBoard V2
+#define BOARD_SAINSMART_2IN1 1118 // Sainsmart 2-in-1 board
+#define BOARD_ULTIMAKER 1119 // Ultimaker
+#define BOARD_ULTIMAKER_OLD 1120 // Ultimaker (Older electronics. Pre 1.5.4. This is rare)
+#define BOARD_AZTEEG_X3 1121 // Azteeg X3
+#define BOARD_AZTEEG_X3_PRO 1122 // Azteeg X3 Pro
+#define BOARD_ULTIMAIN_2 1123 // Ultimainboard 2.x (Uses TEMP_SENSOR 20)
+#define BOARD_RUMBA 1124 // Rumba
+#define BOARD_RUMBA_RAISE3D 1125 // Raise3D N series Rumba derivative
+#define BOARD_RL200 1126 // Rapide Lite 200 (v1, low-cost RUMBA clone with drv)
+#define BOARD_FORMBOT_TREX2PLUS 1127 // Formbot T-Rex 2 Plus
+#define BOARD_FORMBOT_TREX3 1128 // Formbot T-Rex 3
+#define BOARD_FORMBOT_RAPTOR 1129 // Formbot Raptor
+#define BOARD_FORMBOT_RAPTOR2 1130 // Formbot Raptor 2
+#define BOARD_BQ_ZUM_MEGA_3D 1131 // bq ZUM Mega 3D
+#define BOARD_MAKEBOARD_MINI 1132 // MakeBoard Mini v2.1.2 is a control board sold by MicroMake
+#define BOARD_TRIGORILLA_13 1133 // TriGorilla Anycubic version 1.3-based on RAMPS EFB
+#define BOARD_TRIGORILLA_14 1134 // ... Ver 1.4
+#define BOARD_TRIGORILLA_14_11 1135 // ... Rev 1.1 (new servo pin order)
+#define BOARD_RAMPS_ENDER_4 1136 // Creality: Ender-4, CR-8
+#define BOARD_RAMPS_CREALITY 1137 // Creality: CR10S, CR20, CR-X
+#define BOARD_RAMPS_DAGOMA 1138 // Dagoma F5
+#define BOARD_FYSETC_F6_13 1139 // FYSETC F6 1.3
+#define BOARD_FYSETC_F6_14 1140 // FYSETC F6 1.4
+#define BOARD_DUPLICATOR_I3_PLUS 1141 // Wanhao Duplicator i3 Plus
+#define BOARD_VORON 1142 // VORON Design
+#define BOARD_TRONXY_V3_1_0 1143 // Tronxy TRONXY-V3-1.0
+#define BOARD_Z_BOLT_X_SERIES 1144 // Z-Bolt X Series
+#define BOARD_TT_OSCAR 1145 // TT OSCAR
+#define BOARD_OVERLORD 1146 // Overlord/Overlord Pro
+#define BOARD_HJC2560C_REV1 1147 // ADIMLab Gantry v1
+#define BOARD_HJC2560C_REV2 1148 // ADIMLab Gantry v2
+#define BOARD_TANGO 1149 // BIQU Tango V1
+#define BOARD_MKS_GEN_L_V2 1150 // MKS GEN L V2
+#define BOARD_COPYMASTER_3D 1151 // Copymaster 3D
+#define BOARD_ORTUR_4 1152 // Ortur 4
+#define BOARD_TENLOG_D3_HERO 1153 // Tenlog D3 Hero IDEX printer
//
// RAMBo and derivatives
@@ -160,13 +163,15 @@
#define BOARD_SANGUINOLOLU_11 1500 // Sanguinololu < 1.2
#define BOARD_SANGUINOLOLU_12 1501 // Sanguinololu 1.2 and above
#define BOARD_MELZI 1502 // Melzi
-#define BOARD_MELZI_MAKR3D 1503 // Melzi with ATmega1284 (MaKr3d version)
-#define BOARD_MELZI_CREALITY 1504 // Melzi Creality3D board (for CR-10 etc)
-#define BOARD_MELZI_MALYAN 1505 // Melzi Malyan M150 board
-#define BOARD_MELZI_TRONXY 1506 // Tronxy X5S
-#define BOARD_STB_11 1507 // STB V1.1
-#define BOARD_AZTEEG_X1 1508 // Azteeg X1
-#define BOARD_ANET_10 1509 // Anet 1.0 (Melzi clone)
+#define BOARD_MELZI_V2 1503 // Melzi V2
+#define BOARD_MELZI_MAKR3D 1504 // Melzi with ATmega1284 (MaKr3d version)
+#define BOARD_MELZI_CREALITY 1505 // Melzi Creality3D board (for CR-10 etc)
+#define BOARD_MELZI_MALYAN 1506 // Melzi Malyan M150 board
+#define BOARD_MELZI_TRONXY 1507 // Tronxy X5S
+#define BOARD_STB_11 1508 // STB V1.1
+#define BOARD_AZTEEG_X1 1509 // Azteeg X1
+#define BOARD_ANET_10 1510 // Anet 1.0 (Melzi clone)
+#define BOARD_ZMIB_V2 1511 // ZoneStar ZMIB V2
//
// Other ATmega644P, ATmega644, ATmega1284P
@@ -276,28 +281,40 @@
#define BOARD_STM32F103RE 4000 // STM32F103RE Libmaple-based STM32F1 controller
#define BOARD_MALYAN_M200 4001 // STM32C8T6 Libmaple-based STM32F1 controller
-#define BOARD_STM3R_MINI 4002 // STM32F103RE Libmaple-based STM32F1 controller
-#define BOARD_GTM32_PRO_VB 4003 // STM32F103VET6 controller
-#define BOARD_MORPHEUS 4004 // STM32F103C8 / STM32F103CB Libmaple-based STM32F1 controller
-#define BOARD_CHITU3D 4005 // Chitu3D (STM32F103RET6)
-#define BOARD_MKS_ROBIN 4006 // MKS Robin (STM32F103ZET6)
-#define BOARD_MKS_ROBIN_MINI 4007 // MKS Robin Mini (STM32F103VET6)
-#define BOARD_MKS_ROBIN_NANO 4008 // MKS Robin Nano (STM32F103VET6)
-#define BOARD_MKS_ROBIN_LITE 4009 // MKS Robin Lite/Lite2 (STM32F103RCT6)
-#define BOARD_MKS_ROBIN_LITE3 4010 // MKS Robin Lite3 (STM32F103RCT6)
-#define BOARD_MKS_ROBIN_PRO 4011 // MKS Robin Pro (STM32F103ZET6)
-#define BOARD_BTT_SKR_MINI_V1_1 4012 // BigTreeTech SKR Mini v1.1 (STM32F103RC)
-#define BOARD_BTT_SKR_MINI_E3_V1_0 4013 // BigTreeTech SKR Mini E3 (STM32F103RC)
-#define BOARD_BTT_SKR_MINI_E3_V1_2 4014 // BigTreeTech SKR Mini E3 V1.2 (STM32F103RC)
-#define BOARD_BTT_SKR_E3_DIP 4015 // BigTreeTech SKR E3 DIP V1.0 (STM32F103RC / STM32F103RE)
-#define BOARD_JGAURORA_A5S_A1 4016 // JGAurora A5S A1 (STM32F103ZET6)
-#define BOARD_FYSETC_AIO_II 4017 // FYSETC AIO_II
-#define BOARD_FYSETC_CHEETAH 4018 // FYSETC Cheetah
-#define BOARD_FYSETC_CHEETAH_V12 4019 // FYSETC Cheetah V1.2
-#define BOARD_LONGER3D_LK 4020 // Alfawise U20/U20+/U30 (Longer3D LK1/2) / STM32F103VET6
-#define BOARD_GTM32_MINI 4021 // STM32F103VET6 controller
-#define BOARD_GTM32_MINI_A30 4022 // STM32F103VET6 controller
-#define BOARD_GTM32_REV_B 4023 // STM32F103VET6 controller
+#define BOARD_MALYAN_M200_V2 4002 // STM32F070RB Libmaple-based STM32F0 controller
+#define BOARD_STM3R_MINI 4003 // STM32F103RE Libmaple-based STM32F1 controller
+#define BOARD_GTM32_PRO_VB 4004 // STM32F103VET6 controller
+#define BOARD_MORPHEUS 4005 // STM32F103C8 / STM32F103CB Libmaple-based STM32F1 controller
+#define BOARD_CHITU3D 4006 // Chitu3D (STM32F103RET6)
+#define BOARD_MKS_ROBIN 4007 // MKS Robin (STM32F103ZET6)
+#define BOARD_MKS_ROBIN_MINI 4008 // MKS Robin Mini (STM32F103VET6)
+#define BOARD_MKS_ROBIN_NANO 4009 // MKS Robin Nano (STM32F103VET6)
+#define BOARD_MKS_ROBIN_NANO_V2 4010 // MKS Robin Nano V2 (STM32F103VET6)
+#define BOARD_MKS_ROBIN_LITE 4011 // MKS Robin Lite/Lite2 (STM32F103RCT6)
+#define BOARD_MKS_ROBIN_LITE3 4012 // MKS Robin Lite3 (STM32F103RCT6)
+#define BOARD_MKS_ROBIN_PRO 4013 // MKS Robin Pro (STM32F103ZET6)
+#define BOARD_BTT_SKR_MINI_V1_1 4014 // BigTreeTech SKR Mini v1.1 (STM32F103RC)
+#define BOARD_BTT_SKR_MINI_E3_V1_0 4015 // BigTreeTech SKR Mini E3 (STM32F103RC)
+#define BOARD_BTT_SKR_MINI_E3_V1_2 4016 // BigTreeTech SKR Mini E3 V1.2 (STM32F103RC)
+#define BOARD_BTT_SKR_MINI_E3_V2_0 4017 // BigTreeTech SKR Mini E3 V2.0 (STM32F103RC)
+#define BOARD_BTT_SKR_E3_DIP 4018 // BigTreeTech SKR E3 DIP V1.0 (STM32F103RC / STM32F103RE)
+#define BOARD_JGAURORA_A5S_A1 4019 // JGAurora A5S A1 (STM32F103ZET6)
+#define BOARD_FYSETC_AIO_II 4020 // FYSETC AIO_II
+#define BOARD_FYSETC_CHEETAH 4021 // FYSETC Cheetah
+#define BOARD_FYSETC_CHEETAH_V12 4022 // FYSETC Cheetah V1.2
+#define BOARD_LONGER3D_LK 4023 // Alfawise U20/U20+/U30 (Longer3D LK1/2) / STM32F103VET6
+#define BOARD_GTM32_MINI 4024 // STM32F103VET6 controller
+#define BOARD_GTM32_MINI_A30 4025 // STM32F103VET6 controller
+#define BOARD_GTM32_REV_B 4026 // STM32F103VET6 controller
+#define BOARD_MKS_ROBIN_E3D 4027 // MKS Robin E3D (STM32F103RCT6)
+#define BOARD_MKS_ROBIN_E3 4028 // MKS Robin E3 (STM32F103RCT6)
+#define BOARD_MALYAN_M300 4029 // STM32F070-based delta
+#define BOARD_CCROBOT_MEEB_3DP 4030 // ccrobot-online.com MEEB_3DP (STM32F103RC)
+#define BOARD_CHITU3D_V5 4031 // Chitu3D TronXY X5SA V5 Board
+#define BOARD_CHITU3D_V6 4032 // Chitu3D TronXY X5SA V5 Board
+#define BOARD_CREALITY_V4 4033 // Creality v4.x (STM32F103RE)
+#define BOARD_CREALITY_V427 4034 // Creality v4.2.7 (STM32F103RE)
+#define BOARD_TRIGORILLA_PRO 4035 // Trigorilla Pro (STM32F103ZET6)
//
// ARM Cortex-M4F
@@ -313,20 +330,24 @@
#define BOARD_BEAST 4200 // STM32F4xxVxT6 Libmaple-based STM32F4 controller
#define BOARD_GENERIC_STM32F4 4201 // STM32 STM32GENERIC-based STM32F4 controller
#define BOARD_ARMED 4202 // Arm'ed STM32F4-based controller
-#define BOARD_RUMBA32_AUS3D 4203 // RUMBA32 STM32F446VET6 based controller from Aus3D
-#define BOARD_RUMBA32_MKS 4204 // RUMBA32 STM32F446VET6 based controller from Makerbase
-#define BOARD_BLACK_STM32F407VE 4205 // BLACK_STM32F407VE
-#define BOARD_BLACK_STM32F407ZE 4206 // BLACK_STM32F407ZE
-#define BOARD_STEVAL_3DP001V1 4207 // STEVAL-3DP001V1 3D PRINTER BOARD
-#define BOARD_BTT_SKR_PRO_V1_1 4208 // BigTreeTech SKR Pro v1.1 (STM32F407ZG)
-#define BOARD_BTT_BTT002_V1_0 4209 // BigTreeTech BTT002 v1.0 (STM32F407VE)
-#define BOARD_BTT_GTR_V1_0 4210 // BigTreeTech GTR v1.0 (STM32F407IGT)
-#define BOARD_LERDGE_K 4211 // Lerdge K (STM32F407ZG)
-#define BOARD_LERDGE_X 4212 // Lerdge X (STM32F407VE)
-#define BOARD_VAKE403D 4213 // VAkE 403D (STM32F446VET6)
-#define BOARD_FYSETC_S6 4214 // FYSETC S6 board
-#define BOARD_FLYF407ZG 4215 // FLYF407ZG board (STM32F407ZG)
-#define BOARD_MKS_ROBIN2 4216 // MKS_ROBIN2 (STM32F407ZE)
+#define BOARD_RUMBA32_V1_0 4203 // RUMBA32 STM32F446VET6 based controller from Aus3D
+#define BOARD_RUMBA32_V1_1 4204 // RUMBA32 STM32F446VET6 based controller from Aus3D
+#define BOARD_RUMBA32_MKS 4205 // RUMBA32 STM32F446VET6 based controller from Makerbase
+#define BOARD_BLACK_STM32F407VE 4206 // BLACK_STM32F407VE
+#define BOARD_BLACK_STM32F407ZE 4207 // BLACK_STM32F407ZE
+#define BOARD_STEVAL_3DP001V1 4208 // STEVAL-3DP001V1 3D PRINTER BOARD
+#define BOARD_BTT_SKR_PRO_V1_1 4209 // BigTreeTech SKR Pro v1.1 (STM32F407ZG)
+#define BOARD_BTT_SKR_PRO_V1_2 4210 // BigTreeTech SKR Pro v1.2 (STM32F407ZG)
+#define BOARD_BTT_BTT002_V1_0 4211 // BigTreeTech BTT002 v1.0 (STM32F407VG)
+#define BOARD_BTT_GTR_V1_0 4212 // BigTreeTech GTR v1.0 (STM32F407IGT)
+#define BOARD_LERDGE_K 4213 // Lerdge K (STM32F407ZG)
+#define BOARD_LERDGE_S 4214 // Lerdge S (STM32F407VE)
+#define BOARD_LERDGE_X 4215 // Lerdge X (STM32F407VE)
+#define BOARD_VAKE403D 4216 // VAkE 403D (STM32F446VET6)
+#define BOARD_FYSETC_S6 4217 // FYSETC S6 board
+#define BOARD_FYSETC_S6_V2_0 4218 // FYSETC S6 v2.0 board
+#define BOARD_FLYF407ZG 4219 // FLYF407ZG board (STM32F407ZG)
+#define BOARD_MKS_ROBIN2 4220 // MKS_ROBIN2 (STM32F407ZE)
//
// ARM Cortex M7
@@ -348,6 +369,11 @@
//
#define BOARD_AGCM4_RAMPS_144 6100 // RAMPS 1.4.4
+//
+// Custom board
+//
+#define BOARD_CUSTOM 9998 // Custom pins definition for development and/or rare boards
+
//
// Simulations
//
@@ -357,4 +383,4 @@
#define _MB_1(B) (defined(BOARD_##B) && MOTHERBOARD==BOARD_##B)
#define MB(V...) DO(MB,||,V)
-#define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY)
+#define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY, MELZI_V2)
diff --git a/Marlin/src/core/debug_out.h b/Marlin/src/core/debug_out.h
index 4b2cdf9f77..6ae1b9d8bb 100644
--- a/Marlin/src/core/debug_out.h
+++ b/Marlin/src/core/debug_out.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -26,11 +26,13 @@
// (or not) in a given .cpp file
//
+#undef DEBUG_SECTION
#undef DEBUG_PRINT_P
#undef DEBUG_ECHO_START
#undef DEBUG_ERROR_START
#undef DEBUG_CHAR
#undef DEBUG_ECHO
+#undef DEBUG_DECIMAL
#undef DEBUG_ECHO_F
#undef DEBUG_ECHOLN
#undef DEBUG_ECHOPGM
@@ -46,16 +48,23 @@
#undef DEBUG_ECHO_MSG
#undef DEBUG_ERROR_MSG
#undef DEBUG_EOL
+#undef DEBUG_FLUSH
#undef DEBUG_POS
#undef DEBUG_XYZ
#undef DEBUG_DELAY
+#undef DEBUG_SYNCHRONIZE
#if DEBUG_OUT
+
+ #include "debug_section.h"
+ #define DEBUG_SECTION(N,S,D) SectionLog N(PSTR(S),D)
+
#define DEBUG_PRINT_P(P) serialprintPGM(P)
#define DEBUG_ECHO_START SERIAL_ECHO_START
#define DEBUG_ERROR_START SERIAL_ERROR_START
#define DEBUG_CHAR SERIAL_CHAR
#define DEBUG_ECHO SERIAL_ECHO
+ #define DEBUG_DECIMAL SERIAL_DECIMAL
#define DEBUG_ECHO_F SERIAL_ECHO_F
#define DEBUG_ECHOLN SERIAL_ECHOLN
#define DEBUG_ECHOPGM SERIAL_ECHOPGM
@@ -71,15 +80,21 @@
#define DEBUG_ECHO_MSG SERIAL_ECHO_MSG
#define DEBUG_ERROR_MSG SERIAL_ERROR_MSG
#define DEBUG_EOL SERIAL_EOL
+ #define DEBUG_FLUSH SERIAL_FLUSH
#define DEBUG_POS SERIAL_POS
#define DEBUG_XYZ SERIAL_XYZ
#define DEBUG_DELAY(ms) serial_delay(ms)
+ #define DEBUG_SYNCHRONIZE() planner.synchronize()
+
#else
+
+ #define DEBUG_SECTION(...) NOOP
#define DEBUG_PRINT_P(P) NOOP
#define DEBUG_ECHO_START() NOOP
#define DEBUG_ERROR_START() NOOP
#define DEBUG_CHAR(...) NOOP
#define DEBUG_ECHO(...) NOOP
+ #define DEBUG_DECIMAL(...) NOOP
#define DEBUG_ECHO_F(...) NOOP
#define DEBUG_ECHOLN(...) NOOP
#define DEBUG_ECHOPGM(...) NOOP
@@ -95,9 +110,12 @@
#define DEBUG_ECHO_MSG(...) NOOP
#define DEBUG_ERROR_MSG(...) NOOP
#define DEBUG_EOL() NOOP
+ #define DEBUG_FLUSH() NOOP
#define DEBUG_POS(...) NOOP
#define DEBUG_XYZ(...) NOOP
#define DEBUG_DELAY(...) NOOP
+ #define DEBUG_SYNCHRONIZE() NOOP
+
#endif
#undef DEBUG_OUT
diff --git a/Marlin/src/core/debug_section.h b/Marlin/src/core/debug_section.h
new file mode 100644
index 0000000000..7f39bc7424
--- /dev/null
+++ b/Marlin/src/core/debug_section.h
@@ -0,0 +1,49 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "serial.h"
+#include "../module/motion.h"
+
+class SectionLog {
+public:
+ SectionLog(PGM_P const msg=nullptr, bool inbug=true) {
+ the_msg = msg;
+ if ((debug = inbug)) echo_msg(PSTR(">>>"));
+ }
+
+ ~SectionLog() { if (debug) echo_msg(PSTR("<<<")); }
+
+private:
+ PGM_P the_msg;
+ bool debug;
+
+ void echo_msg(PGM_P const pre) {
+ serialprintPGM(pre);
+ if (the_msg) {
+ SERIAL_CHAR(' ');
+ serialprintPGM(the_msg);
+ }
+ SERIAL_CHAR(' ');
+ print_xyz(current_position);
+ }
+};
diff --git a/Marlin/src/core/drivers.h b/Marlin/src/core/drivers.h
index 833899bdcb..3a0e620923 100644
--- a/Marlin/src/core/drivers.h
+++ b/Marlin/src/core/drivers.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -86,6 +86,10 @@
|| AXIS_DRIVER_TYPE_X2(T) || AXIS_DRIVER_TYPE_Y2(T) || AXIS_DRIVER_TYPE_Z2(T) \
|| AXIS_DRIVER_TYPE_Z3(T) || AXIS_DRIVER_TYPE_Z4(T) || HAS_E_DRIVER(T) )
+//
+// Trinamic Stepper Drivers
+//
+
// Test for supported TMC drivers that require advanced configuration
// Does not match standalone configurations
#if ( HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC2160) \
@@ -127,6 +131,7 @@
#define AXIS_HAS_RXTX AXIS_HAS_UART
+#define AXIS_HAS_HW_SERIAL(A) ( AXIS_HAS_UART(A) && defined(A##_HARDWARE_SERIAL) )
#define AXIS_HAS_SW_SERIAL(A) ( AXIS_HAS_UART(A) && !defined(A##_HARDWARE_SERIAL) )
#define AXIS_HAS_STALLGUARD(A) ( AXIS_DRIVER_TYPE(A,TMC2130) || AXIS_DRIVER_TYPE(A,TMC2160) \
@@ -171,17 +176,16 @@
#define HAS_TMC_SPI 1
#endif
-// Defines that can't be evaluated now
-#define HAS_TMC_SW_SERIAL ANY_AXIS_HAS(SW_SERIAL)
+//
+// TMC26XX Stepper Drivers
+//
+#if HAS_DRIVER(TMC26X)
+ #define HAS_TMC26X 1
+#endif
//
-// Stretching 'drivers.h' to include LPC/SAMD51 SD options
+// L64XX Stepper Drivers
//
-#define _SDCARD_LCD 1
-#define _SDCARD_ONBOARD 2
-#define _SDCARD_CUSTOM_CABLE 3
-#define _SDCARD_ID(V) _CAT(_SDCARD_, V)
-#define SD_CONNECTION_IS(V) (_SDCARD_ID(SDCARD_CONNECTION) == _SDCARD_ID(V))
#if HAS_DRIVER(L6470) || HAS_DRIVER(L6474) || HAS_DRIVER(L6480) || HAS_DRIVER(POWERSTEP01)
#define HAS_L64XX 1
diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h
index f58ace7709..f0ddbdd6d0 100644
--- a/Marlin/src/core/language.h
+++ b/Marlin/src/core/language.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -39,7 +39,7 @@
//
// ==> ALWAYS TRY TO COMPILE MARLIN WITH/WITHOUT "ULTIPANEL" / "ULTRA_LCD" / "SDSUPPORT" #define IN "Configuration.h"
// ==> ALSO TRY ALL AVAILABLE LANGUAGE OPTIONS
-// See also http://marlinfw.org/docs/development/lcd_language.html
+// See also https://marlinfw.org/docs/development/lcd_language.html
// Languages
// an Aragonese
@@ -57,6 +57,7 @@
// fr French
// gl Galician
// hr Croatian
+// hu Hungarian
// it Italian
// jp_kana Japanese
// ko_KR Korean (South Korea)
@@ -64,6 +65,7 @@
// pl Polish
// pt Portuguese
// pt_br Portuguese (Brazilian)
+// ro Romanian
// ru Russian
// sk Slovak
// tr Turkish
@@ -80,18 +82,16 @@
#ifdef CUSTOM_MACHINE_NAME
#undef MACHINE_NAME
#define MACHINE_NAME CUSTOM_MACHINE_NAME
-#else
- #ifdef DEFAULT_MACHINE_NAME
- #undef MACHINE_NAME
- #define MACHINE_NAME DEFAULT_MACHINE_NAME
- #endif
+#elif defined(DEFAULT_MACHINE_NAME)
+ #undef MACHINE_NAME
+ #define MACHINE_NAME DEFAULT_MACHINE_NAME
#endif
#ifndef MACHINE_UUID
#define MACHINE_UUID DEFAULT_MACHINE_UUID
#endif
-#define MARLIN_WEBSITE_URL "http://marlinfw.org"
+#define MARLIN_WEBSITE_URL "https://marlinfw.org"
//#if !defined(STRING_SPLASH_LINE3) && defined(WEBSITE_URL)
// #define STRING_SPLASH_LINE3 WEBSITE_URL
@@ -126,7 +126,7 @@
#define STR_INVALID_E_STEPPER "Invalid E stepper"
#define STR_E_STEPPER_NOT_SPECIFIED "E stepper not specified"
#define STR_INVALID_SOLENOID "Invalid solenoid"
-#define STR_M115_REPORT "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID
+#define STR_M115_REPORT "FIRMWARE_NAME:Marlin " DETAILED_BUILD_VERSION " (" __DATE__ " " __TIME__ ") SOURCE_CODE_URL:" SOURCE_CODE_URL " PROTOCOL_VERSION:" PROTOCOL_VERSION " MACHINE_TYPE:" MACHINE_NAME " EXTRUDER_COUNT:" STRINGIFY(EXTRUDERS) " UUID:" MACHINE_UUID
#define STR_COUNT_X " Count X:"
#define STR_COUNT_A " Count A:"
#define STR_WATCHDOG_FIRED "Watchdog timeout. Reset required."
@@ -163,7 +163,7 @@
#define STR_ERR_MATERIAL_INDEX "M145 S out of range (0-1)"
#define STR_ERR_M421_PARAMETERS "M421 incorrect parameter usage"
#define STR_ERR_BAD_PLANE_MODE "G5 requires XY plane mode"
-#define STR_ERR_MESH_XY "Mesh point cannot be resolved"
+#define STR_ERR_MESH_XY "Mesh point out of range"
#define STR_ERR_ARC_ARGS "G2/G3 bad parameters"
#define STR_ERR_PROTECTED_PIN "Protected Pin"
#define STR_ERR_M420_FAILED "Failed to enable Bed Leveling"
@@ -185,7 +185,7 @@
#define STR_INVALID_POS_SLOT "Invalid slot. Total: "
#define STR_SD_CANT_OPEN_SUBDIR "Cannot open subdir "
-#define STR_SD_INIT_FAIL "SD init fail"
+#define STR_SD_INIT_FAIL "No SD card"
#define STR_SD_VOL_INIT_FAIL "volume.init failed"
#define STR_SD_OPENROOT_FAIL "openRoot failed"
#define STR_SD_CARD_OK "SD card ok"
@@ -205,7 +205,6 @@
#define STR_ERR_COLD_EXTRUDE_STOP " cold extrusion prevented"
#define STR_ERR_LONG_EXTRUDE_STOP " too long extrusion prevented"
#define STR_ERR_HOTEND_TOO_COLD "Hotend too cold"
-#define STR_ERR_Z_HOMING_SER "Home XY first"
#define STR_ERR_EEPROM_WRITE "Error writing to EEPROM!"
#define STR_FILAMENT_CHANGE_HEAT_LCD "Press button to heat nozzle"
@@ -221,12 +220,10 @@
#define STR_KILL_BUTTON "!! KILL caused by KILL button/pin"
// temperature.cpp strings
-#define STR_PID_AUTOTUNE_PREFIX "PID Autotune"
-#define STR_PID_AUTOTUNE_START STR_PID_AUTOTUNE_PREFIX " start"
-#define STR_PID_AUTOTUNE_FAILED STR_PID_AUTOTUNE_PREFIX " failed!"
-#define STR_PID_BAD_EXTRUDER_NUM STR_PID_AUTOTUNE_FAILED " Bad extruder number"
-#define STR_PID_TEMP_TOO_HIGH STR_PID_AUTOTUNE_FAILED " Temperature too high"
-#define STR_PID_TIMEOUT STR_PID_AUTOTUNE_FAILED " timeout"
+#define STR_PID_AUTOTUNE_START "PID Autotune start"
+#define STR_PID_BAD_EXTRUDER_NUM "PID Autotune failed! Bad extruder number"
+#define STR_PID_TEMP_TOO_HIGH "PID Autotune failed! Temperature too high"
+#define STR_PID_TIMEOUT "PID Autotune failed! timeout"
#define STR_BIAS " bias: "
#define STR_D_COLON " d: "
#define STR_T_MIN " min: "
@@ -237,7 +234,7 @@
#define STR_KP " Kp: "
#define STR_KI " Ki: "
#define STR_KD " Kd: "
-#define STR_PID_AUTOTUNE_FINISHED STR_PID_AUTOTUNE_PREFIX " finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
+#define STR_PID_AUTOTUNE_FINISHED "PID Autotune finished! Put the last Kp, Ki and Kd constants from below into Configuration.h"
#define STR_PID_DEBUG " PID_DEBUG "
#define STR_PID_DEBUG_INPUT ": Input "
#define STR_PID_DEBUG_OUTPUT " Output "
@@ -269,6 +266,13 @@
#define STR_DEBUG_COMMUNICATION "COMMUNICATION"
#define STR_DEBUG_LEVELING "LEVELING"
+#define STR_PRINTER_LOCKED "Printer locked! (Unlock with M511 or LCD)"
+#define STR_WRONG_PASSWORD "Incorrect Password"
+#define STR_PASSWORD_TOO_LONG "Password too long"
+#define STR_PASSWORD_REMOVED "Password removed"
+#define STR_REMINDER_SAVE_SETTINGS "Remember to save!"
+#define STR_PASSWORD_SET "Password is "
+
// LCD Menu Messages
#define LANGUAGE_DATA_INCL_(M) STRINGIFY_(fontdata/langdata_##M.h)
@@ -349,7 +353,7 @@
*
*/
#if ENABLED(NUMBER_TOOLS_FROM_0)
- #define LCD_FIRST_TOOL '0'
+ #define LCD_FIRST_TOOL 0
#define LCD_STR_N0 "0"
#define LCD_STR_N1 "1"
#define LCD_STR_N2 "2"
@@ -359,7 +363,7 @@
#define LCD_STR_N6 "6"
#define LCD_STR_N7 "7"
#else
- #define LCD_FIRST_TOOL '1'
+ #define LCD_FIRST_TOOL 1
#define LCD_STR_N0 "1"
#define LCD_STR_N1 "2"
#define LCD_STR_N2 "3"
diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h
index 899baf7359..5fc1081019 100644
--- a/Marlin/src/core/macros.h
+++ b/Marlin/src/core/macros.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -76,13 +76,6 @@
// Nanoseconds per cycle
#define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
-// Macros to make sprintf_P read from PROGMEM (AVR extension)
-#ifdef __AVR__
- #define S_FMT "%S"
-#else
- #define S_FMT "%s"
-#endif
-
// Macros to make a string from a macro
#define STRINGIFY_(M) #M
#define STRINGIFY(M) STRINGIFY_(M)
@@ -104,12 +97,15 @@
#define CBI(A,B) (A &= ~(1 << (B)))
#endif
+#define TBI(N,B) (N ^= _BV(B))
+
#define _BV32(b) (1UL << (b))
#define TEST32(n,b) !!((n)&_BV32(b))
#define SBI32(n,b) (n |= _BV32(b))
#define CBI32(n,b) (n &= ~_BV32(b))
+#define TBI32(N,B) (N ^= _BV32(B))
-#define cu(x) ((x)*(x)*(x))
+#define cu(x) ({__typeof__(x) _x = (x); (_x)*(_x)*(_x);})
#define RADIANS(d) ((d)*float(M_PI)/180.0f)
#define DEGREES(r) ((r)*180.0f/float(M_PI))
#define HYPOT2(x,y) (sq(x)+sq(y))
@@ -117,7 +113,7 @@
#define CIRCLE_AREA(R) (float(M_PI) * sq(float(R)))
#define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R))
-#define SIGN(a) ((a>0)-(a<0))
+#define SIGN(a) ({__typeof__(a) _a = (a); (_a>0)-(_a<0);})
#define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
// Macros to constrain values
@@ -137,8 +133,6 @@
#else
- // Using GCC extensions, but Travis GCC version does not like it and gives
- // "error: statement-expressions are not allowed outside functions nor in template-argument lists"
#define NOLESS(v, n) \
do{ \
__typeof__(n) _n = (n); \
@@ -276,7 +270,7 @@
#define NEAR(x,y) NEAR_ZERO((x)-(y))
#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0 : (1 / float(x)))
-#define FIXFLOAT(f) (f + (f < 0 ? -0.00005f : 0.00005f))
+#define FIXFLOAT(f) ({__typeof__(f) _f = (f); _f + (_f < 0 ? -0.0000005f : 0.0000005f);})
//
// Maths macros that can be overridden by HAL
@@ -292,12 +286,6 @@
#define FMOD(x, y) fmodf(x, y)
#define HYPOT(x,y) SQRT(HYPOT2(x,y))
-#ifdef TARGET_LPC1768
- #define I2C_ADDRESS(A) ((A) << 1)
-#else
- #define I2C_ADDRESS(A) A
-#endif
-
// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
@@ -354,15 +342,22 @@
#endif
// Macros for adding
-#define INC_0 1
-#define INC_1 2
-#define INC_2 3
-#define INC_3 4
-#define INC_4 5
-#define INC_5 6
-#define INC_6 7
-#define INC_7 8
-#define INC_8 9
+#define INC_0 1
+#define INC_1 2
+#define INC_2 3
+#define INC_3 4
+#define INC_4 5
+#define INC_5 6
+#define INC_6 7
+#define INC_7 8
+#define INC_8 9
+#define INC_9 10
+#define INC_10 11
+#define INC_11 12
+#define INC_12 13
+#define INC_13 14
+#define INC_14 15
+#define INC_15 16
#define INCREMENT_(n) INC_##n
#define INCREMENT(n) INCREMENT_(n)
@@ -379,16 +374,22 @@
#define ADD10(N) ADD5(ADD5(N))
// Macros for subtracting
-#define DEC_0 0
-#define DEC_1 0
-#define DEC_2 1
-#define DEC_3 2
-#define DEC_4 3
-#define DEC_5 4
-#define DEC_6 5
-#define DEC_7 6
-#define DEC_8 7
-#define DEC_9 8
+#define DEC_0 0
+#define DEC_1 0
+#define DEC_2 1
+#define DEC_3 2
+#define DEC_4 3
+#define DEC_5 4
+#define DEC_6 5
+#define DEC_7 6
+#define DEC_8 7
+#define DEC_9 8
+#define DEC_10 9
+#define DEC_11 10
+#define DEC_12 11
+#define DEC_13 12
+#define DEC_14 13
+#define DEC_15 14
#define DECREMENT_(n) DEC_##n
#define DECREMENT(n) DECREMENT_(n)
@@ -495,3 +496,14 @@
#define RREPEAT(N,OP) RREPEAT_S(0,N,OP)
#define RREPEAT2_S(S,N,OP,V...) EVAL1024(_RREPEAT2(S,SUB##S(N),OP,V))
#define RREPEAT2(N,OP,V...) RREPEAT2_S(0,N,OP,V)
+
+// See https://github.com/swansontec/map-macro
+#define MAP_OUT
+#define MAP_END(...)
+#define MAP_GET_END() 0, MAP_END
+#define MAP_NEXT0(test, next, ...) next MAP_OUT
+#define MAP_NEXT1(test, next) MAP_NEXT0 (test, next, 0)
+#define MAP_NEXT(test, next) MAP_NEXT1 (MAP_GET_END test, next)
+#define MAP0(f, x, peek, ...) f(x) MAP_NEXT (peek, MAP1) (f, peek, __VA_ARGS__)
+#define MAP1(f, x, peek, ...) f(x) MAP_NEXT (peek, MAP0) (f, peek, __VA_ARGS__)
+#define MAP(f, ...) EVAL512 (MAP1 (f, __VA_ARGS__, (), 0))
diff --git a/Marlin/src/core/millis_t.h b/Marlin/src/core/millis_t.h
index 39ea17b9f0..95bc40e1ec 100644
--- a/Marlin/src/core/millis_t.h
+++ b/Marlin/src/core/millis_t.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -25,5 +25,9 @@
typedef uint32_t millis_t;
+#define SEC_TO_MS(N) millis_t((N)*1000UL)
+#define MIN_TO_MS(N) SEC_TO_MS((N)*60UL)
+#define MS_TO_SEC(N) millis_t((N)/1000UL)
+
#define PENDING(NOW,SOON) ((int32_t)(NOW-(SOON))<0)
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
diff --git a/Marlin/src/core/multi_language.cpp b/Marlin/src/core/multi_language.cpp
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/Marlin/src/core/multi_language.h b/Marlin/src/core/multi_language.h
index 98020b1e8d..5852c439a8 100644
--- a/Marlin/src/core/multi_language.h
+++ b/Marlin/src/core/multi_language.h
@@ -16,13 +16,13 @@
* GNU General Public License for more details. *
* *
* To view a copy of the GNU General Public License, go to the following *
- * location: . *
+ * location: . *
****************************************************************************/
#pragma once
typedef const char Language_Str[];
-#if defined(LCD_LANGUAGE_5)
+#ifdef LCD_LANGUAGE_5
#define NUM_LANGUAGES 5
#elif defined(LCD_LANGUAGE_4)
#define NUM_LANGUAGES 4
@@ -76,4 +76,8 @@ typedef const char Language_Str[];
#endif
#define GET_TEXT_F(MSG) (const __FlashStringHelper*)GET_TEXT(MSG)
-#define MSG_CONCAT(A,B) pgm_p_pair_t(GET_TEXT(A),GET_TEXT(B))
+#define GET_LANGUAGE_NAME(INDEX) GET_LANG(LCD_LANGUAGE_##INDEX)::LANGUAGE
+
+#define MSG_1_LINE(A) A "\0" "\0"
+#define MSG_2_LINE(A,B) A "\0" B "\0"
+#define MSG_3_LINE(A,B,C) A "\0" B "\0" C
diff --git a/Marlin/src/core/serial.cpp b/Marlin/src/core/serial.cpp
index 304aa09a8a..0d22f7bfc0 100644
--- a/Marlin/src/core/serial.cpp
+++ b/Marlin/src/core/serial.cpp
@@ -16,19 +16,19 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "serial.h"
-#include "language.h"
+#include "../inc/MarlinConfig.h"
uint8_t marlin_debug_flags = MARLIN_DEBUG_NONE;
-static const char errormagic[] PROGMEM = "Error:";
-static const char echomagic[] PROGMEM = "echo:";
+static PGMSTR(errormagic, "Error:");
+static PGMSTR(echomagic, "echo:");
-#if NUM_SERIAL > 1
+#if HAS_MULTI_SERIAL
int8_t serial_port_index = 0;
#endif
@@ -42,8 +42,8 @@ void serial_echopair_PGM(PGM_P const s_P, const char *v) { serialprintPGM(s_P)
void serial_echopair_PGM(PGM_P const s_P, char v) { serialprintPGM(s_P); SERIAL_CHAR(v); }
void serial_echopair_PGM(PGM_P const s_P, int v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
void serial_echopair_PGM(PGM_P const s_P, long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
-void serial_echopair_PGM(PGM_P const s_P, float v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
-void serial_echopair_PGM(PGM_P const s_P, double v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
+void serial_echopair_PGM(PGM_P const s_P, float v) { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
+void serial_echopair_PGM(PGM_P const s_P, double v) { serialprintPGM(s_P); SERIAL_DECIMAL(v); }
void serial_echopair_PGM(PGM_P const s_P, unsigned int v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
void serial_echopair_PGM(PGM_P const s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); }
@@ -68,7 +68,7 @@ void print_bin(uint16_t val) {
extern const char SP_X_STR[], SP_Y_STR[], SP_Z_STR[];
void print_xyz(const float &x, const float &y, const float &z, PGM_P const prefix/*=nullptr*/, PGM_P const suffix/*=nullptr*/) {
- serialprintPGM(prefix);
+ if (prefix) serialprintPGM(prefix);
SERIAL_ECHOPAIR_P(SP_X_STR, x, SP_Y_STR, y, SP_Z_STR, z);
if (suffix) serialprintPGM(suffix); else SERIAL_EOL();
}
diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h
index 812ff5471f..fc830736a5 100644
--- a/Marlin/src/core/serial.h
+++ b/Marlin/src/core/serial.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -47,14 +47,20 @@ extern uint8_t marlin_debug_flags;
#define DEBUGGING(F) (marlin_debug_flags & (MARLIN_DEBUG_## F))
#define SERIAL_BOTH 0x7F
-#if NUM_SERIAL > 1
+#if HAS_MULTI_SERIAL
extern int8_t serial_port_index;
#define _PORT_REDIRECT(n,p) REMEMBER(n,serial_port_index,p)
#define _PORT_RESTORE(n) RESTORE(n)
- #define SERIAL_OUT(WHAT, V...) do{ \
- if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
- if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
- }while(0)
+
+ #ifdef SERIAL_CATCHALL
+ #define SERIAL_OUT(WHAT, V...) (void)CAT(MYSERIAL,SERIAL_CATCHALL).WHAT(V)
+ #else
+ #define SERIAL_OUT(WHAT, V...) do{ \
+ if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
+ if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
+ }while(0)
+ #endif
+
#define SERIAL_ASSERT(P) if(serial_port_index!=(P)){ debugger(); }
#else
#define _PORT_REDIRECT(n,p) NOOP
@@ -184,7 +190,13 @@ extern uint8_t marlin_debug_flags;
#define _SELP_21(a,b,V...) do{ _SEP_2(a,b); _SELP_19(V); }while(0)
#define _SELP_22(a,b,V...) do{ _SEP_2(a,b); _SELP_20(V); }while(0)
#define _SELP_23(a,b,V...) do{ _SEP_2(a,b); _SELP_21(V); }while(0)
-#define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0) // Eat two args, pass the rest up
+#define _SELP_24(a,b,V...) do{ _SEP_2(a,b); _SELP_22(V); }while(0)
+#define _SELP_25(a,b,V...) do{ _SEP_2(a,b); _SELP_23(V); }while(0)
+#define _SELP_26(a,b,V...) do{ _SEP_2(a,b); _SELP_24(V); }while(0)
+#define _SELP_27(a,b,V...) do{ _SEP_2(a,b); _SELP_25(V); }while(0)
+#define _SELP_28(a,b,V...) do{ _SEP_2(a,b); _SELP_26(V); }while(0)
+#define _SELP_29(a,b,V...) do{ _SEP_2(a,b); _SELP_27(V); }while(0)
+#define _SELP_30(a,b,V...) do{ _SEP_2(a,b); _SELP_28(V); }while(0) // Eat two args, pass the rest up
#define SERIAL_ECHOLNPAIR(V...) _SELP_N(NUM_ARGS(V),V)
@@ -214,7 +226,13 @@ extern uint8_t marlin_debug_flags;
#define _SELP_21_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_19_P(V); }while(0)
#define _SELP_22_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_20_P(V); }while(0)
#define _SELP_23_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_21_P(V); }while(0)
-#define _SELP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_22_P(V); }while(0) // Eat two args, pass the rest up
+#define _SELP_24_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_22_P(V); }while(0)
+#define _SELP_25_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_23_P(V); }while(0)
+#define _SELP_26_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_24_P(V); }while(0)
+#define _SELP_27_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_25_P(V); }while(0)
+#define _SELP_28_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_26_P(V); }while(0)
+#define _SELP_29_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_27_P(V); }while(0)
+#define _SELP_30_P(a,b,V...) do{ _SEP_2_P(a,b); _SELP_28_P(V); }while(0) // Eat two args, pass the rest up
#define SERIAL_ECHOLNPAIR_P(V...) _SELP_N_P(NUM_ARGS(V),V)
@@ -245,10 +263,11 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_ECHOLIST(pre,V...) do{ SERIAL_ECHOPGM(pre); _SLST_N(NUM_ARGS(V),V); }while(0)
#define SERIAL_ECHOLIST_N(N,V...) _SLST_N(N,LIST_N(N,V))
-#define SERIAL_ECHO_P(P) (serialprintPGM(P))
+#define SERIAL_ECHOPGM_P(P) (serialprintPGM(P))
+#define SERIAL_ECHOLNPGM_P(P) (serialprintPGM(P "\n"))
-#define SERIAL_ECHOPGM(S) (SERIAL_ECHO_P(PSTR(S)))
-#define SERIAL_ECHOLNPGM(S) (SERIAL_ECHO_P(PSTR(S "\n")))
+#define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S)))
+#define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n")))
#define SERIAL_ECHOPAIR_F_P(P,V...) do{ serialprintPGM(P); SERIAL_ECHO_F(V); }while(0)
#define SERIAL_ECHOLNPAIR_F_P(V...) do{ SERIAL_ECHOPAIR_F_P(V); SERIAL_EOL(); }while(0)
@@ -267,6 +286,12 @@ extern uint8_t marlin_debug_flags;
#define SERIAL_ECHO_TERNARY(TF, PRE, ON, OFF, POST) serial_ternary(TF, PSTR(PRE), PSTR(ON), PSTR(OFF), PSTR(POST))
+#if SERIAL_FLOAT_PRECISION
+ #define SERIAL_DECIMAL(V) SERIAL_PRINT(V, SERIAL_FLOAT_PRECISION)
+#else
+ #define SERIAL_DECIMAL(V) SERIAL_ECHO(V)
+#endif
+
//
// Functions for serial printing from PROGMEM. (Saves loads of SRAM.)
//
diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h
index 1212eb5ba2..a5b78caabb 100644
--- a/Marlin/src/core/types.h
+++ b/Marlin/src/core/types.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -347,14 +347,14 @@ struct XYZval {
FI XYZval operator* (const XYZEval &rs) { XYZval ls = *this; ls.x *= rs.x; ls.y *= rs.y; ls.z *= rs.z; return ls; }
FI XYZval operator/ (const XYZEval &rs) const { XYZval ls = *this; ls.x /= rs.x; ls.y /= rs.y; ls.z /= rs.z; return ls; }
FI XYZval operator/ (const XYZEval &rs) { XYZval ls = *this; ls.x /= rs.x; ls.y /= rs.y; ls.z /= rs.z; return ls; }
- FI XYZval operator* (const float &v) const { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= z; return ls; }
- FI XYZval operator* (const float &v) { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= z; return ls; }
- FI XYZval operator* (const int &v) const { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= z; return ls; }
- FI XYZval operator* (const int &v) { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= z; return ls; }
- FI XYZval operator/ (const float &v) const { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= z; return ls; }
- FI XYZval operator/ (const float &v) { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= z; return ls; }
- FI XYZval operator/ (const int &v) const { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= z; return ls; }
- FI XYZval operator/ (const int &v) { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= z; return ls; }
+ FI XYZval operator* (const float &v) const { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= v; return ls; }
+ FI XYZval operator* (const float &v) { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= v; return ls; }
+ FI XYZval operator* (const int &v) const { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= v; return ls; }
+ FI XYZval operator* (const int &v) { XYZval ls = *this; ls.x *= v; ls.y *= v; ls.z *= v; return ls; }
+ FI XYZval operator/ (const float &v) const { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= v; return ls; }
+ FI XYZval operator/ (const float &v) { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= v; return ls; }
+ FI XYZval operator/ (const int &v) const { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= v; return ls; }
+ FI XYZval operator/ (const int &v) { XYZval ls = *this; ls.x /= v; ls.y /= v; ls.z /= v; return ls; }
FI XYZval operator>>(const int &v) const { XYZval ls = *this; _RS(ls.x); _RS(ls.y); _RS(ls.z); return ls; }
FI XYZval operator>>(const int &v) { XYZval ls = *this; _RS(ls.x); _RS(ls.y); _RS(ls.z); return ls; }
FI XYZval operator<<(const int &v) const { XYZval ls = *this; _LS(ls.x); _LS(ls.y); _LS(ls.z); return ls; }
@@ -501,4 +501,4 @@ struct XYZEval {
#undef FI
const xyze_char_t axis_codes { 'X', 'Y', 'Z', 'E' };
-#define XYZ_CHAR(A) ('X' + char(A))
+#define XYZ_CHAR(A) ((char)('X' + A))
diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp
index 5e159af581..295657fa64 100644
--- a/Marlin/src/core/utility.cpp
+++ b/Marlin/src/core/utility.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -57,21 +57,21 @@ void safe_delay(millis_t ms) {
void log_machine_info() {
SERIAL_ECHOLNPGM("Machine Type: "
- TERN(DELTA, "Delta", "")
- TERN(IS_SCARA, "SCARA", "")
- TERN(IS_CORE, "Core", "")
- TERN(IS_CARTESIAN, "Cartesian", "")
+ TERN_(DELTA, "Delta")
+ TERN_(IS_SCARA, "SCARA")
+ TERN_(IS_CORE, "Core")
+ TERN_(IS_CARTESIAN, "Cartesian")
);
SERIAL_ECHOLNPGM("Probe: "
- TERN(PROBE_MANUALLY, "PROBE_MANUALLY", "")
- TERN(NOZZLE_AS_PROBE, "NOZZLE_AS_PROBE", "")
- TERN(FIX_MOUNTED_PROBE, "FIX_MOUNTED_PROBE", "")
- TERN(HAS_Z_SERVO_PROBE, TERN(BLTOUCH, "BLTOUCH", "SERVO PROBE"), "")
- TERN(TOUCH_MI_PROBE, "TOUCH_MI_PROBE", "")
- TERN(Z_PROBE_SLED, "Z_PROBE_SLED", "")
- TERN(Z_PROBE_ALLEN_KEY, "Z_PROBE_ALLEN_KEY", "")
- TERN(SOLENOID_PROBE, "SOLENOID_PROBE", "")
+ TERN_(PROBE_MANUALLY, "PROBE_MANUALLY")
+ TERN_(NOZZLE_AS_PROBE, "NOZZLE_AS_PROBE")
+ TERN_(FIX_MOUNTED_PROBE, "FIX_MOUNTED_PROBE")
+ TERN_(HAS_Z_SERVO_PROBE, TERN(BLTOUCH, "BLTOUCH", "SERVO PROBE"))
+ TERN_(TOUCH_MI_PROBE, "TOUCH_MI_PROBE")
+ TERN_(Z_PROBE_SLED, "Z_PROBE_SLED")
+ TERN_(Z_PROBE_ALLEN_KEY, "Z_PROBE_ALLEN_KEY")
+ TERN_(SOLENOID_PROBE, "SOLENOID_PROBE")
TERN(PROBE_SELECTED, "", "NONE")
);
@@ -108,10 +108,10 @@ void safe_delay(millis_t ms) {
#if HAS_ABL_OR_UBL
SERIAL_ECHOPGM("Auto Bed Leveling: "
- TERN(AUTO_BED_LEVELING_LINEAR, "LINEAR", "")
- TERN(AUTO_BED_LEVELING_BILINEAR, "BILINEAR", "")
- TERN(AUTO_BED_LEVELING_3POINT, "3POINT", "")
- TERN(AUTO_BED_LEVELING_UBL, "UBL", "")
+ TERN_(AUTO_BED_LEVELING_LINEAR, "LINEAR")
+ TERN_(AUTO_BED_LEVELING_BILINEAR, "BILINEAR")
+ TERN_(AUTO_BED_LEVELING_3POINT, "3POINT")
+ TERN_(AUTO_BED_LEVELING_UBL, "UBL")
);
if (planner.leveling_active) {
@@ -123,10 +123,10 @@ void safe_delay(millis_t ms) {
#if ABL_PLANAR
SERIAL_ECHOPGM("ABL Adjustment X");
LOOP_XYZ(a) {
- float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a];
+ const float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a];
SERIAL_CHAR(' ', XYZ_CHAR(a));
if (v > 0) SERIAL_CHAR('+');
- SERIAL_ECHO(v);
+ SERIAL_DECIMAL(v);
}
#else
#if ENABLED(AUTO_BED_LEVELING_UBL)
diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h
index 0c2e91d31f..0481ffc02a 100644
--- a/Marlin/src/core/utility.h
+++ b/Marlin/src/core/utility.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/babystep.cpp b/Marlin/src/feature/babystep.cpp
index 5d2dc47bee..b076881461 100644
--- a/Marlin/src/feature/babystep.cpp
+++ b/Marlin/src/feature/babystep.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -26,7 +26,8 @@
#include "babystep.h"
#include "../MarlinCore.h"
-#include "../module/planner.h"
+#include "../module/motion.h" // for axes_should_home()
+#include "../module/planner.h" // for axis_steps_per_mm[]
#include "../module/stepper.h"
#if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
@@ -54,66 +55,13 @@ void Babystep::add_mm(const AxisEnum axis, const float &mm) {
}
void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
-
- if (DISABLED(BABYSTEP_WITHOUT_HOMING) && !TEST(axis_known_position, axis)) return;
+ if (DISABLED(BABYSTEP_WITHOUT_HOMING) && axes_should_home(_BV(axis))) return;
accum += distance; // Count up babysteps for the UI
- #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
- axis_total[BS_TOTAL_IND(axis)] += distance;
- #endif
-
- #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
- #define BSA_ENABLE(AXIS) do{ switch (AXIS) { case X_AXIS: ENABLE_AXIS_X(); break; case Y_AXIS: ENABLE_AXIS_Y(); break; case Z_AXIS: ENABLE_AXIS_Z(); break; default: break; } }while(0)
- #else
- #define BSA_ENABLE(AXIS) NOOP
- #endif
-
- #if IS_CORE
- #if ENABLED(BABYSTEP_XY)
- switch (axis) {
- case CORE_AXIS_1: // X on CoreXY and CoreXZ, Y on CoreYZ
- BSA_ENABLE(CORE_AXIS_1);
- BSA_ENABLE(CORE_AXIS_2);
- steps[CORE_AXIS_1] += distance * 2;
- steps[CORE_AXIS_2] += distance * 2;
- break;
- case CORE_AXIS_2: // Y on CoreXY, Z on CoreXZ and CoreYZ
- BSA_ENABLE(CORE_AXIS_1);
- BSA_ENABLE(CORE_AXIS_2);
- steps[CORE_AXIS_1] += CORESIGN(distance * 2);
- steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
- break;
- case NORMAL_AXIS: // Z on CoreXY, Y on CoreXZ, X on CoreYZ
- default:
- BSA_ENABLE(NORMAL_AXIS);
- steps[NORMAL_AXIS] += distance;
- break;
- }
- #elif CORE_IS_XZ || CORE_IS_YZ
- // Only Z stepping needs to be handled here
- BSA_ENABLE(CORE_AXIS_1);
- BSA_ENABLE(CORE_AXIS_2);
- steps[CORE_AXIS_1] += CORESIGN(distance * 2);
- steps[CORE_AXIS_2] -= CORESIGN(distance * 2);
- #else
- BSA_ENABLE(Z_AXIS);
- steps[Z_AXIS] += distance;
- #endif
- #else
- #if ENABLED(BABYSTEP_XY)
- BSA_ENABLE(axis);
- #else
- BSA_ENABLE(Z_AXIS);
- #endif
- steps[BS_AXIS_IND(axis)] += distance;
- #endif
- #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
- gcode.reset_stepper_timeout();
- #endif
-
- #if ENABLED(INTEGRATED_BABYSTEPPING)
- if (has_steps()) stepper.initiateBabystepping();
- #endif
+ steps[BS_AXIS_IND(axis)] += distance;
+ TERN_(BABYSTEP_DISPLAY_TOTAL, axis_total[BS_TOTAL_IND(axis)] += distance);
+ TERN_(BABYSTEP_ALWAYS_AVAILABLE, gcode.reset_stepper_timeout());
+ TERN_(INTEGRATED_BABYSTEPPING, if (has_steps()) stepper.initiateBabystepping());
}
#endif // BABYSTEPPING
diff --git a/Marlin/src/feature/babystep.h b/Marlin/src/feature/babystep.h
index 287664502c..f85e5909ca 100644
--- a/Marlin/src/feature/babystep.h
+++ b/Marlin/src/feature/babystep.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -55,11 +55,8 @@ public:
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
static int16_t axis_total[BS_TOTAL_IND(Z_AXIS) + 1]; // Total babysteps since G28
static inline void reset_total(const AxisEnum axis) {
- if (true
- #if ENABLED(BABYSTEP_XY)
- && axis == Z_AXIS
- #endif
- ) axis_total[BS_TOTAL_IND(axis)] = 0;
+ if (TERN1(BABYSTEP_XY, axis == Z_AXIS))
+ axis_total[BS_TOTAL_IND(axis)] = 0;
}
#endif
diff --git a/Marlin/src/feature/backlash.cpp b/Marlin/src/feature/backlash.cpp
index bc33ae3185..867e9cdd21 100644
--- a/Marlin/src/feature/backlash.cpp
+++ b/Marlin/src/feature/backlash.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/backlash.h b/Marlin/src/feature/backlash.h
index 20666c540b..8d00570f99 100644
--- a/Marlin/src/feature/backlash.h
+++ b/Marlin/src/feature/backlash.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -55,26 +55,16 @@ public:
static inline float get_measurement(const AxisEnum a) {
// Return the measurement averaged over all readings
- return (
- #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
- measured_count[a] > 0 ? measured_mm[a] / measured_count[a] :
- #endif
- 0
+ return TERN(MEASURE_BACKLASH_WHEN_PROBING
+ , measured_count[a] > 0 ? measured_mm[a] / measured_count[a] : 0
+ , 0
);
- #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING)
- UNUSED(a);
- #endif
+ TERN(MEASURE_BACKLASH_WHEN_PROBING,,UNUSED(a));
}
static inline bool has_measurement(const AxisEnum a) {
- return (false
- #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)
- || (measured_count[a] > 0)
- #endif
- );
- #if DISABLED(MEASURE_BACKLASH_WHEN_PROBING)
- UNUSED(a);
- #endif
+ return TERN0(MEASURE_BACKLASH_WHEN_PROBING, measured_count[a] > 0);
+ TERN(MEASURE_BACKLASH_WHEN_PROBING,,UNUSED(a));
}
static inline bool has_any_measurement() {
diff --git a/Marlin/src/feature/baricuda.cpp b/Marlin/src/feature/baricuda.cpp
index 3899348548..596891707e 100644
--- a/Marlin/src/feature/baricuda.cpp
+++ b/Marlin/src/feature/baricuda.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/baricuda.h b/Marlin/src/feature/baricuda.h
index 567d2253e6..f28d07d642 100644
--- a/Marlin/src/feature/baricuda.h
+++ b/Marlin/src/feature/baricuda.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/bedlevel/abl/abl.cpp b/Marlin/src/feature/bedlevel/abl/abl.cpp
index 33c9cbdfde..a585c1e155 100644
--- a/Marlin/src/feature/bedlevel/abl/abl.cpp
+++ b/Marlin/src/feature/bedlevel/abl/abl.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -74,9 +74,7 @@ static void extrapolate_one_point(const uint8_t x, const uint8_t y, const int8_t
// Take the average instead of the median
z_values[x][y] = (a + b + c) / 3.0;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
// Median is robust (ignores outliers).
// z_values[x][y] = (a < b) ? ((b < c) ? b : (c < a) ? a : c)
@@ -241,9 +239,7 @@ void print_bilinear_leveling_grid() {
// Refresh after other values have been updated
void refresh_bed_level() {
bilinear_grid_factor = bilinear_grid_spacing.reciprocal();
- #if ENABLED(ABL_BILINEAR_SUBDIVISION)
- bed_level_virt_interpolate();
- #endif
+ TERN_(ABL_BILINEAR_SUBDIVISION, bed_level_virt_interpolate());
}
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
diff --git a/Marlin/src/feature/bedlevel/abl/abl.h b/Marlin/src/feature/bedlevel/abl/abl.h
index 312dc0db80..bbe2411dc3 100644
--- a/Marlin/src/feature/bedlevel/abl/abl.h
+++ b/Marlin/src/feature/bedlevel/abl/abl.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp
index 63493712a8..3e9225b7f9 100644
--- a/Marlin/src/feature/bedlevel/bedlevel.cpp
+++ b/Marlin/src/feature/bedlevel/bedlevel.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -47,17 +47,9 @@
#endif
bool leveling_is_valid() {
- return
- #if ENABLED(MESH_BED_LEVELING)
- mbl.has_mesh()
- #elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
- !!bilinear_grid_spacing.x
- #elif ENABLED(AUTO_BED_LEVELING_UBL)
- ubl.mesh_is_valid()
- #else // 3POINT, LINEAR
- true
- #endif
- ;
+ return TERN1(MESH_BED_LEVELING, mbl.has_mesh())
+ && TERN1(AUTO_BED_LEVELING_BILINEAR, !!bilinear_grid_spacing.x)
+ && TERN1(AUTO_BED_LEVELING_UBL, ubl.mesh_is_valid());
}
/**
@@ -69,11 +61,7 @@ bool leveling_is_valid() {
*/
void set_bed_leveling_enabled(const bool enable/*=true*/) {
- #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
- const bool can_change = (!enable || leveling_is_valid());
- #else
- constexpr bool can_change = true;
- #endif
+ const bool can_change = TERN1(AUTO_BED_LEVELING_BILINEAR, !enable || leveling_is_valid());
if (can_change && enable != planner.leveling_active) {
@@ -145,9 +133,7 @@ void reset_bed_level() {
bilinear_grid_spacing.reset();
GRID_LOOP(x, y) {
z_values[x][y] = NAN;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, 0);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, 0));
}
#elif ABL_PLANAR
planner.bed_level_matrix.set_to_identity();
@@ -245,9 +231,7 @@ void reset_bed_level() {
current_position = pos;
- #if ENABLED(LCD_BED_LEVELING)
- ui.wait_for_move = false;
- #endif
+ TERN_(LCD_BED_LEVELING, ui.wait_for_move = false);
}
#endif
diff --git a/Marlin/src/feature/bedlevel/bedlevel.h b/Marlin/src/feature/bedlevel/bedlevel.h
index fd3ed82e52..995e9d0dbc 100644
--- a/Marlin/src/feature/bedlevel/bedlevel.h
+++ b/Marlin/src/feature/bedlevel/bedlevel.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
index 7439c3fcd3..1200c2a1b3 100644
--- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
+++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
index 3a1cbaccb0..ade7a93140 100644
--- a/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
+++ b/Marlin/src/feature/bedlevel/mbl/mesh_bed_leveling.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp
index 8ef2ad564c..809caecf49 100644
--- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp
+++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -31,7 +31,7 @@
#include "../../../MarlinCore.h"
#include "../../../gcode/gcode.h"
- #include "../../../module/configuration_store.h"
+ #include "../../../module/settings.h"
#include "../../../module/planner.h"
#include "../../../module/motion.h"
#include "../../../module/probe.h"
@@ -49,14 +49,13 @@
void unified_bed_leveling::report_current_mesh() {
if (!leveling_is_valid()) return;
SERIAL_ECHO_MSG(" G29 I99");
- LOOP_L_N(x, GRID_MAX_POINTS_X)
- for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
- if (!isnan(z_values[x][y])) {
- SERIAL_ECHO_START();
- SERIAL_ECHOPAIR(" M421 I", int(x), " J", int(y));
- SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4);
- serial_delay(75); // Prevent Printrun from exploding
- }
+ GRID_LOOP(x, y)
+ if (!isnan(z_values[x][y])) {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPAIR(" M421 I", int(x), " J", int(y));
+ SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4);
+ serial_delay(75); // Prevent Printrun from exploding
+ }
}
void unified_bed_leveling::report_state() {
@@ -85,11 +84,7 @@
_GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15)
);
- #if HAS_LCD_MENU
- bool unified_bed_leveling::lcd_map_control = false;
- #endif
-
- volatile int unified_bed_leveling::encoder_diff;
+ volatile int16_t unified_bed_leveling::encoder_diff;
unified_bed_leveling::unified_bed_leveling() {
reset();
@@ -114,9 +109,7 @@
void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
GRID_LOOP(x, y) {
z_values[x][y] = value;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, value);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, value));
}
}
@@ -209,7 +202,7 @@
if (human) SERIAL_CHAR(is_current ? ']' : ' ');
SERIAL_FLUSHTX();
- idle();
+ idle_no_sleep();
}
if (!lcd) SERIAL_EOL();
diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h
index 9e227f02d9..9ac9de1806 100644
--- a/Marlin/src/feature/bedlevel/ubl/ubl.h
+++ b/Marlin/src/feature/bedlevel/ubl/ubl.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -111,9 +111,12 @@ class unified_bed_leveling {
#if HAS_LCD_MENU
static bool lcd_map_control;
+ static void steppers_were_disabled();
+ #else
+ static inline void steppers_were_disabled() {}
#endif
- static volatile int encoder_diff; // Volatile because it's changed at interrupt time.
+ static volatile int16_t encoder_diff; // Volatile because buttons may changed it at interrupt time
unified_bed_leveling();
diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
index 217d894543..d13a8c3dc4 100644
--- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
+++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -28,8 +28,8 @@
#include "../../../MarlinCore.h"
#include "../../../HAL/shared/eeprom_api.h"
- #include "../../../libs/hex_print_routines.h"
- #include "../../../module/configuration_store.h"
+ #include "../../../libs/hex_print.h"
+ #include "../../../module/settings.h"
#include "../../../lcd/ultralcd.h"
#include "../../../module/stepper.h"
#include "../../../module/planner.h"
@@ -38,7 +38,7 @@
#include "../../../gcode/gcode.h"
#include "../../../libs/least_squares_fit.h"
- #if HOTENDS > 1
+ #if HAS_MULTI_HOTEND
#include "../../../module/tool_change.h"
#endif
@@ -54,7 +54,18 @@
#define UBL_G29_P31
#if HAS_LCD_MENU
- void _lcd_ubl_output_map_lcd();
+
+ bool unified_bed_leveling::lcd_map_control = false;
+
+ void unified_bed_leveling::steppers_were_disabled() {
+ if (lcd_map_control) {
+ lcd_map_control = false;
+ ui.defer_status_screen(false);
+ }
+ }
+
+ void ubl_map_screen();
+
#endif
#define SIZE_OF_LITTLE_RAISE 1
@@ -305,17 +316,13 @@
const int8_t p_val = parser.intval('P', -1);
const bool may_move = p_val == 1 || p_val == 2 || p_val == 4 || parser.seen('J');
- #if HOTENDS > 1
- const uint8_t old_tool_index = active_extruder;
- #endif
+ TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index = active_extruder);
// Check for commands that require the printer to be homed
if (may_move) {
planner.synchronize();
- if (axes_need_homing()) gcode.home_all_axes();
- #if HOTENDS > 1
- if (active_extruder != 0) tool_change(0);
- #endif
+ if (axes_should_home()) gcode.home_all_axes();
+ TERN_(HAS_MULTI_HOTEND, if (active_extruder) tool_change(0));
}
// Invalidate Mesh Points. This command is a little bit asymmetrical because
@@ -340,9 +347,7 @@
break; // No more invalid Mesh Points to populate
}
z_values[cpos.x][cpos.y] = NAN;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(cpos, 0.0f);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(cpos, 0.0f));
cnt++;
}
}
@@ -369,9 +374,7 @@
const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x,
p2 = 0.5f * (GRID_MAX_POINTS_Y) - y;
z_values[x][y] += 2.0f * HYPOT(p1, p2);
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
break;
@@ -392,9 +395,7 @@
for (uint8_t x = (GRID_MAX_POINTS_X) / 3; x < 2 * (GRID_MAX_POINTS_X) / 3; x++) // Create a rectangular raised area in
for (uint8_t y = (GRID_MAX_POINTS_Y) / 3; y < 2 * (GRID_MAX_POINTS_Y) / 3; y++) { // the center of the bed
z_values[x][y] += parser.seen('C') ? g29_constant : 9.99f;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
break;
}
@@ -403,17 +404,12 @@
#if HAS_BED_PROBE
if (parser.seen('J')) {
- if (g29_grid_size) { // if not 0 it is a normal n x n grid being probed
- save_ubl_active_state_and_disable();
- tilt_mesh_based_on_probed_grid(false /* false says to do normal grid probing */ );
- restore_ubl_active_state_and_leave();
- }
- else { // grid_size == 0 : A 3-Point leveling has been requested
- save_ubl_active_state_and_disable();
- tilt_mesh_based_on_probed_grid(true /* true says to do 3-Point leveling */ );
- restore_ubl_active_state_and_leave();
- }
- do_blocking_move_to_xy(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)));
+ save_ubl_active_state_and_disable();
+ tilt_mesh_based_on_probed_grid(g29_grid_size == 0); // Zero size does 3-Point
+ restore_ubl_active_state_and_leave();
+ #if ENABLED(UBL_G29_J_RECENTER)
+ do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y)));
+ #endif
report_current_position();
probe_deployed = true;
}
@@ -448,11 +444,11 @@
if (g29_verbose_level > 1) {
SERIAL_ECHOPAIR("Probing around (", g29_pos.x);
SERIAL_CHAR(',');
- SERIAL_ECHO(g29_pos.y);
+ SERIAL_DECIMAL(g29_pos.y);
SERIAL_ECHOLNPGM(").\n");
}
- const xy_pos_t near = g29_pos + probe.offset_xy;
- probe_entire_mesh(near, parser.seen('T'), parser.seen('E'), parser.seen('U'));
+ const xy_pos_t near_probe_xy = g29_pos + probe.offset_xy;
+ probe_entire_mesh(near_probe_xy, parser.seen('T'), parser.seen('E'), parser.seen('U'));
report_current_position();
probe_deployed = true;
@@ -466,7 +462,7 @@
// Manually Probe Mesh in areas that can't be reached by the probe
//
SERIAL_ECHOLNPGM("Manually probing unreachable points.");
- do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
+ do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
if (parser.seen('C') && !xy_seen) {
@@ -488,7 +484,7 @@
}
if (parser.seen('B')) {
- g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness((float) Z_CLEARANCE_BETWEEN_PROBES);
+ g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness(float(Z_CLEARANCE_BETWEEN_PROBES));
if (ABS(g29_card_thickness) > 1.5f) {
SERIAL_ECHOLNPGM("?Error in Business Card measurement.");
return;
@@ -540,9 +536,7 @@
}
else {
z_values[cpos.x][cpos.y] = g29_constant;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(cpos, g29_constant);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(cpos, g29_constant));
}
}
}
@@ -683,9 +677,7 @@
UNUSED(probe_deployed);
#endif
- #if HOTENDS > 1
- tool_change(old_tool_index);
- #endif
+ TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index));
return;
}
@@ -718,9 +710,7 @@
GRID_LOOP(x, y)
if (!isnan(z_values[x][y])) {
z_values[x][y] -= mean + value;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
}
@@ -728,9 +718,7 @@
GRID_LOOP(x, y)
if (!isnan(z_values[x][y])) {
z_values[x][y] += g29_constant;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
}
@@ -742,9 +730,7 @@
void unified_bed_leveling::probe_entire_mesh(const xy_pos_t &near, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) {
probe.deploy(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW
- #if HAS_LCD_MENU
- ui.capture();
- #endif
+ TERN_(HAS_LCD_MENU, ui.capture());
save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
uint8_t count = GRID_MAX_POINTS;
@@ -755,9 +741,7 @@
const int point_num = (GRID_MAX_POINTS) - count + 1;
SERIAL_ECHOLNPAIR("\nProbing mesh point ", point_num, "/", int(GRID_MAX_POINTS), ".\n");
- #if HAS_DISPLAY
- ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), point_num, int(GRID_MAX_POINTS));
- #endif
+ TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), point_num, int(GRID_MAX_POINTS)));
#if HAS_LCD_MENU
if (ui.button_pressed()) {
@@ -776,12 +760,14 @@
: find_closest_mesh_point_of_type(INVALID, near, true);
if (best.pos.x >= 0) { // mesh point found and is reachable by probe
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::PROBE_START));
const float measured_z = probe.probe_at_point(
best.meshpos(),
stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level
);
z_values[best.pos.x][best.pos.y] = measured_z;
#if ENABLED(EXTENSIBLE_UI)
+ ExtUI::onMeshUpdate(best.pos, ExtUI::PROBE_FINISH);
ExtUI::onMeshUpdate(best.pos, measured_z);
#endif
}
@@ -789,17 +775,12 @@
} while (best.pos.x >= 0 && --count);
- #if HAS_LCD_MENU
- ui.release();
- #endif
- probe.stow(); // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW
- #if HAS_LCD_MENU
- ui.capture();
- #endif
+ // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW
+ TERN_(HAS_LCD_MENU, ui.release());
+ probe.stow();
+ TERN_(HAS_LCD_MENU, ui.capture());
- #ifdef Z_AFTER_PROBING
- probe.move_z_after_probing();
- #endif
+ probe.move_z_after_probing();
restore_ubl_active_state_and_leave();
@@ -817,11 +798,11 @@
bool click_and_hold(const clickFunc_t func=nullptr) {
if (ui.button_pressed()) {
- ui.quick_feedback(false); // Preserve button state for click-and-hold
+ ui.quick_feedback(false); // Preserve button state for click-and-hold
const millis_t nxt = millis() + 1500UL;
- while (ui.button_pressed()) { // Loop while the encoder is pressed. Uses hardware flag!
- idle(); // idle, of course
- if (ELAPSED(millis(), nxt)) { // After 1.5 seconds
+ while (ui.button_pressed()) { // Loop while the encoder is pressed. Uses hardware flag!
+ idle(); // idle, of course
+ if (ELAPSED(millis(), nxt)) { // After 1.5 seconds
ui.quick_feedback();
if (func) (*func)();
ui.wait_for_release();
@@ -854,9 +835,7 @@
static void echo_and_take_a_measurement() { SERIAL_ECHOLNPGM(" and take a measurement."); }
float unified_bed_leveling::measure_business_card_thickness(float in_height) {
- #if HAS_LCD_MENU
- ui.capture();
- #endif
+ ui.capture();
save_ubl_active_state_and_disable(); // Disable bed level correction for probing
do_blocking_move_to(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)), in_height);
@@ -877,7 +856,6 @@
echo_and_take_a_measurement();
const float z2 = measure_point_with_encoder();
-
do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES);
const float thickness = ABS(z1 - z2);
@@ -887,17 +865,13 @@
SERIAL_ECHOLNPGM("mm thick.");
}
- ui.release();
-
restore_ubl_active_state_and_leave();
return thickness;
}
void unified_bed_leveling::manually_probe_remaining_mesh(const xy_pos_t &pos, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) {
- #if HAS_LCD_MENU
- ui.capture();
- #endif
+ ui.capture();
save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained
do_blocking_move_to_xy_z(current_position, z_clearance);
@@ -922,12 +896,10 @@
LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT);
do_blocking_move_to(ppos);
- do_blocking_move_to_z(z_clearance);
+ do_z_clearance(z_clearance);
KEEPALIVE_STATE(PAUSED_FOR_USER);
- #if HAS_LCD_MENU
- ui.capture();
- #endif
+ ui.capture();
if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing
@@ -940,15 +912,12 @@
if (click_and_hold()) {
SERIAL_ECHOLNPGM("\nMesh only partially populated.");
- do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
- ui.release();
+ do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE);
return restore_ubl_active_state_and_leave();
}
z_values[lpos.x][lpos.y] = current_position.z - thick;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(location, z_values[lpos.x][lpos.y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, z_values[lpos.x][lpos.y]));
if (g29_verbose_level > 2)
SERIAL_ECHOLNPAIR_F("Mesh Point Measured at: ", z_values[lpos.x][lpos.y], 6);
@@ -968,7 +937,7 @@
void abort_fine_tune() {
ui.return_to_status();
- do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
+ do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES);
set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED));
}
@@ -994,14 +963,11 @@
save_ubl_active_state_and_disable();
LCD_MESSAGEPGM(MSG_UBL_FINE_TUNE_MESH);
- #if HAS_LCD_MENU
- ui.capture(); // Take over control of the LCD encoder
- #endif
- do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance
+ ui.capture(); // Take over control of the LCD encoder
- #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
- do_blocking_move_to_z(h_offset); // Move Z to the given 'H' offset
- #endif
+ do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance
+
+ TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset)); // Move Z to the given 'H' offset
MeshFlags done_flags{0};
const xy_int8_t &lpos = location.pos;
@@ -1022,9 +988,7 @@
do_blocking_move_to(raw); // Move the nozzle to the edit point with probe clearance
- #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
- do_blocking_move_to_z(h_offset); // Move Z to the given 'H' offset before editing
- #endif
+ TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset)); // Move Z to the given 'H' offset before editing
KEEPALIVE_STATE(PAUSED_FOR_USER);
@@ -1039,11 +1003,9 @@
lcd_mesh_edit_setup(new_z);
do {
- new_z = lcd_mesh_edit();
- #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
- do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
- #endif
idle();
+ new_z = lcd_mesh_edit();
+ TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset + new_z)); // Move the nozzle as the point is edited
SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
} while (!ui.button_pressed());
@@ -1052,17 +1014,13 @@
if (click_and_hold(abort_fine_tune)) break; // Button held down? Abort editing
z_values[lpos.x][lpos.y] = new_z; // Save the updated Z value
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(location, new_z);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, new_z));
serial_delay(20); // No switch noise
ui.refresh();
} while (lpos.x >= 0 && --g29_repetition_cnt > 0);
- ui.release();
-
if (do_ubl_mesh_map) display_map(g29_map_type);
restore_ubl_active_state_and_leave();
@@ -1072,7 +1030,7 @@
SERIAL_ECHOLNPGM("Done Editing Mesh");
if (lcd_map_control)
- ui.goto_screen(_lcd_ubl_output_map_lcd);
+ ui.goto_screen(ubl_map_screen);
else
ui.return_to_status();
}
@@ -1082,9 +1040,7 @@
bool unified_bed_leveling::g29_parameter_parsing() {
bool err_flag = false;
- #if HAS_LCD_MENU
- set_message_with_feedback(GET_TEXT(MSG_UBL_DOING_G29));
- #endif
+ TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_DOING_G29)));
g29_constant = 0;
g29_repetition_cnt = 0;
@@ -1206,9 +1162,7 @@
ubl_state_recursion_chk++;
if (ubl_state_recursion_chk != 1) {
SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
- #if HAS_LCD_MENU
- set_message_with_feedback(GET_TEXT(MSG_UBL_SAVE_ERROR));
- #endif
+ TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_SAVE_ERROR)));
return;
}
#endif
@@ -1217,12 +1171,11 @@
}
void unified_bed_leveling::restore_ubl_active_state_and_leave() {
+ TERN_(HAS_LCD_MENU, ui.release());
#if ENABLED(UBL_DEVEL_DEBUGGING)
if (--ubl_state_recursion_chk) {
SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
- #if HAS_LCD_MENU
- set_message_with_feedback(GET_TEXT(MSG_UBL_RESTORE_ERROR));
- #endif
+ TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_RESTORE_ERROR)));
return;
}
#endif
@@ -1337,9 +1290,7 @@
const float v2 = z_values[dx + xdir][dy + ydir];
if (!isnan(v2)) {
z_values[x][y] = v1 < v2 ? v1 : v1 + v1 - v2;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
return true;
}
}
@@ -1403,9 +1354,7 @@
if (do_3_pt_leveling) {
SERIAL_ECHOLNPGM("Tilting mesh (1/3)");
- #if HAS_DISPLAY
- ui.status_printf_P(0, PSTR(S_FMT " 1/3"), GET_TEXT(MSG_LCD_TILTING_MESH));
- #endif
+ TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 1/3"), GET_TEXT(MSG_LCD_TILTING_MESH)));
measured_z = probe.probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level);
if (isnan(measured_z))
@@ -1424,9 +1373,7 @@
if (!abort_flag) {
SERIAL_ECHOLNPGM("Tilting mesh (2/3)");
- #if HAS_DISPLAY
- ui.status_printf_P(0, PSTR(S_FMT " 2/3"), GET_TEXT(MSG_LCD_TILTING_MESH));
- #endif
+ TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 2/3"), GET_TEXT(MSG_LCD_TILTING_MESH)));
measured_z = probe.probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level);
#ifdef VALIDATE_MESH_TILT
@@ -1446,9 +1393,7 @@
if (!abort_flag) {
SERIAL_ECHOLNPGM("Tilting mesh (3/3)");
- #if HAS_DISPLAY
- ui.status_printf_P(0, PSTR(S_FMT " 3/3"), GET_TEXT(MSG_LCD_TILTING_MESH));
- #endif
+ TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 3/3"), GET_TEXT(MSG_LCD_TILTING_MESH)));
measured_z = probe.probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level);
#ifdef VALIDATE_MESH_TILT
@@ -1467,9 +1412,7 @@
}
probe.stow();
- #ifdef Z_AFTER_PROBING
- probe.move_z_after_probing();
- #endif
+ probe.move_z_after_probing();
if (abort_flag) {
SERIAL_ECHOLNPGM("?Error probing point. Aborting operation.");
@@ -1491,9 +1434,7 @@
if (!abort_flag) {
SERIAL_ECHOLNPAIR("Tilting mesh point ", point_num, "/", total_points, "\n");
- #if HAS_DISPLAY
- ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points);
- #endif
+ TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points));
measured_z = probe.probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling
@@ -1532,9 +1473,7 @@
}
}
probe.stow();
- #ifdef Z_AFTER_PROBING
- probe.move_z_after_probing();
- #endif
+ probe.move_z_after_probing();
if (abort_flag || finish_incremental_LSF(&lsf_results)) {
SERIAL_ECHOPGM("Could not complete LSF!");
@@ -1582,9 +1521,7 @@
}
z_values[i][j] = mz - lsf_results.D;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(i, j, z_values[i][j]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, z_values[i][j]));
}
if (DEBUGGING(LEVELING)) {
@@ -1680,9 +1617,7 @@
}
const float ez = -lsf_results.D - lsf_results.A * ppos.x - lsf_results.B * ppos.y;
z_values[ix][iy] = ez;
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy]));
idle(); // housekeeping
}
}
@@ -1743,8 +1678,9 @@
SERIAL_EOL();
#if HAS_KILL
- SERIAL_ECHOLNPAIR("Kill pin on :", int(KILL_PIN), " state:", READ(KILL_PIN));
+ SERIAL_ECHOLNPAIR("Kill pin on :", int(KILL_PIN), " state:", int(kill_state()));
#endif
+
SERIAL_EOL();
serial_delay(50);
@@ -1822,9 +1758,7 @@
GRID_LOOP(x, y) {
z_values[x][y] -= tmp_z_values[x][y];
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onMeshUpdate(x, y, z_values[x][y]);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
}
diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
index 5364108240..63559e0bb8 100644
--- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
+++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../../../inc/MarlinConfig.h"
diff --git a/Marlin/src/feature/binary_protocol.cpp b/Marlin/src/feature/binary_stream.cpp
similarity index 90%
rename from Marlin/src/feature/binary_protocol.cpp
rename to Marlin/src/feature/binary_stream.cpp
index e555c0c463..81e110339b 100644
--- a/Marlin/src/feature/binary_protocol.cpp
+++ b/Marlin/src/feature/binary_stream.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -25,7 +25,7 @@
#if ENABLED(BINARY_FILE_TRANSFER)
#include "../sd/cardreader.h"
-#include "binary_protocol.h"
+#include "binary_stream.h"
char* SDFileTransferProtocol::Packet::Open::data = nullptr;
size_t SDFileTransferProtocol::data_waiting, SDFileTransferProtocol::transfer_timeout, SDFileTransferProtocol::idle_timeout;
@@ -33,4 +33,4 @@ bool SDFileTransferProtocol::transfer_active, SDFileTransferProtocol::dummy_tran
BinaryStream binaryStream[NUM_SERIAL];
-#endif // BINARY_FILE_TRANSFER
+#endif
diff --git a/Marlin/src/feature/binary_protocol.h b/Marlin/src/feature/binary_stream.h
similarity index 97%
rename from Marlin/src/feature/binary_protocol.h
rename to Marlin/src/feature/binary_stream.h
index 978d6a2c02..10dea10d47 100644
--- a/Marlin/src/feature/binary_protocol.h
+++ b/Marlin/src/feature/binary_stream.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -32,7 +32,7 @@
inline bool bs_serial_data_available(const uint8_t index) {
switch (index) {
case 0: return MYSERIAL0.available();
- #if NUM_SERIAL > 1
+ #if HAS_MULTI_SERIAL
case 1: return MYSERIAL1.available();
#endif
}
@@ -42,7 +42,7 @@ inline bool bs_serial_data_available(const uint8_t index) {
inline int bs_read_serial(const uint8_t index) {
switch (index) {
case 0: return MYSERIAL0.read();
- #if NUM_SERIAL > 1
+ #if HAS_MULTI_SERIAL
case 1: return MYSERIAL1.read();
#endif
}
@@ -82,9 +82,7 @@ private:
}
transfer_active = true;
data_waiting = 0;
- #if ENABLED(BINARY_STREAM_COMPRESSION)
- heatshrink_decoder_reset(&hsd);
- #endif
+ TERN_(BINARY_STREAM_COMPRESSION, heatshrink_decoder_reset(&hsd));
return true;
}
@@ -127,9 +125,7 @@ private:
card.closefile();
card.release();
}
- #if ENABLED(BINARY_STREAM_COMPRESSION)
- heatshrink_decoder_finish(&hsd);
- #endif
+ TERN_(BINARY_STREAM_COMPRESSION, heatshrink_decoder_finish(&hsd));
transfer_active = false;
return true;
}
@@ -139,9 +135,7 @@ private:
card.closefile();
card.removeFile(card.filename);
card.release();
- #if ENABLED(BINARY_STREAM_COMPRESSION)
- heatshrink_decoder_finish(&hsd);
- #endif
+ TERN_(BINARY_STREAM_COMPRESSION, heatshrink_decoder_finish(&hsd));
}
transfer_active = false;
return;
diff --git a/Marlin/src/feature/bltouch.cpp b/Marlin/src/feature/bltouch.cpp
index efe575ec63..d6b1f99c16 100644
--- a/Marlin/src/feature/bltouch.cpp
+++ b/Marlin/src/feature/bltouch.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -124,9 +124,7 @@ bool BLTouch::deploy_proc() {
}
// One of the recommended ANTClabs ways to probe, using SW MODE
- #if ENABLED(BLTOUCH_FORCE_SW_MODE)
- _set_SW_mode();
- #endif
+ TERN_(BLTOUCH_FORCE_SW_MODE, _set_SW_mode());
// Now the probe is ready to issue a 10ms pulse when the pin goes up.
// The trigger STOW (see motion.cpp for example) will pull up the probes pin as soon as the pulse
diff --git a/Marlin/src/feature/bltouch.h b/Marlin/src/feature/bltouch.h
index af75fb8b29..40685af1b3 100644
--- a/Marlin/src/feature/bltouch.h
+++ b/Marlin/src/feature/bltouch.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -26,9 +26,17 @@
// BLTouch commands are sent as servo angles
typedef unsigned char BLTCommand;
-#define BLTOUCH_DEPLOY 10
+#if ENABLED(CREALITY_TOUCH)
+ #define STOW_ALARM false
+ #define BLTOUCH_DEPLOY 170
+ #define BLTOUCH_STOW 20
+#else
+ #define STOW_ALARM true
+ #define BLTOUCH_DEPLOY 10
+ #define BLTOUCH_STOW 90
+#endif
+
#define BLTOUCH_SW_MODE 60
-#define BLTOUCH_STOW 90
#define BLTOUCH_SELFTEST 120
#define BLTOUCH_MODE_STORE 130
#define BLTOUCH_5V_MODE 140
@@ -95,7 +103,7 @@ public:
private:
FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
- FORCE_INLINE static bool _stow_query_alarm() { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
+ FORCE_INLINE static bool _stow_query_alarm() { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY) == STOW_ALARM; }
static void clear();
static bool command(const BLTCommand cmd, const millis_t &ms);
diff --git a/Marlin/src/feature/cancel_object.cpp b/Marlin/src/feature/cancel_object.cpp
index e2ee645215..16f876f136 100644
--- a/Marlin/src/feature/cancel_object.cpp
+++ b/Marlin/src/feature/cancel_object.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../inc/MarlinConfig.h"
@@ -45,7 +45,7 @@ void CancelObject::set_active_object(const int8_t obj) {
#if HAS_DISPLAY
if (active_object >= 0)
- ui.status_printf_P(0, PSTR(S_FMT " %i"), GET_TEXT(MSG_PRINTING_OBJECT), int(active_object + 1));
+ ui.status_printf_P(0, PSTR(S_FMT " %i"), GET_TEXT(MSG_PRINTING_OBJECT), int(active_object));
else
ui.reset_status();
#endif
diff --git a/Marlin/src/feature/cancel_object.h b/Marlin/src/feature/cancel_object.h
index 41bbfb70fc..1d2d77f203 100644
--- a/Marlin/src/feature/cancel_object.h
+++ b/Marlin/src/feature/cancel_object.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/caselight.cpp b/Marlin/src/feature/caselight.cpp
index a135cac418..8a128bb12d 100644
--- a/Marlin/src/feature/caselight.cpp
+++ b/Marlin/src/feature/caselight.cpp
@@ -16,20 +16,23 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../inc/MarlinConfig.h"
-#if HAS_CASE_LIGHT
+#if ENABLED(CASE_LIGHT_ENABLE)
-uint8_t case_light_brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
-bool case_light_on = CASE_LIGHT_DEFAULT_ON;
+#include "caselight.h"
+
+CaseLight caselight;
+
+uint8_t CaseLight::brightness = CASE_LIGHT_DEFAULT_BRIGHTNESS;
+bool CaseLight::on = CASE_LIGHT_DEFAULT_ON;
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
- #include "leds/leds.h"
- LEDColor case_light_color =
+ LEDColor CaseLight::color =
#ifdef CASE_LIGHT_NEOPIXEL_COLOR
CASE_LIGHT_NEOPIXEL_COLOR
#else
@@ -38,34 +41,33 @@ bool case_light_on = CASE_LIGHT_DEFAULT_ON;
;
#endif
-/**
- * The following are needed because ARM chips ignore a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that
- * are directly controlled by the PWM module. In order to turn them off the brightness level needs to be
- * set to off. Since we can't use the pwm register to save the last brightness level we need a variable
- * to save it.
- */
-uint8_t case_light_brightness_sav; // saves brighness info so can restore when "M355 S1" received
-bool case_light_arg_flag; // flag to notify if S or P argument type
-
#ifndef INVERT_CASE_LIGHT
#define INVERT_CASE_LIGHT false
#endif
-void update_case_light() {
+void CaseLight::update(const bool sflag) {
+ /**
+ * The brightness_sav (and sflag) is needed because ARM chips ignore
+ * a "WRITE(CASE_LIGHT_PIN,x)" command to the pins that are directly
+ * controlled by the PWM module. In order to turn them off the brightness
+ * level needs to be set to OFF. Since we can't use the PWM register to
+ * save the last brightness level we need a variable to save it.
+ */
+ static uint8_t brightness_sav; // Save brightness info for restore on "M355 S1"
- if (!(case_light_arg_flag && !case_light_on))
- case_light_brightness_sav = case_light_brightness; // save brightness except if this is an S0 argument
- if (case_light_arg_flag && case_light_on)
- case_light_brightness = case_light_brightness_sav; // restore last brightens if this is an S1 argument
+ if (on || !sflag)
+ brightness_sav = brightness; // Save brightness except for M355 S0
+ if (sflag && on)
+ brightness = brightness_sav; // Restore last brightness for M355 S1
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) || DISABLED(CASE_LIGHT_NO_BRIGHTNESS)
- const uint8_t i = case_light_on ? case_light_brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
+ const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i;
#endif
#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
leds.set_color(
- MakeLEDColor(case_light_color.r, case_light_color.g, case_light_color.b, case_light_color.w, n10ct),
+ MakeLEDColor(color.r, color.g, color.b, color.w, n10ct),
false
);
@@ -83,11 +85,11 @@ void update_case_light() {
else
#endif
{
- const bool s = case_light_on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
+ const bool s = on ? !INVERT_CASE_LIGHT : INVERT_CASE_LIGHT;
WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW);
}
#endif // !CASE_LIGHT_USE_NEOPIXEL
}
-#endif // HAS_CASE_LIGHT
+#endif // CASE_LIGHT_ENABLE
diff --git a/Marlin/src/feature/caselight.h b/Marlin/src/feature/caselight.h
index de77f0696b..9d1e76da26 100644
--- a/Marlin/src/feature/caselight.h
+++ b/Marlin/src/feature/caselight.h
@@ -16,14 +16,30 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-extern uint8_t case_light_brightness;
-extern bool case_light_on;
-extern uint8_t case_light_brightness_sav; // saves brighness info when case_light_on is false
-extern bool case_light_arg_flag; // flag to notify if S or P argument type
+#include "../inc/MarlinConfigPre.h"
-void update_case_light();
+#if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
+ #include "leds/leds.h"
+#endif
+
+class CaseLight {
+public:
+ static uint8_t brightness;
+ static bool on;
+
+ static void update(const bool sflag);
+ static inline void update_brightness() { update(false); }
+ static inline void update_enabled() { update(true); }
+
+private:
+ #if ENABLED(CASE_LIGHT_USE_NEOPIXEL)
+ static LEDColor color;
+ #endif
+};
+
+extern CaseLight caselight;
diff --git a/Marlin/src/feature/closedloop.cpp b/Marlin/src/feature/closedloop.cpp
index b777243481..8a97f0c0cd 100644
--- a/Marlin/src/feature/closedloop.cpp
+++ b/Marlin/src/feature/closedloop.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../inc/MarlinConfig.h"
@@ -29,12 +29,14 @@
#include "closedloop.h"
-void init_closedloop() {
+ClosedLoop closedloop;
+
+void ClosedLoop::init() {
OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, LOW);
SET_INPUT_PULLUP(CLOSED_LOOP_MOVE_COMPLETE_PIN);
}
-void set_closedloop(const byte val) {
+void ClosedLoop::set(const byte val) {
OUT_WRITE(CLOSED_LOOP_ENABLE_PIN, val);
}
diff --git a/Marlin/src/feature/closedloop.h b/Marlin/src/feature/closedloop.h
index 7e5594447d..e03400c35c 100644
--- a/Marlin/src/feature/closedloop.h
+++ b/Marlin/src/feature/closedloop.h
@@ -16,10 +16,17 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
-void init_closedloop();
-void set_closedloop(const byte val);
+class ClosedLoop {
+public:
+ static void init();
+ static void set(const byte val);
+};
+
+extern ClosedLoop closedloop;
+
+#define CLOSED_LOOP_WAITING() (READ(CLOSED_LOOP_ENABLE_PIN) && !READ(CLOSED_LOOP_MOVE_COMPLETE_PIN))
diff --git a/Marlin/src/feature/controllerfan.cpp b/Marlin/src/feature/controllerfan.cpp
index 0746700407..fa5a86b019 100644
--- a/Marlin/src/feature/controllerfan.cpp
+++ b/Marlin/src/feature/controllerfan.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -55,43 +55,34 @@ void ControllerFan::update() {
#define MOTOR_IS_ON(A,B) (A##_ENABLE_READ() == bool(B##_ENABLE_ON))
#define _OR_ENABLED_E(N) || MOTOR_IS_ON(E##N,E)
- const bool motor_on = MOTOR_IS_ON(Z,Z)
- #if HAS_Z2_ENABLE
- || MOTOR_IS_ON(Z2,Z)
- #endif
- #if HAS_Z3_ENABLE
- || MOTOR_IS_ON(Z3,Z)
- #endif
- #if HAS_Z4_ENABLE
- || MOTOR_IS_ON(Z4,Z)
- #endif
- || (DISABLED(CONTROLLER_FAN_USE_Z_ONLY) && (
- MOTOR_IS_ON(X,X) || MOTOR_IS_ON(Y,Y)
- #if HAS_X2_ENABLE
- || MOTOR_IS_ON(X2,X)
- #endif
- #if HAS_Y2_ENABLE
- || MOTOR_IS_ON(Y2,Y)
- #endif
+ const bool motor_on = (
+ ( DISABLED(CONTROLLER_FAN_IGNORE_Z) &&
+ ( MOTOR_IS_ON(Z,Z)
+ || TERN0(HAS_Z2_ENABLE, MOTOR_IS_ON(Z2,Z))
+ || TERN0(HAS_Z3_ENABLE, MOTOR_IS_ON(Z3,Z))
+ || TERN0(HAS_Z4_ENABLE, MOTOR_IS_ON(Z4,Z))
+ )
+ ) || (
+ DISABLED(CONTROLLER_FAN_USE_Z_ONLY) &&
+ ( MOTOR_IS_ON(X,X) || MOTOR_IS_ON(Y,Y)
+ || TERN0(HAS_X2_ENABLE, MOTOR_IS_ON(X2,X))
+ || TERN0(HAS_Y2_ENABLE, MOTOR_IS_ON(Y2,Y))
#if E_STEPPERS
REPEAT(E_STEPPERS, _OR_ENABLED_E)
#endif
)
)
- ;
+ );
// If any of the drivers or the heated bed are enabled...
- if (motor_on
- #if HAS_HEATED_BED
- || thermalManager.temp_bed.soft_pwm_amount > 0
- #endif
- ) lastMotorOn = ms; //... set time to NOW so the fan will turn on
+ if (motor_on || TERN0(HAS_HEATED_BED, thermalManager.temp_bed.soft_pwm_amount > 0))
+ lastMotorOn = ms; //... set time to NOW so the fan will turn on
// Fan Settings. Set fan > 0:
// - If AutoMode is on and steppers have been enabled for CONTROLLERFAN_IDLE_TIME seconds.
// - If System is on idle and idle fan speed settings is activated.
set_fan_speed(
- settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + settings.duration * 1000UL)
+ settings.auto_mode && lastMotorOn && PENDING(ms, lastMotorOn + SEC_TO_MS(settings.duration))
? settings.active_speed : settings.idle_speed
);
diff --git a/Marlin/src/feature/controllerfan.h b/Marlin/src/feature/controllerfan.h
index cd56ff8ced..d1d39f21f3 100644
--- a/Marlin/src/feature/controllerfan.h
+++ b/Marlin/src/feature/controllerfan.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -62,11 +62,7 @@ class ControllerFan {
#endif
static inline bool state() { return speed > 0; }
static inline void init() { reset(); }
- static inline void reset() {
- #if ENABLED(CONTROLLER_FAN_EDITABLE)
- settings = controllerFan_defaults;
- #endif
- }
+ static inline void reset() { TERN_(CONTROLLER_FAN_EDITABLE, settings = controllerFan_defaults); }
static void setup();
static void update();
};
diff --git a/Marlin/src/feature/dac/dac_dac084s085.h b/Marlin/src/feature/dac/dac_dac084s085.h
index cccc9cbd45..5be0129fc9 100644
--- a/Marlin/src/feature/dac/dac_dac084s085.h
+++ b/Marlin/src/feature/dac/dac_dac084s085.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/dac/dac_mcp4728.cpp b/Marlin/src/feature/dac/dac_mcp4728.cpp
index 39f873f0cb..55f10a49ef 100644
--- a/Marlin/src/feature/dac/dac_mcp4728.cpp
+++ b/Marlin/src/feature/dac/dac_mcp4728.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -24,10 +24,10 @@
* mcp4728.cpp - Arduino library for MicroChip MCP4728 I2C D/A converter
*
* For implementation details, please take a look at the datasheet:
- * http://ww1.microchip.com/downloads/en/DeviceDoc/22187a.pdf
+ * https://ww1.microchip.com/downloads/en/DeviceDoc/22187a.pdf
*
* For discussion and feedback, please go to:
- * http://arduino.cc/forum/index.php/topic,51842.0.html
+ * https://forum.arduino.cc/index.php/topic,51842.0.html
*/
#include "../../inc/MarlinConfig.h"
@@ -43,7 +43,7 @@ xyze_uint_t mcp4728_values;
*/
void mcp4728_init() {
Wire.begin();
- Wire.requestFrom(I2C_ADDRESS(DAC_DEV_ADDRESS), 24);
+ Wire.requestFrom(I2C_ADDRESS(DAC_DEV_ADDRESS), uint8_t(24));
while (Wire.available()) {
char deviceID = Wire.read(),
hiByte = Wire.read(),
diff --git a/Marlin/src/feature/dac/dac_mcp4728.h b/Marlin/src/feature/dac/dac_mcp4728.h
index 8e8b25ca69..6cce77856a 100644
--- a/Marlin/src/feature/dac/dac_mcp4728.h
+++ b/Marlin/src/feature/dac/dac_mcp4728.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/dac/stepper_dac.cpp b/Marlin/src/feature/dac/stepper_dac.cpp
index c8c1cb2494..6b140a0025 100644
--- a/Marlin/src/feature/dac/stepper_dac.cpp
+++ b/Marlin/src/feature/dac/stepper_dac.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -29,6 +29,7 @@
#if ENABLED(DAC_STEPPER_CURRENT)
#include "stepper_dac.h"
+#include "../../MarlinCore.h" // for SP_X_LBL...
bool dac_present = false;
constexpr xyze_uint8_t dac_order = DAC_STEPPER_ORDER;
@@ -85,15 +86,12 @@ void dac_current_set_percents(xyze_uint8_t &pct) {
void dac_print_values() {
if (!dac_present) return;
-
SERIAL_ECHO_MSG("Stepper current values in % (Amps):");
SERIAL_ECHO_START();
- SERIAL_ECHOLNPAIR_P(
- SP_X_LBL, dac_perc(X_AXIS), PSTR(" ("), dac_amps(X_AXIS), PSTR(")")
- SP_Y_LBL, dac_perc(Y_AXIS), PSTR(" ("), dac_amps(Y_AXIS), PSTR(")")
- SP_Z_LBL, dac_perc(Z_AXIS), PSTR(" ("), dac_amps(Z_AXIS), PSTR(")")
- SP_E_LBL, dac_perc(E_AXIS), PSTR(" ("), dac_amps(E_AXIS), PSTR(")")
- );
+ SERIAL_ECHOPAIR_P( SP_X_LBL, dac_perc(X_AXIS), PSTR(" ("), dac_amps(X_AXIS), PSTR(")"));
+ SERIAL_ECHOPAIR_P( SP_Y_LBL, dac_perc(Y_AXIS), PSTR(" ("), dac_amps(Y_AXIS), PSTR(")"));
+ SERIAL_ECHOPAIR_P( SP_Z_LBL, dac_perc(Z_AXIS), PSTR(" ("), dac_amps(Z_AXIS), PSTR(")"));
+ SERIAL_ECHOLNPAIR_P(SP_E_LBL, dac_perc(E_AXIS), PSTR(" ("), dac_amps(E_AXIS), PSTR(")"));
}
void dac_commit_eeprom() {
diff --git a/Marlin/src/feature/dac/stepper_dac.h b/Marlin/src/feature/dac/stepper_dac.h
index 3e77d471a6..0543b6275e 100644
--- a/Marlin/src/feature/dac/stepper_dac.h
+++ b/Marlin/src/feature/dac/stepper_dac.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/digipot/digipot.h b/Marlin/src/feature/digipot/digipot.h
index b7c0b65036..d59f8b930a 100644
--- a/Marlin/src/feature/digipot/digipot.h
+++ b/Marlin/src/feature/digipot/digipot.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/digipot/digipot_mcp4018.cpp b/Marlin/src/feature/digipot/digipot_mcp4018.cpp
index e8df4a475f..35c513a32c 100644
--- a/Marlin/src/feature/digipot/digipot_mcp4018.cpp
+++ b/Marlin/src/feature/digipot/digipot_mcp4018.cpp
@@ -16,60 +16,52 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../../inc/MarlinConfig.h"
-#if BOTH(DIGIPOT_I2C, DIGIPOT_MCP4018)
+#if ENABLED(DIGIPOT_MCP4018)
-#include "Stream.h"
-#include "utility/twi.h"
-#include //https://github.com/stawel/SlowSoftI2CMaster
+#include
+#include // https://github.com/stawel/SlowSoftI2CMaster
// Settings for the I2C based DIGIPOT (MCP4018) based on WT150
#define DIGIPOT_A4988_Rsx 0.250
#define DIGIPOT_A4988_Vrefmax 1.666
-#define DIGIPOT_A4988_MAX_VALUE 127
+#define DIGIPOT_MCP4018_MAX_VALUE 127
-#define DIGIPOT_A4988_Itripmax(Vref) ((Vref)/(8.0*DIGIPOT_A4988_Rsx))
+#define DIGIPOT_A4988_Itripmax(Vref) ((Vref) / (8.0 * DIGIPOT_A4988_Rsx))
-#define DIGIPOT_A4988_FACTOR ((DIGIPOT_A4988_MAX_VALUE)/DIGIPOT_A4988_Itripmax(DIGIPOT_A4988_Vrefmax))
+#define DIGIPOT_A4988_FACTOR ((DIGIPOT_MCP4018_MAX_VALUE) / DIGIPOT_A4988_Itripmax(DIGIPOT_A4988_Vrefmax))
#define DIGIPOT_A4988_MAX_CURRENT 2.0
static byte current_to_wiper(const float current) {
- const int16_t value = ceil(float(DIGIPOT_A4988_FACTOR) * current);
- return byte(constrain(value, 0, DIGIPOT_A4988_MAX_VALUE));
+ const int16_t value = TERN(DIGIPOT_USE_RAW_VALUES, current, CEIL(current * DIGIPOT_A4988_FACTOR));
+ return byte(constrain(value, 0, DIGIPOT_MCP4018_MAX_VALUE));
}
-const uint8_t sda_pins[DIGIPOT_I2C_NUM_CHANNELS] = {
- DIGIPOTS_I2C_SDA_X
- #if DIGIPOT_I2C_NUM_CHANNELS > 1
- , DIGIPOTS_I2C_SDA_Y
- #if DIGIPOT_I2C_NUM_CHANNELS > 2
- , DIGIPOTS_I2C_SDA_Z
- #if DIGIPOT_I2C_NUM_CHANNELS > 3
- , DIGIPOTS_I2C_SDA_E0
- #if DIGIPOT_I2C_NUM_CHANNELS > 4
- , DIGIPOTS_I2C_SDA_E1
- #endif
- #endif
- #endif
- #endif
-};
-
static SlowSoftI2CMaster pots[DIGIPOT_I2C_NUM_CHANNELS] = {
- SlowSoftI2CMaster { sda_pins[X_AXIS], DIGIPOTS_I2C_SCL }
+ SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_X, DIGIPOTS_I2C_SCL)
#if DIGIPOT_I2C_NUM_CHANNELS > 1
- , SlowSoftI2CMaster { sda_pins[Y_AXIS], DIGIPOTS_I2C_SCL }
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_Y, DIGIPOTS_I2C_SCL)
#if DIGIPOT_I2C_NUM_CHANNELS > 2
- , SlowSoftI2CMaster { sda_pins[Z_AXIS], DIGIPOTS_I2C_SCL }
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_Z, DIGIPOTS_I2C_SCL)
#if DIGIPOT_I2C_NUM_CHANNELS > 3
- , SlowSoftI2CMaster { sda_pins[E_AXIS], DIGIPOTS_I2C_SCL }
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_E0, DIGIPOTS_I2C_SCL)
#if DIGIPOT_I2C_NUM_CHANNELS > 4
- , SlowSoftI2CMaster { sda_pins[E_AXIS + 1], DIGIPOTS_I2C_SCL }
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_E1, DIGIPOTS_I2C_SCL)
+ #if DIGIPOT_I2C_NUM_CHANNELS > 5
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_E2, DIGIPOTS_I2C_SCL)
+ #if DIGIPOT_I2C_NUM_CHANNELS > 6
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_E3, DIGIPOTS_I2C_SCL)
+ #if DIGIPOT_I2C_NUM_CHANNELS > 7
+ , SlowSoftI2CMaster(DIGIPOTS_I2C_SDA_E4, DIGIPOTS_I2C_SCL)
+ #endif
+ #endif
+ #endif
#endif
#endif
#endif
@@ -86,18 +78,23 @@ static void i2c_send(const uint8_t channel, const byte v) {
// This is for the MCP4018 I2C based digipot
void digipot_i2c_set_current(const uint8_t channel, const float current) {
- i2c_send(channel, current_to_wiper(_MIN(_MAX(current, 0), float(DIGIPOT_A4988_MAX_CURRENT))));
+ const float ival = _MIN(_MAX(current, 0), float(DIGIPOT_MCP4018_MAX_VALUE));
+ i2c_send(channel, current_to_wiper(ival));
}
void digipot_i2c_init() {
- static const float digipot_motor_current[] PROGMEM = DIGIPOT_I2C_MOTOR_CURRENTS;
+ LOOP_L_N(i, DIGIPOT_I2C_NUM_CHANNELS) pots[i].i2c_init();
- LOOP_L_N(i, DIGIPOT_I2C_NUM_CHANNELS)
- pots[i].i2c_init();
-
- // setup initial currents as defined in Configuration_adv.h
+ // Init currents according to Configuration_adv.h
+ static const float digipot_motor_current[] PROGMEM =
+ #if ENABLED(DIGIPOT_USE_RAW_VALUES)
+ DIGIPOT_MOTOR_CURRENT
+ #else
+ DIGIPOT_I2C_MOTOR_CURRENTS
+ #endif
+ ;
LOOP_L_N(i, COUNT(digipot_motor_current))
digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
}
-#endif // DIGIPOT_I2C && DIGIPOT_MCP4018
+#endif // DIGIPOT_MCP4018
diff --git a/Marlin/src/feature/digipot/digipot_mcp4451.cpp b/Marlin/src/feature/digipot/digipot_mcp4451.cpp
index 1183c96aa5..0c8ff04a0b 100644
--- a/Marlin/src/feature/digipot/digipot_mcp4451.cpp
+++ b/Marlin/src/feature/digipot/digipot_mcp4451.cpp
@@ -16,15 +16,15 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#include "../../inc/MarlinConfig.h"
-#if ENABLED(DIGIPOT_I2C) && DISABLED(DIGIPOT_MCP4018)
+#if ENABLED(DIGIPOT_MCP4451)
-#include "Stream.h"
+#include
#include
#if MB(MKS_SBASE)
@@ -33,18 +33,18 @@
// Settings for the I2C based DIGIPOT (MCP4451) on Azteeg X3 Pro
#if MB(5DPRINT)
- #define DIGIPOT_I2C_FACTOR 117.96
- #define DIGIPOT_I2C_MAX_CURRENT 1.736
+ #define DIGIPOT_I2C_FACTOR 117.96f
+ #define DIGIPOT_I2C_MAX_CURRENT 1.736f
#elif MB(AZTEEG_X5_MINI, AZTEEG_X5_MINI_WIFI)
- #define DIGIPOT_I2C_FACTOR 113.5
- #define DIGIPOT_I2C_MAX_CURRENT 2.0
+ #define DIGIPOT_I2C_FACTOR 113.5f
+ #define DIGIPOT_I2C_MAX_CURRENT 2.0f
#else
- #define DIGIPOT_I2C_FACTOR 106.7
- #define DIGIPOT_I2C_MAX_CURRENT 2.5
+ #define DIGIPOT_I2C_FACTOR 106.7f
+ #define DIGIPOT_I2C_MAX_CURRENT 2.5f
#endif
static byte current_to_wiper(const float current) {
- return byte(CEIL(float((DIGIPOT_I2C_FACTOR * current))));
+ return byte(TERN(DIGIPOT_USE_RAW_VALUES, current, CEIL(DIGIPOT_I2C_FACTOR * current)));
}
static void digipot_i2c_send(const byte addr, const byte a, const byte b) {
@@ -62,8 +62,8 @@ static void digipot_i2c_send(const byte addr, const byte a, const byte b) {
// This is for the MCP4451 I2C based digipot
void digipot_i2c_set_current(const uint8_t channel, const float current) {
- // these addresses are specific to Azteeg X3 Pro, can be set to others,
- // In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1
+ // These addresses are specific to Azteeg X3 Pro, can be set to others.
+ // In this case first digipot is at address A0=0, A1=0, second one is at A0=0, A1=1
const byte addr = channel < 4 ? DIGIPOT_I2C_ADDRESS_A : DIGIPOT_I2C_ADDRESS_B; // channel 0-3 vs 4-7
// Initial setup
@@ -77,14 +77,20 @@ void digipot_i2c_set_current(const uint8_t channel, const float current) {
void digipot_i2c_init() {
#if MB(MKS_SBASE)
- configure_i2c(16); // Setting clock_option to 16 ensure the I2C bus is initialized at 400kHz
+ configure_i2c(16); // Set clock_option to 16 ensure I2C is initialized at 400kHz
#else
Wire.begin();
#endif
- // setup initial currents as defined in Configuration_adv.h
- static const float digipot_motor_current[] PROGMEM = DIGIPOT_I2C_MOTOR_CURRENTS;
+ // Set up initial currents as defined in Configuration_adv.h
+ static const float digipot_motor_current[] PROGMEM =
+ #if ENABLED(DIGIPOT_USE_RAW_VALUES)
+ DIGIPOT_MOTOR_CURRENT
+ #else
+ DIGIPOT_I2C_MOTOR_CURRENTS
+ #endif
+ ;
LOOP_L_N(i, COUNT(digipot_motor_current))
digipot_i2c_set_current(i, pgm_read_float(&digipot_motor_current[i]));
}
-#endif // DIGIPOT_I2C
+#endif // DIGIPOT_MCP4451
diff --git a/Marlin/src/feature/direct_stepping.cpp b/Marlin/src/feature/direct_stepping.cpp
new file mode 100644
index 0000000000..9766d14640
--- /dev/null
+++ b/Marlin/src/feature/direct_stepping.cpp
@@ -0,0 +1,262 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#include "../inc/MarlinConfigPre.h"
+
+#if ENABLED(DIRECT_STEPPING)
+
+#include "direct_stepping.h"
+
+#include "../MarlinCore.h"
+
+#define CHECK_PAGE(I, R) do{ \
+ if (I >= sizeof(page_states) / sizeof(page_states[0])) { \
+ fatal_error = true; \
+ return R; \
+ } \
+}while(0)
+
+#define CHECK_PAGE_STATE(I, R, S) do { \
+ CHECK_PAGE(I, R); \
+ if (page_states[I] != S) { \
+ fatal_error = true; \
+ return R; \
+ } \
+}while(0)
+
+namespace DirectStepping {
+
+ template
+ State SerialPageManager::state;
+
+ template
+ volatile bool SerialPageManager::fatal_error;
+
+ template
+ volatile PageState SerialPageManager::page_states[Cfg::NUM_PAGES];
+
+ template
+ volatile bool SerialPageManager::page_states_dirty;
+
+ template
+ uint8_t SerialPageManager::pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
+
+ template
+ uint8_t SerialPageManager::checksum;
+
+ template
+ typename Cfg::write_byte_idx_t SerialPageManager::write_byte_idx;
+
+ template
+ typename Cfg::page_idx_t SerialPageManager::write_page_idx;
+
+ template
+ typename Cfg::write_byte_idx_t SerialPageManager::write_page_size;
+
+ template
+ void SerialPageManager::init() {
+ for (int i = 0 ; i < Cfg::NUM_PAGES ; i++)
+ page_states[i] = PageState::FREE;
+
+ fatal_error = false;
+ state = State::NEWLINE;
+
+ page_states_dirty = false;
+
+ SERIAL_ECHOLNPGM("pages_ready");
+ }
+
+ template
+ FORCE_INLINE bool SerialPageManager::maybe_store_rxd_char(uint8_t c) {
+ switch (state) {
+ default:
+ case State::MONITOR:
+ switch (c) {
+ case '\n':
+ case '\r':
+ state = State::NEWLINE;
+ default:
+ return false;
+ }
+ case State::NEWLINE:
+ switch (c) {
+ case Cfg::CONTROL_CHAR:
+ state = State::ADDRESS;
+ return true;
+ case '\n':
+ case '\r':
+ state = State::NEWLINE;
+ return false;
+ default:
+ state = State::MONITOR;
+ return false;
+ }
+ case State::ADDRESS:
+ //TODO: 16 bit address, State::ADDRESS2
+ write_page_idx = c;
+ write_byte_idx = 0;
+ checksum = 0;
+
+ CHECK_PAGE(write_page_idx, true);
+
+ if (page_states[write_page_idx] == PageState::FAIL) {
+ // Special case for fail
+ state = State::UNFAIL;
+ return true;
+ }
+
+ set_page_state(write_page_idx, PageState::WRITING);
+
+ state = Cfg::DIRECTIONAL ? State::COLLECT : State::SIZE;
+
+ return true;
+ case State::SIZE:
+ // Zero means full page size
+ write_page_size = c;
+ state = State::COLLECT;
+ return true;
+ case State::COLLECT:
+ pages[write_page_idx][write_byte_idx++] = c;
+ checksum ^= c;
+
+ // check if still collecting
+ if (Cfg::PAGE_SIZE == 256) {
+ // special case for 8-bit, check if rolled back to 0
+ if (Cfg::DIRECTIONAL || !write_page_size) { // full 256 bytes
+ if (write_byte_idx) return true;
+ } else {
+ if (write_byte_idx < write_page_size) return true;
+ }
+ } else if (Cfg::DIRECTIONAL) {
+ if (write_byte_idx != Cfg::PAGE_SIZE) return true;
+ } else {
+ if (write_byte_idx < write_page_size) return true;
+ }
+
+ state = State::CHECKSUM;
+ return true;
+ case State::CHECKSUM: {
+ const PageState page_state = (checksum == c) ? PageState::OK : PageState::FAIL;
+ set_page_state(write_page_idx, page_state);
+ state = State::MONITOR;
+ return true;
+ }
+ case State::UNFAIL:
+ if (c == 0) {
+ set_page_state(write_page_idx, PageState::FREE);
+ } else {
+ fatal_error = true;
+ }
+ state = State::MONITOR;
+ return true;
+ }
+ }
+
+ template
+ void SerialPageManager::write_responses() {
+ if (fatal_error) {
+ kill(GET_TEXT(MSG_BAD_PAGE));
+ return;
+ }
+
+ if (!page_states_dirty) return;
+ page_states_dirty = false;
+
+ SERIAL_ECHO(Cfg::CONTROL_CHAR);
+ constexpr int state_bits = 2;
+ constexpr int n_bytes = Cfg::NUM_PAGES >> state_bits;
+ volatile uint8_t bits_b[n_bytes] = { 0 };
+
+ for (page_idx_t i = 0 ; i < Cfg::NUM_PAGES ; i++) {
+ bits_b[i >> state_bits] |= page_states[i] << ((i * state_bits) & 0x7);
+ }
+
+ uint8_t crc = 0;
+ for (uint8_t i = 0 ; i < n_bytes ; i++) {
+ crc ^= bits_b[i];
+ SERIAL_ECHO(bits_b[i]);
+ }
+
+ SERIAL_ECHO(crc);
+ SERIAL_EOL();
+ }
+
+ template
+ FORCE_INLINE void SerialPageManager::set_page_state(const page_idx_t page_idx, const PageState page_state) {
+ CHECK_PAGE(page_idx,);
+
+ page_states[page_idx] = page_state;
+ page_states_dirty = true;
+ }
+
+ template <>
+ FORCE_INLINE uint8_t *PageManager::get_page(const page_idx_t page_idx) {
+ CHECK_PAGE(page_idx, nullptr);
+
+ return pages[page_idx];
+ }
+
+ template <>
+ FORCE_INLINE void PageManager::free_page(const page_idx_t page_idx) {
+ set_page_state(page_idx, PageState::FREE);
+ }
+
+};
+
+DirectStepping::PageManager page_manager;
+
+const uint8_t segment_table[DirectStepping::Config::NUM_SEGMENTS][DirectStepping::Config::SEGMENT_STEPS] PROGMEM = {
+
+ #if STEPPER_PAGE_FORMAT == SP_4x4D_128
+
+ { 1, 1, 1, 1, 1, 1, 1 }, // 0 = -7
+ { 1, 1, 1, 0, 1, 1, 1 }, // 1 = -6
+ { 1, 1, 1, 0, 1, 0, 1 }, // 2 = -5
+ { 1, 1, 0, 1, 0, 1, 0 }, // 3 = -4
+ { 1, 1, 0, 0, 1, 0, 0 }, // 4 = -3
+ { 0, 0, 1, 0, 0, 0, 1 }, // 5 = -2
+ { 0, 0, 0, 1, 0, 0, 0 }, // 6 = -1
+ { 0, 0, 0, 0, 0, 0, 0 }, // 7 = 0
+ { 0, 0, 0, 1, 0, 0, 0 }, // 8 = 1
+ { 0, 0, 1, 0, 0, 0, 1 }, // 9 = 2
+ { 1, 1, 0, 0, 1, 0, 0 }, // 10 = 3
+ { 1, 1, 0, 1, 0, 1, 0 }, // 11 = 4
+ { 1, 1, 1, 0, 1, 0, 1 }, // 12 = 5
+ { 1, 1, 1, 0, 1, 1, 1 }, // 13 = 6
+ { 1, 1, 1, 1, 1, 1, 1 }, // 14 = 7
+ { 0 }
+
+ #elif STEPPER_PAGE_FORMAT == SP_4x2_256
+
+ { 0, 0, 0 }, // 0
+ { 0, 1, 0 }, // 1
+ { 1, 0, 1 }, // 2
+ { 1, 1, 1 }, // 3
+
+ #elif STEPPER_PAGE_FORMAT == SP_4x1_512
+
+ {0} // Uncompressed format, table not used
+
+ #endif
+
+};
+
+#endif // DIRECT_STEPPING
diff --git a/Marlin/src/feature/direct_stepping.h b/Marlin/src/feature/direct_stepping.h
new file mode 100644
index 0000000000..cde9d1a0b4
--- /dev/null
+++ b/Marlin/src/feature/direct_stepping.h
@@ -0,0 +1,133 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "../inc/MarlinConfig.h"
+
+namespace DirectStepping {
+
+ enum State : char {
+ MONITOR, NEWLINE, ADDRESS, SIZE, COLLECT, CHECKSUM, UNFAIL
+ };
+
+ enum PageState : uint8_t {
+ FREE, WRITING, OK, FAIL
+ };
+
+ // Static state used for stepping through direct stepping pages
+ struct page_step_state_t {
+ // Current page
+ uint8_t *page;
+ // Current segment
+ uint16_t segment_idx;
+ // Current steps within segment
+ uint8_t segment_steps;
+ // Segment delta
+ xyze_uint8_t sd;
+ // Block delta
+ xyze_int_t bd;
+ };
+
+ template
+ class SerialPageManager {
+ public:
+
+ typedef typename Cfg::page_idx_t page_idx_t;
+
+ static bool maybe_store_rxd_char(uint8_t c);
+ static void write_responses();
+
+ // common methods for page managers
+ static void init();
+ static uint8_t *get_page(const page_idx_t page_idx);
+ static void free_page(const page_idx_t page_idx);
+
+ protected:
+
+ typedef typename Cfg::write_byte_idx_t write_byte_idx_t;
+
+ static State state;
+ static volatile bool fatal_error;
+
+ static volatile PageState page_states[Cfg::NUM_PAGES];
+ static volatile bool page_states_dirty;
+
+ static uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
+ static uint8_t checksum;
+ static write_byte_idx_t write_byte_idx;
+ static page_idx_t write_page_idx;
+ static write_byte_idx_t write_page_size;
+
+ static void set_page_state(const page_idx_t page_idx, const PageState page_state);
+ };
+
+ template struct TypeSelector { typedef T type;} ;
+ template struct TypeSelector { typedef F type; };
+
+ template
+ struct config_t {
+ static constexpr char CONTROL_CHAR = '!';
+
+ static constexpr int NUM_PAGES = num_pages;
+ static constexpr int NUM_AXES = num_axes;
+ static constexpr int BITS_SEGMENT = bits_segment;
+ static constexpr int DIRECTIONAL = dir ? 1 : 0;
+ static constexpr int SEGMENTS = segments;
+
+ static constexpr int NUM_SEGMENTS = 1 << BITS_SEGMENT;
+ static constexpr int SEGMENT_STEPS = (1 << (BITS_SEGMENT - DIRECTIONAL)) - 1;
+ static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS;
+ static constexpr int PAGE_SIZE = (NUM_AXES * BITS_SEGMENT * SEGMENTS) / 8;
+
+ typedef typename TypeSelector<(PAGE_SIZE>256), uint16_t, uint8_t>::type write_byte_idx_t;
+ typedef typename TypeSelector<(NUM_PAGES>256), uint16_t, uint8_t>::type page_idx_t;
+ };
+
+ template
+ using SP_4x4D_128 = config_t;
+
+ template
+ using SP_4x2_256 = config_t;
+
+ template
+ using SP_4x1_512 = config_t;
+
+ // configured types
+ typedef STEPPER_PAGE_FORMAT Config;
+
+ template class PAGE_MANAGER;
+ typedef PAGE_MANAGER PageManager;
+};
+
+#define SP_4x4D_128 1
+//#define SP_4x4_128 2
+//#define SP_4x2D_256 3
+#define SP_4x2_256 4
+#define SP_4x1_512 5
+
+typedef typename DirectStepping::Config::page_idx_t page_idx_t;
+
+// TODO: use config
+typedef DirectStepping::page_step_state_t page_step_state_t;
+
+extern const uint8_t segment_table[DirectStepping::Config::NUM_SEGMENTS][DirectStepping::Config::SEGMENT_STEPS];
+extern DirectStepping::PageManager page_manager;
diff --git a/Marlin/src/feature/e_parser.cpp b/Marlin/src/feature/e_parser.cpp
index e7d79bf745..a4c2d0dac9 100644
--- a/Marlin/src/feature/e_parser.cpp
+++ b/Marlin/src/feature/e_parser.cpp
@@ -16,12 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
/**
- * emergency_parser.cpp - Intercept special commands directly in the serial stream
+ * e_parser.cpp - Intercept special commands directly in the serial stream
*/
#include "../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/feature/e_parser.h b/Marlin/src/feature/e_parser.h
index 41261402a1..8d11463ecd 100644
--- a/Marlin/src/feature/e_parser.h
+++ b/Marlin/src/feature/e_parser.h
@@ -16,13 +16,13 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
/**
- * emergency_parser.h - Intercept special commands directly in the serial stream
+ * e_parser.h - Intercept special commands directly in the serial stream
*/
#include "../inc/MarlinConfigPre.h"
diff --git a/Marlin/src/feature/encoder_i2c.cpp b/Marlin/src/feature/encoder_i2c.cpp
index a70227a270..f67d50a6e0 100644
--- a/Marlin/src/feature/encoder_i2c.cpp
+++ b/Marlin/src/feature/encoder_i2c.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -107,7 +107,7 @@ void I2CPositionEncoder::update() {
SERIAL_ECHOLNPAIR("New zero-offset of ", zeroOffset);
SERIAL_ECHOPAIR("New position reads as ", get_position());
SERIAL_CHAR('(');
- SERIAL_ECHO(mm_from_count(get_position()));
+ SERIAL_DECIMAL(mm_from_count(get_position()));
SERIAL_ECHOLNPGM(")");
#endif
}
@@ -305,7 +305,7 @@ int32_t I2CPositionEncoder::get_raw_count() {
encoderCount.val = 0x00;
- if (Wire.requestFrom((int)i2cAddress, 3) != 3) {
+ if (Wire.requestFrom(I2C_ADDRESS(i2cAddress), uint8_t(3)) != 3) {
//houston, we have a problem...
H = I2CPE_MAG_SIG_NF;
return 0;
@@ -459,9 +459,7 @@ void I2CPositionEncoder::reset() {
Wire.write(I2CPE_RESET_COUNT);
Wire.endTransmission();
- #if ENABLED(I2CPE_ERR_ROLLING_AVERAGE)
- ZERO(err);
- #endif
+ TERN_(I2CPE_ERR_ROLLING_AVERAGE, ZERO(err));
}
@@ -746,7 +744,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
Wire.endTransmission();
// Read value
- if (Wire.requestFrom((int)address, 32)) {
+ if (Wire.requestFrom(I2C_ADDRESS(address), uint8_t(32))) {
char c;
while (Wire.available() > 0 && (c = (char)Wire.read()) > 0)
SERIAL_ECHO(c);
diff --git a/Marlin/src/feature/encoder_i2c.h b/Marlin/src/feature/encoder_i2c.h
index 0665ee809d..511e560ba0 100644
--- a/Marlin/src/feature/encoder_i2c.h
+++ b/Marlin/src/feature/encoder_i2c.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -280,13 +280,13 @@ class I2CPositionEncodersMgr {
static void set_ec_threshold(const int8_t idx, const float newThreshold, const AxisEnum axis) {
CHECK_IDX();
encoders[idx].set_ec_threshold(newThreshold);
- SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis set to ", FIXFLOAT(newThreshold), "mm.");
+ SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis set to ", newThreshold, "mm.");
}
static void get_ec_threshold(const int8_t idx, const AxisEnum axis) {
CHECK_IDX();
const float threshold = encoders[idx].get_ec_threshold();
- SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis is ", FIXFLOAT(threshold), "mm.");
+ SERIAL_ECHOLNPAIR("Error correct threshold for ", axis_codes[axis], " axis is ", threshold, "mm.");
}
static int8_t idx_from_axis(const AxisEnum axis) {
diff --git a/Marlin/src/feature/fanmux.cpp b/Marlin/src/feature/fanmux.cpp
index b90c72c648..43952ca8ee 100644
--- a/Marlin/src/feature/fanmux.cpp
+++ b/Marlin/src/feature/fanmux.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/fanmux.h b/Marlin/src/feature/fanmux.h
index 2e54144478..b1b0c67a55 100644
--- a/Marlin/src/feature/fanmux.h
+++ b/Marlin/src/feature/fanmux.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/filwidth.cpp b/Marlin/src/feature/filwidth.cpp
index 4357d39fe0..2bd9c78980 100644
--- a/Marlin/src/feature/filwidth.cpp
+++ b/Marlin/src/feature/filwidth.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/filwidth.h b/Marlin/src/feature/filwidth.h
index 335a49b74f..ef3859df71 100644
--- a/Marlin/src/feature/filwidth.h
+++ b/Marlin/src/feature/filwidth.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/fwretract.cpp b/Marlin/src/feature/fwretract.cpp
index 7d756ac6d0..c0e4db0a45 100644
--- a/Marlin/src/feature/fwretract.cpp
+++ b/Marlin/src/feature/fwretract.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -60,9 +60,7 @@ float FWRetract::current_retract[EXTRUDERS], // Retract value used by p
FWRetract::current_hop;
void FWRetract::reset() {
- #if ENABLED(FWRETRACT_AUTORETRACT)
- autoretract_enabled = false;
- #endif
+ TERN_(FWRETRACT_AUTORETRACT, autoretract_enabled = false);
settings.retract_length = RETRACT_LENGTH;
settings.retract_feedrate_mm_s = RETRACT_FEEDRATE;
settings.retract_zraise = RETRACT_ZRAISE;
@@ -95,7 +93,7 @@ void FWRetract::reset() {
*/
void FWRetract::retract(const bool retracting
#if EXTRUDERS > 1
- , bool swapping /* =false */
+ , bool swapping/*=false*/
#endif
) {
// Prevent two retracts or recovers in a row
@@ -128,12 +126,8 @@ void FWRetract::retract(const bool retracting
SERIAL_ECHOLNPAIR("current_hop ", current_hop);
//*/
- const float base_retract = (
- (swapping ? settings.swap_retract_length : settings.retract_length)
- #if ENABLED(RETRACT_SYNC_MIXING)
- * (MIXING_STEPPERS)
- #endif
- );
+ const float base_retract = TERN1(RETRACT_SYNC_MIXING, (MIXING_STEPPERS))
+ * (swapping ? settings.swap_retract_length : settings.retract_length);
// The current position will be the destination for E and Z moves
destination = current_position;
@@ -148,10 +142,7 @@ void FWRetract::retract(const bool retracting
// Retract by moving from a faux E position back to the current E position
current_retract[active_extruder] = base_retract;
prepare_internal_move_to_destination( // set current to destination
- settings.retract_feedrate_mm_s
- #if ENABLED(RETRACT_SYNC_MIXING)
- * (MIXING_STEPPERS)
- #endif
+ settings.retract_feedrate_mm_s * TERN1(RETRACT_SYNC_MIXING, (MIXING_STEPPERS))
);
// Is a Z hop set, and has the hop not yet been done?
@@ -177,18 +168,14 @@ void FWRetract::retract(const bool retracting
current_retract[active_extruder] = 0;
- const feedRate_t fr_mm_s = (
+ // Recover E, set_current_to_destination
+ prepare_internal_move_to_destination(
(swapping ? settings.swap_retract_recover_feedrate_mm_s : settings.retract_recover_feedrate_mm_s)
- #if ENABLED(RETRACT_SYNC_MIXING)
- * (MIXING_STEPPERS)
- #endif
+ * TERN1(RETRACT_SYNC_MIXING, (MIXING_STEPPERS))
);
- prepare_internal_move_to_destination(fr_mm_s); // Recover E, set_current_to_destination
}
- #if ENABLED(RETRACT_SYNC_MIXING)
- mixer.T(old_mixing_tool); // Restore original mixing tool
- #endif
+ TERN_(RETRACT_SYNC_MIXING, mixer.T(old_mixing_tool)); // Restore original mixing tool
retracted[active_extruder] = retracting; // Active extruder now retracted / recovered
diff --git a/Marlin/src/feature/fwretract.h b/Marlin/src/feature/fwretract.h
index e08f8f03af..3d68736429 100644
--- a/Marlin/src/feature/fwretract.h
+++ b/Marlin/src/feature/fwretract.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/host_actions.cpp b/Marlin/src/feature/host_actions.cpp
index 2108f4e7f4..9539c82b64 100644
--- a/Marlin/src/feature/host_actions.cpp
+++ b/Marlin/src/feature/host_actions.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -37,7 +37,8 @@
#include "runout.h"
#endif
-void host_action(const char * const pstr, const bool eol) {
+void host_action(PGM_P const pstr, const bool eol) {
+ PORT_REDIRECT(SERIAL_BOTH);
SERIAL_ECHOPGM("//action:");
serialprintPGM(pstr);
if (eol) SERIAL_EOL();
@@ -64,8 +65,8 @@ void host_action(const char * const pstr, const bool eol) {
#if ENABLED(HOST_PROMPT_SUPPORT)
- const char CONTINUE_STR[] PROGMEM = "Continue",
- DISMISS_STR[] PROGMEM = "Dismiss";
+ PGMSTR(CONTINUE_STR, "Continue");
+ PGMSTR(DISMISS_STR, "Dismiss");
#if HAS_RESUME_CONTINUE
extern bool wait_for_user;
@@ -74,33 +75,42 @@ void host_action(const char * const pstr, const bool eol) {
PromptReason host_prompt_reason = PROMPT_NOT_DEFINED;
void host_action_notify(const char * const message) {
+ PORT_REDIRECT(SERIAL_BOTH);
+ host_action(PSTR("notification "), false);
+ SERIAL_ECHOLN(message);
+ }
+
+ void host_action_notify_P(PGM_P const message) {
+ PORT_REDIRECT(SERIAL_BOTH);
host_action(PSTR("notification "), false);
serialprintPGM(message);
SERIAL_EOL();
}
- void host_action_prompt(const char * const ptype, const bool eol=true) {
+ void host_action_prompt(PGM_P const ptype, const bool eol=true) {
+ PORT_REDIRECT(SERIAL_BOTH);
host_action(PSTR("prompt_"), false);
serialprintPGM(ptype);
if (eol) SERIAL_EOL();
}
- void host_action_prompt_plus(const char * const ptype, const char * const pstr, const char extra_char='\0') {
+ void host_action_prompt_plus(PGM_P const ptype, PGM_P const pstr, const char extra_char='\0') {
host_action_prompt(ptype, false);
+ PORT_REDIRECT(SERIAL_BOTH);
SERIAL_CHAR(' ');
serialprintPGM(pstr);
if (extra_char != '\0') SERIAL_CHAR(extra_char);
SERIAL_EOL();
}
- void host_action_prompt_begin(const PromptReason reason, const char * const pstr, const char extra_char/*='\0'*/) {
+ void host_action_prompt_begin(const PromptReason reason, PGM_P const pstr, const char extra_char/*='\0'*/) {
host_action_prompt_end();
host_prompt_reason = reason;
host_action_prompt_plus(PSTR("begin"), pstr, extra_char);
}
- void host_action_prompt_button(const char * const pstr) { host_action_prompt_plus(PSTR("button"), pstr); }
+ void host_action_prompt_button(PGM_P const pstr) { host_action_prompt_plus(PSTR("button"), pstr); }
void host_action_prompt_end() { host_action_prompt(PSTR("end")); }
void host_action_prompt_show() { host_action_prompt(PSTR("show")); }
- void host_prompt_do(const PromptReason reason, const char * const pstr, const char * const btn1/*=nullptr*/, const char * const btn2/*=nullptr*/) {
+ void host_prompt_do(const PromptReason reason, PGM_P const pstr, PGM_P const btn1/*=nullptr*/, PGM_P const btn2/*=nullptr*/) {
host_action_prompt_begin(reason, pstr);
if (btn1) host_action_prompt_button(btn1);
if (btn2) host_action_prompt_button(btn2);
@@ -108,11 +118,7 @@ void host_action(const char * const pstr, const bool eol) {
}
void filament_load_host_prompt() {
- const bool disable_to_continue = (false
- #if HAS_FILAMENT_SENSOR
- || runout.filament_ran_out
- #endif
- );
+ const bool disable_to_continue = TERN0(HAS_FILAMENT_SENSOR, runout.filament_ran_out);
host_prompt_do(PROMPT_FILAMENT_RUNOUT, PSTR("Paused"), PSTR("PurgeMore"),
disable_to_continue ? PSTR("DisableRunout") : CONTINUE_STR
);
@@ -127,11 +133,11 @@ void host_action(const char * const pstr, const bool eol) {
//
void host_response_handler(const uint8_t response) {
#ifdef DEBUG_HOST_ACTIONS
- static const char m876_prefix[] PROGMEM = "M876 Handle Re";
+ static PGMSTR(m876_prefix, "M876 Handle Re");
serialprintPGM(m876_prefix); SERIAL_ECHOLNPAIR("ason: ", host_prompt_reason);
serialprintPGM(m876_prefix); SERIAL_ECHOLNPAIR("sponse: ", response);
#endif
- const char *msg = PSTR("UNKNOWN STATE");
+ PGM_P msg = PSTR("UNKNOWN STATE");
const PromptReason hpr = host_prompt_reason;
host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic
switch (hpr) {
@@ -140,14 +146,14 @@ void host_action(const char * const pstr, const bool eol) {
switch (response) {
case 0: // "Purge More" button
- #if HAS_LCD_MENU && ENABLED(ADVANCED_PAUSE_FEATURE)
+ #if BOTH(HAS_LCD_MENU, ADVANCED_PAUSE_FEATURE)
pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more)
#endif
filament_load_host_prompt(); // Initiate another host prompt. (NOTE: The loop in load_filament may also do this!)
break;
case 1: // "Continue" / "Disable Runout" button
- #if HAS_LCD_MENU && ENABLED(ADVANCED_PAUSE_FEATURE)
+ #if BOTH(HAS_LCD_MENU, ADVANCED_PAUSE_FEATURE)
pause_menu_response = PAUSE_RESPONSE_RESUME_PRINT; // Simulate menu selection
#endif
#if HAS_FILAMENT_SENSOR
@@ -160,9 +166,7 @@ void host_action(const char * const pstr, const bool eol) {
}
break;
case PROMPT_USER_CONTINUE:
- #if HAS_RESUME_CONTINUE
- wait_for_user = false;
- #endif
+ TERN_(HAS_RESUME_CONTINUE, wait_for_user = false);
msg = PSTR("FILAMENT_RUNOUT_CONTINUE");
break;
case PROMPT_PAUSE_RESUME:
diff --git a/Marlin/src/feature/host_actions.h b/Marlin/src/feature/host_actions.h
index 3667b7f430..a6ad2c0485 100644
--- a/Marlin/src/feature/host_actions.h
+++ b/Marlin/src/feature/host_actions.h
@@ -16,14 +16,15 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
#include "../inc/MarlinConfigPre.h"
+#include "../HAL/shared/Marduino.h"
-void host_action(const char * const pstr, const bool eol=true);
+void host_action(PGM_P const pstr, const bool eol=true);
#ifdef ACTION_ON_KILL
void host_action_kill();
@@ -61,12 +62,13 @@ void host_action(const char * const pstr, const bool eol=true);
void host_response_handler(const uint8_t response);
void host_action_notify(const char * const message);
- void host_action_prompt_begin(const PromptReason reason, const char * const pstr, const char extra_char='\0');
- void host_action_prompt_button(const char * const pstr);
+ void host_action_notify_P(PGM_P const message);
+ void host_action_prompt_begin(const PromptReason reason, PGM_P const pstr, const char extra_char='\0');
+ void host_action_prompt_button(PGM_P const pstr);
void host_action_prompt_end();
void host_action_prompt_show();
- void host_prompt_do(const PromptReason reason, const char * const pstr, const char * const btn1=nullptr, const char * const btn2=nullptr);
- inline void host_prompt_open(const PromptReason reason, const char * const pstr, const char * const btn1=nullptr, const char * const btn2=nullptr) {
+ void host_prompt_do(const PromptReason reason, PGM_P const pstr, PGM_P const btn1=nullptr, PGM_P const btn2=nullptr);
+ inline void host_prompt_open(const PromptReason reason, PGM_P const pstr, PGM_P const btn1=nullptr, PGM_P const btn2=nullptr) {
if (host_prompt_reason == PROMPT_NOT_DEFINED) host_prompt_do(reason, pstr, btn1, btn2);
}
diff --git a/Marlin/src/feature/hotend_idle.cpp b/Marlin/src/feature/hotend_idle.cpp
new file mode 100644
index 0000000000..9d5594c2f1
--- /dev/null
+++ b/Marlin/src/feature/hotend_idle.cpp
@@ -0,0 +1,89 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+/**
+ * Hotend Idle Timeout
+ * Prevent filament in the nozzle from charring and causing a critical jam.
+ */
+
+#include "../inc/MarlinConfig.h"
+
+#if ENABLED(HOTEND_IDLE_TIMEOUT)
+
+#include "hotend_idle.h"
+#include "../gcode/gcode.h"
+
+#include "../module/temperature.h"
+#include "../module/motion.h"
+#include "../lcd/ultralcd.h"
+
+extern HotendIdleProtection hotend_idle;
+
+millis_t HotendIdleProtection::next_protect_ms = 0;
+
+void HotendIdleProtection::check_hotends(const millis_t &ms) {
+ bool do_prot = false;
+ HOTEND_LOOP() {
+ if (thermalManager.degHotend(e) >= HOTEND_IDLE_MIN_TRIGGER) {
+ do_prot = true; break;
+ }
+ }
+ if (bool(next_protect_ms) != do_prot)
+ next_protect_ms = do_prot ? ms + hp_interval : 0;
+}
+
+void HotendIdleProtection::check_e_motion(const millis_t &ms) {
+ static float old_e_position = 0;
+ if (old_e_position != current_position.e) {
+ old_e_position = current_position.e; // Track filament motion
+ if (next_protect_ms) // If some heater is on then...
+ next_protect_ms = ms + hp_interval; // ...delay the timeout till later
+ }
+}
+
+void HotendIdleProtection::check() {
+ const millis_t ms = millis(); // Shared millis
+
+ check_hotends(ms); // Any hotends need protection?
+ check_e_motion(ms); // Motion will protect them
+
+ // Hot and not moving for too long...
+ if (next_protect_ms && ELAPSED(ms, next_protect_ms))
+ timed_out();
+}
+
+// Lower (but don't raise) hotend / bed temperatures
+void HotendIdleProtection::timed_out() {
+ next_protect_ms = 0;
+ SERIAL_ECHOLNPGM("Hotend Idle Timeout");
+ LCD_MESSAGEPGM(MSG_HOTEND_IDLE_TIMEOUT);
+ HOTEND_LOOP() {
+ if ((HOTEND_IDLE_NOZZLE_TARGET) < thermalManager.degTargetHotend(e))
+ thermalManager.setTargetHotend(HOTEND_IDLE_NOZZLE_TARGET, e);
+ }
+ #if HAS_HEATED_BED
+ if ((HOTEND_IDLE_BED_TARGET) < thermalManager.degTargetBed())
+ thermalManager.setTargetBed(HOTEND_IDLE_BED_TARGET);
+ #endif
+}
+
+#endif // HOTEND_IDLE_TIMEOUT
diff --git a/Marlin/src/feature/hotend_idle.h b/Marlin/src/feature/hotend_idle.h
new file mode 100644
index 0000000000..40f557d5ed
--- /dev/null
+++ b/Marlin/src/feature/hotend_idle.h
@@ -0,0 +1,37 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "../core/millis_t.h"
+
+class HotendIdleProtection {
+public:
+ static void check();
+private:
+ static constexpr millis_t hp_interval = SEC_TO_MS(HOTEND_IDLE_TIMEOUT_SEC);
+ static millis_t next_protect_ms;
+ static void check_hotends(const millis_t &ms);
+ static void check_e_motion(const millis_t &ms);
+ static void timed_out();
+};
+
+extern HotendIdleProtection hotend_idle;
diff --git a/Marlin/src/feature/joystick.cpp b/Marlin/src/feature/joystick.cpp
index 66afb63b05..d9c5ae7c1b 100644
--- a/Marlin/src/feature/joystick.cpp
+++ b/Marlin/src/feature/joystick.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -154,9 +154,7 @@ Joystick joystick;
// Other non-joystick poll-based jogging could be implemented here
// with "jogging" encapsulated as a more general class.
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::_joystick_update(norm_jog);
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::_joystick_update(norm_jog));
// norm_jog values of [-1 .. 1] maps linearly to [-feedrate .. feedrate]
xyz_float_t move_dist{0};
diff --git a/Marlin/src/feature/joystick.h b/Marlin/src/feature/joystick.h
index 12f9554a71..ca46834578 100644
--- a/Marlin/src/feature/joystick.h
+++ b/Marlin/src/feature/joystick.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -35,19 +35,11 @@
class Joystick {
friend class Temperature;
private:
- #if HAS_JOY_ADC_X
- static temp_info_t x;
- #endif
- #if HAS_JOY_ADC_Y
- static temp_info_t y;
- #endif
- #if HAS_JOY_ADC_Z
- static temp_info_t z;
- #endif
+ TERN_(HAS_JOY_ADC_X, static temp_info_t x);
+ TERN_(HAS_JOY_ADC_Y, static temp_info_t y);
+ TERN_(HAS_JOY_ADC_Z, static temp_info_t z);
public:
- #if ENABLED(JOYSTICK_DEBUG)
- static void report();
- #endif
+ TERN_(JOYSTICK_DEBUG, static void report());
static void calculate(xyz_float_t &norm_jog);
static void inject_jog_moves();
};
diff --git a/Marlin/src/feature/leds/blinkm.cpp b/Marlin/src/feature/leds/blinkm.cpp
index 1c7ceeb669..868eb4b3d9 100644
--- a/Marlin/src/feature/leds/blinkm.cpp
+++ b/Marlin/src/feature/leds/blinkm.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/leds/blinkm.h b/Marlin/src/feature/leds/blinkm.h
index c7c099d3a8..29a9e78412 100644
--- a/Marlin/src/feature/leds/blinkm.h
+++ b/Marlin/src/feature/leds/blinkm.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/leds/leds.cpp b/Marlin/src/feature/leds/leds.cpp
index 995693ffc5..01bca80926 100644
--- a/Marlin/src/feature/leds/leds.cpp
+++ b/Marlin/src/feature/leds/leds.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -39,16 +39,13 @@
#endif
#if ENABLED(PCA9533)
- #include
+ #include "pca9533.h"
#endif
#if ENABLED(LED_COLOR_PRESETS)
const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
- LED_USER_PRESET_RED,
- LED_USER_PRESET_GREEN,
- LED_USER_PRESET_BLUE,
- LED_USER_PRESET_WHITE,
- LED_USER_PRESET_BRIGHTNESS
+ LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE,
+ LED_USER_PRESET_WHITE, LED_USER_PRESET_BRIGHTNESS
);
#endif
@@ -68,15 +65,9 @@ void LEDLights::setup() {
if (PWM_PIN(RGB_LED_W_PIN)) SET_PWM(RGB_LED_W_PIN); else SET_OUTPUT(RGB_LED_W_PIN);
#endif
#endif
- #if ENABLED(NEOPIXEL_LED)
- neo.init();
- #endif
- #if ENABLED(PCA9533)
- RGBinit();
- #endif
- #if ENABLED(LED_USER_PRESET_STARTUP)
- set_default();
- #endif
+ TERN_(NEOPIXEL_LED, neo.init());
+ TERN_(PCA9533, PCA9533_init());
+ TERN_(LED_USER_PRESET_STARTUP, set_default());
}
void LEDLights::set_color(const LEDColor &incol
@@ -123,26 +114,22 @@ void LEDLights::set_color(const LEDColor &incol
// This variant uses 3-4 separate pins for the RGB(W) components.
// If the pins can do PWM then their intensity will be set.
- #define UPDATE_RGBW(C,c) do { if (PWM_PIN(RGB_LED_##C##_PIN)) \
+ #define UPDATE_RGBW(C,c) do { \
+ if (PWM_PIN(RGB_LED_##C##_PIN)) \
analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \
- else WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); }while(0)
- UPDATE_RGBW(R,r);
- UPDATE_RGBW(G,g);
- UPDATE_RGBW(B,b);
+ else \
+ WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); \
+ }while(0)
+ UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b);
#if ENABLED(RGBW_LED)
UPDATE_RGBW(W,w);
#endif
#endif
- #if ENABLED(PCA9632)
- // Update I2C LED driver
- pca9632_set_led_color(incol);
- #endif
-
- #if ENABLED(PCA9533)
- RGBsetColor(incol.r, incol.g, incol.b, true);
- #endif
+ // Update I2C LED driver
+ TERN_(PCA9632, PCA9632_set_led_color(incol));
+ TERN_(PCA9533, PCA9533_set_rgb(incol.r, incol.g, incol.b));
#if EITHER(LED_CONTROL_MENU, PRINTER_EVENT_LEDS)
// Don't update the color when OFF
@@ -169,4 +156,35 @@ void LEDLights::set_color(const LEDColor &incol
#endif
-#endif // HAS_COLOR_LEDS
+#if ENABLED(NEOPIXEL2_SEPARATE)
+
+ #if ENABLED(NEO2_COLOR_PRESETS)
+ const LEDColor LEDLights2::defaultLEDColor = MakeLEDColor(
+ NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE,
+ NEO2_USER_PRESET_WHITE, NEO2_USER_PRESET_BRIGHTNESS
+ );
+ #endif
+
+ #if ENABLED(LED_CONTROL_MENU)
+ LEDColor LEDLights2::color;
+ bool LEDLights2::lights_on;
+ #endif
+
+ LEDLights2 leds2;
+
+ void LEDLights2::setup() {
+ neo2.init();
+ TERN_(NEO2_USER_PRESET_STARTUP, set_default());
+ }
+
+ void LEDLights2::set_color(const LEDColor &incol) {
+ const uint32_t neocolor = LEDColorWhite() == incol
+ ? neo2.Color(NEO2_WHITE)
+ : neo2.Color(incol.r, incol.g, incol.b, incol.w);
+ neo2.set_brightness(incol.i);
+ neo2.set_color(neocolor);
+ }
+
+#endif // NEOPIXEL2_SEPARATE
+
+#endif // HAS_COLOR_LEDS
diff --git a/Marlin/src/feature/leds/leds.h b/Marlin/src/feature/leds/leds.h
index 22184381fc..a13f960a3b 100644
--- a/Marlin/src/feature/leds/leds.h
+++ b/Marlin/src/feature/leds/leds.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -34,7 +34,9 @@
#endif
// A white component can be passed
-#define HAS_WHITE_LED EITHER(RGBW_LED, NEOPIXEL_LED)
+#if EITHER(RGBW_LED, NEOPIXEL_LED)
+ #define HAS_WHITE_LED 1
+#endif
/**
* LEDcolor type for use with leds.set_color
@@ -85,9 +87,7 @@ typedef struct LEDColor {
LEDColor& operator=(const uint8_t (&rgbw)[4]) {
r = rgbw[0]; g = rgbw[1]; b = rgbw[2];
- #if HAS_WHITE_LED
- w = rgbw[3];
- #endif
+ TERN_(HAS_WHITE_LED, w = rgbw[3]);
return *this;
}
@@ -104,11 +104,7 @@ typedef struct LEDColor {
bool operator!=(const LEDColor &right) { return !operator==(right); }
bool is_off() const {
- return 3 > r + g + b
- #if HAS_WHITE_LED
- + w
- #endif
- ;
+ return 3 > r + g + b + TERN0(HAS_WHITE_LED, w);
}
} LEDColor;
@@ -156,14 +152,12 @@ public:
#endif
);
- inline void set_color(uint8_t r, uint8_t g, uint8_t b
+ static inline void set_color(uint8_t r, uint8_t g, uint8_t b
#if HAS_WHITE_LED
, uint8_t w=0
- #if ENABLED(NEOPIXEL_LED)
- , uint8_t i=NEOPIXEL_BRIGHTNESS
- #endif
#endif
#if ENABLED(NEOPIXEL_LED)
+ , uint8_t i=NEOPIXEL_BRIGHTNESS
, bool isSequence=false
#endif
) {
@@ -216,3 +210,44 @@ public:
};
extern LEDLights leds;
+
+#if ENABLED(NEOPIXEL2_SEPARATE)
+
+ class LEDLights2 {
+ public:
+ LEDLights2() {}
+
+ static void setup(); // init()
+
+ static void set_color(const LEDColor &color);
+
+ inline void set_color(uint8_t r, uint8_t g, uint8_t b, uint8_t w=0, uint8_t i=NEOPIXEL2_BRIGHTNESS) {
+ set_color(MakeLEDColor(r, g, b, w, i));
+ }
+
+ static inline void set_off() { set_color(LEDColorOff()); }
+ static inline void set_green() { set_color(LEDColorGreen()); }
+ static inline void set_white() { set_color(LEDColorWhite()); }
+
+ #if ENABLED(NEO2_COLOR_PRESETS)
+ static const LEDColor defaultLEDColor;
+ static inline void set_default() { set_color(defaultLEDColor); }
+ static inline void set_red() { set_color(LEDColorRed()); }
+ static inline void set_orange() { set_color(LEDColorOrange()); }
+ static inline void set_yellow() { set_color(LEDColorYellow()); }
+ static inline void set_blue() { set_color(LEDColorBlue()); }
+ static inline void set_indigo() { set_color(LEDColorIndigo()); }
+ static inline void set_violet() { set_color(LEDColorViolet()); }
+ #endif
+
+ #if ENABLED(LED_CONTROL_MENU)
+ static LEDColor color; // last non-off color
+ static bool lights_on; // the last set color was "on"
+ static void toggle(); // swap "off" with color
+ static inline void update() { set_color(color); }
+ #endif
+ };
+
+ extern LEDLights2 leds2;
+
+#endif // NEOPIXEL2_SEPARATE
diff --git a/Marlin/src/feature/leds/neopixel.cpp b/Marlin/src/feature/leds/neopixel.cpp
index 892ebe15cb..27bbeb348c 100644
--- a/Marlin/src/feature/leds/neopixel.cpp
+++ b/Marlin/src/feature/leds/neopixel.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -30,14 +30,15 @@
#include "neopixel.h"
-#if ENABLED(NEOPIXEL_STARTUP_TEST)
+#if EITHER(NEOPIXEL_STARTUP_TEST, NEOPIXEL2_STARTUP_TEST)
#include "../../core/utility.h"
#endif
Marlin_NeoPixel neo;
+int8_t Marlin_NeoPixel::neoindex;
Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIXEL_TYPE + NEO_KHZ800)
- #if MULTIPLE_NEOPIXEL_TYPES
+ #if CONJOINED_NEOPIXEL
, Marlin_NeoPixel::adaneo2(NEOPIXEL_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE + NEO_KHZ800)
#endif
;
@@ -52,14 +53,20 @@ Adafruit_NeoPixel Marlin_NeoPixel::adaneo1(NEOPIXEL_PIXELS, NEOPIXEL_PIN, NEOPIX
#endif
void Marlin_NeoPixel::set_color(const uint32_t color) {
- for (uint16_t i = 0; i < pixels(); ++i) {
- #ifdef NEOPIXEL_BKGD_LED_INDEX
- if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
- set_color_background();
- continue;
- }
- #endif
- set_pixel_color(i, color);
+ if (neoindex >= 0) {
+ set_pixel_color(neoindex, color);
+ neoindex = -1;
+ }
+ else {
+ for (uint16_t i = 0; i < pixels(); ++i) {
+ #ifdef NEOPIXEL_BKGD_LED_INDEX
+ if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) {
+ set_color_background();
+ continue;
+ }
+ #endif
+ set_pixel_color(i, color);
+ }
}
show();
}
@@ -71,19 +78,18 @@ void Marlin_NeoPixel::set_color_startup(const uint32_t color) {
}
void Marlin_NeoPixel::init() {
- SET_OUTPUT(NEOPIXEL_PIN);
- set_brightness(NEOPIXEL_BRIGHTNESS); // 0 - 255 range
+ neoindex = -1; // -1 .. NEOPIXEL_PIXELS-1 range
+ set_brightness(NEOPIXEL_BRIGHTNESS); // 0 .. 255 range
begin();
show(); // initialize to all off
#if ENABLED(NEOPIXEL_STARTUP_TEST)
- safe_delay(1000);
set_color_startup(adaneo1.Color(255, 0, 0, 0)); // red
- safe_delay(1000);
+ safe_delay(500);
set_color_startup(adaneo1.Color(0, 255, 0, 0)); // green
- safe_delay(1000);
+ safe_delay(500);
set_color_startup(adaneo1.Color(0, 0, 255, 0)); // blue
- safe_delay(1000);
+ safe_delay(500);
#endif
#ifdef NEOPIXEL_BKGD_LED_INDEX
@@ -114,4 +120,53 @@ bool Marlin_NeoPixel::set_led_color(const uint8_t r, const uint8_t g, const uint
}
#endif
+#if ENABLED(NEOPIXEL2_SEPARATE)
+
+ Marlin_NeoPixel2 neo2;
+
+ int8_t Marlin_NeoPixel2::neoindex;
+ Adafruit_NeoPixel Marlin_NeoPixel2::adaneo(NEOPIXEL2_PIXELS, NEOPIXEL2_PIN, NEOPIXEL2_TYPE);
+
+ void Marlin_NeoPixel2::set_color(const uint32_t color) {
+ if (neoindex >= 0) {
+ set_pixel_color(neoindex, color);
+ neoindex = -1;
+ }
+ else {
+ for (uint16_t i = 0; i < pixels(); ++i)
+ set_pixel_color(i, color);
+ }
+ show();
+ }
+
+ void Marlin_NeoPixel2::set_color_startup(const uint32_t color) {
+ for (uint16_t i = 0; i < pixels(); ++i)
+ set_pixel_color(i, color);
+ show();
+ }
+
+ void Marlin_NeoPixel2::init() {
+ neoindex = -1; // -1 .. NEOPIXEL2_PIXELS-1 range
+ set_brightness(NEOPIXEL2_BRIGHTNESS); // 0 .. 255 range
+ begin();
+ show(); // initialize to all off
+
+ #if ENABLED(NEOPIXEL2_STARTUP_TEST)
+ set_color_startup(adaneo.Color(255, 0, 0, 0)); // red
+ safe_delay(500);
+ set_color_startup(adaneo.Color(0, 255, 0, 0)); // green
+ safe_delay(500);
+ set_color_startup(adaneo.Color(0, 0, 255, 0)); // blue
+ safe_delay(500);
+ #endif
+
+ #if ENABLED(NEO2_USER_PRESET_STARTUP)
+ set_color(adaneo.Color(NEO2_USER_PRESET_RED, NEO2_USER_PRESET_GREEN, NEO2_USER_PRESET_BLUE, NEO2_USER_PRESET_WHITE));
+ #else
+ set_color(adaneo.Color(0, 0, 0, 0));
+ #endif
+ }
+
+#endif // NEOPIXEL2_SEPARATE
+
#endif // NEOPIXEL_LED
diff --git a/Marlin/src/feature/leds/neopixel.h b/Marlin/src/feature/leds/neopixel.h
index 11e435b830..81a0a8b1c6 100644
--- a/Marlin/src/feature/leds/neopixel.h
+++ b/Marlin/src/feature/leds/neopixel.h
@@ -16,13 +16,13 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
/**
- * Neopixel support
+ * NeoPixel support
*/
// ------------------------
@@ -38,10 +38,19 @@
// Defines
// ------------------------
-#define MULTIPLE_NEOPIXEL_TYPES (defined(NEOPIXEL2_TYPE) && (NEOPIXEL2_TYPE != NEOPIXEL_TYPE))
+#if defined(NEOPIXEL2_TYPE) && NEOPIXEL2_TYPE != NEOPIXEL_TYPE && DISABLED(NEOPIXEL2_SEPARATE)
+ #define MULTIPLE_NEOPIXEL_TYPES 1
+#endif
-#define NEOPIXEL_IS_RGB (NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR)
-#define NEOPIXEL_IS_RGBW !NEOPIXEL_IS_RGB
+#if EITHER(MULTIPLE_NEOPIXEL_TYPES, NEOPIXEL2_INSERIES)
+ #define CONJOINED_NEOPIXEL 1
+#endif
+
+#if NEOPIXEL_TYPE == NEO_RGB || NEOPIXEL_TYPE == NEO_RBG || NEOPIXEL_TYPE == NEO_GRB || NEOPIXEL_TYPE == NEO_GBR || NEOPIXEL_TYPE == NEO_BRG || NEOPIXEL_TYPE == NEO_BGR
+ #define NEOPIXEL_IS_RGB 1
+#else
+ #define NEOPIXEL_IS_RGBW 1
+#endif
#if NEOPIXEL_IS_RGB
#define NEO_WHITE 255, 255, 255, 0
@@ -56,12 +65,14 @@
class Marlin_NeoPixel {
private:
static Adafruit_NeoPixel adaneo1
- #if MULTIPLE_NEOPIXEL_TYPES
+ #if CONJOINED_NEOPIXEL
, adaneo2
#endif
;
public:
+ static int8_t neoindex;
+
static void init();
static void set_color_startup(const uint32_t c);
@@ -73,29 +84,30 @@ public:
static inline void begin() {
adaneo1.begin();
- #if MULTIPLE_NEOPIXEL_TYPES
- adaneo2.begin();
- #endif
+ TERN_(CONJOINED_NEOPIXEL, adaneo2.begin());
}
static inline void set_pixel_color(const uint16_t n, const uint32_t c) {
- adaneo1.setPixelColor(n, c);
- #if MULTIPLE_NEOPIXEL_TYPES
- adaneo2.setPixelColor(n, c);
+ #if ENABLED(NEOPIXEL2_INSERIES)
+ if (n >= NEOPIXEL_PIXELS) adaneo2.setPixelColor(n - (NEOPIXEL_PIXELS), c);
+ else adaneo1.setPixelColor(n, c);
+ #else
+ adaneo1.setPixelColor(n, c);
+ #if MULTIPLE_NEOPIXEL_TYPES
+ adaneo2.setPixelColor(n, c);
+ #endif
#endif
}
static inline void set_brightness(const uint8_t b) {
adaneo1.setBrightness(b);
- #if MULTIPLE_NEOPIXEL_TYPES
- adaneo2.setBrightness(b);
- #endif
+ TERN_(CONJOINED_NEOPIXEL, adaneo2.setBrightness(b));
}
static inline void show() {
adaneo1.show();
#if PIN_EXISTS(NEOPIXEL2)
- #if MULTIPLE_NEOPIXEL_TYPES
+ #if CONJOINED_NEOPIXEL
adaneo2.show();
#else
adaneo1.setPin(NEOPIXEL2_PIN);
@@ -110,7 +122,7 @@ public:
#endif
// Accessors
- static inline uint16_t pixels() { return adaneo1.numPixels(); }
+ static inline uint16_t pixels() { TERN(NEOPIXEL2_INSERIES, return adaneo1.numPixels() * 2, return adaneo1.numPixels()); }
static inline uint8_t brightness() { return adaneo1.getBrightness(); }
static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
return adaneo1.Color(r, g, b, w);
@@ -118,3 +130,47 @@ public:
};
extern Marlin_NeoPixel neo;
+
+// Neo pixel channel 2
+#if ENABLED(NEOPIXEL2_SEPARATE)
+
+ #if NEOPIXEL2_TYPE == NEO_RGB || NEOPIXEL2_TYPE == NEO_RBG || NEOPIXEL2_TYPE == NEO_GRB || NEOPIXEL2_TYPE == NEO_GBR || NEOPIXEL2_TYPE == NEO_BRG || NEOPIXEL2_TYPE == NEO_BGR
+ #define NEOPIXEL2_IS_RGB 1
+ #else
+ #define NEOPIXEL2_IS_RGBW 1
+ #endif
+
+ #if NEOPIXEL2_IS_RGB
+ #define NEO2_WHITE 255, 255, 255, 0
+ #else
+ #define NEO2_WHITE 0, 0, 0, 255
+ #endif
+
+ class Marlin_NeoPixel2 {
+ private:
+ static Adafruit_NeoPixel adaneo;
+
+ public:
+ static int8_t neoindex;
+
+ static void init();
+ static void set_color_startup(const uint32_t c);
+
+ static void set_color(const uint32_t c);
+
+ static inline void begin() { adaneo.begin(); }
+ static inline void set_pixel_color(const uint16_t n, const uint32_t c) { adaneo.setPixelColor(n, c); }
+ static inline void set_brightness(const uint8_t b) { adaneo.setBrightness(b); }
+ static inline void show() { adaneo.show(); }
+
+ // Accessors
+ static inline uint16_t pixels() { return adaneo.numPixels();}
+ static inline uint8_t brightness() { return adaneo.getBrightness(); }
+ static inline uint32_t Color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
+ return adaneo.Color(r, g, b, w);
+ }
+ };
+
+ extern Marlin_NeoPixel2 neo2;
+
+#endif // NEOPIXEL2_SEPARATE
diff --git a/Marlin/src/feature/leds/pca9533.cpp b/Marlin/src/feature/leds/pca9533.cpp
new file mode 100644
index 0000000000..0fd4d66757
--- /dev/null
+++ b/Marlin/src/feature/leds/pca9533.cpp
@@ -0,0 +1,127 @@
+/*
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+/**
+ * PCA9533 LED controller driver (MightyBoard, FlashForge Creator Pro, etc.)
+ * by @grauerfuchs - 1 Apr 2020
+ */
+#include "../../inc/MarlinConfig.h"
+
+#if ENABLED(PCA9533)
+
+#include "pca9533.h"
+#include
+
+void PCA9533_init() {
+ Wire.begin();
+ PCA9533_reset();
+}
+
+static void PCA9533_writeAllRegisters(uint8_t psc0, uint8_t pwm0, uint8_t psc1, uint8_t pwm1, uint8_t ls0){
+ uint8_t data[6] = { PCA9533_REG_PSC0 | PCA9533_REGM_AI, psc0, pwm0, psc1, pwm1, ls0 };
+ Wire.beginTransmission(PCA9533_Addr >> 1);
+ Wire.write(data, 6);
+ Wire.endTransmission();
+ delayMicroseconds(1);
+}
+
+static void PCA9533_writeRegister(uint8_t reg, uint8_t val){
+ uint8_t data[2] = { reg, val };
+ Wire.beginTransmission(PCA9533_Addr >> 1);
+ Wire.write(data, 2);
+ Wire.endTransmission();
+ delayMicroseconds(1);
+}
+
+// Reset (clear) all registers
+void PCA9533_reset() {
+ PCA9533_writeAllRegisters(0, 0, 0, 0, 0);
+}
+
+// Turn all LEDs off
+void PCA9533_setOff() {
+ PCA9533_writeRegister(PCA9533_REG_SEL, 0);
+}
+
+void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue) {
+ uint8_t r_pwm0 = 0; // Register data - PWM value
+ uint8_t r_pwm1 = 0; // Register data - PWM value
+
+ uint8_t op_g = 0, op_r = 0, op_b = 0; // Opcodes - Green, Red, Blue
+
+ // Light theory! GREEN takes priority because
+ // it's the most visible to the human eye.
+ if (green == 0) op_g = PCA9533_LED_OP_OFF;
+ else if (green == 255) op_g = PCA9533_LED_OP_ON;
+ else { r_pwm0 = green; op_g = PCA9533_LED_OP_PWM0; }
+
+ // RED
+ if (red == 0) op_r = PCA9533_LED_OP_OFF;
+ else if (red == 255) op_r = PCA9533_LED_OP_ON;
+ else if (r_pwm0 == 0 || r_pwm0 == red) {
+ r_pwm0 = red; op_r = PCA9533_LED_OP_PWM0;
+ }
+ else {
+ r_pwm1 = red; op_r = PCA9533_LED_OP_PWM1;
+ }
+
+ // BLUE
+ if (blue == 0) op_b = PCA9533_LED_OP_OFF;
+ else if (blue == 255) op_b = PCA9533_LED_OP_ON;
+ else if (r_pwm0 == 0 || r_pwm0 == blue) {
+ r_pwm0 = blue; op_b = PCA9533_LED_OP_PWM0;
+ }
+ else if (r_pwm1 == 0 || r_pwm1 == blue) {
+ r_pwm1 = blue; op_b = PCA9533_LED_OP_PWM1;
+ }
+ else {
+ /**
+ * Conflict. 3 values are requested but only 2 channels exist.
+ * G is on channel 0 and R is on channel 1, so work from there.
+ * Find the closest match, average the values, then use the free channel.
+ */
+ uint8_t dgb = ABS(green - blue),
+ dgr = ABS(green - red),
+ dbr = ABS(blue - red);
+ if (dgb < dgr && dgb < dbr) { // Mix with G on channel 0.
+ op_b = PCA9533_LED_OP_PWM0;
+ r_pwm0 = uint8_t(((uint16_t)green + (uint16_t)blue) / 2);
+ }
+ else if (dbr <= dgr && dbr <= dgb) { // Mix with R on channel 1.
+ op_b = PCA9533_LED_OP_PWM1;
+ r_pwm1 = uint8_t(((uint16_t)red + (uint16_t)blue) / 2);
+ }
+ else { // Mix R+G on 0 and put B on 1.
+ op_r = PCA9533_LED_OP_PWM0;
+ r_pwm0 = uint8_t(((uint16_t)green + (uint16_t)red) / 2);
+ op_b = PCA9533_LED_OP_PWM1;
+ r_pwm1 = blue;
+ }
+ }
+
+ // Write the changes to the hardware
+ PCA9533_writeAllRegisters(0, r_pwm0, 0, r_pwm1,
+ (op_g << PCA9533_LED_OFS_GRN) | (op_r << PCA9533_LED_OFS_RED) | (op_b << PCA9533_LED_OFS_BLU)
+ );
+}
+
+#endif // PCA9533
diff --git a/Marlin/src/feature/leds/pca9533.h b/Marlin/src/feature/leds/pca9533.h
new file mode 100644
index 0000000000..431058c491
--- /dev/null
+++ b/Marlin/src/feature/leds/pca9533.h
@@ -0,0 +1,59 @@
+/*
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+/*
+ * Driver for the PCA9533 LED controller found on the MightyBoard
+ * used by FlashForge Creator Pro, MakerBot, etc.
+ * Written 2020 APR 01 by grauerfuchs
+ */
+#include
+
+#define ENABLE_I2C_PULLUPS
+
+// Chip address (for Wire)
+#define PCA9533_Addr 0xC4
+
+// Control registers
+#define PCA9533_REG_READ 0x00
+#define PCA9533_REG_PSC0 0x01
+#define PCA9533_REG_PWM0 0x02
+#define PCA9533_REG_PSC1 0x03
+#define PCA9533_REG_PWM1 0x04
+#define PCA9533_REG_SEL 0x05
+#define PCA9533_REGM_AI 0x10
+
+// LED selector operation
+#define PCA9533_LED_OP_OFF 0B00
+#define PCA9533_LED_OP_ON 0B01
+#define PCA9533_LED_OP_PWM0 0B10
+#define PCA9533_LED_OP_PWM1 0B11
+
+// Select register bit offsets for LED colors
+#define PCA9533_LED_OFS_RED 0
+#define PCA9533_LED_OFS_GRN 2
+#define PCA9533_LED_OFS_BLU 4
+
+void PCA9533_init();
+void PCA9533_reset();
+void PCA9533_set_rgb(uint8_t red, uint8_t green, uint8_t blue);
+void PCA9533_setOff();
diff --git a/Marlin/src/feature/leds/pca9632.cpp b/Marlin/src/feature/leds/pca9632.cpp
index af9e39b863..d8af31cb6c 100644
--- a/Marlin/src/feature/leds/pca9632.cpp
+++ b/Marlin/src/feature/leds/pca9632.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -120,7 +120,7 @@ static void PCA9632_WriteAllRegisters(const byte addr, const byte regadd, const
}
#endif
-void pca9632_set_led_color(const LEDColor &color) {
+void PCA9632_set_led_color(const LEDColor &color) {
Wire.begin();
if (!PCA_init) {
PCA_init = 1;
@@ -138,7 +138,7 @@ void pca9632_set_led_color(const LEDColor &color) {
#if ENABLED(PCA9632_BUZZER)
- void pca9632_buzz(const long, const uint16_t) {
+ void PCA9632_buzz(const long, const uint16_t) {
uint8_t data[] = PCA9632_BUZZER_DATA;
Wire.beginTransmission(I2C_ADDRESS(PCA9632_ADDRESS));
Wire.write(data, sizeof(data));
diff --git a/Marlin/src/feature/leds/pca9632.h b/Marlin/src/feature/leds/pca9632.h
index 749230f652..fb59a8c184 100644
--- a/Marlin/src/feature/leds/pca9632.h
+++ b/Marlin/src/feature/leds/pca9632.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -29,9 +29,9 @@
struct LEDColor;
typedef LEDColor LEDColor;
-void pca9632_set_led_color(const LEDColor &color);
+void PCA9632_set_led_color(const LEDColor &color);
#if ENABLED(PCA9632_BUZZER)
#include
- void pca9632_buzz(const long, const uint16_t);
+ void PCA9632_buzz(const long, const uint16_t);
#endif
diff --git a/Marlin/src/feature/leds/printer_event_leds.cpp b/Marlin/src/feature/leds/printer_event_leds.cpp
index 70eee76b30..31c628c281 100644
--- a/Marlin/src/feature/leds/printer_event_leds.cpp
+++ b/Marlin/src/feature/leds/printer_event_leds.cpp
@@ -16,12 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
/**
- * printer_event_leds.cpp - LED color changing based on printer status
+ * feature/leds/printer_event_leds.cpp - LED color changing based on printer status
*/
#include "../../inc/MarlinConfigPre.h"
@@ -47,10 +47,10 @@ PrinterEventLEDs printerEventLEDs;
inline void pel_set_rgb(const uint8_t r, const uint8_t g, const uint8_t b) {
leds.set_color(
MakeLEDColor(r, g, b, 0, neo.brightness())
- #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
- , true
- #endif
- );
+ #if ENABLED(NEOPIXEL_IS_SEQUENTIAL)
+ , true
+ #endif
+ );
}
#endif
diff --git a/Marlin/src/feature/leds/printer_event_leds.h b/Marlin/src/feature/leds/printer_event_leds.h
index d2888705e7..86ec292aa3 100644
--- a/Marlin/src/feature/leds/printer_event_leds.h
+++ b/Marlin/src/feature/leds/printer_event_leds.h
@@ -16,13 +16,13 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
/**
- * printer_event_leds.h - LED color changing based on printer status
+ * feature/leds/printer_event_leds.h - LED color changing based on printer status
*/
#include "leds.h"
diff --git a/Marlin/src/feature/leds/tempstat.cpp b/Marlin/src/feature/leds/tempstat.cpp
index 2d7afdcf9e..880258f852 100644
--- a/Marlin/src/feature/leds/tempstat.cpp
+++ b/Marlin/src/feature/leds/tempstat.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -36,10 +36,7 @@ void handle_status_leds() {
static millis_t next_status_led_update_ms = 0;
if (ELAPSED(millis(), next_status_led_update_ms)) {
next_status_led_update_ms += 500; // Update every 0.5s
- float max_temp = 0.0;
- #if HAS_HEATED_BED
- max_temp = _MAX(thermalManager.degTargetBed(), thermalManager.degBed());
- #endif
+ float max_temp = TERN0(HAS_HEATED_BED, _MAX(thermalManager.degTargetBed(), thermalManager.degBed()));
HOTEND_LOOP()
max_temp = _MAX(max_temp, thermalManager.degHotend(e), thermalManager.degTargetHotend(e));
const int8_t new_red = (max_temp > 55.0) ? HIGH : (max_temp < 54.0 || old_red < 0) ? LOW : old_red;
diff --git a/Marlin/src/feature/leds/tempstat.h b/Marlin/src/feature/leds/tempstat.h
index fefe776cfd..a8b919bd8c 100644
--- a/Marlin/src/feature/leds/tempstat.h
+++ b/Marlin/src/feature/leds/tempstat.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/max7219.cpp b/Marlin/src/feature/max7219.cpp
index a012aeb5fa..ebcb56490d 100644
--- a/Marlin/src/feature/max7219.cpp
+++ b/Marlin/src/feature/max7219.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
diff --git a/Marlin/src/feature/max7219.h b/Marlin/src/feature/max7219.h
index 19170b2d59..8e98c9456c 100644
--- a/Marlin/src/feature/max7219.h
+++ b/Marlin/src/feature/max7219.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/mixing.cpp b/Marlin/src/feature/mixing.cpp
index d6ae2bb629..7de4eb79ea 100644
--- a/Marlin/src/feature/mixing.cpp
+++ b/Marlin/src/feature/mixing.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -44,7 +44,7 @@ int_fast8_t Mixer::runner = 0;
mixer_comp_t Mixer::s_color[MIXING_STEPPERS];
mixer_accu_t Mixer::accu[MIXING_STEPPERS] = { 0 };
-#if DUAL_MIXING_EXTRUDER || ENABLED(GRADIENT_MIX)
+#if EITHER(HAS_DUAL_MIXING, GRADIENT_MIX)
mixer_perc_t Mixer::mix[MIXING_STEPPERS];
#endif
@@ -90,15 +90,13 @@ void Mixer::normalize(const uint8_t tool_index) {
SERIAL_ECHOLNPGM("]");
#endif
- #if ENABLED(GRADIENT_MIX)
- refresh_gradient();
- #endif
+ TERN_(GRADIENT_MIX, refresh_gradient());
}
void Mixer::reset_vtools() {
// Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
// Every virtual tool gets a pure filament
- LOOP_L_N(t, MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS)
+ LOOP_L_N(t, _MIN(MIXING_VIRTUAL_TOOLS, MIXING_STEPPERS))
MIXER_STEPPER_LOOP(i)
color[t][i] = (t == i) ? COLOR_A_MASK : 0;
@@ -115,7 +113,7 @@ void Mixer::init() {
reset_vtools();
- #if ENABLED(RETRACT_SYNC_MIXING)
+ #if HAS_MIXER_SYNC_CHANNEL
// AUTORETRACT_TOOL gets the same amount of all filaments
MIXER_STEPPER_LOOP(i)
color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK;
@@ -123,13 +121,11 @@ void Mixer::init() {
ZERO(collector);
- #if DUAL_MIXING_EXTRUDER || ENABLED(GRADIENT_MIX)
+ #if EITHER(HAS_DUAL_MIXING, GRADIENT_MIX)
update_mix_from_vtool();
#endif
- #if ENABLED(GRADIENT_MIX)
- update_gradient_for_planner_z();
- #endif
+ TERN_(GRADIENT_MIX, update_gradient_for_planner_z());
}
void Mixer::refresh_collector(const float proportion/*=1.0*/, const uint8_t t/*=selected_vtool*/, float (&c)[MIXING_STEPPERS]/*=collector*/) {
diff --git a/Marlin/src/feature/mixing.h b/Marlin/src/feature/mixing.h
index da5240995c..7fe7062a7a 100644
--- a/Marlin/src/feature/mixing.h
+++ b/Marlin/src/feature/mixing.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -25,7 +25,7 @@
//#define MIXER_NORMALIZER_DEBUG
-#ifndef __AVR__ // || DUAL_MIXING_EXTRUDER
+#ifndef __AVR__ // || HAS_DUAL_MIXING
// Use 16-bit (or fastest) data for the integer mix factors
typedef uint_fast16_t mixer_comp_t;
typedef uint_fast16_t mixer_accu_t;
@@ -48,29 +48,23 @@ typedef int8_t mixer_perc_t;
#endif
enum MixTool {
- FIRST_USER_VIRTUAL_TOOL = 0,
- LAST_USER_VIRTUAL_TOOL = MIXING_VIRTUAL_TOOLS - 1,
- NR_USER_VIRTUAL_TOOLS,
- MIXER_DIRECT_SET_TOOL = NR_USER_VIRTUAL_TOOLS,
- #if ENABLED(RETRACT_SYNC_MIXING)
- MIXER_AUTORETRACT_TOOL,
+ FIRST_USER_VIRTUAL_TOOL = 0
+ , LAST_USER_VIRTUAL_TOOL = MIXING_VIRTUAL_TOOLS - 1
+ , NR_USER_VIRTUAL_TOOLS
+ , MIXER_DIRECT_SET_TOOL = NR_USER_VIRTUAL_TOOLS
+ #if HAS_MIXER_SYNC_CHANNEL
+ , MIXER_AUTORETRACT_TOOL
#endif
- NR_MIXING_VIRTUAL_TOOLS
+ , NR_MIXING_VIRTUAL_TOOLS
};
-#if ENABLED(RETRACT_SYNC_MIXING)
- #define MAX_VTOOLS 254
-#else
- #define MAX_VTOOLS 255
-#endif
+#define MAX_VTOOLS TERN(HAS_MIXER_SYNC_CHANNEL, 254, 255)
static_assert(NR_MIXING_VIRTUAL_TOOLS <= MAX_VTOOLS, "MIXING_VIRTUAL_TOOLS must be <= " STRINGIFY(MAX_VTOOLS) "!");
-#define MIXER_STEPPER_LOOP(VAR) \
- for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
-
#define MIXER_BLOCK_FIELD mixer_comp_t b_color[MIXING_STEPPERS]
#define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color)
#define MIXER_STEPPER_SETUP() mixer.stepper_setup(current_block->b_color)
+#define MIXER_STEPPER_LOOP(VAR) for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
#if ENABLED(GRADIENT_MIX)
@@ -81,9 +75,7 @@ static_assert(NR_MIXING_VIRTUAL_TOOLS <= MAX_VTOOLS, "MIXING_VIRTUAL_TOOLS must
int8_t start_vtool, end_vtool; // Start and end virtual tools
mixer_perc_t start_mix[MIXING_STEPPERS], // Start and end mixes from those tools
end_mix[MIXING_STEPPERS];
- #if ENABLED(GRADIENT_VTOOL)
- int8_t vtool_index; // Use this virtual tool number as index
- #endif
+ TERN_(GRADIENT_VTOOL, int8_t vtool_index); // Use this virtual tool number as index
} gradient_t;
#endif
@@ -112,12 +104,8 @@ class Mixer {
FORCE_INLINE static void T(const uint_fast8_t c) {
selected_vtool = c;
- #if ENABLED(GRADIENT_VTOOL)
- refresh_gradient();
- #endif
- #if DUAL_MIXING_EXTRUDER
- update_mix_from_vtool();
- #endif
+ TERN_(GRADIENT_VTOOL, refresh_gradient());
+ TERN_(HAS_DUAL_MIXING, update_mix_from_vtool());
}
// Used when dealing with blocks
@@ -135,7 +123,7 @@ class Mixer {
MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i];
}
- #if DUAL_MIXING_EXTRUDER || ENABLED(GRADIENT_MIX)
+ #if EITHER(HAS_DUAL_MIXING, GRADIENT_MIX)
static mixer_perc_t mix[MIXING_STEPPERS]; // Scratch array for the Mix in proportion to 100
@@ -173,21 +161,19 @@ class Mixer {
#endif
}
- #endif // DUAL_MIXING_EXTRUDER || GRADIENT_MIX
+ #endif // HAS_DUAL_MIXING || GRADIENT_MIX
- #if DUAL_MIXING_EXTRUDER
+ #if HAS_DUAL_MIXING
// Update the virtual tool from an edited mix
static inline void update_vtool_from_mix() {
copy_mix_to_color(color[selected_vtool]);
- #if ENABLED(GRADIENT_MIX)
- refresh_gradient();
- #endif
+ TERN_(GRADIENT_MIX, refresh_gradient());
// MIXER_STEPPER_LOOP(i) collector[i] = mix[i];
// normalize();
}
- #endif // DUAL_MIXING_EXTRUDER
+ #endif // HAS_DUAL_MIXING
#if ENABLED(GRADIENT_MIX)
diff --git a/Marlin/src/feature/mmu2/mmu2.cpp b/Marlin/src/feature/mmu2/mmu2.cpp
index 4506883f46..35f2db45a9 100644
--- a/Marlin/src/feature/mmu2/mmu2.cpp
+++ b/Marlin/src/feature/mmu2/mmu2.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -51,8 +51,13 @@ MMU2 mmu2;
#define MMU_TODELAY 100
#define MMU_TIMEOUT 10
-#define MMU_CMD_TIMEOUT 60000ul // 5min timeout for mmu commands (except P0)
-#define MMU_P0_TIMEOUT 3000ul // Timeout for P0 command: 3seconds
+#define MMU_CMD_TIMEOUT 45000UL // 45s timeout for mmu commands (except P0)
+#define MMU_P0_TIMEOUT 3000UL // Timeout for P0 command: 3seconds
+
+#if ENABLED(MMU_EXTRUDER_SENSOR)
+ uint8_t mmu_idl_sens = 0;
+ static bool mmu_loading_flag = false;
+#endif
#define MMU_CMD_NONE 0
#define MMU_CMD_T0 0x10
@@ -79,11 +84,7 @@ MMU2 mmu2;
#define MMU_CMD_F3 0x73
#define MMU_CMD_F4 0x74
-#if ENABLED(MMU2_MODE_12V)
- #define MMU_REQUIRED_FW_BUILDNR 132
-#else
- #define MMU_REQUIRED_FW_BUILDNR 126
-#endif
+#define MMU_REQUIRED_FW_BUILDNR TERN(MMU2_MODE_12V, 132, 126)
#define MMU2_NO_TOOL 99
#define MMU_BAUD 115200
@@ -91,23 +92,32 @@ MMU2 mmu2;
#define mmuSerial MMU2_SERIAL
bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
+#if ENABLED(PRUSA_MMU2_S_MODE)
+ bool MMU2::mmu2s_triggered;
+#endif
uint8_t MMU2::cmd, MMU2::cmd_arg, MMU2::last_cmd, MMU2::extruder;
int8_t MMU2::state = 0;
volatile int8_t MMU2::finda = 1;
volatile bool MMU2::finda_runout_valid;
int16_t MMU2::version = -1, MMU2::buildnr = -1;
-millis_t MMU2::last_request, MMU2::next_P0_request;
+millis_t MMU2::prev_request, MMU2::prev_P0_request;
char MMU2::rx_buffer[MMU_RX_SIZE], MMU2::tx_buffer[MMU_TX_SIZE];
-#if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
+#if BOTH(HAS_LCD_MENU, MMU2_MENUS)
struct E_Step {
float extrude; //!< extrude distance in mm
feedRate_t feedRate; //!< feed rate in mm/s
};
- static constexpr E_Step ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE };
- static constexpr E_Step load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE };
+ static constexpr E_Step
+ ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE }
+ , load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE }
+ #if ENABLED(PRUSA_MMU2_S_MODE)
+ , can_load_sequence[] PROGMEM = { MMU2_CAN_LOAD_SEQUENCE }
+ , can_load_increment_sequence[] PROGMEM = { MMU2_CAN_LOAD_INCREMENT_SEQUENCE }
+ #endif
+ ;
#endif // MMU2_MENUS
@@ -150,6 +160,10 @@ uint8_t MMU2::get_current_tool() {
return extruder == MMU2_NO_TOOL ? -1 : extruder;
}
+#if EITHER(PRUSA_MMU2_S_MODE, MMU_EXTRUDER_SENSOR)
+ #define FILAMENT_PRESENT() (READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE)
+#endif
+
void MMU2::mmu_loop() {
switch (state) {
@@ -228,6 +242,7 @@ void MMU2::mmu_loop() {
enabled = true;
state = 1;
+ TERN_(PRUSA_MMU2_S_MODE, mmu2s_triggered = false);
}
break;
@@ -238,6 +253,7 @@ void MMU2::mmu_loop() {
int filament = cmd - MMU_CMD_T0;
DEBUG_ECHOLNPAIR("MMU <= T", filament);
tx_printf_P(PSTR("T%d\n"), filament);
+ TERN_(MMU_EXTRUDER_SENSOR, mmu_idl_sens = 1); // enable idler sensor, if any
state = 3; // wait for response
}
else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L4)) {
@@ -286,11 +302,13 @@ void MMU2::mmu_loop() {
last_cmd = cmd;
cmd = MMU_CMD_NONE;
}
- else if (ELAPSED(millis(), next_P0_request)) {
+ else if (ELAPSED(millis(), prev_P0_request + 300)) {
// read FINDA
tx_str_P(PSTR("P0\n"));
state = 2; // wait for response
}
+
+ TERN_(PRUSA_MMU2_S_MODE, check_filament());
break;
case 2: // response to command P0
@@ -300,25 +318,35 @@ void MMU2::mmu_loop() {
// This is super annoying. Only activate if necessary
// if (finda_runout_valid) DEBUG_ECHOLNPAIR_F("MMU <= 'P0'\nMMU => ", finda, 6);
- state = 1;
-
- if (cmd == 0) ready = true;
-
if (!finda && finda_runout_valid) filament_runout();
+ if (cmd == 0) ready = true;
+ state = 1;
}
- else if (ELAPSED(millis(), last_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
+ else if (ELAPSED(millis(), prev_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
state = 1;
+ TERN_(PRUSA_MMU2_S_MODE, check_filament());
break;
case 3: // response to mmu commands
+ #if ENABLED(MMU_EXTRUDER_SENSOR)
+ if (mmu_idl_sens) {
+ if (FILAMENT_PRESENT() && mmu_loading_flag) {
+ DEBUG_ECHOLNPGM("MMU <= 'A'\n");
+ tx_str_P(PSTR("A\n")); // send 'abort' request
+ mmu_idl_sens = 0;
+ DEBUG_ECHOLNPGM("MMU IDLER_SENSOR = 0 - ABORT\n");
+ }
+ }
+ #endif
+
if (rx_ok()) {
DEBUG_ECHOLNPGM("MMU => 'ok'");
ready = true;
state = 1;
last_cmd = MMU_CMD_NONE;
}
- else if (ELAPSED(millis(), last_request + MMU_CMD_TIMEOUT)) {
+ else if (ELAPSED(millis(), prev_request + MMU_CMD_TIMEOUT)) {
// resend request after timeout
if (last_cmd) {
DEBUG_ECHOLNPGM("MMU retry");
@@ -327,6 +355,7 @@ void MMU2::mmu_loop() {
}
state = 1;
}
+ TERN_(PRUSA_MMU2_S_MODE, check_filament());
break;
}
}
@@ -337,7 +366,7 @@ void MMU2::mmu_loop() {
bool MMU2::rx_start() {
// check for start message
if (rx_str_P(PSTR("start\n"))) {
- next_P0_request = millis() + 300;
+ prev_P0_request = millis();
return true;
}
return false;
@@ -383,7 +412,7 @@ void MMU2::tx_str_P(const char* str) {
uint8_t len = strlen_P(str);
LOOP_L_N(i, len) mmuSerial.write(pgm_read_byte(str++));
rx_buffer[0] = '\0';
- last_request = millis();
+ prev_request = millis();
}
/**
@@ -394,7 +423,7 @@ void MMU2::tx_printf_P(const char* format, int argument = -1) {
uint8_t len = sprintf_P(tx_buffer, format, argument);
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
rx_buffer[0] = '\0';
- last_request = millis();
+ prev_request = millis();
}
/**
@@ -405,7 +434,7 @@ void MMU2::tx_printf_P(const char* format, int argument1, int argument2) {
uint8_t len = sprintf_P(tx_buffer, format, argument1, argument2);
LOOP_L_N(i, len) mmuSerial.write(tx_buffer[i]);
rx_buffer[0] = '\0';
- last_request = millis();
+ prev_request = millis();
}
/**
@@ -421,7 +450,7 @@ void MMU2::clear_rx_buffer() {
*/
bool MMU2::rx_ok() {
if (rx_str_P(PSTR("ok\n"))) {
- next_P0_request = millis() + 300;
+ prev_P0_request = millis();
return true;
}
return false;
@@ -433,37 +462,235 @@ bool MMU2::rx_ok() {
void MMU2::check_version() {
if (buildnr < MMU_REQUIRED_FW_BUILDNR) {
SERIAL_ERROR_MSG("Invalid MMU2 firmware. Version >= " STRINGIFY(MMU_REQUIRED_FW_BUILDNR) " required.");
- kill(GET_TEXT(MSG_MMU2_WRONG_FIRMWARE));
+ kill(GET_TEXT(MSG_KILL_MMU2_FIRMWARE));
}
}
+static void mmu2_not_responding() {
+ LCD_MESSAGEPGM(MSG_MMU2_NOT_RESPONDING);
+ BUZZ(100, 659);
+ BUZZ(200, 698);
+ BUZZ(100, 659);
+ BUZZ(300, 440);
+ BUZZ(100, 659);
+}
+
+#if ENABLED(PRUSA_MMU2_S_MODE)
+
+ bool MMU2::load_to_gears() {
+ command(MMU_CMD_C0);
+ manage_response(true, true);
+ LOOP_L_N(i, MMU2_C0_RETRY) { // Keep loading until filament reaches gears
+ if (mmu2s_triggered) break;
+ command(MMU_CMD_C0);
+ manage_response(true, true);
+ check_filament();
+ }
+ const bool success = mmu2s_triggered && can_load();
+ if (!success) mmu2_not_responding();
+ return success;
+ }
+
+ /**
+ * Handle tool change
+ */
+ void MMU2::tool_change(const uint8_t index) {
+
+ if (!enabled) return;
+
+ set_runout_valid(false);
+
+ if (index != extruder) {
+
+ DISABLE_AXIS_E0();
+ ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
+
+ command(MMU_CMD_T0 + index);
+ manage_response(true, true);
+
+ if (load_to_gears()) {
+ extruder = index; // filament change is finished
+ active_extruder = 0;
+ ENABLE_AXIS_E0();
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
+ }
+ ui.reset_status();
+ }
+
+ set_runout_valid(true);
+ }
+
+ /**
+ * Handle special T?/Tx/Tc commands
+ *
+ * T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically
+ * Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load.
+ * Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated.
+ */
+ void MMU2::tool_change(const char* special) {
+
+ if (!enabled) return;
+
+ #if ENABLED(MMU2_MENUS)
+
+ set_runout_valid(false);
+
+ switch (*special) {
+ case '?': {
+ uint8_t index = mmu2_choose_filament();
+ while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
+ load_filament_to_nozzle(index);
+ } break;
+
+ case 'x': {
+ planner.synchronize();
+ uint8_t index = mmu2_choose_filament();
+ DISABLE_AXIS_E0();
+ command(MMU_CMD_T0 + index);
+ manage_response(true, true);
+
+ if (load_to_gears()) {
+ mmu_loop();
+ ENABLE_AXIS_E0();
+ extruder = index;
+ active_extruder = 0;
+ }
+ } break;
+
+ case 'c': {
+ while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
+ execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
+ } break;
+ }
+
+ set_runout_valid(true);
+
+ #endif // MMU2_MENUS
+ }
+
+#elif ENABLED(MMU_EXTRUDER_SENSOR)
+
+ /**
+ * Handle tool change
+ */
+ void MMU2::tool_change(const uint8_t index) {
+ if (!enabled) return;
+
+ set_runout_valid(false);
+
+ if (index != extruder) {
+ DISABLE_AXIS_E0();
+ if (FILAMENT_PRESENT()) {
+ DEBUG_ECHOLNPGM("Unloading\n");
+ mmu_loading_flag = false;
+ command(MMU_CMD_U0);
+ manage_response(true, true);
+ }
+ ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
+ mmu_loading_flag = true;
+ command(MMU_CMD_T0 + index);
+ manage_response(true, true);
+ mmu_continue_loading();
+ command(MMU_CMD_C0);
+ extruder = index;
+ active_extruder = 0;
+
+ ENABLE_AXIS_E0();
+ SERIAL_ECHO_START();
+ SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
+
+ ui.reset_status();
+ }
+
+ set_runout_valid(true);
+ }
+
+ /**
+ * Handle special T?/Tx/Tc commands
+ *
+ * T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically
+ * Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load.
+ * Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated.
+ */
+ void MMU2::tool_change(const char* special) {
+ if (!enabled) return;
+
+ #if ENABLED(MMU2_MENUS)
+
+ set_runout_valid(false);
+
+ switch (*special) {
+ case '?': {
+ DEBUG_ECHOLNPGM("case ?\n");
+ uint8_t index = mmu2_choose_filament();
+ while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
+ load_filament_to_nozzle(index);
+ } break;
+
+ case 'x': {
+ DEBUG_ECHOLNPGM("case x\n");
+ planner.synchronize();
+ uint8_t index = mmu2_choose_filament();
+ DISABLE_AXIS_E0();
+ command(MMU_CMD_T0 + index);
+ manage_response(true, true);
+ mmu_continue_loading();
+ command(MMU_CMD_C0);
+ mmu_loop();
+
+ ENABLE_AXIS_E0();
+ extruder = index;
+ active_extruder = 0;
+ } break;
+
+ case 'c': {
+ DEBUG_ECHOLNPGM("case c\n");
+ while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
+ execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
+ } break;
+ }
+
+ set_runout_valid(true);
+
+ #endif // MMU2_MENUS
+ }
+
+ void MMU2::mmu_continue_loading() {
+ for (uint8_t i = 0; i < MMU_LOADING_ATTEMPTS_NR; i++) {
+ DEBUG_ECHOLNPAIR("Additional load attempt #", i);
+ if (FILAMENT_PRESENT()) break;
+ command(MMU_CMD_C0);
+ manage_response(true, true);
+ }
+ if (!FILAMENT_PRESENT()) {
+ DEBUG_ECHOLNPGM("Filament never reached sensor, runout");
+ filament_runout();
+ }
+ mmu_idl_sens = 0;
+ }
+
+#elif DISABLED(MMU_EXTRUDER_SENSOR) && DISABLED(PRUSA_MMU2_S_MODE)
+
/**
* Handle tool change
*/
-void MMU2::tool_change(uint8_t index) {
-
+void MMU2::tool_change(const uint8_t index) {
if (!enabled) return;
set_runout_valid(false);
if (index != extruder) {
-
DISABLE_AXIS_E0();
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));
-
command(MMU_CMD_T0 + index);
-
manage_response(true, true);
-
command(MMU_CMD_C0);
extruder = index; //filament change is finished
active_extruder = 0;
-
ENABLE_AXIS_E0();
-
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
-
ui.reset_status();
}
@@ -480,7 +707,6 @@ void MMU2::tool_change(uint8_t index) {
*
*/
void MMU2::tool_change(const char* special) {
-
if (!enabled) return;
#if ENABLED(MMU2_MENUS)
@@ -489,12 +715,14 @@ void MMU2::tool_change(const char* special) {
switch (*special) {
case '?': {
+ DEBUG_ECHOLNPGM("case ?\n");
uint8_t index = mmu2_choose_filament();
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
load_filament_to_nozzle(index);
} break;
case 'x': {
+ DEBUG_ECHOLNPGM("case x\n");
planner.synchronize();
uint8_t index = mmu2_choose_filament();
DISABLE_AXIS_E0();
@@ -509,6 +737,7 @@ void MMU2::tool_change(const char* special) {
} break;
case 'c': {
+ DEBUG_ECHOLNPGM("case c\n");
while (!thermalManager.wait_for_hotend(active_extruder, false)) safe_delay(100);
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
} break;
@@ -517,7 +746,9 @@ void MMU2::tool_change(const char* special) {
set_runout_valid(true);
#endif
-}
+ }
+
+#endif // MMU_EXTRUDER_SENSOR
/**
* Set next command
@@ -554,7 +785,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
bool response = false;
mmu_print_saved = false;
xyz_pos_t resume_position;
- int16_t resume_hotend_temp;
+ int16_t resume_hotend_temp = thermalManager.degTargetHotend(active_extruder);
KEEPALIVE_STATE(PAUSED_FOR_USER);
@@ -575,16 +806,11 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
resume_position = current_position;
if (move_axes && all_axes_homed())
- nozzle.park(2, park_point /*= NOZZLE_PARK_POINT*/);
+ nozzle.park(0, park_point /*= NOZZLE_PARK_POINT*/);
if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);
- LCD_MESSAGEPGM(MSG_MMU2_NOT_RESPONDING);
- BUZZ(100, 659);
- BUZZ(200, 698);
- BUZZ(100, 659);
- BUZZ(300, 440);
- BUZZ(100, 659);
+ mmu2_not_responding();
}
}
else if (mmu_print_saved) {
@@ -618,7 +844,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {
}
}
-void MMU2::set_filament_type(uint8_t index, uint8_t filamentType) {
+void MMU2::set_filament_type(const uint8_t index, const uint8_t filamentType) {
if (!enabled) return;
cmd_arg = filamentType;
@@ -632,10 +858,44 @@ void MMU2::filament_runout() {
planner.synchronize();
}
-#if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
+#if ENABLED(PRUSA_MMU2_S_MODE)
+
+ void MMU2::check_filament() {
+ const bool present = FILAMENT_PRESENT();
+ if (present && !mmu2s_triggered) {
+ DEBUG_ECHOLNPGM("MMU <= 'A'");
+ tx_str_P(PSTR("A\n"));
+ }
+ mmu2s_triggered = present;
+ }
+
+ bool MMU2::can_load() {
+ execute_extruder_sequence((const E_Step *)can_load_sequence, COUNT(can_load_sequence));
+
+ int filament_detected_count = 0;
+ const int steps = (MMU2_CAN_LOAD_RETRACT) / (MMU2_CAN_LOAD_INCREMENT);
+ DEBUG_ECHOLNPGM("MMU can_load:");
+ LOOP_L_N(i, steps) {
+ execute_extruder_sequence((const E_Step *)can_load_increment_sequence, COUNT(can_load_increment_sequence));
+ check_filament(); // Don't trust the idle function
+ DEBUG_CHAR(mmu2s_triggered ? 'O' : 'o');
+ if (mmu2s_triggered) ++filament_detected_count;
+ }
+
+ if (filament_detected_count <= steps - (MMU2_CAN_LOAD_DEVIATION) / (MMU2_CAN_LOAD_INCREMENT)) {
+ DEBUG_ECHOLNPGM(" failed.");
+ return false;
+ }
+
+ DEBUG_ECHOLNPGM(" succeeded.");
+ return true;
+ }
+#endif
+
+#if BOTH(HAS_LCD_MENU, MMU2_MENUS)
// Load filament into MMU2
- void MMU2::load_filament(uint8_t index) {
+ void MMU2::load_filament(const uint8_t index) {
if (!enabled) return;
command(MMU_CMD_L0 + index);
manage_response(false, false);
@@ -647,7 +907,7 @@ void MMU2::filament_runout() {
* Switch material and load to nozzle
*
*/
- bool MMU2::load_filament_to_nozzle(uint8_t index) {
+ bool MMU2::load_filament_to_nozzle(const uint8_t index) {
if (!enabled) return false;
@@ -656,24 +916,22 @@ void MMU2::filament_runout() {
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
return false;
}
- else {
- command(MMU_CMD_T0 + index);
- manage_response(true, true);
- command(MMU_CMD_C0);
- mmu_loop();
+ command(MMU_CMD_T0 + index);
+ manage_response(true, true);
+
+ const bool success = load_to_gears();
+ if (success) {
+ mmu_loop();
extruder = index;
active_extruder = 0;
-
load_to_nozzle();
-
BUZZ(200, 404);
- return true;
}
+ return success;
}
/**
- *
* Load filament to nozzle of multimaterial printer
*
* This function is used only only after T? (user select filament) and M600 (change filament).
@@ -685,7 +943,7 @@ void MMU2::filament_runout() {
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
}
- bool MMU2::eject_filament(uint8_t index, bool recover) {
+ bool MMU2::eject_filament(const uint8_t index, const bool recover) {
if (!enabled) return false;
@@ -707,12 +965,8 @@ void MMU2::filament_runout() {
if (recover) {
LCD_MESSAGEPGM(MSG_MMU2_EJECT_RECOVER);
BUZZ(200, 404);
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_USER_CONTINUE, PSTR("MMU2 Eject Recover"), CONTINUE_STR);
- #endif
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onUserConfirmRequired_P(PSTR("MMU2 Eject Recover"));
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("MMU2 Eject Recover"), CONTINUE_STR));
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("MMU2 Eject Recover")));
wait_for_user_response();
BUZZ(200, 404);
BUZZ(200, 404);
@@ -736,9 +990,7 @@ void MMU2::filament_runout() {
}
/**
- *
- * unload from hotend and retract to MMU
- *
+ * Unload from hotend and retract to MMU
*/
bool MMU2::unload() {
diff --git a/Marlin/src/feature/mmu2/mmu2.h b/Marlin/src/feature/mmu2/mmu2.h
index 970b0b4338..678f65d072 100644
--- a/Marlin/src/feature/mmu2/mmu2.h
+++ b/Marlin/src/feature/mmu2/mmu2.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -44,24 +44,24 @@ public:
static void init();
static void reset();
static void mmu_loop();
- static void tool_change(uint8_t index);
+ static void tool_change(const uint8_t index);
static void tool_change(const char* special);
static uint8_t get_current_tool();
- static void set_filament_type(uint8_t index, uint8_t type);
+ static void set_filament_type(const uint8_t index, const uint8_t type);
- #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
+ #if BOTH(HAS_LCD_MENU, MMU2_MENUS)
static bool unload();
static void load_filament(uint8_t);
static void load_all();
- static bool load_filament_to_nozzle(uint8_t index);
- static bool eject_filament(uint8_t index, bool recover);
+ static bool load_filament_to_nozzle(const uint8_t index);
+ static bool eject_filament(const uint8_t index, const bool recover);
#endif
private:
static bool rx_str_P(const char* str);
static void tx_str_P(const char* str);
- static void tx_printf_P(const char* format, int argument);
- static void tx_printf_P(const char* format, int argument1, int argument2);
+ static void tx_printf_P(const char* format, const int argument);
+ static void tx_printf_P(const char* format, const int argument1, const int argument2);
static void clear_rx_buffer();
static bool rx_ok();
@@ -72,7 +72,7 @@ private:
static bool get_response();
static void manage_response(const bool move_axes, const bool turn_off_nozzle);
- #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
+ #if BOTH(HAS_LCD_MENU, MMU2_MENUS)
static void load_to_nozzle();
static void filament_ramming();
static void execute_extruder_sequence(const E_Step * sequence, int steps);
@@ -80,13 +80,27 @@ private:
static void filament_runout();
+ #if ENABLED(PRUSA_MMU2_S_MODE)
+ static bool mmu2s_triggered;
+ static void check_filament();
+ static bool can_load();
+ static bool load_to_gears();
+ #else
+ FORCE_INLINE static bool load_to_gears() { return true; }
+ #endif
+
+ #if ENABLED(MMU_EXTRUDER_SENSOR)
+ static void mmu_continue_loading();
+ #endif
+
static bool enabled, ready, mmu_print_saved;
+
static uint8_t cmd, cmd_arg, last_cmd, extruder;
static int8_t state;
static volatile int8_t finda;
static volatile bool finda_runout_valid;
static int16_t version, buildnr;
- static millis_t last_request, next_P0_request;
+ static millis_t prev_request, prev_P0_request;
static char rx_buffer[MMU_RX_SIZE], tx_buffer[MMU_TX_SIZE];
static inline void set_runout_valid(const bool valid) {
diff --git a/Marlin/src/feature/password/password.cpp b/Marlin/src/feature/password/password.cpp
new file mode 100644
index 0000000000..90bb647118
--- /dev/null
+++ b/Marlin/src/feature/password/password.cpp
@@ -0,0 +1,58 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if ENABLED(PASSWORD_FEATURE)
+
+#include "password.h"
+#include "../../gcode/gcode.h"
+#include "../../core/serial.h"
+
+Password password;
+
+// public:
+bool Password::is_set, Password::is_locked;
+uint32_t Password::value, Password::value_entry;
+
+//
+// Authenticate user with password.
+// Called from Setup, after SD Prinitng Stops/Aborts, and M510
+//
+void Password::lock_machine() {
+ is_locked = true;
+ TERN_(HAS_LCD_MENU, authenticate_user(ui.status_screen, screen_password_entry));
+}
+
+//
+// Authentication check
+//
+void Password::authentication_check() {
+ if (value_entry == value)
+ is_locked = false;
+ else
+ SERIAL_ECHOLNPGM(STR_WRONG_PASSWORD);
+
+ TERN_(HAS_LCD_MENU, authentication_done());
+}
+
+#endif // PASSWORD_FEATURE
diff --git a/Marlin/src/feature/password/password.h b/Marlin/src/feature/password/password.h
new file mode 100644
index 0000000000..3ed584b29d
--- /dev/null
+++ b/Marlin/src/feature/password/password.h
@@ -0,0 +1,57 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (c) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "../../lcd/ultralcd.h"
+
+class Password {
+public:
+ static bool is_set, is_locked;
+ static uint32_t value, value_entry;
+
+ Password() { is_locked = false; }
+
+ static void lock_machine();
+
+ #if HAS_LCD_MENU
+ static void access_menu_password();
+ static void authentication_check();
+ static void authentication_done();
+ static void media_gatekeeper();
+
+ private:
+ static void authenticate_user(const screenFunc_t, const screenFunc_t);
+ static void menu_password();
+ static void menu_password_entry();
+ static void screen_password_entry();
+ static void screen_set_password();
+ static void start_over();
+
+ static void digit_entered();
+ static void set_password_done();
+ static void menu_password_report();
+
+ static void remove_password();
+ #endif
+};
+
+extern Password password;
diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp
index 9c615b6ff8..a7ed93425c 100644
--- a/Marlin/src/feature/pause.cpp
+++ b/Marlin/src/feature/pause.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -53,7 +53,6 @@
#include "../lcd/extui/ui_api.h"
#endif
-#include "../core/language.h"
#include "../lcd/ultralcd.h"
#if HAS_BUZZER
@@ -85,26 +84,30 @@ fil_change_settings_t fc_settings[EXTRUDERS];
#endif
#if HAS_BUZZER
- static void filament_change_beep(const int8_t max_beep_count, const bool init=false) {
+ static void impatient_beep(const int8_t max_beep_count, const bool restart=false) {
- #if HAS_LCD_MENU
- if (pause_mode == PAUSE_MODE_PAUSE_PRINT) return;
- #endif
+ if (TERN0(HAS_LCD_MENU, pause_mode == PAUSE_MODE_PAUSE_PRINT)) return;
static millis_t next_buzz = 0;
static int8_t runout_beep = 0;
- if (init) next_buzz = runout_beep = 0;
+ if (restart) next_buzz = runout_beep = 0;
+
+ const bool always = max_beep_count < 0;
const millis_t ms = millis();
if (ELAPSED(ms, next_buzz)) {
- if (max_beep_count < 0 || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
- next_buzz = ms + ((max_beep_count < 0 || runout_beep < max_beep_count) ? 1000 : 500);
+ if (always || runout_beep < max_beep_count + 5) { // Only beep as long as we're supposed to
+ next_buzz = ms + ((always || runout_beep < max_beep_count) ? 1000 : 500);
BUZZ(50, 880 - (runout_beep & 1) * 220);
runout_beep++;
}
}
}
+ inline void first_impatient_beep(const int8_t max_beep_count) { impatient_beep(max_beep_count, true); }
+#else
+ inline void impatient_beep(const int8_t, const bool=false) {}
+ inline void first_impatient_beep(const int8_t) {}
#endif
/**
@@ -116,7 +119,7 @@ fil_change_settings_t fc_settings[EXTRUDERS];
*
* Returns 'true' if heating was completed, 'false' for abort
*/
-static bool ensure_safe_temperature(const PauseMode mode=PAUSE_MODE_SAME) {
+static bool ensure_safe_temperature(const bool wait=true, const PauseMode mode=PAUSE_MODE_SAME) {
#if ENABLED(PREVENT_COLD_EXTRUSION)
if (!DEBUGGING(DRYRUN) && thermalManager.targetTooColdToExtrude(active_extruder)) {
@@ -131,7 +134,13 @@ static bool ensure_safe_temperature(const PauseMode mode=PAUSE_MODE_SAME) {
UNUSED(mode);
#endif
- return thermalManager.wait_for_hotend(active_extruder);
+ if (wait)
+ return thermalManager.wait_for_hotend(active_extruder);
+
+ while (ABS(thermalManager.degHotend(active_extruder) - thermalManager.degTargetHotend(active_extruder)) > TEMP_WINDOW)
+ idle();
+
+ return true;
}
/**
@@ -151,11 +160,9 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
const PauseMode mode/*=PAUSE_MODE_PAUSE_PRINT*/
DXC_ARGS
) {
- #if !HAS_LCD_MENU
- UNUSED(show_lcd);
- #endif
+ TERN(HAS_LCD_MENU,,UNUSED(show_lcd));
- if (!ensure_safe_temperature(mode)) {
+ if (!ensure_safe_temperature(false, mode)) {
#if HAS_LCD_MENU
if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_STATUS, mode);
#endif
@@ -168,11 +175,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
#endif
SERIAL_ECHO_MSG(_PMSG(STR_FILAMENT_CHANGE_INSERT));
- #if HAS_BUZZER
- filament_change_beep(max_beep_count, true);
- #else
- UNUSED(max_beep_count);
- #endif
+ first_impatient_beep(max_beep_count);
KEEPALIVE_STATE(PAUSED_FOR_USER);
#if ENABLED(HOST_PROMPT_SUPPORT)
@@ -185,13 +188,9 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
host_action_prompt_button(CONTINUE_STR);
host_action_prompt_show();
#endif
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onUserConfirmRequired_P(PSTR("Load Filament"));
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Load Filament")));
while (wait_for_user) {
- #if HAS_BUZZER
- filament_change_beep(max_beep_count);
- #endif
+ impatient_beep(max_beep_count);
idle_no_sleep();
}
}
@@ -236,12 +235,8 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_PURGE);
#endif
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Filament Purging..."), CONTINUE_STR);
- #endif
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onUserConfirmRequired_P(PSTR("Filament Purging..."));
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Filament Purging..."), CONTINUE_STR));
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Filament Purging...")));
wait_for_user = true; // A click or M108 breaks the purge_length loop
for (float purge_count = purge_length; purge_count > 0 && wait_for_user; --purge_count)
unscaled_e_move(1, ADVANCED_PAUSE_PURGE_FEEDRATE);
@@ -260,9 +255,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
unscaled_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE);
}
- #if ENABLED(HOST_PROMPT_SUPPORT)
- filament_load_host_prompt(); // Initiate another host prompt. (NOTE: host_response_handler may also do this!)
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, filament_load_host_prompt()); // Initiate another host prompt. (NOTE: host_response_handler may also do this!)
#if HAS_LCD_MENU
if (show_lcd) {
@@ -275,13 +268,10 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
#endif
// Keep looping if "Purge More" was selected
- } while (false
- #if HAS_LCD_MENU
- || (show_lcd && pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE)
- #endif
- );
+ } while (TERN0(HAS_LCD_MENU, show_lcd && pause_menu_response == PAUSE_RESPONSE_EXTRUDE_MORE));
#endif
+ TERN_(HOST_PROMPT_SUPPORT, host_action_prompt_end());
return true;
}
@@ -302,15 +292,13 @@ bool unload_filament(const float &unload_length, const bool show_lcd/*=false*/,
, const float &mix_multiplier/*=1.0*/
#endif
) {
- #if !HAS_LCD_MENU
- UNUSED(show_lcd);
- #endif
+ TERN(HAS_LCD_MENU,,UNUSED(show_lcd));
#if !BOTH(FILAMENT_UNLOAD_ALL_EXTRUDERS, MIXING_EXTRUDER)
constexpr float mix_multiplier = 1.0;
#endif
- if (!ensure_safe_temperature(mode)) {
+ if (!ensure_safe_temperature(false, mode)) {
#if HAS_LCD_MENU
if (show_lcd) lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
#endif
@@ -370,10 +358,7 @@ bool unload_filament(const float &unload_length, const bool show_lcd/*=false*/,
uint8_t did_pause_print = 0;
bool pause_print(const float &retract, const xyz_pos_t &park_point, const float &unload_length/*=0*/, const bool show_lcd/*=false*/ DXC_ARGS) {
-
- #if !HAS_LCD_MENU
- UNUSED(show_lcd);
- #endif
+ TERN(HAS_LCD_MENU,,UNUSED(show_lcd));
if (did_pause_print) return false; // already paused
@@ -385,9 +370,7 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
#endif
#endif
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_open(PROMPT_INFO, PSTR("Pause"), DISMISS_STR);
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("Pause"), DISMISS_STR));
if (!DEBUGGING(DRYRUN) && unload_length && thermalManager.targetTooColdToExtrude(active_extruder)) {
SERIAL_ECHO_MSG(STR_ERR_HOTEND_TOO_COLD);
@@ -421,7 +404,7 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
// Wait for buffered blocks to complete
planner.synchronize();
- #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && FAN_COUNT > 0
+ #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
thermalManager.set_fans_paused(true);
#endif
@@ -430,8 +413,8 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
unscaled_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
// Park the nozzle by moving up by z_lift and then moving to (x_pos, y_pos)
- if (!axes_need_homing())
- nozzle.park(2, park_point);
+ if (!axes_should_home())
+ nozzle.park(0, park_point);
#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
@@ -466,9 +449,7 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
*/
void show_continue_prompt(const bool is_reload) {
- #if HAS_LCD_MENU
- lcd_pause_show_message(is_reload ? PAUSE_MESSAGE_INSERT : PAUSE_MESSAGE_WAITING);
- #endif
+ TERN_(HAS_LCD_MENU, lcd_pause_show_message(is_reload ? PAUSE_MESSAGE_INSERT : PAUSE_MESSAGE_WAITING));
SERIAL_ECHO_START();
serialprintPGM(is_reload ? PSTR(_PMSG(STR_FILAMENT_CHANGE_INSERT) "\n") : PSTR(_PMSG(STR_FILAMENT_CHANGE_WAIT) "\n"));
}
@@ -478,14 +459,10 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
show_continue_prompt(is_reload);
- #if HAS_BUZZER
- filament_change_beep(max_beep_count, true);
- #else
- UNUSED(max_beep_count);
- #endif
+ first_impatient_beep(max_beep_count);
// Start the heater idle timers
- const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
+ const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
@@ -498,17 +475,11 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
// Wait for filament insert by user and press button
KEEPALIVE_STATE(PAUSED_FOR_USER);
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Nozzle Parked"), CONTINUE_STR);
- #endif
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onUserConfirmRequired_P(PSTR("Nozzle Parked"));
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, GET_TEXT(MSG_NOZZLE_PARKED), CONTINUE_STR));
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_NOZZLE_PARKED)));
wait_for_user = true; // LCD click or M108 will clear this
while (wait_for_user) {
- #if HAS_BUZZER
- filament_change_beep(max_beep_count);
- #endif
+ impatient_beep(max_beep_count);
// If the nozzle has timed out...
if (!nozzle_timed_out)
@@ -517,53 +488,38 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
// Wait for the user to press the button to re-heat the nozzle, then
// re-heat the nozzle, re-show the continue prompt, restart idle timers, start over
if (nozzle_timed_out) {
- #if HAS_LCD_MENU
- lcd_pause_show_message(PAUSE_MESSAGE_HEAT);
- #endif
+ TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_HEAT));
SERIAL_ECHO_MSG(_PMSG(STR_FILAMENT_CHANGE_HEAT));
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_USER_CONTINUE, PSTR("HeaterTimeout"), PSTR("Reheat"));
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, GET_TEXT(MSG_HEATER_TIMEOUT), GET_TEXT(MSG_REHEAT)));
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onUserConfirmRequired_P(PSTR("HeaterTimeout"));
- #endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(GET_TEXT(MSG_HEATER_TIMEOUT)));
wait_for_user_response(0, true); // Wait for LCD click or M108
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_INFO, PSTR("Reheating"));
- #endif
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onStatusChanged(PSTR("Reheating..."));
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_INFO, GET_TEXT(MSG_REHEATING)));
+
+ TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged_P(GET_TEXT(MSG_REHEATING)));
// Re-enable the heaters if they timed out
HOTEND_LOOP() thermalManager.reset_hotend_idle_timer(e);
// Wait for the heaters to reach the target temperatures
- ensure_safe_temperature();
+ ensure_safe_temperature(false);
// Show the prompt to continue
show_continue_prompt(is_reload);
// Start the heater idle timers
- const millis_t nozzle_timeout = (millis_t)(PAUSE_PARK_NOZZLE_TIMEOUT) * 1000UL;
+ const millis_t nozzle_timeout = SEC_TO_MS(PAUSE_PARK_NOZZLE_TIMEOUT);
HOTEND_LOOP() thermalManager.hotend_idle[e].start(nozzle_timeout);
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Reheat Done"), CONTINUE_STR);
- #endif
- #if ENABLED(EXTENSIBLE_UI)
- ExtUI::onUserConfirmRequired_P(PSTR("Reheat finished."));
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Reheat Done"), CONTINUE_STR));
+ TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Reheat finished.")));
wait_for_user = true;
nozzle_timed_out = false;
- #if HAS_BUZZER
- filament_change_beep(max_beep_count, true);
- #endif
+ first_impatient_beep(max_beep_count);
}
idle_no_sleep();
}
@@ -583,16 +539,18 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
* - a nozzle timed out, or
* - the nozzle is already heated.
* - Display "wait for print to resume"
+ * - Retract to prevent oozing
+ * - Move the nozzle back to resume_position
+ * - Unretract
* - Re-prime the nozzle...
* - FWRETRACT: Recover/prime from the prior G10.
* - !FWRETRACT: Retract by resume_position.e, if negative.
* Not sure how this logic comes into use.
- * - Move the nozzle back to resume_position
* - Sync the planner E to resume_position.e
* - Send host action for resume, if configured
* - Resume the current SD print job, if any
*/
-void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/ DXC_ARGS) {
+void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_length/*=0*/, const float &purge_length/*=ADVANCED_PAUSE_PURGE_LENGTH*/, const int8_t max_beep_count/*=0*/, int16_t targetTemp/*=0*/ DXC_ARGS) {
/*
SERIAL_ECHOLNPAIR(
"start of resume_print()\ndual_x_carriage_mode:", dual_x_carriage_mode,
@@ -611,12 +569,33 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le
thermalManager.reset_hotend_idle_timer(e);
}
+ if (targetTemp > thermalManager.degTargetHotend(active_extruder))
+ thermalManager.setTargetHotend(targetTemp, active_extruder);
+
if (nozzle_timed_out || thermalManager.hotEnoughToExtrude(active_extruder)) // Load the new filament
load_filament(slow_load_length, fast_load_length, purge_length, max_beep_count, true, nozzle_timed_out, PAUSE_MODE_SAME DXC_PASS);
- #if HAS_LCD_MENU
- lcd_pause_show_message(PAUSE_MESSAGE_RESUME);
- #endif
+ if (targetTemp > 0) {
+ thermalManager.setTargetHotend(targetTemp, active_extruder);
+ thermalManager.wait_for_hotend(active_extruder, false);
+ }
+
+ TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_RESUME));
+
+ // Check Temperature before moving hotend
+ ensure_safe_temperature();
+
+ // Retract to prevent oozing
+ unscaled_e_move(-(PAUSE_PARK_RETRACT_LENGTH), feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
+
+ // Move XY to starting position, then Z
+ do_blocking_move_to_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE));
+
+ // Move Z_AXIS to saved position
+ do_blocking_move_to_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
+
+ // Unretract
+ unscaled_e_move(PAUSE_PARK_RETRACT_LENGTH, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
// Intelligent resuming
#if ENABLED(FWRETRACT)
@@ -627,13 +606,6 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le
// If resume_position is negative
if (resume_position.e < 0) unscaled_e_move(resume_position.e, feedRate_t(PAUSE_PARK_RETRACT_FEEDRATE));
-
- // Move XY to starting position, then Z
- do_blocking_move_to_xy(resume_position, feedRate_t(NOZZLE_PARK_XY_FEEDRATE));
-
- // Move Z_AXIS to saved position
- do_blocking_move_to_z(resume_position.z, feedRate_t(NOZZLE_PARK_Z_FEEDRATE));
-
#if ADVANCED_PAUSE_RESUME_PRIME != 0
unscaled_e_move(ADVANCED_PAUSE_RESUME_PRIME, feedRate_t(ADVANCED_PAUSE_PURGE_FEEDRATE));
#endif
@@ -642,9 +614,7 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le
// Set extruder to saved position
planner.set_e_position_mm((destination.e = current_position.e = resume_position.e));
- #if HAS_LCD_MENU
- lcd_pause_show_message(PAUSE_MESSAGE_STATUS);
- #endif
+ TERN_(HAS_LCD_MENU, lcd_pause_show_message(PAUSE_MESSAGE_STATUS));
#ifdef ACTION_ON_RESUMED
host_action_resumed();
@@ -654,34 +624,23 @@ void resume_print(const float &slow_load_length/*=0*/, const float &fast_load_le
--did_pause_print;
- #if ENABLED(HOST_PROMPT_SUPPORT)
- host_prompt_open(PROMPT_INFO, PSTR("Resuming"), DISMISS_STR);
- #endif
+ TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("Resuming"), DISMISS_STR));
#if ENABLED(SDSUPPORT)
- if (did_pause_print) {
- card.startFileprint();
- --did_pause_print;
- }
+ if (did_pause_print) { card.startFileprint(); --did_pause_print; }
#endif
- #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && FAN_COUNT > 0
+ #if ENABLED(ADVANCED_PAUSE_FANS_PAUSE) && HAS_FAN
thermalManager.set_fans_paused(false);
#endif
- #if HAS_FILAMENT_SENSOR
- runout.reset();
- #endif
+ TERN_(HAS_FILAMENT_SENSOR, runout.reset());
// Resume the print job timer if it was running
if (print_job_timer.isPaused()) print_job_timer.start();
- #if HAS_DISPLAY
- ui.reset_status();
- #if HAS_LCD_MENU
- ui.return_to_status();
- #endif
- #endif
+ TERN_(HAS_DISPLAY, ui.reset_status());
+ TERN_(HAS_LCD_MENU, ui.return_to_status());
}
#endif // ADVANCED_PAUSE_FEATURE
diff --git a/Marlin/src/feature/pause.h b/Marlin/src/feature/pause.h
index f1c8eed4d3..d8a676afa4 100644
--- a/Marlin/src/feature/pause.h
+++ b/Marlin/src/feature/pause.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
@@ -45,7 +45,7 @@ enum PauseMode : char {
};
enum PauseMessage : char {
- PAUSE_MESSAGE_PAUSING,
+ PAUSE_MESSAGE_PARKING,
PAUSE_MESSAGE_CHANGING,
PAUSE_MESSAGE_WAITING,
PAUSE_MESSAGE_UNLOAD,
@@ -87,7 +87,7 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
void wait_for_confirmation(const bool is_reload=false, const int8_t max_beep_count=0 DXC_PARAMS);
-void resume_print(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=ADVANCED_PAUSE_PURGE_LENGTH, const int8_t max_beep_count=0 DXC_PARAMS);
+void resume_print(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=ADVANCED_PAUSE_PURGE_LENGTH, const int8_t max_beep_count=0, int16_t targetTemp=0 DXC_PARAMS);
bool load_filament(const float &slow_load_length=0, const float &fast_load_length=0, const float &extrude_length=0, const int8_t max_beep_count=0, const bool show_lcd=false,
const bool pause_for_user=false, const PauseMode mode=PAUSE_MODE_PAUSE_PRINT DXC_PARAMS);
diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp
index 1fa751811e..5be554e5e4 100644
--- a/Marlin/src/feature/power.cpp
+++ b/Marlin/src/feature/power.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -33,6 +33,10 @@
#include "../module/stepper/indirection.h"
#include "../MarlinCore.h"
+#if BOTH(USE_CONTROLLER_FAN, AUTO_POWER_CONTROLLERFAN)
+ #include "controllerfan.h"
+#endif
+
Power powerManager;
millis_t Power::lastPowerOn;
@@ -50,15 +54,11 @@ bool Power::is_power_needed() {
if (controllerFan.state()) return true;
#endif
- #if ENABLED(AUTO_POWER_CHAMBER_FAN)
- if (thermalManager.chamberfan_speed) return true;
- #endif
+ if (TERN0(AUTO_POWER_CHAMBER_FAN, thermalManager.chamberfan_speed))
+ return true;
// If any of the drivers or the bed are enabled...
if (X_ENABLE_READ() == X_ENABLE_ON || Y_ENABLE_READ() == Y_ENABLE_ON || Z_ENABLE_READ() == Z_ENABLE_ON
- #if HAS_HEATED_BED
- || thermalManager.temp_bed.soft_pwm_amount > 0
- #endif
#if HAS_X2_ENABLE
|| X2_ENABLE_READ() == X_ENABLE_ON
#endif
@@ -74,13 +74,10 @@ bool Power::is_power_needed() {
#endif
) return true;
- HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0) return true;
+ HOTEND_LOOP() if (thermalManager.degTargetHotend(e) > 0 || thermalManager.temp_hotend[e].soft_pwm_amount > 0) return true;
+ if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0 || thermalManager.temp_bed.soft_pwm_amount > 0)) return true;
- #if HAS_HEATED_BED
- if (thermalManager.degTargetBed() > 0) return true;
- #endif
-
- #if HOTENDS && AUTO_POWER_E_TEMP
+ #if HAS_HOTEND && AUTO_POWER_E_TEMP
HOTEND_LOOP() if (thermalManager.degHotend(e) >= AUTO_POWER_E_TEMP) return true;
#endif
@@ -98,7 +95,7 @@ void Power::check() {
nextPowerCheck = ms + 2500UL;
if (is_power_needed())
power_on();
- else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + (POWER_TIMEOUT) * 1000UL))
+ else if (!lastPowerOn || ELAPSED(ms, lastPowerOn + SEC_TO_MS(POWER_TIMEOUT)))
power_off();
}
}
@@ -107,11 +104,9 @@ void Power::power_on() {
lastPowerOn = millis();
if (!powersupply_on) {
PSU_PIN_ON();
-
- #if HAS_TRINAMIC_CONFIG
- delay(PSU_POWERUP_DELAY); // Wait for power to settle
- restore_stepper_drivers();
- #endif
+ safe_delay(PSU_POWERUP_DELAY);
+ restore_stepper_drivers();
+ TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
}
}
diff --git a/Marlin/src/feature/power.h b/Marlin/src/feature/power.h
index 0bad7736ef..8b988907e6 100644
--- a/Marlin/src/feature/power.h
+++ b/Marlin/src/feature/power.h
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
diff --git a/Marlin/src/feature/power_monitor.cpp b/Marlin/src/feature/power_monitor.cpp
new file mode 100644
index 0000000000..bf5ac748a8
--- /dev/null
+++ b/Marlin/src/feature/power_monitor.cpp
@@ -0,0 +1,75 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (C) 2020 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 .
+ *
+ */
+
+#include "../inc/MarlinConfigPre.h"
+
+#if HAS_POWER_MONITOR
+
+#include "power_monitor.h"
+
+#include "../lcd/ultralcd.h"
+#include "../lcd/lcdprint.h"
+#include "../libs/numtostr.h"
+
+uint8_t PowerMonitor::flags; // = 0
+
+#if ENABLED(POWER_MONITOR_CURRENT)
+ pm_lpf_t PowerMonitor::amps;
+#endif
+#if ENABLED(POWER_MONITOR_VOLTAGE)
+ pm_lpf_t PowerMonitor::volts;
+#endif
+
+millis_t PowerMonitor::display_item_ms;
+uint8_t PowerMonitor::display_item;
+
+PowerMonitor power_monitor; // Single instance - this calls the constructor
+
+#if HAS_GRAPHICAL_LCD
+
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ void PowerMonitor::draw_current() {
+ const float amps = getAmps();
+ lcd_put_u8str(amps < 100 ? ftostr31ns(amps) : ui16tostr4rj((uint16_t)amps));
+ lcd_put_wchar('A');
+ }
+ #endif
+
+ #if HAS_POWER_MONITOR_VREF
+ void PowerMonitor::draw_voltage() {
+ const float volts = getVolts();
+ lcd_put_u8str(volts < 100 ? ftostr31ns(volts) : ui16tostr4rj((uint16_t)volts));
+ lcd_put_wchar('V');
+ }
+ #endif
+
+ #if HAS_POWER_MONITOR_WATTS
+ void PowerMonitor::draw_power() {
+ const float power = getPower();
+ lcd_put_u8str(power < 100 ? ftostr31ns(power) : ui16tostr4rj((uint16_t)power));
+ lcd_put_wchar('W');
+ }
+ #endif
+
+#endif // HAS_GRAPHICAL_LCD
+
+#endif // HAS_POWER_MONITOR
diff --git a/Marlin/src/feature/power_monitor.h b/Marlin/src/feature/power_monitor.h
new file mode 100644
index 0000000000..ca52ed74c6
--- /dev/null
+++ b/Marlin/src/feature/power_monitor.h
@@ -0,0 +1,140 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (C) 2020 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 .
+ *
+ */
+#pragma once
+
+#include "../inc/MarlinConfig.h"
+
+#define PM_SAMPLE_RANGE 1024
+#define PM_K_VALUE 6
+#define PM_K_SCALE 6
+
+template
+struct pm_lpf_t {
+ uint32_t filter_buf;
+ float value;
+ void add_sample(const uint16_t sample) {
+ filter_buf = filter_buf - (filter_buf >> K_VALUE) + (uint32_t(sample) << K_SCALE);
+ }
+ void capture() {
+ value = filter_buf * (SCALE * (1.0f / (1UL << (PM_K_VALUE + PM_K_SCALE)))) + (POWER_MONITOR_CURRENT_OFFSET);
+ }
+ void reset(uint16_t reset_value = 0) {
+ filter_buf = uint32_t(reset_value) << (K_VALUE + K_SCALE);
+ capture();
+ }
+};
+
+class PowerMonitor {
+private:
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ static constexpr float amps_adc_scale = float(ADC_VREF) / (POWER_MONITOR_VOLTS_PER_AMP * PM_SAMPLE_RANGE);
+ static pm_lpf_t amps;
+ #endif
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ static constexpr float volts_adc_scale = float(ADC_VREF) / (POWER_MONITOR_VOLTS_PER_VOLT * PM_SAMPLE_RANGE);
+ static pm_lpf_t volts;
+ #endif
+
+public:
+ static uint8_t flags; // M430 flags to display current
+
+ static millis_t display_item_ms;
+ static uint8_t display_item;
+
+ PowerMonitor() { reset(); }
+
+ enum PM_Display_Bit : uint8_t {
+ PM_DISP_BIT_I, // Current display enable bit
+ PM_DISP_BIT_V, // Voltage display enable bit
+ PM_DISP_BIT_P // Power display enable bit
+ };
+
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ FORCE_INLINE static float getAmps() { return amps.value; }
+ void add_current_sample(const uint16_t value) { amps.add_sample(value); }
+ #endif
+
+ #if HAS_POWER_MONITOR_VREF
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ FORCE_INLINE static float getVolts() { return volts.value; }
+ #else
+ FORCE_INLINE static float getVolts() { return POWER_MONITOR_FIXED_VOLTAGE; } // using a specified fixed valtage as the voltage measurement
+ #endif
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ void add_voltage_sample(const uint16_t value) { volts.add_sample(value); }
+ #endif
+ #endif
+
+ #if HAS_POWER_MONITOR_WATTS
+ FORCE_INLINE static float getPower() { return getAmps() * getVolts(); }
+ #endif
+
+ #if HAS_SPI_LCD
+ FORCE_INLINE static bool display_enabled() { return flags != 0x00; }
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ static void draw_current();
+ FORCE_INLINE static bool current_display_enabled() { return TEST(flags, PM_DISP_BIT_I); }
+ FORCE_INLINE static void set_current_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_I, b); }
+ FORCE_INLINE static void toggle_current_display() { TBI(flags, PM_DISP_BIT_I); }
+ #endif
+ #if HAS_POWER_MONITOR_VREF
+ static void draw_voltage();
+ FORCE_INLINE static bool voltage_display_enabled() { return TEST(flags, PM_DISP_BIT_V); }
+ FORCE_INLINE static void set_voltage_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_V, b); }
+ FORCE_INLINE static void toggle_voltage_display() { TBI(flags, PM_DISP_BIT_V); }
+ #endif
+ #if HAS_POWER_MONITOR_WATTS
+ static void draw_power();
+ FORCE_INLINE static bool power_display_enabled() { return TEST(flags, PM_DISP_BIT_P); }
+ FORCE_INLINE static void set_power_display(const bool b) { SET_BIT_TO(flags, PM_DISP_BIT_P, b); }
+ FORCE_INLINE static void toggle_power_display() { TBI(flags, PM_DISP_BIT_P); }
+ #endif
+ #endif
+
+ static void reset() {
+ flags = 0x00;
+
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ amps.reset();
+ #endif
+
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ volts.reset();
+ #endif
+
+ #if ENABLED(SDSUPPORT)
+ display_item_ms = 0;
+ display_item = 0;
+ #endif
+ }
+
+ static void capture_values() {
+ #if ENABLED(POWER_MONITOR_CURRENT)
+ amps.capture();
+ #endif
+ #if ENABLED(POWER_MONITOR_VOLTAGE)
+ volts.capture();
+ #endif
+ }
+};
+
+extern PowerMonitor power_monitor;
diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp
index bb0062d4ec..06296dd215 100644
--- a/Marlin/src/feature/powerloss.cpp
+++ b/Marlin/src/feature/powerloss.cpp
@@ -16,12 +16,12 @@
* 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 .
+ * along with this program. If not, see .
*
*/
/**
- * power_loss_recovery.cpp - Resume an SD print after power-loss
+ * feature/powerloss.cpp - Resume an SD print after power-loss
*/
#include "../inc/MarlinConfigPre.h"
@@ -40,6 +40,10 @@ uint8_t PrintJobRecovery::queue_index_r;
uint32_t PrintJobRecovery::cmd_sdpos, // = 0
PrintJobRecovery::sdpos[BUFSIZE];
+#if ENABLED(DWIN_CREALITY_LCD)
+ bool PrintJobRecovery::dwin_flag; // = false
+#endif
+
#include "../sd/cardreader.h"
#include "../lcd/ultralcd.h"
#include "../gcode/queue.h"
@@ -62,12 +66,16 @@ PrintJobRecovery recovery;
#ifndef POWER_LOSS_PURGE_LEN
#define POWER_LOSS_PURGE_LEN 0
#endif
+#ifndef POWER_LOSS_ZRAISE
+ #define POWER_LOSS_ZRAISE 2 // Move on loss with backup power, or on resume without it
+#endif
+
+#if DISABLED(BACKUP_POWER_SUPPLY)
+ #undef POWER_LOSS_RETRACT_LEN // No retract at outage without backup power
+#endif
#ifndef POWER_LOSS_RETRACT_LEN
#define POWER_LOSS_RETRACT_LEN 0
#endif
-#ifndef POWER_LOSS_ZRAISE
- #define POWER_LOSS_ZRAISE 2
-#endif
/**
* Clear the recovery info
@@ -103,8 +111,9 @@ void PrintJobRecovery::check() {
//if (!card.isMounted()) card.mount();
if (card.isMounted()) {
load();
- if (!valid()) return purge();
+ if (!valid()) return cancel();
queue.inject_P(PSTR("M1000 S"));
+ TERN_(DWIN_CREALITY_LCD, dwin_flag = true);
}
}
@@ -139,7 +148,7 @@ void PrintJobRecovery::prepare() {
/**
* Save the current machine state to the power-loss recovery file
*/
-void PrintJobRecovery::save(const bool force/*=false*/) {
+void PrintJobRecovery::save(const bool force/*=false*/, const float zraise/*=0*/) {
#if SAVE_INFO_INTERVAL_MS > 0
static millis_t next_save_ms; // = 0
@@ -172,12 +181,9 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
// Machine state
info.current_position = current_position;
- #if HAS_HOME_OFFSET
- info.home_offset = home_offset;
- #endif
- #if HAS_POSITION_SHIFT
- info.position_shift = position_shift;
- #endif
+ info.zraise = zraise;
+ TERN_(HAS_HOME_OFFSET, info.home_offset = home_offset);
+ TERN_(HAS_POSITION_SHIFT, info.position_shift = position_shift);
info.feedrate = uint16_t(feedrate_mm_s * 60.0f);
#if EXTRUDERS > 1
@@ -189,7 +195,7 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
#if EXTRUDERS > 1
for (int8_t e = 0; e < EXTRUDERS; e++) info.filament_size[e] = planner.filament_size[e];
#else
- if (parser.volumetric_enabled) info.filament_size = planner.filament_size[active_extruder];
+ if (parser.volumetric_enabled) info.filament_size[0] = planner.filament_size[active_extruder];
#endif
#endif
@@ -197,28 +203,18 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
HOTEND_LOOP() info.target_temperature[e] = thermalManager.temp_hotend[e].target;
#endif
- #if HAS_HEATED_BED
- info.target_temperature_bed = thermalManager.temp_bed.target;
- #endif
+ TERN_(HAS_HEATED_BED, info.target_temperature_bed = thermalManager.temp_bed.target);
- #if FAN_COUNT
+ #if HAS_FAN
COPY(info.fan_speed, thermalManager.fan_speed);
#endif
#if HAS_LEVELING
info.leveling = planner.leveling_active;
- info.fade = (
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- planner.z_fade_height
- #else
- 0
- #endif
- );
+ info.fade = TERN0(ENABLE_LEVELING_FADE_HEIGHT, planner.z_fade_height);
#endif
- #if ENABLED(GRADIENT_MIX)
- memcpy(&info.gradient, &mixer.gradient, sizeof(info.gradient));
- #endif
+ TERN_(GRADIENT_MIX, memcpy(&info.gradient, &mixer.gradient, sizeof(info.gradient)));
#if ENABLED(FWRETRACT)
COPY(info.retract, fwretract.current_retract);
@@ -237,33 +233,74 @@ void PrintJobRecovery::save(const bool force/*=false*/) {
#if PIN_EXISTS(POWER_LOSS)
+ #if ENABLED(BACKUP_POWER_SUPPLY)
+
+ void PrintJobRecovery::retract_and_lift(const float &zraise) {
+ #if POWER_LOSS_RETRACT_LEN || POWER_LOSS_ZRAISE
+
+ gcode.set_relative_mode(true); // Use relative coordinates
+
+ #if POWER_LOSS_RETRACT_LEN
+ // Retract filament now
+ gcode.process_subcommands_now_P(PSTR("G1 F3000 E-" STRINGIFY(POWER_LOSS_RETRACT_LEN)));
+ #endif
+
+ #if POWER_LOSS_ZRAISE
+ // Raise the Z axis now
+ if (zraise) {
+ char cmd[20], str_1[16];
+ sprintf_P(cmd, PSTR("G0 Z%s"), dtostrf(zraise, 1, 3, str_1));
+ gcode.process_subcommands_now(cmd);
+ }
+ #else
+ UNUSED(zraise);
+ #endif
+
+ //gcode.axis_relative = info.axis_relative;
+ planner.synchronize();
+ #endif
+ }
+
+ #endif
+
+ /**
+ * An outage was detected by a sensor pin.
+ * - If not SD printing, let the machine turn off on its own with no "KILL" screen
+ * - Disable all heaters first to save energy
+ * - Save the recovery data for the current instant
+ * - If backup power is available Retract E and Raise Z
+ * - Go to the KILL screen
+ */
void PrintJobRecovery::_outage() {
#if ENABLED(BACKUP_POWER_SUPPLY)
static bool lock = false;
- if (lock) return; // No re-entrance from idle() during raise_z()
+ if (lock) return; // No re-entrance from idle() during retract_and_lift()
lock = true;
#endif
- if (IS_SD_PRINTING()) save(true);
+
+ #if POWER_LOSS_ZRAISE
+ // Get the limited Z-raise to do now or on resume
+ const float zraise = _MAX(0, _MIN(current_position.z + POWER_LOSS_ZRAISE, Z_MAX_POS - 1) - current_position.z);
+ #else
+ constexpr float zraise = 0;
+ #endif
+
+ // Save, including the limited Z raise
+ if (IS_SD_PRINTING()) save(true, zraise);
+
+ // Disable all heaters to reduce power loss
+ thermalManager.disable_all_heaters();
+
#if ENABLED(BACKUP_POWER_SUPPLY)
- raise_z();
+ // Do a hard-stop of the steppers (with possibly a loud thud)
+ quickstop_stepper();
+ // With backup power a retract and raise can be done now
+ retract_and_lift(zraise);
#endif
kill(GET_TEXT(MSG_OUTAGE_RECOVERY));
}
- #if ENABLED(BACKUP_POWER_SUPPLY)
-
- void PrintJobRecovery::raise_z() {
- // Disable all heaters to reduce power loss
- thermalManager.disable_all_heaters();
- quickstop_stepper();
- // Raise Z axis
- gcode.process_subcommands_now_P(PSTR("G91\nG0 Z" STRINGIFY(POWER_LOSS_ZRAISE)));
- planner.synchronize();
- }
-
- #endif
-
#endif
/**
@@ -285,6 +322,8 @@ void PrintJobRecovery::write() {
*/
void PrintJobRecovery::resume() {
+ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
+
const uint32_t resume_sdpos = info.sdpos; // Get here before the stepper ISR overwrites it
#if HAS_LEVELING
@@ -293,54 +332,46 @@ void PrintJobRecovery::resume() {
#endif
// Reset E, raise Z, home XY...
- gcode.process_subcommands_now_P(PSTR("G92.9 E0"
- #if Z_HOME_DIR > 0
+ #if Z_HOME_DIR > 0
- // If Z homing goes to max, just reset E and home all
- "\n"
- "G28R0"
- #if ENABLED(MARLIN_DEV_MODE)
- "S"
- #endif
+ // If Z homing goes to max, just reset E and home all
+ gcode.process_subcommands_now_P(PSTR(
+ "G92.9 E0\n"
+ "G28R0" TERN_(MARLIN_DEV_MODE, "S")
+ ));
- #else // "G92.9 E0 ..."
+ #else // "G92.9 E0 ..."
- // Set Z to 0, raise Z by RECOVERY_ZRAISE, and Home (XY only for Cartesian)
- // with no raise. (Only do simulated homing in Marlin Dev Mode.)
- #if ENABLED(BACKUP_POWER_SUPPLY)
- "Z" STRINGIFY(POWER_LOSS_ZRAISE) // Z-axis was already raised at outage
- #else
- "Z0\n" // Set Z=0
- "G1Z" STRINGIFY(POWER_LOSS_ZRAISE) // Raise Z
- #endif
- "\n"
+ // Set Z to 0, raise Z by info.zraise, and Home (XY only for Cartesian)
+ // with no raise. (Only do simulated homing in Marlin Dev Mode.)
- "G28R0"
- #if ENABLED(MARLIN_DEV_MODE)
- "S"
- #elif !IS_KINEMATIC
- "XY"
- #endif
- #endif
- ));
+ sprintf_P(cmd, PSTR("G92.9 E0 "
+ #if ENABLED(BACKUP_POWER_SUPPLY)
+ "Z%s" // Z was already raised at outage
+ #else
+ "Z0\nG1Z%s" // Set Z=0 and Raise Z now
+ #endif
+ ),
+ dtostrf(info.zraise, 1, 3, str_1)
+ );
+ gcode.process_subcommands_now(cmd);
+
+ gcode.process_subcommands_now_P(PSTR(
+ "G28R0" // No raise during G28
+ TERN_(MARLIN_DEV_MODE, "S") // Simulated Homing
+ TERN_(IS_CARTESIAN, "XY") // Don't home Z on Cartesian
+ ));
+
+ #endif
// Pretend that all axes are homed
- axis_homed = axis_known_position = xyz_bits;
-
- char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16];
-
- // Select the previously active tool (with no_move)
- #if EXTRUDERS > 1
- sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
- gcode.process_subcommands_now(cmd);
- #endif
+ set_all_homed();
// Recover volumetric extrusion state
#if DISABLED(NO_VOLUMETRICS)
#if EXTRUDERS > 1
for (int8_t e = 0; e < EXTRUDERS; e++) {
- dtostrf(info.filament_size[e], 1, 3, str_1);
- sprintf_P(cmd, PSTR("M200 T%i D%s"), e, str_1);
+ sprintf_P(cmd, PSTR("M200 T%i D%s"), e, dtostrf(info.filament_size[e], 1, 3, str_1));
gcode.process_subcommands_now(cmd);
}
if (!info.volumetric_enabled) {
@@ -349,8 +380,7 @@ void PrintJobRecovery::resume() {
}
#else
if (info.volumetric_enabled) {
- dtostrf(info.filament_size, 1, 3, str_1);
- sprintf_P(cmd, PSTR("M200 D%s"), str_1);
+ sprintf_P(cmd, PSTR("M200 D%s"), dtostrf(info.filament_size[0], 1, 3, str_1));
gcode.process_subcommands_now(cmd);
}
#endif
@@ -366,12 +396,12 @@ void PrintJobRecovery::resume() {
#endif
// Restore all hotend temperatures
- #if HOTENDS
+ #if HAS_HOTEND
HOTEND_LOOP() {
const int16_t et = info.target_temperature[e];
if (et) {
- #if HOTENDS > 1
- sprintf_P(cmd, PSTR("T%i"), e);
+ #if HAS_MULTI_HOTEND
+ sprintf_P(cmd, PSTR("T%i S"), e);
gcode.process_subcommands_now(cmd);
#endif
sprintf_P(cmd, PSTR("M109 S%i"), et);
@@ -380,6 +410,12 @@ void PrintJobRecovery::resume() {
}
#endif
+ // Select the previously active tool (with no_move)
+ #if EXTRUDERS > 1
+ sprintf_P(cmd, PSTR("T%i S"), info.active_extruder);
+ gcode.process_subcommands_now(cmd);
+ #endif
+
// Restore print cooling fan speeds
FANS_LOOP(i) {
uint8_t f = info.fan_speed[i];
@@ -413,18 +449,21 @@ void PrintJobRecovery::resume() {
memcpy(&mixer.gradient, &info.gradient, sizeof(info.gradient));
#endif
- // Extrude and retract to clean the nozzle
- #if POWER_LOSS_PURGE_LEN
- //sprintf_P(cmd, PSTR("G1 E%d F200"), POWER_LOSS_PURGE_LEN);
- //gcode.process_subcommands_now(cmd);
- gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F200"));
+ // Un-retract if there was a retract at outage
+ #if POWER_LOSS_RETRACT_LEN
+ gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_RETRACT_LEN) " F3000"));
#endif
- #if POWER_LOSS_RETRACT_LEN
- sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN - (POWER_LOSS_RETRACT_LEN));
+ // Additional purge if configured
+ #if POWER_LOSS_PURGE_LEN
+ sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN));
gcode.process_subcommands_now(cmd);
#endif
+ #if ENABLED(NOZZLE_CLEAN_FEATURE)
+ gcode.process_subcommands_now_P(PSTR("G12"));
+ #endif
+
// Move back to the saved XY
sprintf_P(cmd, PSTR("G1 X%s Y%s F3000"),
dtostrf(info.current_position.x, 1, 3, str_1),
@@ -442,13 +481,6 @@ void PrintJobRecovery::resume() {
#endif
gcode.process_subcommands_now(cmd);
- // Un-retract
- #if POWER_LOSS_PURGE_LEN
- //sprintf_P(cmd, PSTR("G1 E%d F3000"), POWER_LOSS_PURGE_LEN);
- //gcode.process_subcommands_now(cmd);
- gcode.process_subcommands_now_P(PSTR("G1 E" STRINGIFY(POWER_LOSS_PURGE_LEN) " F3000"));
- #endif
-
// Restore the feedrate
sprintf_P(cmd, PSTR("G1 F%d"), info.feedrate);
gcode.process_subcommands_now(cmd);
@@ -460,12 +492,8 @@ void PrintJobRecovery::resume() {
// Relative axis modes
gcode.axis_relative = info.axis_relative;
- #if HAS_HOME_OFFSET
- home_offset = info.home_offset;
- #endif
- #if HAS_POSITION_SHIFT
- position_shift = info.position_shift;
- #endif
+ TERN_(HAS_HOME_OFFSET, home_offset = info.home_offset);
+ TERN_(HAS_POSITION_SHIFT, position_shift = info.position_shift);
#if HAS_HOME_OFFSET || HAS_POSITION_SHIFT
LOOP_XYZ(i) update_workspace_offset((AxisEnum)i);
#endif
@@ -489,15 +517,17 @@ void PrintJobRecovery::resume() {
DEBUG_ECHOPGM("current_position: ");
LOOP_XYZE(i) {
if (i) DEBUG_CHAR(',');
- DEBUG_ECHO(info.current_position[i]);
+ DEBUG_DECIMAL(info.current_position[i]);
}
DEBUG_EOL();
+ DEBUG_ECHOLNPAIR("zraise: ", info.zraise);
+
#if HAS_HOME_OFFSET
DEBUG_ECHOPGM("home_offset: ");
LOOP_XYZ(i) {
if (i) DEBUG_CHAR(',');
- DEBUG_ECHO(info.home_offset[i]);
+ DEBUG_DECIMAL(info.home_offset[i]);
}
DEBUG_EOL();
#endif
@@ -506,7 +536,7 @@ void PrintJobRecovery::resume() {
DEBUG_ECHOPGM("position_shift: ");
LOOP_XYZ(i) {
if (i) DEBUG_CHAR(',');
- DEBUG_ECHO(info.position_shift[i]);
+ DEBUG_DECIMAL(info.position_shift[i]);
}
DEBUG_EOL();
#endif
@@ -517,7 +547,7 @@ void PrintJobRecovery::resume() {
DEBUG_ECHOLNPAIR("active_extruder: ", int(info.active_extruder));
#endif
- #if HOTENDS
+ #if HAS_HOTEND
DEBUG_ECHOPGM("target_temperature: ");
HOTEND_LOOP() {
DEBUG_ECHO(info.target_temperature[e]);
@@ -530,7 +560,7 @@ void PrintJobRecovery::resume() {
DEBUG_ECHOLNPAIR("target_temperature_bed: ", info.target_temperature_bed);
#endif
- #if FAN_COUNT
+ #if HAS_FAN
DEBUG_ECHOPGM("fan_speed: ");
FANS_LOOP(i) {
DEBUG_ECHO(int(info.fan_speed[i]));
@@ -540,7 +570,7 @@ void PrintJobRecovery::resume() {
#endif
#if HAS_LEVELING
- DEBUG_ECHOLNPAIR("leveling: ", int(info.leveling), "\n fade: ", int(info.fade));
+ DEBUG_ECHOLNPAIR("leveling: ", int(info.leveling), " fade: ", info.fade);
#endif
#if ENABLED(FWRETRACT)
DEBUG_ECHOPGM("retract: ");
diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h
index 0496560785..10653493ab 100644
--- a/Marlin/src/feature/powerloss.h
+++ b/Marlin/src/feature/powerloss.h
@@ -16,16 +16,18 @@
* 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 .
+ * along with this program. If not, see .
*
*/
#pragma once
/**
- * power_loss_recovery.h - Resume an SD print after power-loss
+ * feature/powerloss.h - Resume an SD print after power-loss
*/
#include "../sd/cardreader.h"
+#include "../gcode/gcode.h"
+
#include "../inc/MarlinConfig.h"
#if ENABLED(MIXING_EXTRUDER)
@@ -45,6 +47,7 @@ typedef struct {
// Machine state
xyze_pos_t current_position;
+ float zraise;
#if HAS_HOME_OFFSET
xyz_pos_t home_offset;
@@ -61,14 +64,10 @@ typedef struct {
#if DISABLED(NO_VOLUMETRICS)
bool volumetric_enabled;
- #if EXTRUDERS > 1
- float filament_size[EXTRUDERS];
- #else
- float filament_size;
- #endif
+ float filament_size[EXTRUDERS];
#endif
- #if HOTENDS
+ #if HAS_HOTEND
int16_t target_temperature[HOTENDS];
#endif
@@ -76,7 +75,7 @@ typedef struct {
int16_t target_temperature_bed;
#endif
- #if FAN_COUNT
+ #if HAS_FAN
uint8_t fan_speed[FAN_COUNT];
#endif
@@ -110,6 +109,8 @@ typedef struct {
uint8_t valid_foot;
+ bool valid() { return valid_head && valid_head == valid_foot; }
+
} job_recovery_info_t;
class PrintJobRecovery {
@@ -123,6 +124,10 @@ class PrintJobRecovery {
static uint32_t cmd_sdpos, //!< SD position of the next command
sdpos[BUFSIZE]; //!< SD positions of queued commands
+ #if ENABLED(DWIN_CREALITY_LCD)
+ static bool dwin_flag;
+ #endif
+
static void init();
static void prepare();
@@ -159,33 +164,34 @@ class PrintJobRecovery {
static inline void cancel() { purge(); card.autostart_index = 0; }
static void load();
- static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE));
+ static void save(const bool force=ENABLED(SAVE_EACH_CMD_MODE), const float zraise=0);
- #if PIN_EXISTS(POWER_LOSS)
- static inline void outage() {
- if (enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE)
- _outage();
- }
- #endif
+ #if PIN_EXISTS(POWER_LOSS)
+ static inline void outage() {
+ if (enabled && READ(POWER_LOSS_PIN) == POWER_LOSS_STATE)
+ _outage();
+ }
+ #endif
- static inline bool valid() { return info.valid_head && info.valid_head == info.valid_foot; }
+ static inline bool valid() { return info.valid(); }
- #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
- static void debug(PGM_P const prefix);
- #else
- static inline void debug(PGM_P const) {}
- #endif
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
+ static void debug(PGM_P const prefix);
+ #else
+ static inline void debug(PGM_P const) {}
+ #endif
private:
static void write();
- #if ENABLED(BACKUP_POWER_SUPPLY)
- static void raise_z();
- #endif
+ #if ENABLED(BACKUP_POWER_SUPPLY)
+ static void retract_and_lift(const float &zraise);
+ #endif
- #if PIN_EXISTS(POWER_LOSS)
- static void _outage();
- #endif
+ #if PIN_EXISTS(POWER_LOSS)
+ friend class GcodeSuite;
+ static void _outage();
+ #endif
};
extern PrintJobRecovery recovery;
diff --git a/Marlin/src/feature/probe_temp_comp.cpp b/Marlin/src/feature/probe_temp_comp.cpp
index 6b787f420a..af8039d8b1 100644
--- a/Marlin/src/feature/probe_temp_comp.cpp
+++ b/Marlin/src/feature/probe_temp_comp.cpp
@@ -16,7 +16,7 @@
* 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 .
+ * along with this program. If not, see .
*
*/
@@ -29,11 +29,11 @@
ProbeTempComp temp_comp;
-int16_t ProbeTempComp::z_offsets_probe[ProbeTempComp::cali_info_init[TSI_PROBE].measurements], // = {0}
- ProbeTempComp::z_offsets_bed[ProbeTempComp::cali_info_init[TSI_BED].measurements]; // = {0}
+int16_t ProbeTempComp::z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // = {0}
+ ProbeTempComp::z_offsets_bed[cali_info_init[TSI_BED].measurements]; // = {0}
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
- int16_t ProbeTempComp::z_offsets_ext[ProbeTempComp::cali_info_init[TSI_EXT].measurements]; // = {0}
+ int16_t ProbeTempComp::z_offsets_ext[cali_info_init[TSI_EXT].measurements]; // = {0}
#endif
int16_t *ProbeTempComp::sensor_z_offsets[TSI_COUNT] = {
@@ -44,12 +44,16 @@ int16_t *ProbeTempComp::sensor_z_offsets[TSI_COUNT] = {
};
const temp_calib_t ProbeTempComp::cali_info[TSI_COUNT] = {
- ProbeTempComp::cali_info_init[TSI_PROBE], ProbeTempComp::cali_info_init[TSI_BED]
+ cali_info_init[TSI_PROBE], cali_info_init[TSI_BED]
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
- , ProbeTempComp::cali_info_init[TSI_EXT]
+ , cali_info_init[TSI_EXT]
#endif
};
+constexpr xyz_pos_t ProbeTempComp::park_point;
+constexpr xy_pos_t ProbeTempComp::measure_point;
+constexpr int ProbeTempComp::probe_calib_bed_temp;
+
uint8_t ProbeTempComp::calib_idx; // = 0
float ProbeTempComp::init_measurement; // = 0.0
@@ -161,28 +165,41 @@ void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const float &
}
float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const float &temp) {
-
const uint8_t measurements = cali_info[tsi].measurements;
const float start_temp = cali_info[tsi].start_temp,
- end_temp = cali_info[tsi].end_temp,
res_temp = cali_info[tsi].temp_res;
const int16_t * const data = sensor_z_offsets[tsi];
- if (temp <= start_temp) return 0.0f;
- if (temp >= end_temp) return static_cast(data[measurements - 1]) / 1000.0f;
+ auto point = [&](uint8_t i) {
+ return xy_float_t({start_temp + i*res_temp, static_cast(data[i])});
+ };
+
+ auto linear_interp = [](float x, xy_float_t p1, xy_float_t p2) {
+ return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
+ };
// Linear interpolation
- int16_t val1 = 0, val2 = data[0];
- uint8_t idx = 0;
- float meas_temp = start_temp + res_temp;
- while (meas_temp < temp) {
- if (++idx >= measurements) return static_cast(val2) / 1000.0f;
- meas_temp += res_temp;
- val1 = val2;
- val2 = data[idx];
- }
- const float factor = (meas_temp - temp) / static_cast(res_temp);
- return (static_cast(val2) - static_cast