aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/gpio.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-rp/src/gpio.rs')
-rw-r--r--embassy-rp/src/gpio.rs303
1 files changed, 147 insertions, 156 deletions
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs
index ee7e03e95..9034f3f36 100644
--- a/embassy-rp/src/gpio.rs
+++ b/embassy-rp/src/gpio.rs
@@ -1,4 +1,5 @@
1#![macro_use] 1#![macro_use]
2use core::convert::Infallible;
2use core::future::Future; 3use core::future::Future;
3use core::pin::Pin as FuturePin; 4use core::pin::Pin as FuturePin;
4use core::task::{Context, Poll}; 5use core::task::{Context, Poll};
@@ -1036,217 +1037,207 @@ mod eh02 {
1036 } 1037 }
1037} 1038}
1038 1039
1039#[cfg(feature = "unstable-traits")] 1040impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
1040mod eh1 { 1041 type Error = Infallible;
1041 use core::convert::Infallible; 1042}
1042 1043
1043 use super::*; 1044impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> {
1045 fn is_high(&self) -> Result<bool, Self::Error> {
1046 Ok(self.is_high())
1047 }
1044 1048
1045 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { 1049 fn is_low(&self) -> Result<bool, Self::Error> {
1046 type Error = Infallible; 1050 Ok(self.is_low())
1047 } 1051 }
1052}
1048 1053
1049 impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { 1054impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> {
1050 fn is_high(&self) -> Result<bool, Self::Error> { 1055 type Error = Infallible;
1051 Ok(self.is_high()) 1056}
1052 }
1053 1057
1054 fn is_low(&self) -> Result<bool, Self::Error> { 1058impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> {
1055 Ok(self.is_low()) 1059 fn set_high(&mut self) -> Result<(), Self::Error> {
1056 } 1060 Ok(self.set_high())
1057 } 1061 }
1058 1062
1059 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Output<'d, T> { 1063 fn set_low(&mut self) -> Result<(), Self::Error> {
1060 type Error = Infallible; 1064 Ok(self.set_low())
1061 } 1065 }
1066}
1062 1067
1063 impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { 1068impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> {
1064 fn set_high(&mut self) -> Result<(), Self::Error> { 1069 fn is_set_high(&self) -> Result<bool, Self::Error> {
1065 Ok(self.set_high()) 1070 Ok(self.is_set_high())
1066 }
1067
1068 fn set_low(&mut self) -> Result<(), Self::Error> {
1069 Ok(self.set_low())
1070 }
1071 } 1071 }
1072 1072
1073 impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { 1073 fn is_set_low(&self) -> Result<bool, Self::Error> {
1074 fn is_set_high(&self) -> Result<bool, Self::Error> { 1074 Ok(self.is_set_low())
1075 Ok(self.is_set_high()) 1075 }
1076 } 1076}
1077 1077
1078 fn is_set_low(&self) -> Result<bool, Self::Error> { 1078impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for Output<'d, T> {
1079 Ok(self.is_set_low()) 1079 fn toggle(&mut self) -> Result<(), Self::Error> {
1080 } 1080 Ok(self.toggle())
1081 } 1081 }
1082}
1082 1083
1083 impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for Output<'d, T> { 1084impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> {
1084 fn toggle(&mut self) -> Result<(), Self::Error> { 1085 type Error = Infallible;
1085 Ok(self.toggle()) 1086}
1086 } 1087
1088impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> {
1089 fn set_high(&mut self) -> Result<(), Self::Error> {
1090 Ok(self.set_high())
1087 } 1091 }
1088 1092
1089 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for OutputOpenDrain<'d, T> { 1093 fn set_low(&mut self) -> Result<(), Self::Error> {
1090 type Error = Infallible; 1094 Ok(self.set_low())
1091 } 1095 }
1096}
1092 1097
1093 impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for OutputOpenDrain<'d, T> { 1098impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> {
1094 fn set_high(&mut self) -> Result<(), Self::Error> { 1099 fn is_set_high(&self) -> Result<bool, Self::Error> {
1095 Ok(self.set_high()) 1100 Ok(self.is_set_high())
1096 } 1101 }
1097 1102
1098 fn set_low(&mut self) -> Result<(), Self::Error> { 1103 fn is_set_low(&self) -> Result<bool, Self::Error> {
1099 Ok(self.set_low()) 1104 Ok(self.is_set_low())
1100 }
1101 } 1105 }
1106}
1102 1107
1103 impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for OutputOpenDrain<'d, T> { 1108impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for OutputOpenDrain<'d, T> {
1104 fn is_set_high(&self) -> Result<bool, Self::Error> { 1109 fn toggle(&mut self) -> Result<(), Self::Error> {
1105 Ok(self.is_set_high()) 1110 Ok(self.toggle())
1106 } 1111 }
1112}
1107 1113
1108 fn is_set_low(&self) -> Result<bool, Self::Error> { 1114impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> {
1109 Ok(self.is_set_low()) 1115 fn is_high(&self) -> Result<bool, Self::Error> {
1110 } 1116 Ok(self.is_high())
1111 } 1117 }
1112 1118
1113 impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for OutputOpenDrain<'d, T> { 1119 fn is_low(&self) -> Result<bool, Self::Error> {
1114 fn toggle(&mut self) -> Result<(), Self::Error> { 1120 Ok(self.is_low())
1115 Ok(self.toggle())
1116 }
1117 } 1121 }
1122}
1118 1123
1119 impl<'d, T: Pin> embedded_hal_1::digital::InputPin for OutputOpenDrain<'d, T> { 1124impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
1120 fn is_high(&self) -> Result<bool, Self::Error> { 1125 type Error = Infallible;
1121 Ok(self.is_high()) 1126}
1122 }
1123 1127
1124 fn is_low(&self) -> Result<bool, Self::Error> { 1128impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> {
1125 Ok(self.is_low()) 1129 fn is_high(&self) -> Result<bool, Self::Error> {
1126 } 1130 Ok(self.is_high())
1127 } 1131 }
1128 1132
1129 impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { 1133 fn is_low(&self) -> Result<bool, Self::Error> {
1130 type Error = Infallible; 1134 Ok(self.is_low())
1131 } 1135 }
1136}
1132 1137
1133 impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { 1138impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> {
1134 fn is_high(&self) -> Result<bool, Self::Error> { 1139 fn set_high(&mut self) -> Result<(), Self::Error> {
1135 Ok(self.is_high()) 1140 Ok(self.set_high())
1136 }
1137
1138 fn is_low(&self) -> Result<bool, Self::Error> {
1139 Ok(self.is_low())
1140 }
1141 } 1141 }
1142 1142
1143 impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { 1143 fn set_low(&mut self) -> Result<(), Self::Error> {
1144 fn set_high(&mut self) -> Result<(), Self::Error> { 1144 Ok(self.set_low())
1145 Ok(self.set_high())
1146 }
1147
1148 fn set_low(&mut self) -> Result<(), Self::Error> {
1149 Ok(self.set_low())
1150 }
1151 } 1145 }
1146}
1152 1147
1153 impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { 1148impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> {
1154 fn is_set_high(&self) -> Result<bool, Self::Error> { 1149 fn is_set_high(&self) -> Result<bool, Self::Error> {
1155 Ok(self.is_set_high()) 1150 Ok(self.is_set_high())
1156 } 1151 }
1157 1152
1158 fn is_set_low(&self) -> Result<bool, Self::Error> { 1153 fn is_set_low(&self) -> Result<bool, Self::Error> {
1159 Ok(self.is_set_low()) 1154 Ok(self.is_set_low())
1160 }
1161 } 1155 }
1156}
1162 1157
1163 impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for Flex<'d, T> { 1158impl<'d, T: Pin> embedded_hal_1::digital::ToggleableOutputPin for Flex<'d, T> {
1164 fn toggle(&mut self) -> Result<(), Self::Error> { 1159 fn toggle(&mut self) -> Result<(), Self::Error> {
1165 Ok(self.toggle()) 1160 Ok(self.toggle())
1166 }
1167 } 1161 }
1162}
1168 1163
1169 #[cfg(feature = "nightly")] 1164impl<'d, T: Pin> embedded_hal_async::digital::Wait for Flex<'d, T> {
1170 impl<'d, T: Pin> embedded_hal_async::digital::Wait for Flex<'d, T> { 1165 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
1171 async fn wait_for_high(&mut self) -> Result<(), Self::Error> { 1166 self.wait_for_high().await;
1172 self.wait_for_high().await; 1167 Ok(())
1173 Ok(()) 1168 }
1174 }
1175 1169
1176 async fn wait_for_low(&mut self) -> Result<(), Self::Error> { 1170 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
1177 self.wait_for_low().await; 1171 self.wait_for_low().await;
1178 Ok(()) 1172 Ok(())
1179 } 1173 }
1180 1174
1181 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { 1175 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
1182 self.wait_for_rising_edge().await; 1176 self.wait_for_rising_edge().await;
1183 Ok(()) 1177 Ok(())
1184 } 1178 }
1185 1179
1186 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { 1180 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
1187 self.wait_for_falling_edge().await; 1181 self.wait_for_falling_edge().await;
1188 Ok(()) 1182 Ok(())
1189 } 1183 }
1190 1184
1191 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { 1185 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
1192 self.wait_for_any_edge().await; 1186 self.wait_for_any_edge().await;
1193 Ok(()) 1187 Ok(())
1194 }
1195 } 1188 }
1189}
1196 1190
1197 #[cfg(feature = "nightly")] 1191impl<'d, T: Pin> embedded_hal_async::digital::Wait for Input<'d, T> {
1198 impl<'d, T: Pin> embedded_hal_async::digital::Wait for Input<'d, T> { 1192 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
1199 async fn wait_for_high(&mut self) -> Result<(), Self::Error> { 1193 self.wait_for_high().await;
1200 self.wait_for_high().await; 1194 Ok(())
1201 Ok(()) 1195 }
1202 }
1203 1196
1204 async fn wait_for_low(&mut self) -> Result<(), Self::Error> { 1197 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
1205 self.wait_for_low().await; 1198 self.wait_for_low().await;
1206 Ok(()) 1199 Ok(())
1207 } 1200 }
1208 1201
1209 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { 1202 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
1210 self.wait_for_rising_edge().await; 1203 self.wait_for_rising_edge().await;
1211 Ok(()) 1204 Ok(())
1212 } 1205 }
1213 1206
1214 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { 1207 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
1215 self.wait_for_falling_edge().await; 1208 self.wait_for_falling_edge().await;
1216 Ok(()) 1209 Ok(())
1217 } 1210 }
1218 1211
1219 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { 1212 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
1220 self.wait_for_any_edge().await; 1213 self.wait_for_any_edge().await;
1221 Ok(()) 1214 Ok(())
1222 }
1223 } 1215 }
1216}
1224 1217
1225 #[cfg(feature = "nightly")] 1218impl<'d, T: Pin> embedded_hal_async::digital::Wait for OutputOpenDrain<'d, T> {
1226 impl<'d, T: Pin> embedded_hal_async::digital::Wait for OutputOpenDrain<'d, T> { 1219 async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
1227 async fn wait_for_high(&mut self) -> Result<(), Self::Error> { 1220 self.wait_for_high().await;
1228 self.wait_for_high().await; 1221 Ok(())
1229 Ok(()) 1222 }
1230 }
1231 1223
1232 async fn wait_for_low(&mut self) -> Result<(), Self::Error> { 1224 async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
1233 self.wait_for_low().await; 1225 self.wait_for_low().await;
1234 Ok(()) 1226 Ok(())
1235 } 1227 }
1236 1228
1237 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> { 1229 async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
1238 self.wait_for_rising_edge().await; 1230 self.wait_for_rising_edge().await;
1239 Ok(()) 1231 Ok(())
1240 } 1232 }
1241 1233
1242 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> { 1234 async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
1243 self.wait_for_falling_edge().await; 1235 self.wait_for_falling_edge().await;
1244 Ok(()) 1236 Ok(())
1245 } 1237 }
1246 1238
1247 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> { 1239 async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
1248 self.wait_for_any_edge().await; 1240 self.wait_for_any_edge().await;
1249 Ok(()) 1241 Ok(())
1250 }
1251 } 1242 }
1252} 1243}