Skip to content

HW SSEL Support for SPI API #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions libraries/mbed/api/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,21 @@ namespace mbed {
*
* #include "mbed.h"
*
* // hardware ssel (where applicable)
* //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
*
* // software ssel
* SPI device(p5, p6, p7); // mosi, miso, sclk
* DigitalOut cs(p8); // ssel
*
* int main() {
* // hardware ssel (where applicable)
* //int response = device.write(0xFF);
*
* // software ssel
* cs = 0;
* int response = device.write(0xFF);
* cs = 1;
* }
* @endcode
*/
Expand All @@ -49,17 +60,15 @@ class SPI {
public:

/** Create a SPI master connected to the specified pins
*
* Pin Options:
* (5, 6, 7) or (11, 12, 13)
*
* mosi or miso can be specfied as NC if not used
*
* @param mosi SPI Master Out, Slave In pin
* @param miso SPI Master In, Slave Out pin
* @param sclk SPI Clock pin
* @param ssel SPI chip select pin
*/
SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused=NC);
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC);

/** Configure the data transmission format
*
Expand Down
4 changes: 0 additions & 4 deletions libraries/mbed/api/SPISlave.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,13 @@ class SPISlave {
public:

/** Create a SPI slave connected to the specified pins
*
* Pin Options:
* (5, 6, 7i, 8) or (11, 12, 13, 14)
*
* mosi or miso can be specfied as NC if not used
*
* @param mosi SPI Master Out, Slave In pin
* @param miso SPI Master In, Slave Out pin
* @param sclk SPI Clock pin
* @param ssel SPI chip select pin
* @param name (optional) A string to identify the object
*/
SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);

Expand Down
4 changes: 2 additions & 2 deletions libraries/mbed/common/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

namespace mbed {

SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused) :
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
_spi(),
_bits(8),
_mode(0),
_hz(1000000) {
spi_init(&_spi, mosi, miso, sclk, NC);
spi_init(&_spi, mosi, miso, sclk, ssel);
spi_format(&_spi, _bits, _mode, 0);
spi_frequency(&_spi, _hz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi->MCR &= ~(SPI_MCR_MDIS_MASK | SPI_MCR_HALT_MASK);
//obj->spi->MCR |= SPI_MCR_DIS_RXF_MASK | SPI_MCR_DIS_TXF_MASK;

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// not halt in the debug mode
obj->spi->SR |= SPI_SR_EOQF_MASK;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable SPI
obj->spi->C1 |= SPI_C1_SPE_MASK;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_1: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 23; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable SPI
obj->spi->C1 |= SPI_C1_SPE_MASK;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_1: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 23; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable SPI
obj->spi->C1 |= SPI_C1_SPE_MASK;
obj->spi->C2 &= ~SPI_C2_SPIMODE_MASK; //8bit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_1: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 23; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable SPI
obj->spi->C1 |= SPI_C1_SPE_MASK;
obj->spi->C2 &= ~SPI_C2_SPIMODE_MASK; //8bit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
uint32_t spi_address[] = SPI_BASE_ADDRS;
DSPI_HAL_Init(spi_address[obj->instance]);
DSPI_HAL_Disable(spi_address[obj->instance]);
// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
DSPI_HAL_SetDelay(spi_address[obj->instance], kDspiCtar0, 0, 0, kDspiPcsToSck);
spi_frequency(obj, 1000000);

DSPI_HAL_Enable(spi_address[obj->instance]);
DSPI_HAL_StartTransfer(spi_address[obj->instance]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
obj->spi->gen_ctrl = (MXC_F_SPI_GEN_CTRL_SPI_MSTR_EN |
MXC_F_SPI_GEN_CTRL_TX_FIFO_EN |
MXC_F_SPI_GEN_CTRL_RX_FIFO_EN );

// Give instance the default settings
spi_format(obj, DEFAULT_CHAR, DEFAULT_MODE, 0);
spi_frequency(obj, DEFAULT_FREQ);
}

//******************************************************************************
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11U6X/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC15XX/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
LPC_SYSCON->SYSAHBCLKCTRL1 |= (0x1 << (obj->spi_n + 9));
LPC_SYSCON->PRESETCTRL1 |= (0x1 << (obj->spi_n + 9));
LPC_SYSCON->PRESETCTRL1 &= ~(0x1 << (obj->spi_n + 9));

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the spi channel
spi_enable(obj);
}

void spi_free(spi_t *obj)
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_0: LPC_SC->PCONP |= 1 << 21; break;
case SPI_1: LPC_SC->PCONP |= 1 << 10; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_1: LPC_SC->PCONP |= 1 << 10; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_2: LPC_SC->PCONP |= 1 << 20; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_2: LPC_SC->PCONP |= 1 << 20; break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
pinmap_pinout(miso, PinMap_SPI_MISO);
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
case SPI_0: LPC_CGU->BASE_CLK[CLK_BASE_SSP0] = (1 << 11) | (CLKIN_MAINPLL << 24); break;
case SPI_1: LPC_CGU->BASE_CLK[CLK_BASE_SSP1] = (1 << 11) | (CLKIN_MAINPLL << 24); break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);

// pin out the spi pins
pinmap_pinout(mosi, PinMap_SPI_MOSI);
Expand Down
11 changes: 0 additions & 11 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,6 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
LPC_SYSCON->PRESETCTRL |= (0x1<<1);
break;
}

// set default format and frequency
if (ssel == NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);

// enable the ssp channel
ssp_enable(obj);
}

void spi_free(spi_t *obj) {}
Expand Down
10 changes: 0 additions & 10 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC82X/spi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,7 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
LPC_SYSCON->PRESETCTRL &= ~(1 << obj->spi_n);
LPC_SYSCON->PRESETCTRL |= (1 << obj->spi_n);

// set default format and frequency
if (ssel == (PinName)NC) {
spi_format(obj, 8, 0, 0); // 8 bits, mode 0, master
} else {
spi_format(obj, 8, 0, 1); // 8 bits, mode 0, slave
}
spi_frequency(obj, 1000000);
obj->spi->DLY = 2; // 2 SPI clock times pre-delay

// enable the ssp channel
spi_enable(obj);
}

void spi_free(spi_t *obj)
Expand Down
Loading