Compare commits

...

16 Commits

Author SHA1 Message Date
demik
9c4dc1acb6 New FR-4 based front panel with shine-through LEDs 2024-06-08 23:19:15 +02:00
demik
bef062d1cd added complex PCB front panel 2024-06-07 23:17:22 +02:00
demik
1e142082b1 Upgraded SDK to v5.2.2 2024-06-06 20:44:51 +02:00
demik
75260870c7 fix ADB start and stop bit timings 2024-06-06 00:10:01 +02:00
demik
97a57e89ac added support for Kensington ADB Devices 2024-06-04 10:04:47 +02:00
demik
6a0e7ee968 early work to restore ADB to bluetooth functionality 2024-06-03 22:05:37 +02:00
demik
cfe3c0314a Updated ChangeLog to 1.4.5 2023-12-28 21:45:46 +01:00
demik
8dd60e2d20 Upgraded SDK to v5.1.2 2023-12-28 21:40:18 +01:00
demik
17be92fec7
Merge pull request #2 from ElectronicsArchiver/README-Rework
README Rework
2022-08-03 18:18:02 +02:00
ElectronicsArchiver
405194156c Merge branch 'README-Rework' of https://github.com/ElectronicsArchiver/quack into README-Rework 2022-08-03 12:08:08 -04:00
ElectronicsArchiver
72218018a4 Added Bigger Preview 2022-08-03 12:07:58 -04:00
トトも
6ad6c7bb4e
Adjusted Badge Style 2022-08-02 07:57:02 -04:00
ElectronicsArchiver
876920fd90 Updated Support Section 2022-07-05 06:56:52 -04:00
トトも
c211ab1f2c
Adjusted Spacing 2022-07-05 06:54:28 -04:00
ElectronicsArchiver
86f08d776b Formatted README 2022-07-05 06:51:16 -04:00
ElectronicsArchiver
0ca38e2f0a Cut Out Preview 2022-07-05 06:48:29 -04:00
22 changed files with 5556 additions and 685 deletions

View File

@ -1,6 +1,21 @@
## v1.4.6
- added support for ADB composite devices (Kensignton and some Joysticks)
- fixed ADB start and stop bit times (65 µs vs 70 µs, error in AN591)
- update to ESP-IDF v5.2.2
- https://github.com/espressif/esp-idf/releases/tag/v5.2.2
- fixed flash corruption after pairing too much devices (20+)
- fixed ADB host mode where the ESP boot was too fast (v5.2 regression)
## v1.4.5
- update to ESP-IDF v5.1.2
- https://github.com/espressif/esp-idf/releases/tag/v5.1.2
- big background update, lot of cleaning and rewrites
- as most patches are now mainstream, sdk patching is now minimal
- removed direct ABI bluedroid call
## v1.4.4
- update to ESP-IDF v4.2.3:
- https://github.com/espressif/esp-idf/releases/tag/v4.2.2
- https://github.com/espressif/esp-idf/releases/tag/v4.2.3
- mostly bluetooth related security and bug fixes
## v1.4.3
@ -18,4 +33,4 @@
## v1.4.0
- Initial firmare release
- 1.4.x series is compatible with PCB 1.4 (EDA subfolder)
- 1.4.x series is compatible with 1.3 and 1.4 PCBs (EDA subfolder)

3
EDA/.gitignore vendored
View File

@ -1,6 +1,9 @@
# tmp zip files
*.zip
# production folders
production
# KiCad backup files
*bak

BIN
EDA/Panels/Front/ADB.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -0,0 +1,201 @@
(footprint "LOGO" (version 20221018) (generator bitmap2component)
(layer "F.Cu")
(attr board_only exclude_from_pos_files exclude_from_bom)
(fp_text reference "G***" (at 0 0) (layer "F.SilkS")
(effects (font (size 1.5 1.5) (thickness 0.3)))
(tstamp bab20572-ab1f-4616-b2b2-53186f4f2c29)
)
(fp_text value "LOGO" (at 0.75 0) (layer "F.SilkS") hide
(effects (font (size 1.5 1.5) (thickness 0.3)))
(tstamp 74d306e1-5916-4e5a-bcfe-b8aff857e827)
)
(fp_poly
(pts
(xy -0.967687 0.339291)
(xy -0.863523 0.425217)
(xy -0.828276 0.464011)
(xy -0.792831 0.488322)
(xy -0.743544 0.501571)
(xy -0.666769 0.507180)
(xy -0.548862 0.508573)
(xy -0.530989 0.508620)
(xy -0.341151 0.517855)
(xy -0.194397 0.547254)
(xy -0.079715 0.600882)
(xy 0.013912 0.682801)
(xy 0.045610 0.721340)
(xy 0.078417 0.766596)
(xy 0.101268 0.809170)
(xy 0.116289 0.860518)
(xy 0.125609 0.932099)
(xy 0.131355 1.035369)
(xy 0.135654 1.181785)
(xy 0.136349 1.209947)
(xy 0.139425 1.365776)
(xy 0.139100 1.474832)
(xy 0.134440 1.546731)
(xy 0.124511 1.591091)
(xy 0.108378 1.617527)
(xy 0.095677 1.628535)
(xy 0.009875 1.662387)
(xy -0.081162 1.640472)
(xy -0.091722 1.634628)
(xy -0.114272 1.613811)
(xy -0.128849 1.575766)
(xy -0.137080 1.509794)
(xy -0.140591 1.405195)
(xy -0.141111 1.309529)
(xy -0.146892 1.125701)
(xy -0.165295 0.991346)
(xy -0.197916 0.900583)
(xy -0.246345 0.847530)
(xy -0.269376 0.835976)
(xy -0.317608 0.827890)
(xy -0.405795 0.821776)
(xy -0.517452 0.818649)
(xy -0.554464 0.818444)
(xy -0.672045 0.819513)
(xy -0.747861 0.825340)
(xy -0.796584 0.839856)
(xy -0.832886 0.866990)
(xy -0.863523 0.901227)
(xy -0.966157 0.987013)
(xy -1.081305 1.026299)
(xy -1.199489 1.024329)
(xy -1.311230 0.986344)
(xy -1.407049 0.917588)
(xy -1.477469 0.823301)
(xy -1.513010 0.708727)
(xy -1.504195 0.579108)
(xy -1.496115 0.551355)
(xy -1.430437 0.430842)
(xy -1.332604 0.346956)
(xy -1.214767 0.302121)
(xy -1.089078 0.298758)
)
(stroke (width 0.000000) (type solid)) (fill solid) (layer "F.SilkS") (tstamp c7a58463-b108-42ba-9a88-3d34cf5c1bf4))
(fp_poly
(pts
(xy 1.259897 -0.668993)
(xy 1.331506 -0.635877)
(xy 1.392588 -0.584544)
(xy 1.477977 -0.470504)
(xy 1.512294 -0.345050)
(xy 1.496646 -0.218291)
(xy 1.432143 -0.100335)
(xy 1.329326 -0.007428)
(xy 1.203830 0.045712)
(xy 1.074948 0.045922)
(xy 0.952682 -0.004896)
(xy 0.852152 -0.098214)
(xy 0.820579 -0.132945)
(xy 0.783631 -0.154070)
(xy 0.727320 -0.164935)
(xy 0.637658 -0.168887)
(xy 0.554901 -0.169333)
(xy 0.432714 -0.167543)
(xy 0.351560 -0.160029)
(xy 0.296086 -0.143577)
(xy 0.250935 -0.114973)
(xy 0.235987 -0.102580)
(xy 0.193251 -0.058852)
(xy 0.167831 -0.007829)
(xy 0.153713 0.068037)
(xy 0.146508 0.158475)
(xy 0.136575 0.261590)
(xy 0.122012 0.344227)
(xy 0.106195 0.388056)
(xy 0.053084 0.416405)
(xy -0.022119 0.421180)
(xy -0.090132 0.402187)
(xy -0.107244 0.389467)
(xy -0.125577 0.341817)
(xy -0.137288 0.247941)
(xy -0.141111 0.126881)
(xy -0.138820 0.005686)
(xy -0.128982 -0.078734)
(xy -0.107152 -0.145963)
(xy -0.068884 -0.215585)
(xy -0.060251 -0.229342)
(xy 0.010405 -0.322439)
(xy 0.092776 -0.388945)
(xy 0.197752 -0.433387)
(xy 0.336224 -0.460291)
(xy 0.519082 -0.474183)
(xy 0.529901 -0.474630)
(xy 0.664168 -0.481360)
(xy 0.752841 -0.490158)
(xy 0.806771 -0.503223)
(xy 0.836810 -0.522755)
(xy 0.848238 -0.539158)
(xy 0.913290 -0.606885)
(xy 1.017232 -0.655085)
(xy 1.143924 -0.676781)
(xy 1.167811 -0.677333)
)
(stroke (width 0.000000) (type solid)) (fill solid) (layer "F.SilkS") (tstamp 776a8a2f-41bb-4cbc-b0be-6c9ea146df53))
(fp_poly
(pts
(xy -1.047610 -1.647727)
(xy -0.985222 -1.631585)
(xy -0.932496 -1.593092)
(xy -0.888788 -1.547716)
(xy -0.794134 -1.444431)
(xy -0.484261 -1.434827)
(xy -0.346803 -1.429766)
(xy -0.252227 -1.422635)
(xy -0.186982 -1.410313)
(xy -0.137515 -1.389682)
(xy -0.090274 -1.357620)
(xy -0.066027 -1.338549)
(xy 0.033764 -1.242941)
(xy 0.097440 -1.138070)
(xy 0.131157 -1.009158)
(xy 0.141067 -0.841425)
(xy 0.141067 -0.841211)
(xy 0.139279 -0.728284)
(xy 0.131564 -0.657425)
(xy 0.114486 -0.614314)
(xy 0.084604 -0.584629)
(xy 0.078387 -0.580156)
(xy 0.022452 -0.544875)
(xy -0.016495 -0.542386)
(xy -0.067105 -0.572268)
(xy -0.075165 -0.577899)
(xy -0.108691 -0.611754)
(xy -0.129324 -0.665081)
(xy -0.141424 -0.752568)
(xy -0.145750 -0.815715)
(xy -0.156903 -0.942594)
(xy -0.179676 -1.029777)
(xy -0.223331 -1.084628)
(xy -0.297130 -1.114510)
(xy -0.410334 -1.126790)
(xy -0.539603 -1.128889)
(xy -0.668608 -1.127757)
(xy -0.752679 -1.122959)
(xy -0.803307 -1.112394)
(xy -0.831980 -1.093959)
(xy -0.846510 -1.072737)
(xy -0.911784 -1.003554)
(xy -1.013926 -0.953673)
(xy -1.134380 -0.931694)
(xy -1.151536 -0.931333)
(xy -1.285728 -0.957746)
(xy -1.399504 -1.030666)
(xy -1.479522 -1.140613)
(xy -1.493099 -1.173949)
(xy -1.517829 -1.293905)
(xy -1.498193 -1.400965)
(xy -1.430574 -1.509344)
(xy -1.398285 -1.546545)
(xy -1.337923 -1.606991)
(xy -1.284711 -1.638144)
(xy -1.215233 -1.649587)
(xy -1.143000 -1.651000)
)
(stroke (width 0.000000) (type solid)) (fill solid) (layer "F.SilkS") (tstamp 01ac52df-a17a-4784-9efb-a7bd9808d656))
)

