mirror of
https://github.com/speedypotato/Pico-Game-Controller.git
synced 2026-10-01 03:07:55 +03:00
Pocket SDVX Pico Configuration
This commit is contained in:
committed by
Nicholas G
parent
c23ebfcd33
commit
df2e9e2566
@@ -1,6 +1,6 @@
|
||||
# Pico-Game-Controller
|
||||
|
||||
Code for a keyboard or game controller using a Raspberry Pi Pico. Capable of handling 11 buttons, 10 LEDs, 1 WS2812B RGB strip, and 2 encoders. Developed with SDVX and IIDX in mind - see branches release/pocket-sdvx-pico and release/pocket-iidx for preconfigured versions.
|
||||
This branch was developed with SDVX in mind. Capable of handling 7 LEDs, 1 WS2812B RGB strip, and 2 encoders.
|
||||
|
||||
Demo of this firmware running on Pocket SDVX Pico, purchasable at https://discord.gg/MmuKd73XbY
|
||||
|
||||
|
||||
Binary file not shown.
+3
-1
@@ -4,7 +4,9 @@ Manually copied built uf2 file for quick flashing.
|
||||
|
||||
Quick how-to flash:
|
||||
|
||||
1. Hold down Pi Pico button when plugging it in.
|
||||
If you haven't already, download Pico_Game_Controller.uf2 first by clicking it above and then clicking the Download button near the top right.
|
||||
|
||||
1. Hold down Pi Pico button when plugging it in. (This is the button on the bottom of the controller)
|
||||
2. Drag Pico_Game_Controller.uf2 into the 'drive' RPI-RP2
|
||||
3. Done!
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef CONTROLLER_CONFIG_H
|
||||
#define CONTROLLER_CONFIG_H
|
||||
|
||||
#define SW_GPIO_SIZE 11 // Number of switches
|
||||
#define LED_GPIO_SIZE 10 // Number of switch LEDs
|
||||
#define SW_GPIO_SIZE 9 // Number of switches
|
||||
#define LED_GPIO_SIZE 7 // Number of switch LEDs
|
||||
#define ENC_GPIO_SIZE 2 // Number of encoders
|
||||
#define ENC_PPR 600 // Encoder PPR
|
||||
#define ENC_PPR 24 // Encoder PPR
|
||||
#define ENC_DEBOUNCE true // Encoder Debouncing
|
||||
#define SW_DEBOUNCE_TIME_US 4000 // Switch debounce delay in us
|
||||
#define ENC_PULSE (ENC_PPR * 4) // 4 pulses per PPR
|
||||
@@ -17,14 +17,15 @@
|
||||
#ifdef PICO_GAME_CONTROLLER_C
|
||||
|
||||
// MODIFY KEYBINDS HERE, MAKE SURE LENGTHS MATCH SW_GPIO_SIZE
|
||||
const uint8_t SW_KEYCODE[] = {HID_KEY_D, HID_KEY_F, HID_KEY_J, HID_KEY_K,
|
||||
HID_KEY_C, HID_KEY_M, HID_KEY_A, HID_KEY_B,
|
||||
HID_KEY_1, HID_KEY_E, HID_KEY_G};
|
||||
const uint8_t SW_KEYCODE[] = {
|
||||
HID_KEY_D, HID_KEY_F, HID_KEY_J, HID_KEY_K, HID_KEY_C,
|
||||
HID_KEY_M, HID_KEY_A, HID_KEY_B, HID_KEY_1,
|
||||
};
|
||||
const uint8_t SW_GPIO[] = {
|
||||
4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 27,
|
||||
4, 6, 8, 10, 12, 14, 27, 18, 20,
|
||||
};
|
||||
const uint8_t LED_GPIO[] = {
|
||||
5, 7, 9, 11, 13, 15, 17, 19, 21, 26,
|
||||
5, 7, 9, 11, 13, 15, 21,
|
||||
};
|
||||
const uint8_t ENC_GPIO[] = {0, 2}; // L_ENC(0, 1); R_ENC(2, 3)
|
||||
const bool ENC_REV[] = {false, false}; // Reverse Encoders
|
||||
|
||||
@@ -114,7 +114,7 @@ void update_lights() {
|
||||
if (reactive_timeout_count < REACTIVE_TIMEOUT_MAX) {
|
||||
reactive_timeout_count++;
|
||||
}
|
||||
for (int i = 0; i < LED_GPIO_SIZE; i++) {
|
||||
for (int i = 0; i < LED_GPIO_SIZE - 1; i++) {
|
||||
if (reactive_timeout_count >= REACTIVE_TIMEOUT_MAX) {
|
||||
if (!gpio_get(SW_GPIO[i])) {
|
||||
gpio_put(LED_GPIO[i], 1);
|
||||
@@ -128,6 +128,20 @@ void update_lights() {
|
||||
gpio_put(LED_GPIO[i], 1);
|
||||
}
|
||||
}
|
||||
/* start button sw_val index is offset by two with respect to LED_GPIO */
|
||||
if (reactive_timeout_count >= REACTIVE_TIMEOUT_MAX) {
|
||||
if (!gpio_get(SW_GPIO[LED_GPIO_SIZE + 1])) {
|
||||
gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 1);
|
||||
} else {
|
||||
gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 0);
|
||||
}
|
||||
} else {
|
||||
if (lights_report.lights.buttons[LED_GPIO_SIZE - 1] == 0) {
|
||||
gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 0);
|
||||
} else {
|
||||
gpio_put(LED_GPIO[LED_GPIO_SIZE - 1], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+21
-31
@@ -34,10 +34,6 @@
|
||||
* Auto ProductID layout's Bitmap:
|
||||
* [MSB] HID | MSC | CDC [LSB]
|
||||
*/
|
||||
#define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n))
|
||||
#define USB_PID \
|
||||
(0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
|
||||
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4))
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
@@ -51,8 +47,8 @@ tusb_desc_device_t const desc_device_joy = {
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
|
||||
.idVendor = 0xCafe,
|
||||
.idProduct = USB_PID,
|
||||
.idVendor = 0x1ccf,
|
||||
.idProduct = 0x101c,
|
||||
.bcdDevice = 0x0100,
|
||||
|
||||
.iManufacturer = 0x01,
|
||||
@@ -70,8 +66,8 @@ tusb_desc_device_t const desc_device_key = {
|
||||
.bDeviceProtocol = 0x00,
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
|
||||
.idVendor = 0xCafe,
|
||||
.idProduct = USB_PID,
|
||||
.idVendor = 0x1ccf,
|
||||
.idProduct = 0x101c,
|
||||
.bcdDevice = 0x0100,
|
||||
|
||||
.iManufacturer = 0x01,
|
||||
@@ -92,14 +88,12 @@ uint8_t const* tud_descriptor_device_cb(void) {
|
||||
|
||||
uint8_t const desc_hid_report_joy[] = {
|
||||
GAMECON_REPORT_DESC_JOYSTICK(HID_REPORT_ID(REPORT_ID_JOYSTICK)),
|
||||
GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS))
|
||||
};
|
||||
GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS))};
|
||||
|
||||
uint8_t const desc_hid_report_key[] = {
|
||||
GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS)),
|
||||
GAMECON_REPORT_DESC_NKRO(HID_REPORT_ID(REPORT_ID_KEYBOARD)),
|
||||
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE))
|
||||
};
|
||||
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(REPORT_ID_MOUSE))};
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
@@ -131,7 +125,6 @@ uint8_t const desc_configuration_joy[] = {
|
||||
sizeof(desc_hid_report_joy), EPNUM_HID,
|
||||
CFG_TUD_HID_EP_BUFSIZE, 1)};
|
||||
|
||||
|
||||
uint8_t const desc_configuration_key[] = {
|
||||
// Config number, interface count, string index, total length, attribute,
|
||||
// power in mA
|
||||
@@ -159,25 +152,22 @@ uint8_t const* tud_descriptor_configuration_cb(uint8_t index) {
|
||||
// array of pointer to string descriptors
|
||||
char const* string_desc_arr[] = {
|
||||
(const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
|
||||
"SpeedyPotato", // 1: Manufacturer
|
||||
"Pico Game Controller", // 2: Product
|
||||
"Konami Amusement", // 1: Manufacturer
|
||||
"SOUND VOLTEX controller", // 2: Product
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"Button 1",
|
||||
"Button 2",
|
||||
"Button 3",
|
||||
"Button 4",
|
||||
"Button 5",
|
||||
"Button 6",
|
||||
"Button 7",
|
||||
"Button 8",
|
||||
"Button 9",
|
||||
"Button 10",
|
||||
"Red 1",
|
||||
"Green 1",
|
||||
"Blue 1",
|
||||
"Red 2",
|
||||
"Green 2",
|
||||
"Blue 2",
|
||||
"BT-A",
|
||||
"BT-B",
|
||||
"BT-C",
|
||||
"BT-D",
|
||||
"FX-L",
|
||||
"FX-R",
|
||||
"Start",
|
||||
"Left R",
|
||||
"Left G",
|
||||
"Left B",
|
||||
"Right R",
|
||||
"Right G",
|
||||
"Right B",
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[64];
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define USB_DESCRIPTORS_H_
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
#include "controller_config.h"
|
||||
#include "device/usbd.h"
|
||||
|
||||
enum {
|
||||
REPORT_ID_JOYSTICK = 1,
|
||||
@@ -27,10 +27,10 @@ enum {
|
||||
HID_USAGE(HID_USAGE_DESKTOP_JOYSTICK), \
|
||||
HID_COLLECTION(HID_COLLECTION_APPLICATION), \
|
||||
__VA_ARGS__ HID_USAGE_PAGE(HID_USAGE_PAGE_BUTTON), HID_USAGE_MIN(1), \
|
||||
HID_USAGE_MAX(SW_GPIO_SIZE), \
|
||||
HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), HID_REPORT_COUNT(SW_GPIO_SIZE), \
|
||||
HID_REPORT_SIZE(1), HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
|
||||
HID_REPORT_COUNT(1), HID_REPORT_SIZE(16 - SW_GPIO_SIZE), /*Padding*/\
|
||||
HID_USAGE_MAX(SW_GPIO_SIZE), HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), \
|
||||
HID_REPORT_COUNT(SW_GPIO_SIZE), HID_REPORT_SIZE(1), \
|
||||
HID_INPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_REPORT_COUNT(1), \
|
||||
HID_REPORT_SIZE(16 - SW_GPIO_SIZE), /*Padding*/ \
|
||||
HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \
|
||||
HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_LOGICAL_MIN(0x00), \
|
||||
HID_LOGICAL_MAX_N(0x00ff, 2), \
|
||||
@@ -45,7 +45,7 @@ enum {
|
||||
__VA_ARGS__ HID_REPORT_COUNT(LED_GPIO_SIZE + (WS2812B_LED_ZONES * 3)), \
|
||||
HID_REPORT_SIZE(8), HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \
|
||||
HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), HID_STRING_MINIMUM(4), \
|
||||
HID_STRING_MAXIMUM(16), HID_USAGE_MIN(1), HID_USAGE_MAX(16), \
|
||||
HID_STRING_MAXIMUM(16), HID_USAGE_MIN(1), HID_USAGE_MAX(13), \
|
||||
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_REPORT_COUNT(1), \
|
||||
HID_REPORT_SIZE(8), /*Padding*/ \
|
||||
HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \
|
||||
|
||||
Reference in New Issue
Block a user