makerdiary / python-keyboard

A hand-wired USB & Bluetooth keyboard powered by Python and more
https://makerdiary.com/m60
MIT License
486 stars 61 forks source link

upgrade CircuitPython #37

Open fkpwolf opened 2 years ago

fkpwolf commented 2 years ago

At most time, it works well on Windows 11. I even can see the left Battery volume. It is great.

But sometimes, when I am typing, Bluetooth got lost and I can't type anything. After a while, it connect again. I also noticed device status switched bettwen "paired" and "connected".

Wireless device: Wi-Fi 6 AX200.

Is there way to log error so we can debug and find root cause.

fkpwolf commented 2 years ago

try to upgrade firmware by myself:

  1. https://circuitpython.org/board/makerdiary_m60_keyboard/ download latest firmware
  2. https://github.com/makerdiary/python-keyboard this is m60 keyboard module, aka main module
  3. https://github.com/adafruit/Adafruit_CircuitPython_BLE second module Then code can run. But sometimes failed:
    code.py output:
    Traceback (most recent call last):
    File "code.py", line 7, in <module>
    File "/lib/keyboard/__init__.py", line 97, in __init__
    File "/lib/keyboard/__init__.py", line 254, in set_bt_id
    AttributeError: 'Keyboard' object has no attribute 'ble_hid'

    And keyboard will not response even connects to USB. Ctl+D reload then it will ok. But if usb disconnect, can't connect BLE. At this time, UART reset so I didn't know what happened. It is bad design to debug by an emulated UART.

fkpwolf commented 2 years ago

I upgraded Circuitpython to latest version 7.1. M60 works well when USB connected. But no response when USB disconnected and powered by battery. M60 goes to safe model?

Any clue on this issue? @xiongyihui

fkpwolf commented 2 years ago

I just tried ZMK, so far so good. https://github.com/fkpwolf/zmk-config/actions

hyx0329 commented 2 years ago

I picked up some changes from https://github.com/adafruit/circuitpython/compare/main...xiongyihui:m60 with modifications to suits CPY 7.x, and compiled an experimental firmware (CPY v7.3.1). The keyboard should work fine without usb connection. The matrix module is also ported. Be aware the patches aren't suitable for upstreaming.

For anyone interested, please go to my repo.

BarbUk commented 2 years ago

@hyx0329 Thanks for the new firmware.

Can you share some information about the process of building a new firmware (cf: https://github.com/makerdiary/python-keyboard/issues/8)?

hyx0329 commented 2 years ago

@BarbUk In order to build a new firmware, just follow the official document. You might want to read a different version of document, eg. here for CPY v7.3.x. After walking through the guide, you'll find UF2 file named as firmware.uf2 among the artifacts.

To summarize the whole building process:

  1. prepare environment (gcc toolchain and py stuff)
  2. prepare source code (root repo and submodules)
  3. compile mpy-cross
  4. modifiy target configurations (if any)
  5. compile firmware for the target board in the corresponding port directory (ports/nrf for M60 keyboard)

PS. my primary computer's OS is GNU/Linux

hyx0329 commented 1 year ago

I upgraded Circuitpython to latest version 7.1. M60 works well when USB connected. But no response when USB disconnected and powered by battery. M60 goes to safe model?

Current upstream version doesn't preserve the state of the battery control pin(p0.28), which seems need to be addressed. That's why the keyboard won't work without a USB power.

Edit: this should be fixed in CircuitPython 8.2.0+