Skip to content

Commit 89acd78

Browse files
committed
Atsam4s added a basic pin_in_out, pin_od (open-drain) and pin_in_out_od
1 parent 52dcb87 commit 89acd78

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

targets/chip/atsam4s2b/io/port.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ namespace klib::atsam4s2b::io {
4747

4848
template <typename Pin>
4949
using pin_out = klib::core::atsam4s::io::pin_out<Pin>;
50+
51+
template <typename Pin>
52+
using pin_in_out = klib::core::atsam4s::io::pin_in_out<Pin>;
53+
54+
template <typename Pin>
55+
using pin_od = klib::core::atsam4s::io::pin_od<Pin>;
56+
57+
template <typename Pin>
58+
using pin_in_out_od = klib::core::atsam4s::io::pin_in_out_od<Pin>;
5059
}
5160

5261
#endif

targets/core/atmel/atsam4s/port.hpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)