pico-ice
RaspberryPi Pico with an iCE40 FPGA
Ice_spi

Main SPI bus I/O. More...

Macros

#define ICE_SPI_BAUDRATE   (33 * 1000 * 1000)
 This is chosen to allow all commands to the flash and SRAM to work. More...
 

Functions

void ice_spi_init (void)
 Configure the GPIO pins of the SPI library to high-impedance. More...
 
void ice_spi_init_cs_pin (uint8_t cs_pin, bool active_high)
 
void ice_spi_chip_select (uint8_t cs_pin)
 Sets the SPI chip select pin to low state. More...
 
void ice_spi_chip_deselect (uint8_t csn_pin)
 Sets the SPI chip select pin to high state. More...
 
void ice_spi_write_async (const uint8_t *data, size_t data_size, void(*callback)(volatile void *), void *context)
 Wait previous transfer completion if any and enqueue a new one in the background (interrupt-driven). More...
 
void ice_spi_write_blocking (const uint8_t *data, size_t data_size)
 Blocking version of ice_spi_write_async(). More...
 
void ice_spi_read_async (uint8_t *data, size_t data_size, void(*callback)(volatile void *), void *context)
 Wait previous transfer completion if any and enqueue a new one in the background (interrupt-driven). More...
 
void ice_spi_read_blocking (uint8_t *data, size_t data_size)
 Blocking version of ice_spi_read_async(). More...
 
bool ice_spi_is_async_complete (void)
 Checks for compmletion of the current async operation. More...
 
void ice_spi_wait_completion (void)
 Waits until SPI transfer commpletes.
 

Detailed Description

Main SPI bus I/O.

SPI library exclusive to the main SPI bus between the RP2040 and the various other board components, including the iCE40 CRAM, iCE40 hardened SPI core, SRAM chip, FLASH chip.

Macro Definition Documentation

◆ ICE_SPI_BAUDRATE

#define ICE_SPI_BAUDRATE   (33 * 1000 * 1000)

This is chosen to allow all commands to the flash and SRAM to work.

33MHz is the fastest the SRAM supports a 03h read command.

Function Documentation

◆ ice_spi_chip_deselect()

void ice_spi_chip_deselect ( uint8_t  csn_pin)

Sets the SPI chip select pin to high state.

Parameters
csn_pinUser-selectable GPIO pin to assert, set to LOW voltage level.

Also set the SPI TX and SCK pins back to input/high-z mode.

◆ ice_spi_chip_select()

void ice_spi_chip_select ( uint8_t  cs_pin)

Sets the SPI chip select pin to low state.

Parameters
csn_pinUser-selectable GPIO pin to assert, set to LOW voltage level.
active_hightrue for active-high chip-select pin, false for active-low.

Also set the SPI TX and SCK pins to output/drive mode, and keeps the RX pin to input/high-z mode.

◆ ice_spi_init()

void ice_spi_init ( void  )

Configure the GPIO pins of the SPI library to high-impedance.

This lets others access the bus, such as the iCE40 during initial configuration.

◆ ice_spi_is_async_complete()

bool ice_spi_is_async_complete ( void  )

Checks for compmletion of the current async operation.

Returns
True if an SPI transfer is ongoing, false if ready to enqueue another.

◆ ice_spi_read_async()

void ice_spi_read_async ( uint8_t *  data,
size_t  data_size,
void(*)(volatile void *)  callback,
void *  context 
)

Wait previous transfer completion if any and enqueue a new one in the background (interrupt-driven).

Parameters
txByte to send conotinuously while readying
bufBuffer to fill from SPI.
lenSize of that buffer.
callbackFunction called at the end of the transfer.
contextArgument passed to that function.

If callback is NULL, then nothing will be done.

◆ ice_spi_read_blocking()

void ice_spi_read_blocking ( uint8_t *  data,
size_t  data_size 
)

Blocking version of ice_spi_read_async().

Parameters
txByte to send conotinuously while readying
bufBuffer to fill from SPI.
lenSize of that buffer.

◆ ice_spi_write_async()

void ice_spi_write_async ( const uint8_t *  data,
size_t  data_size,
void(*)(volatile void *)  callback,
void *  context 
)

Wait previous transfer completion if any and enqueue a new one in the background (interrupt-driven).

Parameters
bufbuffer to send over SPI.
lensize of that buffer.
callbackfunction called at the end of the transfer.
contextargument passed to that function.

If callback is NULL, then nothing will be done.

◆ ice_spi_write_blocking()

void ice_spi_write_blocking ( const uint8_t *  data,
size_t  data_size 
)

Blocking version of ice_spi_write_async().

Parameters
bufBuffer to send over SPI.
lenSize of that buffer.