Browse Source

cc3200: Make I2C and SPI API the same as in stmhal.

pull/1401/merge
Daniel Campora 9 years ago
parent
commit
c6926c374d
  1. 3
      cc3200/mods/pybi2c.c
  2. 83
      cc3200/mods/pybspi.c
  3. 2
      cc3200/qstrdefsport.h
  4. 80
      docs/library/pyb.I2C.rst
  5. 47
      docs/library/pyb.SPI.rst

3
cc3200/mods/pybi2c.c

@ -380,6 +380,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_i2c_scan_obj, pyb_i2c_scan);
STATIC const mp_arg_t pyb_i2c_send_args[] = { STATIC const mp_arg_t pyb_i2c_send_args[] = {
{ MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_addr, MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
}; };
#define PYB_I2C_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_send_args) #define PYB_I2C_SEND_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_send_args)
@ -415,6 +416,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_i2c_send_obj, 1, pyb_i2c_send);
STATIC const mp_arg_t pyb_i2c_recv_args[] = { STATIC const mp_arg_t pyb_i2c_recv_args[] = {
{ MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_addr, MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_addr, MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
}; };
#define PYB_I2C_RECV_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_recv_args) #define PYB_I2C_RECV_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_recv_args)
@ -457,6 +459,7 @@ STATIC const mp_arg_t pyb_i2c_mem_read_args[] = {
{ MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, }, { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_addr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, { MP_QSTR_memaddr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
{ MP_QSTR_addr_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, { MP_QSTR_addr_size, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} },
}; };
#define PYB_I2C_MEM_READ_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_mem_read_args) #define PYB_I2C_MEM_READ_NUM_ARGS MP_ARRAY_SIZE(pyb_i2c_mem_read_args)

83
cc3200/mods/pybspi.c

@ -171,13 +171,12 @@ STATIC void pyb_spi_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki
mp_printf(print, "<SPI1, SPI.MASTER, baudrate=%u, bits=%u, polarity=%u, phase=%u, nss=%q>", mp_printf(print, "<SPI1, SPI.MASTER, baudrate=%u, bits=%u, polarity=%u, phase=%u, nss=%q>",
self->baudrate, (self->wlen * 8), self->polarity, self->phase, self->baudrate, (self->wlen * 8), self->polarity, self->phase,
(self->config & SPI_CS_ACTIVELOW) ? MP_QSTR_ACTIVE_LOW : MP_QSTR_ACTIVE_HIGH); (self->config & SPI_CS_ACTIVELOW) ? MP_QSTR_ACTIVE_LOW : MP_QSTR_ACTIVE_HIGH);
} } else {
else {
mp_print_str(print, "<SPI1>"); mp_print_str(print, "<SPI1>");
} }
} }
/// \method init(mode, *, baudrate=1000000, bits=8, polarity=0, phase=0, nss=SPI.ACTIVELOW) /// \method init(mode, *, baudrate=1000000, bits=8, polarity=0, phase=0, nss=SPI.ACTIVE_LOW)
/// ///
/// Initialise the SPI bus with the given parameters: /// Initialise the SPI bus with the given parameters:
/// ///
@ -260,7 +259,6 @@ invalid_args:
/// initialised (it has the settings from the last initialisation of /// initialised (it has the settings from the last initialisation of
/// the bus, if any). If extra arguments are given, the bus is initialised. /// the bus, if any). If extra arguments are given, the bus is initialised.
/// See `init` for parameters of initialisation. /// See `init` for parameters of initialisation.
///
STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t pyb_spi_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
// check arguments // check arguments
mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true); mp_arg_check_num(n_args, n_kw, 1, MP_OBJ_FUN_ARGS_MAX, true);
@ -297,39 +295,59 @@ STATIC mp_obj_t pyb_spi_deinit(mp_obj_t self_in) {
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit); STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_spi_deinit_obj, pyb_spi_deinit);
/// \method send(send) /// \method send(send, *, timeout=5000)
/// Send data on the bus: /// Send data on the bus:
/// ///
/// - `send` is the data to send (a byte to send, or a buffer object). /// - `send` is the data to send (a byte to send, or a buffer object).
/// - `timeout` is the timeout in milliseconds to wait for the send.
/// ///
STATIC mp_obj_t pyb_spi_send (mp_obj_t self_in, mp_obj_t send_o) { STATIC mp_obj_t pyb_spi_send (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
pyb_spi_obj_t *self = self_in; static const mp_arg_t allowed_args[] = {
{ MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
};
// parse args
pyb_spi_obj_t *self = pos_args[0];
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// get the buffer to send from // get the buffer to send from
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
uint8_t data[1]; uint8_t data[1];
pyb_buf_get_for_send(send_o, &bufinfo, data); pyb_buf_get_for_send(args[0].u_obj, &bufinfo, data);
// just send // just send
pybspi_transfer(self, (const char *)bufinfo.buf, NULL, bufinfo.len); pybspi_transfer(self, (const char *)bufinfo.buf, NULL, bufinfo.len);
return mp_const_none; return mp_const_none;
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_send_obj, pyb_spi_send); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_obj, 1, pyb_spi_send);
/// \method recv(recv) /// \method recv(recv, *, timeout=5000)
/// ///
/// Receive data on the bus: /// Receive data on the bus:
/// ///
/// - `recv` can be an integer, which is the number of bytes to receive, /// - `recv` can be an integer, which is the number of bytes to receive,
/// or a mutable buffer, which will be filled with received bytes. /// or a mutable buffer, which will be filled with received bytes.
/// - `timeout` is the timeout in milliseconds to wait for the receive.
/// ///
/// Return: if `recv` is an integer then a new buffer of the bytes received, /// Return: if `recv` is an integer then a new buffer of the bytes received,
/// otherwise the same buffer that was passed in to `recv`. /// otherwise the same buffer that was passed in to `recv`.
STATIC mp_obj_t pyb_spi_recv(mp_obj_t self_in, mp_obj_t recv_o) { STATIC mp_obj_t pyb_spi_recv(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
pyb_spi_obj_t *self = self_in; static const mp_arg_t allowed_args[] = {
{ MP_QSTR_recv, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
};
// parse args
pyb_spi_obj_t *self = pos_args[0];
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// get the buffer to receive into // get the buffer to receive into
vstr_t vstr; vstr_t vstr;
mp_obj_t o_ret = pyb_buf_get_for_recv(recv_o, &vstr); mp_obj_t o_ret = pyb_buf_get_for_recv(args[0].u_obj, &vstr);
// just receive // just receive
pybspi_transfer(self, NULL, vstr.buf, vstr.len); pybspi_transfer(self, NULL, vstr.buf, vstr.len);
@ -341,9 +359,9 @@ STATIC mp_obj_t pyb_spi_recv(mp_obj_t self_in, mp_obj_t recv_o) {
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
} }
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_recv_obj, pyb_spi_recv); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_recv_obj, 1, pyb_spi_recv);
/// \method send_recv(send, recv) /// \method send_recv(send, recv=None, *, timeout=5000)
/// ///
/// Send and receive data on the bus at the same time: /// Send and receive data on the bus at the same time:
/// ///
@ -351,10 +369,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_spi_recv_obj, pyb_spi_recv);
/// - `recv` is a mutable buffer which will be filled with received bytes. /// - `recv` is a mutable buffer which will be filled with received bytes.
/// It can be the same as `send`, or omitted. If omitted, a new buffer will /// It can be the same as `send`, or omitted. If omitted, a new buffer will
/// be created. /// be created.
/// - `timeout` is the timeout in milliseconds to wait for the transaction to complete.
/// ///
/// Return: the buffer with the received bytes. /// Return: the buffer with the received bytes.
STATIC mp_obj_t pyb_spi_send_recv (mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t pyb_spi_send_recv (mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
pyb_spi_obj_t *self = args[0]; static const mp_arg_t allowed_args[] = {
{ MP_QSTR_send, MP_ARG_REQUIRED | MP_ARG_OBJ, },
{ MP_QSTR_recv, MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5000} },
};
// parse args
pyb_spi_obj_t *self = pos_args[0];
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
// get buffers to send from/receive to // get buffers to send from/receive to
mp_buffer_info_t bufinfo_send; mp_buffer_info_t bufinfo_send;
@ -363,35 +391,34 @@ STATIC mp_obj_t pyb_spi_send_recv (mp_uint_t n_args, const mp_obj_t *args) {
vstr_t vstr_recv; vstr_t vstr_recv;
mp_obj_t o_ret; mp_obj_t o_ret;
if (args[1] == args[2]) { if (args[0].u_obj == args[1].u_obj) {
// same object for sending and receiving, it must be a r/w buffer // same object for sending and receiving, it must be a r/w buffer
mp_get_buffer_raise(args[1], &bufinfo_send, MP_BUFFER_RW); mp_get_buffer_raise(args[0].u_obj, &bufinfo_send, MP_BUFFER_RW);
bufinfo_recv = bufinfo_send; bufinfo_recv = bufinfo_send;
o_ret = args[1]; o_ret = args[0].u_obj;
} else { } else {
// get the buffer to send from // get the buffer to send from
pyb_buf_get_for_send(args[1], &bufinfo_send, data_send); pyb_buf_get_for_send(args[0].u_obj, &bufinfo_send, data_send);
// get the buffer to receive into // get the buffer to receive into
if (n_args == 2) { if (args[1].u_obj == mp_const_none) {
// only the send was argument given, so create a fresh buffer of the send length // only the send was argument given, so create a fresh buffer of the send length
vstr_init_len(&vstr_recv, bufinfo_send.len); vstr_init_len(&vstr_recv, bufinfo_send.len);
bufinfo_recv.len = vstr_recv.len; bufinfo_recv.len = vstr_recv.len;
bufinfo_recv.buf = vstr_recv.buf; bufinfo_recv.buf = vstr_recv.buf;
o_ret = MP_OBJ_NULL; o_ret = MP_OBJ_NULL;
} } else {
else {
// recv argument given // recv argument given
mp_get_buffer_raise(args[2], &bufinfo_recv, MP_BUFFER_WRITE); mp_get_buffer_raise(args[1].u_obj, &bufinfo_recv, MP_BUFFER_WRITE);
if (bufinfo_recv.len != bufinfo_send.len) { if (bufinfo_recv.len != bufinfo_send.len) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
} }
o_ret = args[2]; o_ret = args[1].u_obj;
} }
} }
// send and receive // send and receive
pybspi_transfer(self, (const char *)bufinfo_send.buf, vstr_recv.buf, bufinfo_send.len); pybspi_transfer(self, (const char *)bufinfo_send.buf, bufinfo_recv.buf, bufinfo_send.len);
// return the received data // return the received data
if (o_ret != MP_OBJ_NULL) { if (o_ret != MP_OBJ_NULL) {
@ -400,7 +427,7 @@ STATIC mp_obj_t pyb_spi_send_recv (mp_uint_t n_args, const mp_obj_t *args) {
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr_recv); return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr_recv);
} }
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_spi_send_recv_obj, 2, 3, pyb_spi_send_recv); STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_spi_send_recv_obj, 1, pyb_spi_send_recv);
STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = { STATIC const mp_map_elem_t pyb_spi_locals_dict_table[] = {
// instance methods // instance methods

2
cc3200/qstrdefsport.h

@ -166,6 +166,7 @@ Q(mode)
Q(baudrate) Q(baudrate)
Q(addr) Q(addr)
Q(data) Q(data)
Q(timeout)
Q(memaddr) Q(memaddr)
Q(addr_size) Q(addr_size)
Q(init) Q(init)
@ -348,6 +349,7 @@ Q(deinit)
Q(send) Q(send)
Q(recv) Q(recv)
Q(send_recv) Q(send_recv)
Q(timeout)
Q(MASTER) Q(MASTER)
Q(ACTIVE_LOW) Q(ACTIVE_LOW)
Q(ACTIVE_HIGH) Q(ACTIVE_HIGH)

80
docs/library/pyb.I2C.rst

@ -45,8 +45,6 @@ To receive inplace, first create a bytearray::
data = bytearray(3) # create a buffer data = bytearray(3) # create a buffer
i2c.recv(data) # receive 3 bytes, writing them into data i2c.recv(data) # receive 3 bytes, writing them into data
.. only:: port_pyboard
You can specify a timeout (in ms):: You can specify a timeout (in ms)::
i2c.send(b'123', timeout=2000) # timout after 2 seconds i2c.send(b'123', timeout=2000) # timout after 2 seconds
@ -57,8 +55,6 @@ A master must specify the recipient's address::
i2c.send('123', 0x42) # send 3 bytes to slave with address 0x42 i2c.send('123', 0x42) # send 3 bytes to slave with address 0x42
i2c.send(b'456', addr=0x42) # keyword for address i2c.send(b'456', addr=0x42) # keyword for address
.. only:: port_pyboard
Master also has other methods:: Master also has other methods::
i2c.is_ready(0x42) # check if slave 0x42 is ready i2c.is_ready(0x42) # check if slave 0x42 is ready
@ -66,20 +62,8 @@ A master must specify the recipient's address::
# a list of valid addresses # a list of valid addresses
i2c.mem_read(3, 0x42, 2) # read 3 bytes from memory of slave 0x42, i2c.mem_read(3, 0x42, 2) # read 3 bytes from memory of slave 0x42,
# starting at address 2 in the slave # starting at address 2 in the slave
i2c.mem_write('abc', 0x42, 2, timeout=1000) i2c.mem_write('abc', 0x42, 2, timeout=1000) # write 'abc' (3 bytes) to memory of slave 0x42
# starting at address 2 in the slave, timeout after 1 second
.. only:: port_wipy
There are also other methods::
i2c.is_ready(0x42) # check if slave 0x42 is ready
i2c.scan() # scan for slaves on the bus, returning
# a list of valid addresses
i2c.mem_read(3, 0x42, 2) # read 3 bytes from memory of slave 0x42,
# starting at address 2 in the slave
i2c.mem_write('abc', 0x42, 2) # write 'abc' (3 bytes) to memory of slave 0x42
# starting at address 2 in the slave
Constructors Constructors
------------ ------------
@ -141,8 +125,6 @@ Methods
Check if an I2C device responds to the given address. Only valid when in master mode. Check if an I2C device responds to the given address. Only valid when in master mode.
.. only:: port_pyboard
.. method:: i2c.mem_read(data, addr, memaddr, timeout=5000, addr_size=8) .. method:: i2c.mem_read(data, addr, memaddr, timeout=5000, addr_size=8)
Read from the memory of an I2C device: Read from the memory of an I2C device:
@ -156,22 +138,6 @@ Methods
Returns the read data. Returns the read data.
This is only valid in master mode. This is only valid in master mode.
.. only:: port_wipy
.. method:: i2c.mem_read(data, addr, memaddr, addr_size=8)
Read from the memory of an I2C device:
- ``data`` can be an integer (number of bytes to read) or a buffer to read into
- ``addr`` is the I2C device address
- ``memaddr`` is the memory location within the I2C device
- ``addr_size`` selects width of memaddr: 8 or 16 bits
Returns the read data.
This is only valid in master mode.
.. only:: port_pyboard
.. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8) .. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8)
Write to the memory of an I2C device: Write to the memory of an I2C device:
@ -185,22 +151,6 @@ Methods
Returns ``None``. Returns ``None``.
This is only valid in master mode. This is only valid in master mode.
.. only:: port_wipy
.. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8)
Write to the memory of an I2C device:
- ``data`` can be an integer or a buffer to write from
- ``addr`` is the I2C device address
- ``memaddr`` is the memory location within the I2C device
- ``addr_size`` selects width of memaddr: 8 or 16 bits
Returns ``None``.
This is only valid in master mode.
.. only:: port_pyboard
.. method:: i2c.recv(recv, addr=0x00, timeout=5000) .. method:: i2c.recv(recv, addr=0x00, timeout=5000)
Receive data on the bus: Receive data on the bus:
@ -213,26 +163,11 @@ Methods
Return value: if ``recv`` is an integer then a new buffer of the bytes received, Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``. otherwise the same buffer that was passed in to ``recv``.
.. only:: port_wipy
.. method:: i2c.recv(recv, addr=0x00)
Receive data on the bus:
- ``recv`` can be an integer, which is the number of bytes to receive,
or a mutable buffer, which will be filled with received bytes
- ``addr`` is the address to receive from (only required in master mode)
Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``.
.. method:: i2c.scan() .. method:: i2c.scan()
Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond. Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
Only valid when in master mode. Only valid when in master mode.
.. only:: port_pyboard
.. method:: i2c.send(send, addr=0x00, timeout=5000) .. method:: i2c.send(send, addr=0x00, timeout=5000)
Send data on the bus: Send data on the bus:
@ -243,17 +178,6 @@ Methods
Return value: ``None``. Return value: ``None``.
.. only:: port_wipy
.. method:: i2c.send(send, addr=0x00)
Send data on the bus:
- ``send`` is the data to send (an integer to send, or a buffer object)
- ``addr`` is the address to send to (only required in master mode)
Return value: ``None``.
Constants Constants
--------- ---------

