Esempio n. 1
0
void IO_SetBit(u8 bit, u8 value)
{
	if(value)
		XGpio_DiscreteSet(&gpio, 1, (1u<<bit));
	else
		XGpio_DiscreteClear(&gpio, 1, (1u<<bit));
}
Esempio n. 2
0
/******************************************************************************
 * This function displays the pixel buffer, pointed to with psScreenBuf, onto
 * the OLED display.
 *
 * @param	psSpi is the pointer to the SPI driver structure.
 * @param	psGpio is the pointer to the GPIO driver structure.
 * @param	pchScreenBuf is the pointer to the pixel buffer to display on the
 * 			OLED screen.
 *
 * @return	XST_SUCCESS - Everything went well
 * 			XST_FAILURE - Failure
 *****************************************************************************/
XStatus fnOledPixelToDisplay(XSpi *psSpi, XGpio *psGpio,
		const sPixmap_t *psScreenBuf) {

	XStatus Status;
	u32 iPg;
	u8 rgbWrBuf[10];
	u8 u8LowerStartColumn = 0x00;
	u8 u8UpperStartColumn = 0x10;

	// Going through each character line (4)
	for(iPg = 0; iPg < OLED_MAX_PG_CNT; iPg++) {

		rgbWrBuf[0] = OLED_SET_PG_ADDR_CMD;
		rgbWrBuf[1] = iPg;
		rgbWrBuf[2] = u8LowerStartColumn;
		rgbWrBuf[3] = u8UpperStartColumn;

		XGpio_DiscreteClear(psGpio, 1, OLED_DC_MASK);

		u8TransferInProg = TRUE;
		Status = XSpi_Transfer(psSpi, rgbWrBuf, NULL, 4);
		if(Status != XST_SUCCESS) {
			return Status;
		}
		while(u8TransferInProg);

		XGpio_DiscreteSet(psGpio, 1, OLED_DC_MASK);

		// Writing the line to the OLED
		u8TransferInProg = TRUE;
		Status = XSpi_Transfer(psSpi, (u8 *)(psScreenBuf->rgbPixmap +
				(iPg * OLED_CONTROLLER_PG_SZ)), NULL, OLED_CONTROLLER_PG_SZ);
		if(Status != XST_SUCCESS) {
			return Status;
		}
		while(u8TransferInProg);
	}

	return XST_SUCCESS;
}
Esempio n. 3
0
/******************************************************************************
 * This function initializes the OLED display with the proper procedure.
 *
 * @param	psSpi is the pointer to the SPI driver structure.
 * @param	psGpio is the pointer to the GPIO driver structure.
 *
 * @return	XST_SUCCESS - Everything went well
 * 			XST_FAILURE - Failure
 *
 * @note	This is how the GPIO is mapped to the OLED controller:
 *				gpio(0) = vbat
 *				gpio(1) = vdd
 *				gpio(2) = res
 *				gpio(3) = dc
 *****************************************************************************/
