Skip to content

Commit 0cb0bd0

Browse files
committed
atmel-samd: More updates to the docs including the in-code docs.
1 parent 7ebc9a4 commit 0cb0bd0

File tree

2 files changed

+104
-121
lines changed

2 files changed

+104
-121
lines changed

index.rst

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
Adafruit's MicroPython API Reference
1+
Adafruit MicroPython API Reference
22
========================================
33

4-
Welcome! This is the documentation for Adafruit's version MicroPython. It is an
5-
open source derivative of MicroPython for use on educational development boards
6-
designed and sold by Adafruit including the Arduino Zero, Adafruit Feather M0
7-
Basic, Adafruit Feather HUZZAH and Adafruit Feather M0 Bluefruit LE.
4+
Welcome! This is the documentation for Adafruit MicroPython. It is an open
5+
source derivative of `MicroPython <https://micropython.org>`_ for use on
6+
educational development boards designed and sold by `Adafruit
7+
<https://adafruit.com>`_ including the `Arduino Zero
8+
<https://www.arduino.cc/en/Main/ArduinoBoardZero>`_, `Adafruit Feather M0 Basic
9+
<https://www.adafruit.com/product/2772>`_, `Adafruit Feather HUZZAH
10+
<https://www.adafruit.com/products/2821>`_ and `Adafruit Feather M0 Bluefruit LE
11+
<https://www.adafruit.com/products/2995>`_.
812

913
Adafruit's MicroPython port features a unified Python APIs available under
1014
`shared-bindings` and a growing list of drivers that work with it. Currently
1115
only the Atmel SAMD21 port is supported but ESP8266 support will be added in the
1216
near future.
1317

14-
Adafruit has many excellent tutorials available through the Adafruit Learning
15-
System. These docs are low-level API docs and may link out to separate getting
16-
started guides.
18+
`Adafruit <https://adafruit.com>`_ has many excellent tutorials available
19+
through the `Adafruit Learning System <https://learn.adafruit.com/>`_. These
20+
docs are low-level API docs and may link out to separate getting started guides.
1721

1822
.. toctree::
1923
:maxdepth: 2

shared-bindings/modules/machine.c

+92-113
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,29 @@
3838
//| =================================================
3939
//|
4040
//| .. module:: machine
41-
//| :synopsis: functions related to the board
41+
//| :synopsis: functions related to the board
42+
//| :platform: SAMD21
4243
//|
4344
//| The ``machine`` module contains specific functions related to the board.
4445
//|
45-
//| This is soon to be renamed to distinguish it from upstream's machine!
46+
//| This is soon to be renamed to distinguish it from upstream's `machine`!
4647
//|
47-
//| .. currentmodule:: machine
48+
//| :class:`I2C` --- Two wire serial protocol
49+
//| ------------------------------------------
4850
//|
49-
//| class I2C -- a two-wire serial protocol
50-
//| =======================================
51+
//| .. class:: I2C(scl, sda, \*, freq=400000)
5152
//|
52-
//| I2C is a two-wire protocol for communicating between devices. At the
53-
//| physical level it consists of 2 wires: SCL and SDA, the clock and data lines
54-
//| respectively.
53+
//| I2C is a two-wire protocol for communicating between devices. At the
54+
//| physical level it consists of 2 wires: SCL and SDA, the clock and data lines
55+
//| respectively.
5556
//|
56-
//| I2C objects are created attached to a specific bus. They can be initialised
57-
//| when created, or initialised later on.
57+
//| I2C objects are created attached to a specific bus. They can be initialised
58+
//| when created, or initialised later on.
5859
//|
59-
//| Constructors
60-
//| ------------
61-
//| .. class:: I2C(scl, sda, \*, freq=400000)
60+
//| :param str scl: The clock pin
61+
//| :param str sda: The data pin
62+
//| :param int freq: The clock frequency
6263
//|
63-
//| Construct and return a new I2C object.
64-
//| See the init method below for a description of the arguments.
6564
STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *pos_args) {
6665
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, true);
6766
machine_i2c_obj_t *self = m_new_obj(machine_i2c_obj_t);
@@ -83,15 +82,22 @@ STATIC mp_obj_t machine_i2c_make_new(const mp_obj_type_t *type, size_t n_args, s
8382
return (mp_obj_t)self;
8483
}
8584

