I2Cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs

AK8975/AK8975.h
00001 // I2Cdev library collection - AK8975 I2C device class header file
00002 // Based on AKM AK8975/B datasheet, 12/2009
00003 // 8/27/2011 by Jeff Rowberg <jeff@rowberg.net>
00004 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
00005 //
00006 // Changelog:
00007 //     2011-08-27 - initial release
00008 
00009 /* ============================================
00010 I2Cdev device library code is placed under the MIT license
00011 Copyright (c) 2011 Jeff Rowberg
00012 
00013 Permission is hereby granted, free of charge, to any person obtaining a copy
00014 of this software and associated documentation files (the "Software"), to deal
00015 in the Software without restriction, including without limitation the rights
00016 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00017 copies of the Software, and to permit persons to whom the Software is
00018 furnished to do so, subject to the following conditions:
00019 
00020 The above copyright notice and this permission notice shall be included in
00021 all copies or substantial portions of the Software.
00022 
00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00024 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00026 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00028 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00029 THE SOFTWARE.
00030 ===============================================
00031 */
00032 
00033 #ifndef _AK8975_H_
00034 #define _AK8975_H_
00035 
00036 #include "I2Cdev.h"
00037 
00038 #define AK8975_ADDRESS_00         0x0C
00039 #define AK8975_ADDRESS_01         0x0D
00040 #define AK8975_ADDRESS_10         0x0E // default for InvenSense MPU-6050 evaluation board
00041 #define AK8975_ADDRESS_11         0x0F
00042 #define AK8975_DEFAULT_ADDRESS    AK8975_ADDRESS_00
00043 
00044 #define AK8975_RA_WIA             0x00
00045 #define AK8975_RA_INFO            0x01
00046 #define AK8975_RA_ST1             0x02
00047 #define AK8975_RA_HXL             0x03
00048 #define AK8975_RA_HXH             0x04
00049 #define AK8975_RA_HYL             0x05
00050 #define AK8975_RA_HYH             0x06
00051 #define AK8975_RA_HZL             0x07
00052 #define AK8975_RA_HZH             0x08
00053 #define AK8975_RA_ST2             0x09
00054 #define AK8975_RA_CNTL            0x0A
00055 #define AK8975_RA_RSV             0x0B // RESERVED, DO NOT USE
00056 #define AK8975_RA_ASTC            0x0C
00057 #define AK8975_RA_TS1             0x0D // SHIPMENT TEST, DO NOT USE
00058 #define AK8975_RA_TS2             0x0E // SHIPMENT TEST, DO NOT USE
00059 #define AK8975_RA_I2CDIS          0x0F
00060 #define AK8975_RA_ASAX            0x10
00061 #define AK8975_RA_ASAY            0x11
00062 #define AK8975_RA_ASAZ            0x12
00063 
00064 #define AK8975_ST1_DRDY_BIT       0
00065 
00066 #define AK8975_ST2_HOFL_BIT       3
00067 #define AK8975_ST2_DERR_BIT       2
00068 
00069 #define AK8975_CNTL_MODE_BIT      3
00070 #define AK8975_CNTL_MODE_LENGTH   4
00071 
00072 #define AK8975_MODE_POWERDOWN     0x0
00073 #define AK8975_MODE_SINGLE        0x1
00074 #define AK8975_MODE_SELFTEST      0x8
00075 #define AK8975_MODE_FUSEROM       0xF
00076 
00077 #define AK8975_ASTC_SELF_BIT      6
00078 
00079 #define AK8975_I2CDIS_BIT         0
00080 
00081 class AK8975 {
00082     public:
00083         AK8975();
00084         AK8975(uint8_t address);
00085         
00086         void initialize();
00087         bool testConnection();
00088 
00089         // WIA register
00090         uint8_t getDeviceID();
00091         
00092         // INFO register
00093         uint8_t getInfo();
00094         
00095         // ST1 register
00096         bool getDataReady();
00097         
00098         // H* registers
00099         void getHeading(int16_t *x, int16_t *y, int16_t *z);
00100         int16_t getHeadingX();
00101         int16_t getHeadingY();
00102         int16_t getHeadingZ();
00103         
00104         // ST2 register
00105         bool getOverflowStatus();
00106         bool getDataError();
00107 
00108         // CNTL register
00109         uint8_t getMode();
00110         void setMode(uint8_t mode);
00111         void reset();
00112         
00113         // ASTC register
00114         void setSelfTest(bool enabled);
00115         
00116         // I2CDIS
00117         void disableI2C(); // um, why...?
00118         
00119         // ASA* registers
00120         void getAdjustment(uint8_t *x, uint8_t *y, uint8_t *z);
00121         void setAdjustment(uint8_t x, uint8_t y, uint8_t z);
00122         uint8_t getAdjustmentX();
00123         void setAdjustmentX(uint8_t x);
00124         uint8_t getAdjustmentY();
00125         void setAdjustmentY(uint8_t y);
00126         uint8_t getAdjustmentZ();
00127         void setAdjustmentZ(uint8_t z);
00128 
00129     private:
00130         uint8_t devAddr;
00131         uint8_t buffer[6];
00132         uint8_t mode;
00133 };
00134 
00135 #endif /* _AK8975_H_ */
 All Data Structures Functions Variables