Skip to content

Commit 34c290b

Browse files
author
Daniel Campora
committed
cc3200: Rename SPI nss param to cs.
The nss param in the pyboard has a different meaning that doesn't apply to the WiPy.
1 parent ea5061e commit 34c290b

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

cc3200/mods/pybspi.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
/// parameters to init the SPI bus:
5555
///
5656
/// from pyb import SPI
57-
/// spi = SPI(1, SPI.MASTER, baudrate=2000000, bits=8, polarity=0, phase=0, nss=SPI.ACTIVE_LOW)
57+
/// spi = SPI(1, SPI.MASTER, baudrate=2000000, bits=8, polarity=0, phase=0, cs_polarity=SPI.ACTIVE_LOW)
5858
///
5959
/// Only required parameter is the baudrate, in Hz. polarity and phase may be 0 or 1.
6060
/// Bit accepts 8, 16, 32. Chip select values are ACTIVE_LOW and ACTIVE_HIGH
@@ -168,15 +168,15 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
168168
pyb_spi_obj_t *self = self_in;
169169

170170
if (self->baudrate > 0) {
171-
mp_printf(print, "<SPI1, SPI.MASTER, baudrate=%u, bits=%u, polarity=%u, phase=%u, nss=%q>",
171+
mp_printf(print, "<SPI1, SPI.MASTER, baudrate=%u, bits=%u, polarity=%u, phase=%u, cs_polarity=%q>",
172172
self->baudrate, (self->wlen * 8), self->polarity, self->phase,
173173
(self->config & SPI_CS_ACTIVELOW) ? MP_QSTR_ACTIVE_LOW : MP_QSTR_ACTIVE_HIGH);
174174
} else {
175175
mp_print_str(print, "<SPI1>");
176176
}
177177
}
178178

179-
/// \method init(mode, *, baudrate=1000000, bits=8, polarity=0, phase=0, nss=SPI.ACTIVE_LOW)
179+
/// \method init(mode, *, baudrate=1000000, bits=8, polarity=0, phase=0, cs_polarity=SPI.ACTIVE_LOW)
180180
///
181181
/// Initialise the SPI bus with the given parameters:
182182
///
@@ -185,14 +185,14 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
185185
/// - `bits` is the transfer width size (8, 16, 32).
186186
/// - `polarity` (0, 1).
187187
/// - `phase` (0, 1).
188-
/// - `nss` can be ACTIVE_LOW or ACTIVE_HIGH.
188+
/// - `cs_polarity` can be ACTIVE_LOW or ACTIVE_HIGH.
189189
static const mp_arg_t pybspi_init_args[] = {
190190
{ MP_QSTR_mode, MP_ARG_REQUIRED | MP_ARG_INT, },
191191
{ MP_QSTR_baudrate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = PYBSPI_DEF_BAUDRATE} },
192192
{ MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
193193
{ MP_QSTR_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
194194
{ MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
195-
{ MP_QSTR_nss, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SPI_CS_ACTIVELOW} },
195+
{ MP_QSTR_cs_polarity, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = SPI_CS_ACTIVELOW} },
196196
};
197197

198198
STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -227,15 +227,15 @@ STATIC mp_obj_t pyb_spi_init_helper(pyb_spi_obj_t *self, mp_uint_t n_args, const
227227
goto invalid_args;
228228
}
229229

230-
uint nss = args[5].u_int;
231-
if (nss != SPI_CS_ACTIVELOW && nss != SPI_CS_ACTIVEHIGH) {
230+
uint cs = args[5].u_int;
231+
if (cs != SPI_CS_ACTIVELOW && cs != SPI_CS_ACTIVEHIGH) {
232232
goto invalid_args;
233233
}
234234

235235
// build the configuration
236236
self->baudrate = args[1].u_int;
237237
self->wlen = args[2].u_int >> 3;
238-
self->config = bits | nss | SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF;
238+
self->config = bits | cs | SPI_SW_CTRL_CS | SPI_4PIN_MODE | SPI_TURBO_OFF;
239239
self->polarity = polarity;
240240
self->phase = phase;
241241
self->submode = (polarity << 1) | phase;

cc3200/qstrdefsport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ Q(baudrate)
345345
Q(bits)
346346
Q(polarity)
347347
Q(phase)
348-
Q(nss)
348+
Q(cs_polarity)
349349
Q(init)
350350
Q(deinit)
351351
Q(send)

docs/library/pyb.SPI.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ there are 3 lines: SCK, MOSI, MISO.
2525
parameters to init the SPI bus::
2626
2727
from pyb import SPI
28-
spi = SPI(1, SPI.MASTER, baudrate=1000000, polarity=0, phase=0, nss=SPI.ACTIVE_LOW)
28+
spi = SPI(1, SPI.MASTER, baudrate=1000000, polarity=0, phase=0, cs_polarity=SPI.ACTIVE_LOW)
2929

3030
Only required parameter is mode, must be SPI.MASTER. Polarity can be 0 or
3131
1, and is the level the idle clock line sits at. Phase can be 0 or 1 to
@@ -115,8 +115,7 @@ Methods
115115
- ``phase`` can be 0 or 1 to sample data on the first or second clock edge
116116
respectively.
117117
- ``bits`` is the width of each transfer, accepted values are 8, 16 and 32.
118-
- ``nss`` is the polarity of the slave select line. Can be ``SPI.ACTIVE_LOW``
119-
or ``SPI.ACTIVE_HIGH``.
118+
- ``cs_polarity`` can be ``SPI.ACTIVE_LOW`` or ``SPI.ACTIVE_HIGH``.
120119

121120
Note that the SPI clock frequency will not always be the requested baudrate.
122121
Printing the SPI object will show you the computed baudrate and the chosen

0 commit comments

Comments
 (0)