/****************************************************************************** * This function initializes the SPI and GPIO drivers needed to control the * OLED display. * * @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_DEVICE_NOT_FOUND - Device not found * XST_FAILURE - Failure *****************************************************************************/ XStatus fnOledDriverInit(XSpi *psSpi, XGpio *psGpio) { XStatus Status; XSpi_Config *SpiConfigPtr; XGpio_Config *GpioConfigPtr; // Initialize the SPI driver so that it is ready to use. SpiConfigPtr = XSpi_LookupConfig(OLED_SPI_DEVICE_ID); if(SpiConfigPtr == NULL) { return XST_DEVICE_NOT_FOUND; } Status = XSpi_CfgInitialize(psSpi, SpiConfigPtr, SpiConfigPtr->BaseAddress); if(Status != XST_SUCCESS) { return XST_FAILURE; } // Initialize the GPIO driver GpioConfigPtr = XGpio_LookupConfig(OLED_GPIO_DEVICE_ID); if(GpioConfigPtr == NULL) { return XST_DEVICE_NOT_FOUND; } Status = XGpio_CfgInitialize(psGpio, GpioConfigPtr, GpioConfigPtr->BaseAddress); if(Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/** * Initialize the XGpio instance provided by the caller based on the * given DeviceID. * * Nothing is done except to initialize the InstancePtr. * * @param InstancePtr is a pointer to an XGpio instance. The memory the pointer * references must be pre-allocated by the caller. Further calls to * manipulate the component through the XGpio API must be made with this * pointer. * * @param DeviceId is the unique id of the device controlled by this XGpio * component. Passing in a device id associates the generic XGpio * instance to a specific device, as chosen by the caller or application * developer. * * @return * * - XST_SUCCESS Initialization was successfull. * - XST_DEVICE_NOT_FOUND Device configuration data was not found for a device * with the supplied device ID. * * NOTES: * * None * *****************************************************************************/ XStatus XGpio_Initialize(XGpio * InstancePtr, u16 DeviceId) { XGpio_Config *ConfigPtr; /* * Assert arguments */ XASSERT_NONVOID(InstancePtr != NULL); /* * Lookup configuration data in the device configuration table. * Use this configuration info down below when initializing this component. */ ConfigPtr = XGpio_LookupConfig(DeviceId); if (ConfigPtr == (XGpio_Config *) NULL) { InstancePtr->IsReady = 0; return (XST_DEVICE_NOT_FOUND); } /* * Set some default values. */ InstancePtr->BaseAddress = ConfigPtr->BaseAddress; /* * Indicate the instance is now ready to use, initialized without error */ InstancePtr->IsReady = XCOMPONENT_IS_READY; return (XST_SUCCESS); }
void init_GPIO_BUTTONS(XGpio *InstancePtr, u16 Device_ID) { int Status; XGpio_Config *Config; Config = XGpio_LookupConfig(Device_ID); Status = XGpio_CfgInitialize(InstancePtr, Config, Config->BaseAddress); // Initialise GPIO devices Status = XGpio_Initialize(InstancePtr, Device_ID); // Set GPIO direction (output for LEDs and input for BTNS) XGpio_SetDataDirection(InstancePtr, 1, 0xFF); if(Status != XST_FAILURE) { xil_printf("BUTTONS initialized!\n \r"); } XGpio_InterruptEnable(&ButtonsInstancePtr, 1); XGpio_InterruptGlobalEnable(&ButtonsInstancePtr); // Initialize interrupt controller //IntcInitFunction(INTCONTROLLER_DEVICE_ID, InstancePtr); }
/* * Initialize GPIO instance for qdrA Testing */ int qthTest_Init() { XGpio_Config* gpioConfigPtr; int i; int Status; gpioConfigPtr = XGpio_LookupConfig(XPAR_AXI_GPIO_RW_0_DEVICE_ID); if (gpioConfigPtr == NULL) { return XST_FAILURE; } Status = XGpio_CfgInitialize(&gpioRW0_ctrl, gpioConfigPtr, gpioConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } gpioConfigPtr = XGpio_LookupConfig(XPAR_AXI_GPIO_RO_0_DEVICE_ID); if (gpioConfigPtr == NULL) { return XST_FAILURE; } Status = XGpio_CfgInitialize(&gpioRO0_status, gpioConfigPtr, gpioConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } for(i = 0; i < 8; i++) { gpioConfigPtr = XGpio_LookupConfig(arGpioDevIds[i]); if (gpioConfigPtr == NULL) { return XST_FAILURE; } Status = XGpio_CfgInitialize(&gpioROs[i], gpioConfigPtr, gpioConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } } XGpio_DiscreteWrite(&gpioRW0_ctrl, 1, 0x01); for(i = 0; i < 100; i++) { asm("nop"); } XGpio_DiscreteWrite(&gpioRW0_ctrl, 1, 0x00); return XST_SUCCESS; }
/***************************************************************************//** * @brief gpio_init *******************************************************************************/ void gpio_init(uint32_t device_id) { #ifdef _XPARAMETERS_PS_H_ gpio_config = XGpioPs_LookupConfig(device_id); XGpioPs_CfgInitialize(&gpio_instance, gpio_config, gpio_config->BaseAddr); #else gpio_config = XGpio_LookupConfig(device_id); #endif }
/* * Initialize GPIO instance for qdrA Testing */ int qdrTest_Init() { XGpio_Config* gpioConfigPtr; int Status; gpioConfigPtr = XGpio_LookupConfig(XPAR_AXI_GPIO_RO_0_DEVICE_ID); if (gpioConfigPtr == NULL) { return XST_FAILURE; } Status = XGpio_CfgInitialize(&gpioInstance, gpioConfigPtr, gpioConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/***************************************************************************//** * @brief gpio_init *******************************************************************************/ int32_t gpio_init(uint32_t device_id) { uint32_t base_addr = 0; #ifdef _XPARAMETERS_PS_H_ gpio_config = XGpioPs_LookupConfig(device_id); base_addr = gpio_config->BaseAddr; XGpioPs_CfgInitialize(&gpio_instance, gpio_config, base_addr); #else gpio_config = XGpio_LookupConfig(device_id); base_addr = gpio_config->BaseAddress; XGpio_CfgInitialize(&gpio_instance, gpio_config, base_addr); #endif return 0; }
/** * Initialize the XGpio instance provided by the caller based on the * given DeviceID. * * Nothing is done except to initialize the InstancePtr. * * @param InstancePtr is a pointer to an XGpio instance. The memory the * pointer references must be pre-allocated by the caller. Further * calls to manipulate the component through the XGpio API must be * made with this pointer. * * @param DeviceId is the unique id of the device controlled by this XGpio * component. Passing in a device id associates the generic XGpio * instance to a specific device, as chosen by the caller or * application developer. * * @return * - XST_SUCCESS if the initialization was successfull. * - XST_DEVICE_NOT_FOUND if the device configuration data was not * found for a device with the supplied device ID. * * @note None. * *****************************************************************************/ int XGpio_Initialize(XGpio * InstancePtr, u16 DeviceId) { XGpio_Config *ConfigPtr; /* * Assert arguments */ XASSERT_NONVOID(InstancePtr != NULL); /* * Lookup configuration data in the device configuration table. * Use this configuration info down below when initializing this * component. */ ConfigPtr = XGpio_LookupConfig(DeviceId); if (ConfigPtr == (XGpio_Config *) NULL) { InstancePtr->IsReady = 0; return (XST_DEVICE_NOT_FOUND); } return XGpio_CfgInitialize(InstancePtr, ConfigPtr, ConfigPtr->BaseAddress); }
void init_GPIO_LEDS(XGpio *InstancePtr, u16 Device_ID) { int Status; XGpio_Config *Config; Config = XGpio_LookupConfig(Device_ID); Status = XGpio_CfgInitialize(InstancePtr, Config, Config->BaseAddress); // Initialise GPIO devices Status = XGpio_Initialize(InstancePtr, Device_ID); // Set GPIO direction (output for LEDs and input for BTNS) XGpio_SetDataDirection(InstancePtr, 1, 0x00); if(Status != XST_FAILURE) { xil_printf("LEDS initialized!\n \r"); } }
/** * This function implements the USB mouse application. * This function sets up the ML403 evaluation board as a USB mouse. * The mouse cursor movement can be seen on the PC as and when any of the push * buttons SW3, SW4, SW5 and SW7 on the ML403 Evaluation board is pressed. * Pressing the push button SW6 stops the test. * * @param UsbId is the USB device id. * @param GpioId is the GPIO device id. * * @return * - XST_SUCCESS if successful. * - XST_FAILURE if test fails. * * @note None. * *****************************************************************************/ int UsbMouseExample (u16 UsbId, u16 GpioId) { int Status; /* * Initialize the USB driver. */ UsbConfigPtr = XUsb_LookupConfig(UsbId); if (NULL == UsbConfigPtr) { return XST_FAILURE; } /* * We are passing the physical base address as the third argument * because the physical and virtual base address are the same in our * example. For systems that support virtual memory, the third * argument needs to be the virtual base address. */ Status = XUsb_CfgInitialize(&UsbInstance, UsbConfigPtr, UsbConfigPtr->BaseAddress); if (XST_SUCCESS != Status) { return XST_FAILURE; } /* * Initialize the GPIO driver. */ GpioConfigPtr = XGpio_LookupConfig(GpioId); if (GpioConfigPtr == NULL) { return XST_FAILURE; } /* * We are passing the physical base address as the third argument * because the physical and virtual base address are the same in our * example. For systems that support virtual memory, the third * argument needs to be the virtual base address. */ Status = XGpio_CfgInitialize(&Gpio, GpioConfigPtr, GpioConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } XGpio_SetDataDirection(&Gpio, BUTTON_CHANNEL, GPIO_ALL_BUTTONS); /* * Initialize the USB instance as required for the USB mouse * application. */ InitUsbInterface(&UsbInstance); /* * Set USB device address to 0 which is the unenumerated state. */ Status = XUsb_SetDeviceAddress(&UsbInstance, 0); if (XST_SUCCESS != Status) { return XST_FAILURE; } /* * Setup the interrupt handlers. */ XUsb_IntrSetHandler(&UsbInstance, (void *)UsbIfIntrHandler, &UsbInstance); XUsb_EpSetHandler(&UsbInstance, 0, (XUsb_EpHandlerFunc *)Ep0IntrHandler, &UsbInstance); XUsb_EpSetHandler(&UsbInstance, 1, (XUsb_EpHandlerFunc *)Ep1IntrHandler, &UsbInstance); /* * Setup the interrupt system. */ Status = SetupInterruptSystem(&UsbInstance, &Gpio); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Enable the interrupts. */ XUsb_IntrEnable(&UsbInstance, XUSB_STATUS_GLOBAL_INTR_MASK | XUSB_STATUS_RESET_MASK | XUSB_STATUS_SUSPEND_MASK | XUSB_STATUS_DISCONNECT_MASK | XUSB_STATUS_FIFO_BUFF_RDY_MASK | XUSB_STATUS_FIFO_BUFF_FREE_MASK | XUSB_STATUS_EP0_BUFF1_COMP_MASK | XUSB_STATUS_EP1_BUFF1_COMP_MASK | XUSB_STATUS_EP1_BUFF2_COMP_MASK ); XUsb_Start(&UsbInstance); /* * Set the device configuration to unenumerated state. */ UsbInstance.DeviceConfig.CurrentConfiguration = 0; /* * Observe that the mouse movement is seen on the PC whenever any of the * ML403 evaluation board push button is pressed. The test ends when the * center push button on the ML403 Evaluation board is pressed. */ while (!StopTest); return XST_SUCCESS; }
int Mrf24j::initDrivers(void) { // TODO: check pin direction /*pinMode(_pin_reset, OUTPUT); pinMode(_pin_cs, OUTPUT); pinMode(_pin_int, INPUT);*/ XSpi_Config *SPIConfigPtr; XGpio_Config *GPIOConfigPtr; int status; /* * Initialize the SPI driver so that it is ready to use. */ SPIConfigPtr = XSpi_LookupConfig(XPAR_SPI_0_DEVICE_ID); if (SPIConfigPtr == NULL) { return XST_DEVICE_NOT_FOUND; } status = XSpi_CfgInitialize(&MSpiInstance, SPIConfigPtr, SPIConfigPtr->BaseAddress); if (status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the Spi device as a master. */ status = XSpi_SetOptions( &MSpiInstance, XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION ); //TO DO, add msb first config if (status != XST_SUCCESS) { return XST_FAILURE; } /* * Start the SPI driver so that the device is enabled. */ XSpi_Start(&MSpiInstance); /* * Disable Global interrupt to use polled mode operation */ XSpi_IntrGlobalDisable(&MSpiInstance); //GPIO config GPIOConfigPtr = XGpio_LookupConfig(XPAR_GPIO_1_DEVICE_ID); status = XGpio_CfgInitialize(&gpioInstance, GPIOConfigPtr, GPIOConfigPtr->BaseAddress); if (status != XST_SUCCESS) { return XST_FAILURE; } XGpio_SetDataDirection(&gpioInstance, 1, 0x1); //check data direction XGpio_DiscreteWrite(&gpioInstance, 1, 0x6); //check register, check wake pin if it is ok high //for(int i = 0; i < 20; i++) //{ //u32 intr = XGpio_InterruptGetEnabled(&gpioInstance); //u32 sts = XGpio_InterruptGetStatus(&gpioInstance); //XGpio_InterruptClear(&gpioInstance, XGPIO_IR_CH1_MASK); ///sts = XGpio_InterruptGetStatus(&gpioInstance); //u32 usts = sts; //} /*SPI.setBitOrder(MSBFIRST) ; SPI.setDataMode(SPI_MODE0); SPI.begin();*/ return XST_SUCCESS; }
void OledHostInit() { XSpi_Config *SPIConfigPtr; XGpio_Config *GPIOConfigPtr; int status; /* * Initialize the SPI driver so that it is ready to use. */ SPIConfigPtr = XSpi_LookupConfig(XPAR_SPI_1_DEVICE_ID); if (SPIConfigPtr == NULL) { printf("OledHostInit: ERROR: SPI device not found"); } status = XSpi_CfgInitialize(&SpiInstance, SPIConfigPtr, SPIConfigPtr->BaseAddress); if (status != XST_SUCCESS) { printf("OledHostInit: ERROR: cannot init SPI"); } /* * Set the Spi device as a master. */ status = XSpi_SetOptions( &SpiInstance, XSP_MASTER_OPTION | XSP_MANUAL_SSELECT_OPTION | XSP_CLK_ACTIVE_LOW_OPTION | XSP_CLK_PHASE_1_OPTION); if (status != XST_SUCCESS) { printf("OledHostInit: ERROR: set SPI options"); } /* * Start the SPI driver so that the device is enabled. */ XSpi_Start(&SpiInstance); /* * Disable Global interrupt to use polled mode operation */ XSpi_IntrGlobalDisable(&SpiInstance); u32 slaveReg = XSpi_GetSlaveSelectReg(&SpiInstance); XSpi_SetSlaveSelectReg(&SpiInstance, 0x00); slaveReg = XSpi_GetSlaveSelectReg(&SpiInstance); //GPIO config GPIOConfigPtr = XGpio_LookupConfig(XPAR_GPIO_0_DEVICE_ID); if (GPIOConfigPtr == NULL) { printf("OledHostInit: ERROR: GPIO device not found"); } status = XGpio_CfgInitialize(&gpioInstance, GPIOConfigPtr, GPIOConfigPtr->BaseAddress); if (status != XST_SUCCESS) { printf("OledHostInit: ERROR: cannot init GPIO"); } XGpio_SetDataDirection(&gpioInstance, 1, 0xf0); XGpio_DiscreteWrite(&gpioInstance, 1, 0x0F); }