ESPHome  1.15.1
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::GPIOPin Class Reference

A high-level abstraction class that can expose a pin together with useful options like pinMode. More...

#include <esphal.h>

Inheritance diagram for esphome::GPIOPin:
esphome::mcp23008::MCP23008GPIOPin esphome::mcp23016::MCP23016GPIOPin esphome::mcp23017::MCP23017GPIOPin esphome::pcf8574::PCF8574GPIOPin esphome::sn74hc595::SN74HC595GPIOPin esphome::sx1509::SX1509GPIOPin

Public Member Functions

 GPIOPin (uint8_t pin, uint8_t mode, bool inverted=false)
 Construct the GPIOPin instance. More...
 
virtual void setup ()
 Setup the pin mode. More...
 
virtual bool digital_read ()
 Read the binary value from this pin using digitalRead (and inverts automatically). More...
 
virtual void digital_write (bool value)
 Write the binary value to this pin using digitalWrite (and inverts automatically). More...
 
virtual void pin_mode (uint8_t mode)
 Set the pin mode. More...
 
uint8_t get_pin () const
 Get the GPIO pin number. More...
 
const char * get_pin_mode_name () const
 
uint8_t get_mode () const
 Get the pinMode of this pin. More...
 
bool is_inverted () const
 Return whether this pin shall be treated as inverted. (for example active-low) More...
 
template<typename T >
void attach_interrupt (void(*func)(T *), T *arg, int mode) const
 
void detach_interrupt () const
 
ISRInternalGPIOPinto_isr () const
 

Protected Member Functions

void attach_interrupt_ (void(*func)(void *), void *arg, int mode) const
 
void detach_interrupt_ () const
 

Protected Attributes

const uint8_t pin_
 
const uint8_t mode_
 
const bool inverted_
 
volatile uint32_t *const gpio_set_
 
volatile uint32_t *const gpio_clear_
 
volatile uint32_t *const gpio_read_
 
const uint32_t gpio_mask_
 

Detailed Description

A high-level abstraction class that can expose a pin together with useful options like pinMode.

Set the parameters for this at construction time and use setup() to apply them. The inverted parameter will automatically invert the input/output for you.

Use read_value() and write_value() to use digitalRead() and digitalWrite(), respectively.

Definition at line 69 of file esphal.h.

Constructor & Destructor Documentation

◆ GPIOPin()

esphome::GPIOPin::GPIOPin ( uint8_t  pin,
uint8_t  mode,
bool  inverted = false 
)

Construct the GPIOPin instance.

Parameters
pinThe GPIO pin number of this instance.
modeThe Arduino pinMode that this pin should be put into at setup().
invertedWhether all digitalRead/digitalWrite calls should be inverted.

Definition at line 23 of file esphal.cpp.

Member Function Documentation

◆ attach_interrupt()

template<typename T >
void esphome::GPIOPin::attach_interrupt ( void(*)(T *)  func,
T *  arg,
int  mode 
) const

Definition at line 116 of file esphal.h.

◆ attach_interrupt_()

void esphome::GPIOPin::attach_interrupt_ ( void(*)(void *)  func,
void *  arg,
int  mode 
) const
protected

Definition at line 239 of file esphal.cpp.

◆ detach_interrupt()

void esphome::GPIOPin::detach_interrupt ( ) const

Definition at line 230 of file esphal.cpp.

◆ detach_interrupt_()

void esphome::GPIOPin::detach_interrupt_ ( ) const
protected

Definition at line 231 of file esphal.cpp.

◆ digital_read()

bool ICACHE_RAM_ATTR HOT esphome::GPIOPin::digital_read ( )
virtual

Read the binary value from this pin using digitalRead (and inverts automatically).

Reimplemented in esphome::mcp23017::MCP23017GPIOPin, esphome::mcp23016::MCP23016GPIOPin, esphome::mcp23008::MCP23008GPIOPin, esphome::pcf8574::PCF8574GPIOPin, esphome::sn74hc595::SN74HC595GPIOPin, and esphome::sx1509::SX1509GPIOPin.

Definition at line 122 of file esphal.cpp.

◆ digital_write()

void ICACHE_RAM_ATTR HOT esphome::GPIOPin::digital_write ( bool  value)
virtual

Write the binary value to this pin using digitalWrite (and inverts automatically).

Reimplemented in esphome::mcp23017::MCP23017GPIOPin, esphome::mcp23016::MCP23016GPIOPin, esphome::mcp23008::MCP23008GPIOPin, esphome::pcf8574::PCF8574GPIOPin, esphome::sn74hc595::SN74HC595GPIOPin, and esphome::sx1509::SX1509GPIOPin.

Definition at line 128 of file esphal.cpp.

◆ get_mode()

uint8_t esphome::GPIOPin::get_mode ( ) const

Get the pinMode of this pin.

◆ get_pin()

uint8_t esphome::GPIOPin::get_pin ( ) const

Get the GPIO pin number.

◆ get_pin_mode_name()

const char* esphome::GPIOPin::get_pin_mode_name ( ) const

◆ is_inverted()

bool esphome::GPIOPin::is_inverted ( ) const

Return whether this pin shall be treated as inverted. (for example active-low)

◆ pin_mode()

void ICACHE_RAM_ATTR HOT esphome::GPIOPin::pin_mode ( uint8_t  mode)
virtual

◆ setup()

virtual void esphome::GPIOPin::setup ( )
virtual

◆ to_isr()

ISRInternalGPIOPin * esphome::GPIOPin::to_isr ( ) const

Definition at line 266 of file esphal.cpp.

Field Documentation

◆ gpio_clear_

volatile uint32_t* const esphome::GPIOPin::gpio_clear_
protected

Definition at line 110 of file esphal.h.

◆ gpio_mask_

const uint32_t esphome::GPIOPin::gpio_mask_
protected

Definition at line 113 of file esphal.h.

◆ gpio_read_

volatile uint32_t* const esphome::GPIOPin::gpio_read_
protected

Definition at line 112 of file esphal.h.

◆ gpio_set_

volatile uint32_t* const esphome::GPIOPin::gpio_set_
protected

Definition at line 109 of file esphal.h.

◆ inverted_

const bool esphome::GPIOPin::inverted_
protected

Definition at line 107 of file esphal.h.

◆ mode_

const uint8_t esphome::GPIOPin::mode_
protected

Definition at line 106 of file esphal.h.

◆ pin_

const uint8_t esphome::GPIOPin::pin_
protected

Definition at line 105 of file esphal.h.


The documentation for this class was generated from the following files: