docs: Adapt WiPy's ADC doc and quickref to the new API.

pull/1468/head
Daniel Campora 2015-09-15 19:54:58 +02:00
rodzic 22b4c28f85
commit 861fad5819
2 zmienionych plików z 68 dodań i 36 usunięć

Wyświetl plik

@ -1,12 +1,12 @@
.. _pyb.ADC:
class ADC -- analog to digital conversion: read analog values on a pin
======================================================================
class ADC -- analog to digital conversion
=========================================
.. only:: port_pyboard
Usage::
import pyb
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
import pyb
adc = pyb.ADC(pin) # create an analog object on one of the 4 ADC channels
val = adc.read() # read an analog value
adc.deinit() # disable the adc channel
adc.init() # enable the adc channel
adc = pyb.ADC() # create an ADC object
apin = adc.channel(pin='GP3') # create an analog pin on GP3
val = apin() # read an analog value
Constructors
------------
.. only:: port_pyboard
.. class:: pyb.ADC(pin)
Create an ADC object associated with the given pin.
This allows you to then read analog values on that pin.
.. only:: port_wipy
.. class:: pyb.ADC(pin)
.. class:: pyb.ADC(id=0, \*, bits=12)
Create an ADC object associated with the given pin.
This allows you to then read analog values on that pin.
For more info check the `pinout and alternate functions
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
.. warning::
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
@ -58,13 +58,13 @@ Constructors
Methods
-------
.. method:: adc.read()
Read the value on the analog pin and return it. The returned value
will be between 0 and 4095.
.. only:: port_pyboard
.. method:: adc.read()
Read the value on the analog pin and return it. The returned value
will be between 0 and 4095.
.. method:: adc.read_timed(buf, timer)
Read analog values into ``buf`` at a rate set by the ``timer`` object.
@ -97,15 +97,51 @@ Methods
# this will take 10 seconds to finish
for val in buf: # loop over all values
print(val) # print the value out
This function does not allocate any memory.
.. only:: port_wipy
.. method:: adc.channel(id, *, pin)
Create an analog pin. If only channel ID is given, the correct pin will be selected. Alternatively,
only the pin can be passed and the correct channel will be selected. Examples::
# all of these are equivalent and enable ADC channel 1 on GP3
apin = adc.channel(1)
apin = adc.channel(pin='GP3')
apin = adc.channel(id=1, pin='GP3')
.. method:: adc.init()
Enable the ADC channel.
Enable the ADC block.
.. method:: adc.deinit()
Disable the ADC channel.
Disable the ADC block.
.. only:: port_wipy
class ADCChannel --- read analog values from internal or external sources
=========================================================================
.. only:: port_wipy
ADC channels can be connected to internal points of the MCU or to GPIO pins.
ADC channels are created using the ADC.channel method.
.. method:: adcchannel()
Fast method to read the channel value.
.. method:: adcchannel.value()
Read the channel value.
.. method:: adcchannel.init()
Re-init (and effectively enable) the ADC channel.
.. method:: adcchannel.deinit()
Disable the ADC channel.

Wyświetl plik

@ -78,8 +78,9 @@ See :ref:`pyb.ADC <pyb.ADC>`. ::
from pyb import ADC
adc = ADC(1)
adc.read() # read value, 0-4095
adc = ADC()
apin = adc.channel(pin='GP3')
apin() # read value, 0-4095
UART (serial bus)
-----------------
@ -94,21 +95,16 @@ See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.UART <pyb.UART>`. ::
SPI bus
-------
See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.SPI <pyb.SPI>`. ::
See :ref:`pyb.SPI <pyb.SPI>`. ::
from pyb import Pin, SPI
# first assign CLK, MISO, MOSI, CS to the correct pins
Pin('GP14', af=7, mode=Pin.STD) # CLK
Pin('GP15', af=7, mode=Pin.STD) # MISO
Pin('GP16', af=7, mode=Pin.STD) # MOSI
Pin('GP17', af=7, mode=Pin.STD) # NSS/CS
from pyb SPI
# configure the SPI master @ 2MHz
spi = SPI(1, SPI.MASTER, baudrate=200000, polarity=0, phase=0)
spi.send('hello')
spi.recv(5) # receive 5 bytes on the bus
spi.send_recv('hello') # send a receive 5 bytes
spi = SPI(0, SPI.MASTER, baudrate=200000, polarity=0, phase=0)
spi.write('hello')
spi.read(5) # receive 5 bytes on the bus
rbuf = bytearray(5)
spi.write_readinto('hello', rbuf) # send a receive 5 bytes
I2C bus
-------
@ -132,9 +128,9 @@ See :ref:`pyb.WDT <pyb.WDT>`. ::
from pyb import WDT
# enable the WDT with a timeout of 5s (1s is the minimum)
wdt = WDT(5000)
wdt.kick()
wdt = WDT(timeout=5000)
wdt.feed()
Real time clock (RTC)
---------------------