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)
 
pio_sample_t pinmask () const
 
int set ()
 
int set_attr (int mode)
 
void set_value (bool value)
 
- 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 sys::File
int create (const char *path, bool overwrite=true, int perms=0666)
 
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 open (const char *name, int access, int perms)
 
int open_append (const char *path)
 
int open_readonly (const char *path)
 
int open_readwrite (const char *path)
 
int read (int loc, void *buf, int nbyte) const
 
int readline (char *buf, int nbyte, int timeout, char term) const
 
ssize_t size () 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 sys::File
- Static Public Member Functions inherited from sys::File
static const char * name (const char *path)
 
static int remove (const char *path, link_transport_mdriver_t *driver=0)
 
static ssize_t size (const char *path, link_transport_mdriver_t *driver=0)
 
static int stat (const char *path, struct link_stat *st, link_transport_mdriver_t *driver=0)
 
- 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

Initializes 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

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

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

Initializes the pin with the specified mode.

Parameters
modeThe mode to start the pin (e.g., Pin::INPUT | Pin::PULLUP)

Hardware intialization opens the device for reading/writing and then sets the device attributes as specified.

The following is an example of initializing a pin.

#include <stfy/hal.hpp>
Pin p(0,1); //Port 0, pin 1
if( p.get_value() == 0 ){
//this means something is driving the pin low
}
See also
open(), set_attr()
Pin& hal::Pin::operator= ( bool  on)
inline

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

pio_sample_t hal::Pin::pinmask ( ) const
inline

Accesses the pin's associated Pio pinmask.

int hal::Pin::set ( )
inline

Sets the pin high (assign value 1)

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

Sets the pin attributes.

Parameters
modeThe pin mode (e.g., Pin::INPUT)
Returns
Zero on success
void hal::Pin::set_value ( bool  value)
inline

Assigns a boolean to the pin.

Parameters
valueIf true, sets the pin high