8#ifndef ZEPHYR_MCTP_I2C_GPIO_CONTROLLER_H_
9#define ZEPHYR_MCTP_I2C_GPIO_CONTROLLER_H_
27struct mctp_i2c_gpio_controller_cb {
29 struct gpio_callback callback;
30 struct mctp_binding_i2c_gpio_controller *binding;
41 struct mctp_binding binding;
45 uint8_t rx_buf[MCTP_I2C_GPIO_MAX_PKT_SIZE];
46 uint8_t tx_buf[MCTP_I2C_GPIO_MAX_PKT_SIZE];
48 struct mctp_pktbuf *rx_pkt;
51 struct k_sem *tx_lock;
59 struct mctp_i2c_gpio_controller_cb *endpoint_gpio_cbs;
65 struct mctp_i2c_gpio_controller_cb *inflight_rx;
71int mctp_i2c_gpio_controller_start(
struct mctp_binding *binding);
72int mctp_i2c_gpio_controller_tx(
struct mctp_binding *binding,
struct mctp_pktbuf *pkt);
74#define MCTP_I2C_GPIO_CONTROLLER_IODEV_NAME(_idx, _name) _name##_idx
76#define MCTP_I2C_GPIO_CONTROLLER_IODEV_DEFINE(_node_id, addrs, _idx, _name) \
77 I2C_IODEV_DEFINE(MCTP_I2C_GPIO_CONTROLLER_IODEV_NAME(_idx, _name), \
78 DT_PHANDLE(_node_id, i2c), \
79 DT_PROP_BY_IDX(_node_id, addrs, _idx));
82#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIOS(_node_id, _name) \
83 const struct gpio_dt_spec _name##_endpoint_gpios[] = { \
84 DT_FOREACH_PROP_ELEM_SEP(_node_id, endpoint_gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)) \
87#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_IDS(_node_id, _name) \
88 const uint8_t _name##_endpoint_ids[] = DT_PROP(_node_id, endpoint_ids);
90#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIO_CBS(_node_id, _name) \
91 struct mctp_i2c_gpio_controller_cb \
92 _name##_endpoint_gpio_cbs[DT_PROP_LEN(_node_id, endpoint_ids)]
95#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_IODEVS(_node_id, _name) \
96 DT_FOREACH_PROP_ELEM_VARGS(_node_id, endpoint_addrs, \
97 MCTP_I2C_GPIO_CONTROLLER_IODEV_DEFINE, _name) \
98 const struct rtio_iodev *_name##_endpoint_iodevs[] = { \
99 LISTIFY(DT_PROP_LEN(_node_id, endpoint_ids), &MCTP_I2C_GPIO_CONTROLLER_IODEV_NAME, \
127#define MCTP_I2C_GPIO_CONTROLLER_DT_DEFINE(_name, _node_id) \
128 RTIO_DEFINE(_name##_rtio_tx, 5, 5); \
129 RTIO_DEFINE(_name##_rtio_rx, 5, 5); \
130 MCTP_I2C_GPIO_CONTROLLER_DEFINE_IODEVS(_node_id, _name); \
131 MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIOS(_node_id, _name); \
132 MCTP_I2C_GPIO_CONTROLLER_DEFINE_IDS(_node_id, _name); \
133 MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIO_CBS(_node_id, _name); \
134 K_SEM_DEFINE(_name##_tx_lock, 1, 1); \
135 struct mctp_binding_i2c_gpio_controller _name = { \
137 .name = STRINGIFY(_name), .version = 1, \
138 .start = mctp_i2c_gpio_controller_start, \
139 .tx = mctp_i2c_gpio_controller_tx, \
140 .pkt_size = MCTP_I2C_GPIO_MAX_PKT_SIZE, \
142 .i2c = DEVICE_DT_GET(DT_PHANDLE(_node_id, i2c)), \
143 .num_endpoints = DT_PROP_LEN(_node_id, endpoint_ids), \
144 .endpoint_ids = _name##_endpoint_ids, \
145 .endpoint_gpios = _name##_endpoint_gpios, \
146 .endpoint_gpio_cbs = _name##_endpoint_gpio_cbs, \
147 .endpoint_iodevs = _name##_endpoint_iodevs, \
148 .r_tx = &_name##_rtio_tx, \
149 .r_rx = &_name##_rtio_rx, \
150 .tx_lock = &_name##_tx_lock, \
Main header file for GPIO driver API.
Main header file for I2C (Inter-Integrated Circuit) driver API.
A wait-free intrusive multi producer single consumer (MPSC) queue using a singly linked list.
Real-Time IO device API for moving bytes with low effort.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Semaphore structure.
Definition kernel.h:3397
Kernel Spin Lock.
Definition spinlock.h:45
An MCTP binding for Zephyr's I2C interface using GPIO.
Definition mctp_i2c_gpio_controller.h:39
MPSC Queue.
Definition mpsc_lockfree.h:86
An IO device with a function table for submitting requests.
Definition rtio.h:540
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:419