Skip to content

Commit

Permalink
Merge pull request #215 from Spegs21/dev
Browse files Browse the repository at this point in the history
Add support for TinyUSB
  • Loading branch information
Legion2 authored Jan 31, 2022
2 parents 4593dca + 69c57bd commit ba2f6e8
Show file tree
Hide file tree
Showing 48 changed files with 745 additions and 202 deletions.
57 changes: 47 additions & 10 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
name: Test
jobs:
test:
Expand All @@ -17,11 +17,11 @@ jobs:
- name: Build for ${{ matrix.board }}
uses: ArminJo/arduino-test-compile@v3
with:
cli-version: 0.14.0
cli-version: 0.18.3
arduino-board-fqbn: ${{ matrix.board }}
platform-url: https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json,https://raw.githubusercontent.com/Legion2/CorsairLightingProtocolBoards/master/package_Legion2_CorsairLightingProtocolBoards_index.json
arduino-platform: arduino:avr@1.8.3,SparkFun:avr@1.1.13,Legion2:avr@0.2.0
required-libraries: FastLED@3.3.3
arduino-platform: arduino:avr@1.8.3,SparkFun:avr@1.1.13,Legion2:avr@0.3.1
required-libraries: FastLED@3.5.0
sketch-names: LightingNodePRO.ino,
SingleStripLightingNodePRO.ino,
CommanderPRO.ino,
Expand All @@ -35,7 +35,8 @@ jobs:
AdditionalFeatures.ino,
AmbientBacklight.ino,
MultipleFans.ino,
DebugSketch.ino
DebugSketch.ino,
NoEEPROM.ino
build-properties: '{"DebugSketch": "-DDEBUG -DVERBOSE -DPRINT_COMMAND=true -DPRINT_RESPONSE=true -DPRINT_LOOP=true -DPRINT_UPDATE=true"}'
testUnoMega:
name: Test Arduino Uno/Mega sketches for Board ${{ matrix.board }}
Expand All @@ -48,10 +49,10 @@ jobs:
- name: Build for ${{ matrix.board }}
uses: ArminJo/arduino-test-compile@v3
with:
cli-version: 0.14.0
cli-version: 0.18.3
arduino-board-fqbn: ${{ matrix.board }}
arduino-platform: arduino:avr@1.8.3
required-libraries: FastLED@3.3.3
required-libraries: FastLED@3.5.0
sketch-names: HoodLoader2UnoMegaController.ino
test16u2:
name: Test 16u2 sketch for Board ${{ matrix.board }}
Expand All @@ -64,9 +65,45 @@ jobs:
- name: Build for ${{ matrix.board }}
uses: ArminJo/arduino-test-compile@v3
with:
cli-version: 0.14.0
cli-version: 0.18.3
arduino-board-fqbn: ${{ matrix.board }}
platform-url: https://raw.githubusercontent.com/NicoHood/HoodLoader2/master/package_NicoHood_HoodLoader2_index.json,https://raw.githubusercontent.com/Legion2/CorsairLightingProtocolBoards/master/package_Legion2_CorsairLightingProtocolBoards_index.json
arduino-platform: arduino:avr@1.8.3,HoodLoader2:avr@2.0.5,Legion2:avr@0.2.0
required-libraries: FastLED@3.3.3
arduino-platform: arduino:avr@1.8.3,HoodLoader2:avr@2.0.5,Legion2:avr@0.3.1
required-libraries: FastLED@3.5.0
sketch-names: HoodLoader2CLPBridge.ino
testAdafruitM0:
name: Test for Board ${{ matrix.board }}
runs-on: ubuntu-latest
strategy:
matrix:
board:
[
"adafruit:samd:adafruit_feather_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_feather_m0_express:usbstack=tinyusb",
"adafruit:samd:adafruit_metro_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_circuitplayground_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_gemma_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_trinket_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_qtpy_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_neotrinkey_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_rotarytrinkey_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_neokeytrinkey_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_slidetrinkey_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_proxlighttrinkey_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_itsybitsy_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_pirkey:usbstack=tinyusb",
"adafruit:samd:adafruit_hallowing:usbstack=tinyusb",
"adafruit:samd:adafruit_crickit_m0:usbstack=tinyusb",
"adafruit:samd:adafruit_blm_badge:usbstack=tinyusb"
]
steps:
- uses: actions/checkout@v2
- name: Build for ${{ matrix.board }}
uses: ArminJo/arduino-test-compile@v3
with:
cli-version: 0.18.3
arduino-board-fqbn: ${{ matrix.board }}
platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
arduino-platform: adafruit:samd@1.7.8
required-libraries: FastLED@3.5.0,Adafruit TinyUSB Library@1.9.2
sketch-names: TinyUSB.ino
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _This is not an official corsair project._
* Control LEDs with the [Corsair iCUE software](https://www.corsair.com/icue).
* [Support common LED chipsets](/~https://github.com/FastLED/FastLED/wiki/Overview#chipsets). (e.g. WS2812B, WS2801)
* Support [FastLED](http://fastled.io/).
* Supported platform: Arduino AVR
* Supported platforms: Arduino AVR, [TinyUSB supported cores](/~https://github.com/adafruit/Adafruit_TinyUSB_Arduino#supported-cores)
* Hardware Lighting mode.
* Use multiple devices at the same time.
* Repeat or scale LED channels to arbitrary size.
Expand All @@ -33,14 +33,19 @@ This project provides example sketches for easy use with Arduino IDE.

- [Requirements](#requirements)
- [Install the libraries](#install-the-libraries)
- [Create a Lighting Node PRO](#create-a-lighting-node-pro)
- [Create a Lighting Node PRO with AVR](#create-a-lighting-node-pro-with-avr)
- [Create a Lighting Node PRO with TinyUSB](#create-a-lighting-node-pro-for-a-raspberry-pi-pico-with-tinyusb)
- [Use the Lighting Node PRO](#use-the-lighting-node-pro)

## Requirements
The library is compatible with all boards using the MCU ATmega32U4.
This includes **Arduino Leonardo**, **SparkFun Pro Micro**, **Arduino Micro**, and **Adafruit 32u4 AVR Boards**.
It also supports the Arduino Uno and Arduino Mega, **but** this requires the [HoodLoader2](/~https://github.com/NicoHood/HoodLoader2) bootloader, see [this wiki](/~https://github.com/Legion2/CorsairLightingProtocol/wiki/How-to-use-on-Arduino-Uno-and-Arduino-Mega) for more details.
It is **not** compatible with ATmega328 (Arduino Nano), STM8S103F3, teensy, ESP8266 and ESP32 see [list of architecture/platform](/~https://github.com/Legion2/CorsairLightingProtocol/issues?q=is%3Aissue+label%3Aarchitecture%2Fplatform) for a detailed description why they are not supported.

In addition, any board compatible with **Adafruit TinyUSB for Arduino** is also supported without the use of custom board definitions. Be sure to define USE_TINYUSB, which is done automatically when using a supported core and selecting TinyUSB for the USB Stack. See the TinyUSB example for implementation details.

It is **not** compatible with ATmega328 (Arduino Nano), STM8S103F3, teensy, or ESP8266 see [list of architecture/platform](/~https://github.com/Legion2/CorsairLightingProtocol/issues?q=is%3Aissue+label%3Aarchitecture%2Fplatform) for a detailed description why they are not supported.

In the rest of the documentation "Arduino" is used as a synonym for all supported boards regardless of the manufacturer.

When you have problems with a board not listed here, please open an [Issue](/~https://github.com/Legion2/CorsairLightingProtocol/issues).
Expand All @@ -51,8 +56,9 @@ Open the Library-Manager in Arduino IDE via Tools->Manage Libraries...
Search for "Corsair Lighting Protocol" and install the Corsair Lighting Protocol library.
This library also requires the [FastLED](http://fastled.io/) library.
Search for "FastLED" in the Library-Manager and install the FastLED library.
If using TinyUSB, also install the latest "Adafruit TinyUSB Library" as it supersedes some of the core versions.

## Create a Lighting Node PRO
## Create a Lighting Node PRO with AVR
This guide will teach you how to create a Lighting Node PRO with an Arduino Leonardo compatible board.
If you have an Arduino Uno or Mega, see the [other guide](/~https://github.com/Legion2/CorsairLightingProtocol/wiki/How-to-use-on-Arduino-Uno-and-Arduino-Mega).

Expand All @@ -70,7 +76,7 @@ If you have an Arduino Uno or Mega, see the [other guide](/~https://github.com/Leg

![upload sketch](extra/images/upload-sketch.png)
1. Do the wiring.
For more information on [how to wire the leds](/~https://github.com/FastLED/FastLED/wiki/Wiring-leds) and [how to set up the LEDs in the code](/~https://github.com/FastLED/FastLED/wiki/Basic-usage#setting-up-the-leds) see the links.
For more information on [how to wire the LEDs](/~https://github.com/FastLED/FastLED/wiki/Wiring-leds) and [how to set up the LEDs in the code](/~https://github.com/FastLED/FastLED/wiki/Basic-usage#setting-up-the-leds) see the links.

![the wiring](extra/images/board-wiring.jpg)
1. Verify your device works as expected.
Expand All @@ -80,6 +86,31 @@ If you have an Arduino Uno or Mega, see the [other guide](/~https://github.com/Leg

> If you have any problem during setup you may find the solution in the [Troubleshooting section](/~https://github.com/Legion2/CorsairLightingProtocol/wiki/Troubleshooting).
## Create a Lighting Node PRO for a Raspberry Pi Pico with TinyUSB

This guide will teach you how to create a Lighting Node PRO with a Raspberry Pi Pico.

**Note:** FastLED currently does not support the RP2040 natively. You must manually merge support by modifying your library to include the [6 RP2040 platform files](/~https://github.com/FastLED/FastLED/pull/1261/files#diff-fda1710ad90fcc4b2f07be21a834da7d24b00008867655232c84fb0369cfc74b) in the FastLED/src/platforms/arm/rp2040 folder and `#elif defined(ARDUINO_ARCH_RP2040)` / `#include` statements in [led_sysdefs.h](/~https://github.com/FastLED/FastLED/pull/1261/files#diff-95f6b43a0e6b0e58988e1be3bc6415ded5284082a4f2ce2aaa90f5931d4194af) and [platforms.h](/~https://github.com/FastLED/FastLED/pull/1261/files#diff-255ea38a6573ed237ea1fe164d5e87ca46811eef21ba6e2cef120fda47c6e62f).

1. Install the [Raspberry Pi Pico Arduino core](/~https://github.com/earlephilhower/arduino-pico#installing-via-arduino-boards-manager).

1. Open the example "TinyUSB", you can find it in Arduino IDE in the File menu->Examples->Corsair Lighting Protocol->TinyUSB.
If you can't open the LightingNodePRO example the Corsair Lighting Protocol library is not installed correctly.

1. Select the Raspberry Pi Pico as shown in the screenshot below. Be sure to select the "Adafruit TinyUSB" USB Stack.

![select Raspberry Pi Pico](extra/images/select-board-pico.png)
1. Upload the "TinyUSB" sketch to your Pico.

1. Do the wiring.
For more information on [how to wire the LEDs](/~https://github.com/FastLED/FastLED/wiki/Wiring-leds) and [how to set up the LEDs in the code](/~https://github.com/FastLED/FastLED/wiki/Basic-usage#setting-up-the-leds) see the links.

![the wiring](extra/images/board-wiring-pico.jpg)
1. Verify your device works as expected.
Open the Windows settings->devices->Other devices.
Somewhere in the list of devices, there should be a device called "Lighting Node PRO".
1. Now open [iCUE](https://www.corsair.com/icue) there you should see the "Lighting Node PRO".

## Use the Lighting Node PRO

![iCUE RGB Strip example](extra/images/iCUE.jpg)
Expand Down Expand Up @@ -121,7 +152,7 @@ The Serial Number MAY only consist of HEX characters (0-9 and A-F).
The DeviceID can be set with the `setDeviceID` function of `CorsairLightingFirmware`.
```C++
void setup() {
byte deviceId[4] = { 0x9A, 0xDA, 0xA7, 0x8E };
DeviceID deviceId = { 0x9A, 0xDA, 0xA7, 0x8E };
firmware.setDeviceID(deviceId);
...
}
Expand Down Expand Up @@ -173,7 +204,7 @@ ledController.onUpdateHook(0, []() {
The [Hardware Lighting mode](https://forum.corsair.com/v3/showthread.php?t=182874) can be configured in iCUE.
It allows you the set lighting effects that will be active when iCUE **is not** running.
This is the case when the PC is off, in sleep mode, booting or the user is logged out.
So if you want to have lighing effects in all these situations, use the Hardware Lighting mode.
So if you want to have lighting effects in all these situations, use the Hardware Lighting mode.
If you don't want it, configure a static black color.

# License
Expand Down
6 changes: 4 additions & 2 deletions examples/AdditionalFeatures/AdditionalFeatures.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ CRGB ledsChannel2[60];
// Define a custom SerialNumber for the device
const char mySerialNumber[] PROGMEM = "202B6949A967";

CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_PRO, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
// Set the SerialNumber here
CorsairLightingProtocolHID cHID(&cLP, mySerialNumber);
Expand Down
6 changes: 4 additions & 2 deletions examples/AmbientBacklight/AmbientBacklight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
CRGB ledsChannel1[84];
CRGB ledsChannel2[105];

CorsairLightingFirmware firmware = corsairLS100Firmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_SMART_LIGHTING_CONTROLLER, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
9 changes: 5 additions & 4 deletions examples/CommanderPRO/CommanderPRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@

#define CHANNEL_LED_COUNT 96

CorsairLightingFirmware firmware = corsairCommanderPROFirmware();
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_COMMANDER_PRO, &firmwareStorage);
ThermistorTemperatureController temperatureController;
FastLEDController ledController(&temperatureController, true);
SimpleFanController fanController(&temperatureController, FAN_UPDATE_RATE,
EEPROM_ADDRESS + ledController.getEEPROMSize());
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
SimpleFanController fanController(&temperatureController, FAN_UPDATE_RATE, EEPROM_ADDRESS + storage.getEEPROMSize());
CorsairLightingProtocolController cLP(&ledController, &temperatureController, &fanController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
8 changes: 5 additions & 3 deletions examples/DebugSketch/DebugSketch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3

CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_PRO, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cLPS(&cLP);

Expand Down Expand Up @@ -60,7 +62,7 @@ void loop() {

void processCommand(String& cmd) {
if (cmd == F("print DeviceID")) {
byte deviceId[4];
DeviceID deviceId;
firmware.getDeviceID(deviceId);
CLP::printDeviceID(deviceId);
Serial.println();
Expand Down
20 changes: 10 additions & 10 deletions examples/DeviceIDTool/DeviceIDTool.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
// UPLOAD THIS TO THE ARDUINO AND OPEN SERIAL MONITOR WITH BOUDRATE 115200
//
#include <CLPUtils.h>
#include <EEPROM.h>
#include <CorsairLightingFirmwareStorageEEPROM.h>

#define EEPROM_ADDRESS_DEVICE_ID 0
CorsairLightingFirmwareStorageEEPROM firmwareStorage;

void setup() {
Serial.begin(115200);
Serial.setTimeout(100);
uint8_t deviceID[4];
EEPROM.get(EEPROM_ADDRESS_DEVICE_ID, deviceID);
DeviceID deviceID;
firmwareStorage.loadDeviceID(deviceID);

while (!Serial) {
; // wait for serial port to connect. Needed for native USB
Expand All @@ -47,12 +47,12 @@ void loop() {
Serial.println(F("Do not forget the leading zeroes!"));
Serial.println();
} else {
uint8_t newDeviceID[4];
DeviceID newDeviceID;

newDeviceID[0] = strtol(&inputString[0], nullptr, 16);
newDeviceID[1] = strtol(&inputString[3], nullptr, 16);
newDeviceID[2] = strtol(&inputString[6], nullptr, 16);
newDeviceID[3] = strtol(&inputString[9], nullptr, 16);
newDeviceID.data[0] = strtol(&inputString[0], nullptr, 16);
newDeviceID.data[1] = strtol(&inputString[3], nullptr, 16);
newDeviceID.data[2] = strtol(&inputString[6], nullptr, 16);
newDeviceID.data[3] = strtol(&inputString[9], nullptr, 16);
Serial.println(F("Set DeviceID to: "));
CLP::printDeviceID(newDeviceID);
Serial.println();
Expand All @@ -66,7 +66,7 @@ void loop() {
F("This is a special DeviceID, it will reset the device and then generate a new DeviceID!"));
}
Serial.println();
EEPROM.put(EEPROM_ADDRESS_DEVICE_ID, newDeviceID);
firmwareStorage.saveDeviceID(newDeviceID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
#define DATA_PIN_CHANNEL_1 2
#define DATA_PIN_CHANNEL_2 3

CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_PRO, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolSerial cLPS(&cLP);

Expand Down
6 changes: 4 additions & 2 deletions examples/LS100/LS100.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
CRGB ledsChannel1[135];
CRGB ledsChannel2[54];

CorsairLightingFirmware firmware = corsairLS100Firmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_SMART_LIGHTING_CONTROLLER, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
6 changes: 4 additions & 2 deletions examples/LT100/LT100.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

CRGB ledsChannel1[108];

CorsairLightingFirmware firmware = corsairLT100Firmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_SMART_LIGHTING_TOWERS, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
6 changes: 4 additions & 2 deletions examples/LightingNodeCORE/LightingNodeCORE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

CRGB ledsChannel1[204];

CorsairLightingFirmware firmware = corsairLightingNodeCOREFirmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_CORE, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
6 changes: 4 additions & 2 deletions examples/LightingNodePRO/LightingNodePRO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
CRGB ledsChannel1[96];
CRGB ledsChannel2[96];

CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_PRO, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
6 changes: 4 additions & 2 deletions examples/MultipleFans/MultipleFans.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
CRGB ledsChannel1[96];
CRGB ledsChannel2[96];

CorsairLightingFirmware firmware = corsairLightingNodePROFirmware();
FastLEDController ledController(true);
CorsairLightingFirmwareStorageEEPROM firmwareStorage;
CorsairLightingFirmware firmware(CORSAIR_LIGHTING_NODE_PRO, &firmwareStorage);
FastLEDControllerStorageEEPROM storage;
FastLEDController ledController(&storage);
CorsairLightingProtocolController cLP(&ledController, &firmware);
CorsairLightingProtocolHID cHID(&cLP);

Expand Down
Loading

0 comments on commit ba2f6e8

Please sign in to comment.