Add Inter Fonts
This commit is contained in:
@ -0,0 +1,97 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/Atomic.hpp
|
||||
*
|
||||
* Declares functions for performing atomic operations.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ATOMIC_HPP
|
||||
#define TOUCHGFX_ATOMIC_HPP
|
||||
|
||||
/**
|
||||
* Defines a atomic write on supported platforms
|
||||
*/
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
/** Defines the atomic type. */
|
||||
typedef LONG atomic_t;
|
||||
|
||||
/**
|
||||
* Makes a atomic write of value to target.
|
||||
*
|
||||
* @param [out] target The value to write to.
|
||||
* @param value The value to write.
|
||||
*/
|
||||
inline void atomic_set(atomic_t& target, atomic_t value)
|
||||
{
|
||||
InterlockedExchange(&target, value);
|
||||
}
|
||||
|
||||
#elif defined(__GNUC__) && !defined(__ARMCC_VERSION)
|
||||
|
||||
#include <csignal>
|
||||
/** Defines the atomic type. */
|
||||
typedef sig_atomic_t atomic_t;
|
||||
|
||||
/**
|
||||
* Makes a atomic write of value to target.
|
||||
*
|
||||
* @param [out] target The value to write to.
|
||||
* @param value The value to write.
|
||||
*/
|
||||
inline void atomic_set(atomic_t& target, atomic_t value)
|
||||
{
|
||||
__sync_synchronize();
|
||||
target = value;
|
||||
}
|
||||
|
||||
#elif defined(__IAR_SYSTEMS_ICC__)
|
||||
|
||||
/** Defines the atomic type. */
|
||||
typedef unsigned long atomic_t;
|
||||
|
||||
/**
|
||||
* Makes a atomic write of value to target.
|
||||
*
|
||||
* @param [out] target The value to write to.
|
||||
* @param value The value to write.
|
||||
*
|
||||
* @note Assume that 32 bit writes are atomic.
|
||||
*/
|
||||
inline void atomic_set(atomic_t& target, atomic_t value)
|
||||
{
|
||||
target = value;
|
||||
}
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
/** Defines the atomic type. */
|
||||
typedef unsigned long atomic_t;
|
||||
|
||||
/**
|
||||
* Makes a atomic write of value to target.
|
||||
*
|
||||
* @param [out] target The value to write to.
|
||||
* @param value The value to write.
|
||||
*/
|
||||
inline void atomic_set(atomic_t& target, atomic_t value)
|
||||
{
|
||||
target = value;
|
||||
}
|
||||
#else
|
||||
|
||||
#error "Compiler/platform not supported"
|
||||
|
||||
#endif
|
||||
|
||||
#endif // TOUCHGFX_ATOMIC_HPP
|
||||
@ -0,0 +1,66 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/BlitOp.hpp
|
||||
*
|
||||
* Declares constants for specifying blit operation capabilities.
|
||||
*/
|
||||
#ifndef TOUCHGFX_BLITOP_HPP
|
||||
#define TOUCHGFX_BLITOP_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/** The Blit Operations. */
|
||||
enum BlitOperations
|
||||
{
|
||||
BLIT_OP_COPY = 1 << 0, ///< Copy the source to the destination
|
||||
BLIT_OP_FILL = 1 << 1, ///< Fill the destination with color
|
||||
BLIT_OP_COPY_WITH_ALPHA = 1 << 2, ///< Copy the source to the destination using the given alpha
|
||||
BLIT_OP_FILL_WITH_ALPHA = 1 << 3, ///< Fill the destination with color using the given alpha
|
||||
BLIT_OP_COPY_WITH_TRANSPARENT_PIXELS = 1 << 4, ///< Deprecated, ignored. (Copy the source to the destination, but not the transparent pixels)
|
||||
BLIT_OP_COPY_ARGB8888 = 1 << 5, ///< Copy the source to the destination, performing per-pixel alpha blending
|
||||
BLIT_OP_COPY_ARGB8888_WITH_ALPHA = 1 << 6, ///< Copy the source to the destination, performing per-pixel alpha blending and blending the result with an image-wide alpha
|
||||
BLIT_OP_COPY_L8 = 1 << 7, ///< Copy the L8 source to the destination using the given alpha
|
||||
BLIT_OP_COPY_A4 = 1 << 8, ///< Copy 4-bit source text to destination, performing per-pixel alpha blending
|
||||
BLIT_OP_COPY_A8 = 1 << 9, ///< Copy 8-bit source text to destination, performing per-pixel alpha blending
|
||||
BLIT_OP_COPY_16BIT = 1 << 10, ///< Copy 16-bit regardless of frame buffer format
|
||||
BLIT_OP_FILL_16BIT = 1 << 11 ///< Fill 16-bit regardless of frame buffer format
|
||||
};
|
||||
|
||||
/**
|
||||
* BlitOp instances carry the required information for performing operations on the LCD
|
||||
* (framebuffer) using DMA.
|
||||
*/
|
||||
struct BlitOp
|
||||
{
|
||||
uint32_t operation; ///< The operation to perform @see BlitOperations
|
||||
const uint16_t* pSrc; ///< Pointer to the source (pixels or indexes)
|
||||
const uint8_t* pClut; ///< Pointer to the source CLUT entires
|
||||
colortype color; ///< Color to fill
|
||||
uint16_t* pDst; ///< Pointer to the destination
|
||||
uint16_t nSteps; ///< The number of pixels in a line
|
||||
uint16_t nLoops; ///< The number of lines
|
||||
uint16_t srcLoopStride; ///< The number of bytes to stride the source after every loop
|
||||
uint16_t dstLoopStride; ///< The number of bytes to stride the destination after every loop
|
||||
uint8_t alpha; ///< The alpha to use
|
||||
uint8_t srcFormat; ///< The source format @see Bitmap::BitmapFormat
|
||||
uint8_t dstFormat; ///< The destination format @see Bitmap::BitmapFormat
|
||||
bool replaceBgAlpha; ///< Replace the background per pixel alpha value with 255 = solid
|
||||
bool replaceFgAlpha; ///< Replace the fourground per pixel alpha value with 255 = solid
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_BLITOP_HPP
|
||||
@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/BoardConfiguration.hpp
|
||||
*
|
||||
* Declares initialization functions for the hardware as well as for TouchGFX.
|
||||
*/
|
||||
#ifndef TOUCHGFX_BOARDCONFIGURATION_HPP
|
||||
#define TOUCHGFX_BOARDCONFIGURATION_HPP
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Function to perform generic hardware initialization of the board. This function prototype is
|
||||
* only provided as a convention.
|
||||
*/
|
||||
void hw_init();
|
||||
|
||||
/**
|
||||
* Function to perform touchgfx initialization. This function prototype is only provided as a
|
||||
* convention.
|
||||
*/
|
||||
void touchgfx_init();
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_BOARDCONFIGURATION_HPP
|
||||
@ -0,0 +1,40 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/Buttons.hpp
|
||||
*
|
||||
* Declares the touchgfx::Buttons class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_BUTTONS_HPP
|
||||
#define TOUCHGFX_BUTTONS_HPP
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/** A class for accessing a physical button. */
|
||||
class Buttons
|
||||
{
|
||||
public:
|
||||
/** Perform configuration of IO pins. */
|
||||
static void init();
|
||||
|
||||
/**
|
||||
* Sample button states.
|
||||
*
|
||||
* @return the sampled state of the buttons.
|
||||
*/
|
||||
static unsigned int sample();
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_BUTTONS_HPP
|
||||
@ -0,0 +1,153 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/Config.hpp
|
||||
*
|
||||
* Declares various macros defining which section to use during linking.
|
||||
*/
|
||||
#ifndef TOUCHGFX_CONFIG_HPP
|
||||
#define TOUCHGFX_CONFIG_HPP
|
||||
|
||||
/** A macro to generate the passed argument in double quotes */
|
||||
#define STR(X) STR_I(X)
|
||||
/** A macro to generate the passed argument in double quotes */
|
||||
#define STR_I(X) #X
|
||||
|
||||
/**
|
||||
* Compiler specific macros.
|
||||
* LOCATION_PRAGMA is a macro for placing elements in the proper memory section
|
||||
* LOCATION_ATTRIBUTE is a macro for placing attributes in the proper memory section
|
||||
* FORCE_INLINE_FUNCTION is used to force inline of time critical functions.
|
||||
* TOUCHGFX_DEPRECATED is used to mark a function deprecated.
|
||||
*/
|
||||
#ifdef SIMULATOR
|
||||
|
||||
#define LOCATION_PRAGMA(name)
|
||||
#define LOCATION_PRAGMA_NOLOAD(name)
|
||||
#define LOCATION_ATTRIBUTE(name)
|
||||
#define LOCATION_ATTRIBUTE_NOLOAD(name)
|
||||
#define LOCATION_ALIGN_8BYTES(buf)
|
||||
#define FORCE_INLINE_FUNCTION inline
|
||||
#if defined(__GNUC__)
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) decl __attribute__((deprecated(message)))
|
||||
#elif _MSC_VER >= 1900
|
||||
// Visual Studio 2015 or newer
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) [[deprecated("Deprecated: " message)]] decl
|
||||
#else
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) decl
|
||||
#endif
|
||||
|
||||
#elif defined(__GNUC__) && !defined(__ARMCC_VERSION)
|
||||
|
||||
// xgcc
|
||||
#define LOCATION_PRAGMA(name)
|
||||
#define LOCATION_PRAGMA_NOLOAD(name)
|
||||
#define LOCATION_ATTRIBUTE(name) __attribute__((section(STR(name)))) __attribute__((aligned(4)))
|
||||
#define LOCATION_ATTRIBUTE_NOLOAD(name) __attribute__((section(STR(name)))) __attribute__((aligned(4)))
|
||||
#define LOCATION_ALIGN_8BYTES(buf) buf __attribute__((aligned(8)))
|
||||
#define FORCE_INLINE_FUNCTION __attribute__((always_inline)) inline
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) [[deprecated(message)]] decl
|
||||
|
||||
#elif defined __ICCARM__
|
||||
|
||||
// IAR
|
||||
#define LOCATION_PRAGMA(name) _Pragma(STR(location = name))
|
||||
#define LOCATION_PRAGMA_NOLOAD(name) _Pragma(STR(location = name))
|
||||
#define LOCATION_ATTRIBUTE(name)
|
||||
#define LOCATION_ATTRIBUTE_NOLOAD(name)
|
||||
#define LOCATION_ALIGN_8BYTES(buf) _Pragma(STR(data_alignment = 8)) buf
|
||||
#define FORCE_INLINE_FUNCTION _Pragma("inline=forced")
|
||||
#if __IAR_SYSTEMS_ICC__ >= 9
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) [[deprecated(message)]] decl
|
||||
#else
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) decl
|
||||
#endif
|
||||
#pragma diag_suppress = Pe236
|
||||
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
|
||||
// Keil
|
||||
#define LOCATION_PRAGMA(name)
|
||||
#define LOCATION_PRAGMA_NOLOAD(name)
|
||||
#define LOCATION_ATTRIBUTE(name) __attribute__((section(name))) __attribute__((aligned(4)))
|
||||
#define LOCATION_ATTRIBUTE_NOLOAD(name) __attribute__((section(name), zero_init)) __attribute__((aligned(4)))
|
||||
#define LOCATION_ALIGN_8BYTES(buf) buf __attribute__((aligned(8)))
|
||||
#define FORCE_INLINE_FUNCTION inline
|
||||
#if __ARMCC_VERSION >= 6000000
|
||||
// Only newer Keil support message to be given
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) decl __attribute__((deprecated(message)))
|
||||
#else
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) decl __attribute__((deprecated))
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Other/Unknown
|
||||
#define LOCATION_PRAGMA(name)
|
||||
#define LOCATION_PRAGMA_NOLOAD(name)
|
||||
#define LOCATION_ATTRIBUTE(name)
|
||||
#define LOCATION_ATTRIBUTE_NOLOAD(name)
|
||||
#define LOCATION_ALIGN_8BYTES(buf)
|
||||
#define FORCE_INLINE_FUNCTION
|
||||
#define TOUCHGFX_DEPRECATED(message, decl) decl
|
||||
|
||||
#endif
|
||||
|
||||
/** A macro for placing Font Glyph in memory. */
|
||||
#define FONT_GLYPH_LOCATION_FLASH_PRAGMA LOCATION_PRAGMA("FontFlashSection")
|
||||
/** A macro for placing Font Glyph attribute in memory. */
|
||||
#define FONT_GLYPH_LOCATION_FLASH_ATTRIBUTE LOCATION_ATTRIBUTE("FontFlashSection")
|
||||
|
||||
/** A macro for placing Font table in memory. */
|
||||
#define FONT_TABLE_LOCATION_FLASH_PRAGMA LOCATION_PRAGMA("FontFlashSection")
|
||||
/** A macro for placing Font table attribute in memory. */
|
||||
#define FONT_TABLE_LOCATION_FLASH_ATTRIBUTE LOCATION_ATTRIBUTE("FontFlashSection")
|
||||
|
||||
/** A macro for placing Font lookup table in memory. */
|
||||
#define FONT_SEARCHTABLE_LOCATION_FLASH_PRAGMA LOCATION_PRAGMA("FontSearchFlashSection")
|
||||
/** A macro for placing Font table attribute in memory. */
|
||||
#define FONT_SEARCHTABLE_LOCATION_FLASH_ATTRIBUTE LOCATION_ATTRIBUTE("FontSearchFlashSection")
|
||||
|
||||
/** A macro for placing Font kerning in memory. */
|
||||
#define FONT_KERNING_LOCATION_FLASH_PRAGMA LOCATION_PRAGMA("FontSearchFlashSection")
|
||||
/** A macro for placing Font kerning attribute in memory. */
|
||||
#define FONT_KERNING_LOCATION_FLASH_ATTRIBUTE LOCATION_ATTRIBUTE("FontSearchFlashSection")
|
||||
|
||||
/** A macro for placing Text kerning in memory. */
|
||||
#define TEXT_LOCATION_FLASH_PRAGMA LOCATION_PRAGMA("TextFlashSection")
|
||||
/** A macro for placing Text attribute in memory. */
|
||||
#define TEXT_LOCATION_FLASH_ATTRIBUTE LOCATION_ATTRIBUTE("TextFlashSection")
|
||||
|
||||
/** A generic macro for placing an element in memory. */
|
||||
#define LOCATION_EXTFLASH_PRAGMA LOCATION_PRAGMA("ExtFlashSection")
|
||||
/** A generic macro for placing an element attribute in memory. */
|
||||
#define LOCATION_EXTFLASH_ATTRIBUTE LOCATION_ATTRIBUTE("ExtFlashSection")
|
||||
|
||||
/**
|
||||
* To be able to use __restrict__ on the supported platform. The IAR compiler does not support
|
||||
* this.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define RESTRICT __restrict__
|
||||
#else
|
||||
#define RESTRICT
|
||||
#endif // __GNUC__
|
||||
|
||||
/** Use KEEP to make sure the compiler does not remove this. */
|
||||
#ifdef __ICCARM__
|
||||
#define KEEP __root
|
||||
#else
|
||||
#define KEEP
|
||||
#endif
|
||||
|
||||
#endif // TOUCHGFX_CONFIG_HPP
|
||||
@ -0,0 +1,315 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/DMA.hpp
|
||||
*
|
||||
* Declares the touchgfx::DMA_Queue (abstract), touchgfx::LockFreeDMA_Queue and
|
||||
* touchgfx::DMA_Interface (abstract) classes.
|
||||
*/
|
||||
#ifndef TOUCHGFX_DMA_HPP
|
||||
#define TOUCHGFX_DMA_HPP
|
||||
|
||||
#include <touchgfx/hal/Atomic.hpp>
|
||||
#include <touchgfx/hal/BlitOp.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
class DMA_Interface;
|
||||
|
||||
/**
|
||||
* This class provides an interface for a FIFO (circular) list used by DMA_Interface and
|
||||
* descendants for storing BlitOp's.
|
||||
*/
|
||||
class DMA_Queue
|
||||
{
|
||||
friend class DMA_Interface;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Query if this object is empty.
|
||||
*
|
||||
* @return true if the queue is empty.
|
||||
*/
|
||||
virtual bool isEmpty() = 0;
|
||||
|
||||
/**
|
||||
* Query if this object is full.
|
||||
*
|
||||
* @return true if the queue is full.
|
||||
*/
|
||||
virtual bool isFull() = 0;
|
||||
|
||||
/**
|
||||
* Adds the specified blitop to the queue.
|
||||
*
|
||||
* @param op The blitop to add.
|
||||
*/
|
||||
virtual void pushCopyOf(const BlitOp& op) = 0;
|
||||
|
||||
/** Finalizes an instance of the DMA_Queue class. */
|
||||
virtual ~DMA_Queue()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Initializes a new instance of the DMA_Queue class. */
|
||||
DMA_Queue()
|
||||
{
|
||||
}
|
||||
|
||||
/** Pops an element from the queue. */
|
||||
virtual void pop() = 0;
|
||||
|
||||
/**
|
||||
* Gets the first element in the queue.
|
||||
*
|
||||
* @return The first element in the queue.
|
||||
*/
|
||||
virtual const BlitOp* first() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* This implements a simple lock-free FIFO queue (single producer, single consumer)
|
||||
*
|
||||
* @see DMA_Queue
|
||||
*/
|
||||
class LockFreeDMA_Queue : public DMA_Queue
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructs a lock-free queue.
|
||||
*
|
||||
* @param [out] mem Pointer to the memory used by the queue to store elements.
|
||||
* @param n Number of elements the memory provided can contain.
|
||||
*/
|
||||
LockFreeDMA_Queue(BlitOp* mem, atomic_t n);
|
||||
|
||||
virtual bool isEmpty();
|
||||
|
||||
virtual bool isFull();
|
||||
|
||||
virtual void pushCopyOf(const BlitOp& op);
|
||||
|
||||
protected:
|
||||
virtual void pop();
|
||||
|
||||
virtual const BlitOp* first();
|
||||
|
||||
BlitOp* q; ///< Pointer to the queue memory.
|
||||
atomic_t capacity; ///< The number of elements the queue can contain.
|
||||
atomic_t head; ///< Index to the head element.
|
||||
atomic_t tail; ///< Index to the tail element.
|
||||
};
|
||||
|
||||
/**
|
||||
* DMA_Interface provides basic functionality and structure for processing "blit" operations
|
||||
* using DMA.
|
||||
*/
|
||||
class DMA_Interface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Gets the blit capabilities of this DMA.
|
||||
*
|
||||
* @return The blit operations supported by this DMA implementation.
|
||||
*/
|
||||
virtual BlitOperations getBlitCaps() = 0;
|
||||
|
||||
/**
|
||||
* Inserts a BlitOp for processing. This also potentially starts the DMA controller, if
|
||||
* not already running.
|
||||
*
|
||||
* @param op The operation to add.
|
||||
*/
|
||||
virtual void addToQueue(const BlitOp& op);
|
||||
|
||||
/** This function blocks until all DMA transfers in the queue have been completed. */
|
||||
virtual void flush()
|
||||
{
|
||||
waitForFrameBufferSemaphore();
|
||||
}
|
||||
|
||||
/** Perform initialization. Does nothing in this base class. */
|
||||
virtual void initialize()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Query if the DMA is running.
|
||||
*
|
||||
* @return true if a DMA operation is currently in progress.
|
||||
*/
|
||||
bool isDMARunning()
|
||||
{
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not a DMA operation is allowed to begin. Used in single-buffering to
|
||||
* avoid changing the framebuffer while display is being updated.
|
||||
*
|
||||
* @param allowed true if DMA transfers are allowed.
|
||||
*/
|
||||
void setAllowed(bool allowed)
|
||||
{
|
||||
isAllowed = allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether a DMA operation is allowed to begin. Used in single-buffering to avoid
|
||||
* changing the framebuffer while display is being updated.
|
||||
*
|
||||
* @return true if DMA is allowed to start, false if not.
|
||||
*/
|
||||
bool getAllowed() const
|
||||
{
|
||||
return isAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not a DMA operation is reserved by rendering. Used to allow/disallow
|
||||
* other users of DMA2D whom are drawing into the framebuffer, e.g. video thread.
|
||||
*
|
||||
* @param reserved true if DMA is reserved by rendering.
|
||||
*/
|
||||
void setReserved(bool reserved)
|
||||
{
|
||||
isReserved = reserved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether a DMA operation is reserved by rendering. Used to allow/disallow
|
||||
* other users of DMA2D whom are drawing into the framebuffer, e.g. video thread.
|
||||
*
|
||||
* @return true if DMA is reserved by rendering, false if not.
|
||||
*/
|
||||
bool getReserved() const
|
||||
{
|
||||
return isReserved;
|
||||
}
|
||||
|
||||
/** Signals that DMA transfers can start. If any elements are in the queue, start it. */
|
||||
virtual void start();
|
||||
|
||||
/**
|
||||
* This function is called automatically by the framework when a DMA interrupt has been
|
||||
* received.
|
||||
*
|
||||
* This function is called automatically by the framework when a DMA interrupt has been
|
||||
* received.
|
||||
*/
|
||||
virtual void signalDMAInterrupt() = 0;
|
||||
|
||||
/**
|
||||
* Query if the DMA queue is empty.
|
||||
*
|
||||
* @return 1 if DMA queue is empty, else 0.
|
||||
*/
|
||||
uint8_t isDmaQueueEmpty();
|
||||
|
||||
/**
|
||||
* Query if the DMA queue is full.
|
||||
*
|
||||
* @return 1 if DMA queue is full, else 0.
|
||||
*/
|
||||
uint8_t isDmaQueueFull();
|
||||
|
||||
/**
|
||||
* Function for obtaining the DMA type of the concrete DMA_Interface implementation. As
|
||||
* default, will return DMA_TYPE_GENERIC type value.
|
||||
*
|
||||
* @return a DMAType value of the concrete DMA_Interface implementation.
|
||||
*/
|
||||
virtual DMAType getDMAType()
|
||||
{
|
||||
return DMA_TYPE_GENERIC;
|
||||
}
|
||||
|
||||
/** Finalizes an instance of the DMA_Interface class. */
|
||||
virtual ~DMA_Interface()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructs a DMA Interface object.
|
||||
*
|
||||
* @param [in] dmaQueue Reference to the queue of DMA operations.
|
||||
*/
|
||||
DMA_Interface(DMA_Queue& dmaQueue)
|
||||
: queue(dmaQueue), isRunning(false), isAllowed(false)
|
||||
{
|
||||
}
|
||||
|
||||
/** Performs a queued blit-op. */
|
||||
virtual void execute();
|
||||
|
||||
/** To be called when blit-op has been performed. */
|
||||
virtual void executeCompleted();
|
||||
|
||||
/**
|
||||
* Called when elements are added to the DMA-queue.
|
||||
*
|
||||
* @note The framebuffer must be locked before this method returns if the DMA-queue is non-
|
||||
* empty.
|
||||
*/
|
||||
virtual void seedExecution();
|
||||
|
||||
/**
|
||||
* Configures blit-op hardware for a 2D copy as specified by blitOp.
|
||||
*
|
||||
* @param blitOp The operation to execute.
|
||||
*/
|
||||
virtual void setupDataCopy(const BlitOp& blitOp) = 0;
|
||||
|
||||
/**
|
||||
* Configures blit-op hardware for a 2D fill as specified by blitOp.
|
||||
*
|
||||
* @param blitOp The operation to execute.
|
||||
*/
|
||||
virtual void setupDataFill(const BlitOp& blitOp) = 0;
|
||||
|
||||
/**
|
||||
* Configures blit-op hardware for alpha-blending.
|
||||
*
|
||||
* @param alpha The alpha-blending value to apply.
|
||||
*/
|
||||
virtual void enableAlpha(uint8_t alpha);
|
||||
|
||||
/** Configures blit-op hardware for solid operation (no alpha-blending) */
|
||||
virtual void disableAlpha();
|
||||
|
||||
/**
|
||||
* Configures blit-op hardware for alpha-blending while simultaneously skipping
|
||||
* transparent pixels.
|
||||
*
|
||||
* @param alpha The alpha-blending value to apply.
|
||||
*/
|
||||
virtual void enableCopyWithTransparentPixels(uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Waits until framebuffer semaphore is available (i.e. neither DMA or application is
|
||||
* accessing the framebuffer).
|
||||
*/
|
||||
virtual void waitForFrameBufferSemaphore();
|
||||
|
||||
DMA_Queue& queue; ///< Reference to the DMA queue
|
||||
bool isRunning; ///< true if a DMA transfer is currently ongoing.
|
||||
volatile bool isAllowed; ///< true if DMA transfers are currently allowed.
|
||||
volatile bool isReserved; ///< true if DMA is reserved for for HW rendering
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_DMA_HPP
|
||||
@ -0,0 +1,85 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/FlashDataReader.hpp
|
||||
*
|
||||
* Declares the touchgfx::FlashDataReader class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_FLASHDATAREADER_HPP
|
||||
#define TOUCHGFX_FLASHDATAREADER_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* This class is an abstract interface for a class reading data from a flash. The flash can be
|
||||
* any type, but is mostly used for flashes that are not memory mapped. Applications
|
||||
* must implement access to the flash through this interface.
|
||||
*/
|
||||
class FlashDataReader
|
||||
{
|
||||
public:
|
||||
/** Finalizes an instance of the FlashDataReader class. */
|
||||
virtual ~FlashDataReader()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute if an address is directly addressable by the MCU.
|
||||
*
|
||||
* Compute if an address is directly addressable by the MCU. The data is addressable it
|
||||
* should be read direct through a pointer and not through this interface.
|
||||
*
|
||||
* @param address The address in the flash.
|
||||
*
|
||||
* @return True if the address is addressable by the MCU.
|
||||
*/
|
||||
virtual bool addressIsAddressable(const void* address) = 0;
|
||||
|
||||
/**
|
||||
* Copy data from flash to a buffer. This must be a synchrony method that does not
|
||||
* return until the copy is done.
|
||||
*
|
||||
* @param src Address of source data in the flash.
|
||||
* @param [in,out] dst Address of destination buffer in RAM.
|
||||
* @param bytes Number of bytes to copy.
|
||||
*/
|
||||
virtual void copyData(const void* src, void* dst, uint32_t bytes) = 0;
|
||||
|
||||
/**
|
||||
* Initiate a read operation from flash to a buffer. This can be an asynchrony operation
|
||||
* that is still running after this function returns. Buffers must be handled by the
|
||||
* subclass. LCD16bppSerialFlash will at most copy 4 bytes times the width of the
|
||||
* display.
|
||||
*
|
||||
* @param src Address of source data in the flash.
|
||||
* @param bytes Number of bytes to copy.
|
||||
*/
|
||||
virtual void startFlashLineRead(const void* src, uint32_t bytes) = 0;
|
||||
|
||||
/**
|
||||
* Waits until the previous startFlashLineRead operation is complete.
|
||||
*
|
||||
* Waits until the previous startFlashLineRead operation is complete. If the
|
||||
* startFlashLineRead method is asynchrony, this method must wait until the previous
|
||||
* operation has completed.
|
||||
*
|
||||
* @return The address of a buffer containing the read data.
|
||||
*/
|
||||
virtual const uint8_t* waitFlashReadComplete() = 0;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_FLASHDATAREADER_HPP
|
||||
@ -0,0 +1,269 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/FrameBufferAllocator.hpp
|
||||
*
|
||||
* Declares the touchgfx::FrameBufferAllocator, touchgfx::SingleBlockAllocator
|
||||
* and touchgfx::ManyBlockAllocator classes.
|
||||
*/
|
||||
#ifndef TOUCHGFX_FRAMEBUFFERALLOCATOR_HPP
|
||||
#define TOUCHGFX_FRAMEBUFFERALLOCATOR_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Called by FrameBufferAllocator to wait for a LCD Transfer, when the allocator has no free
|
||||
* blocks. The LCD driver can use this function to synchronize the UI thread with the
|
||||
* transfer logic.
|
||||
*/
|
||||
void FrameBufferAllocatorWaitOnTransfer();
|
||||
|
||||
/**
|
||||
* Called by FrameBufferAllocator when a block is drawn and therefore ready for transfer. The
|
||||
* LCD driver should use this method to start a transfer.
|
||||
*/
|
||||
void FrameBufferAllocatorSignalBlockDrawn();
|
||||
|
||||
/**
|
||||
* This class is an abstract interface for a class allocating partial framebuffer blocks. The
|
||||
* interface must be implemented by a subclass.
|
||||
*
|
||||
* @see ManyBlockAllocator
|
||||
*/
|
||||
class FrameBufferAllocator
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Allocates a framebuffer block. The block will have at least the width requested. The
|
||||
* height of the allocated block can be lower than requested if not enough memory is
|
||||
* available.
|
||||
*
|
||||
* @param x The absolute x coordinate of the block on the screen.
|
||||
* @param y The absolute y coordinate of the block on the screen.
|
||||
* @param width The width of the block.
|
||||
* @param height The height of the block.
|
||||
* @param [in,out] block Pointer to pointer to return the block address in.
|
||||
*
|
||||
* @return The height of the allocated block.
|
||||
*/
|
||||
virtual uint16_t allocateBlock(const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, uint8_t** block) = 0;
|
||||
|
||||
/**
|
||||
* Marks a previously allocated block as ready to be transferred to the LCD.
|
||||
*
|
||||
*/
|
||||
virtual void markBlockReadyForTransfer() = 0;
|
||||
|
||||
/**
|
||||
* Check if a block is ready for transfer to the LCD.
|
||||
*
|
||||
* @return True if a block is ready for transfer.
|
||||
*/
|
||||
virtual bool hasBlockReadyForTransfer() = 0;
|
||||
|
||||
/**
|
||||
* Get the block ready for transfer.
|
||||
*
|
||||
* @param [out] rect Reference to rect to write block x, y, width, and height.
|
||||
*
|
||||
* @return Returns the address of the block ready for transfer.
|
||||
*/
|
||||
virtual const uint8_t* getBlockForTransfer(Rect& rect) = 0;
|
||||
|
||||
/**
|
||||
* Get the Rect of the next block to transfer.
|
||||
*
|
||||
* @return Rect ready for transfer.
|
||||
*
|
||||
* @see hasBlockReadyForTransfer
|
||||
*
|
||||
* @note This function should only be called when the allocator has a block ready for transfer.
|
||||
*/
|
||||
virtual const Rect& peekBlockForTransfer() = 0;
|
||||
|
||||
/**
|
||||
* Check if a block is ready for drawing (the block is empty).
|
||||
*
|
||||
* @return True if a block is empty.
|
||||
*/
|
||||
virtual bool hasEmptyBlock() = 0;
|
||||
|
||||
/**
|
||||
* Free a block after transfer to the LCD. Marks a previously allocated block as
|
||||
* transferred and ready to reuse.
|
||||
*/
|
||||
virtual void freeBlockAfterTransfer() = 0;
|
||||
|
||||
/** Finalizes an instance of the FrameBufferAllocator class. */
|
||||
virtual ~FrameBufferAllocator()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
/** BlockState is used for internal state of each block. */
|
||||
enum BlockState
|
||||
{
|
||||
EMPTY, ///< Block is empty, can be allocated
|
||||
ALLOCATED, ///< Block is allocated for drawing
|
||||
DRAWN, ///< Block has been drawn to, can be send
|
||||
SENDING ///< Block is being transmitted to the display
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is partial framebuffer allocator using multiple blocks. New buffers can be
|
||||
* allocated until no free blocks are available. After transfer to LCD, a block is
|
||||
* queued for allocation again.
|
||||
*
|
||||
* @see FrameBufferAllocator
|
||||
*/
|
||||
template <uint32_t block_size, uint32_t blocks, uint32_t bytes_pr_pixel>
|
||||
class ManyBlockAllocator : public FrameBufferAllocator
|
||||
{
|
||||
public:
|
||||
ManyBlockAllocator()
|
||||
{
|
||||
sendingBlock = -1;
|
||||
drawingBlock = -1;
|
||||
for (uint32_t i = 0; i < blocks; i++)
|
||||
{
|
||||
state[i] = EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a framebuffer block. The block will have at least the width requested. The
|
||||
* height of the allocated block can be lower than requested if not enough memory is
|
||||
* available.
|
||||
*
|
||||
* @param x The absolute x coordinate of the block on the screen.
|
||||
* @param y The absolute y coordinate of the block on the screen.
|
||||
* @param width The width of the block.
|
||||
* @param height The height of the block.
|
||||
* @param [in,out] block Pointer to pointer to return the block address in.
|
||||
*
|
||||
* @return The height of the allocated block.
|
||||
*/
|
||||
virtual uint16_t allocateBlock(const uint16_t x, const uint16_t y, const uint16_t width, const uint16_t height, uint8_t** block)
|
||||
{
|
||||
drawingBlock++;
|
||||
if (drawingBlock == blocks)
|
||||
{
|
||||
drawingBlock = 0;
|
||||
}
|
||||
while (state[drawingBlock] != EMPTY)
|
||||
{
|
||||
FrameBufferAllocatorWaitOnTransfer();
|
||||
}
|
||||
assert(state[drawingBlock] == EMPTY);
|
||||
state[drawingBlock] = ALLOCATED;
|
||||
const int32_t stride = width * bytes_pr_pixel;
|
||||
const int32_t lines = block_size / stride;
|
||||
*block = (uint8_t*)&memory[drawingBlock][0];
|
||||
blockRect[drawingBlock].x = x;
|
||||
blockRect[drawingBlock].y = y;
|
||||
blockRect[drawingBlock].width = width;
|
||||
blockRect[drawingBlock].height = MIN(height, lines);
|
||||
return blockRect[drawingBlock].height;
|
||||
}
|
||||
|
||||
/** Marks a previously allocated block as ready to be transferred to the LCD. */
|
||||
virtual void markBlockReadyForTransfer()
|
||||
{
|
||||
assert(state[drawingBlock] == ALLOCATED);
|
||||
state[drawingBlock] = DRAWN;
|
||||
FrameBufferAllocatorSignalBlockDrawn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block is ready for transfer to the LCD.
|
||||
*
|
||||
* @return True if a block is ready for transfer.
|
||||
*/
|
||||
virtual bool hasBlockReadyForTransfer()
|
||||
{
|
||||
for (uint32_t i = 0; i < blocks; i++)
|
||||
{
|
||||
if (state[i] == DRAWN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block ready for transfer.
|
||||
*
|
||||
* @param [in,out] rect Reference to rect to write block x, y, width, and height.
|
||||
*
|
||||
* @return Returns the address of the block ready for transfer.
|
||||
*/
|
||||
virtual const uint8_t* getBlockForTransfer(Rect& rect)
|
||||
{
|
||||
sendingBlock++;
|
||||
if (sendingBlock == blocks)
|
||||
{
|
||||
sendingBlock = 0;
|
||||
}
|
||||
assert(state[sendingBlock] == DRAWN);
|
||||
rect = blockRect[sendingBlock];
|
||||
state[sendingBlock] = SENDING;
|
||||
return (const uint8_t*)&memory[sendingBlock][0];
|
||||
}
|
||||
|
||||
virtual const Rect& peekBlockForTransfer()
|
||||
{
|
||||
int nextSendingBlock = sendingBlock + 1;
|
||||
if (nextSendingBlock == blocks)
|
||||
{
|
||||
nextSendingBlock = 0;
|
||||
}
|
||||
assert(state[nextSendingBlock] == DRAWN);
|
||||
return blockRect[nextSendingBlock];
|
||||
}
|
||||
|
||||
virtual bool hasEmptyBlock()
|
||||
{
|
||||
int nextDrawingBlock = drawingBlock + 1;
|
||||
if (nextDrawingBlock == blocks)
|
||||
{
|
||||
nextDrawingBlock = 0;
|
||||
}
|
||||
return (state[nextDrawingBlock] == EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a block after transfer to the LCD.
|
||||
*
|
||||
* Marks a previously allocated block as transferred and ready to reuse.
|
||||
*/
|
||||
virtual void freeBlockAfterTransfer()
|
||||
{
|
||||
assert(state[sendingBlock] == SENDING);
|
||||
state[sendingBlock] = EMPTY;
|
||||
}
|
||||
|
||||
private:
|
||||
volatile BlockState state[blocks];
|
||||
uint32_t memory[blocks][block_size / 4];
|
||||
Rect blockRect[blocks];
|
||||
int sendingBlock;
|
||||
int drawingBlock;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_FRAMEBUFFERALLOCATOR_HPP
|
||||
@ -0,0 +1,75 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/GPIO.hpp
|
||||
*
|
||||
* Declares the touchgfx::GPIO class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_GPIO_HPP
|
||||
#define TOUCHGFX_GPIO_HPP
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Interface class for manipulating GPIOs in order to do performance measurements on target. Not
|
||||
* used on the PC simulator.
|
||||
*/
|
||||
class GPIO
|
||||
{
|
||||
public:
|
||||
/** Enum for the GPIOs used. */
|
||||
enum GPIO_ID
|
||||
{
|
||||
VSYNC_FREQ, /// Pin is toggled at each VSYNC
|
||||
RENDER_TIME, /// Pin is high when frame rendering begins, low when finished
|
||||
FRAME_RATE, /// Pin is toggled when the framebuffers are swapped.
|
||||
MCU_ACTIVE /// Pin is high when the MCU is doing work (i.e. not in idle task).
|
||||
};
|
||||
|
||||
/** Perform configuration of IO pins. */
|
||||
static void init();
|
||||
|
||||
/**
|
||||
* Sets a pin high.
|
||||
*
|
||||
* @param id the pin to set.
|
||||
*/
|
||||
static void set(GPIO_ID id);
|
||||
|
||||
/**
|
||||
* Sets a pin low.
|
||||
*
|
||||
* @param id the pin to set.
|
||||
*/
|
||||
static void clear(GPIO_ID id);
|
||||
|
||||
/**
|
||||
* Toggles a pin.
|
||||
*
|
||||
* @param id the pin to toggle.
|
||||
*/
|
||||
static void toggle(GPIO_ID id);
|
||||
|
||||
/**
|
||||
* Gets the state of a pin.
|
||||
*
|
||||
* @param id the pin to get.
|
||||
*
|
||||
* @return true if the pin is high, false otherwise.
|
||||
*/
|
||||
static bool get(GPIO_ID id);
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_GPIO_HPP
|
||||
@ -0,0 +1,117 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/Gestures.hpp
|
||||
*
|
||||
* Declares the touchgfx::Gestures class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_GESTURES_HPP
|
||||
#define TOUCHGFX_GESTURES_HPP
|
||||
|
||||
#include <touchgfx/UIEventListener.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/** This class implements the detection of gestures. */
|
||||
class Gestures
|
||||
{
|
||||
static const uint8_t MAX_TICKS_BETWEEN_MOVES_FOR_SWIPE = 7;
|
||||
static const uint8_t MIN_VELOCITY_AT_RELEASE_BEFORE_SWIPE = 3;
|
||||
|
||||
/** Defines the state of a drag. */
|
||||
struct DragState
|
||||
{
|
||||
DragState()
|
||||
: startX(0),
|
||||
startY(0),
|
||||
downX(0),
|
||||
downY(0),
|
||||
tickCount(0),
|
||||
velocityX(0),
|
||||
velocityY(0),
|
||||
inProgress(false)
|
||||
{
|
||||
}
|
||||
|
||||
uint16_t startX; ///< Starting x coordinate
|
||||
uint16_t startY; ///< Starting y coordinate
|
||||
uint16_t downX; ///< Starting x coordinate of the drag
|
||||
uint16_t downY; ///< Starting x coordinate of the drag
|
||||
uint16_t tickCount; ///< Measures the timing of the drag
|
||||
int16_t velocityX; ///< The velocity (X orientation) of the drag
|
||||
int16_t velocityY; ///< The velocity (Y orientation) of the drag
|
||||
bool inProgress; ///< Whether a drag is in progress or not
|
||||
};
|
||||
|
||||
public:
|
||||
/** Default constructor. Does nothing. */
|
||||
Gestures()
|
||||
: drag(), listener(0), dragThresholdValue(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the event listener.
|
||||
*
|
||||
* @param [in] l The EventListener to register.
|
||||
*/
|
||||
void registerEventListener(UIEventListener& l);
|
||||
|
||||
/** Has to be called during the timer tick. */
|
||||
void tick();
|
||||
|
||||
/**
|
||||
* Register a drag event.
|
||||
*
|
||||
* @param oldX The x coordinate of the drag start position (dragged from)
|
||||
* @param oldY The y coordinate of the drag start position (dragged from)
|
||||
* @param newX The x coordinate of the new position (dragged to)
|
||||
* @param newY The y coordinate of the new position (dragged to)
|
||||
*
|
||||
* @return True if the drag exceeds threshold value (and therefore was reported as a
|
||||
* drag), or false if the drag did not exceed threshold (and therefore was
|
||||
* discarded).
|
||||
*/
|
||||
bool registerDragEvent(uint16_t oldX, uint16_t oldY, uint16_t newX, uint16_t newY);
|
||||
|
||||
/**
|
||||
* Register a click event and figure out if this is a drag event, too.
|
||||
*
|
||||
* @param event The type of the click event.
|
||||
* @param x The x coordinate of the click event.
|
||||
* @param y The y coordinate of the click event.
|
||||
*/
|
||||
void registerClickEvent(ClickEvent::ClickEventType event, uint16_t x, uint16_t y);
|
||||
|
||||
/**
|
||||
* Configure the threshold for reporting drag events. A touch input movement must exceed
|
||||
* this value in either axis in order to report a drag. Default value is 0.
|
||||
*
|
||||
* @param val New threshold value.
|
||||
*/
|
||||
void setDragThreshold(uint16_t val)
|
||||
{
|
||||
dragThresholdValue = val;
|
||||
}
|
||||
|
||||
private:
|
||||
DragState drag;
|
||||
UIEventListener* listener;
|
||||
uint16_t dragThresholdValue;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_GESTURES_HPP
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,91 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/NoDMA.hpp
|
||||
*
|
||||
* Declares the touchgfx::NoDMA class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_NODMA_HPP
|
||||
#define TOUCHGFX_NODMA_HPP
|
||||
|
||||
#include <assert.h>
|
||||
#include <touchgfx/hal/BlitOp.hpp>
|
||||
#include <touchgfx/hal/DMA.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* This is an "empty" DMA subclass that does nothing except assert if accidentally used. An
|
||||
* instance of this object can be used if DMA support is not desired.
|
||||
*
|
||||
* @see DMA_Interface
|
||||
*/
|
||||
class NoDMA : public DMA_Interface
|
||||
{
|
||||
public:
|
||||
NoDMA()
|
||||
: DMA_Interface(q), q(&b, 1)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* No blit operations supported by this DMA implementation.
|
||||
*
|
||||
* @return Zero (no blit ops supported).
|
||||
*/
|
||||
virtual BlitOperations getBlitCaps()
|
||||
{
|
||||
return static_cast<BlitOperations>(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts if used.
|
||||
*
|
||||
* @param blitOp The blit operation to be performed by this DMA instance.
|
||||
*/
|
||||
virtual void setupDataCopy(const BlitOp& blitOp)
|
||||
{
|
||||
assert(false && "DMA operation not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts if used.
|
||||
*
|
||||
* @param blitOp The blit operation to be performed by this DMA instance.
|
||||
*/
|
||||
virtual void setupDataFill(const BlitOp& blitOp)
|
||||
{
|
||||
assert(false && "DMA operation not supported");
|
||||
}
|
||||
|
||||
/** Does nothing. */
|
||||
virtual void signalDMAInterrupt()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Block until all DMA transfers are complete. Since this particular DMA does not do
|
||||
* anything, return immediately.
|
||||
*/
|
||||
virtual void flush()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
LockFreeDMA_Queue q;
|
||||
BlitOp b;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_NODMA_HPP
|
||||
@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/OSWrappers.hpp
|
||||
*
|
||||
* Declares the touchgfx::OSWrappers class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_OSWRAPPERS_HPP
|
||||
#define TOUCHGFX_OSWRAPPERS_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* This class specifies OS wrappers for dealing with the framebuffer semaphore and the VSYNC
|
||||
* signal.
|
||||
*/
|
||||
class OSWrappers
|
||||
{
|
||||
public:
|
||||
/** Initialize framebuffer semaphore and queue/mutex for VSYNC signal. */
|
||||
static void initialize();
|
||||
|
||||
/** Initialize framebuffer semaphore and queue/mutex for VSYNC signal. */
|
||||
static void deinitialize();
|
||||
|
||||
/**
|
||||
* Signal that a VSYNC has occurred. Should make the vsync queue/mutex available.
|
||||
*
|
||||
* @note This function is called from an ISR, and should (depending on OS) trigger a
|
||||
* scheduling.
|
||||
*/
|
||||
static void signalVSync();
|
||||
|
||||
/**
|
||||
* Signal that the rendering of the frame has completed. Used by
|
||||
* some systems to avoid using any previous vsync.
|
||||
*/
|
||||
static void signalRenderingDone();
|
||||
|
||||
/**
|
||||
* This function blocks until a VSYNC occurs.
|
||||
*
|
||||
* @note This function must first clear the mutex/queue and then wait for the next one to
|
||||
* occur.
|
||||
*/
|
||||
static void waitForVSync();
|
||||
|
||||
/**
|
||||
* This function checks if a VSync occurred after last
|
||||
* rendering. The function is used in systems that cannot wait in
|
||||
* waitForVSync (because they are also checking other event
|
||||
* sources.
|
||||
*
|
||||
* @note signalRenderingDone is typically used together with this function.
|
||||
*
|
||||
* @return True if VSync occurred.
|
||||
*/
|
||||
static bool isVSyncAvailable();
|
||||
|
||||
/** Take the framebuffer semaphore. Blocks until semaphore is available. */
|
||||
static void takeFrameBufferSemaphore();
|
||||
|
||||
/**
|
||||
* Attempt to obtain the framebuffer semaphore. If semaphore is not available, do
|
||||
* nothing.
|
||||
*
|
||||
* @note must return immediately! This function does not care who has the taken the semaphore,
|
||||
* it only serves to make sure that the semaphore is taken by someone.
|
||||
*/
|
||||
static void tryTakeFrameBufferSemaphore();
|
||||
|
||||
/** Release the framebuffer semaphore. */
|
||||
static void giveFrameBufferSemaphore();
|
||||
|
||||
/**
|
||||
* Release the framebuffer semaphore in a way that is safe in interrupt context. Called
|
||||
* from ISR.
|
||||
*/
|
||||
static void giveFrameBufferSemaphoreFromISR();
|
||||
|
||||
/**
|
||||
* A function that causes executing task to sleep for a number of milliseconds. This
|
||||
* function is OPTIONAL. It is only used by the TouchGFX in the case of a specific frame
|
||||
* refresh strategy (REFRESH_STRATEGY_OPTIM_SINGLE_BUFFER_TFT_CTRL). Due to backwards
|
||||
* compatibility, in order for this function to be usable by the HAL the function must
|
||||
* be explicitly registered:
|
||||
* hal.registerTaskDelayFunction(&OSWrappers::taskDelay)
|
||||
*
|
||||
* @param ms The number of milliseconds to sleep.
|
||||
*
|
||||
* @see HAL::setFrameRefreshStrategy, HAL::registerTaskDelayFunction
|
||||
*/
|
||||
static void taskDelay(uint16_t ms);
|
||||
|
||||
/**
|
||||
* A function that causes the executing task to yield control to
|
||||
* another thread. This function is used by the framework when it
|
||||
* is necessary to wait a little before continuing (e.g. drawing).
|
||||
*
|
||||
* The implementation should typically request the operating
|
||||
* system to change to another task of similar priority. When
|
||||
* running without an operating system, the implementation can run
|
||||
* a very short task and return.
|
||||
*/
|
||||
static void taskYield();
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_OSWRAPPERS_HPP
|
||||
@ -0,0 +1,156 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/Paint.hpp
|
||||
*
|
||||
* Declares paint functions for widgets
|
||||
*/
|
||||
#ifndef TOUCHGFX_PAINT_HPP
|
||||
#define TOUCHGFX_PAINT_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
namespace paint
|
||||
{
|
||||
/**
|
||||
* Sets L8 palette to be used by the painter. The content pointed to be parameter data depends
|
||||
* on the actual L8 format. L8RGB8888 assumes data points to three bytes per palette index,. L8ARGB8888 assumes four bytes per palette index.
|
||||
*
|
||||
* @param data The palette data.
|
||||
*/
|
||||
void setL8Palette(const uint8_t* const data);
|
||||
|
||||
/** Tear down painter - wait for pending draw operations to finish. */
|
||||
void tearDown(void);
|
||||
|
||||
namespace rgb565
|
||||
{
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using the given color.
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param color The color.
|
||||
* @param alpha The alpha.
|
||||
* @param color565 The color565 (same as 'color' but in native format for speed reasons).
|
||||
*/
|
||||
void lineFromColor(uint16_t* const ptr, const unsigned count, const uint32_t color, const uint8_t alpha, const uint32_t color565);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (RGB565
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The RGB5656 data.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromRGB565(uint16_t* const ptr, const uint16_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (ARGB8888
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The ARGB8888 data.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromARGB8888(uint16_t* const ptr, const uint32_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (L8RGB888
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The palette indices.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromL8RGB888(uint16_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (L8ARGB8888
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The palette indices.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromL8ARGB8888(uint16_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha);
|
||||
} // namespace rgb565
|
||||
|
||||
namespace rgb888
|
||||
{
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using the given color.
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param color The color.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromColor(uint8_t* const ptr, const unsigned count, const uint32_t color, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (RGB565
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The RGB888 data.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromRGB888(uint8_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (ARGB8888
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The ARGB8888 data.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromARGB8888(uint8_t* const ptr, const uint32_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (L8RGB888
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The palette indices.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromL8RGB888(uint8_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Draw a horizontal line (one pixel high) using pixels from the given data pointer (L8ARGB8888
|
||||
* data).
|
||||
*
|
||||
* @param [in] ptr The pointer to the position in the framebuffer.
|
||||
* @param data The palette indices.
|
||||
* @param count Number of pixels to draw.
|
||||
* @param alpha The alpha.
|
||||
*/
|
||||
void lineFromL8ARGB8888(uint8_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha);
|
||||
|
||||
} // namespace rgb888
|
||||
} // namespace paint
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_PAINT_HPP
|
||||
@ -0,0 +1,44 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/PaintImpl.hpp
|
||||
*
|
||||
* Declares paint functions for widgets
|
||||
*/
|
||||
#ifndef TOUCHGFX_PAINTIMPL_HPP
|
||||
#define TOUCHGFX_PAINTIMPL_HPP
|
||||
|
||||
#include <touchgfx/hal/Paint.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
namespace paint
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const uint8_t* blendL8CLUT = 0;
|
||||
} //namespace
|
||||
|
||||
void setL8Palette(const uint8_t* const data)
|
||||
{
|
||||
blendL8CLUT = data;
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace paint
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_PAINTIMPL_HPP
|
||||
@ -0,0 +1,210 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/PaintRGB565Impl.hpp
|
||||
*
|
||||
* Implements RGB565 software painter functions for widgets
|
||||
*/
|
||||
#ifndef TOUCHGFX_PAINTRGB565IMPL_HPP
|
||||
#define TOUCHGFX_PAINTRGB565IMPL_HPP
|
||||
|
||||
#include <touchgfx/Color.hpp>
|
||||
#include <touchgfx/hal/Paint.hpp>
|
||||
#include <touchgfx/hal/PaintImpl.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
namespace paint
|
||||
{
|
||||
namespace rgb565
|
||||
{
|
||||
namespace
|
||||
{
|
||||
const uint16_t RMASK = 0xF800; // Mask for red (1111100000000000)
|
||||
const uint16_t GMASK = 0x07E0; // Mask for green (0000011111100000)
|
||||
const uint16_t BMASK = 0x001F; // Mask for blue (0000000000011111)
|
||||
} //namespace
|
||||
|
||||
/**
|
||||
* Mix colors from a new pixel and a buffer pixel with the given alpha applied to the
|
||||
* new pixel, and the inverse alpha applied to the buffer pixel.
|
||||
*
|
||||
* @param R The red color (0-31 shifted into RMASK).
|
||||
* @param G The green color (0-63 shifted into GMASK).
|
||||
* @param B The blue color (0-31 shifted into BMASK).
|
||||
* @param bufpix The buffer pixel value.
|
||||
* @param alpha The alpha of the R,G,B.
|
||||
*
|
||||
* @return The result of blending the two colors into a new color.
|
||||
*/
|
||||
FORCE_INLINE_FUNCTION uint16_t alphaBlend(uint16_t R, uint16_t G, uint16_t B, uint16_t bufpix, uint8_t alpha)
|
||||
{
|
||||
const uint8_t ialpha = 0xFF - alpha;
|
||||
return (((R * alpha + (bufpix & RMASK) * ialpha) / 255) & RMASK) |
|
||||
(((G * alpha + (bufpix & GMASK) * ialpha) / 255) & GMASK) |
|
||||
(((B * alpha + (bufpix & BMASK) * ialpha) / 255) & BMASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mix colors from a new pixel and a buffer pixel with the given alpha applied to the
|
||||
* new pixel, and the inverse alpha applied to the buffer pixel.
|
||||
*
|
||||
* @param newpix The new pixel value.
|
||||
* @param bufpix The buffer pixel value.
|
||||
* @param alpha The alpha to apply to the new pixel.
|
||||
*
|
||||
* @return The result of blending the two colors into a new color.
|
||||
*/
|
||||
FORCE_INLINE_FUNCTION uint16_t alphaBlend(uint16_t newpix, uint16_t bufpix, uint8_t alpha)
|
||||
{
|
||||
return alphaBlend(newpix & RMASK, newpix & GMASK, newpix & BMASK, bufpix, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a color representation to be used on the LCD, based on 24 bit RGB values.
|
||||
*
|
||||
* @param color The color.
|
||||
*
|
||||
* @return The color representation depending on LCD color format.
|
||||
*/
|
||||
FORCE_INLINE_FUNCTION uint16_t getNativeColor(colortype color)
|
||||
{
|
||||
return ((color >> 8) & 0xF800) | ((color >> 5) & 0x07E0) | ((color >> 3) & 0x001F);
|
||||
}
|
||||
|
||||
void lineFromColor(uint16_t* const ptr, const unsigned count, const uint32_t color, const uint8_t alpha, const uint32_t color565)
|
||||
{
|
||||
uint16_t* framebuffer = ptr;
|
||||
const uint16_t* const lineEnd = framebuffer + count;
|
||||
if (alpha == 0xFF)
|
||||
{
|
||||
do
|
||||
{
|
||||
*framebuffer = color565;
|
||||
} while (++framebuffer < lineEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
*framebuffer = alphaBlend(color565, *framebuffer, alpha);
|
||||
} while (++framebuffer < lineEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void lineFromRGB565(uint16_t* const ptr, const uint16_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint16_t* framebuffer = ptr;
|
||||
const uint16_t* bitmapPointer = data;
|
||||
const uint16_t* const chunkend = framebuffer + count;
|
||||
|
||||
if (alpha == 0xFF)
|
||||
{
|
||||
do
|
||||
{
|
||||
*framebuffer = *bitmapPointer++;
|
||||
} while (++framebuffer < chunkend);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
*framebuffer = alphaBlend(*bitmapPointer++, *framebuffer, alpha);
|
||||
} while (++framebuffer < chunkend);
|
||||
}
|
||||
}
|
||||
|
||||
void lineFromARGB8888(uint16_t* const ptr, const uint32_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint16_t* framebuffer = ptr;
|
||||
const uint32_t* bitmapPointer = data;
|
||||
const uint16_t* const chunkend = framebuffer + count;
|
||||
do
|
||||
{
|
||||
const uint8_t srcAlpha = (*bitmapPointer) >> 24;
|
||||
const uint8_t a = LCD::div255(alpha * srcAlpha);
|
||||
if (a == 0xFF)
|
||||
{
|
||||
*framebuffer = getNativeColor(*bitmapPointer);
|
||||
}
|
||||
else if (a)
|
||||
{
|
||||
const uint32_t newpix = *bitmapPointer;
|
||||
*framebuffer = alphaBlend((newpix >> 8) & RMASK, (newpix >> 5) & GMASK, (newpix >> 3) & BMASK, *framebuffer, a);
|
||||
}
|
||||
bitmapPointer++;
|
||||
} while (++framebuffer < chunkend);
|
||||
}
|
||||
|
||||
void lineFromL8RGB888(uint16_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint16_t* framebuffer = ptr;
|
||||
const uint8_t* bitmapPointer = data;
|
||||
const uint16_t* const chunkend = framebuffer + count;
|
||||
if (alpha == 0xFF)
|
||||
{
|
||||
do
|
||||
{
|
||||
const uint8_t* src = &blendL8CLUT[*bitmapPointer++ * 3];
|
||||
// Use alpha from covers directly
|
||||
const uint8_t blue = *src++;
|
||||
const uint8_t green = *src++;
|
||||
const uint8_t red = *src;
|
||||
*framebuffer = ((red << 8) & RMASK) | ((green << 3) & GMASK) | ((blue >> 3) & BMASK);
|
||||
} while (++framebuffer < chunkend);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
const uint8_t* src = &blendL8CLUT[*bitmapPointer++ * 3];
|
||||
// Use alpha from covers directly
|
||||
const uint8_t blue = *src++;
|
||||
const uint8_t green = *src++;
|
||||
const uint8_t red = *src;
|
||||
const uint8_t ialpha = 0xFF - alpha;
|
||||
const uint16_t bufpix = *framebuffer;
|
||||
uint8_t fbr = Color::getRedFromRGB565(bufpix);
|
||||
uint8_t fbg = Color::getGreenFromRGB565(bufpix);
|
||||
uint8_t fbb = Color::getBlueFromRGB565(bufpix);
|
||||
*framebuffer = ((LCD::div255(red * alpha + fbr * ialpha) << 8) & RMASK) | ((LCD::div255(green * alpha + fbg * ialpha) << 3) & GMASK) | ((LCD::div255(blue * alpha + fbb * ialpha) >> 3) & BMASK);
|
||||
} while (++framebuffer < chunkend);
|
||||
}
|
||||
}
|
||||
|
||||
void lineFromL8ARGB8888(uint16_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint16_t* framebuffer = ptr;
|
||||
const uint8_t* bitmapPointer = data;
|
||||
const uint16_t* const chunkend = framebuffer + count;
|
||||
do
|
||||
{
|
||||
const uint32_t newpix = reinterpret_cast<const uint32_t*>(blendL8CLUT)[*bitmapPointer++];
|
||||
const uint8_t srcAlpha = newpix >> 24;
|
||||
const uint8_t a = LCD::div255(alpha * srcAlpha);
|
||||
if (a == 0xFF)
|
||||
{
|
||||
*framebuffer = getNativeColor(newpix);
|
||||
}
|
||||
else if (a)
|
||||
{
|
||||
*framebuffer = alphaBlend((newpix >> 8) & RMASK, (newpix >> 5) & GMASK, (newpix >> 3) & BMASK, *framebuffer, a);
|
||||
}
|
||||
} while (++framebuffer < chunkend);
|
||||
}
|
||||
|
||||
} // namespace rgb565
|
||||
} // namespace paint
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_PAINTRGB565IMPL_HPP
|
||||
@ -0,0 +1,187 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/PaintRGB888Impl.hpp
|
||||
*
|
||||
* Implements RGB888 software painter functions for widgets
|
||||
*/
|
||||
#ifndef TOUCHGFX_PAINTRGB888IMPL_HPP
|
||||
#define TOUCHGFX_PAINTRGB888IMPL_HPP
|
||||
|
||||
#include <touchgfx/Color.hpp>
|
||||
#include <touchgfx/hal/Paint.hpp>
|
||||
#include <touchgfx/hal/PaintImpl.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
namespace paint
|
||||
{
|
||||
namespace rgb888
|
||||
{
|
||||
void lineFromColor(uint8_t* const ptr, const unsigned count, const uint32_t color, const uint8_t alpha)
|
||||
{
|
||||
uint8_t* framebuffer = ptr;
|
||||
const uint8_t* const lineEnd = framebuffer + count * 3;
|
||||
const uint8_t painterRed = Color::getRed(color);
|
||||
const uint8_t painterGreen = Color::getGreen(color);
|
||||
const uint8_t painterBlue = Color::getBlue(color);
|
||||
|
||||
if (alpha == 0xFF)
|
||||
{
|
||||
do
|
||||
{
|
||||
*framebuffer++ = painterBlue;
|
||||
*framebuffer++ = painterGreen;
|
||||
*framebuffer++ = painterRed;
|
||||
} while (framebuffer < lineEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
const uint8_t ialpha = 0xFF - alpha;
|
||||
uint8_t pByte = *framebuffer;
|
||||
*framebuffer++ = LCD::div255(painterBlue * alpha + pByte * ialpha);
|
||||
pByte = *framebuffer;
|
||||
*framebuffer++ = LCD::div255(painterGreen * alpha + pByte * ialpha);
|
||||
pByte = *framebuffer;
|
||||
*framebuffer++ = LCD::div255(painterRed * alpha + pByte * ialpha);
|
||||
} while (framebuffer < lineEnd);
|
||||
}
|
||||
}
|
||||
|
||||
void lineFromRGB888(uint8_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint8_t* framebuffer = ptr;
|
||||
const uint8_t* bitmapPointer = data;
|
||||
const uint8_t* const chunkend = framebuffer + count * 3;
|
||||
if (alpha == 0xFF)
|
||||
{
|
||||
do
|
||||
{
|
||||
*framebuffer++ = *bitmapPointer++;
|
||||
*framebuffer++ = *bitmapPointer++;
|
||||
*framebuffer++ = *bitmapPointer++;
|
||||
} while (framebuffer < chunkend);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
const uint8_t ialpha = 0xFF - alpha;
|
||||
*framebuffer = LCD::div255(*bitmapPointer++ * alpha + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
*framebuffer = LCD::div255(*bitmapPointer++ * alpha + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
*framebuffer = LCD::div255(*bitmapPointer++ * alpha + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
} while (framebuffer < chunkend);
|
||||
}
|
||||
}
|
||||
|
||||
void lineFromARGB8888(uint8_t* const ptr, const uint32_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint8_t* framebuffer = ptr;
|
||||
const uint32_t* bitmapPointer = data;
|
||||
const uint8_t* const chunkend = framebuffer + count * 3;
|
||||
do
|
||||
{
|
||||
const uint32_t argb = *bitmapPointer++;
|
||||
const uint8_t a = LCD::div255(alpha * (argb >> 24));
|
||||
if (a == 0xFF)
|
||||
{
|
||||
*framebuffer++ = argb; // Blue
|
||||
*framebuffer++ = argb >> 8; // Green
|
||||
*framebuffer++ = argb >> 16; // Red
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint8_t ialpha = 0xFF - a;
|
||||
uint8_t cByte = argb;
|
||||
*framebuffer = LCD::div255(cByte * a + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
cByte = argb >> 8;
|
||||
*framebuffer = LCD::div255(cByte * a + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
cByte = argb >> 16;
|
||||
*framebuffer = LCD::div255(cByte * a + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
}
|
||||
} while (framebuffer < chunkend);
|
||||
}
|
||||
|
||||
void lineFromL8RGB888(uint8_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint8_t* framebuffer = ptr;
|
||||
const uint8_t* bitmapPointer = data;
|
||||
const uint8_t* const chunkend = framebuffer + count * 3;
|
||||
if (alpha == 0xFF)
|
||||
{
|
||||
do
|
||||
{
|
||||
const uint8_t* src = &blendL8CLUT[*bitmapPointer++ * 3];
|
||||
*framebuffer++ = *src++;
|
||||
*framebuffer++ = *src++;
|
||||
*framebuffer++ = *src;
|
||||
} while (framebuffer < chunkend);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
const uint8_t* src = &blendL8CLUT[*bitmapPointer++ * 3];
|
||||
const uint8_t ialpha = 0xFF - alpha;
|
||||
*framebuffer = LCD::div255(*src++ * alpha + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
*framebuffer = LCD::div255(*src++ * alpha + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
*framebuffer = LCD::div255(*src * alpha + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
} while (framebuffer < chunkend);
|
||||
}
|
||||
}
|
||||
|
||||
void lineFromL8ARGB8888(uint8_t* const ptr, const uint8_t* const data, const unsigned count, const uint8_t alpha)
|
||||
{
|
||||
uint8_t* framebuffer = ptr;
|
||||
const uint8_t* bitmapPointer = data;
|
||||
const uint8_t* const chunkend = framebuffer + count * 3;
|
||||
do
|
||||
{
|
||||
uint32_t src = reinterpret_cast<const uint32_t*>(blendL8CLUT)[*bitmapPointer++];
|
||||
const uint8_t srcAlpha = src >> 24;
|
||||
const uint8_t a = LCD::div255(alpha * srcAlpha);
|
||||
if (a == 0xFF)
|
||||
{
|
||||
*framebuffer++ = src; // Blue
|
||||
*framebuffer++ = src >> 8; // Green
|
||||
*framebuffer++ = src >> 16; // Red
|
||||
}
|
||||
else
|
||||
{
|
||||
const uint8_t ialpha = 0xFF - a;
|
||||
*framebuffer = LCD::div255((src & 0xFF) * a + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
*framebuffer = LCD::div255(((src >> 8) & 0xFF) * a + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
*framebuffer = LCD::div255(((src >> 16) & 0xFF) * a + *framebuffer * ialpha);
|
||||
framebuffer++;
|
||||
}
|
||||
} while (framebuffer < chunkend);
|
||||
}
|
||||
|
||||
} // namespace rgb888
|
||||
} // namespace paint
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_PAINTRGB888IMPL_HPP
|
||||
@ -0,0 +1,82 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/PartialFrameBufferManager.hpp
|
||||
*
|
||||
* Declares the touchgfx::PartialFrameBufferManager class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_PARTIALFRAMEBUFFERMANAGER_HPP
|
||||
#define TOUCHGFX_PARTIALFRAMEBUFFERMANAGER_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Check if a Frame Buffer Block is being transmitted.
|
||||
*
|
||||
* @return Non zero if possible.
|
||||
*/
|
||||
int transmitActive();
|
||||
|
||||
/**
|
||||
* Check if a Frame Buffer Block ending at bottom may be sent.
|
||||
*
|
||||
* @param bottom The bottom coordinate of the block to transfer.
|
||||
*
|
||||
* @return Non zero if possible.
|
||||
*/
|
||||
int shouldTransferBlock(uint16_t bottom);
|
||||
|
||||
/**
|
||||
* Transmit a Frame Buffer Block.
|
||||
*
|
||||
* @param pixels Pointer to the pixel data.
|
||||
* @param x X coordinate of the block.
|
||||
* @param y Y coordinate of the block.
|
||||
* @param w Width of the block.
|
||||
* @param h Height of the block.
|
||||
*/
|
||||
void transmitBlock(const uint8_t* pixels, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
|
||||
/**
|
||||
* This class specifies strategies for transmitting block to the display using Partial Frame Buffer.
|
||||
*/
|
||||
class PartialFrameBufferManager
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Transmit all remaining drawn Framebuffer blocks.
|
||||
*
|
||||
* @note This function does not return before all blocks have been transmitted.
|
||||
*/
|
||||
static void transmitRemainingBlocks();
|
||||
|
||||
/**
|
||||
* Tries to transmit a drawn block.
|
||||
*
|
||||
* @note Will return immediately if already transmitting.
|
||||
*/
|
||||
static void tryTransmitBlock();
|
||||
|
||||
/**
|
||||
* Tries to transmit a drawn block in interrupt context.
|
||||
*
|
||||
* @note Will transmit next block immediately if drawn.
|
||||
*/
|
||||
static void tryTransmitBlockFromIRQ();
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_PARTIALFRAMEBUFFERMANAGER_HPP
|
||||
@ -0,0 +1,793 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/Types.hpp
|
||||
*
|
||||
* Declares the touchgfx::colortype, touchgfx::Rect, touchgfx::Vector, touchgfx::Point,
|
||||
* touchgfx::Pair classes as well as some less used classes and structs.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TYPES_HPP
|
||||
#define TOUCHGFX_TYPES_HPP
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <touchgfx/hal/Config.hpp>
|
||||
|
||||
/**
|
||||
* A macro that returns the smallest of two items.
|
||||
*
|
||||
* @param a The first item.
|
||||
* @param b The second item.
|
||||
*/
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A macro that returns the largest of two items.
|
||||
*
|
||||
* @param a The first item.
|
||||
* @param b The second item.
|
||||
*/
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A macro that rounds a number up to the next multiple. Works for negative numbers, too.
|
||||
*
|
||||
* @param num The number to round up.
|
||||
* @param multiple The multiple.
|
||||
*/
|
||||
#ifndef ROUNDUP
|
||||
#define ROUNDUP(num, multiple) ((multiple) == 0 ? (num) : ((num) + (abs(multiple) - ((num) % abs(multiple))) % abs(multiple)))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A macro that rounds a number down to the next multiple. Works for negative numbers, too.
|
||||
*
|
||||
* @param num The number to round down.
|
||||
* @param multiple The multiple.
|
||||
*/
|
||||
#ifndef ROUNDDOWN
|
||||
#define ROUNDDOWN(num, multiple) (-(ROUNDUP(-(num), multiple)))
|
||||
#endif
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
static const float PI = 3.14159265358979323846f; ///< PI
|
||||
|
||||
/**
|
||||
* This type can contain a color value. Note that in order to maintain backwards
|
||||
* compatibility, casting this type to an integral value will yield a 16-bit value. To
|
||||
* extract a 24/32-bit color from this type, use the getColor32 function.
|
||||
*/
|
||||
struct colortype
|
||||
{
|
||||
/** Default constructor. Creates a black (0) color. */
|
||||
colortype()
|
||||
: color(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which creates a colortype with the given color. Use
|
||||
* Color::getColorFromRGB() to create a color that will work on your selected LCD type.
|
||||
*
|
||||
* @param col The color.
|
||||
*
|
||||
* @see Color::getColorFromRGB
|
||||
*/
|
||||
colortype(uint32_t col)
|
||||
: color(col)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets color as a 32bit value suitable for passing to Color::getRed(),
|
||||
* Color::getGreen() and Color::getBlue() which will handle all bitdeptchs.
|
||||
*
|
||||
* @return The color 32.
|
||||
*
|
||||
* @see Color::getRed, Color::getGreen, Color::getBlue
|
||||
*/
|
||||
FORCE_INLINE_FUNCTION uint32_t getColor32() const
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast that converts the given colortype to an uint32_t.
|
||||
*
|
||||
* @return The result of the operation.
|
||||
*/
|
||||
operator uint32_t() const
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
uint32_t color; ///< The color
|
||||
};
|
||||
|
||||
/** Class representing a Rectangle with a few convenient methods. */
|
||||
class Rect
|
||||
{
|
||||
public:
|
||||
/** Default constructor. Resulting in an empty Rect with coordinates 0,0. */
|
||||
Rect()
|
||||
: x(0), y(0), width(0), height(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the Rect class.
|
||||
*
|
||||
* @param rectX The x coordinate.
|
||||
* @param rectY The y coordinate.
|
||||
* @param rectWidth The width.
|
||||
* @param rectHeight The height.
|
||||
*/
|
||||
Rect(int16_t rectX, int16_t rectY, int16_t rectWidth, int16_t rectHeight)
|
||||
: x(rectX), y(rectY), width(rectWidth), height(rectHeight)
|
||||
{
|
||||
}
|
||||
|
||||
int16_t x; ///< The x coordinate
|
||||
int16_t y; ///< The y coordinate
|
||||
int16_t width; ///< The width
|
||||
int16_t height; ///< The height
|
||||
|
||||
/**
|
||||
* Gets the x coordinate of the right edge of the Rect, i.e. the number
|
||||
* of the first column just to the right of the Rect.
|
||||
*
|
||||
* @return x coordinate of the right edge (calculated as "x + width").
|
||||
*/
|
||||
FORCE_INLINE_FUNCTION int16_t right() const
|
||||
{
|
||||
return x + width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the y coordinate of the bottom edge of the Rect, i.e. the number
|
||||
* of the first row just below the Rect.
|
||||
*
|
||||
* @return y coordinate of the bottom edge (calculated as "y + height").
|
||||
*/
|
||||
FORCE_INLINE_FUNCTION int16_t bottom() const
|
||||
{
|
||||
return y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether specified point lies inside this rectangle.
|
||||
*
|
||||
* @param otherX The x coordinate of the point.
|
||||
* @param otherY The y coordinate of the point.
|
||||
*
|
||||
* @return true if point lies inside rectangle.
|
||||
*/
|
||||
bool intersect(int16_t otherX, int16_t otherY) const
|
||||
{
|
||||
return otherX >= x && otherX < right() && otherY >= y && otherY < bottom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether specified rectangle intersects with this rectangle.
|
||||
*
|
||||
* @param other The other rectangle.
|
||||
*
|
||||
* @return true if the two rectangles intersect.
|
||||
*/
|
||||
bool intersect(const Rect& other) const
|
||||
{
|
||||
return !(x >= other.right() || right() <= other.x || y >= other.bottom() || bottom() <= other.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the specified rectangle is completely included in this rectangle.
|
||||
*
|
||||
* @param other The other rectangle.
|
||||
*
|
||||
* @return true if the specified rectangle is completely included.
|
||||
*/
|
||||
bool includes(const Rect& other) const
|
||||
{
|
||||
return other.isEmpty() || (other.x >= x && other.y >= y && other.right() <= right() && other.bottom() <= bottom());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a rectangle describing the intersecting area between this rectangle and the
|
||||
* supplied rectangle.
|
||||
*
|
||||
* @param other The other rectangle.
|
||||
*
|
||||
* @return Intersecting rectangle or empty Rect in case of no intersection.
|
||||
*/
|
||||
Rect operator&(const Rect& other) const
|
||||
{
|
||||
Rect r = *this;
|
||||
r &= other;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns this Rect to the intersection of the current Rect and the assigned Rect. The
|
||||
* assignment will result in a empty Rect if they do not intersect.
|
||||
*
|
||||
* @param other The rect to intersect with.
|
||||
*/
|
||||
void operator&=(const Rect& other)
|
||||
{
|
||||
if (intersect(other))
|
||||
{
|
||||
int16_t newX = MAX(x, other.x);
|
||||
int16_t newY = MAX(y, other.y);
|
||||
|
||||
width = MIN(right(), other.right()) - newX;
|
||||
height = MIN(bottom(), other.bottom()) - newY;
|
||||
x = newX;
|
||||
y = newY;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the area covered by this rectangle to encompass the area covered by
|
||||
* supplied rectangle.
|
||||
*
|
||||
* @param other The other rectangle.
|
||||
*/
|
||||
void expandToFit(const Rect& other)
|
||||
{
|
||||
if (!other.isEmpty())
|
||||
{
|
||||
if (isEmpty())
|
||||
{
|
||||
x = other.x;
|
||||
y = other.y;
|
||||
width = other.width;
|
||||
height = other.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
int16_t newX = MIN(x, other.x);
|
||||
int16_t newY = MIN(y, other.y);
|
||||
|
||||
int16_t endPointX = MAX(right(), other.right());
|
||||
int16_t endPointY = MAX(bottom(), other.bottom());
|
||||
|
||||
x = newX;
|
||||
y = newY;
|
||||
width = endPointX - newX;
|
||||
height = endPointY - newY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restrict the area to not exceed the given max width and max height. As a result, width or
|
||||
* height can be negative if the rect is completely outside Rect(0, 0, max_width, max_height),
|
||||
* but this is nicely handled by the isEmpty() function.
|
||||
*
|
||||
* @param max_width The maximum width.
|
||||
* @param max_height The maximum height.
|
||||
*
|
||||
* @see intersect, isEmpty
|
||||
*/
|
||||
void restrictTo(int16_t max_width, int16_t max_height)
|
||||
{
|
||||
// Limit area to the screen (0,0,HAL::WIDTH,HAL::HEIGT)
|
||||
if (x < 0)
|
||||
{
|
||||
width += x;
|
||||
x = 0; // Negative width is ok (isEmpty => true)
|
||||
}
|
||||
if (width > max_width - x) // right() > max_width
|
||||
{
|
||||
width = max_width - x;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
height += y;
|
||||
y = 0; // Negative height is ok (isEmpty => true)
|
||||
}
|
||||
if (height > max_height - y) // bottom() > max_height
|
||||
{
|
||||
height = max_height - y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares equality of two Rect by the dimensions and position of these.
|
||||
*
|
||||
* @param other The Rect to compare with.
|
||||
*
|
||||
* @return true if the compared Rect have the same dimensions and coordinates.
|
||||
*/
|
||||
bool operator==(const Rect& other) const
|
||||
{
|
||||
return isEqual(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opposite of the == operator.
|
||||
*
|
||||
* @param other The Rect to compare with.
|
||||
*
|
||||
* @return true if the compared Rect differ in dimensions or coordinates.
|
||||
*/
|
||||
bool operator!=(const Rect& other) const
|
||||
{
|
||||
return !isEqual(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query if this object is empty.
|
||||
*
|
||||
* @return true if any of the dimensions are 0.
|
||||
*/
|
||||
bool isEmpty() const
|
||||
{
|
||||
return width <= 0 || height <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the area of the rectangle.
|
||||
*
|
||||
* @return area of the rectangle.
|
||||
*/
|
||||
int32_t area() const
|
||||
{
|
||||
return isEmpty() ? 0 : width * height;
|
||||
}
|
||||
|
||||
private:
|
||||
bool isEqual(const Rect& other) const
|
||||
{
|
||||
return x == other.x && y == other.y && width == other.width && height == other.height;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A very simple container class using pre-allocated memory.
|
||||
*
|
||||
* @tparam T The type of objects this container works on.
|
||||
* @tparam capacity The maximum number of objects this container can store.
|
||||
*/
|
||||
template <class T, uint16_t capacity>
|
||||
class Vector
|
||||
{
|
||||
public:
|
||||
/** Default constructor. Constructs an empty vector. */
|
||||
Vector()
|
||||
: _size(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Index operator.
|
||||
*
|
||||
* @param idx The index of the element to obtain.
|
||||
*
|
||||
* @return A reference to the element placed at index idx.
|
||||
*/
|
||||
T& operator[](uint16_t idx)
|
||||
{
|
||||
return _elem[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Const version of the index operator.
|
||||
*
|
||||
* @param idx The index of the element to obtain.
|
||||
*
|
||||
* @return A const reference to the element placed at index idx.
|
||||
*/
|
||||
const T& operator[](uint16_t idx) const
|
||||
{
|
||||
return _elem[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an element to the Vector if the Vector is not full.
|
||||
*
|
||||
*
|
||||
* Adds an element to the Vector if the Vector is not full. Does nothing if the Vector
|
||||
* is full.
|
||||
*
|
||||
* @param e The element to add to the Vector.
|
||||
*/
|
||||
void add(T e)
|
||||
{
|
||||
assert(_size < capacity && "Vector capacity exceeded");
|
||||
if (_size < capacity)
|
||||
{
|
||||
_elem[_size++] = e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element from the Vector if found in the Vector. Does nothing if the
|
||||
* element is not found in the Vector. The == operator of the element is used when
|
||||
* comparing it with the elements in the Vector.
|
||||
*
|
||||
* @param e The element to remove from the Vector.
|
||||
*/
|
||||
void remove(T e)
|
||||
{
|
||||
for (int i = 0; i < _size; i++)
|
||||
{
|
||||
if (_elem[i] == e)
|
||||
{
|
||||
for (int j = i; j < _size && j < capacity - 1; j++)
|
||||
{
|
||||
_elem[j] = _elem[j + 1];
|
||||
}
|
||||
_size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element at the specified index of the Vector. Will "bubble-down" any
|
||||
* remaining elements after the specified index.
|
||||
*
|
||||
* @param index The index to remove.
|
||||
*
|
||||
* @return The value of the removed element.
|
||||
*/
|
||||
T removeAt(uint16_t index)
|
||||
{
|
||||
assert(index < _size);
|
||||
|
||||
_size--;
|
||||
T tmp = _elem[index];
|
||||
for (int i = index; i < _size; i++)
|
||||
{
|
||||
_elem[i] = _elem[i + 1];
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an element at the specified index of the Vector. The last element in the list
|
||||
* is moved to the position where the element is removed.
|
||||
*
|
||||
* @param index The index to remove.
|
||||
*/
|
||||
void quickRemoveAt(uint16_t index)
|
||||
{
|
||||
assert(index < _size);
|
||||
|
||||
_size--;
|
||||
// No need to copy element when removing the last element in the vector
|
||||
if (index < _size)
|
||||
{
|
||||
_elem[index] = _elem[_size];
|
||||
}
|
||||
}
|
||||
|
||||
/** Reverses the ordering of the elements in the Vector. */
|
||||
void reverse()
|
||||
{
|
||||
uint16_t a = 0;
|
||||
uint16_t b = _size;
|
||||
for (; a < --b; a++)
|
||||
{
|
||||
T tmp = _elem[a];
|
||||
_elem[a] = _elem[b];
|
||||
_elem[b] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Vector contains an element. The == operator of the element is used when
|
||||
* comparing it with the elements in the Vector.
|
||||
*
|
||||
* @param elem The element.
|
||||
*
|
||||
* @return true if the Vector contains the element, false otherwise.
|
||||
*/
|
||||
bool contains(T elem)
|
||||
{
|
||||
for (uint16_t i = 0; i < _size; i++)
|
||||
{
|
||||
if (elem == _elem[i])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current size of the Vector which is the number of elements contained in the
|
||||
* Vector.
|
||||
*
|
||||
* Gets the current size of the Vector which is the number of elements contained in the
|
||||
* Vector.
|
||||
*
|
||||
* @return The size of the Vector.
|
||||
*/
|
||||
uint16_t size() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query if this object is empty.
|
||||
*
|
||||
* @return true if the Vector contains no elements.
|
||||
*/
|
||||
bool isEmpty() const
|
||||
{
|
||||
return _size == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the maximum capacity of the vector.
|
||||
*
|
||||
* @return The capacity the Vector was initialized with.
|
||||
*/
|
||||
uint16_t maxCapacity() const
|
||||
{
|
||||
return capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the contents of the container. It does not destruct any of the elements in the
|
||||
* Vector.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
_size = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
T _elem[capacity];
|
||||
uint16_t _size;
|
||||
};
|
||||
|
||||
/** A simple struct containing coordinates. */
|
||||
struct Point
|
||||
{
|
||||
int32_t x; ///< The x coordinate
|
||||
int32_t y; ///< The y coordinate
|
||||
|
||||
/**
|
||||
* The squared distance from this Point to another Point.
|
||||
*
|
||||
* @param [in] o The point to get the squared distance to.
|
||||
*
|
||||
* @return The squared distance.
|
||||
*/
|
||||
int32_t dist_sqr(struct Point& o)
|
||||
{
|
||||
return (x - o.x) * (x - o.x) + (y - o.y) * (y - o.y);
|
||||
}
|
||||
};
|
||||
|
||||
/** Values that represent directions. */
|
||||
enum Direction
|
||||
{
|
||||
NORTH, ///< An enum constant representing the north option
|
||||
SOUTH, ///< An enum constant representing the south option
|
||||
EAST, ///< An enum constant representing the east option
|
||||
WEST ///< An enum constant representing the west option
|
||||
};
|
||||
|
||||
/** Defines an alignment type. */
|
||||
typedef uint8_t Alignment;
|
||||
static const Alignment LEFT = 0; ///< Text is left aligned
|
||||
static const Alignment CENTER = 1; ///< Text is centered horizontally
|
||||
static const Alignment RIGHT = 2; ///< Text is right aligned
|
||||
|
||||
/** Defines a the direction to write text. */
|
||||
typedef uint8_t TextDirection;
|
||||
static const TextDirection TEXT_DIRECTION_LTR = 0; ///< Text is written Left-To-Right, e.g. English
|
||||
static const TextDirection TEXT_DIRECTION_RTL = 1; ///< Text is written Right-To-Left, e.g. Hebrew
|
||||
|
||||
/** Values that represent frame buffers. */
|
||||
enum FrameBuffer
|
||||
{
|
||||
FB_PRIMARY, ///< First framebuffer
|
||||
FB_SECONDARY, ///< Second framebuffer
|
||||
FB_TERTIARY ///< Third framebuffer
|
||||
};
|
||||
|
||||
/** Values that represent gradients. */
|
||||
enum Gradient
|
||||
{
|
||||
GRADIENT_HORIZONTAL, ///< Horizontal gradient.
|
||||
GRADIENT_VERTICAL ///< Vertical gradient
|
||||
};
|
||||
|
||||
/** Values that represent display rotations. */
|
||||
enum DisplayRotation
|
||||
{
|
||||
rotate0, ///< The display is oriented like the framebuffer
|
||||
rotate90 ///< The display is rotated 90 degrees compared to the framebuffer layout
|
||||
};
|
||||
|
||||
/** Values that represent display orientations. */
|
||||
enum DisplayOrientation
|
||||
{
|
||||
ORIENTATION_LANDSCAPE, ///< The display has more pixels from left to right than from top to bottom
|
||||
ORIENTATION_PORTRAIT ///< The display has more pixels from top to bottom than from right to left
|
||||
};
|
||||
|
||||
/** Values that represent text rotations. */
|
||||
enum TextRotation
|
||||
{
|
||||
TEXT_ROTATE_0, ///< Text is written from left to right
|
||||
TEXT_ROTATE_90, ///< Text is written from top to bottom
|
||||
TEXT_ROTATE_180, ///< Text is written from right to left (upside down)
|
||||
TEXT_ROTATE_270 ///< Text is written bottom to top
|
||||
};
|
||||
|
||||
/** Values that represent wide text actions. */
|
||||
enum WideTextAction
|
||||
{
|
||||
WIDE_TEXT_NONE, ///< Do nothing, simply cut the text in the middle of any character that extends beyond the width of the TextArea
|
||||
WIDE_TEXT_WORDWRAP, ///< Wrap between words, no ellipsis, keep wrapping lines
|
||||
WIDE_TEXT_WORDWRAP_ELLIPSIS, ///< Wrap between words, ellipsis anywhere "Very long t..."
|
||||
WIDE_TEXT_WORDWRAP_ELLIPSIS_AFTER_SPACE, ///< Wrap between words, ellipsis only after space "Very long ..."
|
||||
WIDE_TEXT_CHARWRAP, ///< Wrap between any two characters, no ellipsis, keep wrapping lines
|
||||
WIDE_TEXT_CHARWRAP_ELLIPSIS, ///< Wrap between any two characters, ellipsis anywhere, as used in Chinese
|
||||
WIDE_TEXT_CHARWRAP_DOUBLE_ELLIPSIS ///< Wrap between any two characters, double ellipsis anywhere, as used in Chinese
|
||||
};
|
||||
|
||||
/**
|
||||
* A simple struct for holding pairs of data.
|
||||
*
|
||||
* @tparam T1 The type of the first element.
|
||||
* @tparam T2 The type of the second element.
|
||||
*/
|
||||
template <class T1, class T2>
|
||||
struct Pair
|
||||
{
|
||||
public:
|
||||
T1 first; ///< The first element
|
||||
T2 second; ///< The second element
|
||||
|
||||
/**
|
||||
* Constructor initializing the elements it holds, using their default constructors.
|
||||
*/
|
||||
Pair()
|
||||
: first(T1()), second(T2())
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor initializing the elements it holds, using their copy constructor.
|
||||
*
|
||||
* @param x Reference to the first element.
|
||||
* @param y Reference to the second element.
|
||||
*/
|
||||
Pair(const T1& x, const T2& y)
|
||||
: first(x), second(y)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @tparam U Generic type parameter.
|
||||
* @tparam V Generic type parameter.
|
||||
* @param p The pair to copy from.
|
||||
*/
|
||||
template <class U, class V>
|
||||
Pair(const Pair<U, V>& p)
|
||||
: first(p.first), second(p.second)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes a combination of rendering algorithm, image format, and alpha information. The
|
||||
* lowest bit is 0 for "Nearest neighbor", 1 for "Bilinear". The next bit is "0" for "no
|
||||
* alpha", "2" for "alpha". The rest is the Bitmap::Format shifted up by 2.
|
||||
*/
|
||||
typedef uint16_t RenderingVariant;
|
||||
static const uint16_t RenderingVariant_NearestNeighbor = 0; ///< The rendering variant nearest neighbor bit value
|
||||
static const uint16_t RenderingVariant_Bilinear = 1; ///< The rendering variant bilinear bit value
|
||||
static const uint16_t RenderingVariant_NoAlpha = 0; ///< The rendering variant no alpha bit value
|
||||
static const uint16_t RenderingVariant_Alpha = 2; ///< The rendering variant alpha bit value
|
||||
static const uint16_t RenderingVariant_FormatShift = 2; ///< The rendering variant format shift
|
||||
|
||||
/** A fixed point value using 4 bits for the decimal part and 28 bits for the integral part. */
|
||||
typedef int32_t fixed28_4;
|
||||
|
||||
/** A fixed point value using 16 bits for the decimal part and 16 bits for the integral part. */
|
||||
typedef int32_t fixed16_16;
|
||||
|
||||
/** A 3D point. */
|
||||
struct Point3D
|
||||
{
|
||||
fixed28_4 X; ///< The X coordinate
|
||||
fixed28_4 Y; ///< The Y coordinate
|
||||
float Z; ///< The Z coordinate
|
||||
float U; ///< The U coordinate
|
||||
float V; ///< The V coordinate
|
||||
};
|
||||
|
||||
/**
|
||||
* A texture source. Contains a pointer to the data and the width and height of the texture. The
|
||||
* alpha channel is used in 565 rendering with alpha. The stride is the width used when
|
||||
* moving to the next line of the texture.
|
||||
*/
|
||||
struct TextureSurface
|
||||
{
|
||||
const uint16_t* data; ///< The pixel bits or indexes for color in CLUT entries
|
||||
const uint8_t* extraData; ///< The alpha channel or clut data
|
||||
int32_t width; ///< The width
|
||||
int32_t height; ///< The height
|
||||
int32_t stride; ///< The stride
|
||||
};
|
||||
|
||||
/**
|
||||
* The destination of a draw operation. Contains a pointer to where to draw and the stride of
|
||||
* the drawing surface.
|
||||
*/
|
||||
struct DrawingSurface
|
||||
{
|
||||
uint16_t* address; ///< The bits
|
||||
int32_t stride; ///< The stride
|
||||
};
|
||||
|
||||
/** Text IDs as generated by the text converter are simple uint16_t typedefs. */
|
||||
typedef uint16_t TypedTextId;
|
||||
|
||||
/** Values that represent dma types. */
|
||||
enum DMAType
|
||||
{
|
||||
DMA_TYPE_GENERIC, ///< Generic DMA Implementation
|
||||
DMA_TYPE_CHROMART ///< ChromART hardware DMA Implementation
|
||||
};
|
||||
|
||||
/**
|
||||
* A list of the vector graphics primitives.
|
||||
*
|
||||
* @see VectorRenderer::drawPath
|
||||
*/
|
||||
enum VectorPrimitives
|
||||
{
|
||||
VECTOR_PRIM_CLOSE = 0, ///< Close the path
|
||||
VECTOR_PRIM_MOVE = 1, ///< Move to a point
|
||||
VECTOR_PRIM_LINE = 2, ///< Line to a point from current position
|
||||
VECTOR_PRIM_HLINE = 3, ///< Horizontal line to a point from current position
|
||||
VECTOR_PRIM_VLINE = 4, ///< Vertical line to a point from current position
|
||||
VECTOR_PRIM_BEZIER_QUAD = 5, ///< Quadratic Bezier (1 control point) curve to a point from the current position
|
||||
VECTOR_PRIM_BEZIER_CUBIC = 6 ///< Cubic Bezier (2 control points) curve to a point from the current position
|
||||
};
|
||||
|
||||
/**
|
||||
* Dictionary entry used in LZW decompression.
|
||||
*/
|
||||
struct LZW9DictionaryEntry
|
||||
{
|
||||
uint8_t character; ///< Current character of the entry
|
||||
uint8_t length; ///< Remaining length of the entry
|
||||
uint16_t prefixIndex; ///< Index to previous character
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TYPES_HPP
|
||||
@ -0,0 +1,144 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/VectorRenderer.hpp
|
||||
*
|
||||
* Defines the touchgfx::VGShape, and the touchgfx::VGObject structs.
|
||||
*
|
||||
*/
|
||||
#ifndef TOUCHGFX_VGDATA_HPP
|
||||
#define TOUCHGFX_VGDATA_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of vector graphics polygon filling modes.
|
||||
*/
|
||||
enum VGFillMode
|
||||
{
|
||||
VG_FILL_EVEN_ODD, ///< Fill the paths using the even-odd filling rule
|
||||
VG_FILL_NON_ZERO ///< Fill the paths using the non-zero filling rule
|
||||
};
|
||||
|
||||
/**
|
||||
* A list of coloring modes. Each shape can have 2 coloring modes. One
|
||||
* for filling and one for stroking.
|
||||
*/
|
||||
enum VGColorMode
|
||||
{
|
||||
VG_NONE, ///< No coloring
|
||||
VG_FIXED_COLOR, ///< Color with a fixed color in the whole shape
|
||||
VG_LINEAR_GRADIENT ///< Color using a linear gradient
|
||||
};
|
||||
|
||||
/**
|
||||
* Values that represent the different ways strokes lines can be joined. Bevel is a simple cut off,
|
||||
* Miter extends into a spike (possibly falling back to Bevel if the miter limit for the stroke
|
||||
* is exceeded) and Round is a circle arc.
|
||||
*/
|
||||
enum VGStrokeLineJoin
|
||||
{
|
||||
VG_STROKE_LINEJOIN_BEVEL,
|
||||
VG_STROKE_LINEJOIN_MITER,
|
||||
VG_STROKE_LINEJOIN_ROUND
|
||||
};
|
||||
|
||||
/**
|
||||
* Values that represent the different ways stroke lines can end. Butt is a simpe cut off, Round
|
||||
* is a half circle and Square extends the line by half stroke width.
|
||||
*/
|
||||
enum VGStrokeLineCap
|
||||
{
|
||||
VG_STROKE_LINECAP_BUTT,
|
||||
VG_STROKE_LINECAP_ROUND,
|
||||
VG_STROKE_LINECAP_SQUARE
|
||||
};
|
||||
|
||||
/**
|
||||
* Fixed color paint definition.
|
||||
*/
|
||||
struct VGFixedColor
|
||||
{
|
||||
uint32_t argb; ///< The color in ARGB8888 format
|
||||
};
|
||||
|
||||
/**
|
||||
* Linear gradient paint definition.
|
||||
*/
|
||||
struct VGLinearGradient
|
||||
{
|
||||
const uint32_t* palette; ///< 1024 colors in ARGB888
|
||||
uint32_t stops; ///< Number of stops (colors)
|
||||
const float* stopPositions; ///< Stop positions on the vector
|
||||
const uint32_t* colors; ///< Stop colors
|
||||
float x0; ///< The gradient line start x
|
||||
float y0; ///< The gradient line start y
|
||||
float x1; ///< The gradient line end x
|
||||
float y1; ///< The gradient line end y
|
||||
bool isSolid; ///< True if all colors are solid
|
||||
};
|
||||
|
||||
/**
|
||||
* Data structure for a vector shape (polygon, circle, path, etc.).
|
||||
*
|
||||
* Shapes can be linked in a list using the next member. Shapes are linked to by a VGObject.
|
||||
* Which thereby consists of a number of Shapes. Each shape has attributes, e.g. strokeWidth,
|
||||
* that is used when drawing the paths in the Shape.
|
||||
*
|
||||
* All coordinates and sizes (e.g. strokeWidth) are not translated by any transform given in the
|
||||
* svg. This has to be done when drawing.
|
||||
*/
|
||||
struct VGShape
|
||||
{
|
||||
uint16_t numCommands; ///< Number of commands in the paths
|
||||
uint16_t numPoints; ///< Number of coordinate floats in the paths
|
||||
const uint8_t* commands; ///< The paths commands
|
||||
const float* points; ///< The paths coordinates
|
||||
VGFillMode drawingMode; ///< Polygon fill mode for this shape
|
||||
VGColorMode fillMode; ///< Fill coloring mode for this shape
|
||||
VGColorMode strokeMode; ///< Stroke coloring mode for this shape
|
||||
const void* fillPaint; ///< Filling painter object or null if not filled
|
||||
const void* strokePaint; ///< Stroking painter object or null if not stroked
|
||||
float strokeWidth; ///< Stroke width to use when drawing this shape
|
||||
VGStrokeLineJoin strokeLineJoin; ///< The stroke line join
|
||||
VGStrokeLineCap strokeLineCap; ///< The stroke line cap visual
|
||||
float strokeMiterLimit; ///< The stroke miter limit
|
||||
uint8_t fillAlpha; ///< Alpha of this shape's fill in the range [0;255]
|
||||
uint8_t strokeAlpha; ///< Alpha of this shape's stroke in the range [0;255]
|
||||
float boundingbox[4]; ///< Un-transformed bounding box for this Shape [xmin, ymin, xmax, ymax] excluding strokeWidth
|
||||
float transformation[6]; ///< The transformation matrix to apply before drawing
|
||||
const VGShape* next; ///< Pointer to the next Shape
|
||||
};
|
||||
|
||||
/**
|
||||
* Data structure for a vector drawing.
|
||||
*
|
||||
* VGObject drawings consists of a linked list of VGShapes.
|
||||
*/
|
||||
struct VGObject
|
||||
{
|
||||
float x; ///< The x coordinate
|
||||
float y; ///< The y coordinate
|
||||
float width; ///< The width including strokeWidth
|
||||
float height; ///< The height including strokeWidth
|
||||
float imageWidth; ///< Width of the image (either calculated or from SVG width attribute)
|
||||
float imageHeight; ///< Height of the image (either calculated or from SVG height attribute)
|
||||
const VGShape* shape; ///< First shape in this drawing
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_VGDATA_HPP
|
||||
@ -0,0 +1,192 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/hal/VectorRenderer.hpp
|
||||
*
|
||||
* Defines the touchgfx::VectorRenderer class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_VECTORRENDERER_HPP
|
||||
#define TOUCHGFX_VECTORRENDERER_HPP
|
||||
|
||||
#include <touchgfx/Matrix3x3.hpp>
|
||||
#include <touchgfx/hal/VGData.hpp>
|
||||
#include <touchgfx/widgets/Widget.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
|
||||
/**
|
||||
* Abstract interface for classes implementing general 2D vector
|
||||
* drawing.
|
||||
*
|
||||
* Users of this interface are Widgets drawing vector graphics like
|
||||
* SVG images.
|
||||
*
|
||||
* Implementations draw the path given (in drawPath) using the last
|
||||
* color or gradient supplied with setColor or setLinearGradient.
|
||||
*/
|
||||
class VectorRenderer
|
||||
{
|
||||
public:
|
||||
/** Virtual destructor. */
|
||||
virtual ~VectorRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the VectorRenderer instance.
|
||||
*
|
||||
* @return The VectorRenderer instance.
|
||||
*/
|
||||
static VectorRenderer* getInstance();
|
||||
|
||||
/**
|
||||
* Start a new drawing in the given area. The area typically
|
||||
* corresponds to an invalidated area of a Widget.
|
||||
* Implementations may lock the framebuffer here.
|
||||
*
|
||||
* @param renderer The Widget that does the rendering.
|
||||
* @param drawingArea The area of the screen to draw in.
|
||||
*/
|
||||
virtual void setup(const Widget& renderer, const Rect& drawingArea) = 0;
|
||||
|
||||
/**
|
||||
* A list of vector graphics drawing modes.
|
||||
*
|
||||
*/
|
||||
enum DrawMode
|
||||
{
|
||||
STROKE, ///< Draw the outline of the paths
|
||||
FILL_EVEN_ODD, ///< Fill the paths using the even-odd filling rule
|
||||
FILL_NON_ZERO ///< Fill the paths using the non-zero filling rule
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the drawing mode for the VectorRenderer. The mode will be
|
||||
* used for all subsequent drawings until setMode is called again.
|
||||
*
|
||||
* The default mode is non-zero filling.
|
||||
*
|
||||
* @param mode The filling mode.
|
||||
*/
|
||||
virtual void setMode(DrawMode mode) = 0;
|
||||
|
||||
/**
|
||||
* Sets stroke miter limit. This the max distance from the Miter point on the stroke to the
|
||||
* stroke point that will be used. If the miter limit is exceeded for a stroke join, it will not
|
||||
* be drawn as a Miter but as a Bevel.
|
||||
*
|
||||
* @param miterLimit The miter limit.
|
||||
*/
|
||||
virtual void setStrokeMiterLimit(float miterLimit) = 0;
|
||||
|
||||
/**
|
||||
* Sets stroke line join type.
|
||||
*
|
||||
* @param lineJoin The line join type.
|
||||
*/
|
||||
virtual void setStrokeLineJoin(VGStrokeLineJoin lineJoin) = 0;
|
||||
|
||||
/**
|
||||
* Sets stroke line cap type.
|
||||
*
|
||||
* @param lineCap The line cap type.
|
||||
*/
|
||||
virtual void setStrokeLineCap(VGStrokeLineCap lineCap) = 0;
|
||||
|
||||
/**
|
||||
* Finalizes the current drawing. The implementation may block
|
||||
* here until the drawing is done.
|
||||
*
|
||||
* The implementation is required to unlock the framebuffer when
|
||||
* tearDown is called.
|
||||
*/
|
||||
virtual void tearDown() = 0;
|
||||
|
||||
/**
|
||||
* Draw a Path defined by the given array of primitives
|
||||
* (commands) and an array of the corresponding floating point
|
||||
* coordinates.
|
||||
*
|
||||
* @param cmds An uint8_t array of VectorPrimitives values
|
||||
* @param nCmds The number of commands in cmds
|
||||
* @param points An array of coordinates for the commands
|
||||
* @param nPoints The number of values in the points arrays
|
||||
* @param bbox Array describing the bounding box of the path [minx,miny,maxx,maxy] or 0 if unknown
|
||||
*/
|
||||
virtual void drawPath(const uint8_t* cmds, uint32_t nCmds, const float* points, uint32_t nPoints, const float* bbox = 0) = 0;
|
||||
|
||||
/**
|
||||
* Set the width used for future drawings using the VECTOR_STROKE
|
||||
* drawing mode.
|
||||
*
|
||||
* @param w The width used for stroke drawing.
|
||||
*/
|
||||
virtual void setStrokeWidth(float w) = 0;
|
||||
|
||||
/**
|
||||
* Set a constant color used for future drawings.
|
||||
*
|
||||
* @param c An ARGB color value
|
||||
*/
|
||||
virtual void setColor(colortype c) = 0;
|
||||
|
||||
/**
|
||||
* Set the alpha value (opacity) used for future drawings.
|
||||
* The alpha is specified in the interval [0;1].
|
||||
*
|
||||
* @param a The alpha value.
|
||||
*/
|
||||
virtual void setAlpha(uint8_t a) = 0;
|
||||
|
||||
/**
|
||||
* Set a linear gradient used for future drawings.
|
||||
* The linear gradient is transformed using the current
|
||||
* transformation matrix.
|
||||
* Multiple colors (stops) can be specified for the gradient. The
|
||||
* stop positions are given in the range [0;1].
|
||||
*
|
||||
* @param x0 X-coordinate for gradient starting point
|
||||
* @param y0 Y-coordinate for gradient starting point
|
||||
* @param x1 X-coordinate for gradient end point
|
||||
* @param y1 Y-coordinate for gradient end point
|
||||
* @param stops Number of stops
|
||||
* @param stopPositions Positions of the stops on the line
|
||||
* @param stopColors Colors of the stops
|
||||
* @param width Width of the box to fill
|
||||
* @param height Height of the box to fill
|
||||
* @param solid True if all colors in the gradient are solid
|
||||
* @param palette The gradient palette
|
||||
*/
|
||||
virtual void setLinearGradient(float x0, float y0, float x1, float y1,
|
||||
uint32_t stops,
|
||||
const float* stopPositions,
|
||||
const uint32_t* stopColors,
|
||||
float width,
|
||||
float height,
|
||||
bool solid,
|
||||
const uint32_t* palette) = 0;
|
||||
|
||||
/**
|
||||
* Sets the transformation matrix used for future drawings.
|
||||
* The transformation is reset when setup is called.
|
||||
*
|
||||
* @param m The transformation matrix
|
||||
*
|
||||
*/
|
||||
virtual void setTransformationMatrix(const Matrix3x3& m) = 0;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_VECTORRENDERER_HPP
|
||||
@ -0,0 +1,217 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/Drawable.hpp
|
||||
*
|
||||
* Declares the touchgfx::Drawable class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_VIDEOCONTROLLER_HPP
|
||||
#define TOUCHGFX_VIDEOCONTROLLER_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* This type contains various information read from a video file.
|
||||
*/
|
||||
struct VideoInformation
|
||||
{
|
||||
uint32_t ms_between_frames; ///< The number of milliseconds between frames
|
||||
uint32_t number_of_frames; ///< The number of frames in the movie
|
||||
uint32_t frame_width; ///< The frame width in pixels
|
||||
uint32_t frame_height; ///< The frame height in pixels
|
||||
};
|
||||
|
||||
/** Interface for classes reading video data from non-memory-mapped flash storage. */
|
||||
class VideoDataReader
|
||||
{
|
||||
public:
|
||||
/** Virtual destructor. */
|
||||
virtual ~VideoDataReader()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of the data (file).
|
||||
*
|
||||
* @return The length of the data.
|
||||
*/
|
||||
virtual uint32_t getDataLength() = 0;
|
||||
|
||||
/**
|
||||
* Seek to a specific position in the data (file).
|
||||
*
|
||||
* @param position Byte position in the data that is needed next.
|
||||
*/
|
||||
virtual void seek(uint32_t position) = 0;
|
||||
|
||||
/**
|
||||
* Read data from flash to a buffer. This must be a synchrony method that does not return until
|
||||
* the copy is done.
|
||||
*
|
||||
* @param [in,out] dst Address of destination buffer in RAM.
|
||||
* @param bytes Number of bytes to copy.
|
||||
*
|
||||
* @return Returns true if read was successful.
|
||||
*/
|
||||
virtual bool readData(void* dst, uint32_t bytes) = 0;
|
||||
};
|
||||
|
||||
class VideoWidget;
|
||||
|
||||
/**
|
||||
* The VideoController is an abstract interface for the video decoder. A
|
||||
* concrete implementation will be generated by the TouchGFX
|
||||
* Generator.
|
||||
*
|
||||
* The VideoController can control multiple video streams in multiple
|
||||
* VideoWidgets. These are recognized by their Handle.
|
||||
*
|
||||
* Application code should only interact with the VideoWidget class.
|
||||
*
|
||||
* @see VideoWidget
|
||||
*/
|
||||
class VideoController
|
||||
{
|
||||
public:
|
||||
/** The commands send to the Controller. */
|
||||
enum Command
|
||||
{
|
||||
PLAY, ///< Play the video
|
||||
PAUSE, ///< Pause the playing
|
||||
SEEK, ///< Seek to frame
|
||||
SHOW, ///< Show a frame
|
||||
STOP, ///< Stop the video
|
||||
SET_REPEAT ///< Set repeat mode
|
||||
};
|
||||
|
||||
/** Virtual destructor. */
|
||||
virtual ~VideoController()
|
||||
{
|
||||
}
|
||||
|
||||
/** Type to identify a video stream. */
|
||||
typedef uint32_t Handle;
|
||||
|
||||
/**
|
||||
* Gets the VideoController instance.
|
||||
*
|
||||
* @return The VideoController instance.
|
||||
*/
|
||||
static VideoController& getInstance();
|
||||
|
||||
/**
|
||||
* Register a VideoWidget to get a Handle.
|
||||
*
|
||||
* @param [in,out] widget The VideoWidget.
|
||||
*
|
||||
* @return A video stream handle.
|
||||
*/
|
||||
virtual Handle registerVideoWidget(VideoWidget& widget) = 0;
|
||||
|
||||
/**
|
||||
* Unregister a VideoWidget to release the handle.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
*/
|
||||
virtual void unregisterVideoWidget(const Handle handle) = 0;
|
||||
|
||||
/**
|
||||
* Set the framerate for video using a qoutient of screen frames /video frames.
|
||||
*
|
||||
* To get 20 video frames pr second on a 60 fps display use video_frames = 20 and ui_frames = 60.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param ui_frames Number of UI frames (divider)
|
||||
* @param video_frames Number of video_frames (dividend)
|
||||
*/
|
||||
virtual void setFrameRate(const Handle handle, uint32_t ui_frames, uint32_t video_frames) = 0;
|
||||
|
||||
/**
|
||||
* Signal that the widget can be invalidated (tickEvent).
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param [in,out] widget The Widget.
|
||||
*
|
||||
* @return Returns true if video has more frames (i.e. false on the last frame).
|
||||
*/
|
||||
virtual bool updateFrame(const Handle handle, VideoWidget& widget) = 0;
|
||||
|
||||
/**
|
||||
* Draw the video content.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param invalidatedArea The area of the widget that must be redrawn.
|
||||
* @param widget Reference to the widget.
|
||||
*/
|
||||
virtual void draw(const Handle handle, const Rect& invalidatedArea, const VideoWidget& widget) = 0;
|
||||
|
||||
/**
|
||||
* Set the video data for the stream.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param movie Pointer to the video data.
|
||||
* @param length Length of the video data.
|
||||
*/
|
||||
virtual void setVideoData(const Handle handle, const uint8_t* movie, const uint32_t length) = 0;
|
||||
|
||||
/**
|
||||
* Set the video data for the stream.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param [in,out] reader Reference to a VideoDataReader object.
|
||||
*/
|
||||
virtual void setVideoData(const Handle handle, VideoDataReader& reader) = 0;
|
||||
|
||||
/**
|
||||
* Pass a command from the Widget to the Controller.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param cmd The Command.
|
||||
* @param param A parameter.
|
||||
*/
|
||||
virtual void setCommand(const Handle handle, Command cmd, uint32_t param) = 0;
|
||||
|
||||
/**
|
||||
* Get the current frame number.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
*
|
||||
* @return Return the current frame number.
|
||||
*/
|
||||
virtual uint32_t getCurrentFrameNumber(const Handle handle) = 0;
|
||||
|
||||
/**
|
||||
* Get Video information.
|
||||
*
|
||||
* Get information from the video data.
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
* @param [in,out] data Pointer to VideoInformation where information should be stored.
|
||||
*/
|
||||
virtual void getVideoInformation(const Handle handle, VideoInformation* data) = 0;
|
||||
|
||||
/**
|
||||
* Check if the video stream is playing (not paused or stopped).
|
||||
*
|
||||
* @param handle The stream handle.
|
||||
*
|
||||
* @return Returns true if the video is playing.
|
||||
*/
|
||||
virtual bool getIsPlaying(const Handle handle) = 0;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_VIDEOCONTROLLER_HPP
|
||||
Reference in New Issue
Block a user