void TM_EXTI_Handler(uint16_t GPIO_Pin) { volatile static uint8_t counter = 0; /* Handle external line 0 interrupts */ if (GPIO_Pin == GPIO_Pin_0) { /* Toggle RED led */ TM_DISCO_LedToggle(LED_RED); TM_ILI9341_Puts(20, 80, "button pressed, button pressed, button pressed, button pressed, button pressed, button pressed, button pressed, button pressed, ", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Check counter */ if (++counter >= 10) { /* Detach external interrupt for GPIO_Pin_0 no matter on which GPIOx is connected */ TM_EXTI_Detach(GPIO_Pin_0); TM_ILI9341_Puts(20, 80, "Exi detached", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); } } /* Handle external line 13 interrupts */ if (GPIO_Pin == GPIO_Pin_13) { /* Toggle GREEN led */ TM_DISCO_LedToggle(LED_GREEN); /* Check counter */ if (++counter >= 10) { /* Detach external interrupt for GPIO_Pin_0 no matter on which GPIOx is connected */ TM_EXTI_Detach(GPIO_Pin_13); } } }
// Blink LED function void blink_LED(void const *argument) { #if 0 /* Reset counter to 0 */ TM_DELAY_SetTime(0); while (1) { /* If time is more than 500ms */ if (TM_DELAY_Time() >= 500) { /* Reset time */ TM_DELAY_SetTime(0); /* Toggle leds here */ TM_DISCO_LedToggle(LED_RED | LED_GREEN); } /* Place your code here */ /* Code here will be checked without any delay */ /* Constantly */ } #endif #if 1 for (;;) { //LED_On (); // Switch LED on osDelay(1000); TM_DISCO_LedToggle(LED_RED | LED_GREEN); } #endif }
int main(void) { uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize LEDS */ TM_DISCO_LedInit(); /* Initialize RTC with internal clock */ TM_RTC_Init(TM_RTC_ClockSource_Internal); /* Set RTC to generate wakeup interrupt every 10 seconds */ TM_RTC_Interrupts(TM_RTC_Int_10s); /* Set time to 0 */ TM_DELAY_SetTime(0); while (1) { /* Toggle LEDs every 200ms */ if (TM_DELAY_Time() >= 200000) { /* Reset time */ TM_DELAY_SetTime(0); /* Toggle leds */ TM_DISCO_LedToggle(LED_GREEN); /* Increase counter */ i++; /* After 20 toggles, put STM32F4 into sleep mode */ if (i == 20) { /* Reset counter */ i = 0; /* Sleep until interrupt occur */ /* Also disable systick with "1" as parameter */ /* Because systick makes interrupts and it will wakeup */ /* device back after some ticks. This is useless */ /* If you set parameter to "0", then this function will not */ /* affect to Systick timer */ TM_LOWPOWER_SleepUntilInterrupt(1); /* Toggle RED LED to indicate wakeup from sleep mode */ TM_DISCO_LedToggle(LED_RED); } } } }
int main(void) { uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize LEDS */ TM_DISCO_LedInit(); /* Initialize RTC with internal clock */ TM_RTC_Init(TM_RTC_ClockSource_Internal); /* Set RTC to generate wakeup interrupt every 10 seconds */ TM_RTC_Interrupts(TM_RTC_Int_10s); /* Set time to 0 */ TM_DELAY_SetTime(0); while (1) { /* Toggle LEDs every 200ms */ if (TM_DELAY_Time() >= 200) { /* Reset time */ TM_DELAY_SetTime(0); /* Toggle leds */ TM_DISCO_LedToggle(LED_GREEN); /* Increase counter */ i++; /* After 20 toggles, put STM32F4 into STOP mode */ if (i == 20) { /* Reset counter */ i = 0; /* Stop STM32F4 */ /* If you stop device, then you can wake him up with interrupt/event on EXTI line */ /* Put it into STOP mode, allowing EXTI interrupts to wake him up */ /* RTC will wake him up after 10 seconds */ TM_LOWPOWER_StopUntilInterrupt(); /* Toggle RED LED to indicate wakeup from stop mode */ TM_DISCO_LedToggle(LED_RED); } } } }
int main(void) { /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize onboard leds */ TM_DISCO_LedInit(); /* Reset counter to 0 */ TM_DELAY_SetTime(0); while (1) { /* If time is more than 500ms */ if (TM_DELAY_Time() >= 500) { /* Reset time */ TM_DELAY_SetTime(0); /* Toggle leds here */ TM_DISCO_LedToggle(LED_RED | LED_GREEN); } /* Place your code here */ /* Code here will be checked without any delay */ /* Constantly */ } }
int main(void) { char str[100]; TM_DS1307_Time_t time; uint8_t last; /* Initialize system */ SystemInit(); /* Initialize LEDS */ TM_DISCO_LedInit(); /* Initialize ILI9341 LCD on board */ TM_ILI9341_Init(); TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); TM_ILI9341_Puts(90, 310, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Initialize DS1307 */ if (TM_DS1307_Init() != TM_DS1307_Result_Ok) { /* Red LED on */ TM_DISCO_LedOn(LED_RED); /* Show on LCD */ TM_ILI9341_Puts(10, 10, "DS1307 Error", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); while (1); } /* Set date and time */ /* Day 7, 26th May 2014, 02:05:00 */ time.hours = 21; time.minutes = 18; time.seconds = 0; time.date = 26; time.day = 1; time.month = 5; time.year = 14; TM_DS1307_SetDateTime(&time); /* Disable output first */ TM_DS1307_DisableOutputPin(); /* Set output pin to 4096 Hz */ TM_DS1307_EnableOutputPin(TM_DS1307_OutputFrequency_4096Hz); while (1) { /* Get date and time */ TM_DS1307_GetDateTime(&time); /* Display on LCD */ sprintf(str, "Day: %d\nDate: %02d\nMonth: %02d\nYear: %04d\nHours: %02d\nMinutes: %02d\nSeconds: %02d", time.day, time.date, time.month, time.year + 2000, time.hours, time.minutes, time.seconds); TM_ILI9341_Puts(10, 15, str, &TM_Font_11x18, ILI9341_COLOR_ORANGE, 0x0000); /* Toggle GREEN led if needed */ if (last != time.seconds) { last = time.seconds; /* Toggle GREEN LED */ TM_DISCO_LedToggle(LED_GREEN); } } }
/* Handle all EXTI lines */ void TM_EXTI_Handler(uint16_t GPIO_Pin) { /* Check proper line */ if (GPIO_Pin == TM_DISCO_BUTTON_PIN) { /* Toggle pin only if button is pressed */ if (TM_DISCO_ButtonPressed()) { /* Toggle LEDs if interrupt on button line happens */ TM_DISCO_LedToggle(LED_ALL); } } }
int main(void) { uint16_t values[2] = {0, 0}; /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init button */ TM_DISCO_ButtonInit(); /* Init DAC channel 1 = PA4 */ TM_DAC_Init(TM_DAC_Channel_1); /* Init DAC channel 2 = PA5 */ TM_DAC_Init(TM_DAC_Channel_2); while (1) { /* Toggle ALL leds */ if (TM_DELAY_Time() > 200) { /* Toggle leds */ TM_DISCO_LedToggle(LED_ALL); } /* Increase channel 1 value */ values[0]++; /* Decrease channel 2 value */ values[1]--; /* Check if channel 1 is overflowed 12 bit and set it to zero */ if (values[0] > 0x0FFF) { values[0] = 0; } /* Check if channel 2 is less than zero (overflow to 0xFFFF) and set to to max 12 bit value */ if (values[1] > 0x0FFF) { values[1] = 0x0FFF; } /* Set DAC channel 1 = PA4 */ TM_DAC_SetValue(TM_DAC_Channel_1, values[0]); /* Set DAC channel 2 = PA5 */ TM_DAC_SetValue(TM_DAC_Channel_2, values[1]); /* Delay 1ms */ Delayms(1); } }
void TM_EXTI_Handler(uint16_t GPIO_Pin) { /* Handle external line 0 interrupts */ if (GPIO_Pin == GPIO_Pin_0) { /* Toggle RED led */ TM_DISCO_LedToggle(LED_RED); /* Check counter */ if (++counter >= 10) { /* Detach external interrupt for GPIO_Pin_0 no matter on which GPIOx is connected */ TM_EXTI_Detach(GPIO_Pin_0); } } /* Handle external line 13 interrupts */ if (GPIO_Pin == GPIO_Pin_13) { /* Toggle GREEN led */ TM_DISCO_LedToggle(LED_GREEN); /* Check counter */ if (++counter >= 10) { /* Detach external interrupt for GPIO_Pin_0 no matter on which GPIOx is connected */ TM_EXTI_Detach(GPIO_Pin_13); } } }
int main(void) { __IO uint32_t i; /* CPU load structure */ TM_CPULOAD_t CPU_LOAD; /* Init CPU load monitor */ TM_CPULOAD_Init(&CPU_LOAD); /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds on board */ TM_DISCO_LedInit(); /* Init button */ TM_DISCO_ButtonInit(); /* Init USART2, TX: PA2, RX: PA3, 921600 bauds */ TM_USART_Init(USART2, TM_USART_PinsPack_1, 921600); while (1) { /* Check if CPU LOAD variable is updated */ if (CPU_LOAD.Updated) { /* Print to user */ printf("W: %u; S: %u; Load: %5.2f\n", CPU_LOAD.WCNT, CPU_LOAD.SCNT, CPU_LOAD.Load); } /* Toggle leds */ TM_DISCO_LedToggle(LED_ALL); /* If button pressed, do some useless counting */ if (TM_DISCO_ButtonPressed()) { /* Count something to waste some time before entering to sleep mode */ i = 0; while (i++ < 0x1FFF); } /* Go low power mode, sleep mode until interrupt, measure CPU load */ TM_CPULOAD_GoToSleepMode(&CPU_LOAD, TM_LOWPOWERMODE_SleepUntilInterrupt); } }
/* Called on wakeup interrupt */ void TM_RTC_RequestHandler() { /* Get time */ TM_RTC_GetDateTime(&datatime, TM_RTC_Format_BIN); /* Format time */ sprintf(buf, "%02d.%02d.%04d %02d:%02d:%02d Unix: %u\n", datatime.date, datatime.month, datatime.year + 2000, datatime.hours, datatime.minutes, datatime.seconds, datatime.unix ); /* Send to USART */ TM_USART_Puts(USART3, buf); /* Toggle LED */ TM_DISCO_LedToggle(LED_RED | LED_GREEN); }
int main(void) { //Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize onboard leds */ TM_DISCO_LedInit(); while (1) { /* Toggle leds */ TM_DISCO_LedToggle(LED_GREEN); /* Delay 500ms */ Delayms(500); /* Delay 500 us */ //Delay(500); } }
int main(void) { uint16_t write, read; uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds */ // TM_DISCO_LedInit(); /* Initialize SDRAM */ if (TM_SDRAM_Init()) { // TM_DISCO_LedOn(LED_GREEN); } else { // TM_DISCO_LedOn(LED_RED); } /* Some delay */ Delayms(2000); write = 1234; /* Write 16bit value to SDRAM at location 0x3214 */ TM_SDRAM_Write16(0x3214, write); /* Read from location 0x3214 */ read = TM_SDRAM_Read16(0x3214); /* Check if read data is the same as written data */ if (write == read) { TM_DISCO_LedOff(LED_GREEN | LED_RED); /* Blink leds to indicate that reading and writing was correct */ for (i = 0; i < 10; i++) { TM_DISCO_LedToggle(LED_GREEN | LED_RED); Delayms(100); } } while (1) { } }
int main(void) { /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init button */ TM_DISCO_ButtonInit(); while (1) { /* Toggle leds */ TM_DISCO_LedToggle(LED_ALL); /* Delay 500ms */ Delayms(500); } }
int main(void) { /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds on board */ TM_DISCO_LedInit(); /* Turn on all leds */ TM_DISCO_LedOn(LED_ALL); /* Delay 2 seconds */ Delayms(2000); while (1) { /* Toggle leds */ TM_DISCO_LedToggle(LED_ALL); /* Wait 500ms */ Delayms(500); } }
int main(void) { /* Init system clock for maximum system speed */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); while (1) { /* Each 500ms */ if (TM_DELAY_Time() >= 500) { /* Reset time */ TM_DELAY_SetTime(0); /* Toggle LED */ TM_DISCO_LedToggle(LED_ALL); } } }
int main(void) { /* Init system */ TM_RCC_InitSystem(); /* Init HAL layer */ HAL_Init(); /* Timer Init for SysTick */ timer_start(); /* Init leds */ TM_DISCO_LedInit(); /* Init delay */ TM_DELAY_Init(); /* Init USB peripheral */ TM_USB_Init(); /* Init VCP on FS port.. */ TM_USBD_CDC_Init(TM_USB_FS); /* Start USB device mode on FS port.. */ TM_USBD_Start(TM_USB_FS); while (1) { /* Process USB CDC device, send remaining data if needed */ /* It is better if you call this in periodic timer, like each ms in SYSTICK handler */ TM_USBD_CDC_Process(TM_USB_FS); /* Check if device is ready, if drivers are installed if needed on FS port */ if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) { TM_DISCO_LedOn(LED_GREEN); } else { TM_DISCO_LedOff(LED_GREEN); } /* Check if user has changed parameter for COM port */ TM_USBD_CDC_GetSettings(TM_USB_FS, &USB_FS_Settings); /* Check if updated */ if (USB_FS_Settings.Updated) { /* Update settings for UART here if needed */ TM_USBD_CDC_Puts(TM_USB_FS, "USB FS settings changed!\n"); } /* Check if anything received on FS port */ if (TM_USBD_CDC_Getc(TM_USB_FS, &ch)) { /* One character received */ /* Send it back */ /* TM_USBD_CDC_Putc(TM_USB_FS, ch); */ /* Control LEDs based on input (debug) */ switch(ch){ case '1': TM_DISCO_LedToggle(LED_BLUE); break; case '2': TM_DISCO_LedToggle(LED_ORANGE); TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Orange LED\n"); break; case '3': TM_DISCO_LedToggle(LED_RED); TM_USBD_CDC_Puts(TM_USB_FS, "Toggling Red LED\n"); break; case '4': TM_DISCO_LedToggle(LED_GREEN); break; case '5': /* Transfer Sample Audio */ trace_puts("Sending Audio Sample"); /* For now, send entire sample audio data */ /* TODO get size of sample to be transfered from serial port */ /* at 115k BAUD 800 bytes is sub 10 msec total transfer time */ for(int i = 0; i < SAMPLEAUDIO_SIZE;i++) { /* Need to split 16 bit samples into upper and lower bytes */ /* Note that these will need to be reconstructed in the * processing script. Updated Buffer size to 1024 from 256 in * USBD_CDC library file for this operation. */ /* Send MSB first */ TM_USBD_CDC_Putc(TM_USB_FS, Hi(SampleAudio[i])); trace_putchar((int)Hi(SampleAudio[i])); /* Then Send LSB */ TM_USBD_CDC_Putc(TM_USB_FS, Lo(SampleAudio[i])); trace_putchar((int)Lo(SampleAudio[i])); } break; default: break; } } //Wait for next system tick while (g_SysTick_Flag == 0){}; g_SysTick_Flag = 0; TM_DISCO_LedToggle(LED_BLUE); } }
int main(void) { BUTTON_Handle hButton, hB1, hB2, hB3, hB4; PROGBAR_Handle hProgbar; uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay functions */ TM_DELAY_Init(); /* Initialize LEDs */ TM_DISCO_LedInit(); /* Initialize emWin */ if (TM_EMWIN_Init() != TM_EMWIN_Result_Ok) { /* Initialization error */ while (1) { /* Toggle RED led */ TM_DISCO_LedToggle(LED_RED); /* Delay */ Delayms(100); } } /* Create progress bar at location x = 10, y = 10, length = 219, height = 30 */ hProgbar = PROGBAR_CreateEx(10, 10, 219, 30, 0, WM_CF_SHOW, 0, GUI_ID_PROGBAR0); /* Set progress bar font */ PROGBAR_SetFont(hProgbar, &GUI_Font8x16); /* Set progress bar text */ PROGBAR_SetText(hProgbar, "LOADING..Please wait.."); /* Imitate loading */ for (i = 1; i <= 100; i++) { /* Set bar */ PROGBAR_SetValue(hProgbar, i); /* Little delay, update value on LCD */ GUI_Delay(20); } /* Create button with GUI_ID_OK ID number */ hButton = BUTTON_CreateEx(10, 50, 219, 30, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON0); /* Set text and font */ BUTTON_SetText(hButton, "Click me to continue.."); BUTTON_SetFont(hButton, &GUI_Font8x15B_ASCII); /* Execute, show button */ GUI_Exec(); /* Wait till button pressed */ while (1) { /* Check if button was pressed */ if (GUI_GetKey() == GUI_ID_BUTTON0) { /* Led Off */ TM_DISCO_LedOff(LED_GREEN); /* Stop while loop */ break; } /* Toggle green led */ TM_DISCO_LedToggle(LED_GREEN); /* Delay 100ms */ GUI_Delay(100); } /* Delete button functionality */ BUTTON_Delete(hButton); /* Delete button from LCD */ GUI_ClearRect(10, 50, 269, 90); /* Create buttons for leds control */ hB1 = BUTTON_CreateEx(10, 90, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON1); hB2 = BUTTON_CreateEx(124, 90, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON2); hB3 = BUTTON_CreateEx(10, 150, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON3); hB4 = BUTTON_CreateEx(124, 150, 105, 50, 0, WM_CF_SHOW, 0, GUI_ID_BUTTON4); /* Set font for buttons */ BUTTON_SetFont(hB1, &GUI_Font13HB_ASCII); BUTTON_SetFont(hB2, &GUI_Font13HB_ASCII); BUTTON_SetFont(hB3, &GUI_Font13HB_ASCII); BUTTON_SetFont(hB4, &GUI_Font13HB_ASCII); /* Set button text */ BUTTON_SetText(hB1, "GREEN on"); BUTTON_SetText(hB2, "GREEN off"); BUTTON_SetText(hB3, "RED on"); BUTTON_SetText(hB4, "RED off"); /* Button styling */ /* Background color when button is not pressed */ BUTTON_SetBkColor(hB1, BUTTON_CI_UNPRESSED, GUI_DARKGREEN); /* Background color when button is pressed */ BUTTON_SetBkColor(hB1, BUTTON_CI_PRESSED, GUI_GREEN); /* Background color when button is not pressed */ BUTTON_SetBkColor(hB3, BUTTON_CI_UNPRESSED, GUI_DARKRED); /* Background color when button is pressed */ BUTTON_SetBkColor(hB3, BUTTON_CI_PRESSED, GUI_RED); /* Show buttons */ GUI_Exec(); while (1) { /* Get pressed key */ switch (GUI_GetKey()) { case GUI_ID_BUTTON1: /* Button 1 pressed */ TM_DISCO_LedOn(LED_GREEN); break; case GUI_ID_BUTTON2: /* Button 2 pressed */ TM_DISCO_LedOff(LED_GREEN); break; case GUI_ID_BUTTON3: /* Button 3 pressed */ TM_DISCO_LedOn(LED_RED); break; case GUI_ID_BUTTON4: /* Button 4 pressed */ TM_DISCO_LedOff(LED_RED); break; default: break; } } }
int main(void) { TM_KEYPAD_Button_t Keypad_Button; char buff[20]; /* Initialize system */ SystemInit(); /* Initialize leds */ TM_DISCO_LedInit(); /* Initialize USART 1, TX: PB6 */ TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200); /* Initialize matrix keyboard */ TM_KEYPAD_Init(TM_KEYPAD_Type_Large); while (1) { /* Read keyboard data */ Keypad_Button = TM_KEYPAD_Read(); /* Keypad was pressed */ if (Keypad_Button != TM_KEYPAD_Button_NOPRESSED) {/* Keypad is pressed */ switch (Keypad_Button) { case TM_KEYPAD_Button_0: /* Button 0 pressed */ TM_DISCO_LedToggle(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE); break; case TM_KEYPAD_Button_1: /* Button 1 pressed */ TM_DISCO_LedOn(LED_GREEN); break; case TM_KEYPAD_Button_2: /* Button 2 pressed */ TM_DISCO_LedOff(LED_GREEN); break; case TM_KEYPAD_Button_3: /* Button 3 pressed */ TM_DISCO_LedOn(LED_RED); break; case TM_KEYPAD_Button_4: /* Button 4 pressed */ TM_DISCO_LedOff(LED_RED); break; case TM_KEYPAD_Button_5: /* Button 5 pressed */ TM_DISCO_LedOn(LED_ORANGE); break; case TM_KEYPAD_Button_6: /* Button 6 pressed */ TM_DISCO_LedOff(LED_ORANGE); break; case TM_KEYPAD_Button_7: /* Button 7 pressed */ TM_DISCO_LedOn(LED_BLUE); break; case TM_KEYPAD_Button_8: /* Button 8 pressed */ TM_DISCO_LedOff(LED_BLUE); break; case TM_KEYPAD_Button_9: /* Button 9 pressed */ /* Do your stuff here */ break; case TM_KEYPAD_Button_STAR: /* Button STAR pressed */ TM_DISCO_LedOn(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE); break; case TM_KEYPAD_Button_HASH: /* Button HASH pressed */ TM_DISCO_LedOff(LED_GREEN | LED_RED | LED_BLUE | LED_ORANGE); break; case TM_KEYPAD_Button_A: /* Button A pressed, only on large keyboard */ /* Do your stuff here */ break; case TM_KEYPAD_Button_B: /* Button B pressed, only on large keyboard */ /* Do your stuff here */ break; case TM_KEYPAD_Button_C: /* Button C pressed, only on large keyboard */ /* Do your stuff here */ break; case TM_KEYPAD_Button_D: /* Button D pressed, only on large keyboard */ /* Do your stuff here */ break; default: break; } sprintf(buff, "Pressed: %u us\n", (uint8_t)Keypad_Button); TM_USART_Puts(USART1, buff); } } }
int main(void) { uint8_t i; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize LEDS */ TM_DISCO_LedInit(); /* Checks if reset was because of wakeup from standby */ if (TM_LOWPOWER_StandbyReset()) { for (i = 0; i < 10; i++) { /* Toggle LED red to indicate this */ TM_DISCO_LedToggle(LED_RED); /* Delay */ Delayms(100); } } /* Initialize RTC with internal clock */ TM_RTC_Init(TM_RTC_ClockSource_Internal); /* Set RTC to generate wakeup interrupt every 10 seconds */ TM_RTC_Interrupts(TM_RTC_Int_10s); /* Enable wakeup pin, PA0 */ TM_LOWPOWER_EnableWakeUpPin(); /* Set time to 0 */ TM_DELAY_SetTime(0); while (1) { /* Toggle LEDs every 200ms */ if (TM_DELAY_Time() >= 200) { /* Reset time */ TM_DELAY_SetTime(0); /* Toggle leds */ TM_DISCO_LedToggle(LED_GREEN); /* Increase counter */ i++; /* After 20 toggles, put STM32F4 into STANDBY mode */ if (i == 20) { /* Reset counter */ i = 0; /* Put STM32F4 into standby mode */ /* You can wake up MCU with rising edge on PA0 pin */ /* Or with some special interrupts, like RTC, etc */ TM_LOWPOWER_Standby(); /* Toggle RED LED to indicate wakeup from STANDBY mode */ /* This should never happen, because STM32F4 will reset after wakeup from STANDBY */ TM_DISCO_LedToggle(LED_RED); } } } }
int main(void) { //TM_STMPE811_TouchData instance TM_STMPE811_TouchData touchData; //TM_ILI9341_Button_t instance TM_ILI9341_Button_t button; int8_t buttonPressed, button1, button2, button3; char str[30]; //Initialize system SystemInit(); //Initialize onboard leds TM_DISCO_LedInit(); //Initialize LCD TM_ILI9341_Init(); //Fill LCD with gray color TM_ILI9341_Fill(ILI9341_COLOR_GRAY); //Select orientation TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); //Select touch screen orientation touchData.orientation = TM_STMPE811_Orientation_Portrait_2; //Initialize Touch TM_STMPE811_Init(); //Button 1, default configuration //Red with black border and black font 11x18 button.x = 10; button.y = 30; button.width = 219; button.height = 50; button.background = ILI9341_COLOR_RED; button.borderColor = ILI9341_COLOR_BLACK; button.label = "Button 1"; button.color = ILI9341_COLOR_BLACK; button.font = &TM_Font_11x18; //Add button button1 = TM_ILI9341_Button_Add(&button); //Button with custom background and without label button.x = 10; button.y = 260; button.width = 105; button.height = 50; button.background = ILI9341_COLOR_GREEN; button.borderColor = ILI9341_COLOR_BLACK; button.label = "Button 2"; //Use background image and no label button.flags = TM_BUTTON_FLAG_NOLABEL | TM_BUTTON_FLAG_IMAGE; button.color = ILI9341_COLOR_BLACK; button.font = &TM_Font_11x18; button.image = buttonBackground; //Variable stored in //Add button button2 = TM_ILI9341_Button_Add(&button); //Button with custom background and with label and without border and 7x10 fontsize button.x = 125; button.y = 260; button.background = ILI9341_COLOR_BLUE2; button.borderColor = ILI9341_COLOR_BLACK; button.label = "Button 3"; button.color = ILI9341_COLOR_BLACK; button.font = &TM_Font_7x10; button.flags = TM_BUTTON_FLAG_IMAGE | TM_BUTTON_FLAG_NOBORDER; //Use background image, without border //Add button button3 = TM_ILI9341_Button_Add(&button); if (!TM_DISCO_LedIsOn(LED_RED)) { //If led res is turned off, disable buttons 2 and 3 TM_ILI9341_Button_Disable(button2); TM_ILI9341_Button_Disable(button3); TM_ILI9341_Puts(25, 220, "Buttons disabled!", &TM_Font_11x18, ILI9341_COLOR_RED, ILI9341_COLOR_GRAY); } //Draw buttons TM_ILI9341_Button_DrawAll(); //Draw some strings TM_ILI9341_Puts(45, 245, "LED on LED off", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_GRAY); TM_ILI9341_Puts(10, 100, "Bottom buttons work\nonly if red led is turned on.\nYou can toggle red\nled with Button 1.", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_GRAY); while (1) { if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) { buttonPressed = TM_ILI9341_Button_Touch(&touchData); if (buttonPressed >= 0) { //Any button pressed sprintf(str, "Pressed: Button %d", (buttonPressed + 1)); } else { sprintf(str, "Press the button "); } if (buttonPressed == button1) { //Red button 1 is pressed, toggle led TM_DISCO_LedToggle(LED_RED); if (TM_DISCO_LedIsOn(LED_RED)) { //If led is turned on, enable button 2 and button 3 TM_ILI9341_Button_Enable(button2); TM_ILI9341_Button_Enable(button3); TM_ILI9341_Puts(25, 220, "Buttons enabled! ", &TM_Font_11x18, ILI9341_COLOR_GREEN, ILI9341_COLOR_GRAY); } else { //otherwise disable both TM_ILI9341_Button_Disable(button2); TM_ILI9341_Button_Disable(button3); TM_ILI9341_Puts(25, 220, "Buttons disabled!", &TM_Font_11x18, ILI9341_COLOR_RED, ILI9341_COLOR_GRAY); } } else if (buttonPressed == button2) { //If button 2 is pressed, turn green led on TM_DISCO_LedOn(LED_GREEN); } else if (buttonPressed == button3) { //if button 3 is pressed, turn green led off TM_DISCO_LedOff(LED_GREEN); } } TM_ILI9341_Puts(10, 5, str, &TM_Font_11x18, ILI9341_COLOR_GREEN, ILI9341_COLOR_GRAY); } }
/* Handle CGI request for LEDS */ const char* LEDS_CGI_Handler(int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) { uint8_t i; /* This function handles request like one below: */ /* /ledaction.cgi?ledtoggle=1&ledoff=2 */ /* This will toggle LED 1 and turn off LED 2 */ /* Callback */ if (iIndex == 0) { /* Go through all params */ for (i = 0; i < iNumParams; i++) { /* If current pair = ledtoggle=someled */ if (strstr(pcParam[i], "ledtoggle")) { /* Switch first character */ switch (pcValue[i][0]) { case '1': TM_DISCO_LedToggle(LED_GREEN); break; case '2': TM_DISCO_LedToggle(LED_ORANGE); break; case '3': TM_DISCO_LedToggle(LED_RED); break; case '4': TM_DISCO_LedToggle(LED_BLUE); break; default: break; } } else if (strstr(pcParam[i], "ledon")) { switch (pcValue[i][0]) { case '1': TM_DISCO_LedOn(LED_GREEN); break; case '2': TM_DISCO_LedOn(LED_ORANGE); break; case '3': TM_DISCO_LedOn(LED_RED); break; case '4': TM_DISCO_LedOn(LED_BLUE); break; default: break; } } else if (strstr(pcParam[i], "ledoff")) { switch (pcValue[i][0]) { case '1': TM_DISCO_LedOff(LED_GREEN); break; case '2': TM_DISCO_LedOff(LED_ORANGE); break; case '3': TM_DISCO_LedOff(LED_RED); break; case '4': TM_DISCO_LedOff(LED_BLUE); break; default: break; } } } } /* Return URL to be used after call */ return "/index.shtml"; }
int main(void) { /* Variables used */ TM_GPS_Data_t GPS_Data; TM_GPS_Result_t result, current; TM_GPS_Float_t GPS_Float; TM_GPS_Distance_t GPS_Distance; char buffer[40]; uint8_t i; float temp; uint8_t iOff; /* Initialize system */ SystemInit(); /* Delay init */ TM_DELAY_Init(); /* Initialize leds */ TM_DISCO_LedInit(); /* Initialize GPS on 115200 baudrate */ TM_GPS_Init(&GPS_Data, 115200); /* Initialize ili9341 LCD on STM32F429-Discovery board */ TM_ILI9341_Init(); /* Rotate LCD */ TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Go to the begginning of LCD */ iOff = 0; /* Version 1.1 added */ /* Set two test coordinates */ /* from Ljubljana */ GPS_Distance.Latitude1 = 46.050513; GPS_Distance.Longitude1 = 14.512873; /* to New York */ GPS_Distance.Latitude2 = 40.711096; GPS_Distance.Longitude2 = -74.007529; /* Display location */ TM_ILI9341_Puts(10, START_Y + 11 * iOff++, "Ljubljana -> New York", &TM_Font_7x10, 0x0000, 0xFFFF); /* Calculate distance and bearing between 2 pointes */ TM_GPS_DistanceBetween(&GPS_Distance); /* Convert float number */ TM_GPS_ConvertFloat(GPS_Distance.Distance, &GPS_Float, 1); sprintf(buffer, " - Distance: %d.%1d meters", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); TM_GPS_ConvertFloat(GPS_Distance.Bearing, &GPS_Float, 3); sprintf(buffer, " - Bearing: %d.%03d degrees", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Delay 5s */ Delayms(5000); /* Clear screen */ TM_ILI9341_Fill(0xFFFF); /* Go to the begginning of LCD */ iOff = 0; /* Reset counter */ TM_DELAY_SetTime(0); while (1) { /* Update GPR data */ /* Call this as faster as possible */ result = TM_GPS_Update(&GPS_Data); /* If we didn't receive any useful data in the start */ if (result == TM_GPS_Result_FirstDataWaiting && TM_DELAY_Time() > 3000) { /* If we didn't receive nothing within 3 seconds */ TM_DELAY_SetTime(0); /* Display data on LCD */ TM_ILI9341_Puts(10, START_Y + 11 * iOff++, "Check your GPS receiver!", &TM_Font_7x10, 0x0000, 0xFFFF); } /* If we have any unread data */ if (result == TM_GPS_Result_NewData) { /* We received new packet of useful data from GPS */ current = TM_GPS_Result_NewData; /* Go to the begginning of LCD */ iOff = 0; /* Is GPS signal valid? */ if (GPS_Data.Validity) { /* If you want to make a GPS tracker, now is the time to save your data on SD card */ /* Toggle GREEN LED */ TM_DISCO_LedToggle(LED_GREEN); /* We have valid GPS signal */ #ifndef GPS_DISABLE_GPGGA /* Latitude */ /* Convert float to integer and decimal part, with 6 decimal places */ TM_GPS_ConvertFloat(GPS_Data.Latitude, &GPS_Float, 6); sprintf(buffer, " - Latitude: %d.%d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Longitude */ /* Convert float to integer and decimal part, with 6 decimal places */ TM_GPS_ConvertFloat(GPS_Data.Longitude, &GPS_Float, 6); sprintf(buffer, " - Longitude: %d.%d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Satellites in use */ sprintf(buffer, " - Sats in use: %02d", GPS_Data.Satellites); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Current time */ sprintf(buffer, " - UTC Time: %02d.%02d.%02d:%02d", GPS_Data.Time.Hours, GPS_Data.Time.Minutes, GPS_Data.Time.Seconds, GPS_Data.Time.Hundredths); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Fix: 0 = invalid, 1 = GPS, 2 = DGPS */ sprintf(buffer, " - Fix: %d", GPS_Data.Fix); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Altitude */ /* Convert float to integer and decimal part, with 6 decimal places */ TM_GPS_ConvertFloat(GPS_Data.Altitude, &GPS_Float, 6); sprintf(buffer, " - Altitude: %3d.%06d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); #endif #ifndef GPS_DISABLE_GPRMC /* Current date */ sprintf(buffer, " - Date: %02d.%02d.%04d", GPS_Data.Date.Date, GPS_Data.Date.Month, GPS_Data.Date.Year + 2000); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Current speed in knots */ TM_GPS_ConvertFloat(GPS_Data.Speed, &GPS_Float, 6); sprintf(buffer, " - Speed in knots: %2d.%06d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Current speed in km/h */ temp = TM_GPS_ConvertSpeed(GPS_Data.Speed, TM_GPS_Speed_KilometerPerHour); TM_GPS_ConvertFloat(temp, &GPS_Float, 6); sprintf(buffer, " - Speed in km/h: %2d.%06d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); TM_GPS_ConvertFloat(GPS_Data.Direction, &GPS_Float, 3); sprintf(buffer, " - Direction: %3d.%03d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); #endif #ifndef GPS_DISABLE_GPGSA /* Horizontal dilution of precision */ TM_GPS_ConvertFloat(GPS_Data.HDOP, &GPS_Float, 2); sprintf(buffer, " - HDOP: %2d.%02d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Vertical dilution of precision */ TM_GPS_ConvertFloat(GPS_Data.VDOP, &GPS_Float, 2); sprintf(buffer, " - VDOP: %2d.%02d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Position dilution of precision */ TM_GPS_ConvertFloat(GPS_Data.PDOP, &GPS_Float, 2); sprintf(buffer, " - PDOP: %2d.%02d", GPS_Float.Integer, GPS_Float.Decimal); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Current fix mode in use */ sprintf(buffer, " - Fix mode: %d", GPS_Data.FixMode); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); /* Display IDs of satellites in use */ sprintf(buffer, "Sats ids: "); for (i = 0; i < GPS_Data.Satellites; i++) { if (i < (GPS_Data.Satellites - 1)) { sprintf(buffer, "%s%d,", buffer, GPS_Data.SatelliteIDs[i]); } else { sprintf(buffer, "%s%d", buffer, GPS_Data.SatelliteIDs[i]); } } TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); #endif #ifndef GPS_DISABLE_GPGSV /* Satellites in view */ sprintf(buffer, " - Satellites in view: %02d", GPS_Data.SatellitesInView); TM_ILI9341_Puts(10, START_Y + 11 * iOff++, buffer, &TM_Font_7x10, 0x0000, 0xFFFF); #endif } else { /* Clear screen */ if (iOff > 0) { iOff = 0; TM_ILI9341_Fill(0xFFFF); } /* Go to the beginning of LCD */ iOff = 0; /* Toggle RED LED */ TM_DISCO_LedToggle(LED_RED); /* GPS signal is not valid */ TM_ILI9341_Puts(10, START_Y + 11 * iOff, "New received data haven't valid GPS signal!", &TM_Font_7x10, 0x0000, 0xFFFF); } } else if (result == TM_GPS_Result_FirstDataWaiting && current != TM_GPS_Result_FirstDataWaiting) { current = TM_GPS_Result_FirstDataWaiting; TM_ILI9341_Puts(10, START_Y + 11 * iOff++, "Waiting first data from GPS!", &TM_Font_7x10, 0x0000, 0xFFFF); } else if (result == TM_GPS_Result_OldData && current != TM_GPS_Result_OldData) { current = TM_GPS_Result_OldData; /* We already read data, nothing new was received from GPS */ } } }