em_ebi.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. /***************************************************************************//**
  2. * @file
  3. * @brief External Bus Interface (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. #include "em_ebi.h"
  34. #if defined(EBI_COUNT) && (EBI_COUNT > 0)
  35. #include "em_assert.h"
  36. #include "em_bitband.h"
  37. /***************************************************************************//**
  38. * @addtogroup EM_Library
  39. * @{
  40. ******************************************************************************/
  41. /***************************************************************************//**
  42. * @addtogroup EBI
  43. * @brief EBI External Bus Interface (EBI) Peripheral API
  44. * @{
  45. ******************************************************************************/
  46. /***************************************************************************//**
  47. * @brief
  48. * Configure and enable External Bus Interface
  49. *
  50. * @param[in] ebiInit
  51. * EBI configuration structure
  52. *
  53. * @note
  54. * GPIO lines must be configured as PUSH_PULL for correct operation
  55. * GPIO and EBI clocks must be enabled in the CMU
  56. ******************************************************************************/
  57. void EBI_Init(const EBI_Init_TypeDef *ebiInit)
  58. {
  59. uint32_t ctrl = EBI->CTRL;
  60. #if defined(_EFM32_GIANT_FAMILY)
  61. /* Enable Independent Timing for devices that supports it */
  62. ctrl |= EBI_CTRL_ITS;
  63. /* Set polarity of address ready */
  64. EBI_BankPolaritySet(ebiInit->banks, ebiLineARDY, ebiInit->ardyPolarity);
  65. /* Set polarity of address latch enable */
  66. EBI_BankPolaritySet(ebiInit->banks, ebiLineALE, ebiInit->alePolarity);
  67. /* Set polarity of write enable */
  68. EBI_BankPolaritySet(ebiInit->banks, ebiLineWE, ebiInit->wePolarity);
  69. /* Set polarity of read enable */
  70. EBI_BankPolaritySet(ebiInit->banks, ebiLineRE, ebiInit->rePolarity);
  71. /* Set polarity of chip select lines */
  72. EBI_BankPolaritySet(ebiInit->banks, ebiLineCS, ebiInit->csPolarity);
  73. /* Set polarity of byte lane line */
  74. EBI_BankPolaritySet(ebiInit->banks, ebiLineBL, ebiInit->blPolarity);
  75. #else
  76. /* Set polarity of address ready */
  77. EBI_PolaritySet(ebiLineARDY, ebiInit->ardyPolarity);
  78. /* Set polarity of address latch enable */
  79. EBI_PolaritySet(ebiLineALE, ebiInit->alePolarity);
  80. /* Set polarity of write enable */
  81. EBI_PolaritySet(ebiLineWE, ebiInit->wePolarity);
  82. /* Set polarity of read enable */
  83. EBI_PolaritySet(ebiLineRE, ebiInit->rePolarity);
  84. /* Set polarity of chip select lines */
  85. EBI_PolaritySet(ebiLineCS, ebiInit->csPolarity);
  86. #endif
  87. /* Configure EBI mode and control settings */
  88. #if defined(_EFM32_GIANT_FAMILY)
  89. if (ebiInit->banks & EBI_BANK0)
  90. {
  91. ctrl &= ~(_EBI_CTRL_MODE_MASK|
  92. _EBI_CTRL_ARDYEN_MASK|
  93. _EBI_CTRL_ARDYTODIS_MASK|
  94. _EBI_CTRL_BL_MASK|
  95. _EBI_CTRL_NOIDLE_MASK|
  96. _EBI_CTRL_BANK0EN_MASK);
  97. ctrl |= (ebiInit->mode << _EBI_CTRL_MODE_SHIFT);
  98. ctrl |= (ebiInit->ardyEnable << _EBI_CTRL_ARDYEN_SHIFT);
  99. ctrl |= (ebiInit->ardyDisableTimeout << _EBI_CTRL_ARDYTODIS_SHIFT);
  100. ctrl |= (ebiInit->blEnable << _EBI_CTRL_BL_SHIFT);
  101. ctrl |= (ebiInit->noIdle << _EBI_CTRL_NOIDLE_SHIFT);
  102. if ( ebiInit->enable)
  103. {
  104. ctrl |= EBI_CTRL_BANK0EN;
  105. }
  106. }
  107. if (ebiInit->banks & EBI_BANK1)
  108. {
  109. ctrl &= ~(_EBI_CTRL_BL1_MASK|
  110. _EBI_CTRL_MODE1_MASK|
  111. _EBI_CTRL_ARDY1EN_MASK|
  112. _EBI_CTRL_ARDYTO1DIS_MASK|
  113. _EBI_CTRL_NOIDLE1_MASK|
  114. _EBI_CTRL_BANK1EN_MASK);
  115. ctrl |= (ebiInit->mode << _EBI_CTRL_MODE1_SHIFT);
  116. ctrl |= (ebiInit->ardyEnable << _EBI_CTRL_ARDY1EN_SHIFT);
  117. ctrl |= (ebiInit->ardyDisableTimeout << _EBI_CTRL_ARDYTO1DIS_SHIFT);
  118. ctrl |= (ebiInit->blEnable << _EBI_CTRL_BL1_SHIFT);
  119. ctrl |= (ebiInit->noIdle << _EBI_CTRL_NOIDLE1_SHIFT);
  120. if ( ebiInit->enable)
  121. {
  122. ctrl |= EBI_CTRL_BANK1EN;
  123. }
  124. }
  125. if (ebiInit->banks & EBI_BANK2)
  126. {
  127. ctrl &= ~(_EBI_CTRL_BL2_MASK|
  128. _EBI_CTRL_MODE2_MASK|
  129. _EBI_CTRL_ARDY2EN_MASK|
  130. _EBI_CTRL_ARDYTO2DIS_MASK|
  131. _EBI_CTRL_NOIDLE2_MASK|
  132. _EBI_CTRL_BANK2EN_MASK);
  133. ctrl |= (ebiInit->mode << _EBI_CTRL_MODE2_SHIFT);
  134. ctrl |= (ebiInit->ardyEnable << _EBI_CTRL_ARDY2EN_SHIFT);
  135. ctrl |= (ebiInit->ardyDisableTimeout << _EBI_CTRL_ARDYTO2DIS_SHIFT);
  136. ctrl |= (ebiInit->blEnable << _EBI_CTRL_BL2_SHIFT);
  137. ctrl |= (ebiInit->noIdle << _EBI_CTRL_NOIDLE2_SHIFT);
  138. if ( ebiInit->enable)
  139. {
  140. ctrl |= EBI_CTRL_BANK2EN;
  141. }
  142. }
  143. if (ebiInit->banks & EBI_BANK3)
  144. {
  145. ctrl &= ~(_EBI_CTRL_BL3_MASK|
  146. _EBI_CTRL_MODE3_MASK|
  147. _EBI_CTRL_ARDY3EN_MASK|
  148. _EBI_CTRL_ARDYTO3DIS_MASK|
  149. _EBI_CTRL_NOIDLE3_MASK|
  150. _EBI_CTRL_BANK3EN_MASK);
  151. ctrl |= (ebiInit->mode << _EBI_CTRL_MODE3_SHIFT);
  152. ctrl |= (ebiInit->ardyEnable << _EBI_CTRL_ARDY3EN_SHIFT);
  153. ctrl |= (ebiInit->ardyDisableTimeout << _EBI_CTRL_ARDYTO3DIS_SHIFT);
  154. ctrl |= (ebiInit->blEnable << _EBI_CTRL_BL3_SHIFT);
  155. ctrl |= (ebiInit->noIdle << _EBI_CTRL_NOIDLE3_SHIFT);
  156. if ( ebiInit->enable)
  157. {
  158. ctrl |= EBI_CTRL_BANK3EN;
  159. }
  160. }
  161. #else
  162. ctrl &= ~(_EBI_CTRL_MODE_MASK|
  163. _EBI_CTRL_ARDYEN_MASK|
  164. _EBI_CTRL_ARDYTODIS_MASK|
  165. _EBI_CTRL_BANK0EN_MASK|
  166. _EBI_CTRL_BANK1EN_MASK|
  167. _EBI_CTRL_BANK2EN_MASK|
  168. _EBI_CTRL_BANK3EN_MASK);
  169. if ( ebiInit->enable)
  170. {
  171. if ( ebiInit->banks & EBI_BANK0 )
  172. {
  173. ctrl |= EBI_CTRL_BANK0EN;
  174. }
  175. if ( ebiInit->banks & EBI_BANK1 )
  176. {
  177. ctrl |= EBI_CTRL_BANK1EN;
  178. }
  179. if ( ebiInit->banks & EBI_BANK2 )
  180. {
  181. ctrl |= EBI_CTRL_BANK2EN;
  182. }
  183. if ( ebiInit->banks & EBI_BANK3 )
  184. {
  185. ctrl |= EBI_CTRL_BANK3EN;
  186. }
  187. }
  188. ctrl |= ebiInit->mode;
  189. ctrl |= (ebiInit->ardyEnable << _EBI_CTRL_ARDYEN_SHIFT);
  190. ctrl |= (ebiInit->ardyDisableTimeout << _EBI_CTRL_ARDYTODIS_SHIFT);
  191. #endif
  192. /* Configure timing */
  193. #if defined(_EFM32_GIANT_FAMILY)
  194. EBI_BankReadTimingSet(ebiInit->banks,
  195. ebiInit->readSetupCycles,
  196. ebiInit->readStrobeCycles,
  197. ebiInit->readHoldCycles);
  198. EBI_BankReadTimingConfig(ebiInit->banks,
  199. ebiInit->readPageMode,
  200. ebiInit->readPrefetch,
  201. ebiInit->readHalfRE);
  202. EBI_BankWriteTimingSet(ebiInit->banks,
  203. ebiInit->writeSetupCycles,
  204. ebiInit->writeStrobeCycles,
  205. ebiInit->writeHoldCycles);
  206. EBI_BankWriteTimingConfig(ebiInit->banks,
  207. ebiInit->writeBufferDisable,
  208. ebiInit->writeHalfWE);
  209. EBI_BankAddressTimingSet(ebiInit->banks,
  210. ebiInit->addrSetupCycles,
  211. ebiInit->addrHoldCycles);
  212. EBI_BankAddressTimingConfig(ebiInit->banks,
  213. ebiInit->addrHalfALE);
  214. #else
  215. EBI_ReadTimingSet(ebiInit->readSetupCycles,
  216. ebiInit->readStrobeCycles,
  217. ebiInit->readHoldCycles);
  218. EBI_WriteTimingSet(ebiInit->writeSetupCycles,
  219. ebiInit->writeStrobeCycles,
  220. ebiInit->writeHoldCycles);
  221. EBI_AddressTimingSet(ebiInit->addrSetupCycles,
  222. ebiInit->addrHoldCycles);
  223. #endif
  224. /* Configure Adress Latch Enable */
  225. switch (ebiInit->mode)
  226. {
  227. case ebiModeD16A16ALE:
  228. case ebiModeD8A24ALE:
  229. /* Address Latch Enable */
  230. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_ALEPEN_SHIFT, 1);
  231. break;
  232. #if defined(_EFM32_GIANT_FAMILY)
  233. case ebiModeD16:
  234. #endif
  235. case ebiModeD8A8:
  236. /* Make sure Address Latch is disabled */
  237. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_ALEPEN_SHIFT, 0);
  238. break;
  239. }
  240. #if defined(_EFM32_GIANT_FAMILY)
  241. /* Limit pin enable */
  242. EBI->ROUTE = (EBI->ROUTE & ~_EBI_ROUTE_ALB_MASK) | ebiInit->aLow;
  243. EBI->ROUTE = (EBI->ROUTE & ~_EBI_ROUTE_APEN_MASK) | ebiInit->aHigh;
  244. /* Location */
  245. EBI->ROUTE = (EBI->ROUTE & ~_EBI_ROUTE_LOCATION_MASK) | ebiInit->location;
  246. /* Enable EBI BL pin if necessary */
  247. if(ctrl & (_EBI_CTRL_BL_MASK|_EBI_CTRL_BL1_MASK|_EBI_CTRL_BL2_MASK|_EBI_CTRL_BL3_MASK))
  248. {
  249. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_BLPEN_SHIFT, ebiInit->blEnable);
  250. }
  251. #endif
  252. /* Enable EBI pins EBI_WEn and EBI_REn */
  253. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_EBIPEN_SHIFT, 1);
  254. /* Enable chip select lines */
  255. EBI_ChipSelectEnable(ebiInit->csLines, true);
  256. /* Activate new configuration */
  257. EBI->CTRL = ctrl;
  258. }
  259. /***************************************************************************//**
  260. * @brief
  261. * Disable External Bus Interface
  262. ******************************************************************************/
  263. void EBI_Disable(void)
  264. {
  265. /* Disable pins */
  266. EBI->ROUTE = _EBI_ROUTE_RESETVALUE;
  267. /* Disable banks */
  268. EBI->CTRL = _EBI_CTRL_RESETVALUE;
  269. }
  270. /***************************************************************************//**
  271. * @brief
  272. * Enable or disable EBI Bank
  273. *
  274. * @param[in] banks
  275. * Banks to reconfigure, mask of EBI_BANK<n> flags
  276. *
  277. * @param[in] enable
  278. * True to enable, false to disable
  279. ******************************************************************************/
  280. void EBI_BankEnable(uint32_t banks, bool enable)
  281. {
  282. if (banks & EBI_BANK0)
  283. {
  284. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BANK0EN_SHIFT, enable);
  285. }
  286. if (banks & EBI_BANK1)
  287. {
  288. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BANK1EN_SHIFT, enable);
  289. }
  290. if (banks & EBI_BANK2)
  291. {
  292. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BANK2EN_SHIFT, enable);
  293. }
  294. if (banks & EBI_BANK3)
  295. {
  296. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BANK3EN_SHIFT, enable);
  297. }
  298. }
  299. /***************************************************************************//**
  300. * @brief
  301. * Return base address of EBI bank
  302. *
  303. * @param[in] bank
  304. * Bank to return start address for
  305. *
  306. * @return
  307. * Absolute address of bank
  308. ******************************************************************************/
  309. uint32_t EBI_BankAddress(uint32_t bank)
  310. {
  311. #if defined (_EFM32_GIANT_FAMILY)
  312. if(EBI->CTRL & EBI_CTRL_ALTMAP)
  313. {
  314. switch (bank)
  315. {
  316. case EBI_BANK0:
  317. return(EBI_MEM_BASE);
  318. case EBI_BANK1:
  319. return(EBI_MEM_BASE + 0x10000000UL);
  320. case EBI_BANK2:
  321. return(EBI_MEM_BASE + 0x20000000UL);
  322. case EBI_BANK3:
  323. return(EBI_MEM_BASE + 0x30000000UL);
  324. default:
  325. EFM_ASSERT(0);
  326. break;
  327. }
  328. }
  329. #endif
  330. switch (bank)
  331. {
  332. case EBI_BANK0:
  333. return(EBI_MEM_BASE);
  334. case EBI_BANK1:
  335. return(EBI_MEM_BASE + 0x04000000UL);
  336. case EBI_BANK2:
  337. return(EBI_MEM_BASE + 0x08000000UL);
  338. case EBI_BANK3:
  339. return(EBI_MEM_BASE + 0x0C000000UL);
  340. default:
  341. EFM_ASSERT(0);
  342. break;
  343. }
  344. return 0;
  345. }
  346. /***************************************************************************//**
  347. * @brief
  348. * Enable or disable EBI Chip Select
  349. *
  350. * @param[in] cs
  351. * ChipSelect lines to reconfigure, mask of EBI_CS<n> flags
  352. *
  353. * @param[in] enable
  354. * True to enable, false to disable
  355. ******************************************************************************/
  356. void EBI_ChipSelectEnable(uint32_t cs, bool enable)
  357. {
  358. if (cs & EBI_CS0)
  359. {
  360. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_CS0PEN_SHIFT, enable);
  361. }
  362. if (cs & EBI_CS1)
  363. {
  364. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_CS1PEN_SHIFT, enable);
  365. }
  366. if (cs & EBI_CS2)
  367. {
  368. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_CS2PEN_SHIFT, enable);
  369. }
  370. if (cs & EBI_CS3)
  371. {
  372. BITBAND_Peripheral(&(EBI->ROUTE), _EBI_ROUTE_CS3PEN_SHIFT, enable);
  373. }
  374. }
  375. /***************************************************************************//**
  376. * @brief
  377. * Configure EBI pin polarity
  378. *
  379. * @param[in] line
  380. * Which pin/line to configure
  381. *
  382. * @param[in] polarity
  383. * Active high, or active low
  384. ******************************************************************************/
  385. void EBI_PolaritySet(EBI_Line_TypeDef line, EBI_Polarity_TypeDef polarity)
  386. {
  387. switch (line)
  388. {
  389. case ebiLineARDY:
  390. BITBAND_Peripheral(&(EBI->POLARITY), _EBI_POLARITY_ARDYPOL_SHIFT, polarity);
  391. break;
  392. case ebiLineALE:
  393. BITBAND_Peripheral(&(EBI->POLARITY), _EBI_POLARITY_ALEPOL_SHIFT, polarity);
  394. break;
  395. case ebiLineWE:
  396. BITBAND_Peripheral(&(EBI->POLARITY), _EBI_POLARITY_WEPOL_SHIFT, polarity);
  397. break;
  398. case ebiLineRE:
  399. BITBAND_Peripheral(&(EBI->POLARITY), _EBI_POLARITY_REPOL_SHIFT, polarity);
  400. break;
  401. case ebiLineCS:
  402. BITBAND_Peripheral(&(EBI->POLARITY), _EBI_POLARITY_CSPOL_SHIFT, polarity);
  403. break;
  404. #if defined (_EFM32_GIANT_FAMILY)
  405. case ebiLineBL:
  406. BITBAND_Peripheral(&(EBI->POLARITY), _EBI_POLARITY_BLPOL_SHIFT, polarity);
  407. break;
  408. case ebiLineTFTVSync:
  409. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_VSYNCPOL_SHIFT, polarity);
  410. break;
  411. case ebiLineTFTHSync:
  412. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_HSYNCPOL_SHIFT, polarity);
  413. break;
  414. case ebiLineTFTDataEn:
  415. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_DATAENPOL_SHIFT, polarity);
  416. break;
  417. case ebiLineTFTDClk:
  418. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_DCLKPOL_SHIFT, polarity);
  419. break;
  420. case ebiLineTFTCS:
  421. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_CSPOL_SHIFT, polarity);
  422. break;
  423. #endif
  424. default:
  425. EFM_ASSERT(0);
  426. break;
  427. }
  428. }
  429. /***************************************************************************//**
  430. * @brief
  431. * Configure timing values of read bus accesses
  432. *
  433. * @param[in] setupCycles
  434. * Number of clock cycles for address setup before REn is asserted
  435. *
  436. * @param[in] strobeCycles
  437. * The number of cycles the REn is held active. After the specified number of
  438. * cycles, data is read. If set to 0, 1 cycle is inserted by HW
  439. *
  440. * @param[in] holdCycles
  441. * The number of cycles CSn is held active after the REn is dessarted
  442. ******************************************************************************/
  443. void EBI_ReadTimingSet(int setupCycles, int strobeCycles, int holdCycles)
  444. {
  445. uint32_t readTiming;
  446. /* Check that timings are within limits */
  447. EFM_ASSERT(setupCycles < 4);
  448. EFM_ASSERT(strobeCycles < 16);
  449. EFM_ASSERT(holdCycles < 4);
  450. /* Configure timing values */
  451. readTiming = (setupCycles << _EBI_RDTIMING_RDSETUP_SHIFT) |
  452. (strobeCycles << _EBI_RDTIMING_RDSTRB_SHIFT) |
  453. (holdCycles << _EBI_RDTIMING_RDHOLD_SHIFT);
  454. EBI->RDTIMING = (EBI->RDTIMING &
  455. ~(_EBI_RDTIMING_RDSETUP_MASK |
  456. _EBI_RDTIMING_RDSTRB_MASK |
  457. _EBI_RDTIMING_RDHOLD_MASK)) | readTiming;
  458. }
  459. /***************************************************************************//**
  460. * @brief
  461. * Configure timing values of write bus accesses
  462. *
  463. * @param[in] setupCycles
  464. * Number of clock cycles for address setup before WEn is asserted
  465. *
  466. * @param[in] strobeCycles
  467. * Number of cycles WEn is held active. If set to 0, 1 cycle is inserted by HW
  468. *
  469. * @param[in] holdCycles
  470. * Number of cycles CSn is held active after the WEn is deasserted
  471. ******************************************************************************/
  472. void EBI_WriteTimingSet(int setupCycles, int strobeCycles, int holdCycles)
  473. {
  474. uint32_t writeTiming;
  475. /* Check that timings are within limits */
  476. EFM_ASSERT(setupCycles < 4);
  477. EFM_ASSERT(strobeCycles < 16);
  478. EFM_ASSERT(holdCycles < 4);
  479. /* Configure timing values */
  480. writeTiming = (setupCycles << _EBI_WRTIMING_WRSETUP_SHIFT) |
  481. (strobeCycles << _EBI_WRTIMING_WRSTRB_SHIFT) |
  482. (holdCycles << _EBI_WRTIMING_WRHOLD_SHIFT);
  483. EBI->WRTIMING = (EBI->WRTIMING &
  484. ~(_EBI_WRTIMING_WRSETUP_MASK |
  485. _EBI_WRTIMING_WRSTRB_MASK |
  486. _EBI_WRTIMING_WRHOLD_MASK)) | writeTiming;
  487. }
  488. /***************************************************************************//**
  489. * @brief
  490. * Configure timing values of address latch bus accesses
  491. *
  492. * @param[in] setupCycles
  493. * Sets the number of cycles the address is held after ALE is asserted
  494. *
  495. * @param[in] holdCycles
  496. * Sets the number of cycles the address is driven onto the ADDRDAT bus before
  497. * ALE is asserted. If set 0, 1 cycle is inserted by HW
  498. ******************************************************************************/
  499. void EBI_AddressTimingSet(int setupCycles, int holdCycles)
  500. {
  501. uint32_t addressLatchTiming;
  502. /* Check that timing values are within limits */
  503. EFM_ASSERT(setupCycles < 4);
  504. EFM_ASSERT(holdCycles < 4);
  505. /* Configure address latch timing values */
  506. addressLatchTiming = (setupCycles << _EBI_ADDRTIMING_ADDRSETUP_SHIFT) |
  507. (holdCycles << _EBI_ADDRTIMING_ADDRHOLD_SHIFT);
  508. EBI->ADDRTIMING = (EBI->ADDRTIMING &
  509. ~(_EBI_ADDRTIMING_ADDRSETUP_MASK |
  510. _EBI_ADDRTIMING_ADDRHOLD_MASK)) | addressLatchTiming;
  511. }
  512. #if defined(_EFM32_GIANT_FAMILY)
  513. /***************************************************************************//**
  514. * @brief
  515. * Configure and initialize TFT Direct Drive
  516. *
  517. * @param[in] ebiTFTInit
  518. * TFT Initialization structure
  519. ******************************************************************************/
  520. void EBI_TFTInit(const EBI_TFTInit_TypeDef *ebiTFTInit)
  521. {
  522. uint32_t ctrl;
  523. /* Configure base address for frame buffer offset to EBI bank */
  524. EBI_TFTFrameBaseSet(ebiTFTInit->addressOffset);
  525. /* Configure display size and porch areas */
  526. EBI_TFTSizeSet(ebiTFTInit->hsize,
  527. ebiTFTInit->vsize);
  528. EBI_TFTHPorchSet(ebiTFTInit->hPorchFront,
  529. ebiTFTInit->hPorchBack,
  530. ebiTFTInit->hPulseWidth);
  531. EBI_TFTVPorchSet(ebiTFTInit->vPorchFront,
  532. ebiTFTInit->vPorchBack,
  533. ebiTFTInit->vPulseWidth);
  534. /* Configure timing settings */
  535. EBI_TFTTimingSet(ebiTFTInit->dclkPeriod,
  536. ebiTFTInit->startPosition,
  537. ebiTFTInit->setupCycles,
  538. ebiTFTInit->holdCycles);
  539. /* Configure line polarity settings */
  540. EBI_PolaritySet(ebiLineTFTCS, ebiTFTInit->csPolarity);
  541. EBI_PolaritySet(ebiLineTFTDClk, ebiTFTInit->dclkPolarity);
  542. EBI_PolaritySet(ebiLineTFTDataEn, ebiTFTInit->dataenPolarity);
  543. EBI_PolaritySet(ebiLineTFTVSync, ebiTFTInit->vsyncPolarity);
  544. EBI_PolaritySet(ebiLineTFTHSync, ebiTFTInit->hsyncPolarity);
  545. /* Main control, EBI bank select, mask and blending configuration */
  546. ctrl =
  547. (uint32_t)(ebiTFTInit->bank) |
  548. (uint32_t)(ebiTFTInit->width) |
  549. (uint32_t)(ebiTFTInit->colSrc) |
  550. (uint32_t)(ebiTFTInit->interleave) |
  551. (uint32_t)(ebiTFTInit->fbTrigger) |
  552. (uint32_t)(ebiTFTInit->shiftDClk == true ? (1 << _EBI_TFTCTRL_SHIFTDCLKEN_SHIFT) : 0) |
  553. (uint32_t)(ebiTFTInit->maskBlend) |
  554. (uint32_t)(ebiTFTInit->driveMode);
  555. EBI->TFTCTRL = ctrl;
  556. /* Enable TFT pins */
  557. if (ebiTFTInit->driveMode != ebiTFTDDModeDisabled)
  558. {
  559. EBI->ROUTE |= (EBI_ROUTE_TFTPEN);
  560. }
  561. }
  562. /***************************************************************************//**
  563. * @brief
  564. * Configure and initialize TFT size settings
  565. *
  566. * @param[in] horizontal
  567. * TFT display horizontal size in pixels
  568. * @param[in] vertical
  569. * TFT display vertical size in pixels
  570. ******************************************************************************/
  571. void EBI_TFTSizeSet(uint32_t horizontal, uint32_t vertical)
  572. {
  573. EFM_ASSERT((horizontal-1) < 1024);
  574. EFM_ASSERT((vertical-1) < 1024);
  575. EBI->TFTSIZE = ((horizontal-1) << _EBI_TFTSIZE_HSZ_SHIFT) |
  576. ((vertical-1) << _EBI_TFTSIZE_VSZ_SHIFT);
  577. }
  578. /***************************************************************************//**
  579. * @brief
  580. * Configure and initialize Horizontal Porch Settings
  581. *
  582. * @param[in] front
  583. * Horizontal front porch size in pixels
  584. * @param[in] back
  585. * Horizontal back porch size in pixels
  586. * @param[in] pulseWidth
  587. * Horizontal synchronization pulse width. Set to required -1.
  588. ******************************************************************************/
  589. void EBI_TFTHPorchSet(int front, int back, int pulseWidth)
  590. {
  591. EFM_ASSERT(front < 256);
  592. EFM_ASSERT(back < 256);
  593. EFM_ASSERT((pulseWidth-1) < 128);
  594. EBI->TFTHPORCH = (front << _EBI_TFTHPORCH_HFPORCH_SHIFT) |
  595. (back << _EBI_TFTHPORCH_HBPORCH_SHIFT) |
  596. ((pulseWidth-1) << _EBI_TFTHPORCH_HSYNC_SHIFT);
  597. }
  598. /***************************************************************************//**
  599. * @brief
  600. * Configure Vertical Porch Settings
  601. *
  602. * @param[in] front
  603. * Vertical front porch size in pixels
  604. * @param[in] back
  605. * Vertical back porch size in pixels
  606. * @param[in] pulseWidth
  607. * Vertical synchronization pulse width. Set to required -1.
  608. ******************************************************************************/
  609. void EBI_TFTVPorchSet(int front, int back, int pulseWidth)
  610. {
  611. EFM_ASSERT(front < 256);
  612. EFM_ASSERT(back < 256);
  613. EFM_ASSERT((pulseWidth-1) < 128);
  614. EBI->TFTVPORCH = (front << _EBI_TFTVPORCH_VFPORCH_SHIFT) |
  615. (back << _EBI_TFTVPORCH_VBPORCH_SHIFT) |
  616. ((pulseWidth-1) << _EBI_TFTVPORCH_VSYNC_SHIFT);
  617. }
  618. /***************************************************************************//**
  619. * @brief
  620. * Configure TFT Direct Drive Timing Settings
  621. *
  622. * @param[in] dclkPeriod
  623. * DCLK period in internal cycles
  624. *
  625. * @param[in] start
  626. * Starting position of external direct drive, relative to DCLK inactive edge
  627. *
  628. * @param[in] setup
  629. * Number of cycles RGB data is driven before active edge of DCLK
  630. *
  631. * @param[in] hold
  632. * Number of cycles RGB data is held after active edge of DCLK
  633. ******************************************************************************/
  634. void EBI_TFTTimingSet(int dclkPeriod, int start, int setup, int hold)
  635. {
  636. EFM_ASSERT(dclkPeriod < 2048);
  637. EFM_ASSERT(start < 2048);
  638. EFM_ASSERT(setup < 4);
  639. EFM_ASSERT(hold < 4);
  640. EBI->TFTTIMING = (dclkPeriod << _EBI_TFTTIMING_DCLKPERIOD_SHIFT) |
  641. (start << _EBI_TFTTIMING_TFTSTART_SHIFT) |
  642. (setup << _EBI_TFTTIMING_TFTSETUP_SHIFT) |
  643. (hold << _EBI_TFTTIMING_TFTHOLD_SHIFT);
  644. }
  645. #endif
  646. #if defined(_EFM32_GIANT_FAMILY)
  647. /***************************************************************************//**
  648. * @brief
  649. * Configure read operation parameters for selected bank
  650. *
  651. * @param[in] banks
  652. * Mask of memory bank(s) to configure write timing for
  653. *
  654. * @param[in] pageMode
  655. * Enables or disables half cycle WE strobe in last strobe cycle
  656. *
  657. * @param[in] prefetch
  658. * Enables or disables half cycle WE strobe in last strobe cycle
  659. *
  660. * @param[in] halfRE
  661. * Enables or disables half cycle WE strobe in last strobe cycle
  662. ******************************************************************************/
  663. void EBI_BankReadTimingConfig(uint32_t banks, bool pageMode, bool prefetch, bool halfRE)
  664. {
  665. /* Verify only valid banks are used */
  666. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  667. /* Configure read operation parameters */
  668. if( banks & EBI_BANK0 )
  669. {
  670. BITBAND_Peripheral(&EBI->RDTIMING, _EBI_RDTIMING_PAGEMODE_SHIFT, pageMode);
  671. BITBAND_Peripheral(&EBI->RDTIMING, _EBI_RDTIMING_PREFETCH_SHIFT, prefetch);
  672. BITBAND_Peripheral(&EBI->RDTIMING, _EBI_RDTIMING_HALFRE_SHIFT, halfRE);
  673. }
  674. if( banks & EBI_BANK1 )
  675. {
  676. BITBAND_Peripheral(&EBI->RDTIMING1, _EBI_RDTIMING_PAGEMODE_SHIFT, pageMode);
  677. BITBAND_Peripheral(&EBI->RDTIMING1, _EBI_RDTIMING_PREFETCH_SHIFT, prefetch);
  678. BITBAND_Peripheral(&EBI->RDTIMING1, _EBI_RDTIMING_HALFRE_SHIFT, halfRE);
  679. }
  680. if( banks & EBI_BANK2 )
  681. {
  682. BITBAND_Peripheral(&EBI->RDTIMING2, _EBI_RDTIMING_PAGEMODE_SHIFT, pageMode);
  683. BITBAND_Peripheral(&EBI->RDTIMING2, _EBI_RDTIMING_PREFETCH_SHIFT, prefetch);
  684. BITBAND_Peripheral(&EBI->RDTIMING2, _EBI_RDTIMING_HALFRE_SHIFT, halfRE);
  685. }
  686. if( banks & EBI_BANK3 )
  687. {
  688. BITBAND_Peripheral(&EBI->RDTIMING3, _EBI_RDTIMING_PAGEMODE_SHIFT, pageMode);
  689. BITBAND_Peripheral(&EBI->RDTIMING3, _EBI_RDTIMING_PREFETCH_SHIFT, prefetch);
  690. BITBAND_Peripheral(&EBI->RDTIMING3, _EBI_RDTIMING_HALFRE_SHIFT, halfRE);
  691. }
  692. }
  693. /***************************************************************************//**
  694. * @brief
  695. * Configure timing values of read bus accesses
  696. *
  697. * @param[in] banks
  698. * Mask of memory bank(s) to configure timing for
  699. *
  700. * @param[in] setupCycles
  701. * Number of clock cycles for address setup before REn is asserted
  702. *
  703. * @param[in] strobeCycles
  704. * The number of cycles the REn is held active. After the specified number of
  705. * cycles, data is read. If set to 0, 1 cycle is inserted by HW
  706. *
  707. * @param[in] holdCycles
  708. * The number of cycles CSn is held active after the REn is dessarted
  709. ******************************************************************************/
  710. void EBI_BankReadTimingSet(uint32_t banks, int setupCycles, int strobeCycles, int holdCycles)
  711. {
  712. uint32_t readTiming;
  713. /* Verify only valid banks are used */
  714. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  715. /* Check that timings are within limits */
  716. EFM_ASSERT(setupCycles < 4);
  717. EFM_ASSERT(strobeCycles < 64);
  718. EFM_ASSERT(holdCycles < 4);
  719. /* Configure timing values */
  720. readTiming = (setupCycles << _EBI_RDTIMING_RDSETUP_SHIFT) |
  721. (strobeCycles << _EBI_RDTIMING_RDSTRB_SHIFT) |
  722. (holdCycles << _EBI_RDTIMING_RDHOLD_SHIFT);
  723. if (banks & EBI_BANK0)
  724. {
  725. EBI->RDTIMING = (EBI->RDTIMING &
  726. ~(_EBI_RDTIMING_RDSETUP_MASK |
  727. _EBI_RDTIMING_RDSTRB_MASK |
  728. _EBI_RDTIMING_RDHOLD_MASK)) | readTiming;
  729. }
  730. if (banks & EBI_BANK1)
  731. {
  732. EBI->RDTIMING1 = (EBI->RDTIMING1 &
  733. ~(_EBI_RDTIMING1_RDSETUP_MASK |
  734. _EBI_RDTIMING1_RDSTRB_MASK |
  735. _EBI_RDTIMING1_RDHOLD_MASK)) | readTiming;
  736. }
  737. if (banks & EBI_BANK2)
  738. {
  739. EBI->RDTIMING2 = (EBI->RDTIMING2 &
  740. ~(_EBI_RDTIMING2_RDSETUP_MASK |
  741. _EBI_RDTIMING2_RDSTRB_MASK |
  742. _EBI_RDTIMING2_RDHOLD_MASK)) | readTiming;
  743. }
  744. if (banks & EBI_BANK3)
  745. {
  746. EBI->RDTIMING3 = (EBI->RDTIMING3 &
  747. ~(_EBI_RDTIMING3_RDSETUP_MASK |
  748. _EBI_RDTIMING3_RDSTRB_MASK |
  749. _EBI_RDTIMING3_RDHOLD_MASK)) | readTiming;
  750. }
  751. }
  752. /***************************************************************************//**
  753. * @brief
  754. * Configure write operation parameters for selected bank
  755. *
  756. * @param[in] banks
  757. * Mask of memory bank(s) to configure write timing for
  758. *
  759. * @param[in] writeBufferDisable
  760. * If true, disable the write buffer
  761. *
  762. * @param[in] halfWE
  763. * Enables or disables half cycle WE strobe in last strobe cycle
  764. ******************************************************************************/
  765. void EBI_BankWriteTimingConfig(uint32_t banks, bool writeBufDisable, bool halfWE)
  766. {
  767. /* Verify only valid banks are used */
  768. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  769. /* Configure write operation parameters */
  770. if( banks & EBI_BANK0 )
  771. {
  772. BITBAND_Peripheral(&EBI->WRTIMING, _EBI_WRTIMING_WBUFDIS_SHIFT, writeBufDisable);
  773. BITBAND_Peripheral(&EBI->WRTIMING, _EBI_WRTIMING_HALFWE_SHIFT, halfWE);
  774. }
  775. if( banks & EBI_BANK1 )
  776. {
  777. BITBAND_Peripheral(&EBI->WRTIMING1, _EBI_WRTIMING_WBUFDIS_SHIFT, writeBufDisable);
  778. BITBAND_Peripheral(&EBI->WRTIMING1, _EBI_WRTIMING_HALFWE_SHIFT, halfWE);
  779. }
  780. if( banks & EBI_BANK2 )
  781. {
  782. BITBAND_Peripheral(&EBI->WRTIMING2, _EBI_WRTIMING_WBUFDIS_SHIFT, writeBufDisable);
  783. BITBAND_Peripheral(&EBI->WRTIMING2, _EBI_WRTIMING_HALFWE_SHIFT, halfWE);
  784. }
  785. if( banks & EBI_BANK3 )
  786. {
  787. BITBAND_Peripheral(&EBI->WRTIMING3, _EBI_WRTIMING_WBUFDIS_SHIFT, writeBufDisable);
  788. BITBAND_Peripheral(&EBI->WRTIMING3, _EBI_WRTIMING_HALFWE_SHIFT, halfWE);
  789. }
  790. }
  791. /***************************************************************************//**
  792. * @brief
  793. * Configure timing values of write bus accesses
  794. *
  795. * @param[in] banks
  796. * Mask of memory bank(s) to configure write timing for
  797. *
  798. * @param[in] setupCycles
  799. * Number of clock cycles for address setup before WEn is asserted
  800. *
  801. * @param[in] strobeCycles
  802. * Number of cycles WEn is held active. If set to 0, 1 cycle is inserted by HW
  803. *
  804. * @param[in] holdCycles
  805. * Number of cycles CSn is held active after the WEn is deasserted
  806. ******************************************************************************/
  807. void EBI_BankWriteTimingSet(uint32_t banks, int setupCycles, int strobeCycles, int holdCycles)
  808. {
  809. uint32_t writeTiming;
  810. /* Verify only valid banks are used */
  811. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  812. /* Check that timings are within limits */
  813. EFM_ASSERT(setupCycles < 4);
  814. EFM_ASSERT(strobeCycles < 64);
  815. EFM_ASSERT(holdCycles < 4);
  816. /* Configure timing values */
  817. writeTiming = (setupCycles << _EBI_WRTIMING_WRSETUP_SHIFT) |
  818. (strobeCycles << _EBI_WRTIMING_WRSTRB_SHIFT) |
  819. (holdCycles << _EBI_WRTIMING_WRHOLD_SHIFT);
  820. if (banks & EBI_BANK0)
  821. {
  822. EBI->WRTIMING = (EBI->WRTIMING &
  823. ~(_EBI_WRTIMING_WRSETUP_MASK |
  824. _EBI_WRTIMING_WRSTRB_MASK |
  825. _EBI_WRTIMING_WRHOLD_MASK)) | writeTiming;
  826. }
  827. if (banks & EBI_BANK1)
  828. {
  829. EBI->WRTIMING1 = (EBI->WRTIMING1 &
  830. ~(_EBI_WRTIMING1_WRSETUP_MASK |
  831. _EBI_WRTIMING1_WRSTRB_MASK |
  832. _EBI_WRTIMING1_WRHOLD_MASK)) | writeTiming;
  833. }
  834. if (banks & EBI_BANK2)
  835. {
  836. EBI->WRTIMING2 = (EBI->WRTIMING2 &
  837. ~(_EBI_WRTIMING2_WRSETUP_MASK |
  838. _EBI_WRTIMING2_WRSTRB_MASK |
  839. _EBI_WRTIMING2_WRHOLD_MASK)) | writeTiming;
  840. }
  841. if (banks & EBI_BANK3)
  842. {
  843. EBI->WRTIMING3 = (EBI->WRTIMING3 &
  844. ~(_EBI_WRTIMING3_WRSETUP_MASK |
  845. _EBI_WRTIMING3_WRSTRB_MASK |
  846. _EBI_WRTIMING3_WRHOLD_MASK)) | writeTiming;
  847. }
  848. }
  849. /***************************************************************************//**
  850. * @brief
  851. * Configure address operation parameters for selected bank
  852. *
  853. * @param[in] banks
  854. * Mask of memory bank(s) to configure write timing for
  855. *
  856. * @param[in] halfALE
  857. * Enables or disables half cycle ALE strobe in last strobe cycle
  858. ******************************************************************************/
  859. void EBI_BankAddressTimingConfig(uint32_t banks, bool halfALE)
  860. {
  861. /* Verify only valid banks are used */
  862. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  863. if( banks & EBI_BANK0 )
  864. {
  865. BITBAND_Peripheral(&EBI->ADDRTIMING, _EBI_ADDRTIMING_HALFALE_SHIFT, halfALE);
  866. }
  867. if( banks & EBI_BANK1 )
  868. {
  869. BITBAND_Peripheral(&EBI->ADDRTIMING1, _EBI_ADDRTIMING_HALFALE_SHIFT, halfALE);
  870. }
  871. if( banks & EBI_BANK2 )
  872. {
  873. BITBAND_Peripheral(&EBI->ADDRTIMING2, _EBI_ADDRTIMING_HALFALE_SHIFT, halfALE);
  874. }
  875. if( banks & EBI_BANK3 )
  876. {
  877. BITBAND_Peripheral(&EBI->ADDRTIMING3, _EBI_ADDRTIMING_HALFALE_SHIFT, halfALE);
  878. }
  879. }
  880. /***************************************************************************//**
  881. * @brief
  882. * Configure timing values of address latch bus accesses
  883. *
  884. * @param[in] banks
  885. * Mask of memory bank(s) to configure address timing for
  886. *
  887. * @param[in] setupCycles
  888. * Sets the number of cycles the address is held after ALE is asserted
  889. *
  890. * @param[in] holdCycles
  891. * Sets the number of cycles the address is driven onto the ADDRDAT bus before
  892. * ALE is asserted. If set 0, 1 cycle is inserted by HW
  893. ******************************************************************************/
  894. void EBI_BankAddressTimingSet(uint32_t banks, int setupCycles, int holdCycles)
  895. {
  896. uint32_t addressLatchTiming;
  897. /* Verify only valid banks are used */
  898. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  899. /* Check that timing values are within limits */
  900. EFM_ASSERT(setupCycles < 4);
  901. EFM_ASSERT(holdCycles < 4);
  902. /* Configure address latch timing values */
  903. addressLatchTiming = (setupCycles << _EBI_ADDRTIMING_ADDRSETUP_SHIFT) |
  904. (holdCycles << _EBI_ADDRTIMING_ADDRHOLD_SHIFT);
  905. if (banks & EBI_BANK0)
  906. {
  907. EBI->ADDRTIMING = (EBI->ADDRTIMING &
  908. ~(_EBI_ADDRTIMING_ADDRSETUP_MASK |
  909. _EBI_ADDRTIMING_ADDRHOLD_MASK)) | addressLatchTiming;
  910. }
  911. if (banks & EBI_BANK1)
  912. {
  913. EBI->ADDRTIMING1 = (EBI->ADDRTIMING1 &
  914. ~(_EBI_ADDRTIMING1_ADDRSETUP_MASK |
  915. _EBI_ADDRTIMING1_ADDRHOLD_MASK)) | addressLatchTiming;
  916. }
  917. if (banks & EBI_BANK2)
  918. {
  919. EBI->ADDRTIMING2 = (EBI->ADDRTIMING2 &
  920. ~(_EBI_ADDRTIMING2_ADDRSETUP_MASK |
  921. _EBI_ADDRTIMING2_ADDRHOLD_MASK)) | addressLatchTiming;
  922. }
  923. if (banks & EBI_BANK3)
  924. {
  925. EBI->ADDRTIMING3 = (EBI->ADDRTIMING3 &
  926. ~(_EBI_ADDRTIMING3_ADDRSETUP_MASK |
  927. _EBI_ADDRTIMING3_ADDRHOLD_MASK)) | addressLatchTiming;
  928. }
  929. }
  930. /***************************************************************************//**
  931. * @brief
  932. * Configure EBI pin polarity for selected bank(s) for devices with individual
  933. * timing support
  934. *
  935. * @param[in] banks
  936. * Mask of memory bank(s) to configure polarity for
  937. *
  938. * @param[in] line
  939. * Which pin/line to configure
  940. *
  941. * @param[in] polarity
  942. * Active high, or active low
  943. ******************************************************************************/
  944. void EBI_BankPolaritySet(uint32_t banks, EBI_Line_TypeDef line, EBI_Polarity_TypeDef polarity)
  945. {
  946. uint32_t bankSet = 0;
  947. volatile uint32_t *polRegister = 0;
  948. /* Verify only valid banks are used */
  949. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  950. while (banks)
  951. {
  952. #if defined(_EFM32_GIANT_FAMILY)
  953. if (banks & EBI_BANK0)
  954. {
  955. polRegister = &EBI->POLARITY;
  956. bankSet = EBI_BANK0;
  957. }
  958. if (banks & EBI_BANK1)
  959. {
  960. polRegister = &EBI->POLARITY1;
  961. bankSet = EBI_BANK1;
  962. }
  963. if (banks & EBI_BANK2)
  964. {
  965. polRegister = &EBI->POLARITY2;
  966. bankSet = EBI_BANK2;
  967. }
  968. if (banks & EBI_BANK3)
  969. {
  970. polRegister = &EBI->POLARITY3;
  971. bankSet = EBI_BANK3;
  972. }
  973. #else
  974. polRegister = &EBI->POLARITY;
  975. banks = 0;
  976. #endif
  977. /* What line to configure */
  978. switch (line)
  979. {
  980. case ebiLineARDY:
  981. BITBAND_Peripheral(polRegister, _EBI_POLARITY_ARDYPOL_SHIFT, polarity);
  982. break;
  983. case ebiLineALE:
  984. BITBAND_Peripheral(polRegister, _EBI_POLARITY_ALEPOL_SHIFT, polarity);
  985. break;
  986. case ebiLineWE:
  987. BITBAND_Peripheral(polRegister, _EBI_POLARITY_WEPOL_SHIFT, polarity);
  988. break;
  989. case ebiLineRE:
  990. BITBAND_Peripheral(polRegister, _EBI_POLARITY_REPOL_SHIFT, polarity);
  991. break;
  992. case ebiLineCS:
  993. BITBAND_Peripheral(polRegister, _EBI_POLARITY_CSPOL_SHIFT, polarity);
  994. break;
  995. #if defined(_EFM32_GIANT_FAMILY)
  996. case ebiLineBL:
  997. BITBAND_Peripheral(polRegister, _EBI_POLARITY_BLPOL_SHIFT, polarity);
  998. break;
  999. case ebiLineTFTVSync:
  1000. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_VSYNCPOL_SHIFT, polarity);
  1001. break;
  1002. case ebiLineTFTHSync:
  1003. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_HSYNCPOL_SHIFT, polarity);
  1004. break;
  1005. case ebiLineTFTDataEn:
  1006. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_DATAENPOL_SHIFT, polarity);
  1007. break;
  1008. case ebiLineTFTDClk:
  1009. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_DCLKPOL_SHIFT, polarity);
  1010. break;
  1011. case ebiLineTFTCS:
  1012. BITBAND_Peripheral(&(EBI->TFTPOLARITY), _EBI_TFTPOLARITY_CSPOL_SHIFT, polarity);
  1013. break;
  1014. #endif
  1015. default:
  1016. EFM_ASSERT(0);
  1017. break;
  1018. }
  1019. banks = banks & (~bankSet);
  1020. }
  1021. }
  1022. /***************************************************************************//**
  1023. * @brief
  1024. * Configure Byte Lane Enable for select banks
  1025. * timing support
  1026. *
  1027. * @param[in] banks
  1028. * Mask of memory bank(s) to configure polarity for
  1029. *
  1030. * @param[in] enable
  1031. * Flag
  1032. ******************************************************************************/
  1033. void EBI_BankByteLaneEnable(uint32_t banks, bool enable)
  1034. {
  1035. /* Verify only valid banks are used */
  1036. EFM_ASSERT((banks & ~(EBI_BANK0 | EBI_BANK1 | EBI_BANK2 | EBI_BANK3)) == 0);
  1037. /* Configure byte lane support for each selected bank */
  1038. if (banks & EBI_BANK0)
  1039. {
  1040. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BL_SHIFT, enable);
  1041. }
  1042. if (banks & EBI_BANK1)
  1043. {
  1044. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BL1_SHIFT, enable);
  1045. }
  1046. if (banks & EBI_BANK2)
  1047. {
  1048. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BL2_SHIFT, enable);
  1049. }
  1050. if (banks & EBI_BANK3)
  1051. {
  1052. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_BL3_SHIFT, enable);
  1053. }
  1054. }
  1055. /***************************************************************************//**
  1056. * @brief
  1057. * Configure Alternate Address Map support
  1058. * Enables or disables 256MB address range for all banks
  1059. *
  1060. * @param[in] enable
  1061. * Set or clear address map extension
  1062. ******************************************************************************/
  1063. void EBI_AltMapEnable(bool enable)
  1064. {
  1065. BITBAND_Peripheral(&(EBI->CTRL), _EBI_CTRL_ALTMAP_SHIFT, enable);
  1066. }
  1067. #endif
  1068. /** @} (end addtogroup EBI) */
  1069. /** @} (end addtogroup EM_Library) */
  1070. #endif /* defined(EBI_COUNT) && (EBI_COUNT > 0) */