86-
//| .. method:: I2C.init()
85+
//| .. method:: I2C.init()
86+
//|
87+
//| Initializes control of the underlying hardware so other classes cannot
88+
//| use it.
89+
//|
8790
STATIC mp_obj_t machine_i2c_obj_init(mp_obj_t self_in) {
8891
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
8992
mp_hal_i2c_init(self);
9093
return self_in;
9194
}
9295
MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_init_obj, machine_i2c_obj_init);
9396

94-
//| .. method:: I2C.deinit()
97+
//| .. method:: I2C.deinit()
98+
//|
99+
//| Releases control of the underlying hardware so other classes can use it.
100+
//|
95101
STATIC mp_obj_t machine_i2c_obj_deinit(mp_obj_t self_in) {
96102
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
97103
mp_hal_i2c_deinit(self);
@@ -106,11 +112,11 @@ STATIC mp_obj_t machine_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) {
106112
}
107113
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_i2c_obj___exit___obj, 4, 4, machine_i2c_obj___exit__);
108114

109-
//| .. method:: I2C.scan()
115+
//| .. method:: I2C.scan()
110116
//|
111-
//| Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of
112-
//| those that respond. A device responds if it pulls the SDA line low after
113-
//| its address (including a read bit) is sent on the bus.
117+
//| Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of
118+
//| those that respond. A device responds if it pulls the SDA line low after
119+
//| its address (including a read bit) is sent on the bus.
114120
//|
115121
STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
116122
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -126,16 +132,14 @@ STATIC mp_obj_t machine_i2c_scan(mp_obj_t self_in) {
126132
}
127133
MP_DEFINE_CONST_FUN_OBJ_1(machine_i2c_scan_obj, machine_i2c_scan);
128134

