unify indentation across project

Signed-off-by: Szymon Łopaciuk <szymon@lopaciuk.eu>
This commit is contained in:
Szymon Łopaciuk
2021-03-08 21:46:06 +00:00
parent c1ec40ea59
commit 2445fff3df
5 changed files with 135 additions and 135 deletions
+20 -20
View File
@@ -14,33 +14,33 @@ board = bluepill_f103c8_128k
framework = arduino framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries lib_extra_dirs = ~/Documents/Arduino/libraries
build_flags = build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_HID -D PIO_FRAMEWORK_ARDUINO_ENABLE_HID
-D USBCON -D USBCON
-D USBD_VID=0x0483 -D USBD_VID=0x0483
-D USBD_PID=0x5711 -D USBD_PID=0x5711
-D USB_MANUFACTURER="STMicroelectronics" -D USB_MANUFACTURER="STMicroelectronics"
-D USB_PRODUCT="Apple Desktop Bus Device" -D USB_PRODUCT="Apple Desktop Bus Device"
-D HAL_PCD_MODULE_ENABLED -D HAL_PCD_MODULE_ENABLED
;-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC ;-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
;-D PIO_FRAMEWORK_ARDUINO_USB_FULLSPEED_FULLMODE ;-D PIO_FRAMEWORK_ARDUINO_USB_FULLSPEED_FULLMODE
upload_flags = -c set CPUTAPID 0x2ba01477 ; Chinese clone, genuine is 0x1ba01477 upload_flags = -c set CPUTAPID 0x2ba01477 ; Chinese clone, genuine is 0x1ba01477
debug_tool = stlink debug_tool = stlink
upload_protocol = stlink upload_protocol = stlink
debug_server = debug_server =
/Users/szymonlopaciuk/.platformio/packages/tool-openocd/bin/openocd /Users/szymonlopaciuk/.platformio/packages/tool-openocd/bin/openocd
-s /Users/szymonlopaciuk/.platformio/packages/tool-openocd/scripts -s /Users/szymonlopaciuk/.platformio/packages/tool-openocd/scripts
-f interface/stlink-v2.cfg -f interface/stlink-v2.cfg
-c "transport select hla_swd" -c "transport select hla_swd"
-c "set CPUTAPID 0x2ba01477" ; Chinese clone, genuine is 0x1ba01477 -c "set CPUTAPID 0x2ba01477" ; Chinese clone, genuine is 0x1ba01477
-f target/stm32f1x.cfg -f target/stm32f1x.cfg
-c "reset_config none" -c "reset_config none"
test_ignore = test_desktop test_ignore = test_desktop
[env:native] [env:native]
platform = native platform = native
build_flags = build_flags =
-D USBCON -D USBCON
-D USBD_USE_HID_COMPOSITE -D USBD_USE_HID_COMPOSITE
-D PIO_FRAMEWORK_ARDUINO_ENABLE_HID -D PIO_FRAMEWORK_ARDUINO_ENABLE_HID
-I $PROJECT_DIR/test/test_desktop/include -I $PROJECT_DIR/test/test_desktop/include
test_build_project_src = true test_build_project_src = true
+2 -2
View File
@@ -7,8 +7,8 @@
#define KEY_REPORT_KEYS_COUNT 6 #define KEY_REPORT_KEYS_COUNT 6
struct hid_key_report { struct hid_key_report {
uint8_t modifiers; uint8_t modifiers;
uint8_t keys[KEY_REPORT_KEYS_COUNT]; uint8_t keys[KEY_REPORT_KEYS_COUNT];
}; };
void hid_keyboard_init(); void hid_keyboard_init();
+97 -97
View File
@@ -16,141 +16,141 @@ bool keyboard_present = false, mouse_present = false;
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_CDC #ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
void print16b(uint16_t buff) { void print16b(uint16_t buff) {
uint16_t mask = (1 << 15); uint16_t mask = (1 << 15);
for (uint8_t i = 0; i < 16; i++) for (uint8_t i = 0; i < 16; i++)
{ {
Serial.write(buff & mask ? '1' : '0'); Serial.write(buff & mask ? '1' : '0');
mask >>= 1; mask >>= 1;
} }
Serial.write('\n'); Serial.write('\n');
Serial.flush(); Serial.flush();
} }
void printkbresp(adb_kb_keypress buff) { void printkbresp(adb_kb_keypress buff) {
//Keyboard.print(" key1 "); //Keyboard.print(" key1 ");
Serial.print(buff.released0 ? "u" : "d"); Serial.print(buff.released0 ? "u" : "d");
Serial.print(buff.key0, 16); Serial.print(buff.key0, 16);
Serial.print(", "); Serial.print(", ");
Serial.print(buff.released1 ? "u" : "d"); Serial.print(buff.released1 ? "u" : "d");
Serial.print(buff.key1, 16); Serial.print(buff.key1, 16);
Serial.print("\n"); Serial.print("\n");
Serial.flush(); Serial.flush();
} }
#endif #endif
void setup() { void setup() {
// Turn the led on at the beginning of setup // Turn the led on at the beginning of setup
pinMode(PC13, OUTPUT); pinMode(PC13, OUTPUT);
digitalWrite(PC13, LOW); digitalWrite(PC13, LOW);
#ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_CDC #ifdef PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
Serial.begin(115200); Serial.begin(115200);
#endif #endif
// Set up HID // Set up HID
hid_keyboard_init(); hid_keyboard_init();
// Set up the ADB bus // Set up the ADB bus
adb_init(); adb_init();
delay(1000); // A wait for good measure, apparently AEKII can take a moment to reset delay(1000); // A wait for good measure, apparently AEKII can take a moment to reset
// Initialise the ADB devices // Initialise the ADB devices
// Switch the keyboard to Apple Extended if available // Switch the keyboard to Apple Extended if available
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 = 0x03; reg3.data.device_handler_id = 0x03;
mask.data.device_handler_id = 0xFF; mask.data.device_handler_id = 0xFF;
apple_extended_detected = adb_device_update_register3(ADB_ADDR_KEYBOARD, reg3, mask.raw, &error); apple_extended_detected = adb_device_update_register3(ADB_ADDR_KEYBOARD, reg3, mask.raw, &error);
if (!error) keyboard_present = true, if (!error) keyboard_present = true,
// Switch the mouse to higher resolution, if available // Switch the mouse to higher resolution, if available
// TODO: Apple Extended Mouse Protocol (Handler = 4) // TODO: Apple Extended Mouse Protocol (Handler = 4)
error = false; error = false;
reg3.raw = 0; reg3.raw = 0;
mask.raw = 0; mask.raw = 0;
reg3.data.device_handler_id = 0x02; reg3.data.device_handler_id = 0x02;
mask.data.device_handler_id = 0xFF; mask.data.device_handler_id = 0xFF;
adb_device_update_register3(ADB_ADDR_MOUSE, reg3, mask.raw, &error); adb_device_update_register3(ADB_ADDR_MOUSE, reg3, mask.raw, &error);
if (!error) mouse_present = true; if (!error) mouse_present = true;
// Set-up successful, turn of the LED // Set-up successful, turn of the LED
digitalWrite(PC13, HIGH); digitalWrite(PC13, HIGH);
} }
void keyboard_handler() { void keyboard_handler() {
static bool led_caps = false; static bool led_caps = false;
static hid_key_report key_report = {0}; static hid_key_report key_report = {0};
bool error = false; bool error = false;
auto key_press = adb_keyboard_read_key_press(&error); auto key_press = adb_keyboard_read_key_press(&error);
if (error) return; // don't continue changing the hid report if there was if (error) return; // don't continue changing the hid report if there was
// an error reading from ADB most often it's a timeout // an error reading from ADB most often it's a timeout
bool report_changed = hid_keyboard_set_keys_from_adb_register(&key_report, key_press); bool report_changed = hid_keyboard_set_keys_from_adb_register(&key_report, key_press);
// Handle the `toggle' caps lock key. // Handle the `toggle' caps lock key.
// Every action reported by an ADB keyboard on the caps lock key // Every action reported by an ADB keyboard on the caps lock key
// should be interpreted as key down, followed by key released, // should be interpreted as key down, followed by key released,
// unless the keypress was so fast, that it was pressed and depressed // unless the keypress was so fast, that it was pressed and depressed
// within the same `register'. Then ignore. // within the same `register'. Then ignore.
bool caps_lock_action = key_press.data.key0 == ADB_KEY_CAPS_LOCK || bool caps_lock_action = key_press.data.key0 == ADB_KEY_CAPS_LOCK ||
key_press.data.key1 == 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 && 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.key1 == ADB_KEY_CAPS_LOCK &&
key_press.data.released0 != key_press.data.released1; key_press.data.released0 != key_press.data.released1;
if (caps_lock_action && !caps_lock_twice_in_register) if (caps_lock_action && !caps_lock_twice_in_register)
{ {
hid_keyboard_add_key_to_report(&key_report, KEY_CAPSLOCK); hid_keyboard_add_key_to_report(&key_report, KEY_CAPSLOCK);
// Send the preliminary report, with caps lock down // Send the preliminary report, with caps lock down
hid_keyboard_send_report(&key_report); hid_keyboard_send_report(&key_report);
led_caps = !led_caps; led_caps = !led_caps;
adb_keyboard_write_leds(0, led_caps, 0); adb_keyboard_write_leds(0, led_caps, 0);
// Wait a little bit // Wait a little bit
delay(80); delay(80);
// Now just release the caps lock key, and continue as before
hid_keyboard_remove_key_from_report(&key_report, KEY_CAPSLOCK);
report_changed = true;
}
// Now just release the caps lock key, and continue as before // Send the finished report
hid_keyboard_remove_key_from_report(&key_report, KEY_CAPSLOCK); //if (report_changed)
hid_keyboard_send_report(&key_report);
report_changed = true;
}
// Send the finished report
//if (report_changed)
hid_keyboard_send_report(&key_report);
} }
void mouse_handler() { void mouse_handler() {
bool error = false; bool error = false;
auto mouse_data = adb_mouse_read_data(&error); auto mouse_data = adb_mouse_read_data(&error);
if (error || mouse_data.raw == 0) return; if (error || mouse_data.raw == 0) return;
int8_t mouse_x = ADB_MOUSE_CONV_AXIS(mouse_data.data.x_offset); 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); int8_t mouse_y = ADB_MOUSE_CONV_AXIS(mouse_data.data.y_offset);
hid_mouse_send_report(mouse_data.data.button ? 0 : 1, mouse_x, mouse_y); hid_mouse_send_report(mouse_data.data.button ? 0 : 1, mouse_x, mouse_y);
} }
void loop() { void loop() {
if (keyboard_present) { if (keyboard_present) {
keyboard_handler(); keyboard_handler();
// Wait a tiny bit before polling again, // Wait a tiny bit before polling again,
// while ADB seems fairly tolerent of quick requests // while ADB seems fairly tolerent of quick requests
// we don't want to overwhelm USB either // we don't want to overwhelm USB either
delay(POLL_DELAY); delay(POLL_DELAY);
} }
if (mouse_present) { if (mouse_present) {
mouse_handler(); mouse_handler();
delay(POLL_DELAY); delay(POLL_DELAY);
} }
} }
#endif #endif
+14 -14
View File
@@ -2,21 +2,21 @@
#include <cstdint> #include <cstdint>
typedef struct { typedef struct {
uint8_t modifiers; uint8_t modifiers;
uint8_t reserved; uint8_t reserved;
uint8_t keys[6]; uint8_t keys[6];
} KeyReport; } KeyReport;
class Keyboard_ { class Keyboard_ {
private: private:
KeyReport _keyReport; KeyReport _keyReport;
void sendReport(KeyReport *keys) {}; void sendReport(KeyReport *keys) {};
public: public:
Keyboard_(void) {}; Keyboard_(void) {};
void begin(void) {}; void begin(void) {};
void end(void) {}; void end(void) {};
size_t write(uint8_t k) { return 0; }; size_t write(uint8_t k) { return 0; };
size_t press(uint8_t k) { return 0; }; size_t press(uint8_t k) { return 0; };
size_t release(uint8_t k) { return 0; }; size_t release(uint8_t k) { return 0; };
void releaseAll(void) {}; void releaseAll(void) {};
}; };
@@ -1,6 +1,6 @@
typedef enum { typedef enum {
HID_KEYBOARD, HID_KEYBOARD,
HID_MOUSE HID_MOUSE
} HID_Interface; } HID_Interface;
void HID_Composite_Init(HID_Interface device) { void HID_Composite_Init(HID_Interface device) {