Skip to content

Commit

Permalink
v4.1.0
Browse files Browse the repository at this point in the history
- add tones for buzzer
- add rtc 8563 for Elecrow C3
- fix #11 compile error
- add face selector
  • Loading branch information
fbiego committed Aug 28, 2024
1 parent e521305 commit 1a765d6
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"75_2_dial.h": "c",
"radar.h": "c",
"79_2_dial.h": "c",
"racing.h": "c"
"racing.h": "c",
"chrono": "cpp"
}
}
126 changes: 120 additions & 6 deletions hal/esp32/app_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include <Wire.h>
#include "app_hal.h"

#include "tone.h"

#include <lvgl.h>
#include "ui/ui.h"

Expand All @@ -59,6 +61,11 @@
#define QMI8658C_I2C_FREQUENCY 40000 // Define I2C frequency as 80kHz (in Hz)
#endif

#ifdef ENABLE_RTC
#include <RtcPCF8563.h>
RtcPCF8563<TwoWire> Rtc(Wire);
#endif

#define FLASH FFat
#define F_NAME "FATFS"
#define buf_size 10
Expand Down Expand Up @@ -355,6 +362,71 @@ void set_pin_io(uint8_t pin_number, bool value)
}
#endif

#ifdef ENABLE_RTC
bool wasError(const char *errorTopic = "")
{
uint8_t error = Rtc.LastError();
if (error != 0)
{
// we have a communications error
// see https://www.arduino.cc/reference/en/language/functions/communication/wire/endtransmission/
// for what the number means
Serial.print("[");
Serial.print(errorTopic);
Serial.print("] WIRE communications error (");
Serial.print(error);
Serial.print(") : ");

switch (error)
{
case Rtc_Wire_Error_None:
Serial.println("(none?!)");
break;
case Rtc_Wire_Error_TxBufferOverflow:
Serial.println("transmit buffer overflow");
break;
case Rtc_Wire_Error_NoAddressableDevice:
Serial.println("no device responded");
break;
case Rtc_Wire_Error_UnsupportedRequest:
Serial.println("device doesn't support request");
break;
case Rtc_Wire_Error_Unspecific:
Serial.println("unspecified error");
break;
case Rtc_Wire_Error_CommunicationTimeout:
Serial.println("communications timed out");
break;
}
return true;
}
return false;
}
#endif


void toneOut(int pitch, int duration)
{ // pitch in Hz, duration in ms
#if defined(BUZZER) && (BUZZER != -1)
int delayPeriod;
long cycles, i;

pinMode(BUZZER, OUTPUT); // turn on output pin
delayPeriod = (500000 / pitch) - 7; // calc 1/2 period in us -7 for overhead
cycles = ((long)pitch * (long)duration) / 1000; // calc. number of cycles for loop

for (i = 0; i <= cycles; i++)
{ // play note for duration ms
digitalWrite(BUZZER, HIGH);
delayMicroseconds(delayPeriod);
digitalWrite(BUZZER, LOW);
delayMicroseconds(delayPeriod - 1); // - 1 to make up for digitaWrite overhead
}
pinMode(BUZZER, INPUT); // shut off pin to avoid noise from other operations
#endif
}


String heapUsage()
{
String usage;
Expand Down Expand Up @@ -504,6 +576,14 @@ void checkLocal()
}
}

void screenBrightness(uint8_t value)
{
tft.setBrightness(value);
#ifdef ELECROW_C3
set_pin_io(2, value > 0); // ELECROW C3, no brightness control
#endif
}

