1 |
595 |
jeremybenn |
/**************************************************************************//**
|
2 |
|
|
* @file
|
3 |
|
|
* @brief DVK Peripheral Board Control API implementation
|
4 |
|
|
* @author Energy Micro AS
|
5 |
|
|
* @version 1.0.1
|
6 |
|
|
******************************************************************************
|
7 |
|
|
* @section License
|
8 |
|
|
* <b>(C) Copyright 2009 Energy Micro AS, http://www.energymicro.com</b>
|
9 |
|
|
******************************************************************************
|
10 |
|
|
*
|
11 |
|
|
* This source code is the property of Energy Micro AS. The source and compiled
|
12 |
|
|
* code may only be used on Energy Micro "EFM32" microcontrollers.
|
13 |
|
|
*
|
14 |
|
|
* This copyright notice may not be removed from the source code nor changed.
|
15 |
|
|
*
|
16 |
|
|
* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
|
17 |
|
|
* obligation to support this Software. Energy Micro AS is providing the
|
18 |
|
|
* Software "AS IS", with no express or implied warranties of any kind,
|
19 |
|
|
* including, but not limited to, any implied warranties of merchantability
|
20 |
|
|
* or fitness for any particular purpose or warranties against infringement
|
21 |
|
|
* of any proprietary rights of a third party.
|
22 |
|
|
*
|
23 |
|
|
* Energy Micro AS will not be liable for any consequential, incidental, or
|
24 |
|
|
* special damages, or any other relief, or for any claim by any third party,
|
25 |
|
|
* arising from your use of this Software.
|
26 |
|
|
*
|
27 |
|
|
*****************************************************************************/
|
28 |
|
|
|
29 |
|
|
#include "efm32.h"
|
30 |
|
|
#include "dvk.h"
|
31 |
|
|
#include "dvk_boardcontrol.h"
|
32 |
|
|
#include "dvk_bcregisters.h"
|
33 |
|
|
|
34 |
|
|
/**************************************************************************//**
|
35 |
|
|
* @brief Enable EFM32 access to periheral on DVK board
|
36 |
|
|
* @param peri Peripheral to enable
|
37 |
|
|
*****************************************************************************/
|
38 |
|
|
void DVK_enablePeripheral(DVKPeripheral peri)
|
39 |
|
|
{
|
40 |
|
|
uint16_t bit;
|
41 |
|
|
uint16_t tmp;
|
42 |
|
|
|
43 |
|
|
/* Calculate which bit to set */
|
44 |
|
|
bit = (uint16_t) peri;
|
45 |
|
|
|
46 |
|
|
/* Read peripheral control register */
|
47 |
|
|
tmp = DVK_readRegister(BC_PERCTRL);
|
48 |
|
|
|
49 |
|
|
/* Enable peripheral */
|
50 |
|
|
tmp |= bit;
|
51 |
|
|
|
52 |
|
|
/* Special case for RS232, if enabled disable shutdown */
|
53 |
|
|
if ((peri == DVK_RS232A) || (peri == DVK_RS232B))
|
54 |
|
|
{
|
55 |
|
|
/* clear shutdown bit */
|
56 |
|
|
tmp &= ~(BC_PERCTRL_RS232_SHUTDOWN);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/* Special case for IRDA if enabled disable shutdown */
|
60 |
|
|
if (peri == DVK_IRDA)
|
61 |
|
|
{
|
62 |
|
|
/* clear shutdown bit */
|
63 |
|
|
tmp &= ~(BC_PERCTRL_IRDA_SHUTDOWN);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
DVK_writeRegister(BC_PERCTRL, tmp);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
/**************************************************************************//**
|
70 |
|
|
* @brief Disable EFM32 access to peripheral on DVK board
|
71 |
|
|
* @param peri Peripheral to disable
|
72 |
|
|
*****************************************************************************/
|
73 |
|
|
void DVK_disablePeripheral(DVKPeripheral peri)
|
74 |
|
|
{
|
75 |
|
|
uint16_t bit;
|
76 |
|
|
uint16_t tmp;
|
77 |
|
|
|
78 |
|
|
/* Calculate which bit to set */
|
79 |
|
|
bit = (uint16_t) peri;
|
80 |
|
|
|
81 |
|
|
/* Read peripheral control register */
|
82 |
|
|
tmp = DVK_readRegister(BC_PERCTRL);
|
83 |
|
|
|
84 |
|
|
/* Disable peripheral */
|
85 |
|
|
tmp &= ~(bit);
|
86 |
|
|
|
87 |
|
|
/* Special case for RS232, if enabled disable shutdown */
|
88 |
|
|
if ((peri == DVK_RS232A) || (peri == DVK_RS232B))
|
89 |
|
|
{
|
90 |
|
|
/* Set shutdown bit */
|
91 |
|
|
tmp |= (BC_PERCTRL_RS232_SHUTDOWN);
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
/* Special case for IRDA */
|
95 |
|
|
if (peri == DVK_IRDA)
|
96 |
|
|
{
|
97 |
|
|
/* Set shutdown bit */
|
98 |
|
|
tmp |= (BC_PERCTRL_IRDA_SHUTDOWN);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
DVK_writeRegister(BC_PERCTRL, tmp);
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
/**************************************************************************//**
|
107 |
|
|
* @brief Enable BUS access
|
108 |
|
|
*****************************************************************************/
|
109 |
|
|
void DVK_enableBus(void)
|
110 |
|
|
{
|
111 |
|
|
/* Enable bus access */
|
112 |
|
|
DVK_writeRegister(BC_BUS_CFG, 1);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
/**************************************************************************//**
|
117 |
|
|
* @brief Disable BUS access
|
118 |
|
|
*****************************************************************************/
|
119 |
|
|
void DVK_disableBus(void)
|
120 |
|
|
{
|
121 |
|
|
DVK_writeRegister(BC_BUS_CFG, 0);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
/**************************************************************************//**
|
126 |
|
|
* @brief Inform AEM about current energy mode
|
127 |
|
|
* @param energyMode What energy mode we are going to use next
|
128 |
|
|
*****************************************************************************/
|
129 |
|
|
void DVK_setEnergyMode(uint16_t energyMode)
|
130 |
|
|
{
|
131 |
|
|
DVK_writeRegister(BC_EM, energyMode);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
/**************************************************************************//**
|
136 |
|
|
* @brief Get status of bush buttons
|
137 |
|
|
* @return Status of push buttons
|
138 |
|
|
*****************************************************************************/
|
139 |
|
|
uint16_t DVK_getPushButtons(void)
|
140 |
|
|
{
|
141 |
|
|
uint16_t tmp;
|
142 |
|
|
|
143 |
|
|
tmp = (~(DVK_readRegister(BC_PUSHBUTTON))) & 0x000f;
|
144 |
|
|
return tmp;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/**************************************************************************//**
|
148 |
|
|
* @brief Get joystick button status
|
149 |
|
|
* @return Joystick controller status
|
150 |
|
|
*****************************************************************************/
|
151 |
|
|
uint16_t DVK_getJoystick(void)
|
152 |
|
|
{
|
153 |
|
|
uint16_t tmp;
|
154 |
|
|
|
155 |
|
|
tmp = (~(DVK_readRegister(BC_JOYSTICK))) & 0x001f;
|
156 |
|
|
return tmp;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
/**************************************************************************//**
|
160 |
|
|
* @brief Get dipswitch status
|
161 |
|
|
* The DIP switches are free for user programmable purposes
|
162 |
|
|
* @return Joystick controller status
|
163 |
|
|
*****************************************************************************/
|
164 |
|
|
uint16_t DVK_getDipSwitch(void)
|
165 |
|
|
{
|
166 |
|
|
uint16_t tmp;
|
167 |
|
|
|
168 |
|
|
tmp = (~(DVK_readRegister(BC_DIPSWITCH))) & 0x00ff;
|
169 |
|
|
return tmp;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
/**************************************************************************//**
|
173 |
|
|
* @brief Sets user leds
|
174 |
|
|
* @param leds 16-bits which enables or disables the board "User leds"
|
175 |
|
|
*****************************************************************************/
|
176 |
|
|
void DVK_setLEDs(uint16_t leds)
|
177 |
|
|
{
|
178 |
|
|
DVK_writeRegister(BC_LED, leds);
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
/**************************************************************************//**
|
182 |
|
|
* @brief Get status of user LEDs
|
183 |
|
|
* @return Status of 16 user leds, bit 1 = on, bit 0 = off
|
184 |
|
|
*****************************************************************************/
|
185 |
|
|
uint16_t DVK_getLEDs(void)
|
186 |
|
|
{
|
187 |
|
|
return DVK_readRegister(BC_LED);
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
/**************************************************************************//**
|
191 |
|
|
* @brief Enable "Control" buttons/joystick/dip switch interrupts
|
192 |
|
|
* @param flags Board control interrupt flags, BC_INTEN_<something>
|
193 |
|
|
*****************************************************************************/
|
194 |
|
|
void DVK_enableInterrupt(uint16_t flags)
|
195 |
|
|
{
|
196 |
|
|
uint16_t tmp;
|
197 |
|
|
|
198 |
|
|
/* Add flags to interrupt enable register */
|
199 |
|
|
tmp = DVK_readRegister(BC_INTEN);
|
200 |
|
|
tmp |= flags;
|
201 |
|
|
DVK_writeRegister(BC_INTEN, tmp);
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
/**************************************************************************//**
|
205 |
|
|
* @brief Disable "Control" buttons/joystick/dip switch interrupts
|
206 |
|
|
* @param flags Board control interrupt flags, BC_INTEN_<something>
|
207 |
|
|
*****************************************************************************/
|
208 |
|
|
void DVK_disableInterrupt(uint16_t flags)
|
209 |
|
|
{
|
210 |
|
|
uint16_t tmp;
|
211 |
|
|
|
212 |
|
|
/* Clear flags from interrupt enable register */
|
213 |
|
|
tmp = DVK_readRegister(BC_INTEN);
|
214 |
|
|
flags = ~(flags);
|
215 |
|
|
tmp &= flags;
|
216 |
|
|
DVK_writeRegister(BC_INTEN, tmp);
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
/**************************************************************************//**
|
220 |
|
|
* @brief Clear interrupts
|
221 |
|
|
* @param flags Board control interrupt flags, BC_INTEN_<something>
|
222 |
|
|
*****************************************************************************/
|
223 |
|
|
void DVK_clearInterruptFlags(uint16_t flags)
|
224 |
|
|
{
|
225 |
|
|
DVK_writeRegister(BC_INTFLAG, flags);
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
/**************************************************************************//**
|
229 |
|
|
* @brief Read interrupt flags
|
230 |
|
|
* @return Returns currently triggered interrupts
|
231 |
|
|
*****************************************************************************/
|
232 |
|
|
uint16_t DVK_getInterruptFlags(void)
|
233 |
|
|
{
|
234 |
|
|
return DVK_readRegister(BC_INTFLAG);
|
235 |
|
|
}
|