Skip to content

Commit 861fad5

Browse files
author
Daniel Campora
committed
docs: Adapt WiPy's ADC doc and quickref to the new API.
1 parent 22b4c28 commit 861fad5

2 files changed

Lines changed: 67 additions & 35 deletions

File tree

docs/library/pyb.ADC.rst

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.. _pyb.ADC:
22

3-
class ADC -- analog to digital conversion: read analog values on a pin
4-
======================================================================
3+
class ADC -- analog to digital conversion
4+
=========================================
55

66
.. only:: port_pyboard
77

88
Usage::
9-
9+
1010
import pyb
1111
1212
adc = pyb.ADC(pin) # create an analog object from a pin
@@ -24,32 +24,32 @@ class ADC -- analog to digital conversion: read analog values on a pin
2424
2525
import pyb
2626

27-
adc = pyb.ADC(pin) # create an analog object on one of the 4 ADC channels
28-
val = adc.read() # read an analog value
29-
adc.deinit() # disable the adc channel
30-
adc.init() # enable the adc channel
27+
adc = pyb.ADC() # create an ADC object
28+
apin = adc.channel(pin='GP3') # create an analog pin on GP3
29+
val = apin() # read an analog value
3130

3231
Constructors
3332
------------
3433

34+
3535
.. only:: port_pyboard
3636

3737
.. class:: pyb.ADC(pin)
38-
38+
3939
Create an ADC object associated with the given pin.
4040
This allows you to then read analog values on that pin.
4141

4242
.. only:: port_wipy
4343

44-
.. class:: pyb.ADC(pin)
45-
44+
.. class:: pyb.ADC(id=0, \*, bits=12)
45+
4646
Create an ADC object associated with the given pin.
4747
This allows you to then read analog values on that pin.
4848
For more info check the `pinout and alternate functions
4949
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
5050

5151
.. warning::
52-
52+
5353
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
5454
can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
5555
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
@@ -58,12 +58,12 @@ Constructors
5858
Methods
5959
-------
6060

61-
.. method:: adc.read()
61+
.. only:: port_pyboard
6262

63-
Read the value on the analog pin and return it. The returned value
64-
will be between 0 and 4095.
63+
.. method:: adc.read()
6564

66-
.. only:: port_pyboard
65+
Read the value on the analog pin and return it. The returned value
66+
will be between 0 and 4095.
6767

6868
.. method:: adc.read_timed(buf, timer)
6969

@@ -97,15 +97,51 @@ Methods
9797
# this will take 10 seconds to finish
9898
for val in buf: # loop over all values
9999
print(val) # print the value out
100-
100+
101101
This function does not allocate any memory.
102102

103103
.. only:: port_wipy
104104

105+
.. method:: adc.channel(id, *, pin)
106+
107+
Create an analog pin. If only channel ID is given, the correct pin will be selected. Alternatively,
108+
only the pin can be passed and the correct channel will be selected. Examples::
109+
110+
# all of these are equivalent and enable ADC channel 1 on GP3
111+
apin = adc.channel(1)
112+
apin = adc.channel(pin='GP3')
113+
apin = adc.channel(id=1, pin='GP3')
114+
105115
.. method:: adc.init()
106116

107-
Enable the ADC channel.
117+
Enable the ADC block.
108118

109119
.. method:: adc.deinit()
110120

111-
Disable the ADC channel.
121+
Disable the ADC block.
122+
123+
.. only:: port_wipy
124+
125+
class ADCChannel --- read analog values from internal or external sources
126+
=========================================================================
127+
128+
.. only:: port_wipy
129+
130+
ADC channels can be connected to internal points of the MCU or to GPIO pins.
131+
ADC channels are created using the ADC.channel method.
132+
133+
.. method:: adcchannel()
134+
135+
Fast method to read the channel value.
136+
137+
.. method:: adcchannel.value()
138+
139+
Read the channel value.
140+
141+
.. method:: adcchannel.init()
142+
143+
Re-init (and effectively enable) the ADC channel.
144+
145+
.. method:: adcchannel.deinit()
146+
147+
Disable the ADC channel.

docs/wipy/quickref.rst

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ See :ref:`pyb.ADC <pyb.ADC>`. ::
7878

7979
from pyb import ADC
8080

81-
adc = ADC(1)
82-
adc.read() # read value, 0-4095
81+
adc = ADC()
82+
apin = adc.channel(pin='GP3')
83+
apin() # read value, 0-4095
8384

8485
UART (serial bus)
8586
-----------------
@@ -94,21 +95,16 @@ See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.UART <pyb.UART>`. ::
9495
SPI bus
9596
-------
9697

97-
See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.SPI <pyb.SPI>`. ::
98+
See :ref:`pyb.SPI <pyb.SPI>`. ::
9899

99-
from pyb import Pin, SPI
100-
101-
# first assign CLK, MISO, MOSI, CS to the correct pins
102-
Pin('GP14', af=7, mode=Pin.STD) # CLK
103-
Pin('GP15', af=7, mode=Pin.STD) # MISO
104-
Pin('GP16', af=7, mode=Pin.STD) # MOSI
105-
Pin('GP17', af=7, mode=Pin.STD) # NSS/CS
100+
from pyb SPI
106101

107102
# configure the SPI master @ 2MHz
108-
spi = SPI(1, SPI.MASTER, baudrate=200000, polarity=0, phase=0)
109-
spi.send('hello')
110-
spi.recv(5) # receive 5 bytes on the bus
111-
spi.send_recv('hello') # send a receive 5 bytes
103+
spi = SPI(0, SPI.MASTER, baudrate=200000, polarity=0, phase=0)
104+
spi.write('hello')
105+
spi.read(5) # receive 5 bytes on the bus
106+
rbuf = bytearray(5)
107+
spi.write_readinto('hello', rbuf) # send a receive 5 bytes
112108

113109
I2C bus
114110
-------
@@ -132,9 +128,9 @@ See :ref:`pyb.WDT <pyb.WDT>`. ::
132128
from pyb import WDT
133129

134130
# enable the WDT with a timeout of 5s (1s is the minimum)
135-
wdt = WDT(5000)
136-
wdt.kick()
137-
131+
wdt = WDT(timeout=5000)
132+
wdt.feed()
133+
138134
Real time clock (RTC)
139135
---------------------
140136

0 commit comments

Comments
 (0)