<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                本篇博文是為了后面的Android HAL層使用LED而做的準備,板子基于TQIMX6Q,Android 4.3,Android已經編譯完成了,如果還沒有可以參考前面我的博文:[Freescale IMX6 Android: 使用HDMI作為Android顯示輸出的配置](http://blog.csdn.net/sy373466062/article/details/50184041),以及TQ提供的開發者手冊。 ## LED的硬件連接 LED4~6是給用戶使用的,如下: ![](https://box.kancloud.cn/2016-05-05_572afc9ccf55d.jpg) 可以看到是GPIO3_21~23。而且是GPIO給高電平的時候接通。 ## LED軟件方面的配置 ### 直接導出使用 看到前面的原理圖,在用戶態直接將gpio導出來操作(gpiolib)是最容易的了,但是要在/sys/class/gpio中導出來需要知道各組gpio的base number,直接使用cat查看,結果如下: ~~~ #for i in gpiochip* ; do echo `cat $i/label`: `cat $i/base` ; done gpio-0: 0 gpio-4: 128 gpio-5: 160 gpio-6: 192 gpio-1: 32 gpio-2: 64 gpio-3: 96</span></span> ~~~ 可以知道gpio3是從64開始的,gpio3-21為64+21=85,于是直接操作: ~~~ #cd /sys/class/gpio echo 85 > export echo out > gpio85/direction echo 0 > gpio85/value ~~~ 但是發現不成功,因為gpio已經被使用了,無法導出來,盡管操作的時候沒有出現問題log提示。 ### 使用Gpio-led 內核使用的是3.0.35版本的內核,盡管也有dts,但是Freescale在最開始的Linuxkernel中并沒有使用,因此都是hard code在board文件中的,例如這里的LED的配置就是在arch/arm/mach-mx6/board-mx6q_sabresd.c中: ~~~ #define SABRESD_GPIO_LED0 IMX_GPIO_NR(3, 21) //home #define SABRESD_GPIO_LED1 IMX_GPIO_NR(3, 22) //enter #define SABRESD_GPIO_LED2 IMX_GPIO_NR(3, 23) //esc ~~~ 忽略注釋,然后接下來定義了一個Platform device: ~~~ static struct gpio_led imx6q_gpio_leds[] = { GPIO_LED(SABRESD_GPIO_LED0, "led0", 0, 1, "charger-charging"), GPIO_LED(SABRESD_GPIO_LED1, "led1", 0, 1, "charger-charging"), GPIO_LED(SABRESD_GPIO_LED2, "led2", 0, 1, "charger-charging"), /* For the latest B4 board, this GPIO_1 is connected to POR_B, which will reset the whole board if this pin's level is changed, so, for the latest board, we have to avoid using this pin as GPIO. GPIO_LED(SABRESD_CHARGE_DONE, "chg_done_led", 0, 1, "charger-full"), */ }; static struct gpio_led_platform_data imx6q_gpio_leds_data = { .leds = imx6q_gpio_leds, .num_leds = ARRAY_SIZE(imx6q_gpio_leds), }; static struct platform_device imx6q_gpio_led_device = { .name = "leds-gpio", .id = -1, .num_resources = 0, .dev = { .platform_data = &imx6q_gpio_leds_data, } }; ~~~ 直接在代碼中HardCode Device信息,這是老內核的通常做法。從上面的代碼我們知道注冊了leds-gpio設備,這個設備可以在/sys/class/leds中找到,啟動的時候probe時候也會打印出設備信息: ~~~ <span style="font-family:Microsoft YaHei;">Registered led device: led0 Registered led device: led1 Registered led device: led2</span> ~~~ 從前面的imx6q_gpio_leds結構體以及最前面的定義中可以知道LED的對應關系為: ~~~ HW ------- SW led4 led0 led5 led1 led6 led2 ~~~ 在對應的目錄中我們可以看到device設備信息: ~~~ root@sabresd_6dq:/sys/class/leds # ls -l lrwxrwxrwx root root 1970-01-02 09:36 led0 -> ../../devices/platform/leds-gpio/leds/led0 lrwxrwxrwx root root 1970-01-02 09:36 led1 -> ../../devices/platform/leds-gpio/leds/led1 lrwxrwxrwx root root 1970-01-02 09:36 led2 -> ../../devices/platform/leds-gpio/leds/led2 ~~~ ## GPIO-LED設備的控制 gpio-led設備的子目錄中有一個brightness文件,操作這個文件就可以操作led燈的亮滅,例如下面是點亮: ~~~ echo 255 > /class/gpio/leds/led0/brightness ~~~ 如果寫入0,那么就是熄滅。 因為Android中基礎小工具都是由Toolbox提供,因此我們可以往toolbox添加一個ledctrl工具來控制燈的亮滅: ~~~ #include <sys/cdefs.h> #ifndef lint __COPYRIGHT("@(#) Copyright (c) 1989, 1993, 1994\ The Regents of the University of California. All rights reserved."); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)ledctrl.c 8.5 (Berkeley) 5/4/95"; #else __RCSID("$NetBSD: ledctrl.c,v 1.33 2008/07/30 22:03:40 dsl Exp $"); #endif #endif /* not lint */ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> void ledClose(); int ledctrl( int which, int status); int ledOpen(); #define ALOGI printf #define LED_NUM 3 int leds_fd[LED_NUM]; char path_buff[255]; int ledctrl( int which, int status) { int ret = -1; if(status == 1) { ret = write(leds_fd[which], "255", 3); } else { ret = write(leds_fd[which], "0", 1); } if(ret < 0){ return -1; } ALOGI("Native ctrl fd = [%d]\n", which); return 0; } int ledOpen(void) { int i = 0; for(i=0; i<LED_NUM; i++){ sprintf(path_buff, "/sys/class/leds/led%d/brightness", i); printf("path:%s\n",path_buff); leds_fd[i] = open(path_buff, O_RDWR); if(leds_fd[i] < 0){ ALOGI("led%d: %s, open failed\n", i, path_buff); return -1; } else { ALOGI("led%d: %s, open success\n", i, path_buff); } } return 0; } void ledClose(void) { int i = 0; for(i=0; i< LED_NUM; i++){ close(leds_fd[i]); } } int ledctrl_main(int argc, char * argv[]) { int i = 0; int ret = ledOpen(); if (ret < 0){ printf("Open failed\n"); return -1; } for(i=0; i< LED_NUM; i++){ ledctrl(i,1); sleep(1); ledctrl(i,0); } ledClose(); return 0; } ~~~ 我們在main函數中對每一個LED點亮1秒,然后就熄滅。將這個C代碼保存為ledctrl.c,放在system/core/toolbox下面,然后更改toolbox目錄下的Android.mk將其添加到toolbox中: ~~~ diff --git a/core/toolbox/Android.mk b/core/toolbox/Android.mk index c764690..a19338e 100644 --- a/core/toolbox/Android.mk +++ b/core/toolbox/Android.mk @@ -57,6 +57,7 @@ TOOLS := \ touch \ lsof \ du \ + ledctrl \ md5 \ clear \ getenforce \ ~~~ 直接在toolbox目錄下面使用mm命令編譯: ~~~ $ mm ============================================ PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=4.3 TARGET_PRODUCT=sabresd_6dq TARGET_BUILD_VARIANT=eng TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm TARGET_ARCH_VARIANT=armv7-a-neon TARGET_CPU_VARIANT=cortex-a9 HOST_ARCH=x86 HOST_OS=linux HOST_OS_EXTRA=Linux-3.13.0-39-generic-x86_64-with-Ubuntu-12.04-precise HOST_BUILD_TYPE=release BUILD_ID=1.1.0-rc4 OUT_DIR=out ============================================ PRODUCT_COPY_FILES device/fsl/common/input/HannStar_P1003_Touchscreen.idc:system/usr/idc/HannStar_P1003_Touchscreen.idc ignored. PRODUCT_COPY_FILES device/fsl/common/input/Novatek_NT11003_Touch_Screen.idc:system/usr/idc/Novatek_NT11003_Touch_Screen.idc ignored. PRODUCT_COPY_FILES device/fsl/common/input/qwerty.idc:system/usr/idc/qwerty.idc ignored. PRODUCT_COPY_FILES device/fsl/common/input/qwerty2.idc:system/usr/idc/qwerty2.idc ignored. No private recovery resources for TARGET_DEVICE sabresd_6dq make: Entering directory `/home/hexiongjun/iMX6Q/TQIMX6_android-4.3' target thumb C: toolbox <= system/core/toolbox/ledctrl.c target Executable: toolbox (out/target/product/sabresd_6dq/obj/EXECUTABLES/toolbox_intermediates/LINKED/toolbox) target Symbolic: toolbox (out/target/product/sabresd_6dq/symbols/system/bin/toolbox) target Strip: toolbox (out/target/product/sabresd_6dq/obj/EXECUTABLES/toolbox_intermediates/toolbox) Install: out/target/product/sabresd_6dq/system/bin/toolbox make: Leaving directory `/home/hexiongjun/iMX6Q/TQIMX6_android-4.3' ~~~ 編譯完成后toolbox,我們可以重新將system目錄的文件拷貝到SD開對應的system分區中,也可以直接將toolbox push到android機器中,在push之前需要先remount system為rw,因此在串口中,或者有root權限的adb shell中輸入下面命令: ~~~ # mount -t ext4 -r -w -o remount /system EXT4-fs (mmcblk1p2): re-mounted. Opts: (null) ~~~ 然后push文件到機器中: ~~~ $ adb push $OUT/system/bin/toolbox /system/bin/ 1309 KB/s (139096 bytes in 0.103s) ~~~ 然后在機器的console中測試: ~~~ # toolbox ledctrl path:/sys/class/leds/led0/brightness led0: /sys/class/leds/led0/brightness, open success path:/sys/class/leds/led1/brightness led1: /sys/class/leds/led1/brightness, open success path:/sys/class/leds/led2/brightness led2: /sys/class/leds/led2/brightness, open success Native ctrl fd = [0] Native ctrl fd = [0] Native ctrl fd = [1] Native ctrl fd = [1] Native ctrl fd = [2] Native ctrl fd = [2] ~~~ 如果看到LED點亮1秒然后熄滅,那么說明代碼無誤。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看