nxterm_internal.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /****************************************************************************
  2. * apps/examples/nxterm/nxterm_internal.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __EXAMPLES_NXTERM_NXTERM_INTERNAL_H
  21. #define __EXAMPLES_NXTERM_NXTERM_INTERNAL_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <semaphore.h>
  29. #include <nuttx/video/rgbcolors.h>
  30. #include <nuttx/nx/nx.h>
  31. #include <nuttx/nx/nxglib.h>
  32. #include <nuttx/nx/nxtk.h>
  33. #include <nuttx/nx/nxterm.h>
  34. /****************************************************************************
  35. * Pre-processor Definitions
  36. ****************************************************************************/
  37. /* Configuration ************************************************************/
  38. /* Need NX graphics support */
  39. #ifndef CONFIG_NX
  40. # error "NX is not enabled (CONFIG_NX=y)"
  41. #endif
  42. /* Can't do the NxTerm example if the NxTerm driver is not built */
  43. #ifndef CONFIG_NXTERM
  44. # error "NxTerm is not enabled (CONFIG_NXTERM=y)"
  45. #endif
  46. /* If there is no NSH console, then why are we running this example? */
  47. #ifndef CONFIG_NSH_CONSOLE
  48. # warning "Expected CONFIG_NSH_CONSOLE=y"
  49. #endif
  50. /* If not specified, assume that the hardware supports one video plane */
  51. #if CONFIG_NX_NPLANES != 1
  52. # error "Only CONFIG_NX_NPLANES==1 supported"
  53. #endif
  54. /* Pixel depth. If none provided, pick the smallest enabled pixel depth */
  55. #if defined(CONFIG_EXAMPLES_NXTERM_BPP) && \
  56. CONFIG_EXAMPLES_NXTERM_BPP != 1 && \
  57. CONFIG_EXAMPLES_NXTERM_BPP != 2 && \
  58. CONFIG_EXAMPLES_NXTERM_BPP != 4 && \
  59. CONFIG_EXAMPLES_NXTERM_BPP != 8 && \
  60. CONFIG_EXAMPLES_NXTERM_BPP != 16 && \
  61. CONFIG_EXAMPLES_NXTERM_BPP != 32
  62. # error Invalid selection for CONFIG_EXAMPLES_NXTERM_BPP
  63. # undef CONFIG_EXAMPLES_NXTERM_BPP
  64. #endif
  65. #ifndef CONFIG_EXAMPLES_NXTERM_BPP
  66. # if !defined(CONFIG_NX_DISABLE_1BPP)
  67. # define CONFIG_EXAMPLES_NXTERM_BPP 1
  68. # elif !defined(CONFIG_NX_DISABLE_2BPP)
  69. # define CONFIG_EXAMPLES_NXTERM_BPP 2
  70. # elif !defined(CONFIG_NX_DISABLE_4BPP)
  71. # define CONFIG_EXAMPLES_NXTERM_BPP 4
  72. # elif !defined(CONFIG_NX_DISABLE_8BPP)
  73. # define CONFIG_EXAMPLES_NXTERM_BPP 8
  74. # elif !defined(CONFIG_NX_DISABLE_16BPP)
  75. # define CONFIG_EXAMPLES_NXTERM_BPP 16
  76. //#elif !defined(CONFIG_NX_DISABLE_24BPP)
  77. //# define CONFIG_NXTERM_BPP 24
  78. # elif !defined(CONFIG_NX_DISABLE_32BPP)
  79. # define CONFIG_EXAMPLES_NXTERM_BPP 32
  80. # else
  81. # error "No pixel depth provided"
  82. # endif
  83. #endif
  84. /* Background color (default is darker royal blue) */
  85. #ifndef CONFIG_EXAMPLES_NXTERM_BGCOLOR
  86. # if CONFIG_EXAMPLES_NXTERM_BPP == 24 || CONFIG_EXAMPLES_NXTERM_BPP == 32
  87. # define CONFIG_EXAMPLES_NXTERM_BGCOLOR RGBTO24(39, 64, 139)
  88. # elif CONFIG_EXAMPLES_NXTERM_BPP == 16
  89. # define CONFIG_EXAMPLES_NXTERM_BGCOLOR RGBTO16(39, 64, 139)
  90. # else
  91. # define CONFIG_EXAMPLES_NXTERM_BGCOLOR RGBTO8(39, 64, 139)
  92. # endif
  93. #endif
  94. /* Window color (lighter steel blue) */
  95. #ifndef CONFIG_EXAMPLES_NXTERM_WCOLOR
  96. # if CONFIG_EXAMPLES_NXTERM_BPP == 24 || CONFIG_EXAMPLES_NXTERM_BPP == 32
  97. # define CONFIG_EXAMPLES_NXTERM_WCOLOR RGBTO24(202, 225, 255)
  98. # elif CONFIG_EXAMPLES_NXTERM_BPP == 16
  99. # define CONFIG_EXAMPLES_NXTERM_WCOLOR RGBTO16(202, 225, 255)
  100. # else
  101. # define CONFIG_EXAMPLES_NXTERM_WCOLOR RGBTO8(202, 225, 255)
  102. # endif
  103. #endif
  104. /* Toolbar color (medium grey) */
  105. #ifndef CONFIG_EXAMPLES_NXTERM_TBCOLOR
  106. # if CONFIG_EXAMPLES_NXTERM_BPP == 24 || CONFIG_EXAMPLES_NXTERM_BPP == 32
  107. # define CONFIG_EXAMPLES_NXTERM_TBCOLOR RGBTO24(188, 188, 188)
  108. # elif CONFIG_EXAMPLES_NXTERM_BPP == 16
  109. # define CONFIG_EXAMPLES_NXTERM_TBCOLOR RGBTO16(188, 188, 188)
  110. # else
  111. # define CONFIG_EXAMPLES_NXTERM_TBCOLOR RGBTO8(188, 188, 188)
  112. # endif
  113. #endif
  114. /* Font ID */
  115. #ifndef CONFIG_EXAMPLES_NXTERM_FONTID
  116. # define CONFIG_EXAMPLES_NXTERM_FONTID NXFONT_DEFAULT
  117. #endif
  118. /* Font color */
  119. #ifndef CONFIG_EXAMPLES_NXTERM_FONTCOLOR
  120. # if CONFIG_EXAMPLES_NXTERM_BPP == 24 || CONFIG_EXAMPLES_NXTERM_BPP == 32
  121. # define CONFIG_EXAMPLES_NXTERM_FONTCOLOR RGBTO24(0, 0, 0)
  122. # elif CONFIG_EXAMPLES_NXTERM_BPP == 16
  123. # define CONFIG_EXAMPLES_NXTERM_FONTCOLOR RGBTO16(0, 0, 0)
  124. # else
  125. # define CONFIG_EXAMPLES_NXTERM_FONTCOLOR RGBTO8(0, 0, 0)
  126. # endif
  127. #endif
  128. /* Height of the toolbar */
  129. #ifndef CONFIG_EXAMPLES_NXTERM_TOOLBAR_HEIGHT
  130. # define CONFIG_EXAMPLES_NXTERM_TOOLBAR_HEIGHT 16
  131. #endif
  132. /* Multi-user NX support */
  133. #ifdef CONFIG_DISABLE_MQUEUE
  134. # error "The multi-threaded example requires MQ support (CONFIG_DISABLE_MQUEUE=n)"
  135. #endif
  136. #ifdef CONFIG_DISABLE_PTHREAD
  137. # error "This example requires pthread support (CONFIG_DISABLE_PTHREAD=n)"
  138. #endif
  139. #ifndef CONFIG_NX_BLOCKING
  140. # error "This example depends on CONFIG_NX_BLOCKING"
  141. #endif
  142. #ifndef CONFIG_EXAMPLES_NXTERM_STACKSIZE
  143. # define CONFIG_EXAMPLES_NXTERM_STACKSIZE 2048
  144. #endif
  145. #ifndef CONFIG_EXAMPLES_NXTERM_LISTENERPRIO
  146. # define CONFIG_EXAMPLES_NXTERM_LISTENERPRIO 100
  147. #endif
  148. #ifndef CONFIG_EXAMPLES_NXTERM_CLIENTPRIO
  149. # define CONFIG_EXAMPLES_NXTERM_CLIENTPRIO 100
  150. #endif
  151. #ifndef CONFIG_EXAMPLES_NXTERM_SERVERPRIO
  152. # define CONFIG_EXAMPLES_NXTERM_SERVERPRIO 120
  153. #endif
  154. #ifndef CONFIG_EXAMPLES_NXTERM_NOTIFYSIGNO
  155. # define CONFIG_EXAMPLES_NXTERM_NOTIFYSIGNO 4
  156. #endif
  157. /* NX Console Device */
  158. #ifndef CONFIG_EXAMPLES_NXTERM_MINOR
  159. # define CONFIG_EXAMPLES_NXTERM_MINOR 0
  160. #endif
  161. #ifndef CONFIG_EXAMPLES_NXTERM_DEVNAME
  162. # define CONFIG_EXAMPLES_NXTERM_DEVNAME "/dev/nxterm0"
  163. #endif
  164. /* NxTerm task */
  165. #ifndef CONFIG_EXAMPLES_NXTERM_PRIO
  166. # define CONFIG_EXAMPLES_NXTERM_PRIO SCHED_PRIORITY_DEFAULT
  167. #endif
  168. #ifndef CONFIG_EXAMPLES_NXTERM_STACKSIZE
  169. # define CONFIG_EXAMPLES_NXTERM_STACKSIZE 2048
  170. #endif
  171. /****************************************************************************
  172. * Public Types
  173. ****************************************************************************/
  174. /* All example global variables are retained in a structure to minimize
  175. * the chance of name collisions.
  176. */
  177. struct nxterm_state_s
  178. {
  179. volatile bool haveres; /* True: Have screen resolution */
  180. volatile bool connected; /* True: Connected to server */
  181. sem_t eventsem; /* Control waiting for display events */
  182. pid_t pid; /* Console task ID */
  183. NXHANDLE hnx; /* The connection handler */
  184. NXTKWINDOW hwnd; /* The window */
  185. NXTERM hdrvr; /* The console driver */
  186. struct nxterm_window_s wndo; /* Describes the window */
  187. nxgl_coord_t xres; /* Screen X resolution */
  188. nxgl_coord_t yres; /* Screen Y resolution */
  189. struct nxgl_size_s wsize; /* Window size */
  190. struct nxgl_point_s wpos; /* Window position */
  191. };
  192. /****************************************************************************
  193. * Public Data
  194. ****************************************************************************/
  195. /* All example global variables are retained in a structure to minimize
  196. * the chance of name collisions.
  197. */
  198. extern struct nxterm_state_s g_nxterm_vars;
  199. /* NX callback vtables */
  200. extern const struct nx_callback_s g_nxtermcb;
  201. extern const struct nx_callback_s g_nxtoolcb;
  202. /****************************************************************************
  203. * Public Function Prototypes
  204. ****************************************************************************/
  205. /* Server thread support */
  206. FAR void *nxterm_listener(FAR void *arg);
  207. #endif /* __EXAMPLES_NXTERM_NXTERM_INTERNAL_H */