Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2021
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
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
Jonas Jacobsson
e7020e_2021
Commits
1bbef23d
Commit
1bbef23d
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
test of i2c->spi wip4, Transfer
parent
fcb244e8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/rtt_rtic_i2c.rs
+64
-15
64 additions, 15 deletions
examples/rtt_rtic_i2c.rs
with
64 additions
and
15 deletions
examples/rtt_rtic_i2c.rs
+
64
−
15
View file @
1bbef23d
...
@@ -126,6 +126,18 @@ mod SC18IS602 {
...
@@ -126,6 +126,18 @@ mod SC18IS602 {
}
}
}
}
pub
enum
Speed
{
Speed_1843_kHz
=
0b00
,
Speed_461_kHz
=
0b01
,
Speed_115_kHz
=
0b10
,
Speed_58_kHz
=
0b11
,
}
pub
enum
Order
{
MsbFirst
=
0b0
,
MsbLast
=
0b1
,
}
enum
GpioMode
{
enum
GpioMode
{
QuasiBiDirectional
=
0b00
,
QuasiBiDirectional
=
0b00
,
PushPull
=
0b01
,
PushPull
=
0b01
,
...
@@ -139,42 +151,79 @@ mod SC18IS602 {
...
@@ -139,42 +151,79 @@ mod SC18IS602 {
}
}
}
}
use
embedded_hal
::{
blocking
::
i2c
,
digital
::
v2
::
OutputPin
};
use
embedded_hal
::{
blocking
::{
i2c
,
spi
::
Transfer
},
digital
::
v2
::
OutputPin
,
spi
::
Mode
,
};
enum
Error
{
enum
Error
{
NotConfigured
,
NotConfigured
,
}
}
// struct SH18IS602<PINS> {
struct
SH18IS602
<
I2C
>
struct
SH18IS602
<
I2C
>
where
where
I2C
:
i2c
::
Write
,
I2C
:
i2c
::
Write
+
i2c
::
Read
,
{
{
addr
:
u8
,
addr
:
u8
,
cs
:
bool
,
cs
:
bool
,
i2c
:
I2C
,
i2c
:
I2C
,
}
}
use
Function
::
*
;
impl
<
I2C
>
SH18IS602
<
I2C
>
impl
<
I2C
>
SH18IS602
<
I2C
>
where
where
I2C
:
i2c
::
Write
,
I2C
:
i2c
::
Write
+
i2c
::
Read
,
{
{
fn
new
(
mut
i2c
:
I2C
,
addr
:
u8
,
cs
:
bool
)
->
SH18IS602
<
I2C
>
{
fn
new
(
if
cs
{
mut
i2c
:
I2C
,
addr
:
u8
,
order
:
Order
,
mode
:
Mode
,
speed
:
Speed
,
cs
:
bool
,
)
->
SH18IS602
<
I2C
>
{
let
addr
=
(
0x50
+
addr
)
>>
1
;
let
addr
=
(
0x50
+
addr
)
>>
1
;
// set configuration
let
cfg
=
(
order
as
u8
)
<<
5
|
(
mode
.polarity
as
u8
)
<<
3
|
(
mode
.phase
as
u8
)
<<
2
|
speed
as
u8
;
let
x
=
i2c
.write
(
addr
,
&
[
SpiConfigure
.id
(),
cfg
])
.ok
();
cortex_m
::
asm
::
delay
(
100_000
);
if
cs
{
// Configure SS0 as GPIO
// Configure SS0 as GPIO
i2c
.write
(
addr
,
&
[
Function
::
GpioEnable
.id
(),
0x1
])
.ok
();
i2c
.write
(
addr
,
&
[
GpioEnable
.id
(),
0x1
])
.ok
();
// Configure SS0 as a PushPull Output
// Configure GPIO SS0 as a PushPull Output
i2c
.write
(
i2c
.write
(
addr
,
&
[
GpioConfigure
.id
(),
GpioMode
::
PushPull
.val
()])
addr
,
&
[
Function
::
GpioConfigure
.id
(),
GpioMode
::
PushPull
.val
()],
)
.ok
();
.ok
();
}
}
SH18IS602
{
addr
,
cs
,
i2c
}
SH18IS602
{
addr
,
cs
,
i2c
}
}
}
}
}
impl
<
I2C
>
Transfer
<
u8
>
for
SH18IS602
<
I2C
>
where
I2C
:
i2c
::
Write
+
i2c
::
Read
,
{
type
Error
=
Error
;
fn
transfer
<
'w
>
(
&
mut
self
,
words
:
&
'w
mut
[
u8
])
->
Result
<&
'w
[
u8
],
Self
::
Error
>
{
// initiate a transfer on SS0
let
mut
buff
=
[
0
;
8
];
buff
[
0
]
=
0x01
;
// SSO write
buff
[
1
..
]
.clone_from_slice
(
words
);
// perform the transaction on words.len() + 1 bytes
// the actual SPI transfer should be words.len()
self
.i2c
.write
(
self
.addr
,
&
buff
[
0
..
words
.len
()
+
1
])
.ok
();
self
.i2c
.read
(
self
.addr
,
words
)
.ok
();
Ok
(
words
)
}
}
// fn set<I2C>(i2c: I2C, data: u8)
// fn set<I2C>(i2c: I2C, data: u8)
// where
// where
// I2C: i2c::Write,
// I2C: i2c::Write,
...
@@ -184,7 +233,7 @@ mod SC18IS602 {
...
@@ -184,7 +233,7 @@ mod SC18IS602 {
impl
<
I2C
>
OutputPin
for
SH18IS602
<
I2C
>
impl
<
I2C
>
OutputPin
for
SH18IS602
<
I2C
>
where
where
I2C
:
i2c
::
Write
,
I2C
:
i2c
::
Write
+
i2c
::
Read
,
{
{
type
Error
=
Error
;
type
Error
=
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