class::hal::Pio

class hal::Pio
  : public hal::Periph< pio_info_t, pio_attr_t, PioAttributes, 'p'>

This class controls pin input/output.

See also: Hal::Pin

Example:

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){

//This allocates a PIO object but does not affect HW state
   Pio pio(2); //use pio port 2

   //This opens the port and sets the attributes -- same as pio.open(); pio.set_attr(1<<10, PIO_MODE_OUTPUT);
   pio.init(Pio::FLAG_SET_OUTPUT, 1<<10);

   //Bits can be manipulated using clrmask() and setmask()
   pio.clear_mask(1<<10); //clear bit 10 of port 2
   pio.set_mask(1<<10); //set bit 10

//the pin can be reconfigured as an input
   pio.set_attr(Pio::FLAG_SET_INPUT | Pio::FLAG_IS_PULLDOWN, (1<<10)); //set as an input with internal pulldown

   //get() is used to read the port
   if( pio.get_value() & (1<<10) ){
   //bit 10 is set
   }

   //This closes the port for all instances (ports are closed automatically when program exits)
   pio.close();

}

Summary

Pio(

port_t port
)

int assign(

u32 mask
) const

int clear_mask(

u32 mask
) const

u32 get_value() const

const Pio & operator<<(

u32 value
) const

int set_mask(

u32 mask
) const

int set_value(

unsigned int value
) const

enum pio_flags

Members

Pio(

port_t port
)


int assign(

u32 mask
) const

Assigns the mask value to the port

Parameters

  • mask Bits that are set will be output as 1 and bits that are clear will be output as zero

Returns

Zero on success


int clear_mask(

u32 mask
) const

Clears the specified mask.


u32 get_value() const

Gets the value of the port.


const Pio & operator<<(

u32 value
) const


int set_mask(

u32 mask
) const

Sets the specified pin mask


int set_value(

unsigned int value
) const

Sets the value of the port

Parameters

  • value The value to assign to the port

enum pio_flags
  • SET_INPUT Sets the pinmask as input
  • SET_OUTPUT Sets the pinmask as output
  • IS_PULLUP When setting as input, enables the pullup
  • IS_PULLDOWN When setting as input, enables the pulldown
  • IS_REPEATER When setting as input, enables repeater mode (if available)
  • IS_FLOAT When setting as input, enables floating mode (no pullup or pulldown)
  • IS_SPEED_LOW When setting as output, enables low speed mode
  • IS_SPEED_MEDIUM When setting as output, enables medium speed mode
  • IS_SPEED_HIGH When setting as output, enables high speed mode
  • IS_SPEED_BLAZING When setting as output, enables blazing speed mode
  • IS_OPENDRAIN When setting as output, enables open drain mode
  • IS_HYSTERESIS When setting as input, enables hysteresis
  • IS_DIRONLY When set, only affects the direction withouth setting other attributes
  • IS_ANALOG When setting as input, sets pin as analog mode
  • IS_INVERT See PIO_FLAG_IS_INVERT
  • IS_FILTER See PIO_FLAG_IS_FILTER
  • SET Assigns the value of the port to one if the corresponding bit in the pin mask is set.
  • CLEAR Assigns the value of the port to zero if the corresponding bit in the pin mask is set.
  • ASSIGN Assigns the value of the port to the value of the pin mask.

X

Thanks for Coming!

Subscribe to news and updates