1// Copyright 2018 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5library fuchsia.hardware.i2c;
6
7using zx;
8
9const uint32 MAX_TRANSFER_SIZE = 8196;  // More than enough for I2C
10
11enum SegmentType {
12    /// Flags the end of a serialized list of segments.
13    END = 1;
14    /// Segment to be read from the I2C device.
15    READ = 2;
16    /// Segment to be written to the I2C device.
17    WRITE = 3;
18};
19
20/// Segment header for a serialized SlaveTransfer.
21/// TODO(ZX-3029): Avoid requiring serialization and have SlaveTransfer take an argument of
22/// vector<Segment>:MAX_SEGMENTS instead once we have better support in the C bindings or for C++.
23struct Segment {
24    uint32 type;
25    uint32 len;
26};
27
28[Layout = "Simple"]
29interface Device {
30    /// Send and receive data on the I2C device.
31    1: SlaveTransfer(vector<uint8>:MAX_TRANSFER_SIZE in) -> (zx.status s,
32       vector<uint8>:MAX_TRANSFER_SIZE out);
33};
34