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
59#define JOYBUS_PAK_BLOCK_SIZE 32
64#define JOYBUS(bus) ((struct joybus *)(bus))
92 int (*enable)(
struct joybus *bus);
93 int (*disable)(
struct joybus *bus);
94 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);
229void joybus_sync_cb(
struct joybus *bus,
int status,
void *user_data);
joybus_mode
The role a Joybus instance plays on the bus.
Definition bus.h:69
void(* joybus_transfer_cb)(struct joybus *bus, int status, void *user_data)
Function type for transfer completion callbacks.
Definition bus.h:88
static int joybus_detach_target(struct joybus *bus, struct joybus_target *target)
Detach a target from the bus.
Definition bus.h:214
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:24
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
static int joybus_attach_target(struct joybus *bus, struct joybus_target *target)
Attach a target to handle commands received in target mode.
Definition bus.h:199
@ JOYBUS_MODE_HOST
Host mode, sends commands and reads responses from a target device.
Definition bus.h:71
@ JOYBUS_MODE_TARGET
Target mode, listens for commands from a host device and responds accordingly.
Definition bus.h:74
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:72
bool attached
Whether the target is currently attached to a bus.
Definition target.h:77
A Joybus instance.
Definition bus.h:108
struct joybus_target * target
The target device attached to this Joybus instance, if any.
Definition bus.h:119
enum joybus_mode mode
The operating mode of this Joybus instance (host or target).
Definition bus.h:113
uint32_t freq
The frequency of the bus, in Hz.
Definition bus.h:116
const struct joybus_api * api
The backend API implementation for this Joybus instance.
Definition bus.h:110