A project to implement a console using the Mbed using VGA for video output and a PS/2 keyboard for the input. The eventual goal is to also include tools for managing SD cards, and a semi-self-hosting programming environment.

Dependencies:   PS2_MbedConsole fastlib SDFileSystem vga640x480g_mbedconsole lightvm mbed

MbedConsole is a cool little project to have a self-contained computer all on an Mbed. So far it has VGA and PS/2 support and can stand alone without a computer powering it. Next planned features are SD card support and a lightweight programmable VM complete with a file editor and self-hosted assembler.

You can view additional details about it at http://earlz.net/tags/mbedconsole

Files at this revision

API Documentation at this revision

Comitter:
earlz
Date:
Fri Sep 28 04:35:00 2012 +0000
Parent:
11:fede136943a9
Child:
13:442bd2fb4ea0
Commit message:
Converted to completely use PS/2 keyboard for console; Also added a couple of commands

Changed in this revision

keyboard.cpp Show annotated file Show diff for this revision Revisions of this file
keyboard.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
shell.cpp Show annotated file Show diff for this revision Revisions of this file
textio.cpp Show annotated file Show diff for this revision Revisions of this file
vga640x480g.lib Show annotated file Show diff for this revision Revisions of this file
--- a/keyboard.cpp	Fri Sep 28 04:03:54 2012 +0000
+++ b/keyboard.cpp	Fri Sep 28 04:35:00 2012 +0000
@@ -1,41 +1,8 @@
 #include "mbedconsole.h"
+#include "keyboard.h"
 /**This is basically a straight rip off of my x86 OS project AlloyOS. I just ported the keyboard driver from it cause it always treated me well**/
 
 
-#define KEYBOARD_DATAPIN p11
-#define KEYBOARD_CLOCKPIN p12
-
-//how many keys the buffer can hold
-#define KBD_BUFFER_SIZE 128 
-
-//key defines
-#define LSHIFT_KEY 0x12
-#define RSHIFT_KEY 0x59
-
-#define CTRL_KEY 0xF3
-#define ALT_KEY 0xF4
-#define CAPS_KEY 0x58
-#define NUM_KEY 0x77
-#define SCROLL_KEY 0xF7
-//#define F_BASE_KEY 0xFF //59 is F1, 60 is F2, and so on until F10
-#define HOME_KEY 0xFF
-#define UP_KEY 0xFF
-#define PAGE_UP_KEY 0xFF
-#define LEFT_KEY 0xFF
-#define RIGHT_KEY 0xFF
-#define END_KEY 0xFF
-#define DOWN_KEY 0xFF
-#define PAGE_DOWN_KEY 0xFF
-#define INSERT_KEY 0xFF
-#define DEL_KEY 0xFF
-#define F11_KEY 0xFF
-#define F12_KEY 0xFF
-
-#define SCROLL_LED 1
-#define NUM_LED 2
-#define CAPS_LED 4
-
-
 const char kbdus[0x84] =
 {
     0, 
@@ -189,26 +156,6 @@
     0, //83 F7
 };
 
-
-typedef struct {
-    unsigned char caps;
-    unsigned char shift;
-    unsigned char scroll;
-    unsigned char num;
-    unsigned char ctrl;
-    unsigned char alt;
-}
-shift_locks; /*for simplicity and speed*/
-
-extern volatile shift_locks kbd_shifts;
-
-
-typedef struct {
-    uint16_t scancode;
-    uint8_t asci;
-}kbd_key;
-
-
 PS2KB_INIT *ps2_kb_init;
 PS2KB *ps2_kb;
 
@@ -218,8 +165,6 @@
 volatile char pending_key=0;
 volatile uint8_t led_status=0;
 
-void keyboard_callback(PS2KB kb, uint8_t val);
-
 void keyboard_init()
 {
     keys=(kbd_key*)malloc(256*sizeof(kbd_key));
--- a/keyboard.h	Fri Sep 28 04:03:54 2012 +0000
+++ b/keyboard.h	Fri Sep 28 04:35:00 2012 +0000
@@ -0,0 +1,76 @@
+#ifndef KEYBOARD_H
+#define KEYBOARD_H
+
+#include "stdint.h"
+/**This is basically a straight rip off of my x86 OS project AlloyOS. I just ported the keyboard driver from it cause it always treated me well**/
+
+
+#define KEYBOARD_DATAPIN p11
+#define KEYBOARD_CLOCKPIN p12
+
+//how many keys the buffer can hold
+#define KBD_BUFFER_SIZE 128 
+
+//key defines
+#define LSHIFT_KEY 0x12
+#define RSHIFT_KEY 0x59
+
+#define CTRL_KEY 0xF3
+#define ALT_KEY 0xF4
+#define CAPS_KEY 0x58
+#define NUM_KEY 0x77
+#define SCROLL_KEY 0xF7
+//#define F_BASE_KEY 0xFF //59 is F1, 60 is F2, and so on until F10
+#define HOME_KEY 0xFF
+#define UP_KEY 0xFF
+#define PAGE_UP_KEY 0xFF
+#define LEFT_KEY 0xFF
+#define RIGHT_KEY 0xFF
+#define END_KEY 0xFF
+#define DOWN_KEY 0xFF
+#define PAGE_DOWN_KEY 0xFF
+#define INSERT_KEY 0xFF
+#define DEL_KEY 0xFF
+#define F11_KEY 0xFF
+#define F12_KEY 0xFF
+
+#define SCROLL_LED 1
+#define NUM_LED 2
+#define CAPS_LED 4
+
+
+extern const char kbdus[0x84];
+extern const char kbdus_caps[0x84];
+
+typedef struct {
+    unsigned char caps;
+    unsigned char shift;
+    unsigned char scroll;
+    unsigned char num;
+    unsigned char ctrl;
+    unsigned char alt;
+}
+shift_locks; /*for simplicity and speed*/
+
+extern volatile shift_locks kbd_shifts;
+
+typedef struct {
+    uint16_t scancode;
+    uint8_t asci;
+}kbd_key;
+
+void keyboard_callback(PS2KB kb, uint8_t val);
+void keyboard_init();
+
+int kbd_PutBuffer(uint16_t scan,uint8_t asci);
+
+kbd_key kbd_PopBuffer();
+uint8_t kbd_GetKey();
+void kbd_update_leds(uint8_t status);
+int kbd_DoShifts(uint8_t scan);
+int kbd_DoUnshifts(uint8_t scan);
+void keyboard_callback(PS2KB kb, uint8_t val);
+
+
+
+#endif
\ No newline at end of file
--- a/main.cpp	Fri Sep 28 04:03:54 2012 +0000
+++ b/main.cpp	Fri Sep 28 04:35:00 2012 +0000
@@ -14,6 +14,8 @@
 void keyboard_init();
 
 int main() {
+    serial.baud(9600);
+    serial.puts("Resetting interrupt priorities...");
     //Set all priorities to 100 so we are able to make VGA a priority
     //By default, all priorities are at their highest 0
     NVIC_SetPriority( NonMaskableInt_IRQn, 100 ); 
@@ -24,13 +26,13 @@
     NVIC_SetPriority(SVCall_IRQn, 100);
     NVIC_SetPriority(DebugMonitor_IRQn, 100);
     NVIC_SetPriority(PendSV_IRQn, 100);
-    NVIC_SetPriority(SysTick_IRQn, 100);
+    NVIC_SetPriority(SysTick_IRQn, 50);
     NVIC_SetPriority(WDT_IRQn, 100);
-    NVIC_SetPriority(TIMER0_IRQn, 100);
-    NVIC_SetPriority(TIMER1_IRQn, 100);
-    NVIC_SetPriority(TIMER2_IRQn, 100);
-    NVIC_SetPriority(TIMER3_IRQn, 100);
-    NVIC_SetPriority(UART0_IRQn, 100);
+    NVIC_SetPriority(TIMER0_IRQn, 85);
+    NVIC_SetPriority(TIMER1_IRQn, 85);
+    NVIC_SetPriority(TIMER2_IRQn, 85);
+    NVIC_SetPriority(TIMER3_IRQn, 85);
+    NVIC_SetPriority(UART0_IRQn, 75);
     NVIC_SetPriority(UART1_IRQn, 100);
     NVIC_SetPriority(UART2_IRQn, 100);
     NVIC_SetPriority(UART3_IRQn, 100);
@@ -61,19 +63,26 @@
     NVIC_SetPriority(MCPWM_IRQn, 100);
     NVIC_SetPriority(QEI_IRQn, 100);
     NVIC_SetPriority(PLL1_IRQn, 100);
+    //serial.puts("Done!\r\n");
+    //serial.puts("Initializing VGA...");
+    //wait_ms(500);
     init_vga();
     vga_cls();
-    serial.baud(115200);
-    serial.printf("Initializing PS/2..");
+    //serial.puts("Done!\r\n");
+    
+    //serial.puts("Initializing PS/2 Keyboard..");
+    //NVIC_SetPriority( EINT3_IRQn, 90 ); 
+    //wait_ms(500);
     keyboard_init();
     fl_select_clock_i2s(FL_CLOCK_DIV1); // assume 100MHz
     fl_i2s_set_tx_rate(1,4);            // set 25 MHz pixel clock 
     
     
     NVIC_SetPriority( EINT3_IRQn, 90 ); 
-    serial.printf("Done\r\n");
+    //wait_ms(500);
+    //serial.puts("Done\r\n");
     
-    
+    //serial.puts("Entering mbedConsole shell\r\n");
     while(1)
     {
         vputs("mbedConsole by Jordan Earls\n");
--- a/shell.cpp	Fri Sep 28 04:03:54 2012 +0000
+++ b/shell.cpp	Fri Sep 28 04:35:00 2012 +0000
@@ -16,8 +16,12 @@
         if(strlcmp(cmd, "help", 5)==0){
             valid=true;
             vputs("Command list:\n");
-            vputs("help -- this text \n");
-            vputs("cls -- clear the screen\n");
+            vputs("help     -- this text \n");
+            vputs("cls      -- clear the screen\n");
+            vputs("testX    -- test (where X is number) performs tests\n");
+            vputs("reboot   -- resets the processor\n");
+            vputs("about    -- prints text about how we got to here\n");
+            vputs("plearlz  -- enter the PLEarlz Forth shell\n");
         }else if(strlcmp(cmd,"cls",4)==0){
             valid=true;
             vga_cls();
@@ -51,9 +55,15 @@
         }else if(strlcmp(cmd, "plearlz", 8)==0){
             valid=1;
             pl_shell();
+        }else if(strlcmp(cmd,"reboot", 7)==0){
+            valid=1;
+            NVIC_SystemReset();
+        }else if(strlcmp(cmd, "about", 6)==0){
+            valid=1;
+            vputs("I am Jack's broken monolog\n");
         }
         if(!valid){
-            vputs("invalid command!\n");
+            vputs("Invalid Command! Try `help` if you need it\n");
         }
     }
 }
--- a/textio.cpp	Fri Sep 28 04:03:54 2012 +0000
+++ b/textio.cpp	Fri Sep 28 04:35:00 2012 +0000
@@ -1,126 +1,127 @@
-#include "mbedconsole.h"
-
-#define FONTHEIGHT 16
-#define FONTWIDTH 8
-
-int console_x=0, console_y=0;
-int console_color=WHITE; //text color
-
-
-void vsetcursor(int x, int y)
-{
-    console_x=x;
-    console_y=y;
-}
-
-void vrawputc(char c)
-{
-    //fuck that shitv
-    if(console_x>80)
-    {
-        return;
-    }
-    //shift left for fast multiply
-    vga_putchar(console_x<<3, console_y<<4, c, console_color);
-}
-void vputc(char c)
-{
-    //shift left for fast multiply
-    if(console_x>=79)
-    {
-        console_x=0;
-        console_y++;
-    }
-    if(console_y>=24)
-    {
-        console_y--;
-        vga_scroll();
-    }
-    switch(c){
-        case '\n':
-        case '\r':
-        console_y++;
-        console_x=0;
-        break;
-        case '\b':
-        vrawputc(' ');
-        if(console_x>0)
-        {
-            console_x--;
-        }
-        vrawputc(' ');
-        break;
-        case '\t':
-        for(int i=0;i<4;i++)
-        {
-            console_x++;
-            vrawputc(' ');
-        }
-        default:
-        vga_putchar(console_x<<3, console_y<<4, c, console_color);
-        console_x++;
-    }
-}
-
-void vputs(char *s){
-    while(*s!=0){
-        vputc(*s);
-        s++;
-    }
-}
-
-char vgetc()
-{
-    char tmp=kbd_GetKey();
-    vputc(tmp);
-    return tmp;
-}
-int vgetsl(char *buf, int len)
-{
-    int pos=0;
-    while(1){
-        buf[pos]=kbd_GetKey();
-        if(buf[pos]=='\r'){
-            buf[pos]='\n';
-        }
-        
-        vputc(buf[pos]);
-        if(buf[pos]=='\b'){
-            buf[pos]=0;
-            if(pos>0){
-                pos--;
-                buf[pos--]=0;
-            }
-        }
-        if(pos>len-1){
-            break;
-        }
-        if(buf[pos]=='\n'){
-            buf[pos]=0;
-            return 1;
-        }
-        pos++;
-    }
-    return 0;
-}
-
-
-
-int strlcmp(const char *s1,const char *s2,size_t count){
-    int i=0;
-    while((s1[i]!=0) && (s2[i]!=0)){
-        if(s1[i]!=s2[i]){
-            return -1;
-        }
-        if(i>=count){
-            return -1;
-        }
-        i++;
-        
-    }
-    if(s1[i]!=s2[i]){
-        return -1;
-    }
-    return 0;
-}
-
+#include "mbedconsole.h"
+#include "keyboard.h"
+
+#define FONTHEIGHT 16
+#define FONTWIDTH 8
+
+int console_x=0, console_y=0;
+int console_color=WHITE; //text color
+
+
+void vsetcursor(int x, int y)
+{
+    console_x=x;
+    console_y=y;
+}
+
+void vrawputc(char c)
+{
+    //fuck that shitv
+    if(console_x>80)
+    {
+        return;
+    }
+    //shift left for fast multiply
+    vga_putchar(console_x<<3, console_y<<4, c, console_color);
+}
+void vputc(char c)
+{
+    //shift left for fast multiply
+    if(console_x>=79)
+    {
+        console_x=0;
+        console_y++;
+    }
+    if(console_y>=24)
+    {
+        console_y--;
+        vga_scroll();
+    }
+    switch(c){
+        case '\n':
+        case '\r':
+        console_y++;
+        console_x=0;
+        break;
+        case '\b':
+        vrawputc(' ');
+        if(console_x>0)
+        {
+            console_x--;
+        }
+        vrawputc(' ');
+        break;
+        case '\t':
+        for(int i=0;i<4;i++)
+        {
+            console_x++;
+            vrawputc(' ');
+        }
+        default:
+        vga_putchar(console_x<<3, console_y<<4, c, console_color);
+        console_x++;
+    }
+}
+
+void vputs(char *s){
+    while(*s!=0){
+        vputc(*s);
+        s++;
+    }
+}
+
+char vgetc()
+{
+    char tmp=kbd_GetKey();
+    vputc(tmp);
+    return tmp;
+}
+int vgetsl(char *buf, int len)
+{
+    int pos=0;
+    while(1){
+        buf[pos]=kbd_GetKey();
+        if(buf[pos]=='\r'){
+            buf[pos]='\n';
+        }
+        
+        vputc(buf[pos]);
+        if(buf[pos]=='\b'){
+            buf[pos]=0;
+            if(pos>0){
+                pos--;
+                buf[pos--]=0;
+            }
+        }
+        if(pos>len-1){
+            break;
+        }
+        if(buf[pos]=='\n'){
+            buf[pos]=0;
+            return 1;
+        }
+        pos++;
+    }
+    return 0;
+}
+
+
+
+int strlcmp(const char *s1,const char *s2,size_t count){
+    int i=0;
+    while((s1[i]!=0) && (s2[i]!=0)){
+        if(s1[i]!=s2[i]){
+            return -1;
+        }
+        if(i>=count){
+            return -1;
+        }
+        i++;
+        
+    }
+    if(s1[i]!=s2[i]){
+        return -1;
+    }
+    return 0;
+}
+
--- a/vga640x480g.lib	Fri Sep 28 04:03:54 2012 +0000
+++ b/vga640x480g.lib	Fri Sep 28 04:35:00 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/gertk/code/vga640x480g/#c9543fb59830
+http://mbed.org/users/gertk/code/vga640x480g/#be212d7dbb60