Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
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
Nicolò Caruso
Skyward Boardcore
Commits
df63f6af
Commit
df63f6af
authored
1 year ago
by
Federico Mandelli
Browse files
Options
Downloads
Patches
Plain Diff
[LIS3MDL] Fixed casting bug inside lis3mdl driver
parent
4b974e83
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/shared/sensors/LIS3MDL/LIS3MDL.cpp
+15
-17
15 additions, 17 deletions
src/shared/sensors/LIS3MDL/LIS3MDL.cpp
src/shared/sensors/LIS3MDL/LIS3MDL.h
+7
-0
7 additions, 0 deletions
src/shared/sensors/LIS3MDL/LIS3MDL.h
src/tests/sensors/test-lis3mdl.cpp
+2
-2
2 additions, 2 deletions
src/tests/sensors/test-lis3mdl.cpp
with
24 additions
and
19 deletions
src/shared/sensors/LIS3MDL/LIS3MDL.cpp
+
15
−
17
View file @
df63f6af
...
...
@@ -31,6 +31,8 @@ LIS3MDL::LIS3MDL(SPIBusInterface& bus, miosix::GpioPin pin,
SPIBusConfig
spiConfig
,
Config
config
)
:
slave
(
bus
,
pin
,
spiConfig
),
configuration
(
config
)
{
slave
.
config
.
byteOrder
=
SPI
::
Order
::
LSB_FIRST
;
slave
.
config
.
mode
=
SPI
::
Mode
::
MODE_3
;
}
bool
LIS3MDL
::
init
()
...
...
@@ -49,8 +51,8 @@ bool LIS3MDL::init()
if
(
res
!=
WHO_AM_I_VALUE
)
{
LOG_ERR
(
logger
,
"WHO_AM_I value differs from expectation: read 0x{
02
x} "
"but expected 0x{
02
x}"
,
"WHO_AM_I value differs from expectation: read 0x{
:
x} "
"but expected 0x{
:
x}"
,
res
,
WHO_AM_I_VALUE
);
lastError
=
INVALID_WHOAMI
;
return
false
;
...
...
@@ -124,9 +126,13 @@ bool LIS3MDL::selfTest()
bool
passed
=
true
;
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
if
(
deltas
[
j
]
<
(
deltaRange
[
j
][
0
]
-
t
)
||
deltas
[
j
]
>
(
deltaRange
[
j
][
1
]
+
t
))
{
passed
=
false
;
}
}
// Reset configuration, then return
applyConfig
(
configuration
);
...
...
@@ -209,15 +215,11 @@ LIS3MDLData LIS3MDL::sampleImpl()
SPITransaction
spi
(
slave
);
LIS3MDLData
newData
;
tempCounter
++
;
if
(
configuration
.
temperatureDivider
!=
0
&&
tempCounter
%
configuration
.
temperatureDivider
==
0
)
{
uint8_t
values
[
2
];
spi
.
readRegisters
(
TEMP_OUT_L
,
values
,
sizeof
(
values
));
int16_t
outTemp
=
values
[
1
]
<<
8
|
values
[
0
];
int16_t
outTemp
=
spi
.
readRegister16
(
TEMP_OUT_L
|
INCREMENT_REG_FLAG
);
newData
.
temperatureTimestamp
=
TimestampTimer
::
getTimestamp
();
newData
.
temperature
=
DEG_PER_LSB
*
outTemp
;
newData
.
temperature
+=
REFERENCE_TEMPERATURE
;
...
...
@@ -227,17 +229,13 @@ LIS3MDLData LIS3MDL::sampleImpl()
newData
.
temperature
=
lastSample
.
temperature
;
}
uint8_t
values
[
6
];
spi
.
readRegisters
(
OUT_X_L
,
values
,
sizeof
(
values
));
int16_t
outX
=
values
[
1
]
<<
8
|
values
[
0
];
int16_t
outY
=
values
[
3
]
<<
8
|
values
[
2
];
int16_t
outZ
=
values
[
5
]
<<
8
|
values
[
4
];
int16_t
values
[
3
];
spi
.
readRegisters
(
OUT_X_L
|
INCREMENT_REG_FLAG
,
reinterpret_cast
<
uint8_t
*>
(
values
),
sizeof
(
values
));
newData
.
magneticFieldTimestamp
=
TimestampTimer
::
getTimestamp
();
newData
.
magneticFieldX
=
currentUnit
*
outX
;
newData
.
magneticFieldY
=
currentUnit
*
outY
;
newData
.
magneticFieldZ
=
currentUnit
*
outZ
;
newData
.
magneticFieldX
=
currentUnit
*
values
[
0
];
newData
.
magneticFieldY
=
currentUnit
*
values
[
1
];
newData
.
magneticFieldZ
=
currentUnit
*
values
[
2
];
return
newData
;
}
...
...
This diff is collapsed.
Click to expand it.
src/shared/sensors/LIS3MDL/LIS3MDL.h
+
7
−
0
View file @
df63f6af
...
...
@@ -203,6 +203,13 @@ private:
static
constexpr
uint32_t
ENABLE_INT_Y
=
1
<<
6
;
static
constexpr
uint32_t
ENABLE_INT_Z
=
1
<<
5
;
/**
* This flag is needed because the device requires the 7th address bit
* asserted in order to increment the address in transaction with more than
* one bytes.
*/
static
constexpr
uint8_t
INCREMENT_REG_FLAG
=
0x40
;
PrintLogger
logger
=
Logging
::
getLogger
(
"lis3mdl"
);
};
...
...
This diff is collapsed.
Click to expand it.
src/tests/sensors/test-lis3mdl.cpp
+
2
−
2
View file @
df63f6af
...
...
@@ -30,8 +30,8 @@ using namespace miosix;
int
main
()
{
GpioPin
cs
(
GPIO
B
_BASE
,
1
),
miso
(
GPIO
B
_BASE
,
4
),
mosi
(
GPIO
B
_BASE
,
5
),
clk
(
GPIO
B
_BASE
,
3
);
GpioPin
cs
(
GPIO
G
_BASE
,
6
),
miso
(
GPIO
A
_BASE
,
6
),
mosi
(
GPIO
A
_BASE
,
7
),
clk
(
GPIO
A
_BASE
,
5
);
cs
.
mode
(
Mode
::
OUTPUT
);
cs
.
high
();
...
...
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