PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
simpleport.h
Go to the documentation of this file.
1 
26 #pragma once
27 
28 #include <PropWare/gpio/port.h>
29 
30 namespace PropWare {
31 
36 class SimplePort : public Port {
37  public:
46  static void flash_port (const Port::Mask firstPin, const uint8_t portWidth, const uint16_t iterations = 10) {
47  const SimplePort port(firstPin, portWidth);
48  Port::flash_port(port.m_mask, iterations);
49  }
50 
51  public:
56  Port() {
57  this->m_firstPinNum = 0;
58  }
59 
66  SimplePort (const PropWare::Port::Mask firstPin, uint8_t portWidth) {
67  this->set_mask(firstPin, portWidth);
68  }
69 
77  SimplePort (const PropWare::Port::Mask firstPin, uint8_t portWidth, const PropWare::Port::Dir direction) {
78  this->set_mask(firstPin, portWidth);
79  this->set_dir(direction);
80  }
81 
88  void set_mask (const PropWare::Port::Mask firstPin, uint8_t portWidth) {
89  this->m_mask = static_cast<uint32_t>(firstPin);
90  this->m_firstPinNum = PropWare::Port::from_mask(firstPin);
91 
92  // For every pin in the port...
93  while (--portWidth)
94  // Add the next pin to the mask
95  this->m_mask |= this->m_mask << 1;
96  }
97 
105  void write (uint32_t value) const {
106  this->Port::write_fast(value << this->m_firstPinNum);
107  }
108 
116  uint32_t read () const {
117  return this->Port::read_fast() >> this->m_firstPinNum;
118  }
119 
120  private:
121  uint8_t m_firstPinNum;
122 };
123 
124 }
PropWare::Port::from_mask
static uint8_t from_mask(const Mask mask)
Determine which pin number based on a pin mask.
Definition: port.h:98
PropWare::Port::read_fast
uint32_t read_fast() const
Allow easy reading of only selected pins from a port.
Definition: port.h:291
PropWare::SimplePort::set_mask
void set_mask(const PropWare::Port::Mask firstPin, uint8_t portWidth)
Configure a port's bit-mask.
Definition: simpleport.h:88
PropWare::SimplePort::SimplePort
SimplePort(const PropWare::Port::Mask firstPin, uint8_t portWidth, const PropWare::Port::Dir direction)
Initialize a port and configures its bit-mask and direction.
Definition: simpleport.h:77
PropWare::SimplePort::write
void write(uint32_t value) const
Allow easy writing to a port w/o destroying data elsewhere in the port; A shift is performed before w...
Definition: simpleport.h:105
PropWare::Port::Mask
Mask
Definition: port.h:43
port.h
PropWare::SimplePort::SimplePort
SimplePort(const PropWare::Port::Mask firstPin, uint8_t portWidth)
Initialize a port and configures its bit-mask.
Definition: simpleport.h:66
PropWare::Port::flash_port
static void flash_port(const uint32_t pinMask, unsigned int iterations=10)
Great for quick debugging to ensure a line of code is executed, this will quickly flash a given set o...
Definition: port.h:129
PropWare::Port::set_dir
void set_dir(const PropWare::Port::Dir direction) const
Set port as either input or output.
Definition: port.h:191
PropWare::SimplePort::flash_port
static void flash_port(const Port::Mask firstPin, const uint8_t portWidth, const uint16_t iterations=10)
Great for quick debugging to ensure a line of code is executed, this will quickly flash a given set o...
Definition: simpleport.h:46
PropWare::Port::Dir
Dir
Definition: port.h:82
PropWare::SimplePort::read
uint32_t read() const
Allow easy reading of only selected pins from a port.
Definition: simpleport.h:116
PropWare::Port::write_fast
void write_fast(const uint32_t value) const
Allow easy writing to a port w/o destroying data elsewhere in the port; No shift is performed to alig...
Definition: port.h:282
PropWare::Port
Flexible port that can have any pin enabled or disabled. Pins are independent of each other.
Definition: port.h:38
PropWare::SimplePort::SimplePort
SimplePort()
Definition: simpleport.h:55
PropWare::SimplePort
The PropWare::SimplePort is the recommended way to use data ports on the Propeller....
Definition: simpleport.h:36
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33