PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ps2kbd.c File Reference
#include "types.h"
#include "ioman.h"
#include "loadcore.h"
#include "stdio.h"
#include "sifcmd.h"
#include "sifrpc.h"
#include "sysclib.h"
#include <errno.h>
#include "sysmem.h"
#include "usbd.h"
#include "usbd_macro.h"
#include "thbase.h"
#include "thevent.h"
#include "thsemap.h"
#include "ps2kbd.h"
#include "us_keymap.h"
+ Include dependency graph for ps2kbd.c:

Go to the source code of this file.

Data Structures

struct  _kbd_data_recv
 
struct  _keyb_dev
 
struct  _string_descriptor
 

Macros

#define MODNAME   "PS2 USB keyboard driver"
 
#define PS2KBD_VERSION   0x100
 
#define USB_SUBCLASS_BOOT   1
 
#define USB_HIDPROTO_KEYBOARD   1
 
#define PS2KBD_MAXDEV   2
 
#define PS2KBD_MAXKEYS   6
 
#define PS2KBD_DEFLINELEN   4096
 
#define PS2KBD_DEFREPEATRATE   100
 
#define PS2KBD_REPEATWAIT   1000
 
#define USB_KEYB_NUMLOCK   0x53
 
#define USB_KEYB_CAPSLOCK   0x39
 
#define USB_KEYB_SCRLOCK   0x47
 
#define USB_KEYB_NUMPAD_START   0x54
 
#define USB_KEYB_NUMPAD_END   0x63
 
#define SEMA_ZERO   -419
 
#define SEMA_DELETED   -425
 

Typedefs

typedef struct _kbd_data_recv kbd_data_recv
 
typedef struct _keyb_dev kbd_dev
 
typedef struct _string_descriptor string_descriptor
 

Functions

 IRX_ID (MODNAME, 1, 1)
 
int ps2kbd_init ()
 
void ps2kbd_config_set (int resultCode, int bytes, void *arg)
 
void ps2kbd_idlemode_set (int resultCode, int bytes, void *arg)
 
void ps2kbd_data_recv (int resultCode, int bytes, void *arg)
 
int ps2kbd_probe (int devId)
 
int ps2kbd_connect (int devId)
 
int ps2kbd_disconnect (int devId)
 
void usb_getstring (int endp, int index, char *desc)
 
int _start (int argc, char *argv[])
 
void ps2kbd_getstring_set (int resultCode, int bytes, void *arg)
 
void ps2kbd_led_set (int resultCode, int bytes, void *arg)
 
void ps2kbd_build_uniquekeys (u8 *res, const u8 *new, const u8 *old)
 
u32 ps2kbd_repeathandler (void *arg)
 
void ps2kbd_getkeys (u8 keyMods, u8 ledStatus, const u8 *keys, kbd_dev *dev)
 
void ps2kbd_getkeys_raw (u8 newKeyMods, u8 oldKeyMods, const u8 *new, const u8 *old)
 
void flushbuffer ()
 
void ps2kbd_ioctl_setreadmode (u32 readmode)
 
void ps2kbd_ioctl_setkeymap (kbd_keymap *keymaps)
 
void ps2kbd_ioctl_setctrlmap (u8 *ctrlmap)
 
void ps2kbd_ioctl_setaltmap (u8 *altmap)
 
void ps2kbd_ioctl_setspecialmap (u8 *special)
 
void ps2kbd_ioctl_resetkeymap ()
 
void ps2kbd_ioctl_flushbuffer ()
 
void ps2kbd_ioctl_setleds (u8 ledStatus)
 
void ps2kbd_ioctl_setblockmode (u32 blockmode)
 
void ps2kbd_ioctl_setrepeatrate (u32 rate)
 
int fio_dummy ()
 
int fio_init (iop_device_t *driver)
 
int fio_format (iop_file_t *f)
 
int fio_open (iop_file_t *f, const char *name, int mode)
 
int fio_read (iop_file_t *f, void *buf, int size)
 
int fio_ioctl (iop_file_t *f, int cmd, void *param)
 
int fio_close (iop_file_t *f)
 
int init_fio ()
 
void repeat_thread (void *arg)
 
int init_repeatthread ()
 

Variables

int kbd_readmode
 
int kbd_blocking
 
u32 kbd_repeatrate
 
kbd_devdevices [PS2KBD_MAXDEV]
 
int dev_count
 
sceUsbdLddOps kbd_driver = { NULL, NULL, "PS2Kbd", ps2kbd_probe, ps2kbd_connect, ps2kbd_disconnect, 0, 0, 0, 0, 0, NULL }
 