View File

@ -0,0 +1,144 @@
(footprint "LOGO" (version 20221018) (generator bitmap2component)
(layer "F.Cu")
(attr board_only exclude_from_pos_files exclude_from_bom)
(fp_text reference "G***" (at 0 0) (layer "F.SilkS")
(effects (font (size 1.5 1.5) (thickness 0.3)))
(tstamp 7a502b98-1547-4eee-b558-16b64e9d1e25)
)
(fp_text value "LOGO" (at 0.75 0) (layer "F.SilkS") hide
(effects (font (size 1.5 1.5) (thickness 0.3)))
(tstamp fbe39f27-c970-4b01-b8f6-1e2925fe7bc3)
)
(fp_poly
(pts
(xy 0.089038 -0.896103)
(xy 0.268073 -0.863017)
(xy 0.413247 -0.790463)
(xy 0.525487 -0.676820)
(xy 0.605721 -0.520470)
(xy 0.654872 -0.319792)
(xy 0.673869 -0.073167)
(xy 0.670114 0.120058)
(xy 0.650135 0.342081)
(xy 0.612932 0.516754)
(xy 0.555002 0.651480)
(xy 0.472837 0.753660)
(xy 0.362934 0.830697)
(xy 0.324555 0.849770)
(xy 0.204989 0.884808)
(xy 0.055656 0.900154)
(xy -0.100141 0.895335)
(xy -0.239099 0.869884)
(xy -0.264590 0.861649)
(xy -0.406259 0.782930)
(xy -0.524757 0.661680)
(xy -0.607836 0.510746)
(xy -0.613201 0.496021)
(xy -0.636589 0.411856)
(xy -0.643755 0.364231)
(xy -0.372946 0.364231)
(xy -0.360659 0.388025)
(xy -0.352953 0.394965)
(xy -0.322084 0.410909)
(xy -0.286258 0.400569)
(xy -0.232872 0.357834)
(xy -0.188096 0.315009)
(xy -0.121037 0.252266)
(xy -0.069502 0.209650)
(xy -0.048321 0.197555)
(xy -0.039970 0.223805)
(xy -0.033315 0.294678)
(xy -0.029179 0.398361)
(xy -0.028223 0.486127)
(xy -0.028223 0.774698)
(xy 0.183444 0.564444)
(xy 0.270656 0.475308)
(xy 0.340409 0.399248)
(xy 0.384273 0.345753)
(xy 0.395111 0.326149)
(xy 0.376563 0.293452)
(xy 0.327799 0.234001)
(xy 0.259140 0.160320)
(xy 0.254997 0.156109)
(xy 0.114883 0.014111)
(xy 0.252494 -0.142649)
(xy 0.390105 -0.299408)
(xy 0.182248 -0.523649)
(xy -0.025609 -0.747889)
(xy -0.026916 -0.458611)
(xy -0.029282 -0.338540)
(xy -0.034640 -0.242813)
(xy -0.042117 -0.183229)
(xy -0.048321 -0.169334)
(xy -0.077689 -0.187619)
(xy -0.133288 -0.235029)
(xy -0.188096 -0.286787)
(xy -0.257730 -0.351476)
(xy -0.302379 -0.380167)
(xy -0.334645 -0.378972)
(xy -0.352953 -0.366744)
(xy -0.371526 -0.343750)
(xy -0.367478 -0.314695)
(xy -0.335198 -0.269724)
(xy -0.269073 -0.198982)
(xy -0.241401 -0.170861)
(xy -0.167556 -0.093081)
(xy -0.112431 -0.029007)
(xy -0.085755 0.009880)
(xy -0.084667 0.014111)
(xy -0.103274 0.045440)
(xy -0.152610 0.104646)
(xy -0.222943 0.180246)
(xy -0.241401 0.199082)
(xy -0.318929 0.279614)
(xy -0.360907 0.331379)
(xy -0.372946 0.364231)
(xy -0.643755 0.364231)
(xy -0.651831 0.310560)
(xy -0.660156 0.179504)
(xy -0.662791 0.006062)
(xy -0.662789 -0.014111)
(xy -0.661490 -0.171597)
(xy -0.656854 -0.286168)
(xy -0.647125 -0.371333)
(xy -0.630543 -0.440600)
(xy -0.605350 -0.507478)
(xy -0.595725 -0.529372)
(xy -0.500697 -0.689135)
(xy -0.378025 -0.802697)
(xy -0.224107 -0.871987)
(xy -0.035341 -0.898935)
)
(stroke (width 0.000000) (type solid)) (fill solid) (layer "F.SilkS") (tstamp 4334ed97-a708-4f13-92de-630863ad37c0))
(fp_poly
(pts
(xy 0.155222 0.225777)
(xy 0.203229 0.279613)
(xy 0.225572 0.321881)
(xy 0.225777 0.324555)
(xy 0.206811 0.364483)
(xy 0.160609 0.418178)
(xy 0.155222 0.423333)
(xy 0.084666 0.489616)
(xy 0.084666 0.324555)
(xy 0.084666 0.159494)
)
(stroke (width 0.000000) (type solid)) (fill solid) (layer "F.SilkS") (tstamp 29f36ae6-04c7-437b-b68f-e92a1bcc071c))
(fp_poly
(pts
(xy 0.155222 -0.395111)
(xy 0.211843 -0.329289)
(xy 0.219724 -0.275950)
(xy 0.180282 -0.221693)
(xy 0.174166 -0.216041)
(xy 0.126554 -0.179063)
(xy 0.099454 -0.180294)
(xy 0.087337 -0.225869)
(xy 0.084666 -0.315364)
(xy 0.084666 -0.461395)
)
(stroke (width 0.000000) (type solid)) (fill solid) (layer "F.SilkS") (tstamp 29155b15-cb43-451f-bd37-a9b5e52b2a57))
)

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,21 +1,71 @@
# Quack Mouse Converter
The Quack Mouse project is a Bluetooth & ADB Mouse "Dongle" for the Macintosh 128/512/Plus and the Apple Lisa. It allow you to use most ADB and BT2+ mouses with a Macintosh 128/512/Plus and Apple Lisa through the quadrature mouse port.
# Quack Mouse Converter[![Badge License]][License]
It include a custom PCB (EDA subfolder) with the accompanying firmware (code in main subfolder)
![Board](https://raw.githubusercontent.com/demik/quack/master/Images/board.png)
A dongle that allows various retro systems to use the `Apple Desktop Bus` <br>
as well as `Bluetooth 2+` mice through their `quadrature` mouse ports.
### Supported mouse conversions:
<br>
<br>
<br>
Quack support the following conversions:
- ADB mouse to Macintosh 128/512/Plus or Apple Lisa
- Bluetooth mouse to Macintosh 128/512/Plus or Apple Lisa
<div align = center>
### Unsupported mouse conversions:
[![Button Documentation]][Documentation]
[![Button Firmware]][Firmware]
[![Button PCB]][PCB]
[![Button Changelog]][Changelog]
- ADB mouse to Bluetooth LE host
This is a work in progress for now, it doesn't work with all mainstream operating systems (Windows 10 works)
<br>
<br>
### Documentation
<img
src = 'Resources/Preview.png'
width = 500
/>
More documentation is avaible on the Wiki. Please check it out: https://github.com/demik/quack/wiki
</div>
<br>
<br>
## Supported
#### Systems
<kbd>Macintosh 128 / 512 / Plus</kbd><kbd>Apple Lisa</kbd>
#### Connection Types
<kbd>Apple Desktop Bus</kbd><kbd>Bluetooth 2+</kbd>
<br>
<br>
### Unsupported
- `ADB`  ➞  `Bluetooth LE`for **Non-Windows 10**
<br>
<!----------------------------------------------------------------------------->
[Documentation]: https://github.com/demik/quack/wiki
[Changelog]: ChangeLog.md
[Firmware]: main/README.md
[License]: LICENSE
[PCB]: EDA/ChangeLog.md
<!-------------------------------[ Badges ]----------------------------------->
[Badge License]: https://img.shields.io/badge/License-Apache_2.0-961b1f?style=for-the-badge&labelColor=D22128
<!-------------------------------[ Buttons ]----------------------------------->
[Button Documentation]: https://img.shields.io/badge/Documentation-0099E5?style=for-the-badge&logoColor=white&logo=BookStack
[Button Changelog]: https://img.shields.io/badge/Changelog-21375A?style=for-the-badge&logoColor=white&logo=AzureArtifacts
[Button Firmware]: https://img.shields.io/badge/Firmware-E5426E?style=for-the-badge&logoColor=white&logo=ROS
[Button PCB]: https://img.shields.io/badge/PCB-007c40?style=for-the-badge&logoColor=white&logo=PowerApps

BIN
Resources/Preview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@ -10,4 +10,4 @@ set(include_dirs ".")
idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "${include_dirs}"
REQUIRES esp_hid)
REQUIRES driver esp_hid nvs_flash spi_flash)

