Skip to content

Commit

Permalink
Pocket SDVX Pico Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyRedMachine authored and speedypotato committed Nov 8, 2021
1 parent c23ebfc commit df2e9e2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Binary file modified build_uf2/Pico_Game_Controller.uf2
Binary file not shown.
4 changes: 3 additions & 1 deletion build_uf2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
17 changes: 9 additions & 8 deletions src/controller_config.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion src/pico_game_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
}

Expand Down
52 changes: 21 additions & 31 deletions src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down
12 changes: 6 additions & 6 deletions src/usb_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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), \
Expand All @@ -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), \
Expand Down

0 comments on commit df2e9e2

Please sign in to comment.