9#ifndef INFUSE_SDK_INCLUDE_INFUSE_SHARED_DEVICE_H_
10#define INFUSE_SDK_INCLUDE_INFUSE_SHARED_DEVICE_H_
15#include <zephyr/device.h>
79#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx) \
81 .shared = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
82 .state = DT_PHA_BY_IDX(node_id, prop, idx, state), \
83 .priority = DT_PHA_BY_IDX(node_id, prop, idx, priority), \
103#define SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
104 COND_CODE_1(DT_NODE_HAS_PROP(node_id, prop), \
105 (SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, idx)), (default_value))
115#define SHARED_DEVICE_DT_SPEC_GET(node_id, prop) SHARED_DEVICE_DT_SPEC_GET_BY_IDX(node_id, prop, 0)
127#define SHARED_DEVICE_DT_SPEC_GET_OR(node_id, prop, default_value) \
128 SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(node_id, prop, 0, default_value)
140#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, idx) \
141 SHARED_DEVICE_DT_SPEC_GET_BY_IDX(DT_DRV_INST(inst), prop, idx)
154#define SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, idx, default_value) \
155 SHARED_DEVICE_DT_SPEC_GET_BY_IDX_OR(DT_DRV_INST(inst), prop, idx, default_value)
165#define SHARED_DEVICE_DT_SPEC_INST_GET(inst, prop) \
166 SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX(inst, prop, 0)
178#define SHARED_DEVICE_DT_SPEC_INST_GET_OR(inst, prop, default_value) \
179 SHARED_DEVICE_DT_SPEC_INST_GET_BY_IDX_OR(inst, prop, 0, default_value)
184 int (*
request)(
const struct device *dev, uint8_t state_priority, uint8_t state);
186 int (*
release)(
const struct device *dev, uint8_t state_priority);
199 if (spec->
shared == NULL) {
202 return device_is_ready(spec->
shared);
224 return api->
request(dev, state_priority, state);
240 if (spec->
shared == NULL) {
259 return api->
release(dev, state_priority);
275 if (spec->
shared == NULL) {
static bool shared_device_is_ready_dt(const struct shared_device_dt_spec *spec)
Validate that the shared device is ready.
Definition device.h:197
static int shared_device_release_dt(const struct shared_device_dt_spec *spec)
Release a shared device from a shared_device_dt_spec.
Definition device.h:273
static int shared_device_request(const struct device *dev, uint8_t state_priority, uint8_t state)
Request a device to be in a given state.
Definition device.h:219
static int shared_device_request_dt(const struct shared_device_dt_spec *spec)
Request a shared device from a shared_device_dt_spec.
Definition device.h:238
static int shared_device_release(const struct device *dev, uint8_t state_priority)
Release a previous request for a given state.
Definition device.h:255
Shared device driver API.
Definition device.h:182
int(* release)(const struct device *dev, uint8_t state_priority)
Implementation of shared_device_release.
Definition device.h:186
int(* request)(const struct device *dev, uint8_t state_priority, uint8_t state)
Implementation of shared_device_request.
Definition device.h:184
Container for shared device information specified in devicetree.
Definition device.h:39
const struct device * shared
Pointer to the shared device.
Definition device.h:41
uint8_t priority
Priority of the state request.
Definition device.h:45
uint8_t state
State that is being requested.
Definition device.h:43