2023年12月14日 星期四

在 Linux 下使用 Autodesk Fusion 360

 https://github.com/cryinkfly/Autodesk-Fusion-360-for-Linux

3D 列印,很多分享的檔案都用 step 檔。Autodesk Fusion 360 雖然是付費軟體,但提供個人用途的免費使用,就來試試吧。

unset LANG,unset LC_ALL 後,安裝 app-emulation/wine-staging, app-emulation/dxvk。執行 install.sh 時,只要把語言改成 English,選擇 Gentoo,會要求 su 的權限,自動安裝缺少的 package。


https://askubuntu.com/questions/516307/how-do-i-change-default-wine-browser-to-native-ubuntu-browser-instead-of-ie


2023年12月12日 星期二

點焊機 DIY

NY-D02 點焊機控制板

此控制板是寧洋科技的產品,NY,應為 "寧洋" 的縮寫吧。關於控制板的資訊,在淘寶的產品頁面有詳細的說明,將一些資訊整理在此,方便參考。

NY-D02,雙脈衝控制板。

雙脈衝輸出,第一個脈衝除掉焊件表面的髒並預熱,第二個脈衝焊接。增強焊接功能,並且焊點不發黑。

電壓校準

因本控制器帶有網壓補償功能,所以,第一次裝機時,要進行電壓校準。以後只要不更換電源變壓器,就不用再校準。

校準操作,在運行狀能時,長按微動開關,直到時間,電流,間隔的燈全部亮起,此時用萬用表測量一下巿電電壓,比如當時測量的電壓為225V,那麼,旋轉編碼器,使數碼管顯示的值為 225 即可,然後雙擊微動開關,退出校準。

操作顯示板指示燈說明


  1. 電源 - 系統電源,常亮
  2. 腳踏 - 當腳踏開關閉合時,此燈亮
  3. 觸發 - 當可控矽觸發時,此燈亮。亮的時間和焊接時間相等
  4. 運行 - 允許焊接時,此燈常亮。設置參數時,此燈滅
  5. 時間 - 第一次脈衝時間。運行時: 第一次脈衝同步點亮。參數查詢 :此燈亮,數碼管顯示當前設定的焊接時間值。參數設置:此燈亮,數碼管閃爍,通過編碼器修改當前值。
  6. 電流 - 第一次脈衝焊接電流。運行時: 脈衝同步點亮。參數查詢 :此燈亮,數碼管顯示當前設定的焊接電流值。參數設置:此燈亮,數碼管閃爍,通過編碼器修改當前值。
  7. 間隔 - 第一次脈衝焊接和第二次脈衝焊接間隔時間。運行時:間隔狀態同步點亮。參數查詢 :此燈亮,數碼管顯示當前設定的間隔時間值。參數設置:此燈亮,數碼管閃爍,通過編碼器修改當前值。
  8. 時間 - 第二次脈衝時間。運行時: 第二次脈衝同步點亮。參數查詢 :此燈亮,數碼管顯示當前設定的焊接時間值。參數設置:此燈亮,數碼管閃爍,通過編碼器修改當前值。
  9. 電流 - 第二次脈衝焊接電流。運行時: 脈衝同步點亮。參數查詢 :此燈亮,數碼管顯示當前設定的焊接電流值。參數設置:此燈亮,數碼管閃爍,通過編碼器修改當前值。
時間,1-100 個週波,一個週波 20ms。電流,300-999,步進值 0.1%。300-999 代表 30.0% - 99.9%。

DIY 点焊机教程

購買提示,40A 和 100A 都可以輕鬆點焊 0.15mm 及以下鍍鎳片。40A 和 100A的不同之處在於,40A 控制板配 16平方點焊筆,100A 控制板配 25平方點焊筆。100A 控制板可以後期擴展增加變壓器數量加大功率,40A 控制板則不行擴展。

四、焊接調試 -- 就是看焊接效果

接下來,進行焊接測試囉。將插頭插上 100V 巿電,可以清楚的看到數碼管顯示的時間和電流。NY-D01 控制板有兩個電位器,一個調節時間,一個調節電流,使用起來很方便。接下來就可以焊接了。個人建議,調試的時候,先將時間調節到 01,電流調節到 30,然後看看焊接效果。如果不行,逐漸增加電流,直到有明顯的火花出來,電流大小就可以了。如果焊接不牢,就適當的增加時間,時間建議每次增加一個週波。

下面是時間 02 / 電流 75 的焊接效果,亦即時間為 40ms,電流為 75%。


點焊機 DIY 制作提示單

點焊機 DIY 制作提示單,請大家自行對照改造。(非常重要,請先閱讀再製作)

1: 問: 為什麽上電後沒有觸發?

答: 點焊機控制板工作電源需要的是交流電,沒有觸發的,基本上都是用了直流電,而導致不觸發不工作。換了交流電源 (AC9V-AC12V 範圍內) 就可以啦。

2: 問: 為什麽焊不牢? 焊片一撕就掉? (注意以下四條都要符合才可以)

這個問題,分多個原因。1 答: 這個問題,分多個原因。下面一一講解,請對照一下自己是否存在這些問題。

A: 焊接變壓器功率不夠。大部分的 DIY朋友,都是用微波爐變壓器來改造的。首先,一個微波爐變壓器,(無論 800W 鋁 的還是 900E 銅的) 焊 0.15鍍鎳片和 0.1純鎳片是比較理想的。有的朋友想用一個微波爐變壓器來焊 0.2的鎳片,那就是比較困難了。所以,首先看下,自己的焊接變壓器功率是否夠。

B: 變壓器次級改造用線太細。改造次級,最少也要 25平方以上的電纜,而且需要那種細絲軟線 (紫銅材質最好),扒外皮做絕緣後再纏,纏四圈,次級電壓 3.5V左右的樣子。有的朋友次級用線太細,纏的圈數雖然多,電壓雖然高,但是卻限制了電流,導致焊接不上。所以,請對照電纜粗細,最少25平方以上 (說的是國標線哈,非標的不行的)。越粗效果越好呢。

C: 點焊筆過細過長。我們建議點焊筆越短越好,我們做的一般都是 50CM左右,同樣也是焊筆越粗效果越好。比如有的朋友用 16平方的線,長度一米,是焊不上了的呢。

D:變壓器是“水貨”嘍。近年DIY的興起,讓廢舊的微波爐變壓器一路走俏,有些不良商家也就打起了這個市場主意。親們觀察一下自己手裡的變壓器,有的雖然標稱 800W,但是厚度根本不夠。正常厚度應該在 77mm 左右,低於這個厚度的,功率都不夠,基本焊接厚度也就停留在 0.1mm 的鍍鎳焊片差不多,有的甚至連 0.1也焊不牢。

3: 問:我要焊18650電池,時間和電流參數設置多少?

答: 這個參數不是固定的,因為每個人 DIY 都是不一樣的。正常參數範圍應該是: D01 和 D03, D04款時間 05以內,電流 60以上,D02款電流 600以上,時間 05以內,並且第一個電流小於第二個電流,間隔時間同樣 05以內。時間盡量短,感覺火力不夠就調高電流,根據自己的情況進行調試,調試需要耐心,焊接需要多練習,大家都會焊出自己期望的漂亮焊點來。

4: 問: 關於散熱片,需不需要加?

答 :因為點焊機工作是瞬時工作,所以一般DIY自用的親們一般也不用加散熱片。也就是說散熱片不是必須的。當然如果想 加一片也是不錯的。關於散熱片也沒有規定必需的樣子,一般鋁散熱片就可以了。 

5: 問: 兩個微波爐變壓器如何改造?

答: 使用兩個微波爐變壓器的,建議選用兩個一模一樣的,初級並聯,次級串聯,一個兩圈,次級線越粗越好,最少50平方以 上。注意兩個變壓器,一定要使用 100A的控制板,41A的容易被擊穿呢。

NY-D01 單脈衝點焊機控制板

NY-D01 是單脈衝點焊機控制板。

以下擷錄自露天/淘寶網拍的說明,搜尋關鍵字 "NY-D01 點焊機控制板 調節時間電流數碼顯示單片機點焊機diy控制板"。

買前請充分了解點焊機基本原理和有關描述,比如交流電源也不懂的朋友,拍個板子回去接個路由器電源來責問怎么不能用?為什么買的時候不提醒一下?其實描述里都說了,只是個別朋友把插交流電上的 9V 12V 穩壓電源認為是交流電源了!那是交流電嘛?那是整流出來的直流電!DIY 也容易制作失敗和損壞板子,再者畢竟接觸的是 220V 交流強電,一不小心容易發生安全事故。無電子電工基礎知識的玩家一定勿拍!因為不懂也無法準確描述故障,出任何問題就說板子問題,比如曾有一個客戶點焊不穩,就臆想是板子的輸出電壓不穩,就去測變壓器的輸出電壓,顯示是一會兒大一會兒小的,但不想想數字表可以測脈沖電壓嘛?採樣 0.3秒的數字表可以去測 0.1-0.2秒的脈沖電壓?

自製點焊機很容易失敗(其實也不是失敗,就是達不到自己想象的效果而已),實質就是電流小唄,所以不是系統地去了解和學習,而學著其他朋友或憑自己想象隨便買了一堆東西是不一定做好的;強不強不是一個部件決定的,有人 900W 全銅也點不住 0.15mm 純鎳,有人 800W 鋁也能點 0.15 純鎳,這個能的知道變壓器是弱處,他繞組線就加強一下到 30平方,然后繞組線直接點焊針,不用快接座不用黃銅焊筆。

注意:售價 43元的控制板就是主圖中的裸板一塊,不含任何變壓器和其他配件!本板子是交流變壓器控制板,不能做法拉電容儲能的控制板!

      “NY-D01 單脈沖控制板 40A”就是板載 40A 可控硅;需要 100A 的就再拍一只 100A 可控硅,自己換一下,價格和出廠裝好 100A 的也差不多,自己換可以多下一只 40A 備用。

注意:41A 可控硅一般只能接一只微波爐變壓器,大約 700W-800W 初級鋁線,900E 全銅比較勉強,有時候會損壞,建議也換 100A,接 2只變壓器一定要換 100A 可控硅。其他環牛或其他未知參數變壓器一般也要 100A ,這樣保險一點。

        一直有客戶問這個 40A 可以多少電流去點焊?100A 可以多少電流?掌柜回答和點焊電流沒有直接關系,更不要理解為換 100A 會比 40A 的點焊電流大。可控硅大小主要是根據變壓器功率來選擇可控硅。可控硅可理解為家里的空氣開關(斷路器,閘刀)只負責開關而已,斷路器的電流根據負載功率而定。但不是換個大點的空氣開關會提高負載的功率!比如 40A 換 60A 的空氣開關,你家的 2匹空調也不可能會變成 3匹!但空調多了或換 5匹的了,你空氣開關肯定要換大的了!

      功率舉例:40A 可以接一個 900W 變壓器 (點焊時瞬間可以 2000W 左右),如果次級 2.5V,就可以 800A 的瞬間點焊電流,如果次級 5V,則是 400A 的電流,所以掌柜回答可控硅大小和點焊電流沒有直接關系就是這個道理,當然一般點焊電流大了,功率也大了,可控硅也需相應大了。

