Skip to content

Commit 11abbd8

Browse files
authored
Merge pull request #72 from michthom/michthom-patch-1
Enable CS "active-high" device support to resolve #71
2 parents b869a4a + 4b8955b commit 11abbd8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ repos:
3030
name: pylint (examples code)
3131
description: Run pylint rules on "examples/*.py" files
3232
entry: /usr/bin/env bash -c
33-
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
33+
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)']
3434
language: system

adafruit_bus_device/spi_device.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SPIDevice:
2121
:param ~busio.SPI spi: The SPI bus the device is on
2222
:param ~digitalio.DigitalInOut chip_select: The chip select pin object that implements the
2323
DigitalInOut API.
24+
:param bool cs_active_value: Set to true if your device requires CS to be active high.
25+
Defaults to false.
2426
:param int extra_clocks: The minimum number of clock cycles to cycle the bus after CS is high.
2527
(Used for SD cards.)
2628
@@ -55,6 +57,7 @@ def __init__(
5557
spi,
5658
chip_select=None,
5759
*,
60+
cs_active_value=False,
5861
baudrate=100000,
5962
polarity=0,
6063
phase=0,
@@ -66,6 +69,7 @@ def __init__(
6669
self.phase = phase
6770
self.extra_clocks = extra_clocks
6871
self.chip_select = chip_select
72+
self.cs_active_value = cs_active_value
6973
if self.chip_select:
7074
self.chip_select.switch_to_output(value=True)
7175

@@ -76,12 +80,12 @@ def __enter__(self):
7680
baudrate=self.baudrate, polarity=self.polarity, phase=self.phase
7781
)
7882
if self.chip_select:
79-
self.chip_select.value = False
83+
self.chip_select.value = self.cs_active_value
8084
return self.spi
8185

8286
def __exit__(self, exc_type, exc_val, exc_tb):
8387
if self.chip_select:
84-
self.chip_select.value = True
88+
self.chip_select.value = not self.cs_active_value
8589
if self.extra_clocks > 0:
8690
buf = bytearray(1)
8791
buf[0] = 0xFF

0 commit comments

Comments
 (0)