Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
regset_target_lib.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2017 BayLibre, SAS
3 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_DRIVERS_I2C_TARGET_REGSET_TARGET_LIB_H_
13#define ZEPHYR_INCLUDE_DRIVERS_I2C_TARGET_REGSET_TARGET_LIB_H_
14
15#include <stddef.h>
16#include <sys/types.h>
17
24typedef void (*regset_target_lib_changed_handler_t)(const struct device *dev, void *user_data);
25
33 const struct device *dev;
34 struct i2c_target_config config;
35 uint32_t buffer_idx;
36 uint32_t idx_write_cnt;
38 void *changed_handler_data;
39 bool changed;
41};
42
50 struct i2c_dt_spec bus;
51 uint32_t buffer_size;
52 uint8_t *buffer;
53 uint8_t address_width;
55};
56
66 void *user_data);
67
75size_t regset_target_lib_get_size(const struct device *dev);
76
87int regset_target_lib_read_data(const struct device *dev, off_t offset,
88 void *data, size_t len);
89
100int regset_target_lib_write_data(const struct device *dev, off_t offset,
101 const void *data, size_t len);
102
115
119extern const struct i2c_target_driver_api regset_target_api;
120
128int regset_target_lib_init(const struct device *dev);
129
136#define REGSET_TARGET_LIB_STRUCT_CHECK(config, data) \
137 BUILD_ASSERT(offsetof(config, regset_cfg) == 0, \
138 "struct regset_target_lib_config must be placed first"); \
139 BUILD_ASSERT(offsetof(data, regset_data) == 0, \
140 "struct regset_target_lib_data must be placed first")
141
145#define REGSET_TARGET_LIB_DT_BUILD_ASSERT(node_id) \
146 BUILD_ASSERT(DT_PROP(node_id, size) <= (1 << DT_PROP_OR(node_id, address_width, 8)), \
147 "size must be <= than 2^address_width");
148
152#define REGSET_TARGET_LIB_DT_INST_BUILD_ASSERT(inst) \
153 REGSET_TARGET_LIB_DT_BUILD_ASSERT(DT_DRV_INST(inst))
154
158#define REGSET_TARGET_LIB_DT_CONFIG_INIT(node_id) \
159{ \
160 .bus = I2C_DT_SPEC_GET(node_id), \
161 .buffer_size = DT_PROP(node_id, size), \
162 .buffer = (uint8_t[DT_PROP(node_id, size)]) {}, \
163 .address_width = DT_PROP_OR(node_id, address_width, 8), \
164}
165
169#define REGSET_TARGET_LIB_DT_INST_CONFIG_INIT(inst) \
170 REGSET_TARGET_LIB_DT_CONFIG_INIT(DT_DRV_INST(inst))
171
172#endif /* ZEPHYR_INCLUDE_DRIVERS_I2C_TARGET_REGSET_TARGET_LIB_H_ */
__INTPTR_TYPE__ off_t
Definition types.h:36
int regset_target_lib_write_data(const struct device *dev, off_t offset, const void *data, size_t len)
Write data to the register set.
int regset_target_lib_set_addr(const struct device *dev, uint8_t addr)
Change the address of register set target at runtime.
size_t regset_target_lib_get_size(const struct device *dev)
Get size of the register set.
void regset_target_lib_set_changed_callback(const struct device *dev, regset_target_lib_changed_handler_t handler, void *user_data)
Set the regset changed callback handler.
void(* regset_target_lib_changed_handler_t)(const struct device *dev, void *user_data)
Define the application callback handler function signature.
Definition regset_target_lib.h:24
const struct i2c_target_driver_api regset_target_api
Generig register set library i2c target API.
int regset_target_lib_init(const struct device *dev)
Initialize the register set data structures.
int regset_target_lib_read_data(const struct device *dev, off_t offset, void *data, size_t len)
Read data from the register set.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Complete I2C DT information.
Definition i2c.h:121
uint16_t addr
Target address.
Definition i2c.h:125
Structure describing a device that supports the I2C target API.
Definition i2c.h:594
@driver_ops{I2C Target}
Definition i2c.h:369
Register set library data.
Definition regset_target_lib.h:48
Register set library config.
Definition regset_target_lib.h:31