• GPIO Code

    ril3y10/16/2015 at 03:16 0 comments

    To enable GPIO pin5:

    gpio_init();
    	PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO5); //enable pin5 GPIO
    	PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO0_U);  //Enable pullups
    	

    Then to enable a timer to callback and read the value:

    //===================================
    	// TIMER STUFF
    	//===================================
    	
    	//Setup timer callback
    	os_timer_setfn(&buttonTimer, (os_timer_func_t *)buttonTimerCB, NULL);
    
        //Arm the timer
        //&buttonTimer is the pointer
        //35 is the fire time in ms
        //0 for once and 1 for repeating
        os_timer_arm(&buttonTimer, 35, 1);

    Then the timercallback function:

    uint16_t pinvalue=0;
    void buttonTimerCB(void *arg){
    	//INFO("Timer says hi!");
    	pinvalue = GPIO_INPUT_GET(GPIO_ID_PIN(5));
    	if(pinvalue){
    		pressCount = pressCount+1;
    		INFO("Button pressed #%d \r\n", pressCount);
    	}
    }