Git Product home page Git Product logo

cyd28_touchscreen's Introduction

CYD28_Touchscreen

Bit banged XPT2046 SPI library for the CheapYellowDisplay 2.8" version.

The touchscreen interface on the 2.8" version of the CYD is available on completely different pins as both SPI interfaces.
This library is based on the XPT2046 lib written by Paul Stoffregen, but instead of HW SPI it is using a bit banged version leaving the both HSPI and VSPI interfaces for other tasks like handling the SD card or driving the display.

Pinout is fixed in the header file, using the configuration present on the CYD 2.8" board:

#define CYD28_TouchR_IRQ 	36
#define CYD28_TouchR_MOSI 	32
#define CYD28_TouchR_MISO 	39
#define CYD28_TouchR_CLK 	25
#define CYD28_TouchR_CS 	33

PlatformIO

Simply add the library url to the lib_deps in the platformio.ini file:

lib_deps =
	https://github.com/hexeguitar/CYD28_Touchscreen.git

LVGL8.x

Create the touchscreen object + input device driver for the lvgl library:

CYD28_TouchR ts = CYD28_TouchR(CYD28_DISPLAY_HOR_RES, CYD28_DISPLAY_VER_RES);
CYD28_TS_Point oldPoint;
lv_indev_drv_t indev_drv;

Configure it:

lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touch_read;
lv_indev_drv_register(&indev_drv);

Create read callback:

void touch_read(lv_indev_drv_t *drv, lv_indev_data_t *data)
{
    if (dispPtr->ts.touched())
    {
        CYD28_TS_Point p = dispPtr->ts.getPointScaled();
        data->state = LV_INDEV_STATE_PR;
        data->point.x = p.x;
        data->point.y = p.y;
        dispPtr->oldPoint.x = p.x;
        dispPtr->oldPoint.y = p.y;
        //log_i("X = %d, Y = %d", data->point.x, data->point.y);
    }
    else
    {
        data->state = LV_INDEV_STATE_REL;
        data->point.x = dispPtr->oldPoint.x;
        data->point.y = dispPtr->oldPoint.y;
    }
}

(c) 01.2024 by Piotr Zapart
www.hexefx.com

cyd28_touchscreen's People

Contributors

hexeguitar avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.