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
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. 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
int test_exi(void) {
	/* Initialize system */
	SystemInit();

	/* Initialize LEDS */
	TM_DISCO_LedInit();
	
	//Initialize LCD
	TM_ILI9341_Init();
	//Fill with orange color
	TM_ILI9341_Fill(ILI9341_COLOR_ORANGE);
	//Rotate LCD
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	/* Attach interrupt on pin PA0 = External line 0 */
	/* Button connected on discovery boards */
	if (TM_EXTI_Attach(GPIOA, GPIO_Pin_0, TM_EXTI_Trigger_Rising) == TM_EXTI_Result_Ok) {
		TM_DISCO_LedOn(LED_RED);
	}
	
	/* Attach interrupt on pin PC13 = External line 13 */
	/* Button connected on nucleo boards */
	if (TM_EXTI_Attach(GPIOC, GPIO_Pin_13, TM_EXTI_Trigger_Falling) == TM_EXTI_Result_Ok) {
		TM_DISCO_LedOn(LED_GREEN);
	}
	
	while (1) {
		
	}
}
Esempio n. 5
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. 6
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. 7
0
File: log.c Progetto: furhat/STM32
void initialize_log_func(void)
{
	//Initialize LCD
	TM_ILI9341_Init();
	//Fill with orange color
	TM_ILI9341_Fill(ILI9341_COLOR_ORANGE);
	//Rotate LCD
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
	
	memset(str_blank, 0x20, LOG_MAX_SIZE);	
	str_blank[LOG_MAX_SIZE - 1] = '\0';	
}
Esempio n. 8
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);
	}

}
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();
}
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) {
	/* 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. 12
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. 13
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. 14
0
void TM_ILI9341_Init() {
	GPIO_InitTypeDef GPIO_InitDef;

	RCC_AHB1PeriphClockCmd(ILI9341_WRX_CLK, ENABLE);
	  
	GPIO_InitDef.GPIO_Pin = ILI9341_WRX_PIN;
	GPIO_InitDef.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
	GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(ILI9341_WRX_PORT, &GPIO_InitDef);


	RCC_AHB1PeriphClockCmd(ILI9341_CS_CLK, ENABLE);
	GPIO_InitDef.GPIO_Pin = ILI9341_CS_PIN;
	GPIO_Init(ILI9341_CS_PORT, &GPIO_InitDef);	
	
	
	RCC_AHB1PeriphClockCmd(ILI9341_RST_CLK, ENABLE);
	GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitDef.GPIO_Pin = ILI9341_RST_PIN;
	GPIO_Init(ILI9341_RST_PORT, &GPIO_InitDef);	

	ILI9341_CS_SET;
	
	TM_SPI_Init(ILI9341_SPI, ILI9341_SPI_PINS);
	
	TM_ILI9341_InitLCD();	
	
	ILI9341_x = ILI9341_y = 0;
	
	ILI9341_Opts.width = ILI9341_WIDTH;
	ILI9341_Opts.height = ILI9341_HEIGHT;
	ILI9341_Opts.orientation = TM_ILI9341_Portrait;
	
	TM_ILI9341_Fill(ILI9341_COLOR_WHITE);
}
Esempio n. 15
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 */
	}
}
Esempio n. 16
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. 17
0
void TM_ILI9341_Init()
{
	GPIO_InitTypeDef GPIO_InitDef;

	RCC_AHB1PeriphClockCmd(ILI9341_WRX_CLK, ENABLE);

	GPIO_InitDef.GPIO_Pin = ILI9341_WRX_PIN;
	GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
	GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(ILI9341_WRX_PORT, &GPIO_InitDef);


	RCC_AHB1PeriphClockCmd(ILI9341_CS_CLK, ENABLE);
	GPIO_InitDef.GPIO_Pin = ILI9341_CS_PIN;
	GPIO_Init(ILI9341_CS_PORT, &GPIO_InitDef);


	RCC_AHB1PeriphClockCmd(ILI9341_RST_CLK, ENABLE);
	GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitDef.GPIO_Pin = ILI9341_RST_PIN;
	GPIO_Init(ILI9341_RST_PORT, &GPIO_InitDef);

	ILI9341_CS_SET;

	//TM_SPI_Init(ILI9341_SPI, TM_SPI_PinsPack_1);
		  SPI_InitTypeDef  SPI_InitStructure;
		  	  GPIO_InitTypeDef GPIO_InitStructure;

		  	  	  /* Enable the SPI periph */
	  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

	  /* Enable SCK, MOSI and MISO GPIO clocks */
	  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);

	  GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
	  GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
	  GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);

	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_DOWN;
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

		  /* SPI pins configuration */
	  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
	  GPIO_Init(GPIOB, &GPIO_InitStructure);

	  /* SPI configuration -------------------------------------------------------*/
	  SPI_I2S_DeInit(SPI2);
	  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
	  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
	  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
	  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
	  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
	  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
	  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
	  SPI_InitStructure.SPI_CRCPolynomial = 7;
	  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
	  SPI_Init(SPI2, &SPI_InitStructure);

	  /* Enable SPI1  */
	  SPI_Cmd(SPI2, ENABLE);

	TM_ILI9341_InitLCD();

	TM_ILI9341_Fill(ILI9341_COLOR_WHITE);

	ILI9341_x = ILI9341_y = 0;

	ILI9341_Opts.width = ILI9341_WIDTH;
	ILI9341_Opts.height = ILI9341_HEIGHT;
	ILI9341_Opts.orientation = TM_ILI9341_Portrait;
}
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
int main(void) {

    int accelData[3];
    int analogData[BUFFER];
    int i=0;
    for(i=0;i<BUFFER;i++){ analogData[i]=0;	}
    int a = 0;
    int analogIn = 0;
    int analogMin, analogMax;

    /* Initialize system */
    SystemInit();

    /* Initialize delay */
    //TM_DELAY_Init();

    /* Initialize PG13 (GREEN LED) and PG14 (RED LED) */
    TM_GPIO_Init(GPIOG, GPIO_PIN_13 | GPIO_PIN_14, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    TM_GPIO_SetPinValue(GPIOG, GPIO_PIN_14, 1); // Red: ON

#ifdef ENABLE_USART
    /* Initialize USART1 at 115200 baud, TX: PA10, RX: PA9 */
    TM_USART_Init(USART1, TM_USART_PinsPack_1, 115200);
#endif

#ifdef ENABLE_VCP
    /* Initialize USB Virtual Comm Port */

    TM_USB_VCP_Result status = TM_USB_VCP_NOT_CONNECTED;
    while (TM_USB_VCP_GetStatus() != TM_USB_VCP_CONNECTED) {
    	TM_USB_VCP_Init();
    	TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14);
    	Delay(500000);
    }
    SendString("USB VCP initialized and connected\n");
    TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_14 | GPIO_PIN_13); // Red: OFF, Gr: ON

