OpenStickCommunity / GP2040-CE

Multi-Platform Gamepad Firmware for Raspberry Pi Pico and other RP2040 boards
https://gp2040-ce.info
MIT License
1.48k stars 319 forks source link

Bounty - Bluetooth support using the Pico W #247

Open Fortinbra opened 1 year ago

Fortinbra commented 1 year ago

We would like to have support for Bluetooth and the Pico W board.

Requirements

We need to still be able to use the controller as a USB controller when plugged in, or a Bluetooth controller when not.

This is purely from the firmware perspective. Hardware for battery management and charging will be a separate effort.

Addition Considerations

Would be nice to have.

TheTrainGoes commented 1 year ago

We chatted about this and are going to break it down into two separate bounties.

Part 1 will be a proof of concept. This proof of concept is an MVP to see if it is even viable as a controller and has reasonable lag / performance / etc.

This part can be quick and easy.

Part 2 will be the full incorporation into GP2040-CE.

LeeNX commented 1 year ago

Part 1 should be covered by PR https://github.com/bluekitchen/btstack/pull/209.

Extending the HID for more buttons,axis and modes could be seen in https://github.com/lemmingDev/ESP32-BLE-Gamepad

and possibly ForceFeedback with https://github.com/YukMingLaw/ArduinoJoystickWithFFBLibrary

Fortinbra commented 1 year ago

Part 1 should be covered by PR bluekitchen/btstack#209.

Extending the HID for more buttons,axis and modes could be seen in https://github.com/lemmingDev/ESP32-BLE-Gamepad

and possibly ForceFeedback with https://github.com/YukMingLaw/ArduinoJoystickWithFFBLibrary

While this is great information to have. What I'm looking for, for the bounty, is someone to actually make a demonstration using our codebase as the example.

dogtopus commented 1 year ago

I didn't know Pico W also supports Bluetooth Classic (a crucial thing to have for emulating most console Bluetooth controllers) until now.

We might actually get somewhere pretty far with this bounty. GP2040 DIY handheld controller anyone?

TheTrainGoes commented 1 year ago

@dogtopus yes please!

My dreams of a cord free Switch arcade stick are still within reach :)

HoboDev commented 1 year ago

Since the chip is connected via SPI... could this eventually be ported over to use ESP?

dogtopus commented 1 year ago

Since the chip is connected via SPI... could this eventually be ported over to use ESP?

In theory yes but we will eventually run into the issues with Bluekitchen's license agreement since it's not technically free software and from what I heard from them years ago, requires commercial licenses even if the firmware is open source but loaded officially to a board (open source or not) for sale.

RPi foundation licensed from them so the Bluekitchen stack can be used on Pico W free of charge but that only limits to Pico W.

