HOME
Shop
  • English
  • 简体中文
HOME
Shop
  • English
  • 简体中文
  • Product Series

    • FPGA+ARM

      • GM-3568JHF

        • 1. Introduction

          • GM-3568JHF Introduction
        • 2. Quick Start

          • 01 Environment Construction
          • 02 Compilation Instructions
          • 03 Burning Guide
          • 04 Debugging Tools
          • 05 Software Update
          • 06 View information
          • 07 Test Command
          • 08 Application Compilation
          • 09 Source code acquisition
        • 3. Peripherals and Interfaces

          • USB
          • Display and touch
          • Ethernet
          • WIFI
          • Bluetooth
          • TF-Card
          • Audio
          • Serial Port
          • CAN
          • RTC
        • 4. Application Development

          • 01 UART read and write case
          • 02 Key detection case
          • 03 LED light flashing case
          • 04 MIPI screen detection case
          • 05 Read USB device information example
          • 06 FAN Detection Case
          • 07 FPGA FSPI Communication Case
          • 08 FPGA DMA read and write case
          • 09 GPS debugging case
          • 10 Ethernet Test Cases
          • 11 RS485 reading and writing examples
          • 12 FPGA IIC read and write examples
          • 13 PN532 NFC card reader case
          • 14 TF card reading and writing case
        • 5. QT Development

          • 01 ARM64 cross compiler environment construction
          • 02 QT program added automatic startup service
        • 6. Others

          • 01 Modification of the root directory file system
          • 02 System auto-start service
    • ShimetaPi

      • M4-R1

        • Introduction

          • M4-R1 Introduction
        • Get started quickly

          • OpenHarmony概述
          • 镜像烧录
          • 开发环境准备
          • Hello World应用以及部署
        • Application Development

          • getting Started

            • 第一章 ArkTS语言简介
            • 第二章 UI组件介绍和实际应用(上)
            • 第三章 UI组件介绍和实际应用(中)
            • 第四章 UI组件介绍和实际应用(下)
          • Advanced

            • 第一章 入门指引
            • 第二章 三方库的引用和使用
            • 第三章 应用编译以及部署
            • 第四章 命令行恢复出厂设置
            • 第五章 系统调试--HDC调试
            • 第六章 APP 稳定性测试
            • 第七章 应用测试
        • Equipment Development

          • 第一章 环境搭建
          • 第二章 下载源码
          • 第三章 编译源码
        • Peripherals and interfaces

          • 树莓派接口
          • GPIO 接口
          • I2C 接口
          • SPI通信
          • PWM控制
          • 串口通讯
          • TF Card
          • 屏幕
          • 触摸
          • 音频
          • RTC
          • Ethernet
          • M.2
          • MINI-PCIE
          • Camera
          • WIFI&BT
          • 树莓派拓展板
        • Frequently asked questions

          • 资源下载
      • M5-R1

        • Introduction

          • Introduction to ShimetaPi M5-R1
    • OpenHarmony

      • SC-3568HA

        • Introduction

          • SC-3568HA Overview
        • Quick Start Guide

          • OpenHarmony Overview
          • Image Flashing
          • Setting Up the Development Environment
          • Hello World Application and Deployment
        • Application Development

          • ArkUI

            • Chapter 1 Introduction to ArkTS Language
            • Chapter 2 Introduction to UI Components and Practical Applications (Part 1)
            • Chapter 3 Introduction to UI Components and Practical Applications (Part 2)
            • Chapter 4 Introduction to UI Components and Practical Applications (Part 3)
          • Expand

            • Chapter 1 Getting Started Guide
            • Chapter 2 Referencing and Using Third-Party Libraries
            • Chapter 3: Application Compilation and Deployment
            • Chapter 4: Command-Line Factory Reset
            • Chapter 5: System Debugging -- HDC (Huawei Device Connector) Debugging
            • Chapter 6 APP Stability Testing
            • Chapter 7 Application Testing
        • Device Development

          • Chapter 1 Environment Setup
          • Chapter 2 Download Source Code
          • Chapter 3 Compiling Source Code
        • Peripheral And Iinterface

          • Raspberry Pi interface
          • GPIO Interface
          • I2C Interface
          • SPI communication
          • PWM (Pulse Width Modulation) control
          • Serial port communication
          • TF Card
          • Display Screen
          • Touch
          • Audio
          • RTC
          • Ethernet
          • M.2
          • MINI-PCIE
          • Camera
          • WIFI&BT
          • Raspberry Pi expansion board
        • Frequently Asked Questions

          • Resource Downloads
      • M-K1HSE

        • Introduction

          • M-K1HSE Introduction
        • Quick Start

          • Development environment construction
          • Source code acquisition
          • Compilation Notes
          • Burning Guide
        • Peripherals and interfaces

          • 01 Audio
          • 02 RS485
          • 03 Display
        • System customization development

          • System transplant
          • System customization
          • Driver Development
          • System Debugging
          • OTA Update
    • EVS-Camera

      • CF-NRS1

        • 1. Introduction

          • Event Camera Technical Documentation
        • 2. Quick Start

          • Host driver and software installation
        • 3. SDK application development

          • API Usage Instructions
      • CF-CRA2

        • Introduction

          • About CF-NRS1
    • AI-model

      • 1684XB-32T

        • Introduction

          • AIBOX-1684XB-32 Introduction
        • Get started quickly

          • First time use
          • Network Configuration
          • Disk usage
          • Memory allocation
          • Fan Strategy
          • Firmware Upgrade
        • Deployment Tutorial

          • Algorithm deployment
          • Deploy Llama3 Example
        • Application Development

          • Sophgo SDK Development
          • Sophon LLM_api_server development
          • Deploy MiniCPM-V-2_6
          • Qwen-2-5-VL Image and Video Recognition DEMO
          • Qwen3-chat-DEMO
          • Qwen3-Qwen Agent-MCP-Demo
          • Qwen3-langchain-AI Agent
      • 1684X-416T

        • Introduction

          • AIBOX-1684X-416 Introduction
        • Demo simple operation guide

          • Simple instructions for using shimeta smart monitoring demo
    • Core-Board

      • C-3568BQ

        • Introduction

          • C-3568BQ Overview
      • C-3588LQ

        • Introduction

          • C-3588LQ Introduction
      • GC-3568JBAF

        • Introduction

          • GC-3568JBAF Introduction
      • C-K1BA

        • Introduction

          • C-K1BA Introduction

