123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- #ifndef _FSL_PORT_H_
- #define _FSL_PORT_H_
- #include "fsl_common.h"
- #ifndef FSL_COMPONENT_ID
- #define FSL_COMPONENT_ID "platform.drivers.port"
- #endif
- #define FSL_PORT_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
- #if defined(FSL_FEATURE_PORT_HAS_PULL_ENABLE) && FSL_FEATURE_PORT_HAS_PULL_ENABLE
- enum _port_pull
- {
- kPORT_PullDisable = 0U,
- kPORT_PullDown = 2U,
- kPORT_PullUp = 3U,
- };
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_SLEW_RATE) && FSL_FEATURE_PORT_HAS_SLEW_RATE
- enum _port_slew_rate
- {
- kPORT_FastSlewRate = 0U,
- kPORT_SlowSlewRate = 1U,
- };
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
- enum _port_open_drain_enable
- {
- kPORT_OpenDrainDisable = 0U,
- kPORT_OpenDrainEnable = 1U,
- };
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_PASSIVE_FILTER) && FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
- enum _port_passive_filter_enable
- {
- kPORT_PassiveFilterDisable = 0U,
- kPORT_PassiveFilterEnable = 1U,
- };
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
- enum _port_drive_strength
- {
- kPORT_LowDriveStrength = 0U,
- kPORT_HighDriveStrength = 1U,
- };
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
- enum _port_lock_register
- {
- kPORT_UnlockRegister = 0U,
- kPORT_LockRegister = 1U,
- };
- #endif
- #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
- typedef enum _port_mux
- {
- kPORT_PinDisabledOrAnalog = 0U,
- kPORT_MuxAsGpio = 1U,
- kPORT_MuxAlt2 = 2U,
- kPORT_MuxAlt3 = 3U,
- kPORT_MuxAlt4 = 4U,
- kPORT_MuxAlt5 = 5U,
- kPORT_MuxAlt6 = 6U,
- kPORT_MuxAlt7 = 7U,
- kPORT_MuxAlt8 = 8U,
- kPORT_MuxAlt9 = 9U,
- kPORT_MuxAlt10 = 10U,
- kPORT_MuxAlt11 = 11U,
- kPORT_MuxAlt12 = 12U,
- kPORT_MuxAlt13 = 13U,
- kPORT_MuxAlt14 = 14U,
- kPORT_MuxAlt15 = 15U,
- } port_mux_t;
- #endif
- typedef enum _port_interrupt
- {
- kPORT_InterruptOrDMADisabled = 0x0U,
- #if defined(FSL_FEATURE_PORT_HAS_DMA_REQUEST) && FSL_FEATURE_PORT_HAS_DMA_REQUEST
- kPORT_DMARisingEdge = 0x1U,
- kPORT_DMAFallingEdge = 0x2U,
- kPORT_DMAEitherEdge = 0x3U,
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_IRQC_FLAG) && FSL_FEATURE_PORT_HAS_IRQC_FLAG
- kPORT_FlagRisingEdge = 0x05U,
- kPORT_FlagFallingEdge = 0x06U,
- kPORT_FlagEitherEdge = 0x07U,
- #endif
- kPORT_InterruptLogicZero = 0x8U,
- kPORT_InterruptRisingEdge = 0x9U,
- kPORT_InterruptFallingEdge = 0xAU,
- kPORT_InterruptEitherEdge = 0xBU,
- kPORT_InterruptLogicOne = 0xCU,
- #if defined(FSL_FEATURE_PORT_HAS_IRQC_TRIGGER) && FSL_FEATURE_PORT_HAS_IRQC_TRIGGER
- kPORT_ActiveHighTriggerOutputEnable = 0xDU,
- kPORT_ActiveLowTriggerOutputEnable = 0xEU,
- #endif
- } port_interrupt_t;
- #if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
- typedef enum _port_digital_filter_clock_source
- {
- kPORT_BusClock = 0U,
- kPORT_LpoClock = 1U,
- } port_digital_filter_clock_source_t;
- typedef struct _port_digital_filter_config
- {
- uint32_t digitalFilterWidth;
- port_digital_filter_clock_source_t clockSource;
- } port_digital_filter_config_t;
- #endif
- #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
- typedef struct _port_pin_config
- {
- #if defined(FSL_FEATURE_PORT_HAS_PULL_ENABLE) && FSL_FEATURE_PORT_HAS_PULL_ENABLE
- uint16_t pullSelect : 2;
- #else
- uint16_t : 2;
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_SLEW_RATE) && FSL_FEATURE_PORT_HAS_SLEW_RATE
- uint16_t slewRate : 1;
- #else
- uint16_t : 1;
- #endif
- uint16_t : 1;
- #if defined(FSL_FEATURE_PORT_HAS_PASSIVE_FILTER) && FSL_FEATURE_PORT_HAS_PASSIVE_FILTER
- uint16_t passiveFilterEnable : 1;
- #else
- uint16_t : 1;
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_OPEN_DRAIN) && FSL_FEATURE_PORT_HAS_OPEN_DRAIN
- uint16_t openDrainEnable : 1;
- #else
- uint16_t : 1;
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
- uint16_t driveStrength : 1;
- #else
- uint16_t : 1;
- #endif
- uint16_t : 1;
- #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && (FSL_FEATURE_PORT_PCR_MUX_WIDTH == 3)
- uint16_t mux : 3;
- uint16_t : 4;
- #elif defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && (FSL_FEATURE_PORT_PCR_MUX_WIDTH == 4)
- uint16_t mux : 4;
- uint16_t : 3;
- #else
- uint16_t : 7,
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK) && FSL_FEATURE_PORT_HAS_PIN_CONTROL_LOCK
- uint16_t lockRegister : 1;
- #else
- uint16_t : 1;
- #endif
- } port_pin_config_t;
- #endif
- #if defined(__cplusplus)
- extern "C" {
- #endif
- #if defined(FSL_FEATURE_PORT_PCR_MUX_WIDTH) && FSL_FEATURE_PORT_PCR_MUX_WIDTH
- static inline void PORT_SetPinConfig(PORT_Type *base, uint32_t pin, const port_pin_config_t *config)
- {
- assert(config);
- uint32_t addr = (uint32_t)&base->PCR[pin];
- *(volatile uint16_t *)(addr) = *((const uint16_t *)config);
- }
- static inline void PORT_SetMultiplePinsConfig(PORT_Type *base, uint32_t mask, const port_pin_config_t *config)
- {
- assert(config);
- uint16_t pcrl = *((const uint16_t *)config);
- if (mask & 0xffffU)
- {
- base->GPCLR = ((mask & 0xffffU) << 16) | pcrl;
- }
- if (mask >> 16)
- {
- base->GPCHR = (mask & 0xffff0000U) | pcrl;
- }
- }
- #if defined(FSL_FEATURE_PORT_HAS_MULTIPLE_IRQ_CONFIG) && FSL_FEATURE_PORT_HAS_MULTIPLE_IRQ_CONFIG
- static inline void PORT_SetMultipleInterruptPinsConfig(PORT_Type *base, uint32_t mask, port_interrupt_t config)
- {
- assert(config);
- if (mask & 0xffffU)
- {
- base->GICLR = (config << 16) | (mask & 0xffffU);
- }
- mask = mask >> 16;
- if (mask)
- {
- base->GICHR = (config << 16) | (mask & 0xffffU);
- }
- }
- #endif
- static inline void PORT_SetPinMux(PORT_Type *base, uint32_t pin, port_mux_t mux)
- {
- base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_MUX_MASK) | PORT_PCR_MUX(mux);
- }
- #endif
- #if defined(FSL_FEATURE_PORT_HAS_DIGITAL_FILTER) && FSL_FEATURE_PORT_HAS_DIGITAL_FILTER
- static inline void PORT_EnablePinsDigitalFilter(PORT_Type *base, uint32_t mask, bool enable)
- {
- if (enable == true)
- {
- base->DFER |= mask;
- }
- else
- {
- base->DFER &= ~mask;
- }
- }
- static inline void PORT_SetDigitalFilterConfig(PORT_Type *base, const port_digital_filter_config_t *config)
- {
- assert(config);
- base->DFCR = PORT_DFCR_CS(config->clockSource);
- base->DFWR = PORT_DFWR_FILT(config->digitalFilterWidth);
- }
- #endif
- static inline void PORT_SetPinInterruptConfig(PORT_Type *base, uint32_t pin, port_interrupt_t config)
- {
- base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_IRQC_MASK) | PORT_PCR_IRQC(config);
- }
- #if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
- static inline void PORT_SetPinDriveStrength(PORT_Type* base, uint32_t pin, uint8_t strength)
- {
- base->PCR[pin] = (base->PCR[pin] & ~PORT_PCR_DSE_MASK) | PORT_PCR_DSE(strength);
- }
- #endif
- static inline uint32_t PORT_GetPinsInterruptFlags(PORT_Type *base)
- {
- return base->ISFR;
- }
- static inline void PORT_ClearPinsInterruptFlags(PORT_Type *base, uint32_t mask)
- {
- base->ISFR = mask;
- }
- #if defined(__cplusplus)
- }
- #endif
- #endif
|