-
Notifications
You must be signed in to change notification settings - Fork 63
Add JC2432W328C with CST820 driver #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vvuk
wants to merge
3
commits into
suchmememanyskill:master
Choose a base branch
from
vvuk:jc2432w328c
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #ifndef _CST820_H | ||
| #define _CST820_H | ||
|
|
||
| #ifdef TOUCH_CST820 | ||
|
|
||
| #include <Wire.h> | ||
|
|
||
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <SPI.h> | ||
| #include <TFT_eSPI.h> | ||
| #include "../../conf/global_config.h" | ||
| #include "lvgl.h" | ||
| #include <TFT_eSPI.h> | ||
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also an S3 chip, right?