forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using the USB Keyboard

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed Apr 30, 2008 8:40 am    Post subject: Using the USB Keyboard Reply with quote

Hello again,

I have been messing around with the USB Keyboard and I have been having some problems with getting it to work. If someone could shed some light on this for me, I'll document it in the Wiki, because I have seen a lot of other people with the same problems.
After looking at the code for quake and uLaunchELF, I have tried to diagnose what is the absolute minimum neccessary to get the USB keyboard up and working, but it just won't initialize for some reason.

At first I tried this:
Code:

char *myStr;

PS2KbdInit();
PS2KbdSetReadmode( PS2KBD_READMODE_NORMAL );

while( 1 ) {
.....
}


It didn't seem to initialize, so I did some searching and saw that there were some other things I might need to do in order to get it working. I then tried this:
Code:

   SifInitRpc(0);

   SifExecModuleBuffer(usbd, size_usbd, 0, NULL, &ret);
   SifExecModuleBuffer(ps2kbd, size_ps2kbd, 0, NULL, &ret);

   // Initialize the keyboard library.
   scr_printf("Initializing Keyboard...\n");
   if( PS2KbdInit() == 0 ) {
      scr_printf("Could not initialize keyboard.\n");
   }

   PS2KbdSetReadmode( PS2KBD_READMODE_RAW );


but the darn thing still won't initialize. I'm just trying to get the keyboard working or at least a response from it, but I don't know what is necessary and what is not. Could someone give me a clue???

Thanks in advance =)
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Mega Man



Joined: 18 Jun 2005
Posts: 274

PostPosted: Wed Apr 30, 2008 9:13 am    Post subject: Reply with quote

As far as I remember the module "fileXio.irx" needs to be loaded before the keyboard driver.
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed Apr 30, 2008 9:35 am    Post subject: Reply with quote

Thanks for the quick response, Mega Man.

After copying "fileXio.irx" and "ps2kbd.irx" from my PS2SDK/iop/irx directory into the directory my compiled program was running in, I changed the code to this:
Code:

   SifLoadModule("host0:fileXio.irx", 0, NULL);
   SifLoadModule("host0:ps2kbd.irx", 0, NULL);

   // Initialize the keyboard library.
   scr_printf("Initializing Keyboard...\n");
   if( PS2KbdInit() == 0 ) {
      scr_printf("Could not initialize keyboard.\n");
   }


The fileXio module loaded correctly, but not the ps2kbd module... Am I not passing the correct arguments???
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed Apr 30, 2008 9:53 am    Post subject: Reply with quote

It's OK, I got it! =D

Here's what I had to do:
Code:

   SifLoadModule("host0:fileXio.irx", 0, NULL);
   SifLoadModule("host0:usbd.irx", 0, NULL);
   SifLoadModule("host0:ps2kbd.irx", 0, NULL);

   // Initialize the keyboard library.
   PS2KbdInit();


Console output, where the name of the file being executed is "keyboard.elf":
Code:

Loaded, host:keyboard.elf
start address 0x1000e0
gp address 00000000
loadmodule: fname host0:fileXio.irx args 0 arg
fileXio: fileXio RPC Server v1.00
Copyright (c) 2003 adresd
loadmodule: id 34, ret 0
loadmodule: fname host0:usbd.irx args 0 arg
FreeUsbd v.0.1.2
loadmodule: id 35, ret 0
loadmodule: fname host0:ps2kbd.irx args 0 arg
PS2KBD - USB Keyboard Library
loadmodule: id 36, ret 0
open name usbkbd:dev flag 1 data 41378
open fd = 2
PS2KBD: Found a keyboard device
PS2KBD: Connected device


It turns out the order the modules are loaded in important. It makes sense in hind sight. FileXio, then USBD, then PS2KBD. I hope this helps anyone else who are curious. =)
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed Apr 30, 2008 10:39 am    Post subject: Reply with quote

Follow up:

Here's a very simple blurb of code that can be used to get simple input from the keyboard and display it on the screen. I'll post this in the "Getting Started" section of the Wiki for future reference.

Makefile
Code:

