Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
marlin-anet-a8
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jonas Leder
marlin-anet-a8
Commits
a8499096
Commit
a8499096
authored
5 years ago
by
Scott Lahteine
Browse files
Options
Downloads
Patches
Plain Diff
Simplify TWIBus debug
parent
53fe572b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Marlin/src/feature/twibus.cpp
+17
-39
17 additions, 39 deletions
Marlin/src/feature/twibus.cpp
Marlin/src/feature/twibus.h
+5
-2
5 additions, 2 deletions
Marlin/src/feature/twibus.h
with
22 additions
and
41 deletions
Marlin/src/feature/twibus.cpp
+
17
−
39
View file @
a8499096
...
...
@@ -49,37 +49,27 @@ void TWIBus::address(const uint8_t adr) {
addr
=
adr
;
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"address"
),
adr
);
#endif
}
void
TWIBus
::
addbyte
(
const
char
c
)
{
if
(
buffer_s
>=
COUNT
(
buffer
))
return
;
buffer
[
buffer_s
++
]
=
c
;
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"addbyte"
),
c
);
#endif
}
void
TWIBus
::
addbytes
(
char
src
[],
uint8_t
bytes
)
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"addbytes"
),
bytes
);
#endif
while
(
bytes
--
)
addbyte
(
*
src
++
);
}
void
TWIBus
::
addstring
(
char
str
[])
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"addstring"
),
str
);
#endif
while
(
char
c
=
*
str
++
)
addbyte
(
c
);
}
void
TWIBus
::
send
()
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"send"
),
addr
);
#endif
Wire
.
beginTransmission
(
I2C_ADDRESS
(
addr
));
Wire
.
write
(
buffer
,
buffer_s
);
...
...
@@ -89,21 +79,21 @@ void TWIBus::send() {
}
// static
void
TWIBus
::
echoprefix
(
uint8_t
bytes
,
const
char
pref
ix
[],
uint8_t
adr
)
{
void
TWIBus
::
echoprefix
(
uint8_t
bytes
,
const
char
pref
[],
uint8_t
adr
)
{
SERIAL_ECHO_START
();
serialprintPGM
(
pref
ix
);
serialprintPGM
(
pref
);
SERIAL_ECHOPAIR
(
": from:"
,
adr
,
" bytes:"
,
bytes
,
" data:"
);
}
// static
void
TWIBus
::
echodata
(
uint8_t
bytes
,
const
char
pref
ix
[],
uint8_t
adr
)
{
echoprefix
(
bytes
,
pref
ix
,
adr
);
void
TWIBus
::
echodata
(
uint8_t
bytes
,
const
char
pref
[],
uint8_t
adr
)
{
echoprefix
(
bytes
,
pref
,
adr
);
while
(
bytes
--
&&
Wire
.
available
())
SERIAL_CHAR
(
Wire
.
read
());
SERIAL_EOL
();
}
void
TWIBus
::
echobuffer
(
const
char
pref
ix
[],
uint8_t
adr
)
{
echoprefix
(
buffer_s
,
pref
ix
,
adr
);
void
TWIBus
::
echobuffer
(
const
char
pref
[],
uint8_t
adr
)
{
echoprefix
(
buffer_s
,
pref
,
adr
);
LOOP_L_N
(
i
,
buffer_s
)
SERIAL_CHAR
(
buffer
[
i
]);
SERIAL_EOL
();
}
...
...
@@ -111,15 +101,11 @@ void TWIBus::echobuffer(const char prefix[], uint8_t adr) {
bool
TWIBus
::
request
(
const
uint8_t
bytes
)
{
if
(
!
addr
)
return
false
;
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"request"
),
bytes
);
#endif
// requestFrom() is a blocking function
if
(
Wire
.
requestFrom
(
addr
,
bytes
)
==
0
)
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
"request fail"
,
addr
);
#endif
return
false
;
}
...
...
@@ -127,9 +113,7 @@ bool TWIBus::request(const uint8_t bytes) {
}
void
TWIBus
::
relay
(
const
uint8_t
bytes
)
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"relay"
),
bytes
);
#endif
if
(
request
(
bytes
))
echodata
(
bytes
,
PSTR
(
"i2c-reply"
),
addr
);
...
...
@@ -141,9 +125,7 @@ uint8_t TWIBus::capture(char *dst, const uint8_t bytes) {
while
(
count
<
bytes
&&
Wire
.
available
())
dst
[
count
++
]
=
Wire
.
read
();
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"capture"
),
count
);
#endif
return
count
;
}
...
...
@@ -156,16 +138,12 @@ void TWIBus::flush() {
#if I2C_SLAVE_ADDRESS > 0
void
TWIBus
::
receive
(
uint8_t
bytes
)
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"receive"
),
bytes
);
#endif
echodata
(
bytes
,
PSTR
(
"i2c-receive"
),
0
);
}
void
TWIBus
::
reply
(
char
str
[]
/*=nullptr*/
)
{
#if ENABLED(DEBUG_TWIBUS)
debug
(
PSTR
(
"reply"
),
str
);
#endif
if
(
str
)
{
reset
();
...
...
This diff is collapsed.
Click to expand it.
Marlin/src/feature/twibus.h
+
5
−
2
View file @
a8499096
...
...
@@ -223,7 +223,6 @@ class TWIBus {
#endif
#if ENABLED(DEBUG_TWIBUS)
/**
* @brief Prints a debug message
* @details Prints a simple debug message "TWIBus::function: value"
...
...
@@ -233,6 +232,10 @@ class TWIBus {
static
void
debug
(
const
char
func
[],
char
c
);
static
void
debug
(
const
char
func
[],
char
adr
[]);
static
inline
void
debug
(
const
char
func
[],
uint8_t
v
)
{
debug
(
func
,
(
uint32_t
)
v
);
}
#else
static
inline
void
debug
(
const
char
[],
uint32_t
)
{}
static
inline
void
debug
(
const
char
[],
char
)
{}
static
inline
void
debug
(
const
char
[],
char
[])
{}
static
inline
void
debug
(
const
char
[],
uint8_t
)
{}
#endif
};
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