void initGPIO(int nGpio, int modulo, int direction){ switch(modulo){ case MODULO_0: GPIO0_ModuleClkConfig(); modulo0(nGpio); break; case MODULO_1: GPIO1_ModuleClkConfig(); modulo1(nGpio); break; case MODULO_2: GPIO2_ModuleClkConfig(); modulo2(nGpio); break; case MODULO_3: GPIO3_ModuleClkConfig(); modulo3(nGpio); break; } /* Enabling the GPIO module. */ GPIOModuleEnable(GPIO_INSTANCE_ADDRESS(modulo)); /* Resetting the GPIO module. */ //GPIOModuleReset(GPIO_INSTANCE_ADDRESS(modulo)); /* Setting the GPIO pin as an output pin. */ GPIODirModeSet(GPIO_INSTANCE_ADDRESS(modulo), GPIO_INSTANCE_PIN_NUMBER(nGpio), direction); }
void GpioModuleEnable(unsigned int module_addr) { /* Enabling the GPIO module. */ GPIOModuleEnable(module_addr); /* Resetting the GPIO module. */ GPIOModuleReset(module_addr); }
void gpioLedInit() { /* Enabling the GPIO module. */ GPIOModuleEnable(GPIO_INSTANCE_ADDRESS); /* Perform a module reset of the GPIO module. */ GPIOModuleReset(GPIO_INSTANCE_ADDRESS); /* Set the specified pin as an output pin. */ GPIODirModeSet(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_DIR_OUTPUT); }
void gpioInit(void) { // enable clock for gpio 0,1,2 GPIO0ModuleClkConfig(); GPIO1ModuleClkConfig(); GPIO2ModuleClkConfig(); // select gpio pins for use gpioPinMux(); /* Enabling the GPIO module. */ GPIOModuleEnable(GPIO_BASE1); GPIOModuleEnable(GPIO_BASE0); GPIOModuleEnable(GPIO_BASE2); /* Resetting the GPIO module. */ GPIOModuleReset(GPIO_BASE0); GPIOModuleReset(GPIO_BASE1); GPIOModuleReset(GPIO_BASE2); // set directions for the gpio pins in use gpioDirModeSet(); }
/*FUNCTION*------------------------------------------------------- * * Function Name : ledInit * Comments : *END*-----------------------------------------------------------*/ int ledInit(){ /* Enabling functional clocks for GPIO1 instance. */ GPIO1_ModuleClkConfig(); /* Selecting GPIO1[23] pin for use. */ /*GPIOPinMuxSetup(CONTROL_CONF_GPMC_A(7), CONTROL_CONF_MUXMODE(7));*/ GetGPIOPinName(); /* Enabling the GPIO module. */ GPIOModuleEnable(GPIO_INSTANCE_ADDRESS); /* Resetting the GPIO module. */ GPIOModuleReset(GPIO_INSTANCE_ADDRESS); /* Setting the GPIO pin as an output pin. */ GPIODirModeSet(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, DIR_OUTPUT); return(0); }
void configWakeGpio() { /* Enabling the GPIO module. */ GPIOModuleEnable(GPIO_WAKE_INSTANCE); /* Perform a module reset of the GPIO module. */ //GPIOModuleReset(GPIO_WAKE_INSTANCE); /* Set the specified pin as an Input pin. */ GPIODirModeSet(GPIO_WAKE_INSTANCE, GPIO_WAKE_PIN_NUM, GPIO_DIR_INPUT); GPIOIntTypeSet(GPIO_WAKE_INSTANCE, GPIO_WAKE_PIN_NUM, GPIO_INT_TYPE_BOTH_EDGE); HWREG(GPIO_WAKE_INSTANCE + 0x34) = 0x40000000; HWREG(GPIO_WAKE_INSTANCE + 0x38) = 0x40000000; HWREG(GPIO_WAKE_INSTANCE + 0x44) = 0x40000000; }
int main(void) { /* unsigned int count = 0; */ /* Configuring the functional clock for GPIO0 instance. */ GPIO0ModuleClkConfig(); /* Doing a pin multiplexing and selecting GPIO0[7] for use. */ GPIO0Pin7PinMuxSetup(); /* Enabling the GPIO module. */ GPIOModuleEnable(SOC_GPIO_0_REGS); /* Resetting the GPIO module. */ GPIOModuleReset(SOC_GPIO_0_REGS); /* Configuring GPIO0[7] pin as an output pin. */ GPIODirModeSet(SOC_GPIO_0_REGS, GPIO_INSTANCE_PIN_NUMBER, GPIO_DIR_OUTPUT); while(1) { /* Driving GPIO0[7] pin to logic HIGH. */ GPIOPinWrite(SOC_GPIO_0_REGS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_HIGH); Delay(0xFFFFF); /* Driving GPIO0[7] pin to logic LOW. */ GPIOPinWrite(SOC_GPIO_0_REGS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_LOW); Delay(0xFFFFF); } }
static err_t gpio_init(Drive_Gpio *t) { Drive_Gpio *cthis = ( Drive_Gpio *)t ; uint32_t tmp_reg = 0; gpio_cfg *config = cthis->config; int i = 0; assert( config->intr_line < 2); cthis->gpio_vbase = mmap_device_io( AM335X_GPIO_SIZE, GpioBase[ config->pin_group]); #ifdef DEBUG_GPIO TRACE_INFO("Drive Piling :%s-%s-%d \r\n", __FILE__, __func__, __LINE__); TRACE_INFO("pin config 0x%04x \r\n", rd_pin_conf( config->pin_ctrl_off)); return EXIT_SUCCESS; #else if (cthis->gpio_vbase == MAP_DEVICE_FAILED) { return ERROR_T( gpio_init_mapio_fail); } gpioModuleConfig[ config->pin_group](); GPIOModuleEnable( cthis->gpio_vbase); //配置引脚方向为输入 tmp_reg = in32( cthis->gpio_vbase + GPIO_OE ); tmp_reg |= 1 << config->pin_number; out32( cthis->gpio_vbase + GPIO_OE, tmp_reg ); //使能消抖 tmp_reg=in32( cthis->gpio_vbase + GPIO_DEBOUNCENABLE); tmp_reg &=~( 1 << config->pin_number); tmp_reg |= ( 1 << config->pin_number); out32( cthis->gpio_vbase + GPIO_DEBOUNCENABLE, tmp_reg); //消抖时间 out32( cthis->gpio_vbase + GPIO_DEBOUNCINGTIME, ( config->debou_time )); //配置中断监测类型 for( i = 0; i < 4; i ++) { if( ( ( 1 << i) & config->intr_type) ) { //使能该类型 tmp_reg = in32( cthis->gpio_vbase + GPIO_DETECT(i)); tmp_reg |= 1 << config->pin_number; out32(cthis->gpio_vbase + GPIO_DETECT(i), tmp_reg); } else { //禁止其他类型 tmp_reg = in32( cthis->gpio_vbase + GPIO_DETECT(i)); tmp_reg &= ~(1 << config->pin_number); out32(cthis->gpio_vbase + GPIO_DETECT(i), tmp_reg); } } //使能引脚中断 // tmp_reg = in32( cthis->gpio_vbase + GPIO_IRQSTATUS_SET( config->intr_line)); // tmp_reg |= 1 << config->pin_number; // out32(cthis->gpio_vbase + GPIO_IRQSTATUS_SET( config->intr_line), tmp_reg); #ifdef DEBUG_GPIO dump_gpio_reg( cthis->gpio_vbase); #endif SIGEV_INTR_INIT( &cthis->isr_event ); cthis->irq_id = InterruptAttach_r ( GpioIntNum[ config->intr_line][ config->pin_group], gpioExtInteIsr, cthis, 1, _NTO_INTR_FLAGS_END ); return EXIT_SUCCESS; #endif }