Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
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
Andreas Horn
ch32v003fun
Commits
a8740ca9
Commit
a8740ca9
authored
1 year ago
by
Eric Brombaugh
Browse files
Options
Downloads
Patches
Plain Diff
Clean up unused warning, add optional time diags
parent
706ead52
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
examples/i2c_oled/i2c.h
+35
-1
35 additions, 1 deletion
examples/i2c_oled/i2c.h
with
35 additions
and
1 deletion
examples/i2c_oled/i2c.h
+
35
−
1
View file @
a8740ca9
...
...
@@ -18,6 +18,9 @@
#ifdef I2C_IRQ
// some stuff that IRQ mode needs
volatile
uint8_t
i2c_send_buffer
[
64
],
*
i2c_send_ptr
,
i2c_send_sz
,
i2c_irq_state
;
// uncomment this to enable time diags in IRQ
//#define IRQ_DIAG
#endif
/*
...
...
@@ -79,6 +82,16 @@ void i2c_init(void)
GPIO_CFGLR_CNF2_1
|
GPIO_CFGLR_CNF2_0
|
GPIO_CFGLR_MODE2_1
|
GPIO_CFGLR_MODE2_0
;
#ifdef IRQ_DIAG
// GPIO diags on PC3/PC4
GPIOC
->
CFGLR
&=
~
(
0xf
<<
(
4
*
3
));
GPIOC
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
3
);
GPIOC
->
BSHR
=
(
1
<<
(
16
+
3
));
GPIOC
->
CFGLR
&=
~
(
0xf
<<
(
4
*
4
));
GPIOC
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
4
);
GPIOC
->
BSHR
=
(
1
<<
(
16
+
4
));
#endif
// load I2C regs
i2c_setup
();
}
...
...
@@ -132,6 +145,10 @@ uint8_t i2c_send(uint8_t addr, uint8_t *data, uint8_t sz)
{
int32_t
timeout
;
#ifdef IRQ_DIAG
GPIOC
->
BSHR
=
(
1
<<
(
3
));
#endif
// error out if buffer under/overflow
if
((
sz
>
sizeof
(
i2c_send_buffer
))
||
!
sz
)
return
2
;
...
...
@@ -139,6 +156,11 @@ uint8_t i2c_send(uint8_t addr, uint8_t *data, uint8_t sz)
// wait for previous packet to finish
while
(
i2c_irq_state
);
#ifdef IRQ_DIAG
GPIOC
->
BSHR
=
(
1
<<
(
16
+
3
));
GPIOC
->
BSHR
=
(
1
<<
(
4
));
#endif
// init buffer for sending
i2c_send_sz
=
sz
;
i2c_send_ptr
=
i2c_send_buffer
;
...
...
@@ -171,6 +193,10 @@ uint8_t i2c_send(uint8_t addr, uint8_t *data, uint8_t sz)
// Enable TXE interrupt
I2C1
->
CTLR2
|=
I2C_CTLR2_ITBUFEN
|
I2C_CTLR2_ITEVTEN
;
i2c_irq_state
=
1
;
#ifdef IRQ_DIAG
GPIOC
->
BSHR
=
(
1
<<
(
16
+
4
));
#endif
// exit
return
0
;
...
...
@@ -182,8 +208,12 @@ uint8_t i2c_send(uint8_t addr, uint8_t *data, uint8_t sz)
void
I2C1_EV_IRQHandler
(
void
)
__attribute__
((
interrupt
));
void
I2C1_EV_IRQHandler
(
void
)
{
uint16_t
STAR1
,
STAR2
;
uint16_t
STAR1
,
STAR2
__attribute__
((
unused
))
;
#ifdef IRQ_DIAG
GPIOC
->
BSHR
=
(
1
<<
(
4
));
#endif
// read status, clear any events
STAR1
=
I2C1
->
STAR1
;
STAR2
=
I2C1
->
STAR2
;
...
...
@@ -211,6 +241,10 @@ void I2C1_EV_IRQHandler(void)
I2C1
->
CTLR1
|=
I2C_CTLR1_STOP
;
}
}
#ifdef IRQ_DIAG
GPIOC
->
BSHR
=
(
1
<<
(
16
+
4
));
#endif
}
#else
/*
...
...
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