Tomas Kucera / Mbed OS HagridOS5

Dependencies:   RA8875 VS1053 sd-driver-hs

Files at this revision

API Documentation at this revision

Comitter:
Hagrid
Date:
Tue Mar 13 06:35:47 2018 +0000
Parent:
2:a3d00f0610f9
Child:
4:3cdd044a3df4
Commit message:
Add LCD manager suport;

Changed in this revision

include.h Show annotated file Show diff for this revision Revisions of this file
lcd_manager.cpp 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
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
variables.h Show annotated file Show diff for this revision Revisions of this file
w.cpp Show diff for this revision Revisions of this file
--- a/include.h	Thu Mar 01 07:14:46 2018 +0000
+++ b/include.h	Tue Mar 13 06:35:47 2018 +0000
@@ -4,4 +4,4 @@
 #include "RA8875.h"
 #include "pinout.h"
 #include "fce.h"
-#include "VS1053.h"
\ No newline at end of file
+#include "VS1053.h"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcd_manager.cpp	Tue Mar 13 06:35:47 2018 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+#include "RA8875.h"
+#include "pinout.h"
+
+RA8875 lcd_m(MOSI_LCD, MISO_LCD, CLK_LCD, CS_LCD, NC, "tft");
+
+int x;
+int y;
+
+
+void init_lcd()
+{
+    lcd_m.init(480,272);
+    lcd_m.foreground(Orange);
+}
+
+void print(char data[59])
+{
+    int len = strlen(data);
+    for(int i =0; i<len; i++) {
+        lcd_m.SetTextCursor(x,y);
+        lcd_m.putc(data[i]);
+        x+=8;
+        if(data[i] == '\n') {
+            x=0;
+            y+=17;
+        }
+    }
+}
+
+void print_int(int a)
+{
+    char tmp[20];//max 20 digit number
+    sprintf(tmp,"%i",a);
+    print(tmp);
+}
+
+void print_double(double a)
+{
+    char tmp[20];//max 20 digit number
+    sprintf(tmp,"%f",a);
+    print(tmp);
+}
+
+
+void backspace()
+{
+    x-=8;
+    lcd_m.SetTextCursor(x,y);
+    lcd_m.putc(NULL);
+}
+
+void lcd_cls()
+{
+    lcd_m.cls();
+    x=0;
+    y=0;
+}
+
+void set_backlight(float back)
+{
+
+    lcd_m.Backlight(back);
+}
+
+
+
--- a/main.cpp	Thu Mar 01 07:14:46 2018 +0000
+++ b/main.cpp	Tue Mar 13 06:35:47 2018 +0000
@@ -1,11 +1,16 @@
 #include "include.h"
 ///# include
+
+//GPIO define
+BusOut adress(A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13,A14,A15);
+BusInOut data(D0,D1,D2,D3,D4,D5,D6,D7);
+
 //Serial device
 Serial keyboard(Tx_KB,Rx_KB);// Tx, Rx
 
 //SPI device
 VS1053 mp3(MOSI_AUDIO, MISO_AUDIO, CLK_AUDIO, CS_AUDIO, RST_AUDIO,DREQ_AUDIO,DSC_AUDIO,PA_4);
-RA8875 lcd(MOSI_LCD, MISO_LCD, CLK_LCD, CS_LCD, NC, "tft");
+//RA8875 lcd(MOSI_LCD, MISO_LCD, CLK_LCD, CS_LCD, NC, "tft");
 SDBlockDevice sd(MOSI_SD, MISO_SD, CLK_SD, CS_SD);
 
 //File system
@@ -14,6 +19,16 @@
 //Tread
 Thread kb_thread;
 
