èªäœããŒããŒããããçšåºŠåœ¢ã«ãªã£ãŠããŠãããããèªäœããŒããŒãã§éã¶ã®ãçµããããªãŒãªããŠæã£ãŠããã®ã§ããããŸã ãã£ãŠããªãããšããããŸããã
ãããBluetoothæ¥ç¶ã®ããŒããŒãã§ããã調ã¹ãŠã¿ããšèªäœããŒããŒããäœã人ã«ã¯äžå®æ°ã¯ãã£ãŠã¿ãã人ãããããã§ãã
ããããæåãªã®ãsekigonæ°ã®BLE Micro Proã ãšæãã®ã§ããã1ãããã¡ãŒã ãã§ã¢ãäœããªãããš(ã©ã€ã»ã³ã¹ã®éœåã§nRF52ãã©ã³ããå€ã)ããšãå人çã«åé¡ã®ããã«æããŸããå人çãªãšããã ãšãä»ãŸã§ã®ãã®ãšéããããŠäœ¿ãã«ããããããããProMicroã¯äœ¿ã£ãŠããªããããããã¯ããŒãºãªæããããŠæãåºããããªãããšããã®ããããŸãã
ãªã®ã§èªåã§ãªããšãBluetooth察å¿ã®ããŒããŒããäœããããªãšæãã®ã§ãããæ±ããèŠä»¶ã¯ã²ãšãŸãã¯ãããªæãã
- QMKã ãã§ãªãVIAã«å¯Ÿå¿ãã(æžãæãã¯USBã§OK)
- USB/Bluetoothäž¡æ¹ã«å¯Ÿå¿
- Bluetoothã¯ã¢ãžã¥ãŒã«ã§åŸä»ããã圢ã«ããã(æé©ã®é¢ä¿ãªã©)
- ææ°ã®QMKã§ã³ã³ãã€ã«ã§ããããã«ãã
- ã©ã€ã»ã³ã¹çã«ãåé¡ãªãã圢ã«ãªãã°å¬ãã
ãããªæãã§ãããUSB/Bluetoothã®ã¹ã€ããã³ã°ã¯äœãããã§å®çŸã§ãããšæãã®ã§ãUSBã«æ¥ç¶ããªããBluetoothã䜿ãã¿ãããªçŽ°ããã·ãã¥ãšãŒã·ã§ã³ã¯ç¡èŠããŠããšããããäœã£ãŠã¿ãŸãã
ã§ãã©ãããããŒããŒããæ³å®ããããšãããšãProMicroã䜿ããªãå°çšã®åºæ¿ã䜿ãæ³å®ã§èããŸãã
ã©ã®ã¿ã¡çŸç¶ã®ããŒãããã®ãŸãŸçšããŠBluetoothåã¯ç¡çã ãšæããŸãããããæ¹ããèããããã°ProMicroã«èœãšã蟌ãã®ã¯ãã»ã©é£ãããªãã§ããããããšããã®èšäºã§ã¯ProMicroã«æèŒãããATmega32U4(AVR)ã§ã¯ãªãSTM32Fç³»(æ€èšŒã§ã¯STM32F303CBT6)ã䜿ããŸãã
ããããã»ãŒåæ§ã®æ¹æ³ã§AVRç³»ã®ãã€ã³ã³ã§ãå®çŸã§ãããšæãã®ã§é©åã«èªã¿æ¿ããªããèªãã§ããã ãããè¯ãããšæããŸãã
ãšããããã§å®è£ ããŠãã£ãŠã¿ãŸãã
ç®æ¬¡
- QMKãšBluetooth
- ESP32ãéžãã çç±
- ããŒããŒãã®åäœãç¥ã
- çšæãããã®
- å®éã«äœã£ãŠã¿ã
- èããããåé¡
- ãŸãšã
QMKãšBluetooth
QMKãã¡ãŒã ãŠã§ã¢ã¯åºæ¬çã«ã¯USBããŒããŒãã®ãã¡ãŒã ãŠã§ã¢ãäœè£œã§ããããŒã«ã§ããããªã®ã§ãåºæ¬çã«ã¯BluetoothããµããŒãããªãã¹ã¿ã³ã¹ã§ã¯ãããšæããŸãã
ã§ãããå ¬åŒã«å¯Ÿå¿ããŠãããã®ãäºã€ãããŸãã詳现ã¯ä»¥äžã®ããŒãžã«ãããŸãã
GitHub
https://github.com/qmk/qmk_firmware/blob/master/docs/feature_bluetooth.md
ããã«ããéããRN-42ãšnRF51822ã§ãããå ããŠã察å¿ããŠããã®ã¯AVRç³»ãã€ã³ã³ã®ã¿ã§ããç§ãèšèšããŠããã®ã¯åºæ¬çã«ã¯STM32ç³»(ARM)ãªã®ã§ããããæ¡ä»¶ããå€ããŸãã
ãªãã§AVRç³»ã®ã¿ãªãã ããïŒãªãæ°ãããããããµããŒãããªãã®ã ããïŒèª¿ã¹ãŠã¿ããšçãã¯ç°¡åã§ããã©ã€ã»ã³ã¹ã®é¢ä¿ã§ããnRFãæè¿ã¯æµè¡ã£ãŠããããã§ãããããã¯Nordicã®ã©ã€ã»ã³ã¹ã«ã²ã£ãããããã§ãã移æ€ããã®ããã«ãªã¯ããŠæåŠãããŠããã®ãç®æããŠããŸãã
BLE Micro Proãããããããªããã©ãã¯ããã¯ã¹ã«ããŠããŠäœ¿ãåæãææªãªã®ã¯ã©ã€ã»ã³ã¹ã®é¢ä¿ã§ãœãŒã¹ã³ãŒããé åžã§ããªãããã§ãããå€ãã³ãŒãã䜿ãã°ã§ããããã§ãããæ¥ã æŽæ°ãããã³ãŒãã§å€ãã®ã䜿ãã®ã¯âŠãšããã®ã¯ãããŸãã
ãšããããã§ãSTM32ç³»ã®ãããã§ãªããšãBluetoothããŒããŒããäœããããšããã®ãä»åã®è©±ã®åºçºç¹ã§ãã
ESP32ãéžãã çç±
STM32ç³»ã®èªäœããŒããŒãã䜿ã£ãŠBluetoothããŒããŒããäœããããšãã話ã®æµãã¯ç解ããã ããããšæãã®ã§ãããã¿ã€ãã«ã«ããéãä»åã¯ESP32ã䜿ã£ãŠå®è£ ããŠããŸãããã®çç±ã§ããã
ãŸãã¯ã³ãŒããã©ããã圢ã§å®è£ ããããèããŠãããŸããäžã§æžããéããåºæ¬çã«QMKãã¡ãŒã ãŠã§ã¢ã§å¯Ÿå¿ããŠãããã®ããnRFç³»ã®ãã®ã¯ã©ã€ã»ã³ã¹é¢ä¿ã§çŽæ¥çã«QMKãã¡ãŒã ãŠã§ã¢ã§äœ¿ããšããã®ã¯å€§å€ã§ãããšãªããšãã©ã€ã»ã³ã¹ã«åŒã£ããããªããããªåœ¢ã§å®è£ ã§ãããã®ããå®å šã«å¥ã®ã³ãŒããšããŠäœè£œããããšã§ãQMKã«ã¯çµã¿èŸŒãŸãªãã§é åžã§ãããããªåœ¢ã«ããŠããŸãã®ãå°æ¥çã«ã¯è¯ãã§ãããã
ãŸããä»åã¯ã¢ãžã¥ãŒã«åœ¢åŒã§åŸä»ãã«ããããšããã®ãããã®ã§ãã©ããã£ãŠãå¥ã³ãŒãããŠå®è£ ã«ã¯ãªããŸãããªã®ã§ãQMKã«ã¯çµã¿èŸŒãŸãªãæ¹åã§ãã£ãŠããããšæããŸãã
QMKããã¯ç¬ç«ããã³ãŒããäœè£œãããšæ±ºãããšããã§ããããããããã®éžå®ã§ãããå¥ã³ãŒãã§å®è£ ãããšãªãã°ãQMKã«å³ããã©ã€ã»ã³ã¹ã§ããå¿ èŠã¯ãªãã®ã§ãéžã¹ãããããåºãããŸããRN-42ã§ãnRFç³»ã§ãããããã¯åé¡ãããŸããã
ãããã®äžããéžãã§ãè¯ãã£ãã®ã§ããããã以å€ã®éžæè¢ãããã®ããšãããšå²ãšæ°ã¯ãããŸããããã®æã®ããšã調ã¹ãŠå± ãæ¹ã ãšãåãã®éããæ¥æ¬ã«ã¯ããããæé©ããŒã¯ãä»ãããã®ãã䜿ã£ãŠã¯ãããªããšããæ³åŸãããã®ã§ãããã«æºæ ãããããã§ããå¿ èŠããããŸããæ£ããã¯ãããã§ã¯ãªããã¢ã³ããéšãå«ããã¢ãžã¥ãŒã«ã®åœ¢ã§æé©ãéã£ãŠããã°çµã¿èŸŒãã§äœ¿ã£ãŠãOKãšããã«ãŒã«ã§ãããããªããšå人ã®ç¯å²ã§äœ¿ããããããªãã®ã ãšESP32ãRNãnRFãRaspberry Pi Pico Wãããã§ããããã
ä»ã«ãã¿ããªå€§å¥œãè¹ããã®ããããBroadcomã®ãããªæåã©ããã®ã¢ãžã¥ãŒã«ãããã«ã¯ããã®ã§ããããµã³ãã«ã³ãŒãããªãã§ããããªãã¡ã¬ã³ã¹ãããããããªãã£ãããšãå人ã®æã§è¿œãã«ã¯é£ãã代ç©ãå€ãã§ãã
ãªã®ã§ãç°¡åã«äœããããªãããã§ããŒããŒããäœè£œããå Žåã®ã³ãŒããæ¯èŒããŠã¿ãŸããRN-42ã¯èª¿ã¹ãããªãã§äœ¿ããªããšæ±ºããŠããã®ã§ããããããBluetoothã®ããŒãžã§ã³ãå€ãããã§ããnRFã¯ææ°ã®ãã®ã§ããã°BLEãªã©ã«ã察å¿ããŠãããããããã€ã¹çãªåé¡ã¯ãããŸããããã³ãŒããç ©éã§ããçµæ§æ·±ããšãããŸã§æžããªããšåããªããããªã³ãŒãã§ããããµã³ãã«ã³ãŒãã§å ¬éãããŠããåã§ãããªã®ã§ãåã£ããã®ãäœããšãªããšäžã 倧å€ããã§ããRPi Pico Wã¯çºå£²ãããŠéããªããšããã®ãšèšäºå·ç段éã§ã¯æé©ãæªããã®ã§ãä»åŸã®æåŸ ã¯ã§ãããããããŸããããçŸæ®µéã§ã¯ãªãã§ããESP32ã¯BLEããŒããŒãã©ã€ãã©ãªãããã®ã§ããªãç°¡åã«å®è£ ããããšãã§ããŸãã
ãã®äžã§å人ã§æ°è»œã«è©Šããªãäžç®çç¶ã§ESP32ã ã£ãã®ã§ãEPS32ãéžãã§ããŸããä»ã«ãå ¥æã容æã ã£ãããå®äŸ¡ã ã£ãããšè©Šãã§äœãåã«ã¯è¯ããããšããé¢ããããŸããå®è£ æ¹æ³æ¬¡ç¬¬ã§ã¯ãä»ã®ããã€ã¹ã§ã®å¿çšãå¹ãã§ãããããè©Šäœã«ã¯ãã£ãŠããã§ãããã£ãšãã ããªãçç±ã ãšãããã£ãœãããšããã£ãŠå€±æããŠããããQMKãESP32ã«æžã蟌ããçãªè¬ã®å€¢ãèŠãŠãã人ãããã®ãèŠãŠããã£ãŠã¿ãããšæã£ããªããŠã®ããããŸãã
ããŒããŒãã®åäœãç¥ã
ESP32ã䜿ã£ãããšããªãã®ã§äœ¿ãæ¹ãåŠã³ã€ã€å®è£ ããŠãã£ãŠã¿ãŸãããšããããããŒããŒãã®ç°¡åãªä»çµã¿ãããã¯ç¥ã£ãŠããªããšå®è£ ã§ããªãã®ã§ç°¡åã«çŽ¹ä»ããŠãããŸããããŒããŒãããã£ãŠããããšã¯æ¥µããŠã·ã³ãã«ã§ã以äžã®æ§ã«ããŒã³ãŒããšãããã®ãéä¿¡ããŠããŸãã
ããã«çŽ°ããæžããŠãããšãUSBããã€ã¹ã¯ãã£ã¹ã¯ãªãã¿ãšããæ§é äœãã»ããã«ããŠPCçã®ãã¹ãããã€ã¹ã«ããŒã¿ãéãä»ããŠããŸãããã®äžã«ã¯ãã®ããã€ã¹ãã©ããªããã€ã¹ãªã®ã(äŸãã°ããŠã¹ãªã®ã)ãšãã£ãããŒã¿ãããã®ããã€ã¹ãã©ããªãµããŸããããã»ããã®ãã®ããŒã¿ãå ¥ã£ãŠããŸãã
ãã®èå¥ã«ãŸãã¯ã¯ã©ã¹ãšãããã®ããããHID(Human Input Device)ã¯ã©ã¹å ã«ã¯ããŒããŒããããŠã¹ãšãã£ããã®ããããŸããHIDã¯ã©ã¹ã«ã¯HIDã¬ããŒããšãããããã€ã¹ãã©ã®ãããªãµããŸããããããšããããŒã¿ã®æ¬äœããããŸãã
ãã®ããŒã¿å ã«ã¯äžã§æžããããŒã³ãŒããšãããã®ããã®ããŒãæŒããããã®ããŒã¿ãªã©ãå ¥ã£ãŠããŸããããŒã³ãŒããšã¯ããAãã®ããŒãªã2æ¡ã®16é²æ°ã§04ã¿ãããªããŒããšã«å¯Ÿããå²ãåœãŠã®ããšãæããŸãããã®ããŒãæŒããããããŒã³ãŒããšãã®ãæŒãããããšããç¶æ ãéããããŒãé¢ããããããŒã³ãŒããšãé¢ãããããšããHIDã¬ããŒããéãããŸãããã£ãšçŽ°ããããšã¯USBã®ä»æ§æžã§ãã¿ãŠãã ããã
https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf
现ããããšã¯ããŠãããQMKãã¡ãŒã ãŠã§ã¢ã§ã¯ãã®ãããªå éšã®åäœãç°¡åã«ãã£ãŠãããŠããŸããHIDã¬ããŒããªããŠæ°ã«ããããšãªãæ¹ã倧åã§ããä»åã®å 容ãç解ããããã§ã¯HIDã¬ããŒãäžèº«ã«ã€ããŠãããã¯æäœéç解ããŠããã®ãè¯ãã§ãããã
ã¡ãªã¿ã«ãBluetoothã§ãåããããªèŠæ Œã§æãç«ã£ãŠããåæ§ã«HIDã¯ã©ã¹ãå®çŸ©ãããHIDã¬ããŒãã®å 容ãæ¢å®ãããŠããŸããããŒã³ãŒãã¯USBã®ãããšäžç·ã§ãã
çšæãããã®
å®éã«äœ¿ã£ããã®ã玹ä»ããŠãããŸãããã¬ããããŒããªããã¯ãã®ãéžã¶ã®ã§ããã¯ãã£ã¡ãèªãã§ãããŠããã ãããšåŸæããªããããããŸããã
- TH25TK(STM32F103ã®èªäœããŒããŒã)
- EPS32-DevkitC v4
- ãã¬ããããŒã
- ãžã£ã³ãã¯ã€ã€
- USBã·ãªã¢ã«å€æ(CP2102)
ãŸãã¯èªäœããŒããŒããšããŠã¯èªåã®äœã£ãTH25TKãäžå¿BOOTHã§è²©å£²ãããŠããŸãããä»åå®éšã§äœ¿ã£ãã®ãšã¯ããããéãã®ãšãã·ãªã¢ã«éä¿¡çšã®ç·ãããŒãããªãã¯ã¹ã®äžéšãšå ±çšãªã®ã§ãéã³ååã§ãã£ãŠã¿ãŠæºè¶³ãããæ®éã®ããŒããŒããšããŠäœ¿ããæ¹ã«ããããã§ãã
ESP32-DevkitC v4ãšãã¬ããããŒãã¯ã»ããã§äœ¿ããŸãã
åŸæããŠã»ãããªãã®ã§å¿µã®ããæžããŠãããŸããã以äžã®ãªã³ã¯ã®ãµã³ãã€ãã®ãã€ãæ°èŠã§è²·ã£ãŠãããŸãããã
çç±ã¯ç°¡åã§ããããããªããšæšªå¹ ã足ããŸãããä»ã®ãã®ã¯5åã®ãã®ãå€ãã§ããã6åã®ãµã³ãã€ãã®ãã€ã§ãåçã®éãã®ãªã®ãªã§ããæªãããšã¯èšããªãã®ã§ããšãªãããããéžã³ãŸããããåŸã¯ãã³æ°ãå€ãã®ã§æãã®ãåºããŠåŒ·åŒã«æããšãã³ãæ²ããã®ã§å°çšã«ãããããã®æ°æã¡ãè¯ãã§ãã
ESP32èªäœã¯æ£çŽDevkit Cã§ãVã§ã䜿ãããããã®ã§ããã°ãªãã§ãè¯ããšæããŸããåœå ã§ããŒã¿ãå€ãã®ã¯DevkitCãªã®ã§Cã¯ç¡é£ãããããŸããã
ãžã£ã³ãã¯ã€ã€ã¯é·ããå«ããŠãèªèº«ã䜿ããããé·ãã§è¯ããšæããŸããå¥ã®çšéã§ã䜿ããã§ãããããä»åŸã®ããšãèããŠè²·ããšè¯ããããããŸããã
CP2102ã®USBã·ãªã¢ã«å€æããŒãã¯åäœç¢ºèªã§äœ¿ããã®ã§ãæã£ãŠãããŠæã¯ç¡ããšæããŸããããšãçµéšäžESP32DevkitCã«ä¹ã£ãŠããCP2102(ãšãã®ããã¢ã³)ã¯å²ãšå£ããããã®ã§ããããã°&å£ãããšãã®ä¿å¥çšã«1åã¯æã£ãŠããã®ãããããã§ãã
ãããã®éšåãã€ãã£ãŠæ€èšŒãããŸããã
å®éã«äœã£ãŠã¿ã
ãŸãã¯QMKã«å¯Ÿå¿ããèªäœããŒããŒãã¯åäœã§åäœããåæã§ãã®ã§ãèªäœããŒããŒãããã¯HIDã¬ããŒãã§ããå¿ èŠã¯ãããŸãããããŒã³ãŒããšããŒãã¬ã¹ã®æ å ±ãéä¿¡ãESP32ã§ããããåä¿¡ããŠHIDã¬ããŒããšãã®éä¿¡ãè¡ãå¿ èŠãããŸãã
ãšãªããšãæäœéäžã€ã¯èªäœããŒããŒããšESP32ã®éã«äŒéè·¯ãå¿ èŠãšãªãã®ã§ãä»åã¯ã·ãªã¢ã«éä¿¡ãçšããŠéä¿¡ããŸããESP32åŽã§ã®ã·ãªã¢ã«éä¿¡ã¯ãã調ã¹ããåºãŠããã®ã§ããšããããèªäœããŒããŒãåŽã§å®è£ ããŸããã·ãªã¢ã«éä¿¡ã§ããã°UARTã®ããŒãžãèŠãŠã·ãªã¢ã«éä¿¡ãæå¹åããŸãã
GitHub
https://github.com/qmk/qmk_firmware/blob/master/docs/uart_driver.md
䜿ãããã·ãªã¢ã«éä¿¡ã«åãããŠããããžãã¯å®è£ ããŠããããšããŠãå°ãèºããã®ãä»ã®ãã¡ã€ã«ãžã®èšè¿°ããŸããkeyboad.cã«uart.hãã€ã³ã¯ã«ãŒãããå¿ èŠããããŸãããŸããã·ãªã¢ã«ã®åæåã以äžã®é¢æ°ã§ããŠãããŸããããã¯å¥ã®é¢æ°å ã§åŠçããŠãããã£ãã®ã§ãããããã¥ã¡ã³ãã«æå®ãç¡ãã£ãã®ã§ãšããããããã§ããŠããŸãã
#include "uart.h"
//******äœãåŠçããããªã*****
void keyboard_post_init_kb(void){
uart_init(115200);
}
ããã ãã ãšãã«ãã§æãããã®ã§ãrules.mkãããè¿œå ããŸãã
QUANTUM_LIB_SRC += uart.c
äžå¿ããã§äœãããã®åŠçãæžãã°æäœééåä¿¡ãã§ããŸããé©åœã«ãããã°ãããå®éã«ããŒã³ãŒããéãä»ããŠã¿ãŸããQMKãã¡ãŒã ãŠã§ã¢ã®ããŒã³ãŒããèŠãŠã¿ããšãéåžžã®ããŒã³ãŒãã§ã¯äœ¿ããªãæ¡æ°ãŸã§æ¡åŒµãããã®ãå éšã§ã¯äœ¿ãå Žåãããããã§ãããããã¯QMKå°çšã®ç¹æ®ãªããŒã§ã®ã¿çºçããã®ã§ãä»åã¯ãããç¡èŠããŸãããŸããHIDã¯ã©ã¹ã®å®çŸ©ã«ãããšããŒã³ãŒãã¯231ãŸã§ã®ãããªã®ã§ããã掻ãããŠã³ãŒããæžããŠã¿ãŸãããããã°ã®ãšãããã³ãŒããããã£ãŠãªãã®ã§èŠããªãæ©èœãšã䜿éäžæãªãã®ããããšæããŸããããããžãã¯ç¡èŠããŠãã ããã
#include "print.h"
#include "btest.h"
#include "uart.h"
uint8_t LowByte(uint16_t);
uint8_t HighByte(uint16_t);
uint16_t combu8t(uint8_t,uint8_t);
void keyboard_post_init_user_kb(void) {
// Customise these values to desired behaviour
debug_enable=true;
debug_matrix=true;
//debug_keyboard=true;
//debug_mouse=true;
}
void keyboard_post_init_kb(void){
uart_init(115200);
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
uint8_t data[5]={0};
data[0]=0xFF;
data[1]=0xFF;
data[2]=HighByte(keycode);
if(data[2]!=0x00){
return true;
}
data[3]=LowByte(keycode);
data[4]=record->event.pressed;
uprintf("Keycode: %u ,0x%x\ndata[0]=0x%x\ndata[1]=0x%x\n",keycode,keycode,data[2],data[3]);
uprintf("data[2]=0x%x\nPress: %u\n\n",data[4],record->event.pressed);
uprintf("readPin(A11)=%u\nreadPin(A12)=%u\n",readPin(A11),readPin(A12));
uart_transmit(data,5);
if(uart_available()){
uprintf("*******recive data: %u*********\n",(uint8_t)uart_read());
}
return true;
}
uint8_t LowByte(uint16_t u16){
return (uint8_t)u16;
}
uint8_t HighByte (uint16_t u16){
uint8_t ans=u16>>8;
return ans;
}
uint16_t combu8t(uint8_t HB,uint8_t LB){
return (HB<<8)|LB;
}
è²ã èæ ®ããŠäœ¿ã£ãŠãªãäºçŽçšã®ããŒã¿é åãšããçšæããŠããŸãããã®ã³ãŒãã§ããŒã³ãŒãã®æ¬äœãšãªãã®ã¯data[3]ã§ããdata[2]ã¯16ãããã®ãã¡äžåŽ8ããããå€å®ããŠããŠãããã0以äžãªãå°ãªããšãããŒã·ãã¯ããŒã³ãŒãã§ã¯ãªãã®ã§ããããç¡èŠããããã«ããŠããŸããåŸã¯é©åœã«ãããæŒç®ã®é¢æ°ãäœã£ãŠå®è£ ããŠããŸãããã¹ãã€ãã§ã«ããŒã¿ãåãåã£ããšãã®é¢æ°ãäœããŸãããèŠããªãã£ãã§ããã
ããã«ãã£ãŠåŸãããããŒã¿ã確èªãããšæ£ããããŒã³ãŒããããŒãã¬ã¹ã®ããŒã¿ã確èªã§ããŸãã
ESP32ã§BLEããŒããŒããäœãã©ã€ãã©ãªãšããŠArduinoIDEç°å¢ã§åãESP32-BLE-KeyboardããããŸãããããã¯å°ãæ©èœäžè¶³ãšããããæ±ããæ©èœããªãã®ã§ç§ã®ãã©ãŒã¯ã§æ¹é ãããã®ã䜿ããšç°¡åã«å®è£ ã§ããŸããæ¹é ããã©ã€ãã©ãªã¯ä»¥äžã§ãã
ESP32-BLE-keyboard THUN fork
https://github.com/T-H-Un/ESP32-BLE-Keyboard
å°å ¥æ¹æ³ã¯ãªãªãžãã«ã®ãã®ãšåãã§ããããã«ã¯ä»¥äžã®é¢æ°ãè¿œå ããŠããŸãã
- bleKeyboard.HIDpress(uint8_t)
- bleKeyboard.HIDrelease(uint8_t)
ãã®é¢æ°ã¯çŽæ¥uint8åã®ããŒã³ãŒãå€ãHIDã¬ããŒãã«å ¥ããŠéä¿¡ããŠãããé¢æ°ã§ããååã®éãHIDpressãæŒããéã«ãHIDreleaseã話ããéã«å®è¡ãããšããŒããŒããšããŠæ©èœããŸãã
ãããã®é¢æ°ã䜿ã£ãŠæžããã®ããã®ã³ãŒãã§ããèªåçšã«LEDãç¹ãã§ãããããããã°çšã®æäœãããã§ãé©åã«æ¶ãããããŠäœ¿ãã°è¯ãããšæããŸãã
#include <BleKeyboard.h>
#define LED_PIN 21
#define LED_PIN1 13
#define NMOS 15
#define BAUD 115200
#define SERIAL_DEBUG
//#define BLEKBD_TEST
BleKeyboard bleKeyboard("ESP32 KEYBOARD"); //ããã€ã¹ã®åå4
HardwareSerial sSerial1(1);
void setup() {
Serial.begin(BAUD);
Serial.println("Starting BLE work!\n");
bleKeyboard.begin();
pinMode(0,INPUT_PULLUP); //GPIO0(BOOT)ããã«ã¢ããä»ãå
¥åèšå®
//Serial2.begin(BAUD);
sSerial1.begin(115200, SERIAL_8N1, 26, 27);
Serial.println("Waiting for Handshake\n");
delay(2000);
Serial.println("Connected!");
pinMode(LED_PIN, OUTPUT);
pinMode(LED_PIN1, OUTPUT);
pinMode(NMOS, OUTPUT);
}
void loop() {
uint8_t data[5]={0};
digitalWrite(LED_PIN, LOW);
digitalWrite(LED_PIN1, LOW);
digitalWrite(NMOS, LOW);
while( sSerial1.available()){ //Serial1ã«åä¿¡ããŒã¿ãããã
data[0]=(uint8_t)sSerial1.read();
if(data[0]==0xFF){
data[1]=(uint8_t)sSerial1.read();//Check of 0xFF headers
if(data[1]==0xFF){
data[2] = (uint8_t)sSerial1.read();//HighByte of a keycode of QMK_Firmware/
data[3] = (uint8_t)sSerial1.read();//LowByte of a keycode of HID regulations.
data[4] = (uint8_t)sSerial1.read();//Keypress
#ifdef SERIAL_DEBUG
digitalWrite(LED_PIN, HIGH);
Serial.print("data[2]=");
Serial.println(data[2]);
Serial.print("data[3]=");
Serial.println(data[3]);
Serial.print("data[4]=");
Serial.println(data[4]);
#endif
if(bleKeyboard.isConnected()) {
if(data[4]==1){
bleKeyboard.HIDpress(data[3]);
Serial.print("data[3] Press=");
Serial.println(data[3]);
}
else{
bleKeyboard.HIDrelease(data[3]);
Serial.print("data[3] Release=");
Serial.println(data[3]);
}
}
else
Serial.print("BLE Keyboard is not connected");
}
}
}
#ifdef SERIAL_DEBUG
while( Serial.available()){//ã³ã³ãœãŒã«ã«å
¥åãå
¥ãããè¿ããããã°çšé¢æ°
Serial.println((char)Serial.read());
}
#endif
if(bleKeyboard.isConnected()) { //æ¥ç¶ãããŠãããšã
if(digitalRead(0) == LOW){//BOOTã¹ã€ãããæŒãããŠããæ
#ifdef BLEKBD_TEST
bleKeyboard.write(KEY_RETURN); //Enterãéä¿¡
sSerial1.write(0x04);
digitalWrite(LED_PIN1, HIGH);
delay(200);
#endif
digitalWrite(NMOS, HIGH);
}
}
}
ä»æ¥èŒããŠããã³ãŒãã¯ãšããããã³ãããããåãã¯ããã®ã§ãšããã奜ããªåœ¢ã«ããŠããã°åäœç¢ºèªã¯ã§ãããšæããŸãã
ãããã®ã³ãŒãã䜿ã£ãŠåäœç¢ºèªããããšãããå€å°ããã€ããæããå Žé¢ããããŸããããæåå ¥åãªã©äžè¬çãªäœ¿ãæ¹ã§ããã°äœ¿ããªãããšã¯ç¡ãçšåºŠã ãšæããŸãããã²ãŒã ãªããã«ã¯ééããªã䜿ããªãæãã§ãã
ã¡ãªã¿ã«ãããŒããŒãæ¬äœåŽãQMKã«å¯Ÿå¿ãããŠããã°åœç¶ãªããUSBã§æ¥ç¶ããã°ããŒããããæžãæããããšãå¯èœã§ããBluetoothããæžãæããã®ã¯ã§ããŸããããããã¯QMKã®ããŒããŒãå šãŠã§èšããããšãªã®ã§è«ŠããŸãããã
ãšããããã§ã¿ã€ãã«éãã®BLEããŒããŒããäœè£œããããšãã§ããŸããããã®å®è£ æ¹æ³ãªãããçšåºŠã©ã€ã»ã³ã¹ãæ°ã«ããªãã§å€§äžå€«ã ãšæãã®ã§ãä»ã®ãããã§ã䌌ããããªæ¹æ³ã§å®è£ ã§ãããã§ãã
èãããåé¡
å ¥åé 延ã¯å€å°ã¯ãšãããšæãã®ã§å°ãæ°ã«ãªãããªãšããã®ãäžã€ç®ãããäžã€ãæ¥ç¶ãåãããšãã§ãããæŒãã£ã±ãªããç¶ç¶ããããšæãã®ã§ãå ¥åããã£ã±ãªãã®ç¶æ ãåºãŠãããããããŸããããã¹ãã§äœã£ãŠã¿ãçšåºŠãªã®ã§é·æçã«ã©ãããšããã®ãããããŸãããã
ãŸãããããããããªãŒé§åã«ããããšæããšããªãããã©ããšæããŸãããšããã®ããESP32ã¯BLEã®ããŒã¿ããéä¿¡æã«150mAãšããã®ã¬ãã«ã®é»æµãæµãããããªã®ã§ãããªãæ¶è²»é»åçã«ã¯ãã€ãã¯ãã§ããåžžã«é»åãäŸçµŠã§ããç°å¢ãªã䜿ããããªã
ããããžãã¯å®è£ 次第ã§ã¯ãããŸãããUSBæ¥ç¶ãããŠããç¶æ ã§ãPCçãšãã¢ãªã³ã°ãããŠãããšäºéã§å ¥åãããŠããŸããŸããããã¯è²ã ãªæ¹æ³ã§å®çŸã§ãããšæãã®ã§ãä»åã®ã³ãŒãã§ã¯ãšãã話ã§ãããèŠæ¹è¯ãšããããšã§ãã
ãŸãšã
ESP32ãšèªäœããŒããŒãã䜿ã£ãŠBluetooth/QMK/VIA察å¿ã®èªäœããŒããŒããè©ŠäœããŠã¿ãŸããã倧ããªåé¡ã¯ãªãã£ããã®ã®å®çšçãã©ããã¯äººã«ãããããªåºæ¥ã§ãã
ãã ãç 究çãªå 容ãšããŠã¯æ¥œããã£ãã§ãããåŸããã®ããã£ãããªãšæãã®ã§ãèå³ã®ããæ¹ã¯æ¯éãã£ãŠã¿ãŠãã ããããããªã«éšå代ãé«ãããã§ã¯ãªãã§ãããã
以äžã§ãããèªã¿ããã ãããããšãããããŸããã