XStatus fnOledDisplayInit(XSpi *psSpi, XGpio *psGpio) {

	XStatus Status;
	u8 rgbWrBuf[10];

	// Clear the data/cmd bit
	XGpio_DiscreteClear(psGpio, 1, OLED_DC_MASK);

	// Start by turning VDD on and wait for the power to come up
	XGpio_DiscreteClear(psGpio, 1, OLED_VDD_MASK);
	MB_Sleep(1);

	// Send to SPI the display off command
	rgbWrBuf[0] = OLED_DISPLAY_OFF_CMD;
	u8TransferInProg = TRUE;
	Status = XSpi_Transfer(psSpi, rgbWrBuf, NULL, 1);
	while(u8TransferInProg);

	// Bring reset low and then high
	XGpio_DiscreteSet(psGpio, 1, OLED_RES_MASK);
	MB_Sleep(1);
	XGpio_DiscreteClear(psGpio, 1, OLED_RES_MASK);
	MB_Sleep(1);
	XGpio_DiscreteSet(psGpio, 1, OLED_RES_MASK);

	// Send the set charge pump and set pre-charge period commands
	rgbWrBuf[0] = 0x8D;
	rgbWrBuf[1] = 0x14;
	rgbWrBuf[2] = OLED_SET_PRECHARGE_PER_CMD;
	rgbWrBuf[3] = 0xF1;
	u8TransferInProg = TRUE;
	Status = XSpi_Transfer(psSpi, rgbWrBuf, NULL, 4);
	while(u8TransferInProg);

	// Turn on VCC and wait 100 ms
	XGpio_DiscreteClear(psGpio, 1, OLED_VBAT_MASK);
	MB_Sleep(100);

	// Set display contrast
	rgbWrBuf[0] = OLED_CONTRAST_CTRL_CMD;
	rgbWrBuf[1] = 0x0F;

	// Invert the display
	rgbWrBuf[2] = OLED_SET_SEGMENT_REMAP_CMD;
	rgbWrBuf[3] = OLED_SET_COM_DIR_CMD;

	// Select sequential COM configuration
	rgbWrBuf[4] = OLED_SET_COM_PINS_CMD;
	rgbWrBuf[5] = 0x00;
	rgbWrBuf[6] = 0xC0;
	rgbWrBuf[7] = 0x20;
	rgbWrBuf[8] = 0x00;

	// Turn display on
	rgbWrBuf[9]/*[6]*/ = OLED_DISPLAY_ON_CMD;

	u8TransferInProg = TRUE;
	Status = XSpi_Transfer(psSpi, rgbWrBuf, NULL, 10);
	while(u8TransferInProg);

	//Display Digilent logo
	fnOledPixelToDisplay(psSpi, psGpio, &sLogoPixmap);

	return Status;
}
Esempio n. 4
0
int main()
{
    int i;
    init_platform();
    print("--Starting...--\n\r");

    /*for (i = 0; i < n_memory_ranges; i++) {
        test_memory_range(&memory_ranges[i]);
    }*/

	int Status;
	/* Initialize the GPIO driver. If an error occurs then exit */
	Status = XGpio_Initialize(&gpio_btn, XPAR_GPIO_BTN_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/* Initialize the GPIO driver. If an error occurs then exit */
	Status = XGpio_Initialize(&gpio_led, XPAR_GPIO_LED_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test on the GPIO.  This is a minimal test and only
	 * verifies that there is not any bus error when reading the data
	 * register
	 */
	XGpio_SelfTest(&gpio_btn);
	XGpio_SelfTest(&gpio_led);

	XGpio_SetDataDirection(&gpio_btn, XGPIO_IR_CH1_MASK, 0x1);
	XGpio_SetDataDirection(&gpio_led, XGPIO_IR_CH1_MASK, 0x0);

	XGpio_DiscreteClear(&gpio_led, XGPIO_IR_CH1_MASK, 0xffff);

	param_setup();
	XMcml_Initialize(&mcml, XPAR_MCML_0_DEVICE_ID);
    print("--Starting Kernel--\n\r");
	XMcml_Start(&mcml);

    //cleanup_platform();
    while (1)
    {
    	if(XMcml_IsDone(&mcml)) break;
    }

    print("NOTE: MCML kernel is done.\n\r");
	XGpio_DiscreteSet(&gpio_led, XGPIO_IR_CH1_MASK, 0x1);

	float * ar_z = (float *)memory_ranges[ARZ_CTRL].base;
	for(i=0; i< 10000; i++)
	{
		int whole, thousandths;
		float fval = *(ar_z++);
		whole = fval;
		thousandths = (fval - whole) * 1000;
		if(i % 100 == 0)
			xil_printf("\n\r");

		xil_printf("%d.%3d *", whole, thousandths);

	}
	XGpio_DiscreteSet(&gpio_led, XGPIO_IR_CH1_MASK, 0x3);
    print("--DONE-- \n\r");
    return 0;
}
/**
* This function is the Interrupt Service Routine for the GPIO device.  It
* will be called by the processor whenever an interrupt is asserted by the
* device.
*
* This function will detect the push button on the board has changed state
* and then turn on or off the LED.
*
* @param	InstancePtr is the GPIO instance pointer to operate on.
*		It is a void pointer to meet the interface of an interrupt
*		processing function.
*
* @return	None.
*
* @note		None.
*
*****************************************************************************/
void GpioIsr(void *InstancePtr)
{
	XGpio *GpioPtr = (XGpio *)InstancePtr;
	u32 Led;
	u32 LedState;
	u32 Buttons;
	u32 ButtonFound;
	u32 ButtonsChanged = 0;
	static u32 PreviousButtons;

	/*
	 * Disable the interrupt
	 */
	XGpio_InterruptDisable(GpioPtr, BUTTON_INTERRUPT);

	/* Keep track of the number of interrupts that occur */

	InterruptCount++;

	/*
	 * There should not be any other interrupts occuring other than the
	 * the button changes
	 */
	if ((XGpio_InterruptGetStatus(GpioPtr) & BUTTON_INTERRUPT) !=
		BUTTON_INTERRUPT) {
		return;
	}


	/*
	 * Read state of push buttons and determine which ones changed
	 * states from the previous interrupt. Save a copy of the buttons
	 * for the next interrupt
	 */
	Buttons = XGpio_DiscreteRead(GpioPtr, BUTTON_CHANNEL);
	ButtonsChanged = Buttons ^ PreviousButtons;
	PreviousButtons = Buttons;

	/*
	 * Handle all button state changes that occurred since the last
	 * interrupt
	 */
	while (ButtonsChanged != 0) {
		/*
		 * Determine which button changed state and then get
		 * the current state of the associated LED
		 */
		 Led = MapButton2Led(ButtonsChanged, &ButtonFound);
		 LedState = XGpio_DiscreteRead(GpioPtr, LED_CHANNEL) & Led;

		 /*
		  * Clear the button that is being processed so that it is
		  * done and others can be handled also
		  */
		 ButtonsChanged &= ~ButtonFound;

		 /* Toggle the state of the LED */
		 if (LedState) {
			 XGpio_DiscreteClear(GpioPtr, LED_CHANNEL, Led);
		 } else {
			 XGpio_DiscreteSet(GpioPtr, LED_CHANNEL, Led);
		 }
	 }

	 /* Clear the interrupt such that it is no longer pending in the GPIO */

	 (void)XGpio_InterruptClear(GpioPtr, BUTTON_INTERRUPT);

	 /*
	  * Enable the interrupt
	  */
	 XGpio_InterruptEnable(GpioPtr, BUTTON_INTERRUPT);

}
Esempio n. 6
0
void IO_Set(u8 bit)
{
	XGpio_DiscreteSet(&gpio, 1, (1u<<bit));
}
Esempio n. 7
0
inline void wl_setDebugGPIO(u8 mask){
	XGpio_DiscreteSet(&GPIO_debugpin, 1, mask);
}
Esempio n. 8
0
/**
*
* The purpose of this function is to illustrate how to use the GPIO level 1
* driver to turn on and off an LED.
*
* @param	None
*
* @return	XST_FAILURE to indicate that the GPIO Intialisation had failed.
*
* @note		This function will not return if the test is running.
*
******************************************************************************/
int main(void)
{
	u32 Data;
	int Status;
	volatile int Delay;

	/*
	 * Initialize the GPIO driver
	 */
	Status = XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the direction for all signals to be inputs except the
	 * LED output
	 */
	XGpio_SetDataDirection(&Gpio, LED_CHANNEL, ~LED);

	/* Loop forever blinking the LED */

	while (1) {
		/*
		 * Read the state of the data so that only the LED state can be
		 * modified
		 */
		Data = XGpio_DiscreteRead(&Gpio, LED_CHANNEL);

		/*
		 * Set the LED to the opposite state such that it blinks using
		 * the first method, two methods are used for illustration
		 * purposes only
		 */
		if (Data & LED) {
			XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, Data & ~LED);
		} else {
			XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, Data | LED);
		}

		/* Wait a small amount of time so the LED is visible */

		for (Delay = 0; Delay < LED_DELAY; Delay++);

		/*
		 * Read the state of the data so that only the LED state can be
		 * modified
		 */
		Data = XGpio_DiscreteRead(&Gpio, LED_CHANNEL);

		/*
		 * Set the LED to the opposite state such that it blinks using
		 * the other API functions
		 */
		if (Data & LED) {
			XGpio_DiscreteClear(&Gpio, LED_CHANNEL, LED);
		} else {
			XGpio_DiscreteSet(&Gpio, LED_CHANNEL, LED);
		}

		/* Wait a small amount of time so the LED is visible */

		for (Delay = 0; Delay < LED_DELAY; Delay++);
	}

	return XST_SUCCESS;
}