Commit 1a868208 authored by Hubert Miś's avatar Hubert Miś Committed by Carles Cufi
Browse files

samples: FT800 demo application



This patch adds a new sample application demonstrating basic
usage of FT800 display controller including touchscreen events.

Signed-off-by: default avatarHubert Miś <hubert.mis@gmail.com>
parent cb8a271b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ft800)

target_sources(app PRIVATE src/main.c)
+50 −0
Original line number Diff line number Diff line
.. _display-ft800-sample:

FT800
#####

Overview
********

This sample displays a hello message and an incrementing counter using FT800
Embedded Video Engine.

Requirements
************

To use this sample, the following hardware is required:

* A board with SPI support
* Display with `FT800 EVE`_ like `VM800C board`_

Wiring
******

You will need to connect the `FT800 EVE`_ SPI interface onto a board that
supports Arduino shields.

Building and Running
********************

This sample should work on any board that has SPI enabled and has an Arduino
shield interface. For example, it can be run on the nRF52840-DK board as
described below:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/misc/ft800
   :board: nrf52840dk_nrf52840
   :goals: flash
   :compact:

To build the sample for `VM800C board`_ the shild must be defined as described
below:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/misc/ft800
   :board: nrf52840dk_nrf52840
   :shield: ftdi_vm800c
   :goals: flash
   :compact:

.. _VM800C board: https://www.ftdichip.com/Products/Modules/VM800C.html
.. _FT800 EVE: https://www.ftdichip.com/Products/ICs/FT800.html
+2 −0
Original line number Diff line number Diff line
CONFIG_SPI=y
CONFIG_FT800=y
+8 −0
Original line number Diff line number Diff line
sample:
  name: FT800 display sample
tests:
  sample.display.ft800:
    tags: drivers
    depends_on: spi
    platform_allow: nrf52840dk_nrf52840
    extra_args: SHIELD=ftdi_vm800c
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2021 Hubert Miś <hubert.mis@gmail.com>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>

#include <drivers/misc/ft8xx/ft8xx.h>
#include <drivers/misc/ft8xx/ft8xx_copro.h>
#include <drivers/misc/ft8xx/ft8xx_dl.h>

/**
 * @file Display a counter using FT800.
 */

/* sleep time in msec */
#define SLEEPTIME  100

/* touch tags */
#define TAG_PLUS 1
#define TAG_MINUS 2

static volatile bool process_touch;

static void touch_irq(void)
{
	process_touch = true;
}

void main(void)
{
	int cnt;
	int val;
	struct ft8xx_touch_transform tt;

	/* To get touch events calibrate the display */
	ft8xx_calibrate(&tt);

	/* Get interrupts on touch event */
	ft8xx_register_int(touch_irq);

	/* Starting counting */
	val = 0;
	cnt = 0;

	while (1) {
		/* Start Display List */
		ft8xx_copro_cmd_dlstart();
		ft8xx_copro_cmd(FT8XX_CLEAR_COLOR_RGB(0x00, 0x00, 0x00));
		ft8xx_copro_cmd(FT8XX_CLEAR(1, 1, 1));

		/* Set color */
		ft8xx_copro_cmd(FT8XX_COLOR_RGB(0xf0, 0xf0, 0xf0));

		/* Display the counter */
		ft8xx_copro_cmd_number(20, 20, 29, FT8XX_OPT_SIGNED, cnt);
		cnt++;

		/* Display the hello message */
		ft8xx_copro_cmd_text(20, 70, 30, 0, "Hello,");
		/* Set Zephyr color */
		ft8xx_copro_cmd(FT8XX_COLOR_RGB(0x78, 0x29, 0xd2));
		ft8xx_copro_cmd_text(20, 105, 30, 0, "Zephyr!");

		/* Display value set with buttons */
		ft8xx_copro_cmd(FT8XX_COLOR_RGB(0xff, 0xff, 0xff));
		ft8xx_copro_cmd_number(80, 170, 29,
					FT8XX_OPT_SIGNED | FT8XX_OPT_RIGHTX,
					val);
		ft8xx_copro_cmd(FT8XX_TAG(TAG_PLUS));
		ft8xx_copro_cmd_text(90, 160, 31, 0, "+");
		ft8xx_copro_cmd(FT8XX_TAG(TAG_MINUS));
		ft8xx_copro_cmd_text(20, 160, 31, 0, "-");

		/* Finish Display List */
		ft8xx_copro_cmd(FT8XX_DISPLAY());
		/* Display created frame */
		ft8xx_copro_cmd_swap();

		if (process_touch) {
			int tag = ft8xx_get_touch_tag();

			if (tag == TAG_PLUS) {
				val++;
			} else if (tag == TAG_MINUS) {
				val--;
			}

			process_touch = false;
		}

		/* Wait a while */
		k_msleep(SLEEPTIME);
	}
}