update readme esp32 ok
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"name": "Apple-ADB-Ressurector",
|
||||||
|
"path": "."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"stm32-for-vscode.openOCDPath": false,
|
||||||
|
"stm32-for-vscode.armToolchainPath": false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,9 +48,27 @@ Le code source de ce projet est disponible sur mon dépôt GitHub : [Apple ADB R
|
|||||||
|
|
||||||
## 🎮 Utilisation
|
## 🎮 Utilisation
|
||||||
|
|
||||||
1. Branchez votre périphérique ADB à la carte STM32.
|
1. Téléversez le firmware sur votre carte STM32 ou ESP32.
|
||||||
2. Connectez la carte STM32 à votre ordinateur via USB.
|
2. Branchez votre périphérique ADB à la carte STM32 ou ESP32 (selon votre configuration).
|
||||||
3. Admirez la magie : votre périphérique ADB fonctionne maintenant comme un périphérique USB ! ✨
|
3. Ajoutez une résistance de pull-up entre la broche de données (ADB_PIN) et l'alimentation (+V). Voici un schéma de connexion :
|
||||||
|
```
|
||||||
|
+5V
|
||||||
|
|
|
||||||
|
R (4.7kΩ ou 10kΩ)
|
||||||
|
|
|
||||||
|
Périphérique ADB data <------+------------------+---> ADB_PIN (ESP32: GPIO2, STM32: PB4)
|
||||||
|
|
|
||||||
|
|
|
||||||
|
GND
|
||||||
|
```
|
||||||
|
4. Connectez la carte STM32 ou ESP32 à votre ordinateur via USB ou Bluetooth.
|
||||||
|
|
||||||
|
4. **Utilisation de connecteurs et câbles S-Video** :
|
||||||
|
Le connecteur ADB est identique au connecteur S-Video. Vous pouvez donc utiliser des câbles S-Video standard pour connecter vos périphériques ADB.
|
||||||
|
|
||||||
|
5. Admirez la magie : votre périphérique ADB fonctionne maintenant comme un périphérique USB ou Bluetooth ! ✨
|
||||||
|
|
||||||
|
> **Note** : Grâce à l'environnement PlatformIO et à la configuration du firmware, tout le travail complexe est automatisé. Vous n'avez qu'à choisir la plateforme (STM32 ou ESP32) et à téléverser le firmware.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -110,18 +128,36 @@ Mais voilà, je ne trouvais pas exactement ce que je voulais, et comme j'avais d
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## ⚙️ Configuration des pins et paramètres
|
||||||
|
|
||||||
|
Le projet utilise des définitions spécifiques pour configurer les pins en fonction de la plateforme utilisée (ESP32 ou STM32) :
|
||||||
|
|
||||||
|
- `#define POLL_DELAY 5` : Définit un délai de 5 ms entre chaque cycle de polling pour interroger les périphériques ADB.
|
||||||
|
- `#define ADB_PIN` : Configure la pin utilisée pour la communication ADB :
|
||||||
|
- **ESP32** : Pin `2`.
|
||||||
|
- **STM32** : Pin `PB4`.
|
||||||
|
- `#define LED_PIN` : Configure la pin utilisée pour la LED d'état :
|
||||||
|
- **ESP32** : Pin `4` (Devkit Wemos).
|
||||||
|
- **STM32** : Pin `PC13`.
|
||||||
|
|
||||||
|
Ces définitions permettent une compatibilité multi-plateforme en adaptant automatiquement les pins selon la carte utilisée.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 🛑 État du projet
|
## 🛑 État du projet
|
||||||
|
|
||||||
Ce projet est actuellement en **beta**.
|
Ce projet est actuellement en **beta**.
|
||||||
Prochain objectif : transformer vos claviers d'époque en claviers Bluetooth grâce à un ESP32. Oui, on rêve grand. 🌈
|
- **ESP32** : Le support du clavier Bluetooth est désormais fonctionnel. Prochain objectif : ajouter le support Bluetooth pour la souris.
|
||||||
|
- **STM32** : Le support du clavier et de la souris comme périphériques USB est entièrement fonctionnel.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🔮 Plans futurs
|
## 🔮 Plans futurs
|
||||||
|
|
||||||
- Concevoir un PCB pour une alimentation par batterie et une connectivité Bluetooth.
|
- Concevoir un PCB pour une alimentation par batterie et un boîtier adapté.
|
||||||
- Étendre le support à d'autres plateformes comme ESP32.
|
- Ajouter le support Bluetooth pour la souris.
|
||||||
- Améliorer la gestion de l'alimentation pour les périphériques ADB exotiques.
|
- Intégrer un écran OLED pour afficher des informations sur l'état de la connexion.
|
||||||
|
- Ajouter un mode de veille pour économiser la batterie.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -137,15 +173,24 @@ Prochain objectif : transformer vos claviers d'époque en claviers Bluetooth gr
|
|||||||
|
|
||||||
- [x] Faire fonctionner le clavier.
|
- [x] Faire fonctionner le clavier.
|
||||||
- [x] Faire fonctionner la souris.
|
- [x] Faire fonctionner la souris.
|
||||||
- [ ] Ajouter le support Bluetooth.
|
- [x] Gérer plusieurs périphériques ADB simultanément.
|
||||||
- [ ] Gérer plusieurs périphériques ADB simultanément.
|
- [x] Ajouter le support Bluetooth pour le clavier.
|
||||||
|
- [ ] Ajouter le support Bluetooth pour la souris.
|
||||||
|
- [ ] Ajouter le support d'autres périphériques ADB (tablettes graphiques, trackballs, etc.).
|
||||||
|
- [ ] Ajouter le support d'un écran OLED pour afficher des informations sur l'état de la connexion.
|
||||||
|
- [ ] Ajouter un mode de veille pour économiser la batterie.
|
||||||
|
- [ ] Concevoir un PCB pour une alimentation par batterie et un boîtier adapté.
|
||||||
|
- [ ] Améliorer le support de la LED Num Lock.
|
||||||
|
- [ ] Améliorer le support de la LED Caps Lock.
|
||||||
|
- [ ] Améliorer le support de la LED Scroll Lock.
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 💡 Remerciements
|
## 💡 Remerciements
|
||||||
|
|
||||||
Un grand merci à **GitHub Copilot** pour son aide précieuse et ses suggestions parfois hilarantes. 🤖✨
|
Un grand merci à **GitHub Copilot** pour son aide précieuse et ses suggestions parfois hilarantes. 🤖✨
|
||||||
Et bien sûr, merci à **Szymon Łopaciuk** pour l'inspiration initiale.
|
Et bien sûr, surtout merci à **Szymon Łopaciuk** pour l'inspiration initiale.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+296
-214
@@ -2,7 +2,8 @@
|
|||||||
* @file main.cpp
|
* @file main.cpp
|
||||||
* @brief Main file for the Apple ADB Ressurector project.
|
* @brief Main file for the Apple ADB Ressurector project.
|
||||||
|
|
||||||
* Inspiré et basé sur le travail initial de Szymon Łopaciuk https://github.com/szymonlopaciuk/stm32-adb2usb
|
* Inspiré et basé sur le travail initial de Szymon Łopaciuk
|
||||||
|
https://github.com/szymonlopaciuk/stm32-adb2usb
|
||||||
* @credits Szymon Łopaciuk
|
* @credits Szymon Łopaciuk
|
||||||
* @author Clément SAILLANT
|
* @author Clément SAILLANT
|
||||||
* @date 2025
|
* @date 2025
|
||||||
@@ -12,9 +13,9 @@
|
|||||||
|
|
||||||
#ifndef UNIT_TEST
|
#ifndef UNIT_TEST
|
||||||
|
|
||||||
#include <ADB.h>
|
|
||||||
#include "hid_keyboard.h"
|
#include "hid_keyboard.h"
|
||||||
#include "hid_mouse.h"
|
#include "hid_mouse.h"
|
||||||
|
#include <ADB.h>
|
||||||
|
|
||||||
#define POLL_DELAY 5
|
#define POLL_DELAY 5
|
||||||
// Définition de la pin ADB selon la plateforme
|
// Définition de la pin ADB selon la plateforme
|
||||||
@@ -38,324 +39,405 @@
|
|||||||
* @brief Structure pour regrouper les états des périphériques.
|
* @brief Structure pour regrouper les états des périphériques.
|
||||||
*/
|
*/
|
||||||
struct DeviceState {
|
struct DeviceState {
|
||||||
bool apple_extended_detected = false; /**< Détection du clavier Apple étendu. */
|
bool apple_extended_detected =
|
||||||
bool keyboard_present = false; /**< Présence d'un clavier. */
|
false; /**< Détection du clavier Apple étendu. */
|
||||||
bool mouse_present = false; /**< Présence d'une souris. */
|
bool keyboard_present = false; /**< Présence d'un clavier. */
|
||||||
bool led_num = true; /**< État de la LED Num Lock (actif par défaut). */
|
bool mouse_present = false; /**< Présence d'une souris. */
|
||||||
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_scroll = false; /**< État de la LED Scroll Lock. */
|
bool led_caps = false; /**< État de la LED Caps Lock. */
|
||||||
bool led_power = false; /**< État de la LED Power. */
|
bool led_scroll = false; /**< État de la LED Scroll Lock. */
|
||||||
|
bool led_power = false; /**< État de la LED Power. */
|
||||||
};
|
};
|
||||||
|
|
||||||
// Instances globales
|
// Instances globales
|
||||||
ADB adb(ADB_PIN); /**< Instance du bus ADB. */
|
ADB adb(ADB_PIN); /**< Instance du bus ADB. */
|
||||||
ADBDevices adbDevices(adb); /**< Gestionnaire des périphériques ADB. */
|
ADBDevices adbDevices(adb); /**< Gestionnaire des périphériques ADB. */
|
||||||
DeviceState deviceState; /**< État des périphériques. */
|
DeviceState deviceState; /**< État des périphériques. */
|
||||||
static bool caps_lock_mechanical_state = false; /**< État mécanique de la touche Caps Lock. */
|
bool caps_lock_pressed = false; /**< État de la touche Caps Lock. */
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
#include <BLEDevice.h>
|
#include <BLEDevice.h>
|
||||||
#include <BLEHIDDevice.h>
|
#include <BLEHIDDevice.h>
|
||||||
#include <HIDTypes.h>
|
|
||||||
#include <HIDKeyboardTypes.h>
|
#include <HIDKeyboardTypes.h>
|
||||||
|
#include <HIDTypes.h>
|
||||||
|
|
||||||
// Déclaration de la structure InputReport
|
// Déclaration de la structure InputReport
|
||||||
struct InputReport {
|
struct InputReport {
|
||||||
uint8_t modifiers; // bitmask: CTRL = 1, SHIFT = 2, ALT = 4
|
uint8_t modifiers; // bitmask: CTRL = 1, SHIFT = 2, ALT = 4
|
||||||
uint8_t reserved; // doit être 0
|
uint8_t reserved; // doit être 0
|
||||||
uint8_t pressedKeys[6]; // jusqu'à six touches pressées simultanément
|
uint8_t pressedKeys[6]; // jusqu'à six touches pressées simultanément
|
||||||
};
|
};
|
||||||
|
|
||||||
// The report map describes the HID device (a keyboard in this case) and
|
// The report map describes the HID device (a keyboard in this case) and
|
||||||
// the messages (reports in HID terms) sent and received.
|
// the messages (reports in HID terms) sent and received.
|
||||||
static const uint8_t REPORT_MAP[] = {
|
static const uint8_t REPORT_MAP[] = {
|
||||||
USAGE_PAGE(1), 0x01, // Generic Desktop Controls
|
USAGE_PAGE(1),
|
||||||
USAGE(1), 0x06, // Keyboard
|
0x01, // Generic Desktop Controls
|
||||||
COLLECTION(1), 0x01, // Application
|
USAGE(1),
|
||||||
REPORT_ID(1), 0x01, // Report ID (1)
|
0x06, // Keyboard
|
||||||
USAGE_PAGE(1), 0x07, // Keyboard/Keypad
|
COLLECTION(1),
|
||||||
USAGE_MINIMUM(1), 0xE0, // Keyboard Left Control
|
0x01, // Application
|
||||||
USAGE_MAXIMUM(1), 0xE7, // Keyboard Right Control
|
REPORT_ID(1),
|
||||||
LOGICAL_MINIMUM(1), 0x00, // Each bit is either 0 or 1
|
0x01, // Report ID (1)
|
||||||
LOGICAL_MAXIMUM(1), 0x01,
|
USAGE_PAGE(1),
|
||||||
REPORT_COUNT(1), 0x08, // 8 bits for the modifier keys
|
0x07, // Keyboard/Keypad
|
||||||
REPORT_SIZE(1), 0x01,
|
USAGE_MINIMUM(1),
|
||||||
HIDINPUT(1), 0x02, // Data, Var, Abs
|
0xE0, // Keyboard Left Control
|
||||||
REPORT_COUNT(1), 0x01, // 1 byte (unused)
|
USAGE_MAXIMUM(1),
|
||||||
REPORT_SIZE(1), 0x08,
|
0xE7, // Keyboard Right Control
|
||||||
HIDINPUT(1), 0x01, // Const, Array, Abs
|
LOGICAL_MINIMUM(1),
|
||||||
REPORT_COUNT(1), 0x06, // 6 bytes (for up to 6 concurrently pressed keys)
|
0x00, // Each bit is either 0 or 1
|
||||||
REPORT_SIZE(1), 0x08,
|
LOGICAL_MAXIMUM(1),
|
||||||
LOGICAL_MINIMUM(1), 0x00,
|
0x01,
|
||||||
LOGICAL_MAXIMUM(1), 0x65, // 101 keys
|
REPORT_COUNT(1),
|
||||||
USAGE_MINIMUM(1), 0x00,
|
0x08, // 8 bits for the modifier keys
|
||||||
USAGE_MAXIMUM(1), 0x65,
|
REPORT_SIZE(1),
|
||||||
HIDINPUT(1), 0x00, // Data, Array, Abs
|
0x01,
|
||||||
REPORT_COUNT(1), 0x05, // 5 bits (Num lock, Caps lock, Scroll lock, Compose, Kana)
|
HIDINPUT(1),
|
||||||
REPORT_SIZE(1), 0x01,
|
0x02, // Data, Var, Abs
|
||||||
USAGE_PAGE(1), 0x08, // LEDs
|
REPORT_COUNT(1),
|
||||||
USAGE_MINIMUM(1), 0x01, // Num Lock
|
0x01, // 1 byte (unused)
|
||||||
USAGE_MAXIMUM(1), 0x05, // Kana
|
REPORT_SIZE(1),
|
||||||
LOGICAL_MINIMUM(1), 0x00,
|
0x08,
|
||||||
LOGICAL_MAXIMUM(1), 0x01,
|
HIDINPUT(1),
|
||||||
HIDOUTPUT(1), 0x02, // Data, Var, Abs
|
0x01, // Const, Array, Abs
|
||||||
REPORT_COUNT(1), 0x01, // 3 bits (Padding)
|
REPORT_COUNT(1),
|
||||||
REPORT_SIZE(1), 0x03,
|
0x06, // 6 bytes (for up to 6 concurrently pressed keys)
|
||||||
HIDOUTPUT(1), 0x01, // Const, Array, Abs
|
REPORT_SIZE(1),
|
||||||
END_COLLECTION(0) // End application collection
|
0x08,
|
||||||
|
LOGICAL_MINIMUM(1),
|
||||||
|
0x00,
|
||||||
|
LOGICAL_MAXIMUM(1),
|
||||||
|
0x65, // 101 keys
|
||||||
|
USAGE_MINIMUM(1),
|
||||||
|
0x00,
|
||||||
|
USAGE_MAXIMUM(1),
|
||||||
|
0x65,
|
||||||
|
HIDINPUT(1),
|
||||||
|
0x00, // Data, Array, Abs
|
||||||
|
REPORT_COUNT(1),
|
||||||
|
0x05, // 5 bits (Num lock, Caps lock, Scroll lock, Compose, Kana)
|
||||||
|
REPORT_SIZE(1),
|
||||||
|
0x01,
|
||||||
|
USAGE_PAGE(1),
|
||||||
|
0x08, // LEDs
|
||||||
|
USAGE_MINIMUM(1),
|
||||||
|
0x01, // Num Lock
|
||||||
|
USAGE_MAXIMUM(1),
|
||||||
|
0x05, // Kana
|
||||||
|
LOGICAL_MINIMUM(1),
|
||||||
|
0x00,
|
||||||
|
LOGICAL_MAXIMUM(1),
|
||||||
|
0x01,
|
||||||
|
HIDOUTPUT(1),
|
||||||
|
0x02, // Data, Var, Abs
|
||||||
|
REPORT_COUNT(1),
|
||||||
|
0x01, // 3 bits (Padding)
|
||||||
|
REPORT_SIZE(1),
|
||||||
|
0x03,
|
||||||
|
HIDOUTPUT(1),
|
||||||
|
0x01, // Const, Array, Abs
|
||||||
|
END_COLLECTION(0) // End application collection
|
||||||
};
|
};
|
||||||
|
|
||||||
// Déclarations HID Bluetooth
|
// Déclarations HID Bluetooth
|
||||||
BLEHIDDevice* hid;
|
BLEHIDDevice *hid;
|
||||||
BLECharacteristic* input_keyboard;
|
BLECharacteristic *input_keyboard;
|
||||||
BLECharacteristic* input_mouse;
|
BLECharacteristic *input_mouse;
|
||||||
BLECharacteristic* output_keyboard;
|
BLECharacteristic *output_keyboard;
|
||||||
bool isBleConnected = false;
|
bool isBleConnected = false;
|
||||||
|
|
||||||
const InputReport NO_KEY_PRESSED = { };
|
const InputReport NO_KEY_PRESSED = {};
|
||||||
|
|
||||||
// Callbacks pour la connexion BLE
|
// Callbacks pour la connexion BLE
|
||||||
class BleHIDCallbacks : public BLEServerCallbacks {
|
class BleHIDCallbacks : public BLEServerCallbacks {
|
||||||
void onConnect(BLEServer* server) {
|
void onConnect(BLEServer *server) {
|
||||||
isBleConnected = true;
|
isBleConnected = true;
|
||||||
|
|
||||||
BLE2902* cccDescKeyboard = (BLE2902*)input_keyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
|
BLE2902 *cccDescKeyboard = (BLE2902 *)input_keyboard->getDescriptorByUUID(
|
||||||
cccDescKeyboard->setNotifications(true);
|
BLEUUID((uint16_t)0x2902));
|
||||||
|
cccDescKeyboard->setNotifications(true);
|
||||||
|
|
||||||
BLE2902* cccDescMouse = (BLE2902*)input_mouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
|
BLE2902 *cccDescMouse =
|
||||||
cccDescMouse->setNotifications(true);
|
(BLE2902 *)input_mouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
|
||||||
|
cccDescMouse->setNotifications(true);
|
||||||
|
|
||||||
Serial.println("Client connecté au clavier et souris HID Bluetooth.");
|
Serial.println("Client connecté au clavier et souris HID Bluetooth.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDisconnect(BLEServer* server) {
|
void onDisconnect(BLEServer *server) {
|
||||||
isBleConnected = false;
|
isBleConnected = false;
|
||||||
|
|
||||||
BLE2902* cccDescKeyboard = (BLE2902*)input_keyboard->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
|
BLE2902 *cccDescKeyboard = (BLE2902 *)input_keyboard->getDescriptorByUUID(
|
||||||
cccDescKeyboard->setNotifications(false);
|
BLEUUID((uint16_t)0x2902));
|
||||||
|
cccDescKeyboard->setNotifications(false);
|
||||||
|
|
||||||
BLE2902* cccDescMouse = (BLE2902*)input_mouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
|
BLE2902 *cccDescMouse =
|
||||||
cccDescMouse->setNotifications(false);
|
(BLE2902 *)input_mouse->getDescriptorByUUID(BLEUUID((uint16_t)0x2902));
|
||||||
|
cccDescMouse->setNotifications(false);
|
||||||
|
|
||||||
Serial.println("Client déconnecté du clavier et souris HID Bluetooth.");
|
Serial.println("Client déconnecté du clavier et souris HID Bluetooth.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Callbacks pour les LEDs (Num Lock, Caps Lock, etc.)
|
// Callbacks pour les LEDs (Num Lock, Caps Lock, etc.)
|
||||||
class OutputCallbacks : public BLECharacteristicCallbacks {
|
class OutputCallbacks : public BLECharacteristicCallbacks {
|
||||||
void onWrite(BLECharacteristic* characteristic) {
|
void onWrite(BLECharacteristic *characteristic) {
|
||||||
uint8_t* data = characteristic->getData();
|
uint8_t *data = characteristic->getData();
|
||||||
Serial.print("LED state (Bluetooth): ");
|
Serial.print("LED state (Bluetooth): ");
|
||||||
Serial.println(*data, HEX);
|
Serial.println(*data, HEX);
|
||||||
|
|
||||||
// Synchronisation des états des LEDs
|
// Synchronisation des états des LEDs
|
||||||
deviceState.led_num = (*data & 0x01) != 0; // Num Lock
|
//deviceState.led_num = (*data & 0x01) != 0; // Num Lock
|
||||||
deviceState.led_caps = (*data & 0x02) != 0; // Caps Lock
|
//deviceState.led_caps = (*data & 0x02) != 0; // Caps Lock
|
||||||
|
|
||||||
// Si la touche Caps Lock du clavier ADB est mécaniquement active, réactivez le verrouillage
|
// Suppression de la réactivation automatique de Caps Lock
|
||||||
if (caps_lock_mechanical_state && !deviceState.led_caps) {
|
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps,
|
||||||
deviceState.led_caps = true;
|
deviceState.led_scroll);
|
||||||
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps, deviceState.led_scroll);
|
|
||||||
Serial.println("Réactivation de Caps Lock en raison de l'état mécanique du clavier ADB.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour des LEDs sur le clavier ADB
|
Serial.print("bluetooth LED Num Lock : ");
|
||||||
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps, deviceState.led_scroll);
|
Serial.println(deviceState.led_num ? "Allumée" : "Éteinte");
|
||||||
|
Serial.print("bluetooth LED Caps Lock : ");
|
||||||
|
Serial.println(deviceState.led_caps ? "Allumée" : "Éteinte");
|
||||||
|
|
||||||
Serial.print("LED Num Lock : ");
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
Serial.println(deviceState.led_num ? "Allumée" : "Éteinte");
|
if (isBleConnected) {
|
||||||
Serial.print("LED Caps Lock : ");
|
uint8_t buf[1] = {static_cast<uint8_t>((deviceState.led_caps << 1) |
|
||||||
Serial.println(deviceState.led_caps ? "Allumée" : "Éteinte");
|
deviceState.led_num)};
|
||||||
|
output_keyboard->setValue(buf, sizeof(buf));
|
||||||
|
output_keyboard->notify();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void bluetoothTask(void*) {
|
void bluetoothTask(void *) {
|
||||||
BLEDevice::init("ESP32 HID Device");
|
BLEDevice::init("Apple ADB Ressurector");
|
||||||
BLEServer* server = BLEDevice::createServer();
|
BLEServer *server = BLEDevice::createServer();
|
||||||
server->setCallbacks(new BleHIDCallbacks());
|
server->setCallbacks(new BleHIDCallbacks());
|
||||||
|
|
||||||
hid = new BLEHIDDevice(server);
|
hid = new BLEHIDDevice(server);
|
||||||
input_keyboard = hid->inputReport(1); // Report ID 1 pour le clavier
|
input_keyboard = hid->inputReport(1); // Report ID 1 pour le clavier
|
||||||
input_mouse = hid->inputReport(2); // Report ID 2 pour la souris
|
input_mouse = hid->inputReport(2); // Report ID 2 pour la souris
|
||||||
output_keyboard = hid->outputReport(1); // Report ID 1 pour les LEDs clavier
|
output_keyboard = hid->outputReport(1); // Report ID 1 pour les LEDs clavier
|
||||||
output_keyboard->setCallbacks(new OutputCallbacks());
|
output_keyboard->setCallbacks(new OutputCallbacks());
|
||||||
|
|
||||||
hid->manufacturer()->setValue("Maker Community");
|
hid->manufacturer()->setValue("Maker Community");
|
||||||
hid->pnp(0x02, 0xe502, 0xa111, 0x0210);
|
hid->pnp(0x02, 0xe502, 0xa111, 0x0210);
|
||||||
hid->hidInfo(0x00, 0x02);
|
hid->hidInfo(0x00, 0x02);
|
||||||
|
|
||||||
BLESecurity* security = new BLESecurity();
|
BLESecurity *security = new BLESecurity();
|
||||||
security->setAuthenticationMode(ESP_LE_AUTH_BOND);
|
security->setAuthenticationMode(ESP_LE_AUTH_BOND);
|
||||||
|
|
||||||
// Rapport HID pour clavier et souris
|
// Rapport HID pour clavier et souris
|
||||||
hid->reportMap((uint8_t*)REPORT_MAP, sizeof(REPORT_MAP));
|
hid->reportMap((uint8_t *)REPORT_MAP, sizeof(REPORT_MAP));
|
||||||
hid->startServices();
|
hid->startServices();
|
||||||
|
|
||||||
BLEAdvertising* advertising = server->getAdvertising();
|
BLEAdvertising *advertising = server->getAdvertising();
|
||||||
advertising->setAppearance(HID_KEYBOARD);
|
advertising->setAppearance(HID_KEYBOARD);
|
||||||
advertising->addServiceUUID(hid->hidService()->getUUID());
|
advertising->addServiceUUID(hid->hidService()->getUUID());
|
||||||
advertising->start();
|
advertising->start();
|
||||||
|
|
||||||
Serial.println("Bluetooth HID prêt.");
|
Serial.println("Bluetooth HID prêt.");
|
||||||
delay(portMAX_DELAY);
|
delay(portMAX_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupBluetoothTask() {
|
void setupBluetoothTask() {
|
||||||
xTaskCreate(bluetoothTask, "bluetooth", 20000, NULL, 5, NULL);
|
xTaskCreate(bluetoothTask, "bluetooth", 20000, NULL, 5, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise un périphérique ADB.
|
* @brief Initialise un périphérique ADB.
|
||||||
*
|
*
|
||||||
* @param addr Adresse du périphérique.
|
* @param addr Adresse du périphérique.
|
||||||
* @param handler_id Identifiant du gestionnaire de périphérique.
|
* @param handler_id Identifiant du gestionnaire de périphérique.
|
||||||
* @return true si l'initialisation a réussi, false sinon.
|
* @return true si l'initialisation a réussi, false sinon.
|
||||||
*/
|
*/
|
||||||
bool initializeDevice(uint8_t addr, uint8_t handler_id) {
|
bool initializeDevice(uint8_t addr, uint8_t handler_id) {
|
||||||
bool error = false;
|
bool error = false;
|
||||||
adb_data<adb_register3> reg3 = {0}, mask = {0};
|
adb_data<adb_register3> reg3 = {0}, mask = {0};
|
||||||
reg3.data.device_handler_id = handler_id;
|
reg3.data.device_handler_id = handler_id;
|
||||||
mask.data.device_handler_id = 0xFF;
|
mask.data.device_handler_id = 0xFF;
|
||||||
return adbDevices.deviceUpdateRegister3(addr, reg3, mask.raw, &error) && !error;
|
return adbDevices.deviceUpdateRegister3(addr, reg3, mask.raw, &error) &&
|
||||||
|
!error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fonction d'initialisation du programme.
|
* @brief Fonction d'initialisation du programme.
|
||||||
*/
|
*/
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(LED_PIN, OUTPUT); // Configuration de la pin LED
|
pinMode(LED_PIN, OUTPUT); // Configuration de la pin LED
|
||||||
digitalWrite(LED_PIN, LOW); // État initial de la LED
|
digitalWrite(LED_PIN, LOW); // État initial de la LED
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Initialisation du programme...");
|
Serial.println("Initialisation du programme...");
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
setupBluetoothTask(); // Lancer la tâche Bluetooth
|
setupBluetoothTask(); // Lancer la tâche Bluetooth
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hid_keyboard_init();
|
hid_keyboard_init();
|
||||||
hid_mouse_init();
|
hid_mouse_init();
|
||||||
Serial.println("HID initialisé.");
|
Serial.println("HID initialisé.");
|
||||||
|
|
||||||
adb.init(ADB_PIN, true);
|
adb.init(ADB_PIN, true);
|
||||||
Serial.println("Bus ADB initialisé.");
|
Serial.println("Bus ADB initialisé.");
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
deviceState.keyboard_present = initializeDevice(ADBKey::Address::KEYBOARD, 0x03);
|
deviceState.keyboard_present =
|
||||||
Serial.print("Clavier détecté : ");
|
initializeDevice(ADBKey::Address::KEYBOARD, 0x03);
|
||||||
Serial.println(deviceState.keyboard_present ? "Oui" : "Non");
|
Serial.print("Clavier détecté : ");
|
||||||
|
Serial.println(deviceState.keyboard_present ? "Oui" : "Non");
|
||||||
|
|
||||||
deviceState.mouse_present = initializeDevice(ADBKey::Address::MOUSE, 0x02);
|
deviceState.mouse_present = initializeDevice(ADBKey::Address::MOUSE, 0x02);
|
||||||
Serial.print("Souris détectée : ");
|
Serial.print("Souris détectée : ");
|
||||||
Serial.println(deviceState.mouse_present ? "Oui" : "Non");
|
Serial.println(deviceState.mouse_present ? "Oui" : "Non");
|
||||||
|
|
||||||
digitalWrite(LED_PIN, HIGH); // Allumer la LED après l'initialisation
|
digitalWrite(LED_PIN, HIGH); // Allumer la LED après l'initialisation
|
||||||
|
|
||||||
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps, deviceState.led_scroll);
|
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps,
|
||||||
Serial.println("LEDs initialisées.");
|
deviceState.led_scroll);
|
||||||
|
Serial.println("LEDs initialisées.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gère les événements du clavier.
|
* @brief Gère les événements du clavier.
|
||||||
*/
|
*/
|
||||||
void handleKeyboard() {
|
void handleKeyboard() {
|
||||||
static hid_key_report key_report = {0};
|
static hid_key_report key_report = {0};
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
auto key_press = adbDevices.keyboardReadKeyPress(&error);
|
auto key_press = adbDevices.keyboardReadKeyPress(&error);
|
||||||
if (error) {
|
if (error) {
|
||||||
// Serial.println("Erreur lors de la lecture des touches du clavier.");
|
return;
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
bool report_changed =
|
||||||
|
hid_keyboard_set_keys_from_adb_register(&key_report, key_press);
|
||||||
|
|
||||||
|
// Gestion de Caps Lock
|
||||||
|
if (key_press.data.key0 == ADBKey::KeyCode::CAPS_LOCK ||
|
||||||
|
key_press.data.key1 == ADBKey::KeyCode::CAPS_LOCK) {
|
||||||
|
bool is_pressed = (key_press.data.key0 == ADBKey::KeyCode::CAPS_LOCK &&
|
||||||
|
!key_press.data.released0) ||
|
||||||
|
(key_press.data.key1 == ADBKey::KeyCode::CAPS_LOCK &&
|
||||||
|
!key_press.data.released1);
|
||||||
|
|
||||||
|
if (is_pressed) {
|
||||||
|
// Activer Caps Lock
|
||||||
|
deviceState.led_caps = true;
|
||||||
|
Serial.println("Caps Lock activé.");
|
||||||
|
report_changed = true;
|
||||||
|
|
||||||
|
// Envoyer un événement de pression pour Caps Lock
|
||||||
|
key_report.keys[0] = ADBKey::KeyCode::CAPS_LOCK;
|
||||||
|
hid_keyboard_send_report(&key_report);
|
||||||
|
Serial.println("Événement de pression de Caps Lock envoyé.");
|
||||||
|
|
||||||
|
delay(100); // Attendre un court instant pour éviter les rebonds
|
||||||
|
// Envoyer un événement de relâchement pour Caps Lock
|
||||||
|
key_report.keys[0] = 0;
|
||||||
|
hid_keyboard_send_report(&key_report);
|
||||||
|
Serial.println("Événement de relâchement de Caps Lock envoyé.");
|
||||||
|
} else {
|
||||||
|
// Désactiver Caps Lock au relâchement
|
||||||
|
deviceState.led_caps = false;
|
||||||
|
Serial.println("Caps Lock désactivé.");
|
||||||
|
report_changed = true;
|
||||||
|
|
||||||
|
// Envoyer un événement de pression pour Caps Lock
|
||||||
|
key_report.keys[0] = ADBKey::KeyCode::CAPS_LOCK;
|
||||||
|
hid_keyboard_send_report(&key_report);
|
||||||
|
Serial.println("Événement de pression de Caps Lock envoyé.");
|
||||||
|
delay(100); // Attendre un court instant pour éviter les rebonds
|
||||||
|
// Envoyer un événement de relâchement pour Caps Lock
|
||||||
|
key_report.keys[0] = 0;
|
||||||
|
hid_keyboard_send_report(&key_report);
|
||||||
|
Serial.println("Événement de relâchement de Caps Lock envoyé.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool report_changed = hid_keyboard_set_keys_from_adb_register(&key_report, key_press);
|
// Gestion de Num Lock
|
||||||
|
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;
|
||||||
|
Serial.print("Num Lock LED (ADB) : ");
|
||||||
|
Serial.println(deviceState.led_num ? "Allumée" : "Éteinte");
|
||||||
|
report_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Gestion de Caps Lock
|
if (report_changed) {
|
||||||
if (key_press.data.key0 == ADBKey::KeyCode::CAPS_LOCK || key_press.data.key1 == ADBKey::KeyCode::CAPS_LOCK) {
|
Serial.println("Rapport clavier mis à jour.");
|
||||||
if (!key_press.data.released0 || !key_press.data.released1) {
|
hid_keyboard_send_report(&key_report);
|
||||||
// Si la touche est pressée, activez le verrouillage
|
|
||||||
if (!deviceState.led_caps) {
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
deviceState.led_caps = true;
|
if (isBleConnected) {
|
||||||
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps, deviceState.led_scroll);
|
uint8_t buf[1] = {static_cast<uint8_t>((deviceState.led_caps << 1) |
|
||||||
Serial.println("Caps Lock activé.");
|
deviceState.led_num)};
|
||||||
report_changed = true;
|
output_keyboard->setValue(buf, sizeof(buf));
|
||||||
}
|
output_keyboard->notify();
|
||||||
} else {
|
|
||||||
// Si la touche est relâchée, désactivez le verrouillage
|
|
||||||
if (deviceState.led_caps) {
|
|
||||||
deviceState.led_caps = false;
|
|
||||||
adbDevices.keyboardWriteLEDs(deviceState.led_num, deviceState.led_caps, deviceState.led_scroll);
|
|
||||||
Serial.println("Caps Lock désactivé.");
|
|
||||||
report_changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestion de Num Lock
|
|
||||||
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(deviceState.led_num, deviceState.led_caps, deviceState.led_scroll);
|
|
||||||
Serial.print("Num Lock LED (ADB) : ");
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gère les événements de la souris.
|
* @brief Gère les événements de la souris.
|
||||||
*/
|
*/
|
||||||
void handleMouse() {
|
void handleMouse() {
|
||||||
bool error = false;
|
bool error = false;
|
||||||
|
|
||||||
auto mouse_data = adbDevices.mouseReadData(&error);
|
auto mouse_data = adbDevices.mouseReadData(&error);
|
||||||
if (error || mouse_data.raw == 0) {
|
if (error || mouse_data.raw == 0) {
|
||||||
// if (error) Serial.println("Erreur lors de la lecture des données de la souris.");
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int8_t mouse_x = adbMouseConvertAxis(mouse_data.data.x_offset);
|
int8_t mouse_x = adbMouseConvertAxis(mouse_data.data.x_offset);
|
||||||
int8_t mouse_y = adbMouseConvertAxis(mouse_data.data.y_offset);
|
int8_t mouse_y = adbMouseConvertAxis(mouse_data.data.y_offset);
|
||||||
|
|
||||||
Serial.print("Mouvement souris - X: ");
|
Serial.print("Mouvement souris - X: ");
|
||||||
Serial.print(mouse_x);
|
Serial.print(mouse_x);
|
||||||
Serial.print(", Y: ");
|
Serial.print(", Y: ");
|
||||||
Serial.println(mouse_y);
|
Serial.println(mouse_y);
|
||||||
|
|
||||||
hid_mouse_send_report(mouse_data.data.button ? 0 : 1, mouse_x, mouse_y);
|
// Envoyer le rapport HID pour la souris
|
||||||
|
hid_mouse_send_report(mouse_data.data.button ? 0 : 1, mouse_x, mouse_y);
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
if (isBleConnected) {
|
if (isBleConnected) {
|
||||||
uint8_t buf[4] = {mouse_data.data.button ? 0 : 1, (uint8_t)mouse_x, (uint8_t)mouse_y, 0};
|
uint8_t buf[4] = {
|
||||||
input_mouse->setValue(buf, sizeof(buf));
|
static_cast<uint8_t>(mouse_data.data.button ? 0 : 1), // Bouton
|
||||||
input_mouse->notify();
|
static_cast<uint8_t>(mouse_x), // Déplacement X
|
||||||
}
|
static_cast<uint8_t>(mouse_y), // Déplacement Y
|
||||||
#endif
|
0 // Molette (non utilisée)
|
||||||
|
};
|
||||||
|
input_mouse->setValue(buf, sizeof(buf));
|
||||||
|
input_mouse->notify();
|
||||||
|
Serial.println("Rapport HID souris envoyé via Bluetooth.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Boucle principale du programme.
|
* @brief Boucle principale du programme.
|
||||||
*/
|
*/
|
||||||
void loop() {
|
void loop() {
|
||||||
if (deviceState.keyboard_present) {
|
if (deviceState.keyboard_present) {
|
||||||
// Serial.println("Gestion du clavier...");
|
// Serial.println("Gestion du clavier...");
|
||||||
handleKeyboard();
|
handleKeyboard();
|
||||||
delay(POLL_DELAY);
|
delay(POLL_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deviceState.mouse_present) {
|
if (deviceState.mouse_present) {
|
||||||
// Serial.println("Gestion de la souris...");
|
// Serial.println("Gestion de la souris...");
|
||||||
handleMouse();
|
handleMouse();
|
||||||
delay(POLL_DELAY);
|
delay(POLL_DELAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user