From 7bec778c9a59416e3214ac28a6bce29dd03c9c00 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 4 May 2018 01:37:04 +0200 Subject: Update pin class to support input and output mode Also, minor changes in uart1.tpp --- hal/pin.tpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 10 deletions(-) (limited to 'hal/pin.tpp') diff --git a/hal/pin.tpp b/hal/pin.tpp index 4f6bd4a..c3c005f 100644 --- a/hal/pin.tpp +++ b/hal/pin.tpp @@ -7,24 +7,82 @@ #include "pin.hpp" -template -pin::pin(reg *r) + +template +template +pin::pin(latch_T *latch, tris_T *tris, port_T *port) : + _latch(reinterpret_cast(latch)), + _tris(reinterpret_cast(tris)), + _port(reinterpret_cast(port)) { - _register = r; + // default settings + set_mode(pin::mode::OUTPUT); + set(pin::state::OFF); } -template -pin::~pin() +template +pin::~pin() { } -template -void pin::set(bool v) + +template +void pin::set_mode(unsigned m) +{ + if (m) + *_tris |= 1< +void pin::set_mode(pin::mode m) +{ + set(static_cast(m)); +} + +template +typename pin::state pin::read() const +{ + if (*_tris & (1< +void pin::set(unsigned s) { - if (v) - *reinterpret_cast(_register) |= 1<(_register) &= ~(1< +void pin::set(pin::state s) +{ + set(static_cast(s)); +} + +template +void pin::toggle() +{ + *_latch ^= 1< +bool pin::operator==(const pin &other) const +{ + return (_latch == other._latch + && _tris == other._tris + && _port == other._port); +} + +template +bool pin::operator!=(const pin &other) const +{ + return !(*this == other); } \ No newline at end of file -- cgit v1.2.1