Our Latest News

LCD touch screen function to realize the design of control motor

LCD screen display to achieve touch function

Drive 320* 240 ST7789 SPI screen for content display, display text and touch screen basic use; reference: the driver model defines the key interfaces for upper layer applications to call, such as read/write framebuffer, on/off touch action operation screen, get screen device information, set the brightness/contrast/pixel format/orientation, etc.

The following figure shows the four touch screen “buttons” that turn on/off the four motors

Figure 1 (shown after power on)

Figure 2 (No.1 motor working)

Figure 3 (No. 2 motor working)

Figure 4 (No. 3 motor working)

Figure 5 (Motor No. 4 working)

Figure 6 (the state of waiting for operation)

Common API interfaces for displaying the touch screen :

void display_get_capabilities(const struct device *dev, struct display_capabilities *capabilities)

Parameter Description

Figure 7

Display device tree configuration

&csk6002_9s_nano_pinctrl{

/* 显示屏SPI接口配置 */
pinctrl_spi0_sclk_default: spi0_sclk_default {
pinctrls = < &pinmuxa 15 6 >;
};
pinctrl_spi0_mosi_default: spi0_mosi_default {
pinctrls = < &pinmuxa 10 6 >;
};
pinctrl_spi0_miso_default: spi0_miso_default {
pinctrls = < &pinmuxa 17 6 >;
};
pinctrl_spi0_cs_default: spi0_cs_default {
pinctrls = < &pinmuxa 12 6 >;
};
};

Touch screen device tree configuration

Pins used: i2c0_scl(pb2), i2c0_sda(pb3).

Complete the configuration of the peripheral interface in csk6011a_nano.overlay, as follows.

In the csk6002_9s_nano.overlay file in the app/boards/ directory and add the following device tree configuration.

Figure 8

&csk6002_9s_nano_pinctrl{
// …
/* 触摸屏I2C接口配置 */
pinctrl_i2c0_scl_default: i2c0_scl_default{
pinctrls = <&pinmuxb 2 8>;
};

pinctrl_i2c0_sda_default: i2c0_sda_default{
        pinctrls = <&pinmuxb 3 8>;
}; 

};

&i2c0 {
status = “okay”;
pinctrl-0 = <&pinctrl_i2c0_scl_default &pinctrl_i2c0_sda_default>;
pinctrl-names = “default”;
ft5336@0 {
compatible = “focaltech,ft5336”;
reg = <0x38>;
label = “FT5336”;
status = “okay”;
int-gpios = <&gpioa 3 0>;
};
};

Logging serial device tree configuration

In this example, GPIOA_3 of the default log serial port (GPIOA_2, GPIOA_3) of the SDK is multiplexed as the int enable pin of the touch screen, so the log output serial port is configured as GPIOb_10 , GPIOb_11, as follows.

&csk6002_9s_nano_pinctrl{
/* 日志串口配置 */
pinctrl_uart0_rx_default: uart0_rx_default{
pinctrls = <&pinmuxb 10 2>;
};

        pinctrl_uart0_tx_default: uart0_tx_default{
                pinctrls = <&pinmuxb 11 2>;
        };
        ...

};

Touch screen component configuration

Open the touch screen function configuration in the prj.conf file:

Touch Configuration

CONFIG_KSCAN=y

I2C function configuration

CONFIG_I2C=y

Touch screen screen driver configuration

CONFIG_KSCAN_BL6XXX=y

Display component configuration

Open the display configuration in the prj.conf file:

CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_LOG=y

GPIO feature configuration

CONFIG_GPIO=y

Displays the feature configuration

CONFIG_DISPLAY=y

SPI feature configuration

CONFIG_SPI=y

ST7789V display driver configuration

CONFIG_ST7789V=y

LCD screen display implementation

