勇闖新世界︰ 《 Kernel 4.X 》之整裝蓄勢‧PiTFT‧二

大自然用著『基因』紀錄『譜系』,人類為著『分類』而將產品作『編號』。然而透過『編號』有時後並不容易區分事物,因此務須小心。比方說 PiTFT 名目下有前後多種產品,『編號』雖是不同,『名稱』卻是相同,但是不同版本或來源之『核心』 Kernel 的控制很可能不同。在此我們採用的是

【40 PIN 按鍵在右的 #2298

2298-16

 

不是【早期 26 PIN 按鍵在下的 #1601

x1601-00.jpg.pagespeed.ic.ptI8PZq86n

 

若是不審慎一點,當閱讀某些網路文章片段時︰

Backlight Control

Controlling the backlight

There’s a 4-LED backlight on the TFT and it draws ~75mA at all times. There might be times you’d like to save some power and turn off the backlight. The screen and touchplate will still work, you just can’t see anything. We designed the board with the STMPE610 touchscreen controller which has 2 extra GPIO and tied one of them to the transistor that controls the backlight. You can use the command line to control the backlight.

Start by getting access to the GPIO by making a device link

sudo sh -c “echo 508 > /sys/class/gpio/export”
ls -l /sys/class/gpio

Please note, previous versions of the PiTFT kernel had the STMPE GPIO pin ‘252’ not ‘508’ so just substitue that number

Once you verify that you see GPIO #508, then you can set it to an output, this will turn off the display since it will output 0 by default

sudo sh -c “echo ‘out’ > /sys/class/gpio/gpio508/direction”

Then turn the display back on with

sudo sh -c “echo ‘1’ > /sys/class/gpio/gpio508/value”

or back off

sudo sh -c “echo ‘0’ > /sys/class/gpio/gpio508/value”

 

將不知所指,或許會誤解叢生的吧!

這裡的『/sys/class/gpio/』使用者界面,就是之前

Physical computing ︰《三》 GPIO 溯源《上》》文本中所講的︰

二零零六年,在

LKML.ORG? 】︰

In case you haven’t read the titlebar of your webbrowser’s window: this site is the (unofficial) Linux Kernel Mailing List archive. This mailing list is a rather high-volume list, where (technical) discussions on the design of, and bugs in the Linux kernel take place. If that scares you, please read the FAQ.

David Brownell 的一封《電郵》【 Re: [-mm patch 1/4] GPIO framework for AVR32 】開啟了『 GPIO 』之『軟體架構』的討論,大體可說到二零零八年【※Re: [ patch 2.6.24-rc6-mm 2/9] gpiolib: add gpio provider infrastructure 】之前, Linux kernel 的
GPIO Sysfs Interface for Userspace 》整體已經完成。讀者可以參考《  GPIO Interfaces 》與《 Linux/include/linux/gpio.h 》文件作進一步了解。

……

讀者也許可以讀讀那《》《》《》三篇文章,對於『GPIO』之架構與實務能有多一些了解。雖說有部份內容,因著核心改版而變遷,讀書之法或應如

M♪o 之學習筆記本《子》開關︰【青木仁】格物致知

的 M♪o 般與時偕行,能自主驗證,這才是格物致知之道也︰

行 ︰《小狐狸》之書曾寫過︰

就讓我們透過『 Sysfs 』── 是 Linux 2.6 所提供的一種『虛擬檔案系統』 VFS virtual files system 。這個檔案系統不僅可以把『裝置』 devices 和『驅動程式』 device drivers 的資訊從『核心』 kernel 內部輸出到『使用者空間』 user space ,也可以用來對裝置和驅動程式做『設定』。── 來控制『系統 ACT LED』,與 GPIO建立聯繫』吧!

# 為什麼一定得是 root 呢?可以只用 sudo 嗎??
sudo -s

