Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
flow3-rs
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tux coder
flow3-rs
Commits
b4933d91
Commit
b4933d91
authored
1 year ago
by
zdmx
Browse files
Options
Downloads
Patches
Plain Diff
Partially fix captouch
parent
a878d8f9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ad7147/src/device.rs
+5
-5
5 additions, 5 deletions
ad7147/src/device.rs
ad7147/src/driver.rs
+43
-14
43 additions, 14 deletions
ad7147/src/driver.rs
ad7147/src/stage.rs
+14
-2
14 additions, 2 deletions
ad7147/src/stage.rs
src/flow3r/captouch.rs
+11
-6
11 additions, 6 deletions
src/flow3r/captouch.rs
with
73 additions
and
27 deletions
ad7147/src/device.rs
+
5
−
5
View file @
b4933d91
...
@@ -406,13 +406,13 @@ impl Default for AmbientCompensationControl {
...
@@ -406,13 +406,13 @@ impl Default for AmbientCompensationControl {
fn
default
()
->
Self
{
fn
default
()
->
Self
{
Self
{
Self
{
fast_filter_skip
:
Default
::
default
(),
fast_filter_skip
:
Default
::
default
(),
full_power_proximity_disable
:
3
,
full_power_proximity_disable
:
0
,
low_power_proximity_disable
:
2
,
low_power_proximity_disable
:
0
,
power_down_timeout
:
PowerDownTimeout
::
Factor
2
,
power_down_timeout
:
PowerDownTimeout
::
Factor
1_25
,
forced_calibration
:
false
,
forced_calibration
:
false
,
conversion_reset
:
false
,
conversion_reset
:
false
,
proximity_recalibration_level
:
25
,
proximity_recalibration_level
:
64
,
proximity_detection_rate
:
4
,
proximity_detection_rate
:
1
,
slow_filter_update_level
:
0
,
slow_filter_update_level
:
0
,
full_power_proximity_recalibration
:
50
,
full_power_proximity_recalibration
:
50
,
low_power_proximity_recalibration
:
2
,
low_power_proximity_recalibration
:
2
,
...
...
This diff is collapsed.
Click to expand it.
ad7147/src/driver.rs
+
43
−
14
View file @
b4933d91
use
byte_slice_cast
::
{
AsByteSlice
,
AsMutByteSlice
}
;
use
byte_slice_cast
::
AsByteSlice
;
use
embedded_hal_1
::
delay
::
DelayUs
;
use
embedded_hal_1
::
delay
::
DelayUs
;
use
embedded_hal
::
blocking
::
i2c
::{
Write
,
WriteRead
};
use
embedded_hal
::
blocking
::
i2c
::{
Write
,
WriteRead
};
use
esp_println
::
println
;
use
esp_println
::
println
;
...
@@ -11,6 +11,10 @@ use crate::{
...
@@ -11,6 +11,10 @@ use crate::{
interrupt
::
InterruptStatus
,
interrupt
::
InterruptStatus
,
};
};
const
STAGE_CONVERSION_RESULT_REGISTER
:
u16
=
0x0B
;
const
STAGE_COMPLETED_INTERRUPT_RESULT_REGISTER
:
u16
=
0x08
;
const
DEVICE_ID_REGISTER
:
u16
=
0x17
;
pub
struct
Uninit
;
pub
struct
Uninit
;
pub
struct
Initialized
;
pub
struct
Initialized
;
...
@@ -49,22 +53,22 @@ where
...
@@ -49,22 +53,22 @@ where
let
data_idx
=
(
i
*
8
)
+
1
;
let
data_idx
=
(
i
*
8
)
+
1
;
data
[
data_idx
..
data_idx
+
8
]
.copy_from_slice
(
&
stage
.to_reg_value
());
data
[
data_idx
..
data_idx
+
8
]
.copy_from_slice
(
&
stage
.to_reg_value
());
}
}
println!
(
"writing to device:
{:x?}"
,
data
);
println!
(
"writing to device:
addr: {:016b} stage0: {:016b}, stage0: {:016b}"
,
data
[
0
],
data
[
1
],
data
[
2
]
);
self
.i2c
.write
(
self
.address
,
data
.as_byte_slice
())
?
;
self
.i2c
.write
(
self
.address
,
to_be_array
(
data
)
.as_byte_slice
())
?
;
let
mut
data
=
[
0u16
;
9
];
let
mut
data
=
[
0u16
;
9
];
data
[
0
]
=
0x000
;
data
[
0
]
=
0x000
;
data
[
1
..
9
]
.copy_from_slice
(
&
configuration
.0
.to_reg_value_for_init
());
data
[
1
..
9
]
.copy_from_slice
(
&
configuration
.0
.to_reg_value_for_init
());
println!
(
"writing to device:
{:x?}"
,
data
);
println!
(
"writing to device:
addr: {:016b} pwr_cfg: {:016b}, stage_cal: {:016b}, amb_comp_1: {:016b}, amb_comp_2: {:016b}, amb_comp_3: {:016b}, stage_low_int: {:016b}, stage_high_int: {:016b}, stage_complete_int: {:016b}"
,
data
[
0
],
data
[
1
],
data
[
2
],
data
[
3
],
data
[
4
],
data
[
5
],
data
[
6
],
data
[
7
],
data
[
8
]
);
self
.i2c
.write
(
self
.address
,
data
.as_byte_slice
())
?
;
self
.i2c
.write
(
self
.address
,
to_be_array
(
data
)
.as_byte_slice
())
?
;
delay
.delay_ms
(
100
);
delay
.delay_ms
(
100
);
let
mut
data
=
[
0u16
;
2
];
let
mut
data
=
[
0u16
;
2
];
data
[
0
]
=
CalibrationEnable
::
REGISTER
;
data
[
0
]
=
CalibrationEnable
::
REGISTER
;
data
[
1
]
=
configuration
.0
.calibration_enable
.to_reg_value
();
data
[
1
]
=
configuration
.0
.calibration_enable
.to_reg_value
();
println!
(
"writing to device:
{:x?}"
,
data
);
println!
(
"writing to device:
addr: {:016b} stage_cal: {:016b}"
,
data
[
0
],
data
[
1
]
);
self
.i2c
.write
(
self
.address
,
data
.as_byte_slice
())
?
;
self
.i2c
.write
(
self
.address
,
to_be_array
(
data
)
.as_byte_slice
())
?
;
Ok
(
Ad7147
{
Ok
(
Ad7147
{
i2c
:
self
.i2c
,
i2c
:
self
.i2c
,
...
@@ -80,19 +84,26 @@ where
...
@@ -80,19 +84,26 @@ where
I2C
:
WriteRead
<
Error
=
E
>
+
Write
<
Error
=
E
>
,
I2C
:
WriteRead
<
Error
=
E
>
+
Write
<
Error
=
E
>
,
{
{
pub
fn
read_all_stages
(
&
mut
self
)
->
Result
<
[
u16
;
S
],
E
>
{
pub
fn
read_all_stages
(
&
mut
self
)
->
Result
<
[
u16
;
S
],
E
>
{
let
mut
result
=
[
0u
16
;
S
];
let
mut
result
=
[
0u
8
;
12
*
2
];
self
.i2c
self
.i2c
.write_read
(
self
.address
,
&
[
0x00B
],
result
.as_mut_byte_slice
()
)
?
;
.write_read
(
self
.address
,
to_be_array
([
STAGE_CONVERSION_RESULT_REGISTER
])
.as_byte_slice
(),
&
mut
result
)
?
;
println!
(
"read from device {:x?}"
,
result
);
println!
(
"read from device {:x?}"
,
result
);
Ok
(
result
)
Ok
(
to_le_u16_array
(
&
result
)
)
}
}
pub
fn
read_interrupt_registers
(
&
mut
self
)
->
Result
<
InterruptStatus
,
E
>
{
pub
fn
read_interrupt_registers
(
&
mut
self
)
->
Result
<
InterruptStatus
,
E
>
{
let
mut
data
=
[
0u
16
;
3
];
let
mut
data
=
[
0u
8
;
6
];
self
.i2c
self
.i2c
.write_read
(
self
.address
,
&
[
0x008
],
data
.as_mut
_byte_slice
())
?
;
.write_read
(
self
.address
,
to_be_array
([
STAGE_COMPLETED_INTERRUPT_RESULT_REGISTER
])
.as
_byte_slice
()
,
&
mut
data
)
?
;
println!
(
"read from device {:x?}"
,
data
);
println!
(
"read from device {:x?}"
,
data
);
Ok
(
InterruptStatus
::
from_registers
(
data
))
Ok
(
InterruptStatus
::
from_registers
(
to_le_u16_array
(
&
data
)))
}
pub
fn
read_device_id
(
&
mut
self
)
->
Result
<
u16
,
E
>
{
let
mut
data
=
[
0u8
;
2
];
self
.i2c
.write_read
(
self
.address
,
to_be_array
([
DEVICE_ID_REGISTER
])
.as_byte_slice
(),
&
mut
data
)
?
;
Ok
(
u16
::
from_be_bytes
(
data
))
}
}
pub
fn
reset
(
&
mut
self
)
->
Result
<
(),
E
>
{
pub
fn
reset
(
&
mut
self
)
->
Result
<
(),
E
>
{
...
@@ -101,6 +112,24 @@ where
...
@@ -101,6 +112,24 @@ where
let
mut
data
=
[
0u16
;
4
];
let
mut
data
=
[
0u16
;
4
];
data
[
0
]
=
AmbientCompensationControl
::
REGISTER
;
data
[
0
]
=
AmbientCompensationControl
::
REGISTER
;
data
[
1
..
8
]
.copy_from_slice
(
&
acc_reg
.to_reg_value
());
data
[
1
..
8
]
.copy_from_slice
(
&
acc_reg
.to_reg_value
());
self
.i2c
.write
(
self
.address
,
data
.as_byte_slice
())
self
.i2c
.write
(
self
.address
,
to_be_array
(
data
)
.as_byte_slice
())
}
}
fn
to_be_array
<
const
N
:
usize
>
(
data
:
[
u16
;
N
])
->
[
u16
;
N
]
{
let
mut
result
=
[
0u16
;
N
];
for
(
i
,
word
)
in
data
.into_iter
()
.enumerate
()
{
result
[
i
]
=
word
.to_be
();
}
result
}
fn
to_le_u16_array
<
const
N
:
usize
>
(
data
:
&
[
u8
])
->
[
u16
;
N
]
{
let
mut
result
=
[
0u16
;
N
];
for
i
in
0
..
N
{
let
(
int_bytes
,
_
)
=
data
[
i
*
2
..
]
.split_at
(
core
::
mem
::
size_of
::
<
u16
>
());
result
[
i
]
=
u16
::
from_be_bytes
(
int_bytes
.try_into
()
.unwrap
());
}
}
result
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ad7147/src/stage.rs
+
14
−
2
View file @
b4933d91
...
@@ -72,6 +72,16 @@ impl StageConfigurationBuilder {
...
@@ -72,6 +72,16 @@ impl StageConfigurationBuilder {
self
self
}
}
pub
fn
pos_afe_offset
(
mut
self
,
offset
:
u8
)
->
StageConfigurationBuilder
{
self
.configuration.afe_offset_configuration.pos_afe_offset
=
offset
;
self
}
pub
fn
neg_afe_offset
(
mut
self
,
offset
:
u8
)
->
StageConfigurationBuilder
{
self
.configuration.afe_offset_configuration.neg_afe_offset
=
offset
;
self
}
pub
fn
build
(
mut
self
)
->
StageConfiguration
{
pub
fn
build
(
mut
self
)
->
StageConfiguration
{
if
self
.input_connections
.len
()
>
1
{
if
self
.input_connections
.len
()
>
1
{
self
.configuration.input_configuration
=
self
.configuration.input_configuration
=
...
@@ -138,7 +148,8 @@ impl InputMode {
...
@@ -138,7 +148,8 @@ impl InputMode {
panic!
(
"Input mode cannot be left unconfigured"
)
panic!
(
"Input mode cannot be left unconfigured"
)
}
}
InputMode
::
SingleEnded
(
conn
)
=>
{
InputMode
::
SingleEnded
(
conn
)
=>
{
res
|
=
(
conn
.cdc
as
u32
)
<<
(
conn
.cin
as
u32
);
res
|
=
0xFFFFFFFF
>>
4
;
res
&=
((
conn
.cdc
as
u32
)
<<
(
conn
.cin
as
u32
))
|
!
(
0b11
<<
(
conn
.cin
as
u32
));
res
|
=
if
conn
.cdc
==
CdcInput
::
Positive
{
res
|
=
if
conn
.cdc
==
CdcInput
::
Positive
{
0b01
0b01
}
else
{
}
else
{
...
@@ -146,8 +157,9 @@ impl InputMode {
...
@@ -146,8 +157,9 @@ impl InputMode {
}
<<
28
;
}
<<
28
;
}
}
InputMode
::
Differential
(
conns
)
=>
{
InputMode
::
Differential
(
conns
)
=>
{
res
|
=
0xFFFFFFFF
>>
4
;
for
conn
in
conns
{
for
conn
in
conns
{
res
|
=
(
conn
.cdc
as
u32
)
<<
(
conn
.cin
as
u32
);
res
&
=
(
(
conn
.cdc
as
u32
)
<<
(
conn
.cin
as
u32
)
)
|
!
(
0b11
<<
(
conn
.cin
as
u32
))
;
}
}
res
|
=
0b11
<<
28
;
res
|
=
0b11
<<
28
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/flow3r/captouch.rs
+
11
−
6
View file @
b4933d91
...
@@ -3,13 +3,13 @@ use ad7147::{
...
@@ -3,13 +3,13 @@ use ad7147::{
stage
::{
CapInput
,
CdcInput
,
InputConnection
},
stage
::{
CapInput
,
CdcInput
,
InputConnection
},
Ad7147
,
DeviceConfiguration
,
Initialized
,
StageConfiguration
,
Ad7147
,
DeviceConfiguration
,
Initialized
,
StageConfiguration
,
};
};
use
embassy_time
::
Delay
;
use
embassy_time
::
{
Delay
,
Duration
,
Timer
}
;
use
embedded_hal_async
::
digital
::
Wait
;
use
embedded_hal_async
::
digital
::
Wait
;
use
esp_println
::
println
;
use
esp_println
::
println
;
use
hal
::{
use
hal
::{
gpio
::{
Gpio16
,
Unknown
},
gpio
::{
Gpio16
,
Unknown
},
i2c
::
I2C
,
i2c
::
I2C
,
peripherals
::
I2C0
,
peripherals
::
I2C0
,
prelude
::
_esp_hal_gpio_InputPin
,
};
};
use
shared_bus
::{
I2cProxy
,
XtensaMutex
};
use
shared_bus
::{
I2cProxy
,
XtensaMutex
};
...
@@ -24,8 +24,6 @@ fn init_captouch(
...
@@ -24,8 +24,6 @@ fn init_captouch(
let
ad7147
=
Ad7147
::
new
(
i2c
,
0b00101100
);
let
ad7147
=
Ad7147
::
new
(
i2c
,
0b00101100
);
let
config
=
DeviceConfiguration
::
builder
()
let
config
=
DeviceConfiguration
::
builder
()
.decimation
(
DecimationFactor
::
Factor64
)
.decimation
(
DecimationFactor
::
Factor64
)
.cdc_bias_current
(
ad7147
::
device
::
CdcBias
::
Plus35Percent
)
.power_mode
(
ad7147
::
device
::
PowerMode
::
Low
)
.stages
([
StageConfiguration
::
builder
()
.stages
([
StageConfiguration
::
builder
()
.calibration_enabled
(
true
)
.calibration_enabled
(
true
)
.conversion_complete_interrupt_enabled
(
true
)
.conversion_complete_interrupt_enabled
(
true
)
...
@@ -44,18 +42,25 @@ pub async fn captouch_controller(
...
@@ -44,18 +42,25 @@ pub async fn captouch_controller(
i2c
:
I2cProxy
<
'static
,
XtensaMutex
<
I2C
<
'static
,
I2C0
>>>
,
i2c
:
I2cProxy
<
'static
,
XtensaMutex
<
I2C
<
'static
,
I2C0
>>>
,
cap_b_int
:
Gpio16
<
Unknown
>
,
cap_b_int
:
Gpio16
<
Unknown
>
,
)
->
!
{
)
->
!
{
let
mut
cap_b_int
=
cap_b_int
.into_pull_up_input
();
let
mut
ad7147
=
init_captouch
(
i2c
)
.unwrap
();
let
mut
ad7147
=
init_captouch
(
i2c
)
.unwrap
();
let
mut
bottom_interrupt
=
cap_b_int
.into_pull_up_input
();
let
device_id
=
ad7147
.read_device_id
()
.unwrap
();
println!
(
"captouch device id: {:016b}"
,
device_id
);
let
ints
=
ad7147
.read_interrupt_registers
()
.unwrap
();
let
ints
=
ad7147
.read_interrupt_registers
()
.unwrap
();
println!
(
"ints: {:?}"
,
ints
);
println!
(
"ints: {:?}"
,
ints
);
println!
(
"int pin: {}"
,
cap_b_int
.is_input_high
());
println!
(
"initialized captouch"
);
println!
(
"initialized captouch"
);
loop
{
loop
{
bottom_interrupt
.wait_for_low
()
.await
.unwrap
();
println!
(
"int pin: {}"
,
cap_b_int
.is_input_high
());
// cap_b_int.wait_for_low().await.unwrap();
println!
(
"captouch interrupt"
);
let
ints
=
ad7147
.read_interrupt_registers
()
.unwrap
();
let
ints
=
ad7147
.read_interrupt_registers
()
.unwrap
();
println!
(
"ints: {:?}"
,
ints
);
println!
(
"ints: {:?}"
,
ints
);
let
measurement
=
ad7147
.read_all_stages
()
.unwrap
();
let
measurement
=
ad7147
.read_all_stages
()
.unwrap
();
println!
(
"{}"
,
measurement
[
0
]);
println!
(
"{}"
,
measurement
[
0
]);
Timer
::
after
(
Duration
::
from_secs
(
10
))
.await
;
}
}
}
}
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