Hugh Shane
/
imu-daq
Read data from an ADIS16355 IMU and write it to the USB port.
imu-spi.h@0:c6ee363ac724, 2011-08-10 (annotated)
- Committer:
- yahugh
- Date:
- Wed Aug 10 21:50:36 2011 +0000
- Revision:
- 0:c6ee363ac724
initial release, still has some problems but might be of interest to others regardless
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yahugh | 0:c6ee363ac724 | 1 | // |
yahugh | 0:c6ee363ac724 | 2 | // imu-spi.h |
yahugh | 0:c6ee363ac724 | 3 | // |
yahugh | 0:c6ee363ac724 | 4 | // copyright 2010 Hugh Shane |
yahugh | 0:c6ee363ac724 | 5 | // |
yahugh | 0:c6ee363ac724 | 6 | |
yahugh | 0:c6ee363ac724 | 7 | class ImuSpi { |
yahugh | 0:c6ee363ac724 | 8 | private: |
yahugh | 0:c6ee363ac724 | 9 | const static int bufferSize = 7; |
yahugh | 0:c6ee363ac724 | 10 | int16_t buffer[2][bufferSize]; // ping-pong IMU data buffer |
yahugh | 0:c6ee363ac724 | 11 | unsigned pingpong; |
yahugh | 0:c6ee363ac724 | 12 | bool dataReady; |
yahugh | 0:c6ee363ac724 | 13 | SPI spi; |
yahugh | 0:c6ee363ac724 | 14 | DigitalOut cs; |
yahugh | 0:c6ee363ac724 | 15 | DigitalOut reset; |
yahugh | 0:c6ee363ac724 | 16 | DigitalOut diag; |
yahugh | 0:c6ee363ac724 | 17 | InterruptIn imuDataReady; |
yahugh | 0:c6ee363ac724 | 18 | void InitImu(void); |
yahugh | 0:c6ee363ac724 | 19 | void DataReadyISR(void); |
yahugh | 0:c6ee363ac724 | 20 | int16_t Read(char); |
yahugh | 0:c6ee363ac724 | 21 | void Write(char, char); |
yahugh | 0:c6ee363ac724 | 22 | void TogglePingpong() {pingpong = (~pingpong) & 1U;}; |
yahugh | 0:c6ee363ac724 | 23 | int16_t* GetBufferWritePtr() {return buffer[pingpong & 1U];}; |
yahugh | 0:c6ee363ac724 | 24 | public: |
yahugh | 0:c6ee363ac724 | 25 | ImuSpi(void); |
yahugh | 0:c6ee363ac724 | 26 | void BurstRead(void); |
yahugh | 0:c6ee363ac724 | 27 | int16_t* GetBufferReadPtr() {return buffer[(~pingpong) & 1U];}; |
yahugh | 0:c6ee363ac724 | 28 | bool IsDataReady(void); |
yahugh | 0:c6ee363ac724 | 29 | int GetBufferSize(void) {return bufferSize*sizeof(int16_t);}; |
yahugh | 0:c6ee363ac724 | 30 | void reinitInterrupts(void); |
yahugh | 0:c6ee363ac724 | 31 | }; |