add screen library
This commit is contained in:
		| @@ -0,0 +1,227 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * This file is part of the TouchGFX 4.16.1 distribution. | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|  * @file common/AbstractPartition.hpp | ||||
|  * | ||||
|  * Declares the touchgfx::AbstractPartition class. | ||||
|  */ | ||||
| #ifndef ABSTRACTPARTITION_HPP | ||||
| #define ABSTRACTPARTITION_HPP | ||||
|  | ||||
| #include <touchgfx/hal/Types.hpp> | ||||
|  | ||||
| namespace touchgfx | ||||
| { | ||||
| /** | ||||
|  * This type defines an abstract interface to a storage partition for allocating memory slots of | ||||
|  * equal size. The "partition" is not aware of the actual types stored in the partition | ||||
|  * memory, hence it provides no mechanism for deleting C++ objects when clear()'ed. | ||||
|  */ | ||||
| class AbstractPartition | ||||
| { | ||||
| public: | ||||
|     /** Finalizes an instance of the AbstractPartition class. */ | ||||
|     virtual ~AbstractPartition(); | ||||
|  | ||||
|     /** | ||||
|      * Gets the address of the next available storage slot. The slot size is compared with | ||||
|      * the specified size. | ||||
|      * | ||||
|      * @param  size The size. | ||||
|      * | ||||
|      * @return The address of an empty storage slot which contains minimum 'size' bytes. | ||||
|      * | ||||
|      * @note Asserts if 'size' is too large, or the storage is depleted. | ||||
|      */ | ||||
|     virtual void* allocate(uint16_t size); | ||||
|  | ||||
|     /** | ||||
|      * Gets the address of the specified index. | ||||
|      * | ||||
|      * @param  index Zero-based index of the. | ||||
|      * @param  size  The size. | ||||
|      * | ||||
|      * @return The address of the appropriate storage slot which contains minimum 'size' | ||||
|      *         bytes. | ||||
|      * | ||||
|      * @note Asserts if 'size' is too large. | ||||
|      */ | ||||
|     virtual void* allocateAt(uint16_t index, uint16_t size); | ||||
|  | ||||
|     /** | ||||
|      * Gets allocation count. | ||||
|      * | ||||
|      * @return The currently allocated storage slots. | ||||
|      */ | ||||
|     virtual uint16_t getAllocationCount() const; | ||||
|  | ||||
|     /** | ||||
|      * Determines index of previously allocated location. Since the Partition concept is | ||||
|      * loosely typed this method shall be used with care. The method does not guarantee that | ||||
|      * the found object at the returned index is a valid object. It only tests whether or | ||||
|      * not the object is within the bounds of the current partition allocations. | ||||
|      * | ||||
|      * @param  address The location address to lookup. | ||||
|      * | ||||
|      * @return An uint16_t. | ||||
|      */ | ||||
|     virtual uint16_t indexOf(const void* address); | ||||
|  | ||||
|     /** | ||||
|      * Prepares the Partition for new allocations. Any objects present in the Partition | ||||
|      * shall not be used after invoking this method. | ||||
|      */ | ||||
|     virtual void clear(); | ||||
|  | ||||
|     /** | ||||
|      * Gets the capacity, i.e. the maximum allocation count. | ||||
|      * | ||||
|      * @return The maximum allocation count. | ||||
|      */ | ||||
|     virtual uint16_t capacity() const = 0; | ||||
|  | ||||
|     /** | ||||
|      * Gets the address of the next available storage slot. The slot size is determined from | ||||
|      * the size of type T. | ||||
|      * | ||||
|      * @tparam T Generic type parameter. | ||||
|      * | ||||
|      * @return The address of an empty storage slot. | ||||
|      * | ||||
|      * @note Asserts if T is too large, or the storage is depleted. | ||||
|      */ | ||||
|     template <typename T> | ||||
|     void* allocate() | ||||
|     { | ||||
|         return allocate(static_cast<uint16_t>(sizeof(T))); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Gets the address of the specified storage slot. The slot size is determined from the | ||||
|      * size of type T. | ||||
|      * | ||||
|      * @tparam T Generic type parameter. | ||||
|      * @param  index Zero-based index of the. | ||||
|      * | ||||
|      * @return The address of the appropriate storage slot. | ||||
|      * | ||||
|      * @note Asserts if T is too large. | ||||
|      */ | ||||
|     template <typename T> | ||||
|     void* allocateAt(uint16_t index) | ||||
|     { | ||||
|         return allocateAt(index, static_cast<uint16_t>(sizeof(T))); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Gets the object at the specified index. | ||||
|      * | ||||
|      * @tparam T Generic type parameter. | ||||
|      * @param  index The index into the Partition storage where the returned object is located. | ||||
|      * | ||||
|      * @return A typed reference to the object at the specified index. | ||||
|      */ | ||||
|     template <typename T> | ||||
|     T& at(const uint16_t index) | ||||
|     { | ||||
|         return *static_cast<T*>(element(index)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * const version of at(). | ||||
|      * | ||||
|      * @tparam T Generic type parameter. | ||||
|      * @param  index Zero-based index of the. | ||||
|      * | ||||
|      * @return A T& | ||||
|      */ | ||||
|     template <typename T> | ||||
|     const T& at(const uint16_t index) const | ||||
|     { | ||||
|         return *static_cast<const T*>(element(index)); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Determines if the specified object could have been previously allocated in the | ||||
|      * partition. Since the Partition concept is loosely typed this method shall be used | ||||
|      * with care. The method does not guarantee that the found object at the returned index | ||||
|      * is a valid object. It only tests whether or not the object is within the bounds of | ||||
|      * the current partition allocations. | ||||
|      * | ||||
|      * @tparam T Generic type parameter. | ||||
|      * @param  pT Pointer to the object to look up. | ||||
|      * | ||||
|      * @return If the object seems to be allocated in the Partition, a Pair object | ||||
|      *         containing a typed pointer to the object and an index into the Partition | ||||
|      *         storage is returned. Otherwise, a Pair<0, 0> is returned. | ||||
|      */ | ||||
|     template <class T> | ||||
|     Pair<T*, uint16_t> find(const void* pT) | ||||
|     { | ||||
|         uint16_t index = indexOf(pT); | ||||
|         if (0 < getAllocationCount() && index < getAllocationCount()) | ||||
|         { | ||||
|             return Pair<T*, uint16_t>(&at<T>(index), index); | ||||
|         } | ||||
|  | ||||
|         return Pair<T*, uint16_t>(0, (uint16_t) -1); | ||||
|     } | ||||
|  | ||||
|     /** Decreases number of allocations. */ | ||||
|     void dec() | ||||
|     { | ||||
|         if (allocations) | ||||
|         { | ||||
|             allocations--; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Access to concrete element-size. Used internally. | ||||
|      * | ||||
|      * @return An uint32_t. | ||||
|      */ | ||||
|     virtual uint32_t element_size() = 0; | ||||
|  | ||||
| protected: | ||||
|     /** | ||||
|      * Access to stored element. Used internally. | ||||
|      * | ||||
|      * @param  index Zero-based index of the. | ||||
|      * | ||||
|      * @return null if it fails, else a void*. | ||||
|      */ | ||||
|     virtual void* element(uint16_t index) = 0; | ||||
|  | ||||
|     /** | ||||
|      * Access to stored element, const version. | ||||
|      * | ||||
|      * @param  index Zero-based index of the. | ||||
|      * | ||||
|      * @return null if it fails, else a void*. | ||||
|      */ | ||||
|     virtual const void* element(uint16_t index) const = 0; | ||||
|  | ||||
|     /** Initializes a new instance of the AbstractPartition class. */ | ||||
|     AbstractPartition(); | ||||
|  | ||||
| private: | ||||
|     uint16_t allocations; | ||||
| }; | ||||
|  | ||||
| } // namespace touchgfx | ||||
|  | ||||
| #endif // ABSTRACTPARTITION_HPP | ||||
| @@ -0,0 +1,161 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * This file is part of the TouchGFX 4.16.1 distribution. | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|  * @file common/Meta.hpp | ||||
|  * | ||||
|  * Declares the touchgfx::meta namespace. | ||||
|  */ | ||||
| #ifndef META_HPP | ||||
| #define META_HPP | ||||
|  | ||||
| namespace touchgfx | ||||
| { | ||||
| /** | ||||
|  * Template meta-programming tools are grouped in this namespace | ||||
|  */ | ||||
| namespace meta | ||||
| { | ||||
| /** Nil-type, indicates the end of a TypeList. */ | ||||
| struct Nil | ||||
| { | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * TypeList, used for generating compile-time lists of types. | ||||
|  * | ||||
|  * @tparam First Type of the first. | ||||
|  * @tparam Next  Type of the next. | ||||
|  */ | ||||
| template <typename First, typename Next> | ||||
| struct TypeList | ||||
| { | ||||
|     typedef First first; ///< The first element in the TypeList | ||||
|     typedef Next next;   ///< Remainder of the TypeList | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Meta-function, selects the "maximum" type, i.e. the largest type. | ||||
|  * | ||||
|  * @tparam T1      Generic type parameter. | ||||
|  * @tparam T2      Generic type parameter. | ||||
|  * @tparam choose1 True if sizeof(T1) is larger than sizeof(T2). | ||||
|  * @param  parameter1 The first parameter. | ||||
|  */ | ||||
| template < typename T1, typename T2, bool choose1 = (sizeof(T1) > sizeof(T2)) > | ||||
| struct type_max | ||||
| { | ||||
|     typedef T1 type; ///< The resulting type (default case: sizeof(T1)>sizeof(T2)) | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Specialization for the case where sizeof(T2) >= sizeof(T1). | ||||
|  * | ||||
|  * @tparam T1 Generic type parameter. | ||||
|  * @tparam T2 Generic type parameter. | ||||
|  */ | ||||
| template <typename T1, typename T2> | ||||
| struct type_max<T1, T2, false> | ||||
| { | ||||
|     typedef T2 type; ///< The resulting type (default case: sizeof(T2)>=sizeof(T1)) | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Meta-function signature, selects maximum type from TypeList. | ||||
|  * | ||||
|  * @tparam T Generic type parameter. | ||||
|  */ | ||||
| template <typename T> | ||||
| struct select_type_maxsize; | ||||
|  | ||||
| /** | ||||
|  * Specialization to dive into the list (inherits result from type_max). | ||||
|  * | ||||
|  * @tparam First Type of the first. | ||||
|  * @tparam Next  Type of the next. | ||||
|  */ | ||||
| template <typename First, typename Next> | ||||
| struct select_type_maxsize<TypeList<First, Next> > : public type_max<First, typename select_type_maxsize<Next>::type> | ||||
| { | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Specialization for loop termination (when type Nil encountered). | ||||
|  * | ||||
|  * @tparam First Type of the first. | ||||
|  */ | ||||
| template <typename First> | ||||
| struct select_type_maxsize<TypeList<First, Nil> > | ||||
| { | ||||
|     typedef First type; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Meta-function signature, joins typelist with type (or another typelist). | ||||
|  * | ||||
|  * @tparam TList Type of the list. | ||||
|  * @tparam T     Generic type parameter. | ||||
|  */ | ||||
| template <typename TList, typename T> | ||||
| struct list_join; | ||||
|  | ||||
| /** Specialization for termination. */ | ||||
| template <> | ||||
| struct list_join<Nil, Nil> | ||||
| { | ||||
|     typedef Nil result; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Specialization for "end-of-LHS", with RHS as type. | ||||
|  * | ||||
|  * @tparam T Generic type parameter. | ||||
|  */ | ||||
| template <typename T> | ||||
| struct list_join<Nil, T> | ||||
| { | ||||
|     typedef TypeList<T, Nil> result; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Specialization for "end-of-LHS", with RHS as a TypeList. | ||||
|  * | ||||
|  * @tparam First Type of the first. | ||||
|  * @tparam Next  Type of the next. | ||||
|  */ | ||||
| template <typename First, typename Next> | ||||
| struct list_join<Nil, TypeList<First, Next> > | ||||
| { | ||||
|     typedef TypeList<First, Next> result; | ||||
| }; | ||||
|  | ||||
| /** | ||||
|  * Recursively joins a typelist (LHS) with a type or a type-list (RHS). | ||||
|  * | ||||
|  * @tparam First Type of the first. | ||||
|  * @tparam Next  Type of the next. | ||||
|  * @tparam T     Generic type parameter. | ||||
|  */ | ||||
| template <typename First, typename Next, typename T> | ||||
| struct list_join<TypeList<First, Next>, T> | ||||
| { | ||||
|     typedef TypeList<First, typename list_join<Next, T>::result> result; | ||||
| }; | ||||
|  | ||||
| } // namespace meta | ||||
|  | ||||
| } // namespace touchgfx | ||||
|  | ||||
| #endif // META_HPP | ||||
| @@ -0,0 +1,93 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * This file is part of the TouchGFX 4.16.1 distribution. | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|  * @file common/Partition.hpp | ||||
|  * | ||||
|  * Declares the touchgfx::Partition class. | ||||
|  */ | ||||
| #ifndef PARTITION_HPP | ||||
| #define PARTITION_HPP | ||||
|  | ||||
| #include <common/AbstractPartition.hpp> | ||||
| #include <common/Meta.hpp> | ||||
|  | ||||
| namespace touchgfx | ||||
| { | ||||
| /** | ||||
|  * This type provides a concrete Partition of memory-slots capable of holding any of the | ||||
|  * specified list of types. | ||||
|  * | ||||
|  * The Partition is not aware of the types stored in the Partition memory, hence it | ||||
|  * provides no mechanism for deleting C++ objects when the Partition is clear()'ed. | ||||
|  * | ||||
|  * This class implements AbstractPartition. | ||||
|  * | ||||
|  * @tparam ListOfTypes        Type of the list of types. | ||||
|  * @tparam NUMBER_OF_ELEMENTS Type of the number of elements. | ||||
|  * | ||||
|  * @see AbstractPartition | ||||
|  */ | ||||
| template <typename ListOfTypes, uint16_t NUMBER_OF_ELEMENTS> | ||||
| class Partition : public AbstractPartition | ||||
| { | ||||
| public: | ||||
|     /** Provides a generic public type containing the list of supported types. */ | ||||
|     typedef ListOfTypes SupportedTypesList; | ||||
|  | ||||
|     /** | ||||
|      * Compile-time generated constants specifying the "element" or "slot" size used by this | ||||
|      * partition. | ||||
|      */ | ||||
|     enum | ||||
|     { | ||||
|         INTS_PR_ELEMENT = (sizeof(typename meta::select_type_maxsize<SupportedTypesList>::type) + sizeof(int) - 1) / sizeof(int), | ||||
|         SIZE_OF_ELEMENT = INTS_PR_ELEMENT * sizeof(int) | ||||
|     }; | ||||
|  | ||||
|     virtual uint16_t capacity() const | ||||
|     { | ||||
|         return NUMBER_OF_ELEMENTS; | ||||
|     } | ||||
|  | ||||
|     virtual uint32_t element_size() | ||||
|     { | ||||
|         return sizeof(stBlocks[0]); | ||||
|     } | ||||
|  | ||||
| protected: | ||||
|     virtual void* element(uint16_t index) | ||||
|     { | ||||
|         return &stBlocks[index]; | ||||
|     } | ||||
|  | ||||
|     virtual const void* element(uint16_t index) const | ||||
|     { | ||||
|         return &stBlocks[index]; | ||||
|     } | ||||
|  | ||||
| private: | ||||
|     /** Internal type used for storage, in order to ensure "natural" alignment of elements. */ | ||||
|     struct Block | ||||
|     { | ||||
|         int filler[INTS_PR_ELEMENT]; | ||||
|     }; | ||||
|  | ||||
|     Block stBlocks[NUMBER_OF_ELEMENTS]; ///< Actual memory storage | ||||
| }; | ||||
|  | ||||
| } // namespace touchgfx | ||||
|  | ||||
| #endif // PARTITION_HPP | ||||
| @@ -0,0 +1,112 @@ | ||||
| /** | ||||
|   ****************************************************************************** | ||||
|   * This file is part of the TouchGFX 4.16.1 distribution. | ||||
|   * | ||||
|   * <h2><center>© Copyright (c) 2021 STMicroelectronics. | ||||
|   * All rights reserved.</center></h2> | ||||
|   * | ||||
|   * This software component is licensed by ST under Ultimate Liberty license | ||||
|   * SLA0044, the "License"; You may not use this file except in compliance with | ||||
|   * the License. You may obtain a copy of the License at: | ||||
|   *                             www.st.com/SLA0044 | ||||
|   * | ||||
|   ****************************************************************************** | ||||
|   */ | ||||
|  | ||||
| /** | ||||
|  * @file common/TouchGFXInit.hpp | ||||
|  * | ||||
|  * Declares the touch graphics generic initialization function. | ||||
|  */ | ||||
| #ifndef TOUCHGFXINIT_HPP | ||||
| #define TOUCHGFXINIT_HPP | ||||
|  | ||||
| #include <platform/driver/touch/TouchController.hpp> | ||||
| #include <touchgfx/hal/DMA.hpp> | ||||
| #include <touchgfx/hal/HAL.hpp> | ||||
|  | ||||
| #include <BitmapDatabase.hpp> | ||||
| #include <fonts/ApplicationFontProvider.hpp> | ||||
| #include <texts/TypedTextDatabase.hpp> | ||||
| #include <gui/common/FrontendHeap.hpp> | ||||
|  | ||||
| static ApplicationFontProvider fontProvider; ///< The font provider | ||||
|  | ||||
| /** | ||||
|  * The global touchgfx namespace. All TouchGFX framework classes and global functions are placed in this namespace. | ||||
|  */ | ||||
| namespace touchgfx | ||||
| { | ||||
| /// @cond | ||||
|  | ||||
| static Texts texts; ///< The texts | ||||
|  | ||||
| template <class T> | ||||
| HAL& getHAL(DMA_Interface& dma, LCD& display, TouchController& tc, int16_t width, int16_t height) | ||||
| { | ||||
|     static T hal(dma, display, tc, width, height); | ||||
|     return hal; | ||||
| } | ||||
| /// @endcond | ||||
|  | ||||
| /** | ||||
|  * @globalfn | ||||
|  */ | ||||
|  | ||||
| /** | ||||
|  * TouchGFX generic initialize. | ||||
|  * | ||||
|  * @tparam HALType The class type of the HAL subclass used for this port. | ||||
|  * @param [in] dma                    Reference to the DMA implementation object to use. Can be of | ||||
|  *                                    type NoDMA to disable the use of DMA for rendering. | ||||
|  * @param [in] display                Reference to the LCD renderer implementation (subclass of | ||||
|  *                                    LCD). Could be either LCD16bpp for RGB565 UIs, or | ||||
|  *                                    LCD1bpp for monochrome UIs or LCD24bpp for 24bit | ||||
|  *                                    displays using RGB888 UIs. | ||||
|  * @param [in] tc                     Reference to the touch controller driver (or | ||||
|  *                                    NoTouchController to disable touch input). | ||||
|  * @param      width                  The \a native display width of the actual display, in pixels. | ||||
|  *                                    This value is irrespective of whether the concrete UI | ||||
|  *                                    should be portrait or landscape mode. It must match | ||||
|  *                                    what the display itself is configured as. | ||||
|  * @param      height                 The \a native display height of the actual display, in | ||||
|  *                                    pixels. This value is irrespective of whether the | ||||
|  *                                    concrete UI should be portrait or landscape mode. It | ||||
|  *                                    must match what the display itself is configured as. | ||||
|  * @param [in] bitmapCache            Optional pointer to starting address of a memory region in | ||||
|  *                                    which to place the bitmap cache. Usually in external | ||||
|  *                                    RAM. Pass 0 if bitmap caching is not used. | ||||
|  * @param      bitmapCacheSize        Size of bitmap cache in bytes. Pass 0 if bitmap cache is not | ||||
|  *                                    used. | ||||
|  * @param      numberOfDynamicBitmaps (Optional) Number of dynamic bitmaps. | ||||
|  * | ||||
|  * @return A reference to the allocated (and initialized) HAL object. | ||||
|  */ | ||||
| template <class HALType> | ||||
| HAL& touchgfx_generic_init(DMA_Interface& dma, LCD& display, TouchController& tc, int16_t width, int16_t height, | ||||
|                            uint16_t* bitmapCache, uint32_t bitmapCacheSize, uint32_t numberOfDynamicBitmaps = 0) | ||||
| { | ||||
|     HAL& hal = getHAL<HALType>(dma, display, tc, width, height); | ||||
|     hal.initialize(); | ||||
|  | ||||
|     Bitmap::registerBitmapDatabase(BitmapDatabase::getInstance(), | ||||
|                                    BitmapDatabase::getInstanceSize(), | ||||
|                                    bitmapCache, | ||||
|                                    bitmapCacheSize, | ||||
|                                    numberOfDynamicBitmaps); | ||||
|  | ||||
|     TypedText::registerTexts(&texts); | ||||
|     Texts::setLanguage(0); | ||||
|  | ||||
|     FontManager::setFontProvider(&fontProvider); | ||||
|  | ||||
|     FrontendHeap::getInstance(); // We need to initialize the frontend heap. | ||||
|  | ||||
|     hal.registerEventListener(*(Application::getInstance())); | ||||
|  | ||||
|     return hal; | ||||
| } | ||||
|  | ||||
| } // namespace touchgfx | ||||
|  | ||||
| #endif // TOUCHGFXINIT_HPP | ||||
		Reference in New Issue
	
	Block a user