Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
9358cb8b
Commit
9358cb8b
authored
Apr 13, 2011
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added i2c eeprom driver
parent
282dd8cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
0 deletions
+105
-0
i2c.c
dev/i2c.c
+105
-0
No files found.
dev/i2c.c
0 → 100644
View file @
9358cb8b
#include "types.h"
#include "board.h"
#include "gpio.h"
#define I2C_DELAY 100
static
void
mi2c_delay
()
{
int
i
;
for
(
i
=
0
;
i
<
I2C_DELAY
;
i
++
)
asm
volatile
(
"nop"
);
}
#define M_SDA_OUT(x) { gpio_out(GPIO_PIN_SDA_OUT, x); mi2c_delay(); }
#define M_SCL_OUT(x) { gpio_out(GPIO_PIN_SCL_OUT, x); mi2c_delay(); }
#define M_SDA_IN gpio_in(GPIO_PIN_SDA_IN)
void
mi2c_start
()
{
M_SDA_OUT
(
0
);
M_SCL_OUT
(
0
);
}
void
mi2c_repeat_start
()
{
M_SDA_OUT
(
1
);
M_SCL_OUT
(
1
);
M_SDA_OUT
(
0
);
M_SCL_OUT
(
0
);
}
void
mi2c_stop
()
{
M_SDA_OUT
(
0
);
M_SCL_OUT
(
1
);
M_SDA_OUT
(
1
);
}
unsigned
char
mi2c_put_byte
(
unsigned
char
data
)
{
char
i
;
unsigned
char
ack
;
for
(
i
=
0
;
i
<
8
;
i
++
,
data
<<=
1
)
{
M_SDA_OUT
(
data
&
0x80
);
M_SCL_OUT
(
1
);
M_SCL_OUT
(
0
);
}
M_SDA_OUT
(
1
);
M_SCL_OUT
(
1
);
ack
=
M_SDA_IN
;
/* ack: sda is pulled low ->success. */
M_SCL_OUT
(
0
);
M_SDA_OUT
(
0
);
return
ack
!=
0
;
}
void
mi2c_get_byte
(
unsigned
char
*
data
)
{
int
i
;
unsigned
char
indata
=
0
;
/* assert: scl is low */
M_SCL_OUT
(
0
);
for
(
i
=
0
;
i
<
8
;
i
++
)
{
M_SCL_OUT
(
1
);
indata
<<=
1
;
if
(
M_SDA_IN
)
indata
|=
0x01
;
M_SCL_OUT
(
0
);
}
M_SDA_OUT
(
1
);
*
data
=
indata
;
}
void
mi2c_init
()
{
gpio_dir
(
GPIO_PIN_SDA_OUT
,
1
);
gpio_dir
(
GPIO_PIN_SCL_OUT
,
1
);
gpio_dir
(
GPIO_PIN_SDA_IN
,
0
);
M_SCL_OUT
(
1
);
M_SDA_OUT
(
1
);
}
void
mi2c_scan
()
{
int
i
;
for
(
i
=
0
;
i
<
0x80
;
i
++
)
{
mi2c_start
();
mprintf
(
"scan %d
\n
"
,
i
);
if
(
!
mi2c_put_byte
(
i
<<
1
))
mprintf
(
"found : %x
\n
"
,
i
);
mi2c_stop
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment