RK GPIO的一些简单配置

213 阅读1分钟

1.GPIO重命名

一般在dtsi文件里可以对GPIO起一个别名,方便操作,例如

spk_gpio: spk-gpio{
		compatible = "rockchip,gpio-spk-ctl";
		spk-ctl = <&gpio3 RK_PA2  GPIO_ACTIVE_LOW>;
		status = "okay";
	};

gpio3 RK_PA2 的别名为 gpio-spk-ctl,这样就可以通过节点操作GPIO了,一般是dev/gpio-spk-ctl

private void writeFileNode(String cmd, String filePath){     
        try {
            BufferedWriter bufWriter = null;
            bufWriter = new BufferedWriter(new FileWriter(filePath));
            bufWriter.write(cmd);  
            bufWriter.close();
            Slog.d("writeFileNode","wtrieValue = "+cmd);            Slog.d("writeFileNode","filePath = "+filePath);       } catch (IOException e) {
            e.printStackTrace();
            Slog.e("writeFileNode","can't write the " + filePath);        }		
    }

private String readFileNode(String filePath){     
        int size = 0;
        String line;
        
        try {
            BufferedReader bufReader = null;
            bufReader = new BufferedReader(new FileReader(filePath));
            
            while((line=bufReader.readLine())!=null) {
                Slog.e("readFileNode","read line = " + line);                break;
            }
            bufReader.close();            
            return line;
        }catch (IOException e) {
            e.printStackTrace();
            Slog.e("readFileNode","can't read the " + filePath);        }
        return "open";
    }

2.GPIO脚的配置

kernel-4.19\include\dt-bindings\gpio\gpio.h

#ifndef _DT_BINDINGS_GPIO_GPIO_H
#define _DT_BINDINGS_GPIO_GPIO_H

/* Bit 0 express polarity */
#define GPIO_ACTIVE_HIGH 0
#define GPIO_ACTIVE_LOW 1

/* Bit 1 express single-endedness */
#define GPIO_PUSH_PULL 0
#define GPIO_SINGLE_ENDED 2

/* Bit 2 express Open drain or open source */
#define GPIO_LINE_OPEN_SOURCE 0
#define GPIO_LINE_OPEN_DRAIN 4

/*
 * Open Drain/Collector is the combination of single-ended open drain interface.
 * Open Source/Emitter is the combination of single-ended open source interface.
 */
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN)
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE)

/* Bit 3 express GPIO suspend/resume and reset persistence */
#define GPIO_PERSISTENT 0
#define GPIO_TRANSITORY 8

#endif