因為我們板子的響應非常快,假如您的腳法足夠快,連續踩 2次,可以等于雙脈沖點焊機,所以腳踏開關有腳踏開關的好處,用一體焊筆的微動開關的就難實現不了!用腳踏的好處是不影響手持焊筆的壓力,當你手腳協調好的情況下,其實還是手腳分離工作的好,人手是最靈活可控的,不同厚度鎳片和多種情況可以即時調整我們的手持壓力,一個固定壓力并不是完美的。

     本型號板子可以配有2種電流的可控硅,規格價格看選項。40A 和100A可控硅可相互直接替換,不用改變吸收RC大小。板子設計兼容 40A 和 100A。

    本板子的時間同步控制採用單片機的精密過零同步觸發,來保證每個輸出脈沖的同步度和精確個數,所以電流控制可以做在低壓的光耦前端,使用更安全。后面觸發電流兼容 40A和 100A管子,電流調節也不是傳統觸發電流的 RC,我們是直接控制的是脈沖寬度。

    以往市場較流行的控制板只是簡單通過調節 RC 單穩觸發電路的常數來控制時間,再通過一個光耦門來輸出周波,雖然在一定時間內可以大概控制多少個脈沖,但顯然不夠精確。而且 RC 調節里的 R是個高阻電位器,易收到自身脈沖大電流的干擾。使得每次點焊時間不穩定,所以也經常遇到有些朋友焊點忽大忽小的。更因為 555 時基電路觸發後復位需要等待時間的,連續腳踏觸發會引起時基誤差,所以設計者做了防誤觸發功能,實際就是讓頻繁的觸發失效,所以這些板子的觸發速度不會高于每秒 2次,一些點焊熟練點焊工和自動點焊機這個速度就不行了。

   掌柜做了個視頻對比,大家可以看 60秒的寶貝主圖視頻,我們的這個板子可以做到一秒 5-6 次以上的可靠觸發。而且是 1個 2個直至 50個脈沖的精密控制。

     國內廠家的幾十元 DIY 點焊機板子,更不可能去用日本阿爾卑斯電位器的,即使正規國產貨,壽命和 ALPS 相差甚遠,基本 1-2 年后就可能會有接觸不良,以前搞 DIY 音響的朋友特別明知,一會兒響一會兒低,還有很大的旋轉噪音。現在我們這個 N01 板子至少有個數顯,電位器調節的是壓控數字量,并不是直接延遲時間 RC 裡的 R,這點如同音響電路里的直流音量控制器,哪天電位器明顯接觸不良了,你還能知道數字的跳動;而沒有數顯的板子,哪天電位器接觸不良了,影響到焊接電流的忽大忽小,您可能也不知道~~

       目前較先進的交流脈沖點焊機控制板子有 2個關鍵要素,一個是過零觸發,第二個是精密周波數控制時間。所以我們的供電電源只能是交流輸入,不能直流電做電源的,直流電就實現不了過零觸發點了。而不是過零同步觸發的控制板,說是需要交流電供電,你給直流 9V電照樣工作的,就說明不是同步過零觸發板。

        注意:我們的板子可控硅部分的 RC 吸收是專為大多客戶的微波爐變壓器而優化設計的,在使用其他變壓器時,可能會發生抑制不完全而產生干擾影響正常工作,甚至損壞管子,所以更換到非微波爐變壓器時請有個心理準備。

安裝時:主板盡量離大變壓器遠一點!更不能座在變壓器上!因為大變壓器有強大的電磁干擾!

2023年12月7日 星期四

紅米2 手機安裝 Klipper

 紅米2手機 xiaomi redmi 2 

HM2LTE-sa

作業系統與版本 Android 4.4

處理器品牌 Qualcomm

處理器型號 Snapdragon 410

主螢幕尺寸 4.7 inch

主相機畫素 800 萬畫素

RAM記憶體 1 GB

ROM儲存空間 8 GB

電池容量 2200 mAh


Basically, in old Redmi devices, the bootloader is usually unlocked, unlike the new Redmi devices. So you just need to flash the TWRP or CWM zip file into the system replacing the stock recovery of Xiaomi.


參考 https://quickfever.com/root-redmi-2-without-pc/,完全不用 unlock bootloader,只要安裝 root 軟體即可 root。

  • 下載 Redmi2Root.zip
  • [系統工具] > [系統更新] > [...] > [手動選擇安裝檔案]
  • The new Root zip auto installs the SuperSu app on your phone, so any app will ask for root permission and you need to allow them to give root access.


主要參考這個 gaifeng8864 / klipper-on-android 

1. 安裝 kerneladiutor

高通处理器默认有个MPD功耗控制方案,默认情况下会关闭部分CPU核心来控制功耗。 由此带来的最大的问题就是在debian系统里会发现4核心的处理器大多数情况下却只识别出2个核心。 kerneladiutor是简单好用的安卓系统的内核管理软件,用来调整CPU和GPU的频率和性能。可以强制开启所有CPU核心,充分利用手机的性能。


2. 安裝 Linux Deploy,Android 版本較舊,只能安裝較舊的 2.5.1。參考說明,安裝 Debian / oldstable。

要把 print3d 加入 group,不然無法存取網路

 sudo usermod -a -G aid_inet,aid_net_raw print3d

因為紅米2 的儲存空間只有 8GB,系統使用後,剩餘空間只有 2GB 左右。不夠裝 Klipper,必須使用 SD卡。但 SD卡必須使用 ext4 的格式,不然無法安裝成功。但 ext4 格式,Android 的檔案管理無法存取,所以將 32GB 的 SD卡切割成雨部份, FAT32 的 12GB,其餘的 ext4。 

[GUIDE] How to mount ext4 formatted MicroSD card on Android 4.2.2 Phone/Tablet

[Linux Deploy]将linux安装在sd卡区的注意事项

使用 Terminal Emulator,cat /proc/partitions 列出 sd card 的分割區名稱,例如 mmcblk1p2。則在 Linux Deploy 中,Installation type --> Partition,Installation path --> /dev/block/mmcblk1p2。

裝好 klipper,moonraker,fluidd,KlipperScreen 这4个组件後,使用空間約 4GB。裝好後,print3d 的目錄如下。





2023年12月3日 星期日

MKS Monster8 setup


You can then hold reset (blue box), hold boot0 (labled above the blue box) and release reset followed by boot0 to enter DFU mode.

------------------
$ lsusb
Bus 005 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 003: ID 0483:df11 STMicroelectronics STM Device in DFU Mode
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
------------------


------------------
$ make flash FLASH_DEVICE=0483:df11
  Flashing out/klipper.bin to 0483:df11
sudo dfu-util -d ,0483:df11 -R -a 0 -s 0x800c000:leave -D out/klipper.bin

[sudo] password for mks: 
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash  "
Downloading to address = 0x0800c000, size = 26540
Download [=========================] 100%        26540 bytes
Download done.
File downloaded successfully
Transitioning to dfuMANIFEST state
dfu-util: can't detach
Resetting USB to switch back to runtime mode
-------------------

 

-----------------------
[  555.931877] usb 3-1: USB disconnect, device number 2
[  559.147501] usb 3-1: new full-speed USB device number 3 using ohci-platform
[  559.380615] usb 3-1: New USB device found, idVendor=0483, idProduct=df11, bcdDevice=22.00
[  559.380661] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  559.380684] usb 3-1: Product: STM32  BOOTLOADER
[  559.380703] usb 3-1: Manufacturer: STMicroelectronics
[  559.380722] usb 3-1: SerialNumber: 206E327F5131
[ 1296.862092] usb 3-1: USB disconnect, device number 3
[ 1297.345378] usb 3-1: new full-speed USB device number 4 using ohci-platform
[ 1297.579565] usb 3-1: New USB device found, idVendor=1d50, idProduct=614e, bcdDevice= 1.00
[ 1297.579585] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1297.579593] usb 3-1: Product: stm32f407xx
[ 1297.579599] usb 3-1: Manufacturer: Klipper
[ 1297.579605] usb 3-1: SerialNumber: 3E003B000C50315141323320
[ 1297.585773] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[ 1362.504573] usb 3-1: USB disconnect, device number 4
[ 1364.860800] usb 3-1: new full-speed USB device number 5 using ohci-platform
[ 1365.095898] usb 3-1: New USB device found, idVendor=1d50, idProduct=614e, bcdDevice= 1.00
[ 1365.095932] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1365.095948] usb 3-1: Product: stm32f407xx
[ 1365.095960] usb 3-1: Manufacturer: Klipper
[ 1365.095973] usb 3-1: SerialNumber: 3E003B000C50315141323320
[ 1365.100273] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
------------------------





2023年11月29日 星期三

Gentoo 安裝 -- 2023

 ** 切記,裝好 kernel 和 grub 後,重開機前,一定要記得更改 root 的密碼。

從 1994 左右開始,自己的桌機,就一直是安裝 Gentoo Linux,至今快 20年了。這 20年中,硬體的效能進步好幾十倍,以前完全裝好要兩三天至一個星期,現在縮短到一兩天左右。

使用 Gentoo 的特點,每個 package 都要自行編譯後,才安裝,要花很多時間。這樣做有沒有必要呢? 到後來變成單純是樂趣吧,且可以透過它在編譯的過程中,學到許多 Linux 和 Open source 的作法,在效能上並不會有太大的影響。這次 (2023年 12月) 安裝,最顯著的差異是有所謂的 Distribution Kernel,不用自己設定 kernel 的選項。自己設定 kernel,常常會設定不正確,無法開機,或某些應用程式無法安裝或使用。

首先,要找個可開機的系統來進行安裝。例如使用 Ubuntu,在進入圖形的環境下,可以一邊上網看安裝指引,一邊進行安裝。

安裝前,要先規畫安裝 Gentoo Linux 的硬碟分割。以下是目前自己在用的系統,硬碟的使用情形。

# df -h
檔案系統             容量   已用  可用  已用% 掛載點
/dev/root           98G   48G   46G   52% / 
/dev/nvme1n1p4     354G  167G  169G   50% /home

使用 500GB PCIe SSD 的分割情形 

                               Disk: /dev/nvme0n1
             Size: 477 GiB, 512110190592 bytes, 1000215216 sectors
          Label: gpt, identifier: FEA1EFAE-49CD-45B9-A15B-5A5EF9069055

    所用裝置              Start        結束       磁區    Size 類型
    /dev/nvme0n1p1         2048        6143       4096      2M BIOS boot        
    /dev/nvme0n1p2         6144      313343     307200    150M EFI System
    /dev/nvme0n1p3       313344    21284863   20971520     10G Linux swap
    /dev/nvme0n1p4     21284864   231000063  209715200    100G Linux filesystem
    /dev/nvme0n1p5    231000064  1000215182  769215119  366.8G Linux filesystem

目前大部份的 Linux 都使用 systemd,使用  "eselect profile" 選擇 profile 時,可以只選擇 "systemd",儘快裝好一個空的系統,確認可以重新開機。merged-usr,是指 bin, lib, lib64, sbin 等目錄都和 usr 下的目錄合併,不再分開。

