Skip to content

Commit 77d6787

Browse files
committed
more dcx
1 parent e4e7dcc commit 77d6787

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

drivers/SPI.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,23 @@ class SPI : private NonCopyable<SPI> {
132132
*/
133133
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, use_gpio_ssel_t);
134134

135+
/** Create a SPI master connected to the specified pins.
136+
*
137+
* @note This constructor manipulates the SSEL/DCX pin as a GPIO output
138+
* using a DigitalOut object. This should work on any target, and permits
139+
* the use of select() and deselect() methods to keep the pin asserted
140+
* between transfers.
141+
*
142+
* @note You can specify mosi or miso as NC if not used.
143+
*
144+
* @param mosi SPI Master Out, Slave In pin.
145+
* @param miso SPI Master In, Slave Out pin.
146+
* @param sclk SPI Clock pin.
147+
* @param ssel SPI Chip Select pin.
148+
* @param dcx SPI Data Command pin.
149+
*/
150+
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, PinName dcx, use_gpio_ssel_t);
151+
135152
/** Create a SPI master connected to the specified pins.
136153
*
137154
* @note This constructor passes the SSEL pin selection to the target HAL.
@@ -159,6 +176,7 @@ class SPI : private NonCopyable<SPI> {
159176
* @param ssel SPI Chip Select pin.
160177
*/
161178
SPI(const spi_pinmap_t &static_pinmap, PinName ssel);
179+
SPI(const spi_pinmap_t &pinmap, PinName ssel, PinName dcx);
162180
SPI(const spi_pinmap_t &&, PinName) = delete; // prevent passing of temporary objects
163181

164182
virtual ~SPI();
@@ -424,10 +442,12 @@ class SPI : private NonCopyable<SPI> {
424442
PinName _miso;
425443
PinName _sclk;
426444
PinName _hw_ssel;
427-
PinName _dcx;
445+
PinName _hw_dcx;
428446

429447
// The Slave Select GPIO if we're doing it ourselves.
430448
DigitalOut _sw_ssel;
449+
// The Data Command GPIO if we're doing it ourselves.
450+
DigitalOut _sw_dcx;
431451

432452
/* Size of the SPI frame */
433453
int _bits;

drivers/source/SPI.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, PinName dcx) :
3636
_miso(miso),
3737
_sclk(sclk),
3838
_hw_ssel(ssel),
39-
_dcx(dcx),
39+
_hw_dcx(dcx),
4040
_sw_ssel(NC),
41+
_sw_dcx(NC),
4142
_static_pinmap(NULL),
4243
_init_func(_do_init)
4344
{
@@ -59,8 +60,32 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, use_gpio_ssel_t
5960
_miso(miso),
6061
_sclk(sclk),
6162
_hw_ssel(NC),
62-
_dcx(NC),
63+
_hw_dcx(NC),
6364
_sw_ssel(ssel, 1),
65+
_sw_dcx(NC),
66+
_static_pinmap(NULL),
67+
_init_func(_do_init)
68+
{
69+
// Need backwards compatibility with HALs not providing API
70+
#ifdef DEVICE_SPI_COUNT
71+
_peripheral_name = spi_get_peripheral_name(_mosi, _miso, _sclk);
72+
#else
73+
_peripheral_name = GlobalSPI;
74+
#endif
75+
_do_construct();
76+
}
77+
78+
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, PinName dcx, use_gpio_ssel_t) :
79+
#if DEVICE_SPI_ASYNCH
80+
_irq(this),
81+
#endif
82+
_mosi(mosi),
83+
_miso(miso),
84+
_sclk(sclk),
85+
_hw_ssel(NC),
86+
_hw_dcx(NC),
87+
_sw_ssel(ssel, 1),
88+
_sw_dcx(dcx, 1),
6489
_static_pinmap(NULL),
6590
_init_func(_do_init)
6691
{
@@ -81,8 +106,9 @@ SPI::SPI(const spi_pinmap_t &pinmap) :
81106
_miso(pinmap.miso_pin),
82107
_sclk(pinmap.sclk_pin),
83108
_hw_ssel(pinmap.ssel_pin),
84-
_dcx(pinmap.dcx_pin),
109+
_hw_dcx(pinmap.dcx_pin),
85110
_sw_ssel(NC),
111+
_sw_dcx(NC),
86112
_static_pinmap(&pinmap),
87113
_peripheral_name((SPIName)pinmap.peripheral),
88114
_init_func(_do_init_direct)
@@ -99,8 +125,27 @@ SPI::SPI(const spi_pinmap_t &pinmap, PinName ssel) :
99125
_miso(pinmap.miso_pin),
100126
_sclk(pinmap.sclk_pin),
101127
_hw_ssel(NC),
102-
_dcx(NC),
128+
_hw_dcx(NC),
129+
_sw_ssel(ssel, 1),
130+
_sw_dcx(NC),
131+
_static_pinmap(&pinmap),
132+
_peripheral_name((SPIName)pinmap.peripheral),
133+
_init_func(_do_init_direct)
134+
{
135+
_do_construct();
136+
}
137+
138+
SPI::SPI(const spi_pinmap_t &pinmap, PinName ssel, PinName dcx) :
139+
#if DEVICE_SPI_ASYNCH
140+
_irq(this),
141+
#endif
142+
_mosi(pinmap.mosi_pin),
143+
_miso(pinmap.miso_pin),
144+
_sclk(pinmap.sclk_pin),
145+
_hw_ssel(NC),
146+
_hw_dcx(NC),
103147
_sw_ssel(ssel, 1),
148+
_sw_dcx(dcx, 1),
104149
_static_pinmap(&pinmap),
105150
_peripheral_name((SPIName)pinmap.peripheral),
106151
_init_func(_do_init_direct)
@@ -110,7 +155,7 @@ SPI::SPI(const spi_pinmap_t &pinmap, PinName ssel) :
110155

111156
void SPI::_do_init(SPI *obj)
112157
{
113-
spi_init(&obj->_peripheral->spi, obj->_mosi, obj->_miso, obj->_sclk, obj->_hw_ssel, obj->_dcx);
158+
spi_init(&obj->_peripheral->spi, obj->_mosi, obj->_miso, obj->_sclk, obj->_hw_ssel, obj->_hw_dcx);
114159
}
115160

116161
void SPI::_do_init_direct(SPI *obj)

0 commit comments

Comments
 (0)