ah- / anne-key Goto Github PK
View Code? Open in Web Editor NEWFirmware for Anne Pro Keyboard written in Rust
License: Apache License 2.0
Firmware for Anne Pro Keyboard written in Rust
License: Apache License 2.0
We can now pair with the Mac App via bluetooth, but not yet to the official Android App.
This is most likely due to the obins app requesting further information about the keyboard (like firmware version etc.) that we don't implement yet.
Not sure what changed, but the travis builds fail with this:
The command "cargo fmt --all -- --write-mode=diff" exited with 0.
$ make bloat
xargo bloat --target thumbv7m-none-eabi -n 50
Compiling core v0.0.0 (file:///home/travis/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
Finished release [optimized + debuginfo] target(s) in 42.60 secs
Compiling compiler_builtins v0.1.0 (file:///home/travis/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcompiler_builtins)
Finished release [optimized + debuginfo] target(s) in 4.34 secs
error: Invalid arguments.
Usage: cargo bloat [options]
make: *** [bloat] Error 1
Going to remove it from travis until we figure out what's wrong.
It's working fine for me locally, but I'm not on the latest nightly.
Once we can pair to the App it'd be nice to be able to support uploading custom LED themes.
I think all we need to do in the key stm32 is forward the right messages from bluetooth receive to the LED chip.
This might also require a bit of refactoring of the serial support and increasing buffer sizes since those themes are way larger than the data we handle so far.
Right now there is a global timer that continuously scans which keys are pressed and sends out HID reports based on that.
The keys are all wired up so key presses can fire external interrupts that wake up the STM32.
The bootloader even leaves it in a half-enabled state, which is why we have all the EXTI handlers in https://github.com/ah-/anne-key/blob/master/src/main.rs#L177
To enable wakeups we probably need to configure the EXTI registers correctly and then set up the keyboard matrix gpios correctly so that pressing a key pulls an EXTI line up/down.
Once this works it'll be really helpful for power management so we can sleep when noone is using the keyboard. We might even want to consider only running off those interrupts and getting rid of the timer altogether?
During typing every few keys, one key is repeated. Repetition occurs shortly after key press (less than 500ms?), but usually I'm able to type one more letter before the "ghost" one appears. As for now, I couldn't find any regularity in repeated key type (happens to alphas as well as mods) or time between repetitions.
Possible cause is that my Anne Pro is customized with Kailh Pro Purple switches, but on the other hand I verified that there are no repetitions on original firmware (v1.40).
Currently the serialisation is a bunch of slightly sketchy mem transmutes and enums. It works ok, and is as fast as it gets, and produces little binary size overhead.
It would be interesting to see how it would look if we used serde in https://github.com/ah-/anne-key/blob/master/src/protocol.rs and e.g. https://github.com/ah-/anne-key/blob/master/src/bluetooth.rs#L69
The idea is to offer an easy way to access keys lighting programmatically (API?). This will allow cool stuff like receiving notifications visually on the keyboard like flashing "m" letter if you receive an email etc ...
I hope this can be easily implemented in this firmware and thank you in advance if you consider this :)
The original firmware can send special keys like volume and brightness up/down to my laptop, outside of the normal range of keys.
Figure out how it does that and then implement the same.
An interesting first step would be to capture Bluetooth traffic with the original firmware and see what it sends. Especially the HID descriptor, I think this is what I captured a while ago:
Bluetooth descriptor:
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x06, // Usage (Keyboard)
0xA1, 0x01, // Collection (Application)
0x05, 0x07, // Usage Page (Kbrd/Keypad)
0x19, 0xE0, // Usage Minimum (0xE0)
0x29, 0xE7, // Usage Maximum (0xE7)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x08, // Report Count (8)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x95, 0x05, // Report Count (5)
0x75, 0x01, // Report Size (1)
0x05, 0x08, // Usage Page (LEDs)
0x19, 0x01, // Usage Minimum (Num Lock)
0x29, 0x05, // Usage Maximum (Kana)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x95, 0x01, // Report Count (1)
0x75, 0x03, // Report Size (3)
0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x95, 0x06, // Report Count (6)
0x75, 0x08, // Report Size (8)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x65, // Logical Maximum (101)
0x05, 0x07, // Usage Page (Kbrd/Keypad)
0x19, 0x00, // Usage Minimum (0x00)
0x29, 0x65, // Usage Maximum (0x65)
0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
// 63 bytes
// best guess: USB HID Report Descriptor
With the original firmware 1.4 you can't cycle through custom LED themes. If you set up a custom theme and then switch another one you can't get back to your custom theme without using the app.
From what I can tell this is due to custom themes having id 128, and the LED firmware seems to cycle back to theme id 0 before reaching 128.
To fix this nicely we probably need to have our own LED firmware, which might be a while.
ISTR #dev-chat said that there's no wire for the MCU to read the voltage level, so this might go into the README as not possible.
Otherwise, I suggest these feature levels:
Hello hello!
The next cortex-m-rtfm is out. But it is a major rework, so I would like to propose a roadmap.
Short-term, I would like to release the current PRs (#76, #77, #78) as follow:
Long-term involves porting to cortex-m-rtfm 0.4
Going forward, the embedded WG is working on books and documentation
based on these newer crates. The porting effort is not easy, but I
hope clearer documentation can bring in more interest. I intend to
hook up an st-link v2, and if budget allows even get another AP1.
I would like this a lot, but I don't know if this is technically possible with this piece of hardware. Controlling individual leds would make a fun programmable toy, or it could bring a whole new set of off-screen indicators. Want this so bad that I'm willing to get into Rust and driver development for that to happen.
I know it was just announced, but wondering if we could have a tracking issue for what chipset it is, etc.
Due to me not yet fully understanding how macros and cfg
work some of the debug!
statements cause compilation warnings when built without semihosting on.
Need to understand how to deal with this properly and get rid of the warnings.
I would like to initiate reset to DFU without having to flip the keyboard and poke the reset pin. AIUI, booting with the Escape key down enters DFU mode, so I imagined binding a key-combo with Escape to reset the key MCU would do the job.
In hdhoang@13c9604
I have given the SCB to Keyboard
, then tried to write the reset request when processing Action::Reset
. Though the set_theme(3)
call worked, the keyboard went on working normally instead of resetting.
Some paths I would like to explore next:
Nikkelitous also said people normally reset MCU from the host side instead of requesting it to reset itself :)
Please advise me on how to implement this!
Would be good to have cursor control as one of the available options in function layers. This would be great when using the keyboard without a dedicated mouse.
At least for me LEDs are not working since this release: https://github.com/ah-/anne-key/releases/tag/2018-03-10-127-master-f4fe08f
Right now the KeyState struct in https://github.com/ah-/anne-key/blob/master/src/keymatrix.rs#L20 (which holds which physical keys are currently pressed) has two versions. One's a [bool] array, the other one is a manually packed bitset.
Really we should just have the packed version and use that for everything. This might require a bit of refactoring and cleanup though.
I'll add this to the travis test matrix. We have quite a few macOS users.
Caution We don't have any way to recover BLE fw yet, this might brick it?
BleOp::ConnectHost/SaveHost/DeleteHost
accepts a byte argument, but how well do values beyond 0-3 work?
We should document the messaging protocol a bit better, with basics and a few example messages.
Also that it uses 8400 not 115... as the baud rate on both usarts.
Would be pretty cool to be able to use the kb completely wired without having to switch to Bluetooth to change layout or lighting.
It would be nice to have some of the Tap Dance functionality.
When i used it first (formerly known as e.g. double tap action) i felt in love with this feature it basically allows you to give a key more than one 'action' like: When you press and release 'A' just type an 'a', but when you press and hold 'A' you'll get 'Shift' this is called ACTION_TAP_DANCE_DOUBLE in Tap Dance.
You can find more details in the docs.
Because of all the LTO all the code ends up in SYS_TICK and anne_key, which is great for getting the smallest binary but doesn't really tell you much if you're trying to keep it slim.
I tried running cargo bloat with --debug, but then the binary is just too big, so we'd need to either hack the linker file to fake more memory than the stm32l1 actually has, or somehow still build in release mode but disable LTO.
When I want to reduce or increase the brightness of the backlight if the obins app it not running keyboard is crashing on USB!
i'm on ubuntu 20.04 and tried both release and alpha version of firmware .
Sometimes the keyboard stops working for no reason in the middle of typing on linux ( a key gets stuck and repeats sending the last key multiple times for few seconds * on 1.14.7-alpha )
Going to try it on windows and I will update this.
upd 1: backlight is working fine on windows when obinskit is not running.
upd 2: keyboard seems to be working fine on windows, didnt face any problems yet.
( upd 1,2 , firmware is 1.14.7-alpha )
upd 3: thought this is the official firmware, closing the issue.
There is a Web USB flashing tool here: https://devanlai.github.io/webdfu/dfu-util/ that might help making it really easy to install our custom firmware. We could even have a landing page where you just go and click a few buttons to flash your Anne Pro, without needing to install anything besides Chrome.
However, when I tried to use the webdfu tool it didn't flash the firmware correctly and I had to use dfu-util to recover. I think it also showed the firmware size wrong.
Maybe it's possible to fix whatever bugs webdfu has and make it work?
We have a mostly working implementation of bluetooth pairing etc. Talking to the BT controller works, and I have managed to pair with my laptop.
It'd be nice to implement the full workflow, and control the LEDs upon entering BT setup mode, display the BTHostListQuery result, and use the same keymap as the original FW.
I would like to request that the ability to use the keyboard in a Grub menu/BIOS is added, for example being able to use the F10 (Via FN+0) to access the BIOS on boot up, initially as a feature operated via USB cable connection and then also via Bluetooth Connection at a future point in time (If Bluetooth functionality of this type is possible with this keyboard), currently I cannot use my Anne Pro as my main keyboard because I need to have use of the F1-F12 (And other) keys at boot up, thanks for the work that you are doing to expand the Anne Pro's features & making it more stable
Implement the necessary protocol bits. Especially probably handling larger message sizes.
Then somehow convert from the obins layout format (I think it's 2 bytes per key, one with the scancode for the base layer, one for fn layer) to the internal Action based format.
Think about how we want to handle Actions that don't have an obins scan code, like theme switching and layer activation.
And then check how we can persistently store keymaps, maybe in nvram/eeprom or in a special flash region?
It'd be really cool to have some visual feedback when the FN layers are active.
We could for example highlight the arrow keys in blue, and help a bit with knowing how keys are mapped.
The "delete", "insert" and "print screen" combinations do not seem to work for me, the others seem to be fine. Using the release from commit 79207b0 on Windows 10.
Keyboard
is always sending the HID report over BT and USB. Let's add an action to toggle the USB path.
Currently I have to disable the input device on host-side.
Motospeed ck-61 missing tilde and grave.
Can I use anne-key to fix my problem?
The stock firmware has the following locking functions:
Fn + LMeta
: WinlockAlt + Alt
: FnlockThese were often confusing and then removed in the 1.40.02 beta fw. But people who are using these features wouldn't complain on reddit or update to 1.40.02. We should support that use case somehow.
I think the Winlock implementation could be a mostly-transparent layer, where KeyIndex::LMeta
is mapped to No
action instead.
Fnlock could be LayerOn/Off/Toggle(FN)
.
I also remember a comment on reddit that Fn + Alt
is Altlock(?), where someone replied "learn something new everyday". Can anyone confirm?
Somehow support macros. I have never used keyboard macros before, so it might be worth looking at https://docs.qmk.fm/feature_macros.html to see how they do it. Usually QMK does things quite well.
Going forward, there will be a lot of docs PRs & commits. I will see if we can skip CI build and/or github release when only documentations are affected, under this whitelist
README.md
docs/*
There is a half-broken USB driver in https://github.com/ah-/anne-key/tree/master/src/usb.
Fix it up, and integrate it with the rest of the keyboard.
thx u
Looking at code I found that you are performing UB conversion from primitive to enum
Lines 10 to 35 in ac02810
#[repr(u8)]
#[non_exhaustive]
#[derive(Debug, Copy, Clone)]
pub enum MsgType {
Reserved = 0,
Error = 1,
System = 2,
Ack = 3,
Reboot = 4,
Macro = 5,
Ble = 6,
Keyboard = 7,
Keyup = 8,
Led = 9,
FwInfo = 10,
FwUp = 11,
CustomLed = 12,
CustomKey = 13,
}
impl From<u8> for MsgType {
#[inline]
fn from(b: u8) -> Self {
unsafe { transmute(b) }
}
}
You may argue "Hey, but there is an attribute", but in fact it doesn't work the way you expect and may produce panics in safe Rust:
I'd better to be replaced with num_derive
:
#[repr(u8)]
#[derive(Debug, Copy, Clone, FromPrimitive)]
pub enum MsgType {
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.