Skip to content
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

drv: ft8xx: new coprocessor commands #82376

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion drivers/misc/ft8xx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
# Copyright (c) 2020-2021 Hubert Miś <[email protected]>
# SPDX-License-Identifier: Apache-2.0

config FT800
menuconfig FT800
bool "FT800 Embedded Video Engine driver"
default y
depends on DT_HAS_FTDI_FT800_ENABLED
select SPI
help
Enable driver for FT800 controller.

if FT800

config FT800_INIT_PRIORITY
int "FT800 init priority"
default 90
depends on FT800
help
FT800 driver initialization priority in POST_KERNEL.

module = FT800
module-str = FT800
source "subsys/logging/Kconfig.template.log_config"

endif # FT800
9 changes: 7 additions & 2 deletions drivers/misc/ft8xx/ft8xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

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

#include "ft8xx_drv.h"
#include "ft8xx_host_commands.h"

LOG_MODULE_REGISTER(ft8xx, CONFIG_DISPLAY_LOG_LEVEL);
LOG_MODULE_REGISTER(ft8xx, CONFIG_FT800_LOG_LEVEL);

#define FT8XX_DLSWAP_FRAME 0x02

Expand Down Expand Up @@ -178,6 +178,11 @@ int ft8xx_get_touch_tag(void)
return (int)ft8xx_rd8(FT800_REG_TOUCH_TAG);
}

uint32_t ft8xx_get_tracker_value(void)
{
return ft8xx_rd32(FT800_REG_TRACKER);
}

void ft8xx_drv_irq_triggered(const struct device *dev, struct gpio_callback *cb,
uint32_t pins)
{
Expand Down
182 changes: 182 additions & 0 deletions drivers/misc/ft8xx/ft8xx_copro.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
enum {
CMD_DLSTART = 0xffffff00,
CMD_SWAP = 0xffffff01,
CMD_BGCOLOR = 0xffffff09,
CMD_FGCOLOR = 0xffffff0a,
CMD_TEXT = 0xffffff0c,
CMD_SLIDER = 0xffffff10,
CMD_TOGGLE = 0xffffff12,
CMD_TRACK = 0xffffff2c,
CMD_NUMBER = 0xffffff2e,
CMD_CALIBRATE = 0xffffff15,
} ft8xx_cmd;
Expand Down Expand Up @@ -73,6 +78,183 @@ void ft8xx_copro_cmd_swap(void)
ft8xx_copro_cmd(CMD_SWAP);
}

void ft8xx_copro_cmd_fgcolor(uint32_t c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is c for color ? would use the full term :)

{
const uint16_t cmd_size = sizeof(CMD_FGCOLOR) +
sizeof(c);

while (ram_cmd_freespace() < cmd_size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function a blocking call? Probably it should be refelected in documentation as well :) same goes for other functions as well.

refresh_reg_cmd_read();
}

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, CMD_FGCOLOR);
increase_reg_cmd_write(sizeof(CMD_FGCOLOR));

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, c);
increase_reg_cmd_write(sizeof(c));

flush_reg_cmd_write();
}

void ft8xx_copro_cmd_bgcolor(uint32_t c)
{
const uint16_t cmd_size = sizeof(CMD_BGCOLOR) +
sizeof(c);

while (ram_cmd_freespace() < cmd_size) {
refresh_reg_cmd_read();
}

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, CMD_BGCOLOR);
increase_reg_cmd_write(sizeof(CMD_BGCOLOR));

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, c);
increase_reg_cmd_write(sizeof(c));

flush_reg_cmd_write();
}

