Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
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
derf
multipass
Commits
7b8c37d2
Commit
7b8c37d2
authored
7 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Add Software I2C implementation
parent
c374e913
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+5
-0
5 additions, 0 deletions
Makefile
include/driver/soft_i2c.h
+26
-0
26 additions, 0 deletions
include/driver/soft_i2c.h
src/driver/soft_i2c.cc
+121
-0
121 additions, 0 deletions
src/driver/soft_i2c.cc
with
152 additions
and
0 deletions
Makefile
+
5
−
0
View file @
7b8c37d2
...
...
@@ -27,6 +27,11 @@ ifneq ($(findstring sharp96,${drivers}), )
COMMON_FLAGS
+=
-DSHARP96_CS_PIN
=
GPIO::
${
sharp96_cs_pin
}
endif
ifneq
($(findstring softi2c,${drivers}), )
TARGETS
+=
src/driver/soft_i2c.cc
COMMON_FLAGS
+=
-DDRIVER_SOFTI2C
endif
ifeq
(${timer_cycles}, 1)
COMMON_FLAGS
+=
-DTIMER_CYCLES
endif
...
...
This diff is collapsed.
Click to expand it.
include/driver/soft_i2c.h
0 → 100644
+
26
−
0
View file @
7b8c37d2
#ifndef SOFTI2C_H
#define SOFTI2C_H
class
SoftI2C
{
private:
SoftI2C
(
const
SoftI2C
&
copy
);
unsigned
char
sda
,
scl
;
void
start
();
void
stop
();
bool
tx
(
unsigned
char
byte
);
unsigned
char
rx
(
bool
send_ack
);
public:
SoftI2C
(
unsigned
char
sda
,
unsigned
char
scl
)
:
sda
(
sda
),
scl
(
scl
)
{}
signed
char
setup
();
void
scan
(
unsigned
int
*
results
);
signed
char
xmit
(
unsigned
char
address
,
unsigned
char
tx_len
,
unsigned
char
*
tx_buf
,
unsigned
char
rx_len
,
unsigned
char
*
rx_buf
);
};
extern
SoftI2C
i2c
;
#endif
This diff is collapsed.
Click to expand it.
src/driver/soft_i2c.cc
0 → 100644
+
121
−
0
View file @
7b8c37d2
#include
"driver/soft_i2c.h"
#include
"driver/gpio.h"
signed
char
SoftI2C
::
setup
()
{
gpio
.
write
(
sda
,
0
);
gpio
.
write
(
scl
,
0
);
return
0
;
}
void
SoftI2C
::
start
()
{
gpio
.
input
(
sda
);
gpio
.
input
(
scl
);
//
gpio
.
output
(
sda
);
//
gpio
.
output
(
scl
);
}
void
SoftI2C
::
stop
()
{
gpio
.
output
(
sda
);
//
gpio
.
input
(
scl
);
//
gpio
.
input
(
sda
);
}
bool
SoftI2C
::
tx
(
unsigned
char
byte
)
{
unsigned
char
got_ack
=
0
;
for
(
unsigned
char
i
=
0
;
i
<=
8
;
i
++
)
{
if
((
byte
&
0x80
)
||
(
i
==
8
))
{
gpio
.
input
(
sda
);
}
else
{
gpio
.
output
(
sda
);
}
byte
<<=
1
;
//
gpio
.
input
(
scl
);
//
if
(
i
==
8
)
{
if
(
!
gpio
.
read
(
sda
))
{
got_ack
=
1
;
}
}
gpio
.
output
(
scl
);
//
}
return
got_ack
;
}
unsigned
char
SoftI2C
::
rx
(
bool
send_ack
)
{
unsigned
char
byte
=
0
;
gpio
.
input
(
sda
);
for
(
unsigned
char
i
=
0
;
i
<=
8
;
i
++
)
{
//
gpio
.
input
(
scl
);
//
if
((
i
<
8
)
&&
gpio
.
read
(
sda
))
{
byte
|=
1
<<
(
7
-
i
);
}
//
gpio
.
output
(
scl
);
//
if
((
i
==
7
)
&&
send_ack
)
{
gpio
.
output
(
sda
);
}
else
if
((
i
==
8
)
&&
send_ack
)
{
gpio
.
input
(
sda
);
}
}
return
byte
;
}
void
SoftI2C
::
scan
(
unsigned
int
*
results
)
{
unsigned
char
i2caddr
;
for
(
unsigned
char
address
=
0
;
address
<
128
;
address
++
)
{
i2caddr
=
(
address
<<
1
)
|
1
;
start
();
if
(
tx
(
i2caddr
))
{
results
[
address
/
(
8
*
sizeof
(
unsigned
int
))]
|=
1
<<
(
address
%
(
8
*
sizeof
(
unsigned
int
)));
}
}
stop
();
}
signed
char
SoftI2C
::
xmit
(
unsigned
char
address
,
unsigned
char
tx_len
,
unsigned
char
*
tx_buf
,
unsigned
char
rx_len
,
unsigned
char
*
rx_buf
)
{
unsigned
char
i
;
if
(
tx_len
)
{
start
();
tx
((
address
<<
1
)
|
0
);
for
(
i
=
0
;
i
<
tx_len
;
i
++
)
{
tx
(
tx_buf
[
i
]);
}
}
if
(
rx_len
)
{
start
();
tx
((
address
<<
1
)
|
1
);
for
(
i
=
1
;
i
<=
rx_len
;
i
++
)
{
rx_buf
[
i
]
=
rx
((
i
<
rx_len
)
*
1
);
}
}
stop
();
return
0
;
}
SoftI2C
i2c
(
GPIO
::
p1_6
,
GPIO
::
p1_7
);
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