Interfaces for implementing Joybus targets and N64 accessories.
More...
|
| #define | JOYBUS_TARGET(target) |
| | Macro to cast a concrete Joybus target instance to a generic Joybus target instance.
|
|
| 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.
|
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().
◆ JOYBUS_TARGET
| #define JOYBUS_TARGET |
( |
| target | ) |
|
Value:
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.
◆ 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
-
| response | the response data to send |
| len | the length of the response data |
| user_data | user data passed to the command handler |
◆ joybus_target_byte_received()
Handle a received command byte for a Joybus target.
- Parameters
-
| target | the target to handle the command |
| command | the command buffer |
| byte_idx | the index of the byte that was just received |
| send_response | a callback function to send the response |
| user_data | user 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
-
| target | the target to check |
- Returns
- true if the target is registered, false otherwise