Gaëtan Andrieu / AS5048
Revision:
0:3edcf58e51e7
Child:
2:2958500883e0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/as5048spi.h	Thu Sep 18 10:20:22 2014 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+typedef enum {
+    AS_FLAG_PARITY = 0x8000,
+    AS_FLAG_READ = 0x4000,
+} As5048Flag;
+
+typedef enum {
+    AS_CMD_NOP = 0x0000,
+    AS_CMD_ERROR = 0x0001 | AS_FLAG_READ, // Reads error ireguster and clear error flags
+    AS_CMD_DIAGNOSTICS = 0x3FFD |  AS_FLAG_READ, // Reads automatic gain control and diagnostics info
+    AS_CMD_MAGNITUDE = 0x3FFE | AS_FLAG_READ,
+    
+    AS_CMD_ANGLE = 0x3FFF| AS_FLAG_PARITY | AS_FLAG_READ,
+} As5048Command;
+
+
+
+class As5048Spi
+{
+public:
+    As5048Spi(PinName mosi, PinName miso, PinName sclk, PinName chipselect, int nDevices = 1);
+    ~As5048Spi();
+    
+    bool error(int device = -1);
+    void frequency(int frequency = 1000000);
+    const int* read(As5048Command command);
+    const int* read_sequential(As5048Command command);
+    
+    const int* read_angle();
+    const int* read_angle_sequential();
+
+    
+    static int mask(int sensor_result);
+   
+    static bool parity_check(int sensor_result);
+    static int degrees(int sensor_result);
+    static int radian(int sensor_result);
+    
+
+protected:
+    int _nDevices;
+    DigitalOut _chipSelectN;
+    SPI _spi;
+    
+    int* _readBuffer; // Stores the results of the last sequential read
+    
+    int* _read(As5048Command command);
+};
+    
\ No newline at end of file