libeasymcp2221 2.0.3
Classes | Enumerations | Functions
mcp2221_pin.h File Reference

High-level MCP2221 GP pin-function configuration. More...

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

Go to the source code of this file.

Classes

struct  mcp2221_pin_functions_t
 Batch configuration for GP0 through GP3. More...
 

Enumerations

enum  mcp2221_gpio_pin_t { MCP2221_GPIO_PIN_GP0 = 0 , MCP2221_GPIO_PIN_GP1 = 1 , MCP2221_GPIO_PIN_GP2 = 2 , MCP2221_GPIO_PIN_GP3 = 3 }
 MCP2221 general-purpose pin identifiers. More...
 
enum  mcp2221_pin_function_t {
  MCP2221_PIN_FUNC_KEEP = -1 , MCP2221_PIN_FUNC_DEDICATED = 0 , MCP2221_PIN_FUNC_ALT0 = 1 , MCP2221_PIN_FUNC_ALT1 = 2 ,
  MCP2221_PIN_FUNC_ALT2 = 3 , MCP2221_PIN_FUNC_GPIO_IN = 4 , MCP2221_PIN_FUNC_GPIO_OUT = 5
}
 High-level pin functions. More...
 

Functions

mcp2221_error_code_t mcp2221_pin_set_function (mcp2221_t *dev, mcp2221_gpio_pin_t pin, mcp2221_pin_function_t function)
 Set the function of one GP pin. More...
 
mcp2221_error_code_t mcp2221_pin_set_functions (mcp2221_t *dev, const mcp2221_pin_functions_t *cfg)
 Configure the functions of GP0 through GP3 in one operation. More...
 

Detailed Description

High-level MCP2221 GP pin-function configuration.

Definition in file mcp2221_pin.h.

Enumeration Type Documentation

◆ mcp2221_gpio_pin_t

MCP2221 general-purpose pin identifiers.

Enumerator
MCP2221_GPIO_PIN_GP0 

GP0.

MCP2221_GPIO_PIN_GP1 

GP1.

MCP2221_GPIO_PIN_GP2 

GP2.

MCP2221_GPIO_PIN_GP3 

GP3.

Definition at line 18 of file mcp2221_pin.h.

◆ mcp2221_pin_function_t

High-level pin functions.

The ALT function values represent the MCP2221 alternate-function selector, but not every alternate function is valid on every GP pin.

Enumerator
MCP2221_PIN_FUNC_KEEP 

Preserve the current pin configuration in batch configuration.

MCP2221_PIN_FUNC_DEDICATED 

Select the pin's dedicated MCP2221 function.

MCP2221_PIN_FUNC_ALT0 

Select alternate function 0 for the pin.

MCP2221_PIN_FUNC_ALT1 

Select alternate function 1 where supported.

MCP2221_PIN_FUNC_ALT2 

Select alternate function 2; supported only on GP1.

MCP2221_PIN_FUNC_GPIO_IN 

Configure the pin as a GPIO input.

MCP2221_PIN_FUNC_GPIO_OUT 

Configure the pin as a GPIO output.

Definition at line 31 of file mcp2221_pin.h.

Function Documentation

◆ mcp2221_pin_set_function()

mcp2221_error_code_t mcp2221_pin_set_function ( mcp2221_t dev,
mcp2221_gpio_pin_t  pin,
mcp2221_pin_function_t  function 
)

Set the function of one GP pin.

MCP2221_PIN_FUNC_KEEP is not accepted by this single-pin helper and returns MCP2221_ERR_INVALID. Use mcp2221_pin_set_functions() when a batch configuration needs to preserve selected pins.

For accepted functions, the helper writes a complete GP configuration. GPIO outputs are initialized low because this function has no output-value parameter.

Supported functions by pin:

  • GP0: DEDICATED, ALT0, GPIO_IN, GPIO_OUT
  • GP1: DEDICATED, ALT0, ALT1, ALT2, GPIO_IN, GPIO_OUT
  • GP2: DEDICATED, ALT0, ALT1, GPIO_IN, GPIO_OUT
  • GP3: DEDICATED, ALT0, ALT1, GPIO_IN, GPIO_OUT
Parameters
[in]devOpen MCP2221 device handle.
[in]pinGP pin to configure.
[in]functionRequested high-level pin function.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for an invalid pin or unsupported function, or another mcp2221_error_code_t value on failure.

◆ mcp2221_pin_set_functions()

mcp2221_error_code_t mcp2221_pin_set_functions ( mcp2221_t dev,
const mcp2221_pin_functions_t cfg 
)

Configure the functions of GP0 through GP3 in one operation.

Pins whose mcp2221_pin_functions_t::gp entry is MCP2221_PIN_FUNC_KEEP are preserved. For GPIO outputs, the corresponding mcp2221_pin_functions_t::out entry selects the initial output value.

Parameters
[in]devOpen MCP2221 device handle.
[in]cfgFour-pin configuration. Must not be NULL.
Returns
MCP2221_ERR_OK on success, MCP2221_ERR_INVALID for invalid output values or unsupported pin/function combinations, or another mcp2221_error_code_t value on failure.
Note
Every mcp2221_pin_functions_t::out entry must be 0 or 1. A value of 1 is allowed only for a pin configured as MCP2221_PIN_FUNC_GPIO_OUT.