Skip to content

Commit 88cf0d5

Browse files
authored
Merge pull request #6 from sommersoft/new_docs
Improve Ref Docs
2 parents 2532abe + f86cad3 commit 88cf0d5

10 files changed

+214
-63
lines changed
File renamed without changes.

.travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ deploy:
1616
provider: releases
1717
api_key: $GITHUB_TOKEN
1818
file_glob: true
19-
file: bundles/*
19+
file: $TRAVIS_BUILD_DIR/bundles/*
2020
skip_cleanup: true
21+
overwrite: true
2122
on:
2223
tags: true
2324

2425
install:
25-
- pip install pylint circuitpython-build-tools
26+
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
2627

2728
script:
2829
- pylint adafruit_sdcard.py
2930
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py)
3031
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-sd --library_location .
32+
- cd docs && sphinx-build -E -W -b html . _build/html

README.rst

+44-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ Introduction
66
:target: https://circuitpython.readthedocs.io/projects/sdcard/en/latest/
77
:alt: Documentation Status
88

9-
.. image :: https://badges.gitter.im/adafruit/circuitpython.svg
10-
:target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
11-
:alt: Gitter
12-
139
.. image :: https://img.shields.io/discord/327254708534116352.svg
1410
:target: https://adafru.it/discord
1511
:alt: Discord
@@ -64,10 +60,49 @@ Contributions are welcome! Please read our `Code of Conduct
6460
<https://github.com/adafruit/Adafruit_CircuitPython_sdcard/blob/master/CODE_OF_CONDUCT.md>`_
6561
before contributing to help this project stay welcoming.
6662

67-
API Reference
68-
=============
63+
Building locally
64+
================
65+
66+
To build this library locally you'll need to install the
67+
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.
68+
69+
.. code-block:: shell
70+
71+
python3 -m venv .env
72+
source .env/bin/activate
73+
pip install circuitpython-build-tools
74+
75+
Once installed, make sure you are in the virtual environment:
76+
77+
.. code-block:: shell
78+
79+
source .env/bin/activate
80+
81+
Then run the build:
82+
83+
.. code-block:: shell
84+
85+
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-sd --library_location .
86+
87+
Sphinx documentation
88+
-----------------------
89+
90+
Sphinx is used to build the documentation based on rST files and comments in the code. First,
91+
install dependencies (feel free to reuse the virtual environment from above):
92+
93+
.. code-block:: shell
94+
95+
python3 -m venv .env
96+
source .env/bin/activate
97+
pip install Sphinx sphinx-rtd-theme
98+
99+
Now, once you have the virtual environment activated:
100+
101+
.. code-block:: shell
69102
70-
.. toctree::
71-
:maxdepth: 2
103+
cd docs
104+
sphinx-build -E -W -b html . _build/html
72105
73-
api
106+
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
107+
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
108+
locally verify it will pass.

adafruit_sdcard.py

+93-49
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,30 @@
2929
Requires an SPI bus and a CS pin. Provides readblocks and writeblocks
3030
methods so the device can be mounted as a filesystem.
3131
32-
Example usage:
32+
* Author(s): Scott Shawcroft
3333
34-
.. code-block:: python
34+
Implementation Notes
35+
--------------------
3536
36-
import busio
37-
import storage
38-
import adafruit_sdcard
39-
import os
40-
import board
37+
**Hardware:**
4138
42-
spi = busio.SPI(SCK, MOSI, MISO)
43-
sd = adafruit_sdcard.SDCard(spi, board.SD_CS)
44-
vfs = storage.VfsFat(sdcard)
45-
storage.mount(vfs, '/sd')
46-
os.listdir('/')
39+
* Adafruit `MicroSD card breakout board+
40+
<https://www.adafruit.com/product/254>`_ (Product ID: 254)
4741
48-
* Author(s): Scott Shawcroft
42+
* Adafruit `Assembled Data Logging shield for Arduino
43+
<https://www.adafruit.com/product/1141>`_ (Product ID: 1141)
44+
45+
* Adafruit `Feather M0 Adalogger
46+
<https://www.adafruit.com/product/2796>`_ (Product ID: 2796)
47+
48+
* Adalogger `FeatherWing - RTC + SD Add-on For All Feather Boards
49+
<https://www.adafruit.com/product/2922>`_ (Product ID: 2922)
50+
51+
**Software and Dependencies:**
52+
53+
* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards:
54+
https://github.com/adafruit/circuitpython/releases
55+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
4956
"""
5057

5158
import time
@@ -73,7 +80,25 @@ class SDCard:
7380
"""Controls an SD card over SPI.
7481
7582
:param ~busio.SPI spi: The SPI bus
76-
:param ~digitalio.DigitalInOut cs: The chip select connected to the card"""
83+
:param ~digitalio.DigitalInOut cs: The chip select connected to the card
84+
85+
Example usage:
86+
87+
.. code-block:: python
88+
89+
import busio
90+
import storage
91+
import adafruit_sdcard
92+
import os
93+
import board
94+
95+
spi = busio.SPI(SCK, MOSI, MISO)
96+
sd = adafruit_sdcard.SDCard(spi, board.SD_CS)
97+
vfs = storage.VfsFat(sdcard)
98+
storage.mount(vfs, '/sd')
99+
os.listdir('/')
100+
101+
"""
77102
def __init__(self, spi, cs):
78103
# This is the init baudrate. We create a second device for high speed.
79104
self._spi = spi_device.SPIDevice(spi, cs, baudrate=250000, extra_clocks=8)
@@ -88,9 +113,10 @@ def __init__(self, spi, cs):
88113
self._init_card()
89114

90115
def _clock_card(self, cycles=8):
91-
"""Clock the bus a minimum of `cycles` with the chip select high.
116+
"""
117+
Clock the bus a minimum of `cycles` with the chip select high.
92118
93-
:param int cycles: The minimum number of clock cycles to cycle the bus.
119+
:param int cycles: The minimum number of clock cycles to cycle the bus.
94120
"""
95121
while not self._spi.spi.try_lock():
96122
pass
@@ -177,24 +203,28 @@ def _init_card_v2(self):
177203
raise OSError("timeout waiting for v2 card")
178204

179205
def _wait_for_ready(self, spi, timeout=0.3):
180-
"""Wait for the card to clock out 0xff to indicate its ready.
206+
"""
207+
Wait for the card to clock out 0xff to indicate its ready.
181208
182-
:param busio.SPI spi: The locked SPI bus.
183-
:param float timeout: Maximum time to wait in seconds."""
209+
:param busio.SPI spi: The locked SPI bus.
210+
:param float timeout: Maximum time to wait in seconds.
211+
"""
184212
start_time = time.monotonic()
185213
self._single_byte[0] = 0x00
186214
while time.monotonic() - start_time < timeout and self._single_byte[0] != 0xff:
187215
spi.readinto(self._single_byte, write_value=0xff)
188216

189217
#pylint: disable-msg=too-many-arguments
190218
def _cmd(self, cmd, arg=0, crc=0, response_buf=None, data_block=True, wait=True):
191-
"""Issue a command to the card and read an optional data response.
219+
"""
220+
Issue a command to the card and read an optional data response.
192221
193-
:param int cmd: The command number.
194-
:param int arg: The command argument.
195-
:param int crc: The crc to allow the card to verify the command and argument.
196-
:param bytearray response_buf: Buffer to read a data block response into.
197-
:param bool data_block: True if the response data is in a data block."""
222+
:param int cmd: The command number.
223+
:param int arg: The command argument.
224+
:param int crc: The crc to allow the card to verify the command and argument.
225+
:param bytearray response_buf: Buffer to read a data block response into.
226+
:param bool data_block: True if the response data is in a data block.
227+
"""
198228
# create and send the command
199229
buf = self._cmdbuf
200230
buf[0] = 0x40 | cmd
@@ -229,11 +259,13 @@ def _cmd(self, cmd, arg=0, crc=0, response_buf=None, data_block=True, wait=True)
229259
#pylint: enable-msg=too-many-arguments
230260

231261
def _block_cmd(self, cmd, block, crc, response_buf=None):
232-
"""Issue a command to the card with a block argument.
262+
"""
263+
Issue a command to the card with a block argument.
233264
234-
:param int cmd: The command number.
235-
:param int block: The relevant block.
236-
:param int crc: The crc to allow the card to verify the command and argument."""
265+
:param int cmd: The command number.
266+
:param int block: The relevant block.
267+
:param int crc: The crc to allow the card to verify the command and argument.
268+
"""
237269
if self._cdv == 1:
238270
return self._cmd(cmd, block, crc, response_buf=response_buf)
239271

@@ -268,9 +300,11 @@ def _block_cmd(self, cmd, block, crc, response_buf=None):
268300
return result
269301

270302
def _cmd_nodata(self, cmd, response=0xff):
271-
"""Issue a command to the card with no argument.
303+
"""
304+
Issue a command to the card with no argument.
272305
273-
:param int cmd: The command number."""
306+
:param int cmd: The command number.
307+
"""
274308
buf = self._cmdbuf
275309
buf[0] = cmd
276310
buf[1] = 0xff
@@ -284,11 +318,13 @@ def _cmd_nodata(self, cmd, response=0xff):
284318
return 1 # timeout
285319

286320
def _readinto(self, buf, start=0, end=None):
287-
"""Read a data block into buf.
321+
"""
322+
Read a data block into buf.
288323
289-
:param bytearray buf: The buffer to write into
290-
:param int start: The first index to write data at
291-
:param int end: The index after the last byte to write to"""
324+
:param bytearray buf: The buffer to write into
325+
:param int start: The first index to write data at
326+
:param int end: The index after the last byte to write to.
327+
"""
292328
if end is None:
293329
end = len(buf)
294330
with self._spi as spi:
@@ -303,12 +339,14 @@ def _readinto(self, buf, start=0, end=None):
303339
spi.readinto(self._cmdbuf, end=2, write_value=0xff)
304340

305341
def _write(self, token, buf, start=0, end=None):
306-
"""Write a data block to the card.
342+
"""
343+
Write a data block to the card.
307344
308-
:param int token: The start token
309-
:param bytearray buf: The buffer to write from
310-
:param int start: The first index to read data from
311-
:param int end: The index after the last byte to read from"""
345+
:param int token: The start token
346+
:param bytearray buf: The buffer to write from
347+
:param int start: The first index to read data from
348+
:param int end: The index after the last byte to read from.
349+
"""
312350
cmd = self._cmdbuf
313351
if end is None:
314352
end = len(buf)
@@ -340,17 +378,21 @@ def _write(self, token, buf, start=0, end=None):
340378
return 0 # worked
341379

342380
def count(self):
343-
"""Returns the total number of sectors.
381+
"""
382+
Returns the total number of sectors.
344383
345-
:return: The number of 512-byte blocks
346-
:rtype: int"""
384+
:return: The number of 512-byte blocks
385+
:rtype: int
386+
"""
347387
return self._sectors
348388

349389
def readblocks(self, start_block, buf):
350-
"""Read one or more blocks from the card
390+
"""
391+
Read one or more blocks from the card
351392
352-
:param int start_block: The block to start reading from
353-
:param bytearray buf: The buffer to write into. Length must be multiple of 512."""
393+
:param int start_block: The block to start reading from
394+
:param bytearray buf: The buffer to write into. Length must be multiple of 512.
395+
"""
354396
nblocks, err = divmod(len(buf), 512)
355397
assert nblocks and not err, 'Buffer length is invalid'
356398
if nblocks == 1:
@@ -372,10 +414,12 @@ def readblocks(self, start_block, buf):
372414
return 0
373415

374416
def writeblocks(self, start_block, buf):
375-
"""Write one or more blocks to the card
417+
"""
418+
Write one or more blocks to the card
376419
377-
:param int start_block: The block to start writing to
378-
:param bytearray buf: The buffer to write into. Length must be multiple of 512."""
420+
:param int start_block: The block to start writing to
421+
:param bytearray buf: The buffer to write into. Length must be multiple of 512.
422+
"""
379423
nblocks, err = divmod(len(buf), 512)
380424
assert nblocks and not err, 'Buffer length is invalid'
381425
if nblocks == 1:

docs/_static/favicon.ico

4.31 KB
Binary file not shown.

api.rst renamed to docs/api.rst

File renamed without changes.

conf.py renamed to docs/conf.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('.'))
5+
sys.path.insert(0, os.path.abspath('..'))
66

77
# -- General configuration ------------------------------------------------
88

@@ -28,7 +28,7 @@
2828
source_suffix = '.rst'
2929

3030
# The master toctree document.
31-
master_doc = 'README'
31+
master_doc = 'index'
3232

3333
# General information about the project.
3434
project = u'Adafruit SD Card Library'
@@ -54,7 +54,7 @@
5454
# List of patterns, relative to source directory, that match files and
5555
# directories to ignore when looking for source files.
5656
# This patterns also effect to html_static_path and html_extra_path
57-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
57+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
5858

5959
# The reST default role (used for this markup: `text`) to use for all
6060
# documents.
@@ -71,6 +71,9 @@
7171
# If true, `todo` and `todoList` produce output, else they produce nothing.
7272
todo_include_todos = False
7373

74+
# If this is True, todo emits a warning for each TODO entries. The default is False.
75+
todo_emit_warnings = True
76+
7477

7578
# -- Options for HTML output ----------------------------------------------
7679

@@ -95,6 +98,12 @@
9598
# so a file named "default.css" will overwrite the builtin "default.css".
9699
html_static_path = ['_static']
97100

101+
# The name of an image file (relative to this directory) to use as a favicon of
102+
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103+
# pixels large.
104+
#
105+
html_favicon = '_static/favicon.ico'
106+
98107
# Output file base name for HTML help builder.
99108
htmlhelp_basename = 'AdafruitSD CardLibrarydoc'
100109

docs/examples.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Simple test
2+
------------
3+
4+
Ensure your device works with this simple test.
5+
6+
.. literalinclude:: ../examples/sd_read_simpletest.py
7+
:caption: examples/sd_read_simpletest.py
8+
:linenos:

0 commit comments

Comments
 (0)