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

Interfaces for implementing Joybus targets and N64 accessories. More...

Topics

 GameCube Controller Target
 Joybus target implementation for standard GameCube controllers and WaveBird receivers.
 N64 Controller Target
 Joybus target implementation for standard N64 controllers.

Data Structures

struct  joybus_target_api
 API for implementing a Joybus target. More...
struct  joybus_target
 Interface for a Joybus target, a device on the Joybus which responds to commands from a host. More...

Macros

#define JOYBUS_TARGET(target)
 Macro to cast a concrete Joybus target instance to a generic Joybus target instance.

Typedefs

typedef void(* joybus_target_response_cb) (const uint8_t *response, uint8_t len, void *user_data)
 Callback type for sending responses from target command handlers.

Functions

static int joybus_target_byte_received (struct joybus_target *target, const uint8_t *command, uint8_t byte_idx, joybus_target_response_cb send_response, void *user_data)
 Handle a received command byte for a Joybus target.
static bool joybus_target_is_registered (struct joybus_target *target)
 Check if a target is currently registered on the bus.

Detailed Description

Interfaces for implementing Joybus targets and N64 accessories.

A Joybus target is a device on the bus that responds to commands from a host (the console), such as an N64 or GameCube controller.

Commands arrive one byte at a time. As each byte is received, libjoybus calls the joybus_target_api::byte_received handler with the bytes accumulated so far. The handler inspects them to decide how many more bytes the command needs, returning the count of bytes still expected.

To send a response, the handler must call the "response ready" callback with a pointer to the (long-lived) response data and its length.

Handlers should call the response callback as soon as the response is ready, even if they are still expecting more command bytes. For many commands, the response data is fully determined by the first few bytes of the command. This allows the backend to start transmitting the response immediately after the last byte is received.

To create your own target, define a struct whose first member is a joybus_target (so it can be cast through JOYBUS_TARGET), point its api at a joybus_target_api table, and register it on a bus with joybus_target_register().

Macro Definition Documentation

◆ JOYBUS_TARGET

#define JOYBUS_TARGET ( target)
Value:
((struct joybus_target *)(target))
Interface for a Joybus target, a device on the Joybus which responds to commands from a host.
Definition target.h:69

Macro to cast a concrete Joybus target instance to a generic Joybus target instance.

Typedef Documentation

◆ joybus_target_response_cb

typedef void(* joybus_target_response_cb) (const uint8_t *response, uint8_t len, void *user_data)

Callback type for sending responses from target command handlers.

Parameters
responsethe response data to send
lenthe length of the response data
user_datauser data passed to the command handler

Function Documentation

◆ joybus_target_byte_received()

int joybus_target_byte_received ( struct joybus_target * target,
const uint8_t * command,
uint8_t byte_idx,
joybus_target_response_cb send_response,
void * user_data )
inlinestatic

Handle a received command byte for a Joybus target.

Parameters
targetthe target to handle the command
commandthe command buffer
byte_idxthe index of the byte that was just received
send_responsea callback function to send the response
user_datauser data to pass to the response callback
Returns
positive number of bytes still expected, 0 if no more bytes expected, a negative joybus_error on failure

◆ joybus_target_is_registered()

bool joybus_target_is_registered ( struct joybus_target * target)
inlinestatic

Check if a target is currently registered on the bus.

Parameters
targetthe target to check
Returns
true if the target is registered, false otherwise