Giter Site home page Giter Site logo

ah- / anne-key Goto Github PK

View Code? Open in Web Editor NEW
568.0 50.0 32.0 18.24 MB

Firmware for Anne Pro Keyboard written in Rust

License: Apache License 2.0

GDB 0.37% Rust 92.86% Logos 0.37% Shell 0.34% Python 5.13% Makefile 0.93%
firmware anne keyboard rust mechanical-keyboard embedded

anne-key's People

Contributors

ah- avatar fcoury avatar ghostwheel avatar hdhoang avatar mveerd avatar offpics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

anne-key's Issues

Pair with obins Android app

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.

cargo bloat has broken

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.

Support uploading custom LED themes in Keyboard stm32

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.

Power management: Use wakeup instead of polling

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?

Frequent key repetition while typing

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).

[Feature request] Using key lighting programmatically.

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 :)

Figure out how to send special keycodes over bluetooth

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

Cycle through custom LED themes

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.

[feature] battery indicator

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:

  • Low battery indicator (need coordinating with led theme)
  • Led battery meter
  • Awesome level: BLE reporting (need coordinating with BLE chip?)

port to RTFM 0.4

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:

  • fork ykomatsu's PR into a protected branch under either of our accounts
  • rebase and publish releases at each step

Long-term involves porting to cortex-m-rtfm 0.4

  • Fix the crate into 2018 edition (a requirement for rtfm 0.4, and can be started now)
  • Wait for svd2rust 0.14
  • Wait for the next stm32l1 made with svd2rust 0.14
  • Bump stm32l151-hal
  • Rework with 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.

[Question] Is it possible to control individual leds over usb?

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.

Anne Pro 2 support?

I know it was just announced, but wondering if we could have a tracking issue for what chipset it is, etc.

USB mode issues

  1. USB mode only works if I reset the board while it's plugged in, otherwise Windows fails to configure it.
  2. Every key I press is duplicated (I type w, it spews out ww)

Clean build

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.

[feature] reset to DFU mode in software

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:

  • maybe I need to write to AIRCR differently?
  • maybe I need to move SCB base back to bootloader's position so that the CPU starts there after reset?

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!

[feature] Support for cursor control.

Support for cursor control

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.

[dev] macOS CI

I'll add this to the travis test matrix. We have quite a few macOS users.

[feature] Remember more than 4 hosts

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?

Document Message Protocol

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.

[Feature] Implementation of QMK's Tap Dance

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.

Run cargo bloat without LTO

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.

Keyboard USB problems with ubuntu.

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.

Flashing with WebUSB?

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?

Implement Bluetooth Setup Mode

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.

[Feature] Support for Grub/BIOS control

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

Support uploading custom keyboard layouts

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?

Change theme when certain layers are active

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.

FN layer issues

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.

allow disabling USB

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.

[compatibilty] Fnlock & Winlock

The stock firmware has the following locking functions:

  • Fn + LMeta: Winlock
  • Alt + Alt: Fnlock

These 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?

Transmuting enums is UB

Looking at code I found that you are performing UB conversion from primitive to enum

anne-key/src/protocol.rs

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) }
}
}

#[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:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=dd880f555dff38824b094dd8dec2f6f2

I'd better to be replaced with num_derive:

#[repr(u8)]
#[derive(Debug, Copy, Clone, FromPrimitive)]
pub enum MsgType {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.