u8 * lineBuffer
 
u32 lineStartP
 
u32 lineEndP
 
int lineSema
 
int bufferSema
 
u32 lineSize
 
u8 keymap [PS2KBD_KEYMAP_SIZE]
 
u8 shiftkeymap [PS2KBD_KEYMAP_SIZE]
 
u8 keycap [PS2KBD_KEYMAP_SIZE]
 
u8 special_keys [PS2KBD_KEYMAP_SIZE]
 
u8 control_map [PS2KBD_KEYMAP_SIZE]
 
u8 alt_map [PS2KBD_KEYMAP_SIZE]
 
u8 keyModValue [8] = { 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7 }
 
int repeat_tid
 
int eventid
 
static iop_device_ops_t fio_ops
 
static iop_device_t kbd_filedrv
 

Detailed Description

USB Keyboard Driver for PS2

Definition in file ps2kbd.c.


Data Structure Documentation

◆ _kbd_data_recv

struct _kbd_data_recv

Definition at line 70 of file ps2kbd.c.

Data Fields
u8 mod_keys
u8 reserved
u8 keycodes[PS2KBD_MAXKEYS]

◆ _keyb_dev

struct _keyb_dev

Definition at line 78 of file ps2kbd.c.

+ Collaboration diagram for _keyb_dev:
Data Fields
int configEndp
int dataEndp
int packetSize
int devId
int interfaceNo

Holds the interface number selected on this device

char repeatkeys[2]
u32 eventmask
u8 ledStatus

Maintains state on the led status

kbd_data_recv oldData
kbd_data_recv data

Holds the data for the transfers

◆ _string_descriptor

struct _string_descriptor

Definition at line 323 of file ps2kbd.c.

Data Fields
u8 buf[200]
char * desc

Macro Definition Documentation

◆ MODNAME

#define MODNAME   "PS2 USB keyboard driver"

Definition at line 34 of file ps2kbd.c.

◆ PS2KBD_VERSION

#define PS2KBD_VERSION   0x100

Definition at line 38 of file ps2kbd.c.

◆ USB_SUBCLASS_BOOT

#define USB_SUBCLASS_BOOT   1

Definition at line 40 of file ps2kbd.c.

◆ USB_HIDPROTO_KEYBOARD

#define USB_HIDPROTO_KEYBOARD   1

Definition at line 41 of file ps2kbd.c.

◆ PS2KBD_MAXDEV

#define PS2KBD_MAXDEV   2

Definition at line 43 of file ps2kbd.c.

◆ PS2KBD_MAXKEYS

#define PS2KBD_MAXKEYS   6

Definition at line 44 of file ps2kbd.c.

◆ PS2KBD_DEFLINELEN

#define PS2KBD_DEFLINELEN   4096

Definition at line 46 of file ps2kbd.c.

◆ PS2KBD_DEFREPEATRATE

#define PS2KBD_DEFREPEATRATE   100

Definition at line 47 of file ps2kbd.c.

◆ PS2KBD_REPEATWAIT

#define PS2KBD_REPEATWAIT   1000

Default repeat rate in milliseconds

Definition at line 49 of file ps2kbd.c.

◆ USB_KEYB_NUMLOCK

#define USB_KEYB_NUMLOCK   0x53

Number of milliseconds to wait before starting key repeat

Definition at line 51 of file ps2kbd.c.

◆ USB_KEYB_CAPSLOCK

#define USB_KEYB_CAPSLOCK   0x39

Definition at line 52 of file ps2kbd.c.

◆ USB_KEYB_SCRLOCK

#define USB_KEYB_SCRLOCK   0x47

Definition at line 53 of file ps2kbd.c.

◆ USB_KEYB_NUMPAD_START

#define USB_KEYB_NUMPAD_START   0x54

Definition at line 55 of file ps2kbd.c.

◆ USB_KEYB_NUMPAD_END

#define USB_KEYB_NUMPAD_END   0x63

Definition at line 56 of file ps2kbd.c.

◆ SEMA_ZERO

#define SEMA_ZERO   -419

Definition at line 58 of file ps2kbd.c.

◆ SEMA_DELETED

#define SEMA_DELETED   -425

Definition at line 59 of file ps2kbd.c.

Function Documentation

◆ ps2kbd_init()

int ps2kbd_init ( )

Definition at line 1241 of file ps2kbd.c.

◆ ps2kbd_config_set()

void ps2kbd_config_set ( int  resultCode,
int  bytes,
void *  arg 
)

