davidcallanan / os-series

818 stars 119 forks source link

Adding a keyboard? #14

Open dennorak opened 3 years ago

dennorak commented 3 years ago

I tried copying a fork of this repo here to add keyboard support, but I still can't type. I cleaned it up a bit, but I don't think I'm reading the PS/2 controller correctly. Any help?

Toni-d-e-v commented 3 years ago

I am getting an error

Toni-d-e-v commented 3 years ago

Makefile:26: recipe for target 'build-x86_64' failed make: *** [build-x86_64] Error 1

Toni-d-e-v commented 3 years ago

multiple definition of `keys'; build/kernel/main.o:(.data+0x0): first defined here

Toni-d-e-v commented 3 years ago

I tried copying a fork of this repo here to add keyboard support, but I still can't type. I cleaned it up a bit, but I don't think I'm reading the PS/2 controller correctly. Any help?

Fixed a little keyboatf but now I cant type too its because of loop I think

dennorak commented 3 years ago

For the 'multiple definition of keys' error, you have to change the variable name each time. I don't know why this is, but it fixed the problem for me.

Toni-d-e-v commented 3 years ago

For the 'multiple definition of keys' error, you have to change the variable name each time. I don't know why this is, but it fixed the problem for me.

yeah but still I cant type sadly, I wrote some driver cant test it sadly

dennorak commented 3 years ago

@Toni-d-e-v I'm about to clean up the code a bit and push it to a repo, if you want me to add you to it we can try and get this thing working

dennorak commented 3 years ago

also, the problem that I'm having is it's not able to read the input at all; I tried printing straight from memory, and every time it outputs a blank character. Maybe qemu isn't properly passing through the keyboard? or maybe it has to be PS/2?

Toni-d-e-v commented 3 years ago

also, the problem that I'm having is it's not able to read the input at all; I tried printing straight from memory, and every time it outputs a blank character. Maybe qemu isn't properly passing through the keyboard? or maybe it has to be PS/2?

Yeah sure add me

Cat22 commented 3 years ago

I believe you are reading scan codes so you need to handle key-down and key-release. just print out the hex codes as you press and release a key and watch what shows up.

Roseinabox28 commented 3 years ago

take a look at this

Roseinabox28 commented 3 years ago

I went and started implementing this

rualark commented 3 years ago

I went and started implementing this

Thank you so much for your inspiration! It is interesting that input can be implemented without interrupts. I tried to improve input code:

I also implemented precise nanosleep and added beep.

https://github.com/rualark/SimpleOsDemo

Kjur0 commented 3 years ago

I found a better way of solving this problem. I downloaded all of the C libraries (e.g. stdio.h) and included them in my kernel :) It worked, but my kernel is now very heavy and I don't think that was worth it. Because there are better ways.

rualark commented 3 years ago

I found a better way of solving this problem. I downloaded all of the C libraries (e.g. stdio.h) and included them in my kernel :) It worked, but my kernel is now very heavy and I don't think that was worth it. Because there are better ways.

Wow! A nice solution. Can you publish a full working kernel with libraries included?

dennorak commented 2 years ago

@Kjur0 can you post a link to this? I've been trying to figure out how to implement glibc, but to no avail.

M1sterPl0w commented 2 years ago

Shouldn't you use interrupts instead of a "sleep"function?

rualark commented 2 years ago

Shouldn't you use interrupts instead of a "sleep"function?

That is true, using interrupts is usually a more scalable way, but in this case I was looking for the most simple solution.

LarsThePenguin commented 2 years ago

I have a working keyboard driver Heres my main.c file: #include "print.h" unsigned char port_byte_in(uint16_t port) { unsigned char result; asm("in %%dx, %%al" : "=a" (result) : "d" (port)); return result; } char* print_letter(uint8_t scancode) { switch (scancode) { case 0x0: return "ERROR"; break; case 0x1: return "ESC"; break; case 0x2: return "1"; break; case 0x3: return "2"; break; case 0x4: return "3"; break; case 0x5: return "4"; break; case 0x6: return "5"; break; case 0x7: return "6"; break; case 0x8: return "7"; break; case 0x9: return "8"; break; case 0x0A: return "9"; break; case 0x0B: return "0"; break; case 0x0C: return "-"; break; case 0x0D: return "+"; break; case 0x0E: return "\033"; break; case 0x0F: return "Tab"; break; case 0x10: return "Q"; break; case 0x11: return "W"; break; case 0x12: return "E"; break; case 0x13: return "R"; break; case 0x14: return "T"; break; case 0x15: return "Y"; break; case 0x16: return "U"; break; case 0x17: return "I"; break; case 0x18: return "O"; break; case 0x19: return "P"; break; case 0x1A: return "["; break; case 0x1B: return "]"; break; case 0x1C: return "\n"; break; case 0x1D: return "LCtrl"; break; case 0x1E: return "A"; break; case 0x1F: return "S"; break; case 0x20: return "D"; break; case 0x21: return "F"; break; case 0x22: return "G"; break; case 0x23: return "H"; break; case 0x24: return "J"; break; case 0x25: return "K"; break; case 0x26: return "L"; break; case 0x27: return ";"; break; case 0x28: return "'"; break; case 0x29: return ""; break; case 0x2A: return "LShift"; break; case 0x2B: return "\"; break; case 0x2C: return "Z"; break; case 0x2D: return "X"; break; case 0x2E: return "C"; break; case 0x2F: return "V"; break; case 0x30: return "B"; break; case 0x31: return "N"; break; case 0x32: return "M"; break; case 0x33: return ","; break; case 0x34: return "."; break; case 0x35: return "/"; break; case 0x36: return "Rshift"; break; case 0x37: return "Keypad "; break; case 0x38: return "LAlt"; break; case 0x39: return " "; break; default: return ""; } } static char keyboard_callback() { uint8_t scancode = port_byte_in(0x60); return print_letter(scancode); } void kernel_main() { print_clear(); print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK); print("Welcome to Antartic Operating System!\n"); char keyPrev = ""; while (1) { char key = keyboard_callback(); if (key != keyPrev) { print(key); } keyPrev = key; } }`

Gaming-With-Portals commented 2 years ago

I found a better way of solving this problem. I downloaded all of the C libraries (e.g. stdio.h) and included them in my kernel :) It worked, but my kernel is now very heavy and I don't think that was worth it. Because there are better ways.

Wow! A nice solution. Can you publish a full working kernel with libraries included?

Ill update you guys if I figure this out but all the standered C libs are in my install of Unreal Engine, so Im gonna try and implement them and see what happens, if anything does happen ill let yall know