Skip to content

Commit 36edb44

Browse files
committed
Applying patch by @facchinm allowing for Ctor style object creation.
1 parent 77bc88b commit 36edb44

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

examples/ts_wire/ts_wire.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void lsm6dsox_thread_func();
2424
* GLOBAL VARIABLES
2525
**************************************************************************************/
2626

27-
BusDevice lsm6dsox = BusDeviceBase::create(Wire, LSM6DSOX_ADDRESS);
27+
BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS);
2828

2929
static char thread_name[NUM_THREADS][32];
3030

@@ -64,7 +64,7 @@ byte lsm6dsox_read_reg(byte const reg_addr)
6464
byte read_buf = 0;
6565

6666
IoRequest req(write_buf, read_buf);
67-
IoResponse rsp = lsm6dsox->transfer(req);
67+
IoResponse rsp = lsm6dsox.transfer(req);
6868

6969
/* Optionally do other stuff */
7070

src/BusDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* PUBLIC MEMBER FUNCTIONS
3030
**************************************************************************************/
3131

32-
BusDevice BusDeviceBase(arduino::HardwareSPI & spi, int const cs_pin, SPISettings const & spi_settings, byte const fill_symbol)
32+
BusDevice BusDeviceBase::create(arduino::HardwareSPI & spi, int const cs_pin, SPISettings const & spi_settings, byte const fill_symbol)
3333
{
3434
return BusDevice(new SpiBusDevice(SpiBusDeviceConfig{spi,
3535
spi_settings,

src/BusDevice.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ namespace arduino
3737
class HardwareI2C;
3838
}
3939

40-
class BusDeviceBase;
40+
class BusDevice;
4141

4242
/**************************************************************************************
4343
* TYPEDEF
4444
**************************************************************************************/
4545

46-
typedef mbed::SharedPtr<BusDeviceBase> BusDevice;
47-
4846
/**************************************************************************************
4947
* CLASS DECLARATION
5048
**************************************************************************************/
@@ -68,4 +66,31 @@ class BusDeviceBase
6866

6967
};
7068

69+
class BusDevice
70+
{
71+
public:
72+
BusDevice(BusDeviceBase* dev) : instance(dev) {};
73+
/*
74+
BusDevice(arduino::HardwareSPI & spi, int const cs_pin, SPISettings const & spi_settings, byte const fill_symbol = 0xFF) {
75+
this = BusDeviceBase::create(spi, cs_pin, spi_settings, fill_symbol);
76+
}
77+
BusDevice(arduino::HardwareSPI & spi, int const cs_pin, uint32_t const spi_clock, BitOrder const spi_bit_order, SPIMode const spi_bit_mode, byte const fill_symbol = 0xFF);
78+
BusDevice(arduino::HardwareSPI & spi, SpiBusDeviceConfig::SpiSelectFunc spi_select, SpiBusDeviceConfig::SpiDeselectFunc spi_deselect, SPISettings const & spi_settings, byte const fill_symbol = 0xFF);
79+
*/
80+
//BusDevice(BusDevice&&) = default;
81+
BusDevice(arduino::HardwareI2C & wire, byte const slave_addr) {
82+
*this = BusDeviceBase::create(wire, slave_addr);
83+
}
84+
/*
85+
BusDevice(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart);
86+
BusDevice(arduino::HardwareI2C & wire, byte const slave_addr, bool const restart, bool const stop);
87+
*/
88+
IoResponse transfer(IoRequest & req) {
89+
return instance->transfer(req);
90+
};
91+
92+
private:
93+
mbed::SharedPtr<BusDeviceBase> instance;
94+
};
95+
7196
#endif /* BUS_DEVICE_H_ */

0 commit comments

Comments
 (0)