+//lcd methods
+void init_lcd();
+void print(char data[59]);
+void print_int(int a);
+void print_double(double a);
+void backspace();
+void lcd_cls();
+void set_backlight(float back);
+
+//keyboard thread
 void keyboard_task()
 {
     while(true) {
@@ -24,128 +39,153 @@
 int main()
 {
     wait(0.3);
-    //init device  
-    lcd.init(480,272);
+    //init device
+    init_lcd();
     mp3.initialize();
     keyboard.baud(57600);
-    lcd.foreground(Orange);
+    
     kb_thread.start(keyboard_task);
     sd.init();
     fs.mount(&sd);
-    lcd.printf("HagridOS v.5.0\n\r>");
-       
-    fs.mount(&sd);
+    print("HagridOS v.5.0\n>");
+
     ///start main code
     while (true) {
 
         if(!keyboard.readable()) { //scan key
-            if (input[position] == '\n') { //press enter
-                input[position] = '\0'; //insert in end position NULL character
-                kbsplit(input);//split keyboard input
+            if(input[position]=='Q') {//press backspace
+                backspace();
+                input[position] = '\0';
+                position-=1;
+            } else {
+
+                if (input[position] == '\n') { //press enter
+                    input[position] = '\0'; //insert in end position NULL character
+                    kbsplit(input);//split keyboard input
 
-                if(tmpE[0] == NULL) { //press only enter if
-                    lcd.printf("\n\r");
-                    lcd.printf(">");
-                } else {
-                    switch(compare(&tmpE[0])) { //switch run basic commands
-                        case 0:
-                            fs.mkdir(tmpE[1],777);
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 1:
-                            fs.remove(tmpE[1]);
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 2:
-                            fs.mount(&sd);
-                            DIR *d;
-                            struct dirent *p;
-                            d = opendir("/fs/");
-                            if (d != NULL) {
-                                while ((p = readdir(d)) != NULL) {
-                                    lcd.printf("\n\r");
-                                    lcd.printf(p->d_name);
+                    if(tmpE[0] == NULL) { //press only enter if
+                        print("\n>");
+                    } else {
+                        switch(compare(&tmpE[0])) { //switch run basic commands
+                            case 0://mkdir
+                                fs.mkdir(tmpE[1],777);
+                                print("\n>");
+                                erase();
+                                break;
+                            case 1://remove
+                                fs.remove(tmpE[1]);
+                                print("\n>");
+                                erase();
+                                break;
+                            case 2://ls
+                                fs.mount(&sd);
+                                DIR *d;
+                                struct dirent *p;
+                                d = opendir(adir);
+                                if (d != NULL) {
+                                    while ((p = readdir(d)) != NULL) {
+                                        print("\n");
+                                        print(p->d_name);
+                                    }
                                 }
-                            }
-                            closedir(d);
-                            fs.unmount();
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 3:
-                            lcd.cls();
-                            lcd.printf("HagridOS v.5.0\n\r>");
-                            erase();
-                            break;
-                        case 4:
-                            lcd.printf("\n\rBasic Operation System for STM32 by HAGRID\n\r");
-                            lcd.printf("Version: 5.0 release: 24.02.2018\n\r");
-                            lcd.printf("SD size: %lluMb\n\r",(sd.size()/1024)/1024);
-                            lcd.printf("CPU speed: %d MHz", SystemCoreClock/1000000);
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 5:
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 6:
-                            wait(atoi(tmpE[1]));
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case  7:
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 8:
-                            lcd.Backlight(atof(tmpE[1]));
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 9:
-                            FILE* song = fopen(tmpE[1], "r");
+                                closedir(d);
+                                fs.unmount();
+                                print("\n>");
+                                erase();
+                                break;
+                            case 3://cls
+                                lcd_cls();
+                                print("HagridOS v.5.0\n>");
+                                erase();
+                                break;
+                            case 4://info
+                                print("\nBasic Operation System for STM32 by HAGRID\n");
+                                print("Version: 5.0 release: 10.03.2018\n");
+                                //lcd.printf("SD size: %lluMb\n\r",(sd.size()/1024)/1024);
+                                print("CPU speed: ");
+                                print_double(SystemCoreClock/1000000);
+                                print(" MHz");
+                                print("\n>");
+                                erase();
+                                break;
+                            case 5://edit
+                                print("\n>");
+                                erase();
+                                break;
+                            case 6://sleep
+                                wait(atoi(tmpE[1]));
+                                print("\n>");
+                                erase();
+                                break;
+                            case  7://GPIO
+                                if(!strcasecmp("data",tmpE[1])) {
+                                    if(tmpE[2]==NULL) {
+                                        data.input();
+                                        print("\n");
+                                        int in = data.read();
+                                        print_int(in);
+                                    } else {
+                                        data.output();
+                                        data = atoi(tmpE[2]);
+                                    }
+                                }
+                                if(!strcasecmp("adress",tmpE[1])) {
+                                    adress = atoi(tmpE[2]);
+                                }
+                                print("\n>");
+                                erase();
+                                break;
+                            case 8://backlight
+                                set_backlight(atof(tmpE[1]));
+                                print("\n>");
+                                erase();
+                                break;
+                            case 9://play
+                                sprintf(apath,"%s%s",apath,tmpE[1]);
+                                FILE* song = fopen(apath, "r");
 
-                            while(!feof(song)) {
-                                int n=fread(&array, 1, sizeof(array), song);
-                                mp3.writeStream(array,n);
-                            }
-                            mp3.terminateStream();
+                                while(!feof(song)) {
+                                    int n=fread(&array, 1, sizeof(array), song);
+                                    mp3.writeStream(array,n);
+                                }
+                                mp3.terminateStream();
 
-                            fclose(song);  //close the file
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        case 10:
-                            sprintf(c_dir,"%s%s",home,tmpE[1]);
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                        default:
-                            lcd.printf("\n\r");
-                            lcd.printf("hsh: %s command not found",tmpE[0]);
-                            lcd.printf("\n\r");
-                            lcd.printf(">");
-                            erase();
-                            break;
-                    }//end switch
-                }//end press enter only
-            } else {
-                lcd.printf(&(input[position]));
-                position++;
-            }//end press enter
+                                fclose(song);  //close the file
+                                print("\n>");
+                                erase();
+                                break;
+                            case 10://cd
+                                sprintf(adir,"%s%s",adir,tmpE[1]);
+                                print("\n>");
+                                erase();
+                                break;
+                            case 11://help
+                                print("\n");
+                                print("mkdir file_name         rm file_name\n");
+                                print("ls                      cls\n");
+                                print("info                    edit file_name\n");
+                                print("sleep time              gpio mode dec_value\n");
+                                print("backlight value         play file_name\n");
+                                print("cd folder_name          help\n");
+                                print("out data/adress value   ");
+                                print("\n>");
+                                erase();
+                                break;
+                            default://command not found
+                                print("\n");
+                                print("hsh: ");
+                                print(tmpE[0]);
+                                print(" command not found");
+                                print("\n>");
+                                erase();
+                                break;
+                        }//end switch
+                    }//end press enter only
+                } else {
+                    print(&(input[position]));
+                    position++;
+                }//end press enter
+            }//end press backspace
         }//end press key
         wait(0.1);
     }//end while
--- a/mbed-os.lib	Thu Mar 01 07:14:46 2018 +0000
+++ b/mbed-os.lib	Tue Mar 13 06:35:47 2018 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#91e6db1ea251ffcc973001ed90477f42fdca5751
+https://github.com/ARMmbed/mbed-os/#569159b784f70feaa32ce226aaca896fb83452f7
--- a/variables.h	Thu Mar 01 07:14:46 2018 +0000
+++ b/variables.h	Tue Mar 13 06:35:47 2018 +0000
@@ -1,4 +1,4 @@
-#define command_count 11
+#define command_count 12
 
 char input[500];
 int position;
@@ -17,14 +17,15 @@
     {'i', 'n', 'f', 'o', '\0'},
     {'e', 'd', 'i', 't', '\0'},
     {'s', 'l', 'e', 'e', 'p', '\0'},
-    {'o', 'u', 't', '\0'},
+    {'g', 'p', 'i', 'o', '\0'},
     {'b', 'a', 'c', 'k', 'l', 'i', 'g', 'h', 't', '\0'},
     {'p', 'l', 'a', 'y', '\0'},
     {'c', 'd', '\0'},
+    {'h', 'e', 'l', 'p', '\0'},
     {' '}
 };//command field
 
 unsigned char array[25*1024];
 
-char home[10]="/fs/";
-char c_dir[10];
\ No newline at end of file
+char adir[50] = "/fs/"; //home fS path
+char apath[50] = "/fs/"; //home path
\ No newline at end of file
--- a/w.cpp	Thu Mar 01 07:14:46 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-#include "mbed.h"
-#include "RA8875.h"
-#include "pinout.h"
-
-RA8875 lcc_t(MOSI_LCD, MISO_LCD, CLK_LCD, CS_LCD, NC, "tft");