Modified for compatibility with Rev.E. hardware

Fork of AkmSensor by AKM Development Platform

Committer:
masahikofukasawa
Date:
Wed Jul 19 23:30:22 2017 +0000
Revision:
40:42e48427e4b7
Parent:
37:c76d2edf3426
Child:
41:a3ea80c594ec
Changed I2C speed:100kHz --> 400kHz, Serial baud-rate: 115200bps --> 460800bps for faster sampling.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masahikofukasawa 0:7a00359e701e 1 #ifndef AKMSENSOR_H
masahikofukasawa 0:7a00359e701e 2 #define AKMSENSOR_H
masahikofukasawa 0:7a00359e701e 3
masahikofukasawa 0:7a00359e701e 4 #include "mbed.h"
masahikofukasawa 0:7a00359e701e 5 #include "Message.h"
masahikofukasawa 29:b488d2c89fba 6 //#include "debug.h"
masahikofukasawa 0:7a00359e701e 7
tkstreet 23:50c98b286e41 8 // SPI Pin Number Definitions
tkstreet 23:50c98b286e41 9 #define SPI_SCK P0_8 // SPI, SCK
tkstreet 23:50c98b286e41 10 #define SPI_MISO P0_9 // SPI, MISO
masahikofukasawa 0:7a00359e701e 11 #define SPI_MOSI P0_10 //SPI, MOSI
masahikofukasawa 4:af13b985c689 12 #define SPI_CS P0_11 //SPI, CS
masahikofukasawa 7:e269411568c9 13 #define SPI_DRDY P0_7 //SPI, DRDY
masahikofukasawa 0:7a00359e701e 14
tkstreet 23:50c98b286e41 15 // I2C Pin Number Definitions
masahikofukasawa 0:7a00359e701e 16 #define I2C_SCL P0_8 //I2C, SCL
masahikofukasawa 0:7a00359e701e 17 #define I2C_SDA P0_10 //I2C, SDA
masahikofukasawa 40:42e48427e4b7 18 #define I2C_DRDY P0_11
masahikofukasawa 40:42e48427e4b7 19 #define I2C_SPEED 100000
masahikofukasawa 0:7a00359e701e 20
tkstreet 23:50c98b286e41 21 // Digital Port Pin Number Definitions
masahikofukasawa 0:7a00359e701e 22 #define DIGITAL_D0 P0_11
masahikofukasawa 0:7a00359e701e 23 #define DIGITAL_D1 P0_9
masahikofukasawa 0:7a00359e701e 24
tkstreet 23:50c98b286e41 25 // DRDY Port Pin Number Definitions
masahikofukasawa 0:7a00359e701e 26
tkstreet 23:50c98b286e41 27 // Analog In Pin Number Definitions
masahikofukasawa 0:7a00359e701e 28 #define ANALOG_IN_PIN P0_5 //P05
masahikofukasawa 0:7a00359e701e 29
tkstreet 23:50c98b286e41 30 // Sampling rate for ADC
masahikofukasawa 11:cef8dc1cf010 31 #define SENSOR_SAMPLING_RATE 0.1 // 10Hz
masahikofukasawa 0:7a00359e701e 32
tkstreet 22:f44f1018081e 33 /**
tkstreet 22:f44f1018081e 34 * Abstract base class for general AKM sensors.
tkstreet 22:f44f1018081e 35 */
masahikofukasawa 0:7a00359e701e 36 class AkmSensor
masahikofukasawa 0:7a00359e701e 37 {
masahikofukasawa 0:7a00359e701e 38
masahikofukasawa 0:7a00359e701e 39 public:
tkstreet 23:50c98b286e41 40 /**
tkstreet 23:50c98b286e41 41 * Error type for debugging purposes.
tkstreet 23:50c98b286e41 42 */
masahikofukasawa 0:7a00359e701e 43 typedef enum {
tkstreet 34:1ea3357c8d9a 44
tkstreet 23:50c98b286e41 45 SUCCESS = 0, /**< Successful termination (0) */
tkstreet 23:50c98b286e41 46 ERROR, /**< Error during execution (1) */
masahikofukasawa 0:7a00359e701e 47 } Status;
masahikofukasawa 0:7a00359e701e 48
tkstreet 23:50c98b286e41 49 /**
tkstreet 23:50c98b286e41 50 * Primary IDs for the major categories of sensors.
tkstreet 23:50c98b286e41 51 */
masahikofukasawa 0:7a00359e701e 52 typedef enum {
tkstreet 23:50c98b286e41 53 AKM_PRIMARY_ID_AKD_SPI = 0x0, /**< AKD SPI Devices */
tkstreet 23:50c98b286e41 54 AKM_PRIMARY_ID_UNIPOLAR = 0x1, /**< Unipolar Switches */
tkstreet 23:50c98b286e41 55 AKM_PRIMARY_ID_OMNIPOLAR = 0x2, /**< Omnipolar Switches */
tkstreet 23:50c98b286e41 56 AKM_PRIMARY_ID_LATCH = 0x3, /**< Bipolar Latches */
tkstreet 23:50c98b286e41 57 AKM_PRIMARY_ID_DUAL_OUTPUT = 0x4, /**< Dual Output Switches */
tkstreet 23:50c98b286e41 58 AKM_PRIMARY_ID_ONECHIP_ENCODER = 0x5, /**< One-Chip Encoders */
tkstreet 23:50c98b286e41 59 AKM_PRIMARY_ID_TBD1 = 0x6, /**< Undefined */
masahikofukasawa 37:c76d2edf3426 60 AKM_PRIMARY_ID_CURRENT_SENSOR_3V = 0x7, /**< Current Sensor 3V Output */
tkstreet 34:1ea3357c8d9a 61 AKM_PRIMARY_ID_DEMO = 0x8, /**< Demo Sensors */
masahikofukasawa 37:c76d2edf3426 62 AKM_PRIMARY_ID_CURRENT_SENSOR_5V = 0x9, /**< Current Sensors 5V Output */
tkstreet 23:50c98b286e41 63 AKM_PRIMARY_ID_MISC_ANALOG = 0xA, /**< Analog Devices */
tkstreet 23:50c98b286e41 64 AKM_PRIMARY_ID_LINEAR_SENSOR = 0xB, /**< Linear Sensors */
tkstreet 23:50c98b286e41 65 AKM_PRIMARY_ID_MOTOR_DRIVER = 0xC, /**< Motor Drivers */
tkstreet 23:50c98b286e41 66 AKM_PRIMARY_ID_IR_SENSOR = 0xD, /**< IR Sensors */
tkstreet 23:50c98b286e41 67 AKM_PRIMARY_ID_ANGLE_SENSOR = 0xE, /**< Angle Sensors */
tkstreet 23:50c98b286e41 68 AKM_PRIMARY_ID_AKD_I2C = 0xF, /**< AKD I2C Devices */
masahikofukasawa 0:7a00359e701e 69 } SensorPrimaryId;
masahikofukasawa 0:7a00359e701e 70
tkstreet 34:1ea3357c8d9a 71
masahikofukasawa 27:41aa9fb23a2f 72 virtual ~AkmSensor(){};
tkstreet 23:50c98b286e41 73
tkstreet 23:50c98b286e41 74 /**
tkstreet 23:50c98b286e41 75 * Process for intializing the selected sensor.
tkstreet 23:50c98b286e41 76 *
tkstreet 23:50c98b286e41 77 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 78 */
masahikofukasawa 0:7a00359e701e 79 virtual Status init(const uint8_t id, const uint8_t subid) = 0;
tkstreet 23:50c98b286e41 80
tkstreet 23:50c98b286e41 81 /**
tkstreet 23:50c98b286e41 82 * Process abstraction for starting sensor operation.
tkstreet 23:50c98b286e41 83 *
tkstreet 23:50c98b286e41 84 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 85 */
masahikofukasawa 0:7a00359e701e 86 virtual Status startSensor() = 0;
tkstreet 23:50c98b286e41 87
tkstreet 23:50c98b286e41 88 /**
tkstreet 23:50c98b286e41 89 * Process abstraction for starting sensor operation.
tkstreet 23:50c98b286e41 90 *
tkstreet 23:50c98b286e41 91 * @param sec Number of seconds of operation.
tkstreet 23:50c98b286e41 92 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 93 */
masahikofukasawa 0:7a00359e701e 94 virtual Status startSensor(const float sec) = 0;
tkstreet 23:50c98b286e41 95
tkstreet 23:50c98b286e41 96 /**
tkstreet 23:50c98b286e41 97 * Process abstraction for stopping sensor operation.
tkstreet 23:50c98b286e41 98 *
tkstreet 23:50c98b286e41 99 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 100 */
masahikofukasawa 0:7a00359e701e 101 virtual Status stopSensor() = 0;
tkstreet 23:50c98b286e41 102
tkstreet 23:50c98b286e41 103 /**
tkstreet 23:50c98b286e41 104 * Process abstraction for reading data from the sensor.
tkstreet 23:50c98b286e41 105 *
tkstreet 23:50c98b286e41 106 * @param msg Message object that will hold the sensor data.
tkstreet 23:50c98b286e41 107 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 108 */
masahikofukasawa 0:7a00359e701e 109 virtual Status readSensorData(Message* msg) = 0;
tkstreet 23:50c98b286e41 110
tkstreet 23:50c98b286e41 111 /**
tkstreet 23:50c98b286e41 112 * Primary process for interfacing a sensor with the AKDP. When implemented
tkstreet 23:50c98b286e41 113 * in sensor class, it will transfer commands between the the sensor control
tkstreet 23:50c98b286e41 114 * class and AkmSensorManager.
tkstreet 23:50c98b286e41 115 *
tkstreet 23:50c98b286e41 116 * @param in Command message to be processed by sensor.
tkstreet 23:50c98b286e41 117 * @param out Message returned from sensor.
tkstreet 23:50c98b286e41 118 * @return Termination status type for debugging purposes.
tkstreet 23:50c98b286e41 119 */
masahikofukasawa 0:7a00359e701e 120 virtual Status requestCommand(Message* in, Message* out) = 0;
tkstreet 23:50c98b286e41 121
tkstreet 23:50c98b286e41 122 /**
tkstreet 34:1ea3357c8d9a 123 * Set event flag.
tkstreet 34:1ea3357c8d9a 124 */
masahikofukasawa 29:b488d2c89fba 125 virtual void setEvent(){
masahikofukasawa 29:b488d2c89fba 126 // MSG("#setEvent called.\r\n");
masahikofukasawa 29:b488d2c89fba 127 event = true;
masahikofukasawa 29:b488d2c89fba 128 }
masahikofukasawa 29:b488d2c89fba 129
tkstreet 34:1ea3357c8d9a 130 /**
tkstreet 34:1ea3357c8d9a 131 * Clear event flag.
tkstreet 34:1ea3357c8d9a 132 */
masahikofukasawa 29:b488d2c89fba 133 void clearEvent(){
masahikofukasawa 29:b488d2c89fba 134 // MSG("#clearEvent called.\r\n");
masahikofukasawa 29:b488d2c89fba 135 event = false;
masahikofukasawa 29:b488d2c89fba 136 }
masahikofukasawa 29:b488d2c89fba 137
tkstreet 34:1ea3357c8d9a 138 /**
tkstreet 34:1ea3357c8d9a 139 * Checks if an event has occurred.
tkstreet 23:50c98b286e41 140 *
tkstreet 34:1ea3357c8d9a 141 * @return TRUE if event has occurred, FALSE otherwise.
tkstreet 34:1ea3357c8d9a 142 */
masahikofukasawa 27:41aa9fb23a2f 143 bool isEvent(){
masahikofukasawa 27:41aa9fb23a2f 144 return event;
masahikofukasawa 27:41aa9fb23a2f 145 }
masahikofukasawa 27:41aa9fb23a2f 146
tkstreet 34:1ea3357c8d9a 147 /**
tkstreet 34:1ea3357c8d9a 148 * Retrieve the name of the sensor.
tkstreet 34:1ea3357c8d9a 149 *
tkstreet 34:1ea3357c8d9a 150 * @return Name of sensor as a character array.
tkstreet 23:50c98b286e41 151 */
masahikofukasawa 27:41aa9fb23a2f 152 char* getSensorName(){
masahikofukasawa 27:41aa9fb23a2f 153 return sensorName;
masahikofukasawa 27:41aa9fb23a2f 154 };
masahikofukasawa 27:41aa9fb23a2f 155
tkstreet 34:1ea3357c8d9a 156 /**
tkstreet 34:1ea3357c8d9a 157 * Retrieve the primary ID of the sensor.
tkstreet 34:1ea3357c8d9a 158 *
tkstreet 34:1ea3357c8d9a 159 * @return Primary ID as an integer.
tkstreet 34:1ea3357c8d9a 160 */
masahikofukasawa 27:41aa9fb23a2f 161 int getPrimaryId(){
masahikofukasawa 27:41aa9fb23a2f 162 return primaryId;
masahikofukasawa 27:41aa9fb23a2f 163 };
masahikofukasawa 27:41aa9fb23a2f 164
tkstreet 34:1ea3357c8d9a 165 /**
tkstreet 34:1ea3357c8d9a 166 * Retrieve the Sub-ID of the sensor.
tkstreet 34:1ea3357c8d9a 167 *
tkstreet 34:1ea3357c8d9a 168 * @return Sub-ID as an integer.
tkstreet 34:1ea3357c8d9a 169 */
masahikofukasawa 27:41aa9fb23a2f 170 int getSecondaryId(){
masahikofukasawa 27:41aa9fb23a2f 171 return subId;
masahikofukasawa 27:41aa9fb23a2f 172 };
masahikofukasawa 0:7a00359e701e 173
masahikofukasawa 0:7a00359e701e 174 private:
masahikofukasawa 29:b488d2c89fba 175 bool event;
masahikofukasawa 0:7a00359e701e 176
masahikofukasawa 27:41aa9fb23a2f 177 protected:
masahikofukasawa 27:41aa9fb23a2f 178 uint8_t primaryId;
masahikofukasawa 27:41aa9fb23a2f 179 uint8_t subId;
masahikofukasawa 27:41aa9fb23a2f 180 char* sensorName;
masahikofukasawa 27:41aa9fb23a2f 181
masahikofukasawa 27:41aa9fb23a2f 182 AkmSensor(){
masahikofukasawa 27:41aa9fb23a2f 183 event = false;
masahikofukasawa 27:41aa9fb23a2f 184 primaryId = 0;
masahikofukasawa 27:41aa9fb23a2f 185 subId = 0;
masahikofukasawa 27:41aa9fb23a2f 186 sensorName = "";
masahikofukasawa 27:41aa9fb23a2f 187 };
masahikofukasawa 0:7a00359e701e 188 };
masahikofukasawa 0:7a00359e701e 189
masahikofukasawa 0:7a00359e701e 190 #endif