hal::Pin Class Reference

Documentation

This class controls the operation of a single pin. It works similarly to the Pio class, but the mask is built-in.

Here is an example of using the Pin class:

#include <stfy/hal.hpp>
Pin pin(1,0); //control pin P1.0
//Or if working with the pinmask Pin pin(1, 1<<0, true);
pin.init(Pin::OUTPUT); //initialize as an output
//These three all set the pin high
pin = true;
pin.set();
//These turn the pin off
pin = false;
pin.clr();
//now convert to an input
pin.set_attr(Pin::INPUT | Pin::PULLUP); //or use Pin::FLOAT, Pin::PULLDOWN, etc
//or to init as an input use pin.init(Pin::INPUT);
//now check to see if the value is high or low
if( pin.value() == true ){
//pin is high
} else {
//pin is low
}
pin.close(); //close the associated file descriptor (pin keeps its IO properties and state)

Public Member Functions

int clr ()
 
bool get_value () const
 
int init (int mode)
 
Pinoperator= (bool on)
 
 Pin (port_t port, uint32_t pin, bool ismask=false)
 
int set ()
 
int set_attr (int mode)
 
- Public Member Functions inherited from hal::Pio
int clear_mask (unsigned int mask)
 
int get_attr (pio_attr_t &attr)
 
u32 get_value () const
 
int init (pio_sample_t mask, int mode)
 
int set_action (const pio_action_t &action)
 
int set_action (u32 channel, u32 event, s8 prio=0, mcu_callback_t callback=0, void *context=0)
 
int set_attr (const pio_attr_t &attr)
 
int set_attr (pio_sample_t mask, int mode)
 
int set_mask (unsigned int mask)
 
int set_value (unsigned int value)
 
- Public Member Functions inherited from hal::Periph
int close ()
 
int ioctl (int req, void *arg) const
 
int open (int flags=READWRITE)
 
int read (void *buf, int nbyte) const
 
int read (sys::Aio &aio) const
 
int seek (int loc, int whence) const
 
int write (const void *buf, int nbyte) const
 
int write (sys::Aio &aio) const
 
- Public Member Functions inherited from hal::Dev
int fileno () const
 
int flags () const
 
char * gets (char *s, int n, char term= '\n') const
 
char * gets (var::String &s, char term= '\n') const
 
int ioctl (int req, const void *arg) const
 
int ioctl (int req) const
 
int ioctl (int req, int arg) const
 
int loc () const
 
int read (int loc, void *buf, int nbyte) const
 
int readline (char *buf, int nbyte, int timeout, char term) const
 
int write (int loc, const void *buf, int nbyte) const
 
int write (const char *s) const
 
int write (const var::String &str) const
 

Additional Inherited Members

- Public Types inherited from hal::Pio
- Public Types inherited from hal::Dev
- Static Public Member Functions inherited from hal::Dev
static const char * name (const char *path)
 
- Protected Member Functions inherited from hal::Periph
int open (const char *name, int flags)
 

Constructor & Destructor Documentation

hal::Pin::Pin ( port_t  port,
uint32_t  pin,
bool  ismask = false 
)
inline

Initialize the object with a port/pin combination.

Member Function Documentation

int hal::Pin::clr ( )
inline

Clear the pin low (assign value 0)

bool hal::Pin::get_value ( ) const
inline

Get the value of the pin (true is high, false is low)

int hal::Pin::init ( int  mode)
inline

Initialize the pin with the specified mode

Pin& hal::Pin::operator= ( bool  on)
inline

Assign a boolean to the pin (true is high, false is low)

int hal::Pin::set ( )
inline

Set the pin high (assign value 1)

int hal::Pin::set_attr ( int  mode)
inline

Set the pin attributes