libmcp23016  1.1
Linux userspace driver for Microchip MCP23016 I/O expanders
Modules | Data Structures | Enumerations | Functions
Main API

Main data structures and functions. More...

Modules

 Interrupt Output
 Interrupt output functions.
 

Data Structures

struct  mcp23016_device
 Handle to a MCP23016 device. More...
 

Enumerations

enum  mcp23016_control { MCP23016_CONTROL_IARES_NORMAL = 0, MCP23016_CONTROL_IARES_FAST = 1 }
 Enum that describes I/O control values. More...
 

Functions

struct mcp23016_devicemcp23016_open (const char *path, unsigned int num)
 Open the MCP23016 device specified by path and num. More...
 
void mcp23016_close (struct mcp23016_device *dev)
 Close a MCP23016 device handle and free associated memory. More...
 
int mcp23016_reset (struct mcp23016_device *dev)
 Issue a software reset, which resets registers to POR defaults and clears pending interrupts. More...
 
int mcp23016_get_port (struct mcp23016_device *dev, uint16_t *val)
 Get the port value. More...
 
int mcp23016_set_port (struct mcp23016_device *dev, uint16_t val)
 Set the port value. More...
 
int mcp23016_get_output (struct mcp23016_device *dev, uint16_t *val)
 Get the output latch value. More...
 
int mcp23016_set_output (struct mcp23016_device *dev, uint16_t val)
 Set the output latch value. More...
 
int mcp23016_get_polarity (struct mcp23016_device *dev, uint16_t *val)
 Get the input polarity value. More...
 
int mcp23016_set_polarity (struct mcp23016_device *dev, uint16_t val)
 Set the input polarity value. More...
 
int mcp23016_get_direction (struct mcp23016_device *dev, uint16_t *val)
 Get the I/O direction value. More...
 
int mcp23016_set_direction (struct mcp23016_device *dev, uint16_t val)
 Set the I/O direction value. More...
 
int mcp23016_get_interrupt (struct mcp23016_device *dev, uint16_t *val)
 Get the interrupt capture value. More...
 
static int mcp23016_clear_interrupt (struct mcp23016_device *dev)
 Clear interrupt status. More...
 
int mcp23016_get_control (struct mcp23016_device *dev, uint16_t *val)
 Get the I/O control value. More...
 
int mcp23016_set_control (struct mcp23016_device *dev, uint16_t val)
 Set the I/O control value. More...
 

Detailed Description

Main data structures and functions.

#include <mcp23016.h>

Enumeration Type Documentation

◆ mcp23016_control

Enum that describes I/O control values.

Enumerator
MCP23016_CONTROL_IARES_NORMAL 

Normal interrupt activity resolution (32ms).

MCP23016_CONTROL_IARES_FAST 

Fast interrupt activity resolution (200us).

Function Documentation

◆ mcp23016_clear_interrupt()

static int mcp23016_clear_interrupt ( struct mcp23016_device dev)
inlinestatic

Clear interrupt status.

Parameters
devPointer to a MCP23016 device handle.
Returns
0 on success, or -1 on error with errno set appropriately.

This function is equivalent to calling:

uint16_t dummy;

◆ mcp23016_close()

void mcp23016_close ( struct mcp23016_device dev)

Close a MCP23016 device handle and free associated memory.

Parameters
devPointer to a MCP23016 device handle.

Once closed, dev is no longer valid for use.

◆ mcp23016_get_control()

int mcp23016_get_control ( struct mcp23016_device dev,
uint16_t *  val 
)

Get the I/O control value.

Parameters
devPointer to a MCP23016 device handle.
valPointer to the value to receive.
Returns
0 on success, or -1 on error with errno set appropriately.

This function returns the value of the IOCON0 and IOCON1 registers in the low and high bytes, respectively.

◆ mcp23016_get_direction()

int mcp23016_get_direction ( struct mcp23016_device dev,
uint16_t *  val 
)

Get the I/O direction value.

Parameters
devPointer to a MCP23016 device handle.
valPointer to the value to receive.
Returns
0 on success, or -1 on error with errno set appropriately.

This function returns the value of the IODIR0 and IODIR1 registers in the low and high bytes, respectively.

◆ mcp23016_get_interrupt()