#endif

#ifdef ENABLE_MMA

    /* Initialize MMA845X */
    uint8_t mma_status = MMA845X_Initialize(MMA_RANGE_4G);
    if (mma_status == MMA_OK) {
    	SendString("MMA initialized\n");
    } else {
    	SendString("MMA initialization failed, error code: ");
    	// Add 48 to the byte value to have character representation, (48 = '0')
    	SendChar('0'+mma_status);
    	SendChar('\n');
    }

#endif

    /* Initialize Display */
	TM_ILI9341_Init();
	TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_1);
	TM_ILI9341_SetLayer1();
	TM_ILI9341_Fill(ILI9341_COLOR_BLACK); /* Fill data on layer 1 */

	/* Initialize ADC1 */
	TM_ADC_Init(CURRENT_ADC, CURRENT_CH);

	/* Initialize PE2 and PE3 for digital output (Motor direction) */
    TM_GPIO_Init(GPIOE, GPIO_PIN_2 | GPIO_PIN_3, TM_GPIO_Mode_OUT, TM_GPIO_OType_PP, TM_GPIO_PuPd_NOPULL, TM_GPIO_Speed_Fast);
    // Set them to HIGH/LOW
    TM_GPIO_SetPinHigh(GPIOE, GPIO_PIN_3);
    TM_GPIO_SetPinLow(GPIOE, GPIO_PIN_2);

#ifdef ENABLE_PWM
    /* Set up PE5 (in front of PE4) for PWM (TIM9 CH1 PP2) (Motor speed control) */
    TM_PWM_TIM_t TIM9_Data;
    // Set PWM to 1kHz frequency on timer TIM4, 1 kHz = 1ms = 1000us
	TM_PWM_InitTimer(TIM9, &TIM9_Data, 1000);
	// Initialize PWM on TIM9, Channel 1 and PinsPack 2 = PE5
	TM_PWM_InitChannel(&TIM9_Data, TM_PWM_Channel_1, TM_PWM_PinsPack_2);
	// Set channel 1 value, 50% duty cycle
	TM_PWM_SetChannelPercent(&TIM9_Data, TM_PWM_Channel_1, 50);
#endif

	/* Initialize DAC channel 2, pin PA5 (Shaker control) */
	//TM_DAC_Init(TM_DAC2);
	/* Set 12bit analog value of 2047/4096 * 3.3V */
	//TM_DAC_SetValue(TM_DAC2, 4096);

#ifdef ENABLE_DAC
	// DAC PIN PA5
	/* Initialize DAC1, use TIM4 for signal generation */
	TM_DAC_SIGNAL_Init(TM_DAC2, TIM4);
	/* Output predefined triangle signal with frequency of 5kHz */
	TM_DAC_SIGNAL_SetSignal(TM_DAC2, TM_DAC_SIGNAL_Signal_Sinus, 50);
#endif

	/* MAIN LOOP */
    while (1) {

    	// Read acceleration data
#ifdef ENABLE_MMA
		MMA845X_ReadAcceleration(accelData);
#endif

		// Read analog input
		analogData[a] = TM_ADC_Read(CURRENT_ADC, CURRENT_CH);
		a++;
		if(a==BUFFER) {a=0;}

		// Analog average
		analogIn=0;
		analogMax=0;
		analogMin=4096;
		for(i=0;i<BUFFER;i++){
			if(analogData[i] > analogMax) { analogMax = analogData[i]; }
			if(analogData[i] < analogMin) { analogMin = analogData[i]; }
			analogIn+=analogData[i];
		}
		analogIn/=BUFFER;

		// Print graphs
		printGraphsLCD(accelData, analogData[a], analogIn, analogMin, analogMax);

		// Toggle Green led
		TM_GPIO_TogglePinValue(GPIOG, GPIO_PIN_13);

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