コード例 #1
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Attach EXTI pin, enable both edges because of different boards support */
	if (TM_EXTI_Attach(TM_DISCO_BUTTON_PORT, TM_DISCO_BUTTON_PIN, TM_EXTI_Trigger_Rising_Falling) == TM_EXTI_Result_Ok) {
		/* Turn on green LED */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* Turn on RED led */
		TM_DISCO_LedOn(LED_RED);
	}
	
	while (1) {
		/* Do nothing, wait user to press button */
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: BradleyConn/stm32f429
int main(void) {
	/* Initialize system */
	SystemInit();

	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	/* 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) {
		
	}
}
コード例 #3
0
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();
	
	/* Check if system reset because of IWDG */
	if (TM_IWDG_Init(TM_IWDG_Timeout_4s)) {
		/* System reset was done because of IWDG timer */
		TM_DISCO_LedOn(LED_RED);
	} else {
		/* No IWDG */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	/* If there is no LED active (F7-Discovery, Nucleo boards), */
	/* then system reset occurred because of IWDG */
	
	while (1) {
		/* Check for button */
		if (TM_DISCO_ButtonPressed()) {
			/* Wait till pressed */
			/* If pressed more than 4 seconds in a row, system will reset because of IWDG timer */
			while (TM_DISCO_ButtonPressed());
		}
		
		/* Reset watchdog */
		TM_IWDG_Reset();
	}
}
コード例 #4
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Try to mount card */
	if (f_mount(&FS, "SD:", 1) == FR_OK) {
		/* Try to open file */
		if ((fres = f_open(&fil, "SD:first_file.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE)) == FR_OK) {
			/* Read SDCARD size */
			TM_FATFS_GetDriveSize("SD:", &CardSize);
			
			/* Format string */
			sprintf(buffer, "Total card size: %u kBytes\n", CardSize.Total);
			
			/* Write total card size to file */
			f_puts(buffer, &fil);
			
			/* Format string for free card size */
			sprintf(buffer, "Free card size:  %u kBytes\n", CardSize.Free);
			
			/* Write free card size to file */
			f_puts(buffer, &fil);
			
			/* Close file */
			f_close(&fil);
			
			/* Turn led ON */
			TM_DISCO_LedOn(LED_ALL);
		}
		
		/* Unmount SDCARD */
		f_mount(NULL, "SD:", 1);
	}
	
	/* Do nothing */
	while (1) {
		
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: Daventorn/stm32f429
int main(void) {
	/* Initialize System */
	SystemInit();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	/* Initialize button on board */
	TM_DISCO_ButtonInit();
	
    while(1) {
		/* If button pressed */
    	if (TM_DISCO_ButtonPressed()) {
			/* Turn on leds */
    		TM_DISCO_LedOn(LED_RED | LED_GREEN);
    	} else {
			/* Turn off leds */
    		TM_DISCO_LedOff(LED_RED | LED_GREEN);
    	}
    }
}
コード例 #6
0
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();
	
	/* For pinouts, check TM_MPU6050 library */
	
	/* Try to init MPU6050, device address is 0xD0, AD0 pin is set to low */
	if (TM_MPU6050_Init(&MPU6050, TM_MPU6050_Device_0, TM_MPU6050_Accelerometer_8G, TM_MPU6050_Gyroscope_250s) == TM_MPU6050_Result_Ok) {
		/* Green LED on */
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		/* Read everything from device */
		TM_MPU6050_ReadAll(&MPU6050);
		
		/* Raw data are available for use as needed */
		//MPU6050.Accelerometer_X;
		//MPU6050.Accelerometer_Y;
		//MPU6050.Accelerometer_Z;
		//MPU6050.Gyroscope_X;
		//MPU6050.Gyroscope_Y;
		//MPU6050.Gyroscope_Z;
		//MPU6050.Temperature;
		
		/* Delay a little */
		Delayms(1);
	}
}
コード例 #7
0
ファイル: main.c プロジェクト: BradleyConn/stm32f429
int main(void) {
	/* Initialize System */
	SystemInit();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button on board */
	TM_DISCO_ButtonInit();
	
    while(1) {
		/* If button pressed, do stuff all the time button is pressed */
    	if (TM_DISCO_ButtonPressed()) {
			/* Turn on leds */
    		TM_DISCO_LedOn(LED_RED | LED_GREEN);
    	} else {
			/* Turn off leds */
    		TM_DISCO_LedOff(LED_RED | LED_GREEN);
    	}
		
		/* Do the stuff only once when button is pressed */
		if (TM_DISCO_ButtonOnPressed()) {
			/* Do here stuff only once */
			/* This function will return 0 until you release button and press it again */
			/* For example, you can send data here to USART, but only once when button is pressed */
			GPIOD->BSRRL = LED_BLUE;
		}
		
		/* Do the stuff only once when button is released */
		if (TM_DISCO_ButtonOnReleased()) {
			/* DO here stuff only once */
			/* This function will return 0 until you press button and release it again */
			GPIOD->BSRRH = LED_BLUE;
		}
    }
}
コード例 #8
0
void TM_ILI9341_Init() {
	//Initialize pins used
	TM_ILI9341_InitPins();
	//SPI chip select high
	ILI9341_CS_SET;
	//Init SPI
	TM_SPI_Init(ILI9341_SPI, ILI9341_SPI_PINS);
	//Init SDRAM
	TM_DISCO_LedInit();
	if (!TM_SDRAM_Init()) {
		TM_DISCO_LedOn(LED_RED);
	}
	//Initialize LCD for LTDC
	TM_ILI9341_InitLCD();
	//Initialize LTDC
	TM_LCD9341_InitLTDC();
	//Initialize LTDC layers
	TM_ILI9341_InitLayers();
	//Set cursor X and Y
	ILI9341_x = ILI9341_y = 0;
	
	ILI9341_Opts.Width = ILI9341_WIDTH;
	ILI9341_Opts.Height = ILI9341_HEIGHT;
	ILI9341_Opts.Orientation = TM_ILI9341_Portrait;
	ILI9341_Opts.Orient = TM_ILI9341_Orientation_Portrait_1;
	ILI9341_Opts.CurrentLayer = 0;
	ILI9341_Opts.CurrentLayerOffset = 0;
	ILI9341_Opts.Layer1Opacity = 255;
	ILI9341_Opts.Layer2Opacity = 0;
	
	TM_ILI9341_SetLayer1();
	TM_ILI9341_Fill(ILI9341_COLOR_WHITE);
	TM_ILI9341_SetLayer2();
	TM_ILI9341_Fill(ILI9341_COLOR_WHITE);
	TM_ILI9341_SetLayer1();
}
コード例 #9
0
ファイル: main.c プロジェクト: Acse/stm32f429
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);
	}
}
コード例 #10
0
ファイル: tm_stm32f4_snake.c プロジェクト: Xsaren/stm32f429
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);
		}
	}
}
コード例 #11
0
ファイル: main.c プロジェクト: jfs2389/stm32f429
int main(void) {
    /* Initialize system */
    SystemInit();

    /* Init USART6, TX: PC6 for debug */
    TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);

    /* Enable watchdog, 4 seconds before timeout */
    if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_4s)) {
        /* Report to user */
        printf("Reset occured because of Watchdog\n");
    }

    /* Initialize delay */
    TM_DELAY_Init();

    /* Initialize leds on board */
    TM_DISCO_LedInit();

    /* Initialize button */
    TM_DISCO_ButtonInit();

    /* Display to user */
    printf("Program starting..\n");

    /* Initialize ethernet peripheral */
    /* All parameters NULL, default options for MAC, static IP, gateway and netmask will be used */
    /* They are defined in tm_stm32f4_ethernet.h file */
    if (TM_ETHERNET_Init(NULL, NULL, NULL, NULL) == TM_ETHERNET_Result_Ok) {
        /* Successfully initialized */
        TM_DISCO_LedOn(LED_GREEN);
    } else {
        /* Unsuccessfull communication */
        TM_DISCO_LedOn(LED_RED);
    }

    /* Reset watchdog */
    TM_WATCHDOG_Reset();

    while (1) {
        /* Update ethernet, call this as fast as possible */
        TM_ETHERNET_Update();

        /* If DNS is not working and we don't have IP yet */
        if (MyDNS.Working == 0 && MyDNS.HaveIP == 0) {
            /* Try to start DNS */
            /* It will return error in case Ethernet is not ready yet so you have to try more than one time */
            if (TM_ETHERNETDNS_GetHostByName("stm32f4-discovery.com") == TM_ETHERNET_Result_Ok) {
                /* We started with working */
                MyDNS.Working = 1;
            }
        }

        /* On button pressed, make a new connection and if we have IP known */
        if (TM_DISCO_ButtonOnPressed() && MyDNS.HaveIP) {
            /* Try to make a new connection, port 80 */
            if (TM_ETHERNETCLIENT_Connect("stm32f4-discovery.com", MyDNS.ip[0], MyDNS.ip[1], MyDNS.ip[2], MyDNS.ip[3], 80, &requests_count) != TM_ETHERNET_Result_Ok) {
                /* Print to user */
                printf("Can not make a new connection!\n");
            }
        }

        /* Reset watchdog */
        TM_WATCHDOG_Reset();
    }
}
コード例 #12
0
ファイル: main.c プロジェクト: Acse/stm32f429
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);
		}
	}
}
コード例 #13
0
ファイル: main.c プロジェクト: BradleyConn/stm32f429
int main(void) {
	/* Initialize system */
	SystemInit();
	
	/* Init USART6, TX: PC6 for debug */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);
	
	/* Enable watchdog, 4 seconds before timeout */
	if (TM_WATCHDOG_Init(TM_WATCHDOG_Timeout_4s)) {
		/* Report to user */
		printf("Reset occured because of Watchdog\n");
	}
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize leds on board */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Display to user */
	printf("Program starting..\n");
	
	/* Initialize RTC with internal clock if not already */
	if (!TM_RTC_Init(TM_RTC_ClockSource_Internal)) {
		/* Set default time for RTC */
		
		/* Set date and time if RTC is not initialized already */
		TM_RTC_SetDateTimeString("28.02.15.6;23:35:30");
	};
	
	/* Initialize ethernet peripheral */
	/* All parameters NULL, default options for MAC, static IP, gateway and netmask will be used */
	/* They are defined in tm_stm32f4_ethernet.h file */
	if (TM_ETHERNET_Init(NULL, NULL, NULL, NULL) == TM_ETHERNET_Result_Ok) {
		/* Successfully initialized */
		TM_DISCO_LedOn(LED_GREEN);
	} else {
		/* Unsuccessfull communication */
		TM_DISCO_LedOn(LED_RED);
	}
	
	/* Reset watchdog */
	TM_WATCHDOG_Reset();
	
	/* Initialize ethernet server if you want use it, server port 80 */
	TM_ETHERNETSERVER_Enable(80);
	
	/* Set SSI tags, we have 21 SSI tags */
	TM_ETHERNETSERVER_SetSSITags(SSI_Tags, 21);
	
	/* Set CGI tags, we have 1 CGI handler, for leds only */
	TM_ETHERNETSERVER_SetCGIHandlers(CGI_Handlers, 1);
	
	/* Read RTC clock */
	TM_RTC_GetDateTime(&RTC_Data, TM_RTC_Format_BIN);
	
	/* Print current time to USART */
	printf("Current date: %02d:%02d:%02d\n", RTC_Data.hours, RTC_Data.minutes, RTC_Data.seconds);
	
	/* Reset watchdog */
	TM_WATCHDOG_Reset();

	while (1) {
		/* Update ethernet, call this as fast as possible */
		TM_ETHERNET_Update();
		
		/* If button pressed, toggle server status */
		if (TM_DISCO_ButtonOnPressed()) {
			/* If server is enabled */
			if (TM_ETHERNETSERVER_Enabled()) {
				/* Disable it */
				TM_ETHERNETSERVER_Disable();
				/* Print to user */
				printf("Server disabled\n");
			} else {
				/* Enable it */
				TM_ETHERNETSERVER_Enable(80);
				/* Print to user */
				printf("Server enabled\n");
			}
		}
		
		/* Reset watchdog */
		TM_WATCHDOG_Reset();
	}
}
コード例 #14
0
ファイル: main.c プロジェクト: Daventorn/stm32f429
int main(void) {
	char buf[40];
	uint8_t devices, i, j, count, alarm_count;
	uint8_t device[EXPECTING_SENSORS][8];
	uint8_t alarm_device[EXPECTING_SENSORS][8];
	float temps[EXPECTING_SENSORS];
	
	/* Initialize system */
	SystemInit();
	/* Initialize delay */
	TM_DELAY_Init();
	/* Initialize OneWire on pin PD0 */
	TM_OneWire_Init();
	/* Initialize USART, TX: PB6, RX: PB7 */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Initialize Leds */
	TM_DISCO_LedInit();
	/* Turn leds on */
	TM_DISCO_LedOn(LED_RED | LED_GREEN);
	
	/* Checks for any device on 1-wire */
	devices = TM_OneWire_First();
	count = 0;
	while (devices) {
		count++;
		/* Get full ROM value, 8 bytes, give location of first byte where to save */
		TM_OneWire_GetFullROM(&device[count - 1][0]);
		/* Get next device */
		devices = TM_OneWire_Next();
	}
	/* If any devices on 1wire */
	if (count > 0) {
		sprintf(buf, "Devices found on 1-wire: %d\n\r", count);
		TM_USART_Puts(USART1, buf);
		/* Display 64bit rom code for each device */
		for (j = 0; j < count; j++) {
			for (i = 0; i < 8; i++) {
				sprintf(buf, "0x%02X ", device[j][i]);
				TM_USART_Puts(USART1, buf);
			}
			TM_USART_Puts(USART1, "\n\r");
		}
	} else {
		TM_USART_Puts(USART1, "No devices on OneWire.\n\r");
	}
	
	/* Go through all connected devices and set resolution to 12bits */
	for (i = 0; i < count; i++) {
		TM_DS18B20_SetResolution(&device[i][0], TM_DS18B20_Resolution_12bits);
	}
	/* Set high temperature alarm on device number 0, 25degrees celcius */
	TM_DS18B20_SetAlarmHighTemperature(&device[0][0], 25);
	/* Disable alarm temperatures on device number 1 */
	TM_DS18B20_DisableAlarmTemperature(&device[1][0]);
	
	while (1) {
		/* Start temperature conversion on all bits */
		TM_DS18B20_StartAll();
		/* Wait until all are done */
		while (!TM_DS18B20_AllDone());
		/* Read temperature from each device separatelly */
		for (i = 0; i < count; i++) {
			/* Read temperature from ROM address and store it to temps variable */
			TM_DS18B20_Read(&device[i][0], &temps[i]);
			/* Print temperature */
			sprintf(buf, "Temp %d: %3.5f; ", i, temps[i]);
			TM_USART_Puts(USART1, buf);
		}
		alarm_count = 0;
		/* Check if any device has alarm flag set */
		while (TM_DS18B20_AlarmSearch()) {
			/* Store ROM of device which has alarm flag set */
			TM_OneWire_GetFullROM(&alarm_device[alarm_count][0]);
			alarm_count++;
		}
		sprintf(buf, "alarm: %d\n\r", alarm_count);
		TM_USART_Puts(USART1, buf);
		/* Any device has alarm flag set? */
		if (alarm_count > 0) {
			TM_USART_Puts(USART1, "THIS DEVICES HAVE ALARM!\n\r    ");
			/* Show rom of this devices */
			for (j = 0; j < alarm_count; j++) {
				for (i = 0; i < 8; i++) {
					sprintf(buf, "0x%02X ", alarm_device[j][i]);
					TM_USART_Puts(USART1, buf);
				}
				TM_USART_Puts(USART1, "\n\r    ");
			}
			TM_USART_Puts(USART1, "ALARM devices recognized!\n\r");
		}
		/* Some delay */
		Delayms(1000);
	}
}
コード例 #15
0
ファイル: main.c プロジェクト: JoergSH/stm32f429
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);
	}
}
コード例 #16
0
int main(void) {
    /* Init system */
    TM_RCC_InitSystem();

    /* Init HAL layer */
    HAL_Init();

    /* Init leds */
    TM_DISCO_LedInit();

    /* Init delay */
    TM_DELAY_Init();

#if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL)
    /* Init LCD */
    TM_LCD_Init();
    TM_LCD_SetFont(&TM_Font_7x10);
    TM_LCD_SetXY(5, 5);

#if defined(STM32F7_DISCOVERY)
    /* Rotate LCD */
    TM_LCD_SetOrientation(2);
#endif
#endif

    /* Init USB peripheral */
    TM_USB_Init();

    /* Init HOST on HS mode */
    TM_USBH_Init(TM_USB_HS);

    /* Init USB CDC DEVICE on FS port */
    TM_USBD_CDC_Init(TM_USB_FS);

    /* Send debug */
    printf("USB FS configured as CDC device!\n");

    /* Init USB HOST HID on HS port */
    TM_USBH_HID_Init(TM_USB_HS);

    /* Send debug */
    printf("USB HS configured as HID host!\n");

    /* Start USB CDC device */
    TM_USBD_Start(TM_USB_FS);

    /* Send debug */
    printf("USB FS started!\n");

    /* Start USB HID host */
    TM_USBH_Start(TM_USB_HS);

    /* Send debug */
    printf("USB HS started!\n");

    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);

        /* Process USB HID Host */
        TM_USBH_Process(TM_USB_HS);

        /* Check if CDC device is ready, if drivers are installed if needed */
        if (TM_USBD_IsDeviceReady(TM_USB_FS) == TM_USBD_Result_Ok) {
            /* Turn ON led */
            TM_DISCO_LedOn(LED_GREEN);

            /* Print if needed */
            if (!FS_Printed) {
                printf("FS: CDC ready to use!\n");

                FS_Printed = 1;
            }
        } else {
            /* Turn OFF led */
            TM_DISCO_LedOff(LED_GREEN);

            /* Print if needed */
            if (FS_Printed) {
                printf("FS: CDC not ready to use!\n");

                FS_Printed = 0;
            }
        }

        /* 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);
        }

        /* Check HS port if anything connected */
        if (
            TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok &&
            TM_USBH_IsDeviceReady(TM_USB_HS) == TM_USBH_Result_Ok
        ) {
            /* Something is connected */

            /* Check for HID */
            if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Keyboard) {
                if (!HS_Printed) {
                    printf("HS: Keyboard connected!\n");

                    HS_Printed = 1;
                }
            } else if (TM_USBH_HID_GetConnected(TM_USB_HS) == TM_USBH_HID_Mouse) {
                if (!HS_Printed) {
                    printf("HS: Mouse connected!\n");

                    HS_Printed = 1;
                }
            } else {
                /* No HID connected */
                if (!HS_Printed) {
                    printf("HS: Unknown connected!\n");

                    HS_Printed = 1;
                }
            }
        } else {
            /* Device not connected */
            if (HS_Printed) {
                printf("HS: Device disconnected!\n");

                HS_Printed = 0;
            }
        }
    }
}
コード例 #17
0
ファイル: main.c プロジェクト: JoergSH/stm32f429
int main(void) {
	TM_NRF24L01_Transmit_Status_t transmissionStatus;
	char str[40];
	
	//Initialize system
	SystemInit();
	
	//Initialize system and Delay functions
	TM_DELAY_Init();
	
	//Initialize onboard leds
	TM_DISCO_LedInit();
	
	//Initialize USART, TX: PB6, RX: PB7
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	//Initialize NRF24L01+ on channel 15 and 32bytes of payload
	//By default 2Mbps data rate and 0dBm output power
	//NRF24L01 goes to RX mode by default
	TM_NRF24L01_Init(15, 32);
	
	//Set 2MBps data rate and -18dBm output power
	TM_NRF24L01_SetRF(TM_NRF24L01_DataRate_2M, TM_NRF24L01_OutputPower_M18dBm);
	
	//Set my address, 5 bytes
	TM_NRF24L01_SetMyAddress(MyAddress);
	//Set TX address, 5 bytes
	TM_NRF24L01_SetTxAddress(TxAddress);
	
	//Reset counter
	TM_DELAY_SetTime(0);
	while (1) {
		//Every 2 seconds
		if (TM_DELAY_Time() > 2000000) {
			//Fill data with something
			sprintf((char *)dataOut, "abcdefghijklmnoszxABCDEFCBDA");
			//Display on USART
			TM_USART_Puts(USART1, "pinging: ");
			//Reset time, start counting microseconds
			TM_DELAY_SetTime(0);
			//Transmit data, goes automatically to TX mode
			TM_NRF24L01_Transmit(dataOut);
			
			TM_DISCO_LedOn(LED_PIN);
			//Wait for data to be sent
			do {
				transmissionStatus = TM_NRF24L01_GetTransmissionStatus();
			} while (transmissionStatus == TM_NRF24L01_Transmit_Status_Sending);
			TM_DISCO_LedOff(LED_PIN);
			
			//Go back to RX mode
			TM_NRF24L01_PowerUpRx();
			
			//Wait received data, wait max 100ms, if time is larger, than data was probably lost
			while (!TM_NRF24L01_DataReady() && TM_DELAY_Time() < 100000);
			
			//Format time
			sprintf(str, "%d us", TM_DELAY_Time());
			//Show ping time
			TM_USART_Puts(USART1, str);
			
			//Get data from NRF2L01+
			TM_NRF24L01_GetData(dataIn);
			
			//Check transmit status
			if (transmissionStatus == TM_NRF24L01_Transmit_Status_Ok) {
				//Transmit went OK
				TM_USART_Puts(USART1, ": OK\n\r");
			} else if (transmissionStatus == TM_NRF24L01_Transmit_Status_Lost) {
				//Message was LOST
				TM_USART_Puts(USART1, ": LOST\n\r");
			} else {
				//This should never happen
				TM_USART_Puts(USART1, ": SENDING\n\r");
			}
		}
	}
}
コード例 #18
0
ファイル: main.c プロジェクト: BradleyConn/stm32f429
/* 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";
}
コード例 #19
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
#if defined(STM32F429_DISCOVERY) || defined(STM32F7_DISCOVERY) || defined(STM32F439_EVAL)
	/* Init LCD */
	TM_LCD_Init();
	TM_LCD_SetFont(&TM_Font_7x10);
	TM_LCD_SetXY(5, 5);
	
