libeasymcp2221 2.0.3
mcp2221_gpio_poll.h
Go to the documentation of this file.
1
6#ifndef MCP2221_GPIO_POLL_H
7#define MCP2221_GPIO_POLL_H
8
9#include <stdint.h>
10#include <stddef.h>
11
12#include "mcp2221.h"
13
15
19typedef struct {
27
35
39
47typedef struct {
54 int prev[4];
55
58
65 double last_time;
66
74 uint16_t filter_mask;
76
80typedef enum {
84
88typedef struct {
95 char id[12];
96
98 uint8_t gpio;
99
102
104 double time;
105
107 double last_time;
109
114#define MCP2221_GPIO_POLL_MASK_RISE(pin) (1u << ((pin) * 2))
115
120#define MCP2221_GPIO_POLL_MASK_FALL(pin) (1u << ((pin) * 2 + 1))
121
131
141
160 mcp2221_t *dev,
163);
164
196MCP2221_API int mcp2221_gpio_poll_events(mcp2221_t *dev, mcp2221_gpio_poll_state_t *st, const uint16_t *filter_mask_opt,
197 mcp2221_gpio_event_t *out_events, size_t max_events);
198
200#endif // MCP2221_GPIO_POLL_H
Core MCP2221 device and I2C master API.
struct mcp2221_device mcp2221_t
Opaque MCP2221 device handle.
Definition: mcp2221.h:28
mcp2221_error_code_t
Error codes used by libeasymcp2221.
#define MCP2221_API
Export or import a public libeasymcp2221 API symbol.
#define MCP2221_END_DECLS
End a block started by MCP2221_BEGIN_DECLS.
#define MCP2221_BEGIN_DECLS
Begin a block of declarations using C linkage.
void mcp2221_gpio_poll_init(mcp2221_gpio_poll_state_t *st)
Initialize a GPIO polling state object.
void mcp2221_gpio_poll_set_filter_mask(mcp2221_gpio_poll_state_t *st, uint16_t mask)
Set the persistent edge-event filter mask.
mcp2221_gpio_event_type_t
GPIO edge-event type.
@ MCP2221_GPIO_EVENT_RISE
@ MCP2221_GPIO_EVENT_FALL
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.
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.
Change information for one GP pin.
int changed
Nonzero when old_value and new_value differ.
int old_value
Previous sampled state.
int new_value
Current sampled state.
One GPIO edge event produced by mcp2221_gpio_poll_events().
uint8_t gpio
GP pin number from 0 through 3.
double time
Wall-clock time of the current poll, in seconds.
double last_time
Wall-clock time of the previous successful GPIO poll.
mcp2221_gpio_event_type_t type
Detected edge type.
Persistent state used by the GPIO polling helpers.
double last_time
Wall-clock timestamp of the previous successful GPIO poll.
int initialized
Nonzero after the first successful poll has initialized prev.
uint16_t filter_mask
Persistent edge-event filter mask.