diff options
author | Nao Pross <naopross@thearcway.org> | 2018-05-05 17:13:59 +0200 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-05-05 17:13:59 +0200 |
commit | 601ee769f5ceeab7c71e61806804e4788f279c59 (patch) | |
tree | bc0479325be9e69b7039304deba663ad89422700 /hal/pin.hpp | |
parent | Add top comments (diff) | |
download | SAMLiquidSmoke-601ee769f5ceeab7c71e61806804e4788f279c59.tar.gz SAMLiquidSmoke-601ee769f5ceeab7c71e61806804e4788f279c59.zip |
Rename class pin to io_pin, add general gpio class, add uart echo
Diffstat (limited to 'hal/pin.hpp')
-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; |