Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PyPCC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
PyPCC
Commits
3c501ce8
Commit
3c501ce8
authored
5 months ago
by
Paulus Kruger
Browse files
Options
Downloads
Patches
Plain Diff
I2C using SMBUS2 (solving memory leak)
parent
0250a4aa
No related branches found
No related tags found
No related merge requests found
Pipeline
#102026
passed
5 months ago
Stage: run
Stage: image
Changes
3
Pipelines
10
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pypcc/config/APSCTTR.yaml
+1
-1
1 addition, 1 deletion
pypcc/config/APSCTTR.yaml
pypcc/i2cserv/i2c_smbus2.py
+53
-0
53 additions, 0 deletions
pypcc/i2cserv/i2c_smbus2.py
pypcc/i2cserv/i2c_switch.py
+2
-1
2 additions, 1 deletion
pypcc/i2cserv/i2c_switch.py
with
56 additions
and
2 deletions
pypcc/config/APSCTTR.yaml
+
1
−
1
View file @
3c501ce8
...
...
@@ -3,7 +3,7 @@ description: "1234"
drivers
:
-
name
:
I2C
type
:
i2c
type
:
i2c
_smbus2
parameters
:
[
5
]
#I2C port number
-
name
:
I2C_CLK
type
:
i2c_dev
#I2C devices
...
...
This diff is collapsed.
Click to expand it.
pypcc/i2cserv/i2c_smbus2.py
0 → 100644
+
53
−
0
View file @
3c501ce8
import
os
from
smbus2
import
SMBus
,
i2c_msg
import
time
import
logging
#read=0: write to register
#read=1: read from register
#read=2: write to register (common in group)
#read=3: wait ms second
from
.hwdev
import
hwdev
;
class
i2c_smbus2
(
hwdev
):
def
__init__
(
self
,
config
):
hwdev
.
__init__
(
self
,
config
);
self
.
bus_nr
=
config
[
'
parameters
'
][
0
]
logging
.
info
(
"
smbus2 driver on bus
"
+
str
(
self
.
bus_nr
))
self
.
bus
=
SMBus
(
self
.
bus_nr
)
self
.
I2Ccounter
=
0
def
i2csetget
(
self
,
addr
,
data
,
reg
=
None
,
read
=
0
):
# logging.debug(str(("I2C",addr,reg,data,read)))
try
:
# if True:
if
read
==
3
:
time
.
sleep
(
data
[
0
]
/
1000.
)
return
True
if
read
==
1
:
if
not
(
reg
is
None
):
data
[:]
=
self
.
bus
.
read_i2c_block_data
(
addr
,
reg
,
len
(
data
))
else
:
msg
=
i2c_msg
.
read
(
addr
,
len
(
data
))
self
.
bus
.
i2c_rdwr
(
msg
)
if
len
(
msg
)
!=
len
(
data
):
logging
.
debug
(
str
((
"
I2C get failed
"
,
addr
,
reg
,
data
,
read
)))
data
[
0
]
=
0
;
return
False
data
[:]
=
list
(
msg
)
logging
.
debug
(
str
((
"
I2C get
"
,
addr
,
reg
,
data
,
read
)))
else
:
if
not
(
reg
is
None
):
self
.
bus
.
write_i2c_block_data
(
addr
,
reg
,
data
)
else
:
msg
=
i2c_msg
.
write
(
addr
,
data
)
self
.
bus
.
i2c_rdwr
(
msg
)
return
True
;
except
:
# else:
logging
.
debug
(
"
I2C failed!
"
)
if
len
(
data
)
>
0
:
data
[
0
]
=
0
return
False
;
This diff is collapsed.
Click to expand it.
pypcc/i2cserv/i2c_switch.py
+
2
−
1
View file @
3c501ce8
import
logging
from
.i2c
import
i2c
#from .i2c import i2c
from
.i2c_smbus2
import
i2c_smbus2
as
i2c
#import HWconf
#SWaddr=0x70
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment