HOME
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
Shop
  • English
  • 简体中文
HOME
  • GM-3568JHF
  • M4-R1
  • M5-R1
  • SC-3568HA
  • M-K1HSE
  • CF-NRS1
  • CF-CRA2
  • 1684XB-32T
  • 1684X-416T
  • C-3568BQ
  • C-3588LQ
  • GC-3568JBAF
  • C-K1BA
Shop
  • English
  • 简体中文
  • 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

GPIO Interface

1. GPIO Overview

GPIO stands for General Purpose I/O, which refers to universal input/output ports. Simply put, these are pins controllable by the MCU/CPU. These pins typically serve multiple functions, with the most fundamental being high/low level input detection and output. Some pins are also bound to on-chip peripherals of the microcontroller, serving as communication pins for interfaces like UART, I2C, SPI, or voltage detection functions.

2. GPIO Naming Convention

The ID of a Rockchip pin is composed of the controller (bank), port, and pin index.

  • The number of controllers is consistent with the number of GPIO controllers.
  • Ports are fixed as A, B, C, and D, with each port containing only 8 indexes (A=0, B=1, C=2, D=3).
  • The index numbers are fixed as 0, 1, 2, 3, 4, 5, 6, 7.

The RK3568 is equipped with 5 GPIO controllers, each capable of managing 32 IO pins. When configured as GPIO functions, the port behavior is determined by the GPIO controller registers.

Tips

GPIO1_A4 indicates Controller Bank 1, Port A, and Index 4.
The pin number is calculated using the formula:
32 (pins per controller) × 1 (bank) + 0 (port offset within bank) × 8 (pins per port) + 4 (index) = 36.

3. Using the GPIO sysfs interface to control input/output operations

Command-line method

In Linux, the most common method for GPIO read/write operations is through the GPIO sysfs interface, which involves manipulating files such as export, unexport, gpio{N}/direction, and gpio{N}/value (with {N} replaced by the actual pin number) under the /sys/class/gpio directory. This approach is frequently employed in shell scripts. Starting from kernel version 4.8, support for libgpiod was introduced, and the legacy sysfs-based access method is gradually being deprecated.

Taking the SC-3568HA as an example, select 3 GPIO pins from the 40-pin header.

TOOL
GPIOControllerPort numberIndex numberCalculation resultPIN
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
	#All the following operations require administrator privileges to be enabled (HarmonyOS has administrator privileges enabled by default).
    #Enable GPIO4_D2 pin
    echo 154 > /sys/class/gpio/export

    #Set the pin to input mode
    echo in > /sys/class/gpio/gpio154/direction
    #Read the pin value
    cat /sys/class/gpio/gpio154/value

    #Set the pin to output mode
    echo out > /sys/class/gpio/gpio154/direction
    #Set the pin to low level
    echo 0 > /sys/class/gpio/gpio154/value
    #Set the pin to high level
    echo 1 > /sys/class/gpio/gpio154/value

    #Reset pin
    echo 154 > /sys/class/gpio/unexport

4. Extend GPIO ports

The SC-3568HA is equipped with the NCA9555 chip, a 24-pin CMOS device that provides 16-bit general-purpose parallel I2C-bus GPIO input/output expansion functionality.

4.1 Extend GPIO port pins

Currently, 5 IOs are routed out from this chip for use and connected to a 40-pin connector.

TOOLTOOL
NCA955540PIN
IO1_135
IO1_237
IO1_338
IO1_440
IO1_531

4.2 Extend GPIO ports for use

This chip uses I2C communication, is mounted under I2C3, the driver files have been added, and the DTS configuration is as follows:

  • /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>;
		};
	};

Tips

Using NCA9555's IO ports within the kernel is largely consistent with standard GPIO usage.

For example:

	//Using standard GPIO
    &vcc3v3_lcd0_n {
        gpio = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
        enable-active-high;
    };

    //Using NCA9555's IO
    &vcc3v3_lcd1_n {
        gpio = <&nca9555 3 GPIO_ACTIVE_HIGH>;   //Corresponding to NCA9555 IO0_3
        enable-active-high;
    };

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

Edit this page on GitHub
Last Updated:
Contributors: zsl, zwhuang
Prev
Raspberry Pi interface
Next
I2C Interface