clean code with use of library maked : ADB
This commit is contained in:
+89
-6
@@ -1,6 +1,89 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
lib/adb/logo-specifications.md
|
||||
.vscode/
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
.DS_Store
|
||||
|
||||
### KiCad ###
|
||||
# For PCBs designed using KiCad: http://www.kicad-pcb.org/
|
||||
# Format documentation: http://kicad-pcb.org/help/file-formats/
|
||||
|
||||
# Temporary files
|
||||
*.000
|
||||
*.bak
|
||||
*.bck
|
||||
*.kicad_pcb-bak
|
||||
*~
|
||||
_autosave-*
|
||||
*.tmp
|
||||
*-rescue.lib
|
||||
*-save.pro
|
||||
*-save.kicad_pcb
|
||||
|
||||
# Netlist files (exported from Eeschema)
|
||||
*.net
|
||||
|
||||
# Autorouter files (exported from Pcbnew)
|
||||
*.dsn
|
||||
*.ses
|
||||
|
||||
# Exported BOM files
|
||||
*.xml
|
||||
*.csv
|
||||
|
||||
### KiCad Patch ###
|
||||
rescue-backup/
|
||||
|
||||
*.tsv
|
||||
bom/
|
||||
|
||||
# Gerber export output
|
||||
out/
|
||||
|
||||
### Linux ###
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# End of https://www.gitignore.io/api/kicad,linux
|
||||
|
||||
.pio/
|
||||
Submodule
+1
Submodule lib/ADB-pour-Framework-Arduino added at b3a104781e
-46
@@ -1,46 +0,0 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
@@ -0,0 +1,44 @@
|
||||
# Spécifications du logo ADB2USB
|
||||
|
||||
## Concept
|
||||
Un logo représentant la conversion des périphériques Apple Desktop Bus (ADB) vers USB, combinant des éléments vintage Apple et la modernité.
|
||||
|
||||
## Éléments principaux
|
||||
1. **Symbole ADB**: Représentation stylisée du connecteur Mini-DIN 4 broches ADB
|
||||
2. **Flèche de transition**: Indiquant la conversion d'une technologie à l'autre
|
||||
3. **Symbole USB**: Icône USB standard ou connecteur USB-A stylisé
|
||||
4. **Carte STM32**: Petite silhouette d'une carte STM32 (optionnelle)
|
||||
|
||||
## Palette de couleurs
|
||||
- **ADB (côté gauche)**: Couleurs vintage Apple
|
||||
- Beige: #E0D7C5 (couleur des premiers Macintosh)
|
||||
- Rainbow Apple: Utiliser des éléments du logo Apple arc-en-ciel
|
||||
- **USB (côté droit)**: Couleurs modernes
|
||||
- Bleu: #3B7BBF (bleu USB standard)
|
||||
- Blanc: #FFFFFF
|
||||
- **Accent**: Rouge STM32 (#EE3424) pour la partie microcontrôleur
|
||||
|
||||
## Style et composition
|
||||
- Style épuré et légèrement rétro
|
||||
- Disposition horizontale avec ADB à gauche, USB à droite
|
||||
- Polices suggérées:
|
||||
- "Chicago" ou "Geneva" (polices vintage Apple) pour la partie ADB
|
||||
- "Source Sans Pro" ou "Helvetica Neue" pour la partie USB
|
||||
|
||||
## Variantes à créer
|
||||
1. **Logo complet**: Tous les éléments avec texte "ADB2USB"
|
||||
2. **Icône seule**: Version sans texte pour favicon ou petits affichages
|
||||
3. **Version monochrome**: Pour impression ou situations à contraste limité
|
||||
|
||||
## Dimensions recommandées
|
||||
- Logo principal: 2000x800px (ratio 2.5:1)
|
||||
- Icône: 512x512px (ratio 1:1)
|
||||
- Prévoir des versions pour GitHub, Twitter et autres plateformes sociales
|
||||
|
||||
## Exemples d'inspiration
|
||||
- Logo Apple rétro (1977-1998)
|
||||
- Logos d'interface HID standards
|
||||
- Design minimaliste des logos de projets open source
|
||||
|
||||
## Production
|
||||
Créer le logo en format vectoriel (SVG) pour permettre un redimensionnement sans perte de qualité, puis exporter en PNG pour différentes utilisations.
|
||||
+4
-3
@@ -50,12 +50,13 @@ build_flags =
|
||||
debug_tool = stlink
|
||||
upload_protocol = stlink
|
||||
monitor_speed = 115200
|
||||
|
||||
|
||||
lib_deps =
|
||||
https://github.com/electron-rare/ADB-pour-Framework-Arduino
|
||||
; electronrare/ADB @ ^1.0.0
|
||||
[env:native]
|
||||
platform = native
|
||||
build_flags =
|
||||
-D USBCON
|
||||
-D USBD_USE_HID_COMPOSITE
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
test_build_project_src = true
|
||||
test_build_src = true
|
||||
@@ -1,173 +0,0 @@
|
||||
#ifndef ADB_h
|
||||
#define ADB_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define ADB_DATA_PIN PB4
|
||||
#define ADB_DATA_PORT GPIOB
|
||||
#define ADB_DATA_PIN_NO 4
|
||||
#define ADB_WRITE(bit) digitalWrite(ADB_DATA_PIN, bit)
|
||||
#define ADB_READ() (digitalRead(ADB_DATA_PIN))
|
||||
|
||||
#define ADB_ADDRESS(addr) (addr << 4)
|
||||
#define ADB_REGISTER(reg) (reg)
|
||||
#define ADB_CMD_TALK (0b11 << 2)
|
||||
#define ADB_CMD_LISTEN (0b10 << 2)
|
||||
#define ADB_CMD_FLUSH (0b01 << 2)
|
||||
|
||||
#define ADB_ADDR_KEYBOARD 2
|
||||
#define ADB_ADDR_MOUSE 3
|
||||
|
||||
#define ADB_BIT_ERROR 0xFF
|
||||
|
||||
// Reset: signal low for 3 ms.
|
||||
static void adb_reset() {
|
||||
ADB_WRITE(LOW);
|
||||
delayMicroseconds(3000);
|
||||
ADB_WRITE(HIGH);
|
||||
}
|
||||
|
||||
// Attention: signal low for 800 μs.
|
||||
static void adb_attention() {
|
||||
ADB_WRITE(LOW);
|
||||
delayMicroseconds(800);
|
||||
ADB_WRITE(HIGH);
|
||||
}
|
||||
|
||||
// Sync: signal high for 70 μs.
|
||||
static void adb_sync() {
|
||||
ADB_WRITE(HIGH);
|
||||
delayMicroseconds(70);
|
||||
ADB_WRITE(LOW);
|
||||
}
|
||||
|
||||
// Send a single on ADB_DATA_PIN.
|
||||
// '0' if bit == 0x0: write 65 μs LOW, 35 μs HIGH.
|
||||
// '1' if bit >= 0x1: write 35 μs LOW, 65 μs HIGH.
|
||||
static void adb_write_bit(uint16_t bit) {
|
||||
if (bit) { // '1' bit
|
||||
ADB_WRITE(LOW);
|
||||
delayMicroseconds(35);
|
||||
|
||||
ADB_WRITE(HIGH);
|
||||
delayMicroseconds(65);
|
||||
}
|
||||
else { // '0' bit
|
||||
ADB_WRITE(LOW);
|
||||
delayMicroseconds(65);
|
||||
|
||||
ADB_WRITE(HIGH);
|
||||
delayMicroseconds(35);
|
||||
}
|
||||
}
|
||||
|
||||
// Send `length` least significant bits from `bits`,
|
||||
// starting with the most significant bit.
|
||||
static void adb_write_bits(uint16_t bits, uint8_t length) {
|
||||
uint16_t mask = 1 << (length - 1);
|
||||
while (mask) {
|
||||
adb_write_bit(bits & mask);
|
||||
mask >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Like adb_write_bits, but add start and stop bits
|
||||
static void adb_write_data_packet(uint16_t bits, uint8_t length) {
|
||||
adb_write_bit(1);
|
||||
adb_write_bits(bits, length);
|
||||
adb_write_bit(0);
|
||||
}
|
||||
|
||||
// Send the '0' stop bit, and listen for an SRQ.
|
||||
// ``If a device in need of service issues a service request,
|
||||
// it must do so within the 65 μs of the Stop Bit’s low time
|
||||
// and maintain the line low for a total of 300 μs.''
|
||||
// Returns true if there was an SRQ.
|
||||
static bool adb_stop_bit_srq_listen() {
|
||||
adb_write_bit(0);
|
||||
// TODO: Properly handle SRQ, currently waits it out:
|
||||
auto time_end_stop_bit = micros();
|
||||
while (ADB_READ() == LOW && micros() - time_end_stop_bit < 300 - 35) { // TODO: does it make sense to timeout?
|
||||
delayMicroseconds(5);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Write a command to the bus.
|
||||
void adb_write_command(uint8_t command_byte) {
|
||||
adb_attention();
|
||||
adb_sync();
|
||||
adb_write_bits((uint16_t)command_byte, 8);
|
||||
adb_stop_bit_srq_listen(); // TODO: Handle the SRQ
|
||||
}
|
||||
|
||||
// Stop-to-start time: period of 140 - 260 μs before device's
|
||||
// response when the bus is held high.
|
||||
// Returns: true if the response is starting, false if timeout
|
||||
static bool adb_wait_tlt(bool response_expected) {
|
||||
ADB_WRITE(HIGH);
|
||||
delayMicroseconds(140);
|
||||
uint8_t i = 0;
|
||||
while (ADB_READ() == HIGH && i < 240 && response_expected) {
|
||||
delayMicroseconds(1);
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Read a single bit from the bus.
|
||||
static uint8_t adb_read_bit() {
|
||||
auto time_start = micros();
|
||||
|
||||
while (ADB_READ() == LOW) {
|
||||
// devices need to stick to 30% precision, 65 * 1.3 = 85 μs
|
||||
// if this time is exceeded assume timeout
|
||||
if (micros() - time_start > 85)
|
||||
return ADB_BIT_ERROR;
|
||||
}
|
||||
auto low_time = micros() - time_start;
|
||||
|
||||
while (ADB_READ() == HIGH) {
|
||||
// devices need to stick to 30% precision, 65 * 1.3 = 85 μs
|
||||
// if this time is exceeded assume timeout
|
||||
if (micros() - time_start - low_time > 85)
|
||||
return ADB_BIT_ERROR;
|
||||
}
|
||||
auto high_time = micros() - time_start - low_time;
|
||||
|
||||
return (low_time < high_time) ? 0x1 : 0x0;
|
||||
}
|
||||
|
||||
// Read `length` bits from the bus into `buffer`.
|
||||
bool adb_read_data_packet(uint16_t* buffer, uint8_t length)
|
||||
{
|
||||
if (adb_read_bit() != 0x1) { // start bit should equal to '1'
|
||||
return false;
|
||||
}
|
||||
|
||||
*buffer = 0;
|
||||
for (uint8_t i = 0; i < length; i++)
|
||||
{
|
||||
uint8_t current_bit = adb_read_bit();
|
||||
if (current_bit == ADB_BIT_ERROR) {
|
||||
return false;
|
||||
}
|
||||
*buffer <<= 1;
|
||||
*buffer |= current_bit;
|
||||
}
|
||||
|
||||
/* uint8_t stop_bit = */ adb_read_bit(); // should equal to '0'
|
||||
return true;
|
||||
}
|
||||
|
||||
void adb_init() {
|
||||
pinMode(ADB_DATA_PIN, OUTPUT_OPEN_DRAIN);
|
||||
ADB_WRITE(HIGH);
|
||||
|
||||
while (ADB_READ() == LOW); // wait for the bus
|
||||
|
||||
adb_reset();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
#ifndef ADB_DEVICES_h
|
||||
#define ADB_DEVICES_h
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "adb.h"
|
||||
#include "hid_keyboard.h"
|
||||
#include "adb_structures.h"
|
||||
|
||||
#define ADB_POLL_DELAY 5
|
||||
|
||||
adb_data<adb_kb_modifiers> adb_keyboard_read_modifiers(bool* error) {
|
||||
adb_data<adb_kb_modifiers> modifiers = {0};
|
||||
adb_write_command(ADB_CMD_TALK | ADB_ADDRESS(ADB_ADDR_KEYBOARD) | ADB_REGISTER(2));
|
||||
adb_wait_tlt(true);
|
||||
*error = !adb_read_data_packet(&modifiers.raw, 16);
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
adb_data<adb_kb_keypress> adb_keyboard_read_key_press(bool* error) {
|
||||
adb_data<adb_kb_keypress> key_press = {0};
|
||||
adb_write_command(ADB_CMD_TALK | ADB_ADDRESS(ADB_ADDR_KEYBOARD) | ADB_REGISTER(0));
|
||||
adb_wait_tlt(true);
|
||||
*error = !adb_read_data_packet(&key_press.raw, 16);
|
||||
return key_press;
|
||||
}
|
||||
|
||||
adb_data<adb_register3> adb_device_read_register3(uint8_t addr, bool* error) {
|
||||
adb_data<adb_register3> reg3 = {0};
|
||||
adb_write_command(ADB_CMD_TALK | ADB_ADDRESS(addr) | ADB_REGISTER(3));
|
||||
adb_wait_tlt(true);
|
||||
*error = !adb_read_data_packet(®3.raw, 16);
|
||||
return reg3;
|
||||
}
|
||||
|
||||
|
||||
bool adb_device_update_register3(uint8_t addr, adb_data<adb_register3> new_reg3, uint16_t mask, bool* error) {
|
||||
// Read the initial value
|
||||
adb_data<adb_register3> reg3 = adb_device_read_register3(addr, error);
|
||||
if (*error) return false;
|
||||
delay(ADB_POLL_DELAY);
|
||||
|
||||
// Apply the change
|
||||
reg3.raw = (reg3.raw & ~mask) | (new_reg3.raw & mask);
|
||||
|
||||
// Write the new value
|
||||
adb_write_command(ADB_CMD_LISTEN | ADB_ADDRESS(addr) | ADB_REGISTER(3));
|
||||
adb_wait_tlt(false);
|
||||
adb_write_data_packet(reg3.raw, 16);
|
||||
delay(ADB_POLL_DELAY);
|
||||
|
||||
// Read the current value
|
||||
reg3 = adb_device_read_register3(addr, error);
|
||||
if (*error) return false;
|
||||
|
||||
// Check if update worked, return true
|
||||
if ((reg3.raw & mask) == (new_reg3.raw & mask))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void adb_keyboard_write_leds(bool scroll, bool caps, bool num) {
|
||||
adb_data<adb_kb_modifiers> modifiers = {0};
|
||||
modifiers.data.led_scroll = !scroll;
|
||||
modifiers.data.led_caps = !caps;
|
||||
modifiers.data.led_num = !num;
|
||||
|
||||
adb_write_command(ADB_CMD_LISTEN | ADB_ADDRESS(ADB_ADDR_KEYBOARD) | ADB_REGISTER(2));
|
||||
adb_wait_tlt(false);
|
||||
adb_write_data_packet(modifiers.raw, 16);
|
||||
}
|
||||
|
||||
adb_data<adb_mouse_data> adb_mouse_read_data(bool* error) {
|
||||
adb_data<adb_mouse_data> mouse_data = {0};
|
||||
adb_write_command(ADB_CMD_TALK | ADB_ADDRESS(ADB_ADDR_MOUSE) | ADB_REGISTER(0));
|
||||
adb_wait_tlt(true);
|
||||
*error = !adb_read_data_packet(&mouse_data.raw, 16);
|
||||
return mouse_data;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,74 +0,0 @@
|
||||
#ifndef ADB_STRUCTURES_h
|
||||
#define ADB_STRUCTURES_h
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define KEY_POWER 0x66
|
||||
|
||||
#define ADB_KEY_POWER_DOWN 0x7F7F
|
||||
#define ADB_KEY_POWER_UP 0xFFFF
|
||||
|
||||
#define ADB_KEY_LEFT_SHIFT 0x38
|
||||
#define ADB_KEY_RIGHT_SHIFT 0x7B
|
||||
#define ADB_KEY_LEFT_CONTROL 0x36
|
||||
#define ADB_KEY_RIGHT_CONTROL 0x7D
|
||||
#define ADB_KEY_LEFT_OPTION 0x3A
|
||||
#define ADB_KEY_RIGHT_OPTION 0x7C
|
||||
#define ADB_KEY_LEFT_COMMAND 0x37
|
||||
#define ADB_KEY_RIGHT_COMMAND 0x37
|
||||
#define ADB_KEY_CAPS_LOCK 0x39
|
||||
#define ADB_KEY_NUM_LOCK 0x47
|
||||
|
||||
// Convert axis from 7b 2's complement to int8_t
|
||||
#define ADB_MOUSE_CONV_AXIS(x) (int8_t)(x << 1)
|
||||
|
||||
struct adb_kb_keypress {
|
||||
uint8_t key1 : 7;
|
||||
bool released1 : 1;
|
||||
uint8_t key0 : 7;
|
||||
bool released0 : 1;
|
||||
};
|
||||
|
||||
struct adb_kb_modifiers {
|
||||
// Only on Apple Extended Keyboard:
|
||||
bool led_num : 1; // 0, ditto
|
||||
bool led_caps : 1; // 1, ditto
|
||||
bool led_scroll : 1; // 2, changeable with `listen' command
|
||||
uint8_t reserved1 : 3; // 5 – 3
|
||||
bool scroll_lock : 1; // 6
|
||||
bool num_lock : 1; // 7
|
||||
// Apple Standard Keyboard:
|
||||
bool command : 1; // 8
|
||||
bool option : 1; // 9
|
||||
bool shift : 1; // 10
|
||||
bool control : 1; // 11
|
||||
bool reset : 1; // 12
|
||||
bool caps_lock : 1; // 13
|
||||
bool backspace : 1; // 14
|
||||
uint8_t reserved0 : 1; // 15
|
||||
};
|
||||
|
||||
struct adb_mouse_data {
|
||||
uint8_t x_offset : 7; // 6 - 0
|
||||
uint8_t reserved0 : 1; // 7
|
||||
uint8_t y_offset : 7; // 14 - 8
|
||||
bool button : 1; // 15
|
||||
};
|
||||
|
||||
// Contains device info and params
|
||||
struct adb_register3 {
|
||||
uint8_t device_handler_id : 8;
|
||||
uint8_t device_address : 4;
|
||||
uint8_t reserved1 : 1; // must be 0
|
||||
uint8_t srq_enable : 1;
|
||||
uint8_t exceptional_event : 1; // device specific, always 1 if not used
|
||||
uint8_t reserved0 : 1; // must be 0
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
union adb_data {
|
||||
uint16_t raw;
|
||||
T data;
|
||||
};
|
||||
|
||||
#endif
|
||||
+13
-24
@@ -1,7 +1,6 @@
|
||||
#include "hid_keyboard.h"
|
||||
#include "usbd_hid_composite_if.h"
|
||||
#include <Arduino.h>
|
||||
#include "keymap.h"
|
||||
|
||||
void hid_keyboard_init()
|
||||
{
|
||||
@@ -30,31 +29,31 @@ void hid_keyboard_send_report(hid_key_report* report)
|
||||
|
||||
bool hid_keyboard_set_keys_from_adb_register(
|
||||
hid_key_report* report, adb_data<adb_kb_keypress> key_press) {
|
||||
// Power button is a special case, residing in both octets:
|
||||
if (key_press.raw == ADB_KEY_POWER_DOWN)
|
||||
// Power button est un cas spécial, présent dans les deux octets:
|
||||
if (key_press.raw == ADBKey::KeyCode::POWER_DOWN)
|
||||
return hid_keyboard_update_key_in_report(report, KEY_POWER, false);
|
||||
else if (key_press.raw == ADB_KEY_POWER_UP)
|
||||
else if (key_press.raw == ADBKey::KeyCode::POWER_UP)
|
||||
return hid_keyboard_update_key_in_report(report, KEY_POWER, true);
|
||||
|
||||
// Other keys:
|
||||
// Autres touches:
|
||||
bool report_changed = false;
|
||||
// Higher octet key:
|
||||
uint8_t key0 = key_press.data.key0;
|
||||
if (adb_keymap_is_modifier(key0))
|
||||
if (ADBKeymap::isModifier(key0))
|
||||
report_changed = hid_keyboard_update_modifier_in_report(
|
||||
report, key0, key_press.data.released0);
|
||||
else
|
||||
report_changed = hid_keyboard_update_key_in_report(
|
||||
report, adb_keycode_to_hid[key0], key_press.data.released0);
|
||||
report, ADBKeymap::toHID(key0), key_press.data.released0);
|
||||
|
||||
// Lower octet key:
|
||||
uint8_t key1 = key_press.data.key1;
|
||||
if (adb_keymap_is_modifier(key1))
|
||||
if (ADBKeymap::isModifier(key1))
|
||||
report_changed = hid_keyboard_update_modifier_in_report(
|
||||
report, key1, key_press.data.released1) || report_changed;
|
||||
else
|
||||
report_changed = hid_keyboard_update_key_in_report(
|
||||
report, adb_keycode_to_hid[key1], key_press.data.released1) || report_changed;
|
||||
report, ADBKeymap::toHID(key1), key_press.data.released1) || report_changed;
|
||||
|
||||
return report_changed;
|
||||
}
|
||||
@@ -78,27 +77,17 @@ bool hid_keyboard_update_key_in_report(hid_key_report* report, uint8_t hid_keyco
|
||||
}
|
||||
|
||||
bool hid_keyboard_update_modifier_in_report(hid_key_report* report, uint8_t adb_keycode, bool released) {
|
||||
auto put_key = [released, report](uint8_t mask) mutable {
|
||||
// no change if the modifier is already set
|
||||
uint8_t mask = ADBKeymap::getModifierMask(adb_keycode);
|
||||
if (mask == 0) return false;
|
||||
|
||||
// No change if the modifier is already set
|
||||
if (released == !(report->modifiers & mask)) return false;
|
||||
|
||||
// flip the modifier
|
||||
// Flip the modifier
|
||||
if (!released) report->modifiers |= mask;
|
||||
else report->modifiers &= ~mask;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
if (adb_keycode == ADB_KEY_LEFT_SHIFT) return put_key(KEY_MOD_LSHIFT);
|
||||
if (adb_keycode == ADB_KEY_RIGHT_SHIFT) return put_key(KEY_MOD_RSHIFT);
|
||||
if (adb_keycode == ADB_KEY_LEFT_CONTROL) return put_key(KEY_MOD_LCTRL);
|
||||
if (adb_keycode == ADB_KEY_RIGHT_CONTROL) return put_key(KEY_MOD_RCTRL);
|
||||
if (adb_keycode == ADB_KEY_LEFT_OPTION) return put_key(KEY_MOD_LALT);
|
||||
if (adb_keycode == ADB_KEY_RIGHT_OPTION) return put_key(KEY_MOD_RALT);
|
||||
if (adb_keycode == ADB_KEY_LEFT_COMMAND) return put_key(KEY_MOD_LMETA);
|
||||
if (adb_keycode == ADB_KEY_RIGHT_COMMAND) return put_key(KEY_MOD_RMETA);
|
||||
|
||||
return false; // unreachable
|
||||
}
|
||||
|
||||
// Returns true if after execution the key is in the report
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef HID_KEYBOARD_h
|
||||
#define HID_KEYBOARD_h
|
||||
|
||||
#include <cstdint>
|
||||
#include "adb_structures.h"
|
||||
#include <cstdint> // Ajout pour définir uint8_t
|
||||
#include "adb.h" // Inclusion de la bibliothèque ADB
|
||||
|
||||
#define KEY_REPORT_KEYS_COUNT 6
|
||||
|
||||
|
||||
@@ -1,274 +0,0 @@
|
||||
// https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf, pp. 53
|
||||
// adapted from https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2
|
||||
|
||||
#ifndef HID_TABLES_h
|
||||
#define HID_TABLES_h
|
||||
|
||||
#define KEY_MOD_LCTRL 0x01
|
||||
#define KEY_MOD_LSHIFT 0x02
|
||||
#define KEY_MOD_LALT 0x04
|
||||
#define KEY_MOD_LMETA 0x08
|
||||
#define KEY_MOD_RCTRL 0x10
|
||||
#define KEY_MOD_RSHIFT 0x20
|
||||
#define KEY_MOD_RALT 0x40
|
||||
#define KEY_MOD_RMETA 0x80
|
||||
|
||||
/**
|
||||
* 0x00 if no key pressed.
|
||||
*
|
||||
* If more than N keys are pressed, the HID reports
|
||||
* KEY_ERR_OVF in all slots to indicate this condition.
|
||||
*/
|
||||
|
||||
#define KEY_NONE 0x00 // No key pressed
|
||||
#define KEY_ERR_OVF 0x01 // Keyboard Error Roll Over - used for all slots if too many keys are pressed ("Phantom key")
|
||||
// 0x02 // Keyboard POST Fail
|
||||
// 0x03 // Keyboard Error Undefined
|
||||
#define KEY_A 0x04 // Keyboard a and A
|
||||
#define KEY_B 0x05 // Keyboard b and B
|
||||
#define KEY_C 0x06 // Keyboard c and C
|
||||
#define KEY_D 0x07 // Keyboard d and D
|
||||
#define KEY_E 0x08 // Keyboard e and E
|
||||
#define KEY_F 0x09 // Keyboard f and F
|
||||
#define KEY_G 0x0a // Keyboard g and G
|
||||
#define KEY_H 0x0b // Keyboard h and H
|
||||
#define KEY_I 0x0c // Keyboard i and I
|
||||
#define KEY_J 0x0d // Keyboard j and J
|
||||
#define KEY_K 0x0e // Keyboard k and K
|
||||
#define KEY_L 0x0f // Keyboard l and L
|
||||
#define KEY_M 0x10 // Keyboard m and M
|
||||
#define KEY_N 0x11 // Keyboard n and N
|
||||
#define KEY_O 0x12 // Keyboard o and O
|
||||
#define KEY_P 0x13 // Keyboard p and P
|
||||
#define KEY_Q 0x14 // Keyboard q and Q
|
||||
#define KEY_R 0x15 // Keyboard r and R
|
||||
#define KEY_S 0x16 // Keyboard s and S
|
||||
#define KEY_T 0x17 // Keyboard t and T
|
||||
#define KEY_U 0x18 // Keyboard u and U
|
||||
#define KEY_V 0x19 // Keyboard v and V
|
||||
#define KEY_W 0x1a // Keyboard w and W
|
||||
#define KEY_X 0x1b // Keyboard x and X
|
||||
#define KEY_Y 0x1c // Keyboard y and Y
|
||||
#define KEY_Z 0x1d // Keyboard z and Z
|
||||
|
||||
#define KEY_1 0x1e // Keyboard 1 and !
|
||||
#define KEY_2 0x1f // Keyboard 2 and @
|
||||
#define KEY_3 0x20 // Keyboard 3 and #
|
||||
#define KEY_4 0x21 // Keyboard 4 and $
|
||||
#define KEY_5 0x22 // Keyboard 5 and %
|
||||
#define KEY_6 0x23 // Keyboard 6 and ^
|
||||
#define KEY_7 0x24 // Keyboard 7 and &
|
||||
#define KEY_8 0x25 // Keyboard 8 and *
|
||||
#define KEY_9 0x26 // Keyboard 9 and (
|
||||
#define KEY_0 0x27 // Keyboard 0 and )
|
||||
|
||||
#define KEY_ENTER 0x28 // Keyboard Return (ENTER)
|
||||
#define KEY_ESC 0x29 // Keyboard ESCAPE
|
||||
#define KEY_BACKSPACE 0x2a // Keyboard DELETE (Backspace)
|
||||
#define KEY_TAB 0x2b // Keyboard Tab
|
||||
#define KEY_SPACE 0x2c // Keyboard Spacebar
|
||||
#define KEY_MINUS 0x2d // Keyboard - and _
|
||||
#define KEY_EQUAL 0x2e // Keyboard = and +
|
||||
#define KEY_LEFTBRACE 0x2f // Keyboard [ and {
|
||||
#define KEY_RIGHTBRACE 0x30 // Keyboard ] and }
|
||||
#define KEY_BACKSLASH 0x31 // Keyboard \ and |
|
||||
#define KEY_HASHTILDE 0x32 // Keyboard Non-US # and ~
|
||||
#define KEY_SEMICOLON 0x33 // Keyboard ; and :
|
||||
#define KEY_APOSTROPHE 0x34 // Keyboard ' and "
|
||||
#define KEY_GRAVE 0x35 // Keyboard ` and ~
|
||||
#define KEY_COMMA 0x36 // Keyboard , and <
|
||||
#define KEY_DOT 0x37 // Keyboard . and >
|
||||
#define KEY_SLASH 0x38 // Keyboard / and ?
|
||||
#define KEY_CAPSLOCK 0x39 // Keyboard Caps Lock
|
||||
|
||||
#define KEY_F1 0x3a // Keyboard F1
|
||||
#define KEY_F2 0x3b // Keyboard F2
|
||||
#define KEY_F3 0x3c // Keyboard F3
|
||||
#define KEY_F4 0x3d // Keyboard F4
|
||||
#define KEY_F5 0x3e // Keyboard F5
|
||||
#define KEY_F6 0x3f // Keyboard F6
|
||||
#define KEY_F7 0x40 // Keyboard F7
|
||||
#define KEY_F8 0x41 // Keyboard F8
|
||||
#define KEY_F9 0x42 // Keyboard F9
|
||||
#define KEY_F10 0x43 // Keyboard F10
|
||||
#define KEY_F11 0x44 // Keyboard F11
|
||||
#define KEY_F12 0x45 // Keyboard F12
|
||||
|
||||
#define KEY_SYSRQ 0x46 // Keyboard Print Screen
|
||||
#define KEY_SCROLLLOCK 0x47 // Keyboard Scroll Lock
|
||||
#define KEY_PAUSE 0x48 // Keyboard Pause
|
||||
#define KEY_INSERT 0x49 // Keyboard Insert
|
||||
#define KEY_HOME 0x4a // Keyboard Home
|
||||
#define KEY_PAGEUP 0x4b // Keyboard Page Up
|
||||
#define KEY_DELETE 0x4c // Keyboard Delete Forward
|
||||
#define KEY_END 0x4d // Keyboard End
|
||||
#define KEY_PAGEDOWN 0x4e // Keyboard Page Down
|
||||
#define KEY_RIGHT 0x4f // Keyboard Right Arrow
|
||||
#define KEY_LEFT 0x50 // Keyboard Left Arrow
|
||||
#define KEY_DOWN 0x51 // Keyboard Down Arrow
|
||||
#define KEY_UP 0x52 // Keyboard Up Arrow
|
||||
|
||||
#define KEY_NUMLOCK 0x53 // Keyboard Num Lock and Clear
|
||||
#define KEY_KPSLASH 0x54 // Keypad /
|
||||
#define KEY_KPASTERISK 0x55 // Keypad *
|
||||
#define KEY_KPMINUS 0x56 // Keypad -
|
||||
#define KEY_KPPLUS 0x57 // Keypad +
|
||||
#define KEY_KPENTER 0x58 // Keypad ENTER
|
||||
#define KEY_KP1 0x59 // Keypad 1 and End
|
||||
#define KEY_KP2 0x5a // Keypad 2 and Down Arrow
|
||||
#define KEY_KP3 0x5b // Keypad 3 and PageDn
|
||||
#define KEY_KP4 0x5c // Keypad 4 and Left Arrow
|
||||
#define KEY_KP5 0x5d // Keypad 5
|
||||
#define KEY_KP6 0x5e // Keypad 6 and Right Arrow
|
||||
#define KEY_KP7 0x5f // Keypad 7 and Home
|
||||
#define KEY_KP8 0x60 // Keypad 8 and Up Arrow
|
||||
#define KEY_KP9 0x61 // Keypad 9 and Page Up
|
||||
#define KEY_KP0 0x62 // Keypad 0 and Insert
|
||||
#define KEY_KPDOT 0x63 // Keypad . and Delete
|
||||
|
||||
#define KEY_102ND 0x64 // Keyboard Non-US \ and |
|
||||
#define KEY_COMPOSE 0x65 // Keyboard Application
|
||||
#define KEY_POWER 0x66 // Keyboard Power
|
||||
#define KEY_KPEQUAL 0x67 // Keypad =
|
||||
|
||||
#define KEY_F13 0x68 // Keyboard F13
|
||||
#define KEY_F14 0x69 // Keyboard F14
|
||||
#define KEY_F15 0x6a // Keyboard F15
|
||||
#define KEY_F16 0x6b // Keyboard F16
|
||||
#define KEY_F17 0x6c // Keyboard F17
|
||||
#define KEY_F18 0x6d // Keyboard F18
|
||||
#define KEY_F19 0x6e // Keyboard F19
|
||||
#define KEY_F20 0x6f // Keyboard F20
|
||||
#define KEY_F21 0x70 // Keyboard F21
|
||||
#define KEY_F22 0x71 // Keyboard F22
|
||||
#define KEY_F23 0x72 // Keyboard F23
|
||||
#define KEY_F24 0x73 // Keyboard F24
|
||||
|
||||
#define KEY_OPEN 0x74 // Keyboard Execute
|
||||
#define KEY_HELP 0x75 // Keyboard Help
|
||||
#define KEY_PROPS 0x76 // Keyboard Menu
|
||||
#define KEY_FRONT 0x77 // Keyboard Select
|
||||
#define KEY_STOP 0x78 // Keyboard Stop
|
||||
#define KEY_AGAIN 0x79 // Keyboard Again
|
||||
#define KEY_UNDO 0x7a // Keyboard Undo
|
||||
#define KEY_CUT 0x7b // Keyboard Cut
|
||||
#define KEY_COPY 0x7c // Keyboard Copy
|
||||
#define KEY_PASTE 0x7d // Keyboard Paste
|
||||
#define KEY_FIND 0x7e // Keyboard Find
|
||||
#define KEY_MUTE 0x7f // Keyboard Mute
|
||||
#define KEY_VOLUMEUP 0x80 // Keyboard Volume Up
|
||||
#define KEY_VOLUMEDOWN 0x81 // Keyboard Volume Down
|
||||
// 0x82 Keyboard Locking Caps Lock
|
||||
// 0x83 Keyboard Locking Num Lock
|
||||
// 0x84 Keyboard Locking Scroll Lock
|
||||
#define KEY_KPCOMMA 0x85 // Keypad Comma
|
||||
// 0x86 Keypad Equal Sign
|
||||
#define KEY_RO 0x87 // Keyboard International1
|
||||
#define KEY_KATAKANAHIRAGANA 0x88 // Keyboard International2
|
||||
#define KEY_YEN 0x89 // Keyboard International3
|
||||
#define KEY_HENKAN 0x8a // Keyboard International4
|
||||
#define KEY_MUHENKAN 0x8b // Keyboard International5
|
||||
#define KEY_KPJPCOMMA 0x8c // Keyboard International6
|
||||
// 0x8d Keyboard International7
|
||||
// 0x8e Keyboard International8
|
||||
// 0x8f Keyboard International9
|
||||
#define KEY_HANGEUL 0x90 // Keyboard LANG1
|
||||
#define KEY_HANJA 0x91 // Keyboard LANG2
|
||||
#define KEY_KATAKANA 0x92 // Keyboard LANG3
|
||||
#define KEY_HIRAGANA 0x93 // Keyboard LANG4
|
||||
#define KEY_ZENKAKUHANKAKU 0x94 // Keyboard LANG5
|
||||
// 0x95 Keyboard LANG6
|
||||
// 0x96 Keyboard LANG7
|
||||
// 0x97 Keyboard LANG8
|
||||
// 0x98 Keyboard LANG9
|
||||
// 0x99 Keyboard Alternate Erase
|
||||
// 0x9a Keyboard SysReq/Attention
|
||||
// 0x9b Keyboard Cancel
|
||||
// 0x9c Keyboard Clear
|
||||
// 0x9d Keyboard Prior
|
||||
// 0x9e Keyboard Return
|
||||
// 0x9f Keyboard Separator
|
||||
// 0xa0 Keyboard Out
|
||||
// 0xa1 Keyboard Oper
|
||||
// 0xa2 Keyboard Clear/Again
|
||||
// 0xa3 Keyboard CrSel/Props
|
||||
// 0xa4 Keyboard ExSel
|
||||
|
||||
// 0xb0 Keypad 00
|
||||
// 0xb1 Keypad 000
|
||||
// 0xb2 Thousands Separator
|
||||
// 0xb3 Decimal Separator
|
||||
// 0xb4 Currency Unit
|
||||
// 0xb5 Currency Sub-unit
|
||||
#define KEY_KPLEFTPAREN 0xb6 // Keypad (
|
||||
#define KEY_KPRIGHTPAREN 0xb7 // Keypad )
|
||||
// 0xb8 Keypad {
|
||||
// 0xb9 Keypad }
|
||||
// 0xba Keypad Tab
|
||||
// 0xbb Keypad Backspace
|
||||
// 0xbc Keypad A
|
||||
// 0xbd Keypad B
|
||||
// 0xbe Keypad C
|
||||
// 0xbf Keypad D
|
||||
// 0xc0 Keypad E
|
||||
// 0xc1 Keypad F
|
||||
// 0xc2 Keypad XOR
|
||||
// 0xc3 Keypad ^
|
||||
// 0xc4 Keypad %
|
||||
// 0xc5 Keypad <
|
||||
// 0xc6 Keypad >
|
||||
// 0xc7 Keypad &
|
||||
// 0xc8 Keypad &&
|
||||
// 0xc9 Keypad |
|
||||
// 0xca Keypad ||
|
||||
// 0xcb Keypad :
|
||||
// 0xcc Keypad #
|
||||
// 0xcd Keypad Space
|
||||
// 0xce Keypad @
|
||||
// 0xcf Keypad !
|
||||
// 0xd0 Keypad Memory Store
|
||||
// 0xd1 Keypad Memory Recall
|
||||
// 0xd2 Keypad Memory Clear
|
||||
// 0xd3 Keypad Memory Add
|
||||
// 0xd4 Keypad Memory Subtract
|
||||
// 0xd5 Keypad Memory Multiply
|
||||
// 0xd6 Keypad Memory Divide
|
||||
// 0xd7 Keypad +/-
|
||||
// 0xd8 Keypad Clear
|
||||
// 0xd9 Keypad Clear Entry
|
||||
// 0xda Keypad Binary
|
||||
// 0xdb Keypad Octal
|
||||
// 0xdc Keypad Decimal
|
||||
// 0xdd Keypad Hexadecimal
|
||||
|
||||
#define KEY_LEFTCTRL 0xe0 // Keyboard Left Control
|
||||
#define KEY_LEFTSHIFT 0xe1 // Keyboard Left Shift
|
||||
#define KEY_LEFTALT 0xe2 // Keyboard Left Alt
|
||||
#define KEY_LEFTMETA 0xe3 // Keyboard Left GUI
|
||||
#define KEY_RIGHTCTRL 0xe4 // Keyboard Right Control
|
||||
#define KEY_RIGHTSHIFT 0xe5 // Keyboard Right Shift
|
||||
#define KEY_RIGHTALT 0xe6 // Keyboard Right Alt
|
||||
#define KEY_RIGHTMETA 0xe7 // Keyboard Right GUI
|
||||
|
||||
#define KEY_MEDIA_PLAYPAUSE 0xe8
|
||||
#define KEY_MEDIA_STOPCD 0xe9
|
||||
#define KEY_MEDIA_PREVIOUSSONG 0xea
|
||||
#define KEY_MEDIA_NEXTSONG 0xeb
|
||||
#define KEY_MEDIA_EJECTCD 0xec
|
||||
#define KEY_MEDIA_VOLUMEUP 0xed
|
||||
#define KEY_MEDIA_VOLUMEDOWN 0xee
|
||||
#define KEY_MEDIA_MUTE 0xef
|
||||
#define KEY_MEDIA_WWW 0xf0
|
||||
#define KEY_MEDIA_BACK 0xf1
|
||||
#define KEY_MEDIA_FORWARD 0xf2
|
||||
#define KEY_MEDIA_STOP 0xf3
|
||||
#define KEY_MEDIA_FIND 0xf4
|
||||
#define KEY_MEDIA_SCROLLUP 0xf5
|
||||
#define KEY_MEDIA_SCROLLDOWN 0xf6
|
||||
#define KEY_MEDIA_EDIT 0xf7
|
||||
#define KEY_MEDIA_SLEEP 0xf8
|
||||
#define KEY_MEDIA_COFFEE 0xf9
|
||||
#define KEY_MEDIA_REFRESH 0xfa
|
||||
#define KEY_MEDIA_CALC 0xfb
|
||||
|
||||
#endif
|
||||
-149
@@ -1,149 +0,0 @@
|
||||
#ifndef KEYMAP_h
|
||||
#define KEYMAP_h
|
||||
#include <cstdint>
|
||||
#include "hid_tables.h"
|
||||
|
||||
bool adb_keymap_is_modifier(uint8_t key) {
|
||||
return \
|
||||
(key == ADB_KEY_LEFT_SHIFT) ||
|
||||
(key == ADB_KEY_RIGHT_SHIFT) ||
|
||||
(key == ADB_KEY_LEFT_OPTION) ||
|
||||
(key == ADB_KEY_RIGHT_OPTION) ||
|
||||
(key == ADB_KEY_LEFT_COMMAND) ||
|
||||
(key == ADB_KEY_RIGHT_COMMAND) ||
|
||||
(key == ADB_KEY_LEFT_CONTROL) ||
|
||||
(key == ADB_KEY_RIGHT_CONTROL);
|
||||
}
|
||||
|
||||
uint8_t adb_keycode_to_hid[128] = {
|
||||
/* 0x00 = */ KEY_A,
|
||||
/* 0x01 = */ KEY_S,
|
||||
/* 0x02 = */ KEY_D,
|
||||
/* 0x03 = */ KEY_F,
|
||||
/* 0x04 = */ KEY_H,
|
||||
/* 0x05 = */ KEY_G,
|
||||
/* 0x06 = */ KEY_Z,
|
||||
/* 0x07 = */ KEY_X,
|
||||
/* 0x08 = */ KEY_C,
|
||||
/* 0x09 = */ KEY_V,
|
||||
/* 0x0a = */ KEY_102ND,
|
||||
/* 0x0b = */ KEY_B,
|
||||
/* 0x0c = */ KEY_Q,
|
||||
/* 0x0d = */ KEY_W,
|
||||
/* 0x0e = */ KEY_E,
|
||||
/* 0x0f = */ KEY_R,
|
||||
/* 0x10 = */ KEY_Y,
|
||||
/* 0x11 = */ KEY_T,
|
||||
/* 0x12 = */ KEY_1,
|
||||
/* 0x13 = */ KEY_2,
|
||||
/* 0x14 = */ KEY_3,
|
||||
/* 0x15 = */ KEY_4,
|
||||
/* 0x16 = */ KEY_6,
|
||||
/* 0x17 = */ KEY_5,
|
||||
/* 0x18 = */ KEY_EQUAL,
|
||||
/* 0x19 = */ KEY_9,
|
||||
/* 0x1a = */ KEY_7,
|
||||
/* 0x1b = */ KEY_MINUS,
|
||||
/* 0x1c = */ KEY_8,
|
||||
/* 0x1d = */ KEY_0,
|
||||
/* 0x1e = */ KEY_RIGHTBRACE,
|
||||
/* 0x1f = */ KEY_O,
|
||||
/* 0x20 = */ KEY_U,
|
||||
/* 0x21 = */ KEY_LEFTBRACE,
|
||||
/* 0x22 = */ KEY_I,
|
||||
/* 0x23 = */ KEY_P,
|
||||
/* 0x24 = */ KEY_ENTER,
|
||||
/* 0x25 = */ KEY_L,
|
||||
/* 0x26 = */ KEY_J,
|
||||
/* 0x27 = */ KEY_APOSTROPHE,
|
||||
/* 0x28 = */ KEY_K,
|
||||
/* 0x29 = */ KEY_SEMICOLON,
|
||||
/* 0x2a = */ KEY_HASHTILDE,
|
||||
/* 0x2b = */ KEY_COMMA,
|
||||
/* 0x2c = */ KEY_SLASH,
|
||||
/* 0x2d = */ KEY_N,
|
||||
/* 0x2e = */ KEY_M,
|
||||
/* 0x2f = */ KEY_DOT,
|
||||
/* 0x30 = */ KEY_TAB,
|
||||
/* 0x31 = */ KEY_SPACE,
|
||||
/* 0x32 = */ KEY_GRAVE,
|
||||
/* 0x33 = */ KEY_BACKSPACE,
|
||||
/* 0x34 = */ 0,
|
||||
/* 0x35 = */ KEY_ESC,
|
||||
/* 0x36 = */ KEY_LEFTCTRL,
|
||||
/* 0x37 = */ KEY_LEFTMETA,
|
||||
/* 0x38 = */ KEY_LEFTSHIFT,
|
||||
/* 0x39 = */ KEY_CAPSLOCK,
|
||||
/* 0x3a = */ KEY_LEFTALT,
|
||||
/* 0x3b = */ KEY_LEFT,
|
||||
/* 0x3c = */ KEY_RIGHT,
|
||||
/* 0x3d = */ KEY_DOWN,
|
||||
/* 0x3e = */ KEY_UP,
|
||||
/* 0x3f = */ 0,
|
||||
/* 0x40 = */ 0,
|
||||
/* 0x41 = */ KEY_KPDOT,
|
||||
/* 0x42 = */ 0,
|
||||
/* 0x43 = */ KEY_KPASTERISK,
|
||||
/* 0x44 = */ 0,
|
||||
/* 0x45 = */ KEY_KPPLUS,
|
||||
/* 0x46 = */ 0,
|
||||
/* 0x47 = */ KEY_NUMLOCK,
|
||||
/* 0x48 = */ 0,
|
||||
/* 0x49 = */ 0,
|
||||
/* 0x4a = */ 0,
|
||||
/* 0x4b = */ KEY_KPSLASH,
|
||||
/* 0x4c = */ KEY_KPENTER,
|
||||
/* 0x4d = */ 0,
|
||||
/* 0x4e = */ KEY_KPMINUS,
|
||||
/* 0x4f = */ 0,
|
||||
/* 0x50 = */ 0,
|
||||
/* 0x51 = */ KEY_KPEQUAL,
|
||||
/* 0x52 = */ KEY_KP0,
|
||||
/* 0x53 = */ KEY_KP1,
|
||||
/* 0x54 = */ KEY_KP2,
|
||||
/* 0x55 = */ KEY_KP3,
|
||||
/* 0x56 = */ KEY_KP4,
|
||||
/* 0x57 = */ KEY_KP5,
|
||||
/* 0x58 = */ KEY_KP6,
|
||||
/* 0x59 = */ KEY_KP7,
|
||||
/* 0x5a = */ 0,
|
||||
/* 0x5b = */ KEY_KP8,
|
||||
/* 0x5c = */ KEY_KP9,
|
||||
/* 0x5d = */ 0,
|
||||
/* 0x5e = */ 0,
|
||||
/* 0x5f = */ 0,
|
||||
/* 0x60 = */ KEY_F5,
|
||||
/* 0x61 = */ KEY_F6,
|
||||
/* 0x62 = */ KEY_F7,
|
||||
/* 0x63 = */ KEY_F3,
|
||||
/* 0x64 = */ KEY_MEDIA_PREVIOUSSONG, // F7: Lecture en arrière
|
||||
/* 0x65 = */ KEY_MEDIA_PLAYPAUSE, // F8: Play/Pause
|
||||
/* 0x66 = */ KEY_MEDIA_NEXTSONG, // F9: Lecture suivante
|
||||
/* 0x67 = */ KEY_VOLUMEDOWN,
|
||||
/* 0x68 = */ 0,
|
||||
/* 0x69 = */ 0,
|
||||
/* 0x6a = */ 0,
|
||||
/* 0x6b = */ 0,
|
||||
/* 0x6c = */ 0,
|
||||
/* 0x6d = */ KEY_MUTE, // F10: Mute
|
||||
/* 0x6e = */ 0,
|
||||
/* 0x6f = */ KEY_VOLUMEUP, // F12: Volume +
|
||||
/* 0x70 = */ 0,
|
||||
/* 0x71 = */ 0,
|
||||
/* 0x72 = */ KEY_HELP, // or KEY_INSERT
|
||||
/* 0x73 = */ KEY_HOME,
|
||||
/* 0x74 = */ KEY_PAGEUP,
|
||||
/* 0x75 = */ KEY_DELETE,
|
||||
/* 0x76 = */ KEY_F4,
|
||||
/* 0x77 = */ KEY_END,
|
||||
/* 0x78 = */ KEY_F2,
|
||||
/* 0x79 = */ KEY_PAGEDOWN,
|
||||
/* 0x7a = */ KEY_F1,
|
||||
/* 0x7b = */ KEY_RIGHTSHIFT,
|
||||
/* 0x7c = */ KEY_RIGHTALT,
|
||||
/* 0x7d = */ KEY_RIGHTCTRL,
|
||||
/* 0x7e = */ 0,
|
||||
/* 0x7f = */ KEY_POWER, // Special key, repeated in both bytes of the register
|
||||
};
|
||||
|
||||
#endif
|
||||
+80
-133
@@ -1,186 +1,133 @@
|
||||
/*
|
||||
* This file is part of the stm32-adb2usb project.
|
||||
* Inspiré et adapté du projet https://github.com/szymonlopaciuk/stm32-adb2usb
|
||||
*
|
||||
* Copyright (C) 2025 Clément SAILLANT - L'électron rare
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#ifdef STM32F1
|
||||
#include <stm32f1xx_hal_gpio.h> // Inclusion pour STM32F1
|
||||
#elif defined(STM32F3)
|
||||
#include <stm32f3xx_hal_gpio.h> // Inclusion pour STM32F3
|
||||
#else
|
||||
#error "Unsupported STM32 series. Please define STM32F1 or STM32F3 in build_flags."
|
||||
#endif
|
||||
|
||||
#include "hid_tables.h"
|
||||
#include "adb_structures.h"
|
||||
#include <ADB.h>
|
||||
#include "hid_keyboard.h"
|
||||
#include "hid_mouse.h"
|
||||
#include "adb_devices.h"
|
||||
#include "Mouse.h"
|
||||
|
||||
#define POLL_DELAY 5
|
||||
|
||||
bool apple_extended_detected = false;
|
||||
bool keyboard_present = false, mouse_present = false;
|
||||
// Structure pour regrouper les états des périphériques
|
||||
struct DeviceState {
|
||||
bool apple_extended_detected = false;
|
||||
bool keyboard_present = false;
|
||||
bool mouse_present = false;
|
||||
bool led_caps = false; // État de la LED Caps Lock
|
||||
bool led_num = true; // État de la LED Num Lock (actif par défaut)
|
||||
};
|
||||
|
||||
bool led_caps = false; // Déclaration globale pour Caps Lock
|
||||
bool led_num = true; // Déclaration globale pour Num Lock (actif par défaut)
|
||||
// Instances globales
|
||||
ADB adb(PB4); // Remplacez PB4 par la pin appropriée
|
||||
ADBDevices adbDevices(adb);
|
||||
DeviceState deviceState;
|
||||
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
void print16b(uint16_t buff) {
|
||||
uint16_t mask = (1 << 15);
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
{
|
||||
Serial.write(buff & mask ? '1' : '0');
|
||||
mask >>= 1;
|
||||
}
|
||||
Serial.write('\n');
|
||||
Serial.flush();
|
||||
// Fonction utilitaire pour initialiser un périphérique
|
||||
bool initializeDevice(uint8_t addr, uint8_t handler_id) {
|
||||
bool error = false;
|
||||
adb_data<adb_register3> reg3 = {0}, mask = {0};
|
||||
reg3.data.device_handler_id = handler_id;
|
||||
mask.data.device_handler_id = 0xFF;
|
||||
return adbDevices.deviceUpdateRegister3(addr, reg3, mask.raw, &error) && !error;
|
||||
}
|
||||
|
||||
void printkbresp(adb_kb_keypress buff) {
|
||||
//Keyboard.print(" key1 ");
|
||||
Serial.print(buff.released0 ? "u" : "d");
|
||||
Serial.print(buff.key0, 16);
|
||||
Serial.print(", ");
|
||||
Serial.print(buff.released1 ? "u" : "d");
|
||||
Serial.print(buff.key1, 16);
|
||||
Serial.print("\n");
|
||||
Serial.flush();
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Turn the led on at the beginning of setup
|
||||
// Configuration de la LED d'état
|
||||
pinMode(PC13, OUTPUT);
|
||||
digitalWrite(PC13, LOW);
|
||||
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
// Initialisation de la communication série
|
||||
Serial.begin(115200);
|
||||
#endif
|
||||
|
||||
// Set up HID
|
||||
hid_keyboard_init();
|
||||
// Initialisation du bus ADB
|
||||
adb.init(PB4, true); // Active l'utilisation de ADBDevices
|
||||
|
||||
// Set up the ADB bus
|
||||
adb_init();
|
||||
delay(1000); // Attente pour permettre aux périphériques de se réinitialiser
|
||||
|
||||
delay(1000); // A wait for good measure, apparently AEKII can take a moment to reset
|
||||
// Initialisation des périphériques
|
||||
deviceState.keyboard_present = initializeDevice(ADBKey::Address::KEYBOARD, 0x03);
|
||||
deviceState.mouse_present = initializeDevice(ADBKey::Address::MOUSE, 0x02);
|
||||
|
||||
// Initialise the ADB devices
|
||||
// Switch the keyboard to Apple Extended if available
|
||||
bool error = false;
|
||||
adb_data<adb_register3> reg3 = {0}, mask = {0};
|
||||
reg3.data.device_handler_id = 0x03;
|
||||
mask.data.device_handler_id = 0xFF;
|
||||
apple_extended_detected = adb_device_update_register3(ADB_ADDR_KEYBOARD, reg3, mask.raw, &error);
|
||||
if (!error) keyboard_present = true,
|
||||
|
||||
// Switch the mouse to higher resolution, if available
|
||||
// TODO: Apple Extended Mouse Protocol (Handler = 4)
|
||||
error = false;
|
||||
reg3.raw = 0;
|
||||
mask.raw = 0;
|
||||
reg3.data.device_handler_id = 0x02;
|
||||
mask.data.device_handler_id = 0xFF;
|
||||
adb_device_update_register3(ADB_ADDR_MOUSE, reg3, mask.raw, &error);
|
||||
if (!error) mouse_present = true;
|
||||
|
||||
// Set-up successful, turn off the LED
|
||||
// Désactivation de la LED d'état après initialisation
|
||||
digitalWrite(PC13, HIGH);
|
||||
|
||||
// Activer NumLock au démarrage
|
||||
adb_keyboard_write_leds(0, led_caps, led_num); // Mise à jour des LEDs
|
||||
// Activation de Num Lock au démarrage
|
||||
adbDevices.keyboardWriteLEDs(false, deviceState.led_caps, deviceState.led_num);
|
||||
}
|
||||
|
||||
void keyboard_handler() {
|
||||
void handleKeyboard() {
|
||||
static hid_key_report key_report = {0};
|
||||
bool error = false;
|
||||
|
||||
auto key_press = adb_keyboard_read_key_press(&error);
|
||||
|
||||
if (error) return; // don't continue changing the hid report if there was
|
||||
// an error reading from ADB – most often it's a timeout
|
||||
// Lecture des touches pressées
|
||||
auto key_press = adbDevices.keyboardReadKeyPress(&error);
|
||||
if (error) return;
|
||||
|
||||
bool report_changed = hid_keyboard_set_keys_from_adb_register(&key_report, key_press);
|
||||
|
||||
// Ignorer toutes les touches du pavé numérique si NumLock n'est pas actif
|
||||
if (!led_num) {
|
||||
for (int i = 0; i < KEY_REPORT_KEYS_COUNT; i++) {
|
||||
if ((key_report.keys[i] >= KEY_KPSLASH && key_report.keys[i] <= KEY_KPDOT || key_report.keys[i] == KEY_KPEQUAL)) {
|
||||
key_report.keys[i] = 0; // Supprimer la touche du rapport
|
||||
report_changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gestion de la touche Caps Lock
|
||||
bool caps_lock_action = key_press.data.key0 == ADB_KEY_CAPS_LOCK ||
|
||||
key_press.data.key1 == ADB_KEY_CAPS_LOCK;
|
||||
|
||||
bool caps_lock_twice_in_register = key_press.data.key0 == ADB_KEY_CAPS_LOCK &&
|
||||
key_press.data.key1 == ADB_KEY_CAPS_LOCK &&
|
||||
key_press.data.released0 != key_press.data.released1;
|
||||
|
||||
if (caps_lock_action && !caps_lock_twice_in_register)
|
||||
{
|
||||
hid_keyboard_add_key_to_report(&key_report, KEY_CAPSLOCK);
|
||||
|
||||
// Send the preliminary report, with caps lock down
|
||||
hid_keyboard_send_report(&key_report);
|
||||
|
||||
led_caps = !led_caps;
|
||||
adb_keyboard_write_leds(0, led_caps, led_num); // Mise à jour des LEDs
|
||||
|
||||
// Wait a little bit
|
||||
delay(80);
|
||||
|
||||
// Now just release the caps lock key, and continue as before
|
||||
hid_keyboard_remove_key_from_report(&key_report, KEY_CAPSLOCK);
|
||||
|
||||
// Gestion de Caps Lock - utilisation des constantes du namespace ADBKey
|
||||
if ((key_press.data.key0 == ADBKey::KeyCode::CAPS_LOCK && !key_press.data.released0) ||
|
||||
(key_press.data.key1 == ADBKey::KeyCode::CAPS_LOCK && !key_press.data.released1)) {
|
||||
deviceState.led_caps = !deviceState.led_caps;
|
||||
adbDevices.keyboardWriteLEDs(false, deviceState.led_caps, deviceState.led_num);
|
||||
report_changed = true;
|
||||
}
|
||||
|
||||
// Gestion de la touche Num Lock
|
||||
bool num_lock_action = key_press.data.key0 == ADB_KEY_NUM_LOCK && !key_press.data.released0 ||
|
||||
key_press.data.key1 == ADB_KEY_NUM_LOCK && !key_press.data.released1;
|
||||
|
||||
if (num_lock_action) // Changer l'état à chaque appui
|
||||
{
|
||||
led_num = !led_num;
|
||||
adb_keyboard_write_leds(0, led_caps, led_num); // Mise à jour des LEDs
|
||||
|
||||
// Pas besoin d'ajouter ou de retirer NumLock dans le rapport HID,
|
||||
// car il s'agit uniquement d'une bascule de l'état des LEDs.
|
||||
// Gestion de Num Lock - utilisation des constantes du namespace ADBKey
|
||||
if ((key_press.data.key0 == ADBKey::KeyCode::NUM_LOCK && !key_press.data.released0) ||
|
||||
(key_press.data.key1 == ADBKey::KeyCode::NUM_LOCK && !key_press.data.released1)) {
|
||||
deviceState.led_num = !deviceState.led_num;
|
||||
adbDevices.keyboardWriteLEDs(false, deviceState.led_caps, deviceState.led_num);
|
||||
report_changed = true;
|
||||
}
|
||||
|
||||
// Send the finished report
|
||||
//if (report_changed)
|
||||
// Envoi du rapport HID si modifié
|
||||
if (report_changed) {
|
||||
hid_keyboard_send_report(&key_report);
|
||||
}
|
||||
}
|
||||
|
||||
void mouse_handler() {
|
||||
void handleMouse() {
|
||||
bool error = false;
|
||||
auto mouse_data = adb_mouse_read_data(&error);
|
||||
|
||||
// Lecture des données de la souris
|
||||
auto mouse_data = adbDevices.mouseReadData(&error);
|
||||
if (error || mouse_data.raw == 0) return;
|
||||
|
||||
int8_t mouse_x = ADB_MOUSE_CONV_AXIS(mouse_data.data.x_offset);
|
||||
int8_t mouse_y = ADB_MOUSE_CONV_AXIS(mouse_data.data.y_offset);
|
||||
// Conversion des axes avec adbMouseConvertAxis
|
||||
int8_t mouse_x = adbMouseConvertAxis(mouse_data.data.x_offset);
|
||||
int8_t mouse_y = adbMouseConvertAxis(mouse_data.data.y_offset);
|
||||
|
||||
// Envoi du rapport HID pour la souris
|
||||
hid_mouse_send_report(mouse_data.data.button ? 0 : 1, mouse_x, mouse_y);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (keyboard_present) {
|
||||
keyboard_handler();
|
||||
// Wait a tiny bit before polling again,
|
||||
// while ADB seems fairly tolerent of quick requests
|
||||
// we don't want to overwhelm USB either
|
||||
if (deviceState.keyboard_present) {
|
||||
handleKeyboard();
|
||||
delay(POLL_DELAY);
|
||||
}
|
||||
|
||||
if (mouse_present) {
|
||||
mouse_handler();
|
||||
if (deviceState.mouse_present) {
|
||||
handleMouse();
|
||||
delay(POLL_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user