Definition at line 380 of file ps2kbd.c.

◆ ps2kbd_idlemode_set()

void ps2kbd_idlemode_set ( int  resultCode,
int  bytes,
void *  arg 
)

Definition at line 402 of file ps2kbd.c.

◆ ps2kbd_data_recv()

void ps2kbd_data_recv ( int  resultCode,
int  bytes,
void *  arg 
)

Definition at line 714 of file ps2kbd.c.

◆ ps2kbd_probe()

int ps2kbd_probe ( int  devId)

Definition at line 136 of file ps2kbd.c.

◆ ps2kbd_connect()

int ps2kbd_connect ( int  devId)

Definition at line 212 of file ps2kbd.c.

◆ ps2kbd_disconnect()

int ps2kbd_disconnect ( int  devId)

Definition at line 302 of file ps2kbd.c.

◆ usb_getstring()

void usb_getstring ( int  endp,
int  index,
char *  desc 
)

Definition at line 356 of file ps2kbd.c.

◆ _start()

int _start ( int  argc,
char *  argv[] 
)

Definition at line 124 of file ps2kbd.c.

◆ ps2kbd_getstring_set()

void ps2kbd_getstring_set ( int  resultCode,
int  bytes,
void *  arg 
)

Definition at line 330 of file ps2kbd.c.

◆ ps2kbd_led_set()

void ps2kbd_led_set ( int  resultCode,
int  bytes,
void *  arg 
)

Definition at line 422 of file ps2kbd.c.

◆ ps2kbd_build_uniquekeys()

void ps2kbd_build_uniquekeys ( u8 *  res,
const u8 *  new,
const u8 *  old 
)

Definition at line 432 of file ps2kbd.c.

◆ ps2kbd_repeathandler()

u32 ps2kbd_repeathandler ( void *  arg)

Definition at line 462 of file ps2kbd.c.

◆ ps2kbd_getkeys()

void ps2kbd_getkeys ( u8  keyMods,
u8  ledStatus,
const u8 *  keys,
kbd_dev dev 
)

Definition at line 477 of file ps2kbd.c.

◆ ps2kbd_getkeys_raw()

void ps2kbd_getkeys_raw ( u8  newKeyMods,
u8  oldKeyMods,
const u8 *  new,
const u8 *  old 
)

Definition at line 620 of file ps2kbd.c.

◆ flushbuffer()

void flushbuffer ( )

Definition at line 834 of file ps2kbd.c.

◆ ps2kbd_ioctl_setreadmode()

void ps2kbd_ioctl_setreadmode ( u32  readmode)

Definition at line 856 of file ps2kbd.c.

◆ ps2kbd_ioctl_setkeymap()

void ps2kbd_ioctl_setkeymap ( kbd_keymap keymaps)

Definition at line 880 of file ps2kbd.c.

◆ ps2kbd_ioctl_setctrlmap()

void ps2kbd_ioctl_setctrlmap ( u8 *  ctrlmap)

Definition at line 891 of file ps2kbd.c.

◆ ps2kbd_ioctl_setaltmap()

void ps2kbd_ioctl_setaltmap ( u8 *  altmap)

Definition at line 900 of file ps2kbd.c.

◆ ps2kbd_ioctl_setspecialmap()

void ps2kbd_ioctl_setspecialmap ( u8 *  special)

Definition at line 909 of file ps2kbd.c.

◆ ps2kbd_ioctl_resetkeymap()

void ps2kbd_ioctl_resetkeymap ( )

Definition at line 918 of file ps2kbd.c.

◆ ps2kbd_ioctl_flushbuffer()

void ps2kbd_ioctl_flushbuffer ( )

Definition at line 933 of file ps2kbd.c.

◆ ps2kbd_ioctl_setleds()

void ps2kbd_ioctl_setleds ( u8  ledStatus)

Definition at line 943 of file ps2kbd.c.

◆ ps2kbd_ioctl_setblockmode()

void ps2kbd_ioctl_setblockmode ( u32  blockmode)

Definition at line 966 of file ps2kbd.c.

◆ ps2kbd_ioctl_setrepeatrate()

void ps2kbd_ioctl_setrepeatrate ( u32  rate)

Definition at line 976 of file ps2kbd.c.

◆ fio_dummy()

int fio_dummy ( )

Definition at line 982 of file ps2kbd.c.

◆ fio_init()

int fio_init ( iop_device_t driver)

Definition at line 988 of file ps2kbd.c.

◆ fio_format()

int fio_format ( iop_file_t f)

