4848"""
4949import random
5050
51- import adafruit_sdcard
5251import board
5352import busio
5453import digitalio
54+ import adafruit_sdcard
5555import storage
5656
5757__version__ = "0.0.0-auto.0"
5858__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BoardTest.git"
5959
6060# Constants
61- MOSI_PIN_NAME = ' SD_MOSI'
62- MISO_PIN_NAME = ' SD_MISO'
63- SCK_PIN_NAME = ' SD_SCK'
64- CS_PIN_NAME = ' SD_CS'
65- FILENAME = "test.txt" # File that will be written to
66- BAUD_RATE = 100000 # Bits per second
67- NUM_UART_BYTES = 40 # Number of bytes to transmit over UART
68- ASCII_MIN = 0x21 # '!' Lowest ASCII char in random range (inclusive)
69- ASCII_MAX = 0x7E # '~' Highest ASCII char in random range (inclusive)
61+ MOSI_PIN_NAME = " SD_MOSI"
62+ MISO_PIN_NAME = " SD_MISO"
63+ SCK_PIN_NAME = " SD_SCK"
64+ CS_PIN_NAME = " SD_CS"
65+ FILENAME = "test.txt" # File that will be written to
66+ BAUD_RATE = 100000 # Bits per second
67+ NUM_UART_BYTES = 40 # Number of bytes to transmit over UART
68+ ASCII_MIN = 0x21 # '!' Lowest ASCII char in random range (inclusive)
69+ ASCII_MAX = 0x7E # '~' Highest ASCII char in random range (inclusive)
7070
7171# Test result strings
7272PASS = "PASS"
7373FAIL = "FAIL"
7474NA = "N/A"
7575
76- def run_test (pins ,
77- mosi_pin = MOSI_PIN_NAME ,
78- miso_pin = MISO_PIN_NAME ,
79- sck_pin = SCK_PIN_NAME ,
80- cs_pin = CS_PIN_NAME ):
76+
77+ def run_test (
78+ pins ,
79+ mosi_pin = MOSI_PIN_NAME ,
80+ miso_pin = MISO_PIN_NAME ,
81+ sck_pin = SCK_PIN_NAME ,
82+ cs_pin = CS_PIN_NAME ,
83+ ):
8184
8285 """
8386 Performs random writes and reads to file on attached SD card.
@@ -96,8 +99,7 @@ def run_test(pins,
9699
97100 # Tell user to connect SD card
98101 print ("Insert SD card into holder and connect SPI lines to holder." )
99- print ("Connect " + cs_pin + " to the CS (DAT3) pin on the SD " +
100- "card holder." )
102+ print ("Connect " + cs_pin + " to the CS (DAT3) pin on the SD " + "card holder." )
101103 print ("WARNING: " + FILENAME + " will be created or overwritten." )
102104 print ("Press enter to continue." )
103105 input ()
@@ -108,9 +110,11 @@ def run_test(pins,
108110 csel .value = True
109111
110112 # Set up SPI
111- spi = busio .SPI (getattr (board , sck_pin ),
112- MOSI = getattr (board , mosi_pin ),
113- MISO = getattr (board , miso_pin ))
113+ spi = busio .SPI (
114+ getattr (board , sck_pin ),
115+ MOSI = getattr (board , mosi_pin ),
116+ MISO = getattr (board , miso_pin ),
117+ )
114118
115119 # Try to connect to the card and mount the filesystem
116120 try :
@@ -160,24 +164,26 @@ def run_test(pins,
160164 print ("No SD card pins found" )
161165 return NA , []
162166
167+
163168def _main ():
164169
165170 # List out all the pins available to us
166- pins = [ p for p in dir (board )]
171+ pins = list ( dir (board ))
167172 print ()
168- print ("All pins found:" , end = ' ' )
173+ print ("All pins found:" , end = " " )
169174
170175 # Print pins
171176 for pin in pins :
172- print (pin , end = ' ' )
173- print (' \n ' )
177+ print (pin , end = " " )
178+ print (" \n " )
174179
175180 # Run test
176181 result = run_test (pins )
177182 print ()
178183 print (result [0 ])
179184 print ("Pins tested: " + str (result [1 ]))
180185
186+
181187# Execute only if run as main.py or code.py
182188if __name__ == "__main__" :
183189 _main ()
0 commit comments