diff options
Diffstat (limited to '')
-rw-r--r-- | hal/pin.hpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/hal/pin.hpp b/hal/pin.hpp index ff131ef..bbb80dc 100644 --- a/hal/pin.hpp +++ b/hal/pin.hpp @@ -12,9 +12,23 @@ extern "C" { #include <xc.h> } +class gpio +{ +public: + virtual ~gpio() {} + + // digital functions + virtual void set_mode(unsigned m) = 0; + virtual void set(unsigned s) = 0; + virtual unsigned read() const = 0; + virtual void toggle() = 0; + +protected: + gpio() {} +}; template<unsigned bit> -class pin { +class io_pin : public gpio { public: enum class mode : unsigned { INPUT = 1, OUTPUT = 0 }; @@ -22,25 +36,25 @@ public: enum class state : unsigned { ON = 1, OFF = 0 }; - pin() = delete; + io_pin() = delete; template<typename latch_T, typename tris_T, typename port_T> - pin(latch_T *latch, tris_T *tris, port_T *port); + io_pin(latch_T *latch, tris_T *tris, port_T *port); - virtual ~pin(); + virtual ~io_pin(); void set_mode(unsigned m); void set_mode(mode m); - state read() const; + unsigned read() const; void set(unsigned s); void set(state s); void toggle(); - bool operator==(const pin<bit> &other) const; - bool operator!=(const pin<bit> &other) const; + bool operator==(const io_pin<bit> &other) const; + bool operator!=(const io_pin<bit> &other) const; private: volatile uint8_t *_latch; |