EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
em_ebi.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef EM_EBI_H
34 #define EM_EBI_H
35 
36 #include "em_device.h"
37 #if defined(EBI_COUNT) && (EBI_COUNT > 0)
38 
39 #include <stdint.h>
40 #include <stdbool.h>
41 #include "em_assert.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /***************************************************************************/
52 /***************************************************************************/
57 /***************************************************************************/
71 /*******************************************************************************
72  ******************************* DEFINES ***********************************
73  ******************************************************************************/
74 
75 #define EBI_BANK0 (uint32_t)(1 << 1)
76 #define EBI_BANK1 (uint32_t)(1 << 2)
77 #define EBI_BANK2 (uint32_t)(1 << 3)
78 #define EBI_BANK3 (uint32_t)(1 << 4)
80 #define EBI_CS0 (uint32_t)(1 << 1)
81 #define EBI_CS1 (uint32_t)(1 << 2)
82 #define EBI_CS2 (uint32_t)(1 << 3)
83 #define EBI_CS3 (uint32_t)(1 << 4)
85 /*******************************************************************************
86  ******************************** ENUMS ************************************
87  ******************************************************************************/
88 
90 typedef enum
91 {
93  ebiModeD8A8 = EBI_CTRL_MODE_D8A8,
95  ebiModeD16A16ALE = EBI_CTRL_MODE_D16A16ALE,
97  ebiModeD8A24ALE = EBI_CTRL_MODE_D8A24ALE,
98 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
99 
100  ebiModeD16 = EBI_CTRL_MODE_D16,
101 #endif
102 } EBI_Mode_TypeDef;
103 
105 typedef enum
106 {
108  ebiActiveLow = 0,
110  ebiActiveHigh = 1
111 } EBI_Polarity_TypeDef;
112 
114 typedef enum
115 {
117  ebiLineARDY,
119  ebiLineALE,
121  ebiLineWE,
123  ebiLineRE,
125  ebiLineCS,
126 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
127 
128  ebiLineBL,
129 #endif
130 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
131 
132  ebiLineTFTVSync,
134  ebiLineTFTHSync,
136  ebiLineTFTDataEn,
138  ebiLineTFTDClk,
140  ebiLineTFTCS,
141 #endif
142 } EBI_Line_TypeDef;
143 
144 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
145 
146 typedef enum
147 {
149  ebiALowA0 = EBI_ROUTE_ALB_A0,
151  ebiALowA8 = EBI_ROUTE_ALB_A8,
153  ebiALowA16 = EBI_ROUTE_ALB_A16,
155  ebiALowA24 = EBI_ROUTE_ALB_A24,
156 } EBI_ALow_TypeDef;
157 
159 typedef enum
160 {
162  ebiAHighA0 = EBI_ROUTE_APEN_A0,
164  ebiAHighA5 = EBI_ROUTE_APEN_A5,
166  ebiAHighA6 = EBI_ROUTE_APEN_A6,
168  ebiAHighA7 = EBI_ROUTE_APEN_A7,
170  ebiAHighA8 = EBI_ROUTE_APEN_A8,
172  ebiAHighA9 = EBI_ROUTE_APEN_A9,
174  ebiAHighA10 = EBI_ROUTE_APEN_A10,
176  ebiAHighA11 = EBI_ROUTE_APEN_A11,
178  ebiAHighA12 = EBI_ROUTE_APEN_A12,
180  ebiAHighA13 = EBI_ROUTE_APEN_A13,
182  ebiAHighA14 = EBI_ROUTE_APEN_A14,
184  ebiAHighA15 = EBI_ROUTE_APEN_A15,
186  ebiAHighA16 = EBI_ROUTE_APEN_A16,
188  ebiAHighA17 = EBI_ROUTE_APEN_A17,
190  ebiAHighA18 = EBI_ROUTE_APEN_A18,
192  ebiAHighA19 = EBI_ROUTE_APEN_A19,
194  ebiAHighA20 = EBI_ROUTE_APEN_A20,
196  ebiAHighA21 = EBI_ROUTE_APEN_A21,
198  ebiAHighA22 = EBI_ROUTE_APEN_A22,
200  ebiAHighA23 = EBI_ROUTE_APEN_A23,
202  ebiAHighA24 = EBI_ROUTE_APEN_A24,
204  ebiAHighA25 = EBI_ROUTE_APEN_A25,
206  ebiAHighA26 = EBI_ROUTE_APEN_A26,
208  ebiAHighA27 = EBI_ROUTE_APEN_A27,
210  ebiAHighA28 = EBI_ROUTE_APEN_A28,
211 } EBI_AHigh_TypeDef;
212 
214 typedef enum {
216  ebiLocation0 = EBI_ROUTE_LOCATION_LOC0,
218  ebiLocation1 = EBI_ROUTE_LOCATION_LOC1,
220  ebiLocation2 = EBI_ROUTE_LOCATION_LOC2
221 } EBI_Location_TypeDef;
222 #endif
223 
224 /* TFT support */
225 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
226 
227 typedef enum
228 {
230  ebiTFTBank0 = EBI_TFTCTRL_BANKSEL_BANK0,
232  ebiTFTBank1 = EBI_TFTCTRL_BANKSEL_BANK1,
234  ebiTFTBank2 = EBI_TFTCTRL_BANKSEL_BANK2,
236  ebiTFTBank3 = EBI_TFTCTRL_BANKSEL_BANK3
237 } EBI_TFTBank_TypeDef;
238 
240 typedef enum
241 {
243  ebiTFTColorSrcMem = EBI_TFTCTRL_COLOR1SRC_MEM,
245  ebiTFTColorSrcPixel1 = EBI_TFTCTRL_COLOR1SRC_PIXEL1,
246 } EBI_TFTColorSrc_TypeDef;
247 
249 typedef enum
250 {
252  ebiTFTInterleaveUnlimited = EBI_TFTCTRL_INTERLEAVE_UNLIMITED,
254  ebiTFTInterleaveOnePerDClk = EBI_TFTCTRL_INTERLEAVE_ONEPERDCLK,
256  ebiTFTInterleavePorch = EBI_TFTCTRL_INTERLEAVE_PORCH,
257 } EBI_TFTInterleave_TypeDef;
258 
260 typedef enum
261 {
263  ebiTFTFrameBufTriggerVSync = EBI_TFTCTRL_FBCTRIG_VSYNC,
265  ebiTFTFrameBufTriggerHSync = EBI_TFTCTRL_FBCTRIG_HSYNC,
266 } EBI_TFTFrameBufTrigger_TypeDef;
267 
269 typedef enum
270 {
272  ebiTFTMBDisabled = EBI_TFTCTRL_MASKBLEND_DISABLED,
274  ebiTFTMBIMask = EBI_TFTCTRL_MASKBLEND_IMASK,
276  ebiTFTMBIAlpha = EBI_TFTCTRL_MASKBLEND_IALPHA,
278  ebiTFTMBIMaskAlpha = EBI_TFTCTRL_MASKBLEND_IMASKIALPHA,
280  ebiTFTMBEMask = EBI_TFTCTRL_MASKBLEND_EMASK,
282  ebiTFTMBEAlpha = EBI_TFTCTRL_MASKBLEND_EALPHA,
284  ebiTFTMBEMaskAlpha = EBI_TFTCTRL_MASKBLEND_EMASKEALPHA,
285 } EBI_TFTMaskBlend_TypeDef;
286 
288 typedef enum
289 {
291  ebiTFTDDModeDisabled = EBI_TFTCTRL_DD_DISABLED,
293  ebiTFTDDModeInternal = EBI_TFTCTRL_DD_INTERNAL,
295  ebiTFTDDModeExternal = EBI_TFTCTRL_DD_EXTERNAL,
296 } EBI_TFTDDMode_TypeDef;
297 
299 typedef enum
300 {
302  ebiTFTWidthByte = EBI_TFTCTRL_WIDTH_BYTE,
304  ebiTFTWidthHalfWord = EBI_TFTCTRL_WIDTH_HALFWORD,
305 } EBI_TFTWidth_TypeDef;
306 
307 #endif
308 
309 /*******************************************************************************
310  ******************************* STRUCTS ***********************************
311  ******************************************************************************/
312 
314 typedef struct
315 {
317  EBI_Mode_TypeDef mode;
319  EBI_Polarity_TypeDef ardyPolarity;
321  EBI_Polarity_TypeDef alePolarity;
323  EBI_Polarity_TypeDef wePolarity;
325  EBI_Polarity_TypeDef rePolarity;
327  EBI_Polarity_TypeDef csPolarity;
328 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
329 
330  EBI_Polarity_TypeDef blPolarity;
332  bool blEnable;
334  bool noIdle;
335 #endif
336 
337  bool ardyEnable;
339  bool ardyDisableTimeout;
341  uint32_t banks;
343  uint32_t csLines;
345  int addrSetupCycles;
347  int addrHoldCycles;
348 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
349 
350  bool addrHalfALE;
351 #endif
352 
353  int readSetupCycles;
355  int readStrobeCycles;
357  int readHoldCycles;
358 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
359 
360  bool readPageMode;
362  bool readPrefetch;
364  bool readHalfRE;
365 #endif
366 
367  int writeSetupCycles;
369  int writeStrobeCycles;
371  int writeHoldCycles;
372 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
373 
374  bool writeBufferDisable;
376  bool writeHalfWE;
378  EBI_ALow_TypeDef aLow;
380  EBI_AHigh_TypeDef aHigh;
382  EBI_Location_TypeDef location;
383 #endif
384 
385  bool enable;
386 } EBI_Init_TypeDef;
387 
389 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
390 #define EBI_INIT_DEFAULT \
391 { \
392  ebiModeD8A8, /* 8 bit address, 8 bit data */ \
393  ebiActiveLow, /* ARDY polarity */ \
394  ebiActiveLow, /* ALE polarity */ \
395  ebiActiveLow, /* WE polarity */ \
396  ebiActiveLow, /* RE polarity */ \
397  ebiActiveLow, /* CS polarity */ \
398  ebiActiveLow, /* BL polarity */ \
399  false, /* enable BL */ \
400  false, /* enable NOIDLE */ \
401  false, /* enable ARDY */ \
402  false, /* don't disable ARDY timeout */ \
403  EBI_BANK0, /* enable bank 0 */ \
404  EBI_CS0, /* enable chip select 0 */ \
405  0, /* addr setup cycles */ \
406  1, /* addr hold cycles */ \
407  false, /* do not enable half cycle ALE strobe */ \
408  0, /* read setup cycles */ \
409  0, /* read strobe cycles */ \
410  0, /* read hold cycles */ \
411  false, /* disable page mode */ \
412  false, /* disable prefetch */ \
413  false, /* do not enable half cycle REn strobe */ \
414  0, /* write setup cycles */ \
415  0, /* write strobe cycles */ \
416  1, /* write hold cycles */ \
417  false, /* do not disable the write buffer */ \
418  false, /* do not enable halc cycle WEn strobe */ \
419  ebiALowA0, /* ALB - Low bound, address lines */ \
420  ebiAHighA0, /* APEN - High bound, address lines */ \
421  ebiLocation0, /* Use Location 0 */ \
422  true, /* enable EBI */ \
423 }
424 #else
425 #define EBI_INIT_DEFAULT \
426 { \
427  ebiModeD8A8, /* 8 bit address, 8 bit data */ \
428  ebiActiveLow, /* ARDY polarity */ \
429  ebiActiveLow, /* ALE polarity */ \
430  ebiActiveLow, /* WE polarity */ \
431  ebiActiveLow, /* RE polarity */ \
432  ebiActiveLow, /* CS polarity */ \
433  false, /* enable ARDY */ \
434  false, /* don't disable ARDY timeout */ \
435  EBI_BANK0, /* enable bank 0 */ \
436  EBI_CS0, /* enable chip select 0 */ \
437  0, /* addr setup cycles */ \
438  1, /* addr hold cycles */ \
439  0, /* read setup cycles */ \
440  0, /* read strobe cycles */ \
441  0, /* read hold cycles */ \
442  0, /* write setup cycles */ \
443  0, /* write strobe cycles */ \
444  1, /* write hold cycles */ \
445  true, /* enable EBI */ \
446 }
447 #endif
448 
449 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
450 
452 typedef struct
453 {
455  EBI_TFTBank_TypeDef bank;
457  EBI_TFTWidth_TypeDef width;
459  EBI_TFTColorSrc_TypeDef colSrc;
461  EBI_TFTInterleave_TypeDef interleave;
463  EBI_TFTFrameBufTrigger_TypeDef fbTrigger;
465  bool shiftDClk;
467  EBI_TFTMaskBlend_TypeDef maskBlend;
469  EBI_TFTDDMode_TypeDef driveMode;
471  EBI_Polarity_TypeDef csPolarity;
473  EBI_Polarity_TypeDef dclkPolarity;
475  EBI_Polarity_TypeDef dataenPolarity;
477  EBI_Polarity_TypeDef hsyncPolarity;
479  EBI_Polarity_TypeDef vsyncPolarity;
481  int hsize;
483  int hPorchFront;
485  int hPorchBack;
487  int hPulseWidth;
489  int vsize;
491  int vPorchFront;
493  int vPorchBack;
495  int vPulseWidth;
497  uint32_t addressOffset;
499  int dclkPeriod;
501  int startPosition;
503  int setupCycles;
505  int holdCycles;
506 } EBI_TFTInit_TypeDef;
507 
509 #define EBI_TFTINIT_DEFAULT \
510 { \
511  ebiTFTBank0, /* Select EBI Bank 0 */ \
512  ebiTFTWidthHalfWord, /* Select 2-byte increments */ \
513  ebiTFTColorSrcMem, /* Use memory as source for mask/blending */ \
514  ebiTFTInterleaveUnlimited, /* Unlimited interleaved accesses */ \
515  ebiTFTFrameBufTriggerVSync, /* VSYNC as frame buffer update trigger */ \
516  false, /* Drive DCLK from negative edge of internal clock */ \
517  ebiTFTMBDisabled, /* No masking and alpha blending enabled */ \
518  ebiTFTDDModeExternal, /* Drive from external memory */ \
519  ebiActiveLow, /* CS Active Low polarity */ \
520  ebiActiveLow, /* DCLK Active Low polarity */ \
521  ebiActiveLow, /* DATAEN Active Low polarity */ \
522  ebiActiveLow, /* HSYNC Active Low polarity */ \
523  ebiActiveLow, /* VSYNC Active Low polarity */ \
524  320, /* Horizontal size in pixels */ \
525  1, /* Horizontal Front Porch */ \
526  29, /* Horizontal Back Porch */ \
527  2, /* Horizontal Synchronization Pulse Width */ \
528  240, /* Vertical size in pixels */ \
529  1, /* Vertical Front Porch */ \
530  4, /* Vertical Back Porch */ \
531  2, /* Vertical Synchronization Pulse Width */ \
532  0x0000, /* Address offset to EBI memory base */ \
533  5, /* DCLK Period */ \
534  2, /* DCLK Start */ \
535  1, /* DCLK Setup cycles */ \
536  1, /* DCLK Hold cycles */ \
537 }
538 
539 #endif
540 /*******************************************************************************
541  ***************************** PROTOTYPES **********************************
542  ******************************************************************************/
543 
544 void EBI_Init(const EBI_Init_TypeDef *ebiInit);
545 void EBI_Disable(void);
546 uint32_t EBI_BankAddress(uint32_t bank);
547 void EBI_BankEnable(uint32_t banks, bool enable);
548 
549 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
550 void EBI_TFTInit(const EBI_TFTInit_TypeDef *ebiTFTInit);
551 void EBI_TFTSizeSet(uint32_t horizontal, uint32_t vertical);
552 void EBI_TFTHPorchSet(int front, int back, int pulseWidth);
553 void EBI_TFTVPorchSet(int front, int back, int pulseWidth);
554 void EBI_TFTTimingSet(int dclkPeriod, int start, int setup, int hold);
555 #endif
556 
557 #if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_WONDER_FAMILY)
558 /* This functionality is only available on devices with independent timing support */
559 void EBI_BankReadTimingSet(uint32_t bank, int setupCycles, int strobeCycles, int holdCycles);
560 void EBI_BankReadTimingConfig(uint32_t bank, bool pageMode, bool prefetch, bool halfRE);
561 
562 void EBI_BankWriteTimingSet(uint32_t bank, int setupCycles, int strobeCycles, int holdCycles);
563 void EBI_BankWriteTimingConfig(uint32_t bank, bool writeBufDisable, bool halfWE);
564 
565 void EBI_BankAddressTimingSet(uint32_t bank, int setupCycles, int holdCycles);
566 void EBI_BankAddressTimingConfig(uint32_t bank, bool halfALE);
567 
568 void EBI_BankPolaritySet(uint32_t bank, EBI_Line_TypeDef line, EBI_Polarity_TypeDef polarity);
569 void EBI_BankByteLaneEnable(uint32_t bank, bool enable);
570 void EBI_AltMapEnable(bool enable);
571 
572 /***************************************************************************/
579 __STATIC_INLINE void EBI_TFTEnable(EBI_TFTDDMode_TypeDef mode)
580 {
581  EBI->TFTCTRL = (EBI->TFTCTRL & ~(_EBI_TFTCTRL_DD_MASK)) | (uint32_t) mode;
582 }
583 
584 
585 /***************************************************************************/
592 __STATIC_INLINE void EBI_TFTFrameBaseSet(uint32_t address)
593 {
594  EBI->TFTFRAMEBASE = (uint32_t) address;
595 }
596 
597 
598 /***************************************************************************/
606 __STATIC_INLINE void EBI_TFTPixelSet(int pixel, uint32_t color)
607 {
608  EFM_ASSERT(pixel == 0 || pixel == 1);
609 
610  if (pixel == 0)
611  {
612  EBI->TFTPIXEL0 = color;
613  }
614  if (pixel == 1)
615  {
616  EBI->TFTPIXEL1 = color;
617  }
618 }
619 
620 
621 /***************************************************************************/
627 __STATIC_INLINE void EBI_TFTMaskBlendMode(EBI_TFTMaskBlend_TypeDef maskBlend)
628 {
629  EBI->TFTCTRL = (EBI->TFTCTRL & (~_EBI_TFTCTRL_MASKBLEND_MASK))|maskBlend;
630 }
631 
632 
633 /***************************************************************************/
639 __STATIC_INLINE void EBI_TFTAlphaBlendSet(uint8_t alpha)
640 {
641  EBI->TFTALPHA = alpha;
642 }
643 
644 
645 /***************************************************************************/
650 __STATIC_INLINE void EBI_TFTMaskSet(uint32_t mask)
651 {
652  EBI->TFTMASK = mask;
653 }
654 
655 
656 /***************************************************************************/
661 __STATIC_INLINE uint32_t EBI_TFTVCount(void)
662 {
663  return((EBI->TFTSTATUS & _EBI_TFTSTATUS_VCNT_MASK) >> _EBI_TFTSTATUS_VCNT_SHIFT);
664 }
665 
666 
667 /***************************************************************************/
672 __STATIC_INLINE uint32_t EBI_TFTHCount(void)
673 {
674  return((EBI->TFTSTATUS & _EBI_TFTSTATUS_HCNT_MASK) >> _EBI_TFTSTATUS_HCNT_SHIFT);
675 }
676 
677 
678 /***************************************************************************/
688 __STATIC_INLINE void EBI_TFTFBTriggerSet(EBI_TFTFrameBufTrigger_TypeDef sync)
689 {
690  EBI->TFTCTRL = ((EBI->TFTCTRL & ~_EBI_TFTCTRL_FBCTRIG_MASK)|sync);
691 }
692 
693 
694 /***************************************************************************/
701 __STATIC_INLINE void EBI_TFTHStrideSet(uint32_t nbytes)
702 {
703  EFM_ASSERT(nbytes < 0x1000);
704 
705  EBI->TFTSTRIDE = (EBI->TFTSTRIDE & ~(_EBI_TFTSTRIDE_HSTRIDE_MASK))|
706  (nbytes<<_EBI_TFTSTRIDE_HSTRIDE_SHIFT);
707 }
708 
709 
710 /***************************************************************************/
717 __STATIC_INLINE void EBI_IntClear(uint32_t flags)
718 {
719  EBI->IFC = flags;
720 }
721 
722 
723 /***************************************************************************/
731 __STATIC_INLINE void EBI_IntSet(uint32_t flags)
732 {
733  EBI->IFS = flags;
734 }
735 
736 
737 /***************************************************************************/
745 __STATIC_INLINE void EBI_IntDisable(uint32_t flags)
746 {
747  EBI->IEN &= ~(flags);
748 }
749 
750 
751 /***************************************************************************/
759 __STATIC_INLINE void EBI_IntEnable(uint32_t flags)
760 {
761  EBI->IEN |= flags;
762 }
763 
764 
765 /***************************************************************************/
776 __STATIC_INLINE uint32_t EBI_IntGet(void)
777 {
778  return EBI->IF;
779 }
780 
781 
782 /***************************************************************************/
796 __STATIC_INLINE uint32_t EBI_IntGetEnabled(void)
797 {
798  uint32_t ien;
799 
800  ien = EBI->IEN;
801  return EBI->IF & ien;
802 }
803 
804 
805 /***************************************************************************/
809 __STATIC_INLINE void EBI_StartNandEccGen(void)
810 {
811  EBI->CMD = EBI_CMD_ECCSTART | EBI_CMD_ECCCLEAR;
812 }
813 
814 
815 /***************************************************************************/
822 __STATIC_INLINE uint32_t EBI_StopNandEccGen( void )
823 {
824  EBI->CMD = EBI_CMD_ECCSTOP;
825  return EBI->ECCPARITY;
826 }
827 #endif
828 
829 void EBI_ChipSelectEnable(uint32_t banks, bool enable);
830 void EBI_ReadTimingSet(int setupCycles, int strobeCycles, int holdCycles);
831 void EBI_WriteTimingSet(int setupCycles, int strobeCycles, int holdCycles);
832 void EBI_AddressTimingSet(int setupCycles, int holdCycles);
833 void EBI_PolaritySet(EBI_Line_TypeDef line, EBI_Polarity_TypeDef polarity);
834 
838 #ifdef __cplusplus
839 }
840 #endif
841 
842 #endif /* defined(EBI_COUNT) && (EBI_COUNT > 0) */
843 
844 #endif /* EM_EBI_H */
Emlib peripheral API "assert" implementation.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.