Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MCP23017 Class Reference
Inheritance diagram for MCP23017:
Atomic

Classes

class  RefreshTimer
 This timer runs in the parent executor and upon every timeout it executes the update / polling of the IO expander. More...
 

Public Types

enum  { PORTA = 0 , PORTB = 1 }
 

Public Member Functions

 MCP23017 (ExecutorBase *executor, bool a2, bool a1, bool a0)
 Constructor.
 
void init (const char *i2c_path)
 Initializes the device.
 
void init (int i2c_fd)
 Initializes the device.
 

Static Public Attributes

static constexpr long long POLLING_DELAY = MSEC_TO_NSEC(20)
 

Private Types

enum  Registers {
  IODIRA = 0x0 , IODIRB = 0x1 , IPOLA = 0x2 , IPOLB = 0x3 ,
  GPINTENA = 0x4 , GPINTENB = 0x5 , DEFVALA = 0x6 , DEFVALB = 0x7 ,
  INTCONA = 0x8 , INTCONB = 0x9 , IOCON = 0xA , GPPUA = 0xC ,
  GPPUB = 0xD , INTFA = 0xE , INTFB = 0xF , INTCAPA = 0x10 ,
  INTCAPB = 0x11 , RGPIOA = 0x12 , RGPIOB = 0x13 , OLATA = 0x14 ,
  OLATB = 0x15
}
 
enum  { BASE_ADDRESS = 0b0100000 , DIRTY_DIR = 1 , DIRTY_LAT = 2 }
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (MCP23017)
 
void update_out ()
 Updates the output direction and latch registers if any of it is dirty.
 
void update_in ()
 Updates input registers.
 
void register_write (uint8_t reg, const uint8_t *data, uint16_t len)
 Writes one or more (sequential) registers in the MCP23017.
 
void register_read (uint8_t reg, uint8_t *data, uint16_t len)
 Reads one or more (sequential) registers in the MCP23017.
 
- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Private Attributes

ExecutorBaseexecutor_
 Executor. We will be blocking this for the I2C IO.
 
RefreshTimer timer_ {this}
 Timer instance to schedule work on the executor.
 
int fd_
 I2C port file descriptor.
 
uint8_t dir_ [2]
 Shadow of the direction registers.
 
uint8_t lat_ [2]
 Shadow of the latch registers.
 
uint8_t gpio_ [2]
 Shadow of the input registers.
 
uint8_t i2cAddress_
 Address of this particular device on the I2C port.
 
uint8_t dirty_ = 0
 Bit mask of registers that need updating.
 

Friends

class MCP23017Gpio
 

Detailed Description

Definition at line 46 of file MCP23017Gpio.hxx.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Definition at line 98 of file MCP23017Gpio.hxx.

◆ anonymous enum

anonymous enum
private
Enumerator
BASE_ADDRESS 

I2C address of the first device.

Definition at line 134 of file MCP23017Gpio.hxx.

◆ Registers

enum MCP23017::Registers
private

Definition at line 109 of file MCP23017Gpio.hxx.

Constructor & Destructor Documentation

◆ MCP23017()

MCP23017::MCP23017 ( ExecutorBase executor,
bool  a2,
bool  a1,
bool  a0 
)
inline

Constructor.

Parameters
a2address bit 2
a1address bit 1
a0address bit 0

Definition at line 56 of file MCP23017Gpio.hxx.

Member Function Documentation

◆ init() [1/2]

void MCP23017::init ( const char *  i2c_path)
inline

Initializes the device.

Parameters
i2c_pathis the path to the device driver of the i2c port.

Definition at line 77 of file MCP23017Gpio.hxx.

◆ init() [2/2]

void MCP23017::init ( int  i2c_fd)
inline

Initializes the device.

Parameters
i2c_fdis the file descriptor of the i2c port to use.

Definition at line 86 of file MCP23017Gpio.hxx.

◆ register_read()

void MCP23017::register_read ( uint8_t  reg,
uint8_t *  data,
uint16_t  len 
)
inlineprivate

Reads one or more (sequential) registers in the MCP23017.

Parameters
regstarting register offset.
datawhere to write payload
lennumber of registers to read. Returns when the read is complete.

Definition at line 214 of file MCP23017Gpio.hxx.

◆ register_write()

void MCP23017::register_write ( uint8_t  reg,
const uint8_t *  data,
uint16_t  len 
)
inlineprivate

Writes one or more (sequential) registers in the MCP23017.

Parameters
regstarting register offset.
datapayload to write
lennumber of bytes to write. Returns when the write is complete.

Definition at line 188 of file MCP23017Gpio.hxx.

◆ update_in()

void MCP23017::update_in ( )
inlineprivate

Updates input registers.

Definition at line 178 of file MCP23017Gpio.hxx.

◆ update_out()

void MCP23017::update_out ( )
inlineprivate

Updates the output direction and latch registers if any of it is dirty.

Definition at line 144 of file MCP23017Gpio.hxx.

Friends And Related Symbol Documentation

◆ MCP23017Gpio

friend class MCP23017Gpio
friend

Definition at line 107 of file MCP23017Gpio.hxx.

Member Data Documentation

◆ dir_

uint8_t MCP23017::dir_[2]
private

Shadow of the direction registers.

Definition at line 256 of file MCP23017Gpio.hxx.

◆ dirty_

uint8_t MCP23017::dirty_ = 0
private

Bit mask of registers that need updating.

Definition at line 266 of file MCP23017Gpio.hxx.

◆ executor_

ExecutorBase* MCP23017::executor_
private

Executor. We will be blocking this for the I2C IO.

Definition at line 249 of file MCP23017Gpio.hxx.

◆ fd_

int MCP23017::fd_
private

I2C port file descriptor.

Definition at line 253 of file MCP23017Gpio.hxx.

◆ gpio_

uint8_t MCP23017::gpio_[2]
private

Shadow of the input registers.

Definition at line 260 of file MCP23017Gpio.hxx.

◆ i2cAddress_

uint8_t MCP23017::i2cAddress_
private

Address of this particular device on the I2C port.

Definition at line 263 of file MCP23017Gpio.hxx.

◆ lat_

uint8_t MCP23017::lat_[2]
private

Shadow of the latch registers.

Definition at line 258 of file MCP23017Gpio.hxx.

◆ POLLING_DELAY

constexpr long long MCP23017::POLLING_DELAY = MSEC_TO_NSEC(20)
staticconstexpr

Definition at line 50 of file MCP23017Gpio.hxx.

◆ timer_

RefreshTimer MCP23017::timer_ {this}
private

Timer instance to schedule work on the executor.

Definition at line 251 of file MCP23017Gpio.hxx.


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