Legion2 / CorsairLightingProtocol

Control LEDs connected to an Arduino with iCUE, create an unofficial Corsair iCUE compatible Arduino LED controller.
Apache License 2.0
509 stars 64 forks source link

Raspberry PICO 2040 and TinyUSB #281

Closed MakerVejby closed 2 years ago

MakerVejby commented 2 years ago

After uploading the sketch to the RP2040, the RP2040 presents itself as a USB to Serial (TinyUSB Serial).

If I start USBview I can see the following.. Device Descriptor: bcdUSB: 0x0200 bDeviceClass: 0xEF bDeviceSubClass: 0x02 bDeviceProtocol: 0x01 bMaxPacketSize0: 0x40 (64) idVendor: 0x1B1C idProduct: 0x1C1A bcdDevice: 0x0100 iManufacturer: 0x01 iProduct: 0x02 0x0409: "Lighting Node PRO" iSerialNumber: 0x03 0x0409: "FB66DF55421900F5" bNumConfigurations: 0x01

But i can also see in usbview Interface Descriptor: bInterfaceNumber: 0x00 bAlternateSetting: 0x00 bNumEndpoints: 0x01 bInterfaceClass: 0x02 bInterfaceSubClass: 0x02 bInterfaceProtocol: 0x00 iInterface: 0x04 0x0409: "TinyUSB Serial"

System (please complete the following information):

I have added the 6 files for the RP2040 and #elif defined(ARDUINO_ARCH_RP2040) / #include statements in [led_sysdefs.h] and [platforms.h]

Legion2 commented 2 years ago

@Spegs21 can you help here?

Spegs21 commented 2 years ago

The CDC endpoint is not disabled in the code and it will be visible along side the HID endpoint. It should not affect the operation of the device. It is needed to be able to upload to the Pico without manually entering the bootloader.

Is the device not visible in iCue?

MakerVejby commented 2 years ago

No, The device is not visible in ICue / device manager. Only "TinyUSB Serial" is visible in device manager.

When i first programmed the rp2040 and when the sketch was uploaded i could see "Lightning node pro" as a device. But when windows has searched for driver only "TinyUSB Serial" is displayed.

Spegs21 commented 2 years ago

@MakerVejby Have you me any changes to the sketch? Have you used this board or a different board as a different Corsair device through this library on your PC? Sometimes iCue won't show the device without a restart because the device ID it remembers is for a different device.

MakerVejby commented 2 years ago

I have only used this board for this program. I have not made any changes in the code. I have programmed one Arduino Pro Micro and that one works like a charm.

I have tried to reboot the computer but it didn't help.

Spegs21 commented 2 years ago

@MakerVejby Do you have the pro micro plugged in at the same time?

MakerVejby commented 2 years ago

Of course not! :-) That would be a easy fix.

MakerVejby commented 2 years ago

. It is needed to be able to upload to the Pico without manually entering the bootloader.

How do i upload to a raspberry PICO without entering boot mode?

Spegs21 commented 2 years ago

@MakerVejby It doesn't look like the support for entering the bootloader with the serial trigger is implemented in the Pico core. Adafruit has this working for their SAMD boards though.

I compiled and uploaded the TinyUSB sketch to my Pico through the Arduino IDE and it is working fine. Can you enable verbose output during compilation in the IDE preferences and post the build log here?

MakerVejby commented 2 years ago

Please see txt file Compile.txt

Spegs21 commented 2 years ago

@MakerVejby Nothing jumps out at me as being wrong here. Can you change the device ID in the sketch and define a different serial number like shown here? You can then pass the serial number to the CorsairLightingProtocolTinyUSBHID constructor in the same way.

MakerVejby commented 2 years ago

When i try to change serial according to the example i only get "'CorsairLightingProtocolHID' does not name a type; did you mean 'CorsairLightingProtocolSerial'?" Code

#include <CorsairLightingProtocol.h>
#include <FastLED.h>

#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3

CRGB ledsChannel1[96];
CRGB ledsChannel2[96];

// Most ARM devices do not contain an EEPROM; we will use static storage for the Device ID
const char mySerialNumber[] PROGMEM = "202B6949A967";
DeviceID deviceID = {0x9A, 0xDA, 0xA7, 0x8A};
CorsairLightingFirmwareStorageStatic firmwareStorage(deviceID);
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_PRO, &firmwareStorage);
FastLEDController ledController(nullptr);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolTinyUSBHID cHID(&cLP);
CorsairLightingProtocolHID cHID(&cLP, mySerialNumber);

void setup() {
    cHID.setup();
    FastLED.addLeds<WS2812B, DATA_PIN_CHANNEL_1, GRB>(ledsChannel1, 96);
    FastLED.addLeds<WS2812B, DATA_PIN_CHANNEL_2, GRB>(ledsChannel2, 96);
    ledController.addLEDs(0, ledsChannel1, 96);
    ledController.addLEDs(1, ledsChannel2, 96);
}

void loop() {
    cHID.update();

    if (ledController.updateLEDs()) {
        FastLED.show();
    }
}
Spegs21 commented 2 years ago

@MakerVejby You need to pass the serial number to the CorsairLightingProtocolTinyUSBHID constructor not add the CorsairLightingProtocolHID constructor. I just said you do it in the same way.

CorsairLightingProtocolTinyUSBHID cHID(&cLP, mySerialNumber);

MakerVejby commented 2 years ago

@Spegs21 Sorry, My bad. I was to eager to get it to work on the RP2040. I have changed the code so it's correct now. But no success. I've tried the RP2040 on two other computer that have newly installed windows 10 and 7 and the latest Icue. But still the same. It won't show up in Icue as a device. I have tried with new serial and new device id.

Spegs21 commented 2 years ago

@MakerVejby can you enable debug logging in iCue and export the logs after plugging in the device then post the zip file here?

Spegs21 commented 2 years ago

@MakerVejby I just noticed your idProduct is incorrect.

idProduct: 0x1C1A

Did you change some of the files? This should be 0x0C0B

MakerVejby commented 2 years ago

Well, look at that! Now it's working! Show's up as a Corsair Node Pro! Don't remember changing the PID but when i look at the files on github they differs from my files. So i must say that the file has been altered here.

Thank you for all the support!