components/tft/tft.h

Mon, 21 Jun 2021 19:04:10 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 21 Jun 2021 19:04:10 +0200
changeset 102
96e30a3a3980
parent 29
45647136ec95
permissions
-rw-r--r--

Finished experimental code to drive the German HendiControl board. Added BoilPower and RampPower buttons during the while boil process. RampPower (going to boil power) is now adjustable. Added PWM driver code to the driver task.

/**
 * @file tft.h
 * @brief High level TFT functions
 * @author LoBo 04/2017
 * @see https://github.com/loboris
 * @author M. Broek - removed unused code for this app.
 */

#ifndef _TFT_H_
#define _TFT_H_

#include <stdlib.h>
#include "tftspi.h"

/**
 * @brief Window coordinates
 */
typedef struct {
	uint16_t        x1;
	uint16_t        y1;
	uint16_t        x2;
	uint16_t        y2;
} dispWin_t;

/**
 * @brief Font description.
 */
typedef struct {
	uint8_t 	*font;
	uint8_t 	x_size;
	uint8_t 	y_size;
	uint8_t		offset;
	uint16_t	numchars;
	uint16_t	size;
	uint8_t 	max_x_size;
	uint8_t		bitmap;
	color_t		color;
} Font;


//==========================================================================================
// ==== Global variables ===================================================================
//==========================================================================================
extern uint8_t   orientation;			///< current screen orientation
extern uint16_t  font_rotate;			///< current font font_rotate angle (0~395)
extern uint8_t   font_transparent;		///< if not 0 draw fonts transparent
extern uint8_t   font_forceFixed;		///< if not zero force drawing proportional fonts with fixed width
extern uint8_t   font_buffered_char;
extern uint8_t   font_line_space;		///< additional spacing between text lines; added to font height
extern uint8_t   text_wrap;			///< if not 0 wrap long text to the new line, else clip
extern color_t   _fg;				///< current foreground color for fonts
extern color_t   _bg;				///< current background for non transparent fonts
extern dispWin_t dispWin;			///< display clip window
extern float	  _angleOffset;			///< angle offset for arc, polygon and line by angle functions
extern uint8_t	  image_debug;			///< print debug messages during image decode if set to 1

extern Font cfont;				///< Current font structure

extern int	TFT_X;				///< X position of the next character after TFT_print() function
extern int	TFT_Y;				///< Y position of the next character after TFT_print() function

// =========================================================================================


/**
 * @brief rotational offset in degrees defining position of value 0 (-90 will put it at the top of circle)
 *        this can be changed with setAngleOffset function at runtime
 */
#define DEFAULT_ANGLE_OFFSET -90

#define PI 3.14159265359


// === Color names constants ===
extern const color_t TFT_BLACK;
extern const color_t TFT_NAVY;
extern const color_t TFT_DARKGREEN;
extern const color_t TFT_DARKCYAN;
extern const color_t TFT_MAROON;
extern const color_t TFT_PURPLE;
extern const color_t TFT_OLIVE;
extern const color_t TFT_LIGHTGREY;
extern const color_t TFT_DARKGREY;
extern const color_t TFT_BLUE;
extern const color_t TFT_GREEN;
extern const color_t TFT_CYAN;
extern const color_t TFT_RED;
extern const color_t TFT_MAGENTA;
extern const color_t TFT_YELLOW;
extern const color_t TFT_WHITE;
extern const color_t TFT_ORANGE;
extern const color_t TFT_GREENYELLOW;
extern const color_t TFT_PINK;


// === Special coordinates constants ===
#define CENTER	-9003			///< Center X or Y
#define RIGHT	-9004			///< Right X
#define BOTTOM	-9004			///< Bottom Y

#define LASTX	7000			///< At last X position
#define LASTY	8000			///< At last Y position

