Commit graph

126 commits

Author SHA1 Message Date
bunnie
11f9552b96 don't format key lookup tables 2024-01-14 22:53:45 +08:00
bunnie
a994cbd447 format services/keyboard
exceptions are made for the mappings/ modules, because they
are lookup tables and benefit from strict line-by-line ordering
with wide columns.
2024-01-14 22:24:08 +08:00
bunnie
680c8b88c7 fix missing init() methods in hosted mode emulation structures 2023-07-16 18:31:14 +08:00
Sean Cross
d4f4a100bb keyboard: install interrupt handler after ::new()
Signed-off-by: Sean Cross <sean@xobs.io>
2023-07-16 15:33:08 +08:00
wz
e08f4b89c5 Narrow down the exclude list to Apple PUA characters 2023-05-21 14:00:52 +03:00
wz
723cadaff0 Ignore key codes over 0xf000 on insert 2023-05-21 13:49:06 +03:00
Gianguido Sorà
523ec0ac80
services/keyboard: remove explicit early settings FLASH access
Use early_settings service.
2023-04-21 18:11:04 +02:00
bunnie
916ca1e11f expand key injection API.
this does mean your device is notably less secure if you're operating
with usb serial turned on, as a host can just inject arbitrary commands
into your device!
2023-04-16 02:23:59 +08:00
bunnie
51fe53bc83 fix #354
verified to address the issue at least in a simple test case

1) drop repeated keys instead of panic-unwrapping
2) reduce key repeat rate to something more sane
2023-04-04 00:06:59 +08:00
bunnie
02f9701546 make an explicit dvt feature to simplify flags 2022-12-08 17:42:12 +08:00
bunnie
4dd983bfc4 adjust security parameters for dvt build 2022-12-08 17:19:05 +08:00
Gianguido Sorà
8594c0ae14 chore: increment connection limit for keyboard
Needed for prefs restore
2022-11-02 17:57:06 +01:00
Gianguido Sorà
52578e7a3f feat: implement Display trait for keyboard::KeyMap 2022-11-02 17:56:41 +01:00
bunnie
67fc21fbdd harmonize hosted mode selection, but retain an explicit hosted flag
In general, hosted mode is assumed "by default" if the target
is not Xous. This allows packages to be built cleanly on command
lines that don't know to pass a --feature flag to specify a target.

However, an explicit "hosted" flag is still retained so that we
can confirm the build system intent. This saves us from the failure
mode that we thought we were building for target A, but accidentally
ommitted the flag, and instead we've been silently building for
"hosted" mode without any warning. The main consumer of the "hosted"
flag is now just the build.rs script inside of the utralib.
2022-10-25 17:21:02 +08:00
Jean-Pierre De Jesus DIAZ
6163414dd1
keyboard: Implement From instead of Into
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2022-10-12 15:38:35 +02:00
bunnie
4e40ae6c5d move from target selectors to feature selectors for back-ends
This will allow for e.g. xous on riscv32-imac but not a precursor
target, for example: by using feature selectors we get to have
a bigger range of targets that we support, such as for implementations
that haven't been upstreamed or have official target-triples.

The downsides are:

- patch override libraries don't absorb feature flags. so, for
example, the AES crate that is used to patch other crates won't
be aware of the target features without modifying the referencing
crates.

- features are normally meant to be additive, but target features
are mutually exclusive. The mutex is enforced by a check in
utralib that throws a panic on build if two targets are accidentally
selected at the same time.
2022-10-02 02:56:44 +08:00
bunnie
907ac038ff make keyboard observer send messages falliable
this is a partial work around for the status server queue
overflow problem on boot while handling user interactions
in the auto-update flow.
2022-07-19 04:08:39 +08:00
bunnie
e1d946a18d other items for keyboard layout backup/restore 2022-07-16 00:39:34 +08:00
bunnie
c46579117b add the "trusted init" check to hosted mode
need to debug a problem with the IMEF connecting/disconnecting
causing trusted init to fail when there is more than one
plugin in the system.
2022-06-18 01:30:49 +08:00
bunnie
9eec4436ea some comment bookkeeping and whitespace cleanup 2022-06-18 00:17:35 +08:00
bunnie
a91292509e only allow the observer of the key presses to be registered once 2022-06-18 00:15:00 +08:00
bunnie
6a583a5f0c the system as writ does not actually allocate an extra connection
Adjust the connection number back to 4. There isn't a connection
made for a keyboard backlight server anymore. This is necessary
for root key initialization to proceed.
2022-06-14 01:25:41 +08:00
bunnie
9760910991 do not renumber explicitly numbered enums
In general, if an enum has been explicitly numbered, it means
that there are crates that depend on the actual number assigned,
and changing them will break other crates.

