/* Configure GPIO pins to be used as LED and push button */ static void configure_gpios() { mdev_t *pinmux_dev, *gpio_dev; /* Initialize pinmux driver */ pinmux_drv_init(); /* Open pinmux driver */ pinmux_dev = pinmux_drv_open("MDEV_PINMUX"); /* Initialize GPIO driver */ gpio_drv_init(); /* Open GPIO driver */ gpio_dev = gpio_drv_open("MDEV_GPIO"); /* Configure GPIO pin function for GPIO connected to LED */ pinmux_drv_setfunc(pinmux_dev, gpio_led, GPIO_LED_FN); /* Configure GPIO pin direction as Output */ gpio_drv_setdir(gpio_dev, gpio_led, GPIO_OUTPUT); /* Keep initial state of LED: ON */ gpio_drv_write(gpio_dev, gpio_led, 0); /* Close drivers */ pinmux_drv_close(pinmux_dev); gpio_drv_close(gpio_dev); }
/* Basic Sensor IO initialization to be done here This function will be called only once during sensor registration */ int ultrasonic_sensor_init(struct sensor_info *curevent) { wmprintf("%s\r\n", __FUNCTION__); mdev_t *pinmux_dev, *gpio_dev; /* Initialize pinmux driver */ pinmux_drv_init(); /* Open pinmux driver */ pinmux_dev = pinmux_drv_open("MDEV_PINMUX"); /* Initialize GPIO driver */ gpio_drv_init(); /* Open GPIO driver */ gpio_dev = gpio_drv_open("MDEV_GPIO"); /* Configure GPIO pin function for GPIO connected to LED */ pinmux_drv_setfunc(pinmux_dev, ULTRASONIC_SEN_IO, ULTRASONIC_SEN_IO_GPIO); /* Confiugre GPIO pin direction as Input */ gpio_drv_setdir(gpio_dev, ULTRASONIC_SEN_IO, GPIO_INPUT); /* Close drivers */ pinmux_drv_close(pinmux_dev); gpio_drv_close(gpio_dev); #ifdef ULTRASONIC_SENSOR_TEST check_ultrasonic_sensor(); #endif /* ULTRASONIC_SENSOR_TEST */ return 0; }
// configuring gpios static void configure_gpios() { mdev_t *pinmux_dev, *gpio_dev; /* Initialize pinmux driver */ pinmux_drv_init(); /* Open pinmux driver */ pinmux_dev = pinmux_drv_open("MDEV_PINMUX"); /* Initialize GPIO driver */ gpio_drv_init(); /* Open GPIO driver */ gpio_dev = gpio_drv_open("MDEV_GPIO"); /* Configure GPIO pin function for GPIO connected to LED */ pinmux_drv_setfunc(pinmux_dev, gpio_led, GPIO_LED_FN); /* Configure GPIO pin direction as Output */ gpio_drv_setdir(gpio_dev, gpio_led, GPIO_OUTPUT); /* Keep initial state of LED: ON */ gpio_drv_write(gpio_dev, gpio_led, 0); /* Configure GPIO pin function for GPIO connected to push button */ pinmux_drv_setfunc(pinmux_dev, gpio_pushbutton, GPIO_PUSHBUTTON_FN); /* Configure GPIO pin direction as input */ gpio_drv_setdir(gpio_dev, gpio_pushbutton, GPIO_INPUT); /* Register a callback for push button interrupt */ gpio_drv_set_cb(gpio_dev, gpio_pushbutton, GPIO_INT_FALLING_EDGE, NULL, pushbutton_press); /* Close drivers */ pinmux_drv_close(pinmux_dev); gpio_drv_close(gpio_dev); }