better api 1(ioctl still no)
This commit is contained in:
parent
db97135880
commit
a3a2bb4cfe
@ -13,6 +13,6 @@ void serial_tty_init_i(NTTY* tty);
|
|||||||
void serial_tty_init_o(NTTY* tty);
|
void serial_tty_init_o(NTTY* tty);
|
||||||
int serial_tty_read(NTTY* tty, char* buf, int nr);
|
int serial_tty_read(NTTY* tty, char* buf, int nr);
|
||||||
void serial_tty_write(NTTY* tty, char ch);
|
void serial_tty_write(NTTY* tty, char ch);
|
||||||
void serial_tty_rcevbuf(NTTY* tty, char ch);
|
void serial_tty_recvbuf(NTTY* tty, u32 ch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -54,6 +54,9 @@ typedef struct n_tty
|
|||||||
int driver_type; // 1-vga&kbd; 2-serial
|
int driver_type; // 1-vga&kbd; 2-serial
|
||||||
void *input_buf;
|
void *input_buf;
|
||||||
void *output_buf;
|
void *output_buf;
|
||||||
|
void (*write)(struct n_tty *tty, char ch);
|
||||||
|
int (*read)(struct n_tty *tty, char* buf, int nr);
|
||||||
|
void (*recvbuf)(struct n_tty *tty, u32 ch);
|
||||||
} NTTY;
|
} NTTY;
|
||||||
|
|
||||||
enum CSI_state
|
enum CSI_state
|
||||||
@ -117,6 +120,7 @@ void vga_tty_select(NTTY *tty);
|
|||||||
|
|
||||||
void ps2_tty_init(NTTY *tty);
|
void ps2_tty_init(NTTY *tty);
|
||||||
int ps2_tty_read(NTTY *tty, char *buf, int nr);
|
int ps2_tty_read(NTTY *tty, char *buf, int nr);
|
||||||
|
void ps2_tty_recvbuf(NTTY *tty, u32 key);
|
||||||
|
|
||||||
#define CYCLE_SUB(head, tail, _max) ((head) <= (tail) ? (tail) - (head) : (tail) + (_max) - (head))
|
#define CYCLE_SUB(head, tail, _max) ((head) <= (tail) ? (tail) - (head) : (tail) + (_max) - (head))
|
||||||
#define NEXT(x, _max) (((x) + 1) % (_max))
|
#define NEXT(x, _max) (((x) + 1) % (_max))
|
||||||
|
|||||||
@ -33,7 +33,6 @@ static u8 mouse_data[MOUSE_IN_BYTES];
|
|||||||
static void set_leds();
|
static void set_leds();
|
||||||
static void set_mouse_leds();
|
static void set_mouse_leds();
|
||||||
static void kb_wait();
|
static void kb_wait();
|
||||||
static void ps2_push(NTTY *tty, u32 key);
|
|
||||||
static void kbd_process(unsigned char scode);
|
static void kbd_process(unsigned char scode);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -128,7 +127,7 @@ void mouse_handler(int irq)
|
|||||||
aux_state ^= (1 << i);
|
aux_state ^= (1 << i);
|
||||||
pack |= !!(aux_state & (1 << i)) ? MOUSEBTN_CLICK : MOUSEBTN_RELEASE;
|
pack |= !!(aux_state & (1 << i)) ? MOUSEBTN_CLICK : MOUSEBTN_RELEASE;
|
||||||
pack |= (1 << i);
|
pack |= (1 << i);
|
||||||
ps2_push(cur_ntty, pack);
|
cur_ntty->recvbuf(cur_ntty, pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pack = ISMOUSE | MOUSESCR;
|
pack = ISMOUSE | MOUSESCR;
|
||||||
@ -136,13 +135,13 @@ void mouse_handler(int irq)
|
|||||||
{
|
{
|
||||||
// actually it is 0x1
|
// actually it is 0x1
|
||||||
pack |= MOUSESCR_DOWN;
|
pack |= MOUSESCR_DOWN;
|
||||||
ps2_push(cur_ntty, pack);
|
cur_ntty->recvbuf(cur_ntty, pack);
|
||||||
}
|
}
|
||||||
else if ((signed char)mouse_data[3] < 0)
|
else if ((signed char)mouse_data[3] < 0)
|
||||||
{
|
{
|
||||||
// actually it is 0xff
|
// actually it is 0xff
|
||||||
pack |= MOUSESCR_UP;
|
pack |= MOUSESCR_UP;
|
||||||
ps2_push(cur_ntty, pack);
|
cur_ntty->recvbuf(cur_ntty, pack);
|
||||||
}
|
}
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
@ -154,7 +153,7 @@ void mouse_handler(int irq)
|
|||||||
pack |= MOUSEPOS_NEG;
|
pack |= MOUSEPOS_NEG;
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
pack |= MOUSEPOS_XY;
|
pack |= MOUSEPOS_XY;
|
||||||
ps2_push(cur_ntty, pack);
|
cur_ntty->recvbuf(cur_ntty, pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// kprintf("0x%02x 0x%02x 0x%02x 0x%02x\n", mouse_data[0], mouse_data[1], mouse_data[2], mouse_data[3]);
|
// kprintf("0x%02x 0x%02x 0x%02x 0x%02x\n", mouse_data[0], mouse_data[1], mouse_data[2], mouse_data[3]);
|
||||||
@ -365,7 +364,7 @@ static void kbd_process(unsigned char scode)
|
|||||||
|
|
||||||
// inputdriver_send_event(FALSE /*mouse*/, page, code, press, 0);
|
// inputdriver_send_event(FALSE /*mouse*/, page, code, press, 0);
|
||||||
if (press)
|
if (press)
|
||||||
ps2_push(cur_ntty, map_key(code));
|
cur_ntty->recvbuf(cur_ntty, map_key(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
kbd_state = 0;
|
kbd_state = 0;
|
||||||
@ -425,7 +424,7 @@ void ps2_tty_flush(NTTY *tty)
|
|||||||
enable_int();
|
enable_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ps2_push(NTTY *tty, u32 key)
|
void ps2_tty_recvbuf(NTTY *tty, u32 key)
|
||||||
{
|
{
|
||||||
// kprintf("%x\n", key);
|
// kprintf("%x\n", key);
|
||||||
disable_int();
|
disable_int();
|
||||||
@ -483,7 +482,7 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
{
|
{
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n': // escape ENTER
|
case '\n': // escape ENTER
|
||||||
vga_tty_write(tty, '\n');
|
tty->write(tty, '\n');
|
||||||
buf[kbd->tail] = '\n';
|
buf[kbd->tail] = '\n';
|
||||||
kbd->len++;
|
kbd->len++;
|
||||||
kbd->tail = NEXTKEY(kbd->tail);
|
kbd->tail = NEXTKEY(kbd->tail);
|
||||||
@ -493,7 +492,10 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
case '\b':
|
case '\b':
|
||||||
if (kbd->len > kbd->readable)
|
if (kbd->len > kbd->readable)
|
||||||
{
|
{
|
||||||
vga_tty_backspace(tty);
|
// vga_tty_backspace(tty);
|
||||||
|
tty->write(tty, '\b');
|
||||||
|
tty->write(tty, ' ');
|
||||||
|
tty->write(tty, '\b');
|
||||||
kbd->len--;
|
kbd->len--;
|
||||||
kbd->tail = LASTKEY(kbd->tail);
|
kbd->tail = LASTKEY(kbd->tail);
|
||||||
}
|
}
|
||||||
@ -504,7 +506,7 @@ static void ps2_push(NTTY *tty, u32 key)
|
|||||||
return;
|
return;
|
||||||
if (kbd->len == TTY_IN_BYTES - 1)
|
if (kbd->len == TTY_IN_BYTES - 1)
|
||||||
return; // leave one space for ctrl ascii
|
return; // leave one space for ctrl ascii
|
||||||
vga_tty_write(tty, key);
|
tty->write(tty, key);
|
||||||
buf[kbd->tail] = (u8)(key & 0xff);
|
buf[kbd->tail] = (u8)(key & 0xff);
|
||||||
// kprintf("%d %d %d", key & 0xff, kbd->tail, buf[kbd->tail]);
|
// kprintf("%d %d %d", key & 0xff, kbd->tail, buf[kbd->tail]);
|
||||||
kbd->len++;
|
kbd->len++;
|
||||||
|
|||||||
@ -46,7 +46,7 @@ static void serial_buf_push(NTTY* tty, u32 key) {
|
|||||||
sp->len++;
|
sp->len++;
|
||||||
sp->tail = NEXTKEY(sp->tail);
|
sp->tail = NEXTKEY(sp->tail);
|
||||||
sp->readable = CYCLE_SUB(sp->head, sp->tail, SERIAL_BUF_SIZE);
|
sp->readable = CYCLE_SUB(sp->head, sp->tail, SERIAL_BUF_SIZE);
|
||||||
serial_tty_rcevbuf(tty, '\n');
|
tty->recvbuf(tty, '\n');
|
||||||
break;
|
break;
|
||||||
case '\b': case 127:
|
case '\b': case 127:
|
||||||
key = '\b';
|
key = '\b';
|
||||||
@ -54,9 +54,9 @@ static void serial_buf_push(NTTY* tty, u32 key) {
|
|||||||
{
|
{
|
||||||
sp->len--;
|
sp->len--;
|
||||||
sp->tail = LASTKEY(sp->tail);
|
sp->tail = LASTKEY(sp->tail);
|
||||||
serial_tty_rcevbuf(tty, '\b');
|
tty->recvbuf(tty, '\b');
|
||||||
serial_tty_rcevbuf(tty, ' ');
|
tty->recvbuf(tty, ' ');
|
||||||
serial_tty_rcevbuf(tty, '\b');
|
tty->recvbuf(tty, '\b');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ static void serial_buf_push(NTTY* tty, u32 key) {
|
|||||||
buf[sp->tail] = (u8)(key & 0xff);
|
buf[sp->tail] = (u8)(key & 0xff);
|
||||||
sp->len++;
|
sp->len++;
|
||||||
sp->tail = NEXTKEY(sp->tail);
|
sp->tail = NEXTKEY(sp->tail);
|
||||||
serial_tty_rcevbuf(tty, key & 0xff);
|
tty->recvbuf(tty, key & 0xff);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,8 +102,8 @@ void serial_tty_write(NTTY* tty, char ch) {
|
|||||||
write_serial(ch);
|
write_serial(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_tty_rcevbuf(NTTY* tty, char ch) {
|
void serial_tty_recvbuf(NTTY* tty, u32 ch) {
|
||||||
serial_tty_write(tty, ch);
|
tty->write(tty, ch & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_serial() {
|
int init_serial() {
|
||||||
|
|||||||
28
kernel/tty.c
28
kernel/tty.c
@ -46,17 +46,23 @@ void init_tty_main()
|
|||||||
tty->output_buf = (vga_buf*)K_PHY2LIN(do_kmalloc(sizeof(vga_buf)));
|
tty->output_buf = (vga_buf*)K_PHY2LIN(do_kmalloc(sizeof(vga_buf)));
|
||||||
vga_tty_init(tty);
|
vga_tty_init(tty);
|
||||||
ps2_tty_init(tty);
|
ps2_tty_init(tty);
|
||||||
|
tty->write = vga_tty_write;
|
||||||
|
tty->read = ps2_tty_read;
|
||||||
|
tty->recvbuf = ps2_tty_recvbuf;
|
||||||
ntty_table[i] = tty;
|
ntty_table[i] = tty;
|
||||||
// kprintf("tty: %p, outbuf: %p\n", tty, tty->output_buf);
|
|
||||||
}
|
}
|
||||||
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
for (int i = 2; i < 3; ++ i) {
|
||||||
tty->driver_type = 2;
|
tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY)));
|
||||||
tty->input_buf = (serial_buf*)K_PHY2LIN(do_kmalloc(sizeof(serial_buf)));
|
tty->driver_type = 2;
|
||||||
// kprintf("tty: %p, outbuf: %p\n", tty, tty->input_buf);
|
tty->input_buf = (serial_buf*)K_PHY2LIN(do_kmalloc(sizeof(serial_buf)));
|
||||||
tty->output_buf = NULL;
|
tty->output_buf = NULL;
|
||||||
serial_tty_init_i(tty);
|
serial_tty_init_i(tty);
|
||||||
serial_tty_init_o(tty);
|
serial_tty_init_o(tty);
|
||||||
ntty_table[2] = tty;
|
tty->write = serial_tty_write;
|
||||||
|
tty->read = serial_tty_read;
|
||||||
|
tty->recvbuf = serial_tty_recvbuf;
|
||||||
|
ntty_table[2] = tty;
|
||||||
|
}
|
||||||
cur_ntty = ntty_table[0];
|
cur_ntty = ntty_table[0];
|
||||||
tty_ok = 1;
|
tty_ok = 1;
|
||||||
kprintf("TTY initialized\n");
|
kprintf("TTY initialized\n");
|
||||||
@ -72,7 +78,7 @@ void task_tty()
|
|||||||
volatile char serial_input;
|
volatile char serial_input;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
// sys_yield();
|
yield();
|
||||||
// vga_tty_flush(cur_ntty);
|
// vga_tty_flush(cur_ntty);
|
||||||
// serial_input = read_serial();
|
// serial_input = read_serial();
|
||||||
// vga_tty_write(get_tty(2), serial_input);
|
// vga_tty_write(get_tty(2), serial_input);
|
||||||
@ -119,5 +125,5 @@ void tty_write(NTTY *tty, char *buf, int len)
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int tty_read(NTTY *tty, char *buf, int len)
|
int tty_read(NTTY *tty, char *buf, int len)
|
||||||
{
|
{
|
||||||
return ps2_tty_read(tty, buf, len);
|
return tty->read(tty, buf, len);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user