雖然現在的 SSD 很快,如 nvme ssd 更是快,但和 DRAM 比起來,仍然比較慢。為了提昇 emerge 套件的速度,並且避免頻繁寫入 SSD,在記憶體也夠大時,在安裝過程可以使用 tmpfs 。emerge 過程,檔案是放在 /var/tmp/portage 的目錄下,在 chroot 中,需手動 mount tmpfs,指令如下。注意,tmpfs 的大小,一般不宜超過一半的記憶體。

# mount -t tmpfs -o size=4G,uid=portage,gid=portage,mode=755 /var/tmp/portage
有時,要暫時修改 tmpfs 的大小,可以執行下面的指令。
# mount -o remount,size=4G,noatime /tmp

在圖形界面,目前都用 lightdm 登入,並且在 USE flags 加上 "cjk",讓它支援中文。這時候,大概得等到裝好一個輕量級的 Xfce 桌面,才能比較方便的使用新裝好的 OS。這過程,大概要一天吧,還是先用 Ubuntu,進 chroot 繼續後面的安裝步驟,直到有 xfce 可用。

在開機前,要裝好 grub,編好 kernel,更改管理者密碼。常常忘了設定管理者密碼,又要重新 chroot 一次,設定密碼。

更改 host name 的方式如下,便於分辨在那台機器上。

hostnamectl set-hostname aj-i9

裝好的系統,可以在 /etc/fstab 中,加上 tmpfs 的掛載,可以自行參考網路資料。https://wiki.gentoo.org/wiki/Portage_TMPDIR_on_tmpfs

可以安裝 app-portage/cpuid2cpuflags,來偵測 CPU_FLAGS_X86 flags,然後將其加入 /etc/portage/make.conf 中。

在 /etc/portage/make.conf 中,我會加的設定。
ABI_X86="64 32";同時支援 64位元和32位元的程式庫,因為我會用 32 位元的 WINE。
GRUB_PLATFORMS="efi-64 pc";grub 同時安裝 efi 和 dos。

LINGUAS="zh_TW";中文的環境
L10N="zh-TW zh-CN"

INPUT_DEVICES="evdev keyboard mouse";X window 的設定
VIDEO_CARDS="vesa nouveau nv"
ALSA_CARDS="hda-intel"

設定時區

# echo "Asia/Taipei" > /etc/timezone
# emerge --config sys-libs/timezone-data
再來,修改 /etc/locale.gen,然後執行 locale-gen,產生 locale。
en_US ISO-8859-1
en_US.UTF-8 UTF-8
 zh_TW.UTF-8 UTF-8

zh_TW BIG5
zh_CN.UTF-8 UTF-8
zh_CN GB2312

IP 設定

注意,要先執行 systemd-machine-id-setup,建立 machine ID,journal 才會正常運作,service 才會正常起動,網路也才會起來。

建立檔案 /etc/systemd/network/50-wired.network

[Match]
Name=eno1
[Network]
Address=10.61.86.133/20
Gateway=10.61.80.1

[Address]
Label=eno1:1
Address=10.161.86.133/20
DHCP
[Match]
Name=enp*

[Network]
DHCP=yes

然後,設定服務
systemctl enable systemd-networkd.service
systemctl start systemd-networkd.service

Note that systemd-networkd does not update resolv.conf by default. To have systemd manage the DNS settings, replace resolv.conf with a symlink and start systemd-resolved.

ln -snf /run/systemd/resolve/resolv.conf /etc/resolv.conf
systemctl enable systemd-resolved.service
systemctl start systemd-resolved.service 

設定時區 (使用 systemd)
# timedatectl set-timezone Asia/Taipei
# timedatectl set-ntp yes
# timedatectl set-local-rtc no


大概就這些吧。

手動設定 IP:
ip addr add 10.1.1.2/16 dev eth1
ip link set eth1 up

安裝 kernel 及設置 grub2

先安裝 sys-kernel/gentoo-kernel-bin,可以很快的裝系統重新開機。假如要重裝 sys-kernel/gentoo-kernel,必須要先 emerge -W gentoo-kernel-bin,再 emerge -av gentoo-kernel。這樣會先移除 gentoo-kernel-bin,因為兩者不能同時安裝。

 * Messages for package sys-kernel/gentoo-kernel-6.1.60:

 * Your configuration for sys-kernel/gentoo-kernel-6.1.60 has been saved in 
 * "/etc/portage/savedconfig/sys-kernel/gentoo-kernel-6.1.60" for your editing pleasure.
 * You can edit these files by hand and remerge this package with
 * USE=savedconfig to customise the configuration.
 * You can rename this file/directory to one of the following for
 * its configuration to apply to multiple versions:
 * ${PORTAGE_CONFIGROOT}/etc/portage/savedconfig/
 * [${CTARGET}|${CHOST}|""]/${CATEGORY}/[${PF}|${P}|${PN}]


grub,參考 https://wiki.centos.org/zh-tw/HowTos/Grub2

使用 BIOS 時,執行 grub-install --target=i386-pc /dev/nvme0n1 安裝 bootloader。使用 EFI 的話,有點小複雜,就先不折騰了。

產生選單前,可以設定 /etc/default/grub,我習慣的設定如下。

# 預設的開機,儲存在 /boot/grub/grubenv 中的 saved_entry
GRUB_DEFAULT=saved
# 顯示全部的開機選項
GRUB_DISABLE_SUBMENU=y
# 不要建立復原開機選項
GRUB_DISABLE_RECOVERY="true"
# Boot with systemd instead of sysvinit (openrc)
GRUB_CMDLINE_LINUX="init=/usr/lib/systemd/systemd"

其中,GRUB_CMDLINE_LINUX 那一行一定要設,不然使用 lightdm 登入 xfce 後,會不正常。

在 kernel 建好之後,直接下 make install 指令,即可將 kernel 的 image複製到 /boot 下。執行指令 grub-mkconfig -o /boot/grub/grub.cfg,建立開機選單。

注意,假如是把硬碟拔到別的電腦上 install 或 update,一定要在使用的機器上執行此指令,才能建立正確的 grub.cgf,不然會抓到不正確的硬碟資訊,重新開機時,會無法 mount root disk。

執行 awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub/grub.cfg,列出開機時顯示的選單列表。
0 : Gentoo GNU/Linux,採用 Linux 4.9.16-gentoo
1 : Gentoo GNU/Linux,採用 Linux 4.9.16-gentoo.old
2 : Gentoo GNU/Linux,採用 Linux 4.4.52-gentoo.good
3 : Gentoo GNU/Linux,採用 Linux 4.4.52-gentoo
4 : Gentoo GNU/Linux,採用 Linux 4.4.52-gentoo.old

執行 grub-set-default 3,設定預設開機選項為 3。
執行 grub-editenv list,顯示儲存的設定如下
saved_entry=3

假如是升級 kernel,在使用 eselect 設定新的 kernel 後,要重新安裝相關的 package,不然會進不了圖形界面和 VM。

emerge -av x11-drivers/nvidia-drivers app-emulation/vmware-modules

其他安裝

確定可以正常開機後,先裝個基本的圖形介面,emerge -av xorg-server xterm twm,就可以進入 X window。這樣,只需幾個小時,就有視窗可用了,然後再裝其他的 package。

若是已有可用的視窗系統,就不用急,把所有的東西都裝好,再切換過去。

常用小工具

xfce4-notes-plugin
The notes are stored as text files in $XDG_DATA_HOME/notes/ (~/.local/share/notes by default).
The settings are in $XDG_CONFIG_HOME/xfce4 (~/.config/xfce4/xfce4-notes.*).
xfce4-clipman-plugin, 要安裝 x11-themes/gnome-icon-theme, 才會出現圖示

x11-themes/gnome-icon-theme 的 icon,還被一些應用程式使用,如 smb4k 及 krusader 等,不能隨便移除。

修改 tmpfs 的大小

How to change tmpfs partition size in Linux ( RHEL / CentOS 7 )

原來的 tmpfs 大小,把 RAM 都吃光了,要調小一點。
----------------
檔案系統        容量  已用  可用 已用% 掛載點
/dev/root        98G   28G   66G   30% /
devtmpfs        5.8G     0  5.8G    0% /dev
tmpfs           5.8G  507M  5.3G    9% /dev/shm
tmpfs           5.8G  1.2M  5.8G    1% /run
tmpfs           5.8G     0  5.8G    0% /sys/fs/cgroup
tmpfs           5.8G  140K  5.8G    1% /tmp
/dev/nvme0n1p5  361G   53G  290G   16% /home
none            4.0G     0  4.0G    0% /var/tmp/portage
tmpfs           1.2G   28K  1.2G    1% /run/user/1000
----------------

在 /etc/fstab 加入
tmpfs /tmp tmpfs rw,nosuid,noatime,nodev,size=4G,mode=1777 0 0

然後下指令
mount -o remount /tmp

LightDM 無法啟動

Create a new file called nvidia.conf in the /etc/modules-load.d directory. It should contain the NVIDIA module name:

FILE /etc/modules-load.d/nvidia.conf
nvidia
nvidia_modeset
nvidia_drm
確保在啟動 lightdm 之前,載入 nvidia_drm 的 kernel module

連接網芳

使用 gvfs,可在 Thunar 使用 "smb://servername/share" 來連接網芳的分享磁碟。

修改 /etc/samba/smb.conf,才能連 Windows 2003 ~ 2019 的網芳,不然會出現 "Failed to mount Windows share" 的訊息

----------------------------------------
  client min protocol=NT1
  client max protocol=SMB3
  ntlm auth = yes
----------------------------------------

在安裝 gnome-base/gvfs,use flag 要加上 fuse (Enables fuse mount points in $HOME/.gvfs for legacy application access)。Gentoo 則是放在 $XDG_RUNTIME_DIR/gvfs 的目錄下,其中 XDG_RUNTIME_DIR=/run/user/1000。

------------------------------------------------
 $ ls /run/user/1000/gvfs
'smb-share:server=10.161.86.149,share=wwwroot'
------------------------------------------------

音效

必須以普通使用者的身份,啟動 pulseaudio.service。控制界面,需安裝 media-sound/pavucontrol (Pulseaudio Volume Control, GTK based mixer for Pulseaudio)。

$ systemctl --user start pulseaudio
$ systemctl --user status pulseaudio

$ systemctl --user enable pulseaudio
Created symlink /home/ajax/.config/systemd/user/default.target.wants/pulseaudio.service → /usr/lib/systemd/user/pulseaudio.service.
Created symlink /home/ajax/.config/systemd/user/sockets.target.wants/pulseaudio.socket → /usr/lib/systemd/user/pulseaudio.socket.

VMware-Workstation

gentoo ~ # emerge --config vmware-workstation


