|
libeasymcp2221 2.0.3
|
Stateful GPIO change and edge-event polling helpers. More...
Go to the source code of this file.
Classes | |
| struct | mcp2221_gpio_change_t |
| Change information for one GP pin. More... | |
| struct | mcp2221_gpio_poll_state_t |
| Persistent state used by the GPIO polling helpers. More... | |
| struct | mcp2221_gpio_event_t |
| One GPIO edge event produced by mcp2221_gpio_poll_events(). More... | |
Macros | |
| #define | MCP2221_GPIO_POLL_MASK_RISE(pin) (1u << ((pin) * 2)) |
| Build the filter-mask bit for a rising edge on a GP pin. More... | |
| #define | MCP2221_GPIO_POLL_MASK_FALL(pin) (1u << ((pin) * 2 + 1)) |
| Build the filter-mask bit for a falling edge on a GP pin. More... | |
Enumerations | |
| enum | mcp2221_gpio_event_type_t { MCP2221_GPIO_EVENT_RISE = 0 , MCP2221_GPIO_EVENT_FALL = 1 } |
| GPIO edge-event type. More... | |
Functions | |
| void | mcp2221_gpio_poll_init (mcp2221_gpio_poll_state_t *st) |
| Initialize a GPIO polling state object. More... | |
| void | mcp2221_gpio_poll_set_filter_mask (mcp2221_gpio_poll_state_t *st, uint16_t mask) |
| Set the persistent edge-event filter mask. More... | |
| mcp2221_error_code_t | mcp2221_gpio_poll (mcp2221_t *dev, mcp2221_gpio_poll_state_t *st, mcp2221_gpio_change_t out[4]) |
| Poll GP0 through GP3 and report per-pin state changes. More... | |
| int | mcp2221_gpio_poll_events (mcp2221_t *dev, mcp2221_gpio_poll_state_t *st, const uint16_t *filter_mask_opt, mcp2221_gpio_event_t *out_events, size_t max_events) |
| Poll GPIO changes and emit filtered rise/fall events. More... | |
Stateful GPIO change and edge-event polling helpers.
Definition in file mcp2221_gpio_poll.h.
| #define MCP2221_GPIO_POLL_MASK_FALL | ( | pin | ) | (1u << ((pin) * 2 + 1)) |
Build the filter-mask bit for a falling edge on a GP pin.
| pin | GP pin number from 0 through 3. |
Definition at line 120 of file mcp2221_gpio_poll.h.
| #define MCP2221_GPIO_POLL_MASK_RISE | ( | pin | ) | (1u << ((pin) * 2)) |
Build the filter-mask bit for a rising edge on a GP pin.
| pin | GP pin number from 0 through 3. |
Definition at line 114 of file mcp2221_gpio_poll.h.
GPIO edge-event type.
| Enumerator | |
|---|---|
| MCP2221_GPIO_EVENT_RISE | Low-to-high transition. |
| MCP2221_GPIO_EVENT_FALL | High-to-low transition. |
Definition at line 80 of file mcp2221_gpio_poll.h.
| mcp2221_error_code_t mcp2221_gpio_poll | ( | mcp2221_t * | dev, |
| mcp2221_gpio_poll_state_t * | st, | ||
| mcp2221_gpio_change_t | out[4] | ||
| ) |
Poll GP0 through GP3 and report per-pin state changes.
On the first successful call, the function initializes the previous-state snapshot and reports changed == 0 for every pin. Each successful call also updates the timestamp shared with mcp2221_gpio_poll_events().
A sampled value of -1 indicates that the corresponding pin is not currently configured as GPIO.
| [in] | dev | Open MCP2221 device handle. |
| [in,out] | st | Initialized polling state. |
| [out] | out | Four-element array receiving GP0 through GP3 changes. |
| int mcp2221_gpio_poll_events | ( | mcp2221_t * | dev, |
| mcp2221_gpio_poll_state_t * | st, | ||
| const uint16_t * | filter_mask_opt, | ||
| mcp2221_gpio_event_t * | out_events, | ||
| size_t | max_events | ||
| ) |
Poll GPIO changes and emit filtered rise/fall events.
If the polling snapshot has not yet been initialized by either GPIO polling helper, the first successful call initializes it and returns zero events. Transitions are emitted only when both the previous and current samples are valid GPIO states.
If filter_mask_opt is NULL, the filter already stored in st is preserved. Otherwise *filter_mask_opt becomes the new persistent filter; a value of 0 accepts all events.
At most max_events events are written. The polling state advances after every successful call even when more matching transitions occurred than fit in out_events, so excess events are discarded rather than returned by a later poll.
| [in] | dev | Open MCP2221 device handle. |
| [in,out] | st | Initialized polling state. |
| [in] | filter_mask_opt | Optional replacement filter mask, or NULL to preserve the existing filter. |
| [out] | out_events | Event buffer. May be NULL only when max_events is 0. |
| [in] | max_events | Maximum number of events that may be written. |
max_events, on success; otherwise a negative mcp2221_error_code_t value.| void mcp2221_gpio_poll_init | ( | mcp2221_gpio_poll_state_t * | st | ) |
Initialize a GPIO polling state object.
The filter is reset to 0, which accepts all edge events. Passing NULL is a no-op.
| [out] | st | Polling state to initialize. |
| void mcp2221_gpio_poll_set_filter_mask | ( | mcp2221_gpio_poll_state_t * | st, |
| uint16_t | mask | ||
| ) |
Set the persistent edge-event filter mask.
A mask of 0 accepts all events. Passing NULL is a no-op.
| [in,out] | st | Polling state whose filter is updated. |
| [in] | mask | New event filter mask. |