micropython: add micropython component

This commit is contained in:
KY-zhang-X
2022-09-29 12:10:37 +08:00
parent 1514f1cb9b
commit dd76146324
2679 changed files with 354110 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
"""
ADC test for the CC3200 based boards.
"""
from machine import ADC
import os
mch = os.uname().machine
if "LaunchPad" in mch:
adc_pin = "GP5"
adc_channel = 3
elif "WiPy" in mch:
adc_pin = "GP3"
adc_channel = 1
else:
raise Exception("Board not supported!")
adc = ADC(0)
print(adc)
adc = ADC()
print(adc)
adc = ADC(0, bits=12)
print(adc)
apin = adc.channel(adc_channel)
print(apin)
apin = adc.channel(id=adc_channel)
print(apin)
apin = adc.channel(adc_channel, pin=adc_pin)
print(apin)
apin = adc.channel(id=adc_channel, pin=adc_pin)
print(apin)
print(apin.value() > 3000)
print(apin() > 3000)
# de-init must work
apin.deinit()
print(apin)
adc.deinit()
print(adc)
print(apin)
adc.init()
print(adc)
print(apin)
apin.init()
print(apin)
print(apin() > 3000)
# check for memory leaks...
for i in range(0, 1000):
adc = ADC()
apin = adc.channel(adc_channel)
# next ones should raise
try:
adc = ADC(bits=17)
except:
print("Exception")
try:
adc = ADC(id=1)
except:
print("Exception")
try:
adc = ADC(0, 16)
except:
print("Exception")
adc = ADC()
try:
apin = adc.channel(4)
except:
print("Exception")
try:
apin = adc.channel(-1)
except:
print("Exception")
try:
apin = adc.channel(0, pin="GP3")
except:
print("Exception")
apin = adc.channel(1)
apin.deinit()
try:
apin()
except:
print("Exception")
try:
apin.value()
except:
print("Exception")
adc.deinit()
try:
apin.value()
except:
print("Exception")
try:
apin = adc.channel(1)
except:
print("Exception")
# re-init must work
adc.init()
apin.init()
print(apin)
print(apin() > 3000)

View File

@@ -0,0 +1,28 @@
ADC(0, bits=12)
ADC(0, bits=12)
ADC(0, bits=12)
ADCChannel(1, pin=GP3)
ADCChannel(1, pin=GP3)
ADCChannel(1, pin=GP3)
ADCChannel(1, pin=GP3)
True
True
ADCChannel(1)
ADC(0)
ADCChannel(1)
ADC(0, bits=12)
ADCChannel(1)
ADCChannel(1, pin=GP3)
True
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
ADCChannel(1, pin=GP3)
True

View File

@@ -0,0 +1,175 @@
"""
I2C test for the CC3200 based boards.
A MPU-9150 sensor must be connected to the I2C bus.
"""
from machine import I2C
import os
import time
mch = os.uname().machine
if "LaunchPad" in mch:
i2c_pins = ("GP11", "GP10")
elif "WiPy" in mch:
i2c_pins = ("GP15", "GP10")
else:
raise Exception("Board not supported!")
i2c = I2C(0, I2C.MASTER, baudrate=400000)
# try initing without the peripheral id
i2c = I2C()
print(i2c)
i2c = I2C(mode=I2C.MASTER, baudrate=50000, pins=i2c_pins)
print(i2c)
i2c = I2C(0, I2C.MASTER, baudrate=100000)
print(i2c)
i2c = I2C(0, mode=I2C.MASTER, baudrate=400000)
print(i2c)
i2c = I2C(0, mode=I2C.MASTER, baudrate=400000, pins=i2c_pins)
print(i2c)
addr = i2c.scan()[0]
print(addr)
reg = bytearray(1)
reg2 = bytearray(2)
reg2_r = bytearray(2)
# reset the sensor
reg[0] |= 0x80
print(1 == i2c.writeto_mem(addr, 107, reg))
time.sleep_ms(100) # wait for the sensor to reset...
print(1 == i2c.readfrom_mem_into(addr, 107, reg)) # read the power management register 1
print(0x40 == reg[0])
# now just read one byte
data = i2c.readfrom_mem(addr, 117, 1) # read the "who am I?" register
print(0x68 == data[0])
print(len(data) == 1)
print(1 == i2c.readfrom_mem_into(addr, 117, reg)) # read the "who am I?" register again
print(0x68 == reg[0])
# now try reading two bytes
data = i2c.readfrom_mem(addr, 116, 2) # read the "who am I?" register
print(0x68 == data[1])
print(data == b"\x00\x68")
print(len(data) == 2)
print(2 == i2c.readfrom_mem_into(addr, 116, reg2)) # read the "who am I?" register again
print(0x68 == reg2[1])
print(reg2 == b"\x00\x68")
print(1 == i2c.readfrom_mem_into(addr, 107, reg)) # read the power management register 1
print(0x40 == reg[0])
# clear the sleep bit
reg[0] = 0
print(1 == i2c.writeto_mem(addr, 107, reg))
# read it back
i2c.readfrom_mem_into(addr, 107, reg)
print(0 == reg[0])
# set the sleep bit
reg[0] = 0x40
print(1 == i2c.writeto_mem(addr, 107, reg))
# read it back
i2c.readfrom_mem_into(addr, 107, reg)
print(0x40 == reg[0])
# reset the sensor
reg[0] |= 0x80
print(1 == i2c.writeto_mem(addr, 107, reg))
time.sleep_ms(100) # wait for the sensor to reset...
# now read and write two register at a time
print(2 == i2c.readfrom_mem_into(addr, 107, reg2))
print(0x40 == reg2[0])
print(0x00 == reg2[1])
# clear the sleep bit
reg2[0] = 0
# set some other bits
reg2[1] |= 0x03
print(2 == i2c.writeto_mem(addr, 107, reg2))
# read it back
i2c.readfrom_mem_into(addr, 107, reg2_r)
print(reg2 == reg2_r)
# reset the sensor
reg[0] = 0x80
print(1 == i2c.writeto_mem(addr, 107, reg))
time.sleep_ms(100) # wait for the sensor to reset...
# try some raw read and writes
reg[0] = 117 # register address
print(1 == i2c.writeto(addr, reg, stop=False)) # just write the register address
# now read
print(1 == i2c.readfrom_into(addr, reg))
print(reg[0] == 0x68)
reg[0] = 117 # register address
print(1 == i2c.writeto(addr, reg, stop=False)) # just write the register address
# now read
print(0x68 == i2c.readfrom(addr, 1)[0])
i2c.readfrom_mem_into(addr, 107, reg2)
print(0x40 == reg2[0])
print(0x00 == reg2[1])
reg2[0] = 107 # register address
reg2[1] = 0
print(2 == i2c.writeto(addr, reg2, stop=True)) # write the register address and the data
i2c.readfrom_mem_into(addr, 107, reg) # check it back
print(reg[0] == 0)
# check for memory leaks...
for i in range(0, 1000):
i2c = I2C(0, I2C.MASTER, baudrate=100000)
# test deinit
i2c = I2C(0, I2C.MASTER, baudrate=100000)
i2c.deinit()
print(i2c)
# next ones should raise
try:
i2c.scan()
except Exception:
print("Exception")
try:
i2c.readfrom(addr, 1)
except Exception:
print("Exception")
try:
i2c.readfrom_into(addr, reg)
except Exception:
print("Exception")
try:
i2c.readfrom_mem_into(addr, 107, reg)
except Exception:
print("Exception")
try:
i2c.writeto(addr, reg, stop=False)
except Exception:
print("Exception")
try:
i2c.writeto_mem(addr, 107, reg)
except Exception:
print("Exception")
try:
i2c.readfrom_mem(addr, 116, 2)
except Exception:
print("Exception")
try:
I2C(1, I2C.MASTER, baudrate=100000)
except Exception:
print("Exception")
# reinitialization must work
i2c.init(baudrate=400000)
print(i2c)

View File

