Skip to content

Commit e4e7dcc

Browse files
committed
First stab at implement SPIM DCX
1 parent b6a1ec7 commit e4e7dcc

File tree

6 files changed

+47
-802
lines changed

6 files changed

+47
-802
lines changed

drivers/SPI.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ class SPI : private NonCopyable<SPI> {
112112
* @param miso SPI Master In, Slave Out pin.
113113
* @param sclk SPI Clock pin.
114114
* @param ssel SPI Chip Select pin.
115+
* @param dcx SPI Data/Command pin.
115116
*/
116-
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC);
117+
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel = NC, PinName dcx = NC);
117118

118119
/** Create a SPI master connected to the specified pins.
119120
*
@@ -423,6 +424,7 @@ class SPI : private NonCopyable<SPI> {
423424
PinName _miso;
424425
PinName _sclk;
425426
PinName _hw_ssel;
427+
PinName _dcx;
426428

427429
// The Slave Select GPIO if we're doing it ourselves.
428430
DigitalOut _sw_ssel;

drivers/source/SPI.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ namespace mbed {
2828
SPI::spi_peripheral_s SPI::_peripherals[SPI_PERIPHERALS_USED];
2929
int SPI::_peripherals_used;
3030

31-
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
31+
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, PinName dcx) :
3232
#if DEVICE_SPI_ASYNCH
3333
_irq(this),
3434
#endif
3535
_mosi(mosi),
3636
_miso(miso),
3737
_sclk(sclk),
3838
_hw_ssel(ssel),
39+
_dcx(dcx),
3940
_sw_ssel(NC),
4041
_static_pinmap(NULL),
4142
_init_func(_do_init)
@@ -58,6 +59,7 @@ SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel, use_gpio_ssel_t
5859
_miso(miso),
5960
_sclk(sclk),
6061
_hw_ssel(NC),
62+
_dcx(NC),
6163
_sw_ssel(ssel, 1),
6264
_static_pinmap(NULL),
6365
_init_func(_do_init)
@@ -79,6 +81,7 @@ SPI::SPI(const spi_pinmap_t &pinmap) :
7981
_miso(pinmap.miso_pin),
8082
_sclk(pinmap.sclk_pin),
8183
_hw_ssel(pinmap.ssel_pin),
84+
_dcx(pinmap.dcx_pin),
8285
_sw_ssel(NC),
8386
_static_pinmap(&pinmap),
8487
_peripheral_name((SPIName)pinmap.peripheral),
@@ -96,6 +99,7 @@ SPI::SPI(const spi_pinmap_t &pinmap, PinName ssel) :
9699
_miso(pinmap.miso_pin),
97100
_sclk(pinmap.sclk_pin),
98101
_hw_ssel(NC),
102+
_dcx(NC),
99103
_sw_ssel(ssel, 1),
100104
_static_pinmap(&pinmap),
101105
_peripheral_name((SPIName)pinmap.peripheral),
@@ -106,7 +110,7 @@ SPI::SPI(const spi_pinmap_t &pinmap, PinName ssel) :
106110

107111
void SPI::_do_init(SPI *obj)
108112
{
109-
spi_init(&obj->_peripheral->spi, obj->_mosi, obj->_miso, obj->_sclk, obj->_hw_ssel);
113+
spi_init(&obj->_peripheral->spi, obj->_mosi, obj->_miso, obj->_sclk, obj->_hw_ssel, obj->_dcx);
110114
}
111115

112116
void SPI::_do_init_direct(SPI *obj)

hal/spi_api.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ typedef struct {
6363
int sclk_function;
6464
PinName ssel_pin;
6565
int ssel_function;
66+
PinName dcx_pin;
67+
int dcx_function;
6668
} spi_pinmap_t;
6769

6870
/**
@@ -185,8 +187,9 @@ void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap);
185187
* @param[in] miso The pin to use for MISO
186188
* @param[in] sclk The pin to use for SCLK
187189
* @param[in] ssel The pin to use for SSEL
190+
* @param[in] dcx The pin to use for DC (Data/Command) NC if not connected
188191
*/
189-
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel);
192+
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel, PinName dcx);
190193

191194
/** Release a SPI object
192195
*
@@ -325,6 +328,15 @@ const PinMap *spi_master_clk_pinmap(void);
325328
*/
326329
const PinMap *spi_master_cs_pinmap(void);
327330

331+
/** Get the pins that support SPI DC
332+
*
333+
* Return a PinMap array of pins that support SPI DC in
334+
* master mode. The array is terminated with {NC, NC, 0}.
335+
*
336+
* @return PinMap array
337+
*/
338+
const PinMap *spi_master_dc_pinmap(void);
339+
328340
/** Get the pins that support SPI MOSI
329341
*
330342
* Return a PinMap array of pins that support SPI MOSI in
@@ -361,6 +373,15 @@ const PinMap *spi_slave_clk_pinmap(void);
361373
*/
362374
const PinMap *spi_slave_cs_pinmap(void);
363375

376+
/** Get the pins that support SPI DC
377+
*
378+
* Return a PinMap array of pins that support SPI DC in
379+
* slave mode. The array is terminated with {NC, NC, 0}.
380+
*
381+
* @return PinMap array
382+
*/
383+
const PinMap *spi_slave_dc_pinmap(void);
384+
364385
/**@}*/
365386

366387
#if DEVICE_SPI_ASYNCH

hal/static_pinmap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#if DEVICE_SPI
2929
MBED_WEAK void spi_init_direct(spi_t *obj, const spi_pinmap_t *pinmap)
3030
{
31-
spi_init(obj, pinmap->mosi_pin, pinmap->miso_pin, pinmap->sclk_pin, pinmap->ssel_pin);
31+
spi_init(obj, pinmap->mosi_pin, pinmap->miso_pin, pinmap->sclk_pin, pinmap->ssel_pin, pinmap->dcx_pin);
3232
}
3333
#endif
3434

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/config/sdk_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3257,7 +3257,7 @@
32573257

32583258

32593259
#ifndef NRFX_SPIM_EXTENDED_ENABLED
3260-
#define NRFX_SPIM_EXTENDED_ENABLED 0
3260+
#define NRFX_SPIM_EXTENDED_ENABLED 1
32613261
#endif
32623262

32633263
// <o> NRFX_SPIM_MISO_PULL_CFG - MISO pin pull configuration.

0 commit comments

Comments
 (0)