| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| library fuchsia.hardware.i2c; |
| |
| using zx; |
| |
| const uint32 MAX_TRANSFER_SIZE = 8196; // More than enough for I2C |
| const uint32 MAX_COUNT_SEGMENTS = 8; // Enough for all known transfer configurations. |
| |
| enum SegmentType { |
| /// Flags the end of a serialized list of segments. |
| END = 1; |
| /// Segment to be read from the I2C device. |
| READ = 2; |
| /// Segment to be written to the I2C device. |
| WRITE = 3; |
| }; |
| |
| /// Segment header for a serialized SubordinateTransfer. |
| /// TODO(fxbug.dev/32864): Avoid requiring serialization and have SubordinateTransfer take an argument of |
| /// `vector<Segment>:MAX_SEGMENTS` instead once we have better support in the C bindings or for C++. |
| [ForDeprecatedCBindings] |
| struct Segment { |
| uint32 type; |
| uint32 len; |
| }; |
| |
| [ForDeprecatedCBindings] |
| protocol Device { |
| /// Send and receive data on the I2C device. |
| SubordinateTransfer(vector<uint8>:MAX_TRANSFER_SIZE in) -> (zx.status s, |
| vector<uint8>:MAX_TRANSFER_SIZE out); |
| }; |
| |
| // `Device2` removes the simple layout restriction and fully specifies the format in FIDL instead |
| // of manually parsed structs as `Device` above. |
| protocol Device2 { |
| /// Write and read segments of data for a particular I2C device. |
| /// |
| /// The `segments_is_write` vector specifies the type (write or read) of each segment. |
| /// The `write_segments_data` vector of segments specifies the data to write for each write |
| /// segment. Each segment itself is a vector of uint8s, so `write_segments_data` is a vector of |
| /// vectors of uint8s. |
| /// The `read_segments_length` vector specifies the length of the read segments. |
| /// If there is no error, `read_segments_data` returns a vector of segments, with each segment |
| /// data itself returned in vectors. |
| /// |
| /// For a simple I2C read, for instance 2 bytes write followed by one byte read, |
| /// `segments_is_write` would be a vector with 2 elements: true, false and |
| /// `write_segments_data` would be a vector with 1 element including the 2 bytes address of the |
| /// read. Upon success `read_segments_data` would return a vector with one element, the byte |
| /// read. |
| Transfer(vector<bool>:MAX_COUNT_SEGMENTS segments_is_write, |
| vector<vector<uint8>:MAX_TRANSFER_SIZE>:MAX_COUNT_SEGMENTS write_segments_data, |
| vector<uint8>:MAX_COUNT_SEGMENTS read_segments_length) |
| -> (vector<vector<uint8>:MAX_TRANSFER_SIZE>:MAX_COUNT_SEGMENTS read_segments_data) |
| error zx.status; |
| }; |