Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NineIMUAttitude_MadgwickFilter
BMX055.hpp
00001 #ifndef BMX055_HPP 00002 #define BMX055_HPP 00003 00004 #include "mbed.h" 00005 00006 // Aux class 00007 template <typename T = float, unsigned char D = 3> 00008 class FixedLengthVector 00009 { 00010 public: 00011 const unsigned char degree; // length of array, or num of elements 00012 00013 T * const e; // elements 00014 00015 //elements' alias 00016 T &w, &x, &y, &z; 00017 00018 00019 FixedLengthVector (T* arg_init_vec = array_filled_0(D)) 00020 :degree(value_checked_degree(D)) 00021 ,e(new T[degree]) 00022 ,w(e[0]) 00023 ,x((degree > 3 ? e[1] : e[0])) 00024 ,y((degree > 3 ? e[2] : e[1])) 00025 ,z((degree > 3 ? e[3] : (degree == 3 ? e[2] : e[1]))) 00026 { 00027 for (int i = 0; i < degree; i++) e[i] = arg_init_vec[i]; 00028 } 00029 00030 00031 private: 00032 static inline unsigned char value_checked_degree (unsigned char arg_degree) 00033 { 00034 if (arg_degree < 2) return 2; 00035 else return arg_degree; 00036 } 00037 00038 static inline T * array_filled_0 (unsigned char arg_degree) 00039 { 00040 unsigned char l_degree = value_checked_degree(arg_degree); 00041 T* tmp = new T[l_degree]; 00042 00043 for(int i = 0; i < l_degree; i++) tmp[i] = 0; 00044 return tmp; 00045 } 00046 00047 }; 00048 00049 class BMX055 00050 { 00051 public: 00052 /** Main buffers which store 3 cubic data 00053 * 00054 * Acc: all x,y,z has 12 bits payload 00055 * Gyr: all x,y,z has 16 bits payload 00056 * Mag: x,y have 13 bits and z have 15 bits payload 00057 */ 00058 FixedLengthVector<signed short, 3> acc, gyr, mag; 00059 00060 // I2C pin of LPC 1768 is (p9, p10) or (p28, p27); 00061 BMX055( 00062 const char arg_addr_acc = 0x19, 00063 const char arg_addr_gyr = 0x69, 00064 const char arg_addr_mag = 0x13, 00065 PinName arg_SDA = p9, 00066 PinName arg_SCL = p10) 00067 : m_addr_acc(arg_addr_acc << 1) 00068 , m_addr_gyr(arg_addr_gyr << 1) 00069 , m_addr_mag(arg_addr_mag << 1) 00070 { 00071 Init_I2C(arg_SDA, arg_SCL); 00072 } 00073 void Update(); 00074 void UpdateIMU(); 00075 00076 private: 00077 I2C* i2c; 00078 const char m_addr_acc; 00079 const char m_addr_gyr; 00080 const char m_addr_mag; 00081 void Init_I2C(PinName arg_SDA, PinName arg_SCL); 00082 00083 }; 00084 #endif
Generated on Mon Jul 18 2022 02:55:07 by
1.7.2