View File

@ -1,63 +1,13 @@
diff --git a/components/esp_hid/include/esp_hidh.h b/components/esp_hid/include/esp_hidh.h
index b1a8264307..d3d1002103 100644
--- a/components/esp_hid/include/esp_hidh.h
+++ b/components/esp_hid/include/esp_hidh.h
@@ -100,6 +100,7 @@ typedef union {
typedef struct {
esp_event_handler_t callback;
+ uint16_t event_stack_size;
} esp_hidh_config_t;
/**
diff --git a/components/esp_hid/src/ble_hidh.c b/components/esp_hid/src/ble_hidh.c
index 5fe54f2fa7..a56eb04c44 100644
--- a/components/esp_hid/src/ble_hidh.c
+++ b/components/esp_hid/src/ble_hidh.c
@@ -617,7 +617,7 @@ esp_err_t esp_ble_hidh_init(const esp_hidh_config_t *config)
.queue_size = 5,
.task_name = "esp_ble_hidh_events",
.task_priority = uxTaskPriorityGet(NULL),
- .task_stack_size = 2048,
+ .task_stack_size = config->event_stack_size > 0 ? config->event_stack_size : 2048,
.task_core_id = tskNO_AFFINITY
};
ret = esp_event_loop_create(&event_task_args, &event_loop_handle);
diff --git a/components/esp_hid/src/bt_hidh.c b/components/esp_hid/src/bt_hidh.c
index 1a17e6aa35..16fae9e65a 100644
index 6f0410e302..59dfc0b07f 100644
--- a/components/esp_hid/src/bt_hidh.c
+++ b/components/esp_hid/src/bt_hidh.c
@@ -320,7 +320,7 @@ esp_err_t esp_bt_hidh_init(const esp_hidh_config_t *config)
.queue_size = 5,
.task_name = "esp_bt_hidh_events",
.task_priority = uxTaskPriorityGet(NULL),
- .task_stack_size = 2048,
+ .task_stack_size = config->event_stack_size > 0 ? config->event_stack_size : 2048,
.task_core_id = tskNO_AFFINITY
};
esp_err_t ret = esp_event_loop_create(&event_task_args, &event_loop_handle);
@@ -386,6 +386,24 @@ void bta_hh_co_data(uint8_t handle, uint8_t *p_rpt, uint16_t len, tBTA_HH_PROTO_
ESP_LOGE(TAG, "Device Not Found: handle %u", handle);
return;
}
+
+ /*
+ * quack patch: mode is always ESP_HID_PROTOCOL_MODE_BOOT even if the device is in BOOT mode
+ * BTA_HH_PROTO_RPT_MODE from Bluedroid is 0
+ * BOOT report id is also questionable, assume than an REPORT mode with a lengh of 3 or 4 is a BOOT packet
+ */
+
+ if (len >= 2 + 1 && p_rpt[0] == 2 && mode == 0) {
+ esp_hidh_event_data_t p = {0};
+ p.input.dev = dev;
+ p.feature.report_id = 2;
+ p.feature.usage = ESP_HID_USAGE_MOUSE;
+ p.feature.data = p_rpt + 1;
+ p.input.length = len - 1;
+ esp_event_post_to(event_loop_handle, ESP_HIDH_EVENTS, ESP_HIDH_INPUT_EVENT, &p, sizeof(esp_hidh_event_data_t), portMAX_DELAY);
+ return ;
+ }
+
report = esp_hidh_dev_get_input_report_by_id_and_proto(dev, p_rpt[0], mode ? ESP_HID_PROTOCOL_MODE_BOOT : ESP_HID_PROTOCOL_MODE_REPORT);
if (report == NULL) {
ESP_LOGE(TAG, "Report Not Found: %d mode: %s", p_rpt[0], mode ? "BOOT" : "REPORT");
@@ -673,7 +673,7 @@ static void esp_hh_cb(esp_hidh_cb_event_t event, esp_hidh_cb_param_t *param)
if (param->data_ind.len == 9 && *(param->data_ind.data) == 1) {
has_report_id = true;
_usage = ESP_HID_USAGE_KEYBOARD;
- } else if (param->data_ind.len == 4 && *(param->data_ind.data) == 2) {
+ } else if (param->data_ind.len >= 4 && *(param->data_ind.data) == 2) {
has_report_id = true;
_usage = ESP_HID_USAGE_MOUSE;
} else {

View File

@ -24,12 +24,13 @@
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_chip_info.h"
#include "esp_private/periph_ctrl.h"
#include "driver/rmt.h"
#include "driver/periph_ctrl.h"
#include "soc/periph_defs.h"
#include "soc/rmt_reg.h"
@ -58,6 +59,7 @@ static void adb_rx_setup(void);
static void adb_tx_as(void);
static void adb_tx_one(void);
static void adb_tx_setup(void);
static void adb_tx_stop(void);
static void adb_tx_zero(void);
/* functions */
@ -126,7 +128,7 @@ inline bool adb_is_host(void) {
void adb_probe(void) {
uint16_t register3;
ESP_LOGI(TAG, "Probing for mouse...");
ESP_LOGI(TAG, "Probing for mouse");
xTaskNotify(t_yellow, LED_SLOW, eSetValueWithOverwrite);
/* for some reason, RMT misses the first exchange sometimes. Flush the device should give it time */
@ -135,17 +137,52 @@ void adb_probe(void) {
vTaskDelay(12 / portTICK_PERIOD_MS);
while (true) {
adb_tx_cmd(ADB_MOUSE|ADB_TALK|ADB_REG3);
register3 = adb_rx_mouse();
ESP_LOGD("ADB", "Device $3 register3: %x", register3);
ESP_LOGD("ADB", "Device $3 register3: %04x", register3);
if (register3 && (register3 & ADB_H_ALL) == ADB_H_ERR)
ESP_LOGE(TAG, "Mouse failed self init test");
/*
* try to unglue composite devices (Kensington)
* the idea is to move detected devices to $9, and check $3 again
* if there is something again at $3, it may be a composite device, or the user
* plugged two devices.
* if there is nothing anymore, move back $9 to $3
*
* we will handle that further down the line by checking the handler
*/
if (register3 & ADB_H_ALL) {
ESP_LOGI(TAG, "\tMoving $3 to $9 to check for composite devices");
adb_tx_listen(ADB_MOUSE|ADB_LISTEN|ADB_REG3, (ADB_TMP<<4)|ADB_H_MOVE);
vTaskDelay(7 / portTICK_PERIOD_MS);
ESP_LOGI(TAG, "\tChecking $3 again…");
adb_tx_cmd(ADB_MOUSE|ADB_TALK|ADB_REG3);
register3 = adb_rx_mouse();
if (register3) {
adb_tx_cmd(ADB_TMP|ADB_TALK|ADB_REG3);
register3 = adb_rx_mouse();
ESP_LOGI(TAG, "\t… something was there, $9 handler: $%02x", register3 & ADB_H_ALL);
xTaskNotify(t_red, LED_ONCE, eSetValueWithOverwrite);
}
else {
ESP_LOGI(TAG, "\t… nothing, moving $9 back to $3");
adb_tx_listen(ADB_TMP|ADB_LISTEN|ADB_REG3, (ADB_MOUSE<<4)|ADB_H_MOVE);
}
/* restore register3 from $3 for handler detection */
vTaskDelay(7 / portTICK_PERIOD_MS);
adb_tx_cmd(ADB_MOUSE|ADB_TALK|ADB_REG3);
register3 = adb_rx_mouse();
}
/* Accept all known handlers */
if (((register3 & ADB_H_ALL) == ADB_H_C100) || ((register3 & ADB_H_ALL) == ADB_H_C200) ||
((register3 & ADB_H_ALL) == ADB_H_MTRC)) {
ESP_LOGI(TAG, "... detected mouse at $3");
((register3 & ADB_H_ALL) == ADB_H_MTRC) || ((register3 & ADB_H_ALL) == ADB_H_KSGT)) {
ESP_LOGI(TAG, "… detected mouse at $3");
break;
}
@ -171,6 +208,13 @@ void adb_probe(void) {
case ADB_H_MTRC:
ESP_LOGD(TAG, "MacTRAC running at default cpi");
break;
case ADB_H_KSGT:
ESP_LOGD(TAG, "Kensington detected, switching to standard device");
adb_tx_listen(ADB_MOUSE|ADB_LISTEN|ADB_REG3, (ADB_KML1<<4)|ADB_H_MOVE);
adb_tx_listen(ADB_TMP|ADB_LISTEN|ADB_REG3, (ADB_MOUSE<<4)|ADB_H_MOVE);
adb_tx_listen(ADB_MOUSE|ADB_LISTEN|ADB_REG3, 0x6000|(ADB_MOUSE<<4)|ADB_H_C200);
ESP_LOGD(TAG, "Kensington running at 200cpi");
break;
default:
ESP_LOGE(TAG, "Mouse running with unknow handler: %x", register3 & ADB_H_ALL);
}
@ -201,6 +245,9 @@ void adb_task_host(void *pvParameters) {
int8_t move = 0;
uint8_t state = ADB_S_PROBE;
/* wait a little for the LED tasks to start on the other core */
vTaskDelay(200 / portTICK_PERIOD_MS);
/* put green led to steady if BT is disabled. Otherwise BT init will do it */
if (gpio_get_level(GPIO_BTOFF) == 0)
xTaskNotify(t_green, LED_ON, eSetValueWithOverwrite);
@ -267,7 +314,7 @@ void adb_task_host(void *pvParameters) {
else
state = ADB_S_KEEP;
}
ESP_LOGD("ADB", "Check mouse presence %x", data);
ESP_LOGD("ADB", "Check mouse presence %04x", data);
}
}
}
@ -400,11 +447,15 @@ static inline void adb_rx_setup() {
}
static inline void adb_tx_as() {
/* send attention (800 µs low) + sync (70 µs high) */
/*
* send attention (800 µs low) + sync (65 µs high).
* AN591 mentions 70 µs which is a mistake, make some devices angry
*/
gpio_set_level(GPIO_ADB, 0);
ets_delay_us(800-1);
esp_rom_delay_us(800-1);
gpio_set_level(GPIO_ADB, 1);
ets_delay_us(70-1);
esp_rom_delay_us(65-1);
}
void IRAM_ATTR adb_tx_cmd(unsigned char cmd) {
@ -422,13 +473,12 @@ void IRAM_ATTR adb_tx_cmd(unsigned char cmd) {
cmd & 0x01 ? adb_tx_one() : adb_tx_zero();
/* stop bit */
adb_tx_zero();
adb_tx_stop();
adb_rx_setup();
}
void IRAM_ATTR adb_tx_data(uint16_t data) {
adb_tx_setup();
adb_tx_one();
/* send data 2 bytes (unrolled loop) */
@ -450,24 +500,27 @@ void IRAM_ATTR adb_tx_data(uint16_t data) {
data & 0x01 ? adb_tx_one() : adb_tx_zero();
/* stop bit */
adb_tx_zero();
adb_tx_stop();
adb_rx_setup();
}
void adb_tx_listen(unsigned char cmd, uint16_t data) {
adb_tx_cmd(cmd);
/* Stop to start is between 160-240µS. Go for around 160 + time for GPIO setup */
ets_delay_us(160);
/*
* Stop to start is between 160-240µS. Go for around 160 + time for GPIO setup
* values from AN591 Datasheet minus the estimated call to esp_rom_delay_us
*/
esp_rom_delay_us(160);
adb_tx_data(data);
}
static inline void adb_tx_one() {
/* values from AN591 Datasheet minus the estimated call to ets_delay_us */
gpio_set_level(GPIO_ADB, 0);
ets_delay_us(ADB_1_LOW - 1);
esp_rom_delay_us(ADB_1_LOW - 1);
gpio_set_level(GPIO_ADB, 1);
ets_delay_us(ADB_1_HIGH - 1);
esp_rom_delay_us(ADB_1_HIGH - 1);
}
void adb_tx_reset() {
@ -478,9 +531,9 @@ void adb_tx_reset() {
*/
gpio_set_level(GPIO_ADB, 0);
ets_delay_us(ADB_RESET);
esp_rom_delay_us(ADB_RESET);
gpio_set_level(GPIO_ADB, 1);
ets_delay_us(500);
esp_rom_delay_us(500);
}
static inline void adb_tx_setup() {
@ -488,10 +541,16 @@ static inline void adb_tx_setup() {
gpio_set_level(GPIO_DIR, 1);
}
static inline void adb_tx_zero() {
/* values from AN591 Datasheet minus the estimated call to ets_delay_us */
static inline void adb_tx_stop() {
gpio_set_level(GPIO_ADB, 0);
ets_delay_us(ADB_0_LOW - 1);
esp_rom_delay_us(ADB_S_LOW - 1);
gpio_set_level(GPIO_ADB, 1);
ets_delay_us(ADB_0_HIGH - 1);
esp_rom_delay_us(ADB_S_HIGH - 1);
}
static inline void adb_tx_zero() {
gpio_set_level(GPIO_ADB, 0);
esp_rom_delay_us(ADB_0_LOW - 1);
gpio_set_level(GPIO_ADB, 1);
esp_rom_delay_us(ADB_0_HIGH - 1);
}

View File

@ -43,6 +43,8 @@ void adb_tx_reset(void);
#define ADB_0_HIGH 35
#define ADB_1_LOW 35
#define ADB_1_HIGH 65
#define ADB_S_LOW 70
#define ADB_S_HIGH 30
/* Classic Apple Mouse Protocol bitmasks */
#define ADB_CMP_B1 (1<<15)
@ -58,8 +60,9 @@ void adb_tx_reset(void);
#define ADB_REG3 0x3
/* Device addresses */
#define ADB_MOUSE (3<<4)
#define ADB_TMP (9<<4)
#define ADB_MOUSE (3<<4) // main device
#define ADB_KML1 (8<<4) // disabled Kensington device
#define ADB_TMP (9<<4) // temporary device
/* Various stuff */
#define ADB_B_UP 0
@ -70,6 +73,7 @@ void adb_tx_reset(void);
#define ADB_H_C100 0x01 // Handler 1 (Classic @ 100cpi)
#define ADB_H_C200 0x02 // Handler 2 (Classic @ 200cpi)
#define ADB_H_MTRC 0x2f // Handler for MacTRAC 2.0
#define ADB_H_KSGT 0x32 // Handler for Kensington devices
#define ADB_H_MOVE 0xfe // Move to another address
/* Host states */

View File

@ -25,6 +25,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
@ -33,12 +34,16 @@
#include "nvs_flash.h"
#include "esp_bt.h"
#include "esp_bt_defs.h"
#if CONFIG_BT_BLE_ENABLED
#include "esp_gap_ble_api.h"
#include "esp_gatts_api.h"
#include "esp_gatt_defs.h"
#endif
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "esp_timer.h"
#include "esp_hid_common.h"
#include "esp_hidd.h"
#include "esp_hidh.h"
#include "esp_hid_gap.h"
@ -72,8 +77,8 @@ static esp_hid_raw_report_map_t *blue_hid_rm_get(esp_hidh_dev_t *dev);
void blue_set_boot_protocol(esp_hidh_dev_t *dev);
static bool blue_support_boot(esp_hidh_dev_t *dev);
/* direct calls to bluedroid */
extern void BTA_HhSetProtoMode(uint8_t handle, uint8_t t_type);
/* direct calls to esp_hid_* */
void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param);
/* Device specific functions blue_d_* */
static void blue_d_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data)
@ -130,22 +135,21 @@ static void blue_d_connect() {
static void blue_d_disconnect(esp_hidd_event_data_t *dev) {
ESP_LOGI(TAG, "Host disconnected, reason: %s",
esp_hid_disconnect_reason_str(esp_hidd_dev_transport_get(dev->disconnect.dev), dev->disconnect.reason));
#if CONFIG_BT_BLE_ENABLED
esp_hid_ble_gap_adv_start();
#endif
xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite);
}
static void blue_d_init() {
esp_err_t ret;
ret = esp_hid_ble_gap_adv_init(ESP_HID_APPEARANCE_MOUSE, m4848_config.device_name);
ESP_ERROR_CHECK( ret );
if ((ret = esp_ble_gatts_register_callback(esp_hidd_gatts_event_handler)) != ESP_OK) {
ESP_LOGE(TAG, "GATTS register callback failed: %d", ret);
if ((ret = esp_bt_gap_register_callback(bt_gap_event_handler)) != ESP_OK) {
ESP_LOGE(TAG, "BT GAP register callback failed: %d", ret);
return;
}
ESP_ERROR_CHECK(esp_hidd_dev_init(&m4848_config, ESP_HID_TRANSPORT_BLE, blue_d_callback, &hid_dev));
ESP_ERROR_CHECK(esp_hidd_dev_init(&m4848_config, ESP_HID_TRANSPORT_BT, blue_d_callback, &hid_dev));
xTaskCreate(blue_adb2hid, "ADB2BT", 2 * 1024, NULL, tskIDLE_PRIORITY + 1, &t_adb2hid);
}
@ -158,19 +162,23 @@ static void blue_d_start()
{
ESP_LOGD(TAG, "Bluetooth stack started");
xTaskNotify(t_blue, LED_SLOW, eSetValueWithOverwrite);
#if CONFIG_BT_BLE_ENABLED
esp_hid_ble_gap_adv_start();
#endif
}
/*
* Called by the ADB stack from adb_task_host on mouse activity
* Convert the 16bit ADB data to a 3 bytes HID INPUT REPORT matching the m4848
*
* The format is also BOOT compatible so don't bother to check what mode we are in
*/
void blue_adb2hid(void *pvParameters) {
uint16_t data = 0;
uint8_t buffer[3] = {0, 0, 0};
int8_t move = 0;
unsigned int tmp;
long unsigned int tmp;
ESP_LOGD(TAG, "ADB2BT started on core %d", xPortGetCoreID());
@ -332,9 +340,7 @@ void blue_init(void)
ESP_LOGD(TAG, "Starting Bluetooth init on core %d", xPortGetCoreID());
ESP_ERROR_CHECK(ret);
/* ESP_BT_MODE_CLASSIC_BT doesn't work, it freezes esp_hidh_init */
ESP_ERROR_CHECK(esp_hid_gap_init(ESP_BT_MODE_BTDM));
ESP_ERROR_CHECK(esp_ble_gattc_register_callback(esp_hidh_gattc_event_handler));
ESP_ERROR_CHECK(esp_hid_gap_init(ESP_BT_MODE_CLASSIC_BT));
esp_log_level_set("event", ESP_LOG_INFO);
/* complains about wrong data len on BOOT mode and CCONTROL */
@ -373,6 +379,7 @@ void blue_h_input(esp_hidh_dev_t *dev, uint8_t *data, uint16_t length) {
uint8_t i;
int8_t x, y;
//ESP_LOG_BUFFER_HEX(TAG, data, length);
buttons = data[0];
/*
@ -551,12 +558,11 @@ void blue_scan(void *pvParameters) {
esp_hid_scan_result_t *r = results;
while (r) {
ESP_LOGI(TAG, "found %s %s device: " ESP_BD_ADDR_STR ", RSSI: %d, NAME: %s",
(r->transport == ESP_HID_TRANSPORT_BLE) ? "BLE" : "BT",
esp_hid_cod_major_str(r->bt.cod.major),
ESP_BD_ADDR_HEX(r->bda), r->rssi, r->name ? r->name : "");
/*
* as of v1.4.5, esp_hid_gap will print detected devices in console (handle_bt_device_result())
* just look for something that looks like Bluetooth Classic mouse
*/
/* search for something that looks like Bluetooth Classic mouse */
if (r->transport == ESP_HID_TRANSPORT_BT &&
strcmp("PERIPHERAL", esp_hid_cod_major_str(r->bt.cod.major)) == 0
&& (r->bt.cod.minor & ESP_HID_COD_MIN_MOUSE)) {
@ -580,56 +586,8 @@ void blue_scan(void *pvParameters) {
void blue_set_boot_protocol(esp_hidh_dev_t *dev) {
configASSERT(dev != NULL);
/*
* /!\ Disclaimer /!\
* This is ugly. We are accessing directly bluedroid and need the hidden handle to do that
* Extract it from a private esp_hidh_dev_s struct and call BTA_HhSetProtoMode directly.
*/
struct decoy_dev_s {
struct esp_hidh_dev_s *next;
esp_hid_device_config_t config;
esp_hid_usage_t usage;
esp_hid_transport_t transport;
bool connected;
bool opened;
int status;
size_t reports_len;
void *reports;
void *tmp;
size_t tmp_len;
xSemaphoreHandle semaphore;
esp_err_t (*close) (esp_hidh_dev_t *dev);
esp_err_t (*report_write) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, uint8_t *data, size_t len);
esp_err_t (*report_read) (esp_hidh_dev_t *dev, size_t map_index, size_t report_id, int report_type, size_t max_length, uint8_t *value, size_t *value_len);
void (*dump) (esp_hidh_dev_t *dev, FILE *fp);
esp_bd_addr_t bda;
struct {
esp_bt_cod_t cod;
int handle;
uint8_t sub_class;
uint8_t app_id;
uint16_t attr_mask;
} bt;
TAILQ_ENTRY(esp_hidh_dev_s) devices;
};
struct decoy_dev_s *pass_that_handle;
pass_that_handle = (struct decoy_dev_s *)dev;
ESP_LOGI(TAG, "switching " ESP_BD_ADDR_STR " (%i) to protocol mode boot" ,
ESP_BD_ADDR_HEX(pass_that_handle->bda), pass_that_handle->bt.handle);
//ESP_LOG_BUFFER_HEX(TAG, dev, sizeof(struct decoy_dev_s));
/* bluedroid/bta/include/bta_hh_api.h */
BTA_HhSetProtoMode(pass_that_handle->bt.handle, 0x01);
ESP_LOGI(TAG, "switching " ESP_BD_ADDR_STR " to protocol mode boot", ESP_BD_ADDR_HEX(esp_hidh_dev_bda_get(dev)));
esp_hidh_dev_set_protocol(dev, ESP_HID_PROTOCOL_MODE_BOOT);
}
static bool blue_support_boot(esp_hidh_dev_t *dev) {

View File

@ -1,19 +1,13 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <string.h>
#include <stdbool.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -24,8 +18,11 @@
static const char *TAG = "ESP_HID_GAP";
// uncomment to print all devices that were seen during a scan
#define GAP_DBG_PRINTF(...) //printf(__VA_ARGS__)
//static const char * gap_bt_prop_type_names[5] = {"","BDNAME","COD","RSSI","EIR"};
#define GAP_DBG_PRINTF(...) printf(__VA_ARGS__)
#if CONFIG_BT_HID_HOST_ENABLED
static const char * gap_bt_prop_type_names[5] = {"","BDNAME","COD","RSSI","EIR"};
#endif
static esp_hid_scan_result_t *bt_scan_results = NULL;
static size_t num_bt_scan_results = 0;
@ -33,11 +30,11 @@ static size_t num_bt_scan_results = 0;
static esp_hid_scan_result_t *ble_scan_results = NULL;
static size_t num_ble_scan_results = 0;
static xSemaphoreHandle bt_hidh_cb_semaphore = NULL;
static SemaphoreHandle_t bt_hidh_cb_semaphore = NULL;
#define WAIT_BT_CB() xSemaphoreTake(bt_hidh_cb_semaphore, portMAX_DELAY)
#define SEND_BT_CB() xSemaphoreGive(bt_hidh_cb_semaphore)
static xSemaphoreHandle ble_hidh_cb_semaphore = NULL;
static SemaphoreHandle_t ble_hidh_cb_semaphore = NULL;
#define WAIT_BLE_CB() xSemaphoreTake(ble_hidh_cb_semaphore, portMAX_DELAY)
#define SEND_BLE_CB() xSemaphoreGive(ble_hidh_cb_semaphore)
@ -71,6 +68,7 @@ const char *bt_gap_evt_str(uint8_t event)
return bt_gap_evt_names[event];
}
#if CONFIG_BT_BLE_ENABLED
const char *esp_ble_key_type_str(esp_ble_key_type_t key_type)
{
const char *key_str = NULL;
@ -109,6 +107,7 @@ const char *esp_ble_key_type_str(esp_ble_key_type_t key_type)
}
return key_str;
}
#endif /* CONFIG_BT_BLE_ENABLED */
void esp_hid_scan_results_free(esp_hid_scan_result_t *results)
{
@ -123,6 +122,7 @@ void esp_hid_scan_results_free(esp_hid_scan_result_t *results)
}
}
#if (CONFIG_BT_HID_HOST_ENABLED || CONFIG_BT_BLE_ENABLED)
static esp_hid_scan_result_t *find_scan_result(esp_bd_addr_t bda, esp_hid_scan_result_t *results)
{
esp_hid_scan_result_t *r = results;
@ -134,7 +134,9 @@ static esp_hid_scan_result_t *find_scan_result(esp_bd_addr_t bda, esp_hid_scan_r
}
return NULL;
}
#endif /* (CONFIG_BT_HID_HOST_ENABLED || CONFIG_BT_BLE_ENABLED) */
#if CONFIG_BT_HID_HOST_ENABLED
static void add_bt_scan_result(esp_bd_addr_t bda, esp_bt_cod_t *cod, esp_bt_uuid_t *uuid, uint8_t *name, uint8_t name_len, int rssi)
{
esp_hid_scan_result_t *r = find_scan_result(bda, bt_scan_results);
@ -186,7 +188,9 @@ static void add_bt_scan_result(esp_bd_addr_t bda, esp_bt_cod_t *cod, esp_bt_uuid
bt_scan_results = r;
num_bt_scan_results++;
}
#endif
#if CONFIG_BT_BLE_ENABLED
static void add_ble_scan_result(esp_bd_addr_t bda, esp_ble_addr_type_t addr_type, uint16_t appearance, uint8_t *name, uint8_t name_len, int rssi)
{
if (find_scan_result(bda, ble_scan_results)) {
@ -220,13 +224,14 @@ static void add_ble_scan_result(esp_bd_addr_t bda, esp_ble_addr_type_t addr_type
ble_scan_results = r;
num_ble_scan_results++;
}
#endif /* CONFIG_BT_BLE_ENABLED */
void print_uuid(esp_bt_uuid_t *uuid)
{
if (uuid->len == ESP_UUID_LEN_16) {
GAP_DBG_PRINTF("UUID16: 0x%04x", uuid->uuid.uuid16);
} else if (uuid->len == ESP_UUID_LEN_32) {
GAP_DBG_PRINTF("UUID32: 0x%08x", uuid->uuid.uuid32);
GAP_DBG_PRINTF("UUID32: 0x%08"PRIx32, uuid->uuid.uuid32);
} else if (uuid->len == ESP_UUID_LEN_128) {
GAP_DBG_PRINTF("UUID128: %02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x", uuid->uuid.uuid128[0],
uuid->uuid.uuid128[1], uuid->uuid.uuid128[2], uuid->uuid.uuid128[3],
@ -237,6 +242,7 @@ void print_uuid(esp_bt_uuid_t *uuid)
}
}
#if CONFIG_BT_HID_HOST_ENABLED
static void handle_bt_device_result(struct disc_res_param *disc_res)
{
GAP_DBG_PRINTF("BT : " ESP_BD_ADDR_STR, ESP_BD_ADDR_HEX(disc_res->bda));
@ -325,7 +331,9 @@ static void handle_bt_device_result(struct disc_res_param *disc_res)
add_bt_scan_result(disc_res->bda, cod, &uuid, name, name_len, rssi);
}
}
#endif
#if CONFIG_BT_BLE_ENABLED
static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst)
{
@ -371,13 +379,16 @@ static void handle_ble_device_result(struct ble_scan_result_evt_param *scan_rst)
add_ble_scan_result(scan_rst->bda, scan_rst->ble_addr_type, appearance, adv_name, adv_name_len, scan_rst->rssi);
}
}
#endif /* CONFIG_BT_BLE_ENABLED */
#warning here1
#if CONFIG_BT_HID_HOST_ENABLED
/*
* BT GAP
* */
static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
#warning here2
void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
{
switch (event) {
case ESP_BT_GAP_DISC_STATE_CHANGED_EVT: {
@ -392,10 +403,10 @@ static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para
break;
}
case ESP_BT_GAP_KEY_NOTIF_EVT:
ESP_LOGI(TAG, "BT GAP KEY_NOTIF passkey:%d", param->key_notif.passkey);
ESP_LOGI(TAG, "BT GAP KEY_NOTIF passkey:%"PRIu32, param->key_notif.passkey);
break;
default:
ESP_LOGV(TAG, "BT GAP EVENT %s", bt_gap_evt_str(event));
ESP_LOGW(TAG, "BT GAP EVENT %s", bt_gap_evt_str(event));
break;
}
}
@ -403,9 +414,12 @@ static void bt_gap_event_handler(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_para
static esp_err_t init_bt_gap(void)
{
esp_err_t ret;
#if (CONFIG_BT_SSP_ENABLED)
/* Set default parameters for Secure Simple Pairing */
esp_bt_sp_param_t param_type = ESP_BT_SP_IOCAP_MODE;
esp_bt_io_cap_t iocap = ESP_BT_IO_CAP_IO;
esp_bt_gap_set_security_param(param_type, &iocap, sizeof(uint8_t));
#endif
/*
* Set default parameters for Legacy Pairing
* Use fixed pin code
@ -440,7 +454,9 @@ static esp_err_t start_bt_scan(uint32_t seconds)
}
return ret;
}
#endif
#if CONFIG_BT_BLE_ENABLED
/*
* BLE GAP
* */
@ -506,13 +522,13 @@ static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: // ESP_IO_CAP_OUT
// The app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
// Show the passkey number to the user to input it in the peer device.
ESP_LOGI(TAG, "BLE GAP PASSKEY_NOTIF passkey:%d", param->ble_security.key_notif.passkey);
ESP_LOGI(TAG, "BLE GAP PASSKEY_NOTIF passkey:%"PRIu32, param->ble_security.key_notif.passkey);
break;
case ESP_GAP_BLE_NC_REQ_EVT: // ESP_IO_CAP_IO
// The app will receive this event when the IO has DisplayYesNO capability and the peer device IO also has DisplayYesNo capability.
// show the passkey number to the user to confirm it with the number displayed by peer device.
ESP_LOGI(TAG, "BLE GAP NC_REQ passkey:%d", param->ble_security.key_notif.passkey);
ESP_LOGI(TAG, "BLE GAP NC_REQ passkey:%"PRIu32, param->ble_security.key_notif.passkey);
esp_ble_confirm_reply(param->ble_security.key_notif.bd_addr, true);
break;
@ -662,6 +678,7 @@ esp_err_t esp_hid_ble_gap_adv_start(void)
};
return esp_ble_gap_start_advertising(&hidd_adv_params);
}
#endif /* CONFIG_BT_BLE_ENABLED */
/*
* CONTROLLER INIT
@ -671,11 +688,16 @@ static esp_err_t init_low_level(uint8_t mode)
{
esp_err_t ret;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
if (mode & ESP_BT_MODE_CLASSIC_BT) {
#if CONFIG_IDF_TARGET_ESP32
bt_cfg.mode = mode;
#endif
#if CONFIG_BT_HID_HOST_ENABLED
if (mode & ESP_BT_MODE_CLASSIC_BT) {
bt_cfg.bt_max_acl_conn = 3;
bt_cfg.bt_max_sync_conn = 3;
} else {
} else
#endif
{
ret = esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
if (ret) {
ESP_LOGE(TAG, "esp_bt_controller_mem_release failed: %d", ret);
@ -705,26 +727,25 @@ static esp_err_t init_low_level(uint8_t mode)
ESP_LOGE(TAG, "esp_bluedroid_enable failed: %d", ret);
return ret;
}
#if CONFIG_BT_HID_HOST_ENABLED
if (mode & ESP_BT_MODE_CLASSIC_BT) {
ret = init_bt_gap();
if (ret) {
return ret;
}
}
#endif
#if CONFIG_BT_BLE_ENABLED
if (mode & ESP_BT_MODE_BLE) {
ret = init_ble_gap();
if (ret) {
return ret;
}
}
#endif /* CONFIG_BT_BLE_ENABLED */
return ret;
}
esp_err_t esp_hid_gap_init(uint8_t mode)
{
esp_err_t ret;
@ -771,14 +792,21 @@ esp_err_t esp_hid_scan(uint32_t seconds, size_t *num_results, esp_hid_scan_resul
return ESP_FAIL;
}
#if CONFIG_BT_BLE_ENABLED
if (start_ble_scan(seconds) == ESP_OK) {
if (start_bt_scan(seconds) == ESP_OK) {
WAIT_BT_CB();
}
WAIT_BLE_CB();
} else {
return ESP_FAIL;
}
#endif /* CONFIG_BT_BLE_ENABLED */
#if CONFIG_BT_HID_HOST_ENABLED
if (start_bt_scan(seconds) == ESP_OK) {
WAIT_BT_CB();
} else {
return ESP_FAIL;
}
#endif
*num_results = num_bt_scan_results + num_ble_scan_results;
*results = bt_scan_results;

View File

@ -1,31 +1,51 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ESP_HID_GAP_H_
#define _ESP_HID_GAP_H_
#define HIDH_IDLE_MODE 0x00
#define HIDH_BLE_MODE 0x01
#define HIDH_BT_MODE 0x02
#define HIDH_BTDM_MODE 0x03
#if CONFIG_BT_HID_HOST_ENABLED
#if CONFIG_BT_BLE_ENABLED
#define HID_HOST_MODE HIDH_BTDM_MODE
#else
#define HID_HOST_MODE HIDH_BT_MODE
#endif
#elif CONFIG_BT_BLE_ENABLED
#define HID_HOST_MODE HIDH_BLE_MODE
#elif CONFIG_BT_NIMBLE_ENABLED
#define HID_HOST_MODE HIDH_BLE_MODE
#else
#define HID_HOST_MODE HIDH_IDLE_MODE
#endif
#include "esp_err.h"
#include "esp_log.h"
#include "esp_bt.h"
#if !CONFIG_BT_NIMBLE_ENABLED
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "esp_gap_bt_api.h"
#endif
#include "esp_hid_common.h"
#if CONFIG_BT_BLE_ENABLED
#include "esp_gattc_api.h"
#include "esp_gatt_defs.h"
#include "esp_gap_ble_api.h"
#include "esp_gap_bt_api.h"
#include "esp_hid_common.h"
#endif
#if CONFIG_BT_NIMBLE_ENABLED
#include "nimble/ble.h"
#endif
#ifdef __cplusplus
extern "C" {
@ -33,13 +53,18 @@ extern "C" {
typedef struct esp_hidh_scan_result_s {
struct esp_hidh_scan_result_s *next;
#if CONFIG_BT_NIMBLE_ENABLED
uint8_t bda[6];
#else
esp_bd_addr_t bda;
#endif
const char *name;
int8_t rssi;
esp_hid_usage_t usage;
esp_hid_transport_t transport; //BT, BLE or USB
union {
#if !CONFIG_BT_NIMBLE_ENABLED
struct {
esp_bt_cod_t cod;
esp_bt_uuid_t uuid;
@ -48,6 +73,12 @@ typedef struct esp_hidh_scan_result_s {
esp_ble_addr_type_t addr_type;
uint16_t appearance;
} ble;
#else
struct {
uint8_t addr_type;
uint16_t appearance;
} ble;
#endif
};
} esp_hid_scan_result_t;
@ -58,8 +89,10 @@ void esp_hid_scan_results_free(esp_hid_scan_result_t *results);
esp_err_t esp_hid_ble_gap_adv_init(uint16_t appearance, const char *device_name);
esp_err_t esp_hid_ble_gap_adv_start(void);
#if !CONFIG_BT_NIMBLE_ENABLED
void print_uuid(esp_bt_uuid_t *uuid);
const char *ble_addr_type_str(esp_ble_addr_type_t ble_addr_type);
#endif
#ifdef __cplusplus
}

View File

@ -25,7 +25,6 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "gpio.h"

View File

@ -27,7 +27,6 @@
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "led.h"
#include "gpio.h"
@ -164,7 +163,7 @@ const char *led_gpio_name(uint8_t id) {
}
void led_init(void) {
/* blink allds LEDs once */
/* blink alls LEDs once */
gpio_set_level(GPIO_GREENLED, 1);
gpio_set_level(GPIO_BLUELED, 1);
gpio_set_level(GPIO_YELLOWLED, 1);
@ -185,7 +184,7 @@ void led_init(void) {
void led_task(void *pvParameters) {
unsigned int color = (unsigned int)pvParameters;
unsigned int mode = LED_OFF;
long unsigned int mode = LED_OFF;
TickType_t wait = portMAX_DELAY;
/* start only if there is a led specified */

View File

@ -24,10 +24,11 @@
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_flash.h"
#include "esp_hidh.h"
#include "esp_log.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
#include "esp_chip_info.h"
#include "adb.h"
#include "blue.h"
@ -40,20 +41,22 @@ static const char* TAG = "quack";
void app_main(void)
{
uint32_t flash_size;
esp_flash_get_size(NULL, &flash_size);
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
ESP_LOGI(TAG, "This is %s chip with %d CPU cores, WiFi%s%s, "
"revision %d, %dMB %s flash",
"revision %d, %" PRIu32 "MB %s flash",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "",
chip_info.revision,
spi_flash_get_chip_size() / (1024 * 1024),
chip_info.revision, flash_size / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
ESP_LOGI(TAG, "Minimum free heap size: %d bytes", esp_get_minimum_free_heap_size());
ESP_LOGI(TAG, "Minimum free heap size: %" PRIu32 " bytes", esp_get_minimum_free_heap_size());
ESP_LOGI(TAG, "");
ESP_LOGI(TAG, "\\_o< \\_o< \\_o< \\_O<");
ESP_LOGI(TAG, "");

View File

@ -28,7 +28,6 @@
#include "esp_system.h"
#include "esp_err.h"
#include "esp_log.h"
#include "driver/timer.h"
#include "esp_timer.h"
#include "quad.h"
@ -40,8 +39,8 @@ esp_timer_handle_t quad_qx, quad_qy;
QueueHandle_t q_qx, q_qy;
/* static functions */
static void IRAM_ATTR quad_timer(void* arg);
/* ISR functions */
static void IRAM_ATTR quad_isr(void* arg);
/* phases */
const bool q1[] = {true, false, false, true};
@ -51,6 +50,10 @@ const bool q2[] = {true, true, false, false};
void quad_init(void) {
esp_timer_create_args_t args;
/* create quadrature queues */
q_qx = xQueueCreate(4, sizeof(int8_t));
q_qy = xQueueCreate(4, sizeof(int8_t));
/* create quadrature tasks */
xTaskCreate(quad_click, "CLICK", 1024, NULL, tskIDLE_PRIORITY + 1, &t_click);
xTaskCreate(quad_move_x, "QX", 4 * 1024, NULL, tskIDLE_PRIORITY + 1, &t_qx);
@ -66,23 +69,23 @@ void quad_init(void) {
gpio_set_level(GPIO_QY2, q2[0]);
/* create timers for quadrature phases */
args.callback = quad_timer;
args.callback = quad_isr;
args.arg = t_qx;
args.name = "quad_qx";
args.dispatch_method = ESP_TIMER_ISR;
ESP_ERROR_CHECK(esp_timer_create(&args, &quad_qx));
args.callback = quad_timer;
args.callback = quad_isr;
args.arg = t_qy;
args.name = "quad_qy";
args.dispatch_method = ESP_TIMER_ISR;
ESP_ERROR_CHECK(esp_timer_create(&args, &quad_qy));
q_qx = xQueueCreate(4, sizeof(int8_t));
q_qy = xQueueCreate(4, sizeof(int8_t));
ESP_LOGI("quad", "Quadrature tasks started on core %d", xPortGetCoreID());
}
void quad_click(void *pvParameters) {
unsigned int click = 0;
long unsigned int click = 0;
(void)pvParameters;
@ -165,7 +168,7 @@ void IRAM_ATTR quad_move_y(void *pvParameters) {
}
/* simple ISR function. Resume the task that called the oneshot timer */
static void IRAM_ATTR quad_timer(void* arg) {
static void IRAM_ATTR quad_isr(void* arg) {
BaseType_t pxHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(arg, &pxHigherPriorityTaskWoken);

1595
sdkconfig

File diff suppressed because it is too large Load Diff