A mbed-os v5 driver for KX224-1053 (3 axis accelerometer, made by Rohm).
Dependents: rohm-SensorShield-example mbed_blinky
KX224.h
00001 /***************************************************************************** 00002 KX224_I2C.h 00003 00004 Copyright (c) 2017 ROHM Co.,Ltd. 00005 00006 Permission is hereby granted, free of charge, to any person obtaining a copy 00007 of this software and associated documentation files (the "Software"), to deal 00008 in the Software without restriction, including without limitation the rights 00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 copies of the Software, and to permit persons to whom the Software is 00011 furnished to do so, subject to the following conditions: 00012 00013 The above copyright notice and this permission notice shall be included in 00014 all copies or substantial portions of the Software. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 THE SOFTWARE. 00023 * 00024 * KX224-1053 3 axis accelerometer library 00025 * 00026 * @modified by Ren Boting 00027 * @version 1.0 00028 * @date 18-February-2019 00029 * 00030 * Library for "KX224-1053 3 axis accelerometer library" 00031 * https://www.rohm.co.jp/sensor-shield-support/accelerometer 00032 * 00033 */ 00034 #ifndef _KX224_H_ 00035 #define _KX224_H_ 00036 00037 #include "mbed.h" 00038 00039 #define KX224_DEVICE_ADDRESS_1E (0x1E << 1) // 7bit Addrss 00040 #define KX224_DEVICE_ADDRESS_1F (0x1F << 1) // 7bit Address 00041 #define KX224_WAI_VAL (0x2B) 00042 00043 #define KX224_XOUT_L (0x06) 00044 #define KX224_WHO_AM_I (0x0F) 00045 #define KX224_CNTL1 (0x18) 00046 #define KX224_ODCNTL (0x1B) 00047 00048 #define KX224_CNTL1_TPE (1 << 0) 00049 #define KX224_CNTL1_WUFE (1 << 1) 00050 #define KX224_CNTL1_TDTE (1 << 2) 00051 #define KX224_CNTL1_GSELMASK (0x18) 00052 #define KX224_CNTL1_GSEL_8G (0x00) 00053 #define KX224_CNTL1_GSEL_16G (0x08) 00054 #define KX224_CNTL1_GSEL_32G (0x10) 00055 #define KX224_CNTL1_DRDYE (1 << 5) 00056 #define KX224_CNTL1_RES (1 << 6) 00057 #define KX224_CNTL1_PC1 (1 << 7) 00058 00059 #define KX224_ODCNTL_OSA_50HZ (2) 00060 #define KX224_ODCNTL_LPRO (1 << 6) 00061 #define KX224_IIR_BYPASS (1 << 7) 00062 00063 #define KX224_CNTL1_VAL (KX224_CNTL1_RES | KX224_CNTL1_GSEL_8G) 00064 #define KX224_ODCNTL_VAL (KX224_ODCNTL_OSA_50HZ) 00065 00066 #ifdef _DEBUG 00067 #undef DEBUG_PRINT 00068 #define DEBUG_PRINT(...) printf(__VA_ARGS__) 00069 #else 00070 #define DEBUG_PRINT(...) 00071 #endif 00072 00073 class KX224 00074 { 00075 public: 00076 /** 00077 * KX224 constructor 00078 * 00079 * @param sda SDA pin 00080 * @param sdl SCL pin 00081 * @param addr slave address of the I2C peripheral (default: 0x1E) 00082 */ 00083 KX224(PinName sda, PinName scl, int slave_addr = KX224_DEVICE_ADDRESS_1E); 00084 /** 00085 * KX224 destructor 00086 */ 00087 ~KX224(); 00088 uint8_t initialize(void); 00089 void get_val(float *data); 00090 private: 00091 I2C m_i2c; 00092 int m_addr; 00093 uint16_t _g_sens; 00094 void write(uint8_t memory_address, char *data); 00095 void read(uint8_t memory_address, char *data, int size); 00096 }; 00097 00098 #endif // _KX224_H_
Generated on Tue Jul 26 2022 07:48:49 by 1.7.2