Definition at line 996 of file ps2kbd.c.

◆ fio_open()

int fio_open ( iop_file_t f,
const char *  name,
int  mode 
)

Definition at line 1004 of file ps2kbd.c.

◆ fio_read()

int fio_read ( iop_file_t f,
void *  buf,
int  size 
)

Definition at line 1018 of file ps2kbd.c.

◆ fio_ioctl()

int fio_ioctl ( iop_file_t f,
int  cmd,
void *  param 
)

Definition at line 1076 of file ps2kbd.c.

◆ fio_close()

int fio_close ( iop_file_t f)

Definition at line 1110 of file ps2kbd.c.

◆ init_fio()

int init_fio ( )

Definition at line 1150 of file ps2kbd.c.

◆ repeat_thread()

void repeat_thread ( void *  arg)

Definition at line 1156 of file ps2kbd.c.

◆ init_repeatthread()

int init_repeatthread ( )

Definition at line 1212 of file ps2kbd.c.

Variable Documentation

◆ kbd_readmode

int kbd_readmode

Definition at line 98 of file ps2kbd.c.

◆ kbd_blocking

int kbd_blocking

Definition at line 99 of file ps2kbd.c.

◆ kbd_repeatrate

u32 kbd_repeatrate

Definition at line 100 of file ps2kbd.c.

◆ devices

kbd_dev* devices[PS2KBD_MAXDEV]

Holds a list of current devices

Definition at line 102 of file ps2kbd.c.

◆ dev_count

int dev_count

Definition at line 103 of file ps2kbd.c.

◆ kbd_driver

sceUsbdLddOps kbd_driver = { NULL, NULL, "PS2Kbd", ps2kbd_probe, ps2kbd_connect, ps2kbd_disconnect, 0, 0, 0, 0, 0, NULL }

Definition at line 104 of file ps2kbd.c.

◆ lineBuffer

u8* lineBuffer

Definition at line 105 of file ps2kbd.c.

◆ lineStartP

u32 lineStartP

Definition at line 106 of file ps2kbd.c.

◆ lineEndP

u32 lineEndP

Definition at line 106 of file ps2kbd.c.

◆ lineSema

int lineSema

Definition at line 107 of file ps2kbd.c.

◆ bufferSema

int bufferSema

Definition at line 108 of file ps2kbd.c.

◆ lineSize

u32 lineSize

Definition at line 109 of file ps2kbd.c.

◆ keymap

u8 keymap[PS2KBD_KEYMAP_SIZE]

Normal key map

Definition at line 111 of file ps2kbd.c.

◆ shiftkeymap

u8 shiftkeymap[PS2KBD_KEYMAP_SIZE]

Shifted key map

Definition at line 113 of file ps2kbd.c.

◆ keycap

u8 keycap[PS2KBD_KEYMAP_SIZE]

Does this key get shifted by capslock ?

Definition at line 115 of file ps2kbd.c.

◆ special_keys

u8 special_keys[PS2KBD_KEYMAP_SIZE]

Definition at line 116 of file ps2kbd.c.

◆ control_map

u8 control_map[PS2KBD_KEYMAP_SIZE]

Definition at line 117 of file ps2kbd.c.

◆ alt_map

u8 alt_map[PS2KBD_KEYMAP_SIZE]

Definition at line 118 of file ps2kbd.c.

◆ keyModValue

u8 keyModValue[8] = { 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7 }

Definition at line 120 of file ps2kbd.c.

◆ repeat_tid

int repeat_tid

Definition at line 121 of file ps2kbd.c.

◆ eventid

int eventid

Definition at line 122 of file ps2kbd.c.

◆ fio_ops

iop_device_ops_t fio_ops
static
Initial value:
=
{
&fio_init,
(void *)&fio_dummy,
&fio_format,
&fio_open,
&fio_close,
&fio_read,
(void *)&fio_dummy,
(void *)&fio_dummy,
&fio_ioctl,
(void *)&fio_dummy,
(void *)&fio_dummy,
(void *)&fio_dummy,
(void *)&fio_dummy,
(void *)&fio_dummy,
(void *)&fio_dummy,
(void *)&fio_dummy,
(void *)&fio_dummy,
}

Definition at line 1119 of file ps2kbd.c.

◆ kbd_filedrv

iop_device_t kbd_filedrv
static
Initial value:
= {
PS2KBD_FSNAME,
IOP_DT_CHAR,
0,
"USB Keyboard FIO driver",
&fio_ops,
}

Definition at line 1141 of file ps2kbd.c.