I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later

Dependencies:   BufferedSerial FatFileSystemCpp mbed

Committer:
AndyA
Date:
Fri Jan 15 11:49:01 2021 +0000
Revision:
0:97661408d0f9
Child:
7:87aea27cc68b
first;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndyA 0:97661408d0f9 1 #ifndef __LTCDECODE_H__
AndyA 0:97661408d0f9 2 #define __LTCDECODE_H__
AndyA 0:97661408d0f9 3
AndyA 0:97661408d0f9 4 #include "mbed.h"
AndyA 0:97661408d0f9 5
AndyA 0:97661408d0f9 6 const uint32_t minBitPeriodUS =
AndyA 0:97661408d0f9 7 (uint32_t)((1000000.0f / 2400) / 1.1f); // allow for 10% time error
AndyA 0:97661408d0f9 8 const uint32_t maxMidSymbolTimeUS = (uint32_t)(
AndyA 0:97661408d0f9 9 ((1000000.0f / (1920 * 2))) * 1.1f); // allow for 10% time error
AndyA 0:97661408d0f9 10
AndyA 0:97661408d0f9 11 class LTCDecode {
AndyA 0:97661408d0f9 12
AndyA 0:97661408d0f9 13 public:
AndyA 0:97661408d0f9 14 LTCDecode(const PinName pin);
AndyA 0:97661408d0f9 15 void setInputTimer(Timer *inputTimer);
AndyA 0:97661408d0f9 16
AndyA 0:97661408d0f9 17 bool synced() { return LTCsynced; };
AndyA 0:97661408d0f9 18
AndyA 0:97661408d0f9 19 // reads pending data up to a sync marker, returns true is sync is found.
AndyA 0:97661408d0f9 20 bool searchForSync();
AndyA 0:97661408d0f9 21
AndyA 0:97661408d0f9 22 // reads pending data up to the end of the frame, returns true at the end of a
AndyA 0:97661408d0f9 23 // frame. check sync stats and lastFrameData for results.
AndyA 0:97661408d0f9 24 bool readWaitingData();
AndyA 0:97661408d0f9 25
AndyA 0:97661408d0f9 26 typedef struct {
AndyA 0:97661408d0f9 27 int hours;
AndyA 0:97661408d0f9 28 int minutes;
AndyA 0:97661408d0f9 29 int seconds;
AndyA 0:97661408d0f9 30 int frame;
AndyA 0:97661408d0f9 31 bool frameDrop;
AndyA 0:97661408d0f9 32 uint32_t frameStartTime;
AndyA 0:97661408d0f9 33 } LTCData_t;
AndyA 0:97661408d0f9 34
AndyA 0:97661408d0f9 35 const LTCData_t *getLastFrame() { return &lastFrame; };
AndyA 0:97661408d0f9 36
AndyA 0:97661408d0f9 37 // buffer holding received LTC bits and their start times.
AndyA 0:97661408d0f9 38
AndyA 0:97661408d0f9 39 private:
AndyA 0:97661408d0f9 40 void LTCOnEdge(void);
AndyA 0:97661408d0f9 41
AndyA 0:97661408d0f9 42 InterruptIn _LTCIn;
AndyA 0:97661408d0f9 43 Timer *_inputTimer;
AndyA 0:97661408d0f9 44
AndyA 0:97661408d0f9 45 LTCData_t lastFrame;
AndyA 0:97661408d0f9 46
AndyA 0:97661408d0f9 47 static const int _newBitBufferSize_ = 80;
AndyA 0:97661408d0f9 48
AndyA 0:97661408d0f9 49 bool newBitBuffer[_newBitBufferSize_];
AndyA 0:97661408d0f9 50 uint32_t bitTimes[_newBitBufferSize_];
AndyA 0:97661408d0f9 51
AndyA 0:97661408d0f9 52 bool LTCsynced;
AndyA 0:97661408d0f9 53
AndyA 0:97661408d0f9 54 volatile int newBitsWrite;
AndyA 0:97661408d0f9 55 int newBitsRead;
AndyA 0:97661408d0f9 56
AndyA 0:97661408d0f9 57 // max bit period = 520.8 ms (1920 Hz)
AndyA 0:97661408d0f9 58 // min bit period = 416.7 ms (2400 Hz)
AndyA 0:97661408d0f9 59 // max period of a '1' symbol = 260.4ms (1920Hz * 2)
AndyA 0:97661408d0f9 60
AndyA 0:97661408d0f9 61 uint32_t lastTransition;
AndyA 0:97661408d0f9 62 uint32_t lastBitStart;
AndyA 0:97661408d0f9 63
AndyA 0:97661408d0f9 64 uint32_t LTCBuffer[3];
AndyA 0:97661408d0f9 65 uint32_t firstMark;
AndyA 0:97661408d0f9 66 int markCount;
AndyA 0:97661408d0f9 67 uint32_t nextSecondStart;
AndyA 0:97661408d0f9 68 uint32_t PPSWidth;
AndyA 0:97661408d0f9 69 int bitCounter ;
AndyA 0:97661408d0f9 70 int dwordCounter ;
AndyA 0:97661408d0f9 71
AndyA 0:97661408d0f9 72 uint32_t timeOfBit, frameStartTime;
AndyA 0:97661408d0f9 73 };
AndyA 0:97661408d0f9 74
AndyA 0:97661408d0f9 75 #endif