This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathlis3_transport.hpp
128 lines (108 loc) · 3.05 KB
/
lis3_transport.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// coding: utf-8
/* Copyright (c) 2014, Roboterclub Aachen e.V.
* All Rights Reserved.
*
* The file is part of the xpcc library and is released under the 3-clause BSD
* license. See the file `LICENSE` for the full license governing this code.
*/
// ----------------------------------------------------------------------------
#ifndef XPCC_LIS3_TRANSPORT_HPP
#define XPCC_LIS3_TRANSPORT_HPP
#include <xpcc/architecture/interface/spi_device.hpp>
#include <xpcc/architecture/interface/i2c_device.hpp>
#include <xpcc/processing/resumable.hpp>
namespace xpcc
{
/**
* LIS3xx I2C Transport Layer.
*
* This class manages communication with the accelerometer via the I2C bus.
*
* To enable I2C mode in the LIS3xx devices, the CS pin must be tied high.
* However, it is internally pulled-up, so just leaving the CS pin disconnected should work too.
*
* The I2C interface is compliant with Fast Mode (up to 400kHz).
*
* @see Lis302dl
* @see Lis3dsh
*
* @ingroup driver_inertial
* @author Niklas Hauser
*/
template < class I2cMaster >
class Lis3TransportI2c : public xpcc::I2cDevice< I2cMaster, 2 >
{
public:
Lis3TransportI2c(uint8_t address);
protected:
// RAW REGISTER ACCESS
/// write a 8bit value
xpcc::ResumableResult<bool>
write(uint8_t reg, uint8_t value);
/// read a 8bit value
xpcc::ResumableResult<bool> xpcc_always_inline
read(uint8_t reg, uint8_t &value)
{
return read(reg, &value, 1);
}
/// read multiple 8bit values from a start register
xpcc::ResumableResult<bool>
read(uint8_t reg, uint8_t *buffer, uint8_t length);
// increment address or not?
/// @cond
static constexpr uint8_t AddressIncrement = 0x80;
static constexpr uint8_t AddressStatic = 0x00;
/// @endcond
private:
uint8_t buffer[2];
};
/**
* LIS3xx SPI Transport Layer.
*
* This class manages communication with the accelerometer via the SPI bus.
* The SPI interface can be clocked with up to 10MHz and requires Mode3.
*
* @see Lis302dl
* @see Lis3dsh
*
* @tparam Cs connected Chip Select Pin
*
* @ingroup driver_inertial
* @author Niklas Hauser
*/
template < class SpiMaster, class Cs >
class Lis3TransportSpi : public xpcc::SpiDevice< SpiMaster >, protected xpcc::NestedResumable<2>
{
public:
Lis3TransportSpi(uint8_t /*address*/);
/// pings the sensor
xpcc::ResumableResult<bool>
ping();
protected:
// RAW REGISTER ACCESS
/// write a 8bit value
xpcc::ResumableResult<bool>
write(uint8_t reg, uint8_t value);
/// read a 8bit value
xpcc::ResumableResult<bool> xpcc_always_inline
read(uint8_t reg, uint8_t &value)
{
return read(reg, &value, 1);
}
/// read multiple 8bit values from a start register
xpcc::ResumableResult<bool>
read(uint8_t reg, uint8_t *buffer, uint8_t length);
// increment address or not?
/// @cond
static constexpr uint8_t AddressIncrement = 0x40;
static constexpr uint8_t AddressStatic = 0x00;
/// @endcond
private:
uint8_t whoAmI;
// write read bit on the address
static constexpr uint8_t Read = 0x80;
static constexpr uint8_t Write = 0x00;
};
} // namespace xpcc
#include "lis3_transport_impl.hpp"
#endif // XPCC_LIS3_TRANSPORT_HPP