@@ -0,0 +1,51 @@
I2C(0, I2C.MASTER, baudrate=100000)
I2C(0, I2C.MASTER, baudrate=50000)
I2C(0, I2C.MASTER, baudrate=100000)
I2C(0, I2C.MASTER, baudrate=400000)
I2C(0, I2C.MASTER, baudrate=400000)
104
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
I2C(0)
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
I2C(0, I2C.MASTER, baudrate=400000)

View File

@@ -0,0 +1,21 @@
"""
wipy module test for the CC3200 based boards
"""
import os
import wipy
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
print(wipy.heartbeat() == True)
wipy.heartbeat(False)
print(wipy.heartbeat() == False)
wipy.heartbeat(True)
print(wipy.heartbeat() == True)
try:
wipy.heartbeat(True, 1)
except:
print("Exception")

View File

@@ -0,0 +1,4 @@
True
True
True
Exception

View File

@@ -0,0 +1,164 @@
"""
os module test for the CC3200 based boards
"""
from machine import SD
import os
mch = os.uname().machine
if "LaunchPad" in mch:
sd_pins = ("GP16", "GP17", "GP15")
elif "WiPy" in mch:
sd_pins = ("GP10", "GP11", "GP15")
else:
raise Exception("Board not supported!")
sd = SD(pins=sd_pins)
os.mount(sd, "/sd")
os.mkfs("/sd")
os.chdir("/flash")
print(os.listdir())
os.chdir("/sd")
print(os.listdir())
# create a test directory in flash
os.mkdir("/flash/test")
os.chdir("/flash/test")
print(os.getcwd())
os.chdir("..")
print(os.getcwd())
os.chdir("test")
print(os.getcwd())
# create a new file
f = open("test.txt", "w")
test_bytes = os.urandom(1024)
n_w = f.write(test_bytes)
print(n_w == len(test_bytes))
f.close()
f = open("test.txt", "r")
r = bytes(f.read(), "ascii")
# check that we can write and read it correctly
print(r == test_bytes)
f.close()
os.rename("test.txt", "newtest.txt")
print(os.listdir())
os.rename("/flash/test", "/flash/newtest")
print(os.listdir("/flash"))
os.remove("newtest.txt")
os.chdir("..")
os.rmdir("newtest")
# create a test directory in the sd card
os.mkdir("/sd/test")
os.chdir("/sd/test")
print(os.getcwd())
os.chdir("..")
print(os.getcwd())
os.chdir("test")
print(os.getcwd())
# create a new file
f = open("test.txt", "w")
test_bytes = os.urandom(1024)
n_w = f.write(test_bytes)
print(n_w == len(test_bytes))
f.close()
f = open("test.txt", "r")
r = bytes(f.read(), "ascii")
# check that we can write and read it correctly
print(r == test_bytes)
f.close()
print("CC3200" in os.uname().machine)
print("WiPy" == os.uname().sysname)
os.sync()
os.stat("/flash")
os.stat("/flash/sys")
os.stat("/flash/boot.py")
os.stat("/sd")
os.stat("/")
os.chdir("/sd/test")
os.remove("test.txt")
os.chdir("/sd")
os.rmdir("test")
os.listdir("/sd")
print(os.listdir("/"))
os.unmount("/sd")
print(os.listdir("/"))
os.mkfs(sd)
os.mount(sd, "/sd")
print(os.listdir("/"))
os.chdir("/flash")
# next ones must raise
sd.deinit()
try:
os.listdir("/sd")
except:
print("Exception")
# re-initialization must work
sd.init()
print(os.listdir("/sd"))
try:
os.mount(sd, "/sd")
except:
print("Exception")
try:
os.mount(sd, "/sd2")
except:
print("Exception")
os.unmount("/sd")
try:
os.listdir("/sd")
except:
print("Exception")
try:
os.unmount("/flash")
except:
print("Exception")
try:
os.unmount("/something")
except:
print("Exception")
try:
os.unmount("something")
except:
print("Exception")
try:
os.mkfs("flash") # incorrect path format
except:
print("Exception")
try:
os.remove("/flash/nofile.txt")
except:
print("Exception")
try:
os.rename("/flash/nofile.txt", "/flash/nofile2.txt")
except:
print("Exception")
try:
os.chdir("/flash/nodir")
except:
print("Exception")
try:
os.listdir("/flash/nodir")
except:
print("Exception")
os.mount(sd, "/sd")
print(os.listdir("/"))
os.unmount("/sd")

View File

@@ -0,0 +1,32 @@
['main.py', 'sys', 'lib', 'cert', 'boot.py']
[]
/flash/test
/flash
/flash/test
True
True
['newtest.txt']
['main.py', 'sys', 'lib', 'cert', 'boot.py', 'newtest']
/sd/test
/sd
/sd/test
True
True
True
True
['flash', 'sd']
['flash']
['flash', 'sd']
[]
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
['flash', 'sd']

View File

@@ -0,0 +1,217 @@
"""
This test need a set of pins which can be set as inputs and have no external
pull up or pull down connected.
GP12 and GP17 must be connected together
"""
from machine import Pin
import os
mch = os.uname().machine
if "LaunchPad" in mch:
pin_map = [
"GP24",
"GP12",
"GP14",
"GP15",
"GP16",
"GP17",
"GP28",
"GP8",
"GP6",
"GP30",
"GP31",
"GP3",
"GP0",
"GP4",
"GP5",
]
max_af_idx = 15
elif "WiPy" in mch:
pin_map = [
"GP23",
"GP24",
"GP12",
"GP13",
"GP14",
"GP9",
"GP17",
"GP28",
"GP22",
"GP8",
"GP30",
"GP31",
"GP0",
"GP4",
"GP5",
]
max_af_idx = 15
else:
raise Exception("Board not supported!")
# test initial value
p = Pin("GP12", Pin.IN)
Pin("GP17", Pin.OUT, value=1)
print(p() == 1)
Pin("GP17", Pin.OUT, value=0)
print(p() == 0)
def test_noinit():
for p in pin_map:
pin = Pin(p)
pin.value()
def test_pin_read(pull):
# enable the pull resistor on all pins, then read the value
for p in pin_map:
pin = Pin(p, mode=Pin.IN, pull=pull)
for p in pin_map:
print(pin())
def test_pin_af():
for p in pin_map:
for af in Pin(p).alt_list():
if af[1] <= max_af_idx:
Pin(p, mode=Pin.ALT, alt=af[1])
Pin(p, mode=Pin.ALT_OPEN_DRAIN, alt=af[1])
# test un-initialized pins
test_noinit()
# test with pull-up and pull-down
test_pin_read(Pin.PULL_UP)
test_pin_read(Pin.PULL_DOWN)
# test all constructor combinations
pin = Pin(pin_map[0])
pin = Pin(pin_map[0], mode=Pin.IN)
pin = Pin(pin_map[0], mode=Pin.OUT)
pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.PULL_DOWN)
pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.PULL_UP)
pin = Pin(pin_map[0], mode=Pin.OPEN_DRAIN, pull=Pin.PULL_UP)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_DOWN)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=None)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.LOW_POWER)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.MED_POWER)
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.HIGH_POWER)
pin = Pin(pin_map[0], mode=Pin.OUT, drive=pin.LOW_POWER)
pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_DOWN)
pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP)
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP)
test_pin_af() # try the entire af range on all pins
# test pin init and printing
pin = Pin(pin_map[0])
pin.init(mode=Pin.IN)
print(pin)
pin.init(Pin.IN, Pin.PULL_DOWN)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.LOW_POWER)
print(pin)
pin.init(mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.HIGH_POWER)
print(pin)
# test value in OUT mode
pin = Pin(pin_map[0], mode=Pin.OUT)
pin.value(0)
pin.toggle() # test toggle
print(pin())
pin.toggle() # test toggle again
print(pin())
# test different value settings
pin(1)
print(pin.value())
pin(0)
print(pin.value())
pin.value(1)
print(pin())
pin.value(0)
print(pin())
# test all getters and setters
pin = Pin(pin_map[0], mode=Pin.OUT)
# mode
print(pin.mode() == Pin.OUT)
pin.mode(Pin.IN)
print(pin.mode() == Pin.IN)
# pull
pin.pull(None)
print(pin.pull() == None)
pin.pull(Pin.PULL_DOWN)
print(pin.pull() == Pin.PULL_DOWN)
# drive
pin.drive(Pin.MED_POWER)
print(pin.drive() == Pin.MED_POWER)
pin.drive(Pin.HIGH_POWER)
print(pin.drive() == Pin.HIGH_POWER)
# id
print(pin.id() == pin_map[0])
# all the next ones MUST raise
try:
pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.IN) # incorrect drive value
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], mode=Pin.LOW_POWER, pull=Pin.PULL_UP) # incorrect mode value
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.HIGH_POWER) # incorrect pull value
except Exception:
print("Exception")
try:
pin = Pin("A0", Pin.OUT, Pin.PULL_DOWN) # incorrect pin id
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], Pin.IN, Pin.PULL_UP, alt=0) # af specified in GPIO mode
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_UP, alt=7) # af specified in GPIO mode
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP, alt=0) # incorrect af
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=-1) # incorrect af
except Exception:
print("Exception")
try:
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=16) # incorrect af
except Exception:
print("Exception")
try:
pin.mode(Pin.PULL_UP) # incorrect pin mode
except Exception:
print("Exception")
try:
pin.pull(Pin.OUT) # incorrect pull
except Exception:
print("Exception")
try:
pin.drive(Pin.IN) # incorrect drive strength
except Exception:
print("Exception")
try:
pin.id("ABC") # id cannot be set
except Exception:
print("Exception")

