Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions avr-hal-generic/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ macro_rules! impl_pwm {
(
$(#[$timer_pwm_attr:meta])*
pub struct $TimerPwm:ident {
type Duty: $Duty:ty,
timer: $TIMER:ty,
init: |$init_timer:ident, $prescaler:ident| $init_block:block,
pins: {$(
Expand Down Expand Up @@ -76,7 +77,7 @@ macro_rules! impl_pwm {
}

impl $crate::hal::PwmPin for $port::$PXi<$crate::port::mode::Pwm<$TimerPwm>> {
type Duty = u8;
type Duty = $Duty;

fn enable(&mut self) {
// SAFETY: This block will usually result in a read-modify-write sequence which
Expand All @@ -103,7 +104,7 @@ macro_rules! impl_pwm {
}

fn get_max_duty(&self) -> Self::Duty {
u8::MAX
Self::Duty::MAX
}

fn set_duty(&mut self, duty: Self::Duty) {
Expand Down
2 changes: 1 addition & 1 deletion boards/arduino-uno/examples/uno-pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() -> ! {
loop {
for i in 0..=255u16 {
let duty: u16 = i * i / 256;
pin.set_duty(duty as u8);
pin.set_duty(duty);
arduino_uno::delay_ms(10);
}
}
Expand Down
3 changes: 3 additions & 0 deletions chips/atmega168-hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ avr_hal_generic::impl_pwm! {
/// pd5.enable();
/// ```
pub struct Timer0Pwm {
type Duty: u8,
timer: crate::pac::TC0,
init: |tim, prescaler| {
tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast());
Expand Down Expand Up @@ -90,6 +91,7 @@ avr_hal_generic::impl_pwm! {
/// pb1.enable();
/// ```
pub struct Timer1Pwm {
type Duty: u16,
timer: crate::pac::TC1,
init: |tim, prescaler| {
tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01));
Expand Down Expand Up @@ -141,6 +143,7 @@ avr_hal_generic::impl_pwm! {
/// pb3.enable();
/// ```
pub struct Timer2Pwm {
type Duty: u8,
timer: crate::pac::TC2,
init: |tim, prescaler| {
tim.tccr2a.modify(|_, w| w.wgm2().pwm_fast());
Expand Down
6 changes: 6 additions & 0 deletions chips/atmega2560-hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ avr_hal_generic::impl_pwm! {
/// pb7.enable();
/// ```
pub struct Timer0Pwm {
type Duty: u8,
timer: crate::pac::TC0,
init: |tim, prescaler| {
tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast());
Expand Down Expand Up @@ -103,6 +104,7 @@ avr_hal_generic::impl_pwm! {
///
/// **Note**: For `PB7` the method is called `into_pwm1()`!
pub struct Timer1Pwm {
type Duty: u16,
timer: crate::pac::TC1,
init: |tim, prescaler| {
tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01));
Expand Down Expand Up @@ -162,6 +164,7 @@ avr_hal_generic::impl_pwm! {
/// pb4.enable();
/// ```
pub struct Timer2Pwm {
type Duty: u8,
timer: crate::pac::TC2,
init: |tim, prescaler| {
tim.tccr2a.modify(|_, w| w.wgm2().bits(0b01));
Expand Down Expand Up @@ -213,6 +216,7 @@ avr_hal_generic::impl_pwm! {
/// pe3.enable();
/// ```
pub struct Timer3Pwm {
type Duty: u16,
timer: crate::pac::TC3,
init: |tim, prescaler| {
tim.tccr3a.modify(|_, w| w.wgm3().bits(0b01));
Expand Down Expand Up @@ -272,6 +276,7 @@ avr_hal_generic::impl_pwm! {
/// ph3.enable();
/// ```
pub struct Timer4Pwm {
type Duty: u16,
timer: crate::pac::TC4,
init: |tim, prescaler| {
tim.tccr4a.modify(|_, w| w.wgm4().bits(0b01));
Expand Down Expand Up @@ -331,6 +336,7 @@ avr_hal_generic::impl_pwm! {
/// pl3.enable();
/// ```
pub struct Timer5Pwm {
type Duty: u16,
timer: crate::pac::TC5,
init: |tim, prescaler| {
tim.tccr5a.modify(|_, w| w.wgm5().bits(0b01));
Expand Down
5 changes: 5 additions & 0 deletions chips/atmega328p-hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ avr_hal_generic::impl_pwm! {
/// pd5.enable();
/// ```
pub struct Timer0Pwm {
type Duty: u8,
timer: crate::pac::TC0,
init: |tim, prescaler| {
tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast());
Expand Down Expand Up @@ -90,6 +91,7 @@ avr_hal_generic::impl_pwm! {
/// pb1.enable();
/// ```
pub struct Timer1Pwm {
type Duty: u16,
timer: crate::pac::TC1,
init: |tim, prescaler| {
tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01));
Expand Down Expand Up @@ -141,6 +143,7 @@ avr_hal_generic::impl_pwm! {
/// pb3.enable();
/// ```
pub struct Timer2Pwm {
type Duty: u8,
timer: crate::pac::TC2,
init: |tim, prescaler| {
tim.tccr2a.modify(|_, w| w.wgm2().pwm_fast());
Expand Down Expand Up @@ -189,6 +192,7 @@ avr_hal_generic::impl_pwm! {
/// pd1.enable();
/// ```
pub struct Timer3Pwm {
type Duty: u16,
timer: crate::pac::TC3,
init: |tim, prescaler| {
tim.tccr3a.modify(|_, w| w.wgm3().bits(0b01));
Expand Down Expand Up @@ -241,6 +245,7 @@ avr_hal_generic::impl_pwm! {
/// pd1.enable();
/// ```
pub struct Timer4Pwm {
type Duty: u16,
timer: crate::pac::TC4,
init: |tim, prescaler| {
tim.tccr4a.modify(|_, w| w.wgm4().bits(0b01));
Expand Down
4 changes: 4 additions & 0 deletions chips/atmega32u4-hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ avr_hal_generic::impl_pwm! {
/// pb7.enable();
/// ```
pub struct Timer0Pwm {
type Duty: u8,
timer: crate::pac::TC0,
init: |tim, prescaler| {
tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast());
Expand Down Expand Up @@ -95,6 +96,7 @@ avr_hal_generic::impl_pwm! {
///
/// **Note**: For `PB7` the method is called `into_pwm1()`!
pub struct Timer1Pwm {
type Duty: u16,
timer: crate::pac::TC1,
init: |tim, prescaler| {
tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01));
Expand Down Expand Up @@ -152,6 +154,7 @@ avr_hal_generic::impl_pwm! {
/// pc6.enable();
/// ```
pub struct Timer3Pwm {
type Duty: u16,
timer: crate::pac::TC3,
init: |tim, prescaler| {
tim.tccr3a.modify(|_, w| w.wgm3().bits(0b01));
Expand Down Expand Up @@ -199,6 +202,7 @@ avr_hal_generic::impl_pwm! {
///
/// **Note**: For `PB6` the method is called `into_pwm6()`!
pub struct Timer4Pwm {
type Duty: u8,
timer: crate::pac::TC4,
init: |tim, prescaler| {
tim.tccr4b.modify(|_, w| match prescaler {
Expand Down
3 changes: 3 additions & 0 deletions chips/atmega48p-hal/src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ avr_hal_generic::impl_pwm! {
/// pd5.enable();
/// ```
pub struct Timer0Pwm {
type Duty: u8,
timer: crate::pac::TC0,
init: |tim, prescaler| {
tim.tccr0a.modify(|_, w| w.wgm0().pwm_fast());
Expand Down Expand Up @@ -90,6 +91,7 @@ avr_hal_generic::impl_pwm! {
/// pb1.enable();
/// ```
pub struct Timer1Pwm {
type Duty: u16,
timer: crate::pac::TC1,
init: |tim, prescaler| {
tim.tccr1a.modify(|_, w| w.wgm1().bits(0b01));
Expand Down Expand Up @@ -141,6 +143,7 @@ avr_hal_generic::impl_pwm! {
/// pb3.enable();
/// ```
pub struct Timer2Pwm {
type Duty: u8,
timer: crate::pac::TC2,
init: |tim, prescaler| {
tim.tccr2a.modify(|_, w| w.wgm2().pwm_fast());
Expand Down