Skip to content

Commit 18f155a

Browse files
committed
more docs
1 parent 05f53db commit 18f155a

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

docs/ar_ibus.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,101 @@ The first implementation of the IBus interface is for the Arduino development en
4343
The results is outlined in the following class diagram:
4444

4545
![Device Class](images/sfetk_ibus_class.png)
46+
47+
## sfeTkIBus Use
48+
49+
The general steps when using the sfeTkIBus in device development are outlined in the following steps
50+
51+
### Platform Independent/Bus Independent Driver
52+
53+
Develop a platform independent version of a device driver that commutates using the sfeTkIBus interface. This driver should include a method to set the bus object, accepting a pointer to a sfeTkIBus interface/object. Actual bus setup is provided outside of the driver.
54+
55+
This implementation would take the following form:
56+
57+
```c++
58+
59+
class myDriverClass
60+
{
61+
public:
62+
63+
myDriverClass(uint8_t address) : _addr{address}{}
64+
65+
bool begin()
66+
{
67+
// initialize things ...
68+
69+
return true;
70+
}
71+
void setCommunicationBus(sfeTkIBus *theBus)
72+
{
73+
_theBus = theBus;
74+
}
75+
76+
bool updateDeviceData(uint8_t *data, size_t len)
77+
{
78+
if (!_theBus || !data || len == 0)
79+
return false;
80+
81+
int status = _theBus->writeRegisterRegion(_addr, THE_REG, data, len);
82+
83+
return (status == 0);
84+
}
85+
private:
86+
sfeTkIBus *_theBus
87+
uint8_t _addr;
88+
};
89+
```
90+
91+
### Write a Platform Specific Driver, based on the core driver
92+
93+
This driver sub-classes from the general/core driver class, builds and configures the desired bus object and passes this into the core driver.
94+
95+
Basic concept - creating an I2C class in Arduino
96+
97+
```c++
98+
99+
class myArduinoDriveI2C : public myDriverClass
100+
{
101+
public:
102+
myArduinoDriverI2C() : myDriverClass(MY_DEFAULT_ADDRESS)
103+
{}
104+
105+
bool begin()
106+
{
107+
if (!_theI2CBus.init())
108+
return false;
109+
setCommunicationBus(&_theI2CBus);
110+
111+
return myDriverClass::begin();
112+
}
113+
114+
private:
115+
sfeTkBusI2C _theI2CBus;
116+
};
117+
```
118+
119+
Basic concept - creating an SPI class in Arduino
120+
121+
```c++
122+
123+
class myArduinoDriveSPI : public myDriverClass
124+
{
125+
public:
126+
myArduinoDriverSPI() : myDriverClass(MY_DEFAULT_CS)
127+
{}
128+
129+
bool begin()
130+
{
131+
SPISettings spiSettings = SPISettings(4000000, MSBFIRST, SPI_MODE3);
132+
133+
if (!_theSPIBus.init(SPI, spiSettings, true))
134+
return false;
135+
setCommunicationBus(&_theSPIBus);
136+
137+
return myDriverClass::begin();
138+
}
139+
140+
private:
141+
sfeTkBusSPI _theSPIBus;
142+
};
143+
```

0 commit comments

Comments
 (0)