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