libdragon
controller.h
Go to the documentation of this file.
00001 
00006 #ifndef __LIBDRAGON_CONTROLLER_H
00007 #define __LIBDRAGON_CONTROLLER_H
00008 
00021 #define CONTROLLER_1_INSERTED   0xF000
00022 
00023 #define CONTROLLER_2_INSERTED   0x0F00
00024 
00025 #define CONTROLLER_3_INSERTED   0x00F0
00026 
00027 #define CONTROLLER_4_INSERTED   0x000F
00028 
00036 #define ACCESSORY_NONE          0
00037 
00038 #define ACCESSORY_MEMPAK        1
00039 
00040 #define ACCESSORY_RUMBLEPAK     2
00041 
00042 #define ACCESSORY_VRU           3
00043 
00051 #define CONTROLLER_NONE         0xFF
00052 
00053 #define CONTROLLER_MOUSE        2
00054 
00055 #define CONTROLLER_KEYBOARD     4 // ?? fixme!
00056 
00057 #define CONTROLLER_PAD          5
00058 
00065 #define ERROR_NONE          0x0
00066 
00067 #define ERROR_BAD_COMMAND   0x1
00068 
00069 #define ERROR_NOT_PRESENT   0x2
00070 
00073 typedef struct SI_condat
00074 {
00076     unsigned : 16;
00078     unsigned err : 2;
00080     unsigned : 14;
00081 
00082     union
00083     {
00084         struct
00085         {
00087             unsigned int data : 32;
00088         };
00089         struct
00090         {
00092             unsigned A : 1;
00094             unsigned B : 1;
00096             unsigned Z : 1;
00098             unsigned start : 1;
00100             unsigned up : 1;
00102             unsigned down : 1;
00104             unsigned left : 1;
00106             unsigned right : 1;
00108             unsigned : 2;
00110             unsigned L : 1;
00112             unsigned R : 1;
00114             unsigned C_up : 1;
00116             unsigned C_down : 1;
00118             unsigned C_left : 1;
00120             unsigned C_right : 1;
00122             signed x : 8;
00124             signed y : 8;
00125         };
00126     };
00127 } _SI_condat;
00128 
00132 typedef struct controller_data
00133 {
00135     struct SI_condat c[4];
00137     unsigned long unused[4*8];
00138 } _controller_data;
00139 
00140 #ifdef __cplusplus
00141 extern "C" {
00142 #endif
00143 
00144 void controller_init();
00145 void controller_read( struct controller_data * data);
00146 int get_controllers_present();
00147 int get_accessories_present();
00148 void controller_scan();
00149 struct controller_data get_keys_down();
00150 struct controller_data get_keys_up();
00151 struct controller_data get_keys_held();
00152 struct controller_data get_keys_pressed();
00153 int get_dpad_direction( int controller );
00154 int read_mempak_address( int controller, uint16_t address, uint8_t *data );
00155 int write_mempak_address( int controller, uint16_t address, uint8_t *data );
00156 int identify_accessory( int controller );
00157 int identify_controller( int controller );
00158 void rumble_start( int controller );
00159 void rumble_stop( int controller );
00160 void execute_raw_command( int controller, int command, int bytesout, int bytesin, unsigned char *out, unsigned char *in );
00161 int eeprom_present();
00162 void eeprom_read(int block, uint8_t * const buf);
00163 void eeprom_write(int block, const uint8_t * const data);
00164 
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168  /* controller */
00170 
00171 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines