pxidev.h
Go to the documentation of this file.
/**
* @file pxidev.h
* @brief Gamecard PXI service.
*/
#pragma once
#include <3ds/services/fs.h>
/// Card SPI wait operation type.
typedef enum {
WAIT_NONE = 0, ///< Do not wait.
WAIT_SLEEP = 1, ///< Sleep for the specified number of nanoseconds.
WAIT_IREQ_RETURN = 2, ///< Wait for IREQ, return if timeout.
WAIT_IREQ_CONTINUE = 3 ///< Wait for IREQ, continue if timeout.
} PXIDEV_WaitType;
/// Card SPI register deassertion type.
typedef enum {
DEASSERT_NONE = 0, ///< Do not deassert.
DEASSERT_BEFORE_WAIT = 1, ///< Deassert before waiting.
DEASSERT_AFTER_WAIT = 2 ///< Deassert after waiting.
} PXIDEV_DeassertType;
/// Card SPI transfer buffer.
typedef struct {
void* ptr; ///< Data pointer.
u32 size; ///< Data size.
u8 transferOption; ///< Transfer options. See @ref pxiDevMakeTransferOption
u64 waitOperation; ///< Wait operation. See @ref pxiDevMakeWaitOperation
} PXIDEV_SPIBuffer;
/// Initializes pxi:dev.
Result pxiDevInit(void);
/// Shuts down pxi:dev.
void pxiDevExit(void);
/**
* @brief Creates a packed card SPI transfer option value.
* @param baudRate Baud rate to use when transferring.
* @param busMode Bus mode to use when transferring.
* @return A packed card SPI transfer option value.
*/
static inline u8 pxiDevMakeTransferOption(FS_CardSpiBaudRate baudRate, FS_CardSpiBusMode busMode)
{
return (baudRate & 0x3F) | ((busMode & 0x3) << 6);
}
/**
* @brief Creates a packed card SPI wait operation value.
* @param waitType Type of wait to perform.
* @param deassertType Type of register deassertion to perform.
* @param timeout Timeout, in nanoseconds, to wait, if applicable.
* @return A packed card SPI wait operation value.
*/
static inline u64 pxiDevMakeWaitOperation(PXIDEV_WaitType waitType, PXIDEV_DeassertType deassertType, u64 timeout)
{
return (waitType & 0xF) | ((deassertType & 0xF) << 4) | ((timeout & 0xFFFFFFFFFFFFFF) << 8);
}
/**
* @brief Performs multiple card SPI writes and reads.
* @param header Header to lead the transfers with. Must be, at most, 8 bytes in size.
* @param writeBuffer1 Buffer to make first transfer from.
* @param readBuffer1 Buffer to receive first response to.
* @param writeBuffer2 Buffer to make second transfer from.
* @param readBuffer2 Buffer to receive second response to.
* @param footer Footer to follow the transfers with. Must be, at most, 8 bytes in size. Wait operation is unused.
*/
Result PXIDEV_SPIMultiWriteRead(PXIDEV_SPIBuffer* header, PXIDEV_SPIBuffer* writeBuffer1, PXIDEV_SPIBuffer* readBuffer1, PXIDEV_SPIBuffer* writeBuffer2, PXIDEV_SPIBuffer* readBuffer2, PXIDEV_SPIBuffer* footer);
/**
* @brief Performs a single card SPI write and read.
* @param bytesRead Pointer to output the number of bytes received to.
* @param initialWaitOperation Wait operation to perform before transferring data.
* @param writeBuffer Buffer to transfer data from.
* @param readBuffer Buffer to receive data to.
*/
Result PXIDEV_SPIWriteRead(u32* bytesRead, u64 initialWaitOperation, PXIDEV_SPIBuffer* writeBuffer, PXIDEV_SPIBuffer* readBuffer);
fs.h
Filesystem Services.
FS_CardSpiBusMode
FS_CardSpiBusMode
Card SPI bus mode.
Definition: fs.h:108
FS_CardSpiBaudRate
FS_CardSpiBaudRate
Card SPI baud rate.
Definition: fs.h:97
PXIDEV_DeassertType
PXIDEV_DeassertType
Card SPI register deassertion type.
Definition: pxidev.h:18
DEASSERT_AFTER_WAIT
@ DEASSERT_AFTER_WAIT
Deassert after waiting.
Definition: pxidev.h:21
DEASSERT_BEFORE_WAIT
@ DEASSERT_BEFORE_WAIT
Deassert before waiting.
Definition: pxidev.h:20
DEASSERT_NONE
@ DEASSERT_NONE
Do not deassert.
Definition: pxidev.h:19
pxiDevMakeWaitOperation
static u64 pxiDevMakeWaitOperation(PXIDEV_WaitType waitType, PXIDEV_DeassertType deassertType, u64 timeout)
Creates a packed card SPI wait operation value.
Definition: pxidev.h:56
pxiDevInit
Result pxiDevInit(void)
Initializes pxi:dev.
pxiDevExit
void pxiDevExit(void)
Shuts down pxi:dev.
PXIDEV_WaitType
PXIDEV_WaitType
Card SPI wait operation type.
Definition: pxidev.h:10
WAIT_NONE
@ WAIT_NONE
Do not wait.
Definition: pxidev.h:11
WAIT_IREQ_RETURN
@ WAIT_IREQ_RETURN
Wait for IREQ, return if timeout.
Definition: pxidev.h:13
WAIT_SLEEP
@ WAIT_SLEEP
Sleep for the specified number of nanoseconds.
Definition: pxidev.h:12
WAIT_IREQ_CONTINUE
@ WAIT_IREQ_CONTINUE
Wait for IREQ, continue if timeout.
Definition: pxidev.h:14
PXIDEV_SPIMultiWriteRead
Result PXIDEV_SPIMultiWriteRead(PXIDEV_SPIBuffer *header, PXIDEV_SPIBuffer *writeBuffer1, PXIDEV_SPIBuffer *readBuffer1, PXIDEV_SPIBuffer *writeBuffer2, PXIDEV_SPIBuffer *readBuffer2, PXIDEV_SPIBuffer *footer)
Performs multiple card SPI writes and reads.
pxiDevMakeTransferOption
static u8 pxiDevMakeTransferOption(FS_CardSpiBaudRate baudRate, FS_CardSpiBusMode busMode)
Creates a packed card SPI transfer option value.
Definition: pxidev.h:44
PXIDEV_SPIWriteRead
Result PXIDEV_SPIWriteRead(u32 *bytesRead, u64 initialWaitOperation, PXIDEV_SPIBuffer *writeBuffer, PXIDEV_SPIBuffer *readBuffer)
Performs a single card SPI write and read.
PXIDEV_SPIBuffer
Card SPI transfer buffer.
Definition: pxidev.h:25
PXIDEV_SPIBuffer::waitOperation
u64 waitOperation
Wait operation. See pxiDevMakeWaitOperation.
Definition: pxidev.h:29
PXIDEV_SPIBuffer::ptr
void * ptr
Data pointer.
Definition: pxidev.h:26
PXIDEV_SPIBuffer::size
u32 size
Data size.
Definition: pxidev.h:27
PXIDEV_SPIBuffer::transferOption
u8 transferOption
Transfer options. See pxiDevMakeTransferOption.
Definition: pxidev.h:28
u64
uint64_t u64
64-bit unsigned integer
Definition: types.h:24
u8
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
Result
s32 Result
Function result.
Definition: types.h:42
u32
uint32_t u32
32-bit unsigned integer
Definition: types.h:23