Skip to content

Commit

Permalink
Support newer ESP32 chips (e.g. S3)
Browse files Browse the repository at this point in the history
Add support for CDC enabled ESP32 chips like the S3 as well as support
different type of RGB led (e.g. where color order differs from GBR) by
adding a setting option for EOrder.
  • Loading branch information
Abász committed Jun 22, 2024
1 parent e6c0c20 commit 5d8c166
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ src/custom.settings.h
src/profiles/*
!src/profiles/generic.rower-profile.h
!src/profiles/generic.board-profile.h
!src/profiles/lolinS3-mini.board-profile.h
!src/profiles/kayakfirst.rower-profile.h
!src/profiles/kayakfirstBlue.rower-profile.h
!src/profiles/firebeetle.board-profile.h
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
void setup()
{
Serial.begin(static_cast<int>(Configurations::baudRate));

#if ARDUINO_USB_CDC_ON_BOOT != 1
while (!Serial && !(bool)Serial.available())
{
}
#endif

Log.begin(static_cast<int>(Configurations::defaultLogLevel), &Serial, false);
Log.setPrefix(printPrefix);
Expand Down
2 changes: 1 addition & 1 deletion src/peripherals/peripherals.controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void PeripheralsController::setupConnectionIndicatorLed()
{
if constexpr (Configurations::isRgb)
{
FastLED.addLeds<WS2812, static_cast<unsigned char>(Configurations::ledPin), GRB>(leds.data(), 1);
FastLED.addLeds<WS2812, static_cast<unsigned char>(Configurations::ledPin), Configurations::ledColorChannelOrder>(leds.data(), 1);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/profiles/firebeetle.board-profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define LED_BLINK_FREQUENCY 1'000
#define LED_PIN GPIO_NUM_5 // Use GPIO_NUM_NC if no led is available
#define IS_RGB true
#define RGB_LED_COLOR_CHANNEL_ORDER GRB

// Hardware settings
#define SENSOR_PIN_NUMBER GPIO_NUM_15
Expand Down
33 changes: 33 additions & 0 deletions src/profiles/lolinS3-mini.board-profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "../utils/enums.h"

// NOLINTBEGIN(cppcoreguidelines-macro-usage)

// General settings
#define BAUD_RATE BaudRates::Baud1500000
#define BLE_SIGNAL_STRENGTH BleSignalStrength::MaxPower
#define SUPPORT_SD_CARD_LOGGING false

// LED settings
#define LED_BLINK_FREQUENCY 1'000
#define LED_PIN GPIO_NUM_47 // Use GPIO_NUM_NC if no led is available
#define IS_RGB true

// Hardware settings
#define SENSOR_PIN_NUMBER GPIO_NUM_16
#define SENSOR_ON_SWITCH_PIN_NUMBER GPIO_NUM_NC // Use GPIO_NUM_NC if no sensor switch is available
#define WAKEUP_SENSOR_PIN_NUMBER GPIO_NUM_NC // Use GPIO_NUM_NC if no separate wakeup pin is available
#define SD_CARD_CHIP_SELECT_PIN GPIO_NUM_NC

// Device power management settings
#define BATTERY_PIN_NUMBER GPIO_NUM_NC
#define VOLTAGE_DIVIDER_RATIO 2
#define BATTERY_VOLTAGE_MIN 3.3
#define BATTERY_VOLTAGE_MAX 4.00
#define BATTERY_LEVEL_ARRAY_LENGTH 5
#define INITIAL_BATTERY_LEVEL_MEASUREMENT_COUNT 10
#define BATTERY_MEASUREMENT_FREQUENCY 10
#define DEEP_SLEEP_TIMEOUT 4

// NOLINTEND(cppcoreguidelines-macro-usage)
6 changes: 6 additions & 0 deletions src/utils/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>

#include "Arduino.h"
#include "FastLED.h"

#include "./macros.h"

Expand Down Expand Up @@ -31,14 +32,19 @@ class Configurations

// Hardware settings
static const BaudRates baudRate = BAUD_RATE;

static const gpio_num_t sdCardChipSelectPin = SD_CARD_CHIP_SELECT_PIN;
static const gpio_num_t sensorPinNumber = SENSOR_PIN_NUMBER;
static const gpio_num_t wakeupPinNumber = WAKEUP_SENSOR_PIN_NUMBER;
static const bool hasWakeupPinNumber = wakeupPinNumber != GPIO_NUM_NC;
static const gpio_num_t sensorOnSwitchPinNumber = SENSOR_ON_SWITCH_PIN_NUMBER;
static const bool hasSensorOnSwitchPinNumber = sensorOnSwitchPinNumber != GPIO_NUM_NC;

static const gpio_num_t ledPin = static_cast<gpio_num_t>(LED_PIN);
static const bool isRgb = ledPin == GPIO_NUM_NC ? false : IS_RGB;
static const bool rgbLed = ledPin == GPIO_NUM_NC ? false : IS_RGB;
static const EOrder ledColorChannelOrder = RGB_LED_COLOR_CHANNEL_ORDER;

static const unsigned char impulsesPerRevolution = IMPULSES_PER_REVOLUTION;
static constexpr float flywheelInertia = FLYWHEEL_INERTIA;
static const unsigned short ledBlinkFrequency = LED_BLINK_FREQUENCY;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ constexpr unsigned int compileDateDay = (__DATE__[4] == ' ') ? (__DATE__[5] - '0
#endif
#endif

#if !defined(RGB_LED_COLOR_CHANNEL_ORDER)
#define RGB_LED_COLOR_CHANNEL_ORDER RGB
#endif

#if !defined(BATTERY_PIN_NUMBER)
#define BATTERY_PIN_NUMBER GPIO_NUM_NC
#endif
Expand Down
15 changes: 15 additions & 0 deletions test/FastLED.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

/// RGB color channel orderings, used when instantiating controllers to determine
/// what order the controller should send data out in. The default ordering
/// is RGB.
/// Within this enum, the red channel is 0, the green channel is 1, and the
/// blue chanel is 2.
enum EOrder
{
RGB = 0012, ///< Red, Green, Blue (0012)
RBG = 0021, ///< Red, Blue, Green (0021)
GRB = 0102, ///< Green, Red, Blue (0102)
GBR = 0120, ///< Green, Blue, Red (0120)
BRG = 0201, ///< Blue, Red, Green (0201)
BGR = 0210 ///< Blue, Green, Red (0210)
};

0 comments on commit 5d8c166

Please sign in to comment.