First version of my operation system for stm32 board
Dependencies: RA8875 VS1053 sd-driver-hs
Diff: main.cpp
- Revision:
- 0:86f82f777a7a
- Child:
- 2:a3d00f0610f9
diff -r 000000000000 -r 86f82f777a7a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 01 06:58:17 2018 +0000 @@ -0,0 +1,153 @@ +#include "include.h" + +//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"); +SDBlockDevice sd(MOSI_SD, MISO_SD, CLK_SD, CS_SD); + +//File system +FATFileSystem fs("fs"); + +//Tread +Thread kb_thread; + +void keyboard_task() +{ + while(true) { + input[position] = keyboard.getc(); + } +} + +int main() +{ + wait(0.3); + //init device + lcd.init(480,272); + 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); + ///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(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); + } + } + 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"); + + 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 + }//end press key + wait(0.1); + }//end while + fs.unmount(); +}//end main \ No newline at end of file