1
0

em_ebi.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. /***************************************************************************//**
  2. * @file
  3. * @brief External Bus Iterface (EBI) peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #ifndef __EM_EBI_H
  34. #define __EM_EBI_H
  35. #include "em_part.h"
  36. #if defined(EBI_COUNT) && (EBI_COUNT > 0)
  37. #include "em_assert.h"
  38. #include <stdint.h>
  39. #include <stdbool.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /***************************************************************************//**
  44. * @addtogroup EM_Library
  45. * @{
  46. ******************************************************************************/
  47. /***************************************************************************//**
  48. * @addtogroup EBI
  49. * @{
  50. ******************************************************************************/
  51. /***************************************************************************//**
  52. * @verbatim
  53. *
  54. * --------- ---------
  55. * | EBI | /| |\ | Ext. |
  56. * | | / --------- \ | Async |
  57. * |(EFM32)| \ --------- / | Device|
  58. * | | \| |/ | |
  59. * --------- ---------
  60. * Parallel interface
  61. *
  62. * @endverbatim
  63. ******************************************************************************/
  64. /*******************************************************************************
  65. ******************************* DEFINES ***********************************
  66. ******************************************************************************/
  67. #define EBI_BANK0 (uint32_t)(1 << 1) /**< EBI address bank 0 */
  68. #define EBI_BANK1 (uint32_t)(1 << 2) /**< EBI address bank 1 */
  69. #define EBI_BANK2 (uint32_t)(1 << 3) /**< EBI address bank 2 */
  70. #define EBI_BANK3 (uint32_t)(1 << 4) /**< EBI address bank 3 */
  71. #define EBI_CS0 (uint32_t)(1 << 1) /**< EBI chip select line 0 */
  72. #define EBI_CS1 (uint32_t)(1 << 2) /**< EBI chip select line 1 */
  73. #define EBI_CS2 (uint32_t)(1 << 3) /**< EBI chip select line 2 */
  74. #define EBI_CS3 (uint32_t)(1 << 4) /**< EBI chip select line 3 */
  75. /*******************************************************************************
  76. ******************************** ENUMS ************************************
  77. ******************************************************************************/
  78. /** EBI Mode of operation */
  79. typedef enum
  80. {
  81. /** 8 data bits, 8 address bits */
  82. ebiModeD8A8 = EBI_CTRL_MODE_D8A8,
  83. /** 16 data bits, 16 address bits, using address latch enable */
  84. ebiModeD16A16ALE = EBI_CTRL_MODE_D16A16ALE,
  85. /** 8 data bits, 24 address bits, using address latch enable */
  86. ebiModeD8A24ALE = EBI_CTRL_MODE_D8A24ALE,
  87. /** Mode D16 */
  88. #if defined(_EFM32_GIANT_FAMILY)
  89. ebiModeD16 = EBI_CTRL_MODE_D16,
  90. #endif
  91. } EBI_Mode_TypeDef;
  92. /** EBI Polarity configuration */
  93. typedef enum
  94. {
  95. /** Active Low */
  96. ebiActiveLow = 0,
  97. /** Active High */
  98. ebiActiveHigh = 1
  99. } EBI_Polarity_TypeDef;
  100. /** EBI Pin Line types */
  101. typedef enum
  102. {
  103. /** Address Ready line */
  104. ebiLineARDY,
  105. /** Address Latch Enable line */
  106. ebiLineALE,
  107. /** Write Enable line */
  108. ebiLineWE,
  109. /** Read Enable line */
  110. ebiLineRE,
  111. /** Chip Select line */
  112. ebiLineCS,
  113. #if defined(_EFM32_GIANT_FAMILY)
  114. /** BL line */
  115. ebiLineBL,
  116. #endif
  117. #if defined(_EFM32_GIANT_FAMILY)
  118. /** TFT VSYNC line */
  119. ebiLineTFTVSync,
  120. /** TFT HSYNC line */
  121. ebiLineTFTHSync,
  122. /** TFT Data enable line */
  123. ebiLineTFTDataEn,
  124. /** TFT DCLK line */
  125. ebiLineTFTDClk,
  126. /** TFT Chip select line */
  127. ebiLineTFTCS,
  128. #endif
  129. } EBI_Line_TypeDef;
  130. #if defined(_EFM32_GIANT_FAMILY)
  131. /** Address Pin Enable, lower limit - lower range of pins to enable */
  132. typedef enum
  133. {
  134. /** Adress lines EBI_A[0] and upwards are enabled by APEN */
  135. ebiALowA0 = EBI_ROUTE_ALB_A0,
  136. /** Adress lines EBI_A[8] and upwards are enabled by APEN */
  137. ebiALowA8 = EBI_ROUTE_ALB_A8,
  138. /** Adress lines EBI_A[16] and upwards are enabled by APEN */
  139. ebiALowA16 = EBI_ROUTE_ALB_A16,
  140. /** Adress lines EBI_A[24] and upwards are enabled by APEN */
  141. ebiALowA24 = EBI_ROUTE_ALB_A24,
  142. } EBI_ALow_TypeDef;
  143. /** Adress Pin Enable, high limit - higher limit of pins to enable */
  144. typedef enum
  145. {
  146. /** All EBI_A pins are disabled */
  147. ebiAHighA0 = EBI_ROUTE_APEN_A0,
  148. /** All EBI_A[4:ALow] are enabled */
  149. ebiAHighA5 = EBI_ROUTE_APEN_A5,
  150. /** All EBI_A[5:ALow] are enabled */
  151. ebiAHighA6 = EBI_ROUTE_APEN_A6,
  152. /** All EBI_A[6:ALow] are enabled */
  153. ebiAHighA7 = EBI_ROUTE_APEN_A7,
  154. /** All EBI_A[7:ALow] are enabled */
  155. ebiAHighA8 = EBI_ROUTE_APEN_A8,
  156. /** All EBI_A[8:ALow] are enabled */
  157. ebiAHighA9 = EBI_ROUTE_APEN_A9,
  158. /** All EBI_A[9:ALow] are enabled */
  159. ebiAHighA10 = EBI_ROUTE_APEN_A10,
  160. /** All EBI_A[10:ALow] are enabled */
  161. ebiAHighA11 = EBI_ROUTE_APEN_A11,
  162. /** All EBI_A[11:ALow] are enabled */
  163. ebiAHighA12 = EBI_ROUTE_APEN_A12,
  164. /** All EBI_A[12:ALow] are enabled */
  165. ebiAHighA13 = EBI_ROUTE_APEN_A13,
  166. /** All EBI_A[13:ALow] are enabled */
  167. ebiAHighA14 = EBI_ROUTE_APEN_A14,
  168. /** All EBI_A[14:ALow] are enabled */
  169. ebiAHighA15 = EBI_ROUTE_APEN_A15,
  170. /** All EBI_A[15:ALow] are enabled */
  171. ebiAHighA16 = EBI_ROUTE_APEN_A16,
  172. /** All EBI_A[16:ALow] are enabled */
  173. ebiAHighA17 = EBI_ROUTE_APEN_A17,
  174. /** All EBI_A[17:ALow] are enabled */
  175. ebiAHighA18 = EBI_ROUTE_APEN_A18,
  176. /** All EBI_A[18:ALow] are enabled */
  177. ebiAHighA19 = EBI_ROUTE_APEN_A19,
  178. /** All EBI_A[19:ALow] are enabled */
  179. ebiAHighA20 = EBI_ROUTE_APEN_A20,
  180. /** All EBI_A[20:ALow] are enabled */
  181. ebiAHighA21 = EBI_ROUTE_APEN_A21,
  182. /** All EBI_A[21:ALow] are enabled */
  183. ebiAHighA22 = EBI_ROUTE_APEN_A22,
  184. /** All EBI_A[22:ALow] are enabled */
  185. ebiAHighA23 = EBI_ROUTE_APEN_A23,
  186. /** All EBI_A[23:ALow] are enabled */
  187. ebiAHighA24 = EBI_ROUTE_APEN_A24,
  188. /** All EBI_A[24:ALow] are enabled */
  189. ebiAHighA25 = EBI_ROUTE_APEN_A25,
  190. /** All EBI_A[25:ALow] are enabled */
  191. ebiAHighA26 = EBI_ROUTE_APEN_A26,
  192. /** All EBI_A[26:ALow] are enabled */
  193. ebiAHighA27 = EBI_ROUTE_APEN_A27,
  194. /** All EBI_A[27:ALow] are enabled */
  195. ebiAHighA28 = EBI_ROUTE_APEN_A28,
  196. } EBI_AHigh_TypeDef;
  197. /** EBI I/O Alternate Pin Location */
  198. typedef enum {
  199. /** EBI PIN I/O Location 0 */
  200. ebiLocation0 = EBI_ROUTE_LOCATION_LOC0,
  201. /** EBI PIN I/O Location 1 */
  202. ebiLocation1 = EBI_ROUTE_LOCATION_LOC1,
  203. /** EBI PIN I/O Location 2 */
  204. ebiLocation2 = EBI_ROUTE_LOCATION_LOC2,
  205. /** EBI PIN I/O Location 3 */
  206. // ebiLocation3 = EBI_ROUTE_LOCATION_LOC3,
  207. } EBI_Location_TypeDef;
  208. #endif
  209. /* TFT support */
  210. #if defined(_EFM32_GIANT_FAMILY)
  211. /** EBI TFT Graphics Bank Select */
  212. typedef enum
  213. {
  214. /** Memory BANK0 contains frame buffer */
  215. ebiTFTBank0 = EBI_TFTCTRL_BANKSEL_BANK0,
  216. /** Memory BANK1 contains frame buffer */
  217. ebiTFTBank1 = EBI_TFTCTRL_BANKSEL_BANK1,
  218. /** Memory BANK2 contains frame buffer */
  219. ebiTFTBank2 = EBI_TFTCTRL_BANKSEL_BANK2,
  220. /** Memory BANK3 contains frame buffer */
  221. ebiTFTBank3 = EBI_TFTCTRL_BANKSEL_BANK3
  222. } EBI_TFTBank_TypeDef;
  223. /** Masking and Alpha blending source color*/
  224. typedef enum
  225. {
  226. /** Use memory as source color for masking/alpha blending */
  227. ebiTFTColorSrcMem = EBI_TFTCTRL_COLOR1SRC_MEM,
  228. /** Use PIXEL1 register as source color for masking/alpha blending */
  229. ebiTFTColorSrcPixel1 = EBI_TFTCTRL_COLOR1SRC_PIXEL1,
  230. } EBI_TFTColorSrc_TypeDef;
  231. /** Bus Data Interleave Mode */
  232. typedef enum
  233. {
  234. /** Unlimited interleaved accesses per EBI_DCLK period. Can cause jitter */
  235. ebiTFTInterleaveUnlimited = EBI_TFTCTRL_INTERLEAVE_UNLIMITED,
  236. /** Allow 1 interleaved access per EBI_DCLK period */
  237. ebiTFTInterleaveOnePerDClk = EBI_TFTCTRL_INTERLEAVE_ONEPERDCLK,
  238. /** Only allow accesses during porch periods */
  239. ebiTFTInterleavePorch = EBI_TFTCTRL_INTERLEAVE_PORCH,
  240. } EBI_TFTInterleave_TypeDef;
  241. /** Control frame base pointer copy */
  242. typedef enum
  243. {
  244. /** Trigger update of frame buffer pointer on vertical sync */
  245. ebiTFTFrameBufTriggerVSync = EBI_TFTCTRL_FBCTRIG_VSYNC,
  246. /** Trigger update of frame buffer pointer on horizontal sync */
  247. ebiTFTFrameBufTriggerHSync = EBI_TFTCTRL_FBCTRIG_HSYNC,
  248. } EBI_TFTFrameBufTrigger_TypeDef;
  249. /** Control of mask and alpha blending mode */
  250. typedef enum
  251. {
  252. /** Masking and blending are disabled */
  253. ebiTFTMBDisabled = EBI_TFTCTRL_MASKBLEND_DISABLED,
  254. /** Internal masking */
  255. ebiTFTMBIMask = EBI_TFTCTRL_MASKBLEND_IMASK,
  256. /** Internal alpha blending */
  257. ebiTFTMBIAlpha = EBI_TFTCTRL_MASKBLEND_IALPHA,
  258. /** Internal masking and alpha blending are enabled */
  259. ebiTFTMBIMaskAlpha = EBI_TFTCTRL_MASKBLEND_IMASKIALPHA,
  260. /** External masking */
  261. ebiTFTMBEMask = EBI_TFTCTRL_MASKBLEND_EMASK,
  262. /** External alpha blending */
  263. ebiTFTMBEAlpha = EBI_TFTCTRL_MASKBLEND_EALPHA,
  264. /** External masking and alpha blending */
  265. ebiTFTMBEMaskAlpha = EBI_TFTCTRL_MASKBLEND_EMASKEALPHA,
  266. } EBI_TFTMaskBlend_TypeDef;
  267. /** TFT Direct Drive mode */
  268. typedef enum
  269. {
  270. /** Disabled */
  271. ebiTFTDDModeDisabled = EBI_TFTCTRL_DD_DISABLED,
  272. /** Direct Drive from internal memory */
  273. ebiTFTDDModeInternal = EBI_TFTCTRL_DD_INTERNAL,
  274. /** Direct Drive from external memory */
  275. ebiTFTDDModeExternal = EBI_TFTCTRL_DD_EXTERNAL,
  276. } EBI_TFTDDMode_TypeDef;
  277. /** TFT Data Increment Width */
  278. typedef enum
  279. {
  280. /** Pixel increments are 1 byte at a time */
  281. ebiTFTWidthByte = EBI_TFTCTRL_WIDTH_BYTE,
  282. /** Pixel increments are 2 bytes (half word) */
  283. ebiTFTWidthHalfWord = EBI_TFTCTRL_WIDTH_HALFWORD,
  284. } EBI_TFTWidth_TypeDef;
  285. #endif
  286. /*******************************************************************************
  287. ******************************* STRUCTS ***********************************
  288. ******************************************************************************/
  289. /** EBI Initialization structure */
  290. typedef struct
  291. {
  292. /** EBI operation mode, data and address limits */
  293. EBI_Mode_TypeDef mode;
  294. /** Address Ready pin polarity, active high or low */
  295. EBI_Polarity_TypeDef ardyPolarity;
  296. /** Address Latch Enable pin polarity, active high or low */
  297. EBI_Polarity_TypeDef alePolarity;
  298. /** Write Enable pin polarity, active high or low */
  299. EBI_Polarity_TypeDef wePolarity;
  300. /** Read Enable pin polarity, active high or low */
  301. EBI_Polarity_TypeDef rePolarity;
  302. /** Chip Select pin polarity, active high or low */
  303. EBI_Polarity_TypeDef csPolarity;
  304. #if defined(_EFM32_GIANT_FAMILY)
  305. /** Byte Lane pin polaritym, active high or low */
  306. EBI_Polarity_TypeDef blPolarity;
  307. /** Flag to enable or disable Byte Lane support */
  308. bool blEnable;
  309. /** Flag to enable or disable idle state insertion between transfers */
  310. bool noIdle;
  311. #endif
  312. /** Flag to enable or disable Address Ready support */
  313. bool ardyEnable;
  314. /** Set to turn off 32 cycle timeout ability */
  315. bool ardyDisableTimeout;
  316. /** Mask of flags which selects address banks to configure EBI_BANK<0-3> */
  317. uint32_t banks;
  318. /** Mask of flags which selects chip select lines to configure EBI_CS<0-3> */
  319. uint32_t csLines;
  320. /** Number of cycles address is held after Adress Latch Enable is asserted */
  321. int addrSetupCycles;
  322. /** Number of cycles address is driven onto the ADDRDAT bus before ALE is asserted */
  323. int addrHoldCycles;
  324. #if defined(_EFM32_GIANT_FAMILY)
  325. /** Enable or disables half cycle duration of the ALE strobe in the last address setup cycle */
  326. bool addrHalfALE;
  327. #endif
  328. /** Number of cycles for address setup before REn is asserted */
  329. int readSetupCycles;
  330. /** Number of cycles REn is held active */
  331. int readStrobeCycles;
  332. /** Number of cycles CSn is held active after REn is deasserted */
  333. int readHoldCycles;
  334. #if defined(_EFM32_GIANT_FAMILY)
  335. /** Enable or disable page mode reads */
  336. bool readPageMode;
  337. /** Enables or disable prefetching from sequential addresses */
  338. bool readPrefetch;
  339. /** Enabled or disables half cycle duration of the REn signal in the last strobe cycle */
  340. bool readHalfRE;
  341. #endif
  342. /** Number of cycles for address setup before WEn is asserted */
  343. int writeSetupCycles;
  344. /** Number of cycles WEn is held active */
  345. int writeStrobeCycles;
  346. /** Number of cycles CSn is held active after WEn is deasserted */
  347. int writeHoldCycles;
  348. #if defined(_EFM32_GIANT_FAMILY)
  349. /** Enable or disable the write buffer */
  350. bool writeBufferDisable;
  351. /** Enables or disables half cycle duration of the WEn signal in the last strobe cycle */
  352. bool writeHalfWE;
  353. /** Lower address pin limit to enable */
  354. EBI_ALow_TypeDef aLow;
  355. /** High address pin limit to enable */
  356. EBI_AHigh_TypeDef aHigh;
  357. /** Pin Location */
  358. EBI_Location_TypeDef location;
  359. #endif
  360. /** Flag, if EBI should be enabled after configuration */
  361. bool enable;
  362. } EBI_Init_TypeDef;
  363. /** Default config for EBI init structures */
  364. #if defined(_EFM32_GIANT_FAMILY)
  365. #define EBI_INIT_DEFAULT \
  366. { ebiModeD8A8, /* 8 bit address, 8 bit data */ \
  367. ebiActiveLow, /* ARDY polarity */ \
  368. ebiActiveLow, /* ALE polarity */ \
  369. ebiActiveLow, /* WE polarity */ \
  370. ebiActiveLow, /* RE polarity */ \
  371. ebiActiveLow, /* CS polarity */ \
  372. ebiActiveLow, /* BL polarity */ \
  373. false, /* enable BL */ \
  374. false, /* enable NOIDLE */ \
  375. false, /* enable ARDY */ \
  376. false, /* don't disable ARDY timeout */ \
  377. EBI_BANK0, /* enable bank 0 */ \
  378. EBI_CS0, /* enable chip select 0 */ \
  379. 0, /* addr setup cycles */ \
  380. 1, /* addr hold cycles */ \
  381. false, /* do not enable half cycle ALE strobe */ \
  382. 0, /* read setup cycles */ \
  383. 0, /* read strobe cycles */ \
  384. 0, /* read hold cycles */ \
  385. false, /* disable page mode */ \
  386. false, /* disable prefetch */ \
  387. false, /* do not enable half cycle REn strobe */ \
  388. 0, /* write setup cycles */ \
  389. 0, /* write strobe cycles */ \
  390. 1, /* write hold cycles */ \
  391. false, /* do not disable the write buffer */ \
  392. false, /* do not enable halc cycle WEn strobe */ \
  393. ebiALowA0, /* ALB - Low bound, address lines */ \
  394. ebiAHighA0, /* APEN - High bound, address lines */ \
  395. ebiLocation0, /* Use Location 0 */ \
  396. true, /* enable EBI */ \
  397. }
  398. #else
  399. #define EBI_INIT_DEFAULT \
  400. { ebiModeD8A8, /* 8 bit address, 8 bit data */ \
  401. ebiActiveLow, /* ARDY polarity */ \
  402. ebiActiveLow, /* ALE polarity */ \
  403. ebiActiveLow, /* WE polarity */ \
  404. ebiActiveLow, /* RE polarity */ \
  405. ebiActiveLow, /* CS polarity */ \
  406. false, /* enable ARDY */ \
  407. false, /* don't disable ARDY timeout */ \
  408. EBI_BANK0, /* enable bank 0 */ \
  409. EBI_CS0, /* enable chip select 0 */ \
  410. 0, /* addr setup cycles */ \
  411. 1, /* addr hold cycles */ \
  412. 0, /* read setup cycles */ \
  413. 0, /* read strobe cycles */ \
  414. 0, /* read hold cycles */ \
  415. 0, /* write setup cycles */ \
  416. 0, /* write strobe cycles */ \
  417. 1, /* write hold cycles */ \
  418. true, /* enable EBI */ \
  419. }
  420. #endif
  421. #if defined(_EFM32_GIANT_FAMILY)
  422. /** TFT Initialization structure */
  423. typedef struct
  424. {
  425. /** External memory bank for driving display */
  426. EBI_TFTBank_TypeDef bank;
  427. /** Width */
  428. EBI_TFTWidth_TypeDef width;
  429. /** Color source for masking and alpha blending */
  430. EBI_TFTColorSrc_TypeDef colSrc;
  431. /** Bus Interleave mode */
  432. EBI_TFTInterleave_TypeDef interleave;
  433. /** Trigger for updating frame buffer pointer */
  434. EBI_TFTFrameBufTrigger_TypeDef fbTrigger;
  435. /** Drive DCLK from negative clock edge of internal clock */
  436. bool shiftDClk;
  437. /** Masking and alpha blending mode */
  438. EBI_TFTMaskBlend_TypeDef maskBlend;
  439. /** TFT Direct Drive mode */
  440. EBI_TFTDDMode_TypeDef driveMode;
  441. /** TFT Polarity for Chip Select (CS) Line */
  442. EBI_Polarity_TypeDef csPolarity;
  443. /** TFT Polarity for Data Clock (DCLK) Line */
  444. EBI_Polarity_TypeDef dclkPolarity;
  445. /** TFT Polarity for Data Enable (DATAEN) Line */
  446. EBI_Polarity_TypeDef dataenPolarity;
  447. /** TFT Polarity for Horizontal Sync (HSYNC) Line */
  448. EBI_Polarity_TypeDef hsyncPolarity;
  449. /** TFT Polarity for Vertical Sync (VSYNC) Line */
  450. EBI_Polarity_TypeDef vsyncPolarity;
  451. /** Horizontal size in pixels */
  452. int hsize;
  453. /** Horizontal Front Porch Size */
  454. int hPorchFront;
  455. /** Horizontal Back Porch Size */
  456. int hPorchBack;
  457. /** Horizontal Synchronization Pulse Width */
  458. int hPulseWidth;
  459. /** Vertical size in pixels */
  460. int vsize;
  461. /** Vertical Front Porch Size */
  462. int vPorchFront;
  463. /** Vertical Back Porch Size */
  464. int vPorchBack;
  465. /** Vertical Synchronization Pulse Width */
  466. int vPulseWidth;
  467. /** TFT Frame Buffer address, offset to EBI bank base address */
  468. uint32_t addressOffset;
  469. /** TFT DCLK period in internal cycles */
  470. int dclkPeriod;
  471. /** Starting position of External Direct Drive relative to DCLK inactive edge */
  472. int startPosition;
  473. /** Number of cycles RGB data is driven before active edge of DCLK */
  474. int setupCycles;
  475. /** Number of cycles RGB data is held after active edge of DCLK */
  476. int holdCycles;
  477. } EBI_TFTInit_TypeDef;
  478. #define EBI_TFTINIT_DEFAULT \
  479. { ebiTFTBank0, /* Select EBI Bank 0 */ \
  480. ebiTFTWidthHalfWord, /* Select 2-byte increments */ \
  481. ebiTFTColorSrcMem, /* Use memory as source for mask/blending */ \
  482. ebiTFTInterleaveUnlimited, /* Unlimited interleaved accesses */ \
  483. ebiTFTFrameBufTriggerVSync, /* VSYNC as frame buffer update trigger */ \
  484. false, /* Drive DCLK from negative edge of internal clock */ \
  485. ebiTFTMBDisabled, /* No masking and alpha blending enabled */ \
  486. ebiTFTDDModeExternal, /* Drive from external memory */ \
  487. ebiActiveLow, /* CS Active Low polarity */ \
  488. ebiActiveLow, /* DCLK Active Low polarity */ \
  489. ebiActiveLow, /* DATAEN Active Low polarity */ \
  490. ebiActiveLow, /* HSYNC Active Low polarity */ \
  491. ebiActiveLow, /* VSYNC Active Low polarity */ \
  492. 320, /* Horizontal size in pixels */ \
  493. 1, /* Horizontal Front Porch */ \
  494. 29, /* Horizontal Back Porch */ \
  495. 2, /* Horizontal Synchronization Pulse Width */ \
  496. 240, /* Vertical size in pixels */ \
  497. 1, /* Vertical Front Porch */ \
  498. 4, /* Vertical Back Porch */ \
  499. 2, /* Vertical Synchronization Pulse Width */ \
  500. 0x0000, /* Address offset to EBI memory base */ \
  501. 5, /* DCLK Period */ \
  502. 2, /* DCLK Start */ \
  503. 1, /* DCLK Setup cycles */ \
  504. 1, /* DCLK Hold cycles */ \
  505. }
  506. #endif
  507. /*******************************************************************************
  508. ***************************** PROTOTYPES **********************************
  509. ******************************************************************************/
  510. void EBI_Init(const EBI_Init_TypeDef *ebiInit);
  511. void EBI_Disable(void);
  512. uint32_t EBI_BankAddress(uint32_t bank);
  513. void EBI_BankEnable(uint32_t banks, bool enable);
  514. #if defined(_EFM32_GIANT_FAMILY)
  515. void EBI_TFTInit(const EBI_TFTInit_TypeDef *ebiTFTInit);
  516. void EBI_TFTSizeSet(uint32_t horizontal, uint32_t vertical);
  517. void EBI_TFTHPorchSet(int front, int back, int pulseWidth);
  518. void EBI_TFTVPorchSet(int front, int back, int pulseWidth);
  519. void EBI_TFTTimingSet(int dclkPeriod, int start, int setup, int hold);
  520. #endif
  521. #if defined(_EFM32_GIANT_FAMILY)
  522. /* This functionality is only available on devices with independent timing support */
  523. void EBI_BankReadTimingSet(uint32_t bank, int setupCycles, int strobeCycles, int holdCycles);
  524. void EBI_BankReadTimingConfig(uint32_t bank, bool pageMode, bool prefetch, bool halfRE);
  525. void EBI_BankWriteTimingSet(uint32_t bank, int setupCycles, int strobeCycles, int holdCycles);
  526. void EBI_BankWriteTimingConfig(uint32_t bank, bool writeBufDisable, bool halfWE);
  527. void EBI_BankAddressTimingSet(uint32_t bank, int setupCycles, int holdCycles);
  528. void EBI_BankAddressTimingConfig(uint32_t bank, bool halfALE);
  529. void EBI_BankPolaritySet(uint32_t bank, EBI_Line_TypeDef line, EBI_Polarity_TypeDef polarity);
  530. void EBI_BankByteLaneEnable(uint32_t bank, bool enable);
  531. void EBI_BankPage(uint32_t bank, bool enable);
  532. void EBI_AltMapEnable(bool enable);
  533. /***************************************************************************//**
  534. * @brief
  535. * Enable or disable TFT Direct Drive
  536. *
  537. * @param[in] mode
  538. * Drive from Internal or External memory, or Disable Direct Drive
  539. ******************************************************************************/
  540. __STATIC_INLINE void EBI_TFTEnable(EBI_TFTDDMode_TypeDef mode)
  541. {
  542. EBI->TFTCTRL = (EBI->TFTCTRL & ~(_EBI_TFTCTRL_DD_MASK)) | (uint32_t) mode;
  543. }
  544. /***************************************************************************//**
  545. * @brief
  546. * Configure frame buffer pointer
  547. *
  548. * @param[in] address
  549. * Frame pointer address, as offset by EBI base address
  550. ******************************************************************************/
  551. __STATIC_INLINE void EBI_TFTFrameBaseSet(uint32_t address)
  552. {
  553. EBI->TFTFRAMEBASE = (uint32_t) address;
  554. }
  555. /***************************************************************************//**
  556. * @brief Set TFT Pixel Color 0 or 1
  557. *
  558. * @param[in] pixel
  559. * Which pixel instance to set
  560. * @param[in] color
  561. * Color of pixel, 16-bit value
  562. ******************************************************************************/
  563. __STATIC_INLINE void EBI_TFTPixelSet(int pixel, uint32_t color)
  564. {
  565. EFM_ASSERT(pixel == 0 || pixel == 1);
  566. if (pixel == 0)
  567. {
  568. EBI->TFTPIXEL0 = color;
  569. }
  570. if (pixel == 1)
  571. {
  572. EBI->TFTPIXEL1 = color;
  573. }
  574. }
  575. /***************************************************************************//**
  576. * @brief Masking and Blending Mode Set
  577. *
  578. * @param[in] alpha
  579. * 8-bit value indicating blending factor
  580. ******************************************************************************/
  581. __STATIC_INLINE void EBI_TFTMaskBlendMode(EBI_TFTMaskBlend_TypeDef maskBlend)
  582. {
  583. EBI->TFTCTRL = (EBI->TFTCTRL & (~_EBI_TFTCTRL_MASKBLEND_MASK))|maskBlend;
  584. }
  585. /***************************************************************************//**
  586. * @brief Set TFT Alpha Blending Factor
  587. *
  588. * @param[in] alpha
  589. * 8-bit value indicating blending factor
  590. ******************************************************************************/
  591. __STATIC_INLINE void EBI_TFTAlphaBlendSet(uint8_t alpha)
  592. {
  593. EBI->TFTALPHA = alpha;
  594. }
  595. /***************************************************************************//**
  596. * @brief Set TFT mask value
  597. * Data accesses that matches this value are suppressed
  598. * @param[in] mask
  599. ******************************************************************************/
  600. __STATIC_INLINE void EBI_TFTMaskSet(uint32_t mask)
  601. {
  602. EBI->TFTMASK = mask;
  603. }
  604. /***************************************************************************//**
  605. * @brief Get current vertical position counter
  606. * @return
  607. * Returns the current line position for the visible part of a frame
  608. ******************************************************************************/
  609. __STATIC_INLINE uint32_t EBI_TFTVCount(void)
  610. {
  611. return((EBI->TFTSTATUS & _EBI_TFTSTATUS_VCNT_MASK) >> _EBI_TFTSTATUS_VCNT_SHIFT);
  612. }
  613. /***************************************************************************//**
  614. * @brief Get current horizontal position counter
  615. * @return
  616. * Returns the current horizontal pixel position within a visible line
  617. ******************************************************************************/
  618. __STATIC_INLINE uint32_t EBI_TFTHCount(void)
  619. {
  620. return((EBI->TFTSTATUS & _EBI_TFTSTATUS_HCNT_MASK) >> _EBI_TFTSTATUS_HCNT_SHIFT);
  621. }
  622. /***************************************************************************//**
  623. * @brief Set Frame Buffer Trigger
  624. * Frame buffer pointer will be updated either on each horizontal line (hsync)
  625. * or vertical update (vsync)(
  626. ******************************************************************************/
  627. __STATIC_INLINE void EBI_TFTFBTriggerSet(EBI_TFTFrameBufTrigger_TypeDef sync)
  628. {
  629. EBI->TFTCTRL = ((EBI->TFTCTRL & ~_EBI_TFTCTRL_FBCTRIG_MASK)|sync);
  630. }
  631. /***************************************************************************//**
  632. * @brief Set horizontal TFT stride value in number of bytes
  633. *
  634. * @param[in] nbytes
  635. * Number of bytes to add to frame buffer pointer after each horizontal line
  636. * update
  637. ******************************************************************************/
  638. __STATIC_INLINE void EBI_TFTHStrideSet(uint32_t nbytes)
  639. {
  640. EFM_ASSERT(nbytes < 0x1000);
  641. EBI->TFTSTRIDE = (EBI->TFTSTRIDE & ~(_EBI_TFTSTRIDE_HSTRIDE_MASK))|
  642. (nbytes<<_EBI_TFTSTRIDE_HSTRIDE_SHIFT);
  643. }
  644. /***************************************************************************//**
  645. * @brief
  646. * Clear one or more pending EBI interrupts.
  647. * @param[in] flags
  648. * Pending EBI interrupt source to clear. Use a logical OR combination
  649. * of valid interrupt flags for the EBI module (EBI_IF_nnn).
  650. ******************************************************************************/
  651. __STATIC_INLINE void EBI_IntClear(uint32_t flags)
  652. {
  653. EBI->IFC = flags;
  654. }
  655. /***************************************************************************//**
  656. * @brief
  657. * Set one or more pending EBI interrupts from SW.
  658. *
  659. * @param[in] flags
  660. * EBI interrupt sources to set to pending. Use a logical OR combination of
  661. * valid interrupt flags for the EBI module (EBI_IF_nnn).
  662. ******************************************************************************/
  663. __STATIC_INLINE void EBI_IntSet(uint32_t flags)
  664. {
  665. EBI->IFS = flags;
  666. }
  667. /***************************************************************************//**
  668. * @brief
  669. * Disable one or more EBI interrupts
  670. *
  671. * @param[in] flags
  672. * EBI interrupt sources to disable. Use logical OR combination of valid
  673. * interrupt flags for the EBI module (EBI_IF_nnn)
  674. ******************************************************************************/
  675. __STATIC_INLINE void EBI_IntDisable(uint32_t flags)
  676. {
  677. EBI->IEN &= ~(flags);
  678. }
  679. /***************************************************************************//**
  680. * @brief
  681. * Enable one or more EBI interrupts
  682. *
  683. * @param[in] flags
  684. * EBI interrupt sources to enable. Use logical OR combination of valid
  685. * interrupt flags for the EBI module (EBI_IF_nnn)
  686. ******************************************************************************/
  687. __STATIC_INLINE void EBI_IntEnable(uint32_t flags)
  688. {
  689. EBI->IEN |= flags;
  690. }
  691. /***************************************************************************//**
  692. * @brief
  693. * Get pending EBI interrupt flags
  694. *
  695. * @note
  696. * The event bits are not cleared by the use of this function
  697. *
  698. * @return
  699. * EBI interrupt sources pending, a logical combination of valid EBI
  700. * interrupt flags, EBI_IF_nnn
  701. ******************************************************************************/
  702. __STATIC_INLINE uint32_t EBI_IntGet(void)
  703. {
  704. return(EBI->IF);
  705. }
  706. /***************************************************************************//**
  707. * @brief
  708. * Start ECC generator on NAND flash transfers.
  709. ******************************************************************************/
  710. __STATIC_INLINE void EBI_StartNandEccGen(void)
  711. {
  712. EBI->CMD = EBI_CMD_ECCSTART | EBI_CMD_ECCCLEAR;
  713. }
  714. /***************************************************************************//**
  715. * @brief
  716. * Stop NAND flash ECC generator and return generated ECC.
  717. *
  718. * @return
  719. * The generated ECC.
  720. ******************************************************************************/
  721. __STATIC_INLINE uint32_t EBI_StopNandEccGen( void )
  722. {
  723. EBI->CMD = EBI_CMD_ECCSTOP;
  724. return EBI->ECCPARITY;
  725. }
  726. #endif
  727. void EBI_ChipSelectEnable(uint32_t banks, bool enable);
  728. void EBI_ReadTimingSet(int setupCycles, int strobeCycles, int holdCycles);
  729. void EBI_WriteTimingSet(int setupCycles, int strobeCycles, int holdCycles);
  730. void EBI_AddressTimingSet(int setupCycles, int holdCycles);
  731. void EBI_PolaritySet(EBI_Line_TypeDef line, EBI_Polarity_TypeDef polarity);
  732. /** @} (end addtogroup EBI) */
  733. /** @} (end addtogroup EM_Library) */
  734. #ifdef __cplusplus
  735. }
  736. #endif
  737. #endif /* defined(EBI_COUNT) && (EBI_COUNT > 0) */
  738. #endif /* __EM_EBI_H */