View File

@@ -0,0 +1,60 @@
True
True
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Pin('GP23', mode=Pin.IN, pull=None, drive=Pin.MED_POWER, alt=-1)
Pin('GP23', mode=Pin.IN, pull=Pin.PULL_DOWN, drive=Pin.MED_POWER, alt=-1)
Pin('GP23', mode=Pin.OUT, pull=Pin.PULL_UP, drive=Pin.LOW_POWER, alt=-1)
Pin('GP23', mode=Pin.OUT, pull=Pin.PULL_UP, drive=Pin.HIGH_POWER, alt=-1)
1
0
1
0
1
0
True
True
True
True
True
True
True
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception

View File

@@ -0,0 +1,120 @@
"""
Pin IRQ test for the CC3200 based boards.
"""
from machine import Pin
import machine
import os
import time
mch = os.uname().machine
if "LaunchPad" in mch:
pins = ["GP16", "GP13"]
elif "WiPy" in mch:
pins = ["GP16", "GP13"]
else:
raise Exception("Board not supported!")
pin0 = Pin(pins[0], mode=Pin.OUT, value=1)
pin1 = Pin(pins[1], mode=Pin.IN, pull=Pin.PULL_UP)
def pin_handler(pin_o):
global pin_irq_count_trigger
global pin_irq_count_total
global _trigger
if _trigger & pin1_irq.flags():
pin_irq_count_trigger += 1
pin_irq_count_total += 1
pin_irq_count_trigger = 0
pin_irq_count_total = 0
_trigger = Pin.IRQ_FALLING
pin1_irq = pin1.irq(trigger=_trigger, handler=pin_handler)
for i in range(0, 10):
pin0.toggle()
time.sleep_ms(5)
print(pin_irq_count_trigger == 5)
print(pin_irq_count_total == 5)
pin_irq_count_trigger = 0
pin_irq_count_total = 0
_trigger = Pin.IRQ_RISING
pin1_irq = pin1.irq(trigger=_trigger, handler=pin_handler)
for i in range(0, 200):
pin0.toggle()
time.sleep_ms(5)
print(pin_irq_count_trigger == 100)
print(pin_irq_count_total == 100)
pin1_irq.disable()
pin0(1)
pin_irq_count_trigger = 0
pin_irq_count_total = 0
_trigger = Pin.IRQ_FALLING
pin1_irq.init(trigger=_trigger, handler=pin_handler)
pin0(0)
time.sleep_us(50)
print(pin_irq_count_trigger == 1)
print(pin_irq_count_total == 1)
pin0(1)
time.sleep_us(50)
print(pin_irq_count_trigger == 1)
print(pin_irq_count_total == 1)
# check the call method
pin1_irq()
print(pin_irq_count_trigger == 1) # no flags since the irq was manually triggered
print(pin_irq_count_total == 2)
pin1_irq.disable()
pin_irq_count_trigger = 0
pin_irq_count_total = 0
for i in range(0, 10):
pin0.toggle()
time.sleep_ms(5)
print(pin_irq_count_trigger == 0)
print(pin_irq_count_total == 0)
# test waking up from suspended mode on low level
pin0(0)
t0 = time.ticks_ms()
pin1_irq.init(trigger=Pin.IRQ_LOW_LEVEL, wake=machine.SLEEP)
machine.sleep()
print(time.ticks_ms() - t0 < 10)
print("Awake")
# test waking up from suspended mode on high level
pin0(1)
t0 = time.ticks_ms()
pin1_irq.init(trigger=Pin.IRQ_HIGH_LEVEL, wake=machine.SLEEP)
machine.sleep()
print(time.ticks_ms() - t0 < 10)
print("Awake")
# check for memory leaks
for i in range(0, 1000):
pin0_irq = pin0.irq(trigger=_trigger, handler=pin_handler)
pin1_irq = pin1.irq(trigger=_trigger, handler=pin_handler)
# next ones must raise
try:
pin1_irq.init(trigger=123456, handler=pin_handler)
except:
print("Exception")
try:
pin1_irq.init(trigger=Pin.IRQ_LOW_LEVEL, wake=1789456)
except:
print("Exception")
try:
pin0_irq = pin0.irq(
trigger=Pin.IRQ_RISING, wake=machine.SLEEP
) # GP16 can't wake up from DEEPSLEEP
except:
print("Exception")
pin0_irq.disable()
pin1_irq.disable()

View File

@@ -0,0 +1,19 @@
True
True
True
True
True
True
True
True
True
True
True
True
True
Awake
True
Awake
Exception
Exception
Exception

View File

@@ -0,0 +1,17 @@
"""
Reset script for the cc3200 boards
This is needed to force the board to reboot
with the default WLAN AP settings
"""
from machine import WDT
import time
import os
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
wdt = WDT(timeout=1000)
print(wdt)
time.sleep_ms(900)

View File

@@ -0,0 +1 @@
<WDT>

View File