echo none > /sys/class/leds/led0/trigger
echo 1 >/sys/class/leds/led0/brightness
echo 0 >/sys/class/leds/led0/brightness
echo 1 >/sys/class/leds/led0/brightness
echo 0 >/sys/class/leds/led0/brightness
exit

 

Ah Ha!!這樣想要有顆『閃爍』的『小星星』,怕是不可得的了,何不閱讀《 Advanced Bash-Scripting Guide 》一下,寫個『 Shell 』程式呢??

。雖說曾聞『早鳥氏』實證時否定了,然『盡信書,不如無書』,況此一時彼一時已經不同,何不自己格之!!

root@raspberrypi:/sys/class/gpio# cd /sys/class/leds/
root@raspberrypi:/sys/class/leds# ls
led0  led1
root@raspberrypi:/sys/class/leds# cd led0
root@raspberrypi:/sys/class/leds/led0# ls
brightness  device  max_brightness  subsystem  trigger	uevent
echo none > /sys/class/leds/led0/trigger
root@raspberrypi:/sys/class/leds/led0# echo 1 >/sys/class/leds/led0/brightness
root@raspberrypi:/sys/class/leds/led0# echo 0 >/sys/class/leds/led0/brightness
root@raspberrypi:/sys/class/leds/led0# 

果然大功告成。噫!怎有個『 led1 』哩?何妨依樣畫葫蘆!… ☿☺

 

【Kernel 4.0.9 系統參考】

pi@raspberrypi ~ cd /sys/class/gpio/  pi@raspberrypi /sys/class/gpio ls
export  gpiochip0  gpiochip506  unexport

# 背光 LED 測試
pi@raspberrypi /sys/class/gpio sudo sh -c "echo 508 > /sys/class/gpio/export"  pi@raspberrypi /sys/class/gpio ls
export  gpio508  gpiochip0  gpiochip506  unexport

# 關閉背光 LED
pi@raspberrypi /sys/class/gpio sudo sh -c "echo 'out' > /sys/class/gpio/gpio508/direction"  # 打開背光 LED pi@raspberrypi /sys/class/gpio sudo sh -c "echo '1' > /sys/class/gpio/gpio508/value"

# 系統 LED 
pi@raspberrypi /sys/class/gpio cd /sys/class/leds/ pi@raspberrypi /sys/class/leds ls
led0  led1
pi@raspberrypi /sys/class/leds cd  # Kernel 版本 pi@raspberrypi ~ cat /proc/version 
Linux version 4.0.9-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #807 SMP PREEMPT Fri Jul 24 15:21:02 BST 2015
pi@raspberrypi ~ </pre>    <span style="color: #ff0000;">───</span>  <span style="color: #ff0000;">【※ 最新 Kernel 4.1.4 系統參考對比測試 OK】</span> <pre class="lang:sh decode:true ">pi@raspberrypi ~ cat /proc/version 
Linux version 4.1.4-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.8.3 20140303 (prerelease) (crosstool-NG linaro-1.13.1+bzr2650 - Linaro GCC 2014.03) ) #808 SMP PREEMPT Thu Aug 6 16:59:39 BST 2015

pi@raspberrypi ~ cd /sys/class/gpio/ pi@raspberrypi /sys/class/gpio ls
export  gpiochip0  gpiochip506  unexport
pi@raspberrypi /sys/class/gpio sudo sh -c "echo 508 > /sys/class/gpio/export" pi@raspberrypi /sys/class/gpio ls
export  gpio508  gpiochip0  gpiochip506  unexport
pi@raspberrypi /sys/class/gpio sudo sh -c "echo 'out' > /sys/class/gpio/gpio508/direction" pi@raspberrypi /sys/class/gpio sudo sh -c "echo '1' > /sys/class/gpio/gpio508/value"
pi@raspberrypi /sys/class/gpio cd /sys/class/leds/ pi@raspberrypi /sys/class/leds ls
led0  led1
pi@raspberrypi /sys/class/leds $