Alexandre Pirotte
/
AS5048
cc
Fork of AS5048 by
as5048spi.h@0:3edcf58e51e7, 2014-09-18 (annotated)
- Committer:
- JSpikker
- Date:
- Thu Sep 18 10:20:22 2014 +0000
- Revision:
- 0:3edcf58e51e7
- Child:
- 2:2958500883e0
Version 0.3: reads single sensor value, 10000 samples speed test at 10MHz SPI, writes data to local storage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JSpikker | 0:3edcf58e51e7 | 1 | #include "mbed.h" |
JSpikker | 0:3edcf58e51e7 | 2 | typedef enum { |
JSpikker | 0:3edcf58e51e7 | 3 | AS_FLAG_PARITY = 0x8000, |
JSpikker | 0:3edcf58e51e7 | 4 | AS_FLAG_READ = 0x4000, |
JSpikker | 0:3edcf58e51e7 | 5 | } As5048Flag; |
JSpikker | 0:3edcf58e51e7 | 6 | |
JSpikker | 0:3edcf58e51e7 | 7 | typedef enum { |
JSpikker | 0:3edcf58e51e7 | 8 | AS_CMD_NOP = 0x0000, |
JSpikker | 0:3edcf58e51e7 | 9 | AS_CMD_ERROR = 0x0001 | AS_FLAG_READ, // Reads error ireguster and clear error flags |
JSpikker | 0:3edcf58e51e7 | 10 | AS_CMD_DIAGNOSTICS = 0x3FFD | AS_FLAG_READ, // Reads automatic gain control and diagnostics info |
JSpikker | 0:3edcf58e51e7 | 11 | AS_CMD_MAGNITUDE = 0x3FFE | AS_FLAG_READ, |
JSpikker | 0:3edcf58e51e7 | 12 | |
JSpikker | 0:3edcf58e51e7 | 13 | AS_CMD_ANGLE = 0x3FFF| AS_FLAG_PARITY | AS_FLAG_READ, |
JSpikker | 0:3edcf58e51e7 | 14 | } As5048Command; |
JSpikker | 0:3edcf58e51e7 | 15 | |
JSpikker | 0:3edcf58e51e7 | 16 | |
JSpikker | 0:3edcf58e51e7 | 17 | |
JSpikker | 0:3edcf58e51e7 | 18 | class As5048Spi |
JSpikker | 0:3edcf58e51e7 | 19 | { |
JSpikker | 0:3edcf58e51e7 | 20 | public: |
JSpikker | 0:3edcf58e51e7 | 21 | As5048Spi(PinName mosi, PinName miso, PinName sclk, PinName chipselect, int nDevices = 1); |
JSpikker | 0:3edcf58e51e7 | 22 | ~As5048Spi(); |
JSpikker | 0:3edcf58e51e7 | 23 | |
JSpikker | 0:3edcf58e51e7 | 24 | bool error(int device = -1); |
JSpikker | 0:3edcf58e51e7 | 25 | void frequency(int frequency = 1000000); |
JSpikker | 0:3edcf58e51e7 | 26 | const int* read(As5048Command command); |
JSpikker | 0:3edcf58e51e7 | 27 | const int* read_sequential(As5048Command command); |
JSpikker | 0:3edcf58e51e7 | 28 | |
JSpikker | 0:3edcf58e51e7 | 29 | const int* read_angle(); |
JSpikker | 0:3edcf58e51e7 | 30 | const int* read_angle_sequential(); |
JSpikker | 0:3edcf58e51e7 | 31 | |
JSpikker | 0:3edcf58e51e7 | 32 | |
JSpikker | 0:3edcf58e51e7 | 33 | static int mask(int sensor_result); |
JSpikker | 0:3edcf58e51e7 | 34 | |
JSpikker | 0:3edcf58e51e7 | 35 | static bool parity_check(int sensor_result); |
JSpikker | 0:3edcf58e51e7 | 36 | static int degrees(int sensor_result); |
JSpikker | 0:3edcf58e51e7 | 37 | static int radian(int sensor_result); |
JSpikker | 0:3edcf58e51e7 | 38 | |
JSpikker | 0:3edcf58e51e7 | 39 | |
JSpikker | 0:3edcf58e51e7 | 40 | protected: |
JSpikker | 0:3edcf58e51e7 | 41 | int _nDevices; |
JSpikker | 0:3edcf58e51e7 | 42 | DigitalOut _chipSelectN; |
JSpikker | 0:3edcf58e51e7 | 43 | SPI _spi; |
JSpikker | 0:3edcf58e51e7 | 44 | |
JSpikker | 0:3edcf58e51e7 | 45 | int* _readBuffer; // Stores the results of the last sequential read |
JSpikker | 0:3edcf58e51e7 | 46 | |
JSpikker | 0:3edcf58e51e7 | 47 | int* _read(As5048Command command); |
JSpikker | 0:3edcf58e51e7 | 48 | }; |
JSpikker | 0:3edcf58e51e7 | 49 |