Software APIs
i2c_target.h
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_JSON_I2C_TARGET_H_
5 #define OPENTITAN_SW_DEVICE_LIB_TESTING_JSON_I2C_TARGET_H_
6 
7 #include "sw/device/lib/ujson/ujson_derive.h"
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 // clang-format off
12 
13 #define MODULE_ID MAKE_MODULE_ID('j', 'i', 'i')
14 
15 #define STRUCT_I2C_TARGET_ADDRESS(field, string) \
16  field(instance, uint8_t) \
17  field(id0, uint8_t) \
18  field(mask0, uint8_t) \
19  field(id1, uint8_t) \
20  field(mask1, uint8_t)
21 UJSON_SERDE_STRUCT(I2cTargetAddress, i2c_target_address_t, STRUCT_I2C_TARGET_ADDRESS);
22 
23 // Should be used to begin every I2C transfer.
24 // Issues a Start, address, command, and optional data and Stop conditions.
25 // A 0 data_len means there is no data.
26 #define STRUCT_I2C_TRANSFER_START(field, string) \
27  field(length, uint8_t) \
28  field(address, uint8_t) \
29  field(stop, bool) \
30  field(data, uint8_t, 256)
31 UJSON_SERDE_STRUCT(I2cTransferStart, i2c_transfer_start_t, STRUCT_I2C_TRANSFER_START);
32 
33 // Should be used to set parameters for i2c tests.
34 #define STRUCT_I2C_TEST_CONFIG(field, string) \
35  field(clock_stretching_delay_millis, uint32_t)
36 UJSON_SERDE_STRUCT(I2cTestConfig, i2c_test_config_t, STRUCT_I2C_TEST_CONFIG);
37 
38 #undef MODULE_ID
39 
40 // clang-format on
41 #ifdef __cplusplus
42 }
43 #endif
44 #endif // OPENTITAN_SW_DEVICE_LIB_TESTING_JSON_I2C_TARGET_H_