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.
hmc5883.h
00001 00002 #ifndef SKYSCRAPER_MBED_HMC5883L_H_INCLUDED 00003 #define SKYSCRAPER_MBED_HMC5883L_H_INCLUDED 00004 00005 #include "magnetometer.h" 00006 #include "I2CBusDevice.h" 00007 00008 struct hmc5883L : I2CBusDevice{ 00009 00010 hmc5883L(I2C& i2cIn,uint8_t addressIn); 00011 00012 bool detected(bool verbose)const; 00013 00014 bool data_ready()const; 00015 00016 // assume mag_data_ready has returned true before call 00017 bool read(quan::three_d::vect<quan::magnetic_flux_density::uT> & v)const; 00018 00019 bool start_measurement()const; 00020 00021 private: 00022 00023 friend bool mag_init(); 00024 00025 bool make_measurement( 00026 quan::three_d::vect< 00027 quan::magnetic_flux_density::uT 00028 >& result 00029 )const; 00030 // bool write_reg(uint8_t idx, uint8_t val)const; 00031 bool set_reg_idx(uint8_t idx_in)const; 00032 00033 // 00 Configuration Register A R/W 00034 static constexpr char cfg_regA = 0; 00035 00036 //01 Configuration Register B R/W 00037 static constexpr char cfg_regB = 1; 00038 00039 //02 Mode Register R/W 00040 static constexpr char mode_reg = 2; 00041 00042 //03 Data Output X MSB Register R 00043 static constexpr char dout_reg = 3; 00044 //04 Data Output X LSB Register R 00045 //05 Data Output Z MSB Register R 00046 //06 Data Output Z LSB Register R 00047 //07 Data Output Y MSB Register R 00048 //08 Data Output Y LSB Register R 00049 00050 // 09 Status Register R 00051 static constexpr char status_reg = 9; 00052 00053 // 10 Identification Register A R 00054 static constexpr char id_regA = 10; 00055 // 11 Identification Register B R 00056 // 12 Identification Register C R 00057 00058 bool write_reg(uint8_t idx, uint8_t val)const; 00059 bool get_reg(uint8_t idx_in, uint8_t& result)const; 00060 bool modify_reg(uint8_t idx, uint8_t and_val, uint8_t or_val)const; 00061 bool data_locked()const; 00062 bool set_continuous_measurement_mode()const; 00063 bool set_gain( quan::three_d::vect<double> const & gain); 00064 bool set_offset(quan::three_d::vect< 00065 quan::magnetic_flux_density::uT 00066 > const & offset); 00067 00068 bool set_idle_mode()const; 00069 00070 // 1,2,4,8 available 00071 bool set_samples_average(int n_samples)const; 00072 00073 // may change so that always one-shot 00074 // ignore continousos mode 00075 //data rate 0.75, 1.5, 3 ,7.5, 15 (Default) , 30, 75 00076 template <int N, int D=1> 00077 bool set_data_rate()const; 00078 00079 bool set_positive_bias()const; 00080 bool set_negative_bias()const; 00081 bool mag_clear_bias()const; 00082 bool set_range(quan::magnetic_flux_density::uT const & range_in); 00083 00084 quan::magnetic_flux_density::uT 00085 get_flux_density_range()const; 00086 //------------ 00087 // per lsb defualt resolution 00088 quan::magnetic_flux_density::uT mag_resolution; 00089 // range before saturation 00090 quan::magnetic_flux_density::uT mag_range; 00091 quan::three_d::vect<double> mag_gain; 00092 quan::three_d::vect<quan::magnetic_flux_density::uT> mag_offset; 00093 }; 00094 00095 00096 00097 00098 00099 #endif
Generated on Fri Jul 15 2022 16:09:02 by
