Skip to content

Commit

Permalink
drv: ft8xx: new coprocessor commands
Browse files Browse the repository at this point in the history
Implement more co-processor commands in the FT8xx display driver.
The list of the new implemented commands consists of:

* CMD_FGCOLOR
* CMD_BGCOLOR
* CMD_SLIDER
* CMD_TOGGLE
* CMD_TRACK

Signed-off-by: Hubert Miś <hubert.mis@gmail.com>
  • Loading branch information
hubertmis committed Dec 1, 2024
1 parent 922f4db commit 6837dda
Show file tree
Hide file tree
Showing 5 changed files with 460 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/misc/ft8xx/ft8xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#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>

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)
{
const uint16_t cmd_size = sizeof(CMD_FGCOLOR) +
sizeof(c);

while (ram_cmd_freespace() < cmd_size) {
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
123 changes: 123 additions & 0 deletions include/zephyr/drivers/misc/ft8xx/ft8xx_copro.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,129 @@ void ft8xx_copro_cmd_dlstart(void);
*/
void ft8xx_copro_cmd_swap(void);

/**
* @brief Set the foreground color
*
* New foreground color, as a 24-bit RGB number. Red is the most significant 8
* bits, blue is the least. So 0xff0000 is bright red. Foreground color is
* applicable for things that the user can move such as handles and buttons
* ("affordances").
*
* @param c Color to set
*/
void ft8xx_copro_cmd_fgcolor(uint32_t c);

/**
* @brief Set the background color
*
* New background color, as a 24-bit RGB number. Red is the most significant 8
* bits, blue is the least. So 0xff0000 is bright red.
* Background color is applicable for things that the user cannot move. Example
* behind gauges and sliders etc.
*
* @param c Color to set
*/
void ft8xx_copro_cmd_bgcolor(uint32_t c);

/**
* @brief Draw a slider
*
* If width is greater than height, the scroll bar is drawn horizontally.
* If height is greater than width, the scroll bar is drawn vertically.
*
* By default the slider is drawn with a 3D effect. @ref FT8XX_OPT_FLAT removes
* the 3D effect.
*
* @param x x-coordinate of slider top-left, in pixels
* @param y y-coordinate of slider top-left, in pixels
* @param w Width of slider, in pixels
* @param h Height of slider, in pixels
* @param options Options to apply
* @param val Displayed value of slider, between 0 and range inclusive
* @param range Maximum value
*/
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);

/**
* @brief Draw a toggle switch
*
* By default the toggle is drawn with a 3D effect and the value option is zero.
* @ref FT8XX_OPT_FLAT removes the 3D effect and its value is 256.
*
* In @p s, a character value of 255 (it can be written as @c \xff ) separates
* the off and on labels.
*
* @param x x-coordinate of top-left of toggle, in pixels
* @param y y-coordinate of top-left of toggle, in pixels
* @param w Width of toggle, in pixels
* @param font Font to use for text, 0-31. 16-31 are ROM fonts
* @param options Options to apply
* @param state State of the toggle: 0 is off, 65535 is on
* @param s String label for toggle
*/
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);

/**
* @brief Track touches for a graphics object
*
* This command will enable co-processor engine to track the touch on the
* particular graphics object with one valid tag value assigned. Then,
* co-processor engine will update the REG_TRACKER periodically with the frame
* rate of LCD display panel.
*
* Co-processor engine tracks the graphics object in rotary tracker mode and
* linear tracker mode:
*
* - Rotary tracker mode
* Track the angle between the touching point and the center of graphics
* object specified by @p tag value. The value is in units of 1/65536 of a
* circle. 0 means that the angle is straight down, 0x4000 left, 0x8000 up,
* and 0xC000 right from the center.
* - Linear tracker mode
* If @p w is greater than @p h, track the relative distance of touching point
* to the width of graphics object specified by @p tag value. If @p w is not
* greater than @p h, Track the relative distance of touching point to the
* height of graphics object specified by @p tag value. The value is in units
* of 1/65536 of the width or height of graphics object. The distance of
* touching point refers to the distance from the top left pixel of graphics
* object to the coordinate of touching point.
*
* For linear tracker functionality, @p x represents x-coordinate of track area
* top-left and @p y represents y-coordinate of track area top-left. Both
* parameters are in pixels.
*
* For rotary tracker functionality, @p x represents x-coordinate of track area
* center and @p y represents y-coordinate of track area center. Both
* parameters are in pixels.
*
* @note A @p w and @p h of (1,1) means that the tracker is rotary, and reports
* an angle value in REG_TRACKER. A @p w and @p h of (0,0) disables the
* track functionality of co-processor engine.
*
* @param x x-coordinate
* @param y y-coordinate
* @param w Width of track area, in pixels.
* @param h Height of track area, in pixels.
* @param tag Tag of the graphics object to be tracked, 1-255
*/
void ft8xx_copro_cmd_track(int16_t x,
int16_t y,
int16_t w,
int16_t h,
int16_t tag);

/**
* @brief Draw text
*
Expand Down
Loading

0 comments on commit 6837dda

Please sign in to comment.