mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Update kernel/kb/ps2.{cpp,h} to current coding conventions.
This commit is contained in:
parent
6e6df64fa8
commit
bb3b6b0260
2 changed files with 247 additions and 229 deletions
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sortix/keycodes.h>
|
||||
|
@ -36,15 +38,15 @@
|
|||
|
||||
#include "ps2.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Sortix {
|
||||
|
||||
const uint16_t DATA = 0x0;
|
||||
const uint16_t COMMAND = 0x0;
|
||||
const uint16_t STATUS = 0x4;
|
||||
const uint8_t CMD_SETLED = 0xED;
|
||||
const uint8_t LED_SCRLCK = (1<<0);
|
||||
const uint8_t LED_NUMLCK = (1<<1);
|
||||
const uint8_t LED_CAPSLCK = (1<<2);
|
||||
const uint8_t LED_SCRLCK = 1 << 0;
|
||||
const uint8_t LED_NUMLCK = 1 << 1;
|
||||
const uint8_t LED_CAPSLCK = 1 << 2;
|
||||
|
||||
void PS2Keyboard__OnInterrupt(CPU::InterruptRegisters* regs, void* user)
|
||||
{
|
||||
|
@ -108,7 +110,11 @@ namespace Sortix
|
|||
{
|
||||
kthread_mutex_lock(&kblock);
|
||||
int kbkey = DecodeScancode(scancode);
|
||||
if ( !kbkey ) { kthread_mutex_unlock(&kblock); return; }
|
||||
if ( !kbkey )
|
||||
{
|
||||
kthread_mutex_unlock(&kblock);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !PushKey(kbkey) )
|
||||
{
|
||||
|
@ -120,11 +126,15 @@ namespace Sortix
|
|||
|
||||
uint8_t newleds = leds;
|
||||
|
||||
if ( kbkey == KBKEY_CAPSLOCK ) { newleds ^= LED_CAPSLCK; }
|
||||
if ( kbkey == KBKEY_SCROLLLOCK ) { newleds ^= LED_SCRLCK; }
|
||||
if ( kbkey == KBKEY_NUMLOCK ) { newleds ^= LED_NUMLCK; }
|
||||
if ( kbkey == KBKEY_CAPSLOCK )
|
||||
newleds ^= LED_CAPSLCK;
|
||||
if ( kbkey == KBKEY_SCROLLLOCK )
|
||||
newleds ^= LED_SCRLCK;
|
||||
if ( kbkey == KBKEY_NUMLOCK )
|
||||
newleds ^= LED_NUMLCK;
|
||||
|
||||
if ( newleds != leds ) { UpdateLEDs(leds = newleds); }
|
||||
if ( newleds != leds )
|
||||
UpdateLEDs(leds = newleds);
|
||||
|
||||
kthread_mutex_unlock(&kblock);
|
||||
|
||||
|
@ -133,7 +143,8 @@ namespace Sortix
|
|||
|
||||
void PS2Keyboard::NotifyOwner()
|
||||
{
|
||||
if ( !owner) { return; }
|
||||
if ( !owner)
|
||||
return;
|
||||
owner->OnKeystroke(this, ownerptr);
|
||||
}
|
||||
|
||||
|
@ -146,10 +157,9 @@ namespace Sortix
|
|||
return 0;
|
||||
}
|
||||
|
||||
int offset = (scancodeescaped) ? 0x80 : 0;
|
||||
int offset = scancodeescaped ? 0x80 : 0;
|
||||
int kbkey = scancode & 0x7F;
|
||||
if ( scancode & 0x80 ) { kbkey = -kbkey - offset; }
|
||||
else { kbkey = kbkey + offset; }
|
||||
kbkey = scancode & 0x80 ? -kbkey - offset : kbkey + offset;
|
||||
|
||||
scancodeescaped = false;
|
||||
|
||||
|
@ -165,9 +175,9 @@ namespace Sortix
|
|||
|
||||
void PS2Keyboard::UpdateLEDs(int ledval)
|
||||
{
|
||||
while ( (CPU::InPortB(iobase + STATUS) & (1<<1)) != 0 ) { }
|
||||
while ( (CPU::InPortB(iobase + STATUS) & (1<<1)) );
|
||||
CPU::OutPortB(iobase + COMMAND, CMD_SETLED);
|
||||
while ( (CPU::InPortB(iobase + STATUS) & (1<<1)) != 0 ) { }
|
||||
while ( (CPU::InPortB(iobase + STATUS) & (1<<1)) );
|
||||
CPU::OutPortB(iobase + COMMAND, ledval);
|
||||
}
|
||||
|
||||
|
@ -177,7 +187,8 @@ namespace Sortix
|
|||
this->owner = owner;
|
||||
this->ownerptr = user;
|
||||
kthread_mutex_unlock(&kblock);
|
||||
if ( queueused ) { NotifyOwner(); }
|
||||
if ( queueused )
|
||||
NotifyOwner();
|
||||
}
|
||||
|
||||
bool PS2Keyboard::PushKey(int key)
|
||||
|
@ -187,7 +198,8 @@ namespace Sortix
|
|||
{
|
||||
size_t newqueuelength = (queuelength) ? queuelength * 2 : 32UL;
|
||||
int* newqueue = new int[newqueuelength];
|
||||
if ( !newqueue ) { return false; }
|
||||
if ( !newqueue )
|
||||
return false;
|
||||
size_t elemsize = sizeof(*queue);
|
||||
size_t leadingavai = queuelength-queueoffset;
|
||||
size_t leading = (leadingavai < queueused) ? leadingavai : queueused;
|
||||
|
@ -206,7 +218,8 @@ namespace Sortix
|
|||
|
||||
int PS2Keyboard::PopKey()
|
||||
{
|
||||
if ( !queueused ) { return 0; }
|
||||
if ( !queueused )
|
||||
return 0;
|
||||
int kbkey = queue[queueoffset];
|
||||
queueoffset = (queueoffset + 1) % queuelength;
|
||||
queueused--;
|
||||
|
@ -230,4 +243,5 @@ namespace Sortix
|
|||
ScopedLock lock(&kblock);
|
||||
return queueused;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
|
@ -25,11 +25,14 @@
|
|||
#ifndef SORTIX_KB_PS2_H
|
||||
#define SORTIX_KB_PS2_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sortix/kernel/kthread.h>
|
||||
#include <sortix/kernel/keyboard.h>
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace Sortix {
|
||||
|
||||
class PS2Keyboard : public Keyboard
|
||||
{
|
||||
public:
|
||||
|
@ -66,6 +69,7 @@ namespace Sortix
|
|||
mutable kthread_mutex_t kblock;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Sortix
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue