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:
Mon Sep 17 04:41:37 2012 +0000
Parent:
0:6906dbde03da
Child:
2:e2a4c5d17d59
Commit message:
Getting more and more useful

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbedconsole.h 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
--- a/main.cpp	Mon Sep 17 03:25:23 2012 +0000
+++ b/main.cpp	Mon Sep 17 04:41:37 2012 +0000
@@ -1,82 +1,24 @@
-#include "mbed.h"
-#include "vga640x480g.h"
+#include "mbedconsole.h"
 
-#define FONTHEIGHT 16
-#define FONTWIDTH 8
 
-int console_x=0, console_y=0;
-int console_color=WHITE; //text color
 
 DigitalOut myled(LED1);
 
-Serial serial(USBTX,USBRX);
+
+Serial serial(USBTX, USBRX);
 
-void rawputc(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 putc(char c)
-{
-    //shift left for fast multiply
-    if(console_x>=79)
-    {
-        console_x=0;
-        console_y++;
-    }
-    switch(c){
-        case '\n':
-        case '\r':
-        console_y++;
-        console_x=0;
-        break;
-        case '\b':
-        rawputc(' ');
-        if(console_x>0)
-        {
-            console_x--;
-        }
-        rawputc(' ');
-        break;
-        case '\t':
-        for(int i=0;i<4;i++)
-        {
-            console_x++;
-            rawputc(' ');
-        }
-        default:
-        vga_putchar(console_x<<3, console_y<<4, c, console_color);
-        console_x++;
-    }
-}
 
-/*void puts(char *s){
-    while(*s!=0){
-        char c=*s;
-        switch(c)
-            case '\n':
-            case '\r':
-            console_x=0;
-        vga_putchar(console_x,console_y,*s,console_color);
-    }
-*/
+
 
 int main() {
     init_vga();
-
     serial.baud(115200);
     
     vga_cls();
     
     while(1)
     {
-        if(serial.readable()){
-            putc(serial.getc());
-        }
+        vputs("mbedConsole by Jordan Earls\n");
+        shell_begin();
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbedconsole.h	Mon Sep 17 04:41:37 2012 +0000
@@ -0,0 +1,20 @@
+#ifndef MBEDCONSOLE_H
+#define MBEDCONSOLE_H
+
+#include "mbed.h"
+#include "vga640x480g.h"
+
+void vputc(char c);
+void vputs(char *s);
+char vgetc();
+int vgetsl(char *s, int len);
+
+int strlcmp(const char *s1,const char *s2,size_t count);
+
+void shell_begin();
+
+extern Serial serial;
+
+
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shell.cpp	Mon Sep 17 04:41:37 2012 +0000
@@ -0,0 +1,50 @@
+#include "mbedconsole.h"
+LocalFileSystem local("local");
+void shell_begin(){
+    vputs(">>Micro eMBEDded Shell v0.1<<\n");
+    char *cmd=(char*)malloc(128);
+    bool valid=false;
+    while(1){
+        vputs("> ");
+        vgetsl(cmd, 128);
+        vputc('\n');
+        vputs(cmd);
+        valid=false;
+        if(strlcmp(cmd, "help", 5)==0){
+            valid=true;
+            vputs("Command list:\n");
+            vputs("help -- this text \n");
+            vputs("cls -- clear the screen\n");
+        }else if(strlcmp(cmd,"cls",4)==0){
+            valid=true;
+            vga_cls();
+        }else if(strlcmp(cmd,"test", 5)==0){
+            
+        	vputs("Opening File...\n"); // Drive should be marked as removed
+        	FILE *fp = fopen("/local/test.txt", "w");
+        	if(!fp) {
+        		vputs("File /local/test.txt could not be opened!\n");
+        		exit(1);
+        	}
+        	
+        	wait(5.0);
+        	
+        	vputs("Writing Data...\n");	
+        	fprintf(fp, "Hello World!");
+        	
+        	wait(5.0);
+        
+        	vputs("Closing File...\n");
+        	fclose(fp);
+        
+                // Drive should be restored. this is the same as just returning from main
+            wait(5);
+        }
+        if(!valid){
+            vputs("invalid command!\n");
+        }
+    }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/textio.cpp	Mon Sep 17 04:41:37 2012 +0000
@@ -0,0 +1,129 @@
+#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()
+{
+    while(!serial.readable()){
+        return serial.getc();
+    }
+    return '!'; //unreachable
+}
+int vgetsl(char *buf, int len)
+{
+    int pos=0;
+    while(1){
+        if(serial.readable()){
+            buf[pos]=serial.getc();
+            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;
+}
+