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

Commands for communicating with GameCube and N64 controllers. More...

Typedefs

typedef void(* joybus_n64_accessory_detect_cb_t) (int accessory_type, void *user_data)
 Callback type for N64 accessory detection.

Enumerations

enum  joybus_n64_accessory_type {
  JOYBUS_N64_ACCESSORY_NONE = 0 ,
  JOYBUS_N64_ACCESSORY_UNKNOWN ,
  JOYBUS_N64_ACCESSORY_CONTROLLER_PAK ,
  JOYBUS_N64_ACCESSORY_RUMBLE_PAK ,
  JOYBUS_N64_ACCESSORY_TRANSFER_PAK ,
  JOYBUS_N64_ACCESSORY_BIO_SENSOR ,
  JOYBUS_N64_ACCESSORY_SNAP_STATION
}
 N64 controller accessory types. More...

Functions

int joybus_identify (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Identify the target device attached to the Joybus.
int joybus_reset (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Reset the target device attached to the Joybus.
int joybus_gcn_read (struct joybus *bus, enum joybus_gcn_analog_mode analog_mode, enum joybus_gcn_motor_state motor_state, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Read the current input state of a GameCube controller.
int joybus_gcn_read_origin (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Read the origin (neutral) state of a GameCube controller.
int joybus_gcn_calibrate (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Calibrate a GameCube controller, setting its current input state as the origin.
int joybus_gcn_read_long (struct joybus *bus, enum joybus_gcn_motor_state motor_state, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Read the current input state of a GameCube controller, with full precision.
int joybus_gcn_probe_device (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Send a "probe device" command to a WaveBird controller.
int joybus_gcn_fix_device (struct joybus *bus, uint16_t wireless_id, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Send a "fix device" command to a WaveBird controller.
int joybus_gcn_unpack_input (struct joybus_gc_controller_input *dest, const uint8_t *src, enum joybus_gcn_analog_mode analog_mode)
 Unpack raw input data from a GameCube controller.
int joybus_n64_read (struct joybus *bus, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Read the current input state of an N64 controller.
int joybus_n64_accessory_write (struct joybus *bus, uint16_t addr, const uint8_t *data, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Write data to a N64 controller's accessory port.
int joybus_n64_accessory_read (struct joybus *bus, uint16_t addr, uint8_t *response, joybus_transfer_cb_t callback, void *user_data)
 Read data from a N64 controller's accessory port.
void joybus_n64_accessory_detect (struct joybus *bus, joybus_n64_accessory_detect_cb_t callback, void *user_data)
 Detect the accessory connected to a N64 controller.
void joybus_n64_motor_start (struct joybus *bus)
 Start the rumble motor in a N64 Rumble Pak.
void joybus_n64_motor_stop (struct joybus *bus)
 Stop the rumble motor in a N64 Rumble Pak.

Detailed Description

Commands for communicating with GameCube and N64 controllers.

N64 specific Joybus commands.

GameCube specific Joybus commands.

Common Joybus commands.

Typedef Documentation

◆ joybus_n64_accessory_detect_cb_t

typedef void(* joybus_n64_accessory_detect_cb_t) (int accessory_type, void *user_data)

Callback type for N64 accessory detection.

Parameters
accessory_typethe detected accessory type, one of JOYBUS_N64_ACCESSORY_*
user_datauser data passed to the detection function

Enumeration Type Documentation

◆ joybus_n64_accessory_type

N64 controller accessory types.

Enumerator
JOYBUS_N64_ACCESSORY_NONE 

No accessory connected.

JOYBUS_N64_ACCESSORY_UNKNOWN 

Accessory type could not be determined.

JOYBUS_N64_ACCESSORY_CONTROLLER_PAK 

Controller Pak.

JOYBUS_N64_ACCESSORY_RUMBLE_PAK 

Rumble Pak.

JOYBUS_N64_ACCESSORY_TRANSFER_PAK 

Transfer Pak.

JOYBUS_N64_ACCESSORY_BIO_SENSOR 

Bio Sensor.

JOYBUS_N64_ACCESSORY_SNAP_STATION 

Snap Station.

Function Documentation

◆ joybus_gcn_calibrate()

int joybus_gcn_calibrate ( struct joybus * bus,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Calibrate a GameCube controller, setting its current input state as the origin.

Parameters
busthe Joybus to use
responsebuffer to store the response in, must be at least JOYBUS_CMD_GCN_CALIBRATE_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_gcn_fix_device()

int joybus_gcn_fix_device ( struct joybus * bus,
uint16_t wireless_id,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Send a "fix device" command to a WaveBird controller.

Non-wireless controllers will ignore this command. If successful, the response buffer will contain the updated controller ID.

Parameters
busthe Joybus to use
wireless_idthe 10-bit wireless ID to fix the controller to
responsebuffer to store the response in, must be at least JOYBUS_CMD_GCN_FIX_DEVICE_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_gcn_probe_device()

int joybus_gcn_probe_device ( struct joybus * bus,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Send a "probe device" command to a WaveBird controller.

Non-wireless controllers will ignore this command.

Parameters
busthe Joybus to use
responsebuffer to store the response in, must be at least JOYBUS_CMD_GCN_PROBE_DEVICE_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function

◆ joybus_gcn_read()

int joybus_gcn_read ( struct joybus * bus,
enum joybus_gcn_analog_mode analog_mode,
enum joybus_gcn_motor_state motor_state,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Read the current input state of a GameCube controller.

Parameters
busthe Joybus to use
analog_modethe analog mode to use (one of JOYBUS_GCN_ANALOG_MODE_*)
motor_statethe motor state to use (one of JOYBUS_GCN_MOTOR_*)
responsebuffer to store the response in, must be at least JOYBUS_CMD_GCN_READ_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_gcn_read_long()

int joybus_gcn_read_long ( struct joybus * bus,
enum joybus_gcn_motor_state motor_state,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Read the current input state of a GameCube controller, with full precision.

Parameters
busthe Joybus to use
motor_statethe motor state to use (one of JOYBUS_GCN_MOTOR_*)
responsebuffer to store the response in, must be at least JOYBUS_CMD_GCN_READ_LONG_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_gcn_read_origin()

int joybus_gcn_read_origin ( struct joybus * bus,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Read the origin (neutral) state of a GameCube controller.

Parameters
busthe Joybus to use
responsebuffer to store the response in, must be at least JOYBUS_CMD_GCN_READ_ORIGIN_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_gcn_unpack_input()

int joybus_gcn_unpack_input ( struct joybus_gc_controller_input * dest,
const uint8_t * src,
enum joybus_gcn_analog_mode analog_mode )

Unpack raw input data from a GameCube controller.

The "full" internal input state of a GameCube controller is 10 bytes long, so there are various ways to "pack" the input state into 8 bytes. Depending on the analog mode, either one pair of analog inputs can be omitted, or two pairs of analog inputs can be truncated to 4 bits.

All production games, with the exception of Luigi's Mansion, use analog mode 3. This mode omits the analog A/B inputs, and sends the substick X/Y and triggers at full precision. Analog A/B buttons were only present in pre-production GameCube controllers.

Parameters
destpointer to a joybus_gc_controller_input struct to store the unpacked data
srcpointer to the response buffer from a "read" command
analog_modethe analog mode used when reading (one of JOYBUS_GCN_ANALOG_MODE_*)

◆ joybus_identify()

int joybus_identify ( struct joybus * bus,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Identify the target device attached to the Joybus.

Calls the provided callback when complete. The response buffer will be populated with a 3-byte response containing the device ID and status.

Parameters
busthe Joybus to use
responsebuffer to store the response in
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_n64_accessory_detect()

void joybus_n64_accessory_detect ( struct joybus * bus,
joybus_n64_accessory_detect_cb_t callback,
void * user_data )

Detect the accessory connected to a N64 controller.

This function initiates an asynchronous sequence of commands to detect the accessory type. The provided callback will be called with the detected accessory type once the detection sequence is complete.

Parameters
busthe Joybus to use
callbacka callback function to call when the detection is complete
user_datauser data to pass to the callback function

◆ joybus_n64_accessory_read()

int joybus_n64_accessory_read ( struct joybus * bus,
uint16_t addr,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Read data from a N64 controller's accessory port.

Address checksum is automatically calculated.

Parameters
busthe Joybus to use
addrthe address to read from, must be 32-byte aligned
responsebuffer to store the response in, must be at least JOYBUS_CMD_N64_ACCESSORY_READ_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_n64_accessory_write()

int joybus_n64_accessory_write ( struct joybus * bus,
uint16_t addr,
const uint8_t * data,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Write data to a N64 controller's accessory port.

Address checksum is automatically calculated.

Parameters
busthe Joybus to use
addrthe address to write to, must be 32-byte aligned
datathe data to write
responsebuffer to store the response in, must be at least JOYBUS_CMD_N64_WRITE_MEM_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_n64_motor_start()

void joybus_n64_motor_start ( struct joybus * bus)

Start the rumble motor in a N64 Rumble Pak.

Parameters
busthe Joybus to use

◆ joybus_n64_motor_stop()

void joybus_n64_motor_stop ( struct joybus * bus)

Stop the rumble motor in a N64 Rumble Pak.

Parameters
busthe Joybus to use

◆ joybus_n64_read()

int joybus_n64_read ( struct joybus * bus,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Read the current input state of an N64 controller.

Parameters
busthe Joybus to use
responsebuffer to store the response in, must be at least JOYBUS_CMD_N64_READ_RX bytes
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure

◆ joybus_reset()

int joybus_reset ( struct joybus * bus,
uint8_t * response,
joybus_transfer_cb_t callback,
void * user_data )

Reset the target device attached to the Joybus.

Parameters
busthe Joybus to use
responsebuffer to store the response in
callbacka callback function to call when the transfer is complete
user_datauser data to pass to the callback function
Returns
0 on success, negative error code on failure