ISSDK  1.7
IoT Sensing Software Development Kit
frdm_ke15z.c
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2017, Freescale Semiconductor, Inc.
4  * Copyright 2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /**
36  * @file frdm_ke15z.c
37  * @brief The frdm_ke15z.c file defines GPIO pins and I2C CMSIS utilities for FRDM-KE15Z board.
38  */
39 
40 #include "fsl_gpio.h"
41 #include "fsl_port.h"
42 #include "frdm_ke15z.h"
43 
44 // I2C1 Pin Handles
46  .portBase = PORTD,
47  .pinNumber = 9,
48  .mask = 1 << (9),
49  .irq = PORTBCD_IRQn,
50  .clockName = kCLOCK_PortD,
51  .portNumber = PORTD_NUM};
53  .portBase = PORTD,
54  .pinNumber = 8,
55  .mask = 1 << (8),
56  .irq = PORTBCD_IRQn,
57  .clockName = kCLOCK_PortD,
58  .portNumber = PORTD_NUM};
59 
60 // I2C0 Handle
61 gpioHandleKSDK_t A5 = {.base = GPIOA,
62  .portBase = PORTA,
63  .pinNumber = 3,
64  .mask = 1 << (3),
65  .irq = PORTAE_IRQn,
66  .clockName = kCLOCK_PortA,
67  .portNumber = PORTA_NUM};
68 gpioHandleKSDK_t A4 = {.base = GPIOA,
69  .portBase = PORTA,
70  .pinNumber = 2,
71  .mask = 1 << (2),
72  .irq = PORTAE_IRQn,
73  .clockName = kCLOCK_PortA,
74  .portNumber = PORTA_NUM};
75 
76 // SPI0 Handle
78  .portBase = PORTE,
79  .pinNumber = 0,
80  .mask = 1 << (0),
81  .irq = PORTAE_IRQn,
82  .clockName = kCLOCK_PortE,
83  .portNumber = PORTE_NUM};
85  .portBase = PORTE,
86  .pinNumber = 1,
87  .mask = 1 << (1),
88  .irq = PORTAE_IRQn,
89  .clockName = kCLOCK_PortE,
90  .portNumber = PORTE_NUM};
92  .portBase = PORTE,
93  .pinNumber = 2,
94  .mask = 1 << (2),
95  .irq = PORTAE_IRQn,
96  .clockName = kCLOCK_PortE,
97  .portNumber = PORTE_NUM};
98 
99 
100 // UART0 Handle
102  .portBase = PORTC,
103  .pinNumber = 8,
104  .mask = 1 << (8),
105  .irq = PORTBCD_IRQn,
106  .clockName = kCLOCK_PortC,
107  .portNumber = PORTC_NUM};
109  .portBase = PORTC,
110  .pinNumber = 9,
111  .mask = 1 << (9),
112  .irq = PORTBCD_IRQn,
113  .clockName = kCLOCK_PortC,
114  .portNumber = PORTC_NUM};
115 
116 // FRDM-KE15Z Arduino Connector Pin Defintion
118  .portBase = PORTA,
119  .pinNumber = 0,
120  .mask = 1 << (0),
121  .irq = PORTAE_IRQn,
122  .clockName = kCLOCK_PortA,
123  .portNumber = PORTA_NUM};
125  .portBase = PORTA,
126  .pinNumber = 1,
127  .mask = 1 << (1),
128  .irq = PORTAE_IRQn,
129  .clockName = kCLOCK_PortA,
130  .portNumber = PORTA_NUM};
132  .portBase = PORTA,
133  .pinNumber = 6,
134  .mask = 1 << (6),
135  .irq = PORTAE_IRQn,
136  .clockName = kCLOCK_PortA,
137  .portNumber = PORTA_NUM};
139  .portBase = PORTA,
140  .pinNumber = 7,
141  .mask = 1 << (7),
142  .irq = PORTAE_IRQn,
143  .clockName = kCLOCK_PortA,
144  .portNumber = PORTA_NUM};
146  .portBase = PORTD,
147  .pinNumber = 12,
148  .mask = 1 << (12),
149  .irq = PORTBCD_IRQn,
150  .clockName = kCLOCK_PortD,
151  .portNumber = PORTD_NUM};
153  .portBase = PORTC,
154  .pinNumber = 15,
155  .mask = 1 << (15),
156  .irq = PORTBCD_IRQn,
157  .clockName = kCLOCK_PortC,
158  .portNumber = PORTC_NUM};
160  .portBase = PORTE,
161  .pinNumber = 9,
162  .mask = 1 << (9),
163  .irq = PORTAE_IRQn,
164  .clockName = kCLOCK_PortE,
165  .portNumber = PORTE_NUM};
167  .portBase = PORTC,
168  .pinNumber = 5,
169  .mask = 1 << (5),
170  .irq = PORTBCD_IRQn,
171  .clockName = kCLOCK_PortC,
172  .portNumber = PORTC_NUM};
174  .portBase = PORTA,
175  .pinNumber = 16,
176  .mask = 1 << (16),
177  .irq = PORTAE_IRQn,
178  .clockName = kCLOCK_PortA,
179  .portNumber = PORTA_NUM};
181  .portBase = PORTA,
182  .pinNumber = 17,
183  .mask = 1 << (17),
184  .irq = PORTAE_IRQn,
185  .clockName = kCLOCK_PortA,
186  .portNumber = PORTA_NUM};
188  .portBase = PORTE,
189  .pinNumber = 8,
190  .mask = 1 << (8),
191  .irq = PORTAE_IRQn,
192  .clockName = kCLOCK_PortE,
193  .portNumber = PORTE_NUM};
195  .portBase = PORTE,
196  .pinNumber = 7,
197  .mask = 1 << (7),
198  .irq = PORTAE_IRQn,
199  .clockName = kCLOCK_PortE,
200  .portNumber = PORTE_NUM};
202  .portBase = PORTA,
203  .pinNumber = 15,
204  .mask = 1 << (15),
205  .irq = PORTAE_IRQn,
206  .clockName = kCLOCK_PortA,
207  .portNumber = PORTA_NUM};
208 
209 // FRDM-KE15Z Internal Peripheral Pin Definitions
211  .portBase = PORTD,
212  .pinNumber = 0,
213  .mask = 1 << (0),
214  .irq = PORTBCD_IRQn,
215  .clockName = kCLOCK_PortD,
216  .portNumber = PORTD_NUM};
218  .portBase = PORTD,
219  .pinNumber = 16,
220  .mask = 1 << (16),
221  .irq = PORTBCD_IRQn,
222  .clockName = kCLOCK_PortD,
223  .portNumber = PORTD_NUM};
225  .portBase = PORTD,
226  .pinNumber = 15,
227  .mask = 1 << (15),
228  .irq = PORTBCD_IRQn,
229  .clockName = kCLOCK_PortD,
230  .portNumber = PORTD_NUM};
231 
232 // FRDM-KE15Z I2C Inertial Sensor Pin Definitions
234  .portBase = PORTB,
235  .pinNumber = 10,
236  .mask = 1 << (10),
237  .irq = PORTBCD_IRQn,
238  .clockName = kCLOCK_PortB,
239  .portNumber = PORTB_NUM};
241  .portBase = PORTB,
242  .pinNumber = 9,
243  .mask = 1 << (9),
244  .irq = PORTBCD_IRQn,
245  .clockName = kCLOCK_PortB,
246  .portNumber = PORTB_NUM};
247 
248 /*! @brief Determines the Clock Frequency feature.
249  * @details The Clock Frequecny computation API required by fsl_uart_cmsis.c.
250  * @param[in] void
251  * @Constraints None
252  * @Reentrant Yes
253  * @return uint32_t Returns the clock frequency .
254  */
255 uint32_t LPUART0_GetFreq(void)
256 {
257  CLOCK_SetIpSrc(kCLOCK_Lpuart0, kCLOCK_IpSrcSircAsync);
258  return CLOCK_GetIpFreq(kCLOCK_Lpuart0);
259 }
260 
261 /*! @brief Determines the Clock Frequency feature.
262  * @details The Clock Frequecny computation API required by fsl_uart_cmsis.c.
263  * @param[in] void
264  * @Constraints None
265  * @Reentrant Yes
266  * @return uint32_t Returns the clock frequency .
267  */
268 uint32_t LPUART1_GetFreq(void)
269 {
270  CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcSircAsync);
271  return CLOCK_GetIpFreq(kCLOCK_Lpuart1);
272 }
273 
274 /*! @brief Determines the Clock Frequency feature.
275  * @details The Clock Frequecny computation API required by fsl_uart_cmsis.c.
276  * @param[in] void
277  * @Constraints None
278  * @Reentrant Yes
279  * @return uint32_t Returns the clock frequency .
280  */
281 uint32_t LPUART2_GetFreq(void)
282 {
283  CLOCK_SetIpSrc(kCLOCK_Lpuart2, kCLOCK_IpSrcSircAsync);
284  return CLOCK_GetIpFreq(kCLOCK_Lpuart2);
285 }
286 
287 /*! @brief Determines the Clock Frequency feature.
288  * @details The Clock Frequecny computation API required by fsl_i2c_cmsis.c.
289  * @param[in] void
290  * @Constraints None
291  * @Reentrant Yes
292  * @return uint32_t Returns the clock frequency .
293  */
294 uint32_t LPI2C0_GetFreq(void)
295 {
296  CLOCK_SetIpSrc(kCLOCK_Lpi2c0, kCLOCK_IpSrcFircAsync);
297  return CLOCK_GetIpFreq(kCLOCK_Lpi2c0);
298 }
299 
300 /*! @brief Determines the Clock Frequency feature.
301  * @details The Clock Frequecny computation API required by fsl_i2c_cmsis.c.
302  * @param[in] void
303  * @Constraints None
304  * @Reentrant Yes
305  * @return uint32_t Returns the clock frequency .
306  */
307 uint32_t LPI2C1_GetFreq(void)
308 {
309  CLOCK_SetIpSrc(kCLOCK_Lpi2c1, kCLOCK_IpSrcFircAsync);
310  return CLOCK_GetIpFreq(kCLOCK_Lpi2c1);
311 }
312 
313 /*! @brief Determines the Clock Frequency feature.
314  * @details The Clock Frequecny computation API required by fsl_spi_cmsis.c.
315  * @param[in] void
316  * @Constraints None
317  * @Reentrant Yes
318  * @return uint32_t Returns the clock frequency .
319  */
320 uint32_t LPSPI0_GetFreq(void)
321 {
322  CLOCK_SetIpSrc(kCLOCK_Lpspi0, kCLOCK_IpSrcFircAsync);
323  return CLOCK_GetIpFreq(kCLOCK_Lpspi0);
324 }
325 
326 /*! @brief Determines the Clock Frequency feature.
327  * @details The Clock Frequecny computation API required by fsl_spi_cmsis.c.
328  * @param[in] void
329  * @Constraints None
330  * @Reentrant Yes
331  * @return uint32_t Returns the clock frequency .
332  */
333 uint32_t LPSPI1_GetFreq(void)
334 {
335  CLOCK_SetIpSrc(kCLOCK_Lpspi1, kCLOCK_IpSrcFircAsync);
336  return CLOCK_GetIpFreq(kCLOCK_Lpspi1);
337 }
338 
339 /*! @brief Reset the onboard FXOS8700.
340  * @details The API to Reset the onboard FXOS8700 after hardware reset to enable I2C communication.
341  * @param[in] void
342  * @Constraints None
343  * @Reentrant Yes
344  * @return void
345  */
347 {
348  uint32_t i;
349  gpio_pin_config_t pin_config;
350 
351  /* Enable Clock for Reset Port */
352  CLOCK_EnableClock(kCLOCK_PortB);
353  /* PORTB9 (pin 76) is configured as PTB9 */
354  PORT_SetPinMux(PORTB, 9, kPORT_MuxAsGpio);
355 
356  /* Reset sensor by reset pin*/
357  pin_config.pinDirection = kGPIO_DigitalOutput;
358  pin_config.outputLogic = 1;
359  GPIO_PinInit(GPIOB, 9, &pin_config);
360  GPIO_WritePinOutput(GPIOB, 9, 1);
361  /* Delay to ensure reliable sensor reset */
362  for (i = 0; i < SystemCoreClock / 1000U; i++)
363  {
364  __NOP();
365  }
366  GPIO_WritePinOutput(GPIOB, 9, 0);
367 
368  /* Delay to wait sensor stable after reset */
369  for (i = 0; i < SystemCoreClock / 1000U; i++)
370  {
371  __NOP();
372  }
373 }
uint32_t LPI2C1_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:307
uint32_t LPUART1_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:268
gpioHandleKSDK_t D8
Definition: frdm_ke15z.c:187
gpioHandleKSDK_t D11
Definition: frdm_ke15z.c:91
gpioHandleKSDK_t D0
Definition: frdm_ke15z.c:101
gpioHandleKSDK_t A2
Definition: frdm_ke15z.c:131
gpioHandleKSDK_t D14
Definition: frdm_ke15z.c:52
The GPIO pin handle for KSDK.
Definition: gpio_driver.h:75
gpioHandleKSDK_t RED_LED
Definition: frdm_ke15z.c:210
gpioHandleKSDK_t RST_A
Definition: frdm_ke15z.c:240
gpioHandleKSDK_t D4
Definition: frdm_ke15z.c:159
gpioHandleKSDK_t D13
Definition: frdm_ke15z.c:77
gpioHandleKSDK_t A5
Definition: frdm_ke15z.c:61
uint32_t LPSPI1_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:333
gpioHandleKSDK_t BLUE_LED
Definition: frdm_ke15z.c:224
uint32_t LPUART0_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:255
gpioHandleKSDK_t D7
Definition: frdm_ke15z.c:180
uint32_t LPI2C0_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:294
gpioHandleKSDK_t D15
Definition: frdm_ke15z.c:45
gpioHandleKSDK_t D10
Definition: frdm_ke15z.c:201
gpioHandleKSDK_t A0
Definition: frdm_ke15z.c:117
gpioHandleKSDK_t GREEN_LED
Definition: frdm_ke15z.c:217
uint32_t LPSPI0_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:320
gpioHandleKSDK_t INT1
Definition: frdm_ke15z.c:233
void BOARD_ACCEL_Reset(void)
Reset the onboard FXOS8700.
Definition: frdm_ke15z.c:346
gpioHandleKSDK_t D9
Definition: frdm_ke15z.c:194
The frdm_ke15z.h file defines GPIO pin mappings for FRDM-KE15Z board.
gpioHandleKSDK_t D1
Definition: frdm_ke15z.c:108
uint32_t SystemCoreClock
gpioHandleKSDK_t A1
Definition: frdm_ke15z.c:124
gpioHandleKSDK_t D5
Definition: frdm_ke15z.c:166
gpioHandleKSDK_t A3
Definition: frdm_ke15z.c:138
gpioHandleKSDK_t D12
Definition: frdm_ke15z.c:84
GPIO_Type * base
Definition: gpio_driver.h:77
gpioHandleKSDK_t D6
Definition: frdm_ke15z.c:173
gpioHandleKSDK_t D2
Definition: frdm_ke15z.c:145
gpioHandleKSDK_t A4
Definition: frdm_ke15z.c:68
gpioHandleKSDK_t D3
Definition: frdm_ke15z.c:152
uint32_t LPUART2_GetFreq(void)
Determines the Clock Frequency feature.
Definition: frdm_ke15z.c:281