当前位置: 首页> 科技> 能源 > 东莞百度推广教程_重庆公司章程怎么下载_搜索引擎优化的完整过程_百度sem竞价托管公司

东莞百度推广教程_重庆公司章程怎么下载_搜索引擎优化的完整过程_百度sem竞价托管公司

时间:2025/7/10 1:40:53来源:https://blog.csdn.net/hollow2420655128/article/details/145808021 浏览次数:0次
东莞百度推广教程_重庆公司章程怎么下载_搜索引擎优化的完整过程_百度sem竞价托管公司

在使用 GPIO 子系统之前可以通过 Pinctrl 子系统将引脚配置为 GPIO 模式

然后在设备树中加入引脚的定义

以下面设备树代码为例

	sc200ai: sc200ai@30 {compatible = "smartsens,sc200ai";status = "okay";reg = <0x30>;clocks = <&cru MCLK_REF_MIPI0>;clock-names = "xvclk";reset-gpios = <&gpio3 RK_PC5 GPIO_ACTIVE_HIGH>;pwdn-gpios = <&gpio3 RK_PD2 GPIO_ACTIVE_HIGH>;pinctrl-names = "default";pinctrl-0 = <&mipi_refclk_out0>;rockchip,camera-module-index = <0>;rockchip,camera-module-facing = "back";rockchip,camera-module-name = "CMK-OT2115-PC1";rockchip,camera-module-lens-name = "30IRC-F16";port {sc200ai_out: endpoint {remote-endpoint = <&csi_dphy_input9>;data-lanes = <1 2>;};};};

可以使用 gpiod_get_index 获取引脚

这里使用前缀获取,0 表示是第 0 个引脚也就是gpio3 RK_PC5 这个引脚,这里在设备树中用逗号隔开写多个引脚

pwdn = gpiod_get_index(dev, "pwdn", 0, GPIOD_OUT_HIGH);

/ drivers / gpio / gpiolib.c

/*** gpiod_get_index - obtain a GPIO from a multi-index GPIO function* @dev:	GPIO consumer, can be NULL for system-global GPIOs* @con_id:	function within the GPIO consumer* @idx:	index of the GPIO to obtain in the consumer* @flags:	optional GPIO initialization flags** This variant of gpiod_get() allows to access GPIOs other than the first* defined one for functions that define several GPIOs.** Return a valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the* requested function and/or index, or another IS_ERR() code if an error* occurred while trying to acquire the GPIO.*/
struct gpio_desc *__must_check gpiod_get_index(struct device *dev,const char *con_id,unsigned int idx,enum gpiod_flags flags)
{unsigned long lookupflags = GPIO_LOOKUP_FLAGS_DEFAULT;struct gpio_desc *desc = NULL;int ret;/* Maybe we have a device name, maybe not */const char *devname = dev ? dev_name(dev) : "?";const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL;dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);/* Using device tree? */if (is_of_node(fwnode)) {dev_dbg(dev, "using device tree for GPIO lookup\n");desc = of_find_gpio(dev, con_id, idx, &lookupflags);} else if (is_acpi_node(fwnode)) {dev_dbg(dev, "using ACPI for GPIO lookup\n");desc = acpi_find_gpio(dev, con_id, idx, &flags, &lookupflags);}/** Either we are not using DT or ACPI, or their lookup did not return* a result. In that case, use platform lookup as a fallback.*/if (!desc || gpiod_not_found(desc)) {dev_dbg(dev, "using lookup tables for GPIO lookup\n");desc = gpiod_find(dev, con_id, idx, &lookupflags);}if (IS_ERR(desc)) {dev_dbg(dev, "No GPIO consumer %s found\n", con_id);return desc;}/** If a connection label was passed use that, else attempt to use* the device name as label*/ret = gpiod_request(desc, con_id ?: devname);if (ret) {if (!(ret == -EBUSY && flags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))return ERR_PTR(ret);/** This happens when there are several consumers for* the same GPIO line: we just return here without* further initialization. It is a bit of a hack.* This is necessary to support fixed regulators.** FIXME: Make this more sane and safe.*/dev_info(dev, "nonexclusive access to GPIO for %s\n", con_id ?: devname);return desc;}ret = gpiod_configure_flags(desc, con_id, lookupflags, flags);if (ret < 0) {dev_dbg(dev, "setup of GPIO %s failed\n", con_id);gpiod_put(desc);return ERR_PTR(ret);}blocking_notifier_call_chain(&desc->gdev->notifier,GPIOLINE_CHANGED_REQUESTED, desc);return desc;
}
EXPORT_SYMBOL_GPL(gpiod_get_index);

可以通过gpiod_direction_output 设置引脚方向,这里设置的是逻辑值,如果引脚被设置为GPIO_ACTIVE_HIGH 那么 1 就是设置高电平,如果是GPIO_ACTIVE_LOW 的话 1 就是低电平

/ drivers / gpio / gpiolib.c

/*** gpiod_direction_output - set the GPIO direction to output* @desc:	GPIO to set to output* @value:	initial output value of the GPIO** Set the direction of the passed GPIO to output, such as gpiod_set_value() can* be called safely on it. The initial value of the output must be specified* as the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into* account.** Return 0 in case of success, else an error code.*/
int gpiod_direction_output(struct gpio_desc *desc, int value)
{int ret;VALIDATE_DESC(desc);if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))value = !value;elsevalue = !!value;/* GPIOs used for enabled IRQs shall not be set as output */if (test_bit(FLAG_USED_AS_IRQ, &desc->flags) &&test_bit(FLAG_IRQ_IS_ENABLED, &desc->flags)) {gpiod_err(desc,"%s: tried to set a GPIO tied to an IRQ as output\n",__func__);return -EIO;}if (test_bit(FLAG_OPEN_DRAIN, &desc->flags)) {/* First see if we can enable open drain in hardware */ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_DRAIN);if (!ret)goto set_output_value;/* Emulate open drain by not actively driving the line high */if (value) {ret = gpiod_direction_input(desc);goto set_output_flag;}} else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_SOURCE);if (!ret)goto set_output_value;/* Emulate open source by not actively driving the line low */if (!value) {ret = gpiod_direction_input(desc);goto set_output_flag;}} else {gpio_set_config(desc, PIN_CONFIG_DRIVE_PUSH_PULL);}set_output_value:ret = gpio_set_bias(desc);if (ret)return ret;return gpiod_direction_output_raw_commit(desc, value);set_output_flag:/** When emulating open-source or open-drain functionalities by not* actively driving the line (setting mode to input) we still need to* set the IS_OUT flag or otherwise we won't be able to set the line* value anymore.*/if (ret == 0)set_bit(FLAG_IS_OUT, &desc->flags);return ret;
}
EXPORT_SYMBOL_GPL(gpiod_direction_output);
关键字:东莞百度推广教程_重庆公司章程怎么下载_搜索引擎优化的完整过程_百度sem竞价托管公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: