这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 开源硬件 » 如何使用开源硬件BananaPIBPI-R2'sGPIO-s

共3条 1/1 1 跳转至

如何使用开源硬件BananaPIBPI-R2'sGPIO-s

助工
2021-04-06 19:10:55     打赏

BPI-R2集成MTK7623N 四核 ARM Cortex-A7 MP 支持主频1.3 ghz,BPI-R2 路由器提供丰富各种外设接口,包括 HDMI TX 高清接口, MIPI DSI 屏接口, PCIe2.0 接口, USB2.0 OTG 端口, USB3.0 端口, SATA 端口,5 千兆网口, 板载802.11a/b/g/n wifi 无线& BT4.1蓝牙 , 并且通过mini PCI-e支持 802.11ac/n WLAN

BPI-R2 系统支持 Android5.1,并完善支持 OpenWRT,Debian linux,Ubuntu linux, Raspbian 和其他嵌入式操作系统. 尺寸与BPI-R1完全一样大小, 支持 1080P y高清视频输入,40 PIN GPIO 与 Raspberry Pi 3一致.

同香蕉派其他板一样,Banana Pi BPI-R2 也有40-pin GPIO 接口:

Banana Pi BPI-R2 的40 PIN GPIO 定义与树莓派 3 一亲,下面是 Banana Pi GPIO定义:


Banana pi BPI-R2 40 PIN GPIO 定义
GPIO Pin NameDefault Function

CON1-P01VCC-3V3

CON1-P02VCC-5V

CON1-P03I2C\_SDA0GPIO75
CON1-P04VCC-5V

CON1-P05I2C\_SCL0GPIO76
CON1-P06GND

CON1-P07PWM-003GPIO206
CON1-P08UTXD1GPIO80
CON1-P09GND

CON1-P10URXD0GPIO81
CON1-P11URXD1GPIO80
CON1-P12I2S0\_BCKGPIO74
CON1-P13UTXD0GPIO79
CON1-P14GND

CON1-P15PWM-002GPIO205
CON1-P16URTS1GPIO25
CON1-P17VCC-3V3

CON1-P18UCTS1GPIO24
CON1-P19SPI0\_MOGPIO56
CON1-P20GND

CON1-P21SPI0\_MIGPIO55
CON1-P22PCM\_CLKGPIO18
CON1-P23SPI0\_CKGPIO54
CON1-P24SPI0\_CSNGPIO53
CON1-P25GND

CON1-P26PCM\_RXGPIO20
CON1-P27I2C\_SDA1GPIO57
CON1-P28I2C\_SCL1GPIO58
CON1-P29PCM\_RSTGPIO22
CON1-P30GND

CON1-P31SPDIF\_OUTGPIO200
CON1-P32PCM\_TXGPIO21
CON1-P33I2S0\_MCLKGPIO126
CON1-P34GND

CON1-P35I2S0\_LRCKGPIO73
CON1-P36PCM\_SYNCGPIO19
CON1-P37SPDIF\_IN1GPIO202
CON1-P38I2S0\_DATA\_INGPIO72
CON1-P39GND

CON1-P40I2S0\_DATA\_OUTGPI049



有两种方式使用R2的GPIO-s:

使用调试接口/sys/devices/platform/1000b000。pinctrl/mt_gpio,参考脚本1

使用GPIO的通用接口:/sys/class/ GPIO /export和/sys/class/ GPIO /unexport,请参考脚本2


Script 1 (it can be used on Ubuntu system with kernel 4.4.x)

--------------------

    SYS_FILE=/sys/devices/platform/1000b000.pinctrl/mt_gpio

    mt_gpio_mode()

    {

       pin=$1

       mode=$2

      

       if [ ! -f ${SYS_FILE} ]; then

           exit 1

       fi


       echo "mode $pin $mode" > ${SYS_FILE}


       return 0   

    }


    mt_gpio_dir()

    {

       pin=$1

       dir=$2

     

       if [ "x${dir}" == "xout" ]; then

           dir_val=1

       else

           dir_val=0

       fi

     

       if [ ! -f ${SYS_FILE} ]; then

           exit 1

       fi


       echo "dir $pin $dir_val" > ${SYS_FILE}


       return 0   

    }


    mt_gpio_out()

    {

       pin=$1

       out=$2

     

       if [ ! -f ${SYS_FILE} ]; then

           exit 1

       fi


       echo "out $pin $out" > ${SYS_FILE}


       return 0   

    }


    mt_gpio_in()

    {

       pin=$1

     

       if [ ! -f ${SYS_FILE} ]; then

           exit 1

       fi


       echo "start $1" > ${SYS_FILE}

       result=`cat ${SYS_FILE} | grep "$1"`


       if [ "x${result}" == "x" ]; then

           echo "can't get $pin status"

           exit 2

       fi

       echo ${result}

       pin_val=`echo ${result} | awk -F ' |-' '{print $5}'`

       if [ ${pin_val} == "0" ] ; then

           return 0

       else

           return 1

       fi

      

       return 0


    }




Script 2  (it can be used on Ubuntu system with kernel 4.4.x, and lede with kernel 4.9.x)

----------

    #!/bin/ash


    DIR=/sys/class/gpio/


    global_gpio_offset=0


    mt_gpio_init()

    {

        pin=$1


        EXPORT=/sys/class/gpio/export

        UNEXPORT=/sys/class/gpio/unexport



        name=`ls $DIR | grep chip`

        if [ x${name} != x ]; then

            echo "chip id : $name"

        else

            echo "No available gpio chip"

            exit 1

        fi


        base=`cat ${DIR}/${name}/base`


        gpio_offset=`echo $((base+$pin))`

        global_gpio_offset=$gpio_offset


        if [ -d ${DIR}/gpio${gpio_offset} ]; then

            return 0

        else

            echo ${gpio_offset} > ${EXPORT}

        fi

    }


    mt_gpio_init $1


    if [ $2 == 'dir' ]; then

        if [ $3 == 'out' ]; then

            echo out > ${DIR}/gpio${global_gpio_offset}/direction

        else

            echo in > ${DIR}/gpio${global_gpio_offset}/direction

        fi

    elif [ $2 == 'val' ]; then

        if [ $# == 2 ]; then

            cat ${DIR}/gpio${global_gpio_offset}/value

        elif [ $# == 3 ]; then

            echo $3 >  ${DIR}/gpio${global_gpio_offset}/value

        fi   

    fi 


all GPIO 定义,请参考在线文档 : 


%E9%A6%99%E8%95%89%E6%B4%BE_BPI-R2#BPI-R2_GPIO_.E5.AE.9A.E4.B9.89





关键词: 开发板     物联网    

专家
2021-04-07 00:02:40     打赏
2楼

感谢楼主的分享,很实用了。


工程师
2021-04-07 00:11:23     打赏
3楼

感谢楼主的分享,很实用了。


共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]