Crates.io | samd-timer |
lib.rs | samd-timer |
version | 0.2.0 |
source | src |
created_at | 2020-03-08 04:52:24.796025 |
updated_at | 2020-03-16 03:25:33.238152 |
description | High-level API for the TC/TCC peripherals found on the Microchip SAM MCUs. |
homepage | |
repository | https://github.com/proman21/samd-timer |
max_upload_size | |
id | 216486 |
size | 70,386 |
High-level API for the TCC/TC peripherals found on the Microchip SAMD and SAME MCUs.
This library is usable (as in I use it), but could contain bugs. USE AT YOUR OWN RISK.
This library provides the Timer
and ControlTimer
types for working safely with TC
and TCC
peripherals respectively. Full support for waveform generation capabilities, double buffering, and capture modes.
Provides finer grain control over your timers than the abstraction used by atsamd-hal
. Simply drop in the library; it works with the atsamd-hal
clock system.
Add the following line to your Cargo.toml
.
samd-timer = "0.2.0"
The following feature flags control which MCU variant you are targetting.
Name | # TC | # TCC | Boards |
---|---|---|---|
samd21g18a | 3 | 3 | Circuit Playground Express, Feather M0, Metro M0, MKR ZERO, SAMD21 Mini, SODAQ ONE |
samd21e18a | 3 | 3 | Gemma M0, Trinket M0, Serpente |
samd21j18a | 5 | 3 | SODAQ SARA AFF |
samd51j19a | 6 | 5 | EdgeBadge, Feather M4, Metro M4 |
samd51j20a | 6 | 5 | PyPortal |
samd51g19a | 4 | 3 | ItsyBitsy M4, Trellis M4 |
same54p20a | 8 | 5 | PathfinderZA Proto1 |
use atsamd_hal::target_device::Peripherals;
use atsamd_hal::clock::GenericClockController;
use samd_timer::{TimerConfig, Timer, Prescaler, Synchronization, TimerWaveGen};
fn main() {
let mut peri = Peripherals.take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peri.GCLCK,
&mut peri.MCLK,
&mut peri.OSC32KCTRL,
&mut peri.OSCCTRL,
&mut peri.NVMCTRL
);
let timer_clock = clocks.gclk1();
let tc_clock = clocks.tc0_tc1(&timer_clock).unwrap();
/// Create a 8-bit width timer configuration.
let mut config = TimerConfig::count8();
config.prescaler(Prescaler::Div64)
.sync(Synchronization::Prescaler)
.wave_gen(TimerWaveGen::NPWM);
/// Initialise the timer instance.
let mut timer = config.tc0(&mut peri.MCLK, &tc_clock, peri.TC0);
// Output a PWM wave with a period of 2 secs and duty cycle of 50%
timer.set_period(999);
timer.set_cc0(499);
timer.enable();
}
samd-timer
is distributed under the MIT license. See the LICENSE file for the full text of the license.