Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Heizung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
c3pb
Heizung
Commits
295829ec
Commit
295829ec
authored
1 year ago
by
Benjamin Koch
Browse files
Options
Downloads
Patches
Plain Diff
some small improvements
parent
6522374c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
firmware/rust1/src/bin/heizung.rs
+17
-20
17 additions, 20 deletions
firmware/rust1/src/bin/heizung.rs
with
17 additions
and
20 deletions
firmware/rust1/src/bin/heizung.rs
+
17
−
20
View file @
295829ec
...
@@ -72,7 +72,12 @@ fn format_scan_result<const N : usize>(msg : &mut String<N>, scan_result : [Scan
...
@@ -72,7 +72,12 @@ fn format_scan_result<const N : usize>(msg : &mut String<N>, scan_result : [Scan
Ok
(())
Ok
(())
}
}
async
fn
_clockStretch
<
'd
,
SCL
:
gpio
::
Pin
>
(
scl
:
&
mut
Flex
<
'd
,
SCL
>
)
->
Result
<
(),
i2c
::
Error
>
{
// adapted from arduino-pico:
// https://github.com/earlephilhower/arduino-pico/blob/6e52b72523b11470b2ad2b0578ca1500be238108/libraries/Wire/src/Wire.cpp#L257
// This seems to be the only way to do zero-length writes:
// see https://github.com/raspberrypi/pico-sdk/issues/238
async
fn
handle_clock_stretching
<
'd
,
SCL
:
gpio
::
Pin
>
(
scl
:
&
mut
Flex
<
'd
,
SCL
>
)
->
Result
<
(),
i2c
::
Error
>
{
use
i2c
::
Error
::
*
;
use
i2c
::
Error
::
*
;
use
i2c
::
AbortReason
::
*
;
use
i2c
::
AbortReason
::
*
;
...
@@ -88,26 +93,24 @@ async fn _clockStretch<'d, SCL: gpio::Pin>(scl: &mut Flex<'d, SCL>) -> Result<()
...
@@ -88,26 +93,24 @@ async fn _clockStretch<'d, SCL: gpio::Pin>(scl: &mut Flex<'d, SCL>) -> Result<()
Second
(
_
)
=>
Err
(
Abort
(
ArbitrationLoss
)),
Second
(
_
)
=>
Err
(
Abort
(
ArbitrationLoss
)),
}
}
}
}
// adapted from https://github.com/earlephilhower/arduino-pico/blob/6e52b72523b11470b2ad2b0578ca1500be238108/libraries/Wire/src/Wire.cpp#L257
async
fn
i2c_write_zero_bytes_middle_part
<
'd
,
SCL
:
gpio
::
Pin
,
SDA
:
gpio
::
Pin
,
const
FREQ
:
u64
>
(
async
fn
i2c_write_zero_bytes_middle_part
<
'd
,
SCL
:
gpio
::
Pin
,
SDA
:
gpio
::
Pin
,
const
FREQ
:
u64
>
(
mut
addr
:
u16
,
delay
:
Duration
,
scl
:
&
mut
Flex
<
'd
,
SCL
>
,
sda
:
&
mut
Flex
<
'd
,
SDA
>
)
mut
addr
:
u16
,
delay
:
Duration
,
scl
:
&
mut
Flex
<
'd
,
SCL
>
,
sda
:
&
mut
Flex
<
'd
,
SDA
>
)
->
Result
<
(),
i2c
::
Error
>
{
->
Result
<
(),
i2c
::
Error
>
{
sda
.set_as_input
();
sda
.set_as_input
();
Timer
::
after
(
delay
)
.await
;
Timer
::
after
(
delay
)
.await
;
scl
.set_as_input
();
scl
.set_as_input
();
_clock
S
tretch
(
scl
)
.await
?
;
handle
_clock
_s
tretch
ing
(
scl
)
.await
?
;
sda
.set_as_output
();
sda
.set_as_output
();
Timer
::
after
(
delay
)
.await
;
Timer
::
after
(
delay
)
.await
;
scl
.set_as_output
();
scl
.set_as_output
();
Timer
::
after
(
delay
)
.await
;
Timer
::
after
(
delay
)
.await
;
for
i
in
0
..
8
{
for
_
in
0
..
8
{
addr
<<=
1
;
addr
<<=
1
;
sda
.set_level
(
if
(
addr
&
(
1
<<
7
))
!=
0
{
gpio
::
Level
::
High
}
else
{
gpio
::
Level
::
Low
});
sda
.set_level
(
if
(
addr
&
(
1
<<
7
))
!=
0
{
gpio
::
Level
::
High
}
else
{
gpio
::
Level
::
Low
});
Timer
::
after
(
delay
)
.await
;
Timer
::
after
(
delay
)
.await
;
scl
.set_as_input
();
scl
.set_as_input
();
Timer
::
after
(
delay
)
.await
;
Timer
::
after
(
delay
)
.await
;
_clock
S
tretch
(
scl
)
.await
?
;
handle
_clock
_s
tretch
ing
(
scl
)
.await
?
;
scl
.set_as_output
();
scl
.set_as_output
();
Timer
::
after
(
Duration
::
from_micros
(
5
))
.await
;
// Ensure we don't change too close to clock edge
Timer
::
after
(
Duration
::
from_micros
(
5
))
.await
;
// Ensure we don't change too close to clock edge
}
}
...
@@ -115,7 +118,7 @@ async fn i2c_write_zero_bytes_middle_part<'d, SCL: gpio::Pin, SDA: gpio::Pin, co
...
@@ -115,7 +118,7 @@ async fn i2c_write_zero_bytes_middle_part<'d, SCL: gpio::Pin, SDA: gpio::Pin, co
sda
.set_as_input
();
sda
.set_as_input
();
Timer
::
after
(
delay
)
.await
;
Timer
::
after
(
delay
)
.await
;
scl
.set_as_input
();
scl
.set_as_input
();
_clock
S
tretch
(
scl
)
.await
?
;
handle
_clock
_s
tretch
ing
(
scl
)
.await
?
;
let
result
=
if
sda
.is_low
()
{
let
result
=
if
sda
.is_low
()
{
Ok
(())
Ok
(())
...
@@ -129,13 +132,12 @@ async fn i2c_write_zero_bytes_middle_part<'d, SCL: gpio::Pin, SDA: gpio::Pin, co
...
@@ -129,13 +132,12 @@ async fn i2c_write_zero_bytes_middle_part<'d, SCL: gpio::Pin, SDA: gpio::Pin, co
result
result
}
}
async
fn
i2c_write_zero_bytes
<
SCL
:
gpio
::
Pin
,
SDA
:
gpio
::
Pin
,
const
FREQ
:
u64
>
(
mut
addr
:
u16
,
scl
:
&
mut
SCL
,
sda
:
&
mut
SDA
)
async
fn
i2c_write_zero_bytes
<
SCL
:
gpio
::
Pin
,
SDA
:
gpio
::
Pin
,
const
FREQ
:
u64
>
(
addr
:
u16
,
scl
:
&
mut
SCL
,
sda
:
&
mut
SDA
)
->
Result
<
(),
i2c
::
Error
>
{
->
Result
<
(),
i2c
::
Error
>
{
use
i2c
::
Error
::
*
;
use
i2c
::
Error
::
*
;
use
i2c
::
AbortReason
::
*
;
use
i2c
::
AbortReason
::
*
;
let
delay
=
Duration
::
from_micros
((
1000000
/
FREQ
)
/
2
);
let
delay
=
Duration
::
from_micros
((
1000000
/
FREQ
)
/
2
);
let
ack
=
false
;
let
mut
sda
=
Flex
::
new
(
sda
);
let
mut
sda
=
Flex
::
new
(
sda
);
let
mut
scl
=
Flex
::
new
(
scl
);
let
mut
scl
=
Flex
::
new
(
scl
);
...
@@ -181,18 +183,13 @@ async fn i2c_task(mut i2c_peri: embassy_rp::peripherals::I2C0,
...
@@ -181,18 +183,13 @@ async fn i2c_task(mut i2c_peri: embassy_rp::peripherals::I2C0,
const
MAX_ADDRESS
:
u8
=
128
;
const
MAX_ADDRESS
:
u8
=
128
;
let
mut
scan_result
=
[
ScanResult
::
Error
;
MAX_ADDRESS
as
usize
];
let
mut
scan_result
=
[
ScanResult
::
Error
;
MAX_ADDRESS
as
usize
];
for
i
in
0
..
MAX_ADDRESS
{
for
i
in
0
..
MAX_ADDRESS
{
match
i2c_write_zero_bytes
::
<
_
,
_
,
400_000
>
(
i
as
u16
,
&
mut
scl
,
&
mut
sda
)
.await
{
scan_result
[
i
as
usize
]
=
match
i2c_write_zero_bytes
::
<
_
,
_
,
400_000
>
(
i
as
u16
,
&
mut
scl
,
&
mut
sda
)
.await
{
Result
::
Ok
(())
=>
{
Result
::
Ok
(())
=>
ScanResult
::
Ack
,
//info!("I2C ok: {}", i);
Result
::
Err
(
Abort
(
NoAcknowledge
))
=>
ScanResult
::
NAck
,
scan_result
[
i
as
usize
]
=
ScanResult
::
Ack
Result
::
Err
(
AddressReserved
(
_
))
=>
ScanResult
::
Reserved
,
},
Result
::
Err
(
Abort
(
NoAcknowledge
))
=>
scan_result
[
i
as
usize
]
=
ScanResult
::
NAck
,
Result
::
Err
(
AddressReserved
(
_
))
=>
scan_result
[
i
as
usize
]
=
ScanResult
::
Reserved
,
Result
::
Err
(
e
)
=>
{
Result
::
Err
(
e
)
=>
{
scan_result
[
i
as
usize
]
=
ScanResult
::
Error
;
warn!
(
"I2C problem: {:02x}: {:?}"
,
i
,
e
)
;
warn!
(
"I2C problem: {:?}"
,
e
);
ScanResult
::
Error
}
}
}
}
}
}
...
...
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