GPIO 接口

1. GPIO介绍

GPIO是General Purpose I/O的缩写,即通用输入输出端口,简单来说就是MCU/CPU可控制的引脚, 这些引脚通常有多种功能,最基本的是高低电平输入检测和输出,部分引脚还会与主控器的片上外设绑定, 如作为串口、I2C、网络、电压检测的通讯引脚。

2. GPIO命名

Rockchip Pin的ID按照 控制器(bank)+端口(port)+索引序号(pin) 组成。

  • 控制器和GPIO控制器数量一致
  • 端口固定 A、B、C和D,每个端口仅有8个索引号,(a=0,b=1,c=2,d=3)
  • 索引序号固定 0、1、2、3、4、5、6、7

RK3568具有5个GPIO控制器,每个控制器可以控制32个IO,作为GPIO功能时, 端口⾏为由GPIO控制器寄存器配置。

Tips

GPIO1_A4表达的意思为第1组控制器,端口号为A,索引号为4。 该引脚号的计算公式为32 x 1 + 0 x 8 + 4 = 36

3. 使用GPIO sysfs接口控制IO

命令行的方式

在Linux中,最常见的读写GPIO方式就是用GPIO sysfs interface, 是通过操作 /sys/class/gpio 目录下的 export 、 unexport 、gpio{N}/direction, gpio{N} /value (用实际引脚号替代{N})等文件实现的,经常出现shell脚本里面。 在kernel 4.8开始,加入了libgpiod的支持;而原有基于sysfs的访问方式,将被逐渐放弃。

以M4-R1举例,在40PIN引脚上挑选3个GPIO

TOOL
引脚控制器端口号索引号计算结果PIN
GPIO4_D24D2154 (32 x 4 + 8 x 3 + 2)7
GPIO2_D72D795 (32 x 2 + 8 x 3 + 7)18
GPIO0_C50C521 (32 x 0 + 8 x 2 + 5)29
	#以下所有操作均需要打开管理者权限使用(鸿蒙系统默认就是管理者权限)
    #使能引脚GPIO4_D2
    echo 154 > /sys/class/gpio/export

    #设置引脚为输入模式
    echo in > /sys/class/gpio/gpio154/direction
    #读取引脚的值
    cat /sys/class/gpio/gpio154/value

    #设置引脚为输出模式
    echo out > /sys/class/gpio/gpio154/direction
    #设置引脚为低电平
    echo 0 > /sys/class/gpio/gpio154/value
    #设置引脚为高电平
    echo 1 > /sys/class/gpio/gpio154/value

    #复位引脚
    echo 154 > /sys/class/gpio/unexport

4. 拓展GPIO口

M4-R1上带有NCA9555芯片,NCA9555是一款24引脚CMOS器件,提供16位通用并行I2C总线数输入/输出GPIO扩展功能

4.1 拓展GPIO口引脚

目前从该芯片引出了5个IO出来使用,连接到了40PIN引脚上

TOOLTOOL
NCA955540PIN
IO1_135
IO1_237
IO1_338
IO1_440
IO1_531

4.2 拓展GPIO口使用

该芯片为I2C通讯,挂载在I2C3下,驱动文件已添加,DTS配置如下:

  • /arch/arm64/boot/dts/rockchip/rk3568-toybrick-x0-linux.dts
	&i2c3{
	nca9555:nca9555@20{
		reg=<0x20>;
		compatible = "novosense,nca9555";
		status="okay";
		gpio-controller;
		#gpio-cells = <2>;
		};
	};

备注

在内核中使用NCA9555的IO口,其方式与普通的GPIO使用方式基本一致

例如:

	//使用普通GPIO
    &vcc3v3_lcd0_n {
        gpio = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
        enable-active-high;
    };

    //使用NCA9555的IO
    &vcc3v3_lcd1_n {
        gpio = <&nca9555 3 GPIO_ACTIVE_HIGH>;   //对应NCA9555 IO0_3
        enable-active-high;
    };

    &vcc3v3_lcd2_n {
        gpio = <&nca9555 10 GPIO_ACTIVE_HIGH>;   //对应NCA9555 IO1_2
        enable-active-high;
    };

Edit this page on GitHub
Last Updated:
Contributors: zwhuang
Prev
树莓派接口
Next
I2C 接口