Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clocking API V2 (for thumbv7em) #450

Merged
merged 236 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
236 commits
Select commit Hold shift + click to select a range
af2873a
Baseline of clocking API v2
bradleyharden Mar 15, 2021
e72be6b
Iteration of improvements (1)
bradleyharden Apr 24, 2021
eca195a
Dpll: Fix frequency calculation
vcchtjader May 10, 2021
739acb1
Dpll: Synchronized writes
vcchtjader May 10, 2021
ddda999
Gclk: Synchronized writes
vcchtjader May 10, 2021
84e0130
Xosc: Implementation and exposed tokens
vcchtjader May 18, 2021
0e4307e
Xosc32k: Implementation and exposed tokens
vcchtjader May 18, 2021
dfb94e1
OscUlp32k: Implementation and exposed tokens
vcchtjader May 18, 2021
0a66569
Gclk: Documentation & divider selection
vcchtjader May 25, 2021
cef9b76
Dfll: open & closed loop mode support
glaeqen May 3, 2021
03c2aac
Replace in-place instance counter types with a wrapper based solution
glaeqen May 11, 2021
93cbb60
Global rename of \w*SourceType -> $1SourceMarker
glaeqen May 25, 2021
a4be189
Create GclkOutSource and GclkOutSourceMarker and replace direct Count…
glaeqen May 25, 2021
ff08689
Counted: Removed `Deref` implementation for `Counted`
glaeqen May 26, 2021
cea0f96
Move: /typelevel/counted.rs -> /thumbv7em/clock/types.rs
glaeqen May 26, 2021
5c2ec1f
Move: clock-only related types and traits to clock/types.rs
glaeqen May 26, 2021
597a5c7
Global rename of `Counted` to `Enabled`
glaeqen May 26, 2021
15c5690
Refactor `Enabled::new_unsafe` into `Enabled::new`
glaeqen May 26, 2021
f40535c
Rename `pol` to `polarity`
glaeqen May 26, 2021
ef4f580
Rename `Pclk::new` to `Pclk::enable`, marked the hack for removal later
glaeqen May 26, 2021
21fcaed
GclkOut: GclkOut::new -> GclkOut::enable
glaeqen May 26, 2021
a389597
Dfll: Dfll::to_{open, closed}_mode() take `Enabled<Gclk0<..>>` instea…
glaeqen May 26, 2021
097df4c
Update `OscUlp32k` to support `Enabled` wrapper type
vcchtjader May 27, 2021
6bbadef
Update `Xosc` to support `Enabled` wrapper type
vcchtjader May 27, 2021
e494cdf
Update `Xosc32k` to support `Enabled` wrapper type
vcchtjader May 27, 2021
c989894
Xosc, Xosc32k: Fix wrong enum variant + type constraints for trait impls
glaeqen May 27, 2021
8652b2e
Fix `Gclk0::swap()`: Missing HW call through `Gclk::enable()`
vcchtjader May 27, 2021
7df50d4
GclkOut: Add `NotGclkInput` trait + impl it on relevant `GclkSourceMa…
glaeqen May 31, 2021
61d32d6
Rename: `Register` to `*Token`
glaeqen May 31, 2021
2c1d24e
Join the same implementation blocks
glaeqen May 31, 2021
a4a1358
Dpll: Support all sources
vcchtjader Jun 4, 2021
43ec2af
Pclk: Remove previous free-Pclk hack
vcchtjader Jun 4, 2021
30cbc21
Dfll: Set hardware enable
vcchtjader Jun 4, 2021
fb2ba69
Xosc: Formatting
vcchtjader Jun 4, 2021
0a0f7d9
Xosc32k: Add required `fn freq()`
vcchtjader Jun 4, 2021
7354489
Dpll: Rename field `Dpll::freq` to `Dpll::src_freq`
glaeqen Jun 7, 2021
125d7fa
Dpll: Refactor predivider evaluation mechanism
glaeqen Jun 7, 2021
90881f1
Dpll: Rename `fn free_*()` to `fn free()`
glaeqen Jun 7, 2021
3350035
clock/v1: Add v2-to-v1 clocking API compatibility layer
glaeqen Jun 7, 2021
3adeb07
clock/v2: Rename `Tokens::new` to `retrieve_tokens`; flatten `sources…
glaeqen Jun 7, 2021
7080440
clock/v2: Unify calls to `Enabled::new`
glaeqen Jun 7, 2021
889a931
Gclk: Improve GclkDiv, cleanup documentation
vcchtjader Jun 9, 2021
7061f7b
Dpll: Fix Pclk link in documentation
vcchtjader Jun 9, 2021
7b45cae
Gclk: Simplify GclkDividerParts and remove Debug
vcchtjader Jun 10, 2021
829f3d9
clock/v2: Remove re-exports of modules
glaeqen Jun 10, 2021
eb29d9f
Gclk: Store GclkDivider as part of Gclk
vcchtjader Jun 10, 2021
c231495
Gclk: Remove redundant associated type in GclkDivider
vcchtjader Jun 10, 2021
2518334
Rustfmt: According to .rustfmt.toml
vcchtjader Jun 11, 2021
b38aff8
Xosc: Move hardware calls to enable, improve documentation
vcchtjader Jun 11, 2021
e75cede
clock/v2: Add MVP documentation for main v2 module
glaeqen Jun 11, 2021
61d9a2f
Xosc: Removed faulty doc comment
glaeqen Jun 11, 2021
78e4d98
clock/v2: Macro-based presets with ready-to-use clocking configurations
glaeqen Jun 11, 2021
bd29c1e
clock/v2: Improve doc comments
glaeqen Jun 16, 2021
5840826
Xosc32k: Move hardware calls into enable function
vcchtjader Jun 15, 2021
773b556
Rtc: Move and change Rtc traits
vcchtjader Jun 24, 2021
00a942b
Xosc32k: Reworked and documented, tracks 32k and 1k
vcchtjader Jun 19, 2021
3f6f893
Osculp32k: Reworked and documented, tracks 32k and 1k
vcchtjader Jun 24, 2021
9d670e2
Dpll: Comment out assertion, fix frequency calculation
glaeqen Jun 21, 2021
0db5fc4
Apb: Remove `PhantomData<*const ()> field from `apb::Registers`
glaeqen Jun 23, 2021
5cfd9ee
Ahb: Remove `PhantomData<*const ()> field from `ahb::Registers`
glaeqen Jul 7, 2021
6bf7675
Osculp32k, Xosc32k, RTC: Rename output mode types and methods
glaeqen Jul 7, 2021
143602e
Apb: Add documentation
glaeqen Jul 7, 2021
6e1cedb
Ahb: Add documentation
glaeqen Jul 7, 2021
739cd9c
Dfll: Fix incorrect synchronisation
glaeqen Jul 8, 2021
a8e2829
Dfll: Aggregate mode specific HW registers writes
glaeqen Jul 8, 2021
0c3af99
Dfll: Remove redundant allow(dead_code) attributes
glaeqen Jul 8, 2021
727f3f4
Dfll: Add documentation
glaeqen Jul 8, 2021
6d31f05
clock/*: Fix imports broken by `854e3e1dc` commit after a rebase
glaeqen Jul 12, 2021
2554a1b
Xosc32k: Symmetry for clock outputs with Osculp32k
vcchtjader Jul 14, 2021
3cc571e
Osculp32k: Small documentation improvements
vcchtjader Jul 14, 2021
1b0cb95
Gclk,GclkIo: Documentation
vcchtjader Jul 19, 2021
a7f52c1
Pclk: Documentation
vcchtjader Jul 19, 2021
718bd65
Dpll: Introduce mode dependent enable calls
glaeqen Jul 19, 2021
b193f29
Dpll: Fix unsound `from_xosc{32k,} constructors by `DpllSource` trait…
glaeqen Jul 19, 2021
252d5a6
clock/v2/presets: Improve imports and doc-tests
glaeqen Jul 21, 2021
97d25ed
clock/v2: Fix "KHz" typo
glaeqen Jul 21, 2021
102d25a
Dpll: Documentation
glaeqen Jul 21, 2021
a2533c3
GclkIo: Correct doc-tests in module level docs
glaeqen Jul 22, 2021
6ad6815
Dfll: Documentation fix
glaeqen Jul 22, 2021
cbe1583
Pclk: Documentation (module level + small improvements)
glaeqen Jul 22, 2021
b657635
Osculp32k: Make `OscUlp32kToken` unconstructable
glaeqen Sep 9, 2021
732fe3a
clock/v2: Remove `osc_ulp_32k` token
glaeqen Sep 9, 2021
10937c3
Osculp32k: Add documentation
glaeqen Sep 9, 2021
c4d0e70
Osculp32k, Xosc32k: Remove support for a write lock
glaeqen Sep 9, 2021
1aba67c
Gclkio, Pclk: Typos in documentation
glaeqen Sep 9, 2021
c32bc9f
Xosc32k: Add documentation; (Osculp32k: typo)
glaeqen Sep 9, 2021
97a6d12
Clippy fixes and fmt
vcchtjader Sep 29, 2021
46f672e
Gclk: Remove unnecessary public import
glaeqen Oct 5, 2021
310a543
clock: Remove unnecessary example function
glaeqen Oct 5, 2021
b79f9ff
clock/v2: Add documentation
glaeqen Oct 5, 2021
c3c38e4
clock/v1: Change module documentation
glaeqen Oct 5, 2021
7fa94a1
clock/types: Add documentation
glaeqen Oct 5, 2021
a45a782
clock: Move `types` module to `v2`
glaeqen Oct 6, 2021
a529402
clock/v2: Simplify namespacing and imports in an example code
glaeqen Oct 6, 2021
d3a89b6
clock/{v1,v2,v2/types}: Documentation improvements
glaeqen Oct 6, 2021
2529d67
clock/v2: Introduction of `marker` module (step 1)
glaeqen Oct 6, 2021
4f8665d
Rtc: Added unsafe to `fn unset_*` to improve soundness (WiP)
glaeqen Oct 6, 2021
2d30a1b
clock/v2: Introduction of `marker` module - rename `DpllSrc` to `Dpll…
glaeqen Oct 6, 2021
1593064
clock/v2: Introduction of `marker` module (continuation)
glaeqen Oct 6, 2021
cd0bc31
clock/{v2,v2/types}: Documentation improvements
glaeqen Oct 6, 2021
33083d9
clock/v2: Introduction of `marker` module (continuation - gclk)
glaeqen Oct 6, 2021
36d6308
clock/v2: Introduction of `marker` module (finished gclk)
glaeqen Oct 6, 2021
094145d
Dpll: Documentation improvements
glaeqen Oct 7, 2021
27bde97
Gclk: Documentation improvements
glaeqen Oct 7, 2021
4ad11d2
Xosc32k: Documentation improvements
glaeqen Oct 7, 2021
a60d2d4
Xosc: Add documentation & introduce `marker` module
glaeqen Oct 7, 2021
6681abd
Dfll: Remove custom fine and coarse support (open mode)
glaeqen Oct 8, 2021
27150ff
Rtc: Type-safe wrapper type for clocking-v2 based Rtc + docs
glaeqen Oct 8, 2021
159725a
clock/v2: Documentation improvements
glaeqen Oct 8, 2021
e45b724
clock/v2: Remove redundant `missing_docs` attributes
glaeqen Oct 8, 2021
13a7764
Dpll: Documentation fix
glaeqen Oct 8, 2021
220cedf
Gclk: Documentation improvements
glaeqen Oct 8, 2021
7ee3729
Gclkio: Documentation improvements
glaeqen Oct 8, 2021
6f0c7c8
clock/v2: Fix formatting
glaeqen Oct 8, 2021
d7c134a
Dfll: Remove TODO
glaeqen Oct 11, 2021
06f56b1
Dpll: Split `Dpll::enable` into `enable` and `force_enable`
glaeqen Oct 11, 2021
cb0a0eb
Dpll: Remove HW register writes outside of `enable`/`disable`
glaeqen Oct 11, 2021
91130ff
Xosc: Add TODO comment
glaeqen Oct 11, 2021
737b364
clock/v2: Add missing #[inline] attributes
glaeqen Oct 11, 2021
378f898
Dpll: Fix formatting
glaeqen Oct 11, 2021
e1b85f4
Dpll, presets: Make `cargo test --doc` pass
glaeqen Oct 11, 2021
4a5bb00
Dpll: Fix assertion in `Dpll::enable`
glaeqen Oct 13, 2021
b355d90
Rtc: Remove 32kHz clock mode constructor variant
glaeqen Oct 13, 2021
3b971ed
Rtc: Fix frequency values passed in to `InnerRtc` constructors
glaeqen Oct 13, 2021
c3c3126
Xosc: Separate frequency validation from Xosc::from_crystal()
vcchtjader Oct 13, 2021
744d9ce
Feather M4: Add clocking v2 API example
glaeqen Oct 13, 2021
d6ad687
Xosc: CrystalConfig: Impossible constructor fixed
vcchtjader Oct 14, 2021
401088f
clock/v2: Fix Rust 2021 incompatible prefixed identifies
glaeqen Nov 2, 2021
44194e3
Dpll, Xosc: Expose "wait for state" fns on `Enabled` type with nb::Re…
glaeqen Nov 10, 2021
3c7e660
Typelevel: Remove TODO
glaeqen Nov 10, 2021
4104e7a
clock/v2: Fix formatting
glaeqen Nov 10, 2021
e30d491
clock/v2: Migrate counting traits to the typelevel module
bradleyharden Nov 28, 2021
80be0f0
clock/v2: Rename identity types for consistency
bradleyharden Nov 28, 2021
001d2c0
clock/v2: Move `Enabled` from types module to top-level
bradleyharden Nov 28, 2021
d096d6d
clock/v2: Consolidate `*Source` traits into single `Driver` trait
bradleyharden Nov 28, 2021
2c5825f
Rtc: Overhaul `rtc` module to simplify the design
bradleyharden Nov 29, 2021
34949b0
Xosc: Simplify the `xosc` module
bradleyharden Nov 29, 2021
98bc516
clock/v2: Update 1 kHz, 32 kHz and RTC clocks
bradleyharden Dec 4, 2021
8f2ab71
Xosc: Update `xosc::Mode` and `xosc::CrystalCurrent`
bradleyharden Dec 4, 2021
3415973
clock/v2: Refactor `dpll` module
bradleyharden Dec 13, 2021
65702a9
clock/v2: Rename `Driver`/`Source` to `Source`/`Id`
bradleyharden Dec 13, 2021
91c7827
clock/v2: Refactor the `dfll` module
bradleyharden Dec 13, 2021
38733d3
rtcosc: Add documentation for the `rtcosc` module
bradleyharden Dec 13, 2021
d8133de
gclk: Remove `NotGclk1` traits
bradleyharden Dec 14, 2021
224344f
dpll: Rename `Dpll::from_xosc` for each `Xosc`
bradleyharden Dec 14, 2021
0539ad4
clock/2: Overhaul preset clock configurations
bradleyharden Dec 19, 2021
19cfd74
clock/v2: Set default `Counter` type `N = U0` for `Enabled<T, N>`
bradleyharden Dec 25, 2021
d41f8ad
clock/v2: Add `Enabled` type aliases
bradleyharden Dec 25, 2021
974d8bf
clock/v2: Rename sequentially defined `Id` types
bradleyharden Dec 25, 2021
1173158
gclk: Add custom `DynGclkSourceId` type
bradleyharden Dec 26, 2021
e508fc4
clock/v2: Use consistent type parameter names
bradleyharden Dec 26, 2021
c7ed62a
gclk: Add missing wait_syncbusy to improve_duty_cycle
bradleyharden Jan 7, 2022
0d7dcd6
dpll: Add on_demand
bradleyharden Jan 7, 2022
d69dc4c
clock/v2: Remove unnecessary `unsafe` blocks
bradleyharden Jan 7, 2022
7eba037
clock/v2: Remove documentation warnings
bradleyharden Jan 7, 2022
3744ab9
clock/v2: Consolidate ahb, apb and pclk peripheral types
bradleyharden Dec 27, 2021
2aff08d
clock_v2: Refactor `ahb` and `apb` modules
bradleyharden Dec 28, 2021
afc964d
pclk: Make `ids` module public
bradleyharden Jan 7, 2022
cee7703
Fix bugs when dealing with GCLK0
bradleyharden Jan 24, 2022
770e18f
clock_v2: Remove preset configurations
bradleyharden Jan 29, 2022
ded6b91
clock_v2: Update reset state structs and documentation
bradleyharden Jan 30, 2022
b4da3c1
Fix formatting problems
bradleyharden Jan 30, 2022
45ff70e
clock_v2: Repair `feather_m4` example
bradleyharden Jan 30, 2022
27ee5a9
Update module paths from (sercom|gpio)::v2 to (sercom|gpio)
glaeqen Jun 3, 2022
f6c21b3
clock/v2: Fix doc-tests
glaeqen Jun 3, 2022
f7b7d85
Feather M4: Fix broken example
glaeqen Jun 9, 2022
22ed27a
clock/v2: Squashed changes before the back-merge
glaeqen Oct 20, 2022
ec9f305
dpll: Fix prediv bug
bradleyharden Jun 19, 2022
4685e95
Fix feather_m4 example
bradleyharden Jun 19, 2022
7708eaf
Fix errors introduced in merge commit
bradleyharden Jun 21, 2022
438efb9
Add additional documentation
bradleyharden Jun 21, 2022
1238eeb
Further update the clock::v2 documentation
bradleyharden Jul 6, 2022
1107fc2
Flesh out gclk documentation
bradleyharden Jul 6, 2022
ad4ded1
gclk: Rename gclk::Tokens, GclkDiv and Gclk1Div
bradleyharden Jul 16, 2022
11381a3
gclk: Fix typo
bradleyharden Jul 16, 2022
d567557
Fix feather_m4 example
bradleyharden Jul 16, 2022
fb4f291
gclk: Fix documentation typos
bradleyharden Jul 17, 2022
c77740e
dpll: Improve naming consistency and add documentation
bradleyharden Jul 17, 2022
f7dc28b
Improve language and explanations throughout
bradleyharden Jul 17, 2022
e476f9c
gclk: Correct missed changes in previous edits
bradleyharden Jul 18, 2022
21b5f42
pclk: Add documentation
bradleyharden Jul 18, 2022
7412650
Update main documentation based on feedback
bradleyharden Aug 6, 2022
cb4d8c5
dpll: Add enable_unchecked and remove unnecessary trait bound
bradleyharden Aug 6, 2022
d2293cf
dpll: Fix typo
bradleyharden Aug 6, 2022
ee4e8b7
gclk: Fixe typo and change EnabledGclk0 default N = U1
bradleyharden Aug 6, 2022
10c3908
Fix typo and improve documentation
bradleyharden Aug 6, 2022
5d2fef4
gclk: Refactor handling of GCLK_IO and update documentation
bradleyharden Aug 7, 2022
78f042a
Refactor `dpll` to match `gclk` and update docs throughout
bradleyharden Sep 4, 2022
e38f0cb
xosc: Update module to improve naming and handle more cases
bradleyharden Sep 4, 2022
e2e8844
xosc: Finalize `xosc` module and update docs & examples
bradleyharden Sep 5, 2022
38cf00f
dpll: Fix minor documentation issues
bradleyharden Sep 5, 2022
73258b9
xosc: Fix minor issues
bradleyharden Sep 10, 2022
f2f5f5b
Update 32 kHz oscillator modules and documentation
bradleyharden Sep 10, 2022
df0ed45
Update feather_m4
bradleyharden Sep 10, 2022
7a4c944
Fix minor documentation issues
bradleyharden Sep 11, 2022
2457202
Update AHB and APB module documentation
bradleyharden Sep 11, 2022
86d64d4
clock/v1: Patched missing feature gates
glaeqen Oct 20, 2022
5f5c661
clock/v2: PB14 does not exist on same51g
glaeqen Oct 20, 2022
962d298
clock/v2: Remove redundant `Counter` type
bradleyharden Oct 21, 2022
cb72e92
clock/v2: Refactor `Counter` type references in documentation
glaeqen Oct 24, 2022
f7b134f
Xosc32k: Fixed doc-tests
glaeqen Oct 24, 2022
41252c6
Dpll: Incorrect panic condition
glaeqen Oct 27, 2022
0e3fae8
Dfll: Mode handling refactored, added USB based closed loop mode support
glaeqen Oct 21, 2022
692f0ee
Dfll: Module documentation
glaeqen Oct 24, 2022
5b8fea0
dfll: Draft of new API
bradleyharden Nov 26, 2022
0cbc03e
dfll: Only store required settings
bradleyharden Nov 29, 2022
b2286b5
dfll: Refactor settings and improve naming
bradleyharden Nov 29, 2022
6d83610
dfll: Refactor and document settings code
bradleyharden Dec 2, 2022
407346d
dfll: Improve wording in docs
bradleyharden Dec 2, 2022
cec7057
dfll: Store Pclk instead of dropping and recreating
bradleyharden Dec 2, 2022
e0f8457
dfll: Store Pclk in the settings structs
bradleyharden Dec 2, 2022
540bdc7
Improve documentation of unsafe code
bradleyharden Dec 3, 2022
96ff6cc
dfll: Add more documentation
bradley-harden-apl Dec 3, 2022
7001f78
ahb: Fix documentation typo
bradleyharden Dec 4, 2022
9e2aa33
dpll: Make minor doc improvement
bradleyharden Dec 4, 2022
0ccc484
clock: Fix failing doc tests and broken doc links
bradleyharden Dec 4, 2022
6f81e29
dfll: Fix typos and improve docs
bradleyharden Dec 4, 2022
7ebbd61
Add missing documentation for Buses
bradleyharden Dec 4, 2022
152f8a8
Update and remove `unsafe` code
bradleyharden Dec 4, 2022
62c9cba
dpll: Refactor dpll module to mimic dfll
bradleyharden Dec 4, 2022
965ab0d
dpll: Simplify settings implementation
bradleyharden Dec 5, 2022
acaa968
gclk: Refactor GclkOut
bradleyharden Dec 5, 2022
29b5864
dpll: Reduce naming ambiguity
bradleyharden Dec 5, 2022
d0a7e15
gclk: Refactor gclk to store pins and consolidate settings
bradleyharden Dec 5, 2022
25de379
dfll: Add complete example to docs
bradleyharden Dec 5, 2022
94a0dff
rtcosc: Add rtcosc documentation
bradleyharden Dec 5, 2022
950f72e
Fix feather_m4 example
bradleyharden Dec 5, 2022
054a9ef
dfll: Change how to reconfigure an EnabledDfll
bradleyharden Dec 5, 2022
6826985
clock/v2: Fix broken documentation link
glaeqen Dec 6, 2022
45e98d4
dfll: Attempt to refactor EnabledDfll::reconfigure
bradleyharden Dec 7, 2022
f2c9507
dfll: Further refactor to improve EnabledDfll::into_mode
bradleyharden Dec 7, 2022
b0f03ae
Remove macro in `dpll` and improve naming consistency
bradleyharden Dec 17, 2022
396bc5e
dfll: Update documentation
bradleyharden Dec 17, 2022
f6eddd6
clock/v2: Fix formatting
glaeqen Dec 19, 2022
5f3caa5
Bump MSRV because of GATs used
glaeqen Dec 20, 2022
ccd47cb
clock/v2: Remove dead code and unnecessary allow attributes
bradleyharden Dec 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/feather_m4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ optional = true
[dev-dependencies]
cortex-m = "0.7"
usbd-serial = "0.1"
cortex-m-rtic = "0.6.0-rc.2"
panic-halt = "0.2"
panic-semihosting = "0.5"
smart-leds = "0.3"
Expand Down
171 changes: 171 additions & 0 deletions boards/feather_m4/examples/clocking_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#![no_main]
#![no_std]

use panic_halt as _;

use core::fmt::Write as _;

use atsamd_hal::{
clock::v2::{
self as clock,
dpll::Dpll,
gclk::{Gclk, GclkDiv16, GclkDiv8},
osculp32k::OscUlp32k,
pclk::Pclk,
rtcosc::RtcOsc,
xosc32k::{ControlGainMode, Xosc1k, Xosc32k, Xosc32kBase},
},
ehal::serial::Read as _,
ehal::serial::Write,
gpio::{Pins, PA04, PA05},
rtc::{ClockMode, Rtc},
sercom::{
uart::{self, BaudMode, Flags, Oversampling},
IoSet3, Sercom0,
},
time::U32Ext,
};

use rtic::app;

type Pads = uart::PadsFromIds<Sercom0, IoSet3, PA05, PA04>;
type Uart = uart::Uart<uart::Config<Pads>, uart::Duplex>;

#[app(device = atsamd_hal::pac, peripherals = true)]
mod app {
use super::*;

#[shared]
struct SharedResources {
uart: Uart,
rtc: Rtc<ClockMode>,
}

#[local]
struct LocalResources {}

#[init]
fn init(cx: init::Context) -> (SharedResources, LocalResources, init::Monotonics()) {
let mut device = cx.device;

// Get the clocks & tokens
let (_buses, clocks, tokens) = clock::clock_system_at_reset(
device.OSCCTRL,
device.OSC32KCTRL,
device.GCLK,
device.MCLK,
&mut device.NVMCTRL,
);

// This is required because the `sercom` and `rtc` modules have not yet
// been update to use `clock::v2`
let (_, _, _, mut mclk) = unsafe { clocks.pac.steal() };

// Get the pins
let pins = Pins::new(device.PORT);

// Take `Dfll` 48 MHz, divide down to `2 MHz` through `Gclk1`
let (gclk1, dfll) = Gclk::from_source(tokens.gclks.gclk1, clocks.dfll);
let gclk1 = gclk1.div(GclkDiv16::Div(24)).enable();

// Output `Gclk1` on PB15 pin
let (gclk1, _gclk1_out) = gclk1.enable_gclk_out(pins.pb15);

// Setup a peripheral channel to power up `Dpll0` from `Gclk1`
let (pclk_dpll0, gclk1) = Pclk::enable(tokens.pclks.dpll0, gclk1);

// Configure `Dpll0` with `2 * 60 + 0/32 = 120 MHz` frequency
let dpll0 = Dpll::from_pclk(tokens.dpll0, pclk_dpll0)
.loop_div(60, 0)
.enable();

// Swap source of `Gclk0` from Dfll to Dpll0, `48 Mhz -> 120 MHz`
let (gclk0, _dfll, _dpll0) = clocks.gclk0.swap_sources(dfll, dpll0);

// Output `Gclk0` on pin PB14
let (gclk0, _gclk0_out) = gclk0.enable_gclk_out(pins.pb14);

// Setup a peripheral channel to power up `Dpll1` from `Gclk1`
let (pclk_dpll1, _gclk1) = Pclk::enable(tokens.pclks.dpll1, gclk1);

// Configure `Dpll1` with `2 * 50 + 0/32 = 100 MHz` frequency
let dpll1 = Dpll::from_pclk(tokens.dpll1, pclk_dpll1)
.loop_div(50, 0)
.enable();

// Output `Dpll1` on PB20 pin via `Gclk6`, divided by 200 resulting in 0.5 MHz
// output frequency
let (gclk6, _dpll1) = Gclk::from_source(tokens.gclks.gclk6, dpll1);
let gclk6 = gclk6.div(GclkDiv8::Div(200)).enable();
let (_gclk6, _gclk6_out) = gclk6.enable_gclk_out(pins.pb12);

// Configure `Xosc32k` with both outputs (1kHz, 32kHz) activated
let xosc32k_base = Xosc32kBase::from_crystal(tokens.xosc32k.base, pins.pa00, pins.pa01)
.control_gain_mode(ControlGainMode::HighSpeed)
.on_demand(false)
.run_standby(true)
.enable();
let (xosc1k, xosc32k_base) = Xosc1k::enable(tokens.xosc32k.xosc1k, xosc32k_base);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually 1Khz or 1024 Hz? Might be work clarifying, although I'm not sure whether it's standard practice to call that 1KHz in industry. I suppose what we call 32khz is actually 32768, so maybe there's already a precedent in place there. Just something to consider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. So. They should be 32KiHz oscillators technically. But datasheet sometimes calls them 32KHz sometimes 32.768KHz oscillators. So.. dunno how should we refer to them in the code. The slow clock is 1024 Hz and it's referred to as 1k everywhere :/ I think as long as it is correctly documented it should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm being pedantic, we only say 1k and 32k, which could be an abbreviation for KHz or KiHz 😆

I agree that this is slightly confusing, but I don't see a significantly better approach. Let's merge for now and if someone comes up with a better way to name things, we can change it.

let (xosc32k, _xosc32k_base) = Xosc32k::enable(tokens.xosc32k.xosc32k, xosc32k_base);

// Output `Xosc32k` on PB16 pin via `Gclk2`, divided by 2 resulting in 16 kHz
// output frequency
let (gclk2, _xosc32k) = Gclk::from_source(tokens.gclks.gclk2, xosc32k);
let gclk2 = gclk2.div(GclkDiv8::Div(2)).enable();
let (_gclk2, _gclk2_out) = gclk2.enable_gclk_out(pins.pb16);

// Output `OscUlp32k` on PB11 pin via `Gclk5`, without any division resulting in
// 32 kHz output frequency
let (osculp32k, _osculp_base) =
OscUlp32k::enable(tokens.osculp32k.osculp32k, clocks.osculp32k_base);
let (gclk5, _osculp32k) = Gclk::from_source(tokens.gclks.gclk5, osculp32k);
let gclk5 = gclk5.enable();
let (_gclk5, _gclk5_out) = gclk5.enable_gclk_out(pins.pb11);

// Setup a peripheral channel to power up `Uart` from `Gclk0`
let (pclk_sercom0, _gclk0) = Pclk::enable(tokens.pclks.sercom0, gclk0);

use atsamd_hal::sercom::uart;

let pads = uart::Pads::default().rx(pins.pa05).tx(pins.pa04);
// In the future, the `Uart` will take ownership of the `Pclk` and will
// take an `ApbClk` instead of `&MCLK`
let mut uart = uart::Config::new(&mclk, device.SERCOM0, pads, pclk_sercom0.freq())
.baud(115_200.hz(), BaudMode::Arithmetic(Oversampling::Bits16))
.enable();
uart.enable_interrupts(Flags::RXC);

// Initialize the RTC oscillator from the 1 kHz output of XOSC32K
let (rtc_osc, _xosc1k) = RtcOsc::enable(tokens.rtcosc, xosc1k);

// Setup an `Rtc` in `ClockMode`
// In the future, the `Rtc` will take ownership of the `RtcOsc`
let rtc = Rtc::clock_mode(device.RTC, rtc_osc.freq(), &mut mclk);

writeln!(&mut uart as &mut dyn Write<_, Error = _>, "RTIC booted!").unwrap();

(
SharedResources { uart, rtc },
LocalResources {},
init::Monotonics(),
)
}

#[task(binds = SERCOM0_2, shared = [uart, rtc])]
fn uart(cx: uart::Context) {
let mut uart = cx.shared.uart;
let mut rtc = cx.shared.rtc;
// Read from `Uart` to clean interrupt flag
let _ = uart.lock(|u| u.read().unwrap());

// Print out `DateTime` coming from `Rtc`
uart.lock(|u| {
writeln!(
u as &mut dyn Write<_, Error = _>,
"{:#?}",
rtc.lock(|r| r.current_time())
)
.unwrap()
});
}
}
2 changes: 1 addition & 1 deletion hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repository = "https://github.com/atsamd-rs/atsamd"
readme = "README.md"
documentation = "https://docs.rs/crate/atsamd-hal/"
edition = "2021"
rust-version = "1.56"
rust-version = "1.65"

[package.metadata.docs.rs]
features = ["samd21g", "samd21g-rt", "unproven", "usb"]
Expand Down
2 changes: 1 addition & 1 deletion hal/src/dmac/channel/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ macro_rules! reg_proxy {
paste! {
/// Register proxy tied to a specific channel
pub(super) struct [< $reg:camel Proxy >]<Id: ChId, REG> {
#[allow(ununsed)]
#[allow(unused)]
dmac: DMAC,
_id: PhantomData<Id>,
_reg: PhantomData<REG>,
Expand Down
Loading