int main(void) { FIL myFile; // Filehandler uint8_t write_ok=0; SystemInit(); // Quarz Einstellungen aktivieren // Init der LEDs UB_Led_Init(); // Init vom USB-OTG-Port als MSC-HOST // (zum lesen/schreiben auf einen USB-Stick) UB_USB_MSC_HOST_Init(); while(1) { // pollen vom USB-Status if(UB_USB_MSC_HOST_Do()==USB_MSC_DEV_CONNECTED) { // wenn USB-Stick erkannt wurde UB_Led_On(LED_GREEN); // wenn File noch nicht geschrieben wurde if(write_ok==0) { write_ok=1; UB_Led_On(LED_RED); // Media mounten if(UB_Fatfs_Mount(USB_0)==FATFS_OK) { // File zum schreiben im root neu anlegen if(UB_Fatfs_OpenFile(&myFile, "USB_File.txt", F_WR_CLEAR)==FATFS_OK) { // ein paar Textzeilen in das File schreiben UB_Fatfs_WriteString(&myFile,"Test der WriteString-Funktion"); UB_Fatfs_WriteString(&myFile,"hier Zeile zwei"); UB_Fatfs_WriteString(&myFile,"ENDE"); // File schliessen UB_Fatfs_CloseFile(&myFile); } // Media unmounten UB_Fatfs_UnMount(USB_0); } UB_Led_Off(LED_RED); } } else { // wenn kein USB-Stick vorhanden UB_Led_Off(LED_GREEN); } } }
int sd::open(){ uint8_t write_ok = 0; while (write_ok==0) { // pollen vom USB-Status if (UB_USB_MSC_HOST_Do() == USB_MSC_DEV_CONNECTED) { // Media mounten if (UB_Fatfs_Mount(USB_0) == FATFS_OK) { write_ok = 1; // UB_Fatfs_UnMount(USB_0); return 0; } } else if (UB_USB_MSC_HOST_Do() == USB_MSC_DEV_NOT_SUPPORTED) { TFT.string(VISITOR_SMALL_1X_FONT, "Unsupported", 0, 0); return -1; } else { // wenn NOCH kein USB-Stick vorhanden/bereit } } return 1; }
// usuwanie_plikow_i_katalogow void usuwanie_plikow_i_katalogow() { FILINFO fno; DIR dir; uint8_t write_ok = 0; FRESULT res; char *path=""; char *fn; // This function is assuming non-Unicode cfg. SystemInit ( ); UB_Led_Init ( ); UB_USB_MSC_HOST_Init ( ); fno.lfname = lfnBuffer; fno.lfsize = sizeof ( lfnBuffer ); unsigned int counter =0; while ( counter<5000000 ) { if ( UB_USB_MSC_HOST_Do ( ) == USB_MSC_DEV_CONNECTED ) { // Sprawdzenie poprawnsoci po³¹czenia UB_Led_On ( LED_GREEN ); UB_Led_Off ( LED_RED ); // Je¿eli zapisy s¹ poprawne to: if ( write_ok == 0 ) { write_ok = 1; // W trakcie zapisu wieci pomarañczowa dioda. UB_Led_On ( LED_ORANGE ); if ( UB_Fatfs_Mount ( USB_0 ) == FATFS_OK ) // Montowanie pendraiva { res = f_opendir(&dir, path); // Open the directory if (res == FR_OK) { for (;;) { res = f_readdir(&dir, &fno); // Read a directory item if (res != FR_OK || fno.fname[0] == 0) break; // Break on error or end of dir #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif f_unlink(fn); } // for } // if // Odmontowanie usb po wykonaniu akcji UB_Fatfs_UnMount ( USB_0 ); } // if UB_Led_Off ( LED_ORANGE ); } // Kiedy koniec operacji gaszenie ¿ó³tej lampki // stop UB_Led_On ( LED_BLUE ); //mozna tu dac jakies opoznienie counter=5000001; } // if else { // W razie b³êdów zawiecenie diody czerwone i zgaszenie zielonej UB_Led_Off ( LED_GREEN ); UB_Led_On ( LED_RED ); //tu trzeba dac jakies opoznienie counter++; } // else } // while } // main