Configuring pkg...

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.12/emerge", line 57, in main
    retval = emerge_main()
             ^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/_emerge/main.py", line 1308, in emerge_main
    return run_action(emerge_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/_emerge/actions.py", line 3876, in run_action
    return action_config(
           ^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/_emerge/actions.py", line 758, in action_config
    retval = portage.doebuild(
             ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/portage/package/ebuild/doebuild.py", line 1218, in doebuild
    rval = _prepare_env_file(mysettings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/portage/package/ebuild/doebuild.py", line 1686, in _prepare_env_file
    env_extractor.start()
  File "/usr/lib/python3.12/site-packages/_emerge/AsynchronousTask.py", line 34, in start
    self._start()
  File "/usr/lib/python3.12/site-packages/_emerge/BinpkgEnvExtractor.py", line 43, in _start
    env=self.settings.environ(),
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/portage/package/ebuild/config.py", line 3378, in environ
    raise AssertionError(
AssertionError: LC_ALL=zh_TW.UTF-8 for posixish locale. It seems that split_LC_ALL was not called for phase config?
gentoo ~ # unset LC_ALL
gentoo ~ # emerge --config vmware-workstation


Configuring pkg...

Network settings database seems to be invalid,configuring default settings
Configuring Bridged network vmnet0
Configuring hostonly network vmnet1, probing for unused subnet ...
Configuring NAT network vmnet8, probing for unused subnet ...
Configured default networks - Bridged, Hostonly, NAT

gentoo ~ # 


V




2023年10月26日 星期四

Klipper -- 加裝蜂鳴器

 參考 

蜂鳴器的種類

蜂鳴器分成電磁式與壓電式 (piezo buzzer)。電磁式蜂鳴器的工作電壓為 1.5V ~ 24V,壓電式蜂鳴器的工作電壓範圍比較廣,為 1V ~ 220V。因此要使用大於 24V的電壓,那就只能選擇壓電式蜂鳴器。但如果工作電壓較小,則建議使用電磁式蜂鳴器,因為壓電式蜂鳴器一般要使用 9V以上的電壓聲音才會比較大。

電磁式蜂鳴器的耗電流從 10mA ~ 150mA 都有,而壓電式蜂鳴器的耗電流大部分都在 10mA以下,且在蜂鳴器啟動時的瞬間,需消耗約三倍的電流,因此如果有省電或是攜帶型產品的需求,建議使用較省電的壓電式蜂鳴器。

前面所說的消耗電流是指輸出為交流的音頻時,以直流來看,電磁式喇叭的直流阻抗非常低,只有 4Ω ~ 16Ω,對直流幾乎等同短路。因此若選用電磁式喇叭,必須要注意沒有輸出時,輸出電壓必須為 0V,不然,不小心會把 MCU 控制板燒壞。我的經驗較幸運些,連接在風扇的端子,電壓選 5V,config 中將開機時誤設為 1。只是開不了機,沒有燒掉板子,喇叭的溫度高到燙手。

壓電式蜂鳴器則類似於電容,使用上較為安全,但輸出電壓要高一些,例如 24V,聲音才夠響。

另外,還有分有源蜂鳴器和無源蜂鳴器。有源,是只裡面有振盪源,接上直流電就會響,使用方便,缺點是無法控制頻率。

這是一個有源蜂鳴器,內部使用壓電式蜂鳴器。體積較大,聲音比較響,也比較好聽些。因為我想要控制頻率,手邊又沒有可用的壓電式蜂鳴器,就把線重焊,跳過電路板,當無源壓電式蜂鳴器使用。

設定

https://www.reddit.com/r/ender3/comments/n2fd1d/beeperbuzzer_pin/ ,網友的設定。

-------------
[output_pin BEEPER_pin]
pin: PB5
pwm: True         ; A piezo beeper needs a PWM signal, a DC buzzer doesn't.
value: 0          ; Silent at power on, set to 1 if active low.
shutdown_value: 0 ; Disable at emergency shutdown
cycle_time: 0.001 ; PWM frequency : 0.001 = 1ms will give a base tone of 1kHz
scale: 4000       ; PWM parameter will be in the range of (0-4000 Hz).
#enable beeper on printer

[gcode_macro M300]
default_parameter_S: 1000
default_parameter_P: 100
gcode:
    SET_PIN PIN=BEEPER_pin VALUE={S}
    G4 P{P}
    SET_PIN PIN=BEEPER_pin VALUE={S}
#Custom M300 code to allow beeper to be used in gcode

[gcode_macro end_tune]
gcode:
    M300 S3135 P75
    M300 S3135 P150
    M300 S1760 P150
    M300 S1760 P150
    M300 S2637 P150
    M300 S2637 P150
    M300 S3135 P150
-------------

https://github.com/jschuh/klipper-macros,較為完整的設定

--------------
[output_pin beeper]
pin: PC5 # Beeper pin. This parameter must be provided.
pwm: True # A piezo beeper needs a PWM signal, a DC buzzer doesn't.
#pwm: false
#scale: 2
value: 1 # Silent at power on, set to 1 if active low.
shutdown_value: 0

[gcode_macro m300]
description: Emits and audible beep.
  Usage: M300 [P<duration>] [S<frequency>]
gcode:
  {% set settings = printer.configfile.settings %}
  {% if "output_pin beeper" in printer %}
    {% set P = (params.P|default(100)|int, 0)|max %}
    {% set S = (params.S|default(1000)|int, 1)|max %}
    SET_PIN PIN=beeper VALUE={% if settings["output_pin beeper"].pwm %}{
        settings["output_pin beeper"].scale|default(1.0) * 0.5
      } CYCLE_TIME={ 1.0 / S }{% else %}1{% endif %}
    G4 P{P}
    SET_PIN PIN=beeper VALUE=0
  {% else %}
    {action_respond_info(
       "M300 is disabled. To enable create an [output_pin beeper] config.")}
  {% endif %}
--------------

test: SET_PIN PIN=beeper VALUE=0.5 CYCLE_TIME=0.0003

command: M300 P1000 S1000

3D Printer Ringtones | Improve your 3D Printer workflow with sound! | M300,建立 midi 的聲調

  • MIDI Files on bitmidi,https://bitmidi.com/
  • MIDI to M300,https://www.layerfused.com/MIDI-M300
  • Alex Yu's great MIDI to M300 converter,https://github.com/alexyu132/midi-m300
  • MIDI極短音效特選集,http://shells.tw/~bill/midi/midi_s/midi_s.htm

midi 檔案播放

可以用 VLC 軟體,搭配 fluidsynth,但需要 SoundFont 檔 (副檔名為 .sf2),可至 https://github.com/FluidSynth/fluidsynth/wiki/SoundFont 找到相關下載。


------------------
G28 W ; home all without mesh bed level
; start melody
M300 S294 P220 ;N1 D4 1/8
M300 S20000 P20
M300 S311 P220 ;N2 D#4 1/8
M300 S20000 P20
M300 S330 P220 ;N3 E4 1/8
M300 S20000 P20
M300 S523 P460 ;N4 C5 1/4
M300 S20000 P20
M300 S330 P220 ;N5 E4 1/8
M300 S20000 P20
M300 S523 P230 ;N6 C5 1/8
M300 S20000 P10
M300 S330 P220 ;N7 E4 1/8
M300 S20000 P20
M300 S523 P230 ;N8 C5 1/8
M300 S20000 P10
M300 S523 P950 ;N9 C5 1/2
M300 S20000 P10
M300 S523 P220 ;N10 C5 1/8
M300 S20000 P20
M300 S523 P220 ;N11 C5 1/8
M300 S20000 P20
M300 S587 P220 ;N12 D5 1/8
M300 S20000 P20
M300 S622 P220 ;N13 D#5 1/8
M300 S20000 P20
M300 S659 P220 ;N14 E5 1/8
M300 S20000 P20
M300 S523 P220 ;N15 C5 1/8
M300 S20000 P20
M300 S587 P220 ;N16 D5 1/8
M300 S20000 P20
M300 S659 P230 ;N17 E5 1/8
M300 S20000 P10
M300 S659 P230 ;N11 E5 1/8
M300 S20000 P10
M300 S494 P220 ;N19 B4 1/8
M300 S20000 P20
M300 S587 P460 ;N20 D5 1/2
M300 S20000 P20
M300 S523 P1420; C5 1/2+1/4
M300 S20000 P20
M300 S20000 P1920; pause one measure
G1 X0 Y200 Z30; home X axis
M84 ; disable motors
--------------------


2023年10月15日 星期日

新購 ACASIS HS-710PB USB 3.0 12V 4A電源10口分線器

目前手邊在用的 7 port USB Hub,價格只要幾百元,當初是挑最便宜的。雖然聲稱是 USB 3.0 的規格,但 Linux 系統抓到的是 USB 2.0 HUB,而且常常會出問題,因此想換一個。原本只想換一樣 7 port 的就好,後來不小心看到有 16 port 的,但價格不低,就不要太貪心,先買 10 port 的吧。

網拍產品的標題為「 ACASIS HS-710PB USB 3.0 12V 4A電源10口分線器」,價格 NT$ 1,290。附一個 12V/4A 的電源供應器,有些較便宜的,電源供應器是 12V/2A 的。


好奇它是如何加到十個 port 的,使用 Linux 的 dmesg 看到的訊息如下。

----------------------------
[326717.201917] usb 1-8: new high-speed USB device number 44 using xhci_hcd
[326717.340618] usb 1-8: New USB device found, idVendor=0bda, idProduct=5411, bcdDevice= 2.02
[326717.340641] usb 1-8: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[326717.340652] usb 1-8: Product: USB2.1 Hub
[326717.340661] usb 1-8: Manufacturer: Generic
[326717.343176] hub 1-8:1.0: USB hub found
[326717.344225] hub 1-8:1.0: 4 ports detected
[326717.449440] usb 2-7: new SuperSpeed USB device number 2 using xhci_hcd
[326717.473282] usb 2-7: New USB device found, idVendor=0bda, idProduct=0411, bcdDevice= 2.02
[326717.473285] usb 2-7: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[326717.473286] usb 2-7: Product: USB3.2 Hub
[326717.473287] usb 2-7: Manufacturer: Generic
[326717.477616] hub 2-7:1.0: USB hub found
[326717.479084] hub 2-7:1.0: 4 ports detected
[326717.628960] usb 1-8.3: new high-speed USB device number 45 using xhci_hcd
[326717.728606] usb 1-8.3: New USB device found, idVendor=0bda, idProduct=5411, bcdDevice= 2.02
[326717.728614] usb 1-8.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[326717.728616] usb 1-8.3: Product: USB2.1 Hub
[326717.728618] usb 1-8.3: Manufacturer: Generic
[326717.730150] hub 1-8.3:1.0: USB hub found
[326717.731026] hub 1-8.3:1.0: 4 ports detected
[326717.791436] usb 2-7.3: new SuperSpeed USB device number 3 using xhci_hcd
[326717.813658] usb 2-7.3: New USB device found, idVendor=0bda, idProduct=0411, bcdDevice= 2.02
[326717.813661] usb 2-7.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[326717.813663] usb 2-7.3: Product: USB3.2 Hub
[326717.813664] usb 2-7.3: Manufacturer: Generic
[326717.818918] hub 2-7.3:1.0: USB hub found
[326717.820424] hub 2-7.3:1.0: 4 ports detected
[326717.884909] usb 1-8.4: new high-speed USB device number 46 using xhci_hcd
[326717.984578] usb 1-8.4: New USB device found, idVendor=0bda, idProduct=5411, bcdDevice= 2.02
[326717.984596] usb 1-8.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[326717.984602] usb 1-8.4: Product: USB2.1 Hub
[326717.984608] usb 1-8.4: Manufacturer: Generic
[326717.986572] hub 1-8.4:1.0: USB hub found
[326717.987505] hub 1-8.4:1.0: 4 ports detected
[326718.049471] usb 2-7.4: new SuperSpeed USB device number 4 using xhci_hcd
[326718.071675] usb 2-7.4: New USB device found, idVendor=0bda, idProduct=0411, bcdDevice= 2.02
[326718.071694] usb 2-7.4: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[326718.071702] usb 2-7.4: Product: USB3.2 Hub
[326718.071708] usb 2-7.4: Manufacturer: Generic
[326718.076772] hub 2-7.4:1.0: USB hub found
[326718.078548] hub 2-7.4:1.0: 4 ports detected
----------------------------

使用 lsusb 查看 USB 裝置。

----------------------------
Bus 002 Device 010: ID 0bda:0411 Realtek Semiconductor Corp. Hub
Bus 002 Device 009: ID 0bda:0411 Realtek Semiconductor Corp. Hub
Bus 002 Device 008: ID 0bda:0411 Realtek Semiconductor Corp. Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 064: ID 262a:100d SAVITECH Corp. FiiO USB DAC Q1
Bus 001 Device 063: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 001 Device 062: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 001 Device 061: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 065: ID feed:0000 Vial Magicforce 68 with Trackpoint
Bus 001 Device 059: ID 0bda:5411 Realtek Semiconductor Corp. RTS5411 Hub
Bus 001 Device 004: ID 0bda:0169 Realtek Semiconductor Corp. Mass Storage Device
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
----------------------------

使用的是 Realtek 瑞昱半導體的晶片,型號  RTS5411。這是一個 1-4 的 USB HUB 控制晶片,兩個晶片串接就可以得到 7埠的 HUB,三個串接就是這個 10埠的 HUB 了。

以下說明引用自知乎網站。

RTS5411 的一般说明

RTS5411是一个USB3.0 HUB控制器,集成了USB3.0&USB2.0收发器、MCU、SIE、稳压器、和充电电路。RTS5411向后兼容USB2.0,USB1.1规范,支持超速,高速,全速,低速操作。

RTS5411为每个下游端口提供电池充电功能。并且符合电池充电规范1.2,可为为各种手提设备充电。根据BC1.2规范,RTS5411不仅下游端口可以作为充电器,上游端口同样支持两个特别的功能。RTS5411上游端口第一个充电功能被叫做“ACA-dock”模式。支持ACA-dock的设备,它将作为各种外设的主机。然而,尽管处于ACA-dock模式,这个设备也能够同时被充电;RTS5411上游端口第二个充电功能被叫做“chaarger detection”功能。RTS5411可以识别插在上游端口的BC1.2充电器模式,包括CDP、DCP和SDP。RTS5411支持自动侦测开关机制,这样可以在合适的模式下,给手提设备充电。

RTS5411可以通过灵活的ISP通道用外部SPI flash更新固件。可以用外部的SPI flash或者EPROM配置大量特性和设置。仅使用USB线和RTS5411下载工具就可实现ISP功能。

RTS5411的特性和设置也可以通过SMBUS接口或者内部eFuse配置。


RTS5411可以通过各种接口和其他设备通信,例如GPIO,I2C,SMBUS。利用这些接口可以灵活拓展各种应用。


此外,RTS5411支持一个特别的节约电源功能,delink模式。即使RTS5411上游接口连接另外的主机或hub上,但是如果没有设备连接RTS5411,RTS5411进入delink模式,为系统节约电源。

RTS5411 的特性

这部分详见DATASHEET. 此处列出重要特性。

  • MTT(Multiple Transaction Translator)
    1. 每个下游端口有1个TT。
    2. 当多个下游端口全速并发时有更大的数据吞吐量。
  • 符合USB充电规范1.2版本和其他手持设备
    1. DCP模式模式。
    2. CDP模式。
    3. ACA-Dock功能。
    4. 为接在上游端口兼容BC1.2的充电器提供侦测功能。
    5. D+/D– Divider Modes 2.0V/2.7V, 2.7/2.0V and 2.7/2.7V。
    6. D+/D- 1.2V Mode.
  • RTS5411的上游端口可以侦测它所连的DSP是一个SDP、CDP或者DCP。当RTS5411连接到一个充电端口,它被允许从DSP吸收更多的电流。
  • 下游端口支持Gang mode和Individual mode。
  • 支持USB2.0 LPM-L1功能。
  • 支持USB3.0 U1/U2/U3省电模式。
  • 集成Fast 8051微处理器。
  • 支持12MHz晶体时钟。
  • 集成3.3V内部LDO输出,输入范围4.5V-5.5V。
  • 集成1.2V开关稳压器输出,输入范围3.0V-5.5V。
  • 支持Efuse配置功能或者例如non-removable port、gang mode等配置。
  • 支持“Delink”省电功能。
    1. 如果没有任何设备接在RTS5411的下游端口,RTS5411将断开自己和主机或者HUB的下游端口的连接,从而进一步实现省电功能。一旦有任何设备连接下游端口,上游端口将自动重新连接。



2023年10月12日 星期四

PS/2 Mouse/Keyboard Protocol

說明:為了使用 Trackpoint 控制器,將網路找到的 PS2 介紹文件備份在此,下面連結似為原文出處,但無法開啟。

http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/PS2/ps2.htm


PS/2 Mouse/Keyboard Protocol

This article is Copyright 1999, Adam Chapweske

Introduction:

The PS/2 device interface, used by many modern mice and keyboards, was developed by IBM and originally appeared in the IBM Technical Reference Manual.  However, this document has not been printed for many years and as far as I know, there is currently no official publication of this information.  I have not had access to the IBM Technical Reference Manual, so all information on this page comes from my own experiences as well as help from the references listed at the bottom of this page.

This document descibes the interface used by the PS/2 mouse, PS/2 keyboard, and AT keyboard.  I'll cover the physical and electrical interface, as well as the protocol.  If you need higher-level information, such as commands, data packet formats, or other information specific to the keyboard or mouse, I have written separate documents for the two devices:

The PS/2 (AT) Keyboard Interface
The PS/2 Mouse Interface
I also encourage you to check this site's main page for more information related to this topic, including projects, code, and links related to the mouse and keyboard.  Please send an email if you find any mistakes or bad advice on this site.

The Physical Interface:

The physical PS/2 port is one of two styles of connectors:  The 5-pin DIN or the 6-pin mini-DIN.  Both connectors are completely (electrically) similar; the only practical difference between the two is the arrangement of pins.  This means the two types of connectors can easily be changed with simple hard-wired adaptors.  These cost about $6 each or you can make your own by matching the pins on any two connectors.  The DIN standard was created by the German Standardization Organization (Deutsches Institut fuer Norm) .  Their website is at http://www.din.de (this site is in German, but most of their pages are also available in English.)

PC keyboards use either a 6-pin mini-DIN or a 5-pin DIN connector.  If your keyboard has a 6-pin mini-DIN and your computer has a 5-pin DIN (or visa versa), the two can be made compatible with the adaptors described above.  Keyboards with the 6-pin mini-DIN are often referred to as "PS/2" keyboards, while those with the 5-pin DIN are called "AT" devices ("XT" keyboards also used the 5-pin DIN, but they are quite old and haven't been made for many years.)  All modern keyboards built for the PC are either PS/2, AT, or USB.  This document does not apply to USB devices, which use a completely different interface.

Mice come in a number of shapes and sizes (and interfaces.)  The most popular type is probably the PS/2 mouse, with USB mice gaining popularity.  Just a few years ago, serial mice were also quite popular, but the computer industry is abandoning them in support of USB and PS/2 devices.  This document applies only to PS/2 mice.  If you want to interface a serial or USB mouse, there's plenty of information available elsewhere on the web.

The cable connecting the keyboard/mouse to the computer is usually about six feet long and consists of four to six 26 AWG wires surrounded by a thin layer of mylar foil sheilding.  If you need a longer cable, you can buy PS/2 extenstion cables from most consumer electronics stores.  You should not connect multiple extension cables together.  If you need a 30-foot keyboard cable, buy a 30-foot keyboard cable.  Do not simply connect five 6-foot cables together.  Doing so could result in poor communication between the keyboard/mouse and the host.

As a side note, there is one other type of connector you may run into on keyboards. While most keyboard cables are hard-wired to the keyboard, there are some whose cable is not permanently attached and come as a separate component.  These cables have a DIN connector on one end (the end that connects to the computer) and a SDL (Sheilded Data Link) connector on the keyboard end.  SDL was created by a company called "AMP."  This connector is somewhat similar to a telephone connector in that it has wires and springs rather than pins, and a clip holds it in place.  If you need more information on this connector, you might be able to find it on AMP's website at http://www.connect.amp.com.  I have only seen this type of connector on (old) XT keyboards, although there may be AT keyboards that also use the SDL.  Don't confuse the SDL connector with the USB connector--they probably both look similar in my diagram below, but they are actually very different.  Keep in mind that the SDL connector has springs and moving parts, while the USB connector does not.

The pinouts for each connector are shown below:
 

Male

(Plug)
Female 

(Socket)
5-pin DIN (AT/XT): 
1 - Clock
2 - Data
3 - Not Implemented
4 - Ground
5 - Vcc (+5V)


Male

(Plug)
Female

(Socket)
6-pin Mini-DIN (PS/2):
1 - Data
2 - Not Implemented
3 - Ground
4 - Vcc (+5V)
5 - Clock
6 - Not Implemented


 

6-pin SDL:
A - Not Implemented
B - Data
C - Ground
D - Clock
E - Vcc (+5V)
F - Not Implemented


The Electrical Interface:

Note:  Throughout this document, I will use the more general term "host" to refer to the computer--or whatever the keyboard/mouse is connected to-- and the term "device" will refer to the keyboard/mouse.

Vcc/Ground provide power to the keyboard/mouse.  The keyboard or mouse should not draw more than 100 mA from the host and care must be taken to avoid transient surges.  Such surges can be caused by "hot-plugging" a keyboard/mouse (ie, connect/disconnect the device while the computer's power is on.)  Older motherboards had a surface-mounted fuse protecting the keyboard and mouse ports.  When this fuse blew, the motherboard was useless to the consumer, and non-fixable to the average technician.  Most newer motherboards use auto-reset "Poly" fuses that go a long way to remedy this problem.  However, this is not a standard and there's still plenty of older motherboards in use.  Therefore, I recommend against hot-plugging a PS/2 mouse or keyboard.

Summary: Power Specifications
Vcc = +5V.  
Max Current = 100 mA.

The Data and Clock lines are both open-collector with pullup resistors to +5V.  An "open-collector" interface has two possible state: low, or high impedance.  In the "low" state, a transistor pulls the line to ground level.  In the "high impedance" state, the interface acts as an open circuit and doesn't drive the line low or high. Furthermore, a "pullup" resistor is connected between the bus and Vcc so the bus is pulled high if none of the devices on the bus are actively pulling it low.  The exact value of this resistor isn't too important (1~10 kOhms); larger resistances result in less power consumption and smaller resistances result in a faster rise time.  A general open-collector interface is shown below:

Figure 1: General open-collector interface.  Data and Clock are read on the microcontroller's pins A and B, respectively.  Both lines are normally held at +5V, but can be pulled to ground by asserting logic "1" on C and D.  As a result, Data equals D, inverted, and Clock equals C, inverted.


Note: When looking through examples on this website, you'll notice I use a few tricks when implementing an open-collector interface with PIC microcontrollers.  I use the same pin for both input and output, and I enable the PIC's internal pullup resistors rather than using external resistors.  A line is pulled to ground by setting the corresponding pin to output, and writing a "zero" to that port.  The line is set to the "high impedance" state by setting the pin to input.  Taking into account the PIC's built-in protection diodes and sufficient current sinking, I think this is a valid configuration.  Let me know if your experiences have proved otherwise.

Communication: General Description

The PS/2 mouse and keyboard implement a bidirectional synchronous serial protocol.  The bus is "idle" when both lines are high (open-collector).  This is the only state where the keyboard/mouse is allowed begin transmitting data.  The host has ultimate control over the bus and may inhibit communication at any time by pulling the Clock line low.  

The device always generates the clock signal.  If the host wants to send data, it must first inhibit communication from the device by pulling Clock low.  The host then pulls Data low and releases Clock.  This is the "Request-to-Send" state and signals the device to start generating clock pulses.

Summary: Bus States
Data = high, Clock = high:  Idle state.
Data = high, Clock = low:  Communication Inhibited.
Data = low, Clock = high:  Host Request-to-Send

  All data is transmitted one byte at a time and each byte is sent in a frame consisting of 11-12 bits.  These bits are:
  • 1 start bit.  This is always 0.
  • 8 data bits, least significant bit first.
  • 1 parity bit (odd parity).
  • 1 stop bit.  This is always 1.
  • 1 acknowledge bit (host-to-device communication only)

The parity bit is set if there is an even number of 1's in the data bits and reset (0) if there is an odd number of 1's in the data bits.  The number of 1's in the data bits plus the parity bit always add up to an odd number (odd parity.)  This is used for error detection.  The keyboard/mouse must check this bit and if incorrect it should respond as if it had received an invalid command.

Data sent from the device to the host is read on the falling edge of the clock signal; data sent from the host to the device is read on the rising edge.  The clock frequency must be in the range 10 - 16.7 kHz.  This means clock must be high for 30 - 50 microseconds and low for 30 - 50 microseconds..  If you're designing a keyboard, mouse, or host emulator, you should modify/sample the Data line in the middle of each cell.  I.e.  15 - 25 microseconds after the appropriate clock transition.  Again, the keyboard/mouse always generates the clock signal, but the host always has ultimate control over communication.

Timing is absolutely crucial.  Every time quantity I give in this article must be followed exactly.

Communication: Device-to-Host

The Data and Clock lines are both open collector.  A resistor is connected between each line and +5V, so the idle state of the bus is high. When the keyboard or mouse wants to send information, it first checks the Clock line to make sure it's at a high logic level.  If it's not, the host is inhibiting communication and the device must buffer any to-be-sent data until the host releases Clock.  The Clock line must be continuously high for at least 50 microseconds before the device can begin to transmit its data. 

As I mentioned in the previous section, the keyboard and mouse use a serial protocol with 11-bit frames.  These bits are:

  • 1 start bit.  This is always 0.
  • 8 data bits, least significant bit first.
  • 1 parity bit (odd parity).
  • 1 stop bit.  This is always 1.
The keyboard/mouse writes a bit on the Data line when Clock is high, and it is read by the host when Clock is low.  Figures 2 and 3 illustrate this.

Figure 2:  Device-to-host communication.  The Data line changes state when Clock is high and that data is valid when Clock is low.

Figure 3:  Scan code for the "Q" key (15h) being sent from a keyboard to the computer.  Channel A is the Clock signal; channel B is the Data signal.

The clock frequency is 10-16.7 kHz.  The time from the rising edge of a clock pulse to a Data transition must be at least 5 microseconds.  The time from a data transition to the falling edge of a clock pulse must be at least 5 microseconds and no greater than 25 microseconds. 

The host may inhibit communication at any time by pulling the Clock line low for at least 100 microseconds.  If a transmission is inhibited before the 11th clock pulse, the device must abort the current transmission and prepare to retransmit the current "chunk" of data when host releases Clock.  A "chunk" of data could be a make code, break code, device ID, mouse movement packet, etc.  For example, if a keyboard is interrupted while sending the second byte of a two-byte break code, it will need to retransmit both bytes of that break code, not just the one that was interrupted.

If the host pulls clock low before the first high-to-low clock transition, or after the falling edge of the last clock pulse, the keyboard/mouse does not need to retransmit any data.  However, if new data is created that needs to be transmitted, it will have to be buffered until the host releases Clock.  Keyboards have a 16-byte buffer for this purpose.  If more than 16 bytes worth of keystrokes occur, further keystrokes will be ignored until there's room in the buffer.  Mice only store the most current movement packet for transmission.

Host-to-Device Communication:

The packet is sent a little differently in host-to-device communication...

First of all, the PS/2 device always generates the clock signal.  If the host wants to send data, it must first put the Clock and Data lines in a "Request-to-send" state as follows:

  • Inhibit communication by pulling Clock low for at least 100 microseconds.
  • Apply "Request-to-send" by pulling Data low, then release Clock.
The device should check for this state at intervals not to exceed 10 milliseconds.  When the device detects this state, it will begin generating Clock signals and clock in eight data bits and one stop bit.  The host changes the Data line only when the Clock line is low, and data is read by the device when Clock is high.  This is opposite of what occours in device-to-host communication.

After the stop bit is received, the device will acknowledge the received byte by bringing the Data line low and generating one last clock pulse.  If the host does not release the Data line after the 11th clock pulse, the device will continue to generate clock pulses until the the Data line is released (the device will then generate an error.)

The host may abort transmission at time before the 11th clock pulse (acknowledge bit) by holding Clock low for at least 100 microseconds.

To make this process a little easier to understand, here's the steps the host must follow to send data to a PS/2 device:

1)   Bring the Clock line low for at least 100 microseconds.
2)   Bring the Data line low.
3)   Release the Clock line.
4)   Wait for the device to bring the Clock line low.
5)   Set/reset the Data line to send the first data bit
6)   Wait for the device to bring Clock high.
7)   Wait for the device to bring Clock low.
8)   Repeat steps 5-7 for the other seven data bits and the parity bit
9)   Release the Data line.
10) Wait for the device to bring Data low.
11) Wait for the device to bring Clock  low.
12) Wait for the device to release Data and Clock


