TeXitoi / keyseebee

KeySeeBee is a split ergo keyboard. It is only 2 PCB (so the name) with (almost) only SMD components on it. It's only a keyboard, no LED, no display, nothing more than keys and USB.
MIT License
317 stars 34 forks source link

Help with keyseebee keyberon firmware #10

Closed MangoIV closed 2 years ago

MangoIV commented 3 years ago

Hi! I've had a hard time understanding your code for the communication between the halves. Would you give me an insight on how it's happening? I'm especially curious about this function:

    #[task(binds = USART1, priority = 5, spawn = [handle_event], resources = [rx])]
    fn rx(c: rx::Context) {
        static mut BUF: [u8; 4] = [0; 4];

        if let Ok(b) = c.resources.rx.read() {
            BUF.rotate_left(1);
            BUF[3] = b;

            if BUF[3] == b'\n' {
                if let Ok(event) = de(&BUF[..]) {
                    c.spawn.handle_event(Some(event)).unwrap();
                }
            }
        }
    }

What exactly is written to and read from the Buffer? Thanks in advance :)

TeXitoi commented 3 years ago

The function is called (by the harware via an interruption) each time a character is ready to be read.

We get this character in the if let.

We push the character at the end of the buffer, removing the first character to make place.

If the last character is \n then our command is complete. We parse it and send the deserialized event to the layout handler.

TeXitoi commented 3 years ago

For the serialization of an event see the ser function. For the deserialization see the de function.

MangoIV commented 3 years ago

Thanks for your quick answer and sorry if the question is stupid. Now that I know what the functions are doing it's much easier on the eyes.. :D