void gpio_out(usb_dev_handle *h, int gpio, int value) { int shift_dir = gpio_dir_shift(gpio); int shift_val = gpio_val_shift(gpio); unsigned char reg = gpio_read_reg(h); reg |= (1 << shift_dir); reg &= ~(1 << shift_val); reg |= (value << shift_val); gpio_write_reg(h, reg); }
void gpio_in(usb_dev_handle *h, int gpio, int pullup) { int shift_dir = gpio_dir_shift(gpio); int shift_val = gpio_val_shift(gpio); unsigned char reg = gpio_read_reg(h); reg &= ~(1 << shift_dir); reg &= ~(1 << shift_val); reg |= (pullup << shift_val); gpio_write_reg(h, reg); }
static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio) { struct pinmux_data_reg *dr = NULL; int bit = 0; if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0) { BUG(); return 0; } return gpio_read_reg(dr->reg, dr->reg_width, 1, bit); }
static int check_config_reg(struct pinmux_info *gpioc, struct pinmux_cfg_reg *crp, int index) { unsigned long ncomb, pos, value; ncomb = 1 << crp->field_width; pos = index / ncomb; value = index % ncomb; if (gpio_read_reg(crp->reg, crp->reg_width, crp->field_width, pos) == value) return 0; return -1; }
int gpio_read(usb_dev_handle *h, int gpio) { unsigned char r = gpio_read_reg(h); int shift = gpio_val_shift(gpio); return (r & (1<<shift)); }