Example #1
0
int main(void)
{
	char str[20];
	unsigned int channel0;
	unsigned int channel1;
	float lux;

	SPI_Initialize();					//Initialize SPI peripheral
	TFT_Initialize();
	
	I2C_Initialize(APDS9300ADDR);		//Initialize I2C and setup chip address	
	
	AL_Initialize();					//Setup Ambient light sensor

	Image_t LampOn = {_acLampON,100,100};
	TFT_Background(WHITE);
	
	TFT_DisplayImage(&LampOn,5,5);
	
    while(1)
    { 	 
		channel0 = AL_ReadChannel(CH0);		//Take a reading from channel one
		channel1 = AL_ReadChannel(CH1);		//Take a reading from channel two	
        lux = AL_Lux(channel0,channel1);
		sprintf(str, "%3.2f Lx ", lux);
		TFT_PrintString(10,140,RED,WHITE,str,2);
		delay_ms(1000);
    }

    return 0;
}
Example #2
0
int main(void)
{
	SPI_Initialize();				//Initialize SPI peripheral
	TFT_Initialize();
	I2C_Initialize(CAP1203ADDR);
	
    CAP1203_Initialize();
	
	unsigned char button = 0x00;
	
	#ifdef __DEBUG__
		int id = CAP1203_ReadID();							//Read ID of Capacitive touch controller 
		printf("Chip ID: 0x%04X. \r\n",id);
	#endif
	
	TFT_Background(WHITE);
	TFT_Circle(80,35,20,RED);
	TFT_Circle(80,80,20,GREEN);
	TFT_Circle(80,125,20,BLUE);
	  
	while(1)
	{
		button = CAP1203_ReadPressedButton();
			switch(button)
			{
				case 1:
					TFT_Disk(80,125,10,BLUE);
					printf("Button B1 pressed.\r\n");
					break;
				case 2:
					TFT_Disk(80,80,10,GREEN);
					printf("Button B2 pressed.\r\n");
					break;					
				case 3:
					TFT_Disk(80,35,10,RED);
					printf("Button B3 pressed.\r\n");
					break;				
				default:
					TFT_Circle(80,35,20,RED);				//Paint two circles for an annular ring
					TFT_Circle(80,80,20,GREEN);
					TFT_Circle(80,125,20,BLUE);	
					TFT_Circle(80,35,19,RED);
					TFT_Circle(80,80,19,GREEN);
					TFT_Circle(80,125,19,BLUE);
					
					TFT_Disk(80,35,10,WHITE);				//Clear interior
					TFT_Disk(80,80,10,WHITE);
					TFT_Disk(80,125,10,WHITE);
					break;
			}	
		delay_ms(100);		
    }
    return 0;
}
Example #3
0
int main(void)
{
	
	char str[20];
	unsigned int channel0;
	unsigned int channel1;
	float lux;
	
	signal(SIGINT, sigint_handler);		//Install signal handler for user interrupt (CTRL-C)
	
	SPI_Initialize();					//Initialize SPI peripheral
	TFT_Initialize();
	
	I2C_Initialize(APDS9300ADDR);		//Initialize I2C and setup chip address	
	AL_Initialize();					//Setup Ambient light sensor

	Image_t LampOn = {_acLampON,100,100};
	TFT_Background(WHITE);
	
	TFT_DisplayImage(&LampOn,5,5);
	
    while(programRunning)
    { 	 
		channel0 = AL_ReadChannel(CH0);		//Take a reading from channel one
		channel1 = AL_ReadChannel(CH1);		//Take a reading from channel two	
        lux = AL_Lux(channel0,channel1);
		sprintf(str, "%3.2f Lx ", lux);
		TFT_PrintString(10,140,RED,WHITE,str,2);
		delay_ms(1000);		
    }
	
	SPI_Close();
	bcm2835_close();
	
    return 0;
}
Example #4
0
int main(void)
{

	SPI_Initialize();				//Initialize SPI peripheral
	TFT_Initialize();

	char texty[] = "Sensorian-123";

    while(1)
    {
		TFT_Background(WHITE);
		TFT_SetRotation(PORTRAIT);		//Portrait mode 
		TFT_VerticalLine(5,5,90,BLUE);
		TFT_PrintString(10,80,FOREGROUND,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(PORTRAIT_INV);		//Portrait mode 
		TFT_VerticalLine(5,5,90,GREEN);
		TFT_PrintString(10,80,RED,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(PORTRAIT_REF);			//Portrait mode reflected 
		TFT_VerticalLine(5,5,90,YELLOW);
		TFT_PrintString(10,80,GREEN,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(PORTRAIT_INV_REF);		
		TFT_VerticalLine(5,5,90,RED);			//Portrait mode reflected
		TFT_PrintString(10,80,PURPLE,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(LANDSCAPE);			//Landscape mode 
		TFT_VerticalLine(5,5,80,GRAY1);
		TFT_PrintString(10,80,GREEN,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(LANDSCAPE_REF);				//Landscape mode  reflected
		TFT_VerticalLine(5,5,80,PURPLE);
		TFT_PrintString(10,80,PURPLE,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(LANDSCAPE_INV);			//Landscape mode inverted
		TFT_VerticalLine(5,5,80,NAVY);
		TFT_PrintString(10,80,RED,BACKGROUND,texty,1);
		delay_ms(DELAY);   
		
		TFT_Background(WHITE);
		TFT_SetRotation(LANDSCAPE_INV_REF);
		TFT_VerticalLine(5,5,80,PURPLE);
		TFT_PrintString(10,80,FOREGROUND,BACKGROUND,texty,1);	//Landscape mode inverted reflected
		delay_ms(DELAY);     
    }
	
	SPI_Close();

    return 0;
}
/**
 * @brief Prepares the TFT LCD and its SPI bus for use, clearing the screen to black as well
 * @return none
 */
void TFT_Setup()
{
    SPI_Initialize(); //Prepare the SPI bus for use by the LCD
    TFT_Initialize(); //Prepare the TFT LCD for use
    TFT_Background(BLACK); //Clear the screen to Black
}
Example #6
0
int main()
{

	/********************** TouchSensor Setup *********************/
	Status = TouchSensor_Initialize(&touchSensor, XPAR_TOUCHSENSOR_0_DEVICE_ID);
	if (Status != XST_SUCCESS)
	{
	//	printf("TouchSensor initialisation error\n\r\r");
	}
    TouchSensorButtons_InitializeManager(&Manager, &touchSensor, &PrintTouchCoordinates);

    button_t GameboardGridButton;
    Button_SetGridDim(&GameboardGridButton, SQUARE_DIM, SQUARE_DIM, BOARD_OFFSET_X, BOARD_OFFSET_Y, BOARD_SIZE, BOARD_SIZE);
    Button_AssignHandler(&GameboardGridButton, &HandleGameboardTouch);
    TouchSensorButtons_RegisterButton(&Manager, &GameboardGridButton);
    TouchSensorButtons_EnableButton(&GameboardGridButton);

    button_t WhiteModeButton;
    Button_SetGridDim(&WhiteModeButton, 50, 50, 300, 10 , 3, 1);
    Button_AssignHandler(&WhiteModeButton, &HandleWhiteModeTouch);
    TouchSensorButtons_RegisterButton(&Manager, &WhiteModeButton);
    TouchSensorButtons_EnableButton(&WhiteModeButton);

    button_t BlackModeButton;
    Button_SetGridDim(&BlackModeButton, 50, 50, 300, 75, 3, 1);
    Button_AssignHandler(&BlackModeButton, &HandleBlackModeTouch);
    TouchSensorButtons_RegisterButton(&Manager, &BlackModeButton);
    TouchSensorButtons_EnableButton(&BlackModeButton);

    button_t ResetButton;
    Button_SetRectDim(&ResetButton, 100, 50, 325, 200);
    Button_AssignHandler(&ResetButton, &HandleResetTouch);
    TouchSensorButtons_RegisterButton(&Manager, &ResetButton);
    TouchSensorButtons_EnableButton(&ResetButton);

    /********************** BoardCount Accelerator Setup********************/
    initialize_accelerator(&board_count_accelerator, XPAR_GENERATE_BOARD_COUNTS_TOP_0_S_AXI_CTRL_BASEADDR);

    /********************** TFT Setup *********************/
    blackScreen();


	TFT_Initialize(&tft, XPAR_TFT_PERHIPHERAL_0_DEVICE_ID);
	TFT_SetImageAddress(&tft, XPAR_MCB_DDR2_S0_AXI_BASEADDR);
	TFT_SetBrightness(&tft, 7);
	TFT_TurnOn(&tft);


	//Render Buttons
	//TouchSensorButtons_RenderButton(&MyCircle, GREEN, &tft);
	//TouchSensorButtons_RenderButton(&MyRect, RED, &tft);
	TouchSensorButtons_RenderButton(&GameboardGridButton, BLUE, &tft);
	TouchSensorButtons_RenderButton(&ResetButton, ORANGE, &tft);
	TouchSensorButtons_RenderButton(&WhiteModeButton, WHITE, &tft);
	TouchSensorButtons_RenderButton(&BlackModeButton, RED, &tft);


    Gameboard.TftPtr = &tft;

    /********************** UART Setup *********************/

    Status = XUartLite_Initialize(&Uart, XPAR_UARTLITE_1_DEVICE_ID);
    if (Status != XST_SUCCESS)
    {
        printf("XUartLite initialization error\n\r");
    }

    XUartLite_SetRecvHandler(&Uart, (XUartLite_Handler) &RecvUartCommand, &Uart);



/********************** Interrupt Controller Setup *********************/
   /*
	* Initialize the interrupt controller driver so that it's ready to use,
	* using the device ID that is generated in xparameters.h
	*/
   Status = XIntc_Initialize(&InterruptController, XPAR_AXI_INTC_0_DEVICE_ID);
   if (Status != XST_SUCCESS)
   {
	   //printf("Interrupt controller initialization error\n\r");
   }

   /*
	* Connect the device driver handler that will be called when an interrupt
	* for the device occurs, the device driver handler performs the specific
	* interrupt processing for the device
	*/
   Status = XIntc_Connect(&InterruptController,
		   XPAR_AXI_INTC_0_TOUCHSENSOR_0_INTERRUPT_INTR,
						  (XInterruptHandler)TouchSensorButtons_InterruptHandler,
						  &Manager);
   if (Status != XST_SUCCESS)
   {
	   //printf("Interrupt controller connect error\n\r");
   }

   Status = XIntc_Connect(&InterruptController,
		   XPAR_AXI_INTC_0_RS232_UART_1_INTERRUPT_INTR,
						  (XInterruptHandler)XUartLite_InterruptHandler,
						  &Uart);
   if (Status != XST_SUCCESS)
   {
	   printf("Interrupt controller connect to Uart error\n\r");
   }


   Status = XIntc_Start(&InterruptController, XIN_REAL_MODE);
   if (Status != XST_SUCCESS)
   {
	   //printf("Interrupt controller start error\n\r");
   }

   XIntc_Enable(&InterruptController,
		   XPAR_AXI_INTC_0_TOUCHSENSOR_0_INTERRUPT_INTR);
   XIntc_Enable(&InterruptController,
		   XPAR_AXI_INTC_0_RS232_UART_1_INTERRUPT_INTR);

   XUartLite_ResetFifos(&Uart);
   XUartLite_EnableInterrupt(&Uart);

   AI_PLAYER ai = default_ai();
   PLAYER Player1, Player2;
   Player1.num = P1;
   Player2.num = P2;
   Gameboard_Initialize(&Gameboard,human,fpga);
   microblaze_enable_interrupts();

   while (1) {
		PLAYER Curr_P, Opp_P;

		//Workaround to enable multiple resets on turn 0.
		if (Gameboard.MoveBufferSize == -1)
			Gameboard.MoveBufferSize++;

		int CurrentMove = Gameboard.MoveBufferSize;
		player_mode_t CurrentPlayerMode = (CurrentMove % 2) ? Gameboard.WhiteMode : Gameboard.BlackMode;
		Curr_P = (CurrentMove % 2) ? Player1 : Player2;
		Opp_P = (CurrentMove % 2) ? Player2 : Player1;
		switch (CurrentPlayerMode){
			case human:
				TouchSensorButtons_EnableButton(&GameboardGridButton);
				break;
			case fpga:
				TouchSensorButtons_DisableButton(&GameboardGridButton);
				HandleAiMove(ai, Gameboard.master_board, Curr_P, Opp_P);
				break;
			case uart:
				TouchSensorButtons_DisableButton(&GameboardGridButton);
				if(Gameboard.MoveBufferSize > 0){
					SendUartCommand(&Uart, Gameboard.MoveBuffer[Gameboard.MoveBufferSize-1].X,
										Gameboard.MoveBuffer[Gameboard.MoveBufferSize-1].Y);
				}
				break;
			default:
				TouchSensorButtons_EnableButton(&GameboardGridButton);
				break;
		}
		/*
		if (check_board_full(Gameboard.master_board)) {
			//printf("Gameboard full\n\r");
			break;
		}
		*/
		if (check_board_win(Gameboard.master_board, Curr_P)) {
			xil_printf("Player %s won\n\r", (Curr_P.num == P1) ? "white" : "black");
			//Spin waiting on reset
			while(Gameboard.MoveBufferSize != -1);
		}

		while(CurrentMove == Gameboard.MoveBufferSize);

   }

	return 0;
}