@@ -172,6 +172,94 @@ namespace klib::core::atsam4s::io {
172172 }
173173 }
174174 };
175+
176+ template <typename Pin>
177+ class pin_od {
178+ public:
179+ constexpr static void init () {
180+ // init the pin using the pin_out
181+ pin_out<Pin>::init ();
182+
183+ // enable the multi-driver open drain
184+ Pin::port::port->MDER = detail::pins::mask<Pin>;
185+ }
186+
187+ template <bool Val>
188+ constexpr static void set () {
189+ pin_out<Pin>::template set<Val>();
190+ }
191+
192+ constexpr static void set (const bool val) {
193+ pin_out<Pin>::set (val);
194+ }
195+ };
196+
197+ template <typename Pin>
198+ class pin_in_out {
199+ public:
200+ constexpr static void init () {
201+ // init using pin_out as we can read the pin anyway
202+ pin_out<Pin>::init ();
203+ }
204+
205+ constexpr static bool get () {
206+ // get the status of the pin
207+ return pin_in<Pin>::get ();
208+ }
209+
210+ template <bool Val>
211+ constexpr static void pullup_enable () {
212+ pin_in<Pin>::template pullup_enable<Val>();
213+ }
214+
215+ template <bool Val>
216+ constexpr static void pulldown_enable () {
217+ pin_in<Pin>::template pulldown_enable<Val>();
218+ }
219+
220+ template <bool Val>
221+ constexpr static void set () {
222+ pin_out<Pin>::template set<Val>();
223+ }
224+
225+ constexpr static void set (const bool val) {
226+ pin_out<Pin>::set (val);
227+ }
228+ };
229+
230+ template <typename Pin>
231+ class pin_in_out_od {
232+ public:
233+ constexpr static void init () {
234+ // init using pin_od as we can read the pin anyway
235+ pin_od<Pin>::init ();
236+ }
237+
238+ constexpr static bool get () {
239+ // get the status of the pin
240+ return pin_in<Pin>::get ();
241+ }
242+
243+ template <bool Val>
244+ constexpr static void pullup_enable () {
245+ pin_in<Pin>::template pullup_enable<Val>();
246+ }
247+
248+ template <bool Val>
249+ constexpr static void pulldown_enable () {
250+ pin_in<Pin>::template pulldown_enable<Val>();
251+ }
252+
253+ template <bool Val>
254+ constexpr static void set () {
255+ pin_od<Pin>::template set<Val>();
256+ }
257+
258+ constexpr static void set (const bool val) {
259+ pin_od<Pin>::set (val);
260+ }
261+ };
262+
175263}
176264
177265#endif
0 commit comments