This is a class which contains function to interface with the MLX75320
Diff: LidarSpi.h
- Revision:
- 13:ccf4ab73c33d
- Parent:
- 12:d1767e2bd3a8
diff -r d1767e2bd3a8 -r ccf4ab73c33d LidarSpi.h --- a/LidarSpi.h Fri Apr 29 13:39:19 2016 +0000 +++ b/LidarSpi.h Tue May 17 18:54:04 2016 +0000 @@ -5,7 +5,10 @@ #include "typeDef.h" #include "FunctionPointer.h" - +/** LidarSpi class + * This class defines methods and structs to interface with the MLX75320 lidar sensing product + * + */ class LidarSpi { @@ -36,6 +39,8 @@ // Used on header ADDR field to request all channels and as idx argument of GetTrace function static const uint16_t ADDR_ALLCH= 0x1F; + + // Structure for the processed data returned by the sensor struct Echo { uint32_t mDistance; @@ -121,6 +126,7 @@ REG_MAX = 0xFFFF // Number of registers } eASICREG; + //Internal type used by low level functions: SPI packet type enum PackType { PACK_RREG = 0, ///< Read register request @@ -133,7 +139,7 @@ PACK_RDATA_RESP_L, ///< Read data response long PACK_WDATA_L, ///< Write data long }; - + //Internal type used by low level functions: SPI status status type enum StatusType { STAT_OK = 0, @@ -143,7 +149,7 @@ STAT_SEQ_NB, STAT_TIMEOUT, }; - + //Internal type used by low level functions: SPI firmware packet type enum FirmType { FW_OTP = 0, @@ -155,32 +161,133 @@ }; + +/*===================================================================================================================================== +//===================================================================================================================================== + _____ _ _ _ __ _ _ + | __ \ | | | (_) / _| | | (_) + | |__) | _| |__ | |_ ___ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___ + | ___/ | | | '_ \| | |/ __| | _| | | | '_ \ / __| __| |/ _ \| '_ \/ __| + | | | |_| | |_) | | | (__ | | | |_| | | | | (__| |_| | (_) | | | \__ \ + |_| \__,_|_.__/|_|_|\___| |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ + +//===================================================================================================================================== +//====================================================================================================================================*/ + + + /** Constructor + * @param: pin names for mosi, miso, clk, chipselect, dataready, reset, trigger and sample*/ LidarSpi(PinName mosi, PinName miso, PinName clk, PinName chipSelect, PinName dr, PinName rs, PinName tr, PinName smpl); + + /** SpiSetting + * Change frequency and SPI mode(clock phase and polarity) + * @param: frequency in Hz, mode ranging from 0 to 3, pointer to Serial interface for debugging + * @return: 0 on success */ int SpiSetting(long freq, int mode, Serial* pc); + + /** ReadReg + * Read register at address + * @param: register address, pointer to variable to register valueresult + * @return: 0 on success */ + int ReadReg ( uint32_t reg, uint32_t *val); + + /** WriteReg + * Write register to address + * @param: register address, value to write + * @return: 0 on success */ + int WriteReg ( uint32_t reg, uint32_t val); + + + /** GetEchoes + * Perform measurement and read processed data + * @param: pointer to Echo structure array to store measurement, structure array size (must be >=64) + * @return: 0 on success */ + int GetEchoes ( Echo *ech, uint16_t maxN); + + /** GetEchoes + * Perform measurement and read processed data + * @param: pointer to Echo structure array to store measurement, structure array size (must be >=64), pointer to serial interface for debugging + * @return: 0 on success */ + int GetEchoes ( Echo *ech, uint16_t maxN, Serial* pc); + + /** GetTrace + * Perform measurement and read raw trace buffer + * @param: pointer to int array to store trace buffer, structure array size (must be >=9472*2), pointer to serial interface for debugging + * @return: 0 on success */ + int GetTrace ( uint16_t *buf, uint16_t maxN, Serial* pc); + + /** LoadPatch + * Load patch stored on mbed Flash memory in MLX75320 and enable patch + * @param: path of patch.hex location, , pointer to serial interface for debugging + * @return: 0 on success */ + int LoadPatch (const char *patch, Serial *pc); + + /** SetTrace + * Set a variety of registers according to the preset values for a raw data measurement + * @return: 0 on success */ + int setTrace(void); + + /** SetTrace + * Set a variety of registers according to the preset values for a processed data measurement + * @return: 0 on success */ + int setEcho(void); + + /** SetLed + * Set a variety of registers according to the preset values to either fire or don't fire the LEDs during a measurement + * @param: True to enable LEDs, False to disable */ + int setLed(bool state); + + +/*===================================================================================================================================== +//===================================================================================================================================== + _____ _ _ _ _ _ __ _ _ + |_ _| | | | | | | | | (_) / _| | | (_) + | | _ __ | |_ ___ _ __ _ __ __ _| | ___ _ __ __| | ___| |__ _ _ __ _ __ _ _ _ __ __ _ | |_ _ _ _ __ ___| |_ _ ___ _ __ ___ + | | | '_ \| __/ _ \ '__| '_ \ / _` | | / _ \| '__| / _` |/ _ \ '_ \| | | |/ _` |/ _` | | '_ \ / _` | | _| | | | '_ \ / __| __| |/ _ \| '_ \/ __| + _| |_| | | | || __/ | | | | | (_| | | | (_) | | | (_| | __/ |_) | |_| | (_| | (_| | | | | | (_| | | | | |_| | | | | (__| |_| | (_) | | | \__ \ + |_____|_| |_|\__\___|_| |_| |_|\__,_|_| \___/|_| \__,_|\___|_.__/ \__,_|\__, |\__, |_|_| |_|\__, | |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/ + __/ | __/ | __/ | + |___/ |___/ |___/ +//===================================================================================================================================== +//====================================================================================================================================*/ + + + + /** ReadReg (overloaded) + * Read register at address + * @param: register address, pointer to variable to register valueresult, pointer to serial interface for debugging + * @return: 0 on success */ + int ReadReg(uint32_t reg, uint32_t *val, Serial* pc); + + /** WriteReg + * Write register to address + * @param: register address, value to write, pointer to serial interface for debugging + * @return: 0 on success */ + int WriteReg ( uint32_t reg, uint32_t val, Serial* pc); + + /** GetTraceOne + * Perform measurement and read raw trace buffer, this method only reads back a single SPI packet + * @param: pointer to int array to store trace buffer, structure array size (must be >=9472*2), pointer to serial interface for debugging + * @return: 0 on success */ + int GetTraceOne ( uint16_t *buf, uint16_t maxN, uint16_t nSam, uint16_t idx,int index , Serial* pc); + + /** Trigger + * Change pin to high or low to use as trigger point for oscilloscope + * @param: 1 or 0 to set voltage level */ + void Trigger(int level); + + + int PrintAllReg (uint16_t * regs, uint32_t * val, uint16_t size); + int TxPacket(uint8_t* rData, uint16_t *rSz, uint8_t *tData, uint16_t tSz); int TxPacketWord(uint8_t* rData, uint16_t *rSz, uint8_t *tData, uint16_t tSz); int TxPacket(uint8_t* rData, uint16_t *rSz, uint8_t *tData, uint16_t tSz, Serial* pc); int TxPacketSlow(uint8_t* rData, uint16_t *rSz, uint8_t *tData, uint16_t tSz, uint16_t usDelay); int BasicRead(); int BasicTransfer(uint8_t* rData, uint16_t rSz, uint8_t *wData, uint16_t wSz, const event_callback_t callback); - - int ReadReg ( uint32_t reg, uint32_t *val); - int ReadReg(uint32_t reg, uint32_t *val, Serial* pc); - int WriteReg ( uint32_t reg, uint32_t val); int WriteRegSpeed ( uint32_t reg, uint32_t val, uint16_t usDelay); - int WriteReg ( uint32_t reg, uint32_t val, Serial* pc); int WriteRegSpeed ( uint32_t reg, uint32_t val, uint16_t usDelay, Serial* pc); - //int GetRegNfo ( uint16_t reg, const RegInfo **nfo); - int GetEchoes ( Echo *ech, uint16_t maxN, uint16_t mode); - int GetEchoes ( Echo *ech, uint16_t maxN, uint16_t mode, Serial* pc); - int GetTrace ( uint16_t *buf, uint16_t maxN, uint16_t nSam, uint16_t idx, Serial* pc); - int GetTraceOne ( uint16_t *buf, uint16_t maxN, uint16_t nSam, uint16_t idx,int index , Serial* pc); - int LoadPatch (const char *patch, Serial *pc); - int setTrace(void); - int setEcho(void); - int PrintAllReg (uint16_t * regs, uint32_t * val, uint16_t size); - int setLed(bool state); - void Trigger(int level); + //int SetConfig ( int configNum); //int SetAcqCfg ( uint16_t set, uint16_t led, uint16_t accLog, uint16_t ovrLog); //int Acquire ( uchar ab, uchar evGain, uchar evCh, uchar odGain, uchar odCh);