| // Copyright 2019 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.spi; |
| |
| using fuchsia.hardware.sharedmemory; |
| using zx; |
| |
| const MAX_TRANSFER_SIZE uint32 = 8196; // arbitrary - to be removed |
| @discoverable |
| closed protocol Device { |
| /// Half-duplex transmit data to a SPI device; always transmits the entire buffer on success. |
| strict TransmitVector(struct { |
| data vector<uint8>:MAX_TRANSFER_SIZE; |
| }) -> (struct { |
| status zx.Status; |
| }); |
| /// Half-duplex receive data from a SPI device; always reads the full size requested. |
| strict ReceiveVector(struct { |
| size uint32; |
| }) -> (struct { |
| status zx.Status; |
| data vector<uint8>:MAX_TRANSFER_SIZE; |
| }); |
| /// Full-duplex SPI transaction. Received data will exactly equal the length of the transmit |
| /// buffer. |
| strict ExchangeVector(struct { |
| txdata vector<uint8>:MAX_TRANSFER_SIZE; |
| }) -> (struct { |
| status zx.Status; |
| rxdata vector<uint8>:MAX_TRANSFER_SIZE; |
| }); |
| |
| /// Returns true if the device can call |AssertCs()| and |DeassertCs()|. |
| strict CanAssertCs() -> (struct { |
| can bool; |
| }); |
| |
| /// Assert CS for this device. |
| /// Returns ZX_ERR_NOT_SUPPORTED if there is more than one device on the bus. |
| strict AssertCs() -> (struct { |
| status zx.Status; |
| }); |
| /// Deassert CS for this device. |
| /// Returns ZX_ERR_BAD_STATE if CS is already deasserted. |
| /// Returns ZX_ERR_NOT_SUPPORTED if there is more than one device on the bus. |
| strict DeassertCs() -> (struct { |
| status zx.Status; |
| }); |
| |
| compose fuchsia.hardware.sharedmemory.SharedVmoIo; |
| compose fuchsia.hardware.sharedmemory.SharedVmoRegister; |
| }; |
| |
| closed protocol Controller { |
| /// Opens a new session on the device. |
| /// |
| /// At most one session is permitted at one time; the server end will be |
| /// closed with `ZX_ERR_ALREADY_BOUND` if a session already exists. |
| strict OpenSession(resource struct { |
| session server_end:Device; |
| }); |
| }; |
| |
| service Service { |
| device client_end:Device; |
| }; |