MBED driver for Max1471.

MAX1471.h

Committer:
Abdullah.Turan@IST-LT-37344.maxim-ic.internal
Date:
10 months ago
Revision:
0:99e9397112f0

File content as of revision 0:99e9397112f0:

/*
 * MAX1471.h
 *
 *  Created on: Dec 17, 2018
 *      Author: Erman.Komurcu
 */

#ifndef MAX1471_MAX1471_H_
#define MAX1471_MAX1471_H_

#include "mbed.h"
#include "rtos.h"
#include "MAX1471_regs.h"


class MAX1471
{
private:
	max1471_reg_map_t *reg;
	SPI *spi_handler;
	DigitalOut *ssel;
	DigitalOut *bLED;
	DigitalIn *dio;

	int spi_mode;
	int modulation; /*!< Current modulation mode */
	float oscFrequency; /*!< Extern oscillator frequency */


public:

    typedef enum {
        PWR_CFG_ADDR		= 0x00,
        CFG_ADDR       		= 0x01,
        CTRL_ADDR       	= 0x02,
        OSC_FREQ_ADDR       = 0x03,
        OFF_TMR_UP_ADDR 	= 0x04,
        OFF_TMR_DWN_ADDR	= 0x05,
        CPU_REC_ADDR    	= 0x06,
        RF_ST_UP_ADDR   	= 0x07,
        RF_ST_DWN_ADDR  	= 0x08,
        STAT_ADDR       	= 0x09,
        AGC_DWL_TMR_ADDR	= 0x0A,
    } register_address_t;

    typedef enum {
        ASK = 0,
		FSK,
		BOTH
    } modulation_type_t;


	//Constructors

	MAX1471(DigitalOut *cs);


    /* PUBLIC FUNCTION DECLARATIONS */

    /**
    * @brief Read from a register.
    *
    * @param[in] reg Address of a register to be read.
    * @param[out] value Pointer to save result value.
    * @param[in] len Size of result to be read.
    *
    * @returns 0 on success, negative error code on failure.
    */
    int read_register(uint8_t reg, uint8_t *value, uint8_t len);

    /**
    * @brief Write to a register.
    *
    * @param[in] reg Address of a register to be written.
    * @param[out] value Pointer of value to be written to register.
    * @param[in] len Size of result to be written.
    *
    * @returns 0 on success, negative error code on failure.
    */
    int write_register(uint8_t reg, const uint8_t *value, uint8_t len);

    /**
    * @brief Write to a register.
    *
    * @param[in] reg Address of a register to be written.
    * @param[out] value Value to be written to register.
    * @param[in] len Size of result to be written.
    *
    * @returns 0 on success, negative error code on failure.
    */
    int write_register(uint8_t reg, const uint8_t value, uint8_t len);
    /**
    * @brief Set 3-Wire or 4-Wire SPI
    *
    * @param[in] type Type of SPI interface
    * 				  0 -> 3-Wire SPI interface (default)
    * 				  1 -> 4-Wire SPI interface (DOUT_FSK) enabled
    * 				  2 -> 4-Wire SPI interface (DOUT_ASK) enabled
    *
    * @returns 0 on success, negative error code on failure.
    */
    int set_spi_type(uint8_t type);

    /**
    * @brief ASK peak detector management
    *
    * @param[in] enable Requested status of ASK Peak Detector
    *
    * @returns 0 on success, negative error code on failure.
    */
    int ASKPeakDetectorEnable(bool enable);

    /**
    * @brief FSK peak detector management
    *
    * @param[in] enable Requested status of FSK Peak Detector
    *
    * @returns 0 on success, negative error code on failure.
    */
    int FSKPeakDetectorEnable(bool enable);

    /**
      * @brief ASK base band receiver management
      *
      * @param[in] enable Requested status of ASK base band receiver
      *
      * @returns 0 on success, negative error code on failure.
      */
    int ASKBaseBandReceiverEnable(bool enable);

