@@ -130,7 +130,7 @@ def _idle(self, delay_=1, check_on_thread=False, blocking=False) -> None:
130
130
cmd = bytearray (1 )
131
131
cmd [0 ] = 0x06
132
132
133
- self .i2c ._start ()
133
+ self .i2c .start ()
134
134
self .i2c .writeto (0x36 , cmd )
135
135
136
136
soc_raw = struct .unpack ('h' , self .i2c .readfrom (0x36 , 2 ))[0 ]
@@ -1302,7 +1302,7 @@ def is_accessible(self):
1302
1302
"""
1303
1303
return not self ._is_single_thread or _thread .get_ident () == self .__class__ ._main_thread_id
1304
1304
1305
- def _start (self ):
1305
+ def start (self ):
1306
1306
"""
1307
1307
Bitbanging start condition
1308
1308
:return:
@@ -1312,7 +1312,28 @@ def _start(self):
1312
1312
sleep_ms (100 )
1313
1313
_SDA .value (0 )
1314
1314
1315
- def scan (self ):
1315
+ def init (self , scl , sda , freq = 400_000 ) -> None :
1316
+ """
1317
+ init method just for call compatibility
1318
+ """
1319
+ print ("AlvikWarning:: init Unsupported. Alvik defines/initializes its own I2C bus" )
1320
+
1321
+ def deinit (self ):
1322
+ """
1323
+ deinit method just for call compatibility
1324
+ """
1325
+ print ("AlvikWarning:: deinit Unsupported. Alvik defines/initializes its own I2C bus" )
1326
+
1327
+ def stop (self ):
1328
+ """ Bitbanging stop condition (untested)
1329
+ :return:
1330
+ """
1331
+ _SDA = Pin (self .sda , Pin .OUT )
1332
+ _SDA .value (0 )
1333
+ sleep_ms (100 )
1334
+ _SDA .value (1 )
1335
+
1336
+ def scan (self ) -> list [int ]:
1316
1337
"""
1317
1338
I2C scan method
1318
1339
:return:
@@ -1321,24 +1342,98 @@ def scan(self):
1321
1342
return []
1322
1343
with self ._lock :
1323
1344
i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1324
- out = i2c .scan ()
1325
- return out
1345
+ return i2c .scan ()
1326
1346
1327
- def readfrom (self , addr , nbytes , stop = True ):
1347
+ def readfrom (self , addr , nbytes , stop = True ) -> bytes :
1348
+ """
1349
+ Wrapping i2c readfrom
1350
+ """
1328
1351
if not self .is_accessible ():
1329
1352
return bytes (nbytes )
1330
1353
with self ._lock :
1331
1354
i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1332
- out = i2c .readfrom (addr , nbytes , stop )
1333
- return out
1355
+ return i2c .readfrom (addr , nbytes , stop )
1356
+
1357
+ def writeto (self , addr , buf , stop = True ) -> int :
1358
+ """
1359
+ Wrapping i2c writeto
1360
+ """
1361
+ if not self .is_accessible ():
1362
+ return 0
1363
+ with self ._lock :
1364
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1365
+ return i2c .writeto (addr , buf , stop )
1334
1366
1335
- def writeto (self , addr , buf , stop = True ):
1367
+ def readinto (self , buf , nack = True ) -> None :
1368
+ """
1369
+ Wrapping i2c readinto
1370
+ """
1336
1371
if not self .is_accessible ():
1337
- return None
1372
+ return
1338
1373
with self ._lock :
1339
1374
i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1340
- out = i2c .writeto (addr , buf , stop )
1341
- return out
1375
+ return i2c .readinto (buf , nack )
1376
+
1377
+ def write (self , buf ) -> int :
1378
+ """
1379
+ Wrapping i2c write
1380
+ """
1381
+ if not self .is_accessible ():
1382
+ return 0
1383
+ with self ._lock :
1384
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1385
+ return i2c .write (buf )
1386
+
1387
+ def readfrom_into (self , addr , buf , stop = True ) -> None :
1388
+ """
1389
+ Wrapping i2c readfrom_into
1390
+ """
1391
+ if not self .is_accessible ():
1392
+ return
1393
+ with self ._lock :
1394
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1395
+ return i2c .readfrom_into (addr , buf , stop )
1396
+
1397
+ def writevto (self , addr , vector , stop = True ) -> int :
1398
+ """
1399
+ Wrapping i2c writevto
1400
+ """
1401
+ if not self .is_accessible ():
1402
+ return 0
1403
+ with self ._lock :
1404
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1405
+ return i2c .writevto (addr , vector , stop )
1406
+
1407
+ def readfrom_mem (self , addr , memaddr , nbytes , addrsize = 8 ) -> bytes :
1408
+ """
1409
+ Wrapping i2c readfrom_mem
1410
+ """
1411
+ if not self .is_accessible ():
1412
+ return bytes (nbytes )
1413
+ with self ._lock :
1414
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1415
+ return i2c .readfrom_mem (addr , memaddr , nbytes , addrsize = addrsize )
1416
+
1417
+ def readfrom_mem_into (self , addr , memaddr , buf , addrsize = 8 ) -> None :
1418
+ """
1419
+ Wrapping i2c readfrom_mem_into
1420
+ """
1421
+ if not self .is_accessible ():
1422
+ return
1423
+ with self ._lock :
1424
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1425
+ return i2c .readfrom_mem_into (addr , memaddr , buf , addrsize = addrsize )
1426
+
1427
+ def writeto_mem (self , addr , memaddr , buf , addrsize = 8 ) -> None :
1428
+ """
1429
+ Wrapping i2c writeto_mem
1430
+ """
1431
+ if not self .is_accessible ():
1432
+ return
1433
+ with self ._lock :
1434
+ i2c = I2C (0 , scl = Pin (self .scl , Pin .OUT ), sda = Pin (self .sda , Pin .OUT ))
1435
+ return i2c .writeto_mem (addr , memaddr , buf , addrsize = addrsize )
1436
+
1342
1437
1343
1438
1344
1439
class _ArduinoAlvikServo :
0 commit comments