|
3 | 3 |
|
4 | 4 | namespace ZPUino {
|
5 | 5 |
|
6 |
| - int DeviceRegistry::registerDevice(uint8_t slot) { |
7 |
| - if (slot>=MAX_SLOTS) |
8 |
| - return -2; |
9 |
| - if (m_sDeviceRegistry & (1<<slot)) |
10 |
| - return -1; |
11 |
| - m_sDeviceRegistry |= (1<<slot); |
12 |
| - return 0; |
13 |
| - } |
14 |
| - |
15 |
| - uint8_t DeviceRegistry::scanDevice(uint8_t vendor, uint8_t product, int instance) { |
16 |
| - uint8_t i; |
17 |
| - for (i=0;i<16;i++) { |
18 |
| - unsigned val = REGISTER(SYSCTLBASE,16+i); |
19 |
| - if (val!=0) { |
20 |
| - if (vendor!=VENDOR_ANY) { |
21 |
| - if (vendor != ((val>>8)&0xff)) |
| 6 | + int DeviceRegistry::registerDevice(int slot) { |
| 7 | + if (slot>=MAX_SLOTS) |
| 8 | + return -2; |
| 9 | + if (m_sDeviceRegistry & (1<<slot)) |
| 10 | + return -1; |
| 11 | + m_sDeviceRegistry |= (1<<slot); |
| 12 | + return 0; |
| 13 | + } |
| 14 | + |
| 15 | + uint8_t DeviceRegistry::scanDevice(unsigned vendor, unsigned product, int instance) { |
| 16 | + int i; |
| 17 | + for (i=0;i<16;i++) { |
| 18 | + unsigned val = REGISTER(SYSCTLBASE,16+i); |
| 19 | + if (val!=0) { |
| 20 | + if (vendor!=VENDOR_ANY) { |
| 21 | + if (vendor != ((val>>8)&0xff)) |
22 | 22 | continue; /* No match */
|
23 |
| - } |
| 23 | + } |
24 | 24 | if (vendor!=PRODUCT_ANY) {
|
25 |
| - if (product != (val&0xff)) |
26 |
| - continue; /* No match */ |
27 |
| - } |
28 |
| - if (isRegistered(i)) |
29 |
| - continue; |
30 |
| - |
31 |
| - if (--instance==0) |
32 |
| - return i; |
33 |
| - } |
34 |
| - } |
| 25 | + if (product != (val&0xff)) |
| 26 | + continue; /* No match */ |
| 27 | + } |
| 28 | + if (isRegistered(i)) |
| 29 | + continue; |
| 30 | + |
| 31 | + if (--instance==0) |
| 32 | + return i; |
| 33 | + } |
| 34 | + } |
35 | 35 | return NO_DEVICE;
|
36 |
| - } |
37 |
| - |
| 36 | + } |
| 37 | + |
| 38 | + int DeviceRegistry::getPPSInputPin(int masterslot, int offset) |
| 39 | + { |
| 40 | + return getPPSPin(masterslot,offset,16); |
| 41 | + } |
| 42 | + |
| 43 | + int DeviceRegistry::getPPSOutputPin(int masterslot, int offset) |
| 44 | + { |
| 45 | + return getPPSPin(masterslot,offset,0); |
| 46 | + } |
| 47 | + |
| 48 | + int DeviceRegistry::getPPSPin(int masterslot, int offset, int shift) |
| 49 | + { |
| 50 | + unsigned count = REGISTER(SYSCTLBASE, 32+shift); |
| 51 | + //unsigned i; |
| 52 | + register_t startreg = ®ISTER(SYSCTLBASE, 64); |
| 53 | + |
| 54 | + //for (i=0;i<count;i++) { |
| 55 | + while(count--) { |
| 56 | + unsigned val = *startreg++;//REGISTER(SYSCTLBASE, 64+i); |
| 57 | + unsigned char dev = (val>>shift)&0xff; |
| 58 | + if (dev!=masterslot) { |
| 59 | + continue; |
| 60 | + } else { |
| 61 | + int pin = (val>>(8+shift))&0xff; |
| 62 | + if (offset==0) |
| 63 | + return pin; |
| 64 | + offset--; |
| 65 | + } |
| 66 | + } |
| 67 | + return -1; |
| 68 | + } |
38 | 69 |
|
39 |
| - uint32_t DeviceRegistry::m_sDeviceRegistry = 0; |
| 70 | + uint32_t DeviceRegistry::m_sDeviceRegistry = 0; |
40 | 71 | };
|
0 commit comments