ft80x.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /****************************************************************************
  2. * apps/include/graphics/ft80x.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 __APPS_INCLUDE_GRAPHICS_FT80X_H
  21. #define __APPS_INCLUDE_GRAPHICS_FT80X_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <stdint.h>
  28. #ifdef CONFIG_GRAPHICS_FT80X
  29. /****************************************************************************
  30. * Pre-processor Definitions
  31. ****************************************************************************/
  32. /* Buffer size in units of words (truncating any unaligned bytes) */
  33. #define FT80X_DL_BUFSIZE (CONFIG_GRAPHICS_FT80X_BUFSIZE & ~3)
  34. #define FT80X_DL_BUFWORDS (CONFIG_GRAPHICS_FT80X_BUFSIZE >> 2)
  35. /****************************************************************************
  36. * Public Types
  37. ****************************************************************************/
  38. /* This structure defines the local display list buffer */
  39. struct ft80x_dlbuffer_s
  40. {
  41. bool coproc; /* True: Use co-processor FIFO; false: Use DL memory */
  42. uint16_t dlsize; /* Total sizeof the display list written to hardware */
  43. uint16_t dloffset; /* The number display list bytes buffered locally */
  44. uint32_t dlbuffer[FT80X_DL_BUFWORDS];
  45. };
  46. /* Describes touch sample */
  47. union ft80x_touchpos_u
  48. {
  49. uint32_t xy; /* To force 32-bit alignment */
  50. struct /* Little-endian */
  51. {
  52. int16_t x; /* Touch X position (-32768 if no touch) */
  53. int16_t y; /* Touch Y position (-32768 if no touch) */
  54. } u;
  55. };
  56. struct ft80x_touchinfo_s
  57. {
  58. uint8_t tag; /* Touch 0 tag */
  59. #if defined(CONFIG_LCD_FT800)
  60. int16_t pressure; /* Touch pressure (32767 if not touched) */
  61. #endif
  62. union ft80x_touchpos_u tagpos; /* Position associated with tag */
  63. #if defined(CONFIG_LCD_FT800) || !defined(CONFIG_LCD_FT801_MULTITOUCH)
  64. union ft80x_touchpos_u pos; /* Current touch position */
  65. #else
  66. union ft80x_touchpos_u pos[4]; /* Current touch position for up to 5 touches */
  67. #endif
  68. };
  69. /****************************************************************************
  70. * Public Function Prototypes
  71. ****************************************************************************/
  72. #ifdef __cplusplus
  73. #define EXTERN extern "C"
  74. extern "C"
  75. {
  76. #else
  77. #define EXTERN extern
  78. #endif
  79. /****************************************************************************
  80. * Name: ft80x_dl_start
  81. *
  82. * Description:
  83. * Start a new display list. This function will:
  84. *
  85. * 1) Set the total display list size to zero
  86. * 2) Set the display list buffer offset to zero
  87. * 3) Reposition the VFS so that subsequent writes will be to the
  88. * beginning of the hardware display list.
  89. * 4) Write the CMD_DLSTART command into the local display list buffer
  90. * (Only for co-processor commands)
  91. *
  92. * Input Parameters:
  93. * fd - The file descriptor of the FT80x device. Opened by the caller
  94. * with write access.
  95. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller.
  96. * coproc - True: Use co-processor FIFO; false: Use DL memory.
  97. *
  98. * Returned Value:
  99. * Zero (OK) on success. A negated errno value on failure.
  100. *
  101. ****************************************************************************/
  102. int ft80x_dl_start(int fd, FAR struct ft80x_dlbuffer_s *buffer, bool coproc);
  103. /****************************************************************************
  104. * Name: ft80x_dl_end
  105. *
  106. * Description:
  107. * Terminate the display list. This function will:
  108. *
  109. * 1) Add the DISPLAY command to the local display list buffer to finish
  110. * the last display
  111. * 2) If using co-processor RAM CMD, add the CMD_SWAP to the DL command
  112. * list
  113. * 3) Flush the local display buffer to hardware and set the display list
  114. * buffer offset to zero.
  115. * 4) Swap to the newly created display list (DL memory case only).
  116. * 5) For the case of the co-processor RAM CMD, it will also wait for the
  117. * FIFO to be emptied.
  118. *
  119. * Input Parameters:
  120. * fd - The file descriptor of the FT80x device. Opened by the caller
  121. * with write access.
  122. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller.
  123. *
  124. * Returned Value:
  125. * Zero (OK) on success. A negated errno value on failure.
  126. *
  127. ****************************************************************************/
  128. int ft80x_dl_end(int fd, FAR struct ft80x_dlbuffer_s *buffer);
  129. /****************************************************************************
  130. * Name: ft80x_dl_data
  131. *
  132. * Description:
  133. * Add data to the display list and increment the display list buffer
  134. * offset. If the data will not fit into the local display buffer, then
  135. * the local display buffer will first be flushed to hardware in order to
  136. * free up space.
  137. *
  138. * Input Parameters:
  139. * fd - The file descriptor of the FT80x device. Opened by the caller
  140. * with write access.
  141. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller.
  142. * data - The data to be added to the display list
  143. * datlen - The length of the data to be added to the display list. If
  144. * this is not an even multiple of 4 bytes, then the actual length
  145. * will be padded with zero bytes to achieve alignment.
  146. *
  147. * Returned Value:
  148. * Zero (OK) on success. A negated errno value on failure.
  149. *
  150. ****************************************************************************/
  151. int ft80x_dl_data(int fd, FAR struct ft80x_dlbuffer_s *buffer,
  152. FAR const void *data, size_t datlen);
  153. /****************************************************************************
  154. * Name: ft80x_dl_string
  155. *
  156. * Description:
  157. * Add the string along with its NUL terminator to the display list and
  158. * increment the display list buffer offset. If the length of the string
  159. * with its NUL terminator is not an even multiple of 4 bytes, then the
  160. * actual length will be padded with zero bytes to achieve alignment.
  161. *
  162. * If the data will not fit into the local display buffer, then the local
  163. * display buffer will first be flushed to hardware in order to free up
  164. * space.
  165. *
  166. * Input Parameters:
  167. * fd - The file descriptor of the FT80x device. Opened by the caller
  168. * with write access.
  169. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller.
  170. * str - The string to be added to the display list. If NUL, then a
  171. * NUL string will be added to the display list.
  172. *
  173. * Returned Value:
  174. * Zero (OK) on success. A negated errno value on failure.
  175. *
  176. ****************************************************************************/
  177. int ft80x_dl_string(int fd, FAR struct ft80x_dlbuffer_s *buffer,
  178. FAR const char *str);
  179. /****************************************************************************
  180. * Name: ft80x_dl_flush
  181. *
  182. * Description:
  183. * Flush the current contents of the local local display list buffer to
  184. * hardware and reset the local display list buffer offset to zero.
  185. *
  186. * Input Parameters:
  187. * fd - The file descriptor of the FT80x device. Opened by the caller
  188. * with write access.
  189. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller.
  190. * wait - True: wait until data has been consumed by the co-processor
  191. * (only for co-processor destination); false: Send to hardware
  192. * and return immediately.
  193. *
  194. * Returned Value:
  195. * Zero (OK) on success. A negated errno value on failure.
  196. *
  197. ****************************************************************************/
  198. int ft80x_dl_flush(int fd, FAR struct ft80x_dlbuffer_s *buffer, bool wait);
  199. /****************************************************************************
  200. * Name: ft80x_dl_create
  201. *
  202. * Description:
  203. * For simple display lists, this function combines all functionality into
  204. * a single combined. This function does the following:
  205. *
  206. * 1) Calls ft80x_dl_dlstart() to initialize the display list.
  207. * 2) Calls ft80x_dl_data() to transfer the simple display list
  208. * 3) Calls ft80x_dl_end() to complete the display list
  209. *
  210. * Input Parameters:
  211. * fd - The file descriptor of the FT80x device. Opened by the caller
  212. * with write access.
  213. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the caller.
  214. * data - Pointer to a uint32_t array containing the simple display list
  215. * nwords - The number of 32-bit words in the array.
  216. * coproc - True: Use co-processor FIFO; false: Use DL memory.
  217. *
  218. * Returned Value:
  219. * Zero (OK) on success. A negated errno value on failure.
  220. *
  221. ****************************************************************************/
  222. int ft80x_dl_create(int fd, FAR struct ft80x_dlbuffer_s *buffer,
  223. FAR const uint32_t *cmds, unsigned int nwords,
  224. bool coproc);
  225. /****************************************************************************
  226. * Name: ft80x_coproc_send
  227. *
  228. * Description:
  229. * Send commands to the co-processor via the CMD RAM FIFO. This function
  230. * will not return until the command has been consumed by the co-processor.
  231. *
  232. * NOTE: This command is not appropriate use while a display is being
  233. * formed. It is will mess up the CMD RAM FIFO offsets managed by the
  234. * display list logic.
  235. *
  236. * Input Parameters:
  237. * fd - The file descriptor of the FT80x device. Opened by the caller
  238. * with write access.
  239. * cmds - A list of 32-bit commands to be sent.
  240. * ncmds - The number of commands in the list.
  241. *
  242. * Returned Value:
  243. * Zero (OK) on success. A negated errno value on failure.
  244. *
  245. ****************************************************************************/
  246. int ft80x_coproc_send(int fd, FAR const uint32_t *cmds, size_t ncmds);
  247. /****************************************************************************
  248. * Name: ft80x_coproc_waitlogo
  249. *
  250. * Description:
  251. * Wait for the logo animation to complete. The logo command causes the
  252. * co-processor engine to play back a short animation of the FTDI logo.
  253. * During logo playback the MCU should not access any FT800 resources.
  254. * After 2.5 seconds have elapsed, the co-processor engine writes zero to
  255. * REG_CMD_READ and REG_CMD_WRITE, and starts waiting for commands. After
  256. * this command is complete, the MCU shall write the next command to the
  257. * starting address of RAM_CMD.
  258. *
  259. * Input Parameters:
  260. * fd - The file descriptor of the FT80x device. Opened by the caller
  261. * with write access.
  262. *
  263. * Returned Value:
  264. * Zero (OK) on success. A negated errno value on failure.
  265. *
  266. ****************************************************************************/
  267. int ft80x_coproc_waitlogo(int fd);
  268. /****************************************************************************
  269. * Name: ft80x_ramg_write
  270. *
  271. * Description:
  272. * Write to graphics memory
  273. *
  274. * Input Parameters:
  275. * fd - The file descriptor of the FT80x device. Opened by the caller
  276. * with write access.
  277. * offset - Offset in graphics memory to write to (dest)
  278. * data - Pointer to a data to be written (src)
  279. * nbytes - The number of bytes to write to graphics memory.
  280. *
  281. * Returned Value:
  282. * Zero (OK) on success. A negated errno value on failure.
  283. *
  284. ****************************************************************************/
  285. int ft80x_ramg_write(int fd, unsigned int offset, FAR const void *data,
  286. unsigned int nbytes);
  287. /****************************************************************************
  288. * Name: ft80x_touch_gettransform
  289. *
  290. * Description:
  291. * Read the touch transform matrix
  292. *
  293. * Input Parameters:
  294. * fd - The file descriptor of the FT80x device. Opened by the caller
  295. * with write access.
  296. * matrix - The location to return the transform matrix
  297. *
  298. * Returned Value:
  299. * Zero (OK) on success. A negated errno value on failure.
  300. *
  301. ****************************************************************************/
  302. int ft80x_touch_gettransform(int fd, FAR uint32_t matrix[6]);
  303. /****************************************************************************
  304. * Name: ft80x_touch_tag
  305. *
  306. * Description:
  307. * Read the current touch tag. The touch tag is an 8-bit value
  308. * identifying the specific graphics object on the screen that is being
  309. * touched. The value zero indicates that there is no graphic object being
  310. * touched.
  311. *
  312. * Only a single touch can be queried. For the FT801 in "extended",
  313. * multi-touch mode, this value indicates only the tag associated with
  314. * touch 0.
  315. *
  316. * Input Parameters:
  317. * fd - The file descriptor of the FT80x device. Opened by the caller
  318. * with write access.
  319. *
  320. * Returned Value:
  321. * A value of 1-255 is returned if a graphics object is touched. Zero is
  322. * returned if no graphics object is touched. A negated errno value on
  323. * failure.
  324. *
  325. ****************************************************************************/
  326. int ft80x_touch_tag(int fd);
  327. /****************************************************************************
  328. * Name: ft80x_touch_waittag
  329. *
  330. * Description:
  331. * Wait until there is a change in the touch tag.
  332. *
  333. * Input Parameters:
  334. * fd - The file descriptor of the FT80x device. Opened by the caller
  335. * with write access.
  336. * oldtag - The previous tag value. This function will return when the
  337. * current touch tag differs from this value.
  338. *
  339. * Returned Value:
  340. * A value of 1-255 is returned if a graphics object is touched. Zero is
  341. * returned if no graphics object is touched. A negated errno value on
  342. * failure.
  343. *
  344. ****************************************************************************/
  345. int ft80x_touch_waittag(int fd, uint8_t oldtag);
  346. /****************************************************************************
  347. * Name: ft80x_touch_info
  348. *
  349. * Description:
  350. * Return the current touch tag and touch position information.
  351. *
  352. * For the FT801 in "extended", multi-touch mode, the tag value indicates
  353. * only the tag associated with touch 0.
  354. *
  355. * Touch positions of -32768 indicate that no touch is detected.
  356. *
  357. * Input Parameters:
  358. * fd - The file descriptor of the FT80x device. Opened by the caller
  359. * with write access.
  360. * info - Location in which to return the touch information
  361. *
  362. * Returned Value:
  363. * A value of 1-255 is returned if a graphics object is touched. Zero is
  364. * returned if no graphics object is touched. A negated errno value on
  365. * failure.
  366. *
  367. ****************************************************************************/
  368. int ft80x_touch_info(int fd, FAR struct ft80x_touchinfo_s *info);
  369. /****************************************************************************
  370. * Name: ft80x_audio_enable
  371. *
  372. * Description:
  373. * Play an short sound effect. If there is a audio amplifier on board
  374. * (such as TPA6205A or LM4864), then there may also be an active low
  375. * audio shutdown output. That output is controlled by this interface.
  376. *
  377. * Input Parameters:
  378. * fd - The file descriptor of the FT80x device. Opened by the
  379. * caller with write access.
  380. * enable - True: Enabled the audio amplifier; false: disable
  381. *
  382. * Returned Value:
  383. * Zero (OK) on success. A negated errno value on failure.
  384. *
  385. ****************************************************************************/
  386. int ft80x_audio_enable(int fd, bool enable);
  387. /****************************************************************************
  388. * Name: ft80x_audio_playsound
  389. *
  390. * Description:
  391. * Play an short sound effect.
  392. *
  393. * NOTE: It may be necessary to enable the audio amplifier with
  394. * ft80x_audio_enable() prior to calling this function.
  395. *
  396. * Input Parameters:
  397. * fd - The file descriptor of the FT80x device. Opened by the
  398. * caller with write access.
  399. * effect - The sound effect to use (see FT80X_EFFECT_* definitions).
  400. * pitch - Pitch associated with the sound effect (see FT80X_NOTE_*
  401. * definitions). May be zero if there is no pitch associated
  402. * with the effect.
  403. *
  404. * Returned Value:
  405. * Zero (OK) on success. A negated errno value on failure.
  406. *
  407. ****************************************************************************/
  408. int ft80x_audio_playsound(int fd, uint16_t effect, uint16_t pitch);
  409. /****************************************************************************
  410. * Name: ft80x_audio_playfile
  411. *
  412. * Description:
  413. * Play an audio file. Audio files must consist of raw sample data.
  414. *
  415. * NOTE: It may be necessary to enable the audio amplifier with
  416. * ft80x_audio_enable() prior to calling this function.
  417. *
  418. * Input Parameters:
  419. * fd - The file descriptor of the FT80x device. Opened by the
  420. * caller with write access.
  421. * buffer - An instance of struct ft80x_dlbuffer_s allocated by the
  422. * caller.
  423. * filepath - Absolute path to the audio file
  424. * format - Audio format. One of:
  425. *
  426. * AUDIO_FORMAT_LINEAR Linear Sample format
  427. * AUDIO_FORMAT_ULAW uLaw Sample format
  428. * AUDIO_FORMAT_ADPCM 4-bit IMA ADPCM Sample format
  429. *
  430. * frequency - Audio sample frequency (<65,536)
  431. * volume - Playback volume (0=mute; 255=max)
  432. *
  433. * Returned Value:
  434. * Zero (OK) on success. A negated errno value on failure.
  435. *
  436. ****************************************************************************/
  437. int ft80x_audio_playfile(int fd, FAR struct ft80x_dlbuffer_s *buffer,
  438. FAR const char *filepath, uint8_t format,
  439. uint16_t frequency, uint8_t volume);
  440. /****************************************************************************
  441. * Name: ft80x_backlight_set
  442. *
  443. * Description:
  444. * Set the backlight intensity via the PWM duty.
  445. *
  446. * Input Parameters:
  447. * fd - The file descriptor of the FT80x device. Opened by the caller
  448. * with write access.
  449. * duty - The new backlight duty (as a percentage 0..100)
  450. *
  451. * Returned Value:
  452. * Zero (OK) on success. A negated errno value on failure.
  453. *
  454. ****************************************************************************/
  455. int ft80x_backlight_set(int fd, uint8_t duty);
  456. /****************************************************************************
  457. * Name: ft80x_backlight_fade
  458. *
  459. * Description:
  460. * Change the backlight intensity with a controllable fade.
  461. *
  462. * Input Parameters:
  463. * fd - The file descriptor of the FT80x device. Opened by the caller
  464. * with write access.
  465. * duty - The terminal duty (as a percentage 0..100)
  466. * delay - The duration of the fade in milliseconds (10..16700).
  467. *
  468. * Returned Value:
  469. * Zero (OK) on success. A negated errno value on failure.
  470. *
  471. ****************************************************************************/
  472. int ft80x_backlight_fade(int fd, uint8_t duty, uint16_t delay);
  473. /****************************************************************************
  474. * Name: ft80x_gpio_configure
  475. *
  476. * Description:
  477. * Configure an FT80x GPIO pin
  478. *
  479. * Input Parameters:
  480. * fd - The file descriptor of the FT80x device. Opened by the caller
  481. * with write access.
  482. * gpio - Identifies the GPIO pin {0,1}
  483. * dir - Direction: 0=input, 1=output
  484. * drive - Common output drive strength for GPIO 0 and 1 (see
  485. * FT80X_GPIO_DRIVE_* definitions). Default is 4mA.
  486. * value - Initial value for output pins
  487. *
  488. * Returned Value:
  489. * Zero (OK) on success. A negated errno value on failure.
  490. *
  491. ****************************************************************************/
  492. int ft80x_gpio_configure(int fd, uint8_t gpio, uint8_t dir, uint8_t drive,
  493. bool value);
  494. /****************************************************************************
  495. * Name: ft80x_gpio_write
  496. *
  497. * Description:
  498. * Write a value to a pin configured for output
  499. *
  500. * Input Parameters:
  501. * fd - The file descriptor of the FT80x device. Opened by the caller
  502. * with write access.
  503. * gpio - Identifies the GPIO pin {0,1}
  504. * value - True: high, false: low
  505. *
  506. * Returned Value:
  507. * Zero (OK) on success. A negated errno value on failure.
  508. *
  509. ****************************************************************************/
  510. int ft80x_gpio_write(int fd, uint8_t gpio, bool value);
  511. /****************************************************************************
  512. * Name: ft80x_gpio_read
  513. *
  514. * Description:
  515. * Read the value from a pin configured for input
  516. *
  517. * Input Parameters:
  518. * fd - The file descriptor of the FT80x device. Opened by the caller
  519. * with write access.
  520. * gpio - Identifies the GPIO pin {0,1}
  521. *
  522. * Returned Value:
  523. * True: high, false: low
  524. *
  525. ****************************************************************************/
  526. bool ft80x_gpio_read(int fd, uint8_t gpio);
  527. #undef EXTERN
  528. #ifdef __cplusplus
  529. }
  530. #endif
  531. #endif /* CONFIG_GRAPHICS_FT80X */
  532. #endif /* __APPS_INCLUDE_GRAPHICS_FT80X_H */