@@ -87,4 +87,54 @@ avr_hal_generic::impl_simple_pwm! {
87
87
} ,
88
88
} ,
89
89
}
90
- }
90
+ }
91
+
92
+ #[ cfg( feature = "attiny88" ) ]
93
+ avr_hal_generic:: impl_simple_pwm! {
94
+ /// Use `TC1` for PWM (pins `PB1`, 'PB2')
95
+ ///
96
+ /// # Example
97
+ /// ```
98
+ /// let mut timer1 = Timer1Pwm::new(dp.TC1, Prescaler::Prescale64);
99
+ ///
100
+ /// let mut d9 = pins.d9.into_output().into_pwm(&mut timer1);
101
+ /// let mut d10 = pins.d10.into_output().into_pwm(&mut timer1);
102
+ ///
103
+ /// d9.set_duty(128);
104
+ /// d9.enable();
105
+ /// ```
106
+ pub struct Timer1Pwm {
107
+ timer: crate :: pac:: TC1 ,
108
+ init: |tim, prescaler| {
109
+ tim. tccr1a. modify( |_, w| w. wgm1( ) . bits( 0b01 ) ) ;
110
+ tim. tccr1b. modify( |_, w| w. wgm1( ) . bits( 0b01 ) ) ;
111
+
112
+ tim. tccr1b. modify( |_r, w| match prescaler {
113
+ Prescaler :: Direct => w. cs1( ) . direct( ) ,
114
+ Prescaler :: Prescale8 => w. cs1( ) . prescale_8( ) ,
115
+ Prescaler :: Prescale64 => w. cs1( ) . prescale_64( ) ,
116
+ Prescaler :: Prescale256 => w. cs1( ) . prescale_256( ) ,
117
+ Prescaler :: Prescale1024 => w. cs1( ) . prescale_1024( ) ,
118
+ } ) ;
119
+ } ,
120
+ pins: {
121
+ PB1 : {
122
+ ocr: ocr1a,
123
+ into_pwm: |tim| if enable {
124
+ tim. tccr1a. modify( |_, w| w. com1a( ) . bits( 0b10 ) ) ;
125
+ } else {
126
+ tim. tccr1a. modify( |_, w| w. com1a( ) . disconnected( ) ) ;
127
+ } ,
128
+ } ,
129
+
130
+ PB2 : {
131
+ ocr: ocr1b,
132
+ into_pwm: |tim| if enable {
133
+ tim. tccr1a. modify( |_, w| w. com1b( ) . bits( 0b10 ) ) ;
134
+ } else {
135
+ tim. tccr1a. modify( |_, w| w. com1b( ) . disconnected( ) ) ;
136
+ } ,
137
+ } ,
138
+ } ,
139
+ }
140
+ }
0 commit comments