libnile
Loading...
Searching...
No Matches
spi.h File Reference
#include <wonderful.h>
#include "hardware.h"
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define NILE_SPI_XCH_ERROR_MASK   0xFF00

Enumerations

enum  nile_spi_speed_t { NILE_SPI_SPEED_384KHZ = 0x00 , NILE_SPI_SPEED_6MHZ = 0x01 , NILE_SPI_SPEED_24MHZ = 0x02 }

Functions

uint16_t nile_spi_get_timeout (void)
 Get the SPI communication timeout value, in milliseconds.
void nile_spi_set_timeout (uint16_t ms)
 Set the SPI communication timeout value, in milliseconds.
bool nile_spi_wait_ready (void)
 Wait until the SPI interface is ready. The maximum number of milliseconds for the wait is set using nile_spi_set_timeout.
bool nile_spi_abort (void)
 Abort SPI transfer.
bool nile_spi_set_speed (nile_spi_speed_t speed)
 Safely set the speed used by the SPI controller.
bool nile_spi_set_device (uint16_t device)
 Safely set the device targetted by the SPI controller.
bool nile_spi_set_control (uint16_t value)
 Safely configure the control port.
static void nile_spi_flip_buffer (void)
 Flip the currently accessible SPI buffer.
bool nile_spi_rx_async (uint16_t size, uint16_t mode)
 Asynchronously receive block of data over the SPI interface.
static bool nile_spi_tx_async (uint16_t size)
 Asynchronously transfer block of data over the SPI interface.
bool nile_spi_tx_async_block (const void __far *buf, uint16_t size)
 Asynchronously transfer block of data over the SPI interface.
static bool nile_spi_tx_sync_block (const void __far *buf, uint16_t size)
 Synchronously transfer block of data over the SPI interface.
bool nile_spi_rx_sync_flip (uint16_t size, uint16_t mode)
 Synchronously receive block of data over the SPI interface and flip the buffer so that it can be accessed.
bool nile_spi_rx_sync_block (void __far *buf, uint16_t size, uint16_t mode)
 Synchronously receive block of data over the SPI interface.
bool nile_spi_xch_block (void __far *buf, uint16_t size)
 Synchronously exchange block of data over the SPI interface.
uint16_t nile_spi_xch (uint8_t value)
 Synchronously exchange byte over the SPI interface.

Macro Definition Documentation

◆ NILE_SPI_XCH_ERROR_MASK

#define NILE_SPI_XCH_ERROR_MASK   0xFF00

Definition at line 179 of file spi.h.

Enumeration Type Documentation

◆ nile_spi_speed_t

Enumerator
NILE_SPI_SPEED_384KHZ 

384 KHz

NILE_SPI_SPEED_6MHZ 

6 MHz on SPHINX, 384 KHz on ASWAN

NILE_SPI_SPEED_24MHZ 

24 MHz (increased power draw)

Definition at line 61 of file spi.h.

Function Documentation

◆ nile_spi_abort()

bool nile_spi_abort ( void )

Abort SPI transfer.

Returns
true The SPI interface is now ready.
false Wait timed out.

◆ nile_spi_flip_buffer()

void nile_spi_flip_buffer ( void )
inlinestatic

Flip the currently accessible SPI buffer.

Definition at line 91 of file spi.h.

◆ nile_spi_get_timeout()

uint16_t nile_spi_get_timeout ( void )

Get the SPI communication timeout value, in milliseconds.

◆ nile_spi_rx_async()

bool nile_spi_rx_async ( uint16_t size,
uint16_t mode )

Asynchronously receive block of data over the SPI interface.

Parameters
sizeLength of data to receive.
modeTransfer mode.
Returns
true Transfer successful.
false Transfer failed.

◆ nile_spi_rx_sync_block()

bool nile_spi_rx_sync_block ( void __far * buf,
uint16_t size,
uint16_t mode )

Synchronously receive block of data over the SPI interface.

Parameters
bufDestination data block.
sizeLength of data to receive.
modeTransfer mode.
Returns
true Transfer successful.
false Transfer failed.

◆ nile_spi_rx_sync_flip()

bool nile_spi_rx_sync_flip ( uint16_t size,
uint16_t mode )

Synchronously receive block of data over the SPI interface and flip the buffer so that it can be accessed.

Parameters
sizeLength of data to receive.
modeTransfer mode.
Returns
true Transfer successful.
false Transfer failed.

◆ nile_spi_set_control()

bool nile_spi_set_control ( uint16_t value)

Safely configure the control port.

◆ nile_spi_set_device()

bool nile_spi_set_device ( uint16_t device)

Safely set the device targetted by the SPI controller.

Parameters
deviceSPI device.

◆ nile_spi_set_speed()

bool nile_spi_set_speed ( nile_spi_speed_t speed)

Safely set the speed used by the SPI controller.

This does not set the speed expected by the MCU!

Parameters
speedSPI controller speed.

◆ nile_spi_set_timeout()

void nile_spi_set_timeout ( uint16_t ms)

Set the SPI communication timeout value, in milliseconds.

◆ nile_spi_tx_async()

bool nile_spi_tx_async ( uint16_t size)
inlinestatic

Asynchronously transfer block of data over the SPI interface.

Parameters
sizeLength of data block.
Returns
true Transfer successful.
false Transfer failed.

Definition at line 112 of file spi.h.

◆ nile_spi_tx_async_block()

bool nile_spi_tx_async_block ( const void __far * buf,
uint16_t size )

Asynchronously transfer block of data over the SPI interface.

Parameters
bufData block.
sizeLength of data block.
Returns
true Transfer successful.
false Transfer failed.

◆ nile_spi_tx_sync_block()

bool nile_spi_tx_sync_block ( const void __far * buf,
uint16_t size )
inlinestatic

Synchronously transfer block of data over the SPI interface.

Parameters
bufData block.
sizeLength of data block.
Returns
true Transfer successful.
false Transfer failed.

Definition at line 134 of file spi.h.

◆ nile_spi_wait_ready()

bool nile_spi_wait_ready ( void )

Wait until the SPI interface is ready. The maximum number of milliseconds for the wait is set using nile_spi_set_timeout.

Returns
true The SPI interface is now ready.
false Wait timed out.

◆ nile_spi_xch()

uint16_t nile_spi_xch ( uint8_t value)

Synchronously exchange byte over the SPI interface.

Parameters
valueByte to exchange.
Returns
true Transfer successful.
false Transfer failed.

◆ nile_spi_xch_block()

bool nile_spi_xch_block ( void __far * buf,
uint16_t size )

Synchronously exchange block of data over the SPI interface.

Parameters
bufDestination data block.
sizeLength of data to send and receive.
modeTransfer mode.
Returns
true Transfer successful.
false Transfer failed.