8000 drivers: Replace deprecated Pin.high()/low() methods with .__call__(1… · micropython/micropython-esp32@1c9ee49 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 1c9ee49

Browse files
author
Paul Sokolovsky
committed
drivers: Replace deprecated Pin.high()/low() methods with .__call__(1/0).
1 parent bcf31a3 commit 1c9ee49

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

drivers/display/ssd1306.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,23 @@ def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
139139

140140
def write_cmd(self, cmd):
141141
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
142-
self.cs.high()
143-
self.dc.low()
144-
self.cs.low()
142+
self.cs(1)
143+
self.dc(0)
144+
self.cs(0)
145145
self.spi.write(bytearray([cmd]))
146-
self.cs.high()
146+
self.cs(1)
147147

148148
def write_data(self, buf):
149149
self.spi.init(baudrate=self.rate, polarity=0, phase=0)
150-
self.cs.high()
151-
self.dc.high()
152-
self.cs.low()
150+
self.cs(1)
151+
self.dc(1)
152+
self.cs(0)
153153
self.spi.write(buf)
154-
self.cs.high()
154+
self.cs(1)
155155

156156
def poweron(self):
157-
self.res.high()
157+
self.res(1)
158158
time.sleep_ms(1)
159-
self.res.low()
159+
self.res(0)
160160
time.sleep_ms(10)
161-
self.res.high()
161+
self.res(1)

drivers/nrf24l01/nrf24l01.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def __init__(self, spi, cs, ce, channel=46, payload_size=16):
6666
ce.init(ce.OUT, value=0)
6767

6868
# reset everything
69-
self.ce.low()
70-
self.cs.high()
69+
self.ce(0)
70+
self.cs(1)
7171
self.payload_size = payload_size
7272
self.pipe0_read_addr = None
7373
utime.sleep_ms(5)
@@ -109,36 +109,36 @@ def init_spi(self, baudrate):
109109
self.spi.init(master, baudrate=baudrate, polarity=0, phase=0)
110110

111111
def reg_read(self, reg):
112-
self.cs.low()
112+
self.cs(0)
113113
self.spi.readinto(self.buf, reg)
114114
self.spi.readinto(self.buf)
115-
self.cs.high()
115+
self.cs(1)
116116
return self.buf[0]
117117

118118
def reg_write_bytes(self, reg, buf):
119-
self.cs.low()
119+
self.cs(0)
120120
self.spi.readinto(self.buf, 0x20 | reg)
121121
self.spi.write(buf)
122-
self.cs.high()
122+
self.cs(1)
123123
return self.buf[0]
124124

125125
def reg_write(self, reg, value):
126-
self.cs.low()
126+
self.cs(0)
127127
self.spi.readinto(self.buf, 0x20 | reg)
128128
ret = self.buf[0]
129129
self.spi.readinto(self.buf, value)
130-
self.cs.high()
130+
self.cs(1)
131131
return ret
132132

133133
def flush_rx(self):
134-
self.cs.low()
134+
self.cs(0)
135135
self.spi.readinto(self.buf, FLUSH_RX)
136-
self.cs.high()
136+
self.cs(1)
137137

138138
def flush_tx(self):
139-
self.cs.low()
139+
self.cs(0)
140140
self.spi.readinto(self.buf, FLUSH_TX)
141-
self.cs.high()
141+
self.cs(1)
142142

143143
# power is one of POWER_x defines; speed is one of SPEED_x defines
144144
def set_power_speed(self, power, speed):
@@ -190,11 +190,11 @@ def start_listening(self):
190190

191191
self.flush_rx()
192192
self.flush_tx()
193-
self.ce.high()
193+
self.ce(1)
194194
utime.sleep_us(130)
195195

196196
def stop_listening(self):
197-
self.ce.low()
197+
self.ce(0)
198198
self.flush_tx()
199199
self.flush_rx()
200200

@@ -204,10 +204,10 @@ def any(self):
204204

205205
def recv(self):
206206
# get the data
207-
self.cs.low()
207+
self.cs(0)
208208
self.spi.readinto(self.buf, R_RX_PAYLOAD)
209209
buf = self.spi.read(self.payload_size)
210-
self.cs.high()
210+
self.cs(1)
211211
# clear RX ready flag
212212
self.reg_write(STATUS, RX_DR)
213213

@@ -229,17 +229,17 @@ def send_start(self, buf):
229229
self.reg_write(CONFIG, (self.reg_read(CONFIG) | PWR_UP) & ~PRIM_RX)
230230
utime.sleep_us(150)
231231
# send the data
232-
self.cs.low()
232+
self.cs(0)
233233
self.spi.readinto(self.buf, W_TX_PAYLOAD)
234234
self.spi.write(buf)
235235
if len(buf) < self.payload_size:
236236
self.spi.write(b'\x00' * (self.payload_size - len(buf))) # pad out data
237-
self.cs.high()
237+
self.cs(1)
238238

239239
# enable the chip so it can send the data
240-
self.ce.high()
240+
self.ce(1)
241241
utime.sleep_us(15) # needs to be >10us
242-
self.ce.low()
242+
self.ce(0)
243243

244244
# returns None if send still in progress, 1 for success, 2 for fail
245245
def send_done(self):

drivers/onewire/ds18x20.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
The following example assumes the ground of your DS18x20 is connected to
88
Y11, vcc is connected to Y9 and the data pin is connected to Y10.
99
10-
>>> from pyb import Pin
10+
>>> from machine import Pin
1111
>>> gnd = Pin('Y11', Pin.OUT_PP)
12-
>>> gnd.low()
12+
>>> gnd.off()
1313
>>> vcc = Pin('Y9', Pin.OUT_PP)
14-
>>> vcc.high()
14+
>>> vcc.on()
1515
1616
>>> from ds18x20 import DS18X20
1717
>>> d = DS18X20(Pin('Y10'))

drivers/sdcard/sdcard.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def init_card_v2(self):
130130
raise OSError("timeout waiting for v2 card")
131131

132132
def cmd(self, cmd, arg, crc, final=0, release=True):
133-
self.cs.low()
133+
self.cs(0)
134134

135135
# create and send the command
136136
buf = self.cmdbuf
@@ -150,12 +150,12 @@ def cmd(self, cmd, arg, crc, final=0, release=True):
150150
for j in range(final):
151151
self.spi.write(b'\xff')
152152
if release:
153-
self.cs.high()
153+
self.cs(1)
154154
self.spi.write(b'\xff')
155155
return response
156156

157157
# timeout
158-
self.cs.high()
158+
self.cs(1)
159159
self.spi.write(b'\xff')
160160
return -1
161161

@@ -164,15 +164,15 @@ def cmd_nodata(self, cmd):
164164
self.spi.read(1, 0xff) # ignore stuff byte
165165
for _ in range(_CMD_TIMEOUT):
166166
if self.spi.read(1, 0xff)[0] == 0xff:
167-
self.cs.high()
167+
self.cs(1)
168168
self.spi.write(b'\xff')
169169
return 0 # OK
170-
self.cs.high()
170+
self.cs(1)
171171
self.spi.write(b'\xff')
172172
return 1 # timeout
173173

174174
def readinto(self, buf):
175-
self.cs.low()
175+
self.cs(0)
176176

177177
# read until start byte (0xff)
178178
while self.spi.read(1, 0xff)[0] != 0xfe:
@@ -186,11 +186,11 @@ def readinto(self, buf):
186186
self.spi.write(b'\xff')
187187
self.spi.write(b'\xff')
188188

189-
self.cs.high()
189+
self.cs(1)
190190
self.spi.write(b'\xff')
191191

192192
def write(self, token, buf):
193-
self.cs.low()
193+
self.cs(0)
194194

195195
# send: start of block, data, checksum
196196
self.spi.read(1, token)
@@ -200,26 +200,26 @@ def write(self, token, buf):
200200

201201
# check the response
202202
if (self.spi.read(1, 0xff)[0] & 0x1f) != 0x05:
203-
self.cs.high()
203+
self.cs(1)
204204
self.spi.write(b'\xff')
205205
return
206206

207207
# wait for write to finish
208208
while self.spi.read(1, 0xff)[0] == 0:
209209
pass
210210

211-
self.cs.high()
211+
self.cs(1)
212212
self.spi.write(b'\xff')
213213

214214
def write_token(self, token):
215-
self.cs.low()
215+
self.cs(0)
216216
self.spi.read(1, token)
217217
self.spi.write(b'\xff')
218218
# wait for write to finish
219219
while self.spi.read(1, 0xff)[0] == 0x00:
220220
pass
221221

222-
self.cs.high()
222+
self.cs(1)
223223
self.spi.write(b'\xff')
224224

225225
def count(self):

0 commit comments

Comments
 (0)
0