瑞芯微Rockchip开发者社区
直播中

王涛

8年用户 1296经验值
私信 关注
[经验]

怎样去编写RK3399系列GPIO&pinctrl的控制代码呢

Board : Nanopi M4

設備樹

led-ioctl {
status = "okay";
compatible = "gpio,led-sample";

pinctrl-names = "default";
pinctrl-0 = <&led_0 &led_1 &led_2 &led_3>;
led0-gpios = <&gpio1 RK_PA0 GPIO_ACTIVE_LOW>;

};

&pinctrl {
led {
led_0: led_0 {
rockchip,pins = <1 RK_PA0 RK_FUNC_GPIO &pcfg_pull_none>;
};

驅動

static const struct of_device_id gpio_led_of_match[] = {
{ .compatible = "gpio,led-sample", .data = NULL},
{},

static int gpio_led_probe(struct platform_device *pdev)

{ sprintf(dt_gpio_name, "led%d", i);
led_gpio.gpiod[i] = devm_gpiod_get_optional(&pdev->dev, dt_gpio_name,GPIOD_OUT_HIGH);

ret = misc_register(&gpio_led_dev); //misc註冊快速好用

}

//ioctl(fd, value, led); //傳入參數
static long gpio_leds_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) {

gpiod_set_value(led_gpio.gpiod[arg], !cmd);

}

api

./ledtest -l 0 -v 1\r\n : led 0 on -l:led編號 -v:on / off

./ledtest -l 0 -v 0\r\n : led 0 off

ioctl(fd, value, led); //最後執行動作控制, value值/led編號

原作者:andyTW3974

更多回帖

发帖
×
20
完善资料,
赚取积分