1 /**************************************************************************//**
2  * @file
3  * @brief EFM32GG_DK3750 board support package API
4  * @author Energy Micro AS
5  * @version 2.0.1
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  * 4. The source and compiled code may only be used on Energy Micro "EFM32"
21  *    microcontrollers and "EFR4" radios.
22  *
23  * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
24  * obligation to support this Software. Energy Micro AS is providing the
25  * Software "AS IS", with no express or implied warranties of any kind,
26  * including, but not limited to, any implied warranties of merchantability
27  * or fitness for any particular purpose or warranties against infringement
28  * of any proprietary rights of a third party.
29  *
30  * Energy Micro AS will not be liable for any consequential, incidental, or
31  * special damages, or any other relief, or for any claim by any third party,
32  * arising from your use of this Software.
33  *
34  *****************************************************************************/
35 #ifndef __DVK_H
36 #define __DVK_H
37 
38 /***************************************************************************//**
39  * @addtogroup BSP
40  * @{
41  ******************************************************************************/
42 
43 #include <stdbool.h>
44 #include <stdint.h>
45 #include "efm32.h"
46 #include "dvk_bcregisters.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /** DVK board control access method */
53 typedef enum
54 {
55   DVK_Init_EBI,    /**< Use EBI to interface board control functionality */
56   DVK_Init_SPI,    /**< Use SPI to interface board control functionality */
57   DVK_Init_DIRECT, /**< No board control, only GPIO */
58   DVK_Init_OFF,    /**< Disabled */
59 } DVK_Init_TypeDef;
60 
61 extern DVK_Init_TypeDef dvkOperationMode;
62 
63 /** Bus control access */
64 typedef enum
65 {
66   DVK_BusControl_OFF,    /**< Board control disable */
67   DVK_BusControl_DIRECT, /**< GPIO direct drive (n/a) */
68   DVK_BusControl_SPI,    /**< Configure Board controller for SPI mode */
69   DVK_BusControl_EBI,    /**< Configure Board controller for EBI mode */
70 } DVK_BusControl_TypeDef;
71 
72 
73 /** Display Control */
74 typedef enum
75 {
76   DVK_Display_EBI,          /**< SSD2119 TFT controller driven by EFM32GG EBI interface */
77   DVK_Display_SPI,          /**< SSD2119 TFT controller driven by EFM32GG SPI interface */
78   DVK_Display_BC,           /**< SSD2119 TFT controller driven by board controller (AEM) */
79   DVK_Display_PowerEnable,  /**< SSD2119 Enable power  */
80   DVK_Display_PowerDisable, /**< SSD2119 Disable power  */
81   DVK_Display_ResetAssert,  /**< Hold SSD2119 in reset */
82   DVK_Display_ResetRelease, /**< Release SSD2119 in reset */
83   DVK_Display_Mode8080,     /**< Configure SSD2119 for 8080 mode of operation  */
84   DVK_Display_ModeGeneric,  /**< Configure SSD2119 for Generic+SPI mode of operation */
85 } DVK_Display_TypeDef;
86 
87 
88 /** SPI control */
89 typedef enum
90 {
91   DVK_SPI_Audio,    /**< Configure switchable SPI interface to Audio I2S */
92   DVK_SPI_Ethernet, /**< Configure switchable SPI interface to Ethernet */
93   DVK_SPI_Display,  /**< Configure switchable SPI interface to SSD2119 */
94   DVK_SPI_OFF,      /**< Disable SPI interface */
95 } DVK_SpiControl_TypeDef;
96 
97 
98 /** Peripherals control structure */
99 typedef enum
100 {
101   DVK_RS232_SHUTDOWN, /**< Disable RS232 */
102   DVK_RS232_UART,     /**< UART control of RS232 */
103   DVK_RS232_LEUART,   /**< LEUART control of RS232 */
104   DVK_I2C,            /**< I2C */
105   DVK_ETH,            /**< Ethernet */
106   DVK_I2S,            /**< Audio I2S */
107   DVK_TRACE,          /**< ETM Trace */
108   DVK_TOUCH,          /**< Display touch interface */
109   DVK_AUDIO_IN,       /**< Audio In */
110   DVK_AUDIO_OUT,      /**< Audio Out */
111   DVK_ANALOG_DIFF,    /**< Analog DIFF */
112   DVK_ANALOG_SE,      /**< Analog SE */
113   DVK_MICROSD,        /**< MicroSD SPI interace */
114   DVK_TFT,            /**< SSD2119 TFT controller */
115 } DVK_Peripheral_TypeDef;
116 
117 
118 /* Initalize DVK board for access to external PSRAM, Flash and BC registers */
119 void DVK_init(DVK_Init_TypeDef mode);
120 void DVK_disable(void);
121 
122 /* Board controller control API */
123 void DVK_busControlMode(DVK_BusControl_TypeDef mode);
124 void DVK_peripheralAccess(DVK_Peripheral_TypeDef perf, bool enable);
125 void DVK_spiControl(DVK_SpiControl_TypeDef device);
126 
127 /* Board controller access function  */
128 uint16_t DVK_getPushButtons(void);
129 uint16_t DVK_getJoystick(void);
130 uint16_t DVK_getDipSwitch(void);
131 void DVK_setLEDs(uint16_t leds);
132 uint16_t DVK_getLEDs(void);
133 
134 /* Miscellaneous */
135 void DVK_setEnergyMode(uint16_t energyMode);
136 void DVK_displayControl(DVK_Display_TypeDef option);
137 
138 /* Board controller interrupt support */
139 void DVK_enableInterrupt(uint16_t flags);
140 void DVK_disableInterrupt(uint16_t flags);
141 uint16_t DVK_getInterruptFlags(void);
142 void DVK_clearInterruptFlags(uint16_t flags);
143 
144 /* EBI access */
145 bool DVK_EBI_init(void);
146 void DVK_EBI_disable(void);
147 void DVK_EBI_extendedAddressRange(bool enable);
148 __STATIC_INLINE void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data);
149 __STATIC_INLINE uint16_t DVK_EBI_readRegister(volatile uint16_t *addr);
150 
151 /* SPI access */
152 bool DVK_SPI_init(void);
153 void DVK_SPI_disable(void);
154 uint16_t DVK_SPI_readRegister(volatile uint16_t *addr);
155 void DVK_SPI_writeRegister(volatile uint16_t *addr, uint16_t data);
156 
157 /* MCU-plug-in-board (BRD3600) API */
158 void DVK_BRD3600A_init(void);
159 void DVK_BRD3600A_deInit(void);
160 void DVK_BRD3600A_usbStatusLEDEnable(int enable);
161 void DVK_BRD3600A_usbVBUSSwitchEnable(int enable);
162 int  DVK_BRD3600A_usbVBUSGetOCFlagState(void);
163 
164 
165 /* For "backward compatibility" with DVK */
166 /** DVK_enablePeripheral() backward compatibility */
167 #define DVK_enablePeripheral(X)     DVK_peripheralAccess(X, true)
168 /** DVK_disablePeripheral() backward compatibility */
169 #define DVK_disablePeripheral(X)    DVK_peripheralAccess(X, false)
170 
171 /**************************************************************************//**
172  * @brief Write data into 16-bit board control register using mem.mapped EBI
173  * @param addr Address of board controller register
174  * @param data Data to write into register
175  *****************************************************************************/
DVK_EBI_writeRegister(volatile uint16_t * addr,uint16_t data)176 __STATIC_INLINE void DVK_EBI_writeRegister(volatile uint16_t *addr, uint16_t data)
177 {
178   *addr = data;
179 }
180 
181 
182 /**************************************************************************//**
183  * @brief Read data from 16-bit board control register using memory mapped EBI
184  * @param addr Register to read from
185  * @return Value of board controller register
186  *****************************************************************************/
DVK_EBI_readRegister(volatile uint16_t * addr)187 __STATIC_INLINE uint16_t DVK_EBI_readRegister(volatile uint16_t *addr)
188 {
189   return *addr;
190 }
191 
192 
193 /**************************************************************************//**
194  * @brief Read data from 16-bit board control register
195  * @param addr Register to read
196  * @return Value of board controller register
197  *****************************************************************************/
DVK_readRegister(volatile uint16_t * addr)198 __STATIC_INLINE uint16_t DVK_readRegister(volatile uint16_t *addr)
199 {
200   if (dvkOperationMode == DVK_Init_EBI)
201   {
202     return DVK_EBI_readRegister(addr);
203   }
204   else
205   {
206     return DVK_SPI_readRegister(addr);
207   }
208 }
209 
210 
211 /**************************************************************************//**
212  * @brief Write data into 16-bit board control register
213  * @param addr Address to board control register
214  * @param data Data to write into register
215  *****************************************************************************/
DVK_writeRegister(volatile uint16_t * addr,uint16_t data)216 __STATIC_INLINE void DVK_writeRegister(volatile uint16_t *addr, uint16_t data)
217 {
218   if (dvkOperationMode == DVK_Init_EBI)
219   {
220     DVK_EBI_writeRegister(addr, data);
221   }
222   else
223   {
224     DVK_SPI_writeRegister(addr, data);
225   }
226 }
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 /** @} (end group BSP) */
233 
234 #endif
235