2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __FSL_PORT_HAL_H__
31 #define __FSL_PORT_HAL_H__
36 #include "fsl_port_features.h"
37 #include "fsl_device_registers.h"
40 * @addtogroup port_hal
44 /*******************************************************************************
46 ******************************************************************************/
47 /*! @brief Internal resistor pull feature selection*/
48 typedef enum _port_pull
{
49 kPortPullDown
= 0U, /*!< internal pull-down resistor is enabled.*/
50 kPortPullUp
= 1U /*!< internal pull-up resistor is enabled.*/
53 /*! @brief Slew rate selection*/
54 typedef enum _port_slew_rate
{
55 kPortFastSlewRate
= 0U, /*!< fast slew rate is configured.*/
56 kPortSlowSlewRate
= 1U /*!< slow slew rate is configured.*/
59 /*! @brief Configures the drive strength.*/
60 typedef enum _port_drive_strength
{
61 kPortLowDriveStrength
= 0U, /*!< low drive strength is configured.*/
62 kPortHighDriveStrength
= 1U /*!< high drive strength is configured.*/
63 } port_drive_strength_t
;
65 /*! @brief Pin mux selection*/
66 typedef enum _port_mux
{
67 kPortPinDisabled
= 0U, /*!< corresponding pin is disabled as analog.*/
68 kPortMuxAsGpio
= 1U, /*!< corresponding pin is configured as GPIO.*/
69 kPortMuxAlt2
= 2U, /*!< chip-specific*/
70 kPortMuxAlt3
= 3U, /*!< chip-specific*/
71 kPortMuxAlt4
= 4U, /*!< chip-specific*/
72 kPortMuxAlt5
= 5U, /*!< chip-specific*/
73 kPortMuxAlt6
= 6U, /*!< chip-specific*/
74 kPortMuxAlt7
= 7U /*!< chip-specific*/
77 /*! @brief Digital filter clock source selection*/
78 #if FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
79 typedef enum _port_digital_filter_clock_source
{
80 kPortBusClock
= 0U, /*!< Digital filters are clocked by the bus clock.*/
81 kPortLPOClock
= 1U /*!< Digital filters are clocked by the 1 kHz LPO clock.*/
82 } port_digital_filter_clock_source_t
;
85 /*! @brief Configures the interrupt generation condition.*/
86 typedef enum _port_interrupt_config
{
87 kPortIntDisabled
= 0x0U
, /*!< Interrupt/DMA request is disabled.*/
88 kPortDmaRisingEdge
= 0x1U
, /*!< DMA request on rising edge.*/
89 kPortDmaFallingEdge
= 0x2U
, /*!< DMA request on falling edge.*/
90 kPortDmaEitherEdge
= 0x3U
, /*!< DMA request on either edge.*/
91 kPortIntLogicZero
= 0x8U
, /*!< Interrupt when logic zero. */
92 kPortIntRisingEdge
= 0x9U
, /*!< Interrupt on rising edge. */
93 kPortIntFallingEdge
= 0xAU
, /*!< Interrupt on falling edge. */
94 kPortIntEitherEdge
= 0xBU
, /*!< Interrupt on either edge. */
95 kPortIntLogicOne
= 0xCU
/*!< Interrupt when logic one. */
96 } port_interrupt_config_t
;
98 /*******************************************************************************
100 ******************************************************************************/
102 #if defined(__cplusplus)
107 * @name Configuration
112 * @brief Selects the internal resistor as pull-down or pull-up.
114 * Pull configuration is valid in all digital pin muxing modes.
116 * @param baseAddr port base address.
117 * @param pin port pin number
118 * @param pullSelect internal resistor pull feature selection
119 * - kPortPullDown: internal pull-down resistor is enabled.
120 * - kPortPullUp : internal pull-up resistor is enabled.
122 static inline void PORT_HAL_SetPullMode(uint32_t baseAddr
,
124 port_pull_t pullSelect
)
127 BW_PORT_PCRn_PS(baseAddr
, pin
, pullSelect
);
131 * @brief Enables or disables the internal pull resistor.
133 * @param baseAddr port base address
134 * @param pin port pin number
135 * @param isPullEnabled internal pull resistor enable or disable
136 * - true : internal pull resistor is enabled.
137 * - false: internal pull resistor is disabled.
139 static inline void PORT_HAL_SetPullCmd(uint32_t baseAddr
, uint32_t pin
, bool isPullEnabled
)
142 BW_PORT_PCRn_PE(baseAddr
, pin
, isPullEnabled
);
146 * @brief Configures the fast/slow slew rate if the pin is used as a digital output.
148 * @param baseAddr port base address
149 * @param pin port pin number
150 * @param rateSelect slew rate selection
151 * - kPortFastSlewRate: fast slew rate is configured.
152 * - kPortSlowSlewRate: slow slew rate is configured.
154 static inline void PORT_HAL_SetSlewRateMode(uint32_t baseAddr
,
156 port_slew_rate_t rateSelect
)
159 BW_PORT_PCRn_SRE(baseAddr
, pin
, rateSelect
);
163 * @brief Configures the passive filter if the pin is used as a digital input.
165 * If enabled, a low pass filter (10 MHz to 30 MHz bandwidth) is enabled
166 * on the digital input path. Disable the Passive Input Filter when supporting
167 * high speed interfaces (> 2 MHz) on the pin.
169 * @param baseAddr port base address
170 * @param pin port pin number
171 * @param isPassiveFilterEnabled passive filter configuration
172 * - false: passive filter is disabled.
173 * - true : passive filter is enabled.
175 static inline void PORT_HAL_SetPassiveFilterCmd(uint32_t baseAddr
,
177 bool isPassiveFilterEnabled
)
180 BW_PORT_PCRn_PFE(baseAddr
, pin
, isPassiveFilterEnabled
);
183 #if FSL_FEATURE_PORT_HAS_OPEN_DRAIN
185 * @brief Enables or disables the open drain.
187 * @param baseAddr port base address
188 * @param pin port pin number
189 * @param isOpenDrainEnabled enable open drain or not
190 * - false: Open Drain output is disabled on the corresponding pin.
191 * - true : Open Drain output is disabled on the corresponding pin.
193 static inline void PORT_HAL_SetOpenDrainCmd(uint32_t baseAddr
,
195 bool isOpenDrainEnabled
)
198 BW_PORT_PCRn_ODE(baseAddr
, pin
, isOpenDrainEnabled
);
200 #endif /*FSL_FEATURE_PORT_HAS_OPEN_DRAIN*/
203 * @brief Configures the drive strength if the pin is used as a digital output.
205 * @param baseAddr port base address
206 * @param pin port pin number
207 * @param driveSelect drive strength selection
208 * - kLowDriveStrength : low drive strength is configured.
209 * - kHighDriveStrength: high drive strength is configured.
211 static inline void PORT_HAL_SetDriveStrengthMode(uint32_t baseAddr
,
213 port_drive_strength_t driveSelect
)
216 BW_PORT_PCRn_DSE(baseAddr
, pin
, driveSelect
);
220 * @brief Configures the pin muxing.
222 * @param baseAddr port base address
223 * @param pin port pin number
224 * @param mux pin muxing slot selection
225 * - kPinDisabled: Pin disabled.
226 * - kMuxAsGpio : Set as GPIO.
227 * - others : chip-specific.
229 static inline void PORT_HAL_SetMuxMode(uint32_t baseAddr
, uint32_t pin
, port_mux_t mux
)
232 BW_PORT_PCRn_MUX(baseAddr
, pin
, mux
);
235 #if FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
237 * @brief Locks or unlocks the pin control register bits[15:0].
239 * @param baseAddr port base address
240 * @param pin port pin number
241 * @param isPinLockEnabled lock pin control register or not
242 * - false: pin control register bit[15:0] are not locked.
243 * - true : pin control register bit[15:0] are locked, cannot be updated till system reset.
245 static inline void PORT_HAL_SetPinCtrlLockCmd(uint32_t baseAddr
,
247 bool isPinLockEnabled
)
250 BW_PORT_PCRn_LK(baseAddr
, pin
, isPinLockEnabled
);
252 #endif /* FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK*/
254 #if FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
256 * @brief Enables or disables the digital filter in one single port.
257 * Each bit of the 32-bit register represents one pin.
259 * @param baseAddr port base address
260 * @param pin port pin number
261 * @param isDigitalFilterEnabled digital filter enable/disable
262 * - false: digital filter is disabled on the corresponding pin.
263 * - true : digital filter is enabled on the corresponding pin.
265 static inline void PORT_HAL_SetDigitalFilterCmd(uint32_t baseAddr
,
267 bool isDigitalFilterEnabled
)
270 HW_PORT_DFER_SET(baseAddr
, (uint32_t)isDigitalFilterEnabled
<< pin
);
274 * @brief Configures the clock source for the digital input filters. Changing the filter clock source should
275 * only be done after disabling all enabled filters. Every pin in one port uses the same
278 * @param baseAddr port base address
279 * @param clockSource chose which clock source to use for current port
280 * - kBusClock: digital filters are clocked by the bus clock.
281 * - kLPOClock: digital filters are clocked by the 1 kHz LPO clock.
283 static inline void PORT_HAL_SetDigitalFilterClock(uint32_t baseAddr
,
284 port_digital_filter_clock_source_t clockSource
)
286 HW_PORT_DFCR_WR(baseAddr
, clockSource
);
290 * @brief Configures the maximum size of the glitches (in clock cycles) that the digital filter absorbs
291 * for enabled digital filters. Glitches that are longer than this register setting
292 * (in clock cycles) pass through the digital filter, while glitches that are equal
293 * to or less than this register setting (in clock cycles) are filtered. Changing the
294 * filter length should only be done after disabling all enabled filters.
296 * @param baseAddr port base address
297 * @param width configure digital filter width (should be less than 5 bits).
299 static inline void PORT_HAL_SetDigitalFilterWidth(uint32_t baseAddr
, uint8_t width
)
301 HW_PORT_DFWR_WR(baseAddr
, width
);
303 #endif /* FSL_FEATURE_PORT_HAS_DIGITAL_FILTER*/
306 * @brief Configures the low half of the pin control register for the same settings.
307 * This function operates pin 0 -15 of one specific port.
309 * @param baseAddr port base address
310 * @param lowPinSelect update corresponding pin control register or not. For a specific bit:
311 * - 0: corresponding low half of pin control register won't be updated according to configuration.
312 * - 1: corresponding low half of pin control register will be updated according to configuration.
313 * @param config value is written to a low half port control register bits[15:0].
315 void PORT_HAL_SetLowGlobalPinCtrl(uint32_t baseAddr
, uint16_t lowPinSelect
, uint16_t config
);
318 * @brief Configures the high half of pin control register for the same settings.
319 * This function operates pin 16 -31 of one specific port.
321 * @param baseAddr port base address
322 * @param highPinSelect update corresponding pin control register or not. For a specific bit:
323 * - 0: corresponding high half of pin control register won't be updated according to configuration.
324 * - 1: corresponding high half of pin control register will be updated according to configuration.
325 * @param config value is written to a high half port control register bits[15:0].
327 void PORT_HAL_SetHighGlobalPinCtrl(uint32_t baseAddr
, uint16_t highPinSelect
, uint16_t config
);
337 * @brief Configures the port pin interrupt/DMA request.
339 * @param baseAddr port base address.
340 * @param pin port pin number
341 * @param intConfig interrupt configuration
342 * - kIntDisabled : Interrupt/DMA request disabled.
343 * - kDmaRisingEdge : DMA request on rising edge.
344 * - kDmaFallingEdge: DMA request on falling edge.
345 * - kDmaEitherEdge : DMA request on either edge.
346 * - KIntLogicZero : Interrupt when logic zero.
347 * - KIntRisingEdge : Interrupt on rising edge.
348 * - KIntFallingEdge: Interrupt on falling edge.
349 * - KIntEitherEdge : Interrupt on either edge.
350 * - KIntLogicOne : Interrupt when logic one.
352 static inline void PORT_HAL_SetPinIntMode(uint32_t baseAddr
,
354 port_interrupt_config_t intConfig
)
357 BW_PORT_PCRn_IRQC(baseAddr
, pin
, intConfig
);
361 * @brief Gets the current port pin interrupt/DMA request configuration.
363 * @param baseAddr port base address
364 * @param pin port pin number
365 * @return interrupt configuration
366 * - kIntDisabled : Interrupt/DMA request disabled.
367 * - kDmaRisingEdge : DMA request on rising edge.
368 * - kDmaFallingEdge: DMA request on falling edge.
369 * - kDmaEitherEdge : DMA request on either edge.
370 * - KIntLogicZero : Interrupt when logic zero.
371 * - KIntRisingEdge : Interrupt on rising edge.
372 * - KIntFallingEdge: Interrupt on falling edge.
373 * - KIntEitherEdge : Interrupt on either edge.
374 * - KIntLogicOne : Interrupt when logic one.
376 static inline port_interrupt_config_t
PORT_HAL_GetPinIntMode(uint32_t baseAddr
, uint32_t pin
)
379 return (port_interrupt_config_t
)BR_PORT_PCRn_IRQC(baseAddr
, pin
);
383 * @brief Reads the individual pin-interrupt status flag.
385 * If a pin is configured to generate the DMA request, the corresponding flag
386 * is cleared automatically at the completion of the requested DMA transfer.
387 * Otherwise, the flag remains set until a logic one is written to that flag.
388 * If configured for a level sensitive interrupt that remains asserted, the flag
389 * is set again immediately.
391 * @param baseAddr port base address
392 * @param pin port pin number
393 * @return current pin interrupt status flag
394 * - 0: interrupt is not detected.
395 * - 1: interrupt is detected.
397 static inline bool PORT_HAL_IsPinIntPending(uint32_t baseAddr
, uint32_t pin
)
400 return BR_PORT_PCRn_ISF(baseAddr
, pin
);
404 * @brief Clears the individual pin-interrupt status flag.
406 * @param baseAddr port base address
407 * @param pin port pin number
409 static inline void PORT_HAL_ClearPinIntFlag(uint32_t baseAddr
, uint32_t pin
)
412 BW_PORT_PCRn_ISF(baseAddr
, pin
, 1U);
416 * @brief Reads the entire port interrupt status flag.
418 * @param baseAddr port base address
419 * @return all 32 pin interrupt status flags. For specific bit:
420 * - 0: interrupt is not detected.
421 * - 1: interrupt is detected.
423 static inline uint32_t PORT_HAL_GetPortIntFlag(uint32_t baseAddr
)
425 return HW_PORT_ISFR_RD(baseAddr
);
429 * @brief Clears the entire port interrupt status flag.
431 * @param baseAddr port base address
433 static inline void PORT_HAL_ClearPortIntFlag(uint32_t baseAddr
)
435 HW_PORT_ISFR_WR(baseAddr
, ~0U);
440 #if defined(__cplusplus)
446 #endif /* __FSL_PORT_HAL_H__*/
447 /*******************************************************************************
449 ******************************************************************************/