String readFile(const char *path)
{
String result;
Expand Down Expand Up @@ -897,6 +977,14 @@ void configCallback(Config config, uint32_t a, uint32_t b)
{
switch (config)
{
case CF_TIME:
// time has been synced from BLE
#ifdef ENABLE_RTC
// set the RTC time
Rtc.SetDateTime(RtcDateTime(watch.getYear(), watch.getMonth() + 1, watch.getDay(), watch.getHour(true), watch.getMinute(), watch.getSecond()));

#endif
break;
case CF_RST:

Serial.println("Reset request, formating storage");
Expand Down Expand Up @@ -1104,7 +1192,7 @@ void onBrightnessChange(lv_event_t *e)
// Your code here
lv_obj_t *slider = lv_event_get_target(e);
int v = lv_slider_get_value(slider);
tft.setBrightness(v);
screenBrightness(v);

prefs.putInt("brightness", v);
}
Expand Down Expand Up @@ -1422,7 +1510,7 @@ void loadSplash()
int xOffset = 63;
int yOffset = 55;
tft.fillScreen(TFT_BLACK);
tft.setBrightness(200);
screenBrightness(200);
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
Expand Down Expand Up @@ -1460,6 +1548,10 @@ void hal_setup()
tft.fillScreen(TFT_BLACK);
loadSplash();

toneOut(TONE_EN * 2, 170);
toneOut(TONE_FS * 2, 170);
toneOut(TONE_GN * 2, 170);

Serial.println(heapUsage());

lv_init();
Expand Down Expand Up @@ -1566,7 +1658,7 @@ void hal_setup()
tm = 0;
}

tft.setBrightness(br);
screenBrightness(br);

lv_dropdown_set_selected(ui_timeoutSelect, tm);
lv_slider_set_value(ui_brightnessSlider, br, LV_ANIM_OFF);
Expand Down Expand Up @@ -1615,6 +1707,28 @@ void hal_setup()

#endif

#ifdef ENABLE_RTC
Rtc.Begin();

if (!Rtc.GetIsRunning())
{
uint8_t error = Rtc.LastError();
if (error != 0)
{
showError("RTC", "Error on RTC");
}
Rtc.SetIsRunning(true);
}

RtcDateTime now = Rtc.GetDateTime();

watch.setTime(now.Second(), now.Minute(), now.Hour(), now.Day(), now.Month(), now.Year());

Rtc.StopAlarm();
Rtc.StopTimer();
Rtc.SetSquareWavePin(PCF8563SquareWavePinMode_None);
#endif

Timber.i("Setup done");
Timber.i(about);
}
Expand Down Expand Up @@ -1685,7 +1799,7 @@ void hal_loop()
if (screenTimer.active)
{
uint8_t lvl = lv_slider_get_value(ui_brightnessSlider);
tft.setBrightness(lvl);
screenBrightness(lvl);

if (screenTimer.duration < 0)
{
Expand All @@ -1701,7 +1815,7 @@ void hal_loop()
Timber.w("Screen timeout");
screenTimer.active = false;

tft.setBrightness(0);
screenBrightness(0);
lv_disp_load_scr(ui_home);
}
}
Expand All @@ -1712,7 +1826,7 @@ void hal_loop()
{
if (start)
{
tft.setBrightness(200);
screenBrightness(200);
tft.fillScreen(TFT_BLUE);

tft.drawRoundRect(70, 120, 100, 20, 5, TFT_WHITE);
Expand Down
5 changes: 4 additions & 1 deletion hal/esp32/app_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// 240x240 watchfaces

#define ENABLE_FACE_34_2_DIAL // (Shadow)
// #define ENABLE_FACE_75_2_DIAL // (Analog)
#define ENABLE_FACE_75_2_DIAL // (Analog)
// #define ENABLE_FACE_79_2_DIAL // (Blue)
// #define ENABLE_FACE_116_2_DIAL // (Outline)
#define ENABLE_FACE_756_2_DIAL // (Red)
Expand All @@ -38,6 +38,9 @@
#define ENABLE_APP_QMI8658C
#endif

#if defined(ELECROW_C3)
#define ENABLE_RTC
#endif

// #define ENABLE_GAME_RACING

Expand Down
29 changes: 29 additions & 0 deletions hal/esp32/tone.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


#ifndef TONE_H
#define TONE_H

#define TONE_AN 220 // 440 Hz
#define TONE_AS 233 // 466 Hz
#define TONE_BN 247 // 493 Hz
#define TONE_CN 261 // 523 Hz
#define TONE_CS 277 // 554 Hz
#define TONE_DN 294 // 588 Hz
#define TONE_DS 311 // 622 Hz
#define TONE_EN 330 // 658 Hz
#define TONE_FN 349 // 698 Hz
#define TONE_FS 370 // 740 Hz
#define TONE_GN 392 // 784 Hz
#define TONE_GS 415 // 830 Hz
// defines for the duration of the notes (in ms)
// #define WH 1024
// #define H1 100
// #define DQ 448
// #define Q 256
// #define qt 170
// #define de 192
// #define e 128
// #define et 85


#endif
10 changes: 10 additions & 0 deletions include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

#define BL -1 // unused (connected on IO extender)

#define BUZZER 3

#define MAX_FILE_OPEN 10

#elif ESPC3
Expand Down Expand Up @@ -88,6 +90,8 @@

#define BL 3

#define BUZZER -1

#define MAX_FILE_OPEN 10

#elif ESPS3_1_28
Expand Down Expand Up @@ -117,6 +121,8 @@

#define BL 2

#define BUZZER -1

#define MAX_FILE_OPEN 50

#elif ESPS3_1_69
Expand Down Expand Up @@ -146,6 +152,8 @@

#define BL 15

#define BUZZER 33

#define MAX_FILE_OPEN 20

#define CS_CONFIG CS_240x296_191_RTF
Expand Down Expand Up @@ -177,6 +185,8 @@

#define BL 2

#define BUZZER -1

#define MAX_FILE_OPEN 10

#endif
9 changes: 5 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ framework = arduino
board_build.partitions = partitions.csv ;noota_ffat.csv
lib_deps =
${esp32.lib_deps}
makuna/RTC@^2.4.3
build_flags =
${esp32.build_flags}
-D ELECROW_C3=1
Expand All @@ -132,7 +133,7 @@ lib_deps =
build_flags =
${esp32.build_flags}
-D ESPC3=1
-D LV_MEM_SIZE=(120U*1024U)
-D LV_MEM_SIZE=120U*1024U
-D LV_USE_QRCODE=1
; -D NO_WATCHFACES
-D ENABLE_CUSTOM_FACE=1
Expand All @@ -155,7 +156,7 @@ lib_deps =
build_flags =
${esp32.build_flags}
-D ESPS3_1_28=1
-D LV_MEM_SIZE=(120U*1024U)
-D LV_MEM_SIZE=120U*1024U
-D ENABLE_CUSTOM_FACE=1
-D LV_USE_QRCODE=1
build_src_filter =
Expand All @@ -178,7 +179,7 @@ lib_deps =
build_flags =
${esp32.build_flags}
-D ESPS3_1_69=1
-D LV_MEM_SIZE=(120U*1024U)
-D LV_MEM_SIZE=120U*1024U
; -D ENABLE_CUSTOM_FACE=1 ; custom watchface crashes firmware, disable it
-D LV_USE_QRCODE=1
build_src_filter =
Expand All @@ -193,7 +194,7 @@ lib_deps =
${esp32.lib_deps}
build_flags =
${esp32.build_flags}
-D LV_MEM_SIZE=(60U*1024U)
-D LV_MEM_SIZE=60U*1024U
-D LV_MEM_ADR=0
; -D NO_WATCHFACES
build_src_filter =
Expand Down
Loading

0 comments on commit 1a765d6

Please sign in to comment.