Skip to content

Commit ad6ecca

Browse files
committed
[WIP] generic: Accommodate for new return value of write() and modify()
1 parent 9c3fe56 commit ad6ecca

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

avr-hal-generic/src/eeprom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ macro_rules! impl_eeprom_atmega {
319319
regs.eecr().write(|w| {
320320
// Set Master Write Enable bit, and and Erase+Write mode mode..
321321
w.eempe().set_bit().eepm().val_0x00()
322-
})
322+
});
323323
}
324324
#[inline]
325325
pub unsafe fn set_erase_mode(regs: &$EEPROM) {

avr-hal-generic/src/port.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,22 @@ macro_rules! impl_port_traditional_base {
633633
#[inline]
634634
unsafe fn out_set(&mut self) {
635635
match self.port {
636-
$(DynamicPort::[<PORT $name>] => (*<$port>::ptr()).[<port $name:lower>]().modify(|r, w| {
637-
w.bits(r.bits() | self.mask)
638-
}),)+
636+
$(DynamicPort::[<PORT $name>] => {
637+
(*<$port>::ptr()).[<port $name:lower>]().modify(|r, w| {
638+
w.bits(r.bits() | self.mask)
639+
});
640+
})+
639641
}
640642
}
641643

642644
#[inline]
643645
unsafe fn out_clear(&mut self) {
644646
match self.port {
645-
$(DynamicPort::[<PORT $name>] => (*<$port>::ptr()).[<port $name:lower>]().modify(|r, w| {
646-
w.bits(r.bits() & !self.mask)
647-
}),)+
647+
$(DynamicPort::[<PORT $name>] => {
648+
(*<$port>::ptr()).[<port $name:lower>]().modify(|r, w| {
649+
w.bits(r.bits() & !self.mask)
650+
});
651+
})+
648652
}
649653
}
650654

@@ -655,15 +659,15 @@ macro_rules! impl_port_traditional_base {
655659
if $chip_supports_atomic_toggle {
656660
(*<$port>::ptr()).[<pin $name:lower>]().write(|w| {
657661
w.bits(self.mask)
658-
})
662+
});
659663
} else {
660664
// This read-modify-write sequence cannot be optimized into a single sbi/cbi instruction,
661665
// so it is wrapped in a critical section which ensures we will never hit a race-condition here.
662666
$crate::avr_device::interrupt::free(|_| {
663667
(*<$port>::ptr()).[<port $name:lower>]().modify(|r, w| {
664668
w.bits(r.bits() ^ self.mask)
665669
})
666-
})
670+
});
667671
}
668672
},)+
669673
}
@@ -690,18 +694,22 @@ macro_rules! impl_port_traditional_base {
690694
#[inline]
691695
unsafe fn make_output(&mut self) {
692696
match self.port {
693-
$(DynamicPort::[<PORT $name>] => (*<$port>::ptr()).[<ddr $name:lower>]().modify(|r, w| {
694-
w.bits(r.bits() | self.mask)
695-
}),)+
697+
$(DynamicPort::[<PORT $name>] => {
698+
(*<$port>::ptr()).[<ddr $name:lower>]().modify(|r, w| {
699+
w.bits(r.bits() | self.mask)
700+
});
701+
})+
696702
}
697703
}
698704

699705
#[inline]
700706
unsafe fn make_input(&mut self, pull_up: bool) {
701707
match self.port {
702-
$(DynamicPort::[<PORT $name>] => (*<$port>::ptr()).[<ddr $name:lower>]().modify(|r, w| {
703-
w.bits(r.bits() & !self.mask)
704-
}),)+
708+
$(DynamicPort::[<PORT $name>] => {
709+
(*<$port>::ptr()).[<ddr $name:lower>]().modify(|r, w| {
710+
w.bits(r.bits() & !self.mask)
711+
});
712+
})+
705713
}
706714
if pull_up {
707715
self.out_set()
@@ -730,29 +738,29 @@ macro_rules! impl_port_traditional_base {
730738
unsafe fn out_set(&mut self) {
731739
(*<$port>::ptr()).[<port $name:lower>]().modify(|_, w| {
732740
w.[<p $name:lower $pin>]().set_bit()
733-
})
741+
});
734742
}
735743

736744
#[inline]
737745
unsafe fn out_clear(&mut self) {
738746
(*<$port>::ptr()).[<port $name:lower>]().modify(|_, w| {
739747
w.[<p $name:lower $pin>]().clear_bit()
740-
})
748+
});
741749
}
742750

743751
#[inline]
744752
unsafe fn out_toggle(&mut self) {
745753
if $chip_supports_atomic_toggle {
746754
(*<$port>::ptr()).[<pin $name:lower>]().write(|w| {
747755
w.[<p $name:lower $pin>]().set_bit()
748-
})
756+
});
749757
} else {
750758
// This read-modify-write sequence cannot be optimized into a single sbi/cbi instruction,
751759
// so it is wrapped in a critical section which ensures we will never hit a race-condition here.
752760
$crate::avr_device::interrupt::free(|_| {
753761
(*<$port>::ptr()).[<port $name:lower>]().modify(|r, w| {
754762
w.[<p $name:lower $pin>]().bit(!r.[<p $name:lower $pin>]().bit())
755-
})
763+
});
756764
})
757765
}
758766
}
@@ -771,7 +779,7 @@ macro_rules! impl_port_traditional_base {
771779
unsafe fn make_output(&mut self) {
772780
(*<$port>::ptr()).[<ddr $name:lower>]().modify(|_, w| {
773781
w.[<p $name:lower $pin>]().set_bit()
774-
})
782+
});
775783
}
776784

777785
#[inline]

avr-hal-generic/src/usart.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,15 @@ macro_rules! impl_usart_traditional {
535535

536536
fn raw_interrupt(&mut self, event: $crate::usart::Event, state: bool) {
537537
match event {
538-
$crate::usart::Event::RxComplete =>
539-
self.[<ucsr $n b>]().modify(|_, w| w.[<rxcie $n>]().bit(state)),
540-
$crate::usart::Event::TxComplete =>
541-
self.[<ucsr $n b>]().modify(|_, w| w.[<txcie $n>]().bit(state)),
542-
$crate::usart::Event::DataRegisterEmpty =>
543-
self.[<ucsr $n b>]().modify(|_, w| w.[<udrie $n>]().bit(state)),
538+
$crate::usart::Event::RxComplete => {
539+
self.[<ucsr $n b>]().modify(|_, w| w.[<rxcie $n>]().bit(state));
540+
}
541+
$crate::usart::Event::TxComplete => {
542+
self.[<ucsr $n b>]().modify(|_, w| w.[<txcie $n>]().bit(state));
543+
}
544+
$crate::usart::Event::DataRegisterEmpty => {
545+
self.[<ucsr $n b>]().modify(|_, w| w.[<udrie $n>]().bit(state));
546+
}
544547
}
545548
}
546549
}

0 commit comments

Comments
 (0)