-
Notifications
You must be signed in to change notification settings - Fork 0
/
mma8451.h
128 lines (90 loc) · 3.49 KB
/
mma8451.h
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
/* Yangosoft */
/* https://github.com/yangosoft/pic_mma8451 */
// This is a guard condition so that contents of this file are not included
// more than once.
#ifndef XC_HEADER_TEMPLATE_H
#define XC_HEADER_TEMPLATE_H
#include <xc.h> // include processor files - each processor file is guarded.
#include <stdbool.h>
#include <stdint.h>
// TODO Insert appropriate #include <>
// TODO Insert C++ class definitions if appropriate
// TODO Insert declarations
// Comment a function and leverage automatic documentation with slash star star
/**
<p><b>Function prototype:</b></p>
<p><b>Summary:</b></p>
<p><b>Description:</b></p>
<p><b>Precondition:</b></p>
<p><b>Parameters:</b></p>
<p><b>Returns:</b></p>
<p><b>Example:</b></p>
<code>
</code>
<p><b>Remarks:</b></p>
*/
// TODO Insert declarations or function prototypes (right here) to leverage
// live documentation
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// TODO If C++ is being used, regular C code needs function names to have C
// linkage so the functions can be used by the c code.
/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define MMA8451_DEFAULT_ADDRESS (0x1C) // if A is GND, its 0x1C. 0x1D otherwise.
/*=========================================================================*/
#define MMA8451_REG_OUT_X_MSB 0x01
#define MMA8451_REG_SYSMOD 0x0B
#define MMA8451_REG_WHOAMI 0x0D
#define MMA8451_REG_XYZ_DATA_CFG 0x0E
#define MMA8451_REG_PL_STATUS 0x10
#define MMA8451_REG_PL_CFG 0x11
#define MMA8451_REG_MOTION_CFG 0x15
#define MMA8451_REG_FF_MT_CFG 0x16
#define MMA8451_REG_THRESHOLD 0x17
#define MMA8451_REG_CTRL_REG1 0x2A
#define MMA8451_REG_CTRL_REG2 0x2B
#define MMA8451_REG_CTRL_REG3 0x2C
#define MMA8451_REG_CTRL_REG4 0x2D
#define MMA8451_REG_CTRL_REG5 0x2E
#define MMA8451_REG_ASLP_COUNT 0x29
#define MMA8451_PL_PUF 0
#define MMA8451_PL_PUB 1
#define MMA8451_PL_PDF 2
#define MMA8451_PL_PDB 3
#define MMA8451_PL_LRF 4
#define MMA8451_PL_LRB 5
#define MMA8451_PL_LLF 6
#define MMA8451_PL_LLB 7
#define MMA8451_WAKEUP_TRESHOLD 0x0f
typedef enum {
MMA8451_RANGE_8_G = 0b10, // +/- 8g
MMA8451_RANGE_4_G = 0b01, // +/- 4g
MMA8451_RANGE_2_G = 0b00 // +/- 2g (default value)
} mma8451_range_t;
/* Used with register 0x2A (MMA8451_REG_CTRL_REG1) to set bandwidth */
typedef enum {
MMA8451_DATARATE_800_HZ = 0b000, // 800Hz
MMA8451_DATARATE_400_HZ = 0b001, // 400Hz
MMA8451_DATARATE_200_HZ = 0b010, // 200Hz
MMA8451_DATARATE_100_HZ = 0b011, // 100Hz
MMA8451_DATARATE_50_HZ = 0b100, // 50Hz
MMA8451_DATARATE_12_5_HZ = 0b101, // 12.5Hz
MMA8451_DATARATE_6_25HZ = 0b110, // 6.25Hz
MMA8451_DATARATE_1_56_HZ = 0b111, // 1.56Hz
MMA8451_DATARATE_MASK = 0b111
} mma8451_dataRate_t;
// wakeupTreshold = (xg / 0.063g/counter)
bool MMAInit(uint8_t wakeupTreshold);
void MMAGetAccel(int16_t *x, int16_t *y, int16_t *z);
void MMASleep();
void writeRegister8(uint8_t addr, uint8_t value);
uint8_t readRegister8(uint8_t registerAddr);
uint8_t readRegister2(uint8_t address);
void writeRegister2(uint8_t address, uint8_t value);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* XC_HEADER_TEMPLATE_H */