#if defined(STM32F7_DISCOVERY)
	/* Rotate LCD */
	TM_LCD_SetOrientation(2);
#endif
#endif
	
	/* Init USB */
	TM_USB_Init();
	
	/* Init USB Host, FS and HS modes */
	TM_USBH_Init(TM_USB_Both);
	
	/* Enable HID HOST class for USB FS mode */
	TM_USBH_HID_Init(TM_USB_FS);
	
	/* Enable MSC HOST class for USB HS mode */
	TM_USBH_MSC_Init(TM_USB_HS);
	
	/* Start USB host on FS and HS */
	TM_USBH_Start(TM_USB_Both);
	
	while (1) {
		/* Process USB host FS and HS modes */
		TM_USBH_Process(TM_USB_Both);
		
		/* Check if device connected on FS port */
		if (TM_USBH_IsConnected(TM_USB_FS) == TM_USBH_Result_Ok) {
			/* Check if any HID devie is connected to FS port */
			if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_Keyboard) {
				/* Keyboard is connected on FS port */
				
				/* If not printed yet */
				if (!FS_Printed) {
					/* Print to LCD */
					printf("USB FS: Keyboard connected! VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_FS), TM_USBH_GetPID(TM_USB_FS));
					
					/* Set flag */
					FS_Printed = 1;
				}
				
				/* Read pressed button if any */
				if (TM_USBH_HID_GetKeyboard(TM_USB_FS, &KbdInfo) == TM_USBH_HID_Keyboard) {
					/* Something pressed on keyboard */
					
					/* Print on LCD if character is valid */
					if (KbdInfo.C) {
						printf("Character: %c\n", KbdInfo.C);
					}
					
					/* Print others */
					printf("LS: %d ", KbdInfo.Special.S.LShift);
					printf("LC: %d ", KbdInfo.Special.S.LCtrl);
					printf("LA: %d ", KbdInfo.Special.S.LAlt);
					printf("LG: %d ", KbdInfo.Special.S.LGUI);
					printf("\n");
				}
			} else if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_Mouse) {
				/* Mouse is connected on FS port */
				
				/* If not printed yet */
				if (!FS_Printed) {
					/* Print to LCD */
					printf("USB FS: Mouse connected! VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_FS), TM_USBH_GetPID(TM_USB_FS));
					
					/* Turn on green LED */
					TM_DISCO_LedOn(LED_GREEN);
				
					/* Set flag */
					FS_Printed = 1;
				}
				
				/* Read mouse if any */
				if (TM_USBH_HID_GetMouse(TM_USB_FS, &MouseInfo) == TM_USBH_HID_Mouse) {
					/* Something pressed on keyboard */
					printf("Abs X: %d; Abs Y: %d; Rel X: %d; Rel Y %d\n", MouseInfo.AbsoluteX, MouseInfo.AbsoluteY, MouseInfo.RelativeX, MouseInfo.RelativeY);
					printf("Btn1: %d; Btn2: %d; Btn3: %d\n", MouseInfo.Buttons[0], MouseInfo.Buttons[1], MouseInfo.Buttons[2]);
				}
			}
		} else if (FS_Printed) {
			/* Check if no device connected */
			if (TM_USBH_HID_GetConnected(TM_USB_FS) == TM_USBH_HID_None) {
				/* Mouse is connected */
				/* Print to LCD */
				printf("USB FS: Device disconnected\n");
				
				/* Clear flag */
				FS_Printed = 0;
			
				/* Turn off green LED */
				TM_DISCO_LedOff(LED_GREEN);
			}
		}
		
		/* Check MSC host on HS port */
		if (
			TM_USBH_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok &&     /*!< Check if any device connected to USB HS port */
			TM_USBH_MSC_IsConnected(TM_USB_HS) == TM_USBH_Result_Ok && /*!< Device connected to USB port is MSC type */
			TM_USBH_MSC_IsReady(TM_USB_HS) == TM_USBH_Result_Ok        /*!< Device is ready */
		) {
			/* Device is connected on HS port */
			/* Connected device is MSC type */
			
			/* If not printed already */
			if (!HS_Printed) {
				/* Print to LCD */
				printf("--------------------------\n");
				printf("USB HS: USB MSC device connected with VID: %04X; PID: %04X\n", TM_USBH_GetVID(TM_USB_HS), TM_USBH_GetPID(TM_USB_HS));
				
				/* Set flag */
				HS_Printed = 1;
			}
			
			/* If not mounted already */
			if (!mounted) {
				/* Try to mount and write using FATFS */
				if ((fres = f_mount(&FATFS_USB, "USBHS:", 1)) == FR_OK) {
					/* Mounted OK */
					printf("USB HS: Mounted OK!\n");
					
					/* Try to open file */
					if ((fres = f_open(&fil, "USBHS:usb_hs_file.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ)) == FR_OK) {
						/* File opened OK */
						printf("USB HS: File opened!\n");
						
						/* Go to end of file */
						f_lseek(&fil, f_size(&fil));
						
						/* Print string */
						if (f_puts("USB HS: File written using USB HS port\n", &fil)) {
							/* Written OK */
							printf("USB HS: File written OK!\n");
							
							/* Set flag */
							mounted = 1;
				
							/* Turn on red LED */
							TM_DISCO_LedOn(LED_RED);
						} else {
							printf("USB HS: File writing error!\n");
						}
						
						/* Close file */
						f_close(&fil);
						
						printf("USB HS: File closed!\n");
						
						if ((fres = f_open(&fil, "USBHS:usb_hs_file.txt", FA_WRITE | FA_READ)) == FR_OK) {
							printf("USB HS: File reopened OK and closed again!\n");
							f_close(&fil);
						} else {
							printf("USB HS: File reopen ERROR! FRES: %d\n", fres);
						}
					} else {
						/* File not opened */
						printf("USB HS: Failed to open file!\n");
					}
					
					/* Unmount USB */
					f_mount(NULL, "USBHS:", 1);
				} else {
					/* Mounting error! */
					printf("USB HS: Failed to mount!\n");
				}
			}
		} else {
			/* Clear flag */
			mounted = 0;
			
			/* Print disconnection */
			if (HS_Printed) {
				/* Print to LCD */
				printf("USB HS: USB MSC device disconnected!\n");
				
				/* Clear flag */
				HS_Printed = 0;
				
				/* Turn off red LED */
				TM_DISCO_LedOff(LED_RED);
			}
		}
	}
}
コード例 #20
0
int main(void) {
	/* Init system */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Init delay */
	TM_DELAY_Init();
	
	/* Init USB peripheral */
	TM_USB_Init();
	
	/* Init VCP on FS and HS ports.. */
	TM_USBD_CDC_Init(TM_USB_FS);
	TM_USBD_CDC_Init(TM_USB_HS);
	
	/* ..or use single call for both modes */
	//TM_USBD_CDC_Init(TM_USB_Both);
	
	/* Start USB device mode on FS and HS ports.. */
	TM_USBD_Start(TM_USB_FS);
	TM_USBD_Start(TM_USB_HS);
	
	/* .. or use single call for both modes */
	//TM_USBD_Start(TM_USB_Both);
	
	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_Both);
		
		/* 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);
		}
		
		/* Check if device is ready, if drivers are installed if needed on HS port */
		if (TM_USBD_IsDeviceReady(TM_USB_HS) == TM_USBD_Result_Ok) {
			//TM_DISCO_LedOn(LED_GREEN);
		} else {
			//TM_DISCO_LedOff(LED_GREEN);
		}		

		/* Check if any string received on HS port */
		if (TM_USBD_CDC_Gets(TM_USB_HS, string_array, sizeof(string_array))) {
			/* One character received */
			
			/* Send it back */
			TM_USBD_CDC_Puts(TM_USB_HS, string_array);
		}
	}
}
コード例 #21
0
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);
	}
}
コード例 #22
0
ファイル: main.c プロジェクト: PUT-PTM/STMDestroyer2016
int main(void) {
	uint8_t already = 0;

	/* Set structs for all examples */
	TM_USB_HIDDEVICE_Keyboard_t Keyboard;
	TM_USB_HIDDEVICE_Gamepad_t Gamepad1, Gamepad2;
	TM_USB_HIDDEVICE_Mouse_t Mouse;

	/* Initialize system */
	SystemInit();

	//Initialize LIS302DL - acceleration sensor;...
	//... the board position determines the movement of joystick

	LIS302DL_Init1();

	/* Initialize leds */
	TM_DISCO_LedInit();

	/* Initialize button */
	TM_DISCO_ButtonInit();

	/* Initialize delay */
	TM_DELAY_Init();

	/* Initialize USB HID Device */
	TM_USB_HIDDEVICE_Init();

	/* Set default values for mouse struct */
	TM_USB_HIDDEVICE_MouseStructInit(&Mouse);
	/* Set default values for keyboard struct */
	TM_USB_HIDDEVICE_KeyboardStructInit(&Keyboard);
	/* Set default values for gamepad structs */
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad1);
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad2);

	//Variables
	const int8_t axis_x_min = 0; //The number represents maximum deflection of left-stick on left; Default: -128 (!The value recommended for Unity game: 0 - Unity can read only not minus numbers of axis!)
	const int8_t axis_x_max = 127; //The number represents maximum deflection of left-stick on right; Default: 127
	const int8_t axis_x_avg = (axis_x_min + axis_x_max) / 2; //The value presented center position of left stick
	const int8_t acc_x_min = -60; //Minimum (approximately) value reading from accelerometer for X-axis
	const int8_t acc_x_max = 60; //Maximum (approximately) value reading from accelerometer for X-axis
	const int8_t kx = (-axis_x_min + axis_x_max) / (-acc_x_min + acc_x_max); //Thanks to this ratio, can create universal formula on value of gamepad left-axis depends on STM-board position

		const int8_t axis_y_min = 0; //The number represents maximum deflection of left-stick on top; Default: -128 (!The value recommended for Unity game: 0 - Unity can read only not minus numbers of axis!)
		const int8_t axis_y_max = 127; //The number represents maximum deflection of left-stick on bottom; Default: 127
		const int8_t axis_y_avg = (axis_y_min + axis_y_max) / 2; //The value presented center position of left stick
		const int8_t acc_y_min = -60; //Minimum (approximately) value reading from accelerometer for Y-axis
		const int8_t acc_y_max = 60; //Maximum (approximately) value reading from accelerometer for Y-axis
		const int8_t ky = (-axis_y_min + axis_y_max) / (-acc_y_min + acc_y_max); //Thanks to this ratio, can create universal formula on value of gamepad left-axis depends on STM-board position

	while (1) {
		/* If we are connected and drivers are OK */
		if (TM_USB_HIDDEVICE_GetStatus() == TM_USB_HIDDEVICE_Status_Connected) {
			/* Turn on green LED */
			TM_DISCO_LedOn(LED_GREEN);

/* Simple sketch start */

			/* If you pressed button right now and was not already pressed */
			if (TM_DISCO_ButtonPressed() && already == 0) { /* Button on press */
				already = 1;

				/* Gamepad 1 */
				/* Simulate button 1 on gamepad 1 */
				Gamepad1.Button1 = TM_USB_HIDDEVICE_Button_Pressed;

				/* Send report for gamepad 1 */
				TM_USB_HIDDEVICE_GamepadSend(TM_USB_HIDDEVICE_Gamepad_Number_1, &Gamepad1);


			} else if (!TM_DISCO_ButtonPressed() && already == 1) { /* Button on release */
				already = 0;

				//I thought the command that is 5 lines below was sufficient but no...
				//I released blue button but computer "thought" I still pressed it.
				Gamepad1.Button1 = TM_USB_HIDDEVICE_Button_Released; //release button 1

				/* Send command to release all buttons on both gamepads */
				TM_USB_HIDDEVICE_GamepadReleaseAll(TM_USB_HIDDEVICE_Gamepad_Number_1);
			}

			// Read the board position on axes
			LIS302DL_Read(&acc_x,LIS302DL_OUT_X_ADDR,1);
			LIS302DL_Read(&acc_y,LIS302DL_OUT_Y_ADDR,1);
			LIS302DL_Read(&acc_z,LIS302DL_OUT_Z_ADDR,1);

			//The value on axis depends on board lean
			//HERE: Changing orientation of left joystick under the influence of X-axis

			/* Simulate left stick rotation */
			/* X axis */
			if (acc_x > -15 && acc_x < 15) //horizontal position of STM-board
			{
				Gamepad1.LeftXAxis = axis_x_avg;
			}
			else
			{
				if (acc_x >= acc_x_max - 10) //maximum right position --> vertical position of STM-board (USB mini-B on top of board)
				{
					Gamepad1.LeftXAxis = axis_x_max;
				}
				else
				{
					if (acc_x <= acc_x_min + 10) //maximum left position --> vertical position of STM-board (mini-jack out and USB micro-B on top )
					{
						Gamepad1.LeftXAxis = axis_x_min;
					}
					else
					{
						Gamepad1.LeftXAxis = acc_x * kx + axis_x_avg; //universal formula on left-stick position of gamepad depending on STM position
						//it seems to be sufficient (without if-conditionals); but using of "if", it ensures more stability
					}
				}
			}

			/* Y axis */
			if (acc_y > -15 && acc_y < 15) //horizontal position of STM-board
			{
				Gamepad1.LeftYAxis = axis_y_avg;
			}
			else
			{
				if (acc_y >= acc_x_max - 10) //maximum "up" position --> blue button of STM is higher than black reset-button
				{
					Gamepad1.LeftYAxis = axis_y_min;
				}
				else
				{
					if (acc_y <= acc_x_min + 10) //maximum "down" position --> black button of STM is higher than blue button
					{
						Gamepad1.LeftYAxis = axis_y_max;
					}
					else
					{
						Gamepad1.LeftYAxis = acc_y * (-ky) + axis_y_avg; //universal formula on left-stick position of gamepad depending on STM position
						//it seems to be sufficient (without if-conditionals); but using of "if", it ensures more stability
					}
				}
			}

			TM_USB_HIDDEVICE_GamepadSend(TM_USB_HIDDEVICE_Gamepad_Number_1, &Gamepad1);

/* Simple sketch end */

		} else {
			/* Turn off green LED */
			TM_DISCO_LedOff(LED_GREEN);
		}
	}
}
コード例 #23
0
ファイル: main.c プロジェクト: BradleyConn/stm32f429
int main(void) {
	char buffer[50];
	uint8_t write = 1;
	uint32_t free, total;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize delay functions */
	TM_DELAY_Init();
	
	/* Leds init */
	TM_DISCO_LedInit();
	
	/* Initialize USB MSC HOST */
	TM_USB_MSCHOST_Init();
	
	while (1) {
		/* Host Task handler */
		/* This have to be called periodically as fast as possible */
		TM_USB_MSCHOST_Process();
		/* Device is connected and ready to use */
		if (TM_USB_MSCHOST_Device() == TM_USB_MSCHOST_Result_Connected) {
			/* If we didn't write data already */
			if (write) {
				/* Try to mount USB device */
				/* USB is at 1: */
				if ((fres = f_mount(&USB_Fs, "USB:", 1)) == FR_OK) {
					TM_DISCO_LedOn(LED_GREEN);
					/* Mounted ok */
					/* Try to open USB file */
					if ((fres = f_open(&USB_Fil, "USB:usb_file.txt", FA_READ | FA_WRITE | FA_OPEN_ALWAYS)) == FR_OK) {
						/* We want to write only once */
						write = 0;
						
						/* Get total and free space on USB */
						TM_FATFS_USBDriveSize(&total, &free);
						
						/* Put data */
						f_puts("This is my first file with USB and FatFS\n", &USB_Fil);
						f_puts("with USB MSC HOST library from stm32f4-discovery.com\n", &USB_Fil);
						f_puts("----------------------------------------------------\n", &USB_Fil);
						f_puts("USB total and free space:\n\n", &USB_Fil);
						/* Total space */
						sprintf(buffer, "Total: %8u kB; %5u MB; %2u GB\n", total, total / 1024, total / 1048576);
						f_puts(buffer, &USB_Fil);
						/* Free space */
						sprintf(buffer, "Free:  %8u kB; %5u MB; %2u GB\n", free, free / 1024, free / 1048576);
						f_puts(buffer, &USB_Fil);
						f_puts("----------------------------------------------------\n", &USB_Fil);
						/* Close USB file */
						f_close(&USB_Fil);

						/* Turn GREEN LED On and RED LED Off */
						/* Indicate successful write */
						TM_DISCO_LedOn(LED_GREEN);
						TM_DISCO_LedOff(LED_RED);
					}
				}
				/* Unmount USB */
				f_mount(0, "USB:", 1);
			}
		} else {
			/* Not inserted, turn on RED led */
			TM_DISCO_LedOn(LED_RED);
			TM_DISCO_LedOff(LED_GREEN);
			
			/* Ready to write next time */
			write = 1;
		}
	}
}
コード例 #24
0
ファイル: main.c プロジェクト: MaJerle/stm32f429
int main(void) {
	uint8_t already = 0;
	
	/* Set structs for all examples */
	TM_USB_HIDDEVICE_Keyboard_t Keyboard;
	TM_USB_HIDDEVICE_Gamepad_t Gamepad1, Gamepad2;
	TM_USB_HIDDEVICE_Mouse_t Mouse;
	
	/* Initialize system */
	SystemInit();
	
	/* Initialize leds */
	TM_DISCO_LedInit();
	
	/* Initialize button */
	TM_DISCO_ButtonInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize USB HID Device */
	TM_USB_HIDDEVICE_Init();
	
	/* Set default values for mouse struct */
	TM_USB_HIDDEVICE_MouseStructInit(&Mouse);
	/* Set default values for keyboard struct */
	TM_USB_HIDDEVICE_KeyboardStructInit(&Keyboard);
	/* Set default values for gamepad structs */
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad1);
	TM_USB_HIDDEVICE_GamepadStructInit(&Gamepad2);

	while (1) {		  
		/* If we are connected and drivers are OK */
		if (TM_USB_HIDDEVICE_GetStatus() == TM_USB_HIDDEVICE_Status_Connected) {
			/* Turn on green LED */
			TM_DISCO_LedOn(LED_GREEN);
			
/* Simple sketch start */	
			
			/* If you pressed button right now and was not already pressed */
			if (TM_DISCO_ButtonPressed() && already == 0) { /* Button on press */
				already = 1;
				
				/* Set pressed keys = WIN + R */
				Keyboard.L_GUI = TM_USB_HIDDEVICE_Button_Pressed;	/* Win button */
				Keyboard.Key1 = 0x15; 								/* R */
				/* Result = "Run" command */
				
				/* Send keyboard report */
				TM_USB_HIDDEVICE_KeyboardSend(&Keyboard);
			} else if (!TM_DISCO_ButtonPressed() && already == 1) { /* Button on release */
				already = 0;
				
				/* Release all buttons */
				Keyboard.L_GUI = TM_USB_HIDDEVICE_Button_Released;	/* No button */
				Keyboard.Key1 = 0x00; 								/* No key */
				/* Result = Released everything */
				
				/* Send keyboard report */
				TM_USB_HIDDEVICE_KeyboardSend(&Keyboard);
			}
			
/* Simple sketch end */
			
		} else {
			/* Turn off green LED */
			TM_DISCO_LedOff(LED_GREEN);
		}
	}
}
コード例 #25
0
ファイル: main.c プロジェクト: MaJerle/stm32f429
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;
		}
	}
}