Skip to content

Commit d7f3e70

Browse files
adustmmaciejbocianski
authored andcommitted
Move _mode from QSPI::configure_format to QSPI::QSPI
QSPI::configure_format shall not call initialize function. This way, QSPI::configure_format can be called any time, only to change the format of commands. It must contain only parameters for the commands, not for the Init function
1 parent 99e6257 commit d7f3e70

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

drivers/QSPI.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace mbed {
2525
QSPI* QSPI::_owner = NULL;
2626
SingletonPtr<PlatformMutex> QSPI::_mutex;
2727

28-
QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel) : _qspi()
28+
QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel, int mode) : _qspi()
2929
{
3030
_qspi_io0 = io0;
3131
_qspi_io1 = io1;
@@ -39,34 +39,26 @@ QSPI::QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, Pin
3939
_alt_width = QSPI_CFG_BUS_SINGLE;
4040
_alt_size = QSPI_CFG_ALT_SIZE_8;
4141
_data_width = QSPI_CFG_BUS_SINGLE;
42-
_mode = 0;
42+
_mode = mode;
4343
_hz = ONE_MHZ;
4444
_initialized = false;
4545

4646
//Go ahead init the device here with the default config
4747
_initialize();
4848
}
4949

50-
qspi_status_t QSPI::configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width, qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width, int dummy_cycles, int mode )
50+
qspi_status_t QSPI::configure_format(qspi_bus_width_t inst_width, qspi_bus_width_t address_width, qspi_address_size_t address_size, qspi_bus_width_t alt_width, qspi_alt_size_t alt_size, qspi_bus_width_t data_width, int dummy_cycles)
5151
{
5252
qspi_status_t ret_status = QSPI_STATUS_OK;
5353

54-
if (mode != 0 && mode != 1)
55-
return QSPI_STATUS_INVALID_PARAMETER;
56-
5754
lock();
5855
_inst_width = inst_width;
5956
_address_width = address_width;
6057
_address_size = address_size;
6158
_alt_width = alt_width;
6259
_alt_size = alt_size;
6360
_data_width = data_width;
64-
_mode = mode;
6561

66-
//Re-init the device, as the mode might have changed
67-
if ( !_initialize() ) {
68-
ret_status = QSPI_STATUS_ERROR;
69-
}
7062
unlock();
7163

7264
return ret_status;
@@ -223,6 +215,9 @@ void QSPI::unlock()
223215
// Note: Private helper function to initialize qspi HAL
224216
bool QSPI::_initialize()
225217
{
218+
if (_mode != 0 && _mode != 1)
219+
return QSPI_STATUS_INVALID_PARAMETER;
220+
226221
qspi_status_t ret = qspi_init(&_qspi, _qspi_io0, _qspi_io1, _qspi_io2, _qspi_io3, _qspi_clk, _qspi_cs, _hz, _mode );
227222
if (QSPI_STATUS_OK == ret) {
228223
_initialized = true;

drivers/QSPI.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ class QSPI : private NonCopyable<QSPI> {
7676
* @param io3 4th IO pin used for sending/receiving data during data phase of a transaction
7777
* @param sclk QSPI Clock pin
7878
* @param ssel QSPI chip select pin
79+
* @param mode Mode specifies the SPI mode(Mode=0 uses CPOL=0, CPHA=0, Mode=1 uses CPOL=1, CPHA=1)
80+
* default value = 0
81+
*
7982
*/
80-
QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel=NC);
83+
QSPI(PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel=NC, int mode=0);
8184

8285
/** Configure the data transmission format
8386
*
@@ -88,7 +91,6 @@ class QSPI : private NonCopyable<QSPI> {
8891
* @param alt_size Size in bits used by alt phase(Valid values are 8,16,24,32)
8992
* @param data_width Bus width used by data phase(Valid values are 1,2,4)
9093
* @param dummy_cycles Number of dummy clock cycles to be used after alt phase
91-
* @param mode Mode specifies the SPI mode(Mode=0 uses CPOL=0, CPHA=0, Mode=1 uses CPOL=1, CPHA=1)
9294
*
9395
*/
9496
qspi_status_t configure_format(qspi_bus_width_t inst_width,
@@ -97,8 +99,7 @@ class QSPI : private NonCopyable<QSPI> {
9799
qspi_bus_width_t alt_width,
98100
qspi_alt_size_t alt_size,
99101
qspi_bus_width_t data_width,
100-
int dummy_cycles,
101-
int mode);
102+
int dummy_cycles);
102103

103104
/** Set the qspi bus clock frequency
104105
*

0 commit comments

Comments
 (0)