Figure 3 shows this graphically and Figure 4 separates the timing to show which signals are generated by the host, and which are generated by the PS/2 device.  Notice the change in timing for the "ack" bit--the data transition occours when the Clock line is high (rather than when it is low as is the case for the other 11 bits.)

Figure 3:  Host-to-Device Communication.

Figure 4:  Detailed host-to-device communication.

Referring to Figure 4, there's two time quantities the host looks for.  (a) is the time it takes the device to begin generating clock pulses after the host initially takes the Clock line low, which must be no greater than 15 ms. (b) is the time it takes for the  packet to be sent, which must be no greater than 2ms.  If either of these time limits is not met, the host should generate an error.  Immediately after the "ack" is received, the host may bring the Clock line low to inhibit communication while it processes data.  If the command sent by the host requires a response, that response must be received no later than 20 ms after the host releases the Clock line.  If this does not happen, the host generates an error.

    Other Sources / References:


    The PS/2 Mouse Interface

      

    The PS/2 Mouse Interface
    This article is Copyright 2001, Adam Chapweske 

    Electrical Interface / Protocol:

    The PS/2 mouse uses the same protocol as the PS/2 (AT) keyboard.  This standard originally appeared in the IBM technical reference manual, but I am not aware of any current official publication of this standard.  However, you may click here for the (detailed) information I have gathered about that protocol.

    Inputs, Resolution, and Scaling:

    The standard PS/2 mouse supports the following inputs: X (right/left) movement, Y (up/down) movement, left button, middle button, and right button. The mouse reads these inputs at a regular freqency and updates various counters and flags to reflect movement and button states.  There are many PS/2 pointing devices that have additional inputs and may report data differently than described in this document.  One popular extension I cover later in this document is the Microsoft Intellimouse, which includes support for the standard inputs as well as a scrolling wheel and two additional buttons.

    The standard mouse has two counters that keep track of movement: the X-movement counter and the Y-movement counter.  These  are 9-bit 2's complement values and each has an associated overflow flag.  Their contents, along with the state of the three mouse buttons, are sent to the host in the form of a 3-byte movement data packet (as described in the next section.)  The movement counters represent the amount of movement that has occurred since the last movment data packet was sent to the host.

    When the mouse reads its inputs, it records the current state of its buttons, then checks for movement. If movement has occurred, it increments (for +X or +Y movement) or decrements (for -X or -Y movement) its X and/or Y movement counters. If either of the counters has overflowed, it sets the appropriate overflow flag.

    The parameter that determines the amount by which the movement counters are incremented/decremented is the resolution. The default resolution is 4 counts/mm and the host may change that value using the "Set Resolution" (0xE8) command.

    There is a parameter that does not effect the movement counters, but does effect the reported(1) value of these counters.  This parameter is scaling.  By default, the mouse uses 1:1 scaling, which has no effect on the reported mouse movement.  However, the host may select 1:2 scaling by sending the "Set Scaling 2:1" (0xE7) command.  If 2:1 scaling is enabled, the mouse will apply the following algorithm to the counters before sending their contents to the host:
     
     

    Movement Counter
    Reported Movement
    0
    0
    1
    1
    2
    1
    3
    3
    4
    6
    5
    9
    N > 5
    2 * N

    Movement Data Packet:

    The standard PS/2 mouse sends movement (and button) information to the host using the following 3-byte packet (4):

     

    Byte 1 
    Bit 7
    Bit 6
    Bit 5
    Bit 4
    Bit 3
    Bit 2
    Bit 1
    Bit 0
    Y overflow
    X overflow
    Y sign bit
    X sign bit
    Always 1
    Middle Btn
    Right Btn
    Left Btn
    Byte 2
    X Movement
    Byte 3 
    Y Movement
    The movement counters are 9-bit 2's complement integers, where the most significant bit appears as a sign bit in Byte 1 of the movement data packet. These counters are updated when the mouse reads its input and finds movement has occurred. Their value is the amount of movement that has occurred since the last movement data packet was sent to the host (ie, after a packet is sent to the host, the movement counters are reset.) The range of values that can be expressed by the movement counters is -255 to +255. If this range is exceeded, the appropriate overflow bit is set and the counter is not incremented/decremented until it is reset.

    As I mentioned earlier, the movement counters are reset whenever a movement data packet is successfully sent to the host. They are also reset after the mouse receives any command from the host other than the "Resend" (0xFE) command.

    Modes of Operation:

    Data reporting is handled according to the mode in which the mouse is operating.  There are four standard modes of operation: 

    • Reset - The mouse enters Reset mode at power-up or after receiving the "Reset" (0xFF) command. 
    • Stream - This is the default mode (after Reset finishes executing) and is the mode in which most software uses the mouse.  If the host has previously set the mouse to Remote mode, it may re-enter Stream mode by sending the "Set Stream Mode" (0xEA) command to the mouse. 
    • Remote - Remote mode is useful in some situations and may be entered by sending the "Set Remote Mode" (0xF0) command to the mouse. 
    • Wrap - This mode isn't particularly useful except for testing the connection between the mouse and its host.  Wrap mode may be entered by sending the "Set Wrap Mode" (0xEE) command to the mouse.  To exit Wrap mode, the host must issue the "Reset" (0xFF) command or "Reset Wrap Mode" (0xEC) command.  If the "Reset" (0xFF) command is recieved, the mouse will enter Reset mode.  If the "Reset Wrap Mode" (0xEC) command is received, the mouse will enter the mode it was in prior to Wrap Mode.
    (Note: The mouse may also enter "extended" modes of operation, as described later in this document.  However, this is not a feature of the standard PS/2 mouse.)

    Reset Mode:

    The mouse enters reset mode at power-on or in response to the "Reset" (0xFF) command. After entring this mode, the mouse performs a diagnostic self-test referred to as BAT (Basic Assurance Test) and sets the follwing default values:

    • Sample Rate - 100 samples/sec
    • Resolution - 4 counts/mm
    • Scaling - 1:1
    • Data Reporting Disabled
    It then sends a BAT completion code of either 0xAA (BAT successful) or 0xFC (Error). If the host receives a response other than 0xAA, it may cycle the mouse's power supply, causing the mouse to reset and re-execute its BAT.

    Following the BAT completion code (0xAA or 0xFC), the mouse sends its device ID of 0x00. This distinguishes it from a keyboard, or a mouse in an extended mode. I have read documents saything the host is not supposed to transmit any data until it receives a device ID.  However I've found that some BIOS's will send the "Reset" (0xFF) command immediately following the 0xAA received after a power-on reset.

    After the mouse has sent its device ID to the host, it will enter Stream Mode.  Note that one of the default values set by the mouse is "Data Reporting Disabled".  This means the mouse will not send any movement data packets to the host until the "Enable Data Reporting" (0xF4) command is received.

    Stream Mode:

    In stream mode, the mouse sends movement data when it detects movement or a change in state of one or more mouse buttons. The maximum rate at which this data reporting may occur is known as the sample rate.  This parameter ranges from 10 samples/sec to 200 samples/sec. Its default value is 100 samples/sec and the host may change that value by using the "Set Sample Rate" (0xF3) command.  Stream mode is the default mode of operation.

    Remote Mode:

    In this mode, the mouse reads its inputs and updates its counters/flags at the current sampling rate, but it only notifies the host of movement (and change in button state) when that information is requested by the host. The host does this by issuing the "Read Data" (0xEB) command. After receiveing this command, the mouse will send a movement data packet, and reset its movement counters.

    Wrap Mode:

    This is an "echoing" mode in which every byte received by the mouse is sent back to the host. Even if the byte represents a valid command, the mouse will not respond to that command--it will only echo that byte back to the host. There are two exceptions to this: the "Reset" (0xFF) command and "Reset Wrap Mode" (0xEC) command. The mouse treats these as valid commands and does not echo them back to the host.

    Intellimouse Extensions:

    A popular extension to the standard PS/2 mouse is the Microsoft Intellimouse.  This includes support for a total of five mouse buttons and three axises of movement (right-left, up-down, and a scrolling wheel).  These additional features require the use of a 4-byte movement data packet rather than the standard 3-byte packet.  Since standard PS/2 mouse drivers cannot recognize this packet format, the Microsoft Intellimouse is required to operate exactly like a standard PS/2 mouse unless it knows the drivers support the extended packet format.  This way, if a Microsoft Intellimouse is used on a computer which only supports the standard PS/2 mouse, the Microsoft Intellimouse will still function, except for its scrolling wheel and 4th and 5th buttons.

    The Microsoft Intellimouse operates just like a standard PS/2 mouse (ie, it uses a 3-byte movement data packet, responds to all commands in the same way as a standard PS/2 mouse, and reports a device ID of 0x00.)  To enter scrolling wheel mode, the host sends the following command sequence:

    Set sample rate 200
    Set sample rate 100
    Set sample rate 80
    The host then issues the "Get device ID" command (0xF2) and waits for a response.  If a standard PS/2 mouse (ie, non-Intellimouse) is attached, it will respond with a device ID of 0x00.  In this case, the host will recognize the fact that the mouse does have a scrolling wheel and will continue to treat it as a standard PS/2 mouse.  However, if a Microsoft Intellimouse is attached, it will respond with an ID of 0x03.  This tells the host that the attached pointing device has a scrolling wheel and the host will then expect the mouse to use the following 4-byte movement data packet:
     

    Byte 1 
    Bit 7
    Bit 6
    Bit 5
    Bit 4
    Bit 3
    Bit 2
    Bit 1
    Bit 0
    Y overflow
    X overflow
    Y sign bit
    X sign bit
    Always 1
    Middle Btn
    Right Btn
    Left Btn
    Byte 2
    X Movement
    Byte 3 
    Y Movement
    Byte 4
    Z Movement
    Z Movement is a 2's complement number that represents the scrolling wheel's movement since the last data report.  Valid values are in the range of -8 to +7. This means the number is actually represented only by the least significant four bits; the upper four bits act only as sign extension bits.
    To enter scrolling wheel + 5 button mode, the host sends the following command sequence:
    Set sample rate 200
    Set sample rate 200
    Set sample rate 80
    The host then issues the "Get device ID" command (0xF2) and waits for a response.  A Microsoft Intellimouse will respond with a device ID of 0x04, then use the following 4-byte movement data packet:
     

    Byte 1 
    Bit 7
    Bit 6
    Bit 5
    Bit 4
    Bit 3
    Bit 2
    Bit 1
    Bit 0
    Y overflow
    X overflow
    Y sign bit
    X sign bit
    Always 1
    Middle Btn
    Right Btn
    Left Btn
    Byte 2
    X Movement
    Byte 3 
    Y Movement
    Byte 4
    Always 0
    Always 0
    5th Btn
    4th Btn
    Z3
    Z2
    Z1
    Z0
    Z0-Z3 is a 2's complement number which represents the amount of movement that has occurred since the last data report.  Valid values range from -8 to +7.
    4th Btn: 1 = 4th mouse button is pressed; 0 = 4th mouse button is not pressed.
    5th Btn: 1 = 5th mouse button is pressed; 0 = 5th mouse button is not pressed.
    You may have seen mice with two scrolling wheels--one vertical and the other horizontal.  These mice use the Microsoft Intellimouse data packet format as described above.  If the vertical wheel is scrolled upward, the Z-counter is incremented by one and if that wheel is scrolled down, the Z-counter is decremented by one.  This is normal operation for a scrolling wheel.  However, if the horizontal wheel is scrolled right, the Z-counter is incremented by two and if it is scrolled left, the Z-counter is decremented by two.  This seems like an odd way to implement the second scrolling wheel, but it works since the placement of the two wheels make it impossible to use both of them at the same time (and if you try to trick the software and use both at the same time, it will ignore the horizontal wheel.)

    Command Set:

    The following are the only commands that may be sent to the mouse... If the mouse is in Stream mode, the host should disable data reporting (command 0xF5) before sending any other commands...

    • 0xFF (Reset) - The mouse responds to this command with "acknowledge" (0xFA) then enters Reset Mode.
    • 0xFE (Resend) - The host sends this command whenever it receives invalid data from the mouse. The mouse responds by resending the last(2) packet(3) it sent to the host.   If the mouse responds to the "Resend" command with another invalid packet, the host may either issue another "Resend" command, issue an "Error" command, cycle the mouse's power supply to reset the mouse, or it may inhibit communication (by bringing the Clock line low).  The action taken depends on the host.
    • 0xF6 (Set Defaults) - The mouse responds with "acknowledge" (0xFA) then loads the following values:  Sampling rate = 100, Resolution = 4 counts/mm, Scaling = 1:1, Disable Data Reporting.  The mouse then resets its movement counters and enters stream mode.
    • 0xF5 (Disable Data Reporting) - The mouse responds with "acknowledge" (0xFA) then disables data reporting and resets its movement counters.  This only effects data reporting in Stream mode and does not disable sampling.  Disabled stream mode funcions the same as remote mode.
    • 0xF4 (Enable Data Reporting) - The mouse responds with "acknowledge" (0xFA) then enables data reporting and resets its movement counters.  This command may be issued while the mouse is in Remote Mode (or Stream mode), but it will only effect data reporting in Stream mode.
    • 0xF3 (Set Sample Rate) - The mouse responds with "acknowledge" (0xFA) then reads one more byte from the host.  The mouse saves this byte as the new sample rate. After receiving the sample rate, the mouse again responds with "acknowledge" (0xFA) and resets its movement counters.  Valid sample rates are 10, 20, 40, 60, 80, 100, and 200 samples/sec.
    • 0xF2 (Get Device ID) - The mouse responds with "acknowledge" (0xFA) followed by its device ID (0x00 for the standard PS/2 mouse.)  The mouse should also reset its movement counters.
    • 0xF0 (Set Remote Mode) - The mouse responds with "acknowledge" (0xFA) then resets its movement counters and enters remote mode.
    • 0xEE (Set Wrap Mode) - The mouse responds with "acknowledge" (0xFA) then resets its movement counters and  enters wrap mode.
    • 0xEC (Reset Wrap Mode) - The mouse responds with "acknowledge" (0xFA) then resets its movement counters and enters the mode it was in prior to wrap mode (Stream Mode or Remote Mode.)
    • 0xEB (Read Data) - The mouse responds with acknowledge (0xFA) then sends a movement data packet. This is the only way to read data in Remote Mode.  After the data packets has been successfully sent, it resets its movement counters.
    • 0xEA (Set Stream Mode) - The mouse responds with "acknowledge" then resets its movement counters and enters steram mode.
    • 0xE9 (Status Request) - The mouse responds with "acknowledge" then sends the following 3-byte status packet (then resets its movement counters.): 
      •  

        Byte 1 
        Bit 7
        Bit 6
        Bit 5
        Bit 4
        Bit 3
        Bit 2
        Bit 1
        Bit 0
        Always 0
        Mode
        Enable
        Scaling
        Always 0
        Left Btn
        Middle Btn
        Right Btn
        Byte 2
        Resolution
        Byte 3 
        Sample Rate

        Right, Middle, Left Btn = 1 if button pressed; 0 if button is not pressed.
        Scaling = 1 if scaling is 2:1; 0 if scaling is 1:1. (See commands 0xE7 and 0xE6)
        Enable = 1 if data reporting is enabled; 0 if data reporting is disabled. (See commands 0xF5 and 0xF4)
        Mode = 1 if Remote Mode is enabled; 0 if Stream mode is enabled. (See commands 0xF0 and 0xEA)
         

    • 0xE8 (Set Resolution) - The mouse responds with acknowledge (0xFA) then reads one byte from the host and again responds with acknowledge (0xFA) then resets its movement counters.  The byte read from the host determines the resolution as follows: 
       
      Byte Read from Host
      Resolution
      0x00
      1 count/mm
      0x01
      2 count/mm
      0x02
      4 count/mm
      0x03
      8 count/mm
    • 0xE7 (Set Scaling 2:1) - The mouse responds with acknowledge (0xFA) then enables 2:1 scaling (discussed earlier in this document.)
    • 0xE6 (Set Scaling 1:1) - The mouse responds with acknowledge (0xFA) then enables 1:1 scaling (discussed earlier in this document.)
    The only commands the standard PS/2 mouse will send to the host are the "Resend" (0xFE) and "Error" (0xFC) commands.  They both work the same as they do as host-to-device commands. 

    Initialization:

    The PS/2 mouse is normally detected/initialized only when the computer is booting up.  That is, the mouse is not hot-pluggable and you must restart your computer whenever you add/remove a PS/2 mouse (furthermore, some motherboards may be damaged if you add/remove a PS/2 mouse while the computer is running.)

    The initial detection of the PS/2 mouse occurrs during POST.  If a mouse is detected, the BIOS will allow the operating system to configure/enable the mouse.  Otherwise, it will inhibit communication on the mouse's bus.  If you boot the computer with a mouse attached, then detach/reattach the mouse while in Windows, the OS may be able to detect the mouse was reattached.  Microsoft tried to support this, but it only works about 50% of the time.

    The following is the communication between my computer (running Win98SE) and mouse when it boots up with a standard PS/2 mouse attached.  It is fairly typical of how a PS/2 mouse is initialized and if you want to emulate a PS/2 mouse it must (at minimum) be able to support the following sequence of commands... 

    • Power-on Reset:
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  FF  Reset command
      Mouse: FA  Acknowledge
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  FF  Reset command
      Mouse: FA  Acknowledge
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  FF  Reset command
      Mouse: FA  Acknowledge
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  F3  Set Sample Rate   : Attempt to Enter Microsoft
      Mouse: FA  Acknowledge       : Scrolling Mouse mode
      Host:  C8  decimal 200       :
      Mouse: FA  Acknowledge       :
      Host:  F3  Set Sample Rate   :
      Mouse: FA  Acknowledge       :
      Host:  64  decimal 100       :
      Mouse: FA  Acknowledge       :
      Host:  F3  Set Sample Rate   :
      Mouse: FA  Acknowledge       :
      Host:  50  decimal 80        :
      Mouse: FA  Acknowledge       :
      Host:  F2  Read Device Type  :
      Mouse: FA  Acknowledge       :
      Mouse: 00  Mouse ID          : Response 03 if microsoft scrolling mouse
      Host:  F3  Set Sample Rate 
      Mouse: FA  Acknowledge
      Host:  0A  decimal 10
      Mouse: FA  Acknowledge
      Host:  F2  Read Device Type
      Mouse: FA  Acknowledge
      Mouse: 00  Mouse ID
      Host:  E8  Set resolution
      Mouse: FA  Acknowledge
      Host:  03  8 Counts/mm
      Mouse: FA  Acknowledge
      Host:  E6  Set Scaling 1:1
      Mouse: FA  Acknowledge
      Host:  F3  Set Sample Rate
      Mouse: FA  Acknowledge
      Host:  28  decimal 40
      Mouse: FA  Acknowledge
      Host:  F4  Enable
      Mouse: FA  Acknowledge
      Initialization complete...

      If I then press the Left Button...
      Mouse: 09 1 1 00001001; bit0 = Left button state; bit3 = always 1
      Mouse: 00 1 1 No X-movement
      Mouse: 00 1 1 No Y-movement
      ... and release the Left Button:
      Mouse: 08 0 1 00001000 bit0 = Left button state; bit3 = always 1
      Mouse: 00 1 1 No X-movement
      Mouse: 00 1 1 No Y-movement

    The following is the communication between my computer (running Win98SE) and mouse when it boots up with an (emulated) Intellimouse... 
    • Power-on Reset:
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  FF  Reset command
      Mouse: FA  Acknowledge
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  FF  Reset command
      Mouse: FA  Acknowledge
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  FF  Reset command
      Mouse: FA  Acknowledge
      Mouse: AA  Self-test passed
      Mouse: 00  Mouse ID
      Host:  F3  Set Sample Rate   : Attempt to Enter Microsoft 
      Mouse: FA  Acknowledge       : Scrolling Mouse mode
      Host:  C8  decimal 200       :
      Mouse: FA  Acknowledge       :
      Host:  F3  Set Sample Rate   :
      Mouse: FA  Acknowledge       :
      Host:  64  decimal 100       :
      Mouse: FA  Acknowledge       :
      Host:  F3  Set Sample Rate   :
      Mouse: FA  Acknowledge       :
      Host:  50  decimal 80        :
      Mouse: FA  Acknowledge       :
      Host:  F2  Read Device Type  :
      Mouse: FA  Acknowledge       :
      Mouse: 03  Mouse ID          : Response 03 if microsoft scrolling mouse
      Host:  E8  Set Resolution 
      Mouse: FA  Acknowledge 
      Host:  03  8 counts/mm
      Mouse: FA  Acknowledge
      Host:  E6  Set scaling 1:1
      Dev:   FA  Acknowledge
      Host:  F3  Set Sample Rate 
      Mouse: FA  Acknowledge
      Host:  28  decimal 40
      Mouse: FA  Acknowledge
      Host:  F4  Enable device 
      Mouse: FA  Acknowledge

      If I then press the left mouse button:
      Mouse: 09  00001001 bit0 = Left button state; bit3 = always 1
      Mouse: 00  No X-movement
      Mouse: 00  No Y-movement
      Mouse: 00  No Z-movement

      ...and then release the left mouse button button:
      Mouse: 08  00001000 bit0 = Left button state; bit3 = always 1
      Mouse: 00  No X-movement
      Mouse: 00  No Y-movement
      Mouse: 00  No Z-movement

    After I downloaded/installed the Microsoft's Intellimouse drivers with support for the 4th and 5th buttons, the following sequence was found:
    ... (starts same as before) ...
    Host:  F3  Set Sample Rate   : Attempt to Enter Microsoft 
    Mouse: FA  Acknowledge       : Scrolling Mouse mode.
    Host:  C8  decimal 200       :
    Mouse: FA  Acknowledge       :
    Host:  F3  Set Sample Rate   :
    Mouse: FA  Acknowledge       :
    Host:  64  decimal 100       :
    Mouse: FA  Acknowledge       :
    Host:  F3  Set Sample Rate   :
    Mouse: FA  Acknowledge       :
    Host:  50  decimal 80        :
    Mouse: FA  Acknowledge       :
    Host:  F2  Read Device Type  :
    Mouse: FA  Acknowledge       :
    Mouse: 03  Mouse ID          : Response 03 if microsoft scrolling mouse.
    Host:  F3  Set Sample Rate   : Attempt to Enter Microsoft 5-button 
    Mouse: FA  Acknowledge       : Scrolling Mouse mode.
    Host:  C8  decimal 200       :
    Mouse: FA  Acknowledge       :
    Host:  F3  Set Sample Rate   :
    Mouse: FA  Acknowledge       :
    Host:  C8  decimal 200       :
    Mouse: FA  Acknowledge       :
    Host:  F3  Set Sample Rate   :
    Mouse: FA  Acknowledge       :
    Host:  50  decimal 80        :
    Mouse: FA  Acknowledge       :
    Host:  F2  Read Device Type  :
    Mouse: FA  Acknowledge       :
    Mouse: 04  Mouse ID         : Response 04 if 5-button scrolling mouse.
    ... rest of initialization same as before ...
    Emulation/Interfacing:
    • Click here for routines that emulate a PS/2 mouse or keyboard
    • Click here for routines that emulate a PS/2 host (ie, interface a mouse/keyboard)
    • Click here for a fully-functional PS/2 mouse written for the PIC16F84.
    If you want to build a truely fully-implemented mouse or host, you should implement all of the features described in this document (except for, of course, the Microsoft Intellimouse extensions, which are optional).  However, at an absolute minimum, your device should operate as follows:
    To Emulate a Mouse:
    • Never send data when  the "Clock" line low.  If the host pulls the "Data" line low, prepare to read a byte from the host.
    • ~500 milliseconds after powerup, transmit "0xAA, 0x00".
    • Wait for the host to send the enable (0xF4) command before sending any movement/button data.
    • Emulate the various mouse functions as follows:
      Emulated Action
      Data sent to host
      Move up one
      0x08,0x00,0x01
      Move down one
      0x28,0x00,0xFF
      Move right one
      0x08,0x01,0x00
      Move left one
      0x18,0xFF,0x00
      Press left button
      0x09,0x00,0x00
      Release left button
      0x08,0x00,0x00
      Press middle button
      0x0C,0x00,0x00
      Release middle button
      0x08,0x00,0x00
      Press right button
      0x0A,0x00,0x00
      Release right button
      0x08,0x00,0x00
    • Respond to the "Reset" (0xFF) command with "0xFA" then goto the beginning of your program. (ie, send 0xAA, 0x00, then wait for the enable command before sending any movement/button data.)
    • Respond to the "Get Device ID" (0xF2) command with "0xFA, 0x00".
    • Respond to the "Status Request" (0xE9) command with "0xFA, 0x00, 0x02, 0x64".
    • Respond to all other commands with acknowledge (0xFA).
    To Interface a Mouse:
    • Wait for the mouse to send "0xAA", then send the "Enable" (0xF4) command.
    • The mouse will then send a 3-byte movement packets as described earlier in this document.


    Footnotes:

    1) 2:1 scaling only applies to the automatic data reporting in Stream mode. It does not effect the reported data sent in response to the "Read Data" (0xEB) command.

    2)  The mouse and host do not buffer "Resend" (0xFF) commands. This means "0xFE" will never be sent in response to the "Resend" command. 

    3)   A "packet" may be a 3-byte movement data packet, a 4-byte movement data packet (for the Intellimouse), a 3-byte status packet (see "Status Request" [0xE9] command) a 2-byte completion-code-ID packet (0xAA,0x00 or 0xFC,0x00), or a 1-byte response to a command.

    4)  A little advice from my own experience...  Even though bit 3 of the first byte in a movement data packet is supposed to be set, some drivers (such as the standard PS/2 mouse driver included with Windows 98SE) don't care and just ignore that bit.  However, other drivers do check that bit and if it is not set, it is considered an error.  I mention this so that, if you're designing a mouse, you double-check that this bit is set in every movement data packet sent by your mouse.  If it is not, your mouse may work properly when you test it on your computer, but it may not work on other computers that use different mouse drivers. 

    For example, if using MS Intellimouse drivers and bit 3 of the first byte in a movement data packet is not set, the driver will discard that packet, then send the "Disable Data Reporting"  (0xF5) command, followed by the "Set Defaults" (0xF6) command, then it will reinitialize the mouse using the same command sequence as it does when Windows boots up (see the "Initialization" section above.)

    Other Sources / References:


      網誌存檔