Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::drivers::peripherals::KeyboardDriver Class Reference

Driver for the Keyboard Controller, manages the events and the keyboard state. More...

#include <keyboard.h>

Inheritance diagram for MaxOS::drivers::peripherals::KeyboardDriver:
MaxOS::hardwarecommunication::InterruptHandler MaxOS::drivers::Driver MaxOS::common::GenericInputStream< uint8_t >

Public Member Functions

 KeyboardDriver ()
 Construct a new Keyboard Driver object, registering it as an interrupt handler for interrupt 0x21.
 
void handle_interrupt () final
 deactivate the keyboard driver
 
void activate () final
 activate the keyboard driver
 
string device_name () final
 Get the device name.
 
- Public Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
virtual system::cpu_status_thandle_interrupt (system::cpu_status_t *status)
 Handles an interrupt and returns the status.
 
- Public Member Functions inherited from MaxOS::drivers::Driver
virtual void deactivate ()
 Deactivate the driver.
 
virtual void initialise ()
 Initialise the driver.
 
virtual uint32_t reset ()
 Reset the driver.
 
virtual string vendor_name ()
 Get who created the device.
 
- Public Member Functions inherited from MaxOS::common::GenericInputStream< uint8_t >
 GenericInputStream ()
 Creates a new GenericInputStream.
 
 GenericInputStream (InputStreamEventHandler< uint8_t > *)
 Creates a new GenericInputStream and connects it to the handler.
 
 ~GenericInputStream ()
 Destroys the GenericInputStream and disconnects all handlers.
 
void connect_input_stream_event_handler (InputStreamEventHandler< uint8_t > *)
 Adds a inputStreamEventHandler to the list of internetProtocolHandlers.
 
void disconnect_input_stream_event_handler (InputStreamEventHandler< uint8_t > *)
 Removes a handler from the list of handlers.
 

Additional Inherited Members

- Protected Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
 InterruptHandler (uint8_t interrupt_number, int64_t redirect=-1, uint64_t redirect_index=0)
 Creates a new interrupt handler and registers it with the interrupt manager.
 
 ~InterruptHandler ()
 Destroys the interrupt handler and unregisters it from the interrupt manager.
 
- Protected Attributes inherited from MaxOS::hardwarecommunication::InterruptHandler
uint8_t m_interrupt_number
 The interrupt number this handler handles.
 
- Protected Attributes inherited from MaxOS::common::GenericInputStream< uint8_t >
common::Vector< InputStreamEventHandler< uint8_t > * > m_input_stream_event_handlers
 List of streams being observed by this handler.
 

Detailed Description

Driver for the Keyboard Controller, manages the events and the keyboard state.

Definition at line 446 of file keyboard.h.

Constructor & Destructor Documentation

◆ KeyboardDriver()

KeyboardDriver::KeyboardDriver ( )

Construct a new Keyboard Driver object, registering it as an interrupt handler for interrupt 0x21.

Definition at line 67 of file keyboard.cpp.

68: InterruptHandler(0x21, 0x1, 0x12),
69 m_data_port(0x60),
70 m_command_port(0x64)
71{
72
73
74}
Handles a certain interrupt number.
Definition interrupts.h:30

Member Function Documentation

◆ activate()

void KeyboardDriver::activate ( )
finalvirtual

activate the keyboard driver

Reimplemented from MaxOS::drivers::Driver.

Definition at line 81 of file keyboard.cpp.

81 {
82
83 // Wait for user to stop pressing key (this is for the start-up key e.g. hold 'F12' for boot menu or hold 'del' for bios )
84 while (m_command_port.read() & 0x1)
85 m_data_port.read();
86
87 // Enable keyboard interrupts
88 m_command_port.write(0xAE);
89
90 // Get the current state of the keyboard
91 m_command_port.write(0x20);
92 uint8_t status = (m_data_port.read() | 1) & ~0x10;
93
94 // Reset the keyboard
95 m_command_port.write(0x60);
96 m_data_port.write(status);
97
98 // Activate the keyboard
99 m_data_port.write(0xF4);
100}
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
virtual uint8_t read()
read a byte from the port
Definition port.cpp:51
virtual void write(uint8_t data)
write a byte to the port
Definition port.cpp:41

References MaxOS::hardwarecommunication::Port8Bit::read(), and MaxOS::hardwarecommunication::Port8Bit::write().

◆ device_name()

string KeyboardDriver::device_name ( )
finalvirtual

Get the device name.

Returns
The device name

Reimplemented from MaxOS::drivers::Driver.

Definition at line 117 of file keyboard.cpp.

117 {
118 return "Keyboard";
119}

◆ handle_interrupt()

void KeyboardDriver::handle_interrupt ( )
finalvirtual

deactivate the keyboard driver

Reimplemented from MaxOS::hardwarecommunication::InterruptHandler.

Definition at line 105 of file keyboard.cpp.

105 {
106
107 // Pass the scan code to the m_handlers
108 uint8_t key = m_data_port.read();
110 handler->on_stream_read(key);
111}
common::Vector< InputStreamEventHandler< uint8_t > * > m_input_stream_event_handlers
List of streams being observed by this handler.

References MaxOS::common::GenericInputStream< uint8_t >::m_input_stream_event_handlers, and MaxOS::hardwarecommunication::Port8Bit::read().


The documentation for this class was generated from the following files: