libdragon
Data Structures | Macros | Functions
joybus.c File Reference

Joybus Subsystem. More...

Data Structures

struct  joybus_msg_t
 A message to be sent to JoyBus, with its completion callback. More...
 

Macros

#define MAX_JOYBUS_MSGS   8
 Maximum number of pending joybus messages.
 
SI status register bit definitions
#define SI_STATUS_DMA_BUSY   ( 1 << 0 )
 SI DMA busy.
 
#define SI_STATUS_IO_BUSY   ( 1 << 1 )
 SI IO busy.
 
Joybus internal state machine values

#define JOYBUS_STATE_IDLE   0
 Joybus state: idle (no pending messages)
 
#define JOYBUS_STATE_SENDING   1
 JoyBus state: sending a message to PIF.
 
#define JOYBUS_STATE_RECEIVING   2
 JoyBus state: receiving a reply from PIF.
 

Functions

void __joybus_init (void)
 Initialize the joybus subsystem.
 
void joybus_exec_async (const void *input, void(*callback)(uint64_t *output, void *ctx), void *ctx)
 Execute an asynchronous joybus message. More...
 
void joybus_exec (const void *input, void *output)
 Write a 64-byte block of data to the PIF and read the 64-byte result. More...
 

Detailed Description

Joybus Subsystem.

Function Documentation

◆ joybus_exec_async()

void joybus_exec_async ( const void *  input,
void(*)(uint64_t *output, void *ctx)  callback,
void *  ctx 
)

Execute an asynchronous joybus message.

This function executes an asynchronous joybus protocol exchange, sending a message block (input), and receiving a reply (output). The message is sent in background and a completion function "callback" is called when the output is ready to be processed.

It is possible to schedule multiple joybus messages by calling this function multiple times. They will be automatically executed in order. The maximum number of pending messages at any given time is MAX_JOYBUS_MSGS.

Note
The callback function will be called under interrupt.
This function is not part of the public API yet because we want to evaluate the use of threading rather than asynchronous programming. It should only be used internally without exposing a asynchronous API externally.
Parameters
[in]inputThe input block (must be of JOYBUS_BLOCK_SIZE bytes). No specific alignment is required for this data block.
[in]callbackA callback completion function that will be called when the joybus command is finished. The function will receive a pointer to the output buffer and the opaque pointer to the callback's context. Can be NULL if no callback is required.
[in]ctxContext opaque pointer to pass to the callback. Can be NULL if no context is required.