getSpeed
Gets the current clock speed of SPI communication.
func getSpeed() -> Int
Returns
The current clock speed.
Gets the current clock speed of SPI communication.
func getSpeed() -> Int
The current clock speed.
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 Int
A signed integer value type.
func getMode() -> (CPOL: Bool, CPHA: Bool, bitOrder: BitOrder)
Gets the SPI mode.
enum BitOrder
The bit order that the data is sent on SPI bus: MSB or LSB.
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.
@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.
@discardableResult func write(_ byte: UInt8) -> Result<(), Errno>
Writes a UInt8 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.
@discardableResult func write(_ data: [UInt8], count: Int? = nil) -> Result<(), Errno>
Writes an array of 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.