Skip to content

Commit 22345a1

Browse files
committed
update to new thoughts
1 parent 75d9823 commit 22345a1

File tree

1 file changed

+53
-18
lines changed

1 file changed

+53
-18
lines changed

docs/ar_ibus.md

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ The key class to support this pattern are:
2020
| | |
2121
|------|-------|
2222
**sfeTkIBus** | A virtual C++ class that device the bus ```sfeTkIBus``` interface |
23-
**sfeTkBusI2C** | Provides an Arduino I2C implementation for the toolkit |
24-
**sfeTkBusSPI** | Provides an Arduino SPI implementation for the toolkit |
23+
**sfeTkII2C** | Sub-class of the ```sfeTkIIBus``` interface, it provides an interface for I2C devices|
24+
**sfeTkISPI** | Sub-class of the ```sfeTkIIBus``` interface, it provides an interface for SPI devices |
2525

2626
### The sfeTkIBus Interface
2727

@@ -31,18 +31,35 @@ The interface methods:
3131

3232
| Method| Definition |
3333
|------|-------|
34-
**ping** | A method used to determine if a device is connected to the bus |
3534
**writeRegisterByte** | Write a byte of data to a particular register of a device |
35+
**writeRegisterWord** | Write a word of data to a particular register of a device |
3636
**writeRegisterRegion** | Write an array of data to a particular register of a device|
37+
**readRegisterByte** | Read a byte of data from a particular register of a device |
38+
**readRegisterWord** | Read a word of data from a particular register of a device |
3739
**readRegisterRegion** | Read an array of data from a particular register of a device |
3840

39-
### Arduino Implementation
41+
### The sfeTkII2C Implementation
4042

41-
The first implementation of the IBus interface is for the Arduino development environment, as noted above. The implementation consists of two classes, ```sfeTkBusI2C``` and ```sfeTkBusSPI```, each implementing the sfeTkIBus interface using the Arduino SDK.
43+
This class sub-classes from the ```sfeTkIBus``` interface adding additional functionally focused on supporting an I2C implementation. This interface provides the additional functionality.
4244

43-
The results is outlined in the following class diagram:
45+
| Method| Definition |
46+
|------|-------|
47+
**ping** | Determine if a devices is connected to the I2C device at the address set on this bus object. This is an interface method |
48+
**setAddress** | Set the I2C address to use for this I2C object |
49+
**address** | Returns the address used by this I2C object |
50+
51+
> Note: The ```sfeTkII2C``` class manages the I2C address
4452
45-
![Device Class](images/sfetk_ibus_class.png)
53+
### The sfeTkISPI Implementation
54+
55+
This class sub-classes from the ```sfeTkIBus``` interface adding additional functionally focused on supporting an SPI implementation. This interface provides the additional functionality.
56+
57+
| Method| Definition |
58+
|------|-------|
59+
**setCS** | Set the CS Pin to use for this SPI object |
60+
**cs** | Returns the CS Pin used by this SPI object |
61+
62+
> Note: The ```sfeTkISPI``` class manages the CS Pin
4663
4764
## sfeTkIBus Use
4865

@@ -78,13 +95,18 @@ public:
7895
if (!_theBus || !data || len == 0)
7996
return false;
8097

81-
int status = _theBus->writeRegisterRegion(_addr, THE_REG, data, len);
98+
int status = _theBus->writeRegisterRegion(THE_REG, data, len);
8299

83100
return (status == 0);
84101
}
102+
103+
bool checkDeviceID()
104+
{
105+
// do some device ID checks in registers ...etc
106+
return true;
107+
}
85108
private:
86-
sfeTkIBus *_theBus
87-
uint8_t _addr;
109+
sfeTkIBus *_theBus;
88110
};
89111
```
90112
@@ -96,23 +118,31 @@ Basic concept - creating an I2C class in Arduino
96118
97119
```c++
98120
99-
class myArduinoDriveI2C : public myDriverClass
121+
class myArduinoDriverI2C : public myDriverClass
100122
{
101123
public:
102-
myArduinoDriverI2C() : myDriverClass(MY_DEFAULT_ADDRESS)
124+
myArduinoDriverI2C()
103125
{}
104-
126+
105127
bool begin()
106128
{
107-
if (!_theI2CBus.init())
129+
if (!_theI2CBus.init(MY_DEVICE_ADDRESS))
108130
return false;
109131
setCommunicationBus(&_theI2CBus);
110132
111133
return myDriverClass::begin();
112134
}
113135
136+
bool ping()
137+
{
138+
if (!_theI2CBus.ping())
139+
return false;
140+
141+
return checkDeviceID();
142+
}
143+
114144
private:
115-
sfeTkBusI2C _theI2CBus;
145+
sfeTkArdI2C _theI2CBus;
116146
};
117147
```
118148

@@ -123,21 +153,26 @@ Basic concept - creating an SPI class in Arduino
123153
class myArduinoDriveSPI : public myDriverClass
124154
{
125155
public:
126-
myArduinoDriverSPI() : myDriverClass(MY_DEFAULT_CS)
156+
myArduinoDriverSPI()
127157
{}
128158

129159
bool begin()
130160
{
131161
SPISettings spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE3);
132162

133-
if (!_theSPIBus.init(SPI, spiSettings, true))
163+
if (!_theSPIBus.init(SPI, spiSettings, MY_DEFAULT_CS, true))
134164
return false;
135165
setCommunicationBus(&_theSPIBus);
136166

137167
return myDriverClass::begin();
138168
}
139169

170+
bool ping()
171+
{
172+
return checkDeviceID();
173+
}
174+
140175
private:
141-
sfeTkBusSPI _theSPIBus;
176+
sfeTkArdSPI _theSPIBus;
142177
};
143178
```

0 commit comments

Comments
 (0)