updated "API Reference"

This commit is contained in:
watson8544
2018-08-06 12:05:38 +08:00
parent 6f344e6b00
commit b2b0e618ac
17 changed files with 767 additions and 5 deletions
+65
View File
@@ -0,0 +1,65 @@
ADC API
********
-----------------------------
Description
------------
ESP32 integrates two 12-bit SAR (Successive Approximation Register) ADCs (Analog to Digital Converters) and supports measurements on 18 channels (analog enabled pins)
ESP32 DAC output voltage range is 0-Vdd (3.3 V), the resolution is 8-bits
-----------------------------
Function
---------
machine.ADC(pin [,unit=1])
>>>>>>>>>>>>>>>>>>>>>>>>>>
| **Description:**   
| Create the adc instance object
| **Parament:**
| **pin:** pin argument defines the gpio which will will be used as adc input
| **unit:** Optional unit argument select ESP32 ADC unit for this instance. Values 1 (ADC1, default) or 2 (ADC2) can be selected
| **Example:**
.. code:: python
import machine
adc = machine.ADC(35)
read()
>>>>>>>>>>>>>>>>>
| **Description:**   
| Read the ADC value as voltage (in mV)
|
| **Parament:**
| None Parament
| **Example:**
.. code:: python
import machine
adc = machine.ADC(35)
adc.read()
---------------------
Usage
------
.. code:: python
import machine
adc = machine.ADC(35)
adc.read()
+69
View File
@@ -0,0 +1,69 @@
DAC API
********
-----------------------------
Description
------------
ESP32 has two 8-bit DAC (digital to analog converter) channels, connected to GPIO25 (Channel 1) and GPIO26 (Channel 2).
The DAC driver allows these channels to be set to arbitrary voltages.<br The DAC channels can also be driven with DMA-style written sample data, via the I2S driver when using the “built-in DAC mode”.
ESP32 DAC output voltage range is 0-Vdd (3.3 V), the resolution is 8-bits
-----------------------------
Function
---------
machine.DAC(pin)
>>>>>>>>>>>>>>>>>
| **Description:**   
| Pin argument defines the gpio which will will be used as dac output
| *Note: Only GPIOs 25 and 26 can be used as DAC outputs*
|
| **Parament:**
| **pin:** The pin argument can be given as pin number (integer) or the machine.Pin object
| **Example:**
.. code:: python
import machine
dac = machine.DAC(machine.Pin(26))
dac.write(128)
write(value)
>>>>>>>>>>>>>>>>>
| **Description:**   
| Set the DAC value
| *Note: The value of 255 sets the voltage on dac pin to 3.3 V
|
| **Parament:**
| **value:** DAC vaule.Valid range is: 0 - 255
| **Example:**
.. code:: python
import machine
dac = machine.DAC(machine.Pin(26))
dac.write(128)
---------------------
Usage
------
.. code:: python
import machine
dac = machine.DAC(machine.Pin(26))
dac.write(128)
+27
View File
@@ -0,0 +1,27 @@
GPIO API
********
-----------------------------
Function
---------
value()
---------------------
Usage
------
.. code:: python
import machine
pinout = machine.Pin(0, machine.Pin.OUT)
pinout.value(1)
pinin = machine.Pin(2, machine.Pin.IN)
val = pinin.value()
+13
View File
@@ -0,0 +1,13 @@
Peripherals API
***************
.. toctree::
:maxdepth: 1
ADC <adc>
DAC <dac>
SPI <spi>
Neopixel <neopixel>
Timer <timer>
UART <uart>
+116
View File
@@ -0,0 +1,116 @@
Neopixel API
*************
-----------------------------
Description
------------
This class includes full support for various types of Neopixel, individually-addressable RGB(W) LEDs.
ESP32 RMT peripheral is used for very precise timing ( +/- 50 ns ).
Up to 8 Neopixel strips can be used, 1~1024 pixels each.
-----------------------------
Function
---------
machine.Neopixel(pin, pixels, type)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| **Description:**   
| Create the Neopixel instance object
| **Parament:**
| **pin:** the data gpio which connects to rgb
| **pixels:** The number of rgb
| **type:** Neopixel type: 0 (machine.Neopixel.RGB) for RGB LEDs, or 1 (machine.Neopixel.RGBQ) for RGBW LEDs
| **Example:**
.. code:: python
import machine
np = machine.Neopixel(22, 115, 0)
npw = machine.Neopixel(machine.Pin(25), 24, machine.Neopixel.RGBW)
setHSB(pos, hue, saturation, brightness [, white, num, update] ))
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| **Description:**   
| Write bytes from buffer object buf to the Neopixel device
| **Parament:**
| **pos:** required, pixel position; 1 ~ pix_num
| **hue:** float: any number, the floor of this number is subtracted from it
| to create a fraction between 0 and 1.
| This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model
| **saturation:** float; 0 ~ 1.0
| **brightness:** float; 0 ~ 1.0
| **num:** optional; default: 1; number of pixels to set to the same color, starting from pos
| **update:** optional, default: True; update the Neopixel strip.
| *Note: If False np.show() has to be used to update the strip*
| **Return:**
| None
| **Example:**
.. code:: python
import machine, time
np = machine.Neopixel(machine.Pin(22), 24)
def rainbow(loops=120, delay=1, sat=1.0, bri=0.2):
for pos in range(0, loops):
for i in range(0, 24):
dHue = 360.0/24*(pos+i);
hue = dHue % 360;
np.setHSB(i, hue, sat, bri, 1, False)
np.show()
if delay > 0:
time.sleep_ms(delay)
def blinkRainbow(loops=10, delay=250):
for pos in range(0, loops):
for i in range(0, 24):
dHue = 360.0/24*(pos+i);
hue = dHue % 360;
np.setHSB(i, hue, 1.0, 0.1, 1, False)
np.show()
time.sleep_ms(delay)
np.clear()
time.sleep_ms(delay)
---------------------
Usage
------
.. code:: python
import machine, time
np = machine.Neopixel(machine.Pin(22), 24)
def rainbow(loops=120, delay=1, sat=1.0, bri=0.2):
for pos in range(0, loops):
for i in range(0, 24):
dHue = 360.0/24*(pos+i);
hue = dHue % 360;
np.setHSB(i, hue, sat, bri, 1, False)
np.show()
if delay > 0:
time.sleep_ms(delay)
def blinkRainbow(loops=10, delay=250):
for pos in range(0, loops):
for i in range(0, 24):
dHue = 360.0/24*(pos+i);
hue = dHue % 360;
np.setHSB(i, hue, 1.0, 0.1, 1, False)
np.show()
time.sleep_ms(delay)
np.clear()
time.sleep_ms(delay)
+120
View File
@@ -0,0 +1,120 @@
SPI API
********
-----------------------------
Description
------------
This class includes full support for using ESP32 SPI peripheral in master mode
Only SPI master mode is supported for now.
Python exception wil be raised if the requested spihost is used by SD Card driver (sdcard in spi mode).
If the requested spihost is VSPI and the psRAM is used at 80 MHz, the exception will be raised.
The exception will be raised if SPI cannot be configured for given configurations.
-----------------------------
Function
---------
machine.spi(spihost, baudrate, polarity, phase, firstbit, sck, mosi, miso, cs, duplex, bits)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| **Description:**   
| Create the spi instance object
| **Parament:**
| **spihost:** The hardware SPI host. machine-SPI.HSPI (1) or machine.SPI.VSPI (2) can be used. Default: 1
| **baudrate:** SPI clock speed in Hz; Default: 1000000
| **Example:**
.. code:: python
from machine import SPI, Pin
spi = SPI(
spihost=SPI.HSPI,
baudrate=2600000
sck=Pin(18),
mosi=Pin(23),
miso=Pin(19),
cs=Pin(4)
)
write(buf)
>>>>>>>>>>>>>>>>>
| **Description:**   
| Write bytes from buffer object buf to the SPI device
| **Parament:**
| **buf:** data buffer to be write
| **Return:**
| Returns `True` on success, `False` ion error
| **Example:**
.. code:: python
from machine import SPI, Pin
spi = SPI(
spihost=SPI.HSPI,
baudrate=2600000
sck=Pin(18),
mosi=Pin(23),
miso=Pin(19),
cs=Pin(4)
)
spi.write(buf) #NOHEAP
write_readinto(wr_buf, rd_buf)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
| **Description:**   
| Write bytes from buffer object wr_buf to the SPI device and reads from SPI device into buffer object rd_buf
| **Parament:**
| **wr_buf:** data buffer to be write
| **rd_buf:** data buffer to be read
| *Note: * In fullduplex mode write and read are simultaneous. In halfduplex mode the data are first written to the device, then read from it
| **Return:**
| Returns `True` on success, `False` ion error
| **Example:**
.. code:: python
import machine
adc = machine.ADC(35)
adc.read()
---------------------
Usage
------
.. code:: python
from machine import SPI, Pin
spi = SPI(
spihost=SPI.HSPI,
baudrate=2600000
sck=Pin(18),
mosi=Pin(23),
miso=Pin(19),
cs=Pin(4)
)
spi.write(buf) #NOHEAP
spi.read(nbytes, *, write=0x00) #write is the byte to ?output on MOSI for each byte read in
spi.readinto(buf, *, write=0x00) #NOHEAP
spi.write_readinto(write_buf, read_buf) #NOHEAP; write_buf and read_buf can be the same