libdragon
Functions | Variables
controller.c File Reference

Controller Subsystem. More...

#include <string.h>
#include "libdragon.h"
#include "regsinternal.h"

Defines

SI status register bit definitions
#define SI_STATUS_DMA_BUSY   ( 1 << 0 )
 SI DMA busy.
#define SI_STATUS_IO_BUSY   ( 1 << 1 )
 SI IO busy.

Functions

void controller_init ()
 Initialize the controller subsystem.
static void __SI_DMA_wait (void)
 Wait until the SI is finished with a DMA request.
static void __controller_exec_PIF (void *inblock, void *outblock)
 Send a block of data to the PIF and fetch the result.
int eeprom_present ()
 Probe the EEPROM interface.
void eeprom_read (int block, uint8_t *const buf)
 Read a block from EEPROM.
void eeprom_write (int block, const uint8_t *const data)
 Write a block to EEPROM.
void controller_read (struct controller_data *output)
 Read the controller button status for all controllers.
void controller_scan ()
 Scan the controllers to determine the current button state.
struct controller_data get_keys_down ()
 Get keys that were pressed since the last inspection.
struct controller_data get_keys_up ()
 Get keys that were released since the last inspection.
struct controller_data get_keys_held ()
 Get keys that were held since the last inspection.
struct controller_data get_keys_pressed ()
 Get keys that are currently pressed, regardless of previous state.
int get_dpad_direction (int controller)
 Return the DPAD calculated direction.
void execute_raw_command (int controller, int command, int bytesout, int bytesin, unsigned char *out, unsigned char *in)
 Execute a raw PIF command.
int get_controllers_present ()
 Return a bitmask representing which controllers are present.
static int __is_valid_accessory (uint32_t data)
 Return whether the given accessory is recognized.
static void __get_accessories_present (struct controller_data *output)
 Query the PIF as to the status of accessories.
int get_accessories_present ()
 Return a bitmask specifying which controllers have recognized accessories.
static uint16_t __calc_address_crc (uint16_t address)
 Calculate the 5 bit CRC on a mempak address.
static uint8_t __calc_data_crc (uint8_t *data)
 Calculate the 8 bit CRC over a 32-byte block of data.
int read_mempak_address (int controller, uint16_t address, uint8_t *data)
 Read a chunk of data from a mempak.
int write_mempak_address (int controller, uint16_t address, uint8_t *data)
 Write a chunk of data to a mempak.
int identify_accessory (int controller)
 Identify the accessory connected to a controller.
int identify_controller (int controller)
 Identify the controller connected to a controller port.
void rumble_start (int controller)
 Turn rumble on for a particular controller.
void rumble_stop (int controller)
 Turn rumble off for a particular controller.

Variables

static struct SI_regs_s *const SI_regs = (struct SI_regs_s *)0xa4800000
 Structure used to interact with SI registers.
static void *const PIF_RAM = (void *)0x1fc007c0
 Location of the PIF RAM.
static struct controller_data current
 The current sampled controller data.
static struct controller_data last
 The previously sampled controller data.

Detailed Description

Controller Subsystem.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines