raspberrypi-ui / piwiz

First-run startup wizard
11 stars 15 forks source link

Publish specifications for automatic language detection #15

Closed probonopd closed 4 years ago

probonopd commented 4 years ago

The official Raspberry Pi keyboard can automatically tell the operating system the language, something all keyboards should have done since the introduction of USB.

Kudos to the genius at the Raspberry Pi Foundation who made this happen, finally. I only wish I could plug this keyboard into any computer system and have it just work.

How is it working, actually?

Please publish official specifications for the Raspberry Pi automatic language detection and the rationale behind it.

Some wild guesses: https://gist.github.com/probonopd/9646c69f876ff2b4b879aeb1c1cbc532

spl237 commented 4 years ago

There's a language code number embedded in each keyboard which can be queried via USB. This is used as an index into the kb_countries and kb_langs tables you have identified to select the appropriate regional settings. Nothing more to it than that, really!

probonopd commented 4 years ago

Can you confirm?

iProduct RPI Wired Keyboard <integer> Country Language Assumed timezone
None (default) GB en Europe/London
1 GB en Europe/London
2 FR fr Europe/Paris
3 ES es Europe/Madrid
4 US en America/New_York
5 DE de Europe/Berlin
6 IT it Europe/Rome
7 JP jp Asia/Tokyo
8 PT pt Europe/Lisbon
9 NO nn Europe/Oslo
10 SE se Europe/Stockholm
11 DK fi Europe/Helsinki
12 RU ru Europe/Moscow
13 TR tr Europe/Istanbul
14 IL he Europe/Jerusalem

Are the ints based on some standard? What about languages not covered here?

spl237 commented 4 years ago

Yes, that's what those three tables are for. There is no standard for this, and languages not covered in that table are not supported. It's a 4-bit field at present, so can only store 16 different codes. These cover the keyboards used in the majority of markets where Raspberry Pi is sold.

But I'm not sure how useful this will be to anyone else, as it would require other keyboard manufacturers to adopt our approach to embedding country codes, which makes manufacture more complex / expensive, and then other operating systems to adopt our approach to reading codes and making settings, neither of which is likely to happen - we are in the fortunate position of having control over both hardware manufacture and software, which means we can do this. Unless your name is "Microsoft" or "Apple", you probably can't...

probonopd commented 4 years ago

But I'm not sure how useful this will be to anyone else, as it would require other keyboard manufacturers to adopt our approach to embedding country codes

Yes - I am looking for a way to standardize this. Actually, I canot believe that this hasn't been done right from the beginning of the USB spec. Had you considered using the USB bCountryCode field?

probonopd commented 4 years ago

In the meantime, I'd already be happy if all Linuxes and BSDs could set the keyboard (and possibly system) language based on the Official Raspberry Pi keyboards.

spl237 commented 4 years ago

People tend not to buy the RPi keyboard for use on anything other than RPi; I can't see them being adopted as a generic PC keyboard, really. Although we wouldn't object to the additional sales, obviously...

I don't know for sure, because I wasn't heavily involved in the hardware design, but I suspect that bCountryCode is something that the keyboard OEMs already use for some reason of their own, hence it was easier to just customise the product code, as that is custom-set for us anyway.

probonopd commented 4 years ago

(Semi-OT)

People tend not to buy the RPi keyboard for use on anything other than RPi; I can't see them being adopted as a generic PC keyboard, really. Although we wouldn't object to the additional sales, obviously...

In fact, I have outfitted every of my computers with a RPi keyboard and mouse by now (and friends and family). Would not hesitate to recommend. I especially like the slim size and the built-in USB hub of the keyboard. So to whoever worked on the hardware, thank you.

probonopd commented 3 years ago

Hello @spl237 can you confirm that the Raspberry Pi 400 keyboard works identically regarding how it describes itself on USB? Thanks.

spl237 commented 3 years ago

No, it doesn't. For a Pi 400 keyboard, the value in /proc/device-tree/chosen/rpi-country-code is checked. Have a look at the get_pi_keyboard function in the source code for piwiz.

probonopd commented 3 years ago

Thanks @spl237.

rpi-country-code

You guys really don't feel like this should become a universally standardized thing not just limited to rpi, do you? ;-)

/proc/device-tree

I don't think I have this on FreeBSD... https://github.com/helloSystem/ (FreeBSD based) now configures everything (keyboard locale, system language, timezone) correctly using Rasperry Pi keyboards.