rp2040-psram 1.0.0
A header-only library to allow access to SPI PSRAM via PIO on the RP2040 microcontroller.
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
/Users/ian/src/rp2040-psram/psram_spi.h File Reference
#include "hardware/pio.h"
#include "hardware/gpio.h"
#include "hardware/timer.h"
#include "hardware/dma.h"
#include "stdio.h"
#include "psram_spi.pio.h"

Go to the source code of this file.

Classes

struct  psram_spi_inst
 A struct that holds the configuration for the PSRAM interface. More...
 

Typedefs

typedef struct psram_spi_inst psram_spi_inst_t
 A struct that holds the configuration for the PSRAM interface.
 

Functions

__force_inline void __time_critical_func() pio_spi_write_read_blocking (psram_spi_inst_t *spi, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Write and read raw data to the PSRAM SPI PIO, driven by the CPU without DMA. This can be used if DMA has not yet been initialized.
 
__force_inline void __time_critical_func() pio_spi_write_dma_blocking (psram_spi_inst_t *spi, const uint8_t *src, const size_t src_len)
 Write raw data to the PSRAM SPI PIO, driven by DMA without CPU involvement.
 
__force_inline void __time_critical_func() pio_spi_write_read_dma_blocking (psram_spi_inst_t *spi, const uint8_t *src, const size_t src_len, uint8_t *dst, const size_t dst_len)
 Write and read raw data to the PSRAM SPI PIO, driven by DMA without CPU involvement.
 
__force_inline void __time_critical_func() pio_spi_write_async (psram_spi_inst_t *spi, const uint8_t *src, const size_t src_len)
 Write raw data asynchronously to the PSRAM SPI PIO, driven by DMA without CPU involvement.
 
psram_spi_inst_t psram_spi_init (void)
 Initialize the PSRAM over SPI. This function must be called before accessing PSRAM.
 
__force_inline void psram_write8_async (psram_spi_inst_t *spi, uint32_t addr, uint8_t val)
 Write 8 bits of data to a given address asynchronously to the PSRAM SPI PIO, driven by DMA without CPU involvement.
 
__force_inline void psram_write8 (psram_spi_inst_t *spi, uint32_t addr, uint8_t val)
 Write 8 bits of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.
 
__force_inline uint8_t psram_read8 (psram_spi_inst_t *spi, uint32_t addr)
 Read 8 bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.
 
__force_inline void psram_write16 (psram_spi_inst_t *spi, uint32_t addr, uint16_t val)
 Write 16 bits of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.
 
__force_inline uint16_t psram_read16 (psram_spi_inst_t *spi, uint32_t addr)
 Read 16 bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.
 
__force_inline void psram_write32 (psram_spi_inst_t *spi, uint32_t addr, uint32_t val)
 Write 32 bits of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.
 
__force_inline uint32_t psram_read32 (psram_spi_inst_t *spi, uint32_t addr)
 Read 32 bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.
 
__force_inline void psram_write (psram_spi_inst_t *spi, const uint32_t addr, const uint8_t *src, const size_t count)
 Write count bytes of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.
 
__force_inline void psram_read (psram_spi_inst_t *spi, const uint32_t addr, uint8_t *dst, const size_t count)
 Read count bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.
 

Typedef Documentation

◆ psram_spi_inst_t

A struct that holds the configuration for the PSRAM interface.

This struct is generated by psram_spi_init() and must be passed to all calls to the psram access functions.

Function Documentation

◆ pio_spi_write_async()

__force_inline void __time_critical_func() pio_spi_write_async ( psram_spi_inst_t spi,
const uint8_t *  src,
const size_t  src_len 
)

Write raw data asynchronously to the PSRAM SPI PIO, driven by DMA without CPU involvement.

Used to send raw commands to the PSRAM. Usually the psram_write*_async() command should be used instead.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
srcPointer to the source data to write.
src_lenLength of the source data in bytes.

◆ pio_spi_write_dma_blocking()

__force_inline void __time_critical_func() pio_spi_write_dma_blocking ( psram_spi_inst_t spi,
const uint8_t *  src,
const size_t  src_len 
)

Write raw data to the PSRAM SPI PIO, driven by DMA without CPU involvement.

It's recommended to use DMA when possible as it's higher speed. Used to send raw commands to the PSRAM. This function is faster than pio_spi_write_read_dma_blocking() if no data is to be read.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
srcPointer to the source data to write.
src_lenLength of the source data in bytes.

◆ pio_spi_write_read_blocking()

__force_inline void __time_critical_func() pio_spi_write_read_blocking ( psram_spi_inst_t spi,
const uint8_t *  src,
const size_t  src_len,
uint8_t *  dst,
const size_t  dst_len 
)

Write and read raw data to the PSRAM SPI PIO, driven by the CPU without DMA. This can be used if DMA has not yet been initialized.

Used to send raw commands and receive data from the PSRAM. Usually the psram_write*() and psram_read*() commands should be used instead.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
srcPointer to the source data to write.
src_lenLength of the source data in bytes.
dstPointer to the destination for read data, if any. Set to 0 or NULL if no data is to be read.
dst_lenLength of the destination data in bytes. Set to 0 if no data is to be read.

◆ pio_spi_write_read_dma_blocking()

__force_inline void __time_critical_func() pio_spi_write_read_dma_blocking ( psram_spi_inst_t spi,
const uint8_t *  src,
const size_t  src_len,
uint8_t *  dst,
const size_t  dst_len 
)

Write and read raw data to the PSRAM SPI PIO, driven by DMA without CPU involvement.

It's recommended to use DMA when possible as it's higher speed. Used to send raw commands and receive data from the PSRAM. Usually the psram_write* and psram_read* commands should be used instead.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
srcPointer to the source data to write.
src_lenLength of the source data in bytes.
dstPointer to the destination for read data, if any. Set to 0 or NULL if no data is to be read.
dst_lenLength of the destination data in bytes. Set to 0 if no data is to be read.

◆ psram_read()

__force_inline void psram_read ( psram_spi_inst_t spi,
const uint32_t  addr,
uint8_t *  dst,
const size_t  count 
)

Read count bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to read from.
dstPointer to the destination for the read data.
countNumber of bytes to read.

◆ psram_read16()

__force_inline uint16_t psram_read16 ( psram_spi_inst_t spi,
uint32_t  addr 
)

Read 16 bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.

This function is optimized to read 16 bits as quickly as possible from the PSRAM as opposed to the more general-purpose psram_read() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to read from.
Returns
The data at the specified address.

◆ psram_read32()

__force_inline uint32_t psram_read32 ( psram_spi_inst_t spi,
uint32_t  addr 
)

Read 32 bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.

This function is optimized to read 32 bits as quickly as possible from the PSRAM as opposed to the more general-purpose psram_read() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to read from.
Returns
The data at the specified address.

◆ psram_read8()

__force_inline uint8_t psram_read8 ( psram_spi_inst_t spi,
uint32_t  addr 
)

Read 8 bits of data from a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the read is complete.

This function is optimized to read 8 bits as quickly as possible from the PSRAM as opposed to the more general-purpose psram_read() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to read from.
Returns
The data at the specified address.

◆ psram_spi_init()

psram_spi_inst_t psram_spi_init ( void  )

Initialize the PSRAM over SPI. This function must be called before accessing PSRAM.

Returns
The PSRAM configuration instance. This instance should be passed to all PSRAM access functions.

◆ psram_write()

__force_inline void psram_write ( psram_spi_inst_t spi,
const uint32_t  addr,
const uint8_t *  src,
const size_t  count 
)

Write count bytes of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to write to.
srcPointer to the source data to write.
countNumber of bytes to write.

◆ psram_write16()

__force_inline void psram_write16 ( psram_spi_inst_t spi,
uint32_t  addr,
uint16_t  val 
)

Write 16 bits of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.

This function is optimized to write 16 bits as quickly as possible to the PSRAM as opposed to the more general-purpose psram_write() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to write to.
valValue to write.

◆ psram_write32()

__force_inline void psram_write32 ( psram_spi_inst_t spi,
uint32_t  addr,
uint32_t  val 
)

Write 32 bits of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.

This function is optimized to write 32 bits as quickly as possible to the PSRAM as opposed to the more general-purpose psram_write() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to write to.
valValue to write.

◆ psram_write8()

__force_inline void psram_write8 ( psram_spi_inst_t spi,
uint32_t  addr,
uint8_t  val 
)

Write 8 bits of data to a given address to the PSRAM SPI PIO, driven by DMA without CPU involvement, blocking until the write is complete.

This function is optimized to write 8 bits as quickly as possible to the PSRAM as opposed to the more general-purpose psram_write() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to write to.
valValue to write.

◆ psram_write8_async()

__force_inline void psram_write8_async ( psram_spi_inst_t spi,
uint32_t  addr,
uint8_t  val 
)

Write 8 bits of data to a given address asynchronously to the PSRAM SPI PIO, driven by DMA without CPU involvement.

This function is optimized to write 8 bits as quickly as possible to the PSRAM as opposed to the more general-purpose psram_write() function.

Parameters
spiThe PSRAM configuration instance returned from psram_spi_init().
addrAddress to write to.
valValue to write.