@@ -0,0 +1,119 @@
"""
RTC test for the CC3200 based boards.
"""
from machine import RTC
import os
import time
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
rtc = RTC()
print(rtc)
print(rtc.now()[:6])
rtc = RTC(datetime=(2015, 8, 29, 9, 0, 0, 0, None))
print(rtc.now()[:6])
rtc.deinit()
print(rtc.now()[:6])
rtc.init((2015, 8, 29, 9, 0, 0, 0, None))
print(rtc.now()[:6])
seconds = rtc.now()[5]
time.sleep_ms(1000)
print(rtc.now()[5] - seconds == 1)
seconds = rtc.now()[5]
time.sleep_ms(2000)
print(rtc.now()[5] - seconds == 2)
# initialization with shorter tuples
rtc.init((2015, 9, 19, 8, 0, 0, 0))
print(rtc.now()[5])
rtc.init((2015, 9, 19, 8, 0, 0))
print(rtc.now()[5])
rtc.init((2015, 9, 19, 8, 0))
print(rtc.now()[5])
rtc.init((2015, 9, 19, 8))
print(rtc.now()[4])
rtc.init((2015, 9, 19))
print(rtc.now()[3])
def set_and_print(datetime):
rtc.init(datetime)
print(rtc.now()[:6])
# make sure that setting works correctly
set_and_print((2000, 1, 1, 0, 0, 0, 0, None))
set_and_print((2000, 1, 31, 0, 0, 0, 0, None))
set_and_print((2000, 12, 31, 0, 0, 0, 0, None))
set_and_print((2016, 12, 31, 0, 0, 0, 0, None))
set_and_print((2016, 12, 31, 0, 0, 0, 0, None))
set_and_print((2016, 12, 31, 1, 0, 0, 0, None))
set_and_print((2016, 12, 31, 12, 0, 0, 0, None))
set_and_print((2016, 12, 31, 13, 0, 0, 0, None))
set_and_print((2016, 12, 31, 23, 0, 0, 0, None))
set_and_print((2016, 12, 31, 23, 1, 0, 0, None))
set_and_print((2016, 12, 31, 23, 59, 0, 50, None))
set_and_print((2016, 12, 31, 23, 59, 1, 900, None))
set_and_print((2016, 12, 31, 23, 59, 59, 100, None))
set_and_print((2048, 12, 31, 23, 59, 59, 99999, None))
rtc.init((2015, 8, 29, 9, 0, 0, 0, None))
rtc.alarm(0, 5000)
rtc.alarm(time=2000)
time.sleep_ms(1000)
left = rtc.alarm_left()
print(abs(left - 1000) <= 10)
time.sleep_ms(1000)
print(rtc.alarm_left() == 0)
time.sleep_ms(100)
print(rtc.alarm_left(0) == 0)
rtc.alarm(time=1000, repeat=True)
time.sleep_ms(1500)
left = rtc.alarm_left()
print(abs(left - 500) <= 15)
rtc.init((2015, 8, 29, 9, 0, 0, 0, None))
rtc.alarm(time=(2015, 8, 29, 9, 0, 45))
time.sleep_ms(1000)
left = rtc.alarm_left()
print(abs(left - 44000) <= 90)
rtc.alarm_cancel()
rtc.deinit()
# next ones must raise
try:
rtc.alarm(5000)
except:
print("Exception")
try:
rtc.alarm_left(1)
except:
print("Exception")
try:
rtc.alarm_cancel(1)
except:
print("Exception")
try:
rtc.alarm(5000)
except:
print("Exception")
try:
rtc = RTC(200000000)
except:
print("Exception")
try:
rtc = RTC((2015, 8, 29, 9, 0, 0, 0, None))
except:
print("Exception")

View File

@@ -0,0 +1,37 @@
<RTC>
(2015, 1, 1, 0, 0, 0)
(2015, 8, 29, 9, 0, 0)
(2015, 1, 1, 0, 0, 0)
(2015, 8, 29, 9, 0, 0)
True
True
0
0
0
0
0
(2000, 1, 1, 0, 0, 0)
(2000, 1, 31, 0, 0, 0)
(2000, 12, 31, 0, 0, 0)
(2016, 12, 31, 0, 0, 0)
(2016, 12, 31, 0, 0, 0)
(2016, 12, 31, 1, 0, 0)
(2016, 12, 31, 12, 0, 0)
(2016, 12, 31, 13, 0, 0)
(2016, 12, 31, 23, 0, 0)
(2016, 12, 31, 23, 1, 0)
(2016, 12, 31, 23, 59, 0)
(2016, 12, 31, 23, 59, 1)
(2016, 12, 31, 23, 59, 59)
(2048, 12, 31, 23, 59, 59)
True
True
True
True
True
Exception
Exception
Exception
Exception
Exception
Exception

View File

@@ -0,0 +1,45 @@
"""
SD card test for the CC3200 based boards.
"""
from machine import SD
import os
mch = os.uname().machine
if "LaunchPad" in mch:
sd_pins = ("GP16", "GP17", "GP15")
elif "WiPy" in mch:
sd_pins = ("GP10", "GP11", "GP15")
else:
raise Exception("Board not supported!")
sd = SD(pins=sd_pins)
print(sd)
sd.deinit()
print(sd)
sd.init(sd_pins)
print(sd)
sd = SD(0, pins=sd_pins)
sd = SD(id=0, pins=sd_pins)
sd = SD(0, sd_pins)
# check for memory leaks
for i in range(0, 1000):
sd = sd = SD(0, pins=sd_pins)
# next ones should raise
try:
sd = SD(pins=())
except Exception:
print("Exception")
try:
sd = SD(pins=("GP10", "GP11", "GP8"))
except Exception:
print("Exception")
try:
sd = SD(pins=("GP10", "GP11"))
except Exception:
print("Exception")

View File

@@ -0,0 +1,6 @@
<SD>
<SD>
<SD>
Exception
Exception
Exception

View File

@@ -0,0 +1,93 @@
"""
RTC IRQ test for the CC3200 based boards.
"""
from machine import RTC
import machine
import os
import time
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
def rtc_ticks_ms(rtc):
timedate = rtc.now()
return (timedate[5] * 1000) + (timedate[6] // 1000)
rtc_irq_count = 0
def alarm_handler(rtc_o):
global rtc_irq
global rtc_irq_count
if rtc_irq.flags() & RTC.ALARM0:
rtc_irq_count += 1
rtc = RTC()
rtc.alarm(time=500, repeat=True)
rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler)
# active mode
time.sleep_ms(1000)
rtc.alarm_cancel()
print(rtc_irq_count == 2)
rtc_irq_count = 0
rtc.alarm(time=200, repeat=True)
time.sleep_ms(1000)
rtc.alarm_cancel()
print(rtc_irq_count == 5)
rtc_irq_count = 0
rtc.alarm(time=100, repeat=True)
time.sleep_ms(1000)
rtc.alarm_cancel()
print(rtc_irq_count == 10)
# deep sleep mode
rtc.alarm_cancel()
rtc_irq_count = 0
rtc.alarm(time=50, repeat=True)
rtc_irq.init(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP | machine.IDLE)
while rtc_irq_count < 3:
machine.sleep()
print(rtc_irq_count == 3)
# no repetition
rtc.alarm_cancel()
rtc_irq_count = 0
rtc.alarm(time=100, repeat=False)
time.sleep_ms(250)
print(rtc_irq_count == 1)
rtc.alarm_cancel()
t0 = rtc_ticks_ms(rtc)
rtc.alarm(time=500, repeat=False)
machine.sleep()
t1 = rtc_ticks_ms(rtc)
print(abs(t1 - t0 - 500) < 20)
# deep sleep repeated mode
rtc.alarm_cancel()
rtc_irq_count = 0
rtc.alarm(time=500, repeat=True)
t0 = rtc_ticks_ms(rtc)
rtc_irq = rtc.irq(trigger=RTC.ALARM0, handler=alarm_handler, wake=machine.SLEEP)
while rtc_irq_count < 3:
machine.sleep()
t1 = rtc_ticks_ms(rtc)
print(abs(t1 - t0 - (500 * rtc_irq_count)) < 25)
# next ones must raise
try:
rtc_irq = rtc.irq(trigger=10, handler=alarm_handler)
except:
print("Exception")
try:
rtc_irq = rtc.irq(trigger=RTC.ALARM0, wake=1789456)
except:
print("Exception")

View File

@@ -0,0 +1,11 @@
True
True
True
True
True
True
True
True
True
Exception
Exception

View File