(Also take this with a grain of salt since looks like their intention was to make it available for use with RP2040 and not just Pico W. It's better to formally ask them once we actually need to use the stack on non-Pico W boards.)

hizzlekizzle commented 1 year ago

Bluetooth support would also open the door for DIY receivers to connect bluetooth gamepads to S/NES or Wii extensions, right? That is, using the board as a receiver rather than a transmitter; similar to the SNES 'retro receiver' from 8bitdo?

Fortinbra commented 1 year ago

Since the chip is connected via SPI... could this eventually be ported over to use ESP?

For GP2040-CE, we don't have any plans to support any platforms other than the RP2040. You're always welcome to fork, and do your own thing.

Fortinbra commented 1 year ago

Bluetooth support would also open the door for DIY receivers to connect bluetooth gamepads to S/NES or Wii extensions, right? That is, using the board as a receiver rather than a transmitter; similar to the SNES 'retro receiver' from 8bitdo?

We need to get transmission working first.

dogtopus commented 1 year ago

Since the chip is connected via SPI... could this eventually be ported over to use ESP?

For GP2040-CE, we don't have any plans to support any platforms other than the RP2040. You're always welcome to fork, and do your own thing.

I think they meant using ESP as an HCI, which I'm not sure if the license for the Bluekitchen stack in pico-sdk permits such use case.

Fortinbra commented 1 year ago

Since the chip is connected via SPI... could this eventually be ported over to use ESP?

For GP2040-CE, we don't have any plans to support any platforms other than the RP2040. You're always welcome to fork, and do your own thing.

I think they meant using ESP as an HCI, which I'm not sure if the license for the Bluekitchen stack in pico-sdk permits such use case.

Oh, in that case, we're only utilizing what is available from the SDK, and we'll deviate after we have something working, if we have reason to.

futaris commented 1 year ago

I know I said I'd have this working last month. I ended up ordering a couple more Pico Ws so I can implement this.

sanjay900 commented 1 year ago

Bluetooth support would also open the door for DIY receivers to connect bluetooth gamepads to S/NES or Wii extensions, right? That is, using the board as a receiver rather than a transmitter; similar to the SNES 'retro receiver' from 8bitdo?

Just as a sidenote, having done this for a project of my own, there is a bug with the current Bluetooth driver that limits pico hid host polling pretty badly, https://github.com/raspberrypi/pico-sdk/issues/1342

I was mostly focused on making pairs of transmitters and receivers as I was building wireless controllers with console support, but from what I understand that bug should affect receiving from hid in general

Mind you, I guess that's only a problem for non classic, and I suspect everything you'd be doing here would be bt classic anyways

futaris commented 1 year ago

https://github.com/DavidPagels/retro-pico-switch

aallan commented 1 year ago

(Also take this with a grain of salt since looks like https://github.com/raspberrypi/pico-sdk/issues/1164#issuecomment-1372677903 was to make it available for use with RP2040 and not just Pico W. It's better to formally ask them once we actually need to use the stack on non-Pico W boards.)

While the CWY43439 driver is licensed for commercial use for users of Pico W, or anyone else who builds their product around RP2040 and CYW43439, this is not the case for the BlueKitchen license.

In addition to the standard BTstack licensing terms, a supplemental license which covers commercial use of BTstack with Raspberry Pi Pico W or Raspberry Pi Pico WH has been provided. There is no exception for those using RP2040 on their own boards.

dogtopus commented 1 year ago

@aallan Thanks for the clarification. I'm personally not a fan of this licensing model but I guess that's to be expected when using non-free libraries like bluekitchen stack.

TheTrainGoes commented 1 year ago

This issue is going to be re-written to better reflect the goals of the project. I will keep it open until the new issue is posted.

jars28 commented 8 months ago

https://github.com/DavidPagels/retro-pico-switch

Rough implementation of BlueTooth support with Switch connection is in this project.

henrebotha commented 8 months ago

Rough implementation of BlueTooth support with Switch connection is in this project.

Unfortunately, it uses the Pico SDK, which I believe we can't use.

Invictaz commented 8 months ago

Bluetooth support would also open the door for DIY receivers to connect bluetooth gamepads to S/NES or Wii extensions, right? That is, using the board as a receiver rather than a transmitter; similar to the SNES 'retro receiver' from 8bitdo?

We already have that on ESP32 in Blueretro but there must be a reason that Blueretro doesn't get ported to Pico. Maybe because of limited flash storage or the lack of speed.

dogtopus commented 8 months ago

Bluetooth support would also open the door for DIY receivers to connect bluetooth gamepads to S/NES or Wii extensions, right? That is, using the board as a receiver rather than a transmitter; similar to the SNES 'retro receiver' from 8bitdo?

We already have that on ESP32 in Blueretro but there must be a reason that Blueretro doesn't get ported to Pico. Maybe because of limited flash storage or the lack of speed.

It's the same reason why GP2040 is not ported to ESP32. Because it's heavily BSP-specific and effectively not portable without major time and effort spent to rewrite the code.

jars28 commented 8 months ago

"Raspberry Pi Pico W customers benefit from a pre-paid commercial license for BTstack, allowing you to use Pico W as a component in your own products."

https://www.raspberrypi.com/news/new-functionality-bluetooth-for-pico-w/

Fortinbra commented 8 months ago

Rough implementation of BlueTooth support with Switch connection is in this project.

Unfortunately, it uses the Pico SDK, which I believe we can't use.

The Pico Sdk is exactly what we're using, it's why we can't use other drivers for Bluetooth at the moment, only BlueStacks, since it's already part of the SDK.

bsstephan commented 8 months ago

Just adding citations here:

The driver is normally a non-commercial piece of software that has been licensed to RPi by BlueKitchen, and RPi has in turn licensed its free use only if you are creating a Pico-W or Pico-W derived product.

Both licenses lead to a scenario where the usage of BTstack would arguably (if not clearly) limit GP2040-CE to non-commercial applications and/or Pico W-only applications, so it's not an option for us at this time.

Addendum: but, of course, if someone does demonstrate all of this in a working state, maybe then it'd be worth trying to get our own license terms. A big if, to be clear, but just pointing out that the current reality doesn't shoot down the desire to experiment and get a PoC.

sanjay900 commented 8 months ago

By the way, i did ask bluekitchen about this for one of my projects and got this response back:

At the moment, Raspberry Pi has license our stack for all of their Pico W boards. By this, the Pico W can be used in commercial products without a license from us. If a RP2040 with some other Bluetooth Controller is used, this requires to sign a license agreement with us. On the other hand, if you build your own board with a RP 2040, you still need a Bluetooth Controller to use Bluetooth. The Pico W uses a CYW43439 and modules with the are more expensive than a Pico W. If you order 1k of CYW43439 from Mouser/Digikey, you still pay 3.80 USD. If you buy RP2040 on a reel, that's 0.63 USD. This gets you already to about 4.50 USD and you still need a flash, oscillator, ... so, unless there's a good reason, it's easier and cheaper to just buy Pico Ws :) If you want to be cheaper than the Pico W, I would suggest the ESP32 (BR/EDR/LE/Wifi) or the ESP32-C3 (LE/WIFI). You can either use the Bluedroid or NimBLE stack that is free to use, or ours with a license. When you get closer to choosing a path, feel free to get back and discuss your licensing needs. We try to make our stack affordable to small startups/Makers with low volumes.

One thing i have seen some RP2040 based boards do is use other bluetooth modules. I have seen these myself, but have not tried them so I don't know what libraries exist for them.

As for actually implementing bluetooth, XInput won't be possible since that needs USB due to how windows detects those devices, so you would have to implement something using standard HID, but that is easy enough and i have done that myself for my Pico W based firmware.

TheTrainGoes commented 8 months ago

This is an odd line worth more investigation:

"If a RP2040 with some other Bluetooth Controller is used, this requires to sign a license agreement with us."

Mind reaching back out to see if the license is handled should we choose to use the same parts as the W?

Why would I do that if it costs more than the Pico W? Easy! I don't want to solder a bunch of them and I need more GPIO.

sanjay900 commented 8 months ago

You would 100% have to license it with them if you use anything that isn't a PicoW, even if the parts are the same.

I think by that they mean if you wanted to say use btstack on one of the other various RP2040 boards with bluetooth, you would have to license that as well, as its only licensed for use with the PicoW specifically.

But i think if we were looking at other bluetooth modules i would assume they have some other bluetooth lib they can use.