OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Sep 26, 2017 8:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: update keyboard leds
PostPosted: Wed Nov 24, 2004 5:58 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1220
Location: Sweden
Hello, i recently added code in my keyboard irq to update teh leds when caps, num or scroll lock is pressed..

the problem is that bosch gives me a "keyboard buffer full"-error when i have this function enabled..

something i am missing?
thanks in advance..

/ Christoffer

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:update keyboard leds
PostPosted: Wed Nov 24, 2004 6:37 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 11:59 am
Posts: 1600
Location: Vienna/Austria
i wouldn't do this kind of operation in the isr. I'd do it in a sort of task - or a tasklet, which does the work after the isr has fetched the scancodes from kbd port 60 (iirc)

are you still reading scancodes from port 60?

If not, no wonder that bochs doesn't like it.

are you issueing the correct combo of command/data sequence? I don't know it by heart, but can lookup.

is your code caught in a condition which never/always becomes true?

just check it out. Without more info about *how* your kbd isr looks like (a rough sketch in human language or pseudocode suffices), we canna give that much help as we want to. :-)

ha en bra dag

_________________
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image


Top
 Profile  
 
 Post subject: Re:update keyboard leds
PostPosted: Wed Nov 24, 2004 7:01 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1220
Location: Sweden
Hmm. I?ll try to describe the process..

I read the scan code from port 0x60

I check if key is released or pressed. save status as bit in "special-byte"
If ctrl is pressed or not, saved as bit in the "special-byte"
if shift - ||-
if alt - || -
if ctrl+alt+del is pressed, add bit in special-byte..

if caps is pressed, save status in "status-byte"
if num - || -
if scroll - || -

at the end i add the scan code to a buffer, and updates the status and special bytes, after that i "call update_leds" and exits the isr as usual; ack to pic(?) with out 0x20 something..

the update_leds function is adapted from a swedish os, that have a keyboard isr that looks almost excatly like mine.
it sends some bytes (the status-byte and maybe something else) and call a simple "kbd_wait" function 2(?) times in between..

to bad i don?t have my source with me..

[edit] to cold in sweden right now for a "bra dag" (eng: good day).. :-)

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:update keyboard leds
PostPosted: Wed Nov 24, 2004 7:23 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 11:59 am
Posts: 1600
Location: Vienna/Austria
Below are the crucial pieces of code from my own kbd led handling.

Basically you send a bitmask to the controller which tells, which led is on and which one is off.

How are you setting the corresponding bit in status byte say for caps lock?

Code:
void kbd_ack(void){
  while(!(inport(0x60)==0xfa));
}


void kbd_led_handling(uchar_t ledstatus){;
  outport(0x60,0xed);
  kbd_ack();
  outport(0x60,ledstatus);
}


Here in vienna, sun shines but it is cooold as in devils arse.

But that shall not hinder us from enjoying a biiig snow feast. :-)

_________________
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image


Top
 Profile  
 
 Post subject: Re:update keyboard leds
PostPosted: Wed Nov 24, 2004 7:27 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1220
Location: Sweden
hmm. can?t remeber the right order right now, but its something like:
bit 1= 1 for num on, 0 for num off
bit 2= 1 for scroll on, 0 for scroll off
bit 3= 1 for caps on, 0 for caps off
bits 4-8 = 0

i think thats how it?s done.. but as i don?t have my sources right here...

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:update keyboard leds
PostPosted: Fri Nov 26, 2004 4:42 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1220
Location: Sweden
Okay, now i have my source.
Lets see.. Here?s how i check and set the bits in the "kbd_status" byte... (u can?t turn them of yet..)

Code:
;----------------------;
;   Keyboard IRQ         ;
;----------------------;
keyboard_isr:
          push    eax
     ;-----------------------------------;
     ; get the scancode and statusbyte   ;
     ;-----------------------------------;
          xor     eax, eax
          in      al, 0x60
          mov     ah, byte [kbd_special]    ; for ctrl+alt+del etc..

     ;------------------------------;
     ;  check if key was released   ;
     ;------------------------------;
          test    al, 0x80
          jz      .key_down
          or      ah, 10000000b

