|
6 | 6 |
|
7 | 7 | namespace ZPUino {
|
8 | 8 |
|
9 |
| - class REGW { |
10 |
| - public: |
11 |
| - REGW(register_t reg): _r(reg) {}; |
12 |
| - inline operator uint32_t const () |
13 |
| - { |
14 |
| - return*_r; |
15 |
| - } |
16 |
| - void operator=(uint32_t value) { *_r=value; } |
17 |
| - inline void setBit(int bit) { *_r = *_r | BIT(bit); } |
18 |
| - inline void clearBit(int bit) { *_r = *_r & ~(BIT(bit)); } |
19 |
| - private: |
20 |
| - register_t _r; |
21 |
| - }; |
22 |
| - |
23 |
| - class BaseDevice { |
24 |
| - public: |
25 |
| - BaseDevice(uint8_t instance=0xff): m_slot(0xff), m_instance(instance) {} |
26 |
| - inline REGW REG(uint32_t offset=0) { |
27 |
| - return REGW(m_baseaddress+offset); |
28 |
| - } |
29 |
| - int deviceBegin(uint8_t vendor, uint8_t product); |
30 |
| - int isError() { return m_slot==0xff; } |
31 |
| - inline uint8_t getSlot() const { return m_slot; } |
32 |
| - protected: |
33 |
| - private: |
34 |
| - uint8_t m_slot; |
35 |
| - uint8_t m_instance; |
36 |
| - register_t m_baseaddress; |
37 |
| - }; |
| 9 | + class REGBIT |
| 10 | + { |
| 11 | + public: |
| 12 | + REGBIT(register_t&r, int bit): _r(r),_b(bit) { |
| 13 | + } |
| 14 | + REGBIT &operator=(bool value) { |
| 15 | + if (value) |
| 16 | + *_r = *_r | (1<<_b); |
| 17 | + else |
| 18 | + *_r = *_r & ~(1<<_b); |
| 19 | + return *this; |
| 20 | + } |
| 21 | + private: |
| 22 | + register_t _r; |
| 23 | + int _b; |
| 24 | + }; |
| 25 | + |
| 26 | + class REGW { |
| 27 | + public: |
| 28 | + REGW(register_t reg): _r(reg) {}; |
| 29 | + inline operator uint32_t const () |
| 30 | + { |
| 31 | + return*_r; |
| 32 | + } |
| 33 | + void operator=(uint32_t value) { *_r=value; } |
| 34 | + //uint32_t operator&(uint32_t val) const { return *_r & val; } |
| 35 | + inline void setBit(int bit) { *_r = *_r | BIT(bit); } |
| 36 | + inline void clearBit(int bit) { *_r = *_r & ~(BIT(bit)); } |
| 37 | + inline REGBIT bit(int bit) { return REGBIT(_r,bit); } |
| 38 | + private: |
| 39 | + register_t _r; |
| 40 | + }; |
| 41 | + |
| 42 | + class REGAccess { |
| 43 | + public: |
| 44 | + inline void begin(register_t r) { m_baseaddress=r;} |
| 45 | + inline REGW REG(uint32_t offset=0) { |
| 46 | + return REGW(m_baseaddress+offset); |
| 47 | + } |
| 48 | + inline const REGW REG(uint32_t offset=0) const { |
| 49 | + return REGW(m_baseaddress+offset); |
| 50 | + } |
| 51 | + register_t getBaseRegister() { return m_baseaddress; } |
| 52 | + |
| 53 | + protected: |
| 54 | + register_t m_baseaddress; |
| 55 | + }; |
| 56 | + |
| 57 | + class BaseDevice: public REGAccess { |
| 58 | + public: |
| 59 | + BaseDevice(uint8_t instance=0xff): m_slot(0xff), m_instance(instance) {} |
| 60 | + int deviceBegin(uint8_t vendor, uint8_t product); |
| 61 | + int isError() { return m_slot==0xff; } |
| 62 | + inline uint8_t getSlot() const { return m_slot; } |
| 63 | + protected: |
| 64 | + private: |
| 65 | + uint8_t m_slot; |
| 66 | + uint8_t m_instance; |
| 67 | + }; |
38 | 68 | };
|
39 | 69 |
|
40 | 70 | #endif
|
0 commit comments