int main(void) { /* Initialize system */ SystemInit(); /* Initialize ILI9341 */ TM_ILI9341_Init(); /* Rotate LCD for 90 degrees */ TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_2); /* Fill lcd with color */ TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA); /* Draw white circle */ TM_ILI9341_DrawCircle(60, 60, 40, ILI9341_COLOR_GREEN); /* Draw red filled circle */ TM_ILI9341_DrawFilledCircle(60, 60, 35, ILI9341_COLOR_RED); /* Draw blue rectangle */ TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE); /* Draw black filled circle */ TM_ILI9341_DrawFilledRectangle(130, 30, 210, 90, ILI9341_COLOR_BLACK); /* Draw line with custom color 0x0005 */ TM_ILI9341_DrawLine(10, 120, 310, 120, 0x0005); /* Put string with black foreground color and blue background with 11x18px font */ TM_ILI9341_Puts(65, 130, "STM32F4 Discovery", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); /* Put string with black foreground color and blue background with 11x18px font */ TM_ILI9341_Puts(60, 150, "ILI9341 LCD Module", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); /* Put string with black foreground color and red background with 11x18px font */ TM_ILI9341_Puts(45, 229, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); while (1) { } }
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); } } }
int main(void) { /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize ILI9341 with LTDC */ /* By default layer 1 is used */ TM_ILI9341_Init(); /* Rotate LCD for 90 degrees */ TM_ILI9341_Rotate(TM_ILI9341_Orientation_Landscape_2); TM_ILI9341_SetLayer1(); /* Fill data on layer 1 */ TM_ILI9341_Fill(ILI9341_COLOR_WHITE); /* Show text */ TM_ILI9341_Puts(65, 30, "Layer 1", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); TM_ILI9341_Puts(20, 130, "STM32F429 Discovery ONLY!", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); TM_ILI9341_Puts(60, 150, "ILI9341 LCD Module", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); TM_ILI9341_Puts(70, 170, "with LTDC support", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); TM_ILI9341_Puts(170, 230, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Go to layer 2 */ TM_ILI9341_SetLayer2(); /* Fill data on layer 2 */ TM_ILI9341_Fill(ILI9341_COLOR_GREEN2); /* Show text */ TM_ILI9341_Puts(65, 30, "Layer 2", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE); TM_ILI9341_Puts(20, 130, "STM32F429 Discovery ONLY!", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); TM_ILI9341_Puts(60, 150, "ILI9341 LCD Module", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); TM_ILI9341_Puts(70, 170, "with LTDC support", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2); TM_ILI9341_Puts(170, 230, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Draw circle on layer 2 */ TM_ILI9341_DrawCircle(150, 150, 140, ILI9341_COLOR_BLACK); while (1) { /* This will set opacity of one layer to 0, other to max (255) each time */ /* This is like toggle function */ TM_ILI9341_ChangeLayers(); Delayms(500); /* //Bottom code works the same as one before inside while loop //Turn on Layer1 and turn off Layer2 TM_ILI9341_SetLayer1Opacity(255); TM_ILI9341_SetLayer2Opacity(0); Delayms(500); //Turn on Layer2 and turn off Layer1 TM_ILI9341_SetLayer1Opacity(0); TM_ILI9341_SetLayer2Opacity(255); Delayms(500); */ } }
int test_exi(void) { /* Initialize system */ SystemInit(); /* Initialize LEDS */ TM_DISCO_LedInit(); //Initialize LCD TM_ILI9341_Init(); //Fill with orange color TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); //Rotate LCD TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Attach interrupt on pin PA0 = External line 0 */ /* Button connected on discovery boards */ if (TM_EXTI_Attach(GPIOA, GPIO_Pin_0, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) { TM_DISCO_LedOn(LED_RED); } /* Attach interrupt on pin PC13 = External line 13 */ /* Button connected on nucleo boards */ if (TM_EXTI_Attach(GPIOC, GPIO_Pin_13, TM_EXTI_Trigger_Falling) == TM_EXTI_Result_Ok) { TM_DISCO_LedOn(LED_GREEN); } while (1) { } }
int main(void) { /* Set coordinates for poly line */ TM_DMA2DRAPHIC_Poly_t Coordinates[] = { {10, 10}, {15, 65}, {200, 200}, {150, 30}, {10, 10} }; /* Initialize system */ SystemInit(); /* Initialize delay functions */ TM_DELAY_Init(); /* Initialize ILI9341 with LTDC */ /* By default layer 1 is used */ TM_ILI9341_Init(); /* Initialize DMA2D GRAPHIC library */ TM_DMA2DGRAPHIC_Init(); /* Set ILI9341 Orientation */ TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Set DMA2D GRAPHIC library Orientation */ TM_DMA2DGRAPHIC_SetOrientation((uint8_t)TM_ILI9341_Orientation_Portrait_2); /* Layer 1 */ /* Draw red rectangle at X = 10, Y = 10 position, width = 100 and height = 50px */ TM_DMA2DGRAPHIC_DrawRectangle(10, 10, 100, 50, GRAPHIC_COLOR_RED); /* Draw filled blue rectangle at X = 100, Y = 100 position, width = 100 and height = 50px */ TM_DMA2DGRAPHIC_DrawFilledRectangle(100, 100, 100, 50, GRAPHIC_COLOR_BLUE); /* Draw rounded rectangle */ TM_DMA2DGRAPHIC_DrawRoundedRectangle(110, 110, 80, 30, 10, GRAPHIC_COLOR_GREEN); /* Go to layer 2, set address offset in memory for LCD */ TM_DMA2DGRAPHIC_SetLayer(2); /* Fill layer 2 */ TM_DMA2DGRAPHIC_Fill(GRAPHIC_COLOR_YELLOW); /* Draw poly line */ TM_DMA2DGRAPHIC_DrawPolyLine(Coordinates, 5, GRAPHIC_COLOR_BLACK); /* Draw filled circle */ TM_DMA2DGRAPHIC_DrawFilledCircle(100, 170, 40, GRAPHIC_COLOR_CYAN); while (1) { /* Change display layer on LCD using LTDC transfer */ TM_ILI9341_ChangeLayers(); /* Delay */ Delayms(1000); } }
void initialize_log_func(void) { //Initialize LCD TM_ILI9341_Init(); //Fill with orange color TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); //Rotate LCD TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); memset(str_blank, 0x20, LOG_MAX_SIZE); str_blank[LOG_MAX_SIZE - 1] = '\0'; }
int main(void){ SystemInit(); TM_DELAY_Init(); TM_ILI9341_Init(); TM_ILI9341_SetLayer1(); /* Initialize USART2 at 115200 baud, TX: PD5, RX: PD6 */ TM_USART_Init(USART2, TM_USART_PinsPack_2, 115200); uint8_t wacc = 0x3A; // 0xA6 uint8_t racc = 0x3B; // 0xA7 // 0x2D POWER_CTL: Power-saving features control TM_I2C_Write(I2C2, wacc, 0x2D, 0x08); // 0x31 DATA_FORMAT: Data format control //TM_I2C_Write(I2C1, wacc, 0x31, 0x0B); // FULL_RES and +- 16g TM_I2C_Write(I2C2, wacc, 0x31, 0x01); // fixed resolution and +- 4g // 0x2C BW_RATE: Data rate and power mode control TM_I2C_Write(I2C2, wacc, 0x2C, 0x0A); char str[16] = {0}; sprintf(str, "delay = 100"); TM_USART_Puts(USART2, str); while(1){ TM_ILI9341_Fill(ILI9341_COLOR_WHITE); TM_ILI9341_Puts(30, 30, str, &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLUE2); uint8_t buff[6] = {0}; int16_t tri[3] = {0}; TM_I2C_ReadMulti(I2C2, racc, 0x32, buff, 6); // original read digit tri[0] = (int16_t) ((uint16_t)buff[1] << 8 | (uint16_t)buff[0]); tri[1] = (int16_t) ((uint16_t)buff[3] << 8 | (uint16_t)buff[2]); tri[2] = (int16_t) ((uint16_t)buff[5] << 8 | (uint16_t)buff[4]); float ftri[3] = {0}, divisor = 128.0f; ftri[0] = (float) tri[0] / divisor; ftri[1] = (float) tri[1] / divisor; ftri[2] = (float) tri[2] / divisor; sprintf(str, "%.3f,%.3f,%.3f\n\r", ftri[0], ftri[1], ftri[2]); TM_USART_Puts(USART2, str); TM_ILI9341_Puts(30, 50, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE); Delayms(100); } }
int main(void) { char str[30]; /* Create TouchData struct */ TM_STMPE811_TouchData touchData; /* Initialize system */ SystemInit(); /* Initialize LCD */ TM_ILI9341_Init(); /* Fill with orange color */ TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); /* Rotate LCD */ TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Initialize Touch */ if (TM_STMPE811_Init() != TM_STMPE811_State_Ok) { TM_ILI9341_Puts(20, 20, "STMPE811 Error", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK); while (1); } /* Select touch screen orientation */ touchData.orientation = TM_STMPE811_Orientation_Portrait_2; /* Print some text */ TM_ILI9341_Puts(20, 20, "Press on LCD", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK); TM_ILI9341_Puts(93, 310, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_GREEN, ILI9341_COLOR_BLACK); while (1) { if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) { /* Touch valid */ sprintf(str, "Pressed \n\nX: %03d\nY: %03d", touchData.x, touchData.y); TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Draw pixel on touch location */ TM_ILI9341_DrawPixel(touchData.x, touchData.y, 0x0000); } else { sprintf(str, "Not Pressed\n\n \n "); TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); } } }
int main(void) { /* L3GD20 Struct */ TM_L3GD20_t L3GD20_Data; char buffer[20]; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Init ILI9341 with LTDC on STM32F429 Discovery board */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Fill layer 1 */ TM_ILI9341_Fill(ILI9341_COLOR_RED); /* Put some text */ TM_ILI9341_Puts(10, 10, "L3GD20 3-Axis\nGyroscope", &TM_Font_11x18, 0x0000, ILI9341_COLOR_RED); TM_ILI9341_Puts(90, 310, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED); /* Init L3GD20 sensor */ if (TM_L3GD20_Init(TM_L3GD20_Scale_2000) != TM_L3GD20_Result_Ok) { /* Sensor error */ TM_ILI9341_Puts(10, 100, "Sensor ERROR!", &TM_Font_11x18, 0x0000, ILI9341_COLOR_RED); while (1); } while (1) { /* Read data */ TM_L3GD20_Read(&L3GD20_Data); /* Display data on LCD */ sprintf(buffer, "X rotation: %4d", L3GD20_Data.X); TM_ILI9341_Puts(10, 100, buffer, &TM_Font_11x18, 0x0000, ILI9341_COLOR_RED); sprintf(buffer, "Y rotation: %4d", L3GD20_Data.Y); TM_ILI9341_Puts(10, 122, buffer, &TM_Font_11x18, 0x0000, ILI9341_COLOR_RED); sprintf(buffer, "Z rotation: %4d", L3GD20_Data.Z); TM_ILI9341_Puts(10, 144, buffer, &TM_Font_11x18, 0x0000, ILI9341_COLOR_RED); } }
int main(void) { char str[30]; //Create TouchData struct TM_STMPE811_TouchData touchData; //Initialize system SystemInit(); //Initialize LCD TM_ILI9341_Init(); //Fill with orange color TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); //Rotate LCD TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); //Initialize Touch TM_STMPE811_Init(); //Select touch screen orientation touchData.orientation = TM_STMPE811_Orientation_Portrait_2; //Print some text TM_ILI9341_Puts(20, 20, "Press on LCD", &TM_Font_11x18, ILI9341_COLOR_ORANGE, ILI9341_COLOR_BLACK); TM_ILI9341_Puts(168, 308, "majerle.eu", &TM_Font_7x10, ILI9341_COLOR_GREEN, ILI9341_COLOR_BLACK); while (1) { if (TM_STMPE811_ReadTouch(&touchData) == TM_STMPE811_State_Pressed) { //Touch valid sprintf(str, "Pressed \n\nX: %03d\nY: %03d", touchData.x, touchData.y); TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); TM_ILI9341_DrawPixel(touchData.x, touchData.y, 0x0000); } else { sprintf(str, "Not Pressed\n\n \n "); TM_ILI9341_Puts(20, 80, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); } } }
int main(void) { uint16_t i; uint8_t devices_found = 0; char buffer[20]; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds on board */ TM_DISCO_LedInit(); /* Init LCD on STM32F429-Discovery board */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Set background color */ TM_ILI9341_Fill(0x1234); /* Init I2C3 peripheral, PA8, PC9 */ TM_I2C_Init(I2C3, TM_I2C_PinsPack_1, 100000); /* Make search and show on LCD */ for (i = 2; i < 0xFF; i += 2) { /* Check if device detected */ if (TM_I2C_IsDeviceConnected(I2C3, i)) { /* Format string */ sprintf(buffer, "Device: %02X", i); /* Print to LCD */ TM_ILI9341_Puts(10, 10 + 12 * devices_found++, buffer, &TM_Font_7x10, 0x0000, 0x1234); } } while (1) { } }
int main(void) { TM_AM2301_Data_t data; char str[50]; /* Initialize system */ SystemInit(); /* Initialize delay */ TM_DELAY_Init(); /* Initialize LCD on F429-Discovery board */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); TM_ILI9341_Fill(ILI9341_COLOR_ORANGE); TM_ILI9341_Puts(10, 10, "AM2301 (DHT21)\nsensor", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); TM_ILI9341_Puts(90, 310, "stm32f4-discovery.com", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); /* Initialize sensor */ TM_AM2301_Init(); /* Reset time */ TM_DELAY_SetTime(0); while (1) { /* Every 1 second */ if (TM_DELAY_Time() > 1000000) { TM_DELAY_SetTime(0); /* Data valid */ if (TM_AM2301_Read(&data) == TM_AM2301_OK) { /* Show on LCD */ sprintf(str, "Humidity: %2.1f %%\nTemperature: %2.1f C", (float)data.Hum / 10, (float)data.Temp / 10); TM_ILI9341_Puts(10, 100, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE); } } /* Do other stuff constantly */ } }
int main(void) { int accelData[3]; int analogData[BUFFER]; int i=0; for(i=0;i<BUFFER;i++){ analogData[i]=0; } int a = 0; int analogIn = 0; int analogMin, analogMax; /* Initialize system */ SystemInit(); /* Initialize delay */ //TM_DELAY_Init(); /* Initialize PG13 (GREEN LED) and PG14 (RED LED) */ TM_GPIO_Init(GPIOG, GPIO_PIN_13 | GPIO_PIN_14, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast); TM_GPIO_SetPinValue(GPIOG, GPIO_PIN_14, 1); // Red: ON #ifdef ENABLE_USART /* Initialize USART1 at 115200 baud, TX: PA10, RX: PA9 */ TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200); #endif #ifdef ENABLE_VCP /* Initialize USB Virtual Comm Port */ TM_USB_VCP_Result status = TM_USB_VCP_NOT_CONNECTED; while (TM_USB_VCP_GetStatus() != TM_USB_VCP_CONNECTED) { TM_USB_VCP_Init(); TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14); Delay(500000); } SendString("USB VCP initialized and connected\n"); TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14 | GPIO_PIN_13); // Red: OFF, Gr: ON #endif #ifdef ENABLE_MMA /* Initialize MMA845X */ uint8_t mma_status = MMA845X_Initialize(MMA_RANGE_4G); if (mma_status == MMA_OK) { SendString("MMA initialized\n"); } else { SendString("MMA initialization failed, error code: "); // Add 48 to the byte value to have character representation, (48 = '0') SendChar('0'+mma_status); SendChar('\n'); } #endif /* Initialize Display */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_1); TM_ILI9341_SetLayer1(); TM_ILI9341_Fill(ILI9341_COLOR_BLACK); /* Fill data on layer 1 */ /* Initialize ADC1 */ TM_ADC_Init(CURRENT_ADC, CURRENT_CH); /* Initialize PE2 and PE3 for digital output (Motor direction) */ TM_GPIO_Init(GPIOE, GPIO_PIN_2 | GPIO_PIN_3, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast); // Set them to HIGH/LOW TM_GPIO_SetPinHigh(GPIOE, GPIO_PIN_3); TM_GPIO_SetPinLow(GPIOE, GPIO_PIN_2); #ifdef ENABLE_PWM /* Set up PE5 (in front of PE4) for PWM (TIM9 CH1 PP2) (Motor speed control) */ TM_PWM_TIM_t TIM9_Data; // Set PWM to 1kHz frequency on timer TIM4, 1 kHz = 1ms = 1000us TM_PWM_InitTimer(TIM9, &TIM9_Data, 1000); // Initialize PWM on TIM9, Channel 1 and PinsPack 2 = PE5 TM_PWM_InitChannel(&TIM9_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2); // Set channel 1 value, 50% duty cycle TM_PWM_SetChannelPercent(&TIM9_Data, TM_PWM_Channel_1, 50); #endif /* Initialize DAC channel 2, pin PA5 (Shaker control) */ //TM_DAC_Init(TM_DAC2); /* Set 12bit analog value of 2047/4096 * 3.3V */ //TM_DAC_SetValue(TM_DAC2, 4096); #ifdef ENABLE_DAC // DAC PIN PA5 /* Initialize DAC1, use TIM4 for signal generation */ TM_DAC_SIGNAL_Init(TM_DAC2, TIM4); /* Output predefined triangle signal with frequency of 5kHz */ TM_DAC_SIGNAL_SetSignal(TM_DAC2, TM_DAC_SIGNAL_Signal_Sinus, 50); #endif /* MAIN LOOP */ while (1) { // Read acceleration data #ifdef ENABLE_MMA MMA845X_ReadAcceleration(accelData); #endif // Read analog input analogData[a] = TM_ADC_Read(CURRENT_ADC, CURRENT_CH); a++; if(a==BUFFER) {a=0;} // Analog average analogIn=0; analogMax=0; analogMin=4096; for(i=0;i<BUFFER;i++){ if(analogData[i] > analogMax) { analogMax = analogData[i]; } if(analogData[i] < analogMin) { analogMin = analogData[i]; } analogIn+=analogData[i]; } analogIn/=BUFFER; // Print graphs printGraphsLCD(accelData, analogData[a], analogIn, analogMin, analogMax); // Toggle Green led TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_13); } }
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); } }
void TM_SNAKE_Start(void) { /* Initialize delay */ TM_DELAY_Init(); /* Initialize leds on board */ TM_DISCO_LedInit(); /* Turn off all leds */ TM_DISCO_LedOff(LED_ALL); /* Initialize True random number generator */ TM_RNG_Init(); /* Initialize ILI9341 LCD */ TM_ILI9341_Init(); TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2); /* Initialize USB HID Host for keyboard */ TM_USB_HIDHOST_Init(); /* Set default options */ TM_SNAKE_SetFirstOptions(); /* Set default values */ TM_SNAKE_SetDefaultSnake(); /* Prepare display */ TM_SNAKE_PrepareDisplay(); /* Generate random target */ TM_SNAKE_GenerateTarget(); /* Set time to 0 */ TM_DELAY_SetTime(0); while (1) { /* Process USB HID host */ TM_USB_HIDHOST_Process(); /* Check for timeout, move snake here */ if (TM_DELAY_Time() >= Settings.Millis && !Settings.Pause && !GameOver) { /* Reset time */ TM_DELAY_SetTime(0); /* Get new direction value */ Snake.Direction = Snake1.Direction; /* Get last x/y value from snake array = snake head */ Snake_Head[0] = Snake.Snake[Snake.LastIndex][0]; Snake_Head[1] = Snake.Snake[Snake.LastIndex][1]; /* Store last value before update */ Snake_Head_Last[0] = Snake_Head[0]; Snake_Head_Last[1] = Snake_Head[1]; if (!Snake_FirstTime) { /* Move snake */ switch (Snake.Direction) { case SNAKE_DIRECTION_LEFT: Snake_Head[0] -= 1; break; case SNAKE_DIRECTION_RIGHT: Snake_Head[0] += 1; break; case SNAKE_DIRECTION_UP: Snake_Head[1] -= 1; break; case SNAKE_DIRECTION_DOWN: Snake_Head[1] += 1; break; default: break; } } /* Overflow is activated */ if (Settings.Overflow) { /* Check X */ if (Snake_Head[0] == -1) { Snake_Head[0] = SNAKE_PIXELS - 1; } else if (Snake_Head[0] == SNAKE_PIXELS) { Snake_Head[0] = 0; } /* Check Y */ if (Snake_Head[1] == -1) { Snake_Head[1] = SNAKE_PIXELS - 1; } else if (Snake_Head[1] == SNAKE_PIXELS) { Snake_Head[1] = 0; } } else { /* Check walls */ if ( Snake_Head[0] == -1 || Snake_Head[0] == SNAKE_PIXELS || Snake_Head[1] == -1 || Snake_Head[1] == SNAKE_PIXELS ) { /* We hit the wall somewhere */ GameOver = 1; } } if (!Snake_FirstTime) { /* Clear first value from array = snake foot */ TM_SNAKE_DeleteFromArray(0, Snake_Foot); /* Check if snake hit itself */ if (TM_SNAKE_MatchesSnakeLocations(Snake_Head)) { /* Set gameover flag */ GameOver = 1; } } /* Check if target is reached */ if ( !GameOver && Snake_Head[0] == Snake_Food[0] && Snake_Head[1] == Snake_Food[1] ) { /* Add new value to the array, increase snake */ TM_SNAKE_AddToArray(Snake_Head); /* Increase counter for snake hits */ Snake.Hits++; /* Generate new target */ TM_SNAKE_GenerateTarget(); } if (!GameOver) { if (!Snake_FirstTime) { /* Add new value to the array = new snake head */ TM_SNAKE_AddToArray(Snake_Head); } /* Clear pixel on LCD for foot */ /* First clear foot, maybe is new head on the same position */ TM_SNAKE_DrawPixel(Snake_Foot[0], Snake_Foot[1], 0); /* Draw pixel on LCD for new head position with head color */ TM_SNAKE_DrawPixel(Snake_Head[0], Snake_Head[1], 3); /* Draw new pixel for the second pixel after head with new color to delete head color */ TM_SNAKE_DrawPixel(Snake_Head_Last[0], Snake_Head_Last[1], 1); } /* Clear flag if needed */ if (Snake_FirstTime) { Snake_FirstTime = 0; } } if (GameOver) { /* Check flag */ if (!GameOverDisplay) { /* Set flag */ GameOverDisplay = 1; /* Show content to user */ TM_ILI9341_Puts(88, 120, "Game\nOVER", &TM_Font_16x26, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLACK); TM_ILI9341_Puts(28, 180, "Press 'r' to start again!!", &TM_Font_7x10, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLACK); } } else { /* Clear flag */ GameOverDisplay = 0; } /* Check if connected device is keyboard */ if (TM_USB_HIDHOST_Device() == TM_USB_HIDHOST_Result_KeyboardConnected) { /* Green LED ON */ TM_DISCO_LedOn(LED_GREEN); /* Read keyboard data */ TM_USB_HIDHOST_ReadKeyboard(&Keyboard); /* If any buttons active */ if (Keyboard.ButtonStatus == TM_USB_HIDHOST_Button_Pressed) { /* Check pressed button and do actions */ switch ((uint8_t)Keyboard.Button) { case SNAKE_KEY_LEFT: /* Change direction if possible */ if ( Snake.Direction == SNAKE_DIRECTION_UP || Snake.Direction == SNAKE_DIRECTION_DOWN || Snake.Direction == SNAKE_DIRECTION_LEFT ) { /* Disable pause mode */ Settings.Pause = 0; /* Set direction */ Snake1.Direction = SNAKE_DIRECTION_LEFT; } break; case SNAKE_KEY_RIGHT: /* Change direction if possible */ if ( Snake.Direction == SNAKE_DIRECTION_UP || Snake.Direction == SNAKE_DIRECTION_DOWN || Snake.Direction == SNAKE_DIRECTION_RIGHT ) { /* Disable pause mode */ Settings.Pause = 0; /* Set direction */ Snake1.Direction = SNAKE_DIRECTION_RIGHT; } break; case SNAKE_KEY_UP: /* Change direction if possible */ if ( Snake.Direction == SNAKE_DIRECTION_LEFT || Snake.Direction == SNAKE_DIRECTION_RIGHT || Snake.Direction == SNAKE_DIRECTION_UP ) { /* Disable pause mode */ Settings.Pause = 0; /* Set direction */ Snake1.Direction = SNAKE_DIRECTION_UP; } break; case SNAKE_KEY_DOWN: /* Change direction if possible */ if ( Snake.Direction == SNAKE_DIRECTION_LEFT || Snake.Direction == SNAKE_DIRECTION_RIGHT || Snake.Direction == SNAKE_DIRECTION_DOWN ) { /* Disable pause mode */ Settings.Pause = 0; /* Set direction */ Snake1.Direction = SNAKE_DIRECTION_DOWN; } break; case SNAKE_KEY_SPEED_UP: /* Increase speed if possible */ TM_SNAKE_SpeedUp(); break; case SNAKE_KEY_SPEED_DOWN: /* Decrease speed if possible */ TM_SNAKE_SpeedDown(); break; case SNAKE_KEY_PAUSE: /* Toggle pause */ if (Settings.Pause) { Settings.Pause = 0; } else { Settings.Pause = 1; } break; case SNAKE_KEY_RESET: /* Draw snake area */ TM_SNAKE_DrawArea(); /* Set default snake, leave as it was before */ TM_SNAKE_SetDefaultSnake(); /* Generate random target */ TM_SNAKE_GenerateTarget(); /* Disable gameover */ GameOver = 0; /* Reset first time flag */ Snake_FirstTime = 1; break; case SNAKE_KEY_OVERFLOW: /* Toggle overflow mode */ if (Settings.Overflow) { Settings.Overflow = 0; } else { Settings.Overflow = 1; } break; default: break; } } } else { /* Green LED OFF */ TM_DISCO_LedOff(LED_GREEN); } /* Update LCD with changed settings */ /* Check overflow */ if (Settings1.Overflow != Settings.Overflow || Settings1.Speed != Settings.Speed) { /* Save new */ Settings1.Overflow = Settings.Overflow; /* Save new */ Settings1.Speed = Settings.Speed; /* Display game mode and speed */ sprintf(Buffer, "Mode:%4d; Speed: %2d/%2d", Settings.Overflow, Settings.Speed, SNAKE_SPEED_MAX); TM_ILI9341_Puts(10, SNAKE_TEXT_LINE1, Buffer, &TM_Font_7x10, 0x0000, SNAKE_COLOR_MAIN_BCK); } /* Check snake hits */ if (Snake1.Hits != Snake.Hits) { /* Save new */ Snake1.Hits = Snake.Hits; /* Display Speed */ sprintf(Buffer, "Hits:%4d; Score: %5d", Snake.Hits, (2 - Settings.Overflow) * Snake.Hits * Settings.Speed); TM_ILI9341_Puts(10, SNAKE_TEXT_LINE2, Buffer, &TM_Font_7x10, 0x0000, SNAKE_COLOR_MAIN_BCK); } } }
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 */ } } }