;............... some code..............

     ;----------------------------------------------;
     ;  a key was pressed, check for special keys   ;
     ;----------------------------------------------;
     .key_down:
          and     ah, 01111111b     

;............... some code..............

     .check_caps:
          cmp     al, 58
          jnz     .check_num
          or      byte [kbd_status], 00000100b
          jmp     .end

     .check_num:
          cmp     al, 69
          jnz     .check_scroll
          or      byte [kbd_status], 00000010b
          jmp     .end

     .check_scroll:
          cmp     al, 70
          jnz     .end
          or      byte [kbd_status], 00000001b
          jmp     .end

;.............. some more code...................

    .end:
          mov     [kbd_raw_buffer], al
          mov     [kbd_special], ah


          movzx   eax, [kbd_status]  ; to check if the statusbyte was correct..
          call    print_hex32


;          call    update_leds

          mov     al, 0x20
          out     0x20, al
          pop     eax
          ret

the (current) update_leds function
Code:
;------------------------------;
;  Update the keyboard LED?s   ;
;------------------------------;
update_leds:
          push    ax

     .l1:
          in      al, 0x64
          and     al, 0x02
          jnz     .l1

          mov     al, 0xED
          out     0x60, al

     .l2:
          in      al, 0x64
          and     al, 02
          jnz     .l2

          mov     al,[kbd_status]
          out     0x60, al

          pop     ax
          ret

Do you have any links to information about "advanced" keyboard programming? Becasue i would also like to know how to test the type of keyboard, know how to set diffrent "scan-modes(?) etc.

/ Christoffer

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
 Post subject: Re:update keyboard leds
PostPosted: Fri Nov 26, 2004 2:44 pm 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 1220
Location: Sweden
[EDIT] For future forum viewers with the same problem, i now update this post with the correct and fully working code.. :-D

variable defined:
Code:
     ;-------------------------------------------------------------------------;
     ; _________________        LED status byte:                               ;
     ; |0|0|0|0|0|1|1|1|                                                       ;
     ; +---------------+                     1 = True   0 = False              ;
     ;            | | +--->  scroll lock                                       ;
     ;            | +----->  num lock                                          ;
     ;            +------->  caps lock                                         ;
     ;-------------------------------------------------------------------------;
     kbd_status     db   0            ; LED statusbyte


In the keyboard IRQ:
Code:
     ;-------------------------------------;
     ;  toggle caps, num and scroll lock   ;
     ;-------------------------------------;
     .check_caps:
     cmp     al, 58
     jnz     .check_num
     xor     byte [kbd_status], 4
     call     update_leds
     jmp     .end

     .check_num:
     cmp     al, 69
     jnz     .check_scroll
     xor     byte [kbd_status], 2
     call     update_leds
     jmp     .end

     .check_scroll:
     cmp     al, 70
     jnz     .end
     xor     byte [kbd_status], 1
     call     update_leds
     jmp     .end


And the functions required to change the LEDs:
Code:
;------------------------------;
;  Update the keyboard LED?s   ;
;------------------------------;
update_leds:
     push     ax

     call     kbd_wait

     mov     al, 0xED
     out     0x60, al

     call     kbd_wait

     mov     al, [kbd_status]
     out     0x60, al

     call     kbd_wait

     pop     ax
     ret



;------------------;
;  keyboard wait   ;
;------------------;
kbd_wait:
     jmp     $+2
     in     al,64h
     test     al,1
     jz     .ok
     jmp     $+2
     in     al,60h
     jmp     kbd_wait
     .ok:
     test     al,2
     jnz     kbd_wait
     ret



anyway, thanks for the help and major input.. :P ;)

/ Christoffer

_________________
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: AMenard, Majestic-12 [Bot] and 16 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group