📄 gpiohardware.h
字号:
#ifndef GPIO_HARDWARE_H__ // {#define GPIO_HARDWARE_H__//----------------------------------------------------// GPS GPIO Configuration.//// Here are sample hardware configurations for// Bulverde GPIOs connected to the Hammerhead// POWERON and VDDCORE_REG power controls.////----------------------------------------------------#define ONE_GPIO#undef TWO_GPIOS#undef THREE_GPIOS#ifdef THREE_GPIOS // { most complicated method#define OPT_GPIO "3 gpio"#define GPS_GPIO_RESET_EXISTS GPIO_106#define GPS_GPIO_POWER_EXISTS GPIO_13#define GPS_GPIO_STANDBY_EXISTS GPIO_48 // HH.POWERON#define GPS_nINTR_GPIO GPIO_22#define GPSR_RESET GPSR3#define GPDR_RESET GPDR3#define GPCR_RESET GPCR3#define GPLR_RESET GPLR3#define GPSR_POWER GPSR0#define GPDR_POWER GPDR0#define GPCR_POWER GPCR0#define GPLR_POWER GPLR0#define GPSR_STANDBY GPSR1#define GPDR_STANDBY GPDR1#define GPCR_STANDBY GPCR1#define GPLR_STANDBY GPLR1#endif // }#ifdef TWO_GPIOS // { no need for power-sequencing chip.#define OPT_GPIO "2 gpio"#define OPT_GPIO "3 gpio"#undef GPS_GPIO_RESET_EXISTS#define GPS_GPIO_POWER_EXISTS GPIO_13#define GPS_GPIO_STANDBY_EXISTS GPIO_48#define GPSR_POWER GPSR0#define GPDR_POWER GPDR0#define GPCR_POWER GPCR0#define GPLR_POWER GPLR0#define GPSR_STANDBY GPSR1#define GPDR_STANDBY GPDR1#define GPCR_STANDBY GPCR1#define GPLR_STANDBY GPLR1#endif // }#ifdef ONE_GPIO // { simplest way to go.#define OPT_GPIO "1 gpio"#undef GPS_GPIO_RESET_EXISTS#undef GPS_GPIO_POWER_EXISTS#define GPS_GPIO_STANDBY_EXISTS GPIO_74#define GPSR_STANDBY GPSR2#define GPDR_STANDBY GPDR2#define GPCR_STANDBY GPCR2#define GPLR_STANDBY GPLR2#endif // }//----------------------------------------------------// Handy bit field definitions//----------------------------------------------------#ifdef BIT#undef BIT#endif#define BIT(p) (1L << (p))#ifdef MASK#undef MASK#endif#define MASK(nBits,shift) ((BIT(nBits+1) - 1) << (shift))namespace GPS_GPIO {//---------------------------------------------------------------------------// General-Purpose Input/Output Structure - see Chapter 24 on page 24-1//---------------------------------------------------------------------------struct BULVERDE_GPIO_REG{ DWORD GPLR0; DWORD GPLR1; DWORD GPLR2; DWORD GPDR0; DWORD GPDR1; DWORD GPDR2; DWORD GPSR0; DWORD GPSR1; DWORD GPSR2; DWORD GPCR0; DWORD GPCR1; DWORD GPCR2; DWORD GRER0; DWORD GRER1; DWORD GRER2; DWORD GFER0; DWORD GFER1; DWORD GFER2; DWORD GEDR0; DWORD GEDR1; DWORD GEDR2; DWORD GAFR0_L; DWORD GAFR0_U; DWORD GAFR1_L; DWORD GAFR1_U; DWORD GAFR2_L; DWORD GAFR2_U; DWORD res74[(0x100 - 0x74)/sizeof(DWORD)]; DWORD GPLR3; DWORD res104[2]; DWORD GPDR3; DWORD res110[2]; DWORD GPSR3; DWORD res11C[2]; DWORD GPCR3; DWORD res128[2]; DWORD GPER3; DWORD res134[2]; DWORD GFER3; DWORD res140[2]; DWORD GEDR3;};#define BULVERDE_BASE_REG_PA_GPIO 0x40E00000//------------------------------------------------------------------------------// See section 24, table 24-25..24-32 for the alternate functions.//------------------------------------------------------------------------------enum ALTERNATE_FUNCTION{ GPIO = 0, // zero is a special, handy case. AF1 = 1, AF2 = 2, AF3 = 3};inline DWORD buildAF_Mask(int id){ if (id > 16) id -= 16; return MASK(2,(id * 2));}inline DWORD buildAF_Gpio(int id){ // if (id > 16) id -= 16; // return (ALTERNATE_FUNCTION::GPIO << (id * 2)) & buildAF_Mask(id); return 0; // GPIO is AF0 so, always return 0!}//------------------------------------------------------------------------------//// From the schematics, GPS_PWR_EN is connected to GPIO-18 Pd-0// and nSTANDBY is connected to GPS_PWR_EN.//// Excuse the wierd ",comma" syntax below to support the enums better.////------------------------------------------------------------------------------namespace PIN{ enum { UNKNOWN = 0#ifdef GPS_GPIO_RESET_EXISTS // { ,RESET_ID = 0 ,nRESET = BIT(RESET_ID)#endif // }#ifdef GPS_GPIO_STANDBY_EXISTS // { ,STANDBY_ID = 1 ,nSTANDBY = BIT(STANDBY_ID)#endif // }#ifdef GPS_GPIO_POWER_EXISTS // { ,POWER_ID = 74-(2*32) ,POWER = BIT(POWER_ID)#endif // } ,LAST };} // namespace PIN//------------------------------------------------------------------------------//// Set and Get GPIOs - required.////------------------------------------------------------------------------------#ifdef GPS_GPIO_RESET_EXISTS // {inline bool GET_nRESET(volatile BULVERDE_GPIO_REG& hw){ if (hw.GPLR0 & PIN::nRESET) return true; return false;}inline void SET_nRESET(volatile BULVERDE_GPIO_REG& hw){ hw.GPSR0 = PIN::nRESET;}inline void CLEAR_nRESET(volatile BULVERDE_GPIO_REG& hw){ hw.GPCR0 = PIN::nRESET;}#else#define GET_nRESET(hw)#define SET_nRESET(hw)#define CLEAR_nRESET(hw)#endif // }#ifdef GPS_GPIO_STANDBY_EXISTS // {inline bool GET_nSTANDBY(volatile BULVERDE_GPIO_REG& hw){ if (hw.GPLR0 & PIN::nSTANDBY) return true; return false;}inline void SET_nSTANDBY(volatile BULVERDE_GPIO_REG& hw){ hw.GPSR0 = PIN::nSTANDBY;}inline void CLEAR_nSTANDBY(volatile BULVERDE_GPIO_REG& hw){ hw.GPCR0 = PIN::nSTANDBY;}#else#define GET_nSTANDBY(hw)#define SET_nSTANDBY(hw)#define CLEAR_nSTANDBY(hw)#endif // }#ifdef GPS_GPIO_POWER_EXISTS // {inline bool GET_POWER(volatile BULVERDE_GPIO_REG& hw){ if (hw.GPLR2 & PIN::POWER) return true; return false;}inline void SET_POWER(volatile BULVERDE_GPIO_REG& hw){ hw.GPSR2 = PIN::POWER;}inline void CLEAR_POWER(volatile BULVERDE_GPIO_REG& hw){ hw.GPCR2 = PIN::POWER;}#else#define GET_POWER(hw)#define SET_POWER(hw)#define CLEAR_POWER(hw)#endif // }//------------------------------------------------------------------------------//// Init GPS GPIOs//// 1) Clear output level (inactive) for lowest GPS power.// 2) Program to become an output GPIO.// 3) Program to become an output instead of an "alternate function".////------------------------------------------------------------------------------inline void gpioGpsInit(volatile BULVERDE_GPIO_REG& hw){#ifdef GPS_GPIO_POWER_EXISTS // { CLEAR_POWER(hw); hw.GAFR0_U &= ~buildAF_Mask(PIN::POWER_ID); // | buildAF_Gpio(PIN::POWER_ID);#endif // }#ifdef GPS_GPIO_STANDBY_EXISTS // { CLEAR_nSTANDBY(hw); hw.GAFR0_L &= ~buildAF_Mask(PIN::STANDBY_ID); // | buildAF_Gpio(PIN::STANDBY_ID)#endif // }#ifdef GPS_GPIO_RESET_EXISTS // { CLEAR_nRESET(hw); hw.GAFR0_L &= ~buildAF_Mask(PIN::RESET_ID); // | buildAF_Gpio(PIN::RESET_ID);#endif // }}} // namespace GPS_GPIO#endif // GPIO_HARDWARE_H__ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -