summaryrefslogtreecommitdiffstats
path: root/hal/pin.tpp
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-05-05 17:13:59 +0200
committerNao Pross <naopross@thearcway.org>2018-05-05 17:13:59 +0200
commit601ee769f5ceeab7c71e61806804e4788f279c59 (patch)
treebc0479325be9e69b7039304deba663ad89422700 /hal/pin.tpp
parentAdd top comments (diff)
downloadSAMLiquidSmoke-601ee769f5ceeab7c71e61806804e4788f279c59.tar.gz
SAMLiquidSmoke-601ee769f5ceeab7c71e61806804e4788f279c59.zip
Rename class pin to io_pin, add general gpio class, add uart echo
Diffstat (limited to '')
-rw-r--r--hal/pin.tpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/hal/pin.tpp b/hal/pin.tpp
index 3954945..42d03de 100644
--- a/hal/pin.tpp
+++ b/hal/pin.tpp
@@ -12,26 +12,26 @@
template<unsigned bit>
template<typename latch_T, typename tris_T, typename port_T>
-pin<bit>::pin(latch_T *latch, tris_T *tris, port_T *port) :
+io_pin<bit>::io_pin(latch_T *latch, tris_T *tris, port_T *port) :
_latch(reinterpret_cast<volatile uint8_t *>(latch)),
_tris(reinterpret_cast<volatile uint8_t *>(tris)),
_port(reinterpret_cast<volatile uint8_t *>(port))
{
// default settings
- set_mode(pin<bit>::mode::OUTPUT);
- set(pin<bit>::state::OFF);
+ set_mode(io_pin<bit>::mode::OUTPUT);
+ set(io_pin<bit>::state::OFF);
}
template<unsigned bit>
-pin<bit>::~pin()
+io_pin<bit>::~io_pin()
{
}
template<unsigned bit>
-void pin<bit>::set_mode(unsigned m)
+void io_pin<bit>::set_mode(unsigned m)
{
if (m)
*_tris |= 1<<bit; // input
@@ -40,22 +40,19 @@ void pin<bit>::set_mode(unsigned m)
}
template<unsigned bit>
-void pin<bit>::set_mode(pin<bit>::mode m)
+void io_pin<bit>::set_mode(io_pin<bit>::mode m)
{
set_mode(static_cast<unsigned>(m));
}
template<unsigned bit>
-typename pin<bit>::state pin<bit>::read() const
+unsigned io_pin<bit>::read() const
{
- if (*_port & (1<<bit))
- return state::ON;
- else
- return state::OFF;
+ return (*_port & (1<<bit)) ? 1 : 0;
}
template<unsigned bit>
-void pin<bit>::set(unsigned s)
+void io_pin<bit>::set(unsigned s)
{
if (s > 0)
*_latch |= 1<<bit; // on
@@ -64,19 +61,19 @@ void pin<bit>::set(unsigned s)
}
template<unsigned bit>
-void pin<bit>::set(pin<bit>::state s)
+void io_pin<bit>::set(io_pin<bit>::state s)
{
set(static_cast<unsigned>(s));
}
template<unsigned bit>
-void pin<bit>::toggle()
+void io_pin<bit>::toggle()
{
*_latch ^= 1<<bit;
}
template<unsigned bit>
-bool pin<bit>::operator==(const pin<bit> &other) const
+bool io_pin<bit>::operator==(const io_pin<bit> &other) const
{
return (_latch == other._latch
&& _tris == other._tris
@@ -84,7 +81,7 @@ bool pin<bit>::operator==(const pin<bit> &other) const
}
template<unsigned bit>
-bool pin<bit>::operator!=(const pin<bit> &other) const
+bool io_pin<bit>::operator!=(const io_pin<bit> &other) const
{
return !(*this == other);
}