void main(void)
{
size_t x;
size_t y;
size_t rect_w;
size_t rect_h;
size_t h_step;
size_t scale;
size_t grey_count;
uint8_t *buf;
int32_t grey_scale_sleep;
const struct device *display_dev;
struct display_capabilities capabilities;
struct display_buffer_descriptor buf_desc;
size_t buf_size = 0;
fill_buffer fill_buffer_fnc = NULL;

LOG_INF("Display sample for %s", DISPLAY_DEV_NAME);

/* kscan初始化 */
kscan_init();

/* 获取display设备实例 */
display_dev = device_get_binding(DISPLAY_DEV_NAME);

if (display_dev == NULL) {
    LOG_ERR("Device %s not found. Aborting sample.",
        DISPLAY_DEV_NAME);
    RETURN_FROM_MAIN(1);
}

/* 获取显示功能 */
display_get_capabilities(display_dev, &capabilities);

if (capabilities.screen_info & SCREEN_INFO_MONO_VTILED) {
    rect_w = 32;
    rect_h = 10;
} else {
    rect_w = 2;
    rect_h = 1;
}

h_step = rect_h;
scale = (capabilities.x_resolution / 8) / rect_h;

rect_w *= scale;
rect_h *= scale;

if (capabilities.screen_info & SCREEN_INFO_EPD) {
    grey_scale_sleep = 10000;
} else {
    grey_scale_sleep = 100;
}

buf_size = rect_w * rect_h;

if (buf_size < (capabilities.x_resolution * h_step)) {
    buf_size = capabilities.x_resolution * h_step;
}

/* 色块配置 */
switch (capabilities.current_pixel_format) {
case PIXEL_FORMAT_ARGB_8888:
    fill_buffer_fnc = fill_buffer_argb8888;
    buf_size *= 4;
    break;
case PIXEL_FORMAT_RGB_888:
    fill_buffer_fnc = fill_buffer_rgb888;
    buf_size *= 3;
    break;
case PIXEL_FORMAT_RGB_565:
    fill_buffer_fnc = fill_buffer_rgb565;
    buf_size *= 2;
    break;
case PIXEL_FORMAT_BGR_565:
    fill_buffer_fnc = fill_buffer_bgr565;
    buf_size *= 2;
    break;
case PIXEL_FORMAT_MONO01:
case PIXEL_FORMAT_MONO10:
    fill_buffer_fnc = fill_buffer_mono;
    buf_size /= 8;
    break;
default:
    LOG_ERR("Unsupported pixel format. Aborting sample.");
    RETURN_FROM_MAIN(1);
}

buf = k_malloc(buf_size);

if (buf == NULL) {
    LOG_ERR("Could not allocate memory. Aborting sample.");
    RETURN_FROM_MAIN(1);
}

(void)memset(buf, 0xFFu, buf_size);

buf_desc.buf_size = buf_size;
buf_desc.pitch = capabilities.x_resolution;
buf_desc.width = capabilities.x_resolution;
buf_desc.height = h_step;

/*整屏填充白色背景*/
for (int idx = 0; idx < capabilities.y_resolution; idx += h_step) {
    display_write(display_dev, 0, idx, &buf_desc, buf);
}

/*左上角填充红色块*/
fill_buffer_fnc(TOP_LEFT, 0, buf, buf_size);
x = 0;
y = 0;
display_write(display_dev, x, y, &buf_desc, buf);

/*右上角填充绿色块*/
fill_buffer_fnc(TOP_RIGHT, 0, buf, buf_size);
x = capabilities.x_resolution - rect_w;
y = 0;
display_write(display_dev, x, y, &buf_desc, buf);

/*右下角填充蓝色块*/
fill_buffer_fnc(BOTTOM_RIGHT, 0, buf, buf_size);
x = capabilities.x_resolution - rect_w;
y = capabilities.y_resolution - rect_h;
display_write(display_dev, x, y, &buf_desc, buf);

/* 关闭显示消隐 */
display_blanking_off(display_dev);

grey_count = 0;
x = 0;
y = capabilities.y_resolution - rect_h;

/*左下角灰色动态色块*/
while (1) {
    fill_buffer_fnc(BOTTOM_LEFT, grey_count, buf, buf_size);
    display_write(display_dev, x, y, &buf_desc, buf);
    ++grey_count;
    k_msleep(grey_scale_sleep);
}

}

Touch screen function realization

Zephyr has a kscan (keyboard scan matrix) driver model, which is used to detect keys in matrix keyboards or devices with buttons (the user touches the touch screen essentially generating a row coordinate). Check out the Display Interface on the zephyr website.

Figure 9

Registering the callback function

/* 触摸回调函数,打印坐标 */
static void k_callback(const struct device *dev, uint32_t row, uint32_t col,
bool pressed)
{
ARG_UNUSED(dev);
printk(“row = %u col = %u, pressed:%s\n”, row, col, pressed ? “TRUE” : “FLASE”);
}

void kscan_init(void)
{
/* 获取kscan设备实例 */
const struct device *kscan_dev = device_get_binding(DISPLAY_KSAN_DEV_NAME);

if (!device_is_ready(kscan_dev)) {
    LOG_ERR("kscan device %s not ready", kscan_dev->name);
    return;
}

/* 注册回调,在k_callback中可看到对应的坐标与状态printk输出操作 */
kscan_config(kscan_dev, k_callback);
/* 使能回调 */
kscan_enable_callback(kscan_dev);

}

void main(void)
{
kscan_init();

}

The compiled instructions are

lisa zep build

The instructions for burning are

lisa zep flash

Results

Touch screen shows four touch switch symbols, respectively, touch the corresponding display in (LED1 symbol LED2 symbol LED3 symbol LED4 symbol below the touch switch). Four functions (GPIO) PWM control motor operation, later to make up (after the high incidence of the epidemic, back to work to make up, solder on the motor driver board). We developed a PC upper computer software (for visual map analysis). GC032A camera uploaded images can later be displayed on the touch screen (a static figure).

Figure 10

    GET A FREE QUOTE

    FPGA IC & FULL BOM LIST

    We'd love to

    hear from you

    Highlight multiple sections with this eye-catching call to action style.

      Contact Us

      Exhibition Bay South Squre, Fuhai Bao’an Shenzhen China

      • Sales@ebics.com
      • +86.755.27389663