Skip to content

Commit d9f7590

Browse files
WIP - Added m5stack-fire as compile target
1 parent 8e796ca commit d9f7590

File tree

4 files changed

+66
-30
lines changed

4 files changed

+66
-30
lines changed

platformio.ini

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
description = aquacontrol-v2-esp32-box-lite
33
;https://github.com/espressif/esp-box
44

5+
default_envs = m5stack-fire ;esp32s3box ;m5stack-fire
6+
57
[user]
68
build_flags =
79
-D NTP_POOL=\"nl.pool.ntp.org\"
@@ -15,6 +17,8 @@ build_flags =
1517
;ESP_LOG_VERBOSE 5
1618

1719
[env]
20+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
21+
framework = arduino
1822
build_flags =
1923
-Wall
2024
;-Werror
@@ -24,25 +28,44 @@ build_flags =
2428
-D NUMBER_OF_CHANNELS=5
2529

2630
lib_deps =
27-
;lovyan03/LovyanGFX@^1.1.16
2831
celliesprojects/MoonPhase@^1.0.3
2932
https://github.com/lovyan03/LovyanGFX#develop
3033

34+
upload_speed = 921600
35+
monitor_speed = 115200
36+
monitor_filters = esp32_exception_decoder
37+
3138
[env:esp32s3box]
32-
platform = https://github.com/pioarduino/platform-espressif32/releases/download/51.03.07/platform-espressif32.zip
39+
;https://github.com/espressif/esp-box
3340
board = esp32s3box
34-
framework = arduino
35-
3641
board_build.mcu=esp32s3
3742
board_build.arduino.memory_type = qio_opi
3843

39-
upload_speed = 921600
40-
monitor_speed = 115200
41-
monitor_filters = esp32_exception_decoder
42-
4344
build_flags =
44-
${env.build_flags}
45+
-D LGFX_ESP32_S3_BOX_LITE
46+
-D LEDPIN_0=38
47+
-D LEDPIN_1=39
48+
-D LEDPIN_2=40
49+
-D LEDPIN_3=41
50+
-D LEDPIN_4=42
51+
-D SDCARD_SS=10
4552
${user.build_flags}
53+
${env.build_flags}
4654

47-
lib_deps =
48-
${env.lib_deps}
55+
56+
57+
[env:m5stack-fire]
58+
board = esp32dev ;m5stack-fire
59+
board_build.mcu=esp32
60+
build_flags =
61+
-D LGFX_M5STACK
62+
-D LEDPIN_0=3
63+
-D LEDPIN_1=16
64+
-D LEDPIN_2=17
65+
-D LEDPIN_3=2
66+
-D LEDPIN_4=5
67+
-D SDCARD_SS=4
68+
${user.build_flags}
69+
${env.build_flags}
70+
-D BOARD_HAS_PSRAM
71+
-mfix-esp32-psram-cache-issue

src/dimmerTask.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ static unsigned long long msSinceMidnight()
2323

2424
void dimmerTask(void *parameter)
2525
{
26-
constexpr const uint8_t ledPin[NUMBER_OF_CHANNELS] = {38, 39, 40, 41, 42};
27-
constexpr const float fullMoonLevel[NUMBER_OF_CHANNELS] = {0, 0, 0, 0, 0.06};
26+
static constexpr const uint8_t ledPin[NUMBER_OF_CHANNELS] =
27+
{LEDPIN_0, LEDPIN_1, LEDPIN_2, LEDPIN_3, LEDPIN_4};
28+
static constexpr const float fullMoonLevel[NUMBER_OF_CHANNELS] =
29+
{0, 0, 0, 0, 0.06};
30+
static constexpr const int PWM_BITDEPTH = min(SOC_LEDC_TIMER_BIT_WIDTH, 16);
31+
static constexpr const int LEDC_MAX_VALUE = (1 << PWM_BITDEPTH) - 1;
32+
static constexpr const int freq = 1220;
33+
34+
#ifdef LGFX_M5STACK
35+
static constexpr const int BACKLIGHT_PIN = 32;
36+
if (!ledcChangeFrequency(BACKLIGHT_PIN, freq, PWM_BITDEPTH) ||
37+
!ledcWrite(BACKLIGHT_PIN, LEDC_MAX_VALUE >> 6))
38+
log_w("Could not capture M5Stack backlight");
39+
#endif
2840

29-
const int freq = 1200;
3041
for (int index = 0; index < NUMBER_OF_CHANNELS; index++)
31-
if (!ledcAttachChannel(ledPin[index], freq, SOC_LEDC_TIMER_BIT_WIDTH, index + 2))
42+
if (!ledcAttachChannel(ledPin[index], freq, PWM_BITDEPTH, index + 2))
3243
{
3344
log_e("Error setting ledc pin %i. system halted", index);
3445
while (1)
@@ -80,7 +91,6 @@ void dimmerTask(void *parameter)
8091

8192
currentPercentage[index] = newPercentage < currentMoonLevel ? currentMoonLevel : newPercentage;
8293

83-
constexpr const int LEDC_MAX_VALUE = (1 << SOC_LEDC_TIMER_BIT_WIDTH) - 1;
8494
const int dutyCycle = mapf(currentPercentage[index], 0, 100, 0, LEDC_MAX_VALUE);
8595

8696
if (!ledcWrite(ledPin[index], dutyCycle))
@@ -99,7 +109,7 @@ void dimmerTask(void *parameter)
99109
lastLcdRefresh = millis();
100110
}
101111

102-
constexpr const int MOON_UPDATE_INTERVAL_SECONDS = 1;
112+
constexpr const int MOON_UPDATE_INTERVAL_SECONDS = 5;
103113
static time_t lastMoonUpdate = time(NULL);
104114
if (time(NULL) - lastMoonUpdate >= MOON_UPDATE_INTERVAL_SECONDS)
105115
{
@@ -113,16 +123,16 @@ void dimmerTask(void *parameter)
113123
msg.int1 = moon.angle;
114124
xQueueSend(lcdQueue, &msg, portMAX_DELAY);
115125
}
116-
/*
117-
static int lps = 0;
118-
lps++;
119-
static time_t lastlps = time(NULL);
120-
if (time(NULL) != lastlps)
121-
{
122-
log_i("loops per second: %i", lps);
123-
lastlps++;
124-
lps = 0;
125-
}
126-
*/
126+
/*
127+
static int lps = 0;
128+
lps++;
129+
static time_t lastlps = time(NULL);
130+
if (time(NULL) != lastlps)
131+
{
132+
log_i("loops per second: %i", lps);
133+
lastlps++;
134+
lps = 0;
135+
}
136+
*/
127137
}
128138
}

src/lcdTask.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef _DISPLAY_TASK_
22
#define _DISPLAY_TASK_
33

4-
#define LGFX_ESP32_S3_BOX_LITE
54
#include <LovyanGFX.hpp>
65
#include <LGFX_AUTODETECT.hpp>
76

src/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ void setup(void)
169169
{
170170
Serial.begin(115200);
171171

172+
#ifdef LGFX_M5STACK
173+
pinMode(DAC1, OUTPUT); // prevents high pitched noise on the builtin speaker which is connected to DAC1
174+
#endif
175+
172176
log_i("aquacontrol v2");
173177

174178
if (!lcdQueue)
@@ -187,7 +191,7 @@ void setup(void)
187191
SPI.begin(SCK, MISO, MOSI);
188192
SPI.setHwCs(true);
189193

190-
if (!SD.begin(SS))
194+
if (!SD.begin(SDCARD_SS))
191195
log_w("could not mount SD");
192196
else
193197
{

0 commit comments

Comments
 (0)