write(_:count:)
Writes an array of UInt8 to the slave device.
@discardableResult func write(_ data: [UInt8], count: Int? = nil) -> Result<(), Errno>
Parameters
Returns
Whether the communication succeeds. If not, it returns the specific error.
Writes an array of UInt8 to the slave device.
@discardableResult func write(_ data: [UInt8], count: Int? = nil) -> Result<(), Errno>
s7SwiftIO3SPIC5write_5counts6ResultOyytAA5ErrnoVGSays5UInt8VG_SiSgtF
What are these?X9V4
Whether the communication succeeds. If not, it returns the specific error.
import SwiftIO
The SwiftIO library allows you to access and control the hardware in an easy way.
final class SPI
SPI is a four wire serial protocol for communication between devices.
@frozen struct UInt8
An 8-bit unsigned integer value type.
@frozen struct Int
A signed integer value type.
@frozen enum Result<Success, Failure> where Failure : Error, Success : ~Copyable
A value that represents either a success or a failure, including an associated value in each case.
struct Errno
The Errno struct lists all the possible errors.
@discardableResult func write(_ byte: UInt8) -> Result<(), Errno>
Writes a UInt8 to the slave device.
@discardableResult func write<Element>(_ data: [Element], count: Int? = nil) -> Result<(), Errno> where Element : BinaryInteger
Write an array of binary integer to the slave device.
@discardableResult func write(_ data: UnsafeRawBufferPointer, count: Int? = nil) -> Result<(), Errno>
Writes a buffer pointer of the data in the underlying storage to the slave device.
init(_ idName: Id, speed: Int = 5_000_000, csPin: DigitalOut? = nil, CPOL: Bool = false, CPHA: Bool = false, bitOrder: BitOrder = .MSB)
Initializes a specified interface for SPI communication as a master device.
var CPHA: Bool { get }
The phase to sample data, false for the first edge of the clock pulse, true for the second edge.
var CPOL: Bool { get }
The state of SCK line when it’s idle.
var LSB: Bool { get }
Whether the bit order is LSB.
var MSB: Bool { get }
Whether the bit order is MSB.
var bitOrder: BitOrder { get }
The bit order on data line.
var cs: Bool { get }
A boolean value that tells whether the cs pin is set (true) or not (false).
let obj: UnsafeMutableRawPointer
var speed: Int { get }
The transmission speed of SPI communication.
func getMode() -> (CPOL: Bool, CPHA: Bool, bitOrder: BitOrder)
Gets the SPI mode.
func getSpeed() -> Int
Gets the current clock speed of SPI communication.
@discardableResult func read(into byte: inout UInt8) -> Result<(), Errno>
Reads a UInt8 from the slave device.
@discardableResult func read(into buffer: inout [UInt8], count: Int? = nil) -> Result<(), Errno>
Reads an array of data from the slave device.
@discardableResult func read<Element>(into buffer: inout [Element], count: Int? = nil) -> Result<(), Errno> where Element : BinaryInteger
Read an array of binary integer from the slave device.
@discardableResult func read(into buffer: UnsafeMutableRawBufferPointer, count: Int? = nil) -> Result<(), Errno>
Reads the data from the slave device into the specified buffer pointer.
func transceive(_ byte: UInt8, into buffer: inout [UInt8], readCount: Int? = nil) -> Result<(), Errno>
Writes a UInt8 to the slave device and then read bytes from it.
func transceive(_ data: [UInt8], writeCount: Int? = nil, into buffer: inout [UInt8], readCount: Int? = nil) -> Result<(), Errno>
Writes an array of UInt8 to the slave device and then read bytes from it.
enum BitOrder
The bit order that the data is sent on SPI bus: MSB or LSB.