Beispiel #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);
		*/
	}
}
void TM_ILI9341_ChangeLayers(void) {
	if (ILI9341_Opts.CurrentLayer == 0) {
		TM_ILI9341_SetLayer2();
		TM_ILI9341_SetLayer1Opacity(0);
		TM_ILI9341_SetLayer2Opacity(255);
	} else {
		TM_ILI9341_SetLayer1();
		TM_ILI9341_SetLayer1Opacity(255);
		TM_ILI9341_SetLayer2Opacity(0);
	}
}
Beispiel #3
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();
}
Beispiel #5
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);

    }
}