bool Skitt::initalize() { /* Check the settings the gave us. */ /* Configure GPIO pins. */ if (!is_pin_exported(good_led_pin)) { set_mux("gpmc_ad4", "7"); set_mux("gpmc_ad0", "7"); set_mux("lcd_vsync", "7"); set_mux("lcd_hsync", "7"); set_mux("lcd_data6", "7"); set_mux("lcd_data4", "7"); set_mux("gpmc_ad15", "7"); set_mux("gpmc_ad11", "7"); set_mux("gpmc_ad13", "7"); export_pin(mux_pins[0][0]); export_pin(mux_pins[0][1]); export_pin(mux_pins[0][2]); export_pin(mux_pins[1][0]); export_pin(mux_pins[1][1]); export_pin(mux_pins[1][2]); export_pin(good_led_pin); export_pin(error_led_pin); export_pin(streaming_led_pin); set_pin_direction(mux_pins[0][0], OUT); set_pin_direction(mux_pins[0][1], OUT); set_pin_direction(mux_pins[0][2], OUT); set_pin_direction(mux_pins[1][0], OUT); set_pin_direction(mux_pins[1][1], OUT); set_pin_direction(mux_pins[1][2], OUT); set_pin_direction(good_led_pin, OUT); set_pin_direction(error_led_pin, OUT); set_pin_direction(streaming_led_pin, OUT); } /* Configure SPI connection. */ if (!connect_to_spi("/dev/spidev2.0")) { return false; } return true; }
static int export_dio_pins(int io_points) { int i, msg, retval=0; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ if (io_points == 0) return 0; msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); for (i = 0; i < io_points; i++) { /* point, direction, driver */ retval |= export_pin(i, vti_driver->dir_bits[i / 4], vti_driver); } /* restore saved message level */ rtapi_set_msg_level(msg); return retval; }
int gpio_init(uint8_t gpio_pin) { if (!check_pin(gpio_pin)) return -1; /* Ensure that PWM GPIO's are not used as PWM output at the same time */ switch (gpio_pin) { case MIKROBUS_1_PWM: pwm_release(MIKROBUS_1); break; case MIKROBUS_2_PWM: pwm_release(MIKROBUS_2); break; } /* Export a GPIO by writing its index to file /sys/class/gpio/export. */ if (!is_gpio_exported(gpio_pin)) { if (export_pin(GPIO_DIR_BASE_PATH, gpio_pin) < 0) return -1; } return gpio_set_direction(gpio_pin, GPIO_INPUT); }