Compare commits
200 Commits
1.2.0
...
1.5.0-beta
Author | SHA1 | Date | |
---|---|---|---|
|
fb281baa27 | ||
|
640fce0c02 | ||
|
33a8c67631 | ||
|
b115276fee | ||
|
36c8aee75b | ||
|
a9513299c0 | ||
|
9e5248e65d | ||
|
c9f1b91bbe | ||
|
029b37077a | ||
|
4885c082fe | ||
|
0f75d5be1d | ||
|
affad24f74 | ||
|
bd5eba2a0c | ||
|
b750daf391 | ||
|
4fc8948e0b | ||
|
41c16006a1 | ||
|
d43d99bead | ||
|
fd58245bd2 | ||
|
bd0f3a9aa5 | ||
|
55170f9fc8 | ||
|
c2c950bbca | ||
|
c03aa9d5a4 | ||
|
8877ad534d | ||
|
3a19d9ef69 | ||
|
3be0c7e7a6 | ||
|
67c7ce7b79 | ||
|
fe9ea826a5 | ||
|
24d306ccb0 | ||
|
ac7c272403 | ||
|
38f15215f8 | ||
|
bd49cc3d48 | ||
|
867ba6abc4 | ||
|
db27202614 | ||
|
6368552ced | ||
|
afee7b10c2 | ||
|
031c095019 | ||
|
bf2795c51e | ||
|
986e416c7f | ||
|
626283aadb | ||
|
84c181d4cf | ||
|
41d069464e | ||
|
4f459362c2 | ||
|
4fcbe2afd0 | ||
|
465f4cbf60 | ||
|
e3a2aeb4cf | ||
|
51da7acc6c | ||
|
cbc02f7f3d | ||
|
4985c9abf5 | ||
|
0eaa8f902f | ||
|
7444f4bb45 | ||
|
0440770618 | ||
|
c66f3559d7 | ||
|
1183a5b51c | ||
|
2bc946edab | ||
|
3afc5c0dc1 | ||
|
f03df0b280 | ||
|
b035c464dd | ||
|
7071629534 | ||
|
23609b0d40 | ||
|
fd35e6b0f8 | ||
|
ff88387916 | ||
|
b217d9fe69 | ||
|
de61898c55 | ||
|
d95fcd7673 | ||
|
eb57d10ec3 | ||
|
7852f925ce | ||
|
e32e753ebf | ||
|
8e2c5513d1 | ||
|
8cdd188612 | ||
|
b2e68e6fa8 | ||
|
e0819d42de | ||
|
790e3ec512 | ||
|
e5271d7b2f | ||
|
69328f5246 | ||
|
d19dbf0be5 | ||
|
425f89e924 | ||
|
66eeb0d7ec | ||
|
f56b9f58ab | ||
|
f85e2ebb22 | ||
|
47adc716b2 | ||
|
a2efdedde4 | ||
|
c8ffbe769b | ||
|
f041be8338 | ||
|
a09cf3034e | ||
|
03c4a3de09 | ||
|
0d4346542b | ||
|
0e74f4cebc | ||
|
7ef2dbdac3 | ||
|
7b9e0c4e02 | ||
|
f3c4dfa196 | ||
|
a7495a49c5 | ||
|
341addb39f | ||
|
b6b2995b5e | ||
|
899f35e029 | ||
|
12545edfc7 | ||
|
0ae2f00fc8 | ||
|
bba456db14 | ||
|
f631eeac24 | ||
|
60ff8e8cb2 | ||
|
f2615b7972 | ||
|
2719ba6690 | ||
|
d0219c5632 | ||
|
4b9b66b8a6 | ||
|
515df460ae | ||
|
446e447c50 | ||
|
deb825eb61 | ||
|
b7d66def62 | ||
|
83aca360b7 | ||
|
d7cd75dba6 | ||
|
62e2473450 | ||
|
33a90d329b | ||
|
866675b72b | ||
|
85fb3005e4 | ||
|
8bf38f49a0 | ||
|
3669004077 | ||
|
35ea8497b0 | ||
|
e03c58d79a | ||
|
9cbf70c2ee | ||
|
dd169b7cca | ||
|
39e9d4f642 | ||
|
62479aabd0 | ||
|
d2e7bf96ba | ||
|
5fa2ac947c | ||
|
9bf04b2e18 | ||
|
806737d701 | ||
|
48688147b9 | ||
|
0fae7ebb09 | ||
|
38962febfe | ||
|
b6a11d2648 | ||
|
bdd8e15b65 | ||
|
bb8c10ea60 | ||
|
d581c26db2 | ||
|
09abca7bc7 | ||
|
0d7f1927cb | ||
|
751da659fb | ||
|
7432ea4000 | ||
|
1707addea7 | ||
|
a16109379e | ||
|
f7a3a6a610 | ||
|
9ffed0e031 | ||
|
7077da3591 | ||
|
b9d7ba838e | ||
|
5f39a77129 | ||
|
fcfbc53e76 | ||
|
62fb935883 | ||
|
250e7a34eb | ||
|
7e2409b8a0 | ||
|
c4725d946d | ||
|
bf4572488f | ||
|
4a58b4b093 | ||
|
2368fe1a55 | ||
|
d845160163 | ||
|
21d062c285 | ||
|
04fcfa3b30 | ||
|
3eff63185d | ||
|
533d44bf94 | ||
|
ad974e176c | ||
|
f8208b7e5e | ||
|
f1dc45dcd3 | ||
|
978403d1c8 | ||
|
59ec01bdd1 | ||
|
8b3b4c47cf | ||
|
85bac6b396 | ||
|
2e1c2343cb | ||
|
8aa79ade6a | ||
|
0b48145044 | ||
|
28993ec8b6 | ||
|
cf29882768 | ||
|
b16342e759 | ||
|
6bc23bb27e | ||
|
d85ebb2506 | ||
|
4ad1429c5b | ||
|
1729115a07 | ||
|
01a8239da3 | ||
|
e2c1dd0b3c | ||
|
1a8d83556a | ||
|
923693fc14 | ||
|
39deaa0fc0 | ||
|
096caa47ed | ||
|
01272e0626 | ||
|
cd7cd794dc | ||
|
6b2ad60d47 | ||
|
1ecca13347 | ||
|
856f20dd26 | ||
|
8fc3d6eaa0 | ||
|
918820850e | ||
|
d464e036e0 | ||
|
92bfd1b495 | ||
|
b3f4dcb2d1 | ||
|
35656c7782 | ||
|
a0618b4a1e | ||
|
b740c9f747 | ||
|
4d953f30f8 | ||
|
a0b9947172 | ||
|
5cbf59285d | ||
|
6adfa4571e | ||
|
0cb10a5255 | ||
|
d5e526cc02 | ||
|
c06c1f37a4 | ||
|
6e74183381 |
23
.editorconfig
Normal file
23
.editorconfig
Normal file
@@ -0,0 +1,23 @@
|
||||
# editorconfig.org
|
||||
root = true
|
||||
|
||||
[{*.patch,syntax_test_*}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{*.c,*.cpp,*.h,*.ino}]
|
||||
charset = utf-8
|
||||
|
||||
[{*.c,*.cpp,*.h,*.ino,Makefile}]
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[{*.py}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[{*.conf,*.sublime-project}]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
21
.gitattributes
vendored
Normal file
21
.gitattributes
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Files with Unix line endings
|
||||
*.c text eol=lf
|
||||
*.cpp text eol=lf
|
||||
*.h text eol=lf
|
||||
*.ino text eol=lf
|
||||
*.py text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.scad text eol=lf
|
||||
|
||||
# Files with native line endings
|
||||
# *.sln text
|
||||
|
||||
# Binary files
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.fon binary
|
||||
*.bin binary
|
||||
*.woff binary
|
46
.github/code_of_conduct.md
vendored
Normal file
46
.github/code_of_conduct.md
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [marlinfirmware@github.com](mailto:marlinfirmware@github.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: https://contributor-covenant.org
|
||||
[version]: https://contributor-covenant.org/version/1/4/
|
146
.github/contributing.md
vendored
Normal file
146
.github/contributing.md
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
# Contributing to Marlin
|
||||
|
||||
Thanks for your interest in contributing to Marlin Firmware!
|
||||
|
||||
The following is a set of guidelines for contributing to Marlin, hosted by the [MarlinFirmware Organization](https://github.com/MarlinFirmware) on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a Pull Request.
|
||||
|
||||
#### Table Of Contents
|
||||
|
||||
[Code of Conduct](#code-of-conduct)
|
||||
|
||||
[I don't want to read this whole thing, I just have a question!!!](#i-dont-want-to-read-this-whole-thing-i-just-have-a-question)
|
||||
|
||||
[How Can I Contribute?](#how-can-i-contribute)
|
||||
* [Reporting Bugs](#reporting-bugs)
|
||||
* [Suggesting Features or Changes](#suggesting-features-or-changes)
|
||||
* [Your First Code Contribution](#your-first-code-contribution)
|
||||
* [Pull Requests](#pull-requests)
|
||||
|
||||
[Styleguides](#styleguides)
|
||||
* [Git Commit Messages](#git-commit-messages)
|
||||
* [C++ Coding Standards](#c++-coding-standards)
|
||||
* [Documentation Styleguide](#documentation)
|
||||
|
||||
[Additional Notes](#additional-notes)
|
||||
* [Issue and Pull Request Labels](#issue-and-pull-request-labels)
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project and everyone participating in it is governed by the [Marlin Code of Conduct](code_of_conduct.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [marlinfirmware@github.com](mailto:marlinfirmware@github.com).
|
||||
|
||||
## I don't want to read this whole thing I just have a question!!!
|
||||
|
||||
> **Note:** Please don't file an issue to ask a question. You'll get faster results by using the resources below.
|
||||
|
||||
We have a Message Board and a Facebook group where our knowledgable user community can provide helpful advice if you have questions.
|
||||
|
||||
- [Marlin Documentation](https://marlinfw.org) - Official Marlin documentation
|
||||
- Facebook Group ["Marlin Firmware"](https://www.facebook.com/groups/1049718498464482/)
|
||||
- RepRap.org [Marlin Forum](https://forums.reprap.org/list.php?415)
|
||||
- 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
|
||||
|
||||
If chat is more your speed, you can join the MarlinFirmware Discord server:
|
||||
|
||||
* 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?
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
This section guides you through submitting a Bug Report for Marlin. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.
|
||||
|
||||
Before creating a Bug Report, please test the "nightly" development branch, as you might find out that you don't need to create one. When you are creating a Bug Report, please [include as many details as possible](#how-do-i-submit-a-good-bug-report). Fill out [the required template](ISSUE_TEMPLATE/bug_report.yml), the information it asks for helps us resolve issues faster.
|
||||
|
||||
> **Note:** Regressions can happen. If you find a **Closed** issue that seems like your issue, go ahead and open a new issue and include a link to the original issue in the body of your new one. All you need to create a link is the issue number, preceded by #. For example, #8888.
|
||||
|
||||
#### How Do I Submit A (Good) Bug Report?
|
||||
|
||||
Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). Use the New Issue button to create an issue and provide the following information by filling in [the template](ISSUE_TEMPLATE/bug_report.yml).
|
||||
|
||||
Explain the problem and include additional details to help maintainers reproduce the problem:
|
||||
|
||||
* **Use a clear and descriptive title** for the issue to identify the problem.
|
||||
* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining how you started Marlin, e.g. which command exactly you used in the terminal, or how you started Marlin otherwise. When listing steps, **don't just say what you did, but explain how you did it**. For example, if you moved the cursor to the end of a line, explain if you used the mouse, or a keyboard shortcut or an Marlin command, and if so which one?
|
||||
* **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets or log output in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
|
||||
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
|
||||
* **Explain which behavior you expected to see instead and why.**
|
||||
* **Include detailed log output** especially for probing and leveling. See below for usage of `DEBUG_LEVELING_FEATURE`.
|
||||
* **Include screenshots, links to videos, etc.** which clearly demonstrate the problem.
|
||||
* **Include G-code** (if relevant) that reliably causes the problem to show itself.
|
||||
* **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened and share more information using the guidelines below.
|
||||
|
||||
Provide more context:
|
||||
|
||||
* **Can you reproduce the problem with a minimum of options enabled?**
|
||||
* **Did the problem start happening recently** (e.g. after updating to a new version of Marlin) or was this always a problem?
|
||||
* If the problem started happening recently, **can you reproduce the problem in an older version of Marlin?** What's the most recent version in which the problem doesn't happen? You can download older versions of Marlin from [the releases page](https://github.com/MarlinFirmware/Marlin/releases).
|
||||
* **Can you reliably reproduce the issue?** If not, provide details about how often the problem happens and under which conditions it normally happens.
|
||||
|
||||
Include details about your configuration and environment:
|
||||
|
||||
* **Which version of Marlin are you using?** Marlin's exact version and build date can be seen in the startup message when a host connects to Marlin, or in the LCD Info menu (if enabled).
|
||||
* **What kind of 3D Printer and electronics are you using**?
|
||||
* **What kind of add-ons (probe, filament sensor) do you have**?
|
||||
* **Include your Configuration files.** Make a ZIP file containing `Configuration.h` and `Configuration_adv.h` and drop it on your reply.
|
||||
|
||||
### Suggesting Features or Changes
|
||||
|
||||
This section guides you through submitting a suggestion for Marlin, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions.
|
||||
|
||||
Before creating a suggestion, please check [this list](https://github.com/MarlinFirmware/Marlin/issues?q=is%3Aopen+is%3Aissue+label%3A%22T%3A+Feature+Request%22) as you might find out that you don't need to create one. When you are creating an enhancement suggestion, please [include as many details as possible](#how-do-i-submit-a-good-feature-request). Fill in [the template](ISSUE_TEMPLATE/feature_request.yml), including the steps that you imagine you would take if the feature you're requesting existed.
|
||||
|
||||
#### Before Submitting a Feature Request
|
||||
|
||||
* **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%3Aopen+is%3Aissue+label%3A%22T%3A+Feature+Request%22)** 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?
|
||||
|
||||
Feature Requests are tracked as [GitHub issues](https://guides.github.com/features/issues/). Please follow these guidelines in your request:
|
||||
|
||||
* **Use a clear and descriptive title** for the issue to identify the suggestion.
|
||||
* **Provide a step-by-step description of the requested feature** in as much detail as possible.
|
||||
* **Provide specific examples to demonstrate the steps**.
|
||||
* **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
|
||||
* **Include screenshots and links to videos** which demonstrate the feature or point out the part of Marlin to which the request is related.
|
||||
* **Explain why this feature would be useful** to most Marlin users.
|
||||
* **Name other firmwares that have this feature, if any.**
|
||||
|
||||
### Your First Code Contribution
|
||||
|
||||
Unsure where to begin contributing to Marlin? You can start by looking through these `good-first-issue` and `help-wanted` issues:
|
||||
|
||||
* [Beginner issues][good-first-issue] - issues which should only require a few lines of code, and a test or two.
|
||||
* [Help Wanted issues][help-wanted] - issues which should be a bit more involved than `beginner` issues.
|
||||
|
||||
### Pull Requests
|
||||
|
||||
Pull Requests should always be targeted to working branches (e.g., `bugfix-2.1.x` and/or `bugfix-1.1.x`) and never to release branches (e.g., `2.0.x` and/or `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](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.
|
||||
|
||||
## Styleguides
|
||||
|
||||
### Git Commit Messages
|
||||
|
||||
* Use the present tense ("Add feature" not "Added feature").
|
||||
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...").
|
||||
* Limit the first line to 72 characters or fewer.
|
||||
* Reference issues and Pull Requests liberally after the first line.
|
||||
|
||||
### C++ Coding Standards
|
||||
|
||||
* 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
|
||||
|
||||
* Guidelines for documentation are still under development. In-general, be clear, concise, and to-the-point.
|
24
.github/pull_request_template.md
vendored
24
.github/pull_request_template.md
vendored
@@ -1,18 +1,32 @@
|
||||
### Requirements
|
||||
<!--
|
||||
|
||||
* Filling out this template is required. Pull Requests without a clear description may be closed at the maintainers' discretion.
|
||||
Submitting a Pull Request
|
||||
|
||||
- Please fill out all sections of this form. You can delete the helpful comments.
|
||||
- Pull Requests without clear information will take longer and may even be rejected.
|
||||
- We get a high volume of submissions so please be patient during review.
|
||||
|
||||
-->
|
||||
|
||||
### Description
|
||||
|
||||
<!--
|
||||
|
||||
We must be able to understand your proposed change from this description. If we can't understand what the code will do from this description, the Pull Request may be closed at the maintainers' discretion. Keep in mind that the maintainer reviewing this PR may not be familiar with or have worked with the code recently, so please walk us through the concepts.
|
||||
Clearly describe the submitted changes with lots of details. Include images where helpful. Initial reviewers may not be familiar with the subject, so be as thorough as possible. You can use MarkDown syntax to improve readability with bullet lists, code blocks, and so on. PREVIEW and fix up formatting before submitting.
|
||||
|
||||
-->
|
||||
|
||||
### Requirements
|
||||
|
||||
<!-- Does this PR require a specific board, LCD, etc.? -->
|
||||
|
||||
### Benefits
|
||||
|
||||
<!-- What does this fix or improve? -->
|
||||
<!-- What does this PR fix or improve? -->
|
||||
|
||||
### Configurations
|
||||
|
||||
<!-- Attach Configurations ZIP and any other files needed to test this PR. -->
|
||||
|
||||
### Configurations
|
||||
|
||||
@@ -20,4 +34,4 @@ We must be able to understand your proposed change from this description. If we
|
||||
|
||||
### Related Issues
|
||||
|
||||
<!-- Whether this fixes a bug or fulfills a feature request, please list any related Issues here. -->
|
||||
<!-- Does this PR fix a bug or fulfill a Feature Request? Link related Issues here. -->
|
||||
|
24
.github/workflows/build-all.yml
vendored
24
.github/workflows/build-all.yml
vendored
@@ -65,16 +65,28 @@ jobs:
|
||||
- MEGA_X_DGUS_BLT_11
|
||||
- MEGA_X_DGUS_TMC_BLT_10
|
||||
- MEGA_X_DGUS_TMC_BLT_11
|
||||
- MEGA_P
|
||||
- MEGA_P_TMC
|
||||
- MEGA_P_BLT_10
|
||||
- MEGA_P_BLT_11
|
||||
- MEGA_P_TMC_BLT_10
|
||||
- MEGA_P_TMC_BLT_11
|
||||
- MEGA_P_DGUS
|
||||
- MEGA_P_DGUS_TMC
|
||||
- MEGA_P_DGUS_BLT_10
|
||||
- MEGA_P_DGUS_BLT_11
|
||||
- MEGA_P_DGUS_TMC_BLT_10
|
||||
- MEGA_P_DGUS_TMC_BLT_11
|
||||
- CHIRON
|
||||
- CHIRON_TMC
|
||||
- CHIRON_DGUS
|
||||
- CHIRON_DGUS_TMC
|
||||
- 4MAXP2
|
||||
- 4MAXP2_TMC
|
||||
- 4MAXP2_BLT_10
|
||||
- 4MAXP2_BLT_11
|
||||
- 4MAXP2_TMC_BLT_10
|
||||
- 4MAXP2_TMC_BLT_11
|
||||
- 4MAXP2_DGUS
|
||||
- 4MAXP2_DGUS_TMC
|
||||
- 4MAXP2_DGUS_BLT_10
|
||||
- 4MAXP2_DGUS_BLT_11
|
||||
- 4MAXP2_DGUS_TMC_BLT_10
|
||||
- 4MAXP2_DGUS_TMC_BLT_11
|
||||
|
||||
steps:
|
||||
|
||||
|
172
.gitignore
vendored
Executable file
172
.gitignore
vendored
Executable file
@@ -0,0 +1,172 @@
|
||||
#
|
||||
# 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 <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# Generated files
|
||||
_Version.h
|
||||
bdf2u8g
|
||||
marlin_config.json
|
||||
mczip.h
|
||||
*.gen
|
||||
*.sublime-workspace
|
||||
|
||||
#
|
||||
# OS
|
||||
#
|
||||
applet/
|
||||
.DS_Store
|
||||
|
||||
#
|
||||
# Misc
|
||||
#
|
||||
*~
|
||||
*.orig
|
||||
*.rej
|
||||
*.bak
|
||||
*.idea
|
||||
*.i
|
||||
*.ii
|
||||
*.swp
|
||||
tags
|
||||
|
||||
#
|
||||
# C++
|
||||
#
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
*.ino.cpp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
#
|
||||
# C
|
||||
#
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
|
||||
# PlatformIO files/dirs
|
||||
.pio*
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.clang_complete
|
||||
.gcc-flags.json
|
||||
/lib/
|
||||
|
||||
# Secure Credentials
|
||||
Configuration_Secure.h
|
||||
|
||||
# Visual Studio
|
||||
*.sln
|
||||
*.vcxproj
|
||||
*.vcxproj.user
|
||||
*.vcxproj.filters
|
||||
Release/
|
||||
Debug/
|
||||
__vm/
|
||||
.vs/
|
||||
vc-fileutils.settings
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
|
||||
#Simulation
|
||||
imgui.ini
|
||||
eeprom.dat
|
||||
spi_flash.bin
|
||||
fs.img
|
||||
|
||||
#cmake
|
||||
CMakeLists.txt
|
||||
src/CMakeLists.txt
|
||||
CMakeListsPrivate.txt
|
||||
build/
|
||||
|
||||
# CLion
|
||||
cmake-build-*
|
||||
|
||||
# Eclipse
|
||||
.project
|
||||
.cproject
|
||||
.pydevproject
|
||||
.settings
|
||||
.classpath
|
||||
|
||||
# Python
|
||||
__pycache__
|
||||
|
||||
# IOLogger logs
|
||||
*_log.csv
|
11
.vscode/extensions.json
vendored
Normal file
11
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"marlinfirmware.auto-build",
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
9
LICENSE
9
LICENSE
@@ -3,7 +3,7 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (c) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Copyright (c) 2007 Free Software Foundation, Inc. <https://www.fsf.org/>
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
52
Makefile
Normal file
52
Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
help:
|
||||
@echo "Tasks for local development:"
|
||||
@echo "* tests-single-ci: Run a single test from inside the CI"
|
||||
@echo "* tests-single-local: Run a single test locally"
|
||||
@echo "* tests-single-local-docker: Run a single test locally, using docker-compose"
|
||||
@echo "* tests-all-local: Run all tests locally"
|
||||
@echo "* tests-all-local-docker: Run all tests locally, using docker-compose"
|
||||
@echo "* setup-local-docker: Setup local docker-compose"
|
||||
@echo ""
|
||||
@echo "Options for testing:"
|
||||
@echo " TEST_TARGET Set when running tests-single-*, to select the"
|
||||
@echo " test. If you set it to ALL it will run all "
|
||||
@echo " tests, but some of them are broken: use "
|
||||
@echo " tests-all-* instead to run only the ones that "
|
||||
@echo " run on GitHub CI"
|
||||
@echo " ONLY_TEST Limit tests to only those that contain this, or"
|
||||
@echo " the index of the test (1-based)"
|
||||
@echo " VERBOSE_PLATFORMIO If you want the full PIO output, set any value"
|
||||
@echo " GIT_RESET_HARD Used by CI: reset all local changes. WARNING:"
|
||||
@echo " THIS WILL UNDO ANY CHANGES YOU'VE MADE!"
|
||||
.PHONY: help
|
||||
|
||||
tests-single-ci:
|
||||
export GIT_RESET_HARD=true
|
||||
$(MAKE) tests-single-local TEST_TARGET=$(TEST_TARGET)
|
||||
.PHONY: tests-single-ci
|
||||
|
||||
tests-single-local:
|
||||
@if ! test -n "$(TEST_TARGET)" ; then echo "***ERROR*** Set TEST_TARGET=<your-module> or use make tests-all-local" ; return 1; fi
|
||||
export PATH="./buildroot/bin/:./buildroot/tests/:${PATH}" \
|
||||
&& export VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) \
|
||||
&& run_tests . $(TEST_TARGET) "$(ONLY_TEST)"
|
||||
.PHONY: tests-single-local
|
||||
|
||||
tests-single-local-docker:
|
||||
@if ! test -n "$(TEST_TARGET)" ; then echo "***ERROR*** Set TEST_TARGET=<your-module> or use make tests-all-local-docker" ; return 1; fi
|
||||
docker-compose run --rm marlin $(MAKE) tests-single-local TEST_TARGET=$(TEST_TARGET) VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) GIT_RESET_HARD=$(GIT_RESET_HARD) ONLY_TEST="$(ONLY_TEST)"
|
||||
.PHONY: tests-single-local-docker
|
||||
|
||||
tests-all-local:
|
||||
export PATH="./buildroot/bin/:./buildroot/tests/:${PATH}" \
|
||||
&& export VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) \
|
||||
&& for TEST_TARGET in $$(./get_test_targets.py) ; do echo "Running tests for $$TEST_TARGET" ; run_tests . $$TEST_TARGET ; done
|
||||
.PHONY: tests-all-local
|
||||
|
||||
tests-all-local-docker:
|
||||
docker-compose run --rm marlin $(MAKE) tests-all-local VERBOSE_PLATFORMIO=$(VERBOSE_PLATFORMIO) GIT_RESET_HARD=$(GIT_RESET_HARD)
|
||||
.PHONY: tests-all-local-docker
|
||||
|
||||
setup-local-docker:
|
||||
docker-compose build
|
||||
.PHONY: setup-local-docker
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1037
Marlin/Makefile
Normal file
1037
Marlin/Makefile
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -28,20 +28,20 @@
|
||||
/**
|
||||
* Marlin release version identifier
|
||||
*/
|
||||
//#define SHORT_BUILD_VERSION "2.0.5.4"
|
||||
//#define SHORT_BUILD_VERSION "2.1.2"
|
||||
|
||||
/**
|
||||
* 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-07-09"
|
||||
//#define STRING_DISTRIBUTION_DATE "2022-08-06"
|
||||
|
||||
/**
|
||||
* Defines a generic printer name to be output to the LCD after booting Marlin.
|
||||
@@ -54,7 +54,7 @@
|
||||
* has a distinct Github fork— the Source Code URL should just be the main
|
||||
* Marlin repository.
|
||||
*/
|
||||
//#define SOURCE_CODE_URL "https://github.com/MarlinFirmware/Marlin"
|
||||
//#define SOURCE_CODE_URL "github.com/MarlinFirmware/Marlin"
|
||||
|
||||
/**
|
||||
* Default generic printer UUID.
|
||||
@@ -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 "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
|
||||
|
211
Marlin/config.ini
Normal file
211
Marlin/config.ini
Normal file
@@ -0,0 +1,211 @@
|
||||
#
|
||||
# Marlin Firmware
|
||||
# config.ini - Options to apply before the build
|
||||
#
|
||||
[config:base]
|
||||
ini_use_config = none
|
||||
|
||||
# Load all config: sections in this file
|
||||
;ini_use_config = all
|
||||
# Load config file relative to Marlin/
|
||||
;ini_use_config = another.ini
|
||||
# Download configurations from GitHub
|
||||
;ini_use_config = example/Creality/Ender-5 Plus @ bugfix-2.1.x
|
||||
# Download configurations from your server
|
||||
;ini_use_config = https://me.myserver.com/path/to/configs
|
||||
# Evaluate config:base and do a config dump
|
||||
;ini_use_config = base
|
||||
;config_export = 2
|
||||
|
||||
[config:minimal]
|
||||
motherboard = BOARD_RAMPS_14_EFB
|
||||
serial_port = 0
|
||||
baudrate = 250000
|
||||
|
||||
use_watchdog = on
|
||||
thermal_protection_hotends = on
|
||||
thermal_protection_hysteresis = 4
|
||||
thermal_protection_period = 40
|
||||
|
||||
bufsize = 4
|
||||
block_buffer_size = 16
|
||||
max_cmd_size = 96
|
||||
|
||||
extruders = 1
|
||||
temp_sensor_0 = 1
|
||||
|
||||
temp_hysteresis = 3
|
||||
heater_0_mintemp = 5
|
||||
heater_0_maxtemp = 275
|
||||
preheat_1_temp_hotend = 180
|
||||
|
||||
bang_max = 255
|
||||
pidtemp = on
|
||||
pid_k1 = 0.95
|
||||
pid_max = BANG_MAX
|
||||
pid_functional_range = 10
|
||||
|
||||
default_kp = 22.20
|
||||
default_ki = 1.08
|
||||
default_kd = 114.00
|
||||
|
||||
x_driver_type = A4988
|
||||
y_driver_type = A4988
|
||||
z_driver_type = A4988
|
||||
e0_driver_type = A4988
|
||||
|
||||
x_bed_size = 200
|
||||
x_min_pos = 0
|
||||
x_max_pos = X_BED_SIZE
|
||||
|
||||
y_bed_size = 200
|
||||
y_min_pos = 0
|
||||
y_max_pos = Y_BED_SIZE
|
||||
|
||||
z_min_pos = 0
|
||||
z_max_pos = 200
|
||||
|
||||
x_home_dir = -1
|
||||
y_home_dir = -1
|
||||
z_home_dir = -1
|
||||
|
||||
use_xmin_plug = on
|
||||
use_ymin_plug = on
|
||||
use_zmin_plug = on
|
||||
|
||||
x_min_endstop_inverting = false
|
||||
y_min_endstop_inverting = false
|
||||
z_min_endstop_inverting = false
|
||||
|
||||
default_axis_steps_per_unit = { 80, 80, 400, 500 }
|
||||
axis_relative_modes = { false, false, false, false }
|
||||
default_max_feedrate = { 300, 300, 5, 25 }
|
||||
default_max_acceleration = { 3000, 3000, 100, 10000 }
|
||||
|
||||
homing_feedrate_mm_m = { (50*60), (50*60), (4*60) }
|
||||
homing_bump_divisor = { 2, 2, 4 }
|
||||
|
||||
x_enable_on = 0
|
||||
y_enable_on = 0
|
||||
z_enable_on = 0
|
||||
e_enable_on = 0
|
||||
|
||||
invert_x_dir = false
|
||||
invert_y_dir = true
|
||||
invert_z_dir = false
|
||||
invert_e0_dir = false
|
||||
|
||||
invert_e_step_pin = false
|
||||
invert_x_step_pin = false
|
||||
invert_y_step_pin = false
|
||||
invert_z_step_pin = false
|
||||
|
||||
disable_x = false
|
||||
disable_y = false
|
||||
disable_z = false
|
||||
disable_e = false
|
||||
|
||||
proportional_font_ratio = 1.0
|
||||
default_nominal_filament_dia = 1.75
|
||||
|
||||
junction_deviation_mm = 0.013
|
||||
|
||||
default_acceleration = 3000
|
||||
default_travel_acceleration = 3000
|
||||
default_retract_acceleration = 3000
|
||||
|
||||
default_minimumfeedrate = 0.0
|
||||
default_mintravelfeedrate = 0.0
|
||||
|
||||
minimum_planner_speed = 0.05
|
||||
min_steps_per_segment = 6
|
||||
default_minsegmenttime = 20000
|
||||
|
||||
[config:basic]
|
||||
bed_overshoot = 10
|
||||
busy_while_heating = on
|
||||
default_ejerk = 5.0
|
||||
default_keepalive_interval = 2
|
||||
default_leveling_fade_height = 0.0
|
||||
disable_inactive_extruder = on
|
||||
display_charset_hd44780 = JAPANESE
|
||||
eeprom_boot_silent = on
|
||||
eeprom_chitchat = on
|
||||
endstoppullups = on
|
||||
extrude_maxlength = 200
|
||||
extrude_mintemp = 170
|
||||
host_keepalive_feature = on
|
||||
hotend_overshoot = 15
|
||||
jd_handle_small_segments = on
|
||||
lcd_info_screen_style = 0
|
||||
lcd_language = en
|
||||
max_bed_power = 255
|
||||
mesh_inset = 0
|
||||
min_software_endstops = on
|
||||
max_software_endstops = on
|
||||
min_software_endstop_x = on
|
||||
min_software_endstop_y = on
|
||||
min_software_endstop_z = on
|
||||
max_software_endstop_x = on
|
||||
max_software_endstop_y = on
|
||||
max_software_endstop_z = on
|
||||
preheat_1_fan_speed = 0
|
||||
preheat_1_label = "PLA"
|
||||
preheat_1_temp_bed = 70
|
||||
prevent_cold_extrusion = on
|
||||
prevent_lengthy_extrude = on
|
||||
printjob_timer_autostart = on
|
||||
probing_margin = 10
|
||||
show_bootscreen = on
|
||||
soft_pwm_scale = 0
|
||||
string_config_h_author = "(none, default config)"
|
||||
temp_bed_hysteresis = 3
|
||||
temp_bed_residency_time = 10
|
||||
temp_bed_window = 1
|
||||
temp_residency_time = 10
|
||||
temp_window = 1
|
||||
validate_homing_endstops = on
|
||||
xy_probe_feedrate = (133*60)
|
||||
z_clearance_between_probes = 5
|
||||
z_clearance_deploy_probe = 10
|
||||
z_clearance_multi_probe = 5
|
||||
|
||||
[config:advanced]
|
||||
arc_support = on
|
||||
auto_report_temperatures = on
|
||||
autotemp = on
|
||||
autotemp_oldweight = 0.98
|
||||
bed_check_interval = 5000
|
||||
default_stepper_deactive_time = 120
|
||||
default_volumetric_extruder_limit = 0.00
|
||||
disable_inactive_e = true
|
||||
disable_inactive_x = true
|
||||
disable_inactive_y = true
|
||||
disable_inactive_z = true
|
||||
e0_auto_fan_pin = -1
|
||||
encoder_100x_steps_per_sec = 80
|
||||
encoder_10x_steps_per_sec = 30
|
||||
encoder_rate_multiplier = on
|
||||
extended_capabilities_report = on
|
||||
extruder_auto_fan_speed = 255
|
||||
extruder_auto_fan_temperature = 50
|
||||
fanmux0_pin = -1
|
||||
fanmux1_pin = -1
|
||||
fanmux2_pin = -1
|
||||
faster_gcode_parser = on
|
||||
homing_bump_mm = { 5, 5, 2 }
|
||||
max_arc_segment_mm = 1.0
|
||||
min_arc_segment_mm = 0.1
|
||||
min_circle_segments = 72
|
||||
n_arc_correction = 25
|
||||
serial_overrun_protection = on
|
||||
slowdown = on
|
||||
slowdown_divisor = 2
|
||||
temp_sensor_bed = 0
|
||||
thermal_protection_bed_hysteresis = 2
|
||||
thermocouple_max_errors = 15
|
||||
tx_buffer_size = 0
|
||||
watch_bed_temp_increase = 2
|
||||
watch_bed_temp_period = 60
|
||||
watch_temp_increase = 2
|
||||
watch_temp_period = 20
|
@@ -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
|
||||
|
125
Marlin/src/HAL/AVR/HAL.cpp
Executable file → Normal file
125
Marlin/src/HAL/AVR/HAL.cpp
Executable file → Normal file
@@ -16,26 +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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
#include <avr/wdt.h>
|
||||
|
||||
#ifdef USBCON
|
||||
DefaultSerial1 MSerial0(false, Serial);
|
||||
#ifdef BLUETOOTH
|
||||
BTSerial btSerial(false, bluetoothSerial);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
// Public Variables
|
||||
// ------------------------
|
||||
|
||||
//uint8_t MCUSR;
|
||||
// Don't initialize/override variable (which would happen in .init4)
|
||||
uint8_t MarlinHAL::reset_reason __attribute__((section(".noinit")));
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
void HAL_init() {
|
||||
__attribute__((naked)) // Don't output function pro- and epilogue
|
||||
__attribute__((used)) // Output the function, even if "not used"
|
||||
__attribute__((section(".init3"))) // Put in an early user definable section
|
||||
void save_reset_reason() {
|
||||
#if ENABLED(OPTIBOOT_RESET_REASON)
|
||||
__asm__ __volatile__(
|
||||
A("STS %0, r2")
|
||||
: "=m"(hal.reset_reason)
|
||||
);
|
||||
#else
|
||||
hal.reset_reason = MCUSR;
|
||||
#endif
|
||||
|
||||
// Clear within 16ms since WDRF bit enables a 16ms watchdog timer -> Boot loop
|
||||
hal.clear_reset_source();
|
||||
wdt_disable();
|
||||
}
|
||||
|
||||
void MarlinHAL::init() {
|
||||
// Init Servo Pins
|
||||
#define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)
|
||||
#if HAS_SERVO_0
|
||||
@@ -50,8 +76,75 @@ void HAL_init() {
|
||||
#if HAS_SERVO_3
|
||||
INIT_SERVO(3);
|
||||
#endif
|
||||
|
||||
init_pwm_timers(); // Init user timers to default frequency - 1000HZ
|
||||
}
|
||||
|
||||
void MarlinHAL::reboot() {
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
while (1) { /* run out the watchdog */ }
|
||||
#else
|
||||
void (*resetFunc)() = 0; // Declare resetFunc() at address 0
|
||||
resetFunc(); // Jump to address 0
|
||||
#endif
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Watchdog Timer
|
||||
// ------------------------
|
||||
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
|
||||
#include <avr/wdt.h>
|
||||
#include "../../MarlinCore.h"
|
||||
|
||||
// Initialize watchdog with 8s timeout, if possible. Otherwise, make it 4s.
|
||||
void MarlinHAL::watchdog_init() {
|
||||
#if ENABLED(WATCHDOG_DURATION_8S) && defined(WDTO_8S)
|
||||
#define WDTO_NS WDTO_8S
|
||||
#else
|
||||
#define WDTO_NS WDTO_4S
|
||||
#endif
|
||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||
// Enable the watchdog timer, but only for the interrupt.
|
||||
// Take care, as this requires the correct order of operation, with interrupts disabled.
|
||||
// See the datasheet of any AVR chip for details.
|
||||
wdt_reset();
|
||||
cli();
|
||||
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
|
||||
_WD_CONTROL_REG = _BV(WDIE) | (WDTO_NS & 0x07) | ((WDTO_NS & 0x08) << 2); // WDTO_NS directly does not work. bit 0-2 are consecutive in the register but the highest value bit is at bit 5
|
||||
// So worked for up to WDTO_2S
|
||||
sei();
|
||||
wdt_reset();
|
||||
#else
|
||||
wdt_enable(WDTO_NS); // The function handles the upper bit correct.
|
||||
#endif
|
||||
//delay(10000); // test it!
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//=================================== ISR ===================================
|
||||
//===========================================================================
|
||||
|
||||
// Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
|
||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||
ISR(WDT_vect) {
|
||||
sei(); // With the interrupt driven serial we need to allow interrupts.
|
||||
SERIAL_ERROR_MSG(STR_WATCHDOG_FIRED);
|
||||
minkill(); // interrupt-safe final kill and infinite loop
|
||||
}
|
||||
#endif
|
||||
|
||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||
// first watchdog_init or AVR will go into emergency procedures.
|
||||
void MarlinHAL::watchdog_refresh() { wdt_reset(); }
|
||||
|
||||
#endif // USE_WATCHDOG
|
||||
|
||||
// ------------------------
|
||||
// Free Memory Accessor
|
||||
// ------------------------
|
||||
|
||||
#if ENABLED(SDSUPPORT)
|
||||
|
||||
#include "../../sd/SdFatUtil.h"
|
||||
@@ -59,20 +152,20 @@ void HAL_init() {
|
||||
|
||||
#else // !SDSUPPORT
|
||||
|
||||
extern "C" {
|
||||
extern char __bss_end;
|
||||
extern char __heap_start;
|
||||
extern void* __brkval;
|
||||
extern "C" {
|
||||
extern char __bss_end;
|
||||
extern char __heap_start;
|
||||
extern void* __brkval;
|
||||
|
||||
int freeMemory() {
|
||||
int free_memory;
|
||||
if ((int)__brkval == 0)
|
||||
free_memory = ((int)&free_memory) - ((int)&__bss_end);
|
||||
else
|
||||
free_memory = ((int)&free_memory) - ((int)__brkval);
|
||||
return free_memory;
|
||||
int freeMemory() {
|
||||
int free_memory;
|
||||
if ((int)__brkval == 0)
|
||||
free_memory = ((int)&free_memory) - ((int)&__bss_end);
|
||||
else
|
||||
free_memory = ((int)&free_memory) - ((int)__brkval);
|
||||
return free_memory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !SDSUPPORT
|
||||
|
||||
|
505
Marlin/src/HAL/AVR/HAL.h
Executable file → Normal file
505
Marlin/src/HAL/AVR/HAL.h
Executable file → Normal file
@@ -14,21 +14,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* HAL for Arduino AVR
|
||||
*/
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/HAL_SPI.h"
|
||||
#include "fastio.h"
|
||||
#include "watchdog.h"
|
||||
#include "math.h"
|
||||
|
||||
#ifdef USBCON
|
||||
#include <HardwareSerial.h>
|
||||
#else
|
||||
#define HardwareSerial_h // Hack to prevent HardwareSerial.h header inclusion
|
||||
#include "MarlinSerial.h"
|
||||
#define BOARD_NO_NATIVE_USB
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -38,6 +42,19 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
//
|
||||
// Default graphical display delays
|
||||
//
|
||||
#if F_CPU >= 20000000
|
||||
#define CPU_ST7920_DELAY_1 150
|
||||
#define CPU_ST7920_DELAY_2 0
|
||||
#define CPU_ST7920_DELAY_3 150
|
||||
#elif F_CPU == 16000000
|
||||
#define CPU_ST7920_DELAY_1 125
|
||||
#define CPU_ST7920_DELAY_2 0
|
||||
#define CPU_ST7920_DELAY_3 188
|
||||
#endif
|
||||
|
||||
#ifndef pgm_read_ptr
|
||||
// Compatibility for avr-libc 1.8.0-4.1 included with Ubuntu for
|
||||
// Windows Subsystem for Linux on Windows 10 as of 10/18/2019
|
||||
@@ -50,343 +67,97 @@
|
||||
// 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()
|
||||
#define CRITICAL_SECTION_END() SREG = _sreg
|
||||
#endif
|
||||
#define ISRS_ENABLED() TEST(SREG, SREG_I)
|
||||
#define ENABLE_ISRS() sei()
|
||||
#define DISABLE_ISRS() cli()
|
||||
|
||||
// On AVR this is in math.h?
|
||||
//#define square(x) ((x)*(x))
|
||||
#define HAL_CAN_SET_PWM_FREQ // This HAL supports PWM Frequency adjustment
|
||||
#define PWM_FREQUENCY 1000 // Default PWM frequency when set_pwm_duty() is called without set_pwm_frequency()
|
||||
|
||||
// ------------------------
|
||||
// Types
|
||||
// ------------------------
|
||||
|
||||
typedef uint16_t hal_timer_t;
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFF
|
||||
|
||||
typedef int8_t pin_t;
|
||||
|
||||
#define SHARED_SERVOS HAS_SERVOS
|
||||
#define HAL_SERVO_LIB Servo
|
||||
#define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
|
||||
|
||||
class Servo;
|
||||
typedef Servo hal_servo_t;
|
||||
|
||||
// ------------------------
|
||||
// Public Variables
|
||||
// ------------------------
|
||||
|
||||
//extern uint8_t MCUSR;
|
||||
|
||||
// Serial ports
|
||||
// ------------------------
|
||||
|
||||
#ifdef USBCON
|
||||
#if ENABLED(BLUETOOTH)
|
||||
#define MYSERIAL0 bluetoothSerial
|
||||
#else
|
||||
#define MYSERIAL0 Serial
|
||||
#endif
|
||||
#define NUM_SERIAL 1
|
||||
#else
|
||||
#if !WITHIN(SERIAL_PORT, -1, 3)
|
||||
#error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#include "../../core/serial_hook.h"
|
||||
typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
|
||||
extern DefaultSerial1 MSerial0;
|
||||
#ifdef BLUETOOTH
|
||||
typedef ForwardSerial1Class< decltype(bluetoothSerial) > BTSerial;
|
||||
extern BTSerial btSerial;
|
||||
#endif
|
||||
|
||||
#define MYSERIAL0 customizedSerial1
|
||||
#define MYSERIAL1 TERN(BLUETOOTH, btSerial, MSerial0)
|
||||
#else
|
||||
#if !WITHIN(SERIAL_PORT, 0, 3)
|
||||
#error "SERIAL_PORT must be from 0 to 3."
|
||||
#endif
|
||||
#define MYSERIAL1 customizedSerial1
|
||||
|
||||
#ifdef SERIAL_PORT_2
|
||||
#if !WITHIN(SERIAL_PORT_2, -1, 3)
|
||||
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
|
||||
#elif SERIAL_PORT_2 == SERIAL_PORT
|
||||
#error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
|
||||
#if !WITHIN(SERIAL_PORT_2, 0, 3)
|
||||
#error "SERIAL_PORT_2 must be from 0 to 3."
|
||||
#endif
|
||||
#define MYSERIAL1 customizedSerial2
|
||||
#define NUM_SERIAL 2
|
||||
#else
|
||||
#define NUM_SERIAL 1
|
||||
#define MYSERIAL2 customizedSerial2
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_PORT_3
|
||||
#if !WITHIN(SERIAL_PORT_3, 0, 3)
|
||||
#error "SERIAL_PORT_3 must be from 0 to 3."
|
||||
#endif
|
||||
#define MYSERIAL3 customizedSerial3
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if !WITHIN(DGUS_SERIAL_PORT, -1, 3)
|
||||
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#elif DGUS_SERIAL_PORT == SERIAL_PORT
|
||||
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
|
||||
#elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
|
||||
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
|
||||
#ifdef MMU2_SERIAL_PORT
|
||||
#if !WITHIN(MMU2_SERIAL_PORT, 0, 3)
|
||||
#error "MMU2_SERIAL_PORT must be from 0 to 3"
|
||||
#endif
|
||||
#define DGUS_SERIAL internalDgusSerial
|
||||
|
||||
#define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.get_tx_buffer_free
|
||||
#define MMU2_SERIAL mmuSerial
|
||||
#endif
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
void HAL_init();
|
||||
|
||||
//void cli();
|
||||
|
||||
//void _delay_ms(const int delay);
|
||||
|
||||
inline void HAL_clear_reset_source() { MCUSR = 0; }
|
||||
inline uint8_t HAL_get_reset_source() { return MCUSR; }
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
extern "C" {
|
||||
int freeMemory();
|
||||
}
|
||||
#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<<OCIE0B)),\
|
||||
[msk1] "M" ((uint8_t)(1<<OCIE1A)) \
|
||||
: \
|
||||
); \
|
||||
} \
|
||||
void TIMER1_COMPA_vect_bottom()
|
||||
|
||||
/* 14 cycles maximum latency */
|
||||
#define HAL_TEMP_TIMER_ISR() \
|
||||
extern "C" void TIMER0_COMPB_vect() __attribute__ ((signal, naked, used, externally_visible)); \
|
||||
extern "C" void TIMER0_COMPB_vect_bottom() asm ("TIMER0_COMPB_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
|
||||
void TIMER0_COMPB_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("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
|
||||
A("sts %[timsk0], r16") /* 2 And set the new value */ \
|
||||
A("sei") /* 1 Enable global interrupts - It is safe, as the temperature ISR is disabled, so we cannot reenter it */ \
|
||||
A("push r16") /* 2 Save TIMSK0 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 TIMER0_COMPB_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 TIMSK0 value but with temperature ISR disabled */ \
|
||||
A("ori r16,%[msk0]") /* 1 Enable temperature ISR */ \
|
||||
A("cli") /* 1 Disable global interrupts - We must do this, as we will reenable the temperature ISR, and we don't want to reenter this handler until the current one is done */ \
|
||||
A("sts %[timsk0], r16") /* 2 And restore the old value */ \
|
||||
A("pop r16") /* 2 Get the old SREG */ \
|
||||
A("out __SREG__, r16") /* 1 And restore the SREG value */ \
|
||||
A("pop r16") /* 2 Restore R16 */ \
|
||||
A("reti") /* 4 Return from interrupt */ \
|
||||
: \
|
||||
: [timsk0] "i"((uint16_t)&TIMSK0), \
|
||||
[msk0] "M" ((uint8_t)(1<<OCIE0B)) \
|
||||
: \
|
||||
); \
|
||||
} \
|
||||
void TIMER0_COMPB_vect_bottom()
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if !WITHIN(LCD_SERIAL_PORT, 0, 3)
|
||||
#error "LCD_SERIAL_PORT must be from 0 to 3."
|
||||
#endif
|
||||
#define LCD_SERIAL lcdSerial
|
||||
#if HAS_DGUS_LCD
|
||||
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.get_tx_buffer_free()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// ADC
|
||||
#ifdef DIDR2
|
||||
#define HAL_ANALOG_SELECT(ind) do{ if (ind < 8) SBI(DIDR0, ind); else SBI(DIDR2, ind & 0x07); }while(0)
|
||||
#else
|
||||
#define HAL_ANALOG_SELECT(ind) SBI(DIDR0, ind);
|
||||
#endif
|
||||
|
||||
inline void HAL_adc_init() {
|
||||
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
|
||||
DIDR0 = 0;
|
||||
#ifdef DIDR2
|
||||
DIDR2 = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define SET_ADMUX_ADCSRA(ch) ADMUX = _BV(REFS0) | (ch & 0x07); SBI(ADCSRA, ADSC)
|
||||
#ifdef MUX5
|
||||
#define HAL_START_ADC(ch) if (ch > 7) ADCSRB = _BV(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(ch)
|
||||
#else
|
||||
#define HAL_START_ADC(ch) ADCSRB = 0; SET_ADMUX_ADCSRA(ch)
|
||||
#endif
|
||||
|
||||
//
|
||||
#define HAL_ADC_VREF 5.0
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() ADC
|
||||
#define HAL_ADC_READY() !TEST(ADCSRA, ADSC)
|
||||
|
||||
//
|
||||
// Pin Mapping for M42, M43, M226
|
||||
//
|
||||
#define GET_PIN_MAP_PIN(index) index
|
||||
#define GET_PIN_MAP_INDEX(pin) pin
|
||||
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
|
||||
|
||||
#define HAL_SENSITIVE_PINS 0, 1
|
||||
#define HAL_SENSITIVE_PINS 0, 1,
|
||||
|
||||
#ifdef __AVR_AT90USB1286__
|
||||
#define JTAG_DISABLE() do{ MCUCR = 0x80; MCUCR = 0x80; }while(0)
|
||||
@@ -395,21 +166,113 @@ inline void HAL_adc_init() {
|
||||
// AVR compatibility
|
||||
#define strtof strtod
|
||||
|
||||
/**
|
||||
* set_pwm_frequency
|
||||
* Sets the frequency of the timer corresponding to the provided pin
|
||||
* as close as possible to the provided desired frequency. Internally
|
||||
* calculates the required waveform generation mode, prescaler and
|
||||
* resolution values required and sets the timer registers accordingly.
|
||||
* NOTE that the frequency is applied to all pins on the timer (Ex OC3A, OC3B and OC3B)
|
||||
* NOTE that there are limitations, particularly if using TIMER2. (see Configuration_adv.h -> FAST FAN PWM Settings)
|
||||
*/
|
||||
void set_pwm_frequency(const pin_t pin, int f_desired);
|
||||
// ------------------------
|
||||
// Free Memory Accessor
|
||||
// ------------------------
|
||||
|
||||
/**
|
||||
* set_pwm_duty
|
||||
* Sets the PWM duty cycle of the provided pin to the provided value
|
||||
* Optionally allows inverting the duty cycle [default = false]
|
||||
* Optionally allows changing the maximum size of the provided value to enable finer PWM duty control [default = 255]
|
||||
*/
|
||||
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
|
||||
#pragma GCC diagnostic push
|
||||
#if GCC_VERSION <= 50000
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#endif
|
||||
|
||||
extern "C" int freeMemory();
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
// ------------------------
|
||||
// MarlinHAL Class
|
||||
// ------------------------
|
||||
|
||||
class MarlinHAL {
|
||||
public:
|
||||
|
||||
// Earliest possible init, before setup()
|
||||
MarlinHAL() {}
|
||||
|
||||
// Watchdog
|
||||
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||
|
||||
static void init(); // Called early in setup()
|
||||
static void init_board() {} // Called less early in setup()
|
||||
static void reboot(); // Restart the firmware from 0x0
|
||||
|
||||
// Interrupts
|
||||
static bool isr_state() { return TEST(SREG, SREG_I); }
|
||||
static void isr_on() { sei(); }
|
||||
static void isr_off() { cli(); }
|
||||
|
||||
static void delay_ms(const int ms) { _delay_ms(ms); }
|
||||
|
||||
// Tasks, called from idle()
|
||||
static void idletask() {}
|
||||
|
||||
// Reset
|
||||
static uint8_t reset_reason;
|
||||
static uint8_t get_reset_source() { return reset_reason; }
|
||||
static void clear_reset_source() { MCUSR = 0; }
|
||||
|
||||
// Free SRAM
|
||||
static int freeMemory() { return ::freeMemory(); }
|
||||
|
||||
//
|
||||
// ADC Methods
|
||||
//
|
||||
|
||||
// Called by Temperature::init once at startup
|
||||
static void adc_init() {
|
||||
ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
|
||||
DIDR0 = 0;
|
||||
#ifdef DIDR2
|
||||
DIDR2 = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Called by Temperature::init for each sensor at startup
|
||||
static void adc_enable(const uint8_t ch) {
|
||||
#ifdef DIDR2
|
||||
if (ch > 7) { SBI(DIDR2, ch & 0x07); return; }
|
||||
#endif
|
||||
SBI(DIDR0, ch);
|
||||
}
|
||||
|
||||
// Begin ADC sampling on the given channel. Called from Temperature::isr!
|
||||
static void adc_start(const uint8_t ch) {
|
||||
#ifdef MUX5
|
||||
ADCSRB = ch > 7 ? _BV(MUX5) : 0;
|
||||
#else
|
||||
ADCSRB = 0;
|
||||
#endif
|
||||
ADMUX = _BV(REFS0) | (ch & 0x07);
|
||||
SBI(ADCSRA, ADSC);
|
||||
}
|
||||
|
||||
// Is the ADC ready for reading?
|
||||
static bool adc_ready() { return !TEST(ADCSRA, ADSC); }
|
||||
|
||||
// The current value of the ADC register
|
||||
static __typeof__(ADC) adc_value() { return ADC; }
|
||||
|
||||
/**
|
||||
* init_pwm_timers
|
||||
* Set the default frequency for timers 2-5 to 1000HZ
|
||||
*/
|
||||
static void init_pwm_timers();
|
||||
|
||||
/**
|
||||
* Set the PWM duty cycle for the pin to the given value.
|
||||
* Optionally invert the duty cycle [default = false]
|
||||
* Optionally change the scale of the provided value to enable finer PWM duty control [default = 255]
|
||||
*/
|
||||
static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size=255, const bool invert=false);
|
||||
|
||||
/**
|
||||
* Set the frequency of the timer for the given pin as close as
|
||||
* possible to the provided desired frequency. Internally calculate
|
||||
* the required waveform generation mode, prescaler, and resolution
|
||||
* values and set timer registers accordingly.
|
||||
* NOTE that the frequency is applied to all pins on the timer (Ex OC3A, OC3B and OC3B)
|
||||
* NOTE that there are limitations, particularly if using TIMER2. (see Configuration_adv.h -> FAST_PWM_FAN Settings)
|
||||
*/
|
||||
static void set_pwm_frequency(const pin_t pin, const uint16_t f_desired);
|
||||
};
|
||||
|
57
Marlin/src/HAL/AVR/HAL_SPI.cpp
Executable file → Normal file
57
Marlin/src/HAL/AVR/HAL_SPI.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -34,21 +34,21 @@
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
void spiBegin() {
|
||||
OUT_WRITE(SS_PIN, HIGH);
|
||||
SET_OUTPUT(SCK_PIN);
|
||||
SET_INPUT(MISO_PIN);
|
||||
SET_OUTPUT(MOSI_PIN);
|
||||
|
||||
#if DISABLED(SOFTWARE_SPI)
|
||||
// SS must be in output mode even it is not chip select
|
||||
//SET_OUTPUT(SS_PIN);
|
||||
// set SS high - may be chip select for another SPI device
|
||||
//#if SET_SPI_SS_HIGH
|
||||
//WRITE(SS_PIN, HIGH);
|
||||
//#endif
|
||||
// set a default rate
|
||||
spiInit(1);
|
||||
#if PIN_EXISTS(SD_SS)
|
||||
// Do not init HIGH for boards with pin 4 used as Fans or Heaters or otherwise, not likely to have multiple SPI devices anyway.
|
||||
#if defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__)
|
||||
// SS must be in output mode even it is not chip select
|
||||
SET_OUTPUT(SD_SS_PIN);
|
||||
#else
|
||||
// set SS high - may be chip select for another SPI device
|
||||
OUT_WRITE(SD_SS_PIN, HIGH);
|
||||
#endif
|
||||
#endif
|
||||
SET_OUTPUT(SD_SCK_PIN);
|
||||
SET_INPUT(SD_MISO_PIN);
|
||||
SET_OUTPUT(SD_MOSI_PIN);
|
||||
|
||||
IF_DISABLED(SOFTWARE_SPI, spiInit(SPI_HALF_SPEED));
|
||||
}
|
||||
|
||||
#if NONE(SOFTWARE_SPI, FORCE_SOFT_SPI)
|
||||
@@ -74,7 +74,8 @@ void spiBegin() {
|
||||
#elif defined(PRR0)
|
||||
PRR0
|
||||
#endif
|
||||
, PRSPI);
|
||||
, PRSPI
|
||||
);
|
||||
|
||||
SPCR = _BV(SPE) | _BV(MSTR) | (spiRate >> 1);
|
||||
SPSR = spiRate & 1 || spiRate == 6 ? 0 : _BV(SPI2X);
|
||||
@@ -88,7 +89,7 @@ void spiBegin() {
|
||||
}
|
||||
|
||||
/** SPI read data */
|
||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||
void spiRead(uint8_t *buf, uint16_t nbyte) {
|
||||
if (nbyte-- == 0) return;
|
||||
SPDR = 0xFF;
|
||||
for (uint16_t i = 0; i < nbyte; i++) {
|
||||
@@ -107,7 +108,7 @@ void spiBegin() {
|
||||
}
|
||||
|
||||
/** SPI send block */
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
void spiSendBlock(uint8_t token, const uint8_t *buf) {
|
||||
SPDR = token;
|
||||
for (uint16_t i = 0; i < 512; i += 2) {
|
||||
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
||||
@@ -195,19 +196,19 @@ void spiBegin() {
|
||||
// no interrupts during byte receive - about 8µs
|
||||
cli();
|
||||
// output pin high - like sending 0xFF
|
||||
WRITE(MOSI_PIN, HIGH);
|
||||
WRITE(SD_MOSI_PIN, HIGH);
|
||||
|
||||
LOOP_L_N(i, 8) {
|
||||
WRITE(SCK_PIN, HIGH);
|
||||
WRITE(SD_SCK_PIN, HIGH);
|
||||
|
||||
nop; // adjust so SCK is nice
|
||||
nop;
|
||||
|
||||
data <<= 1;
|
||||
|
||||
if (READ(MISO_PIN)) data |= 1;
|
||||
if (READ(SD_MISO_PIN)) data |= 1;
|
||||
|
||||
WRITE(SCK_PIN, LOW);
|
||||
WRITE(SD_SCK_PIN, LOW);
|
||||
}
|
||||
|
||||
sei();
|
||||
@@ -215,7 +216,7 @@ void spiBegin() {
|
||||
}
|
||||
|
||||
// Soft SPI read data
|
||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||
void spiRead(uint8_t *buf, uint16_t nbyte) {
|
||||
for (uint16_t i = 0; i < nbyte; i++)
|
||||
buf[i] = spiRec();
|
||||
}
|
||||
@@ -225,10 +226,10 @@ void spiBegin() {
|
||||
// no interrupts during byte send - about 8µs
|
||||
cli();
|
||||
LOOP_L_N(i, 8) {
|
||||
WRITE(SCK_PIN, LOW);
|
||||
WRITE(MOSI_PIN, data & 0x80);
|
||||
WRITE(SD_SCK_PIN, LOW);
|
||||
WRITE(SD_MOSI_PIN, data & 0x80);
|
||||
data <<= 1;
|
||||
WRITE(SCK_PIN, HIGH);
|
||||
WRITE(SD_SCK_PIN, HIGH);
|
||||
}
|
||||
|
||||
nop; // hold SCK high for a few ns
|
||||
@@ -236,13 +237,13 @@ void spiBegin() {
|
||||
nop;
|
||||
nop;
|
||||
|
||||
WRITE(SCK_PIN, LOW);
|
||||
WRITE(SD_SCK_PIN, LOW);
|
||||
|
||||
sei();
|
||||
}
|
||||
|
||||
// Soft SPI send block
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
void spiSendBlock(uint8_t token, const uint8_t *buf) {
|
||||
spiSend(token);
|
||||
for (uint16_t i = 0; i < 512; i++)
|
||||
spiSend(buf[i]);
|
||||
|
26
Marlin/src/HAL/AVR/MarlinSPI.h
Normal file
26
Marlin/src/HAL/AVR/MarlinSPI.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
using MarlinSPI = SPIClass;
|
1182
Marlin/src/HAL/AVR/MarlinSerial.cpp
Executable file → Normal file
1182
Marlin/src/HAL/AVR/MarlinSerial.cpp
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
125
Marlin/src/HAL/AVR/MarlinSerial.h
Executable file → Normal file
125
Marlin/src/HAL/AVR/MarlinSerial.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <WString.h>
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
#include "../../core/serial_hook.h"
|
||||
|
||||
#ifndef SERIAL_PORT
|
||||
#define SERIAL_PORT 0
|
||||
@@ -48,11 +49,11 @@
|
||||
|
||||
// These are macros to build serial port register names for the selected SERIAL_PORT (C preprocessor
|
||||
// requires two levels of indirection to expand macro values properly)
|
||||
#define SERIAL_REGNAME(registerbase,number,suffix) SERIAL_REGNAME_INTERNAL(registerbase,number,suffix)
|
||||
#define SERIAL_REGNAME(registerbase,number,suffix) _SERIAL_REGNAME(registerbase,number,suffix)
|
||||
#if SERIAL_PORT == 0 && (!defined(UBRR0H) || !defined(UDR0)) // use un-numbered registers if necessary
|
||||
#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##suffix
|
||||
#define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##suffix
|
||||
#else
|
||||
#define SERIAL_REGNAME_INTERNAL(registerbase,number,suffix) registerbase##number##suffix
|
||||
#define _SERIAL_REGNAME(registerbase,number,suffix) registerbase##number##suffix
|
||||
#endif
|
||||
|
||||
// Registers used by MarlinSerial class (expanded depending on selected serial port)
|
||||
@@ -135,10 +136,6 @@
|
||||
UART_DECL(3);
|
||||
#endif
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
#define BYTE 0
|
||||
|
||||
// Templated type selector
|
||||
@@ -194,66 +191,38 @@
|
||||
rx_framing_errors;
|
||||
static ring_buffer_pos_t rx_max_enqueued;
|
||||
|
||||
static FORCE_INLINE ring_buffer_pos_t atomic_read_rx_head();
|
||||
FORCE_INLINE static ring_buffer_pos_t atomic_read_rx_head();
|
||||
|
||||
static volatile bool rx_tail_value_not_stable;
|
||||
static volatile uint16_t rx_tail_value_backup;
|
||||
|
||||
static FORCE_INLINE void atomic_set_rx_tail(ring_buffer_pos_t value);
|
||||
static FORCE_INLINE ring_buffer_pos_t atomic_read_rx_tail();
|
||||
|
||||
public:
|
||||
FORCE_INLINE static void atomic_set_rx_tail(ring_buffer_pos_t value);
|
||||
FORCE_INLINE static ring_buffer_pos_t atomic_read_rx_tail();
|
||||
|
||||
public:
|
||||
FORCE_INLINE static void store_rxd_char();
|
||||
FORCE_INLINE static void _tx_udr_empty_irq();
|
||||
|
||||
public:
|
||||
MarlinSerial() {};
|
||||
static void begin(const long);
|
||||
static void end();
|
||||
static int peek();
|
||||
static int read();
|
||||
static void flush();
|
||||
static ring_buffer_pos_t available();
|
||||
static void write(const uint8_t c);
|
||||
static void flushTX();
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
static ring_buffer_pos_t get_tx_buffer_free();
|
||||
#endif
|
||||
public:
|
||||
static void begin(const long);
|
||||
static void end();
|
||||
static int peek();
|
||||
static int read();
|
||||
static void flush();
|
||||
static ring_buffer_pos_t available();
|
||||
static void write(const uint8_t c);
|
||||
static void flushTX();
|
||||
#if HAS_DGUS_LCD
|
||||
static ring_buffer_pos_t get_tx_buffer_free();
|
||||
#endif
|
||||
|
||||
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
|
||||
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
|
||||
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
|
||||
FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return Cfg::MAX_RX_QUEUED ? rx_max_enqueued : 0; }
|
||||
enum { HasEmergencyParser = Cfg::EMERGENCYPARSER };
|
||||
static bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
|
||||
|
||||
FORCE_INLINE static void write(const char* str) { while (*str) write(*str++); }
|
||||
FORCE_INLINE static void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); }
|
||||
FORCE_INLINE static void print(const String& s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
|
||||
FORCE_INLINE static void print(const char* str) { write(str); }
|
||||
|
||||
static void print(char, int = BYTE);
|
||||
static void print(unsigned char, int = BYTE);
|
||||
static void print(int, int = DEC);
|
||||
static void print(unsigned int, int = DEC);
|
||||
static void print(long, int = DEC);
|
||||
static void print(unsigned long, int = DEC);
|
||||
static void print(double, int = 2);
|
||||
|
||||
static void println(const String& s);
|
||||
static void println(const char[]);
|
||||
static void println(char, int = BYTE);
|
||||
static void println(unsigned char, int = BYTE);
|
||||
static void println(int, int = DEC);
|
||||
static void println(unsigned int, int = DEC);
|
||||
static void println(long, int = DEC);
|
||||
static void println(unsigned long, int = DEC);
|
||||
static void println(double, int = 2);
|
||||
static void println();
|
||||
operator bool() { return true; }
|
||||
|
||||
private:
|
||||
static void printNumber(unsigned long, const uint8_t);
|
||||
static void printFloat(double, uint8_t);
|
||||
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
|
||||
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
|
||||
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
|
||||
FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return Cfg::MAX_RX_QUEUED ? rx_max_enqueued : 0; }
|
||||
};
|
||||
|
||||
template <uint8_t serial>
|
||||
@@ -268,51 +237,61 @@
|
||||
static constexpr bool RX_FRAMING_ERRORS = ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS);
|
||||
static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED);
|
||||
};
|
||||
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
|
||||
|
||||
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT1;
|
||||
extern MSerialT1 customizedSerial1;
|
||||
|
||||
#ifdef SERIAL_PORT_2
|
||||
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
|
||||
extern MSerialT2 customizedSerial2;
|
||||
#endif
|
||||
|
||||
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
|
||||
|
||||
#ifdef SERIAL_PORT_3
|
||||
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_3> > > MSerialT3;
|
||||
extern MSerialT3 customizedSerial3;
|
||||
#endif
|
||||
|
||||
#endif // !USBCON
|
||||
|
||||
#ifdef INTERNAL_SERIAL_PORT
|
||||
#ifdef MMU2_SERIAL_PORT
|
||||
template <uint8_t serial>
|
||||
struct MarlinInternalSerialCfg {
|
||||
struct MMU2SerialCfg {
|
||||
static constexpr int PORT = serial;
|
||||
static constexpr unsigned int RX_SIZE = 32;
|
||||
static constexpr unsigned int TX_SIZE = 32;
|
||||
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;
|
||||
static constexpr bool RX_OVERRUNS = false;
|
||||
};
|
||||
|
||||
extern MarlinSerial<MarlinInternalSerialCfg<INTERNAL_SERIAL_PORT>> internalSerial;
|
||||
typedef Serial1Class< MarlinSerial< MMU2SerialCfg<MMU2_SERIAL_PORT> > > MSerialMMU2;
|
||||
extern MSerialMMU2 mmuSerial;
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
|
||||
template <uint8_t serial>
|
||||
struct MarlinInternalSerialCfg {
|
||||
struct LCDSerialCfg {
|
||||
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 = TERN(HAS_DGUS_LCD, DGUS_RX_BUFFER_SIZE, 64);
|
||||
static constexpr unsigned int TX_SIZE = TERN(HAS_DGUS_LCD, DGUS_TX_BUFFER_SIZE, 128);
|
||||
static constexpr bool XONOFF = false;
|
||||
static constexpr bool EMERGENCYPARSER = false;
|
||||
static constexpr bool EMERGENCYPARSER = ENABLED(EMERGENCY_PARSER);
|
||||
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_FRAMING_ERRORS = false;
|
||||
static constexpr bool MAX_RX_QUEUED = false;
|
||||
static constexpr bool RX_OVERRUNS = BOTH(HAS_DGUS_LCD, SERIAL_STATS_RX_BUFFER_OVERRUNS);
|
||||
};
|
||||
|
||||
extern MarlinSerial<MarlinInternalSerialCfg<DGUS_SERIAL_PORT>> internalDgusSerial;
|
||||
typedef Serial1Class< MarlinSerial< LCDSerialCfg<LCD_SERIAL_PORT> > > MSerialLCD;
|
||||
extern MSerialLCD lcdSerial;
|
||||
#endif
|
||||
|
||||
// Use the UART for Bluetooth in AT90USB configurations
|
||||
#if defined(USBCON) && ENABLED(BLUETOOTH)
|
||||
extern HardwareSerial bluetoothSerial;
|
||||
typedef Serial1Class<HardwareSerial> MSerialBT;
|
||||
extern MSerialBT bluetoothSerial;
|
||||
#endif
|
||||
|
198
Marlin/src/HAL/AVR/Servo.cpp
Executable file → Normal file
198
Marlin/src/HAL/AVR/Servo.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
* readMicroseconds() - Get the last-written servo pulse width in microseconds.
|
||||
* attached() - Return true if a servo is attached.
|
||||
* detach() - Stop an attached servo from pulsing its i/o pin.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
@@ -59,7 +58,6 @@
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/servo.h"
|
||||
#include "../shared/servo_private.h"
|
||||
|
||||
@@ -68,27 +66,26 @@ static volatile int8_t Channel[_Nbr_16timers]; // counter for the s
|
||||
|
||||
/************ static functions common to all instances ***********************/
|
||||
|
||||
static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t* TCNTn, volatile uint16_t* OCRnA) {
|
||||
if (Channel[timer] < 0)
|
||||
*TCNTn = 0; // channel set to -1 indicated that refresh interval completed so reset the timer
|
||||
else {
|
||||
if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && SERVO(timer, Channel[timer]).Pin.isActive)
|
||||
extDigitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, LOW); // pulse this channel low if activated
|
||||
}
|
||||
static inline void handle_interrupts(const timer16_Sequence_t timer, volatile uint16_t* TCNTn, volatile uint16_t* OCRnA) {
|
||||
int8_t cho = Channel[timer]; // Handle the prior Channel[timer] first
|
||||
if (cho < 0) // Channel -1 indicates the refresh interval completed...
|
||||
*TCNTn = 0; // ...so reset the timer
|
||||
else if (SERVO_INDEX(timer, cho) < ServoCount) // prior channel handled?
|
||||
extDigitalWrite(SERVO(timer, cho).Pin.nbr, LOW); // pulse the prior channel LOW
|
||||
|
||||
Channel[timer]++; // increment to the next channel
|
||||
if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) {
|
||||
*OCRnA = *TCNTn + SERVO(timer, Channel[timer]).ticks;
|
||||
if (SERVO(timer, Channel[timer]).Pin.isActive) // check if activated
|
||||
extDigitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, HIGH); // it's an active channel so pulse it high
|
||||
Channel[timer] = ++cho; // Handle the next channel (or 0)
|
||||
if (cho < SERVOS_PER_TIMER && SERVO_INDEX(timer, cho) < ServoCount) {
|
||||
*OCRnA = *TCNTn + SERVO(timer, cho).ticks; // set compare to current ticks plus duration
|
||||
if (SERVO(timer, cho).Pin.isActive) // activated?
|
||||
extDigitalWrite(SERVO(timer, cho).Pin.nbr, HIGH); // yes: pulse HIGH
|
||||
}
|
||||
else {
|
||||
// finished all channels so wait for the refresh period to expire before starting over
|
||||
if (((unsigned)*TCNTn) + 4 < usToTicks(REFRESH_INTERVAL)) // allow a few ticks to ensure the next OCR1A not missed
|
||||
*OCRnA = (unsigned int)usToTicks(REFRESH_INTERVAL);
|
||||
else
|
||||
*OCRnA = *TCNTn + 4; // at least REFRESH_INTERVAL has elapsed
|
||||
Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel
|
||||
const unsigned int cval = ((unsigned)*TCNTn) + 32 / (SERVO_TIMER_PRESCALER), // allow 32 cycles to ensure the next OCR1A not missed
|
||||
ival = (unsigned int)usToTicks(REFRESH_INTERVAL); // at least REFRESH_INTERVAL has elapsed
|
||||
*OCRnA = max(cval, ival);
|
||||
|
||||
Channel[timer] = -1; // reset the timer counter to 0 on the next call
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,91 +122,102 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
|
||||
|
||||
/****************** end of static functions ******************************/
|
||||
|
||||
void initISR(timer16_Sequence_t timer) {
|
||||
#ifdef _useTimer1
|
||||
if (timer == _timer1) {
|
||||
TCCR1A = 0; // normal counting mode
|
||||
TCCR1B = _BV(CS11); // set prescaler of 8
|
||||
TCNT1 = 0; // clear the timer count
|
||||
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
|
||||
SBI(TIFR, OCF1A); // clear any pending interrupts;
|
||||
SBI(TIMSK, OCIE1A); // enable the output compare interrupt
|
||||
#else
|
||||
// here if not ATmega8 or ATmega128
|
||||
SBI(TIFR1, OCF1A); // clear any pending interrupts;
|
||||
SBI(TIMSK1, OCIE1A); // enable the output compare interrupt
|
||||
#endif
|
||||
#ifdef WIRING
|
||||
timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
void initISR(const timer16_Sequence_t timer_index) {
|
||||
switch (timer_index) {
|
||||
default: break;
|
||||
|
||||
#ifdef _useTimer3
|
||||
if (timer == _timer3) {
|
||||
TCCR3A = 0; // normal counting mode
|
||||
TCCR3B = _BV(CS31); // set prescaler of 8
|
||||
TCNT3 = 0; // clear the timer count
|
||||
#ifdef __AVR_ATmega128__
|
||||
SBI(TIFR, OCF3A); // clear any pending interrupts;
|
||||
SBI(ETIMSK, OCIE3A); // enable the output compare interrupt
|
||||
#else
|
||||
SBI(TIFR3, OCF3A); // clear any pending interrupts;
|
||||
SBI(TIMSK3, OCIE3A); // enable the output compare interrupt
|
||||
#endif
|
||||
#ifdef WIRING
|
||||
timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service); // for Wiring platform only
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#ifdef _useTimer1
|
||||
case _timer1:
|
||||
TCCR1A = 0; // normal counting mode
|
||||
TCCR1B = _BV(CS11); // set prescaler of 8
|
||||
TCNT1 = 0; // clear the timer count
|
||||
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
|
||||
SBI(TIFR, OCF1A); // clear any pending interrupts;
|
||||
SBI(TIMSK, OCIE1A); // enable the output compare interrupt
|
||||
#else
|
||||
// here if not ATmega8 or ATmega128
|
||||
SBI(TIFR1, OCF1A); // clear any pending interrupts;
|
||||
SBI(TIMSK1, OCIE1A); // enable the output compare interrupt
|
||||
#endif
|
||||
#ifdef WIRING
|
||||
timerAttach(TIMER1OUTCOMPAREA_INT, Timer1Service);
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef _useTimer4
|
||||
if (timer == _timer4) {
|
||||
TCCR4A = 0; // normal counting mode
|
||||
TCCR4B = _BV(CS41); // set prescaler of 8
|
||||
TCNT4 = 0; // clear the timer count
|
||||
TIFR4 = _BV(OCF4A); // clear any pending interrupts;
|
||||
TIMSK4 = _BV(OCIE4A); // enable the output compare interrupt
|
||||
}
|
||||
#endif
|
||||
#ifdef _useTimer3
|
||||
case _timer3:
|
||||
TCCR3A = 0; // normal counting mode
|
||||
TCCR3B = _BV(CS31); // set prescaler of 8
|
||||
TCNT3 = 0; // clear the timer count
|
||||
#ifdef __AVR_ATmega128__
|
||||
SBI(TIFR, OCF3A); // clear any pending interrupts;
|
||||
SBI(ETIMSK, OCIE3A); // enable the output compare interrupt
|
||||
#else
|
||||
SBI(TIFR3, OCF3A); // clear any pending interrupts;
|
||||
SBI(TIMSK3, OCIE3A); // enable the output compare interrupt
|
||||
#endif
|
||||
#ifdef WIRING
|
||||
timerAttach(TIMER3OUTCOMPAREA_INT, Timer3Service); // for Wiring platform only
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef _useTimer5
|
||||
if (timer == _timer5) {
|
||||
TCCR5A = 0; // normal counting mode
|
||||
TCCR5B = _BV(CS51); // set prescaler of 8
|
||||
TCNT5 = 0; // clear the timer count
|
||||
TIFR5 = _BV(OCF5A); // clear any pending interrupts;
|
||||
TIMSK5 = _BV(OCIE5A); // enable the output compare interrupt
|
||||
}
|
||||
#endif
|
||||
#ifdef _useTimer4
|
||||
case _timer4:
|
||||
TCCR4A = 0; // normal counting mode
|
||||
TCCR4B = _BV(CS41); // set prescaler of 8
|
||||
TCNT4 = 0; // clear the timer count
|
||||
TIFR4 = _BV(OCF4A); // clear any pending interrupts;
|
||||
TIMSK4 = _BV(OCIE4A); // enable the output compare interrupt
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef _useTimer5
|
||||
case _timer5:
|
||||
TCCR5A = 0; // normal counting mode
|
||||
TCCR5B = _BV(CS51); // set prescaler of 8
|
||||
TCNT5 = 0; // clear the timer count
|
||||
TIFR5 = _BV(OCF5A); // clear any pending interrupts;
|
||||
TIMSK5 = _BV(OCIE5A); // enable the output compare interrupt
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void finISR(timer16_Sequence_t timer) {
|
||||
void finISR(const timer16_Sequence_t timer_index) {
|
||||
// Disable use of the given timer
|
||||
#ifdef WIRING
|
||||
if (timer == _timer1) {
|
||||
CBI(
|
||||
#if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
|
||||
TIMSK1
|
||||
#else
|
||||
TIMSK
|
||||
#endif
|
||||
, OCIE1A); // disable timer 1 output compare interrupt
|
||||
timerDetach(TIMER1OUTCOMPAREA_INT);
|
||||
}
|
||||
else if (timer == _timer3) {
|
||||
CBI(
|
||||
#if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
|
||||
TIMSK3
|
||||
#else
|
||||
ETIMSK
|
||||
#endif
|
||||
, OCIE3A); // disable the timer3 output compare A interrupt
|
||||
timerDetach(TIMER3OUTCOMPAREA_INT);
|
||||
switch (timer_index) {
|
||||
default: break;
|
||||
|
||||
case _timer1:
|
||||
CBI(
|
||||
#if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
|
||||
TIMSK1
|
||||
#else
|
||||
TIMSK
|
||||
#endif
|
||||
, OCIE1A // disable timer 1 output compare interrupt
|
||||
);
|
||||
timerDetach(TIMER1OUTCOMPAREA_INT);
|
||||
break;
|
||||
|
||||
case _timer3:
|
||||
CBI(
|
||||
#if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
|
||||
TIMSK3
|
||||
#else
|
||||
ETIMSK
|
||||
#endif
|
||||
, OCIE3A // disable the timer3 output compare A interrupt
|
||||
);
|
||||
timerDetach(TIMER3OUTCOMPAREA_INT);
|
||||
break;
|
||||
}
|
||||
#else // !WIRING
|
||||
// For arduino - in future: call here to a currently undefined function to reset the timer
|
||||
UNUSED(timer);
|
||||
UNUSED(timer_index);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
10
Marlin/src/HAL/AVR/ServoTimers.h
Executable file → Normal file
10
Marlin/src/HAL/AVR/ServoTimers.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#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
|
||||
|
25
Marlin/src/HAL/AVR/eeprom.cpp
Executable file → Normal file
25
Marlin/src/HAL/AVR/eeprom.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef __AVR__
|
||||
@@ -25,19 +25,28 @@
|
||||
|
||||
#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) {
|
||||
uint16_t written = 0;
|
||||
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 != eeprom_read_byte(p)) {
|
||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||
eeprom_write_byte(p, v);
|
||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||
if (eeprom_read_byte(p) != v) {
|
||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||
return true;
|
||||
@@ -46,11 +55,11 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
||||
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*/) {
|
||||
bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||
do {
|
||||
uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
||||
if (writing) *value = c;
|
||||
@@ -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__
|
||||
|
126
Marlin/src/HAL/AVR/endstop_interrupts.h
Executable file → Normal file
126
Marlin/src/HAL/AVR/endstop_interrupts.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -124,7 +124,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(X_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(X_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -132,7 +132,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(X_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(X_MIN_PIN), "X_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(X_MIN_PIN), "X_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(X_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -140,7 +140,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Y_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Y_MAX_PIN), "Y_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Y_MAX_PIN), "Y_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Y_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -148,7 +148,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Y_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Y_MIN_PIN), "Y_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Y_MIN_PIN), "Y_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Y_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -156,7 +156,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z_MAX_PIN), "Z_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z_MAX_PIN), "Z_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -164,15 +164,105 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z_MIN_PIN), "Z_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z_MIN_PIN), "Z_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_I_MAX
|
||||
#if (digitalPinToInterrupt(I_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(I_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(I_MAX_PIN), "I_MAX_PIN is not interrupt-capable");
|
||||
pciSetup(I_MAX_PIN);
|
||||
#endif
|
||||
#elif HAS_I_MIN
|
||||
#if (digitalPinToInterrupt(I_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(I_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(I_MIN_PIN), "I_MIN_PIN is not interrupt-capable");
|
||||
pciSetup(I_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_J_MAX
|
||||
#if (digitalPinToInterrupt(J_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(J_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(J_MAX_PIN), "J_MAX_PIN is not interrupt-capable");
|
||||
pciSetup(J_MAX_PIN);
|
||||
#endif
|
||||
#elif HAS_J_MIN
|
||||
#if (digitalPinToInterrupt(J_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(J_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(J_MIN_PIN), "J_MIN_PIN is not interrupt-capable");
|
||||
pciSetup(J_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_K_MAX
|
||||
#if (digitalPinToInterrupt(K_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(K_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(K_MAX_PIN), "K_MAX_PIN is not interrupt-capable");
|
||||
pciSetup(K_MAX_PIN);
|
||||
#endif
|
||||
#elif HAS_K_MIN
|
||||
#if (digitalPinToInterrupt(K_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(K_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(K_MIN_PIN), "K_MIN_PIN is not interrupt-capable");
|
||||
pciSetup(K_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_U_MAX
|
||||
#if (digitalPinToInterrupt(U_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(U_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(U_MAX_PIN), "U_MAX_PIN is not interrupt-capable");
|
||||
pciSetup(U_MAX_PIN);
|
||||
#endif
|
||||
#elif HAS_U_MIN
|
||||
#if (digitalPinToInterrupt(U_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(U_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(U_MIN_PIN), "U_MIN_PIN is not interrupt-capable");
|
||||
pciSetup(U_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_V_MAX
|
||||
#if (digitalPinToInterrupt(V_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(V_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(V_MAX_PIN), "V_MAX_PIN is not interrupt-capable");
|
||||
pciSetup(V_MAX_PIN);
|
||||
#endif
|
||||
#elif HAS_V_MIN
|
||||
#if (digitalPinToInterrupt(V_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(V_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(V_MIN_PIN), "V_MIN_PIN is not interrupt-capable");
|
||||
pciSetup(V_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_W_MAX
|
||||
#if (digitalPinToInterrupt(W_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(W_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(W_MAX_PIN), "W_MAX_PIN is not interrupt-capable");
|
||||
pciSetup(W_MAX_PIN);
|
||||
#endif
|
||||
#elif HAS_W_MIN
|
||||
#if (digitalPinToInterrupt(W_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(W_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(W_MIN_PIN), "W_MIN_PIN is not interrupt-capable");
|
||||
pciSetup(W_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
#if HAS_X2_MAX
|
||||
#if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(X2_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(X2_MAX_PIN), "X2_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(X2_MAX_PIN), "X2_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(X2_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -180,7 +270,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(X2_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(X2_MIN_PIN), "X2_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(X2_MIN_PIN), "X2_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(X2_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -188,7 +278,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Y2_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Y2_MAX_PIN), "Y2_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Y2_MAX_PIN), "Y2_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Y2_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -196,7 +286,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Y2_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Y2_MIN_PIN), "Y2_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Y2_MIN_PIN), "Y2_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Y2_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -204,7 +294,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z2_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z2_MAX_PIN), "Z2_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z2_MAX_PIN), "Z2_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z2_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -212,7 +302,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z2_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z2_MIN_PIN), "Z2_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z2_MIN_PIN), "Z2_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z2_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -220,7 +310,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z3_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z3_MAX_PIN), "Z3_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z3_MAX_PIN), "Z3_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z3_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -228,7 +318,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z3_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z3_MIN_PIN), "Z3_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z3_MIN_PIN), "Z3_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z3_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -236,7 +326,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z4_MAX_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z4_MAX_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z4_MAX_PIN), "Z4_MAX_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z4_MAX_PIN), "Z4_MAX_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z4_MAX_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -244,7 +334,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z4_MIN_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z4_MIN_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z4_MIN_PIN), "Z4_MIN_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z4_MIN_PIN), "Z4_MIN_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z4_MIN_PIN);
|
||||
#endif
|
||||
#endif
|
||||
@@ -252,7 +342,7 @@ void setup_endstop_interrupts() {
|
||||
#if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
|
||||
_ATTACH(Z_MIN_PROBE_PIN);
|
||||
#else
|
||||
static_assert(digitalPinHasPCICR(Z_MIN_PROBE_PIN), "Z_MIN_PROBE_PIN is not interrupt-capable");
|
||||
static_assert(digitalPinHasPCICR(Z_MIN_PROBE_PIN), "Z_MIN_PROBE_PIN is not interrupt-capable. Disable ENDSTOP_INTERRUPTS_FEATURE to continue.");
|
||||
pciSetup(Z_MIN_PROBE_PIN);
|
||||
#endif
|
||||
#endif
|
||||
|
332
Marlin/src/HAL/AVR/fast_pwm.cpp
Executable file → Normal file
332
Marlin/src/HAL/AVR/fast_pwm.cpp
Executable file → Normal file
@@ -16,16 +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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef __AVR__
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_PWM
|
||||
|
||||
#include "HAL.h"
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
struct Timer {
|
||||
volatile uint8_t* TCCRnQ[3]; // max 3 TCCR registers per timer
|
||||
@@ -33,250 +29,194 @@ struct Timer {
|
||||
volatile uint16_t* ICRn; // max 1 ICR register per timer
|
||||
uint8_t n; // the timer number [0->5]
|
||||
uint8_t q; // the timer output [0->2] (A->C)
|
||||
bool isPWM; // True if pin is a "hardware timer"
|
||||
bool isProtected; // True if timer is protected
|
||||
};
|
||||
|
||||
// Macros for the Timer structure
|
||||
#define _SET_WGMnQ(T, V) do{ \
|
||||
*(T.TCCRnQ)[0] = (*(T.TCCRnQ)[0] & ~(0x3 << 0)) | (( int(V) & 0x3) << 0); \
|
||||
*(T.TCCRnQ)[1] = (*(T.TCCRnQ)[1] & ~(0x3 << 3)) | (((int(V) >> 2) & 0x3) << 3); \
|
||||
}while(0)
|
||||
|
||||
// Set TCCR CS bits
|
||||
#define _SET_CSn(T, V) (*(T.TCCRnQ)[1] = (*(T.TCCRnQ[1]) & ~(0x7 << 0)) | ((int(V) & 0x7) << 0))
|
||||
|
||||
// Set TCCR COM bits
|
||||
#define _SET_COMnQ(T, Q, V) (*(T.TCCRnQ)[0] = (*(T.TCCRnQ)[0] & ~(0x3 << (6-2*(Q)))) | (int(V) << (6-2*(Q))))
|
||||
|
||||
// Set OCRnQ register
|
||||
#define _SET_OCRnQ(T, Q, V) (*(T.OCRnQ)[Q] = int(V) & 0xFFFF)
|
||||
|
||||
// Set ICRn register (one per timer)
|
||||
#define _SET_ICRn(T, V) (*(T.ICRn) = int(V) & 0xFFFF)
|
||||
|
||||
/**
|
||||
* get_pwm_timer
|
||||
* Get the timer information and register of the provided pin.
|
||||
* Return a Timer struct containing this information.
|
||||
* Used by set_pwm_frequency, set_pwm_duty
|
||||
* Return a Timer struct describing a pin's timer.
|
||||
*/
|
||||
Timer get_pwm_timer(const pin_t pin) {
|
||||
const Timer get_pwm_timer(const pin_t pin) {
|
||||
|
||||
uint8_t q = 0;
|
||||
|
||||
switch (digitalPinToTimer(pin)) {
|
||||
// Protect reserved timers (TIMER0 & TIMER1)
|
||||
#ifdef TCCR0A
|
||||
#if !AVR_AT90USB1286_FAMILY
|
||||
case TIMER0A:
|
||||
#endif
|
||||
case TIMER0B:
|
||||
IF_DISABLED(AVR_AT90USB1286_FAMILY, case TIMER0A:)
|
||||
#endif
|
||||
#ifdef TCCR1A
|
||||
case TIMER1A: case TIMER1B:
|
||||
#endif
|
||||
break;
|
||||
#if defined(TCCR2) || defined(TCCR2A)
|
||||
#ifdef TCCR2
|
||||
case TIMER2: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR2, nullptr, nullptr },
|
||||
/*OCRnQ*/ { (uint16_t*)&OCR2, nullptr, nullptr },
|
||||
/*ICRn*/ nullptr,
|
||||
/*n, q*/ 2, 0
|
||||
};
|
||||
}
|
||||
#elif defined(TCCR2A)
|
||||
#if ENABLED(USE_OCR2A_AS_TOP)
|
||||
case TIMER2A: break; // protect TIMER2A
|
||||
case TIMER2B: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
|
||||
/*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
|
||||
/*ICRn*/ nullptr,
|
||||
/*n, q*/ 2, 1
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
#else
|
||||
case TIMER2B: ++q;
|
||||
case TIMER2A: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR2A, &TCCR2B, nullptr },
|
||||
/*OCRnQ*/ { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr },
|
||||
/*ICRn*/ nullptr,
|
||||
2, q
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
break; // Protect reserved timers (TIMER0 & TIMER1)
|
||||
|
||||
#ifdef TCCR0A
|
||||
case TIMER0B: // Protected timer, but allow setting the duty cycle on OCR0B for pin D4 only
|
||||
return Timer({ { &TCCR0A, nullptr, nullptr }, { (uint16_t*)&OCR0A, (uint16_t*)&OCR0B, nullptr }, nullptr, 0, 1, true, true });
|
||||
#endif
|
||||
|
||||
#if HAS_TCCR2
|
||||
case TIMER2:
|
||||
return Timer({ { &TCCR2, nullptr, nullptr }, { (uint16_t*)&OCR2, nullptr, nullptr }, nullptr, 2, 0, true, false });
|
||||
#elif ENABLED(USE_OCR2A_AS_TOP)
|
||||
case TIMER2A: break; // Protect TIMER2A since its OCR is used by TIMER2B
|
||||
case TIMER2B:
|
||||
return Timer({ { &TCCR2A, &TCCR2B, nullptr }, { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr }, nullptr, 2, 1, true, false });
|
||||
#elif defined(TCCR2A)
|
||||
case TIMER2B: ++q; case TIMER2A:
|
||||
return Timer({ { &TCCR2A, &TCCR2B, nullptr }, { (uint16_t*)&OCR2A, (uint16_t*)&OCR2B, nullptr }, nullptr, 2, q, true, false });
|
||||
#endif
|
||||
|
||||
#ifdef OCR3C
|
||||
case TIMER3C: ++q;
|
||||
case TIMER3B: ++q;
|
||||
case TIMER3A: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR3A, &TCCR3B, &TCCR3C },
|
||||
/*OCRnQ*/ { &OCR3A, &OCR3B, &OCR3C },
|
||||
/*ICRn*/ &ICR3,
|
||||
/*n, q*/ 3, q
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
case TIMER3C: ++q; case TIMER3B: ++q; case TIMER3A:
|
||||
return Timer({ { &TCCR3A, &TCCR3B, &TCCR3C }, { &OCR3A, &OCR3B, &OCR3C }, &ICR3, 3, q, true, false });
|
||||
#elif defined(OCR3B)
|
||||
case TIMER3B: ++q;
|
||||
case TIMER3A: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR3A, &TCCR3B, nullptr },
|
||||
/*OCRnQ*/ { &OCR3A, &OCR3B, nullptr },
|
||||
/*ICRn*/ &ICR3,
|
||||
/*n, q*/ 3, q
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
case TIMER3B: ++q; case TIMER3A:
|
||||
return Timer({ { &TCCR3A, &TCCR3B, nullptr }, { &OCR3A, &OCR3B, nullptr }, &ICR3, 3, q, true, false });
|
||||
#endif
|
||||
|
||||
#ifdef TCCR4A
|
||||
case TIMER4C: ++q;
|
||||
case TIMER4B: ++q;
|
||||
case TIMER4A: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR4A, &TCCR4B, &TCCR4C },
|
||||
/*OCRnQ*/ { &OCR4A, &OCR4B, &OCR4C },
|
||||
/*ICRn*/ &ICR4,
|
||||
/*n, q*/ 4, q
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
case TIMER4C: ++q; case TIMER4B: ++q; case TIMER4A:
|
||||
return Timer({ { &TCCR4A, &TCCR4B, &TCCR4C }, { &OCR4A, &OCR4B, &OCR4C }, &ICR4, 4, q, true, false });
|
||||
#endif
|
||||
|
||||
#ifdef TCCR5A
|
||||
case TIMER5C: ++q;
|
||||
case TIMER5B: ++q;
|
||||
case TIMER5A: {
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { &TCCR5A, &TCCR5B, &TCCR5C },
|
||||
/*OCRnQ*/ { &OCR5A, &OCR5B, &OCR5C },
|
||||
/*ICRn*/ &ICR5,
|
||||
/*n, q*/ 5, q
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
case TIMER5C: ++q; case TIMER5B: ++q; case TIMER5A:
|
||||
return Timer({ { &TCCR5A, &TCCR5B, &TCCR5C }, { &OCR5A, &OCR5B, &OCR5C }, &ICR5, 5, q, true, false });
|
||||
#endif
|
||||
}
|
||||
Timer timer = {
|
||||
/*TCCRnQ*/ { nullptr, nullptr, nullptr },
|
||||
/*OCRnQ*/ { nullptr, nullptr, nullptr },
|
||||
/*ICRn*/ nullptr,
|
||||
0, 0
|
||||
};
|
||||
return timer;
|
||||
|
||||
return Timer();
|
||||
}
|
||||
|
||||
void set_pwm_frequency(const pin_t pin, int f_desired) {
|
||||
Timer timer = get_pwm_timer(pin);
|
||||
if (timer.n == 0) return; // Don't proceed if protected timer or not recognised
|
||||
uint16_t size;
|
||||
if (timer.n == 2) size = 255; else size = 65535;
|
||||
void MarlinHAL::set_pwm_frequency(const pin_t pin, const uint16_t f_desired) {
|
||||
const Timer timer = get_pwm_timer(pin);
|
||||
if (timer.isProtected || !timer.isPWM) return; // Don't proceed if protected timer or not recognized
|
||||
|
||||
uint16_t res = 255; // resolution (TOP value)
|
||||
uint8_t j = 0; // prescaler index
|
||||
uint8_t wgm = 1; // waveform generation mode
|
||||
const bool is_timer2 = timer.n == 2;
|
||||
const uint16_t maxtop = is_timer2 ? 0xFF : 0xFFFF;
|
||||
|
||||
uint16_t res = 0xFF; // resolution (TOP value)
|
||||
uint8_t j = CS_NONE; // prescaler index
|
||||
uint8_t wgm = WGM_PWM_PC_8; // waveform generation mode
|
||||
|
||||
// Calculating the prescaler and resolution to use to achieve closest frequency
|
||||
if (f_desired != 0) {
|
||||
int f = (F_CPU) / (2 * 1024 * size) + 1; // Initialize frequency as lowest (non-zero) achievable
|
||||
uint16_t prescaler[] = { 0, 1, 8, /*TIMER2 ONLY*/32, 64, /*TIMER2 ONLY*/128, 256, 1024 };
|
||||
constexpr uint16_t prescaler[] = { 1, 8, (32), 64, (128), 256, 1024 }; // (*) are Timer 2 only
|
||||
uint16_t f = (F_CPU) / (2 * 1024 * maxtop) + 1; // Start with the lowest non-zero frequency achievable (1 or 31)
|
||||
|
||||
// loop over prescaler values
|
||||
LOOP_S_L_N(i, 1, 8) {
|
||||
uint16_t res_temp_fast = 255, res_temp_phase_correct = 255;
|
||||
if (timer.n == 2) {
|
||||
// No resolution calculation for TIMER2 unless enabled USE_OCR2A_AS_TOP
|
||||
#if ENABLED(USE_OCR2A_AS_TOP)
|
||||
const uint16_t rtf = (F_CPU) / (prescaler[i] * f_desired);
|
||||
res_temp_fast = rtf - 1;
|
||||
res_temp_phase_correct = rtf / 2;
|
||||
LOOP_L_N(i, COUNT(prescaler)) { // Loop through all prescaler values
|
||||
const uint16_t p = prescaler[i];
|
||||
uint16_t res_fast_temp, res_pc_temp;
|
||||
if (is_timer2) {
|
||||
#if ENABLED(USE_OCR2A_AS_TOP) // No resolution calculation for TIMER2 unless enabled USE_OCR2A_AS_TOP
|
||||
const uint16_t rft = (F_CPU) / (p * f_desired);
|
||||
res_fast_temp = rft - 1;
|
||||
res_pc_temp = rft / 2;
|
||||
#else
|
||||
res_fast_temp = res_pc_temp = maxtop;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
// Skip TIMER2 specific prescalers when not TIMER2
|
||||
if (i == 3 || i == 5) continue;
|
||||
const uint16_t rtf = (F_CPU) / (prescaler[i] * f_desired);
|
||||
res_temp_fast = rtf - 1;
|
||||
res_temp_phase_correct = rtf / 2;
|
||||
if (p == 32 || p == 128) continue; // Skip TIMER2 specific prescalers when not TIMER2
|
||||
const uint16_t rft = (F_CPU) / (p * f_desired);
|
||||
res_fast_temp = rft - 1;
|
||||
res_pc_temp = rft / 2;
|
||||
}
|
||||
|
||||
LIMIT(res_temp_fast, 1u, size);
|
||||
LIMIT(res_temp_phase_correct, 1u, size);
|
||||
LIMIT(res_fast_temp, 1U, maxtop);
|
||||
LIMIT(res_pc_temp, 1U, maxtop);
|
||||
|
||||
// Calculate frequencies of test prescaler and resolution values
|
||||
const int f_temp_fast = (F_CPU) / (prescaler[i] * (1 + res_temp_fast)),
|
||||
f_temp_phase_correct = (F_CPU) / (2 * prescaler[i] * res_temp_phase_correct),
|
||||
f_diff = ABS(f - f_desired),
|
||||
f_fast_diff = ABS(f_temp_fast - f_desired),
|
||||
f_phase_diff = ABS(f_temp_phase_correct - f_desired);
|
||||
const uint16_t f_fast_temp = (F_CPU) / (p * (1 + res_fast_temp)),
|
||||
f_pc_temp = (F_CPU) / (2 * p * res_pc_temp);
|
||||
const int f_diff = _MAX(f, f_desired) - _MIN(f, f_desired),
|
||||
f_fast_diff = _MAX(f_fast_temp, f_desired) - _MIN(f_fast_temp, f_desired),
|
||||
f_pc_diff = _MAX(f_pc_temp, f_desired) - _MIN(f_pc_temp, f_desired);
|
||||
|
||||
// If FAST values are closest to desired f
|
||||
if (f_fast_diff < f_diff && f_fast_diff <= f_phase_diff) {
|
||||
// Remember this combination
|
||||
f = f_temp_fast;
|
||||
res = res_temp_fast;
|
||||
j = i;
|
||||
if (f_fast_diff < f_diff && f_fast_diff <= f_pc_diff) { // FAST values are closest to desired f
|
||||
// Set the Wave Generation Mode to FAST PWM
|
||||
if (timer.n == 2) {
|
||||
wgm = (
|
||||
#if ENABLED(USE_OCR2A_AS_TOP)
|
||||
WGM2_FAST_PWM_OCR2A
|
||||
#else
|
||||
WGM2_FAST_PWM
|
||||
#endif
|
||||
);
|
||||
}
|
||||
else wgm = WGM_FAST_PWM_ICRn;
|
||||
wgm = is_timer2 ? uint8_t(TERN(USE_OCR2A_AS_TOP, WGM2_FAST_PWM_OCR2A, WGM2_FAST_PWM)) : uint8_t(WGM_FAST_PWM_ICRn);
|
||||
// Remember this combination
|
||||
f = f_fast_temp; res = res_fast_temp; j = i + 1;
|
||||
}
|
||||
// If PHASE CORRECT values are closes to desired f
|
||||
else if (f_phase_diff < f_diff) {
|
||||
f = f_temp_phase_correct;
|
||||
res = res_temp_phase_correct;
|
||||
j = i;
|
||||
else if (f_pc_diff < f_diff) { // PHASE CORRECT values are closes to desired f
|
||||
// Set the Wave Generation Mode to PWM PHASE CORRECT
|
||||
if (timer.n == 2) {
|
||||
wgm = (
|
||||
#if ENABLED(USE_OCR2A_AS_TOP)
|
||||
WGM2_PWM_PC_OCR2A
|
||||
#else
|
||||
WGM2_PWM_PC
|
||||
#endif
|
||||
);
|
||||
}
|
||||
else wgm = WGM_PWM_PC_ICRn;
|
||||
wgm = is_timer2 ? uint8_t(TERN(USE_OCR2A_AS_TOP, WGM2_PWM_PC_OCR2A, WGM2_PWM_PC)) : uint8_t(WGM_PWM_PC_ICRn);
|
||||
f = f_pc_temp; res = res_pc_temp; j = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
_SET_WGMnQ(timer.TCCRnQ, wgm);
|
||||
_SET_CSn(timer.TCCRnQ, j);
|
||||
|
||||
if (timer.n == 2) {
|
||||
#if ENABLED(USE_OCR2A_AS_TOP)
|
||||
_SET_OCRnQ(timer.OCRnQ, 0, res); // Set OCR2A value (TOP) = res
|
||||
#endif
|
||||
_SET_WGMnQ(timer, wgm);
|
||||
_SET_CSn(timer, j);
|
||||
|
||||
if (is_timer2) {
|
||||
TERN_(USE_OCR2A_AS_TOP, _SET_OCRnQ(timer, 0, res)); // Set OCR2A value (TOP) = res
|
||||
}
|
||||
else
|
||||
_SET_ICRn(timer.ICRn, res); // Set ICRn value (TOP) = res
|
||||
_SET_ICRn(timer, res); // Set ICRn value (TOP) = res
|
||||
}
|
||||
|
||||
void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
|
||||
void MarlinHAL::set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t v_size/*=255*/, const bool invert/*=false*/) {
|
||||
// If v is 0 or v_size (max), digitalWrite to LOW or HIGH.
|
||||
// Note that digitalWrite also disables pwm output for us (sets COM bit to 0)
|
||||
// Note that digitalWrite also disables PWM output for us (sets COM bit to 0)
|
||||
if (v == 0)
|
||||
digitalWrite(pin, invert);
|
||||
else if (v == v_size)
|
||||
digitalWrite(pin, !invert);
|
||||
else {
|
||||
Timer timer = get_pwm_timer(pin);
|
||||
if (timer.n == 0) return; // Don't proceed if protected timer or not recognised
|
||||
// Set compare output mode to CLEAR -> SET or SET -> CLEAR (if inverted)
|
||||
_SET_COMnQ(timer.TCCRnQ, (timer.q
|
||||
#ifdef TCCR2
|
||||
+ (timer.q == 2) // COM20 is on bit 4 of TCCR2, thus requires q + 1 in the macro
|
||||
#endif
|
||||
), COM_CLEAR_SET + invert
|
||||
);
|
||||
|
||||
uint16_t top;
|
||||
if (timer.n == 2) { // if TIMER2
|
||||
top = (
|
||||
#if ENABLED(USE_OCR2A_AS_TOP)
|
||||
*timer.OCRnQ[0] // top = OCR2A
|
||||
#else
|
||||
255 // top = 0xFF (max)
|
||||
#endif
|
||||
);
|
||||
const Timer timer = get_pwm_timer(pin);
|
||||
if (timer.isPWM) {
|
||||
if (timer.n == 0) {
|
||||
_SET_COMnQ(timer, timer.q, COM_CLEAR_SET); // Only allow a TIMER0B select...
|
||||
_SET_OCRnQ(timer, timer.q, v); // ...and OCR0B duty update. For output pin D4 no frequency changes are permitted.
|
||||
}
|
||||
else if (!timer.isProtected) {
|
||||
const uint16_t top = timer.n == 2 ? TERN(USE_OCR2A_AS_TOP, *timer.OCRnQ[0], 255) : *timer.ICRn;
|
||||
_SET_COMnQ(timer, SUM_TERN(HAS_TCCR2, timer.q, timer.q == 2), COM_CLEAR_SET + invert); // COM20 is on bit 4 of TCCR2, so +1 for q==2
|
||||
_SET_OCRnQ(timer, timer.q, uint16_t(uint32_t(v) * top / v_size)); // Scale 8/16-bit v to top value
|
||||
}
|
||||
}
|
||||
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
|
||||
digitalWrite(pin, v < v_size / 2 ? LOW : HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // FAST_PWM_FAN || SPINDLE_LASER_PWM
|
||||
void MarlinHAL::init_pwm_timers() {
|
||||
// Init some timer frequencies to a default 1KHz
|
||||
const pin_t pwm_pin[] = {
|
||||
#ifdef __AVR_ATmega2560__
|
||||
10, 5, 6, 46
|
||||
#elif defined(__AVR_ATmega1280__)
|
||||
12, 31
|
||||
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284__)
|
||||
15, 6
|
||||
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_mega64) || defined(__AVR_mega128)
|
||||
16, 24
|
||||
#endif
|
||||
};
|
||||
|
||||
LOOP_L_N(i, COUNT(pwm_pin))
|
||||
set_pwm_frequency(pwm_pin[i], 1000);
|
||||
}
|
||||
|
||||
#endif // __AVR__
|
||||
|
52
Marlin/src/HAL/AVR/fastio.cpp
Executable file → Normal file
52
Marlin/src/HAL/AVR/fastio.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -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_t 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_ECHOLNPGM(" Prescaler=", prescaler);
|
||||
//SERIAL_ECHOLNPGM(" TOP=", ICR5);
|
||||
//SERIAL_ECHOLNPGM(" OCR5A=", OCR5A);
|
||||
//SERIAL_ECHOLNPGM(" OCR5B=", OCR5B);
|
||||
//SERIAL_ECHOLNPGM(" 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__
|
||||
|
95
Marlin/src/HAL/AVR/fastio.h
Executable file → Normal file
95
Marlin/src/HAL/AVR/fastio.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -29,11 +29,17 @@
|
||||
|
||||
#include <avr/io.h>
|
||||
|
||||
#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__))
|
||||
#define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
|
||||
#define AVR_ATmega2560_FAMILY (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__))
|
||||
#define AVR_ATmega2561_FAMILY (defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__))
|
||||
#define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
|
||||
#if defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__) || defined(__AVR_AT90USB647__)
|
||||
#define AVR_AT90USB1286_FAMILY 1
|
||||
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__)
|
||||
#define AVR_ATmega1284_FAMILY 1
|
||||
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||
#define AVR_ATmega2560_FAMILY 1
|
||||
#elif defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
|
||||
#define AVR_ATmega2561_FAMILY 1
|
||||
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
|
||||
#define AVR_ATmega328_FAMILY 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Include Ports and Functions
|
||||
@@ -57,7 +63,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)
|
||||
@@ -112,7 +118,7 @@
|
||||
*/
|
||||
|
||||
// Waveform Generation Modes
|
||||
enum WaveGenMode : char {
|
||||
enum WaveGenMode : uint8_t {
|
||||
WGM_NORMAL, // 0
|
||||
WGM_PWM_PC_8, // 1
|
||||
WGM_PWM_PC_9, // 2
|
||||
@@ -132,19 +138,19 @@ enum WaveGenMode : char {
|
||||
};
|
||||
|
||||
// Wavefore Generation Modes (Timer 2 only)
|
||||
enum WaveGenMode2 : char {
|
||||
WGM2_NORMAL, // 0
|
||||
WGM2_PWM_PC, // 1
|
||||
WGM2_CTC_OCR2A, // 2
|
||||
WGM2_FAST_PWM, // 3
|
||||
WGM2_reserved_1, // 4
|
||||
WGM2_PWM_PC_OCR2A, // 5
|
||||
WGM2_reserved_2, // 6
|
||||
WGM2_FAST_PWM_OCR2A, // 7
|
||||
enum WaveGenMode2 : uint8_t {
|
||||
WGM2_NORMAL, // 0
|
||||
WGM2_PWM_PC, // 1
|
||||
WGM2_CTC_OCR2A, // 2
|
||||
WGM2_FAST_PWM, // 3
|
||||
WGM2_reserved_1, // 4
|
||||
WGM2_PWM_PC_OCR2A, // 5
|
||||
WGM2_reserved_2, // 6
|
||||
WGM2_FAST_PWM_OCR2A, // 7
|
||||
};
|
||||
|
||||
// Compare Modes
|
||||
enum CompareMode : char {
|
||||
enum CompareMode : uint8_t {
|
||||
COM_NORMAL, // 0
|
||||
COM_TOGGLE, // 1 Non-PWM: OCnx ... Both PWM (WGM 9,11,14,15): OCnA only ... else NORMAL
|
||||
COM_CLEAR_SET, // 2 Non-PWM: OCnx ... Fast PWM: OCnx/Bottom ... PF-FC: OCnx Up/Down
|
||||
@@ -152,7 +158,7 @@ enum CompareMode : char {
|
||||
};
|
||||
|
||||
// Clock Sources
|
||||
enum ClockSource : char {
|
||||
enum ClockSource : uint8_t {
|
||||
CS_NONE, // 0
|
||||
CS_PRESCALER_1, // 1
|
||||
CS_PRESCALER_8, // 2
|
||||
@@ -164,7 +170,7 @@ enum ClockSource : char {
|
||||
};
|
||||
|
||||
// Clock Sources (Timer 2 only)
|
||||
enum ClockSource2 : char {
|
||||
enum ClockSource2 : uint8_t {
|
||||
CS2_NONE, // 0
|
||||
CS2_PRESCALER_1, // 1
|
||||
CS2_PRESCALER_8, // 2
|
||||
@@ -197,40 +203,33 @@ enum ClockSource2 : char {
|
||||
TCCR##T##B = (TCCR##T##B & ~(0x3 << WGM##T##2)) | (((int(V) >> 2) & 0x3) << WGM##T##2); \
|
||||
}while(0)
|
||||
#define SET_WGM(T,V) _SET_WGM(T,WGM_##V)
|
||||
// Runtime (see set_pwm_frequency):
|
||||
#define _SET_WGMnQ(TCCRnQ, V) do{ \
|
||||
*(TCCRnQ)[0] = (*(TCCRnQ)[0] & ~(0x3 << 0)) | (( int(V) & 0x3) << 0); \
|
||||
*(TCCRnQ)[1] = (*(TCCRnQ)[1] & ~(0x3 << 3)) | (((int(V) >> 2) & 0x3) << 3); \
|
||||
}while(0)
|
||||
|
||||
// Set Clock Select bits
|
||||
// Ex: SET_CS3(PRESCALER_64);
|
||||
#ifdef TCCR2
|
||||
#define HAS_TCCR2 1
|
||||
#endif
|
||||
#define _SET_CS(T,V) (TCCR##T##B = (TCCR##T##B & ~(0x7 << CS##T##0)) | ((int(V) & 0x7) << CS##T##0))
|
||||
#define _SET_CS0(V) _SET_CS(0,V)
|
||||
#define _SET_CS1(V) _SET_CS(1,V)
|
||||
#ifdef TCCR2
|
||||
#define _SET_CS2(V) (TCCR2 = (TCCR2 & ~(0x7 << CS20)) | (int(V) << CS20))
|
||||
#else
|
||||
#define _SET_CS2(V) _SET_CS(2,V)
|
||||
#endif
|
||||
#define _SET_CS3(V) _SET_CS(3,V)
|
||||
#define _SET_CS4(V) _SET_CS(4,V)
|
||||
#define _SET_CS5(V) _SET_CS(5,V)
|
||||
#define SET_CS0(V) _SET_CS0(CS_##V)
|
||||
#define SET_CS1(V) _SET_CS1(CS_##V)
|
||||
#ifdef TCCR2
|
||||
|
||||
#if HAS_TCCR2
|
||||
#define _SET_CS2(V) (TCCR2 = (TCCR2 & ~(0x7 << CS20)) | (int(V) << CS20))
|
||||
#define SET_CS2(V) _SET_CS2(CS2_##V)
|
||||
#else
|
||||
#define _SET_CS2(V) _SET_CS(2,V)
|
||||
#define SET_CS2(V) _SET_CS2(CS_##V)
|
||||
#endif
|
||||
|
||||
#define SET_CS3(V) _SET_CS3(CS_##V)
|
||||
#define SET_CS4(V) _SET_CS4(CS_##V)
|
||||
#define SET_CS5(V) _SET_CS5(CS_##V)
|
||||
#define SET_CS(T,V) SET_CS##T(V)
|
||||
// Runtime (see set_pwm_frequency)
|
||||
#define _SET_CSn(TCCRnQ, V) do{ \
|
||||
(*(TCCRnQ)[1] = (*(TCCRnQ[1]) & ~(0x7 << 0)) | ((int(V) & 0x7) << 0)); \
|
||||
}while(0)
|
||||
|
||||
// Set Compare Mode bits
|
||||
// Ex: SET_COMS(4,CLEAR_SET,CLEAR_SET,CLEAR_SET);
|
||||
@@ -240,22 +239,6 @@ enum ClockSource2 : char {
|
||||
#define SET_COMB(T,V) SET_COM(T,B,V)
|
||||
#define SET_COMC(T,V) SET_COM(T,C,V)
|
||||
#define SET_COMS(T,V1,V2,V3) do{ SET_COMA(T,V1); SET_COMB(T,V2); SET_COMC(T,V3); }while(0)
|
||||
// Runtime (see set_pwm_duty)
|
||||
#define _SET_COMnQ(TCCRnQ, Q, V) do{ \
|
||||
(*(TCCRnQ)[0] = (*(TCCRnQ)[0] & ~(0x3 << (6-2*(Q)))) | (int(V) << (6-2*(Q)))); \
|
||||
}while(0)
|
||||
|
||||
// Set OCRnQ register
|
||||
// Runtime (see set_pwm_duty):
|
||||
#define _SET_OCRnQ(OCRnQ, Q, V) do{ \
|
||||
(*(OCRnQ)[(Q)] = (0x0000) | (int(V) & 0xFFFF)); \
|
||||
}while(0)
|
||||
|
||||
// Set ICRn register (one per timer)
|
||||
// Runtime (see set_pwm_frequency)
|
||||
#define _SET_ICRn(ICRn, V) do{ \
|
||||
(*(ICRn) = (0x0000) | (int(V) & 0xFFFF)); \
|
||||
}while(0)
|
||||
|
||||
// Set Noise Canceler bit
|
||||
// Ex: SET_ICNC(2,1)
|
||||
@@ -278,8 +261,8 @@ enum ClockSource2 : char {
|
||||
* PWM availability macros
|
||||
*/
|
||||
|
||||
// Determine which harware PWMs are already in use
|
||||
#define _PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == E6_AUTO_FAN_PIN || P == E7_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN)
|
||||
// Determine which hardware PWMs are already in use
|
||||
#define _PWM_CHK_FAN_B(P) (P == E0_AUTO_FAN_PIN || P == E1_AUTO_FAN_PIN || P == E2_AUTO_FAN_PIN || P == E3_AUTO_FAN_PIN || P == E4_AUTO_FAN_PIN || P == E5_AUTO_FAN_PIN || P == E6_AUTO_FAN_PIN || P == E7_AUTO_FAN_PIN || P == CHAMBER_AUTO_FAN_PIN || P == COOLER_AUTO_FAN_PIN)
|
||||
#if PIN_EXISTS(CONTROLLER_FAN)
|
||||
#define PWM_CHK_FAN_B(P) (_PWM_CHK_FAN_B(P) || P == CONTROLLER_FAN_PIN)
|
||||
#else
|
||||
@@ -310,11 +293,11 @@ enum ClockSource2 : char {
|
||||
|
||||
#if HAS_MOTOR_CURRENT_PWM
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_Z || P == MOTOR_CURRENT_PWM_XY)
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_E0 || P == MOTOR_CURRENT_PWM_E1 || P == MOTOR_CURRENT_PWM_Z || P == MOTOR_CURRENT_PWM_XY)
|
||||
#elif PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_Z)
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_E0 || P == MOTOR_CURRENT_PWM_E1 || P == MOTOR_CURRENT_PWM_Z)
|
||||
#else
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E)
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) (P == MOTOR_CURRENT_PWM_E || P == MOTOR_CURRENT_PWM_E0 || P == MOTOR_CURRENT_PWM_E1)
|
||||
#endif
|
||||
#else
|
||||
#define PWM_CHK_MOTOR_CURRENT(P) false
|
||||
|
2
Marlin/src/HAL/AVR/fastio/fastio_1280.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/fastio/fastio_1280.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
2
Marlin/src/HAL/AVR/fastio/fastio_1281.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/fastio/fastio_1281.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
2
Marlin/src/HAL/AVR/fastio/fastio_168.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/fastio/fastio_168.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
2
Marlin/src/HAL/AVR/fastio/fastio_644.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/fastio/fastio_644.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
2
Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/fastio/fastio_AT90USB.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
6
Marlin/src/HAL/AVR/inc/Conditionals_LCD.h
Executable file → Normal file
6
Marlin/src/HAL/AVR/inc/Conditionals_LCD.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if HAS_SPI_TFT || HAS_FSMC_TFT
|
||||
#error "Sorry! TFT displays are not available for HAL/AVR."
|
||||
#endif
|
||||
|
2
Marlin/src/HAL/AVR/inc/Conditionals_adv.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/inc/Conditionals_adv.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
2
Marlin/src/HAL/AVR/inc/Conditionals_post.h
Executable file → Normal file
2
Marlin/src/HAL/AVR/inc/Conditionals_post.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
70
Marlin/src/HAL/AVR/inc/SanityCheck.h
Executable file → Normal file
70
Marlin/src/HAL/AVR/inc/SanityCheck.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -26,40 +26,86 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Digipot requirement
|
||||
* Check for common serial pin conflicts
|
||||
*/
|
||||
#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."
|
||||
#define CHECK_SERIAL_PIN(N) ( \
|
||||
X_STOP_PIN == N || Y_STOP_PIN == N || Z_STOP_PIN == N \
|
||||
|| X_MIN_PIN == N || Y_MIN_PIN == N || Z_MIN_PIN == N \
|
||||
|| X_MAX_PIN == N || Y_MAX_PIN == N || Z_MAX_PIN == N \
|
||||
|| X_STEP_PIN == N || Y_STEP_PIN == N || Z_STEP_PIN == N \
|
||||
|| X_DIR_PIN == N || Y_DIR_PIN == N || Z_DIR_PIN == N \
|
||||
|| X_ENA_PIN == N || Y_ENA_PIN == N || Z_ENA_PIN == N \
|
||||
|| BTN_EN1 == N || BTN_EN2 == N \
|
||||
)
|
||||
#if SERIAL_IN_USE(0)
|
||||
// D0-D1. No known conflicts.
|
||||
#endif
|
||||
#if SERIAL_IN_USE(1)
|
||||
#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__)
|
||||
#if CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19)
|
||||
#error "Serial Port 1 pin D18 and/or D19 conflicts with another pin on the board."
|
||||
#endif
|
||||
#else
|
||||
#if CHECK_SERIAL_PIN(10) || CHECK_SERIAL_PIN(11)
|
||||
#error "Serial Port 1 pin D10 and/or D11 conflicts with another pin on the board."
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#if SERIAL_IN_USE(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17))
|
||||
#error "Serial Port 2 pin D16 and/or D17 conflicts with another pin on the board."
|
||||
#endif
|
||||
#if SERIAL_IN_USE(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15))
|
||||
#error "Serial Port 3 pin D14 and/or D15 conflicts with another pin on the board."
|
||||
#endif
|
||||
#undef CHECK_SERIAL_PIN
|
||||
|
||||
/**
|
||||
* Checks for FAST PWM
|
||||
*/
|
||||
#if ENABLED(FAST_PWM_FAN) && (ENABLED(USE_OCR2A_AS_TOP) && defined(TCCR2))
|
||||
#error "USE_OCR2A_AS_TOP does not apply to devices with a single output TIMER2"
|
||||
#if ALL(FAST_PWM_FAN, USE_OCR2A_AS_TOP, HAS_TCCR2)
|
||||
#error "USE_OCR2A_AS_TOP does not apply to devices with a single output TIMER2."
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Checks for SOFT PWM
|
||||
*/
|
||||
#if HAS_FAN0 && FAN_PIN == 9 && DISABLED(FAN_SOFT_PWM) && ENABLED(SPEAKER)
|
||||
#error "FAN_PIN 9 Hardware PWM uses Timer 2 which conflicts with Arduino AVR Tone Timer (for SPEAKER)."
|
||||
#error "Disable SPEAKER or enable FAN_SOFT_PWM."
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sanity checks for Spindle / Laser PWM
|
||||
*/
|
||||
#if ENABLED(SPINDLE_LASER_PWM)
|
||||
#if ENABLED(SPINDLE_LASER_USE_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 SPINDLE_LASER_FREQUENCY
|
||||
#error "SPINDLE_LASER_FREQUENCY requires SPINDLE_LASER_USE_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
|
||||
|
||||
/**
|
||||
* Postmortem debugging
|
||||
*/
|
||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||
#error "POSTMORTEM_DEBUGGING is not supported on AVR boards."
|
||||
#endif
|
||||
|
||||
#if USING_PULLDOWNS
|
||||
#error "PULLDOWN pin mode is not available on AVR boards."
|
||||
#endif
|
||||
|
6
Marlin/src/HAL/AVR/math.h
Executable file → Normal file
6
Marlin/src/HAL/AVR/math.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -35,7 +35,7 @@
|
||||
// C B A is longIn1
|
||||
// D C B A is longIn2
|
||||
//
|
||||
static FORCE_INLINE uint16_t MultiU24X32toH16(uint32_t longIn1, uint32_t longIn2) {
|
||||
FORCE_INLINE static uint16_t MultiU24X32toH16(uint32_t longIn1, uint32_t longIn2) {
|
||||
uint8_t tmp1;
|
||||
uint8_t tmp2;
|
||||
uint16_t intRes;
|
||||
@@ -89,7 +89,7 @@ static FORCE_INLINE uint16_t MultiU24X32toH16(uint32_t longIn1, uint32_t longIn2
|
||||
// uses:
|
||||
// r26 to store 0
|
||||
// r27 to store the byte 1 of the 24 bit result
|
||||
static FORCE_INLINE uint16_t MultiU16X8toH16(uint8_t charIn1, uint16_t intIn2) {
|
||||
FORCE_INLINE static uint16_t MultiU16X8toH16(uint8_t charIn1, uint16_t intIn2) {
|
||||
uint8_t tmp;
|
||||
uint16_t intRes;
|
||||
__asm__ __volatile__ (
|
||||
|
85
Marlin/src/HAL/AVR/pinsDebug.h
Executable file → Normal file
85
Marlin/src/HAL/AVR/pinsDebug.h
Executable file → Normal file
@@ -2,6 +2,9 @@
|
||||
* 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
|
||||
@@ -13,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -26,7 +29,9 @@
|
||||
|
||||
#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
|
||||
|
||||
#define AVR_ATmega2560_FAMILY_PLUS_70 MB(BQ_ZUM_MEGA_3D, MIGHTYBOARD_REVE, MINIRAMBO, SCOOVO_X9H)
|
||||
#if MB(BQ_ZUM_MEGA_3D, MIGHTYBOARD_REVE, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14)
|
||||
#define AVR_ATmega2560_FAMILY_PLUS_70 1
|
||||
#endif
|
||||
|
||||
#if AVR_AT90USB1286_FAMILY
|
||||
|
||||
@@ -36,7 +41,7 @@
|
||||
// portModeRegister takes a different argument
|
||||
#define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
|
||||
#define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
|
||||
#define digitalPinToPort_DEBUG(p) digitalPinToPort_Teensy(p)
|
||||
#define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
|
||||
#define GET_PINMODE(pin) (*portModeRegister(pin) & digitalPinToBitMask_DEBUG(pin))
|
||||
|
||||
#elif AVR_ATmega2560_FAMILY_PLUS_70 // So we can access/display all the pins on boards using more than 70
|
||||
@@ -69,7 +74,7 @@
|
||||
#define MULTI_NAME_PAD 26 // space needed to be pretty if not first name assigned to a pin
|
||||
|
||||
void PRINT_ARRAY_NAME(uint8_t x) {
|
||||
char *name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
|
||||
PGM_P const name_mem_pointer = (PGM_P)pgm_read_ptr(&pin_array[x].name);
|
||||
LOOP_L_N(y, MAX_NAME_LENGTH) {
|
||||
char temp_char = pgm_read_byte(name_mem_pointer + y);
|
||||
if (temp_char != 0)
|
||||
@@ -97,7 +102,7 @@ void PRINT_ARRAY_NAME(uint8_t x) {
|
||||
return true; \
|
||||
} else return false
|
||||
|
||||
|
||||
#define ABTEST(N) defined(TCCR##N##A) && defined(COM##N##A1)
|
||||
|
||||
/**
|
||||
* Print a pin's PWM status.
|
||||
@@ -108,7 +113,7 @@ static bool pwm_status(uint8_t pin) {
|
||||
|
||||
switch (digitalPinToTimer_DEBUG(pin)) {
|
||||
|
||||
#if defined(TCCR0A) && defined(COM0A1)
|
||||
#if ABTEST(0)
|
||||
#ifdef TIMER0A
|
||||
#if !AVR_AT90USB1286_FAMILY // not available in Teensyduino type IDEs
|
||||
PWM_CASE(0, A);
|
||||
@@ -117,20 +122,20 @@ static bool pwm_status(uint8_t pin) {
|
||||
PWM_CASE(0, B);
|
||||
#endif
|
||||
|
||||
#if defined(TCCR1A) && defined(COM1A1)
|
||||
#if ABTEST(1)
|
||||
PWM_CASE(1, A);
|
||||
PWM_CASE(1, B);
|
||||
#if defined(COM1C1) && defined(TIMER1C)
|
||||
PWM_CASE(1, C);
|
||||
#endif
|
||||
#if defined(COM1C1) && defined(TIMER1C)
|
||||
PWM_CASE(1, C);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(TCCR2A) && defined(COM2A1)
|
||||
#if ABTEST(2)
|
||||
PWM_CASE(2, A);
|
||||
PWM_CASE(2, B);
|
||||
#endif
|
||||
|
||||
#if defined(TCCR3A) && defined(COM3A1)
|
||||
#if ABTEST(3)
|
||||
PWM_CASE(3, A);
|
||||
PWM_CASE(3, B);
|
||||
#ifdef COM3C1
|
||||
@@ -144,7 +149,7 @@ static bool pwm_status(uint8_t pin) {
|
||||
PWM_CASE(4, C);
|
||||
#endif
|
||||
|
||||
#if defined(TCCR5A) && defined(COM5A1)
|
||||
#if ABTEST(5)
|
||||
PWM_CASE(5, A);
|
||||
PWM_CASE(5, B);
|
||||
PWM_CASE(5, C);
|
||||
@@ -161,16 +166,16 @@ static bool pwm_status(uint8_t pin) {
|
||||
const volatile uint8_t* const PWM_other[][3] PROGMEM = {
|
||||
{ &TCCR0A, &TCCR0B, &TIMSK0 },
|
||||
{ &TCCR1A, &TCCR1B, &TIMSK1 },
|
||||
#if defined(TCCR2A) && defined(COM2A1)
|
||||
#if ABTEST(2)
|
||||
{ &TCCR2A, &TCCR2B, &TIMSK2 },
|
||||
#endif
|
||||
#if defined(TCCR3A) && defined(COM3A1)
|
||||
#if ABTEST(3)
|
||||
{ &TCCR3A, &TCCR3B, &TIMSK3 },
|
||||
#endif
|
||||
#ifdef TCCR4A
|
||||
{ &TCCR4A, &TCCR4B, &TIMSK4 },
|
||||
#endif
|
||||
#if defined(TCCR5A) && defined(COM5A1)
|
||||
#if ABTEST(5)
|
||||
{ &TCCR5A, &TCCR5B, &TIMSK5 },
|
||||
#endif
|
||||
};
|
||||
@@ -190,11 +195,11 @@ const volatile uint8_t* const PWM_OCR[][3] PROGMEM = {
|
||||
{ (const uint8_t*)&OCR1A, (const uint8_t*)&OCR1B, 0 },
|
||||
#endif
|
||||
|
||||
#if defined(TCCR2A) && defined(COM2A1)
|
||||
#if ABTEST(2)
|
||||
{ &OCR2A, &OCR2B, 0 },
|
||||
#endif
|
||||
|
||||
#if defined(TCCR3A) && defined(COM3A1)
|
||||
#if ABTEST(3)
|
||||
#ifdef COM3C1
|
||||
{ (const uint8_t*)&OCR3A, (const uint8_t*)&OCR3B, (const uint8_t*)&OCR3C },
|
||||
#else
|
||||
@@ -206,7 +211,7 @@ const volatile uint8_t* const PWM_OCR[][3] PROGMEM = {
|
||||
{ (const uint8_t*)&OCR4A, (const uint8_t*)&OCR4B, (const uint8_t*)&OCR4C },
|
||||
#endif
|
||||
|
||||
#if defined(TCCR5A) && defined(COM5A1)
|
||||
#if ABTEST(5)
|
||||
{ (const uint8_t*)&OCR5A, (const uint8_t*)&OCR5B, (const uint8_t*)&OCR5C },
|
||||
#endif
|
||||
};
|
||||
@@ -233,9 +238,9 @@ static void print_is_also_tied() { SERIAL_ECHOPGM(" is also tied to this pin");
|
||||
|
||||
inline void com_print(const uint8_t N, const uint8_t Z) {
|
||||
const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
|
||||
SERIAL_ECHOPGM(" COM");
|
||||
SERIAL_CHAR('0' + N, Z);
|
||||
SERIAL_ECHOPAIR(": ", int((*TCCRA >> (6 - Z * 2)) & 0x03));
|
||||
SERIAL_ECHOPGM(" COM", AS_DIGIT(N));
|
||||
SERIAL_CHAR(Z);
|
||||
SERIAL_ECHOPGM(": ", int((*TCCRA >> (6 - Z * 2)) & 0x03));
|
||||
}
|
||||
|
||||
void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N - WGM bit layout
|
||||
@@ -245,8 +250,8 @@ void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N -
|
||||
uint8_t WGM = (((*TCCRB & _BV(WGM_2)) >> 1) | (*TCCRA & (_BV(WGM_0) | _BV(WGM_1))));
|
||||
if (N == 4) WGM |= ((*TCCRB & _BV(WGM_3)) >> 1);
|
||||
|
||||
SERIAL_ECHOPGM(" TIMER");
|
||||
SERIAL_CHAR(T + '0', L);
|
||||
SERIAL_ECHOPGM(" TIMER", AS_DIGIT(T));
|
||||
SERIAL_CHAR(L);
|
||||
SERIAL_ECHO_SP(3);
|
||||
|
||||
if (N == 3) {
|
||||
@@ -257,22 +262,14 @@ void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N -
|
||||
const uint16_t *OCRVAL16 = (uint16_t*)OCR_VAL(T, L - 'A');
|
||||
PWM_PRINT(*OCRVAL16);
|
||||
}
|
||||
SERIAL_ECHOPAIR(" WGM: ", WGM);
|
||||
SERIAL_ECHOPGM(" WGM: ", WGM);
|
||||
com_print(T,L);
|
||||
SERIAL_ECHOPAIR(" CS: ", (*TCCRB & (_BV(CS_0) | _BV(CS_1) | _BV(CS_2)) ));
|
||||
|
||||
SERIAL_ECHOPGM(" TCCR");
|
||||
SERIAL_CHAR(T + '0');
|
||||
SERIAL_ECHOPAIR("A: ", *TCCRA);
|
||||
|
||||
SERIAL_ECHOPGM(" TCCR");
|
||||
SERIAL_CHAR(T + '0');
|
||||
SERIAL_ECHOPAIR("B: ", *TCCRB);
|
||||
SERIAL_ECHOPGM(" CS: ", (*TCCRB & (_BV(CS_0) | _BV(CS_1) | _BV(CS_2)) ));
|
||||
SERIAL_ECHOPGM(" TCCR", AS_DIGIT(T), "A: ", *TCCRA);
|
||||
SERIAL_ECHOPGM(" TCCR", AS_DIGIT(T), "B: ", *TCCRB);
|
||||
|
||||
const uint8_t *TMSK = (uint8_t*)TIMSK(T);
|
||||
SERIAL_ECHOPGM(" TIMSK");
|
||||
SERIAL_CHAR(T + '0');
|
||||
SERIAL_ECHOPAIR(": ", *TMSK);
|
||||
SERIAL_ECHOPGM(" TIMSK", AS_DIGIT(T), ": ", *TMSK);
|
||||
|
||||
const uint8_t OCIE = L - 'A' + 1;
|
||||
if (N == 3) { if (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6) err_is_counter(); }
|
||||
@@ -284,7 +281,7 @@ void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N -
|
||||
static void pwm_details(uint8_t pin) {
|
||||
switch (digitalPinToTimer_DEBUG(pin)) {
|
||||
|
||||
#if defined(TCCR0A) && defined(COM0A1)
|
||||
#if ABTEST(0)
|
||||
#ifdef TIMER0A
|
||||
#if !AVR_AT90USB1286_FAMILY // not available in Teensyduino type IDEs
|
||||
case TIMER0A: timer_prefix(0, 'A', 3); break;
|
||||
@@ -293,7 +290,7 @@ static void pwm_details(uint8_t pin) {
|
||||
case TIMER0B: timer_prefix(0, 'B', 3); break;
|
||||
#endif
|
||||
|
||||
#if defined(TCCR1A) && defined(COM1A1)
|
||||
#if ABTEST(1)
|
||||
case TIMER1A: timer_prefix(1, 'A', 4); break;
|
||||
case TIMER1B: timer_prefix(1, 'B', 4); break;
|
||||
#if defined(COM1C1) && defined(TIMER1C)
|
||||
@@ -301,12 +298,12 @@ static void pwm_details(uint8_t pin) {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(TCCR2A) && defined(COM2A1)
|
||||
#if ABTEST(2)
|
||||
case TIMER2A: timer_prefix(2, 'A', 3); break;
|
||||
case TIMER2B: timer_prefix(2, 'B', 3); break;
|
||||
#endif
|
||||
|
||||
#if defined(TCCR3A) && defined(COM3A1)
|
||||
#if ABTEST(3)
|
||||
case TIMER3A: timer_prefix(3, 'A', 4); break;
|
||||
case TIMER3B: timer_prefix(3, 'B', 4); break;
|
||||
#ifdef COM3C1
|
||||
@@ -320,7 +317,7 @@ static void pwm_details(uint8_t pin) {
|
||||
case TIMER4C: timer_prefix(4, 'C', 4); break;
|
||||
#endif
|
||||
|
||||
#if defined(TCCR5A) && defined(COM5A1)
|
||||
#if ABTEST(5)
|
||||
case TIMER5A: timer_prefix(5, 'A', 4); break;
|
||||
case TIMER5B: timer_prefix(5, 'B', 4); break;
|
||||
case TIMER5C: timer_prefix(5, 'C', 4); break;
|
||||
@@ -354,7 +351,6 @@ static void pwm_details(uint8_t pin) {
|
||||
#endif
|
||||
} // pwm_details
|
||||
|
||||
|
||||
#ifndef digitalRead_mod // Use Teensyduino's version of digitalRead - it doesn't disable the PWMs
|
||||
int digitalRead_mod(const int8_t pin) { // same as digitalRead except the PWM stop section has been removed
|
||||
const uint8_t port = digitalPinToPort_DEBUG(pin);
|
||||
@@ -399,3 +395,6 @@ static void pwm_details(uint8_t pin) {
|
||||
#endif
|
||||
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%3d "), p); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
|
||||
|
||||
#undef ABTEST
|
||||
|
5
Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h
Executable file → Normal file
5
Marlin/src/HAL/AVR/pinsDebug_Teensyduino.h
Executable file → Normal file
@@ -2,6 +2,9 @@
|
||||
* 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
|
||||
@@ -13,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
14
Marlin/src/HAL/AVR/pinsDebug_plus_70.h
Executable file → Normal file
14
Marlin/src/HAL/AVR/pinsDebug_plus_70.h
Executable file → Normal file
@@ -2,6 +2,9 @@
|
||||
* 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
|
||||
@@ -13,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -22,15 +25,12 @@
|
||||
* Structures for 2560 family boards that use more than 70 pins
|
||||
*/
|
||||
|
||||
#undef NUM_DIGITAL_PINS
|
||||
#if MB(BQ_ZUM_MEGA_3D)
|
||||
#if MB(BQ_ZUM_MEGA_3D, MINIRAMBO, SCOOVO_X9H, TRIGORILLA_14)
|
||||
#undef NUM_DIGITAL_PINS
|
||||
#define NUM_DIGITAL_PINS 85
|
||||
#elif MB(MIGHTYBOARD_REVE)
|
||||
#undef NUM_DIGITAL_PINS
|
||||
#define NUM_DIGITAL_PINS 80
|
||||
#elif MB(MINIRAMBO)
|
||||
#define NUM_DIGITAL_PINS 85
|
||||
#elif MB(SCOOVO_X9H)
|
||||
#define NUM_DIGITAL_PINS 85
|
||||
#endif
|
||||
|
||||
#define PA 1
|
||||
|
18
Marlin/src/HAL/AVR/spi_pins.h
Executable file → Normal file
18
Marlin/src/HAL/AVR/spi_pins.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -51,15 +51,15 @@
|
||||
#define AVR_SS_PIN 16
|
||||
#endif
|
||||
|
||||
#ifndef SCK_PIN
|
||||
#define SCK_PIN AVR_SCK_PIN
|
||||
#ifndef SD_SCK_PIN
|
||||
#define SD_SCK_PIN AVR_SCK_PIN
|
||||
#endif
|
||||
#ifndef MISO_PIN
|
||||
#define MISO_PIN AVR_MISO_PIN
|
||||
#ifndef SD_MISO_PIN
|
||||
#define SD_MISO_PIN AVR_MISO_PIN
|
||||
#endif
|
||||
#ifndef MOSI_PIN
|
||||
#define MOSI_PIN AVR_MOSI_PIN
|
||||
#ifndef SD_MOSI_PIN
|
||||
#define SD_MOSI_PIN AVR_MOSI_PIN
|
||||
#endif
|
||||
#ifndef SS_PIN
|
||||
#define SS_PIN AVR_SS_PIN
|
||||
#ifndef SD_SS_PIN
|
||||
#define SD_SS_PIN AVR_SS_PIN
|
||||
#endif
|
||||
|
260
Marlin/src/HAL/AVR/timers.h
Normal file
260
Marlin/src/HAL/AVR/timers.h
Normal file
@@ -0,0 +1,260 @@
|
||||
/**
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// ------------------------
|
||||
// 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 MF_TIMER_STEP
|
||||
#define MF_TIMER_STEP 1
|
||||
#endif
|
||||
#ifndef MF_TIMER_PULSE
|
||||
#define MF_TIMER_PULSE MF_TIMER_STEP
|
||||
#endif
|
||||
#ifndef MF_TIMER_TEMP
|
||||
#define MF_TIMER_TEMP 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, OCIE0A)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0A)
|
||||
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0A)
|
||||
|
||||
FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
|
||||
switch (timer_num) {
|
||||
case MF_TIMER_STEP:
|
||||
// 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 MF_TIMER_TEMP:
|
||||
// Use timer0 for temperature measurement
|
||||
// Interleave temperature interrupt with millies interrupt
|
||||
OCR0A = 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(T) NOOP
|
||||
#define HAL_timer_isr_epilogue(T) NOOP
|
||||
|
||||
#ifndef HAL_STEP_TIMER_ISR
|
||||
|
||||
/* 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<<OCIE0A)),\
|
||||
[msk1] "M" ((uint8_t)(1<<OCIE1A)) \
|
||||
: \
|
||||
); \
|
||||
} \
|
||||
void TIMER1_COMPA_vect_bottom()
|
||||
|
||||
#endif // HAL_STEP_TIMER_ISR
|
||||
|
||||
#ifndef HAL_TEMP_TIMER_ISR
|
||||
|
||||
/* 14 cycles maximum latency */
|
||||
#define HAL_TEMP_TIMER_ISR() \
|
||||
extern "C" void TIMER0_COMPA_vect() __attribute__ ((signal, naked, used, externally_visible)); \
|
||||
extern "C" void TIMER0_COMPA_vect_bottom() asm ("TIMER0_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
|
||||
void TIMER0_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("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
|
||||
A("sts %[timsk0], r16") /* 2 And set the new value */ \
|
||||
A("sei") /* 1 Enable global interrupts - It is safe, as the temperature ISR is disabled, so we cannot reenter it */ \
|
||||
A("push r16") /* 2 Save TIMSK0 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 TIMER0_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 TIMSK0 value but with temperature ISR disabled */ \
|
||||
A("ori r16,%[msk0]") /* 1 Enable temperature ISR */ \
|
||||
A("cli") /* 1 Disable global interrupts - We must do this, as we will reenable the temperature ISR, and we don't want to reenter this handler until the current one is done */ \
|
||||
A("sts %[timsk0], r16") /* 2 And restore the old value */ \
|
||||
A("pop r16") /* 2 Get the old SREG */ \
|
||||
A("out __SREG__, r16") /* 1 And restore the SREG value */ \
|
||||
A("pop r16") /* 2 Restore R16 */ \
|
||||
A("reti") /* 4 Return from interrupt */ \
|
||||
: \
|
||||
: [timsk0] "i"((uint16_t)&TIMSK0), \
|
||||
[msk0] "M" ((uint8_t)(1<<OCIE0A)) \
|
||||
: \
|
||||
); \
|
||||
} \
|
||||
void TIMER0_COMPA_vect_bottom()
|
||||
|
||||
#endif // HAL_TEMP_TIMER_ISR
|
12
Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp
Executable file → Normal file
12
Marlin/src/HAL/AVR/u8g_com_HAL_AVR_sw_spi.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -57,15 +57,15 @@
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
#if HAS_MARLINUI_U8GLIB
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
uint8_t u8g_bitData, u8g_bitNotData, u8g_bitClock, u8g_bitNotClock;
|
||||
volatile uint8_t *u8g_outData, *u8g_outClock;
|
||||
static uint8_t u8g_bitData, u8g_bitNotData, u8g_bitClock, u8g_bitNotClock;
|
||||
static volatile uint8_t *u8g_outData, *u8g_outClock;
|
||||
|
||||
static void u8g_com_arduino_init_shift_out(uint8_t dataPin, uint8_t clockPin) {
|
||||
u8g_outData = portOutputRegister(digitalPinToPort(dataPin));
|
||||
@@ -189,5 +189,5 @@ uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD
|
||||
#endif // HAS_MARLINUI_U8GLIB
|
||||
#endif // ARDUINO_ARCH_SAM
|
||||
|
@@ -1,71 +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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __AVR__
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
|
||||
#include "watchdog.h"
|
||||
|
||||
#include "../../MarlinCore.h"
|
||||
|
||||
// Initialize watchdog with 8s timeout, if possible. Otherwise, make it 4s.
|
||||
void watchdog_init() {
|
||||
#if ENABLED(WATCHDOG_DURATION_8S) && defined(WDTO_8S)
|
||||
#define WDTO_NS WDTO_8S
|
||||
#else
|
||||
#define WDTO_NS WDTO_4S
|
||||
#endif
|
||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||
// Enable the watchdog timer, but only for the interrupt.
|
||||
// Take care, as this requires the correct order of operation, with interrupts disabled.
|
||||
// See the datasheet of any AVR chip for details.
|
||||
wdt_reset();
|
||||
cli();
|
||||
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
|
||||
_WD_CONTROL_REG = _BV(WDIE) | (WDTO_NS & 0x07) | ((WDTO_NS & 0x08) << 2); // WDTO_NS directly does not work. bit 0-2 are consecutive in the register but the highest value bit is at bit 5
|
||||
// So worked for up to WDTO_2S
|
||||
sei();
|
||||
wdt_reset();
|
||||
#else
|
||||
wdt_enable(WDTO_NS); // The function handles the upper bit correct.
|
||||
#endif
|
||||
//delay(10000); // test it!
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//=================================== ISR ===================================
|
||||
//===========================================================================
|
||||
|
||||
// Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
|
||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||
ISR(WDT_vect) {
|
||||
sei(); // With the interrupt driven serial we need to allow interrupts.
|
||||
SERIAL_ERROR_MSG(STR_WATCHDOG_FIRED);
|
||||
minkill(); // interrupt-safe final kill and infinite loop
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // USE_WATCHDOG
|
||||
#endif // __AVR__
|
@@ -1,31 +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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <avr/wdt.h>
|
||||
|
||||
// Initialize watchdog with a 4 second interrupt time
|
||||
void watchdog_init();
|
||||
|
||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||
// first watchdog_init or AVR will go into emergency procedures.
|
||||
inline void HAL_watchdog_refresh() { wdt_reset(); }
|
@@ -1,343 +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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../core/macros.h"
|
||||
#include "../../core/serial.h"
|
||||
|
||||
#include "../shared/backtrace/unwinder.h"
|
||||
#include "../shared/backtrace/unwmemaccess.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
// Debug monitor that dumps to the Programming port all status when
|
||||
// an exception or WDT timeout happens - And then resets the board
|
||||
|
||||
// All the Monitor routines must run with interrupts disabled and
|
||||
// under an ISR execution context. That is why we cannot reuse the
|
||||
// Serial interrupt routines or any C runtime, as we don't know the
|
||||
// state we are when running them
|
||||
|
||||
// A SW memory barrier, to ensure GCC does not overoptimize loops
|
||||
#define sw_barrier() __asm__ volatile("": : :"memory");
|
||||
|
||||
// (re)initialize UART0 as a monitor output to 250000,n,8,1
|
||||
static void TXBegin() {
|
||||
|
||||
// Disable UART interrupt in NVIC
|
||||
NVIC_DisableIRQ( UART_IRQn );
|
||||
|
||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
||||
__DSB();
|
||||
__ISB();
|
||||
|
||||
// Disable clock
|
||||
pmc_disable_periph_clk( ID_UART );
|
||||
|
||||
// Configure PMC
|
||||
pmc_enable_periph_clk( ID_UART );
|
||||
|
||||
// Disable PDC channel
|
||||
UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
||||
|
||||
// Reset and disable receiver and transmitter
|
||||
UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;
|
||||
|
||||
// Configure mode: 8bit, No parity, 1 bit stop
|
||||
UART->UART_MR = UART_MR_CHMODE_NORMAL | US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO;
|
||||
|
||||
// Configure baudrate (asynchronous, no oversampling) to BAUDRATE bauds
|
||||
UART->UART_BRGR = (SystemCoreClock / (BAUDRATE << 4));
|
||||
|
||||
// Enable receiver and transmitter
|
||||
UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
||||
}
|
||||
|
||||
// Send character through UART with no interrupts
|
||||
static void TX(char c) {
|
||||
while (!(UART->UART_SR & UART_SR_TXRDY)) { WDT_Restart(WDT); sw_barrier(); };
|
||||
UART->UART_THR = c;
|
||||
}
|
||||
|
||||
// Send String through UART
|
||||
static void TX(const char* s) {
|
||||
while (*s) TX(*s++);
|
||||
}
|
||||
|
||||
static void TXDigit(uint32_t d) {
|
||||
if (d < 10) TX((char)(d+'0'));
|
||||
else if (d < 16) TX((char)(d+'A'-10));
|
||||
else TX('?');
|
||||
}
|
||||
|
||||
// Send Hex number thru UART
|
||||
static void TXHex(uint32_t v) {
|
||||
TX("0x");
|
||||
for (uint8_t i = 0; i < 8; i++, v <<= 4)
|
||||
TXDigit((v >> 28) & 0xF);
|
||||
}
|
||||
|
||||
// Send Decimal number thru UART
|
||||
static void TXDec(uint32_t v) {
|
||||
if (!v) {
|
||||
TX('0');
|
||||
return;
|
||||
}
|
||||
|
||||
char nbrs[14];
|
||||
char *p = &nbrs[0];
|
||||
while (v != 0) {
|
||||
*p++ = '0' + (v % 10);
|
||||
v /= 10;
|
||||
}
|
||||
do {
|
||||
p--;
|
||||
TX(*p);
|
||||
} while (p != &nbrs[0]);
|
||||
}
|
||||
|
||||
// Dump a backtrace entry
|
||||
static bool UnwReportOut(void* ctx, const UnwReport* bte) {
|
||||
int* p = (int*)ctx;
|
||||
|
||||
(*p)++;
|
||||
TX('#'); TXDec(*p); TX(" : ");
|
||||
TX(bte->name?bte->name:"unknown"); TX('@'); TXHex(bte->function);
|
||||
TX('+'); TXDec(bte->address - bte->function);
|
||||
TX(" PC:");TXHex(bte->address); TX('\n');
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef UNW_DEBUG
|
||||
void UnwPrintf(const char* format, ...) {
|
||||
char dest[256];
|
||||
va_list argptr;
|
||||
va_start(argptr, format);
|
||||
vsprintf(dest, format, argptr);
|
||||
va_end(argptr);
|
||||
TX(&dest[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Table of function pointers for passing to the unwinder */
|
||||
static const UnwindCallbacks UnwCallbacks = {
|
||||
UnwReportOut,
|
||||
UnwReadW,
|
||||
UnwReadH,
|
||||
UnwReadB
|
||||
#ifdef UNW_DEBUG
|
||||
, UnwPrintf
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* HardFaultHandler_C:
|
||||
* This is called from the HardFault_HandlerAsm with a pointer the Fault stack
|
||||
* as the parameter. We can then read the values from the stack and place them
|
||||
* into local variables for ease of reading.
|
||||
* We then read the various Fault Status and Address Registers to help decode
|
||||
* cause of the fault.
|
||||
* The function ends with a BKPT instruction to force control back into the debugger
|
||||
*/
|
||||
extern "C"
|
||||
void HardFault_HandlerC(unsigned long *sp, unsigned long lr, unsigned long cause) {
|
||||
|
||||
static const char* causestr[] = {
|
||||
"NMI","Hard","Mem","Bus","Usage","Debug","WDT","RSTC"
|
||||
};
|
||||
|
||||
UnwindFrame btf;
|
||||
|
||||
// Dump report to the Programming port (interrupts are DISABLED)
|
||||
TXBegin();
|
||||
TX("\n\n## Software Fault detected ##\n");
|
||||
TX("Cause: "); TX(causestr[cause]); TX('\n');
|
||||
|
||||
TX("R0 : "); TXHex(((unsigned long)sp[0])); TX('\n');
|
||||
TX("R1 : "); TXHex(((unsigned long)sp[1])); TX('\n');
|
||||
TX("R2 : "); TXHex(((unsigned long)sp[2])); TX('\n');
|
||||
TX("R3 : "); TXHex(((unsigned long)sp[3])); TX('\n');
|
||||
TX("R12 : "); TXHex(((unsigned long)sp[4])); TX('\n');
|
||||
TX("LR : "); TXHex(((unsigned long)sp[5])); TX('\n');
|
||||
TX("PC : "); TXHex(((unsigned long)sp[6])); TX('\n');
|
||||
TX("PSR : "); TXHex(((unsigned long)sp[7])); TX('\n');
|
||||
|
||||
// Configurable Fault Status Register
|
||||
// Consists of MMSR, BFSR and UFSR
|
||||
TX("CFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED28)))); TX('\n');
|
||||
|
||||
// Hard Fault Status Register
|
||||
TX("HFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED2C)))); TX('\n');
|
||||
|
||||
// Debug Fault Status Register
|
||||
TX("DFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED30)))); TX('\n');
|
||||
|
||||
// Auxiliary Fault Status Register
|
||||
TX("AFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED3C)))); TX('\n');
|
||||
|
||||
// Read the Fault Address Registers. These may not contain valid values.
|
||||
// Check BFARVALID/MMARVALID to see if they are valid values
|
||||
// MemManage Fault Address Register
|
||||
TX("MMAR : "); TXHex((*((volatile unsigned long *)(0xE000ED34)))); TX('\n');
|
||||
|
||||
// Bus Fault Address Register
|
||||
TX("BFAR : "); TXHex((*((volatile unsigned long *)(0xE000ED38)))); TX('\n');
|
||||
|
||||
TX("ExcLR: "); TXHex(lr); TX('\n');
|
||||
TX("ExcSP: "); TXHex((unsigned long)sp); TX('\n');
|
||||
|
||||
btf.sp = ((unsigned long)sp) + 8*4; // The original stack pointer
|
||||
btf.fp = btf.sp;
|
||||
btf.lr = ((unsigned long)sp[5]);
|
||||
btf.pc = ((unsigned long)sp[6]) | 1; // Force Thumb, as CORTEX only support it
|
||||
|
||||
// Perform a backtrace
|
||||
TX("\nBacktrace:\n\n");
|
||||
int ctr = 0;
|
||||
UnwindStart(&btf, &UnwCallbacks, &ctr);
|
||||
|
||||
// Disable all NVIC interrupts
|
||||
NVIC->ICER[0] = 0xFFFFFFFF;
|
||||
NVIC->ICER[1] = 0xFFFFFFFF;
|
||||
|
||||
// Relocate VTOR table to default position
|
||||
SCB->VTOR = 0;
|
||||
|
||||
// Disable USB
|
||||
otg_disable();
|
||||
|
||||
// Restart watchdog
|
||||
WDT_Restart(WDT);
|
||||
|
||||
// Reset controller
|
||||
NVIC_SystemReset();
|
||||
for (;;) WDT_Restart(WDT);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void NMI_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#0")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void HardFault_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#1")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void MemManage_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#2")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void BusFault_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#3")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void UsageFault_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#4")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void DebugMon_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#5")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
/* This is NOT an exception, it is an interrupt handler - Nevertheless, the framing is the same */
|
||||
__attribute__((naked)) void WDT_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#6")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
__attribute__((naked)) void RSTC_Handler() {
|
||||
__asm__ __volatile__ (
|
||||
".syntax unified" "\n\t"
|
||||
A("tst lr, #4")
|
||||
A("ite eq")
|
||||
A("mrseq r0, msp")
|
||||
A("mrsne r0, psp")
|
||||
A("mov r1,lr")
|
||||
A("mov r2,#7")
|
||||
A("b HardFault_HandlerC")
|
||||
);
|
||||
}
|
||||
|
||||
#endif // ARDUINO_ARCH_SAM
|
File diff suppressed because it is too large
Load Diff
163
Marlin/src/HAL/DUE/HAL.cpp
Executable file → Normal file
163
Marlin/src/HAL/DUE/HAL.cpp
Executable file → Normal file
@@ -14,19 +14,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*
|
||||
* For ARDUINO_ARCH_SAM
|
||||
* HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
#include "../../MarlinCore.h"
|
||||
|
||||
#include <Wire.h>
|
||||
#include "usb/usb_task.h"
|
||||
@@ -35,36 +34,33 @@
|
||||
// Public Variables
|
||||
// ------------------------
|
||||
|
||||
uint16_t HAL_adc_result;
|
||||
uint16_t MarlinHAL::adc_result;
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
// ------------------------
|
||||
|
||||
// HAL initialization task
|
||||
void HAL_init() {
|
||||
// Initialize the USB stack
|
||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||
extern void install_min_serial();
|
||||
#endif
|
||||
|
||||
void MarlinHAL::init() {
|
||||
#if ENABLED(SDSUPPORT)
|
||||
OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up
|
||||
#endif
|
||||
usb_task_init();
|
||||
usb_task_init(); // Initialize the USB stack
|
||||
TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler
|
||||
}
|
||||
|
||||
// HAL idle task
|
||||
void HAL_idletask() {
|
||||
// Perform USB stack housekeeping
|
||||
usb_task_idle();
|
||||
void MarlinHAL::init_board() {
|
||||
#ifdef BOARD_INIT
|
||||
BOARD_INIT();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Disable interrupts
|
||||
void cli() { noInterrupts(); }
|
||||
void MarlinHAL::idletask() { usb_task_idle(); } // Perform USB stack housekeeping
|
||||
|
||||
// Enable interrupts
|
||||
void sei() { interrupts(); }
|
||||
|
||||
void HAL_clear_reset_source() { }
|
||||
|
||||
uint8_t HAL_get_reset_source() {
|
||||
uint8_t MarlinHAL::get_reset_source() {
|
||||
switch ((RSTC->RSTC_SR >> 8) & 0x07) {
|
||||
case 0: return RST_POWER_ON;
|
||||
case 1: return RST_BACKUP;
|
||||
@@ -75,11 +71,105 @@ uint8_t HAL_get_reset_source() {
|
||||
}
|
||||
}
|
||||
|
||||
void _delay_ms(const int delay_ms) {
|
||||
// Todo: port for Due?
|
||||
delay(delay_ms);
|
||||
void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
|
||||
|
||||
// ------------------------
|
||||
// Watchdog Timer
|
||||
// ------------------------
|
||||
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
|
||||
// Initialize watchdog - On SAM3X, Watchdog was already configured
|
||||
// and enabled or disabled at startup, so no need to reconfigure it
|
||||
// here.
|
||||
void MarlinHAL::watchdog_init() { WDT_Restart(WDT); } // Reset watchdog to start clean
|
||||
|
||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||
// first watchdog_init or AVR will go into emergency procedures.
|
||||
void MarlinHAL::watchdog_refresh() { watchdogReset(); }
|
||||
|
||||
#endif
|
||||
|
||||
// Override Arduino runtime to either config or disable the watchdog
|
||||
//
|
||||
// We need to configure the watchdog as soon as possible in the boot
|
||||
// process, because watchdog initialization at hardware reset on SAM3X8E
|
||||
// is unreliable, and there is risk of unintended resets if we delay
|
||||
// that initialization to a later time.
|
||||
void watchdogSetup() {
|
||||
|
||||
#if ENABLED(USE_WATCHDOG)
|
||||
|
||||
// 4 seconds timeout
|
||||
uint32_t timeout = TERN(WATCHDOG_DURATION_8S, 8000, 4000);
|
||||
|
||||
// Calculate timeout value in WDT counter ticks: This assumes
|
||||
// the slow clock is running at 32.768 kHz watchdog
|
||||
// frequency is therefore 32768 / 128 = 256 Hz
|
||||
timeout = (timeout << 8) / 1000;
|
||||
if (timeout == 0)
|
||||
timeout = 1;
|
||||
else if (timeout > 0xFFF)
|
||||
timeout = 0xFFF;
|
||||
|
||||
// We want to enable the watchdog with the specified timeout
|
||||
uint32_t value =
|
||||
WDT_MR_WDV(timeout) | // With the specified timeout
|
||||
WDT_MR_WDD(timeout) | // and no invalid write window
|
||||
#if !(SAMV70 || SAMV71 || SAME70 || SAMS70)
|
||||
WDT_MR_WDRPROC | // WDT fault resets processor only - We want
|
||||
// to keep PIO controller state
|
||||
#endif
|
||||
WDT_MR_WDDBGHLT | // WDT stops in debug state.
|
||||
WDT_MR_WDIDLEHLT; // WDT stops in idle state.
|
||||
|
||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||
// We enable the watchdog timer, but only for the interrupt.
|
||||
|
||||
// Configure WDT to only trigger an interrupt
|
||||
value |= WDT_MR_WDFIEN; // Enable WDT fault interrupt.
|
||||
|
||||
// Disable WDT interrupt (just in case, to avoid triggering it!)
|
||||
NVIC_DisableIRQ(WDT_IRQn);
|
||||
|
||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
||||
__DSB();
|
||||
__ISB();
|
||||
|
||||
// Initialize WDT with the given parameters
|
||||
WDT_Enable(WDT, value);
|
||||
|
||||
// Configure and enable WDT interrupt.
|
||||
NVIC_ClearPendingIRQ(WDT_IRQn);
|
||||
NVIC_SetPriority(WDT_IRQn, 0); // Use highest priority, so we detect all kinds of lockups
|
||||
NVIC_EnableIRQ(WDT_IRQn);
|
||||
|
||||
#else
|
||||
|
||||
// a WDT fault triggers a reset
|
||||
value |= WDT_MR_WDRSTEN;
|
||||
|
||||
// Initialize WDT with the given parameters
|
||||
WDT_Enable(WDT, value);
|
||||
|
||||
#endif
|
||||
|
||||
// Reset the watchdog
|
||||
WDT_Restart(WDT);
|
||||
|
||||
#else
|
||||
|
||||
// Make sure to completely disable the Watchdog
|
||||
WDT_Disable(WDT);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// Free Memory Accessor
|
||||
// ------------------------
|
||||
|
||||
extern "C" {
|
||||
extern unsigned int _ebss; // end of bss section
|
||||
}
|
||||
@@ -91,16 +181,21 @@ int freeMemory() {
|
||||
}
|
||||
|
||||
// ------------------------
|
||||
// ADC
|
||||
// Serial Ports
|
||||
// ------------------------
|
||||
|
||||
void HAL_adc_start_conversion(const uint8_t ch) {
|
||||
HAL_adc_result = analogRead(ch);
|
||||
}
|
||||
|
||||
uint16_t HAL_adc_get_result() {
|
||||
// nop
|
||||
return HAL_adc_result;
|
||||
}
|
||||
// Forward the default serial ports
|
||||
#if USING_HW_SERIAL0
|
||||
DefaultSerial1 MSerial0(false, Serial);
|
||||
#endif
|
||||
#if USING_HW_SERIAL1
|
||||
DefaultSerial2 MSerial1(false, Serial1);
|
||||
#endif
|
||||
#if USING_HW_SERIAL2
|
||||
DefaultSerial3 MSerial2(false, Serial2);
|
||||
#endif
|
||||
#if USING_HW_SERIAL3
|
||||
DefaultSerial4 MSerial3(false, Serial3);
|
||||
#endif
|
||||
|
||||
#endif // ARDUINO_ARCH_SAM
|
||||
|
252
Marlin/src/HAL/DUE/HAL.h
Executable file → Normal file
252
Marlin/src/HAL/DUE/HAL.h
Executable file → Normal file
@@ -16,151 +16,122 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Description: HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*
|
||||
* For ARDUINO_ARCH_SAM
|
||||
* HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*/
|
||||
|
||||
#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 <stdint.h>
|
||||
|
||||
// Define MYSERIAL0/1 before MarlinSerial includes!
|
||||
#include "../../core/serial_hook.h"
|
||||
|
||||
// ------------------------
|
||||
// Serial ports
|
||||
// ------------------------
|
||||
|
||||
typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
|
||||
typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
|
||||
typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
|
||||
typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
|
||||
extern DefaultSerial1 MSerial0;
|
||||
extern DefaultSerial2 MSerial1;
|
||||
extern DefaultSerial3 MSerial2;
|
||||
extern DefaultSerial4 MSerial3;
|
||||
|
||||
#define _MSERIAL(X) MSerial##X
|
||||
#define MSERIAL(X) _MSERIAL(X)
|
||||
|
||||
#if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
|
||||
#define MYSERIAL0 customizedSerial1
|
||||
#elif SERIAL_PORT == 0
|
||||
#define MYSERIAL0 Serial
|
||||
#elif SERIAL_PORT == 1
|
||||
#define MYSERIAL0 Serial1
|
||||
#elif SERIAL_PORT == 2
|
||||
#define MYSERIAL0 Serial2
|
||||
#elif SERIAL_PORT == 3
|
||||
#define MYSERIAL0 Serial3
|
||||
#define MYSERIAL1 customizedSerial1
|
||||
#elif WITHIN(SERIAL_PORT, 0, 3)
|
||||
#define MYSERIAL1 MSERIAL(SERIAL_PORT)
|
||||
#else
|
||||
#error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#error "The required SERIAL_PORT must be from 0 to 3, or -1 for USB Serial."
|
||||
#endif
|
||||
|
||||
#ifdef SERIAL_PORT_2
|
||||
#if SERIAL_PORT_2 == SERIAL_PORT
|
||||
#error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration."
|
||||
#elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
|
||||
#define MYSERIAL1 customizedSerial2
|
||||
#elif SERIAL_PORT_2 == 0
|
||||
#define MYSERIAL1 Serial
|
||||
#elif SERIAL_PORT_2 == 1
|
||||
#define MYSERIAL1 Serial1
|
||||
#elif SERIAL_PORT_2 == 2
|
||||
#define MYSERIAL1 Serial2
|
||||
#elif SERIAL_PORT_2 == 3
|
||||
#define MYSERIAL1 Serial3
|
||||
#if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
|
||||
#define MYSERIAL2 customizedSerial2
|
||||
#elif WITHIN(SERIAL_PORT_2, 0, 3)
|
||||
#define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
|
||||
#else
|
||||
#error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
|
||||
#error "SERIAL_PORT_2 must be from 0 to 3, or -1 for USB Serial."
|
||||
#endif
|
||||
#define NUM_SERIAL 2
|
||||
#else
|
||||
#define NUM_SERIAL 1
|
||||
#endif
|
||||
|
||||
#ifdef DGUS_SERIAL_PORT
|
||||
#if DGUS_SERIAL_PORT == SERIAL_PORT
|
||||
#error "DGUS_SERIAL_PORT must be different from SERIAL_PORT. Please update your configuration."
|
||||
#elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
|
||||
#error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
|
||||
#elif DGUS_SERIAL_PORT == -1
|
||||
#define DGUS_SERIAL internalDgusSerial
|
||||
#elif DGUS_SERIAL_PORT == 0
|
||||
#define DGUS_SERIAL Serial
|
||||
#elif DGUS_SERIAL_PORT == 1
|
||||
#define DGUS_SERIAL Serial1
|
||||
#elif DGUS_SERIAL_PORT == 2
|
||||
#define DGUS_SERIAL Serial2
|
||||
#elif DGUS_SERIAL_PORT == 3
|
||||
#define DGUS_SERIAL Serial3
|
||||
#ifdef SERIAL_PORT_3
|
||||
#if SERIAL_PORT_3 == -1 || ENABLED(EMERGENCY_PARSER)
|
||||
#define MYSERIAL3 customizedSerial3
|
||||
#elif WITHIN(SERIAL_PORT_3, 0, 3)
|
||||
#define MYSERIAL3 MSERIAL(SERIAL_PORT_3)
|
||||
#else
|
||||
#error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
|
||||
#error "SERIAL_PORT_3 must be from 0 to 3, or -1 for USB Serial."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MMU2_SERIAL_PORT
|
||||
#if WITHIN(MMU2_SERIAL_PORT, 0, 3)
|
||||
#define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
|
||||
#else
|
||||
#error "MMU2_SERIAL_PORT must be from 0 to 3."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LCD_SERIAL_PORT
|
||||
#if WITHIN(LCD_SERIAL_PORT, 0, 3)
|
||||
#define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
|
||||
#else
|
||||
#error "LCD_SERIAL_PORT must be from 0 to 3."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "MarlinSerial.h"
|
||||
#include "MarlinSerialUSB.h"
|
||||
|
||||
// On AVR this is in math.h?
|
||||
#define square(x) ((x)*(x))
|
||||
|
||||
#ifndef strncpy_P
|
||||
#define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
|
||||
#endif
|
||||
|
||||
// Fix bug in pgm_read_ptr
|
||||
#undef pgm_read_ptr
|
||||
#define pgm_read_ptr(addr) (*((void**)(addr)))
|
||||
#undef pgm_read_word
|
||||
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
|
||||
// ------------------------
|
||||
// Types
|
||||
// ------------------------
|
||||
|
||||
typedef int8_t pin_t;
|
||||
|
||||
#define SHARED_SERVOS HAS_SERVOS
|
||||
#define HAL_SERVO_LIB Servo
|
||||
#define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
|
||||
|
||||
class Servo;
|
||||
typedef Servo hal_servo_t;
|
||||
|
||||
//
|
||||
// Interrupts
|
||||
//
|
||||
#define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
|
||||
#define CRITICAL_SECTION_END() if (!primask) __enable_irq()
|
||||
#define ISRS_ENABLED() (!__get_PRIMASK())
|
||||
#define ENABLE_ISRS() __enable_irq()
|
||||
#define DISABLE_ISRS() __disable_irq()
|
||||
#define sei() interrupts()
|
||||
#define cli() noInterrupts()
|
||||
|
||||
void cli(); // Disable interrupts
|
||||
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);
|
||||
#define CRITICAL_SECTION_START() const bool _irqon = hal.isr_state(); hal.isr_off()
|
||||
#define CRITICAL_SECTION_END() if (_irqon) hal.isr_on()
|
||||
|
||||
//
|
||||
// ADC
|
||||
//
|
||||
extern uint16_t HAL_adc_result; // result of last ADC conversion
|
||||
#define HAL_ADC_VREF 3.3
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
|
||||
#ifndef analogInputToDigitalPin
|
||||
#define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
|
||||
#define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
|
||||
#endif
|
||||
|
||||
#define HAL_ANALOG_SELECT(ch)
|
||||
|
||||
inline void HAL_adc_init() {}//todo
|
||||
|
||||
#define HAL_START_ADC(ch) HAL_adc_start_conversion(ch)
|
||||
#define HAL_ADC_RESOLUTION 10
|
||||
#define HAL_READ_ADC() HAL_adc_result
|
||||
#define HAL_ADC_READY() true
|
||||
|
||||
void HAL_adc_start_conversion(const uint8_t ch);
|
||||
uint16_t HAL_adc_get_result();
|
||||
|
||||
//
|
||||
// Pin Map
|
||||
// Pin Mapping for M42, M43, M226
|
||||
//
|
||||
#define GET_PIN_MAP_PIN(index) index
|
||||
#define GET_PIN_MAP_INDEX(pin) pin
|
||||
@@ -169,23 +140,18 @@ uint16_t HAL_adc_get_result();
|
||||
//
|
||||
// Tone
|
||||
//
|
||||
void toneInit();
|
||||
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
|
||||
void noTone(const pin_t _pin);
|
||||
|
||||
// Enable hooks into idle and setup for HAL
|
||||
#define HAL_IDLETASK 1
|
||||
void HAL_idletask();
|
||||
void HAL_init();
|
||||
|
||||
//
|
||||
// Utility functions
|
||||
//
|
||||
void _delay_ms(const int delay);
|
||||
// ------------------------
|
||||
// Class Utilities
|
||||
// ------------------------
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
int freeMemory();
|
||||
#if GCC_VERSION <= 50000
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -195,3 +161,73 @@ char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Return free RAM between end of heap (or end bss) and whatever is current
|
||||
int freeMemory();
|
||||
|
||||
// ------------------------
|
||||
// MarlinHAL Class
|
||||
// ------------------------
|
||||
|
||||
class MarlinHAL {
|
||||
public:
|
||||
|
||||
// Earliest possible init, before setup()
|
||||
MarlinHAL() {}
|
||||
|
||||
// Watchdog
|
||||
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||
|
||||
static void init(); // Called early in setup()
|
||||
static void init_board(); // Called less early in setup()
|
||||
static void reboot(); // Restart the firmware
|
||||
|
||||
// Interrupts
|
||||
static bool isr_state() { return !__get_PRIMASK(); }
|
||||
static void isr_on() { __enable_irq(); }
|
||||
static void isr_off() { __disable_irq(); }
|
||||
|
||||
static void delay_ms(const int ms) { delay(ms); }
|
||||
|
||||
// Tasks, called from idle()
|
||||
static void idletask();
|
||||
|
||||
// Reset
|
||||
static uint8_t get_reset_source();
|
||||
static void clear_reset_source() {}
|
||||
|
||||
// Free SRAM
|
||||
static int freeMemory() { return ::freeMemory(); }
|
||||
|
||||
//
|
||||
// ADC Methods
|
||||
//
|
||||
|
||||
static uint16_t adc_result;
|
||||
|
||||
// Called by Temperature::init once at startup
|
||||
static void adc_init() {}
|
||||
|
||||
// Called by Temperature::init for each sensor at startup
|
||||
static void adc_enable(const uint8_t /*ch*/) {}
|
||||
|
||||
// Begin ADC sampling on the given channel. Called from Temperature::isr!
|
||||
static void adc_start(const uint8_t ch) { adc_result = analogRead(ch); }
|
||||
|
||||
// Is the ADC ready for reading?
|
||||
static bool adc_ready() { return true; }
|
||||
|
||||
// The current value of the ADC register
|
||||
static uint16_t adc_value() { return adc_result; }
|
||||
|
||||
/**
|
||||
* Set the PWM duty cycle for the pin to the given value.
|
||||
* No inverting the duty cycle in this HAL.
|
||||
* No changing the maximum size of the provided value to enable finer PWM duty control in this HAL.
|
||||
*/
|
||||
static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t=255, const bool=false) {
|
||||
analogWrite(pin, v);
|
||||
}
|
||||
|
||||
};
|
||||
|
153
Marlin/src/HAL/DUE/HAL_SPI.cpp
Executable file → Normal file
153
Marlin/src/HAL/DUE/HAL_SPI.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -30,9 +30,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*
|
||||
* For ARDUINO_ARCH_SAM
|
||||
* HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
@@ -56,8 +54,8 @@
|
||||
#pragma GCC optimize (3)
|
||||
|
||||
typedef uint8_t (*pfnSpiTransfer)(uint8_t b);
|
||||
typedef void (*pfnSpiRxBlock)(uint8_t* buf, uint32_t nbyte);
|
||||
typedef void (*pfnSpiTxBlock)(const uint8_t* buf, uint32_t nbyte);
|
||||
typedef void (*pfnSpiRxBlock)(uint8_t *buf, uint32_t nbyte);
|
||||
typedef void (*pfnSpiTxBlock)(const uint8_t *buf, uint32_t nbyte);
|
||||
|
||||
/* ---------------- Macros to be able to access definitions from asm */
|
||||
#define _PORT(IO) DIO ## IO ## _WPORT
|
||||
@@ -69,10 +67,10 @@
|
||||
|
||||
// run at ~8 .. ~10Mhz - Tx version (Rx data discarded)
|
||||
static uint8_t spiTransferTx0(uint8_t bout) { // using Mode 0
|
||||
uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(MOSI_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t MOSI_MASK = PIN_MASK(MOSI_PIN);
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SCK_PIN);
|
||||
uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(SD_MOSI_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t MOSI_MASK = PIN_MASK(SD_MOSI_PIN);
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SD_SCK_PIN);
|
||||
uint32_t idx = 0;
|
||||
|
||||
/* Negate bout, as the assembler requires a negated value */
|
||||
@@ -154,9 +152,9 @@
|
||||
static uint8_t spiTransferRx0(uint8_t) { // using Mode 0
|
||||
uint32_t bin = 0;
|
||||
uint32_t work = 0;
|
||||
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(MISO_PIN))+0x3C, PIN_SHIFT(MISO_PIN)); /* PDSR of port in bitband area */
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SCK_PIN);
|
||||
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(SD_MISO_PIN))+0x3C, PIN_SHIFT(SD_MISO_PIN)); /* PDSR of port in bitband area */
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SD_SCK_PIN);
|
||||
|
||||
/* The software SPI routine */
|
||||
__asm__ __volatile__(
|
||||
@@ -225,36 +223,36 @@
|
||||
static uint8_t spiTransfer1(uint8_t b) { // using Mode 0
|
||||
int bits = 8;
|
||||
do {
|
||||
WRITE(MOSI_PIN, b & 0x80);
|
||||
WRITE(SD_MOSI_PIN, b & 0x80);
|
||||
b <<= 1; // little setup time
|
||||
|
||||
WRITE(SCK_PIN, HIGH);
|
||||
WRITE(SD_SCK_PIN, HIGH);
|
||||
DELAY_NS(125); // 10 cycles @ 84mhz
|
||||
|
||||
b |= (READ(MISO_PIN) != 0);
|
||||
b |= (READ(SD_MISO_PIN) != 0);
|
||||
|
||||
WRITE(SCK_PIN, LOW);
|
||||
WRITE(SD_SCK_PIN, LOW);
|
||||
DELAY_NS(125); // 10 cycles @ 84mhz
|
||||
} while (--bits);
|
||||
return b;
|
||||
}
|
||||
|
||||
// all the others
|
||||
static uint32_t spiDelayCyclesX4 = (F_CPU) / 1000000; // 4µs => 125khz
|
||||
static uint16_t spiDelayNS = 4000; // 4000ns => 125khz
|
||||
|
||||
static uint8_t spiTransferX(uint8_t b) { // using Mode 0
|
||||
int bits = 8;
|
||||
do {
|
||||
WRITE(MOSI_PIN, b & 0x80);
|
||||
WRITE(SD_MOSI_PIN, b & 0x80);
|
||||
b <<= 1; // little setup time
|
||||
|
||||
WRITE(SCK_PIN, HIGH);
|
||||
__delay_4cycles(spiDelayCyclesX4);
|
||||
WRITE(SD_SCK_PIN, HIGH);
|
||||
DELAY_NS_VAR(spiDelayNS);
|
||||
|
||||
b |= (READ(MISO_PIN) != 0);
|
||||
b |= (READ(SD_MISO_PIN) != 0);
|
||||
|
||||
WRITE(SCK_PIN, LOW);
|
||||
__delay_4cycles(spiDelayCyclesX4);
|
||||
WRITE(SD_SCK_PIN, LOW);
|
||||
DELAY_NS_VAR(spiDelayNS);
|
||||
} while (--bits);
|
||||
return b;
|
||||
}
|
||||
@@ -270,11 +268,11 @@
|
||||
static pfnSpiTransfer spiTransferTx = (pfnSpiTransfer)spiTransferX;
|
||||
|
||||
// Block transfers run at ~8 .. ~10Mhz - Tx version (Rx data discarded)
|
||||
static void spiTxBlock0(const uint8_t* ptr, uint32_t todo) {
|
||||
uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(MOSI_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t MOSI_MASK = PIN_MASK(MOSI_PIN);
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SCK_PIN);
|
||||
static void spiTxBlock0(const uint8_t *ptr, uint32_t todo) {
|
||||
uint32_t MOSI_PORT_PLUS30 = ((uint32_t) PORT(SD_MOSI_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t MOSI_MASK = PIN_MASK(SD_MOSI_PIN);
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SD_SCK_PIN);
|
||||
uint32_t work = 0;
|
||||
uint32_t txval = 0;
|
||||
|
||||
@@ -349,12 +347,12 @@
|
||||
);
|
||||
}
|
||||
|
||||
static void spiRxBlock0(uint8_t* ptr, uint32_t todo) {
|
||||
static void spiRxBlock0(uint8_t *ptr, uint32_t todo) {
|
||||
uint32_t bin = 0;
|
||||
uint32_t work = 0;
|
||||
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(MISO_PIN))+0x3C, PIN_SHIFT(MISO_PIN)); /* PDSR of port in bitband area */
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SCK_PIN);
|
||||
uint32_t BITBAND_MISO_PORT = BITBAND_ADDRESS( ((uint32_t)PORT(SD_MISO_PIN))+0x3C, PIN_SHIFT(SD_MISO_PIN)); /* PDSR of port in bitband area */
|
||||
uint32_t SCK_PORT_PLUS30 = ((uint32_t) PORT(SD_SCK_PIN)) + 0x30; /* SODR of port */
|
||||
uint32_t SCK_MASK = PIN_MASK(SD_SCK_PIN);
|
||||
|
||||
/* The software SPI routine */
|
||||
__asm__ __volatile__(
|
||||
@@ -425,48 +423,48 @@
|
||||
);
|
||||
}
|
||||
|
||||
static void spiTxBlockX(const uint8_t* buf, uint32_t todo) {
|
||||
static void spiTxBlockX(const uint8_t *buf, uint32_t todo) {
|
||||
do {
|
||||
(void)spiTransferTx(*buf++);
|
||||
} while (--todo);
|
||||
}
|
||||
|
||||
static void spiRxBlockX(uint8_t* buf, uint32_t todo) {
|
||||
static void spiRxBlockX(uint8_t *buf, uint32_t todo) {
|
||||
do {
|
||||
*buf++ = spiTransferRx(0xFF);
|
||||
} while (--todo);
|
||||
}
|
||||
|
||||
// Pointers to generic functions for block tranfers
|
||||
// Pointers to generic functions for block transfers
|
||||
static pfnSpiTxBlock spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;
|
||||
static pfnSpiRxBlock spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
|
||||
|
||||
#if MB(ALLIGATOR)
|
||||
#define _SS_WRITE(S) WRITE(SS_PIN, S)
|
||||
#define _SS_WRITE(S) WRITE(SD_SS_PIN, S)
|
||||
#else
|
||||
#define _SS_WRITE(S) NOOP
|
||||
#endif
|
||||
|
||||
void spiBegin() {
|
||||
SET_OUTPUT(SS_PIN);
|
||||
SET_OUTPUT(SD_SS_PIN);
|
||||
_SS_WRITE(HIGH);
|
||||
SET_OUTPUT(SCK_PIN);
|
||||
SET_INPUT(MISO_PIN);
|
||||
SET_OUTPUT(MOSI_PIN);
|
||||
SET_OUTPUT(SD_SCK_PIN);
|
||||
SET_INPUT(SD_MISO_PIN);
|
||||
SET_OUTPUT(SD_MOSI_PIN);
|
||||
}
|
||||
|
||||
uint8_t spiRec() {
|
||||
_SS_WRITE(LOW);
|
||||
WRITE(MOSI_PIN, HIGH); // Output 1s 1
|
||||
WRITE(SD_MOSI_PIN, HIGH); // Output 1s 1
|
||||
uint8_t b = spiTransferRx(0xFF);
|
||||
_SS_WRITE(HIGH);
|
||||
return b;
|
||||
}
|
||||
|
||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||
void spiRead(uint8_t *buf, uint16_t nbyte) {
|
||||
if (nbyte) {
|
||||
_SS_WRITE(LOW);
|
||||
WRITE(MOSI_PIN, HIGH); // Output 1s 1
|
||||
WRITE(SD_MOSI_PIN, HIGH); // Output 1s 1
|
||||
spiRxBlock(buf, nbyte);
|
||||
_SS_WRITE(HIGH);
|
||||
}
|
||||
@@ -478,7 +476,7 @@
|
||||
_SS_WRITE(HIGH);
|
||||
}
|
||||
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
void spiSendBlock(uint8_t token, const uint8_t *buf) {
|
||||
_SS_WRITE(LOW);
|
||||
(void)spiTransferTx(token);
|
||||
spiTxBlock(buf, 512);
|
||||
@@ -510,7 +508,7 @@
|
||||
spiRxBlock = (pfnSpiRxBlock)spiRxBlockX;
|
||||
break;
|
||||
default:
|
||||
spiDelayCyclesX4 = ((F_CPU) / 1000000) >> (6 - spiRate);
|
||||
spiDelayNS = 4000 >> (6 - spiRate); // spiRate of 2 gives the maximum error with current CPU
|
||||
spiTransferTx = (pfnSpiTransfer)spiTransferX;
|
||||
spiTransferRx = (pfnSpiTransfer)spiTransferX;
|
||||
spiTxBlock = (pfnSpiTxBlock)spiTxBlockX;
|
||||
@@ -519,8 +517,8 @@
|
||||
}
|
||||
|
||||
_SS_WRITE(HIGH);
|
||||
WRITE(MOSI_PIN, HIGH);
|
||||
WRITE(SCK_PIN, LOW);
|
||||
WRITE(SD_MOSI_PIN, HIGH);
|
||||
WRITE(SD_SCK_PIN, LOW);
|
||||
}
|
||||
|
||||
/** Begin SPI transaction, set clock, bit order, data mode */
|
||||
@@ -575,38 +573,34 @@
|
||||
|
||||
// Configure SPI pins
|
||||
PIO_Configure(
|
||||
g_APinDescription[SCK_PIN].pPort,
|
||||
g_APinDescription[SCK_PIN].ulPinType,
|
||||
g_APinDescription[SCK_PIN].ulPin,
|
||||
g_APinDescription[SCK_PIN].ulPinConfiguration);
|
||||
g_APinDescription[SD_SCK_PIN].pPort,
|
||||
g_APinDescription[SD_SCK_PIN].ulPinType,
|
||||
g_APinDescription[SD_SCK_PIN].ulPin,
|
||||
g_APinDescription[SD_SCK_PIN].ulPinConfiguration);
|
||||
PIO_Configure(
|
||||
g_APinDescription[MOSI_PIN].pPort,
|
||||
g_APinDescription[MOSI_PIN].ulPinType,
|
||||
g_APinDescription[MOSI_PIN].ulPin,
|
||||
g_APinDescription[MOSI_PIN].ulPinConfiguration);
|
||||
g_APinDescription[SD_MOSI_PIN].pPort,
|
||||
g_APinDescription[SD_MOSI_PIN].ulPinType,
|
||||
g_APinDescription[SD_MOSI_PIN].ulPin,
|
||||
g_APinDescription[SD_MOSI_PIN].ulPinConfiguration);
|
||||
PIO_Configure(
|
||||
g_APinDescription[MISO_PIN].pPort,
|
||||
g_APinDescription[MISO_PIN].ulPinType,
|
||||
g_APinDescription[MISO_PIN].ulPin,
|
||||
g_APinDescription[MISO_PIN].ulPinConfiguration);
|
||||
g_APinDescription[SD_MISO_PIN].pPort,
|
||||
g_APinDescription[SD_MISO_PIN].ulPinType,
|
||||
g_APinDescription[SD_MISO_PIN].ulPin,
|
||||
g_APinDescription[SD_MISO_PIN].ulPinConfiguration);
|
||||
|
||||
// set master mode, peripheral select, fault detection
|
||||
SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_MR_PS);
|
||||
SPI_Enable(SPI0);
|
||||
|
||||
SET_OUTPUT(DAC0_SYNC);
|
||||
#if EXTRUDERS > 1
|
||||
SET_OUTPUT(DAC1_SYNC);
|
||||
WRITE(DAC1_SYNC, HIGH);
|
||||
SET_OUTPUT(DAC0_SYNC_PIN);
|
||||
#if HAS_MULTI_EXTRUDER
|
||||
OUT_WRITE(DAC1_SYNC_PIN, HIGH);
|
||||
#endif
|
||||
SET_OUTPUT(SPI_EEPROM1_CS);
|
||||
SET_OUTPUT(SPI_EEPROM2_CS);
|
||||
SET_OUTPUT(SPI_FLASH_CS);
|
||||
WRITE(DAC0_SYNC, HIGH);
|
||||
WRITE(SPI_EEPROM1_CS, HIGH);
|
||||
WRITE(SPI_EEPROM2_CS, HIGH);
|
||||
WRITE(SPI_FLASH_CS, HIGH);
|
||||
WRITE(SS_PIN, HIGH);
|
||||
WRITE(DAC0_SYNC_PIN, HIGH);
|
||||
OUT_WRITE(SPI_EEPROM1_CS_PIN, HIGH);
|
||||
OUT_WRITE(SPI_EEPROM2_CS_PIN, HIGH);
|
||||
OUT_WRITE(SPI_FLASH_CS_PIN, HIGH);
|
||||
WRITE(SD_SS_PIN, HIGH);
|
||||
|
||||
OUT_WRITE(SDSS, LOW);
|
||||
|
||||
@@ -645,7 +639,7 @@
|
||||
}
|
||||
|
||||
// Read from SPI into buffer
|
||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||
void spiRead(uint8_t *buf, uint16_t nbyte) {
|
||||
if (!nbyte) return;
|
||||
--nbyte;
|
||||
for (int i = 0; i < nbyte; i++) {
|
||||
@@ -668,7 +662,7 @@
|
||||
//DELAY_US(1U);
|
||||
}
|
||||
|
||||
void spiSend(const uint8_t* buf, size_t nbyte) {
|
||||
void spiSend(const uint8_t *buf, size_t nbyte) {
|
||||
if (!nbyte) return;
|
||||
--nbyte;
|
||||
for (size_t i = 0; i < nbyte; i++) {
|
||||
@@ -689,7 +683,7 @@
|
||||
FLUSH_RX();
|
||||
}
|
||||
|
||||
void spiSend(uint32_t chan, const uint8_t* buf, size_t nbyte) {
|
||||
void spiSend(uint32_t chan, const uint8_t *buf, size_t nbyte) {
|
||||
if (!nbyte) return;
|
||||
--nbyte;
|
||||
for (size_t i = 0; i < nbyte; i++) {
|
||||
@@ -702,7 +696,7 @@
|
||||
}
|
||||
|
||||
// Write from buffer to SPI
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
void spiSendBlock(uint8_t token, const uint8_t *buf) {
|
||||
SPI0->SPI_TDR = (uint32_t)token | SPI_PCS(SPI_CHAN);
|
||||
WHILE_TX(0);
|
||||
//WHILE_RX(0);
|
||||
@@ -759,7 +753,6 @@
|
||||
*
|
||||
* All of the above can be avoided by defining FORCE_SOFT_SPI to force the
|
||||
* display to use software SPI.
|
||||
*
|
||||
*/
|
||||
|
||||
void spiInit(uint8_t spiRate=6) { // Default to slowest rate if not specified)
|
||||
@@ -802,19 +795,19 @@
|
||||
|
||||
uint8_t spiRec() { return (uint8_t)spiTransfer(0xFF); }
|
||||
|
||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||
void spiRead(uint8_t *buf, uint16_t nbyte) {
|
||||
for (int i = 0; i < nbyte; i++)
|
||||
buf[i] = spiTransfer(0xFF);
|
||||
}
|
||||
|
||||
void spiSend(uint8_t data) { spiTransfer(data); }
|
||||
|
||||
void spiSend(const uint8_t* buf, size_t nbyte) {
|
||||
void spiSend(const uint8_t *buf, size_t nbyte) {
|
||||
for (uint16_t i = 0; i < nbyte; i++)
|
||||
spiTransfer(buf[i]);
|
||||
}
|
||||
|
||||
void spiSendBlock(uint8_t token, const uint8_t* buf) {
|
||||
void spiSendBlock(uint8_t token, const uint8_t *buf) {
|
||||
spiTransfer(token);
|
||||
for (uint16_t i = 0; i < 512; i++)
|
||||
spiTransfer(buf[i]);
|
||||
|
4
Marlin/src/HAL/DUE/InterruptVectors.cpp
Executable file → Normal file
4
Marlin/src/HAL/DUE/InterruptVectors.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
practice, we need alignment to 256 bytes to make this work in all
|
||||
cases */
|
||||
__attribute__ ((aligned(256)))
|
||||
static DeviceVectors ram_tab = { nullptr };
|
||||
static DeviceVectors ram_tab[61] = { nullptr };
|
||||
|
||||
/**
|
||||
* This function checks if the exception/interrupt table is already in SRAM or not.
|
||||
|
2
Marlin/src/HAL/DUE/InterruptVectors.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/InterruptVectors.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
26
Marlin/src/HAL/DUE/MarlinSPI.h
Normal file
26
Marlin/src/HAL/DUE/MarlinSPI.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
using MarlinSPI = SPIClass;
|
179
Marlin/src/HAL/DUE/MarlinSerial.cpp
Executable file → Normal file
179
Marlin/src/HAL/DUE/MarlinSerial.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -382,7 +382,7 @@ void MarlinSerial<Cfg>::flush() {
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::write(const uint8_t c) {
|
||||
size_t MarlinSerial<Cfg>::write(const uint8_t c) {
|
||||
_written = true;
|
||||
|
||||
if (Cfg::TX_SIZE == 0) {
|
||||
@@ -400,13 +400,13 @@ void MarlinSerial<Cfg>::write(const uint8_t c) {
|
||||
// XOFF char at the RX isr, but it is properly handled there
|
||||
if (!(HWUART->UART_IMR & UART_IMR_TXRDY) && (HWUART->UART_SR & UART_SR_TXRDY)) {
|
||||
HWUART->UART_THR = c;
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const uint8_t i = (tx_buffer.head + 1) & (Cfg::TX_SIZE - 1);
|
||||
|
||||
// If global interrupts are disabled (as the result of being called from an ISR)...
|
||||
if (!ISRS_ENABLED()) {
|
||||
if (!hal.isr_state()) {
|
||||
|
||||
// Make room by polling if it is possible to transmit, and do so!
|
||||
while (i == tx_buffer.tail) {
|
||||
@@ -428,6 +428,7 @@ void MarlinSerial<Cfg>::write(const uint8_t c) {
|
||||
// Enable TX isr - Non atomic, but it will eventually enable TX isr
|
||||
HWUART->UART_IER = UART_IER_TXRDY;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
@@ -453,7 +454,7 @@ void MarlinSerial<Cfg>::flushTX() {
|
||||
if (!_written) return;
|
||||
|
||||
// If global interrupts are disabled (as the result of being called from an ISR)...
|
||||
if (!ISRS_ENABLED()) {
|
||||
if (!hal.isr_state()) {
|
||||
|
||||
// Wait until everything was transmitted - We must do polling, as interrupts are disabled
|
||||
while (tx_buffer.head != tx_buffer.tail || !(HWUART->UART_SR & UART_SR_TXEMPTY)) {
|
||||
@@ -473,169 +474,21 @@ void MarlinSerial<Cfg>::flushTX() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports from print.h
|
||||
*/
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(char c, int base) {
|
||||
print((long)c, base);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(unsigned char b, int base) {
|
||||
print((unsigned long)b, base);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(int n, int base) {
|
||||
print((long)n, base);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(unsigned int n, int base) {
|
||||
print((unsigned long)n, base);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(long n, int base) {
|
||||
if (base == 0) write(n);
|
||||
else if (base == 10) {
|
||||
if (n < 0) { print('-'); n = -n; }
|
||||
printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
printNumber(n, base);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(unsigned long n, int base) {
|
||||
if (base == 0) write(n);
|
||||
else printNumber(n, base);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::print(double n, int digits) {
|
||||
printFloat(n, digits);
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println() {
|
||||
print('\r');
|
||||
print('\n');
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(const String& s) {
|
||||
print(s);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(const char c[]) {
|
||||
print(c);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(char c, int base) {
|
||||
print(c, base);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(unsigned char b, int base) {
|
||||
print(b, base);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(int n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(unsigned int n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(long n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(unsigned long n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::println(double n, int digits) {
|
||||
print(n, digits);
|
||||
println();
|
||||
}
|
||||
|
||||
// Private Methods
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::printNumber(unsigned long n, uint8_t base) {
|
||||
if (n) {
|
||||
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
|
||||
int8_t i = 0;
|
||||
while (n) {
|
||||
buf[i++] = n % base;
|
||||
n /= base;
|
||||
}
|
||||
while (i--)
|
||||
print((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10)));
|
||||
}
|
||||
else
|
||||
print('0');
|
||||
}
|
||||
|
||||
template<typename Cfg>
|
||||
void MarlinSerial<Cfg>::printFloat(double number, uint8_t digits) {
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
LOOP_L_N(i, digits) rounding *= 0.1;
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits) {
|
||||
print('.');
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits--) {
|
||||
remainder *= 10.0;
|
||||
int toPrint = int(remainder);
|
||||
print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If not using the USB port as serial port
|
||||
#if SERIAL_PORT >= 0
|
||||
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT>>; // Define
|
||||
MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1; // Instantiate
|
||||
#if defined(SERIAL_PORT) && SERIAL_PORT >= 0
|
||||
template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT> >;
|
||||
MSerialT1 customizedSerial1(MarlinSerialCfg<SERIAL_PORT>::EMERGENCYPARSER);
|
||||
#endif
|
||||
|
||||
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
|
||||
template class MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>>; // Define
|
||||
MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2; // Instantiate
|
||||
template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> >;
|
||||
MSerialT2 customizedSerial2(MarlinSerialCfg<SERIAL_PORT_2>::EMERGENCYPARSER);
|
||||
#endif
|
||||
|
||||
#if defined(SERIAL_PORT_3) && SERIAL_PORT_3 >= 0
|
||||
template class MarlinSerial< MarlinSerialCfg<SERIAL_PORT_3> >;
|
||||
MSerialT3 customizedSerial3(MarlinSerialCfg<SERIAL_PORT_3>::EMERGENCYPARSER);
|
||||
#endif
|
||||
|
||||
#endif // ARDUINO_ARCH_SAM
|
||||
|
54
Marlin/src/HAL/DUE/MarlinSerial.h
Executable file → Normal file
54
Marlin/src/HAL/DUE/MarlinSerial.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -30,11 +30,7 @@
|
||||
#include <WString.h>
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
#include "../../core/serial_hook.h"
|
||||
|
||||
// Define constants and variables for buffering incoming serial data. We're
|
||||
// using a ring buffer (I think), in which rx_buffer_head is the index of the
|
||||
@@ -119,42 +115,15 @@ public:
|
||||
static int read();
|
||||
static void flush();
|
||||
static ring_buffer_pos_t available();
|
||||
static void write(const uint8_t c);
|
||||
static size_t write(const uint8_t c);
|
||||
static void flushTX();
|
||||
|
||||
static bool emergency_parser_enabled() { return Cfg::EMERGENCYPARSER; }
|
||||
|
||||
FORCE_INLINE static uint8_t dropped() { return Cfg::DROPPED_RX ? rx_dropped_bytes : 0; }
|
||||
FORCE_INLINE static uint8_t buffer_overruns() { return Cfg::RX_OVERRUNS ? rx_buffer_overruns : 0; }
|
||||
FORCE_INLINE static uint8_t framing_errors() { return Cfg::RX_FRAMING_ERRORS ? rx_framing_errors : 0; }
|
||||
FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return Cfg::MAX_RX_QUEUED ? rx_max_enqueued : 0; }
|
||||
|
||||
FORCE_INLINE static void write(const char* str) { while (*str) write(*str++); }
|
||||
FORCE_INLINE static void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); }
|
||||
FORCE_INLINE static void print(const String& s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
|
||||
FORCE_INLINE static void print(const char* str) { write(str); }
|
||||
|
||||
static void print(char, int = 0);
|
||||
static void print(unsigned char, int = 0);
|
||||
static void print(int, int = DEC);
|
||||
static void print(unsigned int, int = DEC);
|
||||
static void print(long, int = DEC);
|
||||
static void print(unsigned long, int = DEC);
|
||||
static void print(double, int = 2);
|
||||
|
||||
static void println(const String& s);
|
||||
static void println(const char[]);
|
||||
static void println(char, int = 0);
|
||||
static void println(unsigned char, int = 0);
|
||||
static void println(int, int = DEC);
|
||||
static void println(unsigned int, int = DEC);
|
||||
static void println(long, int = DEC);
|
||||
static void println(unsigned long, int = DEC);
|
||||
static void println(double, int = 2);
|
||||
static void println();
|
||||
operator bool() { return true; }
|
||||
|
||||
private:
|
||||
static void printNumber(unsigned long, const uint8_t);
|
||||
static void printFloat(double, uint8_t);
|
||||
};
|
||||
|
||||
// Serial port configuration
|
||||
@@ -171,10 +140,17 @@ struct MarlinSerialCfg {
|
||||
static constexpr bool MAX_RX_QUEUED = ENABLED(SERIAL_STATS_MAX_RX_QUEUED);
|
||||
};
|
||||
|
||||
#if SERIAL_PORT >= 0
|
||||
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT>> customizedSerial1;
|
||||
#if defined(SERIAL_PORT) && SERIAL_PORT >= 0
|
||||
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT> > > MSerialT1;
|
||||
extern MSerialT1 customizedSerial1;
|
||||
#endif
|
||||
|
||||
#if defined(SERIAL_PORT_2) && SERIAL_PORT_2 >= 0
|
||||
extern MarlinSerial<MarlinSerialCfg<SERIAL_PORT_2>> customizedSerial2;
|
||||
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_2> > > MSerialT2;
|
||||
extern MSerialT2 customizedSerial2;
|
||||
#endif
|
||||
|
||||
#if defined(SERIAL_PORT_3) && SERIAL_PORT_3 >= 0
|
||||
typedef Serial1Class< MarlinSerial< MarlinSerialCfg<SERIAL_PORT_3> > > MSerialT3;
|
||||
extern MSerialT3 customizedSerial3;
|
||||
#endif
|
||||
|
190
Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
Executable file → Normal file
190
Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
Executable file → Normal file
@@ -16,16 +16,16 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
/**
|
||||
* MarlinSerial_Due.cpp - Hardware serial library for Arduino DUE
|
||||
* Copyright (c) 2017 Eduardo José Tagle. All right reserved
|
||||
* Based on MarlinSerial for AVR, copyright (c) 2006 Nicholas Zambetti. All right reserved.
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
@@ -33,10 +33,6 @@
|
||||
|
||||
#include "MarlinSerialUSB.h"
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
#include "../../feature/e_parser.h"
|
||||
#endif
|
||||
|
||||
// Imports from Atmel USB Stack/CDC implementation
|
||||
extern "C" {
|
||||
bool usb_task_cdc_isenabled();
|
||||
@@ -45,15 +41,11 @@ extern "C" {
|
||||
int udi_cdc_getc();
|
||||
bool udi_cdc_is_tx_ready();
|
||||
int udi_cdc_putc(int value);
|
||||
};
|
||||
}
|
||||
|
||||
// Pending character
|
||||
static int pending_char = -1;
|
||||
|
||||
#if ENABLED(EMERGENCY_PARSER)
|
||||
static EmergencyParser::State emergency_state; // = EP_RESET
|
||||
#endif
|
||||
|
||||
// Public Methods
|
||||
void MarlinSerialUSB::begin(const long) {}
|
||||
|
||||
@@ -73,9 +65,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(static_cast<MSerialT1*>(this)->emergency_state, (char)pending_char));
|
||||
|
||||
return pending_char;
|
||||
}
|
||||
@@ -97,31 +87,27 @@ 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(static_cast<MSerialT1*>(this)->emergency_state, (char)c));
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
bool MarlinSerialUSB::available() {
|
||||
/* If Pending chars */
|
||||
return pending_char >= 0 ||
|
||||
/* or USB CDC enumerated and configured on the PC side and some
|
||||
bytes where sent to us */
|
||||
(usb_task_cdc_isenabled() && udi_cdc_is_rx_ready());
|
||||
int MarlinSerialUSB::available() {
|
||||
if (pending_char > 0) return pending_char;
|
||||
return pending_char == 0 ||
|
||||
// or USB CDC enumerated and configured on the PC side and some bytes where sent to us */
|
||||
(usb_task_cdc_isenabled() && udi_cdc_is_rx_ready());
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::flush() { }
|
||||
void MarlinSerialUSB::flushTX() { }
|
||||
|
||||
void MarlinSerialUSB::write(const uint8_t c) {
|
||||
size_t MarlinSerialUSB::write(const uint8_t c) {
|
||||
|
||||
/* Do not even bother sending anything if USB CDC is not enumerated
|
||||
or not configured on the PC side or there is no program on the PC
|
||||
listening to our messages */
|
||||
if (!usb_task_cdc_isenabled() || !usb_task_cdc_dtr_active())
|
||||
return;
|
||||
return 0;
|
||||
|
||||
/* Wait until the PC has read the pending to be sent data */
|
||||
while (usb_task_cdc_isenabled() &&
|
||||
@@ -133,161 +119,23 @@ void MarlinSerialUSB::write(const uint8_t c) {
|
||||
or not configured on the PC side or there is no program on the PC
|
||||
listening to our messages at this point */
|
||||
if (!usb_task_cdc_isenabled() || !usb_task_cdc_dtr_active())
|
||||
return;
|
||||
return 0;
|
||||
|
||||
// Fifo full
|
||||
// udi_cdc_signal_overrun();
|
||||
udi_cdc_putc(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports from print.h
|
||||
*/
|
||||
|
||||
void MarlinSerialUSB::print(char c, int base) {
|
||||
print((long)c, base);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::print(unsigned char b, int base) {
|
||||
print((unsigned long)b, base);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::print(int n, int base) {
|
||||
print((long)n, base);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::print(unsigned int n, int base) {
|
||||
print((unsigned long)n, base);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::print(long n, int base) {
|
||||
if (base == 0)
|
||||
write(n);
|
||||
else if (base == 10) {
|
||||
if (n < 0) {
|
||||
print('-');
|
||||
n = -n;
|
||||
}
|
||||
printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
printNumber(n, base);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::print(unsigned long n, int base) {
|
||||
if (base == 0) write(n);
|
||||
else printNumber(n, base);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::print(double n, int digits) {
|
||||
printFloat(n, digits);
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println() {
|
||||
print('\r');
|
||||
print('\n');
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(const String& s) {
|
||||
print(s);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(const char c[]) {
|
||||
print(c);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(char c, int base) {
|
||||
print(c, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(unsigned char b, int base) {
|
||||
print(b, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(int n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(unsigned int n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(long n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(unsigned long n, int base) {
|
||||
print(n, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::println(double n, int digits) {
|
||||
print(n, digits);
|
||||
println();
|
||||
}
|
||||
|
||||
// Private Methods
|
||||
|
||||
void MarlinSerialUSB::printNumber(unsigned long n, uint8_t base) {
|
||||
if (n) {
|
||||
unsigned char buf[8 * sizeof(long)]; // Enough space for base 2
|
||||
int8_t i = 0;
|
||||
while (n) {
|
||||
buf[i++] = n % base;
|
||||
n /= base;
|
||||
}
|
||||
while (i--)
|
||||
print((char)(buf[i] + (buf[i] < 10 ? '0' : 'A' - 10)));
|
||||
}
|
||||
else
|
||||
print('0');
|
||||
}
|
||||
|
||||
void MarlinSerialUSB::printFloat(double number, uint8_t digits) {
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
LOOP_L_N(i, digits)
|
||||
rounding *= 0.1;
|
||||
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits) {
|
||||
print('.');
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits--) {
|
||||
remainder *= 10.0;
|
||||
int toPrint = int(remainder);
|
||||
print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Preinstantiate
|
||||
#if SERIAL_PORT == -1
|
||||
MarlinSerialUSB customizedSerial1;
|
||||
MSerialT1 customizedSerial1(TERN0(EMERGENCY_PARSER, true));
|
||||
#endif
|
||||
#if SERIAL_PORT_2 == -1
|
||||
MarlinSerialUSB customizedSerial2;
|
||||
MSerialT2 customizedSerial2(TERN0(EMERGENCY_PARSER, true));
|
||||
#endif
|
||||
#if SERIAL_PORT_3 == -1
|
||||
MSerialT3 customizedSerial3(TERN0(EMERGENCY_PARSER, true));
|
||||
#endif
|
||||
|
||||
#endif // HAS_USB_SERIAL
|
||||
|
74
Marlin/src/HAL/DUE/MarlinSerialUSB.h
Executable file → Normal file
74
Marlin/src/HAL/DUE/MarlinSerialUSB.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -27,73 +27,39 @@
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_USB_SERIAL
|
||||
#include "../../core/serial_hook.h"
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
|
||||
class MarlinSerialUSB {
|
||||
|
||||
public:
|
||||
MarlinSerialUSB() {};
|
||||
static void begin(const long);
|
||||
static void end();
|
||||
static int peek();
|
||||
static int read();
|
||||
static void flush();
|
||||
static void flushTX();
|
||||
static bool available();
|
||||
static void write(const uint8_t c);
|
||||
struct MarlinSerialUSB {
|
||||
void begin(const long);
|
||||
void end();
|
||||
int peek();
|
||||
int read();
|
||||
void flush();
|
||||
int available();
|
||||
size_t write(const uint8_t c);
|
||||
|
||||
#if ENABLED(SERIAL_STATS_DROPPED_RX)
|
||||
FORCE_INLINE static uint32_t dropped() { return 0; }
|
||||
FORCE_INLINE uint32_t dropped() { return 0; }
|
||||
#endif
|
||||
|
||||
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
|
||||
FORCE_INLINE static int rxMaxEnqueued() { return 0; }
|
||||
FORCE_INLINE int rxMaxEnqueued() { return 0; }
|
||||
#endif
|
||||
|
||||
FORCE_INLINE static void write(const char* str) { while (*str) write(*str++); }
|
||||
FORCE_INLINE static void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); }
|
||||
FORCE_INLINE static void print(const String& s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
|
||||
FORCE_INLINE static void print(const char* str) { write(str); }
|
||||
|
||||
static void print(char, int = 0);
|
||||
static void print(unsigned char, int = 0);
|
||||
static void print(int, int = DEC);
|
||||
static void print(unsigned int, int = DEC);
|
||||
static void print(long, int = DEC);
|
||||
static void print(unsigned long, int = DEC);
|
||||
static void print(double, int = 2);
|
||||
|
||||
static void println(const String& s);
|
||||
static void println(const char[]);
|
||||
static void println(char, int = 0);
|
||||
static void println(unsigned char, int = 0);
|
||||
static void println(int, int = DEC);
|
||||
static void println(unsigned int, int = DEC);
|
||||
static void println(long, int = DEC);
|
||||
static void println(unsigned long, int = DEC);
|
||||
static void println(double, int = 2);
|
||||
static void println();
|
||||
operator bool() { return true; }
|
||||
|
||||
private:
|
||||
static void printNumber(unsigned long, const uint8_t);
|
||||
static void printFloat(double, uint8_t);
|
||||
};
|
||||
|
||||
#if SERIAL_PORT == -1
|
||||
extern MarlinSerialUSB customizedSerial1;
|
||||
typedef Serial1Class<MarlinSerialUSB> MSerialT1;
|
||||
extern MSerialT1 customizedSerial1;
|
||||
#endif
|
||||
|
||||
#if SERIAL_PORT_2 == -1
|
||||
extern MarlinSerialUSB customizedSerial2;
|
||||
typedef Serial1Class<MarlinSerialUSB> MSerialT2;
|
||||
extern MSerialT2 customizedSerial2;
|
||||
#endif
|
||||
|
||||
#endif // HAS_USB_SERIAL
|
||||
#if SERIAL_PORT_3 == -1
|
||||
typedef Serial1Class<MarlinSerialUSB> MSerialT3;
|
||||
extern MSerialT3 customizedSerial3;
|
||||
#endif
|
||||
|
91
Marlin/src/HAL/DUE/MinSerial.cpp
Normal file
91
Marlin/src/HAL/DUE/MinSerial.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||
|
||||
#include "../shared/MinSerial.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
static void TXBegin() {
|
||||
// Disable UART interrupt in NVIC
|
||||
NVIC_DisableIRQ( UART_IRQn );
|
||||
|
||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
||||
__DSB();
|
||||
__ISB();
|
||||
|
||||
// Disable clock
|
||||
pmc_disable_periph_clk( ID_UART );
|
||||
|
||||
// Configure PMC
|
||||
pmc_enable_periph_clk( ID_UART );
|
||||
|
||||
// Disable PDC channel
|
||||
UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
|
||||
|
||||
// Reset and disable receiver and transmitter
|
||||
UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS;
|
||||
|
||||
// Configure mode: 8bit, No parity, 1 bit stop
|
||||
UART->UART_MR = UART_MR_CHMODE_NORMAL | US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO;
|
||||
|
||||
// Configure baudrate (asynchronous, no oversampling) to BAUDRATE bauds
|
||||
UART->UART_BRGR = (SystemCoreClock / (BAUDRATE << 4));
|
||||
|
||||
// Enable receiver and transmitter
|
||||
UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
|
||||
}
|
||||
|
||||
// A SW memory barrier, to ensure GCC does not overoptimize loops
|
||||
#define sw_barrier() __asm__ volatile("": : :"memory");
|
||||
static void TX(char c) {
|
||||
while (!(UART->UART_SR & UART_SR_TXRDY)) { WDT_Restart(WDT); sw_barrier(); };
|
||||
UART->UART_THR = c;
|
||||
}
|
||||
|
||||
void install_min_serial() {
|
||||
HAL_min_serial_init = &TXBegin;
|
||||
HAL_min_serial_out = &TX;
|
||||
}
|
||||
|
||||
#if DISABLED(DYNAMIC_VECTORTABLE)
|
||||
extern "C" {
|
||||
__attribute__((naked)) void JumpHandler_ASM() {
|
||||
__asm__ __volatile__ (
|
||||
"b CommonHandler_ASM\n"
|
||||
);
|
||||
}
|
||||
void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler();
|
||||
void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler();
|
||||
void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler();
|
||||
void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler();
|
||||
void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // POSTMORTEM_DEBUGGING
|
||||
#endif // ARDUINO_ARCH_SAM
|
135
Marlin/src/HAL/DUE/Servo.cpp
Executable file → Normal file
135
Marlin/src/HAL/DUE/Servo.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -44,16 +44,15 @@
|
||||
|
||||
#if HAS_SERVOS
|
||||
|
||||
#include "../shared/Marduino.h"
|
||||
#include "../shared/servo.h"
|
||||
#include "../shared/servo_private.h"
|
||||
|
||||
static volatile int8_t Channel[_Nbr_16timers]; // counter for the servo being pulsed for each timer (or -1 if refresh interval)
|
||||
static Flags<_Nbr_16timers> DisablePending; // ISR should disable the timer at the next timer reset
|
||||
|
||||
// ------------------------
|
||||
/// Interrupt handler for the TC0 channel 1.
|
||||
// ------------------------
|
||||
void Servo_Handler(timer16_Sequence_t timer, Tc *pTc, uint8_t channel);
|
||||
void Servo_Handler(const timer16_Sequence_t, Tc*, const uint8_t);
|
||||
|
||||
#ifdef _useTimer1
|
||||
void HANDLER_FOR_TIMER1() { Servo_Handler(_timer1, TC_FOR_TIMER1, CHANNEL_FOR_TIMER1); }
|
||||
@@ -71,88 +70,92 @@ void Servo_Handler(timer16_Sequence_t timer, Tc *pTc, uint8_t channel);
|
||||
void HANDLER_FOR_TIMER5() { Servo_Handler(_timer5, TC_FOR_TIMER5, CHANNEL_FOR_TIMER5); }
|
||||
#endif
|
||||
|
||||
void Servo_Handler(timer16_Sequence_t timer, Tc *tc, uint8_t channel) {
|
||||
// clear interrupt
|
||||
tc->TC_CHANNEL[channel].TC_SR;
|
||||
if (Channel[timer] < 0)
|
||||
tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // channel set to -1 indicated that refresh interval completed so reset the timer
|
||||
else if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && SERVO(timer, Channel[timer]).Pin.isActive)
|
||||
extDigitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, LOW); // pulse this channel low if activated
|
||||
void Servo_Handler(const timer16_Sequence_t timer, Tc *tc, const uint8_t channel) {
|
||||
static int8_t Channel[_Nbr_16timers]; // Servo counters to pulse (or -1 for refresh interval)
|
||||
int8_t cho = Channel[timer]; // Handle the prior Channel[timer] first
|
||||
if (cho < 0) { // Channel -1 indicates the refresh interval completed...
|
||||
tc->TC_CHANNEL[channel].TC_CCR |= TC_CCR_SWTRG; // ...so reset the timer
|
||||
if (DisablePending[timer]) {
|
||||
// Disabling only after the full servo period expires prevents
|
||||
// pulses being too close together if immediately re-enabled.
|
||||
DisablePending.clear(timer);
|
||||
TC_Stop(tc, channel);
|
||||
tc->TC_CHANNEL[channel].TC_SR; // clear interrupt
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (SERVO_INDEX(timer, cho) < ServoCount) // prior channel handled?
|
||||
extDigitalWrite(SERVO(timer, cho).Pin.nbr, LOW); // pulse the prior channel LOW
|
||||
|
||||
Channel[timer]++; // increment to the next channel
|
||||
if (SERVO_INDEX(timer, Channel[timer]) < ServoCount && Channel[timer] < SERVOS_PER_TIMER) {
|
||||
tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + SERVO(timer,Channel[timer]).ticks;
|
||||
if (SERVO(timer,Channel[timer]).Pin.isActive) // check if activated
|
||||
extDigitalWrite(SERVO(timer, Channel[timer]).Pin.nbr, HIGH); // its an active channel so pulse it high
|
||||
Channel[timer] = ++cho; // go to the next channel (or 0)
|
||||
if (cho < SERVOS_PER_TIMER && SERVO_INDEX(timer, cho) < ServoCount) {
|
||||
tc->TC_CHANNEL[channel].TC_RA = tc->TC_CHANNEL[channel].TC_CV + SERVO(timer, cho).ticks;
|
||||
if (SERVO(timer, cho).Pin.isActive) // activated?
|
||||
extDigitalWrite(SERVO(timer, cho).Pin.nbr, HIGH); // yes: pulse HIGH
|
||||
}
|
||||
else {
|
||||
// finished all channels so wait for the refresh period to expire before starting over
|
||||
tc->TC_CHANNEL[channel].TC_RA =
|
||||
tc->TC_CHANNEL[channel].TC_CV < usToTicks(REFRESH_INTERVAL) - 4
|
||||
? (unsigned int)usToTicks(REFRESH_INTERVAL) // allow a few ticks to ensure the next OCR1A not missed
|
||||
: tc->TC_CHANNEL[channel].TC_CV + 4; // at least REFRESH_INTERVAL has elapsed
|
||||
Channel[timer] = -1; // this will get incremented at the end of the refresh period to start again at the first channel
|
||||
const unsigned int cval = tc->TC_CHANNEL[channel].TC_CV + 128 / (SERVO_TIMER_PRESCALER), // allow 128 cycles to ensure the next CV not missed
|
||||
ival = (unsigned int)usToTicks(REFRESH_INTERVAL); // at least REFRESH_INTERVAL has elapsed
|
||||
tc->TC_CHANNEL[channel].TC_RA = max(cval, ival);
|
||||
|
||||
Channel[timer] = -1; // reset the timer CCR on the next call
|
||||
}
|
||||
|
||||
tc->TC_CHANNEL[channel].TC_SR; // clear interrupt
|
||||
}
|
||||
|
||||
static void _initISR(Tc *tc, uint32_t channel, uint32_t id, IRQn_Type irqn) {
|
||||
pmc_enable_periph_clk(id);
|
||||
TC_Configure(tc, channel,
|
||||
TC_CMR_TCCLKS_TIMER_CLOCK3 | // MCK/32
|
||||
TC_CMR_WAVE | // Waveform mode
|
||||
TC_CMR_WAVSEL_UP_RC ); // Counter running up and reset when equals to RC
|
||||
TC_CMR_WAVE // Waveform mode
|
||||
| TC_CMR_WAVSEL_UP_RC // Counter running up and reset when equal to RC
|
||||
| (SERVO_TIMER_PRESCALER == 2 ? TC_CMR_TCCLKS_TIMER_CLOCK1 : 0) // MCK/2
|
||||
| (SERVO_TIMER_PRESCALER == 8 ? TC_CMR_TCCLKS_TIMER_CLOCK2 : 0) // MCK/8
|
||||
| (SERVO_TIMER_PRESCALER == 32 ? TC_CMR_TCCLKS_TIMER_CLOCK3 : 0) // MCK/32
|
||||
| (SERVO_TIMER_PRESCALER == 128 ? TC_CMR_TCCLKS_TIMER_CLOCK4 : 0) // MCK/128
|
||||
);
|
||||
|
||||
/* 84MHz, MCK/32, for 1.5ms: 3937 */
|
||||
TC_SetRA(tc, channel, 2625); // 1ms
|
||||
// Wait 1ms before the first ISR
|
||||
TC_SetRA(tc, channel, (F_CPU) / (SERVO_TIMER_PRESCALER) / 1000UL); // 1ms
|
||||
|
||||
/* Configure and enable interrupt */
|
||||
// Configure and enable interrupt
|
||||
NVIC_EnableIRQ(irqn);
|
||||
// TC_IER_CPAS: RA Compare
|
||||
tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPAS;
|
||||
tc->TC_CHANNEL[channel].TC_IER = TC_IER_CPAS; // TC_IER_CPAS: RA Compare
|
||||
|
||||
// Enables the timer clock and performs a software reset to start the counting
|
||||
TC_Start(tc, channel);
|
||||
}
|
||||
|
||||
void initISR(timer16_Sequence_t timer) {
|
||||
#ifdef _useTimer1
|
||||
if (timer == _timer1)
|
||||
_initISR(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1, ID_TC_FOR_TIMER1, IRQn_FOR_TIMER1);
|
||||
#endif
|
||||
#ifdef _useTimer2
|
||||
if (timer == _timer2)
|
||||
_initISR(TC_FOR_TIMER2, CHANNEL_FOR_TIMER2, ID_TC_FOR_TIMER2, IRQn_FOR_TIMER2);
|
||||
#endif
|
||||
#ifdef _useTimer3
|
||||
if (timer == _timer3)
|
||||
_initISR(TC_FOR_TIMER3, CHANNEL_FOR_TIMER3, ID_TC_FOR_TIMER3, IRQn_FOR_TIMER3);
|
||||
#endif
|
||||
#ifdef _useTimer4
|
||||
if (timer == _timer4)
|
||||
_initISR(TC_FOR_TIMER4, CHANNEL_FOR_TIMER4, ID_TC_FOR_TIMER4, IRQn_FOR_TIMER4);
|
||||
#endif
|
||||
#ifdef _useTimer5
|
||||
if (timer == _timer5)
|
||||
_initISR(TC_FOR_TIMER5, CHANNEL_FOR_TIMER5, ID_TC_FOR_TIMER5, IRQn_FOR_TIMER5);
|
||||
#endif
|
||||
void initISR(const timer16_Sequence_t timer_index) {
|
||||
CRITICAL_SECTION_START();
|
||||
const bool disable_soon = DisablePending[timer_index];
|
||||
DisablePending.clear(timer_index);
|
||||
CRITICAL_SECTION_END();
|
||||
|
||||
if (!disable_soon) switch (timer_index) {
|
||||
default: break;
|
||||
#ifdef _useTimer1
|
||||
case _timer1: return _initISR(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1, ID_TC_FOR_TIMER1, IRQn_FOR_TIMER1);
|
||||
#endif
|
||||
#ifdef _useTimer2
|
||||
case _timer2: return _initISR(TC_FOR_TIMER2, CHANNEL_FOR_TIMER2, ID_TC_FOR_TIMER2, IRQn_FOR_TIMER2);
|
||||
#endif
|
||||
#ifdef _useTimer3
|
||||
case _timer3: return _initISR(TC_FOR_TIMER3, CHANNEL_FOR_TIMER3, ID_TC_FOR_TIMER3, IRQn_FOR_TIMER3);
|
||||
#endif
|
||||
#ifdef _useTimer4
|
||||
case _timer4: return _initISR(TC_FOR_TIMER4, CHANNEL_FOR_TIMER4, ID_TC_FOR_TIMER4, IRQn_FOR_TIMER4);
|
||||
#endif
|
||||
#ifdef _useTimer5
|
||||
case _timer5: return _initISR(TC_FOR_TIMER5, CHANNEL_FOR_TIMER5, ID_TC_FOR_TIMER5, IRQn_FOR_TIMER5);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void finISR(timer16_Sequence_t) {
|
||||
#ifdef _useTimer1
|
||||
TC_Stop(TC_FOR_TIMER1, CHANNEL_FOR_TIMER1);
|
||||
#endif
|
||||
#ifdef _useTimer2
|
||||
TC_Stop(TC_FOR_TIMER2, CHANNEL_FOR_TIMER2);
|
||||
#endif
|
||||
#ifdef _useTimer3
|
||||
TC_Stop(TC_FOR_TIMER3, CHANNEL_FOR_TIMER3);
|
||||
#endif
|
||||
#ifdef _useTimer4
|
||||
TC_Stop(TC_FOR_TIMER4, CHANNEL_FOR_TIMER4);
|
||||
#endif
|
||||
#ifdef _useTimer5
|
||||
TC_Stop(TC_FOR_TIMER5, CHANNEL_FOR_TIMER5);
|
||||
#endif
|
||||
void finISR(const timer16_Sequence_t timer_index) {
|
||||
// Timer is disabled from the ISR, to ensure proper final pulse length.
|
||||
DisablePending.set(timer_index);
|
||||
}
|
||||
|
||||
#endif // HAS_SERVOS
|
||||
|
2
Marlin/src/HAL/DUE/ServoTimers.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/ServoTimers.h
Executable file → Normal file
@@ -37,7 +37,7 @@
|
||||
#define _useTimer5
|
||||
|
||||
#define TRIM_DURATION 2 // compensation ticks to trim adjust for digitalWrite delays
|
||||
#define SERVO_TIMER_PRESCALER 32 // timer prescaler
|
||||
#define SERVO_TIMER_PRESCALER 2 // timer prescaler
|
||||
|
||||
/*
|
||||
TC0, chan 0 => TC0_Handler
|
||||
|
13
Marlin/src/HAL/DUE/Tone.cpp
Executable file → Normal file
13
Marlin/src/HAL/DUE/Tone.cpp
Executable file → Normal file
@@ -18,38 +18,37 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: Tone function for Arduino Due and compatible (SAM3X8E)
|
||||
* Derived from http://forum.arduino.cc/index.php?topic=136500.msg2903012#msg2903012
|
||||
* 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;
|
||||
|
||||
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration) {
|
||||
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration/*=0*/) {
|
||||
tone_pin = _pin;
|
||||
toggles = 2 * frequency * duration / 1000;
|
||||
HAL_timer_start(TONE_TIMER_NUM, 2 * frequency);
|
||||
HAL_timer_start(MF_TIMER_TONE, 2 * frequency);
|
||||
}
|
||||
|
||||
void noTone(const pin_t _pin) {
|
||||
HAL_timer_disable_interrupt(TONE_TIMER_NUM);
|
||||
HAL_timer_disable_interrupt(MF_TIMER_TONE);
|
||||
extDigitalWrite(_pin, LOW);
|
||||
}
|
||||
|
||||
HAL_TONE_TIMER_ISR() {
|
||||
static uint8_t pin_state = 0;
|
||||
HAL_timer_isr_prologue(TONE_TIMER_NUM);
|
||||
HAL_timer_isr_prologue(MF_TIMER_TONE);
|
||||
|
||||
if (toggles) {
|
||||
toggles--;
|
||||
|
27
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
Executable file → Normal file
27
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_shared_hw_spi.cpp
Executable file → Normal file
@@ -16,11 +16,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Based on u8g_com_msp430_hw_spi.c
|
||||
*
|
||||
@@ -52,25 +51,23 @@
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __SAM3X8E__
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
#if HAS_MARLINUI_U8GLIB
|
||||
|
||||
#include <U8glib.h>
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
#include "../../../MarlinCore.h"
|
||||
|
||||
void spiBegin();
|
||||
void spiInit(uint8_t spiRate);
|
||||
void spiSend(uint8_t b);
|
||||
void spiSend(const uint8_t* buf, size_t n);
|
||||
#ifndef LCD_SPI_SPEED
|
||||
#define LCD_SPI_SPEED SPI_QUARTER_SPEED
|
||||
#endif
|
||||
|
||||
#include "../../shared/Marduino.h"
|
||||
#include "../../shared/HAL_SPI.h"
|
||||
#include "../fastio.h"
|
||||
|
||||
void u8g_SetPIOutput_DUE_hw_spi(u8g_t *u8g, uint8_t pin_index) {
|
||||
@@ -101,11 +98,7 @@ uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
|
||||
spiBegin();
|
||||
|
||||
#ifndef SPI_SPEED
|
||||
#define SPI_SPEED SPI_FULL_SPEED // use same SPI speed as SD card
|
||||
#endif
|
||||
spiInit(2);
|
||||
|
||||
spiInit(LCD_SPI_SPEED);
|
||||
break;
|
||||
|
||||
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
|
||||
@@ -145,6 +138,6 @@ uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD
|
||||
#endif // HAS_MARLINUI_U8GLIB
|
||||
|
||||
#endif //__SAM3X8E__
|
||||
#endif // __SAM3X8E__
|
||||
|
11
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
Executable file → Normal file
11
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_st7920_sw_spi.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -57,11 +57,12 @@
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(U8GLIB_ST7920)
|
||||
#if IS_U8GLIB_ST7920
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
#include "../../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
#include "u8g_com_HAL_DUE_sw_spi_shared.h"
|
||||
|
||||
@@ -145,7 +146,7 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
}
|
||||
|
||||
#if ENABLED(LIGHTWEIGHT_UI)
|
||||
#include "../../../lcd/ultralcd.h"
|
||||
#include "../../../lcd/marlinui.h"
|
||||
#include "../../shared/HAL_ST7920.h"
|
||||
|
||||
#define ST7920_CS_PIN LCD_PINS_RS
|
||||
@@ -181,5 +182,5 @@ uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_va
|
||||
}
|
||||
#endif // LIGHTWEIGHT_UI
|
||||
|
||||
#endif // U8GLIB_ST7920
|
||||
#endif // IS_U8GLIB_ST7920
|
||||
#endif // ARDUINO_ARCH_SAM
|
||||
|
11
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
Executable file → Normal file
11
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -57,17 +57,14 @@
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD && DISABLED(U8GLIB_ST7920)
|
||||
|
||||
#undef SPI_SPEED
|
||||
#define SPI_SPEED 2 // About 2 MHz
|
||||
#if HAS_MARLINUI_U8GLIB && !IS_U8GLIB_ST7920
|
||||
|
||||
#include "u8g_com_HAL_DUE_sw_spi_shared.h"
|
||||
|
||||
#include "../../shared/Marduino.h"
|
||||
#include "../../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
#if ENABLED(FYSETC_MINI_12864)
|
||||
#define SPISEND_SW_DUE u8g_spiSend_sw_DUE_mode_3
|
||||
@@ -144,5 +141,5 @@ uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD && !U8GLIB_ST7920
|
||||
#endif // HAS_MARLINUI_U8GLIB && !IS_U8GLIB_ST7920
|
||||
#endif // ARDUINO_ARCH_SAM
|
||||
|
9
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
Executable file → Normal file
9
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -57,11 +57,12 @@
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if HAS_GRAPHICAL_LCD
|
||||
#if HAS_MARLINUI_U8GLIB
|
||||
|
||||
#include "../../../inc/MarlinConfig.h"
|
||||
#include "../../shared/Delay.h"
|
||||
|
||||
#include <U8glib.h>
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
#include "u8g_com_HAL_DUE_sw_spi_shared.h"
|
||||
|
||||
@@ -108,5 +109,5 @@ void u8g_spiSend_sw_DUE_mode_3(uint8_t val) { // 3.5MHz
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAS_GRAPHICAL_LCD
|
||||
#endif // HAS_MARLINUI_U8GLIB
|
||||
#endif // ARDUINO_ARCH_SAM
|
||||
|
4
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
Executable file → Normal file
4
Marlin/src/HAL/DUE/dogm/u8g_com_HAL_DUE_sw_spi_shared.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../../../inc/MarlinConfigPre.h"
|
||||
#include "../../shared/Marduino.h"
|
||||
#include <U8glib.h>
|
||||
#include <U8glib-HAL.h>
|
||||
|
||||
void u8g_SetPIOutput_DUE(u8g_t *u8g, uint8_t pin_index);
|
||||
void u8g_SetPILevel_DUE(u8g_t *u8g, uint8_t pin_index, uint8_t level);
|
||||
|
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfigPre.h"
|
||||
|
||||
#if ENABLED(EEPROM_SETTINGS)
|
||||
|
||||
#include "../../inc/MarlinConfig.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)
|
||||
#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;
|
||||
}
|
||||
|
||||
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 != 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 c = eeprom_read_byte((uint8_t*)pos);
|
||||
if (writing) *value = c;
|
||||
crc16(crc, &c, 1);
|
||||
pos++;
|
||||
value++;
|
||||
} while (--size);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t PersistentStore::capacity() { return E2END + 1; }
|
||||
|
||||
#endif // EEPROM_SETTINGS
|
||||
#endif // ARDUINO_ARCH_SAM
|
998
Marlin/src/HAL/DUE/eeprom_flash.cpp
Normal file
998
Marlin/src/HAL/DUE/eeprom_flash.cpp
Normal file
@@ -0,0 +1,998 @@
|
||||
/**
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if ENABLED(FLASH_EEPROM_EMULATION)
|
||||
|
||||
/* EEPROM emulation over flash with reduced wear
|
||||
*
|
||||
* We will use 2 contiguous groups of pages as main and alternate.
|
||||
* We want an structure that allows to read as fast as possible,
|
||||
* without the need of scanning the whole FLASH memory.
|
||||
*
|
||||
* FLASH bits default erased state is 1, and can be set to 0
|
||||
* on a per bit basis. To reset them to 1, a full page erase
|
||||
* is needed.
|
||||
*
|
||||
* Values are stored as differences that should be applied to a
|
||||
* completely erased EEPROM (filled with 0xFFs). We just encode
|
||||
* the starting address of the values to change, the length of
|
||||
* the block of new values, and the values themselves. All diffs
|
||||
* are accumulated into a RAM buffer, compacted into the least
|
||||
* amount of non overlapping diffs possible and sorted by starting
|
||||
* address before being saved into the next available page of FLASH
|
||||
* of the current group.
|
||||
* Once the current group is completely full, we compact it and save
|
||||
* it into the other group, then erase the current group and switch
|
||||
* to that new group and set it as current.
|
||||
*
|
||||
* The FLASH endurance is about 1/10 ... 1/100 of an EEPROM
|
||||
* endurance, but EEPROM endurance is specified per byte, not
|
||||
* per page. We can't emulate EE endurance with FLASH for all
|
||||
* bytes, but we can emulate endurance for a given percent of
|
||||
* bytes.
|
||||
*/
|
||||
|
||||
//#define EE_EMU_DEBUG
|
||||
|
||||
#define EEPROMSize 4096
|
||||
#define PagesPerGroup 128
|
||||
#define GroupCount 2
|
||||
#define PageSize 256U
|
||||
|
||||
/* Flash storage */
|
||||
typedef struct FLASH_SECTOR {
|
||||
uint8_t page[PageSize];
|
||||
} FLASH_SECTOR_T;
|
||||
|
||||
#define PAGE_FILL \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, \
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
|
||||
|
||||
#define FLASH_INIT_FILL \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL, \
|
||||
PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL,PAGE_FILL
|
||||
|
||||
/* This is the FLASH area used to emulate a 2Kbyte EEPROM -- We need this buffer aligned
|
||||
to a 256 byte boundary. */
|
||||
static const uint8_t flashStorage[PagesPerGroup * GroupCount * PageSize] __attribute__ ((aligned (PageSize))) = { FLASH_INIT_FILL };
|
||||
|
||||
/* Get the address of an specific page */
|
||||
static const FLASH_SECTOR_T* getFlashStorage(int page) {
|
||||
return (const FLASH_SECTOR_T*)&flashStorage[page*PageSize];
|
||||
}
|
||||
|
||||
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 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);
|
||||
DEBUG_ECHO(buffer);
|
||||
|
||||
char* p = &buffer[0];
|
||||
for (int i = 0; i< PageSize; ++i) {
|
||||
if ((i & 0xF) == 0) p += sprintf_P(p, PSTR("%04x] "), i);
|
||||
|
||||
p += sprintf_P(p, PSTR(" %02x"), c[i]);
|
||||
if ((i & 0xF) == 0xF) {
|
||||
*p++ = '\n';
|
||||
*p = 0;
|
||||
DEBUG_ECHO(buffer);
|
||||
p = &buffer[0];
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
UNUSED(page);
|
||||
UNUSED(data);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Flash Writing Protection Key */
|
||||
#define FWP_KEY 0x5Au
|
||||
|
||||
#if SAM4S_SERIES
|
||||
#define EEFC_FCR_FCMD(value) \
|
||||
((EEFC_FCR_FCMD_Msk & ((value) << EEFC_FCR_FCMD_Pos)))
|
||||
#define EEFC_ERROR_FLAGS (EEFC_FSR_FLOCKE | EEFC_FSR_FCMDE | EEFC_FSR_FLERR)
|
||||
#else
|
||||
#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) {
|
||||
|
||||
uint16_t i;
|
||||
uint32_t addrflash = uint32_t(getFlashStorage(page));
|
||||
|
||||
// Read the flash contents
|
||||
uint32_t pageContents[PageSize>>2];
|
||||
memcpy(pageContents, (void*)addrflash, PageSize);
|
||||
|
||||
// We ONLY want to toggle bits that have changed, and that have changed to 0.
|
||||
// SAM3X8E tends to destroy contiguous bits if reprogrammed without erasing, so
|
||||
// we try by all means to avoid this. That is why it says: "The Partial
|
||||
// Programming mode works only with 128-bit (or higher) boundaries. It cannot
|
||||
// be used with boundaries lower than 128 bits (8, 16 or 32-bit for example)."
|
||||
// All bits that did not change, set them to 1.
|
||||
for (i = 0; i <PageSize >> 2; i++)
|
||||
pageContents[i] = (((uint32_t*)data)[i]) | (~(pageContents[i] ^ ((uint32_t*)data)[i]));
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM PageWrite ", page);
|
||||
DEBUG_ECHOLNPGM(" in FLASH address ", (uint32_t)addrflash);
|
||||
DEBUG_ECHOLNPGM(" 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;
|
||||
uint16_t fpage;
|
||||
if (addrflash >= IFLASH1_ADDR) {
|
||||
efc = EFC1;
|
||||
fpage = (addrflash - IFLASH1_ADDR) / IFLASH1_PAGE_SIZE;
|
||||
}
|
||||
else {
|
||||
efc = EFC0;
|
||||
fpage = (addrflash - IFLASH0_ADDR) / IFLASH0_PAGE_SIZE;
|
||||
}
|
||||
|
||||
// Get the page that must be unlocked, then locked
|
||||
uint16_t lpage = fpage & (~((IFLASH0_LOCK_REGION_SIZE / IFLASH0_PAGE_SIZE) - 1));
|
||||
|
||||
// Disable all interrupts
|
||||
__disable_irq();
|
||||
|
||||
// Get the FLASH wait states
|
||||
uint32_t orgWS = (efc->EEFC_FMR & EEFC_FMR_FWS_Msk) >> EEFC_FMR_FWS_Pos;
|
||||
|
||||
// Set wait states to 6 (SAM errata)
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(6);
|
||||
|
||||
// Unlock the flash page
|
||||
uint32_t status;
|
||||
efc->EEFC_FCR = EEFC_FCR_FKEY(FWP_KEY) | EEFC_FCR_FARG(lpage) | EEFC_FCR_FCMD(EFC_FCMD_CLB);
|
||||
while (((status = efc->EEFC_FSR) & EEFC_FSR_FRDY) != EEFC_FSR_FRDY) {
|
||||
// force compiler to not optimize this -- NOPs don't work!
|
||||
__asm__ __volatile__("");
|
||||
};
|
||||
|
||||
if ((status & EEFC_ERROR_FLAGS) != 0) {
|
||||
|
||||
// Restore original wait states
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(orgWS);
|
||||
|
||||
// Reenable interrupts
|
||||
__enable_irq();
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM Unlock failure for page ", page);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write page and lock: Writing 8-bit and 16-bit data is not allowed and may lead to unpredictable data corruption.
|
||||
const uint32_t * aligned_src = (const uint32_t *) &pageContents[0]; /*data;*/
|
||||
uint32_t * p_aligned_dest = (uint32_t *) addrflash;
|
||||
for (i = 0; i < (IFLASH0_PAGE_SIZE / sizeof(uint32_t)); ++i) {
|
||||
*p_aligned_dest++ = *aligned_src++;
|
||||
}
|
||||
efc->EEFC_FCR = EEFC_FCR_FKEY(FWP_KEY) | EEFC_FCR_FARG(fpage) | EEFC_FCR_FCMD(EFC_FCMD_WPL);
|
||||
while (((status = efc->EEFC_FSR) & EEFC_FSR_FRDY) != EEFC_FSR_FRDY) {
|
||||
// force compiler to not optimize this -- NOPs don't work!
|
||||
__asm__ __volatile__("");
|
||||
};
|
||||
|
||||
if ((status & EEFC_ERROR_FLAGS) != 0) {
|
||||
|
||||
// Restore original wait states
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(orgWS);
|
||||
|
||||
// Reenable interrupts
|
||||
__enable_irq();
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM Write failure for page ", page);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Restore original wait states
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(orgWS);
|
||||
|
||||
// Reenable interrupts
|
||||
__enable_irq();
|
||||
|
||||
// Compare contents
|
||||
if (memcmp(getFlashStorage(page),data,PageSize)) {
|
||||
|
||||
#ifdef EE_EMU_DEBUG
|
||||
DEBUG_ECHO_MSG("EEPROM Verify Write failure for page ", page);
|
||||
|
||||
ee_Dump( page, (uint32_t *)addrflash);
|
||||
ee_Dump(-page, data);
|
||||
|
||||
// Calculate count of changed bits
|
||||
uint32_t *p1 = (uint32_t*)addrflash;
|
||||
uint32_t *p2 = (uint32_t*)data;
|
||||
int count = 0;
|
||||
for (i =0; i<PageSize >> 2; i++) {
|
||||
if (p1[i] != p2[i]) {
|
||||
uint32_t delta = p1[i] ^ p2[i];
|
||||
while (delta) {
|
||||
if ((delta&1) != 0)
|
||||
count++;
|
||||
delta >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
DEBUG_ECHOLNPGM("--> Differing bits: ", count);
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erases the contents of the specified page
|
||||
* @param page (page #)
|
||||
*/
|
||||
__attribute__ ((long_call, section (".ramfunc")))
|
||||
static bool ee_PageErase(uint16_t page) {
|
||||
|
||||
uint16_t i;
|
||||
uint32_t addrflash = uint32_t(getFlashStorage(page));
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM PageErase ", page);
|
||||
DEBUG_ECHOLNPGM(" in FLASH address ", (uint32_t)addrflash);
|
||||
DEBUG_ECHOLNPGM(" 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;
|
||||
uint16_t fpage;
|
||||
if (addrflash >= IFLASH1_ADDR) {
|
||||
efc = EFC1;
|
||||
fpage = (addrflash - IFLASH1_ADDR) / IFLASH1_PAGE_SIZE;
|
||||
}
|
||||
else {
|
||||
efc = EFC0;
|
||||
fpage = (addrflash - IFLASH0_ADDR) / IFLASH0_PAGE_SIZE;
|
||||
}
|
||||
|
||||
// Get the page that must be unlocked, then locked
|
||||
uint16_t lpage = fpage & (~((IFLASH0_LOCK_REGION_SIZE / IFLASH0_PAGE_SIZE) - 1));
|
||||
|
||||
// Disable all interrupts
|
||||
__disable_irq();
|
||||
|
||||
// Get the FLASH wait states
|
||||
uint32_t orgWS = (efc->EEFC_FMR & EEFC_FMR_FWS_Msk) >> EEFC_FMR_FWS_Pos;
|
||||
|
||||
// Set wait states to 6 (SAM errata)
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(6);
|
||||
|
||||
// Unlock the flash page
|
||||
uint32_t status;
|
||||
efc->EEFC_FCR = EEFC_FCR_FKEY(FWP_KEY) | EEFC_FCR_FARG(lpage) | EEFC_FCR_FCMD(EFC_FCMD_CLB);
|
||||
while (((status = efc->EEFC_FSR) & EEFC_FSR_FRDY) != EEFC_FSR_FRDY) {
|
||||
// force compiler to not optimize this -- NOPs don't work!
|
||||
__asm__ __volatile__("");
|
||||
};
|
||||
if ((status & EEFC_ERROR_FLAGS) != 0) {
|
||||
|
||||
// Restore original wait states
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(orgWS);
|
||||
|
||||
// Reenable interrupts
|
||||
__enable_irq();
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM Unlock failure for page ",page);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Erase Write page and lock: Writing 8-bit and 16-bit data is not allowed and may lead to unpredictable data corruption.
|
||||
uint32_t * p_aligned_dest = (uint32_t *) addrflash;
|
||||
for (i = 0; i < (IFLASH0_PAGE_SIZE / sizeof(uint32_t)); ++i) {
|
||||
*p_aligned_dest++ = 0xFFFFFFFF;
|
||||
}
|
||||
efc->EEFC_FCR = EEFC_FCR_FKEY(FWP_KEY) | EEFC_FCR_FARG(fpage) | EEFC_FCR_FCMD(EFC_FCMD_EWPL);
|
||||
while (((status = efc->EEFC_FSR) & EEFC_FSR_FRDY) != EEFC_FSR_FRDY) {
|
||||
// force compiler to not optimize this -- NOPs don't work!
|
||||
__asm__ __volatile__("");
|
||||
};
|
||||
if ((status & EEFC_ERROR_FLAGS) != 0) {
|
||||
|
||||
// Restore original wait states
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(orgWS);
|
||||
|
||||
// Reenable interrupts
|
||||
__enable_irq();
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM Erase failure for page ",page);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Restore original wait states
|
||||
efc->EEFC_FMR = (efc->EEFC_FMR & (~EEFC_FMR_FWS_Msk)) | EEFC_FMR_FWS(orgWS);
|
||||
|
||||
// Reenable interrupts
|
||||
__enable_irq();
|
||||
|
||||
// Check erase
|
||||
uint32_t * aligned_src = (uint32_t *) addrflash;
|
||||
for (i = 0; i < PageSize >> 2; i++) {
|
||||
if (*aligned_src++ != 0xFFFFFFFF) {
|
||||
DEBUG_ECHO_MSG("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) {
|
||||
|
||||
uint32_t baddr;
|
||||
uint32_t blen;
|
||||
|
||||
// If we were requested an address outside of the emulated range, fail now
|
||||
if (address >= EEPROMSize)
|
||||
return false;
|
||||
|
||||
// Check that the value is not contained in the RAM buffer
|
||||
if (!excludeRAMBuffer) {
|
||||
uint16_t i = 0;
|
||||
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
|
||||
// Get the address of the block
|
||||
baddr = buffer[i] | (buffer[i + 1] << 8);
|
||||
|
||||
// Get the length of the block
|
||||
blen = buffer[i + 2];
|
||||
|
||||
// If we reach the end of the list, break loop
|
||||
if (blen == 0xFF)
|
||||
break;
|
||||
|
||||
// Check if data is contained in this block
|
||||
if (address >= baddr &&
|
||||
address < (baddr + blen)) {
|
||||
|
||||
// Yes, it is contained. Return it!
|
||||
return buffer[i + 3 + address - baddr];
|
||||
}
|
||||
|
||||
// As blocks are always sorted, if the starting address of this block is higher
|
||||
// than the address we are looking for, break loop now - We wont find the value
|
||||
// associated to the address
|
||||
if (baddr > address)
|
||||
break;
|
||||
|
||||
// Jump to the next block
|
||||
i += 3 + blen;
|
||||
}
|
||||
}
|
||||
|
||||
// It is NOT on the RAM buffer. It could be stored in FLASH. We are
|
||||
// ensured on a given FLASH page, address contents are never repeated
|
||||
// but on different pages, there is no such warranty, so we must go
|
||||
// backwards from the last written FLASH page to the first one.
|
||||
for (int page = curPage - 1; page >= 0; --page) {
|
||||
|
||||
// Get a pointer to the flash page
|
||||
uint8_t *pflash = (uint8_t*)getFlashStorage(page + curGroup * PagesPerGroup);
|
||||
|
||||
uint16_t i = 0;
|
||||
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
|
||||
// Get the address of the block
|
||||
baddr = pflash[i] | (pflash[i + 1] << 8);
|
||||
|
||||
// Get the length of the block
|
||||
blen = pflash[i + 2];
|
||||
|
||||
// If we reach the end of the list, break loop
|
||||
if (blen == 0xFF)
|
||||
break;
|
||||
|
||||
// Check if data is contained in this block
|
||||
if (address >= baddr && address < (baddr + blen))
|
||||
return pflash[i + 3 + address - baddr]; // Yes, it is contained. Return it!
|
||||
|
||||
// As blocks are always sorted, if the starting address of this block is higher
|
||||
// than the address we are looking for, break loop now - We wont find the value
|
||||
// associated to the address
|
||||
if (baddr > address) break;
|
||||
|
||||
// Jump to the next block
|
||||
i += 3 + blen;
|
||||
}
|
||||
}
|
||||
|
||||
// If reached here, value is not stored, so return its default value
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
static uint32_t ee_GetAddrRange(uint32_t address, bool excludeRAMBuffer=false) {
|
||||
uint32_t baddr,
|
||||
blen,
|
||||
nextAddr = 0xFFFF,
|
||||
nextRange = 0;
|
||||
|
||||
// Check that the value is not contained in the RAM buffer
|
||||
if (!excludeRAMBuffer) {
|
||||
uint16_t i = 0;
|
||||
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
|
||||
// Get the address of the block
|
||||
baddr = buffer[i] | (buffer[i + 1] << 8);
|
||||
|
||||
// Get the length of the block
|
||||
blen = buffer[i + 2];
|
||||
|
||||
// If we reach the end of the list, break loop
|
||||
if (blen == 0xFF) break;
|
||||
|
||||
// Check if address and address + 1 is contained in this block
|
||||
if (address >= baddr && address < (baddr + blen))
|
||||
return address | ((blen - address + baddr) << 16); // Yes, it is contained. Return it!
|
||||
|
||||
// Otherwise, check if we can use it as a limit
|
||||
if (baddr > address && baddr < nextAddr) {
|
||||
nextAddr = baddr;
|
||||
nextRange = blen;
|
||||
}
|
||||
|
||||
// As blocks are always sorted, if the starting address of this block is higher
|
||||
// than the address we are looking for, break loop now - We wont find the value
|
||||
// associated to the address
|
||||
if (baddr > address) break;
|
||||
|
||||
// Jump to the next block
|
||||
i += 3 + blen;
|
||||
}
|
||||
}
|
||||
|
||||
// It is NOT on the RAM buffer. It could be stored in FLASH. We are
|
||||
// ensured on a given FLASH page, address contents are never repeated
|
||||
// but on different pages, there is no such warranty, so we must go
|
||||
// backwards from the last written FLASH page to the first one.
|
||||
for (int page = curPage - 1; page >= 0; --page) {
|
||||
|
||||
// Get a pointer to the flash page
|
||||
uint8_t *pflash = (uint8_t*)getFlashStorage(page + curGroup * PagesPerGroup);
|
||||
|
||||
uint16_t i = 0;
|
||||
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
|
||||
// Get the address of the block
|
||||
baddr = pflash[i] | (pflash[i + 1] << 8);
|
||||
|
||||
// Get the length of the block
|
||||
blen = pflash[i + 2];
|
||||
|
||||
// If we reach the end of the list, break loop
|
||||
if (blen == 0xFF) break;
|
||||
|
||||
// Check if data is contained in this block
|
||||
if (address >= baddr && address < (baddr + blen))
|
||||
return address | ((blen - address + baddr) << 16); // Yes, it is contained. Return it!
|
||||
|
||||
// Otherwise, check if we can use it as a limit
|
||||
if (baddr > address && baddr < nextAddr) {
|
||||
nextAddr = baddr;
|
||||
nextRange = blen;
|
||||
}
|
||||
|
||||
// As blocks are always sorted, if the starting address of this block is higher
|
||||
// than the address we are looking for, break loop now - We wont find the value
|
||||
// associated to the address
|
||||
if (baddr > address) break;
|
||||
|
||||
// Jump to the next block
|
||||
i += 3 + blen;
|
||||
}
|
||||
}
|
||||
|
||||
// If reached here, we will return the next valid address
|
||||
return nextAddr | (nextRange << 16);
|
||||
}
|
||||
|
||||
static bool ee_IsPageClean(int page) {
|
||||
uint32_t *pflash = (uint32_t*) getFlashStorage(page);
|
||||
for (uint16_t i = 0; i < (PageSize >> 2); ++i)
|
||||
if (*pflash++ != 0xFFFFFFFF) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ee_Flush(uint32_t overrideAddress = 0xFFFFFFFF, uint8_t overrideData=0xFF) {
|
||||
|
||||
// Check if RAM buffer has something to be written
|
||||
bool isEmpty = true;
|
||||
uint32_t *p = (uint32_t*) &buffer[0];
|
||||
for (uint16_t j = 0; j < (PageSize >> 2); j++) {
|
||||
if (*p++ != 0xFFFFFFFF) {
|
||||
isEmpty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If something has to be written, do so!
|
||||
if (!isEmpty) {
|
||||
|
||||
// Write the current ram buffer into FLASH
|
||||
ee_PageWrite(curPage + curGroup * PagesPerGroup, buffer);
|
||||
|
||||
// Clear the RAM buffer
|
||||
memset(buffer, 0xFF, sizeof(buffer));
|
||||
|
||||
// Increment the page to use the next time
|
||||
++curPage;
|
||||
}
|
||||
|
||||
// Did we reach the maximum count of available pages per group for storage ?
|
||||
if (curPage < PagesPerGroup) {
|
||||
|
||||
// Do we have an override address ?
|
||||
if (overrideAddress < EEPROMSize) {
|
||||
|
||||
// Yes, just store the value into the RAM buffer
|
||||
buffer[0] = overrideAddress & 0xFF;
|
||||
buffer[0 + 1] = (overrideAddress >> 8) & 0xFF;
|
||||
buffer[0 + 2] = 1;
|
||||
buffer[0 + 3] = overrideData;
|
||||
}
|
||||
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// We have no space left on the current group - We must compact the values
|
||||
uint16_t i = 0;
|
||||
|
||||
// Compute the next group to use
|
||||
int curwPage = 0, curwGroup = curGroup + 1;
|
||||
if (curwGroup >= GroupCount) curwGroup = 0;
|
||||
|
||||
uint32_t rdAddr = 0;
|
||||
do {
|
||||
|
||||
// Get the next valid range
|
||||
uint32_t addrRange = ee_GetAddrRange(rdAddr, true);
|
||||
|
||||
// Make sure not to skip the override address, if specified
|
||||
int rdRange;
|
||||
if (overrideAddress < EEPROMSize &&
|
||||
rdAddr <= overrideAddress &&
|
||||
(addrRange & 0xFFFF) > overrideAddress) {
|
||||
|
||||
rdAddr = overrideAddress;
|
||||
rdRange = 1;
|
||||
}
|
||||
else {
|
||||
rdAddr = addrRange & 0xFFFF;
|
||||
rdRange = addrRange >> 16;
|
||||
}
|
||||
|
||||
// If no range, break loop
|
||||
if (rdRange == 0)
|
||||
break;
|
||||
|
||||
do {
|
||||
|
||||
// Get the value
|
||||
uint8_t rdValue = overrideAddress == rdAddr ? overrideData : ee_Read(rdAddr, true);
|
||||
|
||||
// Do not bother storing default values
|
||||
if (rdValue != 0xFF) {
|
||||
|
||||
// If we have room, add it to the buffer
|
||||
if (buffer[i + 2] == 0xFF) {
|
||||
|
||||
// Uninitialized buffer, just add it!
|
||||
buffer[i] = rdAddr & 0xFF;
|
||||
buffer[i + 1] = (rdAddr >> 8) & 0xFF;
|
||||
buffer[i + 2] = 1;
|
||||
buffer[i + 3] = rdValue;
|
||||
|
||||
}
|
||||
else {
|
||||
// Buffer already has contents. Check if we can extend it
|
||||
|
||||
// Get the address of the block
|
||||
uint32_t baddr = buffer[i] | (buffer[i + 1] << 8);
|
||||
|
||||
// Get the length of the block
|
||||
uint32_t blen = buffer[i + 2];
|
||||
|
||||
// Can we expand it ?
|
||||
if (rdAddr == (baddr + blen) &&
|
||||
i < (PageSize - 4) && /* This block has a chance to contain data AND */
|
||||
buffer[i + 2] < (PageSize - i - 3)) {/* There is room for this block to be expanded */
|
||||
|
||||
// Yes, do it
|
||||
++buffer[i + 2];
|
||||
|
||||
// And store the value
|
||||
buffer[i + 3 + rdAddr - baddr] = rdValue;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
// No, we can't expand it - Skip the existing block
|
||||
i += 3 + blen;
|
||||
|
||||
// Can we create a new slot ?
|
||||
if (i > (PageSize - 4)) {
|
||||
|
||||
// Not enough space - Write the current buffer to FLASH
|
||||
ee_PageWrite(curwPage + curwGroup * PagesPerGroup, buffer);
|
||||
|
||||
// Advance write page (as we are compacting, should never overflow!)
|
||||
++curwPage;
|
||||
|
||||
// Clear RAM buffer
|
||||
memset(buffer, 0xFF, sizeof(buffer));
|
||||
|
||||
// Start fresh */
|
||||
i = 0;
|
||||
}
|
||||
|
||||
// Enough space, add the new block
|
||||
buffer[i] = rdAddr & 0xFF;
|
||||
buffer[i + 1] = (rdAddr >> 8) & 0xFF;
|
||||
buffer[i + 2] = 1;
|
||||
buffer[i + 3] = rdValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next address
|
||||
++rdAddr;
|
||||
|
||||
// Repeat for bytes of this range
|
||||
} while (--rdRange);
|
||||
|
||||
// Repeat until we run out of ranges
|
||||
} while (rdAddr < EEPROMSize);
|
||||
|
||||
// We must erase the previous group, in preparation for the next swap
|
||||
for (int page = 0; page < curPage; page++) {
|
||||
ee_PageErase(page + curGroup * PagesPerGroup);
|
||||
}
|
||||
|
||||
// Finally, Now the active group is the created new group
|
||||
curGroup = curwGroup;
|
||||
curPage = curwPage;
|
||||
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ee_Write(uint32_t address, uint8_t data) {
|
||||
|
||||
// If we were requested an address outside of the emulated range, fail now
|
||||
if (address >= EEPROMSize) return false;
|
||||
|
||||
// Lets check if we have a block with that data previously defined. Block
|
||||
// start addresses are always sorted in ascending order
|
||||
uint16_t i = 0;
|
||||
while (i <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
|
||||
// Get the address of the block
|
||||
uint32_t baddr = buffer[i] | (buffer[i + 1] << 8);
|
||||
|
||||
// Get the length of the block
|
||||
uint32_t blen = buffer[i + 2];
|
||||
|
||||
// If we reach the end of the list, break loop
|
||||
if (blen == 0xFF)
|
||||
break;
|
||||
|
||||
// Check if data is contained in this block
|
||||
if (address >= baddr &&
|
||||
address < (baddr + blen)) {
|
||||
|
||||
// Yes, it is contained. Just modify it
|
||||
buffer[i + 3 + address - baddr] = data;
|
||||
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// Maybe we could add it to the front or to the back
|
||||
// of this block ?
|
||||
if ((address + 1) == baddr || address == (baddr + blen)) {
|
||||
|
||||
// Potentially, it could be done. But we must ensure there is room
|
||||
// so we can expand the block. Lets find how much free space remains
|
||||
uint32_t iend = i;
|
||||
do {
|
||||
uint32_t ln = buffer[iend + 2];
|
||||
if (ln == 0xFF) break;
|
||||
iend += 3 + ln;
|
||||
} while (iend <= (PageSize - 4)); /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
|
||||
// Here, inxt points to the first free address in the buffer. Do we have room ?
|
||||
if (iend < PageSize) {
|
||||
// Yes, at least a byte is free - We can expand the block
|
||||
|
||||
// Do we have to insert at the beginning ?
|
||||
if ((address + 1) == baddr) {
|
||||
|
||||
// Insert at the beginning
|
||||
|
||||
// Make room at the beginning for our byte
|
||||
memmove(&buffer[i + 3 + 1], &buffer[i + 3], iend - i - 3);
|
||||
|
||||
// Adjust the header and store the data
|
||||
buffer[i] = address & 0xFF;
|
||||
buffer[i + 1] = (address >> 8) & 0xFF;
|
||||
buffer[i + 2]++;
|
||||
buffer[i + 3] = data;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
// Insert at the end - There is a very interesting thing that could happen here:
|
||||
// Maybe we could coalesce the next block with this block. Let's try to do it!
|
||||
uint16_t inext = i + 3 + blen;
|
||||
if (inext <= (PageSize - 4) &&
|
||||
(buffer[inext] | uint16_t(buffer[inext + 1] << 8)) == (baddr + blen + 1)) {
|
||||
// YES! ... we can coalesce blocks! . Do it!
|
||||
|
||||
// Adjust this block header to include the next one
|
||||
buffer[i + 2] += buffer[inext + 2] + 1;
|
||||
|
||||
// Store data at the right place
|
||||
buffer[i + 3 + blen] = data;
|
||||
|
||||
// Remove the next block header and append its data
|
||||
memmove(&buffer[inext + 1], &buffer[inext + 3], iend - inext - 3);
|
||||
|
||||
// Finally, as we have saved 2 bytes at the end, make sure to clean them
|
||||
buffer[iend - 2] = 0xFF;
|
||||
buffer[iend - 1] = 0xFF;
|
||||
|
||||
}
|
||||
else {
|
||||
// NO ... No coalescing possible yet
|
||||
|
||||
// Make room at the end for our byte
|
||||
memmove(&buffer[i + 3 + blen + 1], &buffer[i + 3 + blen], iend - i - 3 - blen);
|
||||
|
||||
// And add the data to the block
|
||||
buffer[i + 2]++;
|
||||
buffer[i + 3 + blen] = data;
|
||||
}
|
||||
}
|
||||
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// As blocks are always sorted, if the starting address of this block is higher
|
||||
// than the address we are looking for, break loop now - We wont find the value
|
||||
// associated to the address
|
||||
if (baddr > address) break;
|
||||
|
||||
// Jump to the next block
|
||||
i += 3 + blen;
|
||||
}
|
||||
|
||||
// Value is not stored AND we can't expand previous block to contain it. We must create a new block
|
||||
|
||||
// First, lets find how much free space remains
|
||||
uint32_t iend = i;
|
||||
while (iend <= (PageSize - 4)) { /* (PageSize - 4) because otherwise, there is not enough room for data and headers */
|
||||
uint32_t ln = buffer[iend + 2];
|
||||
if (ln == 0xFF) break;
|
||||
iend += 3 + ln;
|
||||
}
|
||||
|
||||
// If there is room for a new block, insert it at the proper place
|
||||
if (iend <= (PageSize - 4)) {
|
||||
|
||||
// We have room to create a new block. Do so --- But add
|
||||
// the block at the proper position, sorted by starting
|
||||
// address, so it will be possible to compact it with other blocks.
|
||||
|
||||
// Make space
|
||||
memmove(&buffer[i + 4], &buffer[i], iend - i);
|
||||
|
||||
// And add the block
|
||||
buffer[i] = address & 0xFF;
|
||||
buffer[i + 1] = (address >> 8) & 0xFF;
|
||||
buffer[i + 2] = 1;
|
||||
buffer[i + 3] = data;
|
||||
|
||||
// Done!
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not enough room to store this information on this FLASH page - Perform a
|
||||
// flush and override the address with the specified contents
|
||||
return ee_Flush(address, data);
|
||||
}
|
||||
|
||||
static void ee_Init() {
|
||||
|
||||
// Just init once!
|
||||
if (curGroup != 0xFF) return;
|
||||
|
||||
// Clean up the SRAM buffer
|
||||
memset(buffer, 0xFF, sizeof(buffer));
|
||||
|
||||
// Now, we must find out the group where settings are stored
|
||||
for (curGroup = 0; curGroup < GroupCount; curGroup++)
|
||||
if (!ee_IsPageClean(curGroup * PagesPerGroup)) break;
|
||||
|
||||
// If all groups seem to be used, default to first group
|
||||
if (curGroup >= GroupCount) curGroup = 0;
|
||||
|
||||
DEBUG_ECHO_MSG("EEPROM Current Group: ",curGroup);
|
||||
DEBUG_FLUSH();
|
||||
|
||||
// Now, validate that all the other group pages are empty
|
||||
for (int grp = 0; grp < GroupCount; grp++) {
|
||||
if (grp == curGroup) continue;
|
||||
|
||||
for (int page = 0; page < PagesPerGroup; page++) {
|
||||
if (!ee_IsPageClean(grp * PagesPerGroup + page)) {
|
||||
DEBUG_ECHO_MSG("EEPROM Page ", page, " not clean on group ", grp);
|
||||
DEBUG_FLUSH();
|
||||
ee_PageErase(grp * PagesPerGroup + page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, for the active group, determine the first unused page
|
||||
// and also validate that all the other ones are clean
|
||||
for (curPage = 0; curPage < PagesPerGroup; curPage++) {
|
||||
if (ee_IsPageClean(curGroup * PagesPerGroup + curPage)) {
|
||||
ee_Dump(curGroup * PagesPerGroup + curPage, getFlashStorage(curGroup * PagesPerGroup + curPage));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_ECHO_MSG("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)) {
|
||||
DEBUG_ECHO_MSG("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* PersistentStore -----------------------------------------------------------*/
|
||||
|
||||
#include "../shared/eeprom_api.h"
|
||||
|
||||
#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) {
|
||||
uint16_t written = 0;
|
||||
while (size--) {
|
||||
uint8_t * const p = (uint8_t * const)pos;
|
||||
uint8_t v = *value;
|
||||
if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||
ee_Write(uint32_t(p), v);
|
||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||
if (ee_Read(uint32_t(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 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_SAM
|
76
Marlin/src/HAL/DUE/eeprom_wired.cpp
Normal file
76
Marlin/src/HAL/DUE/eeprom_wired.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
||||
#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_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) {
|
||||
uint16_t written = 0;
|
||||
while (size--) {
|
||||
uint8_t * const p = (uint8_t * const)pos;
|
||||
uint8_t v = *value;
|
||||
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||
eeprom_write_byte(p, v);
|
||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||
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 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_SAM
|
70
Marlin/src/HAL/DUE/endstop_interrupts.h
Executable file → Normal file
70
Marlin/src/HAL/DUE/endstop_interrupts.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -47,43 +47,33 @@ 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));
|
||||
TERN_(HAS_I_MAX, _ATTACH(I_MAX_PIN));
|
||||
TERN_(HAS_I_MIN, _ATTACH(I_MIN_PIN));
|
||||
TERN_(HAS_J_MAX, _ATTACH(J_MAX_PIN));
|
||||
TERN_(HAS_J_MIN, _ATTACH(J_MIN_PIN));
|
||||
TERN_(HAS_K_MAX, _ATTACH(K_MAX_PIN));
|
||||
TERN_(HAS_K_MIN, _ATTACH(K_MIN_PIN));
|
||||
TERN_(HAS_U_MAX, _ATTACH(U_MAX_PIN));
|
||||
TERN_(HAS_U_MIN, _ATTACH(U_MIN_PIN));
|
||||
TERN_(HAS_V_MAX, _ATTACH(V_MAX_PIN));
|
||||
TERN_(HAS_V_MIN, _ATTACH(V_MIN_PIN));
|
||||
TERN_(HAS_W_MAX, _ATTACH(W_MAX_PIN));
|
||||
TERN_(HAS_W_MIN, _ATTACH(W_MIN_PIN));
|
||||
}
|
||||
|
15
Marlin/src/HAL/DUE/fastio.h
Executable file → Normal file
15
Marlin/src/HAL/DUE/fastio.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -33,7 +33,7 @@
|
||||
* For ARDUINO_ARCH_SAM
|
||||
* Note the code here was specifically crafted by disassembling what GCC produces
|
||||
* out of it, so GCC is able to optimize it out as much as possible to the least
|
||||
* amount of instructions. Be very carefull if you modify them, as "clean code"
|
||||
* amount of instructions. Be very careful if you modify them, as "clean code"
|
||||
* leads to less efficient compiled code!!
|
||||
*/
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
#define PWM_PIN(P) WITHIN(P, 2, 13)
|
||||
|
||||
#ifndef MASK
|
||||
#define MASK(PIN) (1 << PIN)
|
||||
#define MASK(PIN) _BV(PIN)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -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
|
||||
@@ -163,6 +163,9 @@
|
||||
#define SET_INPUT(IO) _SET_INPUT(IO)
|
||||
// Set pin as input with pullup (wrapper)
|
||||
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
||||
// Set pin as input with pulldown (substitution)
|
||||
#define SET_INPUT_PULLDOWN SET_INPUT
|
||||
|
||||
// Set pin as output (wrapper) - reads the pin and sets the output to that value
|
||||
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
||||
// Set pin as PWM
|
||||
@@ -174,7 +177,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)
|
||||
@@ -477,7 +480,7 @@
|
||||
#define DIO91_PIN 15
|
||||
#define DIO91_WPORT PIOB
|
||||
|
||||
#if ARDUINO_SAM_ARCHIM
|
||||
#ifdef ARDUINO_SAM_ARCHIM
|
||||
|
||||
#define DIO92_PIN 11
|
||||
#define DIO92_WPORT PIOC
|
||||
|
6
Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
Executable file → Normal file
6
Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
* is NOT used to directly toggle pins. The ISR writes to the pin assigned to
|
||||
* that interrupt.
|
||||
*
|
||||
* All PWMs use the same repetition rate. The G2 needs about 10KHz min in order to
|
||||
* All PWMs use the same repetition rate. The G2 needs about 10kHz min in order to
|
||||
* not have obvious ripple on the Vref signals.
|
||||
*
|
||||
* The data structures are setup to minimize the computation done by the ISR which
|
||||
@@ -154,7 +154,7 @@ void Stepper::digipot_init() {
|
||||
NVIC_SetPriority(PWM_IRQn, NVIC_EncodePriority(0, 10, 0)); // normal priority for PWM module (can stand some jitter on the Vref signals)
|
||||
}
|
||||
|
||||
void Stepper::digipot_current(const uint8_t driver, const int16_t current) {
|
||||
void Stepper::set_digipot_current(const uint8_t driver, const int16_t current) {
|
||||
|
||||
if (!(PWM->PWM_CH_NUM[0].PWM_CPRD == PWM_PERIOD_US)) digipot_init(); // Init PWM system if needed
|
||||
|
||||
|
2
Marlin/src/HAL/DUE/fastio/G2_PWM.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/fastio/G2_PWM.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
2
Marlin/src/HAL/DUE/fastio/G2_pins.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/fastio/G2_pins.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
6
Marlin/src/HAL/DUE/inc/Conditionals_LCD.h
Executable file → Normal file
6
Marlin/src/HAL/DUE/inc/Conditionals_LCD.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#if HAS_SPI_TFT || HAS_FSMC_TFT
|
||||
#error "Sorry! TFT displays are not available for HAL/DUE."
|
||||
#endif
|
||||
|
2
Marlin/src/HAL/DUE/inc/Conditionals_adv.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/inc/Conditionals_adv.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
6
Marlin/src/HAL/DUE/inc/Conditionals_post.h
Executable file → Normal file
6
Marlin/src/HAL/DUE/inc/Conditionals_post.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#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
|
||||
|
38
Marlin/src/HAL/DUE/inc/SanityCheck.h
Executable file → Normal file
38
Marlin/src/HAL/DUE/inc/SanityCheck.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -25,6 +25,30 @@
|
||||
* Test Arduino Due specific configuration values for errors at compile-time.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check for common serial pin conflicts
|
||||
*/
|
||||
#define CHECK_SERIAL_PIN(N) ( \
|
||||
X_STOP_PIN == N || Y_STOP_PIN == N || Z_STOP_PIN == N \
|
||||
|| X_MIN_PIN == N || Y_MIN_PIN == N || Z_MIN_PIN == N \
|
||||
|| X_MAX_PIN == N || Y_MAX_PIN == N || Z_MAX_PIN == N \
|
||||
|| X_STEP_PIN == N || Y_STEP_PIN == N || Z_STEP_PIN == N \
|
||||
|| X_DIR_PIN == N || Y_DIR_PIN == N || Z_DIR_PIN == N \
|
||||
|| X_ENA_PIN == N || Y_ENA_PIN == N || Z_ENA_PIN == N \
|
||||
)
|
||||
#if SERIAL_IN_USE(0) // D0-D1. No known conflicts.
|
||||
#endif
|
||||
#if SERIAL_IN_USE(1) && (CHECK_SERIAL_PIN(18) || CHECK_SERIAL_PIN(19))
|
||||
#error "Serial Port 1 pin D18 and/or D19 conflicts with another pin on the board."
|
||||
#endif
|
||||
#if SERIAL_IN_USE(2) && (CHECK_SERIAL_PIN(16) || CHECK_SERIAL_PIN(17))
|
||||
#error "Serial Port 2 pin D16 and/or D17 conflicts with another pin on the board."
|
||||
#endif
|
||||
#if SERIAL_IN_USE(3) && (CHECK_SERIAL_PIN(14) || CHECK_SERIAL_PIN(15))
|
||||
#error "Serial Port 3 pin D14 and/or D15 conflicts with another pin on the board."
|
||||
#endif
|
||||
#undef CHECK_SERIAL_PIN
|
||||
|
||||
/**
|
||||
* HARDWARE VS. SOFTWARE SPI COMPATIBILITY
|
||||
*
|
||||
@@ -40,7 +64,7 @@
|
||||
* Usually the hardware SPI pins are only available to the LCD. This makes the DUE hard SPI used at the same time
|
||||
* as the TMC2130 soft SPI the most common setup.
|
||||
*/
|
||||
#define _IS_HW_SPI(P) (defined(TMC_SW_##P) && (TMC_SW_##P == MOSI_PIN || TMC_SW_##P == MISO_PIN || TMC_SW_##P == SCK_PIN))
|
||||
#define _IS_HW_SPI(P) (defined(TMC_SW_##P) && (TMC_SW_##P == SD_MOSI_PIN || TMC_SW_##P == SD_MISO_PIN || TMC_SW_##P == SD_SCK_PIN))
|
||||
|
||||
#if ENABLED(SDSUPPORT) && HAS_DRIVER(TMC2130)
|
||||
#if ENABLED(TMC_USE_SW_SPI)
|
||||
@@ -52,10 +76,14 @@
|
||||
#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
|
||||
#error "TMC220x Software Serial is not supported on this platform."
|
||||
#error "TMC220x Software Serial is not supported on the DUE platform."
|
||||
#endif
|
||||
|
||||
#if USING_PULLDOWNS
|
||||
#error "PULLDOWN pin mode is not available on DUE boards."
|
||||
#endif
|
||||
|
14
Marlin/src/HAL/DUE/pinsDebug.h
Executable file → Normal file
14
Marlin/src/HAL/DUE/pinsDebug.h
Executable file → Normal file
@@ -2,6 +2,9 @@
|
||||
* 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
|
||||
@@ -13,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -50,7 +53,7 @@
|
||||
* The net result is that both the g_pinStatus[pin] array and the PIO_OSR register
|
||||
* needs to be looked at when determining if a pin is an input or an output.
|
||||
*
|
||||
* b) Due has only pins 6, 7, 8 & 9 enabled for PWMs. FYI - they run at 1KHz
|
||||
* b) Due has only pins 6, 7, 8 & 9 enabled for PWMs. FYI - they run at 1kHz
|
||||
*
|
||||
* c) NUM_DIGITAL_PINS does not include the analog pins
|
||||
*
|
||||
@@ -64,9 +67,10 @@
|
||||
#define PRINT_PORT(p)
|
||||
#define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
|
||||
#define PRINT_PIN_ANALOG(p) do{ sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); SERIAL_ECHO(buffer); }while(0)
|
||||
#define GET_ARRAY_PIN(p) pin_array[p].pin
|
||||
#define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
|
||||
#define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
|
||||
#define VALID_PIN(pin) (pin >= 0 && pin < int8_t(NUMBER_PINS_TOTAL))
|
||||
#define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
|
||||
#define IS_ANALOG(P) WITHIN(P, char(analogInputToDigitalPin(0)), char(analogInputToDigitalPin(NUM_ANALOG_INPUTS - 1)))
|
||||
#define pwm_status(pin) (((g_pinStatus[pin] & 0xF) == PIN_STATUS_PWM) && \
|
||||
@@ -82,11 +86,10 @@ bool GET_PINMODE(int8_t pin) { // 1: output, 0: input
|
||||
|| pwm_status(pin));
|
||||
}
|
||||
|
||||
|
||||
void pwm_details(int32_t pin) {
|
||||
if (pwm_status(pin)) {
|
||||
uint32_t chan = g_APinDescription[pin].ulPWMChannel;
|
||||
SERIAL_ECHOPAIR("PWM = ", PWM_INTERFACE->PWM_CH_NUM[chan].PWM_CDTY);
|
||||
SERIAL_ECHOPGM("PWM = ", PWM_INTERFACE->PWM_CH_NUM[chan].PWM_CDTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,5 +182,4 @@ void pwm_details(int32_t pin) {
|
||||
* ----------------+--------
|
||||
* ID | PB11
|
||||
* VBOF | PB10
|
||||
*
|
||||
*/
|
||||
|
22
Marlin/src/HAL/DUE/spi_pins.h
Executable file → Normal file
22
Marlin/src/HAL/DUE/spi_pins.h
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
@@ -43,22 +43,22 @@
|
||||
#define SPI_PIN 87
|
||||
#define SPI_CHAN 1
|
||||
#endif
|
||||
#define SCK_PIN 76
|
||||
#define MISO_PIN 74
|
||||
#define MOSI_PIN 75
|
||||
#define SD_SCK_PIN 76
|
||||
#define SD_MISO_PIN 74
|
||||
#define SD_MOSI_PIN 75
|
||||
#else
|
||||
// defaults
|
||||
#define DUE_SOFTWARE_SPI
|
||||
#ifndef SCK_PIN
|
||||
#define SCK_PIN 52
|
||||
#ifndef SD_SCK_PIN
|
||||
#define SD_SCK_PIN 52
|
||||
#endif
|
||||
#ifndef MISO_PIN
|
||||
#define MISO_PIN 50
|
||||
#ifndef SD_MISO_PIN
|
||||
#define SD_MISO_PIN 50
|
||||
#endif
|
||||
#ifndef MOSI_PIN
|
||||
#define MOSI_PIN 51
|
||||
#ifndef SD_MOSI_PIN
|
||||
#define SD_MOSI_PIN 51
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* A.28, A.29, B.21, C.26, C.29 */
|
||||
#define SS_PIN SDSS
|
||||
#define SD_SS_PIN SDSS
|
||||
|
37
Marlin/src/HAL/DUE/timers.cpp
Executable file → Normal file
37
Marlin/src/HAL/DUE/timers.cpp
Executable file → Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description: HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*
|
||||
* For ARDUINO_ARCH_SAM
|
||||
* HAL Timers for Arduino Due and compatible (SAM3X8E)
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
@@ -34,8 +32,6 @@
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
#include "HAL.h"
|
||||
|
||||
#include "timers.h"
|
||||
|
||||
// ------------------------
|
||||
// Local defines
|
||||
// ------------------------
|
||||
@@ -46,7 +42,7 @@
|
||||
// Private Variables
|
||||
// ------------------------
|
||||
|
||||
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
|
||||
const tTimerConfig timer_config[NUM_HARDWARE_TIMERS] = {
|
||||
{ TC0, 0, TC0_IRQn, 3}, // 0 - [servo timer5]
|
||||
{ TC0, 1, TC1_IRQn, 0}, // 1
|
||||
{ TC0, 2, TC2_IRQn, 2}, // 2 - stepper
|
||||
@@ -70,9 +66,9 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
|
||||
*/
|
||||
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
Tc *tc = TimerConfig[timer_num].pTimerRegs;
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
uint32_t channel = TimerConfig[timer_num].channel;
|
||||
Tc *tc = timer_config[timer_num].pTimerRegs;
|
||||
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
uint32_t channel = timer_config[timer_num].channel;
|
||||
|
||||
// Disable interrupt, just in case it was already enabled
|
||||
NVIC_DisableIRQ(irq);
|
||||
@@ -90,13 +86,20 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
|
||||
pmc_set_writeprotect(false);
|
||||
pmc_enable_periph_clk((uint32_t)irq);
|
||||
NVIC_SetPriority(irq, TimerConfig [timer_num].priority);
|
||||
NVIC_SetPriority(irq, timer_config[timer_num].priority);
|
||||
|
||||
// wave mode, reset counter on match with RC,
|
||||
TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
|
||||
TC_Configure(tc, channel,
|
||||
TC_CMR_WAVE
|
||||
| TC_CMR_WAVSEL_UP_RC
|
||||
| (HAL_TIMER_PRESCALER == 2 ? TC_CMR_TCCLKS_TIMER_CLOCK1 : 0)
|
||||
| (HAL_TIMER_PRESCALER == 8 ? TC_CMR_TCCLKS_TIMER_CLOCK2 : 0)
|
||||
| (HAL_TIMER_PRESCALER == 32 ? TC_CMR_TCCLKS_TIMER_CLOCK3 : 0)
|
||||
| (HAL_TIMER_PRESCALER == 128 ? TC_CMR_TCCLKS_TIMER_CLOCK4 : 0)
|
||||
);
|
||||
|
||||
// Set compare value
|
||||
TC_SetRC(tc, channel, VARIANT_MCK / 2 / frequency);
|
||||
TC_SetRC(tc, channel, VARIANT_MCK / (HAL_TIMER_PRESCALER) / frequency);
|
||||
|
||||
// And start timer
|
||||
TC_Start(tc, channel);
|
||||
@@ -109,12 +112,12 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
}
|
||||
|
||||
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
NVIC_EnableIRQ(irq);
|
||||
}
|
||||
|
||||
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
NVIC_DisableIRQ(irq);
|
||||
|
||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||
@@ -125,11 +128,11 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
|
||||
|
||||
// missing from CMSIS: Check if interrupt is enabled or not
|
||||
static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
|
||||
return (NVIC->ISER[(uint32_t)(IRQn) >> 5] & (1 << ((uint32_t)(IRQn) & 0x1F))) != 0;
|
||||
return TEST(NVIC->ISER[uint32_t(IRQn) >> 5], uint32_t(IRQn) & 0x1F);
|
||||
}
|
||||
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
|
||||
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
|
||||
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
|
||||
return NVIC_GetEnabledIRQ(irq);
|
||||
}
|
||||
|
||||
|
67
Marlin/src/HAL/DUE/timers.h
Executable file → Normal file
67
Marlin/src/HAL/DUE/timers.h
Executable file → Normal file
@@ -15,15 +15,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 <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* HAL for Arduino Due and compatible (SAM3X8E)
|
||||
*
|
||||
* For ARDUINO_ARCH_SAM
|
||||
* HAL Timers for Arduino Due and compatible (SAM3X8E)
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -37,37 +35,48 @@
|
||||
typedef uint32_t hal_timer_t;
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
|
||||
|
||||
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
|
||||
#define HAL_TIMER_PRESCALER 2
|
||||
#define HAL_TIMER_RATE ((F_CPU) / (HAL_TIMER_PRESCALER)) // frequency of timers peripherals
|
||||
|
||||
#ifndef STEP_TIMER_NUM
|
||||
#define STEP_TIMER_NUM 2 // index of timer to use for stepper
|
||||
#ifndef MF_TIMER_STEP
|
||||
#define MF_TIMER_STEP 2 // Timer Index for Stepper
|
||||
#endif
|
||||
#ifndef MF_TIMER_PULSE
|
||||
#define MF_TIMER_PULSE MF_TIMER_STEP
|
||||
#endif
|
||||
#ifndef MF_TIMER_TEMP
|
||||
#define MF_TIMER_TEMP 4 // Timer Index for Temperature
|
||||
#endif
|
||||
#ifndef MF_TIMER_TONE
|
||||
#define MF_TIMER_TONE 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
|
||||
|
||||
#define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
||||
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
||||
#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
|
||||
#define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
||||
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
||||
#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
|
||||
|
||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
||||
#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() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
|
||||
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
|
||||
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
|
||||
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
|
||||
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
|
||||
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
|
||||
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
|
||||
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
|
||||
|
||||
#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
|
||||
@@ -84,7 +93,7 @@ typedef struct {
|
||||
// Public Variables
|
||||
// ------------------------
|
||||
|
||||
extern const tTimerConfig TimerConfig[];
|
||||
extern const tTimerConfig timer_config[];
|
||||
|
||||
// ------------------------
|
||||
// Public functions
|
||||
@@ -93,17 +102,17 @@ extern const tTimerConfig TimerConfig[];
|
||||
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) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
const tTimerConfig * const pConfig = &timer_config[timer_num];
|
||||
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = compare;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
const tTimerConfig * const pConfig = &timer_config[timer_num];
|
||||
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
|
||||
}
|
||||
|
||||
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
const tTimerConfig * const pConfig = &timer_config[timer_num];
|
||||
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
|
||||
}
|
||||
|
||||
@@ -112,9 +121,9 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num);
|
||||
bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
|
||||
|
||||
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
|
||||
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
|
||||
const tTimerConfig * const pConfig = &timer_config[timer_num];
|
||||
// Reading the status register clears the interrupt flag
|
||||
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;
|
||||
}
|
||||
|
||||
#define HAL_timer_isr_epilogue(TIMER_NUM)
|
||||
#define HAL_timer_isr_epilogue(T) NOOP
|
||||
|
19
Marlin/src/HAL/DUE/upload_extra_script.py
Normal file
19
Marlin/src/HAL/DUE/upload_extra_script.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Set upload_command
|
||||
#
|
||||
# Windows: bossac.exe
|
||||
# Other: leave unchanged
|
||||
#
|
||||
import pioutil
|
||||
if pioutil.is_pio_build():
|
||||
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 $SOURCE"
|
||||
)
|
6
Marlin/src/HAL/DUE/usb/arduino_due_x.h
Executable file → Normal file
6
Marlin/src/HAL/DUE/usb/arduino_due_x.h
Executable file → Normal file
@@ -43,7 +43,7 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
/**
|
||||
* \page arduino_due_x_board_info "Arduino Due/X - Board informations"
|
||||
* \page arduino_due_x_board_info "Arduino Due/X - Board information"
|
||||
* This page lists several definition related to the board description.
|
||||
*
|
||||
*/
|
||||
@@ -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
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
169
Marlin/src/HAL/DUE/usb/compiler.h
Executable file → Normal file
169
Marlin/src/HAL/DUE/usb/compiler.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef UTILS_COMPILER_H
|
||||
@@ -173,11 +173,11 @@
|
||||
# define __always_inline __forceinline
|
||||
#elif (defined __GNUC__)
|
||||
#ifdef __always_inline
|
||||
# undef __always_inline
|
||||
# undef __always_inline
|
||||
#endif
|
||||
# define __always_inline inline __attribute__((__always_inline__))
|
||||
# define __always_inline inline __attribute__((__always_inline__))
|
||||
#elif (defined __ICCARM__)
|
||||
# define __always_inline _Pragma("inline=forced")
|
||||
# define __always_inline _Pragma("inline=forced")
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -188,11 +188,11 @@
|
||||
* heuristics and not inline the function.
|
||||
*/
|
||||
#ifdef __CC_ARM
|
||||
# define __no_inline __attribute__((noinline))
|
||||
# define __no_inline __attribute__((noinline))
|
||||
#elif (defined __GNUC__)
|
||||
# define __no_inline __attribute__((__noinline__))
|
||||
# define __no_inline __attribute__((__noinline__))
|
||||
#elif (defined __ICCARM__)
|
||||
# define __no_inline _Pragma("inline=never")
|
||||
# define __no_inline _Pragma("inline=never")
|
||||
#endif
|
||||
|
||||
/*! \brief This macro is used to test fatal errors.
|
||||
@@ -211,9 +211,9 @@
|
||||
# else
|
||||
#undef TEST_SUITE_DEFINE_ASSERT_MACRO
|
||||
# define Assert(expr) \
|
||||
{\
|
||||
if (!(expr)) while (true);\
|
||||
}
|
||||
{\
|
||||
if (!(expr)) while (true);\
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
# define Assert(expr) ((void) 0)
|
||||
@@ -609,37 +609,37 @@ typedef struct
|
||||
# define clz(u) ((u) ? __CLZ(u) : 32)
|
||||
#else
|
||||
# define clz(u) (((u) == 0) ? 32 : \
|
||||
((u) & (1ul << 31)) ? 0 : \
|
||||
((u) & (1ul << 30)) ? 1 : \
|
||||
((u) & (1ul << 29)) ? 2 : \
|
||||
((u) & (1ul << 28)) ? 3 : \
|
||||
((u) & (1ul << 27)) ? 4 : \
|
||||
((u) & (1ul << 26)) ? 5 : \
|
||||
((u) & (1ul << 25)) ? 6 : \
|
||||
((u) & (1ul << 24)) ? 7 : \
|
||||
((u) & (1ul << 23)) ? 8 : \
|
||||
((u) & (1ul << 22)) ? 9 : \
|
||||
((u) & (1ul << 21)) ? 10 : \
|
||||
((u) & (1ul << 20)) ? 11 : \
|
||||
((u) & (1ul << 19)) ? 12 : \
|
||||
((u) & (1ul << 18)) ? 13 : \
|
||||
((u) & (1ul << 17)) ? 14 : \
|
||||
((u) & (1ul << 16)) ? 15 : \
|
||||
((u) & (1ul << 15)) ? 16 : \
|
||||
((u) & (1ul << 14)) ? 17 : \
|
||||
((u) & (1ul << 13)) ? 18 : \
|
||||
((u) & (1ul << 12)) ? 19 : \
|
||||
((u) & (1ul << 11)) ? 20 : \
|
||||
((u) & (1ul << 10)) ? 21 : \
|
||||
((u) & (1ul << 9)) ? 22 : \
|
||||
((u) & (1ul << 8)) ? 23 : \
|
||||
((u) & (1ul << 7)) ? 24 : \
|
||||
((u) & (1ul << 6)) ? 25 : \
|
||||
((u) & (1ul << 5)) ? 26 : \
|
||||
((u) & (1ul << 4)) ? 27 : \
|
||||
((u) & (1ul << 3)) ? 28 : \
|
||||
((u) & (1ul << 2)) ? 29 : \
|
||||
((u) & (1ul << 1)) ? 30 : \
|
||||
((u) & (1UL << 31)) ? 0 : \
|
||||
((u) & (1UL << 30)) ? 1 : \
|
||||
((u) & (1UL << 29)) ? 2 : \
|
||||
((u) & (1UL << 28)) ? 3 : \
|
||||
((u) & (1UL << 27)) ? 4 : \
|
||||
((u) & (1UL << 26)) ? 5 : \
|
||||
((u) & (1UL << 25)) ? 6 : \
|
||||
((u) & (1UL << 24)) ? 7 : \
|
||||
((u) & (1UL << 23)) ? 8 : \
|
||||
((u) & (1UL << 22)) ? 9 : \
|
||||
((u) & (1UL << 21)) ? 10 : \
|
||||
((u) & (1UL << 20)) ? 11 : \
|
||||
((u) & (1UL << 19)) ? 12 : \
|
||||
((u) & (1UL << 18)) ? 13 : \
|
||||
((u) & (1UL << 17)) ? 14 : \
|
||||
((u) & (1UL << 16)) ? 15 : \
|
||||
((u) & (1UL << 15)) ? 16 : \
|
||||
((u) & (1UL << 14)) ? 17 : \
|
||||
((u) & (1UL << 13)) ? 18 : \
|
||||
((u) & (1UL << 12)) ? 19 : \
|
||||
((u) & (1UL << 11)) ? 20 : \
|
||||
((u) & (1UL << 10)) ? 21 : \
|
||||
((u) & (1UL << 9)) ? 22 : \
|
||||
((u) & (1UL << 8)) ? 23 : \
|
||||
((u) & (1UL << 7)) ? 24 : \
|
||||
((u) & (1UL << 6)) ? 25 : \
|
||||
((u) & (1UL << 5)) ? 26 : \
|
||||
((u) & (1UL << 4)) ? 27 : \
|
||||
((u) & (1UL << 3)) ? 28 : \
|
||||
((u) & (1UL << 2)) ? 29 : \
|
||||
((u) & (1UL << 1)) ? 30 : \
|
||||
31)
|
||||
#endif
|
||||
#endif
|
||||
@@ -654,38 +654,38 @@ typedef struct
|
||||
#if (defined __GNUC__) || (defined __CC_ARM)
|
||||
# define ctz(u) ((u) ? __builtin_ctz(u) : 32)
|
||||
#else
|
||||
# define ctz(u) ((u) & (1ul << 0) ? 0 : \
|
||||
(u) & (1ul << 1) ? 1 : \
|
||||
(u) & (1ul << 2) ? 2 : \
|
||||
(u) & (1ul << 3) ? 3 : \
|
||||
(u) & (1ul << 4) ? 4 : \
|
||||
(u) & (1ul << 5) ? 5 : \
|
||||
(u) & (1ul << 6) ? 6 : \
|
||||
(u) & (1ul << 7) ? 7 : \
|
||||
(u) & (1ul << 8) ? 8 : \
|
||||
(u) & (1ul << 9) ? 9 : \
|
||||
(u) & (1ul << 10) ? 10 : \
|
||||
(u) & (1ul << 11) ? 11 : \
|
||||
(u) & (1ul << 12) ? 12 : \
|
||||
(u) & (1ul << 13) ? 13 : \
|
||||
(u) & (1ul << 14) ? 14 : \
|
||||
(u) & (1ul << 15) ? 15 : \
|
||||
(u) & (1ul << 16) ? 16 : \
|
||||
(u) & (1ul << 17) ? 17 : \
|
||||
(u) & (1ul << 18) ? 18 : \
|
||||
(u) & (1ul << 19) ? 19 : \
|
||||
(u) & (1ul << 20) ? 20 : \
|
||||
(u) & (1ul << 21) ? 21 : \
|
||||
(u) & (1ul << 22) ? 22 : \
|
||||
(u) & (1ul << 23) ? 23 : \
|
||||
(u) & (1ul << 24) ? 24 : \
|
||||
(u) & (1ul << 25) ? 25 : \
|
||||
(u) & (1ul << 26) ? 26 : \
|
||||
(u) & (1ul << 27) ? 27 : \
|
||||
(u) & (1ul << 28) ? 28 : \
|
||||
(u) & (1ul << 29) ? 29 : \
|
||||
(u) & (1ul << 30) ? 30 : \
|
||||
(u) & (1ul << 31) ? 31 : \
|
||||
# define ctz(u) ((u) & (1UL << 0) ? 0 : \
|
||||
(u) & (1UL << 1) ? 1 : \
|
||||
(u) & (1UL << 2) ? 2 : \
|
||||
(u) & (1UL << 3) ? 3 : \
|
||||
(u) & (1UL << 4) ? 4 : \
|
||||
(u) & (1UL << 5) ? 5 : \
|
||||
(u) & (1UL << 6) ? 6 : \
|
||||
(u) & (1UL << 7) ? 7 : \
|
||||
(u) & (1UL << 8) ? 8 : \
|
||||
(u) & (1UL << 9) ? 9 : \
|
||||
(u) & (1UL << 10) ? 10 : \
|
||||
(u) & (1UL << 11) ? 11 : \
|
||||
(u) & (1UL << 12) ? 12 : \
|
||||
(u) & (1UL << 13) ? 13 : \
|
||||
(u) & (1UL << 14) ? 14 : \
|
||||
(u) & (1UL << 15) ? 15 : \
|
||||
(u) & (1UL << 16) ? 16 : \
|
||||
(u) & (1UL << 17) ? 17 : \
|
||||
(u) & (1UL << 18) ? 18 : \
|
||||
(u) & (1UL << 19) ? 19 : \
|
||||
(u) & (1UL << 20) ? 20 : \
|
||||
(u) & (1UL << 21) ? 21 : \
|
||||
(u) & (1UL << 22) ? 22 : \
|
||||
(u) & (1UL << 23) ? 23 : \
|
||||
(u) & (1UL << 24) ? 24 : \
|
||||
(u) & (1UL << 25) ? 25 : \
|
||||
(u) & (1UL << 26) ? 26 : \
|
||||
(u) & (1UL << 27) ? 27 : \
|
||||
(u) & (1UL << 28) ? 28 : \
|
||||
(u) & (1UL << 29) ? 29 : \
|
||||
(u) & (1UL << 30) ? 30 : \
|
||||
(u) & (1UL << 31) ? 31 : \
|
||||
32)
|
||||
#endif
|
||||
#endif
|
||||
@@ -1059,7 +1059,7 @@ static inline void convert_64_bit_to_byte_array(uint64_t value, uint8_t *data)
|
||||
while (val_index < 8)
|
||||
{
|
||||
data[val_index++] = value & 0xFF;
|
||||
value = value >> 8;
|
||||
value >>= 8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1106,17 +1106,16 @@ static inline uint16_t convert_byte_array_to_16_bit(uint8_t *data)
|
||||
/* Converts a 8 Byte array into a 32-Bit value */
|
||||
static inline uint32_t convert_byte_array_to_32_bit(uint8_t *data)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t u32;
|
||||
uint8_t u8[8];
|
||||
}long_addr;
|
||||
uint8_t index;
|
||||
for (index = 0; index < 4; index++)
|
||||
{
|
||||
long_addr.u8[index] = *data++;
|
||||
}
|
||||
return long_addr.u32;
|
||||
union
|
||||
{
|
||||
uint32_t u32;
|
||||
uint8_t u8[8];
|
||||
}long_addr;
|
||||
uint8_t index;
|
||||
for (index = 0; index < 4; index++) {
|
||||
long_addr.u8[index] = *data++;
|
||||
}
|
||||
return long_addr.u32;
|
||||
}
|
||||
|
||||
/**
|
||||
|
2
Marlin/src/HAL/DUE/usb/conf_access.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/conf_access.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef _CONF_ACCESS_H_
|
||||
|
2
Marlin/src/HAL/DUE/usb/conf_clock.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/conf_clock.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_CLOCK_H_INCLUDED
|
||||
|
6
Marlin/src/HAL/DUE/usb/conf_usb.h
Executable file → Normal file
6
Marlin/src/HAL/DUE/usb/conf_usb.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#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)
|
||||
|
2
Marlin/src/HAL/DUE/usb/ctrl_access.c
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/ctrl_access.c
Executable file → Normal file
@@ -53,7 +53,7 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_ARCH_SAM
|
||||
|
2
Marlin/src/HAL/DUE/usb/ctrl_access.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/ctrl_access.h
Executable file → Normal file
@@ -53,7 +53,7 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
|
||||
|
2
Marlin/src/HAL/DUE/usb/genclk.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/genclk.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CHIP_GENCLK_H_INCLUDED
|
||||
|
2
Marlin/src/HAL/DUE/usb/mrepeat.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/mrepeat.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef _MREPEAT_H_
|
||||
|
2
Marlin/src/HAL/DUE/usb/osc.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/osc.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CHIP_OSC_H_INCLUDED
|
||||
|
2
Marlin/src/HAL/DUE/usb/pll.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/pll.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CHIP_PLL_H_INCLUDED
|
||||
|
2
Marlin/src/HAL/DUE/usb/preprocessor.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/preprocessor.h
Executable file → Normal file
@@ -41,7 +41,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef _PREPROCESSOR_H_
|
||||
|
2
Marlin/src/HAL/DUE/usb/sbc_protocol.h
Executable file → Normal file
2
Marlin/src/HAL/DUE/usb/sbc_protocol.h
Executable file → Normal file
@@ -52,7 +52,7 @@
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
* Support and FAQ: visit <a href="https://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
#ifndef _SBC_PROTOCOL_H_
|
||||
#define _SBC_PROTOCOL_H_
|
||||
|
28
Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp
Executable file → Normal file
28
Marlin/src/HAL/DUE/usb/sd_mmc_spi_mem.cpp
Executable file → Normal file
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "../../../sd/cardreader.h"
|
||||
extern "C" {
|
||||
#include "sd_mmc_spi_mem.h"
|
||||
#include "sd_mmc_spi_mem.h"
|
||||
}
|
||||
|
||||
#define SD_MMC_BLOCK_SIZE 512
|
||||
@@ -32,7 +32,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready() {
|
||||
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) {
|
||||
if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted())
|
||||
return CTRL_NO_PRESENT;
|
||||
*nb_sector = card.getSd2Card().cardSize() - 1;
|
||||
*nb_sector = card.diskIODriver()->cardSize() - 1;
|
||||
return CTRL_GOOD;
|
||||
}
|
||||
|
||||
@@ -68,30 +68,30 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
|
||||
{
|
||||
char buffer[80];
|
||||
sprintf_P(buffer, PSTR("SDRD: %d @ 0x%08x\n"), nb_sector, addr);
|
||||
PORT_REDIRECT(0);
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(0));
|
||||
SERIAL_ECHO(buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Start reading
|
||||
if (!card.getSd2Card().readStart(addr))
|
||||
if (!card.diskIODriver()->readStart(addr))
|
||||
return CTRL_FAIL;
|
||||
|
||||
// For each specified sector
|
||||
while (nb_sector--) {
|
||||
|
||||
// Read a sector
|
||||
card.getSd2Card().readData(sector_buf);
|
||||
card.diskIODriver()->readData(sector_buf);
|
||||
|
||||
// RAM -> USB
|
||||
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) {
|
||||
card.getSd2Card().readStop();
|
||||
if (!udi_msc_trans_block(true, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
|
||||
card.diskIODriver()->readStop();
|
||||
return CTRL_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
// Stop reading
|
||||
card.getSd2Card().readStop();
|
||||
card.diskIODriver()->readStop();
|
||||
|
||||
// Done
|
||||
return CTRL_GOOD;
|
||||
@@ -108,29 +108,29 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
|
||||
{
|
||||
char buffer[80];
|
||||
sprintf_P(buffer, PSTR("SDWR: %d @ 0x%08x\n"), nb_sector, addr);
|
||||
PORT_REDIRECT(0);
|
||||
PORT_REDIRECT(SERIAL_PORTMASK(0));
|
||||
SERIAL_ECHO(buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!card.getSd2Card().writeStart(addr, nb_sector))
|
||||
if (!card.diskIODriver()->writeStart(addr, nb_sector))
|
||||
return CTRL_FAIL;
|
||||
|
||||
// For each specified sector
|
||||
while (nb_sector--) {
|
||||
|
||||
// USB -> RAM
|
||||
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, NULL)) {
|
||||
card.getSd2Card().writeStop();
|
||||
if (!udi_msc_trans_block(false, sector_buf, SD_MMC_BLOCK_SIZE, nullptr)) {
|
||||
card.diskIODriver()->writeStop();
|
||||
return CTRL_FAIL;
|
||||
}
|
||||
|
||||
// Write a sector
|
||||
card.getSd2Card().writeData(sector_buf);
|
||||
card.diskIODriver()->writeData(sector_buf);
|
||||
}
|
||||
|
||||
// Stop writing
|
||||
card.getSd2Card().writeStop();
|
||||
card.diskIODriver()->writeStop();
|
||||
|
||||
// Done
|
||||
return CTRL_GOOD;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user