// === Embedded fonts constants ===
#define DEFAULT_FONT		0	///< 12 points 95 characters DejaVu font.
#define DEJAVU18_FONT		1	///< 18 points 95 characters DejaVuSans font.
#define DEJAVU24_FONT		2	///< 24 points 95 characters DejaVu font.
#define UBUNTU16_FONT		3	///< 16 points 95 characters Ubuntu font.
#define COMIC24_FONT		4	///< 24 points 95 characters Comic font.
#define MINYA24_FONT		5	///< 24 points 95 characters Minya font.
#define TOONEY32_FONT		6	///< 32 points 95 characters Tooney font.
#define SMALL_FONT		7	///< 8x12 pixels 95 characters fixed font.
#define DEF_SMALL_FONT		8	///<  9 points 95 characters font.
#define FONT_7SEG		9	///< Variable size 14 characters 7 segment font.
#define USER_FONT		10	///< font will be read from file



// ===== PUBLIC FUNCTIONS =========================================================================


/**
 * @brief Draw pixel at given x,y coordinates
 * @param x horizontal position
 * @param y vertical position
 * @param color pixel color
 * @param sel if not 0 activate CS before and deactivat after sending pixel data to display
 *            when sending multiple pixels it is faster to activate the CS first,
 *            send all pixels an deactivate CS after all pixela was sent
 */
void TFT_drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel);

/**
 * @brief Read pixel color value from display GRAM at given x,y coordinates
 * @param[in] x horizontal position
 * @param[in] y vertical position
 */
color_t TFT_readPixel(int16_t x, int16_t y);

/**
 * @brief Draw vertical line at given x,y coordinates
 * 
 * @param x horizontal start position
 * @param y vertical start position
 * @param h line height in pixels
 * @param color line color
 */
void TFT_drawFastVLine(int16_t x, int16_t y, int16_t h, color_t color);

/**
 * @brief Draw horizontal line at given x,y coordinates
 * 
 * @param x horizontal start position
 * @param y vertical start position
 * @param w line width in pixels
 * @param color line color
 */
void TFT_drawFastHLine(int16_t x, int16_t y, int16_t w, color_t color);

/**
 * @brief Draw line on screen
 * 
 * @param x0 horizontal start position
 * @param y0 vertical start position
 * @param x1 horizontal end position
 * @param y1 vertical end position
 * @param color line color
 */
void TFT_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color);

/**
 * @brief Fill given rectangular screen region with color
 * 
 * @param x horizontal rect start position
 * @param y vertical rect start position
 * @param w rectangle width
 * @param h rectangle height
 * @param color fill color
 */
void TFT_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color);

/**
 * @brief Draw rectangle on screen
 * 
 * @param x horizontal rect start position
 * @param y vertical rect start position
 * @param w rectangle width
 * @param h rectangle height
 * @param color rect line color
 */
void TFT_drawRect(uint16_t x1,uint16_t y1,uint16_t w,uint16_t h, color_t color);

/**
 * @brief Draw rectangle with rounded corners on screen
 * 
 * @param x horizontal rect start position
 * @param y vertical rect start position
 * @param w rectangle width
 * @param h rectangle height
 * @param r corner radius
 * @param color rectangle color
 */
void TFT_drawRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color);

/**
 * @brief Fill given rectangular screen region with rounded corners with color
 * 
 * @param x horizontal rect start position
 * @param y vertical rect start position
 * @param w rectangle width
 * @param h rectangle height
 * @param r corner radius
 * @param color fill color
 */
void TFT_fillRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color);

/**
 * @brief Fill the whole screen with color
 * 
 * @param color fill color
 */
void TFT_fillScreen(color_t color);

/**
 * @brief Fill the current clip window with color
 *
 * @param color fill color
 */
void TFT_fillWindow(color_t color);

/**
 * @brief Draw circle on screen
 * 
 * @param x circle center x position
 * @param y circle center x position
 * @param r circle radius
 * @param color circle color
 */
void TFT_drawCircle(int16_t x, int16_t y, int radius, color_t color);

/**
 * @brief Fill circle on screen with color
 * 
 * @param x circle center x position
 * @param y circle center x position
 * @param r circle radius
 * @param color circle fill color
 */
void TFT_fillCircle(int16_t x, int16_t y, int radius, color_t color);

/**
 * @brief Set the font used for writing the text to display.
 *
 * ------------------------------------------------------------------------------------
 * For 7 segment font only characters 0,1,2,3,4,5,6,7,8,9, . , - , : , / are available.
 *   Character ‘/‘ draws the degree sign.
 * ------------------------------------------------------------------------------------
 *
 * @param font font number; use defined font names
 * @param font_file pointer to font file name; NULL for embeded fonts
 */
