1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /*! \file frdm_k22f.h
10     \brief The \b frdm_k22f.h file defines GPIO pins for FRDM-K22F board
11 */
12 
13 #ifndef FRDM_K22F_H_
14 #define FRDM_K22F_H_
15 
16 #include "pin_mux.h"
17 #include "fsl_smc.h"
18 #include "MK22F51212.h"
19 #include "RTE_Device.h"
20 #include "gpio_driver.h"
21 
22 // I2C0 Handle
23 extern gpioHandleKSDK_t A5;
24 extern gpioHandleKSDK_t A4;
25 
26 // SPI1 Handle
27 extern gpioHandleKSDK_t D13;
28 extern gpioHandleKSDK_t D11;
29 extern gpioHandleKSDK_t D12;
30 
31 // UART1 Handle
32 extern gpioHandleKSDK_t D14;
33 extern gpioHandleKSDK_t D15;
34 
35 // FRDM-K22F Arduino Connector Pin Defintion
36 extern gpioHandleKSDK_t A0;
37 extern gpioHandleKSDK_t A1;
38 extern gpioHandleKSDK_t A2;
39 extern gpioHandleKSDK_t A3;
40 extern gpioHandleKSDK_t D0;
41 extern gpioHandleKSDK_t D1;
42 extern gpioHandleKSDK_t D2;
43 extern gpioHandleKSDK_t D3;
44 extern gpioHandleKSDK_t D4;
45 extern gpioHandleKSDK_t D5;
46 extern gpioHandleKSDK_t D6;
47 extern gpioHandleKSDK_t D7;
48 extern gpioHandleKSDK_t D8;
49 extern gpioHandleKSDK_t D9;
50 extern gpioHandleKSDK_t D10;
51 
52 // FRDM-K22F RGB LED Pin Definitions
53 extern gpioHandleKSDK_t RED_LED;
54 extern gpioHandleKSDK_t GREEN_LED;
55 extern gpioHandleKSDK_t BLUE_LED;
56 extern gpioHandleKSDK_t INT1;
57 extern gpioHandleKSDK_t INT2;
58 
59 // I2C_S1: Pin mapping and driver information for default I2C brought to shield
60 #define I2C_S1_SCL_PIN A5
61 #define I2C_S1_SDA_PIN A4
62 #define I2C_S1_DRIVER Driver_I2C0
63 #define I2C_S1_DEVICE_INDEX I2C0_INDEX
64 #define I2C_S1_SIGNAL_EVENT I2C0_SignalEvent_t
65 
66 // I2C_S2: Pin mapping and driver information for alternate I2C bus on shield
67 // Note :  I2C1 cannot be used with UART1 (which is the TGT_MCU Debug UART).
68 #define I2C_S2_SCL_PIN D15
69 #define I2C_S2_SDA_PIN D14
70 #define I2C_S2_DRIVER Driver_I2C1
71 #define I2C_S2_DEVICE_INDEX I2C1_INDEX
72 #define I2C_S2_SIGNAL_EVENT I2C1_SignalEvent_t
73 
74 // I2C_BB: PPin mapping and driver information for I2C routed on K22F base board
75 #define I2C_BB_SCL_PIN A5
76 #define I2C_BB_SDA_PIN A4
77 #define I2C_BB_DRIVER Driver_I2C0
78 #define I2C_BB_DEVICE_INDEX I2C0_INDEX
79 #define I2C_BB_SIGNAL_EVENT I2C0_SignalEvent_t
80 
81 // SPIS: Pin mapping and driver information default SPI brought to shield
82 #define SPI_S_SCLK D13
83 #define SPI_S_MOSI D11
84 #define SPI_S_MISO D12
85 #define SPI_S_DRIVER Driver_SPI1
86 #define SPI_S_BAUDRATE 500000U ///< Transfer baudrate - 500k
87 #define SPI_S_DEVICE_INDEX SPI1_INDEX
88 #define SPI_S_SIGNAL_EVENT SPI1_SignalEvent_t
89 
90 // UART: Driver information for default UART to communicate with HOST PC.
91 #define HOST_S_DRIVER Driver_USART1
92 #define HOST_S_SIGNAL_EVENT HOST_SignalEvent_t
93 
94 // Bluetooth: Driver information for default UART to communicate with HOST PC.
95 #define HOST_B_DRIVER Driver_USART2
96 #define HOST_B_SIGNAL_EVENT HOST_SignalEvent_t
97 
98 // On-Board FXOS8700 Sensor Information
99 #define FXOS8700_BB_I2C_ADDR 0x1C
100 #define FXOS8700_BB_INT1 INT1
101 #define FXOS8700_BB_INT2 INT2
102 
103 /* @brief  Ask use input to resume after specified samples have been processed. */
104 #define ASK_USER_TO_RESUME(x)                                                          \
105     static volatile bool askResume = true;                                             \
106     static uint16_t samplesToProcess = x - 1;                                          \
107     if (askResume && !samplesToProcess--)                                              \
108     {                                                                                  \
109         PRINTF("\r\n Specified samples processed, press any key to continue... \r\n"); \
110         GETCHAR();                                                                     \
111         askResume = false;                                                             \
112     }
113 
114 /// @name Wired UART Parameters
115 /// Sensor Fusion aliases are defined in terms of specific hardware features
116 /// defined in MK22F51212.h.
117 ///@{
118 #define WIRED_UART UART1                             ///< KSDK instance name for the debug UART
119 #define WIRED_UART_PORT_CLKEN kCLOCK_PortE           ///< KDSK handle for the pin port clock enable
120 #define WIRED_UART_PORT PORTE                        ///< KDSK handle for the pin port associated with this UART
121 #define WIRED_UART_RX_PIN 1U                         ///< The port number associated with RX
122 #define WIRED_UART_TX_PIN 0U                         ///< The port number associated with TX
123 #define WIRED_UART_MUX kPORT_MuxAlt3                 ///< KDSK pin mux selector
124 #ifndef USE_ORIENT_APP_CONTROL                       ///< If Using Orient App then use Host I/O
125 #define WIRED_UART_IRQHandler UART1_RX_TX_IRQHandler ///< KDSK-specified IRQ handler name
126 #endif
127 #define WIRED_UART_IRQn UART1_RX_TX_IRQn ///< The interrupt number associated with this IRQ
128 #define WIRED_UART_CLKSRC UART1_CLK_SRC  ///< KSDK instance name for the clock feeding this module
129 #define WIRED_UART_IRQn UART1_RX_TX_IRQn ///< KSDK interrupt vector number
130 ///@}
131 
132 /// @name Wireless UART Parameters
133 /// Sensor Fusion aliases are defined in terms of specific hardware features
134 /// defined in MK22F51212.h.
135 ///@{
136 #define WIRELESS_UART UART2                             ///< KSDK instance name for the debug UART
137 #define WIRELESS_UART_PORT_CLKEN kCLOCK_PortD           ///< KDSK handle for the pin port clock enable
138 #define WIRELESS_UART_PORT PORTD                        ///< KDSK handle for the pin port associated with this UART
139 #define WIRELESS_UART_RX_PIN 2U                         ///< The port number associated with RX
140 #define WIRELESS_UART_TX_PIN 3U                         ///< The port number associated with TX
141 #define WIRELESS_UART_MUX kPORT_MuxAlt3                 ///< KDSK pin mux selector
142 #define WIRELESS_UART_IRQHandler UART2_RX_TX_IRQHandler ///< KDSK-specified IRQ handler name
143 #define WIRELESS_UART_IRQn UART2_RX_TX_IRQn             ///< The interrupt number associated with this IRQ
144 #define WIRELESS_UART_CLKSRC UART2_CLK_SRC              ///< KSDK instance name for the clock feeding this module
145 #define WIRELESS_UART_IRQn UART2_RX_TX_IRQn             ///< KSDK interrupt vector number
146 ///@}
147 
148 ///@name Miscellaneous Hardware Configuration Parameters
149 ///@{
150 #define THIS_BOARD 9                    ///< FRDM_K22F
151 #define CORE_SYSTICK_HZ 80000000        ///< core and systick clock rate (Hz)
152 #define CALIBRATION_NVM_ADDR 0x0007F800 ///< start of final 2K (sector size) of 512K flash
153 #define ADS_NVM_ADDR 0x0007F000         ///< start of the next to last 2K (sector size) of the 512K flash
154 #define FLASH_SECTOR_SIZE_PROPERTY kFLASH_PropertyPflashSectorSize
155 #define FLASH_ERASE_KEY kFLASH_ApiEraseKey
156 
157 // offsets from start of NVM block for calibration coefficients
158 #define MAG_NVM_OFFSET 0     // 68 bytes used
159 #define GYRO_NVM_OFFSET 100  // 16 bytes used
160 #define ACCEL_NVM_OFFSET 140 // 88 bytes used
161 ///@}
162 
163 #endif /* FRDM_K22F_H_ */
164