rp2040-psram 1.0.0
A header-only library to allow access to SPI PSRAM via PIO on the RP2040 microcontroller.
|
#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 struct psram_spi_inst 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.
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
src | Pointer to the source data to write. |
src_len | Length of the source data in bytes. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
src | Pointer to the source data to write. |
src_len | Length of the source data in bytes. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
src | Pointer to the source data to write. |
src_len | Length of the source data in bytes. |
dst | Pointer to the destination for read data, if any. Set to 0 or NULL if no data is to be read. |
dst_len | Length of the destination data in bytes. Set to 0 if no data is to be read. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
src | Pointer to the source data to write. |
src_len | Length of the source data in bytes. |
dst | Pointer to the destination for read data, if any. Set to 0 or NULL if no data is to be read. |
dst_len | Length of the destination data in bytes. Set to 0 if no data is to be 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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to read from. |
dst | Pointer to the destination for the read data. |
count | Number of bytes to read. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to read from. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to read from. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to read from. |
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_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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to write to. |
src | Pointer to the source data to write. |
count | Number of bytes to write. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to write to. |
val | Value to write. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to write to. |
val | Value to write. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to write to. |
val | Value to write. |
__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.
spi | The PSRAM configuration instance returned from psram_spi_init(). |
addr | Address to write to. |
val | Value to write. |