Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Committer:
tkstreet
Date:
Thu Apr 13 22:50:02 2017 +0000
Revision:
24:1d37438f31a9
Parent:
23:50c98b286e41
Parent:
20:2fca76521680
Child:
34:1ea3357c8d9a
Merge of revisions 20 and 23

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masahikofukasawa 0:7a00359e701e 1 #ifndef AKMAKD_H
masahikofukasawa 0:7a00359e701e 2 #define AKMAKD_H
masahikofukasawa 0:7a00359e701e 3
masahikofukasawa 0:7a00359e701e 4 #include "mbed.h"
masahikofukasawa 0:7a00359e701e 5 #include "SerialNano.h"
masahikofukasawa 0:7a00359e701e 6 #include "akmsensor.h"
masahikofukasawa 0:7a00359e701e 7 #include "akmecompass.h"
masahikofukasawa 0:7a00359e701e 8
masahikofukasawa 20:2fca76521680 9 #define AKDP_MAG_SENSITIVITY (0.15) // [uT/LSB]
masahikofukasawa 20:2fca76521680 10 #define AKDP_POLLING_FREQUENCY (200.0) // [Hz]
masahikofukasawa 20:2fca76521680 11
tkstreet 23:50c98b286e41 12 /**
tkstreet 23:50c98b286e41 13 * Collection class for handling commands to all of the specialty AKM
tkstreet 23:50c98b286e41 14 * daughter board adapter modules.
tkstreet 23:50c98b286e41 15 *
tkstreet 23:50c98b286e41 16 * 3-Axis Electronic Compass Devices: AK8963C, AK8963N, AK09911C, AK09912C,
tkstreet 23:50c98b286e41 17 * AK09915C, AK09915D, AK09916C, AK09916D, AK09970
tkstreet 23:50c98b286e41 18 */
masahikofukasawa 0:7a00359e701e 19 class AkmAkd : public AkmSensor
masahikofukasawa 0:7a00359e701e 20 {
masahikofukasawa 0:7a00359e701e 21
masahikofukasawa 0:7a00359e701e 22 public:
masahikofukasawa 0:7a00359e701e 23
tkstreet 23:50c98b286e41 24 /**
tkstreet 23:50c98b286e41 25 * List of daughter board adapter devices (5-bit Sub-IDs). Primary ID = 0Fh
tkstreet 23:50c98b286e41 26 */
tkstreet 23:50c98b286e41 27 typedef enum {
tkstreet 23:50c98b286e41 28 SUB_ID_AK8963N = 0x1A, /**< AK8963N: ID = 1Ah (26) */
tkstreet 23:50c98b286e41 29 SUB_ID_AK8963C = 0x1C, /**< AK8963C: ID = 1Ch (28) */
tkstreet 23:50c98b286e41 30 SUB_ID_AK09911C = 0x0A, /**< AK09911C: ID = 0Ah (10) */
tkstreet 23:50c98b286e41 31 SUB_ID_AK09912C = 0x09, /**< AK09912C: ID = 09h (9) */
tkstreet 23:50c98b286e41 32 SUB_ID_AK09915C = 0x0D, /**< AK09915C: ID = 0Dh (13) */
tkstreet 23:50c98b286e41 33 SUB_ID_AK09916C = 0x0E, /**< AK09916C: ID = 0Eh (14) */
tkstreet 23:50c98b286e41 34 SUB_ID_AK09916D = 0x0F, /**< AK09916D: ID = 0Fh (15) */
tkstreet 23:50c98b286e41 35 SUB_ID_AK09915D = 0x10, /**< AK09915D: ID = 10h (16) */
tkstreet 24:1d37438f31a9 36 SUB_ID_AK09918 = 0x11, /**< AK09918: ID = 11h (17) */
masahikofukasawa 0:7a00359e701e 37 } SubIdAkd;
masahikofukasawa 0:7a00359e701e 38
masahikofukasawa 19:8dcc4f323bdc 39 typedef enum {
masahikofukasawa 19:8dcc4f323bdc 40 INTERRUPT_DISABLED = 0x00, // Polling
masahikofukasawa 19:8dcc4f323bdc 41 INTERRUPT_ENABLED_PP = 0x01, // Push-Pull
masahikofukasawa 19:8dcc4f323bdc 42 INTERRUPT_ENABLED_OD = 0x02, // Open drain
masahikofukasawa 19:8dcc4f323bdc 43 } InterruptMode;
masahikofukasawa 19:8dcc4f323bdc 44
masahikofukasawa 0:7a00359e701e 45 /**
masahikofukasawa 0:7a00359e701e 46 * Constructor.
masahikofukasawa 0:7a00359e701e 47 *
masahikofukasawa 0:7a00359e701e 48 */
masahikofukasawa 0:7a00359e701e 49 AkmAkd();
masahikofukasawa 0:7a00359e701e 50
masahikofukasawa 0:7a00359e701e 51 /**
masahikofukasawa 0:7a00359e701e 52 * Destructor.
masahikofukasawa 0:7a00359e701e 53 *
masahikofukasawa 0:7a00359e701e 54 */
masahikofukasawa 0:7a00359e701e 55 virtual ~AkmAkd();
tkstreet 23:50c98b286e41 56
tkstreet 23:50c98b286e41 57 /**
tkstreet 23:50c98b286e41 58 * Process for intializing the selected sensor.
tkstreet 23:50c98b286e41 59 *
tkstreet 23:50c98b286e41 60 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 61 */
masahikofukasawa 0:7a00359e701e 62 virtual AkmSensor::Status init(const uint8_t id, const uint8_t subid);
tkstreet 23:50c98b286e41 63
tkstreet 23:50c98b286e41 64 /**
tkstreet 23:50c98b286e41 65 * Simple flag process to determine if an event has occurred.
tkstreet 23:50c98b286e41 66 *
tkstreet 23:50c98b286e41 67 * @return TRUE if event has occurred, FALSE if not.
tkstreet 23:50c98b286e41 68 */
masahikofukasawa 0:7a00359e701e 69 virtual bool isEvent();
tkstreet 23:50c98b286e41 70
tkstreet 23:50c98b286e41 71 /**
tkstreet 23:50c98b286e41 72 * Process abstraction for starting sensor operation.
tkstreet 23:50c98b286e41 73 *
tkstreet 23:50c98b286e41 74 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 75 */
masahikofukasawa 0:7a00359e701e 76 virtual AkmSensor::Status startSensor();
tkstreet 23:50c98b286e41 77
tkstreet 23:50c98b286e41 78 /**
tkstreet 23:50c98b286e41 79 * Process abstraction for starting sensor operation.
tkstreet 23:50c98b286e41 80 *
tkstreet 23:50c98b286e41 81 * @param sec Number of seconds of operation.
tkstreet 23:50c98b286e41 82 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 83 */
masahikofukasawa 0:7a00359e701e 84 virtual AkmSensor::Status startSensor(const float sec);
tkstreet 23:50c98b286e41 85
tkstreet 23:50c98b286e41 86 /**
tkstreet 23:50c98b286e41 87 * Process abstraction for stopping sensor operation.
tkstreet 23:50c98b286e41 88 *
tkstreet 23:50c98b286e41 89 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 90 */
masahikofukasawa 0:7a00359e701e 91 virtual AkmSensor::Status stopSensor();
tkstreet 23:50c98b286e41 92
tkstreet 23:50c98b286e41 93 /**
tkstreet 23:50c98b286e41 94 * Process abstraction for reading data from the sensor.
tkstreet 23:50c98b286e41 95 *
tkstreet 23:50c98b286e41 96 * @param msg Message object that will hold the sensor data.
tkstreet 23:50c98b286e41 97 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 98 */
masahikofukasawa 0:7a00359e701e 99 virtual AkmSensor::Status readSensorData(Message* msg);
tkstreet 23:50c98b286e41 100
tkstreet 23:50c98b286e41 101 /**
tkstreet 23:50c98b286e41 102 * Primary process for interfacing a sensor with the AKDP. When implemented
tkstreet 23:50c98b286e41 103 * in sensor class, it will transfer commands between the the sensor control
tkstreet 23:50c98b286e41 104 * class and AkmSensorManager.
tkstreet 23:50c98b286e41 105 *
tkstreet 23:50c98b286e41 106 * @param in Command message to be processed by sensor.
tkstreet 23:50c98b286e41 107 * @param out Message returned from sensor.
tkstreet 23:50c98b286e41 108 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 109 */
masahikofukasawa 0:7a00359e701e 110 virtual Status requestCommand(Message* in, Message* out);
tkstreet 23:50c98b286e41 111
tkstreet 23:50c98b286e41 112 /**
tkstreet 23:50c98b286e41 113 * Get the name of the sensor in char format.
tkstreet 23:50c98b286e41 114 *
tkstreet 23:50c98b286e41 115 * @return Sensor name as a char array.
tkstreet 23:50c98b286e41 116 */
masahikofukasawa 13:d008249f0359 117 virtual char* getSensorName();
masahikofukasawa 0:7a00359e701e 118
tkstreet 23:50c98b286e41 119 /**
tkstreet 23:50c98b286e41 120 * Checks if data is ready or if there is a data overrun and store the
tkstreet 23:50c98b286e41 121 * status in 'event'.
tkstreet 23:50c98b286e41 122 */
masahikofukasawa 0:7a00359e701e 123 void checkDRDY();
tkstreet 23:50c98b286e41 124 /**
tkstreet 23:50c98b286e41 125 * Forces a data ready state by setting 'event' to TRUE.
tkstreet 23:50c98b286e41 126 */
masahikofukasawa 0:7a00359e701e 127 void detectDRDY();
tkstreet 23:50c98b286e41 128 /**
tkstreet 23:50c98b286e41 129 * For AK8963, returns the type of sensor.
tkstreet 23:50c98b286e41 130 */
masahikofukasawa 0:7a00359e701e 131 int getSensorType();
masahikofukasawa 19:8dcc4f323bdc 132 InterruptMode getInterrupt(uint8_t primaryId, uint8_t subId);
masahikofukasawa 20:2fca76521680 133 AkmSensor::Status checkSensor( const uint8_t primaryid, const uint8_t subid, AkmECompass::DeviceId* devid);
masahikofukasawa 19:8dcc4f323bdc 134
masahikofukasawa 0:7a00359e701e 135 private:
masahikofukasawa 0:7a00359e701e 136 bool event;
masahikofukasawa 0:7a00359e701e 137 uint8_t primaryId;
masahikofukasawa 0:7a00359e701e 138 uint8_t subId;
masahikofukasawa 13:d008249f0359 139 char* sensorName;
masahikofukasawa 0:7a00359e701e 140
masahikofukasawa 0:7a00359e701e 141 Ticker ticker;
masahikofukasawa 0:7a00359e701e 142 AkmECompass* compass;
masahikofukasawa 0:7a00359e701e 143 InterruptIn* drdy;
masahikofukasawa 9:6fa3e7b17c27 144 AkmECompass::OperationMode mode;
masahikofukasawa 9:6fa3e7b17c27 145 AkmECompass::Nsf nsf;
masahikofukasawa 19:8dcc4f323bdc 146 AkmECompass::Sdr sdr;
masahikofukasawa 0:7a00359e701e 147 };
masahikofukasawa 0:7a00359e701e 148
masahikofukasawa 0:7a00359e701e 149 #endif