diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-01-13 23:56:25 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-01-13 23:56:39 +0100 |
| commit | 7997687f3b4c8f679ae458ee28cd338ed9e44b2e (patch) | |
| tree | 9d31efb45bd909a249f6ff61f066c4638b0832f9 /embassy-nrf/src/uarte.rs | |
| parent | 6eec3d8acca1a4c6a853d0b65e43ec0a0f5c5c27 (diff) | |
nrf: impl embedded-hal 1.0 and embedded-hal-async traits.
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 07cec5d6b..b10e55a05 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -712,3 +712,206 @@ macro_rules! impl_uarte { | |||
| 712 | } | 712 | } |
| 713 | }; | 713 | }; |
| 714 | } | 714 | } |
| 715 | |||
| 716 | // ==================== | ||
| 717 | |||
| 718 | mod eh02 { | ||
| 719 | use super::*; | ||
| 720 | |||
| 721 | impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write<u8> for Uarte<'d, T> { | ||
| 722 | type Error = Error; | ||
| 723 | |||
| 724 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 725 | self.blocking_write(buffer) | ||
| 726 | } | ||
| 727 | |||
| 728 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 729 | Ok(()) | ||
| 730 | } | ||
| 731 | } | ||
| 732 | |||
| 733 | impl<'d, T: Instance> embedded_hal_02::blocking::serial::Write<u8> for UarteTx<'d, T> { | ||
| 734 | type Error = Error; | ||
| 735 | |||
| 736 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 737 | self.blocking_write(buffer) | ||
| 738 | } | ||
| 739 | |||
| 740 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 741 | Ok(()) | ||
| 742 | } | ||
| 743 | } | ||
| 744 | |||
| 745 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8> | ||
| 746 | for UarteWithIdle<'d, U, T> | ||
| 747 | { | ||
| 748 | type Error = Error; | ||
| 749 | |||
| 750 | fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 751 | self.blocking_write(buffer) | ||
| 752 | } | ||
| 753 | |||
| 754 | fn bflush(&mut self) -> Result<(), Self::Error> { | ||
| 755 | Ok(()) | ||
| 756 | } | ||
| 757 | } | ||
| 758 | } | ||
| 759 | |||
| 760 | #[cfg(feature = "unstable-traits")] | ||
| 761 | mod eh1 { | ||
| 762 | use super::*; | ||
| 763 | use core::future::Future; | ||
| 764 | |||
| 765 | impl embedded_hal_1::serial::Error for Error { | ||
| 766 | fn kind(&self) -> embedded_hal_1::serial::ErrorKind { | ||
| 767 | match *self { | ||
| 768 | Self::BufferTooLong => embedded_hal_1::serial::ErrorKind::Other, | ||
| 769 | Self::BufferZeroLength => embedded_hal_1::serial::ErrorKind::Other, | ||
| 770 | Self::DMABufferNotInDataMemory => embedded_hal_1::serial::ErrorKind::Other, | ||
| 771 | } | ||
| 772 | } | ||
| 773 | } | ||
| 774 | |||
| 775 | // ===================== | ||
| 776 | |||
| 777 | impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for Uarte<'d, T> { | ||
| 778 | type Error = Error; | ||
| 779 | } | ||
| 780 | |||
| 781 | impl<'d, T: Instance> embedded_hal_1::serial::blocking::Write for Uarte<'d, T> { | ||
| 782 | fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 783 | self.blocking_write(buffer) | ||
| 784 | } | ||
| 785 | |||
| 786 | fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 787 | Ok(()) | ||
| 788 | } | ||
| 789 | } | ||
| 790 | |||
| 791 | impl<'d, T: Instance> embedded_hal_async::serial::Read for Uarte<'d, T> { | ||
| 792 | type ReadFuture<'a> | ||
| 793 | where | ||
| 794 | Self: 'a, | ||
| 795 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 796 | |||
| 797 | fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { | ||
| 798 | self.read(buffer) | ||
| 799 | } | ||
| 800 | } | ||
| 801 | |||
| 802 | impl<'d, T: Instance> embedded_hal_async::serial::Write for Uarte<'d, T> { | ||
| 803 | type WriteFuture<'a> | ||
| 804 | where | ||
| 805 | Self: 'a, | ||
| 806 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 807 | |||
| 808 | fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> { | ||
| 809 | self.write(buffer) | ||
| 810 | } | ||
| 811 | |||
| 812 | type FlushFuture<'a> | ||
| 813 | where | ||
| 814 | Self: 'a, | ||
| 815 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 816 | |||
| 817 | fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { | ||
| 818 | async move { Ok(()) } | ||
| 819 | } | ||
| 820 | } | ||
| 821 | |||
| 822 | // ===================== | ||
| 823 | |||
| 824 | impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UarteTx<'d, T> { | ||
| 825 | type Error = Error; | ||
| 826 | } | ||
| 827 | |||
| 828 | impl<'d, T: Instance> embedded_hal_1::serial::blocking::Write for UarteTx<'d, T> { | ||
| 829 | fn write(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { | ||
| 830 | self.blocking_write(buffer) | ||
| 831 | } | ||
| 832 | |||
| 833 | fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 834 | Ok(()) | ||
| 835 | } | ||
| 836 | } | ||
| 837 | |||
| 838 | impl<'d, T: Instance> embedded_hal_async::serial::Write for UarteTx<'d, T> { | ||
| 839 | type WriteFuture<'a> | ||
| 840 | where | ||
| 841 | Self: 'a, | ||
| 842 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 843 | |||
| 844 | fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> { | ||
| 845 | self.write(buffer) | ||
| 846 | } | ||
| 847 | |||
| 848 | type FlushFuture<'a> | ||
| 849 | where | ||
| 850 | Self: 'a, | ||
| 851 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 852 | |||
| 853 | fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { | ||
| 854 | async move { Ok(()) } | ||
| 855 | } | ||
| 856 | } | ||
| 857 | |||
| 858 | // ===================== | ||
| 859 | |||
| 860 | impl<'d, T: Instance> embedded_hal_1::serial::ErrorType for UarteRx<'d, T> { | ||
| 861 | type Error = Error; | ||
| 862 | } | ||
| 863 | |||
| 864 | impl<'d, T: Instance> embedded_hal_async::serial::Read for UarteRx<'d, T> { | ||
| 865 | type ReadFuture<'a> | ||
| 866 | where | ||
| 867 | Self: 'a, | ||
| 868 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 869 | |||
| 870 | fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { | ||
| 871 | self.read(buffer) | ||
| 872 | } | ||
| 873 | } | ||
| 874 | |||
| 875 | // ===================== | ||
| 876 | |||
| 877 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType | ||
| 878 | for UarteWithIdle<'d, U, T> | ||
| 879 | { | ||
| 880 | type Error = Error; | ||
| 881 | } | ||
| 882 | |||
| 883 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Read | ||
| 884 | for UarteWithIdle<'d, U, T> | ||
| 885 | { | ||
| 886 | type ReadFuture<'a> | ||
| 887 | where | ||
| 888 | Self: 'a, | ||
| 889 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 890 | |||
| 891 | fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { | ||
| 892 | self.read(buffer) | ||
| 893 | } | ||
| 894 | } | ||
| 895 | |||
| 896 | impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Write | ||
| 897 | for UarteWithIdle<'d, U, T> | ||
| 898 | { | ||
| 899 | type WriteFuture<'a> | ||
| 900 | where | ||
| 901 | Self: 'a, | ||
| 902 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 903 | |||
| 904 | fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> { | ||
| 905 | self.write(buffer) | ||
| 906 | } | ||
| 907 | |||
| 908 | type FlushFuture<'a> | ||
| 909 | where | ||
| 910 | Self: 'a, | ||
| 911 | = impl Future<Output = Result<(), Self::Error>> + 'a; | ||
| 912 | |||
| 913 | fn flush<'a>(&'a mut self) -> Self::FlushFuture<'a> { | ||
| 914 | async move { Ok(()) } | ||
| 915 | } | ||
| 916 | } | ||
| 917 | } | ||