    /**
      * @brief FSK base band receiver management
      *
      * @param[in] enable Requested status of FSK base band receiver
      *
      * @returns 0 on success, negative error code on failure.
      */
    int FSKBaseBandReceiverEnable(bool enable);

    /**
      * @brief RF Mixer on/off management
      *
      * @param[in] enable Requested status of RF mixer
      *
      * @returns 0 on success, negative error code on failure.
      */
    int RFMixerEnable(bool enable);

    /**
      * @brief Automatic gain controller on/off management
      *
      * @param[in] enable Requested status of AGC
      *
      * @returns 0 on success, negative error code on failure.
      */
    int AGCEnable(bool enable);

    /**
      * @brief Low noise amplifier on/off management
      *
      * @param[in] enable Requested status of LNA
      *
      * @returns 0 on success, negative error code on failure.
      */
    int LNAEnable(bool enable);

    /**
      * @brief 4-wire SPI MISO pin assignment to FSK data pin
      *
      * @param[in] enable Requested status of DOUT as FSK data pin
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetFDATAasDOUTPin(bool enable);

    /**
      * @brief 4-wire SPI MISO pin assignment to ASK data pin
      *
      * @param[in] enable Requested status of DOUT as ASK data pin
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetADATAasDOUTPin(bool enable);

    /**
      * @brief Long FSK calibration on/off management
      *
      * @param[in] enable Requested status of longer FSK calibration mode
      *
      * @returns 0 on success, negative error code on failure.
      */
    int LongerFSKCalibrationEnable(bool enable);

    /**
      * @brief Discontinuous receive mode on/off management
      *
      * @param[in] enable Requested status of discontinuous receive mode
      *
      * @returns 0 on success, negative error code on failure.
      */
    int DRXEnable(bool enable);

    /**
      * @brief LNA's low or high gain mode selection
      *
      * @param[in] isHighGain Requested gain mode is high gain or low gain
      *
      * @returns 0 on success, negative error code on failure.
      */
    int LNAGainState(bool isHighGain);

    /**
      * @brief FSK Calibration starter
      *
      * @param[in] enable Start or stop FSK calibration
      *
      * @returns 0 on success, negative error code on failure.
      */
    int FSKCalibrationDone(bool enable);

    /**
      * @brief Get AGC Dwell timer value
      *
      * @param[out] valuePtr Pointer to AGC Dwell timer value
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetAGCDwellTimer( unsigned char *valuePtr );

    /**
       * @brief Set AGC Dwell timer value
       *
       * @param[in] value Desired value of AGC Dwell timer
       *
       * @returns 0 on success, negative error code on failure.
       */
    int SetAGCDwellTimer( unsigned char value );

    /**
      * @brief Poll timer calibration starter
      *
      * @param[in] enable Start or stop poll timer calibration
      *
      * @returns 0 on success, negative error code on failure.
      */
    int PollTimerCalibrationEnable(bool enable);

    /**
      * @brief Track mode for ASK peak detector on/off control
      *
      * @param[in] enable Enable/disable track mode of ASK peak detector
      *
      * @returns 0 on success, negative error code on failure.
      */
    int ASKPeakDetectorTrackEnable(bool enable);

    /**
      * @brief Track mode for FSK peak detector on/off control
      *
      * @param[in] enable Enable/disable track mode of FSK peak detector
      *
      * @returns 0 on success, negative error code on failure.
      */
    int FSKPeakDetectorTrackEnable(bool enable);

    /**
      * @brief Locks AGC's current state
      *
      * @returns 0 on success, negative error code on failure.
      */
    int LockAGCCurrentState();

    /**
      * @brief Gets calibration status of poll timer calibration
      *
      * @param[out] valuePtr Pointer to current status of poll timer calibration
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetPollTimerCalibrationDoneStatus( unsigned char *valuePtr );

    /**
      * @brief Gets calibration status of FSK calibration
      *
      * @param[out] valuePtr Pointer to current status of FSK calibration
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetFSKCalibrationDoneStatus( unsigned char *valuePtr );

    /**
      * @brief Gets clock alive status
      *
      * @param[out] valuePtr Pointer to clock alive status
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetClockAliveStatus( unsigned char *valuePtr );

    /**
      * @brief Gets AGC's current status
      *
      * @param[out] valuePtr Pointer to AGC's current status
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetAGCStatus( unsigned char *valuePtr );

    /**
      * @brief Get whether PLL is locked or not
      *
      * @param[out] valuePtr Pointer to PLL's current status
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetPLLLockStatus( unsigned char *valuePtr );

    /**
      * @brief Get off timer prescale value
      *
      * @param[out] valuePtr Pointer to off timer prescale value
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetOffTimerPrescale( unsigned char *valuePtr );

    /**
      * @brief Set off timer prescale value
      *
      * @param[in] value Desired value of off timer prescale
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetOffTimerPrescale( unsigned char value );

    /**
      * @brief Set rf settle timer value
      *
      * @param[in] value Desired value of off timer rf settle timer
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetRFSettleTimer( unsigned short int value );

    /**
      * @brief Get rf settle timer value
      *
      * @param[out] valuePtr Pointer to rf settle timer value
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetRFSettleTimer( unsigned short int *valuePtr );

    /**
      * @brief Set off timer value
      *
      * @param[in] value Desired value of off timer
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetOFFTimer( unsigned short int value );

    /**
      * @brief Get off timer value
      *
      * @param[out] valuePtr Pointer to off timer value
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetOFFTimer( unsigned short int *valuePtr );

    /**
      * @brief Set CPU recovery timer value
      *
      * @param[in] value Desired value of CPU recovery timer
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetCPURecoveryTimer( unsigned char value );

    /**
      * @brief Get CPU recovery timer value
      *
      * @param[out] valuePtr Pointer to CPU recovery timer value
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetCPURecoveryTimer( unsigned char *valuePtr );

    /**
      * @brief Set RF oscillator frequency
      *
      * @param[in] value Desired frequency
      *
      * @returns 0 on success, negative error code on failure.
      */
    int SetRFOscillatorFreq( float frequency );

    /**
      * @brief Get RF oscillator frequency
      *
      * @param[out] freqPtr Pointer to RF oscillator frequency
      *
      * @returns 0 on success, negative error code on failure.
      */
    int GetRFOscillatorFreq( float *freqPtr );

    /**
    * @brief Reset the chip
    *
    * @returns 0 on success, negative error code on failure.
    */
    int reset();

    /**
    * @brief NOP command
    *
    * @returns 0 on success, negative error code on failure.
    */
    int nop();

    /**
    * @brief Initialize the chip
    *
    * @returns 0 on success, negative error code on failure.
    */
    int InitMAX1471();

    int PrepMAX1471RX();

    int PrepMAX1471RX( modulation_type_t modType );

    int PrepMAX1471RX_DRX();

    /**
      * @brief Prepare MAX1471's sleep mode
      *
      * @param[in] enable Sleep mode enable/disable
      *
      * @returns 0 on success, negative error code on failure.
      */
    int PrepMAX1471Sleep(bool enable);

};
extern const uint32_t pmu_program_sample_data_in[];
extern const uint32_t pmu_program_stop_buff1_filling[];
extern const uint32_t pmu_program_stop_buff0_filling[];
extern const uint32_t pmu_program_start_buff1_filling[];
extern const uint32_t pmu_program_save_current_data_to_buffer0[];
extern const uint32_t pmu_program_save_current_data_to_buffer1[];
extern const uint32_t pmu_program_sample_0[];
extern const uint32_t pmu_program_sample_1[];

#endif /* MAX1471_MAX1471_H_ */