129-
//| Standard bus operations
130-
//| -----------------------
135+
//| .. method:: I2C.readfrom(addr, nbytes)
131136
//|
132-
//| The following methods implement the standard I2C master read and write
133-
//| operations that target a given slave device.
137+
//| Read `nbytes` from the slave specified by `addr`.
134138
//|
135-
//| .. method:: I2C.readfrom(addr, nbytes)
136-
//|
137-
//| Read `nbytes` from the slave specified by `addr`.
138-
//| Returns a `bytes` object with the data read.
139+
//| :param int addr: The 7 bit address of the device
140+
//| :param int nbytes: The number of bytes to read
141+
//| :return: the data read
142+
//| :rtype: bytes
139143
//|
140144
STATIC mp_obj_t machine_i2c_readfrom(mp_obj_t self_in, mp_obj_t addr_in, mp_obj_t nbytes_in) {
141145
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -146,13 +150,10 @@ STATIC mp_obj_t machine_i2c_readfrom(mp_obj_t self_in, mp_obj_t addr_in, mp_obj_
146150
}
147151
MP_DEFINE_CONST_FUN_OBJ_3(machine_i2c_readfrom_obj, machine_i2c_readfrom);
148152

149-
//| .. method:: I2C.readfrom_into(addr, buf)
150-
//|
151-
//| Read into `buf` from the slave specified by `addr`.
152-
//| The number of bytes read will be the length of `buf`.
153+
//| .. method:: I2C.readfrom_into(addr, buf)
153154
//|
154-
//| On WiPy the return value is the number of bytes read. Otherwise the
155-
//| return value is `None`.
155+
//| Read into `buf` from the slave specified by `addr`.
156+
//| The number of bytes read will be the length of `buf`.
156157
//|
157158
STATIC mp_obj_t machine_i2c_readfrom_into(mp_obj_t self_in, mp_obj_t addr_in, mp_obj_t buf_in) {
158159
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -163,9 +164,9 @@ STATIC mp_obj_t machine_i2c_readfrom_into(mp_obj_t self_in, mp_obj_t addr_in, mp
163164
}
164165
MP_DEFINE_CONST_FUN_OBJ_3(machine_i2c_readfrom_into_obj, machine_i2c_readfrom_into);
165166

166-
//| .. method:: I2C.writeto(addr, buf)
167+
//| .. method:: I2C.writeto(addr, buf)
167168
//|
168-
//| Write the bytes from `buf` to the slave specified by `addr`.
169+
//| Write the bytes from `buf` to the slave specified by `addr`.
169170
//|
170171
STATIC mp_obj_t machine_i2c_writeto(mp_obj_t self_in, mp_obj_t addr_in, mp_obj_t buf_in) {
171172
machine_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -176,22 +177,13 @@ STATIC mp_obj_t machine_i2c_writeto(mp_obj_t self_in, mp_obj_t addr_in, mp_obj_t
176177
}
177178
STATIC MP_DEFINE_CONST_FUN_OBJ_3(machine_i2c_writeto_obj, machine_i2c_writeto);
178179

179-
//| Memory operations
180-
//| -----------------
180+
//| .. method:: I2C.readfrom_mem(addr, memaddr, nbytes, \*, addrsize=8)
181181
//|
182-
//| Some I2C devices act as a memory device (or set of registers) that can be
183-
//| read from and written to. In this case there are two addresses associated
184-
//| with an I2C transaction: the slave address and the memory address. The following
185-
//| following methods are convenience functions to communicate with such
186-
//| devices.
187-
//|
188-
//| .. method:: I2C.readfrom_mem(addr, memaddr, nbytes, \*, addrsize=8)
189-
//|
190-
//| Read `nbytes` from the slave specified by `addr` starting from the memory
191-
//| address specified by `memaddr`.
192-
//| The argument `addrsize` specifies the address size in bits (on ESP8266
193-
//| this argument is not recognised and the address size is always 8 bits).
194-
//| Returns a `bytes` object with the data read.
182+
//| Read `nbytes` from the slave specified by `addr` starting from the memory
183+
//| address specified by `memaddr`.
184+
//| The argument `addrsize` specifies the address size in bits (on ESP8266
185+
//| this argument is not recognised and the address size is always 8 bits).
186+
//| Returns a `bytes` object with the data read.
195187
//|
196188
STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
197189
enum { ARG_addr, ARG_memaddr, ARG_n, ARG_addrsize };
@@ -216,16 +208,13 @@ STATIC mp_obj_t machine_i2c_readfrom_mem(size_t n_args, const mp_obj_t *pos_args
216208
MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_readfrom_mem_obj, 1, machine_i2c_readfrom_mem);
217209

218210

219-
//| .. method:: I2C.readfrom_mem_into(addr, memaddr, buf, \*, addrsize=8)
211+
//| .. method:: I2C.readfrom_mem_into(addr, memaddr, buf, \*, addrsize=8)
220212
//|
221-
//| Read into `buf` from the slave specified by `addr` starting from the
222-
//| memory address specified by `memaddr`. The number of bytes read is the
223-
//| length of `buf`.
224-
//| The argument `addrsize` specifies the address size in bits (on ESP8266
225-
//| this argument is not recognised and the address size is always 8 bits).
226-
//|
227-
//| On WiPy the return value is the number of bytes read. Otherwise the
228-
//| return value is `None`.
213+
//| Read into `buf` from the slave specified by `addr` starting from the
214+
//| memory address specified by `memaddr`. The number of bytes read is the
215+
//| length of `buf`.
216+
//| The argument `addrsize` specifies the address size in bits (on ESP8266
217+
//| this argument is not recognised and the address size is always 8 bits).
229218
//|
230219
STATIC mp_obj_t machine_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
231220
enum { ARG_addr, ARG_memaddr, ARG_buf, ARG_addrsize };
@@ -249,15 +238,12 @@ STATIC mp_obj_t machine_i2c_readfrom_mem_into(size_t n_args, const mp_obj_t *pos
249238
}
250239
MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2c_readfrom_mem_into_obj, 1, machine_i2c_readfrom_mem_into);
251240

252-
//| .. method:: I2C.writeto_mem(addr, memaddr, buf, \*, addrsize=8)
253-
//|
254-
//| Write `buf` to the slave specified by `addr` starting from the
255-
//| memory address specified by `memaddr`.
256-
//| The argument `addrsize` specifies the address size in bits (on ESP8266
257-
//| this argument is not recognised and the address size is always 8 bits).
241+
//| .. method:: I2C.writeto_mem(addr, memaddr, buf, \*, addrsize=8)
258242
//|
259-
//| On WiPy the return value is the number of bytes written. Otherwise the
260-
//| return value is `None`.
243+
//| Write `buf` to the slave specified by `addr` starting from the
244+
//| memory address specified by `memaddr`.
245+
//| The argument `addrsize` specifies the address size in bits (on ESP8266
246+
//| this argument is not recognised and the address size is always 8 bits).
261247
//|
262248
STATIC mp_obj_t machine_i2c_writeto_mem(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
263249
enum { ARG_addr, ARG_memaddr, ARG_buf, ARG_addrsize };
@@ -309,31 +295,29 @@ const mp_obj_type_t machine_i2c_type = {
309295
.locals_dict = (mp_obj_dict_t*)&machine_i2c_locals_dict,
310296
};
311297

312-
//| class SPI -- a master-driven serial protocol
313-
//| ============================================
298+
//| :class:`SPI` -- a 3-4 wire serial protocol
299+
//| -----------------------------------------------
314300
//|
315-
//| SPI is a serial protocol that is driven by a master. This class only
316-
//| manages three of the four SPI lines: SCK, MOSI, MISO. Its up to the client
317-
//| to manage the appropriate slave select line.
301+
//| SPI is a serial protocol that has exlusive pins for data in and out of the
302+
//| master. It is typically faster than `I2C` because a separate pin is used to
303+
//| control the active slave rather than a transitted address. This class only
304+
//| manages three of the four SPI lines: `clock`, `MOSI`, `MISO`. Its up to the
305+
//| client to manage the appropriate slave select line. (This is common because
306+
//| multiple slaves can share the `clock`, `MOSI` and `MISO` lines and therefore
307+
//| the hardware.)
318308
//|
319-
//| Constructors
320-
//| ------------
309+
//| .. class:: SPI(clock, MOSI, MISO, baudrate=1000000)
321310
//|
322-
//| .. class:: SPI(clock, MOSI, MISO, baudrate=1000000)
311+
//| Construct an SPI object on the given bus. ``id`` can be only 0.
312+
//| With no additional parameters, the SPI object is created but not
313+
//| initialised (it has the settings from the last initialisation of
314+
//| the bus, if any). If extra arguments are given, the bus is initialised.
315+
//| See ``init`` for parameters of initialisation.
323316
//|
324-
//| Construct an SPI object on the given bus. ``id`` can be only 0.
325-
//| With no additional parameters, the SPI object is created but not
326-
//| initialised (it has the settings from the last initialisation of
327-
//| the bus, if any). If extra arguments are given, the bus is initialised.
328-
//| See ``init`` for parameters of initialisation.
329-
//|
330-
//| - ``clock`` is the pin to use for the clock.
331-
//| - ``MOSI`` is the Master Out Slave In pin.
332-
//| - ``MISO`` is the Master In Slave Out pin.
333-
//| - ``baudrate`` is the SCK clock rate.
334-
//|
335-
//| Methods
336-
//| -------
317+
//| - ``clock`` is the pin to use for the clock.
318+
//| - ``MOSI`` is the Master Out Slave In pin.
319+
//| - ``MISO`` is the Master In Slave Out pin.
320+
//| - ``baudrate`` is the SCK clock rate.
337321
//|
338322

339323
// TODO(tannewt): Support LSB SPI.
@@ -364,9 +348,9 @@ STATIC mp_obj_t machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, s
364348
return (mp_obj_t)self;
365349
}
366350

367-
//| .. method:: SPI.init()
351+
//| .. method:: SPI.init()
368352
//|
369-
//| Initialises the bus.
353+
//| Initialises the bus.
370354
//|
371355
STATIC mp_obj_t machine_spi_obj_init(mp_obj_t self_in) {
372356
machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -375,9 +359,9 @@ STATIC mp_obj_t machine_spi_obj_init(mp_obj_t self_in) {
375359
}
376360
MP_DEFINE_CONST_FUN_OBJ_1(machine_spi_init_obj, machine_spi_obj_init);
377361

378-
//| .. method:: SPI.deinit()
362+
//| .. method:: SPI.deinit()
379363
//|
380-
//| Turn off the SPI bus.
364+
//| Turn off the SPI bus.
381365
//|
382366
STATIC mp_obj_t machine_spi_obj_deinit(mp_obj_t self_in) {
383367
machine_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -393,11 +377,11 @@ STATIC mp_obj_t machine_spi_obj___exit__(size_t n_args, const mp_obj_t *args) {
393377
}
394378
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_spi_obj___exit___obj, 4, 4, machine_spi_obj___exit__);
395379

396-
//| .. method:: SPI.write_readinto(write_buf, read_buf)
380+
//| .. method:: SPI.write_readinto(write_buf, read_buf)
397381
//|
398-
//| Write from ``write_buf`` and read into ``read_buf``. Both buffers must have the
399-
//| same length. This is the same as a SPI transfer function on other platforms.
400-
//| Returns the number of bytes written
382+
//| Write from ``write_buf`` and read into ``read_buf``. Both buffers must have the
383+
//| same length. This is the same as a SPI transfer function on other platforms.
384+
//| Returns the number of bytes written
401385
//|
402386
STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self_in, mp_obj_t wr_buf, mp_obj_t rd_buf) {
403387
mp_buffer_info_t src;
@@ -413,15 +397,10 @@ STATIC mp_obj_t mp_machine_spi_write_readinto(mp_obj_t self_in, mp_obj_t wr_buf,
413397
}
414398
MP_DEFINE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj, mp_machine_spi_write_readinto);
415399

416-
//| Helper operations
417-
//| -----------------
418-
//| The below operations are finer grained operations based upon ``SPI.write_readinto``.
419-
//| They may be moved out of the core module later.
420-
//|
421-
//| .. method:: SPI.write(buf)
400+
//| .. method:: SPI.write(buf)
422401
//|
423-
//| Write the data contained in ``buf``.
424-
//| Returns the number of bytes written.
402+
//| Write the data contained in ``buf``.
403+
//| Returns the number of bytes written.
425404
//|
426405
STATIC mp_obj_t mp_machine_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
427406
mp_buffer_info_t src;
@@ -432,10 +411,10 @@ STATIC mp_obj_t mp_machine_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
432411
}
433412
MP_DEFINE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj, mp_machine_spi_write);
434413

