libeasymcp2221 2.0.3
Classes | Macros | Functions
mcp2221_gpio.h File Reference

Direct GPIO input and output helpers. More...

#include <stdint.h>
#include "mcp2221.h"
Include dependency graph for mcp2221_gpio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  mcp2221_gpio_write_t
 Per-pin GPIO output update request. More...
 

Macros

#define MCP2221_GPIO_KEEP   (-1)
 Preserve the current GPIO output value. More...
 

Functions

mcp2221_error_code_t mcp2221_gpio_write (mcp2221_t *dev, const mcp2221_gpio_write_t *wr)
 Update GPIO output values. More...
 
mcp2221_error_code_t mcp2221_gpio_read (mcp2221_t *dev, int out_state[4])
 Read the current state of GP0 through GP3. More...
 
mcp2221_error_code_t mcp2221_gpio_read_mask (mcp2221_t *dev, int out_state[4], uint8_t *out_valid_mask)
 Read GPIO state and report which GP pins are configured as GPIO. More...
 

Detailed Description

Direct GPIO input and output helpers.

Definition in file mcp2221_gpio.h.

Macro Definition Documentation

◆ MCP2221_GPIO_KEEP

#define MCP2221_GPIO_KEEP   (-1)

Preserve the current GPIO output value.

Use this value in a member of mcp2221_gpio_write_t to leave the corresponding output unchanged.

Note
This sentinel is separate from MCP2221_CONFIG_KEEP, which belongs to the SRAM configuration API.

Definition at line 24 of file mcp2221_gpio.h.

Function Documentation

◆ mcp2221_gpio_read()

mcp2221_error_code_t mcp2221_gpio_read ( mcp2221_t dev,
int  out_state[4] 
)

Read the current state of GP0 through GP3.

Each element of out_state corresponds to the same-numbered GP pin.

Parameters
[in]devOpen MCP2221 device handle.
[out]out_stateFour-element array receiving pin states:
  • -1 when the pin is not configured as GPIO
  • 0 for logic low
  • 1 for logic high
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid arguments, or another mcp2221_error_code_t value on failure.

◆ mcp2221_gpio_read_mask()

mcp2221_error_code_t mcp2221_gpio_read_mask ( mcp2221_t dev,
int  out_state[4],
uint8_t *  out_valid_mask 
)

Read GPIO state and report which GP pins are configured as GPIO.

This mirrors the EasyMCP2221 GPIO-read semantics while providing an explicit validity mask in C.

Parameters
[in]devOpen MCP2221 device handle.
[out]out_stateFour-element array receiving -1 for non-GPIO pins, otherwise 0 or 1 for the sampled logic level.
[out]out_valid_maskReceives a bit mask where bit 0 through bit 3 correspond to GP0 through GP3. A set bit means the corresponding pin is configured as GPIO.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid arguments, or another mcp2221_error_code_t value on failure.
See also
mcp2221_gpio_read()

◆ mcp2221_gpio_write()

mcp2221_error_code_t mcp2221_gpio_write ( mcp2221_t dev,
const mcp2221_gpio_write_t wr 
)

Update GPIO output values.

Only members whose value is 0 or 1 are changed; members set to MCP2221_GPIO_KEEP preserve the current output value.

Parameters
[in]devOpen MCP2221 device handle.
[in]wrPer-pin output update request. Must not be NULL.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid arguments or member values, MCP2221_ERR_GPIO_MODE when a requested pin cannot be written as GPIO, MCP2221_ERR_PROTOCOL for an inconsistent device response, or another mcp2221_error_code_t value on failure.
Note
The library updates its cached GPIO output state for pins successfully accepted by the device. A return value of MCP2221_ERR_GPIO_MODE can therefore indicate partial success: other requested pins may already have been updated successfully.