ui_memsetcpy.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief UI specific memeset/memcpy
  9. */
  10. #ifndef ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_UI_MEMSETCPY_H_
  11. #define ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_UI_MEMSETCPY_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string.h>
  15. /**
  16. * @defgroup display-util Display Utilities
  17. * @ingroup display_libraries
  18. * @{
  19. */
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #ifdef CONFIG_UI_DMA_MEMSETCPY
  24. /*
  25. * @brief memset 8-bit pattern
  26. *
  27. * @note This function is asynchronous. Call ui_memsetcpy_wait_finish() to synchronize.
  28. *
  29. * @param buf buf address
  30. * @param c 8-bit pattern to set
  31. * @param n number of elements in 8-bit
  32. *
  33. * @retval N/A
  34. */
  35. void ui_memset(void * buf, uint8_t c, size_t n);
  36. /*
  37. * @brief memset 16-bit pattern
  38. *
  39. * @note This function is asynchronous. Call ui_memsetcpy_wait_finish() to synchronize.
  40. *
  41. * @param buf buf address
  42. * @param c16 16-bit pattern to set
  43. * @param n16 number of elements in 16-bit
  44. *
  45. * @retval 0 on success else negative code
  46. */
  47. int ui_memset16(void * buf, uint16_t c16, size_t n16);
  48. /*
  49. * @brief memset 32-bit pattern
  50. *
  51. * @note This function is asynchronous. Call ui_memsetcpy_wait_finish() to synchronize.
  52. *
  53. * @param buf buf address
  54. * @param c32 32-bit pattern to set
  55. * @param n32 number of elements in 32-bit
  56. *
  57. * @retval 0 on success else negative code
  58. */
  59. int ui_memset32(void * buf, uint32_t c32, size_t n32);
  60. /*
  61. * @brief memcpy
  62. *
  63. * @note This function is asynchronous. Call ui_memsetcpy_wait_finish() to synchronize.
  64. *
  65. * @param dest dest address
  66. * @param src src address
  67. * @param n number of bytes
  68. *
  69. * @retval N/A
  70. */
  71. void ui_memcpy(void * dest, const void * src, size_t n);
  72. /*
  73. * @brief wait prevous memset/memcpy finished
  74. *
  75. * @param timeout_ms time to wait, set negative value to wait forever.
  76. *
  77. * @retval 0 Finished.
  78. * @retval -EAGAIN Waiting period timed out.
  79. */
  80. int ui_memsetcpy_wait_finish(int timeout_ms);
  81. #else /* CONFIG_UI_DMA_MEMSETCPY */
  82. static inline void ui_memset(void * buf, uint8_t c, size_t n)
  83. {
  84. memset(buf, c, n);
  85. }
  86. static inline int ui_memset16(void * buf, uint16_t c16, size_t n16)
  87. {
  88. return -ENOTSUP;
  89. }
  90. static inline int ui_memset32(void * buf, uint32_t c32, size_t n32)
  91. {
  92. return -ENOTSUP;
  93. }
  94. static inline void ui_memcpy(void * dest, const void * src, size_t n)
  95. {
  96. memcpy(dest, src, n);
  97. }
  98. static inline int ui_memsetcpy_wait_finish(int timeout_ms)
  99. {
  100. return 0;
  101. }
  102. #endif /* CONFIG_UI_DMA_MEMSETCPY */
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. /**
  107. * @}
  108. */
  109. #endif /* ZEPHYR_FRAMEWORK_INCLUDE_DISPLAY_UI_MEMSETCPY_H_ */