Skip to content

Commit

Permalink
feat : add esp32 s3 wroom 1 with rgb led
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio authored and Julio MATARRANZ committed Nov 29, 2023
1 parent af07816 commit 3ebba3e
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 3 deletions.
31 changes: 30 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,37 @@

[platformio]
globallib_dir = lib
default_envs = NerminerV2 ; esp32cam, ESP32-2432S028R, NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R, M5-StampS3
default_envs = NerminerV2 ; esp32cam, ESP32-2432S028R, NerminerV2, ESP32-devKitv1, NerminerV2-S3-DONGLE, NerminerV2-S3-AMOLED, NerminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R, M5-StampS3, ESP32-S3-devKitv1

[env:ESP32-S3-devKitv1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
monitor_filters =
esp32_exception_decoder
time
log2file
board_build.arduino.memory_type = qio_opi
monitor_speed = 115200
upload_speed = 115200
board_build.partitions = huge_app.csv
build_flags =
-D BOARD_HAS_PSRAM
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
-D DEVKITV1RGB=1
;-D DEBUG_MINING=1
lib_deps =
https://github.com/takkaO/OpenFontRender
bblanchon/ArduinoJson@^6.21.2
https://github.com/tzapu/WiFiManager.git#v2.0.16-rc.2
mathertel/OneButton @ ^2.0.3
arduino-libraries/NTPClient
https://github.com/FastLED/FastLED
lib_ignore =
TFT_eSPI

;--------------------------------------------------------------------


[env:NerminerV2]
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/devices/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "esp32CAM.h"
#elif defined(M5_STAMP_S3)
#include "m5StampS3.h"
#elif defined(DEVKITV1RGB)
#include "esp32DevKitRGB.h"

#else
#error "No device defined"
Expand Down
10 changes: 10 additions & 0 deletions src/drivers/devices/esp32DevKitRGB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _ESP32_DEV_KIT_RGB_H
#define _ESP32_DEV_KIT_RGB_H

#define PIN_BUTTON_1 0
#define RGB_LED_PIN 48

#define LED_DISPLAY
#define USE_LED

#endif
4 changes: 4 additions & 0 deletions src/drivers/displays/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
DisplayDriver *currentDisplayDriver = &noDisplayDriver;
#endif

#ifdef LED_DISPLAY
DisplayDriver *currentDisplayDriver = &ledDisplayDriver;
#endif

#ifdef T_DISPLAY
DisplayDriver *currentDisplayDriver = &tDisplayDriver;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/drivers/displays/displayDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef struct
extern DisplayDriver *currentDisplayDriver;

extern DisplayDriver noDisplayDriver;
extern DisplayDriver ledDisplayDriver;
extern DisplayDriver tDisplayDriver;
extern DisplayDriver amoledDisplayDriver;
extern DisplayDriver dongleDisplayDriver;
Expand Down
138 changes: 138 additions & 0 deletions src/drivers/displays/ledDisplayDriver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "displayDriver.h"

#ifdef LED_DISPLAY

#include <Arduino.h>
#include "monitor.h"
#include "wManager.h"

#ifdef USE_LED
#include <FastLED.h>
#endif

#ifdef USE_LED
#define MAX_BRIGHTNESS 16
#define SLOW_FADE 1;
#define FAST_FADE 4;

CRGB leds(0, 0, 0);
int brightness = 0;
int fadeDirection = 1;
int fadeAmount = 0;
#endif // USE_LED

bool ledOn = false;
extern monitor_data mMonitor;

void ledDisplay_Init(void)
{
Serial.println("Led display driver initialized");
#ifdef USE_LED
FastLED.addLeds<WS2812B, RGB_LED_PIN, BGR>(&leds, 1);
FastLED.show();
#endif // USE_LED
}

void ledDisplay_AlternateScreenState(void)
{
Serial.println("Switching display state");
ledOn = !ledOn;
}

void ledDisplay_AlternateRotation(void)
{
}

void ledDisplay_NoScreen(unsigned long mElapsed)
{
mining_data data = getMiningData(mElapsed);

// Print hashrate to serial
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());

// Print extended data to serial for no display devices
Serial.printf(">>> Valid blocks: %s\n", data.valids.c_str());
Serial.printf(">>> Block templates: %s\n", data.templates.c_str());
Serial.printf(">>> Best difficulty: %s\n", data.bestDiff.c_str());
Serial.printf(">>> 32Bit shares: %s\n", data.completedShares.c_str());
Serial.printf(">>> Temperature: %s\n", data.temp.c_str());
Serial.printf(">>> Total MHashes: %s\n", data.totalMHashes.c_str());
Serial.printf(">>> Time mining: %s\n", data.timeMining.c_str());
}
void ledDisplay_LoadingScreen(void)
{
Serial.println("Initializing...");
}

void ledDisplay_SetupScreen(void)
{
Serial.println("Setup...");
}

// Variables para controlar el parpadeo con millis()
unsigned long previousMillis = 0;

void ledDisplay_DoLedStuff(unsigned long frame)
{

#ifdef USE_LED

if (!ledOn)
{
FastLED.clear(true);
return;
}

switch (mMonitor.NerdStatus)
{
case NM_waitingConfig:
brightness = MAX_BRIGHTNESS;
leds.setRGB(255, 255, 0);
fadeAmount = 0;
break;

case NM_Connecting:
leds.setRGB(0, 0, 255);
fadeAmount = SLOW_FADE;
break;

case NM_hashing:
leds.setRGB(0, 0, 255);
fadeAmount = FAST_FADE;
break;
}

leds.fadeLightBy(0xFF - brightness);
FastLED.show();

brightness = brightness + (fadeDirection * fadeAmount);
if (brightness <= 0 || brightness >= MAX_BRIGHTNESS)
{
fadeDirection = -fadeDirection;
}
brightness = constrain(brightness, 0, MAX_BRIGHTNESS);
#endif
}

void ledDisplay_AnimateCurrentScreen(unsigned long frame)
{
}

CyclicScreenFunction ledDisplayCyclicScreens[] = {ledDisplay_NoScreen};

DisplayDriver ledDisplayDriver = {
ledDisplay_Init,
ledDisplay_AlternateScreenState,
ledDisplay_AlternateRotation,
ledDisplay_LoadingScreen,
ledDisplay_SetupScreen,
ledDisplayCyclicScreens,
ledDisplay_AnimateCurrentScreen,
ledDisplay_DoLedStuff,
SCREENS_ARRAY_SIZE(ledDisplayCyclicScreens),
0,
0,
0,
};
#endif
4 changes: 2 additions & 2 deletions src/drivers/storage/SDCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <SD.h>
#include "..\lib\TFT_eSPI\User_Setup_Select.h"

#ifndef NO_DISPLAY
#if !defined(NO_DISPLAY) && !defined(LED_DISPLAY)
#if !defined(SDSPI_CLK) && defined(TFT_CLK)
#define SDSPI_CLK TFT_CLK
#endif // SDSPI_CLK
Expand All @@ -41,7 +41,7 @@
#endif // SDSPI_MISO
#elif !defined(SDSPI_CLK) || !defined(SDSPI_MOSI) || !defined(SDSPI_MISO)
#error: Please define SDSPI pins!
#endif // NO_DISPLAY
#endif // NO_DISPLAY or LED_DISPLAY

#warning SD card support in SPI mode enabled!
#endif
Expand Down

0 comments on commit 3ebba3e

Please sign in to comment.