1 /**************************************************************************//**
\r
3 * @brief DVK Peripheral Board Control API implementation
\r
4 * @author Energy Micro AS
\r
6 ******************************************************************************
\r
8 * <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
\r
9 ******************************************************************************
\r
11 * This source code is the property of Energy Micro AS. The source and compiled
\r
12 * code may only be used on Energy Micro "EFM32" microcontrollers.
\r
14 * This copyright notice may not be removed from the source code nor changed.
\r
16 * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
\r
17 * obligation to support this Software. Energy Micro AS is providing the
\r
18 * Software "AS IS", with no express or implied warranties of any kind,
\r
19 * including, but not limited to, any implied warranties of merchantability
\r
20 * or fitness for any particular purpose or warranties against infringement
\r
21 * of any proprietary rights of a third party.
\r
23 * Energy Micro AS will not be liable for any consequential, incidental, or
\r
24 * special damages, or any other relief, or for any claim by any third party,
\r
25 * arising from your use of this Software.
\r
27 *****************************************************************************/
\r
31 #include "dvk_boardcontrol.h"
\r
32 #include "dvk_bcregisters.h"
\r
34 /**************************************************************************//**
\r
35 * @brief Enable EFM32 access to periheral on DVK board
\r
36 * @param peri Peripheral to enable
\r
37 *****************************************************************************/
\r
38 void DVK_enablePeripheral(DVKPeripheral peri)
\r
43 /* Calculate which bit to set */
\r
44 bit = (uint16_t) peri;
\r
46 /* Read peripheral control register */
\r
47 tmp = DVK_readRegister(BC_PERCTRL);
\r
49 /* Enable peripheral */
\r
52 /* Special case for RS232, if enabled disable shutdown */
\r
53 if ((peri == DVK_RS232A) || (peri == DVK_RS232B))
\r
55 /* clear shutdown bit */
\r
56 tmp &= ~(BC_PERCTRL_RS232_SHUTDOWN);
\r
59 /* Special case for IRDA if enabled disable shutdown */
\r
60 if (peri == DVK_IRDA)
\r
62 /* clear shutdown bit */
\r
63 tmp &= ~(BC_PERCTRL_IRDA_SHUTDOWN);
\r
66 DVK_writeRegister(BC_PERCTRL, tmp);
\r
69 /**************************************************************************//**
\r
70 * @brief Disable EFM32 access to peripheral on DVK board
\r
71 * @param peri Peripheral to disable
\r
72 *****************************************************************************/
\r
73 void DVK_disablePeripheral(DVKPeripheral peri)
\r
78 /* Calculate which bit to set */
\r
79 bit = (uint16_t) peri;
\r
81 /* Read peripheral control register */
\r
82 tmp = DVK_readRegister(BC_PERCTRL);
\r
84 /* Disable peripheral */
\r
87 /* Special case for RS232, if enabled disable shutdown */
\r
88 if ((peri == DVK_RS232A) || (peri == DVK_RS232B))
\r
90 /* Set shutdown bit */
\r
91 tmp |= (BC_PERCTRL_RS232_SHUTDOWN);
\r
94 /* Special case for IRDA */
\r
95 if (peri == DVK_IRDA)
\r
97 /* Set shutdown bit */
\r
98 tmp |= (BC_PERCTRL_IRDA_SHUTDOWN);
\r
102 DVK_writeRegister(BC_PERCTRL, tmp);
\r
106 /**************************************************************************//**
\r
107 * @brief Enable BUS access
\r
108 *****************************************************************************/
\r
109 void DVK_enableBus(void)
\r
111 /* Enable bus access */
\r
112 DVK_writeRegister(BC_BUS_CFG, 1);
\r
116 /**************************************************************************//**
\r
117 * @brief Disable BUS access
\r
118 *****************************************************************************/
\r
119 void DVK_disableBus(void)
\r
121 DVK_writeRegister(BC_BUS_CFG, 0);
\r
125 /**************************************************************************//**
\r
126 * @brief Inform AEM about current energy mode
\r
127 * @param energyMode What energy mode we are going to use next
\r
128 *****************************************************************************/
\r
129 void DVK_setEnergyMode(uint16_t energyMode)
\r
131 DVK_writeRegister(BC_EM, energyMode);
\r
135 /**************************************************************************//**
\r
136 * @brief Get status of bush buttons
\r
137 * @return Status of push buttons
\r
138 *****************************************************************************/
\r
139 uint16_t DVK_getPushButtons(void)
\r
143 tmp = (~(DVK_readRegister(BC_PUSHBUTTON))) & 0x000f;
\r
147 /**************************************************************************//**
\r
148 * @brief Get joystick button status
\r
149 * @return Joystick controller status
\r
150 *****************************************************************************/
\r
151 uint16_t DVK_getJoystick(void)
\r
155 tmp = (~(DVK_readRegister(BC_JOYSTICK))) & 0x001f;
\r
159 /**************************************************************************//**
\r
160 * @brief Get dipswitch status
\r
161 * The DIP switches are free for user programmable purposes
\r
162 * @return Joystick controller status
\r
163 *****************************************************************************/
\r
164 uint16_t DVK_getDipSwitch(void)
\r
168 tmp = (~(DVK_readRegister(BC_DIPSWITCH))) & 0x00ff;
\r
172 /**************************************************************************//**
\r
173 * @brief Sets user leds
\r
174 * @param leds 16-bits which enables or disables the board "User leds"
\r
175 *****************************************************************************/
\r
176 void DVK_setLEDs(uint16_t leds)
\r
178 DVK_writeRegister(BC_LED, leds);
\r
181 /**************************************************************************//**
\r
182 * @brief Get status of user LEDs
\r
183 * @return Status of 16 user leds, bit 1 = on, bit 0 = off
\r
184 *****************************************************************************/
\r
185 uint16_t DVK_getLEDs(void)
\r
187 return DVK_readRegister(BC_LED);
\r
190 /**************************************************************************//**
\r
191 * @brief Enable "Control" buttons/joystick/dip switch interrupts
\r
192 * @param flags Board control interrupt flags, BC_INTEN_<something>
\r
193 *****************************************************************************/
\r
194 void DVK_enableInterrupt(uint16_t flags)
\r
198 /* Add flags to interrupt enable register */
\r
199 tmp = DVK_readRegister(BC_INTEN);
\r
201 DVK_writeRegister(BC_INTEN, tmp);
\r
204 /**************************************************************************//**
\r
205 * @brief Disable "Control" buttons/joystick/dip switch interrupts
\r
206 * @param flags Board control interrupt flags, BC_INTEN_<something>
\r
207 *****************************************************************************/
\r
208 void DVK_disableInterrupt(uint16_t flags)
\r
212 /* Clear flags from interrupt enable register */
\r
213 tmp = DVK_readRegister(BC_INTEN);
\r
216 DVK_writeRegister(BC_INTEN, tmp);
\r
219 /**************************************************************************//**
\r
220 * @brief Clear interrupts
\r
221 * @param flags Board control interrupt flags, BC_INTEN_<something>
\r
222 *****************************************************************************/
\r
223 void DVK_clearInterruptFlags(uint16_t flags)
\r
225 DVK_writeRegister(BC_INTFLAG, flags);
\r
228 /**************************************************************************//**
\r
229 * @brief Read interrupt flags
\r
230 * @return Returns currently triggered interrupts
\r
231 *****************************************************************************/
\r
232 uint16_t DVK_getInterruptFlags(void)
\r
234 return DVK_readRegister(BC_INTFLAG);
\r