Lines Matching +full:device +full:- +full:id

4  * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/pm/device.h>
19 #define SHIM_NRF_TWIS_NODE(id) \ argument
20 DT_NODELABEL(_CONCAT(i2c, id))
22 #define SHIM_NRF_TWIS_DEVICE_GET(id) \ argument
23 DEVICE_DT_GET(SHIM_NRF_TWIS_NODE(id))
25 #define SHIM_NRF_TWIS_IRQ_HANDLER(id) \ argument
26 _CONCAT_3(nrfx_twis_, id, _irq_handler)
28 #define SHIM_NRF_TWIS_IRQN(id) \ argument
29 DT_IRQN(SHIM_NRF_TWIS_NODE(id))
31 #define SHIM_NRF_TWIS_IRQ_PRIO(id) \ argument
32 DT_IRQ(SHIM_NRF_TWIS_NODE(id), priority)
34 #define SHIM_NRF_TWIS_HAS_MEMORY_REGIONS(id) \ argument
35 DT_NODE_HAS_PROP(id, memory_regions)
37 #define SHIM_NRF_TWIS_LINKER_REGION_NAME(id) \ argument
38 LINKER_DT_NODE_REGION_NAME(DT_PHANDLE(SHIM_NRF_TWIS_NODE(id), memory_regions))
40 #define SHIM_NRF_TWIS_BUF_ATTR_SECTION(id) \ argument
43 #define SHIM_NRF_TWIS_BUF_ATTR(id) \ argument
45 SHIM_NRF_TWIS_HAS_MEMORY_REGIONS(id), \
46 (SHIM_NRF_TWIS_BUF_ATTR_SECTION(id)), \
69 static bool shim_nrf_twis_is_resumed(const struct device *dev) in shim_nrf_twis_is_resumed()
77 static bool shim_nrf_twis_is_resumed(const struct device *dev) in shim_nrf_twis_is_resumed()
85 static void shim_nrf_twis_enable(const struct device *dev) in shim_nrf_twis_enable()
87 struct shim_nrf_twis_data *dev_data = dev->data; in shim_nrf_twis_enable()
88 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_enable()
90 if (dev_data->enabled) { in shim_nrf_twis_enable()
94 if (dev_data->target_config == NULL) { in shim_nrf_twis_enable()
98 (void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); in shim_nrf_twis_enable()
99 nrfx_twis_enable(&dev_config->twis); in shim_nrf_twis_enable()
100 dev_data->enabled = true; in shim_nrf_twis_enable()
103 static void shim_nrf_twis_disable(const struct device *dev) in shim_nrf_twis_disable()
105 struct shim_nrf_twis_data *dev_data = dev->data; in shim_nrf_twis_disable()
106 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_disable()
108 if (!dev_data->enabled) { in shim_nrf_twis_disable()
112 dev_data->enabled = false; in shim_nrf_twis_disable()
113 nrfx_twis_disable(&dev_config->twis); in shim_nrf_twis_disable()
114 (void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); in shim_nrf_twis_disable()
117 static void shim_nrf_twis_handle_read_req(const struct device *dev) in shim_nrf_twis_handle_read_req()
119 struct shim_nrf_twis_data *dev_data = dev->data; in shim_nrf_twis_handle_read_req()
120 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_handle_read_req()
121 struct i2c_target_config *target_config = dev_data->target_config; in shim_nrf_twis_handle_read_req()
122 const struct i2c_target_callbacks *callbacks = target_config->callbacks; in shim_nrf_twis_handle_read_req()
123 const nrfx_twis_t *twis = &dev_config->twis; in shim_nrf_twis_handle_read_req()
128 if (callbacks->buf_read_requested(target_config, &buf, &buf_size)) { in shim_nrf_twis_handle_read_req()
138 memcpy(dev_config->buf, buf, buf_size); in shim_nrf_twis_handle_read_req()
140 err = nrfx_twis_tx_prepare(twis, dev_config->buf, buf_size); in shim_nrf_twis_handle_read_req()
147 static void shim_nrf_twis_handle_write_req(const struct device *dev) in shim_nrf_twis_handle_write_req()
149 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_handle_write_req()
150 const nrfx_twis_t *twis = &dev_config->twis; in shim_nrf_twis_handle_write_req()
153 err = nrfx_twis_rx_prepare(twis, dev_config->buf, SHIM_NRF_TWIS_BUF_SIZE); in shim_nrf_twis_handle_write_req()
160 static void shim_nrf_twis_handle_write_done(const struct device *dev) in shim_nrf_twis_handle_write_done()
162 struct shim_nrf_twis_data *dev_data = dev->data; in shim_nrf_twis_handle_write_done()
163 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_handle_write_done()
164 struct i2c_target_config *target_config = dev_data->target_config; in shim_nrf_twis_handle_write_done()
165 const struct i2c_target_callbacks *callbacks = target_config->callbacks; in shim_nrf_twis_handle_write_done()
166 const nrfx_twis_t *twis = &dev_config->twis; in shim_nrf_twis_handle_write_done()
168 callbacks->buf_write_received(target_config, dev_config->buf, nrfx_twis_rx_amount(twis)); in shim_nrf_twis_handle_write_done()
171 static void shim_nrf_twis_event_handler(const struct device *dev, in shim_nrf_twis_event_handler()
174 switch (event->type) { in shim_nrf_twis_event_handler()
192 static int shim_nrf_twis_pm_action_cb(const struct device *dev, in shim_nrf_twis_pm_action_cb()
207 return -ENOTSUP; in shim_nrf_twis_pm_action_cb()
213 static int shim_nrf_twis_target_register(const struct device *dev, in shim_nrf_twis_target_register()
216 struct shim_nrf_twis_data *dev_data = dev->data; in shim_nrf_twis_target_register()
217 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_target_register()
218 const nrfx_twis_t *twis = &dev_config->twis; in shim_nrf_twis_target_register()
222 target_config->address, in shim_nrf_twis_target_register()
228 if (target_config->flags) { in shim_nrf_twis_target_register()
229 LOG_ERR("16-bit address unsupported"); in shim_nrf_twis_target_register()
230 return -EINVAL; in shim_nrf_twis_target_register()
237 return -ENODEV; in shim_nrf_twis_target_register()
240 dev_data->target_config = target_config; in shim_nrf_twis_target_register()
249 static int shim_nrf_twis_target_unregister(const struct device *dev, in shim_nrf_twis_target_unregister()
252 struct shim_nrf_twis_data *dev_data = dev->data; in shim_nrf_twis_target_unregister()
254 if (dev_data->target_config != target_config) { in shim_nrf_twis_target_unregister()
255 return -EINVAL; in shim_nrf_twis_target_unregister()
259 dev_data->target_config = NULL; in shim_nrf_twis_target_unregister()
268 static int shim_nrf_twis_init(const struct device *dev) in shim_nrf_twis_init()
270 const struct shim_nrf_twis_config *dev_config = dev->config; in shim_nrf_twis_init()
277 err = nrfx_twis_init(&dev_config->twis, &config, dev_config->event_handler); in shim_nrf_twis_init()
279 return -ENODEV; in shim_nrf_twis_init()
282 dev_config->irq_connect(); in shim_nrf_twis_init()
286 #define SHIM_NRF_TWIS_NAME(id, name) \ argument
287 _CONCAT_4(shim_nrf_twis_, name, _, id)
289 #define SHIM_NRF_TWIS_DEVICE_DEFINE(id) \ argument
290 static void SHIM_NRF_TWIS_NAME(id, irq_connect)(void) \
293 SHIM_NRF_TWIS_IRQN(id), \
294 SHIM_NRF_TWIS_IRQ_PRIO(id), \
296 SHIM_NRF_TWIS_IRQ_HANDLER(id), \
301 static void SHIM_NRF_TWIS_NAME(id, event_handler)(nrfx_twis_evt_t const *event) \
303 shim_nrf_twis_event_handler(SHIM_NRF_TWIS_DEVICE_GET(id), event); \
306 static struct shim_nrf_twis_data SHIM_NRF_TWIS_NAME(id, data); \
308 PINCTRL_DT_DEFINE(SHIM_NRF_TWIS_NODE(id)); \
310 static uint8_t SHIM_NRF_TWIS_NAME(id, buf) \
311 [SHIM_NRF_TWIS_BUF_SIZE] SHIM_NRF_TWIS_BUF_ATTR(id); \
313 static const struct shim_nrf_twis_config SHIM_NRF_TWIS_NAME(id, config) = { \
314 .twis = NRFX_TWIS_INSTANCE(id), \
315 .irq_connect = SHIM_NRF_TWIS_NAME(id, irq_connect), \
316 .event_handler = SHIM_NRF_TWIS_NAME(id, event_handler), \
317 .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SHIM_NRF_TWIS_NODE(id)), \
318 .buf = SHIM_NRF_TWIS_NAME(id, buf), \
322 SHIM_NRF_TWIS_NODE(id), \
327 SHIM_NRF_TWIS_NODE(id), \
329 PM_DEVICE_DT_GET(SHIM_NRF_TWIS_NODE(id)), \
330 &SHIM_NRF_TWIS_NAME(id, data), \
331 &SHIM_NRF_TWIS_NAME(id, config), \