amiro-lld / include / alld_l3g4200d.h @ 1d4fc180
History | View | Annotate | Download (9.326 KB)
| 1 |
/*
|
|---|---|
| 2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
| 3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
| 4 |
|
| 5 |
This program is free software: you can redistribute it and/or modify
|
| 6 |
it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
the Free Software Foundation, either version 3 of the License, or
|
| 8 |
(at your option) any later version.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU Lesser General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public License
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
*/
|
| 18 |
|
| 19 |
/**
|
| 20 |
* @file alld_l3g4200d.h
|
| 21 |
* @brief Gyroscope macros and structures.
|
| 22 |
*
|
| 23 |
* @addtogroup lld_gyroscope
|
| 24 |
* @{
|
| 25 |
*/
|
| 26 |
|
| 27 |
#ifndef _AMIROLLD_L3G4200D_H_
|
| 28 |
#define _AMIROLLD_L3G4200D_H_
|
| 29 |
|
| 30 |
#include <amiro-lld.h> |
| 31 |
|
| 32 |
#if defined(AMIROLLD_CFG_USE_L3G4200D) || defined(__DOXYGEN__)
|
| 33 |
|
| 34 |
/**
|
| 35 |
* @brief A rising edge indicates an interrupt.
|
| 36 |
*/
|
| 37 |
#define L3G4200D_LLD_INT_EDGE APAL_GPIO_EDGE_RISING
|
| 38 |
|
| 39 |
/**
|
| 40 |
* @brief The L3G4200D driver struct
|
| 41 |
*/
|
| 42 |
typedef struct { |
| 43 |
apalSPIDriver_t* spid; /**< @brief The SPI Driver */
|
| 44 |
} L3G4200DDriver; |
| 45 |
|
| 46 |
/**
|
| 47 |
* @brief SPI access modes.
|
| 48 |
*/
|
| 49 |
typedef enum { |
| 50 |
L3G4200D_LLD_SPI_MULT = 0x40u,
|
| 51 |
L3G4200D_LLD_SPI_READ = 0x80u,
|
| 52 |
L3G4200D_LLD_SPI_WRITE = 0x00u,
|
| 53 |
} l3g4200d_lld_SPI_mode_t; |
| 54 |
|
| 55 |
/**
|
| 56 |
* @brief Registers.
|
| 57 |
*/
|
| 58 |
typedef enum { |
| 59 |
L3G4200D_LLD_REGISTER_WHO_AM_I = 0x0F,
|
| 60 |
L3G4200D_LLD_REGISTER_CTRL_REG1 = 0x20,
|
| 61 |
L3G4200D_LLD_REGISTER_CTRL_REG2 = 0x21,
|
| 62 |
L3G4200D_LLD_REGISTER_CTRL_REG3 = 0x22,
|
| 63 |
L3G4200D_LLD_REGISTER_CTRL_REG4 = 0x23,
|
| 64 |
L3G4200D_LLD_REGISTER_CTRL_REG5 = 0x24,
|
| 65 |
L3G4200D_LLD_REGISTER_REFERECE = 0x25,
|
| 66 |
L3G4200D_LLD_REGISTER_OUT_TEMP = 0x26,
|
| 67 |
L3G4200D_LLD_REGISTER_STATUS_REG = 0x27,
|
| 68 |
L3G4200D_LLD_REGISTER_OUT_X_L = 0x28,
|
| 69 |
L3G4200D_LLD_REGISTER_OUT_X_H = 0x29,
|
| 70 |
L3G4200D_LLD_REGISTER_OUT_Y_L = 0x2A,
|
| 71 |
L3G4200D_LLD_REGISTER_OUT_Y_H = 0x2B,
|
| 72 |
L3G4200D_LLD_REGISTER_OUT_Z_L = 0x2C,
|
| 73 |
L3G4200D_LLD_REGISTER_OUT_Z_H = 0x2D,
|
| 74 |
L3G4200D_LLD_REGISTER_FIFO_CTRL_REG = 0x2E,
|
| 75 |
L3G4200D_LLD_REGISTER_FIFO_SRC_REG = 0x2F,
|
| 76 |
L3G4200D_LLD_REGISTER_INT1_CFG = 0x30,
|
| 77 |
L3G4200D_LLD_REGISTER_INT1_SRC = 0x31,
|
| 78 |
L3G4200D_LLD_REGISTER_INT1_TSH_XH = 0x32,
|
| 79 |
L3G4200D_LLD_REGISTER_INT1_TSH_XL = 0x33,
|
| 80 |
L3G4200D_LLD_REGISTER_INT1_TSH_YH = 0x34,
|
| 81 |
L3G4200D_LLD_REGISTER_INT1_TSH_YL = 0x35,
|
| 82 |
L3G4200D_LLD_REGISTER_INT1_TSH_ZH = 0x36,
|
| 83 |
L3G4200D_LLD_REGISTER_INT1_TSH_ZL = 0x37,
|
| 84 |
L3G4200D_LLD_REGISTER_INT1_DURATION = 0x38,
|
| 85 |
} l3g4200d_lld_register_t; |
| 86 |
|
| 87 |
/**
|
| 88 |
* @brief WHO_AM_I register constant content.
|
| 89 |
*/
|
| 90 |
typedef enum { |
| 91 |
L3G4200D_LLD_WHO_AM_I = 0xD3,
|
| 92 |
} l3g4200d_lld_whoami_t; |
| 93 |
|
| 94 |
/**
|
| 95 |
* @brief Control register 1 flags.
|
| 96 |
*/
|
| 97 |
typedef enum { |
| 98 |
L3G4200D_LLD_DR_100_HZ = 0x00,
|
| 99 |
L3G4200D_LLD_DR_200_HZ = 0x40,
|
| 100 |
L3G4200D_LLD_DR_400_HZ = 0x80,
|
| 101 |
L3G4200D_LLD_DR_800_HZ = 0xC0,
|
| 102 |
L3G4200D_LLD_BW_12_5 = 0x00,
|
| 103 |
L3G4200D_LLD_BW_20 = 0x00,
|
| 104 |
L3G4200D_LLD_BW_25 = 0x10,
|
| 105 |
L3G4200D_LLD_BW_30 = 0x00,
|
| 106 |
L3G4200D_LLD_BW_35 = 0x10,
|
| 107 |
L3G4200D_LLD_BW_50 = 0x20,
|
| 108 |
L3G4200D_LLD_BW_70 = 0x30,
|
| 109 |
L3G4200D_LLD_BW_110 = 0x30,
|
| 110 |
L3G4200D_LLD_PD = 0x08,
|
| 111 |
L3G4200D_LLD_ZEN = 0x04,
|
| 112 |
L3G4200D_LLD_YEN = 0x02,
|
| 113 |
L3G4200D_LLD_XEN = 0x01,
|
| 114 |
} l3g4200d_lld_ctrl_reg1_t; |
| 115 |
|
| 116 |
/**
|
| 117 |
* @brief Control register 2 flags.
|
| 118 |
*/
|
| 119 |
typedef enum { |
| 120 |
L3G4200D_LLD_HPM_NORMAL_RST = 0x00,
|
| 121 |
L3G4200D_LLD_HPM_REFERENCE = 0x10,
|
| 122 |
L3G4200D_LLD_HPM_NORMAL = 0x20,
|
| 123 |
L3G4200D_LLD_HPM_AUTO_RST = 0x30,
|
| 124 |
L3G4200D_LLD_HPCF_2 = 0x00,
|
| 125 |
L3G4200D_LLD_HPCF_4 = 0x01,
|
| 126 |
L3G4200D_LLD_HPCF_8 = 0x02,
|
| 127 |
L3G4200D_LLD_HPCF_16 = 0x03,
|
| 128 |
L3G4200D_LLD_HPCF_32 = 0x04,
|
| 129 |
L3G4200D_LLD_HPCF_64 = 0x05,
|
| 130 |
L3G4200D_LLD_HPCF_128 = 0x06,
|
| 131 |
L3G4200D_LLD_HPCF_256 = 0x07,
|
| 132 |
L3G4200D_LLD_HPCF_512 = 0x08,
|
| 133 |
L3G4200D_LLD_HPCF_1024 = 0x09,
|
| 134 |
} l3g4200d_lld_ctrl_reg2_t; |
| 135 |
|
| 136 |
/**
|
| 137 |
* @brief Control register 3 flags.
|
| 138 |
*/
|
| 139 |
typedef enum { |
| 140 |
L3G4200D_LLD_I1_INT1 = 0x80,
|
| 141 |
L3G4200D_LLD_I1_BOOT = 0x40,
|
| 142 |
L3G4200D_LLD_H_IACTIVE = 0x20,
|
| 143 |
L3G4200D_LLD_PP_OD = 0x10,
|
| 144 |
L3G4200D_LLD_I2_DRDY = 0x08,
|
| 145 |
L3G4200D_LLD_I2_WTM = 0x04,
|
| 146 |
L3G4200D_LLD_I2_ORUN = 0x02,
|
| 147 |
L3G4200D_LLD_I2_EMPTY = 0x01,
|
| 148 |
} l3g4200d_lld_ctrl_reg3_t; |
| 149 |
|
| 150 |
/**
|
| 151 |
* @brief Control register 4 flags.
|
| 152 |
*/
|
| 153 |
typedef enum { |
| 154 |
L3G4200D_LLD_BDU_CONT = 0x00,
|
| 155 |
L3G4200D_LLD_BDU_SINGLE = 0x80,
|
| 156 |
L3G4200D_LLD_BLE_MSB = 0x40,
|
| 157 |
L3G4200D_LLD_BLE_LSB = 0x00,
|
| 158 |
L3G4200D_LLD_FS_250_DPS = 0x00,
|
| 159 |
L3G4200D_LLD_FS_500_DPS = 0x10,
|
| 160 |
L3G4200D_LLD_FS_2000_DPS = 0x20,
|
| 161 |
L3G4200D_LLD_ST_SIGN_M = 0x04,
|
| 162 |
L3G4200D_LLD_ST_SIGN_P = 0x00,
|
| 163 |
L3G4200D_LLD_ST_EN = 0x02,
|
| 164 |
L3G4200D_LLD_SIM_3W = 0x01,
|
| 165 |
L3G4200D_LLD_SIM_4W = 0x00,
|
| 166 |
} l3g4200d_lld_ctrl_reg4_t; |
| 167 |
|
| 168 |
/**
|
| 169 |
* @brief Control register 5 flags.
|
| 170 |
*/
|
| 171 |
typedef enum { |
| 172 |
L3G4200D_LLD_BOOT = 0x80,
|
| 173 |
L3G4200D_LLD_FIFO_EN = 0x40,
|
| 174 |
L3G4200D_LLD_HP_EN = 0x10,
|
| 175 |
L3G4200D_LLD_INT1_SEL_NOHP = 0x00,
|
| 176 |
L3G4200D_LLD_INT1_SEL_HP = 0x04,
|
| 177 |
L3G4200D_LLD_INT1_SEL_LP = 0x08,
|
| 178 |
L3G4200D_LLD_OUT_SEL_NOHP = 0x00,
|
| 179 |
L3G4200D_LLD_OUT_SEL_HP = 0x01,
|
| 180 |
L3G4200D_LLD_OUT_SEL_LP = 0x02,
|
| 181 |
} l3g4200d_lld_ctrl_reg5_t; |
| 182 |
|
| 183 |
/**
|
| 184 |
* @brief Status register flags.
|
| 185 |
*/
|
| 186 |
typedef enum { |
| 187 |
L3G4200D_LLD_ZYXOR = 0x80,
|
| 188 |
L3G4200D_LLD_ZOR = 0x40,
|
| 189 |
L3G4200D_LLD_YOR = 0x20,
|
| 190 |
L3G4200D_LLD_XOR = 0x10,
|
| 191 |
L3G4200D_LLD_ZYXDA = 0x08,
|
| 192 |
L3G4200D_LLD_ZDA = 0x04,
|
| 193 |
L3G4200D_LLD_YDA = 0x02,
|
| 194 |
L3G4200D_LLD_XDA = 0x01,
|
| 195 |
} l3g4200d_lld_status_reg_t; |
| 196 |
|
| 197 |
/**
|
| 198 |
* @brief Fifo control register masks.
|
| 199 |
*/
|
| 200 |
typedef enum { |
| 201 |
L3G4200D_LLD_FM_BYPASS = 0x00,
|
| 202 |
L3G4200D_LLD_FM_FMMODE = 0x20,
|
| 203 |
L3G4200D_LLD_FM_STREAM = 0x40,
|
| 204 |
L3G4200D_LLD_FM_STREAM2FIFO = 0x60,
|
| 205 |
L3G4200D_LLD_FM_BYPASS2STREAM = 0x80,
|
| 206 |
L3G4200D_LLD_WTM_MASK = 0x1F,
|
| 207 |
} l3g4200d_lld_fifo_ctrl_reg_t; |
| 208 |
|
| 209 |
/**
|
| 210 |
* @brief FIFO source register masks.
|
| 211 |
*/
|
| 212 |
typedef enum { |
| 213 |
L3G4200D_LLD_WTM = 0x80,
|
| 214 |
L3G4200D_LLD_OVRN = 0x40,
|
| 215 |
L3G4200D_LLD_EMPTY = 0x20,
|
| 216 |
L3G4200D_LLD_FSS_MASK = 0x1F,
|
| 217 |
} l3g4200d_lld_fifo_src_reg_t; |
| 218 |
|
| 219 |
/**
|
| 220 |
* @brief Interrupt 1 config register flags.
|
| 221 |
*/
|
| 222 |
typedef enum { |
| 223 |
L3G4200D_LLD_ANDOR = 0x80,
|
| 224 |
L3G4200D_LLD_LIR = 0x40,
|
| 225 |
L3G4200D_LLD_ZHIE = 0x20,
|
| 226 |
L3G4200D_LLD_ZLIE = 0x10,
|
| 227 |
L3G4200D_LLD_YHIE = 0x08,
|
| 228 |
L3G4200D_LLD_YLIE = 0x04,
|
| 229 |
L3G4200D_LLD_XHIE = 0x02,
|
| 230 |
L3G4200D_LLD_XLIE = 0x01,
|
| 231 |
} l3g4200d_lld_int1_cfg_reg_t; |
| 232 |
|
| 233 |
/**
|
| 234 |
* @brief Interrupt 1 source register flags.
|
| 235 |
*/
|
| 236 |
typedef enum { |
| 237 |
L3G4200D_LLD_IA = 0x40,
|
| 238 |
L3G4200D_LLD_ZH = 0x20,
|
| 239 |
L3G4200D_LLD_ZL = 0x10,
|
| 240 |
L3G4200D_LLD_YH = 0x08,
|
| 241 |
L3G4200D_LLD_YL = 0x04,
|
| 242 |
L3G4200D_LLD_XH = 0x02,
|
| 243 |
L3G4200D_LLD_XL = 0x01,
|
| 244 |
} l3g4200d_lld_int1_src_t; |
| 245 |
|
| 246 |
/**
|
| 247 |
* @brief Threshold mask.
|
| 248 |
*/
|
| 249 |
enum {
|
| 250 |
L3G4200D_LLD_THS_L_MASK = 0x7F
|
| 251 |
}; |
| 252 |
|
| 253 |
/**
|
| 254 |
* @brief Interrupt duration register masks.
|
| 255 |
*/
|
| 256 |
typedef enum { |
| 257 |
L3G4200D_LLD_INT1_WAIT = 0x80,
|
| 258 |
L3G4200D_LLD_INT1_DURATION_MASK = 0x7F,
|
| 259 |
} l3g4200d_lld_int1_duration_reg_t; |
| 260 |
|
| 261 |
/**
|
| 262 |
* @brief Axis enum.
|
| 263 |
*/
|
| 264 |
typedef enum { |
| 265 |
L3G4200D_LLD_X_AXIS = 0x00,
|
| 266 |
L3G4200D_LLD_Y_AXIS = 0x01,
|
| 267 |
L3G4200D_LLD_Z_AXIS = 0x02,
|
| 268 |
} l3g4200d_lld_axis_t; |
| 269 |
|
| 270 |
/**
|
| 271 |
* @brief Config register struct.
|
| 272 |
*/
|
| 273 |
typedef union { |
| 274 |
uint8_t data[5];
|
| 275 |
struct {
|
| 276 |
uint8_t ctrl_reg1; |
| 277 |
uint8_t ctrl_reg2; |
| 278 |
uint8_t ctrl_reg3; |
| 279 |
uint8_t ctrl_reg4; |
| 280 |
uint8_t ctrl_reg5; |
| 281 |
} registers; |
| 282 |
} l3g4200d_lld_cfg_t; |
| 283 |
|
| 284 |
/**
|
| 285 |
* @brief Interrupt config struct.
|
| 286 |
*/
|
| 287 |
typedef union { |
| 288 |
uint8_t data[9];
|
| 289 |
struct {
|
| 290 |
uint8_t int1_cfg; |
| 291 |
uint8_t int1_src; |
| 292 |
uint8_t int1_tsh_xh; |
| 293 |
uint8_t int1_tsh_xl; |
| 294 |
uint8_t int1_tsh_yh; |
| 295 |
uint8_t int1_tsh_yl; |
| 296 |
uint8_t int1_tsh_zh; |
| 297 |
uint8_t int1_tsh_zl; |
| 298 |
uint8_t int1_duration; |
| 299 |
} registers; |
| 300 |
} l3g4200d_lld_int_cfg_t; |
| 301 |
|
| 302 |
#ifdef __cplusplus
|
| 303 |
extern "C" { |
| 304 |
#endif
|
| 305 |
apalExitStatus_t l3g4200d_lld_read_register(const L3G4200DDriver* const l3gd, const l3g4200d_lld_register_t regaddr, uint8_t* const data, const uint8_t length); |
| 306 |
apalExitStatus_t l3g4200d_lld_write_register(const L3G4200DDriver* const l3gd, const l3g4200d_lld_register_t regaddr, const uint8_t* const data, const uint8_t length); |
| 307 |
apalExitStatus_t l3g4200d_lld_read_all_data(const L3G4200DDriver* const l3gd, int16_t* const data, const l3g4200d_lld_cfg_t* const cfg); |
| 308 |
apalExitStatus_t l3g4200d_lld_read_data(const L3G4200DDriver* const l3gd, int16_t* const data, const l3g4200d_lld_axis_t axis, const l3g4200d_lld_cfg_t* const cfg); |
| 309 |
apalExitStatus_t l3g4200d_lld_read_config(const L3G4200DDriver* const l3gd, l3g4200d_lld_cfg_t* const cfg); |
| 310 |
apalExitStatus_t l3g4200d_lld_write_config(const L3G4200DDriver* const l3gd, const l3g4200d_lld_cfg_t cfg); |
| 311 |
apalExitStatus_t l3g4200d_lld_read_int_config(const L3G4200DDriver* const l3gd, l3g4200d_lld_int_cfg_t* const cfg); |
| 312 |
apalExitStatus_t l3g4200d_lld_write_int_config(const L3G4200DDriver* const l3gd, const l3g4200d_lld_int_cfg_t cfg); |
| 313 |
apalExitStatus_t l3g4200d_lld_read_int_src(const L3G4200DDriver* const l3gd, uint8_t* const cfg); |
| 314 |
apalExitStatus_t l3g4200d_lld_read_status_register(const L3G4200DDriver* const l3gd, uint8_t* const status); |
| 315 |
apalExitStatus_t l3g4200d_lld_read_fifo_ctrl_register(const L3G4200DDriver* const l3gd, uint8_t* const fifo); |
| 316 |
apalExitStatus_t l3g4200d_lld_write_fifo_ctrl_register(const L3G4200DDriver* const l3gd, const uint8_t fifo); |
| 317 |
apalExitStatus_t l3g4200d_lld_read_fifo_src_register(const L3G4200DDriver* const l3gdd, uint8_t* const fifo); |
| 318 |
#ifdef __cplusplus
|
| 319 |
} |
| 320 |
#endif
|
| 321 |
|
| 322 |
#endif /* defined(AMIROLLD_CFG_USE_L3G4200D) */ |
| 323 |
|
| 324 |
#endif /* _AMIROLLD_L3G4200D_H_ */ |
| 325 |
|
| 326 |
/** @} */
|