Skip to content

Commit 96803dc

Browse files
committed
Move SD card initializations into the if statement
As requested by review. Unable to test the "bitmapsaver_simpletest" bitmap palette example on my featherwing since SCK is in use by other things.
1 parent 877f507 commit 96803dc

3 files changed

+29
-31
lines changed

examples/bitmapsaver_screenshot_simpletest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4-
54
"""Example of taking a screenshot."""
65

76
# pylint:disable=invalid-name
@@ -14,13 +13,14 @@
1413

1514
TAKE_SCREENSHOT = False # Set to True to take a screenshot
1615

17-
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
18-
cs = digitalio.DigitalInOut(board.SD_CS)
19-
sdcard = adafruit_sdcard.SDCard(spi, cs)
20-
vfs = storage.VfsFat(sdcard)
21-
storage.mount(vfs, "/sd")
22-
2316
if TAKE_SCREENSHOT:
17+
# Initialize SD Card & Mount Virtual File System
18+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
19+
cs = digitalio.DigitalInOut(board.SD_CS)
20+
sdcard = adafruit_sdcard.SDCard(spi, cs)
21+
vfs = storage.VfsFat(sdcard)
22+
storage.mount(vfs, "/sd") # /sd is root dir of SD Card
23+
2424
print("Taking Screenshot... ")
2525
save_pixels("/sd/screenshot.bmp")
2626
print("Screenshot Saved")

examples/bitmapsaver_screenshot_tft_featherwing.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# SPDX-FileCopyrightText: 2022 DJDevon3 for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2023 DJDevon3
22
# SPDX-License-Identifier: MIT
3-
"""Screenshot on a 3.5" TFT Featherwing (integrated SD Card)"""
3+
""" Screenshot on a 3.5" TFT Featherwing (integrated SD Card) """
44
# pylint:disable=invalid-name
5+
56
import board
67
import digitalio
78
import displayio
@@ -18,24 +19,23 @@
1819

1920
TAKE_SCREENSHOT = False # Set to True to take a screenshot
2021

21-
# Initialize Protocol Busses and SD Card
22+
# Initialize SPI Bus
2223
spi = board.SPI()
23-
cs = digitalio.DigitalInOut(board.D5)
24-
sdcard = adafruit_sdcard.SDCard(spi, cs)
25-
vfs = storage.VfsFat(sdcard)
26-
displayio.release_displays()
2724

28-
# Setup Pinouts according to your feather board
25+
# Initialize TFT Featherwing Display
2926
tft_cs = board.D9
3027
tft_dc = board.D10
3128
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
3229
display = HX8357(display_bus, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT)
3330

34-
# Mount Virtual File System
35-
virtual_root = "/sd"
36-
storage.mount(vfs, virtual_root)
37-
3831
if TAKE_SCREENSHOT:
32+
# Initialize SD Card & Mount Virtual File System
33+
cs = digitalio.DigitalInOut(board.D5)
34+
sdcard = adafruit_sdcard.SDCard(spi, cs)
35+
vfs = storage.VfsFat(sdcard)
36+
virtual_root = "/sd" # /sd is root dir of SD Card
37+
storage.mount(vfs, virtual_root)
38+
3939
print("Taking Screenshot... ")
4040
save_pixels("/sd/screenshot.bmp", display)
4141
print("Screenshot Saved")

examples/bitmapsaver_simpletest.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
22
# SPDX-License-Identifier: MIT
3-
4-
53
"""Example of using save_bitmap"""
4+
# pylint:disable=invalid-name
65

76
import board
87
import busio
@@ -12,16 +11,7 @@
1211
import storage
1312
from adafruit_bitmapsaver import save_pixels
1413

15-
# pylint:disable=invalid-name
16-
17-
TAKE_SCREENSHOT = False # Set to True to take a screenshot
18-
19-
print("Setting up SD card")
20-
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
21-
cs = digitalio.DigitalInOut(board.SD_CS)
22-
sdcard = adafruit_sdcard.SDCard(spi, cs)
23-
vfs = storage.VfsFat(sdcard)
24-
storage.mount(vfs, "/sd")
14+
TAKE_SCREENSHOT = False # Set True to take a screenshot
2515

2616
WHITE = 0xFFFFFF
2717
BLACK = 0x000000
@@ -53,6 +43,14 @@
5343
bitmap[x, y] = 0
5444

5545
if TAKE_SCREENSHOT:
46+
# Initialize SD Card & Mount Virtual File System
47+
print("Setting up SD card")
48+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
49+
cs = digitalio.DigitalInOut(board.SD_CS)
50+
sdcard = adafruit_sdcard.SDCard(spi, cs)
51+
vfs = storage.VfsFat(sdcard)
52+
storage.mount(vfs, "/sd") # /sd is root dir of SD Card
53+
5654
print("Taking Screenshot... ")
5755
save_pixels("/sd/screenshot.bmp", bitmap, palette)
5856
print("Screenshot Saved")

0 commit comments

Comments
 (0)