libjoybus
Joybus implementation for 32-bit MCUs
Loading...
Searching...
No Matches
Joybus

Joybus library core functionality. More...

Data Structures

struct  joybus_api
struct  joybus
 A Joybus instance. More...

Macros

#define JOYBUS_FREQ_GCC   250000
 Bus frequency of an OEM GameCube controller.
#define JOYBUS_FREQ_WAVEBIRD   225000
 Bus frequency of WaveBird receiver.
#define JOYBUS_FREQ_CONSOLE   200000
 Bus frequency of a console.
#define JOYBUS_BLOCK_SIZE   64
 Maximum size of a Joybus transfer, in bytes.
#define JOYBUS_INTER_TRANSFER_DELAY_US   20
 Minimum delay between Joybus transfers, in microseconds.
#define JOYBUS_REPLY_TIMEOUT_US   100
 Timeout for waiting for a reply from a target, in microseconds.
#define JOYBUS(bus)
 Macro to cast a backend-specific Joybus instance to a generic Joybus instance.

Typedefs

typedef void(* joybus_transfer_cb_t) (struct joybus *bus, int result, void *user_data)
 Function type for transfer completion callbacks.

Functions

static int joybus_enable (struct joybus *bus)
 Enable the Joybus instance.
static int joybus_disable (struct joybus *bus)
 Disable the Joybus instance.
static int joybus_transfer (struct joybus *bus, const uint8_t *write_buf, uint8_t write_len, uint8_t *read_buf, uint8_t read_len, joybus_transfer_cb_t callback, void *user_data)
 Perform a Joybus "write then read" transfer.
static int joybus_target_register (struct joybus *bus, struct joybus_target *target)
 Enable Joybus "target" mode, and register a target to handle commands.
static int joybus_target_unregister (struct joybus *bus, struct joybus_target *target)
 Unregister a Joybus target.

Detailed Description

Joybus library core functionality.

Macro Definition Documentation

◆ JOYBUS

#define JOYBUS ( bus)
Value:
((struct joybus *)(bus))
A Joybus instance.
Definition bus.h:59

Macro to cast a backend-specific Joybus instance to a generic Joybus instance.

Typedef Documentation

◆ joybus_transfer_cb_t

typedef void(* joybus_transfer_cb_t) (struct joybus *bus, int result, void *user_data)

Function type for transfer completion callbacks.

Parameters
busthe Joybus associated with the transfer
resultpositive number of bytes read on success, negative error code on failure
user_datauser data passed to the callback

Function Documentation

◆ joybus_disable()

int joybus_disable ( struct joybus * bus)
inlinestatic

Disable the Joybus instance.

Parameters
busthe Joybus instance to disable

◆ joybus_enable()

int joybus_enable ( struct joybus * bus)
inlinestatic

Enable the Joybus instance.

Parameters
busthe Joybus instance to enable

◆ joybus_target_register()

int joybus_target_register ( struct joybus * bus,
struct joybus_target * target )
inlinestatic

Enable Joybus "target" mode, and register a target to handle commands.

Parameters
busthe Joybus instance to use
targetthe target to register
Returns
0 on success, negative error code on failure

◆ joybus_target_unregister()

int joybus_target_unregister ( struct joybus * bus,
struct joybus_target * target )
inlinestatic

Unregister a Joybus target.

Parameters
busthe Joybus instance to use
targetthe target to unregister
Returns
0 on success, negative error code on failure

◆ joybus_transfer()

int joybus_transfer ( struct joybus * bus,
const uint8_t * write_buf,
uint8_t write_len,
uint8_t * read_buf,
uint8_t read_len,
joybus_transfer_cb_t callback,
void * user_data )
inlinestatic

Perform a Joybus "write then read" transfer.

Sends a command to a device, and reads the response. The provided buffers must be valid until the transfer is complete.

Parameters
busthe Joybus instance to use
write_bufthe buffer containing the command to send
write_lenthe number of bytes to write
read_bufthe buffer to store the response in
read_lenthe number of bytes to read
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback
Returns
0 on success, negative error code on failure