MBED driver for Max1471.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX1471.h Source File

MAX1471.h

00001 /*
00002  * MAX1471.h
00003  *
00004  *  Created on: Dec 17, 2018
00005  *      Author: Erman.Komurcu
00006  */
00007 
00008 #ifndef MAX1471_MAX1471_H_
00009 #define MAX1471_MAX1471_H_
00010 
00011 #include "mbed.h"
00012 #include "rtos.h"
00013 #include "MAX1471_regs.h"
00014 
00015 
00016 class MAX1471
00017 {
00018 private:
00019     max1471_reg_map_t *reg;
00020     SPI *spi_handler;
00021     DigitalOut *ssel;
00022     DigitalOut *bLED;
00023     DigitalIn *dio;
00024 
00025     int spi_mode;
00026     int modulation; /*!< Current modulation mode */
00027     float oscFrequency; /*!< Extern oscillator frequency */
00028 
00029 
00030 public:
00031 
00032     typedef enum {
00033         PWR_CFG_ADDR        = 0x00,
00034         CFG_ADDR            = 0x01,
00035         CTRL_ADDR           = 0x02,
00036         OSC_FREQ_ADDR       = 0x03,
00037         OFF_TMR_UP_ADDR     = 0x04,
00038         OFF_TMR_DWN_ADDR    = 0x05,
00039         CPU_REC_ADDR        = 0x06,
00040         RF_ST_UP_ADDR       = 0x07,
00041         RF_ST_DWN_ADDR      = 0x08,
00042         STAT_ADDR           = 0x09,
00043         AGC_DWL_TMR_ADDR    = 0x0A,
00044     } register_address_t;
00045 
00046     typedef enum {
00047         ASK = 0,
00048         FSK,
00049         BOTH
00050     } modulation_type_t;
00051 
00052 
00053     //Constructors
00054 
00055     MAX1471(DigitalOut *cs);
00056 
00057 
00058     /* PUBLIC FUNCTION DECLARATIONS */
00059 
00060     /**
00061     * @brief Read from a register.
00062     *
00063     * @param[in] reg Address of a register to be read.
00064     * @param[out] value Pointer to save result value.
00065     * @param[in] len Size of result to be read.
00066     *
00067     * @returns 0 on success, negative error code on failure.
00068     */
00069     int read_register(uint8_t reg, uint8_t *value, uint8_t len);
00070 
00071     /**
00072     * @brief Write to a register.
00073     *
00074     * @param[in] reg Address of a register to be written.
00075     * @param[out] value Pointer of value to be written to register.
00076     * @param[in] len Size of result to be written.
00077     *
00078     * @returns 0 on success, negative error code on failure.
00079     */
00080     int write_register(uint8_t reg, const uint8_t *value, uint8_t len);
00081 
00082     /**
00083     * @brief Write to a register.
00084     *
00085     * @param[in] reg Address of a register to be written.
00086     * @param[out] value Value to be written to register.
00087     * @param[in] len Size of result to be written.
00088     *
00089     * @returns 0 on success, negative error code on failure.
00090     */
00091     int write_register(uint8_t reg, const uint8_t value, uint8_t len);
00092     /**
00093     * @brief Set 3-Wire or 4-Wire SPI
00094     *
00095     * @param[in] type Type of SPI interface
00096     *                 0 -> 3-Wire SPI interface (default)
00097     *                 1 -> 4-Wire SPI interface (DOUT_FSK) enabled
00098     *                 2 -> 4-Wire SPI interface (DOUT_ASK) enabled
00099     *
00100     * @returns 0 on success, negative error code on failure.
00101     */
00102     int set_spi_type(uint8_t type);
00103 
00104     /**
00105     * @brief ASK peak detector management
00106     *
00107     * @param[in] enable Requested status of ASK Peak Detector
00108     *
00109     * @returns 0 on success, negative error code on failure.
00110     */
00111     int ASKPeakDetectorEnable(bool enable);
00112 
00113     /**
00114     * @brief FSK peak detector management
00115     *
00116     * @param[in] enable Requested status of FSK Peak Detector
00117     *
00118     * @returns 0 on success, negative error code on failure.
00119     */
00120     int FSKPeakDetectorEnable(bool enable);
00121 
00122     /**
00123       * @brief ASK base band receiver management
00124       *
00125       * @param[in] enable Requested status of ASK base band receiver
00126       *
00127       * @returns 0 on success, negative error code on failure.
00128       */
00129     int ASKBaseBandReceiverEnable(bool enable);
00130 
00131     /**
00132       * @brief FSK base band receiver management
00133       *
00134       * @param[in] enable Requested status of FSK base band receiver
00135       *
00136       * @returns 0 on success, negative error code on failure.
00137       */
00138     int FSKBaseBandReceiverEnable(bool enable);
00139 
00140     /**
00141       * @brief RF Mixer on/off management
00142       *
00143       * @param[in] enable Requested status of RF mixer
00144       *
00145       * @returns 0 on success, negative error code on failure.
00146       */
00147     int RFMixerEnable(bool enable);
00148 
00149     /**
00150       * @brief Automatic gain controller on/off management
00151       *
00152       * @param[in] enable Requested status of AGC
00153       *
00154       * @returns 0 on success, negative error code on failure.
00155       */
00156     int AGCEnable(bool enable);
00157 
00158     /**
00159       * @brief Low noise amplifier on/off management
00160       *
00161       * @param[in] enable Requested status of LNA
00162       *
00163       * @returns 0 on success, negative error code on failure.
00164       */
00165     int LNAEnable(bool enable);
00166 
00167     /**
00168       * @brief 4-wire SPI MISO pin assignment to FSK data pin
00169       *
00170       * @param[in] enable Requested status of DOUT as FSK data pin
00171       *
00172       * @returns 0 on success, negative error code on failure.
00173       */
00174     int SetFDATAasDOUTPin(bool enable);
00175 
00176     /**
00177       * @brief 4-wire SPI MISO pin assignment to ASK data pin
00178       *
00179       * @param[in] enable Requested status of DOUT as ASK data pin
00180       *
00181       * @returns 0 on success, negative error code on failure.
00182       */
00183     int SetADATAasDOUTPin(bool enable);
00184 
00185     /**
00186       * @brief Long FSK calibration on/off management
00187       *
00188       * @param[in] enable Requested status of longer FSK calibration mode
00189       *
00190       * @returns 0 on success, negative error code on failure.
00191       */
00192     int LongerFSKCalibrationEnable(bool enable);
00193 
00194     /**
00195       * @brief Discontinuous receive mode on/off management
00196       *
00197       * @param[in] enable Requested status of discontinuous receive mode
00198       *
00199       * @returns 0 on success, negative error code on failure.
00200       */
00201     int DRXEnable(bool enable);
00202 
00203     /**
00204       * @brief LNA's low or high gain mode selection
00205       *
00206       * @param[in] isHighGain Requested gain mode is high gain or low gain
00207       *
00208       * @returns 0 on success, negative error code on failure.
00209       */
00210     int LNAGainState(bool isHighGain);
00211 
00212     /**
00213       * @brief FSK Calibration starter
00214       *
00215       * @param[in] enable Start or stop FSK calibration
00216       *
00217       * @returns 0 on success, negative error code on failure.
00218       */
00219     int FSKCalibrationDone(bool enable);
00220 
00221     /**
00222       * @brief Get AGC Dwell timer value
00223       *
00224       * @param[out] valuePtr Pointer to AGC Dwell timer value
00225       *
00226       * @returns 0 on success, negative error code on failure.
00227       */
00228     int GetAGCDwellTimer( unsigned char *valuePtr );
00229 
00230     /**
00231        * @brief Set AGC Dwell timer value
00232        *
00233        * @param[in] value Desired value of AGC Dwell timer
00234        *
00235        * @returns 0 on success, negative error code on failure.
00236        */
00237     int SetAGCDwellTimer( unsigned char value );
00238 
00239     /**
00240       * @brief Poll timer calibration starter
00241       *
00242       * @param[in] enable Start or stop poll timer calibration
00243       *
00244       * @returns 0 on success, negative error code on failure.
00245       */
00246     int PollTimerCalibrationEnable(bool enable);
00247 
00248     /**
00249       * @brief Track mode for ASK peak detector on/off control
00250       *
00251       * @param[in] enable Enable/disable track mode of ASK peak detector
00252       *
00253       * @returns 0 on success, negative error code on failure.
00254       */
00255     int ASKPeakDetectorTrackEnable(bool enable);
00256 
00257     /**
00258       * @brief Track mode for FSK peak detector on/off control
00259       *
00260       * @param[in] enable Enable/disable track mode of FSK peak detector
00261       *
00262       * @returns 0 on success, negative error code on failure.
00263       */
00264     int FSKPeakDetectorTrackEnable(bool enable);
00265 
00266     /**
00267       * @brief Locks AGC's current state
00268       *
00269       * @returns 0 on success, negative error code on failure.
00270       */
00271     int LockAGCCurrentState();
00272 
00273     /**
00274       * @brief Gets calibration status of poll timer calibration
00275       *
00276       * @param[out] valuePtr Pointer to current status of poll timer calibration
00277       *
00278       * @returns 0 on success, negative error code on failure.
00279       */
00280     int GetPollTimerCalibrationDoneStatus( unsigned char *valuePtr );
00281 
00282     /**
00283       * @brief Gets calibration status of FSK calibration
00284       *
00285       * @param[out] valuePtr Pointer to current status of FSK calibration
00286       *
00287       * @returns 0 on success, negative error code on failure.
00288       */
00289     int GetFSKCalibrationDoneStatus( unsigned char *valuePtr );
00290 
00291     /**
00292       * @brief Gets clock alive status
00293       *
00294       * @param[out] valuePtr Pointer to clock alive status
00295       *
00296       * @returns 0 on success, negative error code on failure.
00297       */
00298     int GetClockAliveStatus( unsigned char *valuePtr );
00299 
00300     /**
00301       * @brief Gets AGC's current status
00302       *
00303       * @param[out] valuePtr Pointer to AGC's current status
00304       *
00305       * @returns 0 on success, negative error code on failure.
00306       */
00307     int GetAGCStatus( unsigned char *valuePtr );
00308 
00309     /**
00310       * @brief Get whether PLL is locked or not
00311       *
00312       * @param[out] valuePtr Pointer to PLL's current status
00313       *
00314       * @returns 0 on success, negative error code on failure.
00315       */
00316     int GetPLLLockStatus( unsigned char *valuePtr );
00317 
00318     /**
00319       * @brief Get off timer prescale value
00320       *
00321       * @param[out] valuePtr Pointer to off timer prescale value
00322       *
00323       * @returns 0 on success, negative error code on failure.
00324       */
00325     int GetOffTimerPrescale( unsigned char *valuePtr );
00326 
00327     /**
00328       * @brief Set off timer prescale value
00329       *
00330       * @param[in] value Desired value of off timer prescale
00331       *
00332       * @returns 0 on success, negative error code on failure.
00333       */
00334     int SetOffTimerPrescale( unsigned char value );
00335 
00336     /**
00337       * @brief Set rf settle timer value
00338       *
00339       * @param[in] value Desired value of off timer rf settle timer
00340       *
00341       * @returns 0 on success, negative error code on failure.
00342       */
00343     int SetRFSettleTimer( unsigned short int value );
00344 
00345     /**
00346       * @brief Get rf settle timer value
00347       *
00348       * @param[out] valuePtr Pointer to rf settle timer value
00349       *
00350       * @returns 0 on success, negative error code on failure.
00351       */
00352     int GetRFSettleTimer( unsigned short int *valuePtr );
00353 
00354     /**
00355       * @brief Set off timer value
00356       *
00357       * @param[in] value Desired value of off timer
00358       *
00359       * @returns 0 on success, negative error code on failure.
00360       */
00361     int SetOFFTimer( unsigned short int value );
00362 
00363     /**
00364       * @brief Get off timer value
00365       *
00366       * @param[out] valuePtr Pointer to off timer value
00367       *
00368       * @returns 0 on success, negative error code on failure.
00369       */
00370     int GetOFFTimer( unsigned short int *valuePtr );
00371 
00372     /**
00373       * @brief Set CPU recovery timer value
00374       *
00375       * @param[in] value Desired value of CPU recovery timer
00376       *
00377       * @returns 0 on success, negative error code on failure.
00378       */
00379     int SetCPURecoveryTimer( unsigned char value );
00380 
00381     /**
00382       * @brief Get CPU recovery timer value
00383       *
00384       * @param[out] valuePtr Pointer to CPU recovery timer value
00385       *
00386       * @returns 0 on success, negative error code on failure.
00387       */
00388     int GetCPURecoveryTimer( unsigned char *valuePtr );
00389 
00390     /**
00391       * @brief Set RF oscillator frequency
00392       *
00393       * @param[in] value Desired frequency
00394       *
00395       * @returns 0 on success, negative error code on failure.
00396       */
00397     int SetRFOscillatorFreq( float frequency );
00398 
00399     /**
00400       * @brief Get RF oscillator frequency
00401       *
00402       * @param[out] freqPtr Pointer to RF oscillator frequency
00403       *
00404       * @returns 0 on success, negative error code on failure.
00405       */
00406     int GetRFOscillatorFreq( float *freqPtr );
00407 
00408     /**
00409     * @brief Reset the chip
00410     *
00411     * @returns 0 on success, negative error code on failure.
00412     */
00413     int reset();
00414 
00415     /**
00416     * @brief NOP command
00417     *
00418     * @returns 0 on success, negative error code on failure.
00419     */
00420     int nop();
00421 
00422     /**
00423     * @brief Initialize the chip
00424     *
00425     * @returns 0 on success, negative error code on failure.
00426     */
00427     int InitMAX1471();
00428 
00429     int PrepMAX1471RX();
00430 
00431     int PrepMAX1471RX( modulation_type_t modType );
00432 
00433     int PrepMAX1471RX_DRX();
00434 
00435     /**
00436       * @brief Prepare MAX1471's sleep mode
00437       *
00438       * @param[in] enable Sleep mode enable/disable
00439       *
00440       * @returns 0 on success, negative error code on failure.
00441       */
00442     int PrepMAX1471Sleep(bool enable);
00443 
00444 };
00445 extern const uint32_t pmu_program_sample_data_in[];
00446 extern const uint32_t pmu_program_stop_buff1_filling[];
00447 extern const uint32_t pmu_program_stop_buff0_filling[];
00448 extern const uint32_t pmu_program_start_buff1_filling[];
00449 extern const uint32_t pmu_program_save_current_data_to_buffer0[];
00450 extern const uint32_t pmu_program_save_current_data_to_buffer1[];
00451 extern const uint32_t pmu_program_sample_0[];
00452 extern const uint32_t pmu_program_sample_1[];
00453 
00454 #endif /* MAX1471_MAX1471_H_ */