1
0
Fork 0
forked from AbleOS/ableos

Mouse driver finished for 3 button mice.

This commit is contained in:
peony 2024-11-03 23:04:10 +01:00
parent e670a0ef53
commit f31d35703d
5 changed files with 90 additions and 94 deletions

14
Cargo.lock generated
View file

@ -97,9 +97,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cc"
version = "1.1.31"
version = "1.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f"
checksum = "67b9470d453346108f93a59222a9a1a5724db32d0a4727b7ab7ace4b4d822dc9"
dependencies = [
"shlex",
]
@ -253,12 +253,12 @@ dependencies = [
[[package]]
name = "hbbytecode"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#38a00cbaa09434324d209fc5f59480d2b6743fb3"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#44fc9c3e2e0aa32b92a4a9a20e4eadbf354d7b6c"
[[package]]
name = "hblang"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#38a00cbaa09434324d209fc5f59480d2b6743fb3"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#44fc9c3e2e0aa32b92a4a9a20e4eadbf354d7b6c"
dependencies = [
"hashbrown 0.15.0",
"hbbytecode",
@ -270,7 +270,7 @@ dependencies = [
[[package]]
name = "hbvm"
version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#38a00cbaa09434324d209fc5f59480d2b6743fb3"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#44fc9c3e2e0aa32b92a4a9a20e4eadbf354d7b6c"
dependencies = [
"hbbytecode",
]
@ -677,9 +677,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.86"
version = "2.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e89275301d38033efb81a6e60e3497e734dfcc62571f2854bf4b16690398824c"
checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d"
dependencies = [
"proc-macro2",
"quote",

View file

@ -409,8 +409,8 @@ fn run(release: bool, target: Target, do_accel: bool) -> Result<(), Error> {
"-machine", accel,
"-cpu", "max",
"-serial", "stdio",
"-d", "trace:ps2_mouse_send_packet",
//"-d", "trace:ps2_mouse_event_disabled",
//"-d", "trace:ps2_mouse_send_packet",
"-d", "trace:ps2_mouse_event_disabled",
"-audiodev", "pa,id=speaker",
"-machine", "pcspk-audiodev=speaker",
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04",

View file

@ -60,9 +60,9 @@ init := fn(doublebuffer: bool): ?Surface {
if errlevel > 0 return null
if doublebuffer {
return new_surface(width, height)
return new_surface(@unwrap(width), @unwrap(height))
} else {
return .(framebuffer, width, height)
return .(@unwrap(framebuffer), @unwrap(width), @unwrap(height))
}
}

View file

@ -1,7 +1,24 @@
.{memory, buffer, log, string} := @use("../../../libraries/stn/src/lib.hb")
render := @use("../../../libraries/render/src/lib.hb")
.{memory, buffer, log, string, math} := @use("../../../libraries/stn/src/lib.hb")
Vec2 := math.Vec2
ACK := 250
i9 := packed struct {sign: bool, value: u8}
Button := struct {id: u8}
LeftButton := Button.(1)
RightButton := Button.(2)
MiddleButton := Button.(4)
Button4 := Button.(8)
Button5 := Button.(16)
mouse_moved := fn(delta: Vec2(i9)): void {
log.info("Mouse movement.\0")
}
button_event := fn(button: Button, pressed: bool): void {
if pressed {
log.info("Mouse-button pressed.\0")
} else {
log.info("Mouse-button released.\0")
}
}
send_byte := fn(target: u8, data: u8): void {
loop if (memory.inb(0x64) & 2) == 0 break
@ -11,13 +28,19 @@ send_byte := fn(target: u8, data: u8): void {
reset_mouse := fn(): void {
@inline(send_byte, 0x64, 0xD4)
@inline(send_byte, 0x60, 0xFF)
loop if memory.inb(0x60) == 0xAA return
loop if memory.inb(0x60) == 0xAA {
log.info("Self check passed.\0")
return
}
}
send_command_byte := fn(byte: u8): void {
@inline(send_byte, 0x64, 0xD4)
@inline(send_byte, 0x60, byte)
loop if memory.inb(0x60) == 0xFA return
loop if memory.inb(0x60) == 0xFA {
log.info("ACK\0")
return
}
}
set_defaults := fn(): void @inline(send_command_byte, 0xF6)
@ -32,7 +55,9 @@ set_stream_mode := fn(): void @inline(send_command_byte, 0xEA)
set_non_linear_scaling := fn(): void @inline(send_command_byte, 0xE7)
set_linear_scaling := fn(): void @inline(send_command_byte, 0xE6)
SampleRate := struct { value: u8 }
resend_packet := fn(): void @inline(send_command_byte, 0xFE)
SampleRate := struct {value: u8}
sr10 := SampleRate.(10)
sr20 := SampleRate.(20)
sr40 := SampleRate.(40)
@ -46,9 +71,9 @@ set_sample_rate := fn(sample_rate: SampleRate): void {
@inline(send_command_byte, sample_rate.value)
}
Resolution := struct { value: u8 }
Resolution := struct {value: u8}
res_1count_per_mm := Resolution.(0)
res_2count_per_mm := Resolution.(01)
res_2count_per_mm := Resolution.(1)
res_4count_per_mm := Resolution.(2)
res_8count_per_mm := Resolution.(3)
@ -57,91 +82,62 @@ set_resolution := fn(resolution: Resolution): void {
@inline(send_command_byte, resolution.value)
}
wait_for := fn(for: u8): void {
log.info("Start waiting\0")
loop {
if (memory.inb(0x64) & 2 >> for) == for {
log.info("End waiting\0")
return
}
}
}
send_info := fn(info: u8): void {
wait_for(1)
memory.outb(0x64, info)
}
send_command := fn(command: u8): void {
send_info(0xD4)
wait_for(1)
memory.outb(0x60, command)
}
get_response := fn(): u8 {
wait_for(1)
return memory.inb(0x60)
}
button_states := @as(u8, 0)
main := fn(): int {
// screen := render.init(true)
format_page := memory.alloc(u8, 1024)
wait_for(0)
memory.outb(0x64, 0xA8)
send_byte(0x64, 0xA8)
log.info("Aux mouse device enabled.\0")
send_command(0xF6)
a := get_response()
reset_mouse()
set_defaults()
enable_streaming()
send_command(0xF4)
b := get_response()
x := @as(int, 0)
y := @as(int, 0)
x := @as(i16, 0)
y := @as(i16, 0)
loop {
// render.clear(screen, render.black)
loop {
if (memory.inb(0x64) & 0x20) == 0x20 {
log.info("Yeah\0")
break
}
}
loop if (memory.inb(0x64) & 0x20) == 0x20 break
status := memory.inb(0x60)
if status == 0xAA {
loop if memory.inb(0x60) == 0 break
log.info("Mouse plugged in!\0")
reset_mouse()
set_defaults()
enable_streaming()
continue
}
changes := button_states ^ status & 7
if (changes & LeftButton.id) != 0 {
button_event(LeftButton, (status & LeftButton.id) != 0)
}
if (changes & RightButton.id) != 0 {
button_event(RightButton, (status & RightButton.id) != 0)
}
if (changes & MiddleButton.id) != 0 {
button_event(MiddleButton, (status & MiddleButton.id) != 0)
}
button_states ^= changes
log.info(string.display_int(status, format_page, 10))
d_x := @as(i32, @bitcast(@as(u32, @intcast(memory.inb(0x60)))))
if (status & 0x10) > 0 {
d_x = d_x | 0xFFFFFF00
}
x = x + d_x
if x < 0 {
x = 0
}
log.info(string.display_int(d_x, format_page, 10))
d_y := @as(i32, @bitcast(@as(u32, @intcast(memory.inb(0x60)))))
if (status & 0x20) > 0 {
d_y = d_y | 0xFFFFFF00
dx := i9.(false, 0)
dy := i9.(false, 0)
dx.value = memory.inb(0x60)
dx.sign = (status & 0x10) > 0
dy.value = memory.inb(0x60) ^ 0xFF
dy.sign = (status & 0x20) == 0
if dy.value != 0 & dx.value != 0 {
mouse_moved(.(dx, dy))
}
y = y + d_y
if y < 0 {
y = 0
}
log.info(string.display_int(d_y, format_page, 10))
// render.put_rect(screen, .(x, y), .(x + 10, y + 10), render.white)
log.info("XY\0")
log.info(string.display_int(x, format_page, 10))
log.info(string.display_int(y, format_page, 10))
}
return 0

View file

@ -3,8 +3,8 @@
default_entry = 1
timeout = 0
verbose = false
# interface_resolution = "1600x900x24"
interface_resolution = "640x480x32"
interface_resolution = "1600x900x24"
# interface_resolution = "640x480x32"
# Terminal related settings
# term_wallpaper = "boot:///background.bmp"
term_wallpaper = "boot:///empty-background.bmp"
@ -15,8 +15,8 @@ comment = "Default AbleOS boot entry."
protocol = "limine"
kernel_path = "boot:///kernel_${ARCH}"
kernel_cmdline = ""
resolution = "640x480x32"
# resolution = "1600x900x24"
# resolution = "640x480x32"
resolution = "1600x900x24"
[boot.limine.ableos.modules]