• 【全志T113-S3_100ask】15-2 linux系统gpio模拟spi驱动屏幕——ILI9341


    【全志T113-S3_100ask】15-2 linux系统gpio模拟spi驱动屏幕——ILI9341

    背景

    • 在上一小节里,我们使用了硬件spi以及内核程序对spi屏幕进行了控制,刷屏的速度还是非常快的。
    • 既然stm32和esp32等单片机都能模拟spi进行驱动,那么强大的arm理论上也能通过gpio模拟spi进行控制,本小节将实现如何配置模拟spi。

    (一)查阅参考文档

    文档路径 :Documentation/devicetree/bindings/spi/spi-gpio.yaml

    # SPDX-License-Identifier: GPL-2.0
    %YAML 1.2
    ---
    $id: http://devicetree.org/schemas/spi/spi-gpio.yaml#
    $schema: http://devicetree.org/meta-schemas/core.yaml#
    
    title: SPI-GPIO devicetree bindings
    
    maintainers:
      - Rob Herring <robh@kernel.org>
    
    description:
      This represents a group of 3-n GPIO lines used for bit-banged SPI on
      dedicated GPIO lines.
    
    allOf:
      - $ref: "/schemas/spi/spi-controller.yaml#"
    
    properties:
      compatible:
        const: spi-gpio
    
      sck-gpios:
        description: GPIO spec for the SCK line to use
        maxItems: 1
    
      miso-gpios:
        description: GPIO spec for the MISO line to use
        maxItems: 1
    
      mosi-gpios:
        description: GPIO spec for the MOSI line to use
        maxItems: 1
    
      cs-gpios:
        description: GPIOs to use for chipselect lines.
          Not needed if num-chipselects = <0>.
        minItems: 1
        maxItems: 1024
    
      num-chipselects:
        description: Number of chipselect lines. Should be <0> if a single device
          with no chip select is connected.
        $ref: "/schemas/types.yaml#/definitions/uint32"
    
      # Deprecated properties
      gpio-sck: false
      gpio-miso: false
      gpio-mosi: false
    
    required:
      - compatible
      - num-chipselects
      - sck-gpios
    
    examples:
      - |
        spi {
          compatible = "spi-gpio";
          #address-cells = <0x1>;
          #size-cells = <0x0>;
    
          sck-gpios = <&gpio 95 0>;
          miso-gpios = <&gpio 98 0>;
          mosi-gpios = <&gpio 97 0>;
          cs-gpios = <&gpio 125 0>;
          num-chipselects = <1>;
    
          /* clients */
        };
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71

    看起来还是挺简单的,只需要配置 compatible 和对应的 gpio。
    但是要在内核勾选相应的模块。

    (二)使能内核模块

    1、在linux内核目录下,输入 make menuconfig 即可进入菜单页面
    2、左斜杠 / 进入搜素 ,输入 spi_gpio ,然后回车
    在这里插入图片描述
    在这里插入图片描述
    3、输入 1 选中它,然后勾选这两项
    在这里插入图片描述
    4、然后退出

    (三)修改设备树

    此时工作已经完成一半了,下面直接修改设备树即可使用。
    参照那个文档,进行设备树的配置

    • 在根节点下:
    aspi{
    	compatible = "spi-gpio";
    	#address-cells = <0x1>;
    	#size-cells = <0x0>;
    
    	sck-gpios = <&pio PE 8 0>;
    	miso-gpios = <&pio PE 9 0>;
    	mosi-gpios = <&pio PE 10 0>;
    	cs-gpios = <&pio PE 11 0>;
    	num-chipselects = <1>;
    
    	status = "okay";
    	/* 下面添加具体的spi设备*/
    	
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    如下所示:
    在这里插入图片描述

    • 在pio添加对应的gpio
    aspi_pin: aspi_pin{
    			allwinner,pins = "PE8","PE9","PE10","PE11"; 
    		};
    
    • 1
    • 2
    • 3

    如下所示:
    在这里插入图片描述
    然后编译内核、buildroot、烧录balabala。。。

    (四)测试

    参照上一个文档的程序 fb-test-rect
    感受:慢。
    明显感觉到一帧帧地刷过去。
    在这里插入图片描述

    (五)后语

    其实实现模拟spi不是为了刷屏,而是这个屏幕使用的是电阻屏,使用的是XPT2046芯片,需要使用spi通信,对于读取触摸屏位置来说,对速度的要求其实不高。但是这个板子没有多余的spi了,cs只有一个,只能暂时模拟spi使用了(如果把核心板的spi nand拆掉呢)

  • 相关阅读:
    Shell编程之免交互
    RDMA测试集:preftest安装与使用
    uniapp+vue3+ts+vite+echarts开发图表类小程序,将echarts导入项目使用的详细步骤,耗时一天终于弄好了
    SQL注入之宽字节注入、堆叠注入、二次注入
    宗老师计算机教学-大型集群开发基础知识
    利用SOP完成新客户培育
    【ETL工具】本地环境IDEA远程DEBUG调试Flume代码
    MCR3516与MCR3512读写器在麒麟系统中info.plist文件冲突解决方案
    Spring 项目的创建和 “使用“
    MySQL入门指南5(约束,索引,事务)
  • 原文地址:https://blog.csdn.net/qq_46079439/article/details/128072100