2812中的GPIO被分成很多组:GPA,GPB,GPD,GPE,GPF,GPG。
我们将组进行抽象。 组抽象:CGpio类namespace NF281x{class CGpio{ CGpio( const CGpio& );public: CGpio( volatile unsigned int& mux,volatile unsigned int& dir, volatile unsigned int& dat,volatile unsigned int& set,volatile unsigned int& clr, volatile unsigned int& tog );这里对拷贝构造进行了限制。
一下包含了相关寄存器的引用。定义这些寄存器,是为了在头文件中暴露出来,可以使用内联函数访问到。在一些需要快速操作的应用中,这样的设计是必要的。 protected: volatile unsigned int& m_mux; volatile unsigned int& m_dir; volatile unsigned int& m_dat; volatile unsigned int& m_set; volatile unsigned int& m_clr; volatile unsigned int& m_toggle;};} /** * 获取该组GPIO第i个io口的MUX * @param i 0~15 * @return * - 0 作为IO * - 1 作为外设 */ inline unsigned int getMux( const int& i )const{ return m_mux&(0x0001<const int& i )const{ return getMux(i)==0; } inline bool isMuxPeripheral( const int& i )const{ return getMux(i)!=0; } /** * 设置GPIO作为IO * @param i */ void setMuxIo( const int& i ); /** * 设置GPIO为外设模式 * @param i */ void setMuxPeripheral( const int& i ); /** * 设置GPIO的MUX * @param i * @param mux * - 0 IO模式 * - 1 外设模式 */ inline void setMux( const int& i,const unsigned int& mux ){ if( mux==0 ) setMuxIo(i); else setMuxPeripheral(i); }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
inline unsigned int getIoDir( const int& i )const{ return m_dir&(0x0001<inline void setIoDir( const int& i,const unsigned int& dir ){ if( dir==0 ) setIoIn(i); else setIoOut(i); } void setIoIn( const int& i ); void setIoOut( const int& i ); inline bool isIoIn( const int& i )const{ return getIoDir(i)==0; } inline bool isIoOut( const int& i )const{ return getIoDir(i)!=0; }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
inline unsigned int getIoState( const int& i )const{ return m_dat&(0x0001<inline bool isIoSet( const int& i )const{ return getIoState(i)!=0; } inline bool isIoUnset( const int& i )const{ return getIoState(i)==0; } inline void set( const int& i ){ m_set |= (0x0001<inline void clear( const int& i ){ m_clr |= (0x0001<inline void toggle( const int& i ){ m_toggle |= (0x0001<123456789101112
子类CGpa,CGpb等- 这里举一个例子,CGpa的类设计 namespace NF281x{class CGpa:public CGpio{ CGpa( const CGpa& );public: CGpa();};}
|