12#include <joybus/target.h>
17#define JOYBUS_FREQ_NOMINAL 250000
20#define JOYBUS_FREQ_N64_CONSOLE 244141
23#define JOYBUS_FREQ_N64_EXTJOY JOYBUS_FREQ_N64_CONSOLE
26#define JOYBUS_FREQ_N64_CONTROLLER 250000
29#define JOYBUS_FREQ_N64_VRU 250000
32#define JOYBUS_FREQ_GCN_CONSOLE 202500
35#define JOYBUS_FREQ_GCN_CONTROLLER 250000
38#define JOYBUS_FREQ_WAVEBIRD_RECEIVER 225000
41#define JOYBUS_FREQ_WII_CONSOLE 202500
44#define JOYBUS_FREQ_GCN_GBA_CABLE 262144
47#define JOYBUS_INTER_TRANSFER_DELAY_US 80
50#define JOYBUS_REPLY_TIMEOUT_US 64
53#define JOYBUS_BUS_IDLE_US 100
56#define JOYBUS_BLOCK_SIZE 64
61#define JOYBUS(bus) ((struct joybus *)(bus))
89 int (*enable)(
struct joybus *bus);
90 int (*disable)(
struct joybus *bus);
91 int (*transfer)(
struct joybus *bus,
const uint8_t *write_buf, uint8_t write_len, uint8_t *read_buf, uint8_t read_len,
139 return bus->
api->enable(bus);
149 return bus->
api->disable(bus);
168static inline int joybus_transfer(
struct joybus *bus,
const uint8_t *write_buf, uint8_t write_len, uint8_t *read_buf,
171 return bus->
api->transfer(bus, write_buf, write_len, read_buf, read_len, callback, user_data);
260void joybus_sync_cb(
struct joybus *bus,
int status,
void *user_data);
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 single Joybus target.
Definition target.h:116
void(* joybus_target_response_cb)(const uint8_t *response, uint8_t len, void *user_data)
Callback type for sending responses from target command handlers.
Definition target.h:68
joybus_mode
The role a Joybus instance plays on the bus.
Definition bus.h:66
void(* joybus_transfer_cb)(struct joybus *bus, int status, void *user_data)
Function type for transfer completion callbacks.
Definition bus.h:85
static int joybus_byte_received(struct joybus *bus, const uint8_t *command, uint8_t byte_idx, joybus_target_response_cb send_response, void *user_data)
Offer a received command byte to the targets attached to the bus.
Definition bus.h:231
static int joybus_enable(struct joybus *bus, enum joybus_mode mode)
Enable the Joybus instance in the given mode.
Definition bus.h:136
#define JOYBUS_BLOCK_SIZE
Maximum size of a Joybus transfer, in bytes.
Definition bus.h:56
int joybus_transfer_sync(struct joybus *bus, const uint8_t *write_buf, uint8_t write_len, uint8_t *read_buf, uint8_t read_len)
Perform a synchronous "write then read" Joybus transfer.
Definition bus.c:61
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 callback, void *user_data)
Perform a Joybus "write then read" transfer.
Definition bus.h:168
static int joybus_disable(struct joybus *bus)
Disable the Joybus instance.
Definition bus.h:147
int joybus_attach_target(struct joybus *bus, struct joybus_target *target)
Attach a target to handle commands received in target mode.
Definition bus.c:3
int joybus_detach_target(struct joybus *bus, struct joybus_target *target)
Detach a target from the bus.
Definition bus.c:20
@ JOYBUS_MODE_HOST
Host mode, sends commands and reads responses from a target device.
Definition bus.h:68
@ JOYBUS_MODE_TARGET
Target mode, listens for commands from a host device and responds accordingly.
Definition bus.h:71
@ JOYBUS_ERR_NOT_SUPPORTED
Command not supported by Joybus target.
Definition errors.h:27
uint8_t status
Status flags.
Definition identify.h:4
Interface for a Joybus target, a device on the Joybus which responds to commands from a host.
Definition target.h:92
struct joybus_target * next
The next target attached to the same bus, in attachment order.
Definition target.h:100
A Joybus instance.
Definition bus.h:105
enum joybus_mode mode
The operating mode of this Joybus instance (host or target).
Definition bus.h:110
uint32_t freq
The frequency of the bus, in Hz.
Definition bus.h:113
const struct joybus_api * api
The backend API implementation for this Joybus instance.
Definition bus.h:107
struct joybus_target * targets
The targets attached to this Joybus instance, in attachment order.
Definition bus.h:116
struct joybus_target * active_target
The target that claimed the command being received, if any.
Definition bus.h:119