int mcp23016_get_interrupt ( struct mcp23016_device dev,
uint16_t *  val 
)

Get the interrupt capture value.

Parameters
devPointer to a MCP23016 device handle.
valPointer to the value to receive.
Returns
0 on success, or -1 on error with errno set appropriately.

This function returns the value of the INTCAP0 and INTCAP1 registers in the low and high bytes, respectively.

◆ mcp23016_get_output()

int mcp23016_get_output ( struct mcp23016_device dev,
uint16_t *  val 
)

Get the output latch value.

Parameters
devPointer to a MCP23016 device handle.
valPointer to the value to receive.
Returns
0 on success, or -1 on error with errno set appropriately.

This function returns the value of the OLAT0 and OLAT1 registers in the low and high bytes, respectively.

◆ mcp23016_get_polarity()

int mcp23016_get_polarity ( struct mcp23016_device dev,
uint16_t *  val 
)

Get the input polarity value.

Parameters
devPointer to a MCP23016 device handle.
valPointer to the value to receive.
Returns
0 on success, or -1 on error with errno set appropriately.

This function returns the value of the IPOL0 and IPOL1 registers in the low and high bytes, respectively.

◆ mcp23016_get_port()

int mcp23016_get_port ( struct mcp23016_device dev,
uint16_t *  val 
)

Get the port value.

Parameters
devPointer to a MCP23016 device handle.
valPointer to the value to receive.
Returns
0 on success, or -1 on error with errno set appropriately.

This function returns the value of the GP0 and GP1 registers in the low and high bytes, respectively.

◆ mcp23016_open()

struct mcp23016_device* mcp23016_open ( const char *  path,
unsigned int  num 
)

Open the MCP23016 device specified by path and num.

Parameters
pathPointer to an I2C character device.
numRelative position of device on I2C bus (ie. AD0-2).
Returns
Pointer to a MCP23016 device handle, or NULL on error with errno set appropriately.

◆ mcp23016_reset()

int mcp23016_reset ( struct mcp23016_device dev)

Issue a software reset, which resets registers to POR defaults and clears pending interrupts.

Parameters
devPointer to a MCP23016 device handle.
Returns
0 on success, or -1 on error with errno set appropriately.

◆ mcp23016_set_control()

int mcp23016_set_control ( struct mcp23016_device dev,
uint16_t  val 
)

Set the I/O control value.

Parameters
devPointer to a MCP23016 device handle.
valThe value to set.
Returns
0 on success, or -1 on error with errno set appropriately.

This function writes the value of the IOCON0 and IOCON1 registers in the low and high bytes, respectively.

◆ mcp23016_set_direction()

int mcp23016_set_direction ( struct mcp23016_device dev,
uint16_t  val 
)

Set the I/O direction value.

Parameters
devPointer to a MCP23016 device handle.
valThe value to set.
Returns
0 on success, or -1 on error with errno set appropriately.

This function writes the value of the IODIR0 and IODIR1 registers in the low and high bytes, respectively.

◆ mcp23016_set_output()

int mcp23016_set_output ( struct mcp23016_device dev,
uint16_t  val 
)

Set the output latch value.

Parameters
devPointer to a MCP23016 device handle.
valThe value to set.
Returns
0 on success, or -1 on error with errno set appropriately.

This function writes the value of the OLAT0 and OLAT1 registers in the low and high bytes, respectively.

◆ mcp23016_set_polarity()

int mcp23016_set_polarity ( struct mcp23016_device dev,
uint16_t  val 
)

Set the input polarity value.

Parameters
devPointer to a MCP23016 device handle.
valThe value to set.
Returns
0 on success, or -1 on error with errno set appropriately.

This function writes the value of the IPOL0 and IPOL1 registers in the low and high bytes, respectively.

◆ mcp23016_set_port()

int mcp23016_set_port ( struct mcp23016_device dev,
uint16_t  val 
)

Set the port value.

Parameters
devPointer to a MCP23016 device handle.
valThe value to set.
Returns
0 on success, or -1 on error with errno set appropriately.

This function writes the value of the GP0 and GP1 registers in the low and high bytes, respectively.

mcp23016_get_interrupt
int mcp23016_get_interrupt(struct mcp23016_device *dev, uint16_t *val)
Get the interrupt capture value.