@@ -0,0 +1,147 @@
"""
SPI test for the CC3200 based boards.
"""
from machine import SPI
import os
mch = os.uname().machine
if "LaunchPad" in mch:
spi_pins = ("GP14", "GP16", "GP30")
elif "WiPy" in mch:
spi_pins = ("GP14", "GP16", "GP30")
else:
raise Exception("Board not supported!")
spi = SPI(0, SPI.MASTER, baudrate=2000000, polarity=0, phase=0, firstbit=SPI.MSB, pins=spi_pins)
print(spi)
spi = SPI(baudrate=5000000)
print(spi)
spi = SPI(0, SPI.MASTER, baudrate=200000, bits=16, polarity=0, phase=0)
print(spi)
spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=0, phase=1)
print(spi)
spi = SPI(0, SPI.MASTER, baudrate=5000000, bits=32, polarity=1, phase=0)
print(spi)
spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=1, phase=1)
print(spi)
spi.init(baudrate=20000000, polarity=0, phase=0)
print(spi)
spi = SPI()
print(spi)
SPI(mode=SPI.MASTER)
SPI(mode=SPI.MASTER, pins=spi_pins)
SPI(id=0, mode=SPI.MASTER, polarity=0, phase=0, pins=("GP14", "GP16", "GP15"))
SPI(0, SPI.MASTER, polarity=0, phase=0, pins=("GP31", "GP16", "GP15"))
spi = SPI(0, SPI.MASTER, baudrate=10000000, polarity=0, phase=0, pins=spi_pins)
print(spi.write("123456") == 6)
buffer_r = bytearray(10)
print(spi.readinto(buffer_r) == 10)
print(spi.readinto(buffer_r, write=0x55) == 10)
read = spi.read(10)
print(len(read) == 10)
read = spi.read(10, write=0xFF)
print(len(read) == 10)
buffer_w = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
print(spi.write_readinto(buffer_w, buffer_r) == 10)
print(buffer_w == buffer_r)
# test all polaritiy and phase combinations
spi.init(polarity=1, phase=0, pins=None)
buffer_r = bytearray(10)
spi.write_readinto(buffer_w, buffer_r)
print(buffer_w == buffer_r)
spi.init(polarity=1, phase=1, pins=None)
buffer_r = bytearray(10)
spi.write_readinto(buffer_w, buffer_r)
print(buffer_w == buffer_r)
spi.init(polarity=0, phase=1, pins=None)
buffer_r = bytearray(10)
spi.write_readinto(buffer_w, buffer_r)
print(buffer_w == buffer_r)
# test 16 and 32 bit transfers
buffer_w = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2])
buffer_r = bytearray(12)
spi.init(SPI.MASTER, baudrate=10000000, bits=16, polarity=0, phase=0, pins=None)
print(spi.write_readinto(buffer_w, buffer_r) == 12)
print(buffer_w == buffer_r)
buffer_r = bytearray(12)
spi.init(SPI.MASTER, baudrate=10000000, bits=32, polarity=0, phase=0, pins=None)
print(spi.write_readinto(buffer_w, buffer_r) == 12)
print(buffer_w == buffer_r)
# check for memory leaks...
for i in range(0, 1000):
spi = SPI(0, SPI.MASTER, baudrate=1000000)
# test deinit
spi = SPI(0, SPI.MASTER, baudrate=1000000)
spi.deinit()
print(spi)
spi = SPI(0, SPI.MASTER, baudrate=1000000)
# next ones must fail
try:
spi = SPI(0, 10, baudrate=10000000, polarity=0, phase=0)
except:
print("Exception")
try:
spi = SPI(0, mode=SPI.MASTER, baudrate=10000000, polarity=1, phase=2)
except:
print("Exception")
try:
spi = SPI(1, mode=SPI.MASTER, baudrate=10000000, polarity=1, phase=1)
except:
print("Exception")
try:
spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0)
except:
print("Exception")
try:
spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0, firstbit=2)
except:
print("Exception")
try:
spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=2, phase=0, pins=("GP1", "GP2"))
except:
print("Exception")
try:
spi = SPI(0, mode=SPI.MASTER, baudrate=2000000, polarity=0, phase=0, bits=9)
except:
print("Exception")
spi.deinit()
try:
spi.read(15)
except Exception:
print("Exception")
try:
spi.spi.readinto(buffer_r)
except Exception:
print("Exception")
try:
spi.spi.write("abc")
except Exception:
print("Exception")
try:
spi.write_readinto(buffer_w, buffer_r)
except Exception:
print("Exception")
# reinitialization must work
spi.init(baudrate=500000)
print(spi)

View File

@@ -0,0 +1,35 @@
SPI(0, SPI.MASTER, baudrate=2000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=5000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=200000, bits=16, polarity=0, phase=0, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=10000000, bits=8, polarity=0, phase=1, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=5000000, bits=32, polarity=1, phase=0, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=10000000, bits=8, polarity=1, phase=1, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=20000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
SPI(0, SPI.MASTER, baudrate=1000000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)
True
True
True
True
True
True
True
True
True
True
True
True
True
True
SPI(0)
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
SPI(0, SPI.MASTER, baudrate=500000, bits=8, polarity=0, phase=0, firstbit=SPI.MSB)

View File

@@ -0,0 +1,95 @@
import time
DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def is_leap(year):
return (year % 4) == 0
def test():
seconds = 0
wday = 5 # Jan 1, 2000 was a Saturday
for year in range(2000, 2049):
print("Testing %d" % year)
yday = 1
for month in range(1, 13):
if month == 2 and is_leap(year):
DAYS_PER_MONTH[2] = 29
else:
DAYS_PER_MONTH[2] = 28
for day in range(1, DAYS_PER_MONTH[month] + 1):
secs = time.mktime((year, month, day, 0, 0, 0, 0, 0))
if secs != seconds:
print(
"mktime failed for %d-%02d-%02d got %d expected %d"
% (year, month, day, secs, seconds)
)
tuple = time.localtime(seconds)
secs = time.mktime(tuple)
if secs != seconds:
print(
"localtime failed for %d-%02d-%02d got %d expected %d"
% (year, month, day, secs, seconds)
)
return
seconds += 86400
if yday != tuple[7]:
print(
"locatime for %d-%02d-%02d got yday %d, expecting %d"
% (year, month, day, tuple[7], yday)
)
return
if wday != tuple[6]:
print(
"locatime for %d-%02d-%02d got wday %d, expecting %d"
% (year, month, day, tuple[6], wday)
)
return
yday += 1
wday = (wday + 1) % 7
def spot_test(seconds, expected_time):
actual_time = time.localtime(seconds)
for i in range(len(actual_time)):
if actual_time[i] != expected_time[i]:
print(
"time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time
)
return
print("time.localtime(", seconds, ") returned", actual_time, "(pass)")
test()
# fmt: off
spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1))
spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1))
spot_test( 59, (2000, 1, 1, 0, 0, 59, 5, 1))
spot_test( 60, (2000, 1, 1, 0, 1, 0, 5, 1))
spot_test( 3599, (2000, 1, 1, 0, 59, 59, 5, 1))
spot_test( 3600, (2000, 1, 1, 1, 0, 0, 5, 1))
spot_test( -1, (1999, 12, 31, 23, 59, 59, 4, 365))
spot_test( 447549467, (2014, 3, 7, 23, 17, 47, 4, 66))
spot_test( -940984933, (1970, 3, 7, 23, 17, 47, 5, 66))
spot_test(-1072915199, (1966, 1, 1, 0, 0, 1, 5, 1))
spot_test(-1072915200, (1966, 1, 1, 0, 0, 0, 5, 1))
spot_test(-1072915201, (1965, 12, 31, 23, 59, 59, 4, 365))
# fmt: on
t1 = time.time()
time.sleep(2)
t2 = time.time()
print(abs(time.ticks_diff(t1, t2) - 2) <= 1)
t1 = time.ticks_ms()
time.sleep_ms(50)
t2 = time.ticks_ms()
print(abs(time.ticks_diff(t1, t2) - 50) <= 1)
t1 = time.ticks_us()
time.sleep_us(1000)
t2 = time.ticks_us()
print(time.ticks_diff(t1, t2) < 1500)
print(time.ticks_diff(time.ticks_cpu(), time.ticks_cpu()) < 16384)

View File

@@ -0,0 +1,65 @@
Testing 2000
Testing 2001
Testing 2002
Testing 2003
Testing 2004
Testing 2005
Testing 2006
Testing 2007
Testing 2008
Testing 2009
Testing 2010
Testing 2011
Testing 2012
Testing 2013
Testing 2014
Testing 2015
Testing 2016
Testing 2017
Testing 2018
Testing 2019
Testing 2020
Testing 2021
Testing 2022
Testing 2023
Testing 2024
Testing 2025
Testing 2026
Testing 2027
Testing 2028
Testing 2029
Testing 2030
Testing 2031
Testing 2032
Testing 2033
Testing 2034
Testing 2035
Testing 2036
Testing 2037
Testing 2038
Testing 2039
Testing 2040
Testing 2041
Testing 2042
Testing 2043
Testing 2044
Testing 2045
Testing 2046
Testing 2047
Testing 2048
time.localtime( 0 ) returned (2000, 1, 1, 0, 0, 0, 5, 1) (pass)
time.localtime( 1 ) returned (2000, 1, 1, 0, 0, 1, 5, 1) (pass)
time.localtime( 59 ) returned (2000, 1, 1, 0, 0, 59, 5, 1) (pass)
time.localtime( 60 ) returned (2000, 1, 1, 0, 1, 0, 5, 1) (pass)
time.localtime( 3599 ) returned (2000, 1, 1, 0, 59, 59, 5, 1) (pass)
time.localtime( 3600 ) returned (2000, 1, 1, 1, 0, 0, 5, 1) (pass)
time.localtime( -1 ) returned (1999, 12, 31, 23, 59, 59, 4, 365) (pass)
time.localtime( 447549467 ) returned (2014, 3, 7, 23, 17, 47, 4, 66) (pass)
time.localtime( -940984933 ) returned (1970, 3, 7, 23, 17, 47, 5, 66) (pass)
time.localtime( -1072915199 ) returned (1966, 1, 1, 0, 0, 1, 5, 1) (pass)
time.localtime( -1072915200 ) returned (1966, 1, 1, 0, 0, 0, 5, 1) (pass)
time.localtime( -1072915201 ) returned (1965, 12, 31, 23, 59, 59, 4, 365) (pass)
True
True
True
True

