nrf_gfx.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF_GFX_H__
  41. #define NRF_GFX_H__
  42. #include <stdint.h>
  43. #include <stdbool.h>
  44. #include "sdk_errors.h"
  45. #include "nrf_lcd.h"
  46. #include "nrf_font.h"
  47. /** @file
  48. *
  49. * @addtogroup ili9341_config
  50. * @ingroup ext_drivers
  51. *
  52. * @addtogroup st7735_config
  53. * @ingroup ext_drivers
  54. *
  55. * @defgroup nrf_gfx GFX Library
  56. * @{
  57. * @ingroup app_common
  58. *
  59. * @brief Module for drawing graphical objects like lines, circles, and rectangles.
  60. Provides support for different fonts.
  61. */
  62. /**
  63. * @brief GFX point object structure.
  64. */
  65. typedef struct
  66. {
  67. uint16_t x; /**< Horizontal coordinate of the point where to start drawing the object. */
  68. uint16_t y; /**< Vertical coordinate of the point where to start drawing the object. */
  69. }nrf_gfx_point_t;
  70. /**
  71. * @brief GFX line object structure.
  72. */
  73. typedef struct
  74. {
  75. uint16_t x_start; /**< Horizontal coordinate of the point where to start drawing the object. */
  76. uint16_t y_start; /**< Vertical coordinate of the point where to start drawing the object. */
  77. uint16_t x_end; /**< Horizontal coordinate of the point where to end drawing the object. */
  78. uint16_t y_end; /**< Vertical coordinate of the point where to end drawing the object. */
  79. uint16_t thickness; /**< Thickness of the border of the object. */
  80. }nrf_gfx_line_t;
  81. /**
  82. * @brief GFX circle object structure.
  83. */
  84. typedef struct
  85. {
  86. uint16_t x; /**< Horizontal coordinate of the centre of the object. */
  87. uint16_t y; /**< Vertical coordinate of the centre of the object. */
  88. uint16_t r; /**< Radius of the object. */
  89. }nrf_gfx_circle_t;
  90. /**
  91. * @brief GFX rectangle object structure.
  92. */
  93. typedef struct
  94. {
  95. uint16_t x; /**< Horizontal coordinate of the point where to start drawing the object. */
  96. uint16_t y; /**< Vertical coordinate of the point where to start drawing the object. */
  97. uint16_t width; /**< Width of the object. */
  98. uint16_t height; /**< Height of the object. */
  99. }nrf_gfx_rect_t;
  100. /**
  101. * @defgroup nrf_gfx_macros Macros for defining new graphic objects
  102. * @{
  103. */
  104. #define NRF_GFX_POINT(_x, _y) \
  105. { \
  106. .x = (_x), \
  107. .y = (_y) \
  108. }
  109. #define NRF_GFX_LINE(_x_0, _y_0, _x_1, _y_1, _thickness) \
  110. { \
  111. .x_start = (_x_0), \
  112. .y_start = (_y_0), \
  113. .x_end = (_x_1), \
  114. .y_end = (_y_1), \
  115. .thickness = (_thickness) \
  116. }
  117. #define NRF_GFX_CIRCLE(_x, _y, _radius) \
  118. { \
  119. .x = (_x), \
  120. .y = (_y), \
  121. .r = (_radius) \
  122. }
  123. #define NRF_GFX_RECT(_x, _y, _width, _height) \
  124. { \
  125. .x = (_x), \
  126. .y = (_y), \
  127. .width = (_width), \
  128. .height = (_height) \
  129. }
  130. /* @} */
  131. /**
  132. * @brief Font descriptor type.
  133. */
  134. typedef FONT_INFO nrf_gfx_font_desc_t;
  135. /**
  136. * @brief Function for initializing the GFX library.
  137. *
  138. * @param[in] p_instance Pointer to the LCD instance.
  139. *
  140. * @return Values returned by @ref nrf_lcd_t::lcd_init.
  141. */
  142. ret_code_t nrf_gfx_init(nrf_lcd_t const * p_instance);
  143. /**
  144. * @brief Function for uninitializing the GFX library.
  145. *
  146. * @param[in] p_instance Pointer to the LCD instance.
  147. *
  148. * @return Values returned by @ref nrf_lcd_t::lcd_uninit.
  149. */
  150. void nrf_gfx_uninit(nrf_lcd_t const * p_instance);
  151. /**
  152. * @brief Function for drawing a point.
  153. *
  154. * @param[in] p_instance Pointer to the LCD instance.
  155. * @param[in] p_point Pointer to the point object.
  156. * @param[in] color Color of the object in the display accepted format.
  157. */
  158. void nrf_gfx_point_draw(nrf_lcd_t const * p_instance, nrf_gfx_point_t const * p_point, uint32_t color);
  159. /**
  160. * @brief Function for drawing a line.
  161. *
  162. * @param[in] p_instance Pointer to the LCD instance.
  163. * @param[in] p_line Pointer to the line object.
  164. * @param[in] color Color of the object in the display accepted format.
  165. *
  166. * @retval NRF_ERROR_INVALID_PARAM If object position is not on the screen.
  167. * @retval NRF_SUCCESS If object was successfully drawn.
  168. */
  169. ret_code_t nrf_gfx_line_draw(nrf_lcd_t const * p_instance, nrf_gfx_line_t const * p_line, uint32_t color);
  170. /**
  171. * @brief Function for drawing a circle.
  172. *
  173. * @param[in] p_instance Pointer to the LCD instance.
  174. * @param[in] p_circle Pointer to the circle object.
  175. * @param[in] color Color of the object in the display accepted format.
  176. * @param[in] fill If true, the circle will be filled.
  177. *
  178. * @retval NRF_ERROR_INVALID_PARAM If object position is not on the screen.
  179. * @retval NRF_SUCCESS If object was successfully drawn.
  180. *
  181. * @note The height and width of the drawn circle are determined by: radius * 2 + 1.
  182. *
  183. */
  184. ret_code_t nrf_gfx_circle_draw(nrf_lcd_t const * p_instance,
  185. nrf_gfx_circle_t const * p_circle,
  186. uint32_t color,
  187. bool fill);
  188. /**
  189. * @brief Function for drawing a rectangle.
  190. *
  191. * @param[in] p_instance Pointer to the LCD instance.
  192. * @param[in] p_rect Pointer to the rectangle object.
  193. * @param[in] thickness Thickness of the rectangle border.
  194. * @param[in] color Color of the object in the display accepted format.
  195. * @param[in] fill If true, the rectangle will be filled.
  196. *
  197. * @retval NRF_ERROR_INVALID_PARAM If object position is not on the screen.
  198. * @retval NRF_SUCCESS If object was successfully drawn.
  199. */
  200. ret_code_t nrf_gfx_rect_draw(nrf_lcd_t const * p_instance,
  201. nrf_gfx_rect_t const * p_rect,
  202. uint16_t thickness,
  203. uint32_t color,
  204. bool fill);
  205. /**
  206. * @brief Function for filling the screen with selected color.
  207. *
  208. * @param[in] p_instance Pointer to the LCD instance.
  209. * @param[in] color Color of the screen in the display accepted format.
  210. */
  211. void nrf_gfx_screen_fill(nrf_lcd_t const * p_instance, uint32_t color);
  212. /**
  213. * @brief Function for drawing an image from a .bmp file.
  214. *
  215. * Data in img_buf is expected to be stored in 2-byte samples, little endianness, RGB565 format.
  216. * Pointer should skip the header and point to the first byte of data.
  217. *
  218. * @param[in] p_instance Pointer to the LCD instance.
  219. * @param[in] p_rect Pointer to the rectangle object.
  220. * @param[in] img_buf Pointer to data from the .bmp file.
  221. *
  222. * @note Only compatible with displays that accept pixels in RGB565 format.
  223. */
  224. ret_code_t nrf_gfx_bmp565_draw(nrf_lcd_t const * p_instance,
  225. nrf_gfx_rect_t const * p_rect,
  226. uint16_t const * img_buf);
  227. /**
  228. * @brief Function for drawing an image from a .bmp file.
  229. *
  230. * Data in img_buf is expected to be stored in 2-byte samples, little endianness, RGB565 format.
  231. * Pointer should skip the header and point to the first byte of data.
  232. *
  233. * @param[in] p_instance Pointer to the LCD instance.
  234. * @param[in] img_buf Pointer to data from the .bmp file.
  235. *
  236. * @note Only compatible with displays that accept pixels in RGB565 format.
  237. */
  238. void nrf_gfx_background_set(nrf_lcd_t const * p_instance, uint16_t const * img_buf);
  239. /**
  240. * @brief Function for displaying data from an internal frame buffer.
  241. *
  242. * @param[in] p_instance Pointer to the LCD instance.
  243. */
  244. void nrf_gfx_display(nrf_lcd_t const * p_instance);
  245. /**
  246. * @brief Function for setting screen rotation.
  247. *
  248. * @param[in] p_instance Pointer to the LCD instance.
  249. * @param[in] rotation Rotation to be made.
  250. */
  251. void nrf_gfx_rotation_set(nrf_lcd_t const * p_instance, nrf_lcd_rotation_t rotation);
  252. /**
  253. * @brief Function for setting inversion of colors.
  254. *
  255. * @param[in] p_instance Pointer to the LCD instance.
  256. * @param[in] invert If true, inversion will be set.
  257. */
  258. void nrf_gfx_invert(nrf_lcd_t const * p_instance, bool invert);
  259. /**
  260. * @brief Function for printing a string to the screen.
  261. *
  262. * @param[in] p_instance Pointer to the LCD instance.
  263. * @param[in] p_point Pointer to the point where to start drawing the object.
  264. * @param[in] font_color Color of the font in the display accepted format.
  265. * @param[in] p_string Pointer to the string.
  266. * @param[in] p_font Pointer to the font descriptor.
  267. * @param[in] wrap If true, the string will be wrapped to the new line.
  268. */
  269. ret_code_t nrf_gfx_print(nrf_lcd_t const * p_instance,
  270. nrf_gfx_point_t const * p_point,
  271. uint16_t font_color,
  272. const char * p_string,
  273. const nrf_gfx_font_desc_t * p_font,
  274. bool wrap);
  275. /**
  276. * @brief Function for getting the height of the screen.
  277. *
  278. * @param[in] p_instance Pointer to the LCD instance.
  279. *
  280. */
  281. uint16_t nrf_gfx_height_get(nrf_lcd_t const * p_instance);
  282. /**
  283. * @brief Function for getting the width of the screen.
  284. *
  285. * @param[in] p_instance Pointer to the LCD instance.
  286. *
  287. */
  288. uint16_t nrf_gfx_width_get(nrf_lcd_t const * p_instance);
  289. /* @} */
  290. #endif //NRF_GFX_H__