int main(void) // Объявляем функцию которая принимает значение void { SystemInit(); // Настройка и включение кварца (Quarz Einstellungen aktivieren) // ### SystemInit кокофигурируется где то в дебрях system_stm32f4xx.h UB_Button_Init(); // Активация Кнопки (Init der Buttons) UB_Led_Init(); // Активация LEDs (Init der LEDs) // ### UB_Button_Init UB_Led_Init кофигурируется в файлах // ### stm32_ub_button.c stm32_ub_button.h stm32_ub_led.c stm32_ub_led.h UB_Led_On(LED_GREEN); // Включение GREEN СветоДиода (gruene LED einschalten) // ### UB_Led_On кофигурируется в файлах stm32_ub_led.c stm32_ub_led.h while(1) // Открываем цикл { // прорверяем нажата ли кнопка USER (Test ob Button gedruckt ist) if(UB_Button_Read(BTN_USER)==BTN_PRESSED) { // ### UB_Button_Read кофигурируется в файлах stm32_ub_button.c stm32_ub_button.h UB_Led_On(LED_RED); // Включение RED СветоДиода (rote LED einschalten) UB_Led_Off(LED_GREEN); // ### UB_Led_On UB_Led_Off кофигурируется в файлах stm32_ub_led.c stm32_ub_led.h UB_Led_On(LED_ORANGE); UB_Led_Off(LED_BLUE); } else { UB_Led_Off(LED_RED); // Выключение RED СветоДиода (rote LED ausschalten) UB_Led_On(LED_GREEN); UB_Led_Off(LED_ORANGE); UB_Led_On(LED_BLUE); } } }
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); } } }
//-------------------------------------------------------------- // Initiation all of LEDs //-------------------------------------------------------------- void UB_Led_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; LED_NAME_t led_name; for(led_name=0;led_name<LED_ANZ;led_name++) { // Clock Enable RCC_AHB1PeriphClockCmd(LED[led_name].LED_CLK, ENABLE); // Configuration of all Digital Output GPIO_InitStructure.GPIO_Pin = LED[led_name].LED_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(LED[led_name].LED_PORT, &GPIO_InitStructure); // Default settings if(LED[led_name].LED_INIT==LED_OFF) { UB_Led_Off(led_name); } else { UB_Led_On(led_name); } } }
void UB_Led_Switch(LED_NAME_t led_name, LED_STATUS_t status) { if(status==LED_OFF) { UB_Led_Off(led_name); } else { UB_Led_On(led_name); } }
//-------------------------------------------------------------- // LED Switch on or off //-------------------------------------------------------------- void UB_Led_Switch(LED_NAME_t led_name, LED_STATUS_t wert) { if(wert==LED_OFF) { UB_Led_Off(led_name); } else { UB_Led_On(led_name); } }
void UB_LED_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; uint8_t led_name; for (led_name=0; led_name < LED_ANZ; led_name++) { RCC_APB2PeriphClockCmd(LED[led_name].LED_CLK , ENABLE); GPIO_InitStructure.GPIO_Pin = LED[led_name].LED_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LED[led_name].LED_PORT, &GPIO_InitStructure); // Default Wert einstellen if(LED[led_name].LED_INIT==LED_ON) { UB_Led_Off((LED_NAME_t)led_name); } else { UB_Led_On((LED_NAME_t)led_name); } } }
// 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
int main(void) { RTC_STATUS_t check; uint8_t old_sek=0; char buf[APP_TX_BUF_SIZE]; // puffer fuer Datenempfang SystemInit(); // Quarz Einstellungen aktivieren // Init der LEDs UB_Led_Init(); // Init der Buttons UB_Button_Init ( ); // Init und start der RTC check=UB_RTC_Init(); if(check==RTC_UNDEFINED) { // RTC war noch nie initialisiert UB_Led_On(LED_RED); } else { // RTC war schon initialisiert UB_Led_On(LED_GREEN); } // Init vom USB-OTG-Port als CDC-Device // (Virtueller-ComPort) /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! * die nächste Zeile auskommentieren, * dann funktioniert das Zurücksetzen * des RTC */ UB_USB_CDC_Init(); while ( 1 ) { // wenn Button gedrückt -> RTC zurücksetzen if ( UB_Button_Read ( BTN_USER ) ) { // orange LED ein UB_Led_On ( LED_ORANGE ); // RTC zurücksetzen ResetRTC ( ); // warten bis Button gelöst while ( UB_Button_Read ( BTN_USER ) ); // die LED noch ein Weilchen an lassen Delay ( 10000000 ); UB_Led_Off ( LED_ORANGE ); } // aktuelle RTC-Zeit auslesen UB_RTC_GetClock(RTC_DEC); if(UB_RTC.sek!=old_sek) { // wenn eine Sekunde um ist old_sek=UB_RTC.sek; UB_Led_Toggle(LED_BLUE); // aktuelle Zeit als String formatieren sprintf ( buf, "%02d.%02d.%02d %02d:%02d:%02d", UB_RTC.tag, UB_RTC.monat, UB_RTC.jahr, UB_RTC.std, UB_RTC.min, UB_RTC.sek ); // an Semihosting senden printf ( "%s\r\n", buf ); // Test ob USB-Verbindung zum PC besteht if(UB_USB_CDC_GetStatus()==USB_CDC_CONNECTED) { // an PC senden UB_USB_CDC_SendString ( buf, LFCR ); } } } }
/***************************************** * MAIN *****************************************/ int main(void) { SystemInit(); UB_Systick_Init(); // Init of UB libs UB_TIMER2_Init_FRQ( 100 ); UB_TIMER5_Init_FRQ( 10000 ); UB_Led_Init(); UB_DigIn_Init(); UB_DigOut_Init(); UB_ADC1_SINGLE_Init(); UB_RTC_Init(); UB_RTC_SetWakeUpInterrupt(RTC_WAKEUP_5s); // Note: code needs to be reconfigured for Nucleo Board (Frequency of 96 MHz should also be checked) UB_WS2812_Init(); WC_DisableAllElements(); WC_SetColor( WS2812_HSV_COL_WHITE ); WC_SetBrightness( 10 ); WC_SetElement(WC_ELEMENT_ES, 1); WC_Refresh(); UB_Uart_Init(); esp8266_init(); UB_Systick_Pause_ms(1000); // Indicate successful booting UB_Led_On( LED_GREEN ); UB_Systick_Pause_s(1); UB_Led_Off( LED_GREEN ); // Start timers and therefore cyclic actions in the call backs below UB_TIMER2_Start(); UB_TIMER5_Start(); UB_DigOut_Lo(DOUT_PB7); // Set ground for LDR UB_DigOut_Lo(DOUT_PB9); // Set PC9 low to start DCF module while(1) { // Handle word matrix refreshes if ( gWcIsToBeRefreshed == Bit_SET ){ WC_Refresh(); gWcIsToBeRefreshed = Bit_RESET; } // Check if update of time is necessary #ifndef DISABLE_DCF if ( DcfTimeWasSetRecently() == Bit_RESET ) gDcfRxInProgress = Bit_SET; #endif // Handle IR remote if ( irmp_get_data( &irData ) ) ProcessIrDataPacket( irData ); // Read Ambient brightness and set LED brightness if ( gDcfRxInProgress == Bit_RESET ){ ambientBrightnessCurrent = SlidingAverageOnLastValues( UB_ADC1_SINGLE_Read( ADC_PA1 ) ); int brightnessToSet = 100.0 * GetBrightnessFactor( ambientBrightnessPoints, ambientBrightnessLedDimmingFactors, ambientBrightnessCurrent ); if ( brightnessToSet < LED_BRIGHTNESS_OFF_THRESHOLD ) WC_SetColor( WS2812_HSV_COL_OFF ); else WC_SetBrightness( brightnessToSet ); gWcIsToBeRefreshed = Bit_SET; } // Handle ESP8266 receive esp8266_handle_receive(); if( esp8266_request_time_from_google() == 1 ) { UB_RTC = Esp8266_curTime; UB_RTC_SetClock( RTC_DEC ); SetWordMatrix( UB_RTC_GetClock(RTC_DEC) ); gWcIsToBeRefreshed = Bit_SET; } } }
/***************************************** * Timer 2 Callback @100Hz * - Used for: DCF77 sampling *****************************************/ void UB_TIMER2_ISR_CallBack( void ) { #ifdef DISABLE_DCF return; #endif gDcfInputState = UB_DigIn_Read( DIN_PB8 ); if ( gDcfInputState == Bit_SET ) UB_Led_On( LED_GREEN ); else UB_Led_Off( LED_GREEN ); #ifdef ENABLE_TESTMODE //Testing: Just set a time gLastSuccessfulDcfRxTime.jahr = 0; gLastSuccessfulDcfRxTime.monat = 1; gLastSuccessfulDcfRxTime.tag = 1; gLastSuccessfulDcfRxTime.wotag = 1; gLastSuccessfulDcfRxTime.sek = 0; gLastSuccessfulDcfRxTime.min = 0; gLastSuccessfulDcfRxTime.std = 0; WC_SetElement(WC_ELEMENT_ES, 1); SetWordMatrix( UB_RTC_GetClock(RTC_DEC) ); gDcfRxInProgress = Bit_RESET; gDcfRxWasSuccesful = Bit_SET; gCurrentMatrixColor = WS2812_HSV_COL_WHITE; #else dcf77_SignalState_t dcf77state = Dcf77_ProcessSignal( gDcfInputState ); if ( dcf77state == dcf77_TimeRxSuccess ) { gLastSuccessfulDcfRxTime = Dcf77_GetTime(); UB_RTC = gLastSuccessfulDcfRxTime; UB_RTC_SetClock( RTC_DEC ); gDcfRxWasSuccesful = Bit_SET; // Set word matrix directly after first DCF RX if ( gDcfRxInProgress == Bit_SET ){ WC_SetElement(WC_ELEMENT_ES, 1); SetWordMatrix( UB_RTC_GetClock(RTC_DEC) ); gDcfRxInProgress = Bit_RESET; gCurrentMatrixColor = WS2812_HSV_COL_WHITE; } } // Indicate status of DCF reception by FUNK in red/green while DCF RX in progress if ( gDcfRxWasSuccesful == Bit_RESET ){ WC_DisableAllElements(); WC_SetElement( WC_ELEMENT_FUNK, 1 ); if ( dcf77state == dcf77_RxStateUnkown ) WC_SetColor( WS2812_HSV_COL_RED ); else if ( dcf77state == dcf77_RxStateGood ) WC_SetColor( WS2812_HSV_COL_GREEN ); WC_SetBrightness( 50 ); WC_SetElement( WC_ELEMENT_FUNK, 1 ); } else{ // Disable FUNK and set normal color WC_SetElement( WC_ELEMENT_FUNK, 0 ); WC_SetColor( gCurrentMatrixColor ); } #endif gWcIsToBeRefreshed = Bit_SET; }