View File

@@ -0,0 +1,118 @@
"""
Timer test for the CC3200 based boards.
"""
from machine import Timer
import os
import time
mch = os.uname().machine
if "LaunchPad" in mch:
pwm_pin = "GP24"
elif "WiPy" in mch:
pwm_pin = "GP24"
else:
raise Exception("Board not supported!")
for i in range(4):
tim = Timer(i, mode=Timer.PERIODIC)
print(tim)
ch = tim.channel(Timer.A, freq=5)
print(ch)
ch = tim.channel(Timer.B, freq=5)
print(ch)
tim = Timer(i, mode=Timer.ONE_SHOT)
print(tim)
ch = tim.channel(Timer.A, freq=50)
print(ch)
ch = tim.channel(Timer.B, freq=50)
print(ch)
tim = Timer(i, mode=Timer.PWM)
print(tim)
ch = tim.channel(Timer.A, freq=50000, duty_cycle=2000, polarity=Timer.POSITIVE)
print(ch)
ch = tim.channel(Timer.B, freq=50000, duty_cycle=8000, polarity=Timer.NEGATIVE)
print(ch)
tim.deinit()
print(tim)
for i in range(4):
tim = Timer(i, mode=Timer.PERIODIC)
tim.deinit()
class TimerTest:
def __init__(self):
self.tim = Timer(0, mode=Timer.PERIODIC)
self.int_count = 0
def timer_isr(self, tim_ch):
self.int_count += 1
timer_test = TimerTest()
ch = timer_test.tim.channel(Timer.A, freq=5)
print(ch.freq() == 5)
ch.irq(handler=timer_test.timer_isr, trigger=Timer.TIMEOUT)
time.sleep_ms(1001)
print(timer_test.int_count == 5)
ch.freq(100)
timer_test.int_count = 0
time.sleep_ms(1001)
print(timer_test.int_count == 100)
ch.freq(1000)
time.sleep_ms(1500)
timer_test.int_count = 0
time.sleep_ms(2000)
print(timer_test.int_count == 2000)
timer_test.tim.deinit()
timer_test.tim.init(mode=Timer.ONE_SHOT)
ch = timer_test.tim.channel(Timer.A, period=100000)
ch.irq(handler=timer_test.timer_isr, trigger=Timer.TIMEOUT)
timer_test.int_count = 0
time.sleep_ms(101)
print(timer_test.int_count == 1)
time.sleep_ms(101)
print(timer_test.int_count == 1)
timer_test.tim.deinit()
print(timer_test.tim)
# 32 bit modes
tim = Timer(0, mode=Timer.PERIODIC, width=32)
ch = tim.channel(Timer.A | Timer.B, period=5000000)
# check for memory leaks...
for i in range(1000):
tim = Timer(0, mode=Timer.PERIODIC)
ch = tim.channel(Timer.A, freq=5)
# next ones must fail
try:
tim = Timer(0, mode=12)
except:
print("Exception")
try:
tim = Timer(4, mode=Timer.ONE_SHOT)
except:
print("Exception")
try:
tim = Timer(0, mode=Timer.PWM, width=32)
except:
print("Exception")
tim = Timer(0, mode=Timer.PWM)
try:
ch = tim.channel(TIMER_A | TIMER_B, freq=10)
except:
print("Exception")
try:
ch = tim.channel(TIMER_A, freq=4)
except:
print("Exception")

View File

@@ -0,0 +1,52 @@
Timer(0, mode=Timer.PERIODIC)
timer.channel(Timer.A, freq=5)
timer.channel(Timer.B, freq=5)
Timer(0, mode=Timer.ONE_SHOT)
timer.channel(Timer.A, freq=50)
timer.channel(Timer.B, freq=50)
Timer(0, mode=Timer.PWM)
timer.channel(Timer.A, freq=50000, polarity=Timer.POSITIVE, duty_cycle=20.00)
timer.channel(Timer.B, freq=50000, polarity=Timer.NEGATIVE, duty_cycle=80.00)
Timer(0, mode=Timer.PWM)
Timer(1, mode=Timer.PERIODIC)
timer.channel(Timer.A, freq=5)
timer.channel(Timer.B, freq=5)
Timer(1, mode=Timer.ONE_SHOT)
timer.channel(Timer.A, freq=50)
timer.channel(Timer.B, freq=50)
Timer(1, mode=Timer.PWM)
timer.channel(Timer.A, freq=50000, polarity=Timer.POSITIVE, duty_cycle=20.00)
timer.channel(Timer.B, freq=50000, polarity=Timer.NEGATIVE, duty_cycle=80.00)
Timer(1, mode=Timer.PWM)
Timer(2, mode=Timer.PERIODIC)
timer.channel(Timer.A, freq=5)
timer.channel(Timer.B, freq=5)
Timer(2, mode=Timer.ONE_SHOT)
timer.channel(Timer.A, freq=50)
timer.channel(Timer.B, freq=50)
Timer(2, mode=Timer.PWM)
timer.channel(Timer.A, freq=50000, polarity=Timer.POSITIVE, duty_cycle=20.00)
timer.channel(Timer.B, freq=50000, polarity=Timer.NEGATIVE, duty_cycle=80.00)
Timer(2, mode=Timer.PWM)
Timer(3, mode=Timer.PERIODIC)
timer.channel(Timer.A, freq=5)
timer.channel(Timer.B, freq=5)
Timer(3, mode=Timer.ONE_SHOT)
timer.channel(Timer.A, freq=50)
timer.channel(Timer.B, freq=50)
Timer(3, mode=Timer.PWM)
timer.channel(Timer.A, freq=50000, polarity=Timer.POSITIVE, duty_cycle=20.00)
timer.channel(Timer.B, freq=50000, polarity=Timer.NEGATIVE, duty_cycle=80.00)
Timer(3, mode=Timer.PWM)
True
True
True
True
True
True
Timer(0, mode=Timer.ONE_SHOT)
Exception
Exception
Exception
Exception
Exception

View File

