Commit 6d1ff7e9 authored by Damien George's avatar Damien George
Browse files

tests: Add tests to create valid and invalid UART, I2C, SPI, CAN busses.

parent 17d9b500
from pyb import CAN
import pyb
# test we can correctly create by id or name
for bus in (-1, 0, 1, 2, 3, "YA", "YB", "YC"):
try:
CAN(bus, CAN.LOOPBACK)
print("CAN", bus)
except ValueError:
print("ValueError", bus)
CAN.initfilterbanks(14)
can = CAN(1)
print(can)
......
ValueError -1
ValueError 0
CAN 1
CAN 2
ValueError 3
CAN YA
CAN YB
ValueError YC
CAN(1)
CAN(1, CAN.LOOPBACK, extframe=False)
False
......
import pyb
from pyb import I2C
# test we can correctly create by id or name
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
try:
I2C(bus)
print("I2C", bus)
except ValueError:
print("ValueError", bus)
i2c = I2C(1)
i2c2 = I2C(2)
i2c.init(I2C.MASTER, baudrate=400000)
print(i2c.scan())
......
ValueError -1
ValueError 0
I2C 1
I2C 2
ValueError 3
I2C X
I2C Y
ValueError Z
[]
[76]
True
......
from pyb import SPI
# test we can correctly create by id or name
for bus in (-1, 0, 1, 2, 3, "X", "Y", "Z"):
try:
SPI(bus)
print("SPI", bus)
except ValueError:
print("ValueError", bus)
spi = SPI(1)
print(spi)
......
ValueError -1
ValueError 0
SPI 1
SPI 2
ValueError 3
SPI X
SPI Y
ValueError Z
SPI(1)
SPI(1, SPI.MASTER, baudrate=328125, prescaler=256, polarity=1, phase=0, bits=8)
SPI(1, SPI.SLAVE, polarity=1, phase=1, bits=8)
......
from pyb import UART
# test we can correctly create by id or name
for bus in (-1, 0, 1, 2, 3, 4, 5, 6, 7, "XA", "XB", "YA", "YB", "Z"):
try:
UART(bus, 9600)
print("UART", bus)
except ValueError:
print("ValueError", bus)
uart = UART(1)
uart = UART(1, 9600)
uart = UART(1, 9600, bits=8, parity=None, stop=1)
......
ValueError -1
ValueError 0
UART 1
UART 2
UART 3
UART 4
ValueError 5
UART 6
ValueError 7
UART XA
UART XB
UART YA
UART YB
ValueError Z
UART(1, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=0, read_buf_len=64)
UART(1, baudrate=2400, bits=8, parity=None, stop=1, timeout=1000, timeout_char=0, read_buf_len=64)
False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment