{"id":13802136,"url":"https://github.com/alankrantas/micropython_GT30L24T3Y_big5_font","last_synced_at":"2025-05-13T12:32:28.053Z","repository":{"id":113012381,"uuid":"395394467","full_name":"alankrantas/micropython_GT30L24T3Y_big5_font","owner":"alankrantas","description":"從 GT30L24T3Y/ER3303-1 字庫芯片讀取 BIG-5 漢字的簡易 MicroPython 驅動程式","archived":false,"fork":false,"pushed_at":"2021-08-20T18:38:51.000Z","size":770,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T15:38:01.354Z","etag":null,"topics":["er3303-1","font","gt30l24t3y","spi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alankrantas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-08-12T17:21:49.000Z","updated_at":"2024-10-24T16:27:26.000Z","dependencies_parsed_at":"2024-01-07T21:53:21.225Z","dependency_job_id":"6770e884-bbca-4a0f-b7a7-cfe688c7b89e","html_url":"https://github.com/alankrantas/micropython_GT30L24T3Y_big5_font","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython_GT30L24T3Y_big5_font","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython_GT30L24T3Y_big5_font/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython_GT30L24T3Y_big5_font/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fmicropython_GT30L24T3Y_big5_font/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alankrantas","download_url":"https://codeload.github.com/alankrantas/micropython_GT30L24T3Y_big5_font/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253942650,"owners_count":21988105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["er3303-1","font","gt30l24t3y","spi"],"created_at":"2024-08-04T00:01:36.993Z","updated_at":"2025-05-13T12:32:27.756Z","avatar_url":"https://github.com/alankrantas.png","language":"Python","funding_links":[],"categories":["Libraries"],"sub_categories":["Display"],"readme":"# 從 GT30L24T3Y/ER3303-1 SPI 字庫芯片讀取 BIG-5 漢字的簡易 MicroPython 驅動程式\n\n![IMG_0001](https://user-images.githubusercontent.com/44191076/129242480-861ec0a6-f84e-44bd-9a00-d1b0b5d3048f.JPG)\n\nGT30L24T3Y 又名 ER3303-1 是高通 (Genitop，不是那個 Qualcomm) 生產的[眾多字庫晶片](http://www.mitsutech.com.tw/vision_T/product_genitop0.htm)之一，如今還可以買到，但網路上找不到什麼操作範例，原始文件也寫得不是很清楚。花了一番功夫，總算搞懂是怎麼運作的了。\n\n![0117021043](https://user-images.githubusercontent.com/44191076/129241611-219bcaa0-8109-4579-b90f-2b75e650b112.jpg)\n\n## 使用\n\n把 [big5.py](https://github.com/alankrantas/micropython_Big5_GT30L24T3Y_ER3303-1/blob/main/big5.py) 內的 getBig5Font 函式拷貝到你的程式中即可。其呼叫參數如下：\n\n```python\ngetBig5Font(spi, cs, font_code, font_size, raw=False, printout=False)\n```\n\n| 參數 | 意義 |\n| --- | --- |\n| spi | SPI 物件 (machine.SPI 或 machine.SoftSPI) |\n| cs | CS 腳位物件 (machine.Pin) |\n| font_code | BIG-5 字碼 (字串或數值, 如 'A140' 或 0xA140, 參閱[字碼表](http://web.tnu.edu.tw/me/study/moodle/tutor/vb6/tutor/r05/index.htm)) |\n| font_size | BIG-5 字體大小 (12, 16 或 24) |\n| raw | 設為 True 時直接傳回 bytes 陣列, 否則預設傳回 framebuf.FrameBuffer |\n| printout | 設為 True 時會在 REPL 印出該字的文字圖檔 |\n\n傳入不正確的 font_code 或 font_size 引數會使它拋出錯誤。SPI 物件的最高 baudrate 只能設為  40 MHz；儘管官方文件指出 GT30L24T3Y 通訊速度可達 80 MHz，但測試上無法這樣穩定運作。\n\n預設下此函式會傳回 MicroPython 的 [FrameBuffer](https://docs.micropython.org/en/latest/library/framebuf.html) 物件，讓你能把它直接貼在某些顯示器模組上。據我所知 [SSD1306 OLED](https://github.com/stlehmann/micropython-ssd1306) 及 [PCD8544/Nokia 5110 LCD](https://github.com/mcauser/micropython-pcd8544) 的驅動程式都會使用 FrameBuffer。\n\n如果你要使用純 bytes 陣列，[ER3303-1 手冊](https://github.com/alankrantas/micropython_GT30L24T3Y_big5_font/blob/main/ER3303-1_Datasheet.pdf)的 12-13 頁有說明字型資料是如何排列的。\n\n## BIG-5 字體\n\nGT30L24T3Y 支援 GB、BIG-5 和 Unicode 三種中文字，以及幾種 ASCII 英數字形。目前我只實作 BIG-5。MicroPython 本身已經提供 8x8 英數字體，BIG-5 本身也有數字和符號等等，所以 ASCII 的部分儘管查詢上更簡單，在此仍比較沒有使用的需要。\n\nGT30L24T3Y 將漢字字庫的索引資料一併存在晶片中，所以查詢時其實要做兩次 SPI 讀寫，第一次是用某字在字碼表的排列順序去查它在晶片裡的 offset，第二次才是把字讀出來。問題就在於，這個已經有點歷史的晶片的 BIG-5 字碼和你在現代軟體得到的結果 (包括用正規 Python 的 ```codecs.encode()```) 會有出入，有很多後面的非中文字並不存在於晶片中，所以還是乖乖用舊的字碼表吧。\n\n可用的 BIG-5 字體有 12x12、16x16 及 24x24 像素三種尺寸 (正確來說是 11x12，15x16 與 24x24)。有趣的是 Unicode 字庫似乎跟 BIG-5 是共用的，只不過是改成讓你用 Unicode 字碼來查詢而已，但我並不清楚此晶片使用的 Unicode 編碼順序 (用 ```ord()``` 取得的字碼跟晶片用的似乎不太一樣)。另外就文件的說法，24x24 字體只支援基本中文字，所以字碼不能超過 E1BC。\n\n## 測試\n\n我在圖中用的是 Raspberry Pi Pico 與 SSD1306，但這應該也適用於 ESP8266/ESP32。我用的 MicroPython 版本為 v1.16。\n\n![1](https://user-images.githubusercontent.com/44191076/129292442-1f8f4ce8-6ff3-4abf-b93d-7ad05be40aaa.png)\n\nGT30L24T3Y 接線 (使用 SPI0 硬體腳位)：\n\n| 腳位 | 接線 |\n| --- | --- |\n| GND | GND |\n| 3.3-5V | 3.3V |\n| CS | GPIO 17 |\n| SI (MOSI) | GPIO 19 |\n| SO (MISO) | GPIO 16 |\n| SCK | GPIO 18 |\n\nSSD1306 接線 (使用 I2C1 硬體腳位)：\n\n| 腳位 | 接線 |\n| --- | --- |\n| VCC | 3.3V |\n| GND | GND |\n| SCL | GPIO 27 |\n| SDA | GPIO 26 |\n\n下面的範例會用不同大小印出一連串文字。你可以先在字碼表查詢你要使用的字，並建一個 Python 字典當對照表。不過由於 MicroPython 是基於 Python 3.4，走訪字典內容時不會照元素的存入順序印出，所以你仍得用另外的方式 (比如一個串列) 來走訪。\n\n```python\n    # 前面貼上 getBig5Font() 函式\n\n    # 字碼對照表    \n    data = {\n        '我': 'A7DA',\n        '要': 'AD6E',\n        '代': 'A54E',\n        '替': 'B4C0',\n        '月': 'A4EB',\n        '亮': 'AB47',\n        '懲': 'C367',\n        '罰': 'BB40',\n        '你': 'A741',\n        }\n\n    # 要顯示的文字\n    text = '我要代替月亮懲罰你'\n\n    from machine import Pin, I2C, SPI\n    from ssd1306 import SSD1306_I2C  # https://github.com/stlehmann/micropython-ssd1306\n\n    spi = SPI(0, baudrate=40000000, sck=Pin(18), mosi=Pin(19), miso=Pin(16))\n    cs = Pin(17, Pin.OUT, value=1)\n    \n    display = SSD1306_I2C(128, 64, I2C(1, scl=Pin(27), sda=Pin(26)))\n    display.fill(0)\n    \n    pos = 0\n    for t in text:\n        display.blit(getBig5Font(spi, cs, data[t], font_size=12), pos, 0)  # 印上文字\n        pos += 12\n    \n    pos = 0\n    for t in text:\n        display.blit(getBig5Font(spi, cs, data[t], font_size=16), pos, 18)\n        pos += 16\n        \n    pos = 0\n    for t in text:\n        display.blit(getBig5Font(spi, cs, data[t], font_size=24), pos, 40)\n        pos += 24\n    \n    display.show()  # 顯示文字\n    \n    buf = getBig5Font(spi, cs, data['月'], font_size=24, raw=True, printout=True)\n    print(buf)\n```\n\n最後兩行會在主控台印出\n\n```\n------------------------\n------------------------\n------------------------\n#-----------------------\n-#----------------------\n-##---------------------\n--###-------------------\n---####################-\n-----#################--\n----------#-----#----#--\n----------#-----#----#--\n----------#-----#----#--\n----------#-----#----#--\n----------#-----#----#--\n--#-------#-----#----#--\n--#-------#-----#----#--\n###-------#-----#----#--\n-######################-\n--#####################-\n---------------------#--\n------------------------\n------------------------\n------------------------\n------------------------\nb'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xfe\\xfc\\x84\\x84\\x84\\x84\\x84\\x84\\x84\\x84\\xfe\\xfe\\x04\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xff\\xff        \\xff\\xff\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80@`8\\x1f\\x07\\x00\\x00\\x00\\x00\\x00  \\xe0\\x7f?\\x00\\x00\\x00\\x00\\x00'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fmicropython_GT30L24T3Y_big5_font","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falankrantas%2Fmicropython_GT30L24T3Y_big5_font","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fmicropython_GT30L24T3Y_big5_font/lists"}