@@ -0,0 +1,164 @@
"""
UART test for the CC3200 based boards.
UART0 and UART1 must be connected together for this test to pass.
"""
from machine import UART
from machine import Pin
import os
import time
mch = os.uname().machine
if "LaunchPad" in mch:
uart_id_range = range(0, 2)
uart_pins = [
[("GP12", "GP13"), ("GP12", "GP13", "GP7", "GP6")],
[("GP16", "GP17"), ("GP16", "GP17", "GP7", "GP6")],
]
elif "WiPy" in mch:
uart_id_range = range(0, 2)
uart_pins = [
[("GP12", "GP13"), ("GP12", "GP13", "GP7", "GP6")],
[("GP16", "GP17"), ("GP16", "GP17", "GP7", "GP6")],
]
else:
raise Exception("Board not supported!")
# just in case we have the repl duplicated on any of the uarts
os.dupterm(None)
for uart_id in uart_id_range:
uart = UART(uart_id, 38400)
print(uart)
uart.init(57600, 8, None, 1, pins=uart_pins[uart_id][0])
uart.init(baudrate=9600, stop=2, parity=UART.EVEN, pins=uart_pins[uart_id][1])
uart.init(baudrate=115200, parity=UART.ODD, stop=0, pins=uart_pins[uart_id][0])
uart = UART(baudrate=1000000)
uart.sendbreak()
uart = UART(baudrate=1000000)
uart = UART()
print(uart)
uart = UART(baudrate=38400, pins=("GP12", "GP13"))
print(uart)
uart = UART(pins=("GP12", "GP13"))
print(uart)
uart = UART(pins=(None, "GP17"))
print(uart)
uart = UART(baudrate=57600, pins=("GP16", "GP17"))
print(uart)
# now it's time for some loopback tests between the uarts
uart0 = UART(0, 1000000, pins=uart_pins[0][0])
print(uart0)
uart1 = UART(1, 1000000, pins=uart_pins[1][0])
print(uart1)
print(uart0.write(b"123456") == 6)
print(uart1.read() == b"123456")
print(uart1.write(b"123") == 3)
print(uart0.read(1) == b"1")
print(uart0.read(2) == b"23")
print(uart0.read() == None)
uart0.write(b"123")
buf = bytearray(3)
print(uart1.readinto(buf, 1) == 1)
print(buf)
print(uart1.readinto(buf) == 2)
print(buf)
# try initializing without the id
uart0 = UART(baudrate=1000000, pins=uart_pins[0][0])
uart0.write(b"1234567890")
time.sleep_ms(2) # because of the fifo interrupt levels
print(uart1.any() == 10)
print(uart1.readline() == b"1234567890")
print(uart1.any() == 0)
uart0.write(b"1234567890")
print(uart1.read() == b"1234567890")
# tx only mode
uart0 = UART(0, 1000000, pins=("GP12", None))
print(uart0.write(b"123456") == 6)
print(uart1.read() == b"123456")
print(uart1.write(b"123") == 3)
print(uart0.read() == None)
# rx only mode
uart0 = UART(0, 1000000, pins=(None, "GP13"))
print(uart0.write(b"123456") == 6)
print(uart1.read() == None)
print(uart1.write(b"123") == 3)
print(uart0.read() == b"123")
# leave pins as they were (rx only mode)
uart0 = UART(0, 1000000, pins=None)
print(uart0.write(b"123456") == 6)
print(uart1.read() == None)
print(uart1.write(b"123") == 3)
print(uart0.read() == b"123")
# no pin assignment
uart0 = UART(0, 1000000, pins=(None, None))
print(uart0.write(b"123456789") == 9)
print(uart1.read() == None)
print(uart1.write(b"123456789") == 9)
print(uart0.read() == None)
print(Pin.board.GP12)
print(Pin.board.GP13)
# check for memory leaks...
for i in range(0, 1000):
uart0 = UART(0, 1000000)
uart1 = UART(1, 1000000)
# next ones must raise
try:
UART(0, 9600, parity=None, pins=("GP12", "GP13", "GP7"))
except Exception:
print("Exception")
try:
UART(0, 9600, parity=UART.ODD, pins=("GP12", "GP7"))
except Exception:
print("Exception")
uart0 = UART(0, 1000000)
uart0.deinit()
try:
uart0.any()
except Exception:
print("Exception")
try:
uart0.read()
except Exception:
print("Exception")
try:
uart0.write("abc")
except Exception:
print("Exception")
try:
uart0.sendbreak("abc")
except Exception:
print("Exception")
try:
UART(2, 9600)
except Exception:
print("Exception")
for uart_id in uart_id_range:
uart = UART(uart_id, 1000000)
uart.deinit()
# test printing an unitialized uart
print(uart)
# initialize it back and check that it works again
uart.init(115200)
print(uart)
uart.read()

View File

@@ -0,0 +1,52 @@
UART(0, baudrate=38400, bits=8, parity=None, stop=1)
UART(1, baudrate=38400, bits=8, parity=None, stop=1)
UART(0, baudrate=9600, bits=8, parity=None, stop=1)
UART(0, baudrate=38400, bits=8, parity=None, stop=1)
UART(0, baudrate=9600, bits=8, parity=None, stop=1)
UART(1, baudrate=9600, bits=8, parity=None, stop=1)
UART(1, baudrate=57600, bits=8, parity=None, stop=1)
UART(0, baudrate=1000000, bits=8, parity=None, stop=1)
UART(1, baudrate=1000000, bits=8, parity=None, stop=1)
True
True
True
True
True
True
True
bytearray(b'1\x00\x00')
True
bytearray(b'23\x00')
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
Pin('GP12', mode=Pin.IN, pull=None, drive=Pin.MED_POWER, alt=-1)
Pin('GP13', mode=Pin.IN, pull=None, drive=Pin.MED_POWER, alt=-1)
Exception
Exception
Exception
Exception
Exception
Exception
Exception
UART(0)
UART(0, baudrate=115200, bits=8, parity=None, stop=1)
UART(1)
UART(1, baudrate=115200, bits=8, parity=None, stop=1)

View File

@@ -0,0 +1,157 @@
"""
UART IRQ test for the CC3200 based boards.
"""
from machine import UART
import os
import time
mch = os.uname().machine
if "LaunchPad" in mch:
uart_pins = [
[("GP12", "GP13"), ("GP12", "GP13", "GP7", "GP6")],
[("GP16", "GP17"), ("GP16", "GP17", "GP7", "GP6")],
]
elif "WiPy" in mch:
uart_pins = [
[("GP12", "GP13"), ("GP12", "GP13", "GP7", "GP6")],
[("GP16", "GP17"), ("GP16", "GP17", "GP7", "GP6")],
]
else:
raise Exception("Board not supported!")
# just in case we have stdio duplicated on any of the uarts
os.dupterm(None)
uart0 = UART(0, 1000000, pins=uart_pins[0][0])
uart1 = UART(1, 1000000, pins=uart_pins[1][0])
uart0_int_count = 0
uart1_int_count = 0
def uart0_handler(uart_o):
global uart0_irq
global uart0_int_count
if uart0_irq.flags() & UART.RX_ANY:
uart0_int_count += 1
def uart1_handler(uart_o):
global uart1_irq
global uart1_int_count
if uart1_irq.flags() & UART.RX_ANY:
uart1_int_count += 1
uart0_irq = uart0.irq(trigger=UART.RX_ANY, handler=uart0_handler)
uart1_irq = uart1.irq(trigger=UART.RX_ANY, handler=uart1_handler)
uart0.write(b"123")
# wait for the characters to be received
while not uart1.any():
pass
time.sleep_us(100)
print(uart1.any() == 3)
print(uart1_int_count > 0)
print(uart1_irq.flags() == 0)
print(uart0_irq.flags() == 0)
print(uart1.read() == b"123")
uart1.write(b"12345")
# wait for the characters to be received
while not uart0.any():
pass
time.sleep_us(100)
print(uart0.any() == 5)
print(uart0_int_count > 0)
print(uart0_irq.flags() == 0)
print(uart1_irq.flags() == 0)
print(uart0.read() == b"12345")
# do it again
uart1_int_count = 0
uart0.write(b"123")
# wait for the characters to be received
while not uart1.any():
pass
time.sleep_us(100)
print(uart1.any() == 3)
print(uart1_int_count > 0)
print(uart1_irq.flags() == 0)
print(uart0_irq.flags() == 0)
print(uart1.read() == b"123")
# disable the interrupt
uart1_irq.disable()
# do it again
uart1_int_count = 0
uart0.write(b"123")
# wait for the characters to be received
while not uart1.any():
pass
time.sleep_us(100)
print(uart1.any() == 3)
print(uart1_int_count == 0) # no interrupt triggered this time
print(uart1_irq.flags() == 0)
print(uart0_irq.flags() == 0)
print(uart1.read() == b"123")
# enable the interrupt
uart1_irq.enable()
# do it again
uart1_int_count = 0
uart0.write(b"123")
# wait for the characters to be received
while not uart1.any():
pass
time.sleep_us(100)
print(uart1.any() == 3)
print(uart1_int_count > 0)
print(uart1_irq.flags() == 0)
print(uart0_irq.flags() == 0)
print(uart1.read() == b"123")
uart1_irq.init(trigger=UART.RX_ANY, handler=None) # No handler
# do it again
uart1_int_count = 0
uart0.write(b"123")
# wait for the characters to be received
while not uart1.any():
pass
time.sleep_us(100)
print(uart1.any() == 3)
print(uart1_int_count == 0) # no interrupt handler called
print(uart1_irq.flags() == 0)
print(uart0_irq.flags() == 0)
print(uart1.read() == b"123")
# check for memory leaks
for i in range(0, 1000):
uart0_irq = uart0.irq(trigger=UART.RX_ANY, handler=uart0_handler)
uart1_irq = uart1.irq(trigger=UART.RX_ANY, handler=uart1_handler)
# next ones must raise
try:
uart0_irq = uart0.irq(trigger=100, handler=uart0_handler)
except:
print("Exception")
try:
uart0_irq = uart0.irq(trigger=0)
except:
print("Exception")
try:
uart0_irq = uart0.irq(trigger=UART.RX_ANY, wake=Sleep.SUSPENDED)
except:
print("Exception")
uart0_irq.disable()
uart1_irq.disable()

