- 论坛徽章:
- 0
|
本帖最后由 vip-weiwei 于 2012-08-24 14:32 编辑
请教大侠,最近在看linux的gpiolib.c,有个地方看不懂,
struct gpio_desc {
struct gpio_chip *chip;
unsigned long flags;
。。。。。。
#ifdef CONFIG_DEBUG_FS
const char *label;
#endif
};
static struct gpio_desc gpio_desc[ARCH_NR_GPIOS];
static ssize_t gpio_direction_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t size)
{
const struct gpio_desc *desc = dev_get_drvdata(dev);
unsigned gpio = desc - gpio_desc;//这句怎么理解?
if (!test_bit(FLAG_EXPORT, &desc->flags)) status = -EIO;
else if (sysfs_streq(buf, "high"))
status = gpio_direction_output(gpio, 1);
else if
。。。。。
return status ? : size;
}
gpio = desc - gpio_desc;//这句怎么理解?看样子似乎是取得gpio在数组中的位置,但我怎么觉得gpio = (desc - gpio_desc)/sizeof(struct gpio_desc )呢?还请大侠解惑一下,谢谢了!! |
|