driver: ad9833

This commit is contained in:
2023-03-25 21:30:15 +01:00
parent 42c8f0bc1b
commit 7d30ec0355
10 changed files with 632 additions and 105 deletions

View File

@@ -0,0 +1,56 @@
#pragma once
#define AD_DEFAULT_FREQ 1000U ///< Default initialisation frequency (Hz)
#define AD_DEFAULT_PHASE 0 ///< Default initialisation phase angle (degrees)
#define AD_MCLK 25000000UL ///< Clock speed of the AD9833 reference clock in Hz
/**
* Channel enumerated type.
*
* This enumerated type is used with the to specify which channel
* is being invoked on operations that could be channel related.
*/
typedef enum
{
CHAN_0 = 0, ///< Channel 0 definition
CHAN_1 = 1, ///< Channel 1 definition
} AD_channel_t;
/**
* Output mode request enumerated type.
*
* This enumerated type is used with the \ref setMode() methods to identify
* the mode request.
*/
typedef enum
{
MODE_OFF, ///< Set output all off
MODE_SINE, ///< Set output to a sine wave at selected frequency
MODE_SQUARE1, ///< Set output to a square wave at selected frequency
MODE_SQUARE2, ///< Set output to a square wave at half selected frequency
MODE_TRIANGLE, ///< Set output to a triangle wave at selected frequency
} AD_mode_t;
typedef struct
{
uint16_t _regCtl; // control register image
uint32_t _regFreq[2]; // frequency registers
uint32_t _regPhase[2]; // phase registers
AD_mode_t _mode; // last set mode
float _freq[2]; // last frequencies set
uint16_t _phase[2]; // last phase setting
SPI_HandleTypeDef *hspi;
GPIO_TypeDef *cs_port;
uint16_t cs_pin;
} ad9833_handle_t;
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin);
void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold);
void ad9833_setActiveChannelFreq(ad9833_handle_t *hfg, AD_channel_t chan);
AD_channel_t ad9833_getActiveChannelFreq(ad9833_handle_t *hfg);
void ad9833_setActiveChannelPhase(ad9833_handle_t *hfg, AD_channel_t chan);
AD_channel_t ad9833_getActiveChannelPhase(ad9833_handle_t *hfg);
void ad9833_setMode(ad9833_handle_t *hfg, AD_mode_t mode);
void ad9833_setFrequency(ad9833_handle_t *hfg, AD_channel_t chan, float freq);
void ad9833_setPhase(ad9833_handle_t *hfg, AD_channel_t chan, uint16_t phase);