This is done to allow for cross-compatibility reasons, for
example, going to a C FFI or to the standard library, where
we can't simply refer to a Rust crate to import the symbolic
enums and have the compiler figure out a consistent numbering
method.

Thus even though it's a bit "ugly", please assign only unused
numbers to new enums, and when old enums are retired, do not
re-use the number.
2022-06-14 01:23:48 +08:00
Gianguido Sorà
7985ad9a95 make the thing compile 2022-06-08 12:08:49 +02:00
Gianguido Sorà
c99ac0b3f5 Merge branch 'main' into gsora/backlight-on-keypress 2022-06-08 11:58:45 +02:00
bunnie
6f8590e4e7 fixup config flags on keyboard option 2022-06-08 04:37:08 +08:00
kelas
37d3e4973e don't block if the queue isn't empty 2022-06-07 19:21:43 +02:00
bunnie
ba874a653e make the rawserial path queue up to 128 characters if getchar() isn't live 2022-06-07 13:03:49 +08:00
bunnie
0d1244dc32 add a "rawserial" feature to the UART injection path 2022-06-06 14:10:31 +08:00
bunnie
62913a6560 meant to have keyboard injection as a feature. restore that. 2022-06-06 13:59:01 +08:00
bunnie
28a9d5bca7 add hooks so unsafe C-FFI calls can connect to the keyboard
- Opcodes are mapped to static IDs
- connection ID is now visible to someone who already owns
  the keyboard object. This can then be shared with the FFI
  interface to do calls to the keyboard server.
2022-06-06 03:56:05 +08:00
bunnie
72996bc453 add a facility for a simple blocking keyboard listener 2022-06-05 18:32:54 +08:00
Sean Cross
3ae9d8abf0 apps/services: remove xous::xous_main macro usage
This macro will be removed, since it is no longer necessary. Remove this
macro across the project and replace it with a standard `main()`
function.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-31 13:33:30 +08:00
Gianguido Sorà
9b58fc6bf8 first somewhat working code 2022-05-20 12:40:32 +02:00
bunnie
3bfdc238a0 add support for keymaps in HID
remaps keys based on the assumed keymap based on the user's
preference for the keyboard layout on the device.

So far, only dvorak and QWERTY are supported.
2022-05-17 16:41:08 +08:00
Gianguido Sorà
cb2a3b442d intermediate commit 2022-05-14 11:17:26 +02:00
bunnie
a6af300157 don't repeat the menu key if it is press-held 2022-03-27 00:19:55 +08:00
bunnie
5d754efc07 reduce debug verbosity on braille 2022-03-17 17:56:52 +08:00
bunnie
6d98c5db3d fix braille keyboard mappings 2022-03-17 15:20:20 +08:00
bunnie
bbccf1c2a7 reached a reasonable integration point for tts until braille protos are in
tts is working fairly well and much more stably, menus and ui
elements are wired up for tts.

just waiting for the latest braille keyboard pcb to come in and
then we'll be able to fire off some prototypes...
2022-03-11 19:08:39 +08:00
bunnie
b498669003 use NIST SP800-38F (AES-KWP) to wrap the system key for the PDDB
this is instead of our lolfail ECB-based method with a check block.
2022-02-03 18:24:06 +08:00
bunnie
3f61a298a5 helps to map in the key-up 2022-02-03 03:39:28 +08:00
bunnie
8080c1db22 split mappings into separate files, and add azerty/qwertz mappings
totally untested, i'm sure I messed up a character or two.

I'm sure there will be opinions. Pull requests welcome!
2022-02-03 03:26:18 +08:00
bunnie
30910dbd4f add keyboard layout setting and retention
Keyboard setting is "the one and only" exception to user settings
that are saved without encryption. This is because you need your
keyboard layout to be set in order for you to type your password.
Thus, this needed a bit of a special-case to handle its storage record.

We decided to lop off 1 page from the loader and have it store
the keyboard layout code.

Let's hope we can have the discipline to really just store that
one word of information and not later be like "gee wally, you have
a whoooole 4092 unused bytes of space we can cram unencrypted
user settings in, sure would be a waste to not put those use those".
2022-02-03 02:46:37 +08:00
bunnie
5c91645ede Merge branch 'i18n-jp' into bunnie-dev 2022-02-01 01:04:43 +08:00
bunnie
827888ccbb fix up the REFCOUNT on connections
Was doing disjoint loads and stores on an Atomic, really, should
be using the fetch_add, fetch_sub variants to be proper.

Didn't seem to impact anything but maybe there's a future version
of me that high fives me for doing this.
2022-01-31 23:13:10 +08:00
bunnie
f1dcbd17f1 fix hosted mode debug field missing 2022-01-30 15:35:44 +08:00
bunnie
25bccd9446 THE BALDEST YAK: keyboard injection now working
I wrote in a commit yesterday how there was no ROI on doing this
yet somehow I kept on doing it. I blame poor impulse control.

Turns out there was a series of race conditions and bugs that
caused this thing to "mostly work" on the first go at it but
really hard to debug and get very right.

1. Litex UART has a weird undocumented API. You advance the Rx
FIFO by writing `1` to the PENDING bit, and no other way. However,
you determine if there are any more characters to receive by
reading the EMPTY bit and seeing if it is 1. The previous method
wrote `1` to the PENDING bit and then used the PENDING bit to
see if a character was available, under the theory that the
PENDING bit would be set again if there was still a character.
This is somewhat true, except that the PENDING bit is set only
some amount of time later which is about comparable to a few
CPU instructions, so if you had a fast loop path the PENDING
bit would show as cleared and you'd exit, which would cause
no further interrupts to fire because the interrupt was
effecitvely not acknowledged.

This isn't written up anywhere but I figured this out by
just reading the source code for Litex UART and BIOS:
e8be391504/litex/soc/cores/uart.py (L264-L279)
ccd3ab17be/litex/soc/software/libbase/uart.c (L38-L44)

2. I had the Key Injector IP block in the `sys` domain, which
would have its clock cut when the CPU went to sleep, which would
cause input characters to disappear when the CPU went into power
saving. moving this to "always on" domain fixes that.

3. I had the UART PHY in the always on block (so you could
send or receive exactly one character), but not the
separate UART block (which contained the FIFOs).
The UART block would also go into power
savings, and this would cause FIFO entries to go missing.

4. Escape sequences get sent as a burst of characters. The Key Injector
originally did not have a FIFO of its own, so it would only
remember the *last* key of the sequence that was written, causing
some keys to be dropped occassionally. Adding a 16-deep FIFO
to the injector fixes this.

5. The code I had to read out the injector's results was designed with
the "strobe" bit (to indicate that the FIFO had characters) in the
same regsiter as the character itself. Thus the loop that 1. checked
if the fifo was empty then 2. read and forwarded the character
would actually perform two reads from the FIFO. However, this "mostly worked"
I think because the FIFO retains the last value that was written
even when it was empty, so if only one character was read at a time
everything was fine. It only didn't work when you stuffed two characters
in there, as you'd drop the first one. Reading the FIFO once and
then interpreting the code with a bitmask fixes this.

6. The escape sequences, in their full glory with no dropped characters,
required a refactored parsing routine, which I have now added.

7. backspace->delete mappings, the bane of computer engineers since 1960.

OK. very bald yak. Here I lay down the shears next to several
mooshi pillows stuffed with the finest Yak hair.
2022-01-28 15:17:47 +08:00
bunnie
ea31f54a79 console escape codes working better
just couldn't let it go. figured out the issue is a race condition
in how the Litex UARTs are constructed...I don't know how Litex
normally handles this kind of situation but they have this funky
construction where reading the fifo doesn't advance it, you have
to...clear the pending bit. I think it was meant to be a "clever"
thing that saves an instruction or something like that since you
always have to clear the pending bit.

Anyways, the previous incarnation of this loop checked to see
if the pending bit was set again and if it was it'd run back
and fetch another character. This turns out to be a bad idea
because the pending bit goes through a multireg and other stuff
before it's readable which means it has a lot of delay on it.
This leads to a race condition.

This version actually checks if the fifo is empty and if it isn't,
it reads the character *and* pumps the pending bit (because
the FIFO doesn't auto-advance when you read it, you have to clear
the pending bit).

This works a lot better, but it's not at all well documented how
this works and it's very hard to tell from reading the source code
because it's written using really fancy migen abstractions that
are also poorly documented and have a lot of cursed constructions.

Anyways. At least the console doesn't die now when you type
a control character, *but* you do have the problem that the
escape codes get mis-interpreted sometimes. If it really really
becomes important later on to fix that it would involve tracing
out the sequence of keys that arrive at InjectKey and figuring
out if things are coming out of order or what is triggering the
bad escape codes.
2022-01-28 04:21:40 +08:00
bunnie
9cfffb18e9 some minor fixes to the console debug system to make it more consistent
there is still some mysterious problem involving a race condition
of the raw hardware console UART Rx path deciding it doesn't want
to report new characters anymore to the interrupt handler that
is triggered when multi-byte sequences are shoved down the
pipe. So long as you're typing simple commands it's fine, but
escape sequences tend to lock things up. I don't think there's
enough ROI to continue investigating this facility.
2022-01-28 03:36:14 +08:00