435-
//| .. method:: SPI.read(nbytes, *, write=0x00)
414+
//| .. method:: SPI.read(nbytes, *, write=0x00)
436415
//|
437-
//| Read the ``nbytes`` while writing the data specified by ``write``.
438-
//| Return the number of bytes read.
416+
//| Read the ``nbytes`` while writing the data specified by ``write``.
417+
//| Return the number of bytes read.
439418
//|
440419
STATIC mp_obj_t mp_machine_spi_read(size_t n_args, const mp_obj_t *args) {
441420
vstr_t vstr;
@@ -446,11 +425,11 @@ STATIC mp_obj_t mp_machine_spi_read(size_t n_args, const mp_obj_t *args) {
446425
}
447426
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_read_obj, 2, 3, mp_machine_spi_read);
448427

449-
//| .. method:: SPI.readinto(buf, *, write=0x00)
428+
//| .. method:: SPI.readinto(buf, *, write=0x00)
450429
//|
451-
//| Read into the buffer specified by ``buf`` while writing the data specified by
452-
//| ``write``.
453-
//| Return the number of bytes read.
430+
//| Read into the buffer specified by ``buf`` while writing the data
431+
//| specified by ``write``.
432+
//| Return the number of bytes read.
454433
//|
455434
STATIC mp_obj_t mp_machine_spi_readinto(size_t n_args, const mp_obj_t *args) {
456435
mp_buffer_info_t bufinfo;

0 commit comments

Comments
 (0)