mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2025-06-06 00:41:28 -07:00
adding stub usb and mouse code
This commit is contained in:
parent
49361a98be
commit
69762b6650
@ -49,3 +49,6 @@ git clone https://github.com/gbowne1/ClassicOS.git
|
|||||||
cd ClassicOS
|
cd ClassicOS
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
build kernel
|
||||||
|
for %f in (*.c) do gcc -m32 -O0 -Wall -Wextra -Werror -pedantic -ffreestanding -nostdlib -fno-pic -fno-stack-protector -fno-pie -march=i386 -mtune=i386 -c "%f" -o "%f.o"
|
||||||
|
66
kernel/mouse.c
Normal file
66
kernel/mouse.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "mouse.h"
|
||||||
|
#include "usb.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// Struct to store mouse state
|
||||||
|
typedef struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
bool left_button;
|
||||||
|
bool right_button;
|
||||||
|
} mouse_data_t;
|
||||||
|
|
||||||
|
// Mouse buffer
|
||||||
|
static mouse_data_t mouse_data;
|
||||||
|
|
||||||
|
// Initialize USB Mouse (1.x & HID 1.0-1.11)
|
||||||
|
bool usb_mouse_init(void) {
|
||||||
|
if (!usb_init()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usb_hid_init()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usb_enumerate_devices()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect if a USB mouse is connected
|
||||||
|
bool usb_mouse_detected(void) {
|
||||||
|
return usb_hid_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if USB mouse data has been received
|
||||||
|
bool usb_mouse_received(void) {
|
||||||
|
return usb_interrupt_transfer(/* parameters */);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read USB mouse data
|
||||||
|
mouse_data_t usb_read_mouse(void) {
|
||||||
|
uint8_t buffer[3]; // USB HID Mouse reports typically use 3 bytes
|
||||||
|
if (usb_interrupt_transfer(/* parameters */)) {
|
||||||
|
// Process the received data
|
||||||
|
mouse_data.x += buffer[1]; // X movement
|
||||||
|
mouse_data.y += buffer[2]; // Y movement
|
||||||
|
mouse_data.left_button = buffer[0] & 0x01;
|
||||||
|
mouse_data.right_button = buffer[0] & 0x02;
|
||||||
|
}
|
||||||
|
return mouse_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// USB Host Controller Initialization (for USB 1.x)
|
||||||
|
bool uhci_init(void) {
|
||||||
|
// Initialize UHCI controller for legacy USB support
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ohci_init(void) {
|
||||||
|
// Initialize OHCI controller for USB 1.x
|
||||||
|
return true;
|
||||||
|
}
|
25
kernel/mouse.h
Normal file
25
kernel/mouse.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef MOUSE_H
|
||||||
|
#define MOUSE_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// Mouse data structure
|
||||||
|
typedef struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
bool left_button;
|
||||||
|
bool right_button;
|
||||||
|
} mouse_data_t;
|
||||||
|
|
||||||
|
// Function declarations for USB 1.x HID mouse support
|
||||||
|
bool usb_mouse_init(void);
|
||||||
|
bool usb_mouse_detected(void);
|
||||||
|
bool usb_mouse_received(void);
|
||||||
|
mouse_data_t usb_read_mouse(void);
|
||||||
|
|
||||||
|
// USB Host Controller Interface functions (USB 1.x support)
|
||||||
|
bool uhci_init(void);
|
||||||
|
bool ohci_init(void);
|
||||||
|
|
||||||
|
#endif // MOUSE_H
|
64
kernel/usb.c
Normal file
64
kernel/usb.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "usb.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// USB version detection
|
||||||
|
bool usb_detect_version(uint16_t *version) {
|
||||||
|
if (!version) return false;
|
||||||
|
*version = 0x0110; // Example: USB 1.1
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// USB initialization for 1.x
|
||||||
|
bool usb_init(void) {
|
||||||
|
// Detect controller type (UHCI or OHCI)
|
||||||
|
bool uhci_supported = uhci_init();
|
||||||
|
bool ohci_supported = ohci_init();
|
||||||
|
|
||||||
|
if (!uhci_supported && !ohci_supported) {
|
||||||
|
return false; // No supported controllers found
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// USB device enumeration (1.x)
|
||||||
|
bool usb_enumerate_devices(void) {
|
||||||
|
// Implementation for detecting devices on USB 1.x ports
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HID initialization for USB 1.x
|
||||||
|
bool usb_hid_init(void) {
|
||||||
|
// Ensure USB is initialized
|
||||||
|
if (!usb_init()) return false;
|
||||||
|
|
||||||
|
return usb_enumerate_devices();
|
||||||
|
}
|
||||||
|
|
||||||
|
// USB transfers (stubs for 1.x)
|
||||||
|
bool usb_control_transfer(/* parameters */) {
|
||||||
|
// Implement control transfer for USB 1.x
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool usb_interrupt_transfer(/* parameters */) {
|
||||||
|
// Implement interrupt transfer for USB 1.x
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool usb_bulk_transfer(/* parameters */) {
|
||||||
|
// Implement bulk transfer for USB 1.x
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// USB host controller initialization (UHCI & OHCI)
|
||||||
|
bool uhci_init(void) {
|
||||||
|
// Initialize UHCI controller (USB 1.x)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ohci_init(void) {
|
||||||
|
// Initialize OHCI controller (USB 1.x)
|
||||||
|
return true;
|
||||||
|
}
|
24
kernel/usb.h
Normal file
24
kernel/usb.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef USB_H
|
||||||
|
#define USB_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// USB initialization and management functions
|
||||||
|
bool usb_init(void);
|
||||||
|
bool usb_detect_version(uint16_t *version);
|
||||||
|
bool usb_enumerate_devices(void);
|
||||||
|
|
||||||
|
// HID-specific functions
|
||||||
|
bool usb_hid_init(void);
|
||||||
|
|
||||||
|
// USB transfer functions
|
||||||
|
bool usb_control_transfer(/* parameters */);
|
||||||
|
bool usb_interrupt_transfer(/* parameters */);
|
||||||
|
bool usb_bulk_transfer(/* parameters */);
|
||||||
|
|
||||||
|
// USB host controller initialization (USB 1.x only)
|
||||||
|
bool uhci_init(void); // UHCI support
|
||||||
|
bool ohci_init(void); // OHCI support
|
||||||
|
|
||||||
|
#endif // USB_H
|
Loading…
x
Reference in New Issue
Block a user