diff --git a/CYD-Klipper/boards/esp32-JC2432W328C.json b/CYD-Klipper/boards/esp32-JC2432W328C.json new file mode 100644 index 0000000..f3dd7d1 --- /dev/null +++ b/CYD-Klipper/boards/esp32-JC2432W328C.json @@ -0,0 +1,86 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DUSER_SETUP_LOADED=1", + "-DILI9341_2_DRIVER=1", + "-DTFT_BACKLIGHT_ON=HIGH", + "-DTFT_BL=27", + "-DTFT_MISO=12", + "-DTFT_MOSI=13", + "-DTFT_SCLK=14", + "-DTFT_CS=15", + "-DTFT_DC=2", + "-DTFT_RST=-1", + "-DLOAD_GCLD=1", + "-DSPI_FREQUENCY=15999999", + "-DSPI_READ_FREQUENCY=20000000", + + "-DCYD_SCREEN_HEIGHT_PX=240", + "-DCYD_SCREEN_WIDTH_PX=320", + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_JC2432W328C=1", + + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1", + "-DCYD_SCREEN_DISABLE_INVERT_COLORS=1", + + "-DTOUCH_CST820=1", + "'-D TOUCH_SWAP_XY=true'", + "'-D TOUCH_SWAP_X=false'", + "'-D TOUCH_SWAP_Y=true'", + + "'-D BOARD_HAS_TF'", + "'-D TF_CS=5'", + "'-D TF_SPI_MOSI=23'", + "'-D TF_SPI_SCLK=18'", + "'-D TF_SPI_MISO=19'", + + "'-D BOARD_HAS_RGB_LED'", + "'-D RGB_LED_R=4'", + "'-D RGB_LED_G=16'", + "'-D RGB_LED_B=17'", + + "'-D BOARD_HAS_CDS'", + "'-D CDS=34'", + + "'-D BOARD_HAS_SPEAK'", + "'-D SPEAK=26'" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-jc2432w28c", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.us/item/3256806543392861.html", + "vendor": "Guition" + } diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index ee36d08..ca615b9 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -117,3 +117,15 @@ lib_deps = knolleary/PubSubClient@^2.8 WiFiClientSecure +[env:esp32-JC2432W3-28C] +board = esp32-JC2432W328C +lib_deps = + SPI + https://github.com/suchmememanyskill/lvgl + https://github.com/Bodmer/TFT_eSPI.git + bblanchon/ArduinoJson@^7.0.0 + plageoj/UrlEncode@^1.0.1 + knolleary/PubSubClient@^2.8 + WiFiClientSecure + + diff --git a/CYD-Klipper/src/core/device/CST820.cpp b/CYD-Klipper/src/core/device/CST820.cpp new file mode 100644 index 0000000..e96939a --- /dev/null +++ b/CYD-Klipper/src/core/device/CST820.cpp @@ -0,0 +1,103 @@ +#ifdef TOUCH_CST820 + +#include "CST820.h" + +CST820::CST820(int8_t sda_pin, int8_t scl_pin, int8_t rst_pin, int8_t int_pin) { + _sda = sda_pin; + _scl = scl_pin; + _rst = rst_pin; + _int = int_pin; +} + +void CST820::begin(void) { + if (_sda != -1 && _scl != -1) { + Wire.begin(_sda, _scl); + } else { + Wire.begin(); + } + + if (_int != -1) { + pinMode(_int, OUTPUT); + digitalWrite(_int, HIGH); + delay(1); + digitalWrite(_int, LOW); + delay(1); + } + + if (_rst != -1) { + pinMode(_rst, OUTPUT); + digitalWrite(_rst, LOW); + delay(10); + digitalWrite(_rst, HIGH); + delay(300); + } + + // Final init + i2c_write(0xFE, 0XFF); +} + +bool CST820::getTouch(uint16_t *x, uint16_t *y, uint8_t *gesture) { + bool finger = false; + finger = (bool)i2c_read(0x02); + + *gesture = i2c_read(0x01); + if (!(*gesture == SlideUp || *gesture == SlideDown)) { + *gesture = None; + } + + uint8_t data[4]; + i2c_read_continuous(0x03, data, 4); + *x = ((data[0] & 0x0f) << 8) | data[1]; + *y = ((data[2] & 0x0f) << 8) | data[3]; + + return finger; +} + +uint8_t CST820::i2c_read(uint8_t addr) { + uint8_t rdData; + uint8_t rdDataCount; + do { + Wire.beginTransmission(I2C_ADDR_CST820); + Wire.write(addr); + Wire.endTransmission(false); // Restart + rdDataCount = Wire.requestFrom(I2C_ADDR_CST820, 1); + } while (rdDataCount == 0); + while (Wire.available()) { + rdData = Wire.read(); + } + return rdData; +} + +uint8_t CST820::i2c_read_continuous(uint8_t addr, uint8_t *data, + uint32_t length) { + Wire.beginTransmission(I2C_ADDR_CST820); + Wire.write(addr); + if (Wire.endTransmission(true)) + return -1; + Wire.requestFrom(I2C_ADDR_CST820, length); + for (int i = 0; i < length; i++) { + *data++ = Wire.read(); + } + return 0; +} + +void CST820::i2c_write(uint8_t addr, uint8_t data) { + Wire.beginTransmission(I2C_ADDR_CST820); + Wire.write(addr); + Wire.write(data); + Wire.endTransmission(); +} + +uint8_t CST820::i2c_write_continuous(uint8_t addr, const uint8_t *data, + uint32_t length) { + Wire.beginTransmission(I2C_ADDR_CST820); + Wire.write(addr); + for (int i = 0; i < length; i++) { + Wire.write(*data++); + } + if (Wire.endTransmission(true)) + return -1; + return 0; +} + +#endif \ No newline at end of file diff --git a/CYD-Klipper/src/core/device/CST820.h b/CYD-Klipper/src/core/device/CST820.h new file mode 100644 index 0000000..26ce1eb --- /dev/null +++ b/CYD-Klipper/src/core/device/CST820.h @@ -0,0 +1,40 @@ +#ifndef _CST820_H +#define _CST820_H + +#ifdef TOUCH_CST820 + +#include + +#define I2C_ADDR_CST820 0x15 + +enum GESTURE { + None = 0x00, + SlideDown = 0x01, + SlideUp = 0x02, + SlideLeft = 0x03, + SlideRight = 0x04, + SingleTap = 0x05, + DoubleTap = 0x0B, + LongPress = 0x0C +}; + +class CST820 { +public: + CST820(int8_t sda_pin = -1, int8_t scl_pin = -1, int8_t rst_pin = -1, + int8_t int_pin = -1); + + void begin(void); + bool getTouch(uint16_t *x, uint16_t *y, uint8_t *gesture); + +private: + int8_t _sda, _scl, _rst, _int; + + uint8_t i2c_read(uint8_t addr); + uint8_t i2c_read_continuous(uint8_t addr, uint8_t *data, uint32_t length); + void i2c_write(uint8_t addr, uint8_t data); + uint8_t i2c_write_continuous(uint8_t addr, const uint8_t *data, + uint32_t length); +}; +#endif + +#endif \ No newline at end of file diff --git a/CYD-Klipper/src/core/device/ESP32-JC2432W328C.cpp b/CYD-Klipper/src/core/device/ESP32-JC2432W328C.cpp new file mode 100644 index 0000000..195b2a5 --- /dev/null +++ b/CYD-Klipper/src/core/device/ESP32-JC2432W328C.cpp @@ -0,0 +1,121 @@ +#ifdef CYD_SCREEN_DRIVER_ESP32_JC2432W328C +#include "../screen_driver.h" + +#ifdef CYD_SCREEN_VERTICAL + #error "Vertical screen not supported with the ESP32_JC2432W328C driver" +#endif + +#include +#include +#include "../../conf/global_config.h" +#include "lvgl.h" +#include +#include "../lv_setup.h" + +#include "CST820.h" + +#define CPU_FREQ_HIGH 240 + +static lv_disp_draw_buf_t draw_buf; +static lv_color_t buf[CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10]; + +#define TOUCH_I2C_SDA 33 +#define TOUCH_I2C_SCL 32 +#define TOUCH_TP_RST 25 +#define TOUCH_TP_INT 21 + +TFT_eSPI tft = TFT_eSPI(); +CST820 touch(TOUCH_I2C_SDA, TOUCH_I2C_SCL, TOUCH_TP_RST, TOUCH_TP_INT); + +void screen_setBrightness(byte brightness) +{ + // calculate duty, 4095 from 2 ^ 12 - 1 + uint32_t duty = (4095 / 255) * brightness; + + // write duty to LEDC + ledcWrite(0, duty); +} + +void screen_lv_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) +{ + uint32_t w = (area->x2 - area->x1 + 1); + uint32_t h = (area->y2 - area->y1 + 1); + + tft.startWrite(); + tft.setAddrWindow(area->x1, area->y1, w, h); + tft.pushColors((uint16_t *)&color_p->full, w * h, true); + tft.endWrite(); + + lv_disp_flush_ready(disp); +} + +void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) +{ + bool touched; + uint8_t gesture; + uint16_t touchX, touchY, tmp; + + #if TOUCH_SWAP_XY + touched = touch.getTouch(&touchY, &touchX, &gesture); + #else + touched = touch.getTouch(&touchX, &touchY, &gesture); + #endif + + if (!touched) + { + data->state = LV_INDEV_STATE_REL; + return; + } + data->state = LV_INDEV_STATE_PR; + + #if TOUCH_SWAP_X + touchX = CYD_SCREEN_WIDTH_PX - touchX; + #endif + #if TOUCH_SWAP_Y + touchY = CYD_SCREEN_HEIGHT_PX - touchY; + #endif + + data->point.x = touchX; + data->point.y = touchY; +} + +void set_invert_display(){ + tft.invertDisplay(global_config.printer_config[global_config.printer_index].invert_colors); +} + +void screen_setup() +{ + lv_init(); + + tft.init(); + tft.fillScreen(TFT_BLACK); + tft.invertDisplay(false); + delay(300); + + tft.setRotation(1); + + ledcSetup(0, 5000, 12); + ledcAttachPin(TFT_BL, 0); + + touch.begin(); + + lv_disp_draw_buf_init(&draw_buf, buf, NULL, CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10); + + /*Initialize the display*/ + static lv_disp_drv_t disp_drv; + lv_disp_drv_init(&disp_drv); + disp_drv.hor_res = CYD_SCREEN_WIDTH_PX; + disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX; + disp_drv.flush_cb = screen_lv_flush; + disp_drv.draw_buf = &draw_buf; + lv_disp_drv_register(&disp_drv); + + /*Initialize the (dummy) input device driver*/ + static lv_indev_drv_t indev_drv; + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = screen_lv_touchRead; + lv_indev_drv_register(&indev_drv); +} + +#endif // CYD_SCREEN_DRIVER_ESP32_JC2432W328C \ No newline at end of file diff --git a/_site/index.html b/_site/index.html index b3766a9..6666f4d 100644 --- a/_site/index.html +++ b/_site/index.html @@ -141,6 +141,7 @@

Install

+ diff --git a/ci.py b/ci.py index 2aa9040..b064e00 100644 --- a/ci.py +++ b/ci.py @@ -12,6 +12,7 @@ #"esp32-4827S043R-SD", "esp32-CROWPANEL-28R", "esp32-CROWPANEL-35C", + "esp32-JC2432W328C" ] ESP_S3_CHIPS = [