Skip to content

Commit 6d9459c

Browse files
authored
Overload SpiBusDeviceConfig in order to support the simple use case of just using a cs pin. (#2)
1 parent ce281e6 commit 6d9459c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Diff for: examples/ts_spi/ts_spi.ino

+1-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ void bmp388_thread_func();
2727
* GLOBAL VARIABLES
2828
**************************************************************************************/
2929

30-
SpiBusDevice bmp388{"SPI",
31-
SpiBusDeviceConfig {
32-
SPISettings{1000000, MSBFIRST, SPI_MODE0},
33-
/* bmp388_select or ... */ [](){ digitalWrite(BMP388_CS_PIN, LOW ); },
34-
/* bmp388_deselect or ... */ [](){ digitalWrite(BMP388_CS_PIN, HIGH); }
35-
}
36-
};
37-
30+
SpiBusDevice bmp388{"SPI", SpiBusDeviceConfig {SPISettings{1000000, MSBFIRST, SPI_MODE0}, BMP388_CS_PIN}};
3831

3932
static char thread_name[NUM_THREADS][32];
4033

Diff for: src/spi/SpiBusDeviceConfig.h

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ class SpiBusDeviceConfig
4848
, _fill_symbol{fill_symbol}
4949
{ }
5050

51+
SpiBusDeviceConfig(SPISettings const & spi_settings, int const cs_pin, byte const fill_symbol = 0xFF)
52+
: SpiBusDeviceConfig
53+
{spi_settings,
54+
[cs_pin](){ digitalWrite(cs_pin, LOW); },
55+
[cs_pin](){ digitalWrite(cs_pin, HIGH); },
56+
fill_symbol
57+
}
58+
{ }
59+
5160

5261
SPISettings settings () const { return _spi_settings; }
5362
void select () const { if (_spi_select) _spi_select(); }

0 commit comments

Comments
 (0)