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