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.
Fork of AK7451 by
ak7451.h
00001 #ifndef AK7451_H 00002 #define AK7451_H 00003 00004 #include "mbed.h" 00005 00006 /** 00007 * This is a device driver of AK7451 with SPI interface. 00008 * 00009 * @note AK7451 is a high speed angle sensor IC manufactured by AKM. 00010 * 00011 * Example: 00012 * @code 00013 * #include "mbed.h" 00014 * #include "ak7451.h" 00015 * 00016 * 00017 * int main() { 00018 * // Creates an instance of SPI 00019 * } 00020 * @endcode 00021 */ 00022 class AK7451 00023 { 00024 public: 00025 00026 /** 00027 * Available opration modes in AK7451. 00028 */ 00029 typedef enum { 00030 AK7451_NORMAL_MODE = 0x0000, /**< Normal mode operation. */ 00031 AK7451_USER_MODE = 0x050F, /**< User mode operation. */ 00032 } OperationMode; 00033 00034 /** 00035 * Status of function. 00036 */ 00037 typedef enum { 00038 SUCCESS, /**< The function processed successfully. */ 00039 ERROR, /**< General Error */ 00040 ERROR_IN_USER_MODE, /**< Error in user mode. */ 00041 ERROR_IN_NORMAL_MODE, /**< Error in normal mode. */ 00042 ERROR_PARITY, /**< Parity bit error. */ 00043 ERROR_ABNORMAL_STRENGTH, /**< Abnormal strength error. */ 00044 } Status; 00045 00046 /** 00047 * Constructor. 00048 * 00049 */ 00050 AK7451(); 00051 00052 /** 00053 * Destructor. 00054 * 00055 */ 00056 ~AK7451(); 00057 00058 /** 00059 * begin 00060 * 00061 * @param *spi pointer to SPI instance 00062 * @param *cs pointer to DigitalOut instance for CS 00063 */ 00064 void begin(SPI *spi, DigitalOut *cs); 00065 00066 /** 00067 * Check the connection. 00068 * 00069 * @note Connection check is performed by reading a register which has a fixed value and verify it. 00070 * 00071 * @return Returns SUCCESS when succeeded, otherwise returns another code. 00072 */ 00073 Status checkConnection(); 00074 00075 /** 00076 * Writes data to EEPROM on the device. 00077 * @param address EEPROM address 00078 * @param data data to be written 00079 * @return Returns SUCCESS when succeeded, otherwise returns another. 00080 */ 00081 Status writeEEPROM(char address, const char *data); 00082 00083 /** 00084 * Reads data from EEPROM on the device. 00085 * @param address EEPROM address 00086 * @param data data to read 00087 * @return Returns SUCCESS when succeeded, otherwise returns another. 00088 */ 00089 Status readEEPROM(char address, char *data); 00090 00091 /** 00092 * Writes data to register on the device. 00093 * @param address register address 00094 * @param data data to be written 00095 * @return Returns SUCCESS when succeeded, otherwise returns another. 00096 */ 00097 Status writeRegister(char address, const char *data); 00098 00099 /** 00100 * Reads data from register on the device. 00101 * @param address register address 00102 * @param data data to read 00103 * @return Returns SUCCESS when succeeded, otherwise returns another. 00104 */ 00105 Status readRegister(char address, char *data); 00106 00107 /** 00108 * Sets device operation mode. 00109 * 00110 * @param mode device opration mode 00111 * 00112 * @return Returns SUCCESS when succeeded, otherwise returns another code. 00113 */ 00114 Status setOperationMode(OperationMode mode); 00115 00116 /** 00117 * Gets device operation mode. 00118 * 00119 * @return Returns OperationMode. 00120 */ 00121 OperationMode getOperationMode(); 00122 00123 /** 00124 * Reads angle data from the device. 00125 * 00126 * @param angle pointer to read angle data buffer 00127 * 00128 * @return Returns SUCCESS when succeeded, otherwise returns another code. 00129 */ 00130 Status readAngle(char *angle); 00131 00132 /** 00133 * Measures and reads angle, magnetic flux density and abnormal state code while in the user mode. 00134 * 00135 * @param angle pointer to angle data buffer 00136 * @param density magnetic flux density 00137 * @param abnormal_state abnormal state 00138 * 00139 * @return Returns SUCCESS when succeeded, otherwise returns another code. 00140 */ 00141 Status readAngleMeasureCommand(char *angle, char *density, char *abnormal_state); 00142 00143 /** 00144 * Measures current angle and sets the value to EEPROM as zero angle position. 00145 * 00146 * @return Returns SUCCESS when succeeded, otherwise returns another code. 00147 */ 00148 Status setAngleZero(); 00149 00150 /** 00151 * Sets the value to EEPROM as zero angle position. 00152 * 00153 * @param angle zero angle position 00154 * 00155 * @return Returns SUCCESS when succeeded, otherwise returns another code. 00156 */ 00157 Status setAngleZero(const char *angle); 00158 00159 private: 00160 /** 00161 * Holds a pointer to an SPI object. 00162 */ 00163 SPI *_spi; 00164 00165 /** 00166 * Holds a DigitalOut oblject for CS; 00167 */ 00168 DigitalOut *_cs; 00169 00170 /** 00171 * Holds current mode 00172 */ 00173 OperationMode operationMode; 00174 00175 /** 00176 * Reads data from device. 00177 * @param operation_code OPCODE 00178 * @param address memory/register addredd 00179 * @param *data pointer to the read buffer. length=2 fixed. 00180 * @return Returns SUCCESS when succeeded, otherwise returns another. 00181 */ 00182 Status read(char operation_code, char address, char *data); 00183 00184 /** 00185 * Writes data to the device. 00186 * @param operation_code OPCODE 00187 * @param address memory/register addredd 00188 * @param *data pointer to the read buffer. length=2 fixed. 00189 * @return Returns SUCCESS when succeeded, otherwise returns another. 00190 */ 00191 Status write(char operation_code, char address, const char *data); 00192 00193 /** 00194 * Checks parity bits sub function 00195 * @param data data 12bit read data 00196 * @param parity parity bit status 00197 * @param error error bit status 00198 * @return Returns SUCCESS when succeeded, otherwise returns another. 00199 */ 00200 Status parityCheckSub(const char data, const char parity, const char error); 00201 00202 /** 00203 * Checks parity bits 00204 * @param data 2 byte read data to chek parity 00205 * @return Returns SUCCESS when succeeded, otherwise returns another. 00206 */ 00207 Status parityCheck(const char *data); 00208 }; 00209 00210 #endif
Generated on Thu Jul 14 2022 01:58:56 by
1.7.2
