working good on stm32
This commit is contained in:
Submodule lib/ADB-pour-Framework-Arduino updated: a18f71613a...1b35d9ea54
+2
-3
@@ -21,7 +21,7 @@ build_flags =
|
||||
-D USB_PRODUCT="Apple Desktop Bus Device"
|
||||
-D HAL_PCD_MODULE_ENABLED
|
||||
-D STM32F1
|
||||
;-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
; -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
;-D PIO_FRAMEWORK_ARDUINO_USB_FULLSPEED_FULLMODE
|
||||
|
||||
upload_flags = -c set CPUTAPID 0x2ba01477 ; Chinese clone, genuine is 0x1ba01477
|
||||
@@ -35,7 +35,6 @@ platform = ststm32
|
||||
board = disco_f303vc
|
||||
framework = arduino
|
||||
build_flags =
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
-D USBCON
|
||||
-D USBD_VID=0x0483
|
||||
-D USBD_PID=0x5711
|
||||
@@ -51,7 +50,7 @@ debug_tool = stlink
|
||||
upload_protocol = stlink
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
; https://github.com/electron-rare/ADB-pour-Framework-Arduino
|
||||
; je voudrais
|
||||
; electronrare/ADB @ ^1.0.0
|
||||
[env:native]
|
||||
platform = native
|
||||
|
||||
+55
-8
@@ -20,7 +20,9 @@
|
||||
*/
|
||||
void hid_keyboard_init() {
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
Serial.println("Initialisation du clavier HID...");
|
||||
HID_Composite_Init(HID_KEYBOARD);
|
||||
Serial.println("Clavier HID initialisé.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -29,7 +31,9 @@ void hid_keyboard_init() {
|
||||
*/
|
||||
void hid_keyboard_close() {
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
Serial.println("Fermeture du clavier HID...");
|
||||
HID_Composite_DeInit(HID_KEYBOARD);
|
||||
Serial.println("Clavier HID fermé.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -42,6 +46,16 @@ void hid_keyboard_send_report(hid_key_report* report) {
|
||||
uint8_t buf[8] = {report->modifiers, 0, report->keys[0],
|
||||
report->keys[1], report->keys[2], report->keys[3],
|
||||
report->keys[4], report->keys[5]};
|
||||
|
||||
Serial.print("Envoi du rapport HID clavier - Modificateurs: ");
|
||||
Serial.print(report->modifiers, HEX);
|
||||
Serial.print(", Touches: ");
|
||||
for (int i = 0; i < KEY_REPORT_KEYS_COUNT; i++) {
|
||||
Serial.print(report->keys[i], HEX);
|
||||
if (i < KEY_REPORT_KEYS_COUNT - 1) Serial.print(", ");
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
HID_Composite_keyboard_sendReport(buf, 8);
|
||||
#endif
|
||||
@@ -55,6 +69,9 @@ void hid_keyboard_send_report(hid_key_report* report) {
|
||||
* @return true si le rapport a été modifié, false sinon.
|
||||
*/
|
||||
bool hid_keyboard_set_keys_from_adb_register(hid_key_report* report, adb_data<adb_kb_keypress> key_press) {
|
||||
Serial.print("Mise à jour des touches HID depuis le registre ADB - Raw: ");
|
||||
Serial.println(key_press.raw, HEX);
|
||||
|
||||
if (key_press.raw == ADBKey::KeyCode::POWER_DOWN)
|
||||
return hid_keyboard_update_key_in_report(report, KEY_POWER, false);
|
||||
else if (key_press.raw == ADBKey::KeyCode::POWER_UP)
|
||||
@@ -86,6 +103,11 @@ bool hid_keyboard_set_keys_from_adb_register(hid_key_report* report, adb_data<ad
|
||||
* @return true si le rapport a été modifié, false sinon.
|
||||
*/
|
||||
bool hid_keyboard_update_key_in_report(hid_key_report* report, uint8_t hid_keycode, bool released) {
|
||||
Serial.print("Mise à jour d'une touche HID - Code: ");
|
||||
Serial.print(hid_keycode, HEX);
|
||||
Serial.print(", Relâché: ");
|
||||
Serial.println(released);
|
||||
|
||||
if (hid_keycode == KEY_NONE) return false;
|
||||
|
||||
if (released)
|
||||
@@ -102,6 +124,9 @@ bool hid_keyboard_update_key_in_report(hid_key_report* report, uint8_t hid_keyco
|
||||
* @return true si la touche a été ajoutée, false sinon.
|
||||
*/
|
||||
bool hid_keyboard_add_key_to_report(hid_key_report* report, uint8_t hid_keycode) {
|
||||
Serial.print("Ajout d'une touche HID - Code: ");
|
||||
Serial.println(hid_keycode, HEX);
|
||||
|
||||
int8_t free_slot = -1;
|
||||
|
||||
for (uint8_t i = 0; i < KEY_REPORT_KEYS_COUNT; i++) {
|
||||
@@ -127,6 +152,9 @@ bool hid_keyboard_add_key_to_report(hid_key_report* report, uint8_t hid_keycode)
|
||||
* @return true si la touche a été supprimée, false sinon.
|
||||
*/
|
||||
bool hid_keyboard_remove_key_from_report(hid_key_report* report, uint8_t hid_keycode) {
|
||||
Serial.print("Suppression d'une touche HID - Code: ");
|
||||
Serial.println(hid_keycode, HEX);
|
||||
|
||||
bool report_changed = false;
|
||||
for (uint8_t i = 0; i < KEY_REPORT_KEYS_COUNT; i++) {
|
||||
if (report->keys[i] == hid_keycode) {
|
||||
@@ -145,14 +173,33 @@ bool hid_keyboard_remove_key_from_report(hid_key_report* report, uint8_t hid_key
|
||||
* @param pressed Indique si le modificateur est pressé (true) ou relâché (false).
|
||||
* @return true si le rapport a été modifié, false sinon.
|
||||
*/
|
||||
bool hid_keyboard_update_modifier_in_report(hid_key_report* report, uint8_t modifier, bool pressed) {
|
||||
uint8_t old_modifiers = report->modifiers;
|
||||
bool hid_keyboard_update_modifier_in_report(hid_key_report* report, uint8_t adb_keycode, bool released) {
|
||||
Serial.print("Mise à jour d'un modificateur HID - ADB Keycode: ");
|
||||
Serial.print(adb_keycode, HEX);
|
||||
Serial.print(", Relâché: ");
|
||||
Serial.println(released);
|
||||
|
||||
if (pressed) {
|
||||
report->modifiers |= modifier; // Active le bit correspondant au modificateur.
|
||||
} else {
|
||||
report->modifiers &= ~modifier; // Désactive le bit correspondant au modificateur.
|
||||
}
|
||||
auto update_modifier = [released, report](uint8_t mask) {
|
||||
// Vérifie si le modificateur est déjà dans l'état souhaité
|
||||
if (released == !(report->modifiers & mask)) return false;
|
||||
|
||||
return old_modifiers != report->modifiers; // Retourne true si le rapport a été modifié.
|
||||
// Met à jour le modificateur
|
||||
if (!released) report->modifiers |= mask; // Active le modificateur
|
||||
else report->modifiers &= ~mask; // Désactive le modificateur
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Correspondance des codes ADB avec les modificateurs HID
|
||||
if (adb_keycode == ADBKey::KeyCode::LEFT_SHIFT) return update_modifier(KEY_MOD_LSHIFT);
|
||||
if (adb_keycode == ADBKey::KeyCode::RIGHT_SHIFT) return update_modifier(KEY_MOD_RSHIFT);
|
||||
if (adb_keycode == ADBKey::KeyCode::LEFT_CONTROL) return update_modifier(KEY_MOD_LCTRL);
|
||||
if (adb_keycode == ADBKey::KeyCode::RIGHT_CONTROL) return update_modifier(KEY_MOD_RCTRL);
|
||||
if (adb_keycode == ADBKey::KeyCode::LEFT_OPTION) return update_modifier(KEY_MOD_LALT);
|
||||
if (adb_keycode == ADBKey::KeyCode::RIGHT_OPTION) return update_modifier(KEY_MOD_RALT);
|
||||
if (adb_keycode == ADBKey::KeyCode::LEFT_COMMAND) return update_modifier(KEY_MOD_LMETA);
|
||||
if (adb_keycode == ADBKey::KeyCode::RIGHT_COMMAND) return update_modifier(KEY_MOD_RMETA);
|
||||
|
||||
Serial.println("Modificateur inconnu.");
|
||||
return false; // Aucun changement
|
||||
}
|
||||
|
||||
@@ -17,6 +17,16 @@
|
||||
|
||||
#define KEY_REPORT_KEYS_COUNT 6 /**< Nombre maximum de touches dans un rapport HID. */
|
||||
|
||||
// Masques pour les modificateurs HID
|
||||
#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
|
||||
|
||||
/**
|
||||
* @struct hid_key_report
|
||||
* @brief Structure représentant un rapport HID pour un clavier.
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
*/
|
||||
void hid_mouse_init() {
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
Serial.println("Initialisation de la souris HID...");
|
||||
HID_Composite_Init(HID_MOUSE);
|
||||
Serial.println("Souris HID initialisée.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -29,7 +31,9 @@ void hid_mouse_init() {
|
||||
*/
|
||||
void hid_mouse_close() {
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
Serial.println("Fermeture de la souris HID...");
|
||||
HID_Composite_DeInit(HID_MOUSE);
|
||||
Serial.println("Souris HID fermée.");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -47,6 +51,13 @@ void hid_mouse_send_report(bool button, int8_t offset_x, int8_t offset_y) {
|
||||
m[2] = offset_y;
|
||||
m[3] = 0;
|
||||
|
||||
Serial.print("Envoi du rapport HID souris - Bouton: ");
|
||||
Serial.print(button);
|
||||
Serial.print(", X: ");
|
||||
Serial.print(offset_x);
|
||||
Serial.print(", Y: ");
|
||||
Serial.println(offset_y);
|
||||
|
||||
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_HID
|
||||
HID_Composite_mouse_sendReport(m, 4);
|
||||
#endif
|
||||
|
||||
+33
-2
@@ -58,17 +58,30 @@ void setup() {
|
||||
digitalWrite(PC13, LOW);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Initialisation du programme...");
|
||||
|
||||
// Set up HID
|
||||
hid_keyboard_init();
|
||||
hid_mouse_init();
|
||||
Serial.println("HID initialisé.");
|
||||
|
||||
adb.init(PB4, true);
|
||||
Serial.println("Bus ADB initialisé.");
|
||||
|
||||
delay(1000);
|
||||
|
||||
deviceState.keyboard_present = initializeDevice(ADBKey::Address::KEYBOARD, 0x03);
|
||||
Serial.print("Clavier détecté : ");
|
||||
Serial.println(deviceState.keyboard_present ? "Oui" : "Non");
|
||||
|
||||
deviceState.mouse_present = initializeDevice(ADBKey::Address::MOUSE, 0x02);
|
||||
Serial.print("Souris détectée : ");
|
||||
Serial.println(deviceState.mouse_present ? "Oui" : "Non");
|
||||
|
||||
digitalWrite(PC13, HIGH);
|
||||
|
||||
adbDevices.keyboardWriteLEDs(false, deviceState.led_caps, deviceState.led_num);
|
||||
Serial.println("LEDs initialisées.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +92,10 @@ void handleKeyboard() {
|
||||
bool error = false;
|
||||
|
||||
auto key_press = adbDevices.keyboardReadKeyPress(&error);
|
||||
if (error) return;
|
||||
if (error) {
|
||||
// Serial.println("Erreur lors de la lecture des touches du clavier.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool report_changed = hid_keyboard_set_keys_from_adb_register(&key_report, key_press);
|
||||
|
||||
@@ -87,6 +103,8 @@ void handleKeyboard() {
|
||||
(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);
|
||||
Serial.print("Caps Lock LED : ");
|
||||
Serial.println(deviceState.led_caps ? "Allumée" : "Éteinte");
|
||||
report_changed = true;
|
||||
}
|
||||
|
||||
@@ -94,10 +112,13 @@ void handleKeyboard() {
|
||||
(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);
|
||||
Serial.print("Num Lock LED : ");
|
||||
Serial.println(deviceState.led_num ? "Allumée" : "Éteinte");
|
||||
report_changed = true;
|
||||
}
|
||||
|
||||
if (report_changed) {
|
||||
Serial.println("Rapport clavier mis à jour.");
|
||||
hid_keyboard_send_report(&key_report);
|
||||
}
|
||||
}
|
||||
@@ -109,11 +130,19 @@ void handleMouse() {
|
||||
bool error = false;
|
||||
|
||||
auto mouse_data = adbDevices.mouseReadData(&error);
|
||||
if (error || mouse_data.raw == 0) return;
|
||||
if (error || mouse_data.raw == 0) {
|
||||
// if (error) Serial.println("Erreur lors de la lecture des données de la souris.");
|
||||
return;
|
||||
}
|
||||
|
||||
int8_t mouse_x = adbMouseConvertAxis(mouse_data.data.x_offset);
|
||||
int8_t mouse_y = adbMouseConvertAxis(mouse_data.data.y_offset);
|
||||
|
||||
Serial.print("Mouvement souris - X: ");
|
||||
Serial.print(mouse_x);
|
||||
Serial.print(", Y: ");
|
||||
Serial.println(mouse_y);
|
||||
|
||||
hid_mouse_send_report(mouse_data.data.button ? 0 : 1, mouse_x, mouse_y);
|
||||
}
|
||||
|
||||
@@ -122,11 +151,13 @@ void handleMouse() {
|
||||
*/
|
||||
void loop() {
|
||||
if (deviceState.keyboard_present) {
|
||||
// Serial.println("Gestion du clavier...");
|
||||
handleKeyboard();
|
||||
delay(POLL_DELAY);
|
||||
}
|
||||
|
||||
if (deviceState.mouse_present) {
|
||||
// Serial.println("Gestion de la souris...");
|
||||
handleMouse();
|
||||
delay(POLL_DELAY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user