void TFT_setFont(uint8_t font, const char *font_file);

/**
 * @brief Returns current font height & width in pixels.
 *
 * @param[in] width pointer to returned font width
 * @param[in] height pointer to returned font height
 */
int TFT_getfontsize(int *width, int* height);

/**
 * @brief Returns current font height in pixels.
 * @return The font height in pixels.
 */
int TFT_getfontheight();

/**
 * @brief Write text to display.
 *
 * Rotation of the displayed text depends on 'font_rotate' variable (0~360)
 * if 'font_transparent' variable is set to 1, no background pixels will be printed
 *
 * If the text does not fit the screen width it will be clipped (if text_wrap=0),
 * or continued on next line (if text_wrap=1)
 *
 * Two special characters are allowed in strings:
 *
 * 		‘\r’ CR (0x0D), clears the display to EOL
 * 		‘\n’ LF (ox0A), continues to the new line, x=0
 *
 * @param st pointer to null terminated string to be printed
 * @param x horizontal position of the upper left point in pixels. Special values can be entered:
 *
 *		CENTER, centers the text
 *		RIGHT, right justifies the text
 *		LASTX, continues from last X position; offset can be used: LASTX+n
 *
 * @param y vertical position of the upper left point in pixels. Special values can be entered:
 *
 *		CENTER, centers the text
 *		BOTTOM, bottom justifies the text
 *		LASTY, continues from last Y position; offset can be used: LASTY+n
 *
 */
void TFT_print(char *st, int x, int y);

/**
 * @brief Set atributes for 7 segment vector font
 * @note 7 segment font must be the current font to this function to have effect
 *
 * @param l 6~40; distance between bars in pixels
 * @param w 1~12, max l/2;  bar width in pixels
 * @param outline draw font outline if set to 1
 * @param color	font outline color, only used if outline=1
 */
void set_7seg_font_atrib(uint8_t l, uint8_t w, int outline, color_t color);

/**
 * @brief Sets the clipping area coordinates.
 *        All writing to screen is clipped to that area.
 *        Starting x & y in all functions will be adjusted to the clipping area.
 *
 * @param x1,y1	upper left point of the clipping area
 * @param x2,y2	bottom right point of the clipping area
 */
void TFT_setclipwin(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);

/**
 * @brief Resets the clipping area to full screen (0,0),(_wodth,_height)
 */
void TFT_resetclipwin();

/**
 * @brief Save current clipping area to temporary variable
 */
void TFT_saveClipWin();

/**
 * @brief Restore current clipping area from temporary variable
 */
void TFT_restoreClipWin();

/**
 * @brief Set the screen rotation
 *        Also resets the clip window and clears the screen with current background color
 *
 * @param rot 0~3; screen rotation; use defined rotation constants:
 * 	      PORTRAIT, LANDSCAPE, PORTRAIT_FLIP, LANDSCAPE_FLIP
 */
void TFT_setRotation(uint8_t rot);

/**
 * @brief Select gamma curve
 * @param gm gama curve, values 0~3
 */
void TFT_setGammaCurve(uint8_t gm);

/**
 * @brief returns the string width in pixels. Useful for positions strings on the screen.
 * @return The string width.
 */
int TFT_getStringWidth(char* str);


/**
 * @brief Fills the rectangle occupied by string with current background color
 * @param x X position
 * @param Y Y position
 * @param str The string
 */
void TFT_clearStringRect(int x, int y, char *str);

/**
 * @brief Get the touch panel coordinates.
 *        The coordinates are adjusted to screen orientation if raw=0
 *
 * @param[in] x pointer to X coordinate
 * @param[in] y pointer to Y coordinate
 * @param raw if 0 returns calibrated screen coordinates; if 1 returns raw touch controller coordinates
 * @return 0 if touch panel is not touched; x=y=0
 *         1 if touch panel is touched; x&y are the valid coordinates
 */
int TFT_read_touch(int *x, int* y, uint8_t raw);

#endif

mercurial