diff --git a/variants/m5stack_coreink/Speaker.cpp b/variants/m5stack_coreink/Speaker.cpp new file mode 100644 index 000000000..0aaff1238 --- /dev/null +++ b/variants/m5stack_coreink/Speaker.cpp @@ -0,0 +1,33 @@ +#include "Speaker.h" + +TONE::TONE(void) { + _volume = 5; + _begun = false; +} + +void TONE::begin() { + _begun = true; + ledcSetup(TONE_PIN_CHANNEL, 0, 13); + ledcAttachPin(PIN_BUZZER, TONE_PIN_CHANNEL); +} + +void TONE::end() { + mute(); + ledcDetachPin(PIN_BUZZER); + _begun = false; +} + +void TONE::tone(uint16_t frequency) { + if(!_begun) begin(); + ledcWriteTone(TONE_PIN_CHANNEL, frequency); + ledcWrite(TONE_PIN_CHANNEL, 0x400 >> _volume); +} + +void TONE::setVolume(uint8_t volume) { + _volume = 11 - volume; +} + +void TONE::mute() { + ledcWriteTone(TONE_PIN_CHANNEL, 0); + digitalWrite(PIN_BUZZER, 0); +} \ No newline at end of file diff --git a/variants/m5stack_coreink/Speaker.h b/variants/m5stack_coreink/Speaker.h new file mode 100644 index 000000000..2ab877d9b --- /dev/null +++ b/variants/m5stack_coreink/Speaker.h @@ -0,0 +1,30 @@ +#ifndef _SPEAKER_H_ + #define _SPEAKER_H_ + + #include "configuration.h" + + #ifdef __cplusplus + extern "C" + { + #endif /* __cplusplus */ + #include "esp32-hal-dac.h" + #ifdef __cplusplus + } + #endif /* __cplusplus */ + + class TONE { + public: + TONE(void); + + void begin(); + void end(); + void mute(); + void tone(uint16_t frequency); + void setVolume(uint8_t volume); + + private: + uint8_t _volume; + bool _begun; + bool speaker_on; + }; +#endif diff --git a/variants/m5stack_coreink/platformio.ini b/variants/m5stack_coreink/platformio.ini index c33187da0..796b58e67 100644 --- a/variants/m5stack_coreink/platformio.ini +++ b/variants/m5stack_coreink/platformio.ini @@ -1,18 +1,26 @@ [env:m5stack-coreink] extends = esp32_base board = m5stack-coreink +build_src_filter = + ${esp32_base.build_src_filter} + +<../variants/m5stack_coreink> build_flags = - ${esp32_base.build_flags} -D M5_COREINK -I variants/m5stack_coreink + ${esp32_base.build_flags} -I variants/m5stack_coreink ;-D RADIOLIB_VERBOSE -Ofast -D__MCUXPRESSO -DEPD_HEIGHT=200 -DEPD_WIDTH=200 + -DUSER_SETUP_LOADED + -DM5_COREINK -DM5STACK lib_deps = ${esp32_base.lib_deps} zinggjm/GxEPD2@^1.4.9 lewisxhe/PCF8563_Library@^1.0.1 +lib_ignore = + m5stack-coreink +monitor_filters = esp32_exception_decoder board_build.f_cpu = 240000000L upload_protocol = esptool -upload_port = /dev/ttyACM* +upload_port = /dev/ttyACM0 diff --git a/variants/m5stack_coreink/variant.h b/variants/m5stack_coreink/variant.h index ef490415c..0676fda1c 100644 --- a/variants/m5stack_coreink/variant.h +++ b/variants/m5stack_coreink/variant.h @@ -1,34 +1,40 @@ -#define I2C_SDA 21 //-1 -#define I2C_SCL 22 //-1 +#define I2C_SDA 21 +#define I2C_SCL 22 -//#define LED_PIN 10 +// LED? +#define LED_INVERTED 0 +#define LED_PIN 10 #include "pcf8563.h" // PCF8563 RTC Module #define PCF8563_RTC 0x51 - -#define BUTTON_NEED_PULLUP -#define BUTTON_PIN 5 +#define HAS_RTC 1 //Wheel // Down 37 // Push 38 // Up 39 - // Top Physical Button 5 +#define BUTTON_NEED_PULLUP +#define BUTTON_PIN 5 + +//BUZZER +#define PIN_BUZZER 2 +#define TONE_PIN_CHANNEL 0 + #undef RF95_SCK #undef RF95_MISO #undef RF95_MOSI #undef RF95_NSS #define USE_RF95 -#define RF95_SCK 18 //13 -#define RF95_MISO 34 //26 -#define RF95_MOSI 23 //25 +#define RF95_SCK 18 +#define RF95_MISO 34 +#define RF95_MOSI 23 #define RF95_NSS 14 -#define LORA_DIO0 25 //32 now moved from ext port -#define LORA_RESET 26 //33 now moved from ext port +#define LORA_DIO0 25 +#define LORA_RESET 26 #define LORA_DIO1 RADIOLIB_NC #define LORA_DIO2 RADIOLIB_NC @@ -39,12 +45,10 @@ #define USE_EINK //https://docs.m5stack.com/en/core/coreink //https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/schematic/Core/coreink/coreink_sch.pdf -#define PIN_EINK_EN -1 -#define PIN_EINK_CS 9 // EPD_CS -#define PIN_EINK_BUSY 4 // EPD_BUSY +#define PIN_EINK_EN -1 // N/C +#define PIN_EINK_CS 9 // EPD_CS +#define PIN_EINK_BUSY 4 // EPD_BUSY #define PIN_EINK_DC 15 // EPD_D/C -#define PIN_EINK_RES -1 // Connected to GPIO0 but no needed !!!! maybe causing issue ? -#define PIN_EINK_SCLK 18 // EPD_SCLK +#define PIN_EINK_RES -1 // Connected but not needed +#define PIN_EINK_SCLK 18 // EPD_SCLK #define PIN_EINK_MOSI 23 // EPD_MOSI - -#define HAS_RTC 1