47
docs/library/pyb.SPI.rst

@ -25,7 +25,7 @@ there are 3 lines: SCK, MOSI, MISO.
parameters to init the SPI bus:: parameters to init the SPI bus::
from pyb import SPI from pyb import SPI
spi = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0) spi = SPI(1, SPI.MASTER, baudrate=1000000, polarity=0, phase=0, nss=SPI.ACTIVE_LOW)
Only required parameter is mode, must be SPI.MASTER. Polarity can be 0 or Only required parameter is mode, must be SPI.MASTER. Polarity can be 0 or
1, and is the level the idle clock line sits at. Phase can be 0 or 1 to 1, and is the level the idle clock line sits at. Phase can be 0 or 1 to
@ -105,7 +105,7 @@ Methods
.. only:: port_wipy .. only:: port_wipy
.. method:: spi.init(mode, baudrate=328125, \*, polarity=1, phase=0, bits=8, nss=SPI.ACTIVE_LOW) .. method:: spi.init(mode, baudrate=1000000, \*, polarity=0, phase=0, bits=8, nss=SPI.ACTIVE_LOW)
Initialise the SPI bus with the given parameters: Initialise the SPI bus with the given parameters:
@ -122,8 +122,6 @@ Methods
Printing the SPI object will show you the computed baudrate and the chosen Printing the SPI object will show you the computed baudrate and the chosen
prescaler. prescaler.
.. only:: port_pyboard
.. method:: spi.recv(recv, \*, timeout=5000) .. method:: spi.recv(recv, \*, timeout=5000)
Receive data on the bus: Receive data on the bus:
@ -135,20 +133,6 @@ Methods
Return value: if ``recv`` is an integer then a new buffer of the bytes received, Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``. otherwise the same buffer that was passed in to ``recv``.
.. only:: port_wipy
.. method:: spi.recv(recv)
Receive data on the bus:
- ``recv`` can be an integer, which is the number of bytes to receive,
or a mutable buffer, which will be filled with received bytes.
Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``.
.. only:: port_pyboard
.. method:: spi.send(send, \*, timeout=5000) .. method:: spi.send(send, \*, timeout=5000)
Send data on the bus: Send data on the bus:
@ -158,18 +142,6 @@ Methods
Return value: ``None``. Return value: ``None``.
.. only:: port_wipy
.. method:: spi.send(send)
Send data on the bus:
- ``send`` is the data to send (an integer to send, or a buffer object).
Return value: ``None``.
.. only:: port_pyboard
.. method:: spi.send_recv(send, recv=None, \*, timeout=5000) .. method:: spi.send_recv(send, recv=None, \*, timeout=5000)
Send and receive data on the bus at the same time: Send and receive data on the bus at the same time:
@ -182,19 +154,6 @@ Methods
Return value: the buffer with the received bytes. Return value: the buffer with the received bytes.
.. only:: port_wipy
.. method:: spi.send_recv(send, recv=None)
Send and receive data on the bus at the same time:
- ``send`` is the data to send (an integer to send, or a buffer object).
- ``recv`` is a mutable buffer which will be filled with received bytes.
It can be the same as ``send``, or omitted. If omitted, a new buffer will
be created.
Return value: the buffer with the received bytes.
Constants Constants
--------- ---------
@ -219,4 +178,4 @@ Constants
.. data:: SPI.ACTIVE_LOW .. data:: SPI.ACTIVE_LOW
.. data:: SPI.ACTIVE_HIGH .. data:: SPI.ACTIVE_HIGH
decides the polarity of the NSS pin selects the polarity of the NSS pin

Loading…
Cancel
Save