Esempio n. 1
0
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);
		*/
	}
}
Esempio n. 2
0
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);
		}
	}
}
Esempio n. 3
0
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) {
		
	}
}
Esempio n. 4
0
void TM_EXTI_Handler(uint16_t GPIO_Pin) {
	
	volatile static uint8_t counter = 0;
	
	/* Handle external line 0 interrupts */
	if (GPIO_Pin == GPIO_Pin_0) {
		/* Toggle RED led */
		TM_DISCO_LedToggle(LED_RED);
		TM_ILI9341_Puts(20, 80, "button pressed, button pressed, button pressed, button pressed, button pressed, button pressed, button pressed, button pressed, ", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		/* Check counter */
		if (++counter >= 10) {
			/* Detach external interrupt for GPIO_Pin_0 no matter on which GPIOx is connected */
			TM_EXTI_Detach(GPIO_Pin_0);
			TM_ILI9341_Puts(20, 80, "Exi detached", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		}
	}
	
	/* Handle external line 13 interrupts */
	if (GPIO_Pin == GPIO_Pin_13) {
		/* Toggle GREEN led */
		TM_DISCO_LedToggle(LED_GREEN);
		/* Check counter */
		if (++counter >= 10) {
			/* Detach external interrupt for GPIO_Pin_0 no matter on which GPIOx is connected */
			TM_EXTI_Detach(GPIO_Pin_13);
		}
	}
}
Esempio n. 5
0
File: log.c Progetto: furhat/STM32
void log2lcd(uint8_t id, char* str)
{
	if(id == 1)
	{
		TM_ILI9341_Puts(0, 160, str_blank, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		TM_ILI9341_Puts(0, 160, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
	}
	else
	{
		TM_ILI9341_Puts(0, 10, str_blank, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		TM_ILI9341_Puts(0, 10, str, &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
	}
}
Esempio n. 6
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);
	}

}
Esempio n. 7
0
void printGraphsLCD(int* accelData, int analogIn) {
	// Only draw if it is time to do so
	//if (TM_DELAY_Time() > 1) {
		mini_snprintf(lcdstr,100,"A:%d___",analogIn);
		TM_ILI9341_Puts(30, 60, lcdstr, &TM_Font_11x18, ILI9341_COLOR_YELLOW, ILI9341_COLOR_BLACK);

		// Draw 3 accel graphs on top half of the screen
		int ax = 80 + accelData[0]*40/4096;
		int ay = 80 + accelData[1]*40/4096;
		int az = 80 + accelData[2]*40/4096;
		TM_ILI9341_DrawLine(xpix,80,xpix+1,80,ILI9341_COLOR_GRAY);
		TM_ILI9341_DrawLine(xpix,axprev,xpix+1,ax,ILI9341_COLOR_RED);
		TM_ILI9341_DrawLine(xpix,ayprev,xpix+1,ay,ILI9341_COLOR_GREEN);
		TM_ILI9341_DrawLine(xpix,azprev,xpix+1,az,ILI9341_COLOR_BLUE);
		axprev = ax;
		ayprev = ay;
		azprev = az;
		// Draw vertical line
		TM_ILI9341_DrawLine(1,160,240,160,ILI9341_COLOR_WHITE);
		// Draw strain graph on bottom half
		int strain = 180 + analogIn*140/4096;
		TM_ILI9341_DrawLine(xpix,strainprev,xpix+1,strain,ILI9341_COLOR_CYAN);
		strainprev = strain;
		// Move x coord
		xpix++;
		if(xpix > 239) {
			xpix = 1;
			// Clear whole screen
			TM_ILI9341_Fill(ILI9341_COLOR_BLACK);
		}
		// Reset timer
	//	TM_DELAY_SetTime(0);
	//}
}
Esempio n. 8
0
void TM_SNAKE_PrepareDisplay(void) {
	/* Fill screen */
	TM_ILI9341_Fill(SNAKE_COLOR_MAIN_BCK);
	
	/* Draw snake area */
	TM_SNAKE_DrawArea();
	
	/* Show text */
	TM_ILI9341_Puts(40, 5, SNAKE_GAME_TITLE, &TM_Font_7x10, 0x0000, SNAKE_COLOR_MAIN_BCK);
}
Esempio n. 9
0
void TOUCH_init(){
	//Initialize Touch
	    if (TM_STMPE811_Init() != TM_STMPE811_State_Ok) {
	    	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);
	    	}
	    }
}
Esempio n. 10
0
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);
		}
	}
}
Esempio n. 11
0
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);
		}
	}
}
Esempio n. 12
0
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 */
	}
}
ErrorStatus TM_ILI9341_Button_Draw(uint8_t id) {
	uint16_t fontWidth, fontHeight, x, y, i, j;
	if ((TM_ILI9341_Buttons[id].flags & TM_BUTTON_FLAG_USED) == 0) {
		//Button not enabled
		return ERROR;
	}
	//Draw label
	if (TM_ILI9341_Buttons[id].flags & TM_BUTTON_FLAG_IMAGE) {
		//Draw picture
		for (i = 0; i < TM_ILI9341_Buttons[id].width; i++) {
			for (j = 0; j < TM_ILI9341_Buttons[id].height; j++) {
				TM_ILI9341_DrawPixel(	TM_ILI9341_Buttons[id].x + i,
										TM_ILI9341_Buttons[id].y + j,
										*(uint16_t *)(TM_ILI9341_Buttons[id].image + j * TM_ILI9341_Buttons[id].width + i)
				);
			}
		}
	} else {
		//Background
		TM_ILI9341_DrawFilledRectangle(	TM_ILI9341_Buttons[id].x,
										TM_ILI9341_Buttons[id].y,
										TM_ILI9341_Buttons[id].x + TM_ILI9341_Buttons[id].width,
										TM_ILI9341_Buttons[id].y + TM_ILI9341_Buttons[id].height,
										TM_ILI9341_Buttons[id].background );
		
	}
	
	//Display label
	if ((TM_ILI9341_Buttons[id].flags & TM_BUTTON_FLAG_NOLABEL) == 0) {
		TM_ILI9341_GetStringSize(TM_ILI9341_Buttons[id].label, TM_ILI9341_Buttons[id].font, &fontWidth, &fontHeight);
		x = TM_ILI9341_Buttons[id].x + TM_ILI9341_Buttons[id].width / 2 - (fontWidth / 2);
		y = TM_ILI9341_Buttons[id].y + TM_ILI9341_Buttons[id].height / 2 - (fontHeight / 2);
		TM_ILI9341_Puts(x, y, TM_ILI9341_Buttons[id].label, TM_ILI9341_Buttons[id].font, TM_ILI9341_Buttons[id].color, TM_ILI9341_Buttons[id].background);
	}
	
	//Border
	if ((TM_ILI9341_Buttons[id].flags & TM_BUTTON_FLAG_NOBORDER) == 0) {
		//Border enabled
		TM_ILI9341_DrawRectangle(	TM_ILI9341_Buttons[id].x,
									TM_ILI9341_Buttons[id].y,
									TM_ILI9341_Buttons[id].x + TM_ILI9341_Buttons[id].width,
									TM_ILI9341_Buttons[id].y + TM_ILI9341_Buttons[id].height,
									TM_ILI9341_Buttons[id].borderColor );
	}
	
	return SUCCESS;
}
Esempio n. 14
0
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) {
		
	}
}
Esempio n. 15
0
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);
	}
}
Esempio n. 16
0
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);
		}
	}
}
Esempio n. 17
0
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 */
		}
	}
}
Esempio n. 18
0
void ekran(int nr){
	switch(nr){
	case 1:
		//Rotate LCD for 90 degrees
		TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
		//FIll lcd with color
		TM_ILI9341_Fill(ILI9341_COLOR_ORANGE);
		//Draw white circle
		//TM_ILI9341_DrawCircle(0, 0, 10, ILI9341_COLOR_GREEN);
		//Draw red filled circle
		TM_ILI9341_DrawFilledCircle(60, 40, 35, ILI9341_COLOR_RED);
		//Draw blue rectangle
		//TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE);
		//Draw black filled rectangle
		TM_ILI9341_DrawFilledRectangle(70, 200, 160, 240, ILI9341_COLOR_RED);
		TM_ILI9341_Puts(85, 215, "START", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED);
		//Draw line with custom color 0x0005
		TM_ILI9341_DrawLine(20, 120, 220, 120, 0x0005);
		//Put string with black foreground color and blue background with 11x18px font
		TM_ILI9341_Puts(40, 110, " STEP DRIVER ", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		//Put string with black foreground color and blue background with 11x18px font
		TM_ILI9341_Puts(10, 140, "Press START to begin", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		//Put string with black foreground color and red background with 11x18px font
		TM_ILI9341_Puts(1, 310, "LB", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_ORANGE);
		return;
	case 2:
		//Rotate LCD for 90 degrees
		TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
		//FIll lcd with color
		TM_ILI9341_Fill(ILI9341_COLOR_BLUE2);
		//Draw blue rectangle
		//TM_ILI9341_DrawRectangle(120, 20, 220, 100, ILI9341_COLOR_BLUE);
		//Draw black filled rectangle
		TM_ILI9341_DrawFilledRectangle(10, 10, 50, 210, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(70, 10, 110, 210, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(130, 10, 170, 210, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(10, 220, 50, 260, ILI9341_COLOR_RED);
		TM_ILI9341_Puts(15, 230, "STOP", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED);
		TM_ILI9341_DrawFilledRectangle(70, 220, 110, 260, ILI9341_COLOR_RED);
		TM_ILI9341_Puts(75, 230, "STOP", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED);
		TM_ILI9341_DrawFilledRectangle(130, 220, 170, 260, ILI9341_COLOR_RED);
		TM_ILI9341_Puts(135, 230, "STOP", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_RED);
		TM_ILI9341_DrawFilledRectangle(10, 270, 50, 310, ILI9341_COLOR_YELLOW);
		TM_ILI9341_Puts(15, 280, "CW", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_YELLOW);
		TM_ILI9341_DrawFilledRectangle(70, 270, 110, 310, ILI9341_COLOR_YELLOW);
		TM_ILI9341_Puts(75, 280, "CW", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_YELLOW);
		TM_ILI9341_DrawFilledRectangle(130, 270, 170, 310, ILI9341_COLOR_YELLOW);
		TM_ILI9341_Puts(135, 280, "CW", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_YELLOW);
		TM_ILI9341_DrawFilledRectangle(180, 100, 235, 125, ILI9341_COLOR_BLUE);
		TM_ILI9341_Puts(185, 105, "FULL", &TM_Font_11x18, ILI9341_COLOR_WHITE, ILI9341_COLOR_BLUE);
		TM_ILI9341_DrawFilledRectangle(180, 130, 235, 155, ILI9341_COLOR_WHITE);
		TM_ILI9341_Puts(185, 135, "1/2", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(180, 160, 235, 185, ILI9341_COLOR_WHITE);
		TM_ILI9341_Puts(185, 165, "1/4", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(180, 190, 235, 215, ILI9341_COLOR_WHITE);
		TM_ILI9341_Puts(185, 195, "1/8", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(180, 220, 235, 245, ILI9341_COLOR_WHITE);
		TM_ILI9341_Puts(185, 225, "1/16", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_WHITE);
		TM_ILI9341_DrawFilledRectangle(180, 260, 235, 315, ILI9341_COLOR_MAGENTA);
		TM_ILI9341_Puts(185, 280, "DOWN", &TM_Font_11x18, ILI9341_COLOR_BLACK, ILI9341_COLOR_MAGENTA);
		return;
	default:
		//Rotate LCD for 90 degrees
		TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
		//FIll lcd with color
		TM_ILI9341_Fill(ILI9341_COLOR_GREEN);
		//Draw white circle
		//TM_ILI9341_DrawCircle(0, 0, 10, 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 rectangle
		TM_ILI9341_DrawFilledRectangle(120, 200, 220, 230, ILI9341_COLOR_RED);
		return;
	}
}
Esempio n. 19
0
void printAccelLCD(int* accelData) {
	mini_snprintf(lcdstr,100,"X:%d___\nY:%d___\nZ:%d___\n",accelData[0],accelData[1],accelData[2]);
	TM_ILI9341_Puts(30, 60, lcdstr, &TM_Font_11x18, ILI9341_COLOR_YELLOW, ILI9341_COLOR_BLACK);
}
Esempio n. 20
0
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);
	}
}