void ft8xx_copro_cmd_slider(int16_t x,
int16_t y,
int16_t w,
int16_t h,
uint16_t options,
uint16_t val,
uint16_t range)
{
size_t padding_bytes = 2;
const uint16_t cmd_size = sizeof(CMD_SLIDER) +
sizeof(x) +
sizeof(y) +
sizeof(w) +
sizeof(h) +
sizeof(options) +
sizeof(val) +
sizeof(range) +
padding_bytes;

while (ram_cmd_freespace() < cmd_size) {
refresh_reg_cmd_read();
}

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, CMD_SLIDER);
increase_reg_cmd_write(sizeof(CMD_SLIDER));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, x);
increase_reg_cmd_write(sizeof(x));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, y);
increase_reg_cmd_write(sizeof(y));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, w);
increase_reg_cmd_write(sizeof(w));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, h);
increase_reg_cmd_write(sizeof(h));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, options);
increase_reg_cmd_write(sizeof(options));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, val);
increase_reg_cmd_write(sizeof(val));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, range);
increase_reg_cmd_write(sizeof(range) + padding_bytes);

flush_reg_cmd_write();
}

void ft8xx_copro_cmd_toggle(int16_t x,
int16_t y,
int16_t w,
int16_t font,
uint16_t options,
uint16_t state,
const char *s)
{
const uint16_t str_bytes = strlen(s) + 1;
const uint16_t padding_bytes = (4 - (str_bytes % 4)) % 4;
const uint16_t cmd_size = sizeof(CMD_TOGGLE) +
sizeof(x) +
sizeof(y) +
sizeof(w) +
sizeof(font) +
sizeof(options) +
sizeof(state) +
str_bytes +
padding_bytes;

while (ram_cmd_freespace() < cmd_size) {
refresh_reg_cmd_read();
}

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, CMD_TOGGLE);
increase_reg_cmd_write(sizeof(CMD_TOGGLE));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, x);
increase_reg_cmd_write(sizeof(x));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, y);
increase_reg_cmd_write(sizeof(y));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, w);
increase_reg_cmd_write(sizeof(w));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, font);
increase_reg_cmd_write(sizeof(font));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, options);
increase_reg_cmd_write(sizeof(options));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, state);
increase_reg_cmd_write(sizeof(state));

(void)ft8xx_drv_write(FT800_RAM_CMD + reg_cmd_write, s, str_bytes);
increase_reg_cmd_write(str_bytes + padding_bytes);

flush_reg_cmd_write();
}

void ft8xx_copro_cmd_track(int16_t x,
int16_t y,
int16_t w,
int16_t h,
int16_t tag)
{
size_t padding_bytes = 2;
const uint16_t cmd_size = sizeof(CMD_TRACK) +
sizeof(x) +
sizeof(y) +
sizeof(w) +
sizeof(h) +
sizeof(tag) +
padding_bytes;

while (ram_cmd_freespace() < cmd_size) {
refresh_reg_cmd_read();
}

ft8xx_wr32(FT800_RAM_CMD + reg_cmd_write, CMD_TRACK);
increase_reg_cmd_write(sizeof(CMD_TRACK));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, x);
increase_reg_cmd_write(sizeof(x));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, y);
increase_reg_cmd_write(sizeof(y));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, w);
increase_reg_cmd_write(sizeof(w));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, h);
increase_reg_cmd_write(sizeof(h));

ft8xx_wr16(FT800_RAM_CMD + reg_cmd_write, tag);
increase_reg_cmd_write(sizeof(tag) + padding_bytes);

flush_reg_cmd_write();
}

void ft8xx_copro_cmd_text(int16_t x,
int16_t y,
int16_t font,
Expand Down
11 changes: 11 additions & 0 deletions include/zephyr/drivers/misc/ft8xx/ft8xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ void ft8xx_touch_transform_set(const struct ft8xx_touch_transform *data);
*/
int ft8xx_get_touch_tag(void);

/**
* @brief Get the tag and the tracking value of the tracked object.
*
* The reported tag and the tracking value apply to an object tracked by the
* coprocessor with the ft8xx_copro_cmd_track() function.
*
* @return Track register content where 2 MS bytes (0xffff0000 mask) indicate
* the track value and 2 LS bytes (0x0000ffff mask) indicate the tag.
*/
uint32_t ft8xx_get_tracker_value(void);

/**
* @brief Set callback executed when FT8xx triggers interrupt
*
Expand Down
Loading
Loading