Skip to content

Commit

Permalink
Example: ESP32, Pico W, Linux moved to their own folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Nov 18, 2023
1 parent 105d397 commit 9578c3f
Show file tree
Hide file tree
Showing 24 changed files with 883 additions and 415 deletions.
113 changes: 31 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@

![logo](https://lh3.googleusercontent.com/pw/ADCreHccTUqtDIguBBUaQJH0iWsE6Ee1mLdL8urNKmewdvioWjWqT2rlBIWszdMT5jZOs0HJmrbnB4AEuRoRmE4zeR3TeXQZEHl8xZJCplBb9qtYaA3UCU-Dw8d58jIXsQz1qbzNYhAxQzmDBT1EGBCGW8Zd4w=-no-gm?authuser=0)

A Bluetooth controller "host" for the ESP32 / ESP32-S3 / ESP32-C3 / Raspberry Pi Pico W.
A Bluetooth controller "host" for the ESP32, ESP32-S3, ESP32-C3, Raspberry Pi Pico W and Linux.

Add Bluetooth gamepad, mouse and keyboard support to your projects easily.

## Where to start

Choose your target platform:

| Platform | Start here | Further info | Community projects |
| ----------------- | ---------- | ------------ | ------------------ |
| Arduino IDE | [![Watch the video][youtube_image]](https://youtu.be/0jnY-XXiD8Q) | [Doc][plat_arduino] | [Controller for Tello drone][tello] |
| Arduino using ESP-IDF toolchain | [Template project][esp-idf-bluepad32-arduino] | [Doc][plat_arduino] | [Lego Robot][esp32_example] ([video][esp32_video]), [gbaHD Shield][esp32_example2] (a GameBoy consolizer) |
| Arduino + NINA coprocessor | [Arduino Library][bp32-arduino] | [Doc][plat_nina] | [Philips CD-i meets Bluetooth][nina_example] |
| CircuitPython + AirLift coprocessor | [CircuitPython Library][bp32-circuitpython] | [Doc][plat_airlift] | [Quico console][airlift_example], Controlling 4 servos ([video][airlift_video]) |
| Pico W | | | |
| Unijoysticle | [Unijoysticle2][unijoysticle2]| [Doc][plat_unijoysticle] | |
| MightyMiggy | [Unijoysticle for Amiga][unijoysticle_sukko] | [Doc][plat_mightymiggy] | |
| Custom | | [Doc][plat_custom] | |
| Platform | Start here | Further info | Community projects |
| ----------------------------------- | ----------------------------------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------- |
| Arduino IDE | [![Watch the video][youtube_image]](https://youtu.be/0jnY-XXiD8Q) | [Doc][plat_arduino] | [Controller for Tello drone][tello] |
| Arduino using ESP-IDF toolchain | [Template project][esp-idf-bluepad32-arduino] | [Doc][plat_arduino] | [Lego Robot][esp32_example] ([video][esp32_video]), [gbaHD Shield][esp32_example2] (a GameBoy consolizer) |
| Arduino + NINA coprocessor | [Arduino Library][bp32-arduino] | [Doc][plat_nina] | [Philips CD-i meets Bluetooth][nina_example] |
| CircuitPython + AirLift coprocessor | [CircuitPython Library][bp32-circuitpython] | [Doc][plat_airlift] | [Quico console][airlift_example], Controlling 4 servos ([video][airlift_video]) |
| Pico W | [Pico W example][pico-w-example] | [Doc][plat_custom] | |
| ESP-IDF | [ESP32 example][esp32-example] | [Doc][plat_custom] | |
| Linux | [Linux example][linux-example] | [Doc][plat_custom] | |
| Unijoysticle | [Unijoysticle2][unijoysticle2] | [Doc][plat_unijoysticle] | |
| MightyMiggy | [Unijoysticle for Amiga][unijoysticle_sukko] | [Doc][plat_mightymiggy] | |


[airlift_example]: https://gitlab.com/ricardoquesada/quico
Expand All @@ -46,12 +47,13 @@ Choose your target platform:

## Features

* Supports most, if not all, modern Bluetooth gamepads and mice (see below)
* Supports most, if not all, modern Bluetooth gamepads, mice and keyboards (see below)
* Fast (very low latency)
* Small footprint
* Uses only one core (CPU0). The remaining one is free to use.
* C11 based
* Open Source (see below)
* Easy to integrate into 3rd party projects

## Supported controllers

Expand All @@ -70,6 +72,7 @@ Choose your target platform:
* Stadia controller
* PC/Window controller
* 8BitDo controllers
* Atari joystick
* iCade
* Mouse
* Keyboards
Expand All @@ -85,81 +88,27 @@ See: [Supported gamepads][gamepads], [supported mice][mice] and [supported keybo

## Pre-compiled binaries

* https://gitlab.com/ricardoquesada/bluepad32/-/releases

## How to compile it for ESP32

1. Install ESP-IDF

Install the ESP32 toolchain. Use version **4.4** or **5.1**. Might work on newer / older
ones, but not tested.

* <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/>

2. Clone repo

```sh
git clone --recursive https://gitlab.com/ricardoquesada/bluepad32.git
```

3. Integrate BTstack into ESP32

```sh
cd ${BLUEPAD32}/external/btstack/port/esp32
# This will install BTstack as a component inside Bluepad32 source code (recommended).
# Remove "IDF_PATH=../../../../src" if you want it installed in the ESP-IDF folder
IDF_PATH=../../../../src ./integrate_btstack.py
```

4. Compile Bluepad32

Choose target platform (default is *Unijoysticle*):

```sh
cd ${BLUEPAD32}/src
idf.py menuconfig
```
Download pre-compiled binaries for Unijoysticle, Nina, AirLift, MightyMiggy:

The Bluepad32 options are in:
`Components config` -> `Bluepad32` (find it at the very bottom) -> `Target platform`

And compile it:

```sh
idf.py build
```

5. Flash it

```sh
idf.py flash monitor
```

## How to compile it for Pico W

1. Install Pico SDK

Install latest stable Pico SDK (v1.5.1 as of 2023-11-11).

* <https://www.raspberrypi.com/documentation/microcontrollers/c_sdk.html>

2. Compile example project
* https://gitlab.com/ricardoquesada/bluepad32/-/releases

```sh
cd tools/pico_w
mkdir build
cd build
cmake .. -DPICO_BOARD=pico_w
make -j
```
## Creating your project

3. Flash it
See the examples folder which includes examples for:

Copy `build/bluepad32_picow_app.uf2` to Pico W.
* [Bluepad32 for ESP32][esp32-example] (ESP32, ESP32-S3, ESP32-C3)
* [Bluepad32 for Pico W][pico-w-example]
* [Bluepad32 for Linux][linux-example]

Use this guide if you are not sure how to do it:
Arduino examples are in:
* [Bluepad32 for Arduino IDE][arduino-ide-example]
* [Bluepad32 for Arduino + ESP-IDF][arduino-esp-idf-example]

* <https://projects.raspberrypi.org/en/projects/get-started-pico-w/>
[esp32-example]: examples/esp32/
[pico-w-example]: examples/pico_w/
[linux-example]: examples/linux
[arduino-ide-example]: https://www.youtube.com/watch?v=0jnY-XXiD8Q
[arduino-esp-idf-example]: https://gitlab.com/ricardoquesada/esp-idf-arduino-bluepad32-template

## Support

Expand All @@ -180,7 +129,7 @@ If you are developing a commercial product for:

- ESP32: [You should contact BTstack people][btstack-homepage].
- Pico W: [You are already covered by Raspberry Pi License][rpi-btstack-license].

Notice: I’m not affiliated with BTstack people. They are super friendly and willing to help.

[btstack-github]: https://github.com/bluekitchen/btstack
Expand Down
5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Examples

These examples use the "raw" API. These are **NOT** the Arduino Examples.

Each folder has a `README.md` with install / compile / flash instructions.
7 changes: 7 additions & 0 deletions examples/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

set(EXTRA_COMPONENT_DIRS ../../src/components)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(bluepad32-libusb-app)
53 changes: 53 additions & 0 deletions examples/esp32/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Bluepad32 for ESP32

Supports the different ESP32 chips:

* ESP32
* ESP32-S3
* ESP32-C3

## Install dependencies

1. Install ESP-IDF

Install the ESP32 toolchain. Use version **4.4** or **5.1**. Might work on newer / older
ones, but not tested.

* <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/>

2. Integrate BTstack into ESP32

```sh
cd ${BLUEPAD32}/external/btstack/port/esp32
# This will install BTstack as a component inside Bluepad32 source code (recommended).
# Remove "IDF_PATH=../../../../src" if you want it installed in the ESP-IDF folder
IDF_PATH=../../../../src ./integrate_btstack.py
```

3. Compile Bluepad32

```sh
# Possible options: esp32, esp32-s3 or esp32-c3
idf.py set-target esp32
```

And compile it:

```sh
idf.py build
```

4. Flash it

```sh
idf.py flash monitor
```

## License

- Example code: licensed under Public Domain.
- Bluepad32: licensed under Apache 2.
- BTstack:
- Free to use for open source projects.
- Paid for commercial projects.
- <https://github.com/bluekitchen/btstack/blob/master/LICENSE>
7 changes: 7 additions & 0 deletions examples/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(srcs "main.c" "my_platform.c")

set(requires "bluepad32" "btstack")

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "."
REQUIRES "${requires}")
42 changes: 42 additions & 0 deletions examples/esp32/main/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Example file - Public Domain
// Need help? https://tinyurl.com/bluepad32-help

#include <stdlib.h>

#include <btstack_port_esp32.h>
#include <btstack_run_loop.h>

#include "sdkconfig.h"
#include "uni_main.h"
#include "uni_platform.h"

// Sanity check
#ifndef CONFIG_BLUEPAD32_PLATFORM_CUSTOM
#error "Must use BLUEPAD32_PLATFORM_CUSTOM"
#endif

// Defined in my_platform.c
struct uni_platform* get_my_platform(void);

int app_main(void) {
// hci_dump_open(NULL, HCI_DUMP_STDOUT);

// Configure BTstack for ESP32 VHCI Controller
btstack_init();

// hci_dump_init(hci_dump_embedded_stdout_get_instance());

#ifdef CONFIG_BLUEPAD32_PLATFORM_CUSTOM
// Must be called before uni_main()
uni_platform_set_custom(get_my_platform());
#endif // CONFIG_BLUEPAD32_PLATFORM_CUSTOM

// Init Bluepad32.
uni_main(0 /* argc */, NULL /* argv */);

// Does not return.
btstack_run_loop_execute();

return 0;
}

Loading

0 comments on commit 9578c3f

Please sign in to comment.