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.
AK09912.h@1:4eefcf1d7351, 2017-01-26 (annotated)
- Committer:
- bcc6
- Date:
- Thu Jan 26 03:22:34 2017 +0000
- Revision:
- 1:4eefcf1d7351
- Parent:
- 0:4f87d5af61b1
Basic functions is OK. Lack interrupts function.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bcc6 | 1:4eefcf1d7351 | 1 | /* Copyright (c) 2016 MtM Technology Corporation, MIT License |
| bcc6 | 1:4eefcf1d7351 | 2 | * |
| bcc6 | 1:4eefcf1d7351 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| bcc6 | 1:4eefcf1d7351 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| bcc6 | 1:4eefcf1d7351 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| bcc6 | 1:4eefcf1d7351 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| bcc6 | 1:4eefcf1d7351 | 7 | * furnished to do so, subject to the following conditions: |
| bcc6 | 1:4eefcf1d7351 | 8 | * |
| bcc6 | 1:4eefcf1d7351 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| bcc6 | 1:4eefcf1d7351 | 10 | * substantial portions of the Software. |
| bcc6 | 1:4eefcf1d7351 | 11 | * |
| bcc6 | 1:4eefcf1d7351 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| bcc6 | 1:4eefcf1d7351 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| bcc6 | 1:4eefcf1d7351 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| bcc6 | 1:4eefcf1d7351 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| bcc6 | 1:4eefcf1d7351 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| bcc6 | 1:4eefcf1d7351 | 17 | */ |
| bcc6 | 0:4f87d5af61b1 | 18 | #ifndef AK09912_H |
| bcc6 | 0:4f87d5af61b1 | 19 | #define AK09912_H |
| bcc6 | 0:4f87d5af61b1 | 20 | |
| bcc6 | 0:4f87d5af61b1 | 21 | #include "mbed.h" |
| bcc6 | 0:4f87d5af61b1 | 22 | |
| bcc6 | 0:4f87d5af61b1 | 23 | |
| bcc6 | 0:4f87d5af61b1 | 24 | #define AK09912_SLAVE_ADDR 0x1A // 0001_1010b |
| bcc6 | 0:4f87d5af61b1 | 25 | |
| bcc6 | 0:4f87d5af61b1 | 26 | |
| bcc6 | 0:4f87d5af61b1 | 27 | class AK09912 { |
| bcc6 | 0:4f87d5af61b1 | 28 | public: |
| bcc6 | 0:4f87d5af61b1 | 29 | struct Data { |
| bcc6 | 0:4f87d5af61b1 | 30 | float x; // uT/LSB |
| bcc6 | 0:4f87d5af61b1 | 31 | float y; |
| bcc6 | 0:4f87d5af61b1 | 32 | float z; |
| bcc6 | 0:4f87d5af61b1 | 33 | float t; // 'C |
| bcc6 | 0:4f87d5af61b1 | 34 | }; |
| bcc6 | 0:4f87d5af61b1 | 35 | |
| bcc6 | 0:4f87d5af61b1 | 36 | static const uint8_t DEVICE_ID = 0x04; |
| bcc6 | 0:4f87d5af61b1 | 37 | |
| bcc6 | 0:4f87d5af61b1 | 38 | AK09912(I2C &i2c, PinName int1 = NC); |
| bcc6 | 0:4f87d5af61b1 | 39 | |
| bcc6 | 0:4f87d5af61b1 | 40 | void ConfigDevice(); |
| bcc6 | 0:4f87d5af61b1 | 41 | void GetDeviceID(uint8_t *id); |
| bcc6 | 0:4f87d5af61b1 | 42 | void GetData(Data *data); |
| bcc6 | 0:4f87d5af61b1 | 43 | |
| bcc6 | 0:4f87d5af61b1 | 44 | private: |
| bcc6 | 0:4f87d5af61b1 | 45 | I2C &_i2c; |
| bcc6 | 0:4f87d5af61b1 | 46 | InterruptIn _int1; |
| bcc6 | 0:4f87d5af61b1 | 47 | |
| bcc6 | 0:4f87d5af61b1 | 48 | uint8_t _asa[3]; // ASAX, ASAY, ASAZ |
| bcc6 | 0:4f87d5af61b1 | 49 | |
| bcc6 | 0:4f87d5af61b1 | 50 | float ConvertAdcToMagnetic(int16_t adc, uint8_t asa); |
| bcc6 | 0:4f87d5af61b1 | 51 | float ConvertAdcToTemperature(uint8_t adc); |
| bcc6 | 0:4f87d5af61b1 | 52 | |
| bcc6 | 0:4f87d5af61b1 | 53 | void RegWrite(char reg, char val); |
| bcc6 | 0:4f87d5af61b1 | 54 | void RegRead (char reg, char *val, int len); |
| bcc6 | 0:4f87d5af61b1 | 55 | void RegReadModifyWrite(char reg, char clr_mask, char set_mask); |
| bcc6 | 0:4f87d5af61b1 | 56 | }; |
| bcc6 | 0:4f87d5af61b1 | 57 | |
| bcc6 | 0:4f87d5af61b1 | 58 | #endif |