EE_BIN = keyboard.elf
EE_OBJS = keyboard.o
EE_LIBS = -lkbd -ldebug

all: $(EE_BIN)

clean:
   rm -f *.elf *.o *.a

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal


keyboard.c
Code:

#include <tamtypes.h>
#include <stdio.h>
#include <debug.h>
#include <libkbd.h>
#include <loadfile.h>

int main() {
   char newChar = 0;

   init_scr();

   SifLoadModule("host0:fileXio.irx", 0, NULL);
   SifLoadModule("host0:usbd.irx", 0, NULL);
   SifLoadModule("host0:ps2kbd.irx", 0, NULL);

   PS2KbdInit();

   PS2KbdSetReadmode( PS2KBD_READMODE_NORMAL );

   //////Do stuff//////
   scr_printf("Type something!\n");
   while( 1 ) {
      while (!PS2KbdRead(&newChar)) ;;;
      scr_printf("%c", newChar);
   }
   ////////////////////
   // Shut down the keyboard library.
   PS2KbdClose();

   // End program.
   return 0;
}

_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Wed Apr 30, 2008 9:45 pm    Post subject: Reply with quote

Normally I wouldn't care, but since you are targeting the USB keyboard example towards beginners, I'd recommend not having the infinite loop and the unreachable PS2KbdClose() afterwards.

I'd just make the example exit with the ESC button or something similar, to avoid confusion :-)
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Thu May 01, 2008 4:37 am    Post subject: Reply with quote

Is there a list of the default character mapping somewhere? I really hate infinite loops, and I would have done as you said, but I didn't know how. Tthere isn't much info on character mapping with the USB Keyboard. If only there was a reference somewhere...
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Thu May 01, 2008 5:47 am    Post subject: Reply with quote

Try PS2KbdReadRaw (libkbd.h) and have look inside ps2kbd.h.

I've never used USB keyboard in PS2SDK myself, but digging through headers (and sometimes source) is the way forward with PS2SDK :-)
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Thu May 01, 2008 6:56 am    Post subject: Reply with quote

Thank you for the example. I'm sure it will be useful when needed.
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Thu May 01, 2008 8:13 am    Post subject: Reply with quote

How painfully obvious...
The default keymap is ASCII...
heh... =\

http://www.bbdsoft.com/ascii.html
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Thu May 01, 2008 8:18 pm    Post subject: Reply with quote

When finished I think that would be a good idea to add the example to the SVN repository, don't you think?
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Fri May 02, 2008 3:04 am    Post subject: Reply with quote

Yeah, I don't have a lot of experience with Subversion, but I'll look into it. This little adventure has also brought to my attention the need for a few more functions in LIBKBD. I was going to implement some "scanf" type functions that pull straight from the file stream instead of calling "PS2KbdRead()" continuously. LIBKBD right now is useful for detecting key presses, but we need some more versatile functions for keyboard input.
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Fri May 02, 2008 4:24 am    Post subject: Reply with quote

Great.
But about the SVN, my suggestion was to the repository admins, since only they have "commit" rights.
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Fri May 02, 2008 7:17 am    Post subject: Reply with quote

oh...heh...of course...
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Fri May 02, 2008 4:51 pm    Post subject: Reply with quote

Contact Oobles for SVN access, otherwise if the patch/addition is minor, you can just post here in the forums and someone will commit it for you.
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
TracerH



Joined: 24 Feb 2008
Posts: 5

PostPosted: Sat May 10, 2008 6:08 am    Post subject: Reply with quote

Thanks for the example, whatisdot. It will come in very handy.
Back to top
View user's profile Send private message
NoobWithBoobs



Joined: 16 Jul 2008
Posts: 23

PostPosted: Sun Aug 03, 2008 4:22 pm    Post subject: Reply with quote

could i just add those sets of code u posted above,to a different makefile ,and add keyboard.c to the compiling folder? Was lookin to add keyboard support to a project.Im very new to this,and have been messin around with the different examples.
Only thing is i noticed in the makefile code u posted,it is creating keyboard.elf,so i would have to edit that,i assume.
After tinkerin around with it,i see i need to do more than simply add this to the makefile,lol,not sure what though.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group