Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Ardupilot
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
OpenSource
Ardupilot
Commits
38512e37
Commit
38512e37
authored
11 years ago
by
Mike McCauley
Browse files
Options
Downloads
Patches
Plain Diff
AP_HAL_FLYMAPLE: I2CDriver improvements to interrupt hygiene
parent
8e5a9b06
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libraries/AP_HAL_FLYMAPLE/I2CDriver.cpp
+13
-17
13 additions, 17 deletions
libraries/AP_HAL_FLYMAPLE/I2CDriver.cpp
with
13 additions
and
17 deletions
libraries/AP_HAL_FLYMAPLE/I2CDriver.cpp
+
13
−
17
View file @
38512e37
...
@@ -14,6 +14,8 @@
...
@@ -14,6 +14,8 @@
*/
*/
/*
/*
Flymaple port by Mike McCauley
Flymaple port by Mike McCauley
Uses the low level libmaple i2c library.
Caution: requires fixes against the libmaple git master as of 2013-10-10
*/
*/
#include
<AP_HAL.h>
#include
<AP_HAL.h>
...
@@ -26,12 +28,9 @@
...
@@ -26,12 +28,9 @@
using
namespace
AP_HAL_FLYMAPLE_NS
;
using
namespace
AP_HAL_FLYMAPLE_NS
;
// We use a 0 delay to go as fast as we can with bitbanging
//static TwoWire twowire(5, 9, 0); // Flymaple has non-standard SCL, SDA, speed ~285kHz
extern
const
AP_HAL
::
HAL
&
hal
;
extern
const
AP_HAL
::
HAL
&
hal
;
// This is the instanc
x
e of the libmaple I2C device to use
// This is the instance of the libmaple I2C device to use
#define FLYMAPLE_I2C_DEVICE I2C1
#define FLYMAPLE_I2C_DEVICE I2C1
FLYMAPLEI2CDriver
::
FLYMAPLEI2CDriver
(
AP_HAL
::
Semaphore
*
semaphore
)
FLYMAPLEI2CDriver
::
FLYMAPLEI2CDriver
(
AP_HAL
::
Semaphore
*
semaphore
)
...
@@ -104,22 +103,19 @@ uint8_t FLYMAPLEI2CDriver::readRegister(uint8_t addr, uint8_t reg, uint8_t* data
...
@@ -104,22 +103,19 @@ uint8_t FLYMAPLEI2CDriver::readRegister(uint8_t addr, uint8_t reg, uint8_t* data
uint8_t
FLYMAPLEI2CDriver
::
readRegisters
(
uint8_t
addr
,
uint8_t
reg
,
uint8_t
FLYMAPLEI2CDriver
::
readRegisters
(
uint8_t
addr
,
uint8_t
reg
,
uint8_t
len
,
uint8_t
*
data
)
uint8_t
len
,
uint8_t
*
data
)
{
{
// Write the
desired
register
we wish to
read
// W
e conduct a w
rite
of
the register
number we want followed by a
read
data
[
0
]
=
reg
;
// Temp steal this
data
[
0
]
=
reg
;
// Temp
orarily
steal this
for the write
i2c_msg
msgs
[
1
];
i2c_msg
msgs
[
2
];
msgs
[
0
].
addr
=
addr
;
msgs
[
0
].
addr
=
addr
;
msgs
[
0
].
flags
=
0
;
// Write
msgs
[
0
].
flags
=
0
;
// Write
msgs
[
0
].
length
=
1
;
msgs
[
0
].
length
=
1
;
msgs
[
0
].
data
=
data
;
msgs
[
0
].
data
=
data
;
if
(
_transfer
(
msgs
,
1
))
// Second transaction is a read
return
1
;
// Fail
msgs
[
1
].
addr
=
addr
;
msgs
[
1
].
flags
=
I2C_MSG_READ
;
// Now read it
msgs
[
1
].
length
=
len
;
msgs
[
0
].
addr
=
addr
;
msgs
[
1
].
data
=
data
;
msgs
[
0
].
flags
=
I2C_MSG_READ
;
return
_transfer
(
msgs
,
2
);
msgs
[
0
].
length
=
len
;
msgs
[
0
].
data
=
data
;
return
_transfer
(
msgs
,
1
);
}
}
uint8_t
FLYMAPLEI2CDriver
::
lockup_count
()
{
uint8_t
FLYMAPLEI2CDriver
::
lockup_count
()
{
...
@@ -130,7 +126,7 @@ uint8_t FLYMAPLEI2CDriver::_transfer(i2c_msg *msgs, uint16 num)
...
@@ -130,7 +126,7 @@ uint8_t FLYMAPLEI2CDriver::_transfer(i2c_msg *msgs, uint16 num)
{
{
// ALERT: patch to libmaple required for this to work else
// ALERT: patch to libmaple required for this to work else
// crashes next line due to a bug in latest git libmaple see http://forums.leaflabs.com/topic.php?id=13458
// crashes next line due to a bug in latest git libmaple see http://forums.leaflabs.com/topic.php?id=13458
int32
result
=
i2c_master_xfer
(
I2C1
,
msgs
,
1
,
_timeout_ms
);
int32
result
=
i2c_master_xfer
(
I2C1
,
msgs
,
num
,
_timeout_ms
);
if
(
result
!=
0
)
if
(
result
!=
0
)
{
{
// Some sort of I2C bus fault, or absent device, reinitialise the bus
// Some sort of I2C bus fault, or absent device, reinitialise the bus
...
...
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