|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
63 m_channel(Channel::A) {
64 this->update_pin_number();
72 :
Port(mask, direction),
73 m_channel(Channel::A) {
74 this->update_pin_number();
82 this->update_pin_number();
98 return this->m_pinNumber;
102 return static_cast<Pin::Mask>(this->m_mask);
105 Channel get_channel ()
const {
106 return this->m_channel;
109 void set_channel (
const Channel channel) {
110 this->m_channel = channel;
118 void write (
const bool value)
const {
131 return static_cast<bool>(this->read_fast());
141 waitpeq(this->m_mask, this->m_mask);
161 waitpne(this->read_fast(), this->m_mask);
174 if (!(this->
read())) {
175 waitcnt(debounceDelayInMillis * MILLISECOND +
CNT);
177 return !(this->
read());
207 uint32_t ctr =
static_cast<uint32_t
>((8 + ((!state & 1) * 4)) << 26);
208 ctr += this->m_pinNumber;
209 const uint32_t startTime =
CNT;
220 }
else if (
CTRB == 0) {
246 const uint32_t frq =
static_cast<uint32_t
>((UINT32_MAX + 1ULL) * frequency /
CLKFREQ);
247 const uint32_t ctr = (4 << 26) | this->m_pinNumber;
248 if (Channel::A == this->m_channel) {
252 }
else if (Channel::B == this->m_channel) {
263 if (Channel::A == this->m_channel) {
265 }
else if (Channel::B == this->m_channel) {
271 void update_pin_number () {
282 void set_mask (
const uint32_t mask) {
288 void add_pins (
const uint32_t mask) {
294 uint32_t read_fast ()
const {
300 uint_fast8_t m_pinNumber;
#define PHSB
Counter B phase accumulation register.
void stop_hardware_pwm() const
Stop the hardware counter.
static uint8_t from_mask(const Mask mask)
Determine which pin number based on a pin mask.
int rc_time(const bool state, const uint32_t timeout=SECOND/4)
Set to input and measure the time it takes a signal to transition from a start state to the opposite ...
uint32_t read_fast() const
Allow easy reading of only selected pins from a port.
uint_fast8_t get_pin_number() const
Get the pin's number (an integer, 0 through 31)
void set_mask(const Pin::Mask mask)
#define waitpeq(state, mask)
Wait until INA equal state & mask.
#define PHSA
Counter A phase accumulation register.
void set_pin_number(const uint8_t pinNum)
Set a Pin's mask based on the pin number (an integer, 0 through 31)
#define FRQA
Counter A frequency register.
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...
void wait_until_low() const
Hold cog execution until an input pin goes low.
Pin(const PropWare::Pin::Mask mask=NULL_PIN)
Create a Pin variable.
void set_dir_in() const
Set the port for input.
Utility class to handle general purpose I/O pins.
void set_dir(const PropWare::Port::Dir direction) const
Set port as either input or output.
void start_hardware_pwm(const uint32_t frequency) const
Output a PWM signal on this pin.
bool read() const
Read the value from a single pin and return its state.
Flexible port that can have any pin enabled or disabled. Pins are independent of each other.
#define FRQB
Counter B frequency register.
void write(const bool value) const
Set or clear the pin programmatically.
bool is_switch_low(const uint16_t debounceDelayInMillis=3) const
Allow easy switch-press detection of any pin; Includes de-bounce protection.
Pin(const Pin::Mask mask, const Pin::Dir direction)
void wait_until_toggle() const
Hold cog execution until an input pin toggles.
#define CLKFREQ
Returns the current clock frequency.
void set() const
Set selected output port high (set all pins to 1)
#define CTRB
Counter B control register.
void set_mask(const uint32_t mask)
Set the mask for this port.
#define waitcnt(a)
Wait until system counter reaches a value.
#define CNT
The system clock count.
static void flash_pin(const Pin::Mask pinMask, const unsigned int iterations=10)
Great for quick debugging to ensure a line of code is executed, this will quickly flash a given pin a...
void wait_until_high() const
Hold cog execution until an input pin goes high.
#define waitpne(state, mask)
Wait until INA not equal state & mask.
static Mask to_mask(const uint8_t pinNum)
Return a Mask type based on a pin number.
Generic definitions and functions for the Parallax Propeller.
void clear() const
Clear selected output port (set it to 0)
#define CTRA
Counter A control register.