int ara_key_enable(const struct ara_board_info *info, int (*longpress_callback)(void *priv), bool enable) { if (enable) { if (!info->ara_key_configured) { dbg_error("%s: no ara key gpio defined\n", __func__); return -EINVAL; } the_ara_key.longpress_callback = longpress_callback; the_ara_key.db.gpio = info->ara_key_gpio; the_ara_key.db.ms = ARA_KEY_DEBOUNCE_TIME_MS; the_ara_key.db.isr = ara_key_irqhandler; the_ara_key.db.db_state = DB_ST_INVALID; the_ara_key.rising_edge = info->ara_key_rising_edge; gpio_activate(info->ara_key_gpio); gpio_direction_in(info->ara_key_gpio); gpio_irq_mask(info->ara_key_gpio); gpio_irq_settriggering(info->ara_key_gpio, IRQ_TYPE_EDGE_BOTH); gpio_irq_attach(info->ara_key_gpio, ara_key_irqhandler); } else { gpio_irq_mask(info->ara_key_gpio); gpio_deactivate(info->ara_key_gpio); } return OK; }
/** * @brief Hardware initialization * * The function initializes the GPIO pins used in the bit-bang interface and * also assigned a default output value for SPI signal. * * @param dev pointer to structure of device data * @return 0 on success, negative errno on error */ static int tsb_spi_hw_init(struct device *dev) { struct tsb_spi_info *info = NULL; int i = 0; int retval; /* check input parameters */ if (!dev || !device_get_private(dev)) { return -EINVAL; } info = device_get_private(dev); retval = tsb_request_pinshare(TSB_PIN_GPIO10); if (retval) { lowsyslog("SPI: cannot get ownership of GPIO10 pin.\n"); return retval; } /* backup pinshare#5 setting */ info->pinshare = tsb_get_pinshare(); /* set pinshare#5 (DBG) to normal GPIO */ if (!(info->pinshare & TSB_PIN_GPIO10)) { tsb_set_pinshare(TSB_PIN_GPIO10); } /* setup GPIO pins */ gpio_activate(SPI_SCK); gpio_direction_out(SPI_SCK, 0); gpio_activate(SPI_SDI); gpio_direction_in(SPI_SDI); gpio_activate(SPI_SDO); gpio_direction_out(SPI_SDO, 0); /* setup all chip-select pins */ for (i = 0; i < info->caps.csnum; i++) { gpio_activate(info->chipselect[i]); gpio_direction_out(info->chipselect[i], 1); } return 0; }
/** * Init the USB4624 hub * * Activate the GPIO line * * @param dev Device * @return 0 if successful */ static int usb4624_open(struct device *dev) { /* GPIO0 is pinshared on ES2 and later, but not on ES1 */ #if !defined(CONFIG_TSB_CHIP_REV_ES1) tsb_clr_pinshare(TSB_PIN_UART_CTSRTS); #endif gpio_activate(HUB_LINE_N_RESET); return 0; }
static uint8_t gb_vibrator_vibrator_off(struct gb_operation *operation) { // Deactivate the GPIO line, somehow. gpio_activate(GB_VIBRATOR_DUMMY_GPIO); gpio_set_value(GB_VIBRATOR_DUMMY_GPIO, 0); gpio_deactivate(GB_VIBRATOR_DUMMY_GPIO); return GB_OP_SUCCESS; }
static uint8_t gb_vibrator_vibrator_on(struct gb_operation *operation) { struct gb_vibrator_on_request *request = gb_operation_get_request_payload(operation); if (gb_operation_get_request_payload_size(operation) < sizeof(*request)) { gb_error("dropping short message\n"); return GB_OP_INVALID; } gpio_activate(GB_VIBRATOR_DUMMY_GPIO); gpio_set_value(GB_VIBRATOR_DUMMY_GPIO, 1); usleep(le16_to_cpu(request->timeout_ms)); gpio_deactivate(GB_VIBRATOR_DUMMY_GPIO); return GB_OP_SUCCESS; }
/** * Init the USB3813 hub * * Activate the GPIO line * * @param dev Device * @return 0 if successful */ static int usb3813_open(struct device *dev) { gpio_activate(HUB_LINE_N_RESET); return 0; }
void cmd_parse(const char * str) { int name_len; name_len=0; char cmd_name[MAX_LEN_NAME]; int arg_len; arg_len=0; char cmd_arg[MAX_LEN_ARG]; while(*str && *str != ' ') { cmd_name[name_len] = *str; name_len++; str++; } cmd_name[name_len] = '\0'; while(*str && *str == ' ') str++; while(*str && *str != ' ') { cmd_arg[arg_len] = *str; arg_len++; str++; } cmd_arg[arg_len] = '\0'; if (console_streq(cmd_name, led_cmd.name)) { int arg_value; led_cfg_set(1); if(arg_len == 0) led_dat_set(!led_dat_get_state()); else if (arg_len == 1) { arg_value = atoi(cmd_arg); if(arg_value == 1 || arg_value == 0) led_dat_set(arg_value); else { console_print("Bad argument : Not 0 or 1.\r\n"); cmd_print_usage(led_cmd); } } else { console_print("Bad number of arguments\r\n"); cmd_print_usage(led_cmd); } console_prompt(); } else if (console_streq(cmd_name, gpio_cmd.name)) { gpio_output_set(9); gpio_activate(9); console_prompt(); } else { console_print("Unknown command : "); console_print(cmd_name); console_print("\r\n"); console_prompt(); } }