View File

@@ -0,0 +1,33 @@
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
Exception
Exception
Exception

View File

@@ -0,0 +1,38 @@
"""
WDT test for the CC3200 based boards
"""
from machine import WDT
import time
# test the invalid cases first
try:
wdt = WDT(1)
except Exception:
print("Exception")
try:
wdt = WDT(0, 500)
except Exception:
print("Exception")
try:
wdt = WDT(1, timeout=2000)
except Exception:
print("Exception")
wdt = WDT(timeout=1000)
print(wdt)
try:
wdt = WDT(0, timeout=2000)
except Exception:
print("Exception")
time.sleep_ms(500)
wdt.feed()
print(wdt)
time.sleep_ms(900)
wdt.feed()
print(wdt)
time.sleep_ms(950)

View File

@@ -0,0 +1,7 @@
Exception
Exception
Exception
<WDT>
Exception
<WDT>
<WDT>

View File

@@ -0,0 +1,42 @@
"""
machine test for the CC3200 based boards.
"""
import machine
import os
from network import WLAN
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
wifi = WLAN()
print(machine)
machine.idle()
print(machine.freq() == (80000000,))
print(machine.unique_id() == wifi.mac())
machine.main("main.py")
rand_nums = []
for i in range(0, 100):
rand = machine.rng()
if rand not in rand_nums:
rand_nums.append(rand)
else:
print("RNG number repeated")
break
for i in range(0, 10):
machine.idle()
print("Active")
print(machine.reset_cause() >= 0)
print(machine.wake_reason() >= 0)
try:
machine.main(123456)
except:
print("Exception")

View File

@@ -0,0 +1,7 @@
<module 'umachine'>
True
True
Active
True
True
Exception

View File

@@ -0,0 +1,41 @@
"""
network server test for the CC3200 based boards.
"""
import os
import network
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
server = network.Server()
print(server.timeout() == 300)
print(server.isrunning() == True)
server.deinit()
print(server.isrunning() == False)
server.init(login=("test-user", "test-password"), timeout=60)
print(server.isrunning() == True)
print(server.timeout() == 60)
server.deinit()
print(server.isrunning() == False)
server.init()
print(server.isrunning() == True)
try:
server.init(1)
except:
print("Exception")
try:
server.init(0, login=("0000000000011111111111222222222222333333", "abc"))
except:
print("Exception")
try:
server.timeout(1)
except:
print("Exception")

View File

@@ -0,0 +1,10 @@
True
True
True
True
True
True
True
Exception
Exception
Exception

View File

@@ -0,0 +1,183 @@
"""
WLAN test for the CC3200 based boards.
"""
from network import WLAN
import os
import time
import testconfig
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
def wait_for_connection(wifi, timeout=10):
while not wifi.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wifi.isconnected():
print("Connected")
else:
print("Connection failed!")
wifi = WLAN(0, WLAN.STA)
print(wifi.mode() == WLAN.STA)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.AP)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 1)
print(wifi.auth() == None)
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(0, mode=WLAN.AP, ssid="test-wlan", auth=(WLAN.WPA, "123456abc"), channel=7)
print(wifi.mode() == WLAN.AP)
print(wifi.channel() == 7)
print(wifi.ssid() == "test-wlan")
print(wifi.auth() == (WLAN.WPA, "123456abc"))
print(wifi.antenna() == WLAN.INT_ANT)
wifi = WLAN(mode=WLAN.STA)
print(wifi.mode() == WLAN.STA)
time.sleep(5) # this ensures a full network scan
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
# test that the scan results contains the desired params
print(len(net.bssid) == 6)
print(net.channel == None)
print(net.sec == testconfig.wlan_auth[0])
print(net.rssi < 0)
print("Network found")
break
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.channel(7)
print(wifi.channel() == 7)
wifi.ssid("t-wlan")
print(wifi.ssid() == "t-wlan")
wifi.auth(None)
print(wifi.auth() == None)
wifi.auth((WLAN.WEP, "11223344556677889900"))
print(wifi.auth() == (WLAN.WEP, "11223344556677889900"))
wifi.antenna(WLAN.INT_ANT)
print(wifi.antenna() == WLAN.INT_ANT)
wifi.antenna(WLAN.EXT_ANT)
print(wifi.antenna() == WLAN.EXT_ANT)
time.sleep(2) # this ensures a full network scan
scan_r = wifi.scan()
print(len(scan_r) > 3)
for net in scan_r:
if net.ssid == testconfig.wlan_ssid:
print("Network found")
break
wifi.antenna(WLAN.INT_ANT)
wifi.mode(WLAN.STA)
print(wifi.mode() == WLAN.STA)
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=10000)
wait_for_connection(wifi)
wifi.ifconfig(config="dhcp")
wait_for_connection(wifi)
print("0.0.0.0" not in wifi.ifconfig())
wifi.ifconfig(0, ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
wait_for_connection(wifi)
print(wifi.ifconfig(0) == ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
wait_for_connection(wifi)
print(wifi.isconnected() == True)
wifi.disconnect()
print(wifi.isconnected() == False)
t0 = time.ticks_ms()
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
print(time.ticks_ms() - t0 < 500)
wifi.disconnect()
print(wifi.isconnected() == False)
# test init again
wifi.init(WLAN.AP, ssid="www.wipy.io", auth=None, channel=5, antenna=WLAN.INT_ANT)
print(wifi.mode() == WLAN.AP)
# get the current instance without re-init
wifi = WLAN()
print(wifi.mode() == WLAN.AP)
wifi = WLAN(0)
print(wifi.mode() == WLAN.AP)
# test the MAC address length
print(len(wifi.mac()) == 6)
# next ones MUST raise
try:
wifi.init(mode=12345)
except:
print("Exception")
try:
wifi.init(1, mode=WLAN.AP)
except:
print("Exception")
try:
wifi.init(mode=WLAN.AP, ssid=None)
except:
print("Exception")
try:
wifi = WLAN(mode=WLAN.AP, channel=12)
except:
print("Exception")
try:
wifi.antenna(2)
except:
print("Exception")
try:
wifi.mode(10)
except:
print("Exception")
try:
wifi.ssid(
"11111sdfasdfasdfasdf564sdf654asdfasdf123451245ssdgfsdf1111111111111111111111111234123412341234asdfasdf"
)
except:
print("Exception")
try:
wifi.auth((0))
except:
print("Exception")
try:
wifi.auth((0, None))
except:
print("Exception")
try:
wifi.auth((10, 10))
except:
print("Exception")
try:
wifi.channel(0)
except:
print("Exception")
try:
wifi.ifconfig(1, "dhcp")
except:
print("Exception")
try:
wifi.ifconfig(config=())
except:
print("Exception")

View File

@@ -0,0 +1,55 @@
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
Network found
True
True
True
True
True
True
True
True
Network found
True
Connected
Connected
True
Connected
True
Connected
True
True
True
True
True
True
True
True
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception
Exception