git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7938 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
0b7c0f050c
commit
b2431579e4
|
@ -239,6 +239,12 @@ extern "C" {
|
|||
void dacObjectInit(DACDriver *dacp);
|
||||
void dacStart(DACDriver *dacp, const DACConfig *config);
|
||||
void dacStop(DACDriver *dacp);
|
||||
void dacPutChannel(DACDriver *dacp,
|
||||
dacchannel_t channel,
|
||||
dacsample_t sample);
|
||||
void dacPutChannelI(DACDriver *dacp,
|
||||
dacchannel_t channel,
|
||||
dacsample_t sample);
|
||||
void dacStartConversion(DACDriver *dacp, const DACConversionGroup *grpp,
|
||||
const dacsample_t *samples, size_t depth);
|
||||
void dacStartConversionI(DACDriver *dacp, const DACConversionGroup *grpp,
|
||||
|
|
|
@ -81,7 +81,9 @@ DACDriver DACD4;
|
|||
/* Driver local variables. */
|
||||
/*===========================================================================*/
|
||||
|
||||
static const DACConfig default_config = {0};
|
||||
static const DACConfig default_config = {
|
||||
datamode: DAC_DHRM_12BIT_RIGHT
|
||||
};
|
||||
|
||||
#if STM32_DAC_USE_DAC1_CH1 == TRUE
|
||||
static const dacparams_t dma1_ch1_params = {
|
||||
|
@ -310,6 +312,24 @@ void dac_lld_stop(DACDriver *dacp) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Outputs a value directly on a DAC channel.
|
||||
*
|
||||
* @param[in] dacp pointer to the @p DACDriver object
|
||||
* @param[in] channel DAC channel number
|
||||
* @param[in] sample value to be output
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void dac_lld_put_channel(DACDriver *dacp,
|
||||
dacchannel_t channel,
|
||||
dacsample_t sample) {
|
||||
|
||||
(void)dacp;
|
||||
(void)channel;
|
||||
(void)sample;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts a DAC conversion.
|
||||
* @details Starts an asynchronous conversion operation.
|
||||
|
@ -322,7 +342,7 @@ void dac_lld_start_conversion(DACDriver *dacp) {
|
|||
uint32_t cr, dmamode;
|
||||
|
||||
#if STM32_DAC_DUAL_MODE == FALSE
|
||||
switch (dacp->grpp->datamode) {
|
||||
switch (dacp->config->datamode) {
|
||||
/* Sets the DAC data register */
|
||||
case DAC_DHRM_12BIT_RIGHT:
|
||||
dmaStreamSetPeripheral(dacp->params->dma, &dacp->params->dac->DHR12R1 +
|
||||
|
|
|
@ -226,10 +226,24 @@
|
|||
#define STM32_DMA_REQUIRED
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Max DAC channels.
|
||||
*/
|
||||
#if STM32_DAC_DUAL_MODE == FALSE
|
||||
#define DAC_MAX_CHANNELS 1
|
||||
#else
|
||||
#define DAC_MAX_CHANNELS 2
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Type of a DAC channel index.
|
||||
*/
|
||||
typedef uint32_t dacchannel_t;
|
||||
|
||||
/**
|
||||
* @brief DAC channel parameters type.
|
||||
*/
|
||||
|
@ -336,10 +350,6 @@ typedef struct {
|
|||
*/
|
||||
dacerrorcallback_t error_cb;
|
||||
/* End of the mandatory fields.*/
|
||||
/**
|
||||
* @brief DAC data holding register mode.
|
||||
*/
|
||||
dacdhrmode_t datamode;
|
||||
/**
|
||||
* @brief DAC initialization data.
|
||||
* @note This field contains the (not shifted) value to be put into the
|
||||
|
@ -354,7 +364,10 @@ typedef struct {
|
|||
*/
|
||||
typedef struct {
|
||||
/* End of the mandatory fields.*/
|
||||
uint32_t dummy;
|
||||
/**
|
||||
* @brief DAC data holding register mode.
|
||||
*/
|
||||
dacdhrmode_t datamode;
|
||||
} DACConfig;
|
||||
|
||||
/**
|
||||
|
@ -433,6 +446,9 @@ extern "C" {
|
|||
void dac_lld_init(void);
|
||||
void dac_lld_start(DACDriver *dacp);
|
||||
void dac_lld_stop(DACDriver *dacp);
|
||||
void dac_lld_put_channel(DACDriver *dacp,
|
||||
dacchannel_t channel,
|
||||
dacsample_t sample);
|
||||
void dac_lld_start_conversion(DACDriver *dacp);
|
||||
void dac_lld_stop_conversion(DACDriver *dacp);
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -130,6 +130,40 @@ void dacStop(DACDriver *dacp) {
|
|||
osalSysUnlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Outputs a value directly on a DAC channel.
|
||||
*
|
||||
* @param[in] dacp pointer to the @p DACDriver object
|
||||
* @param[in] channel DAC channel number
|
||||
* @param[in] sample value to be output
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
void dacPutChannel(DACDriver *dacp, dacchannel_t channel, dacsample_t sample) {
|
||||
|
||||
osalSysLock();
|
||||
dacPutChannelI(dacp, channel, sample);
|
||||
osalSysUnlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Outputs a value directly on a DAC channel.
|
||||
*
|
||||
* @param[in] dacp pointer to the @p DACDriver object
|
||||
* @param[in] channel DAC channel number
|
||||
* @param[in] sample value to be output
|
||||
*
|
||||
* @iclass
|
||||
*/
|
||||
void dacPutChannelI(DACDriver *dacp, dacchannel_t channel, dacsample_t sample) {
|
||||
|
||||
osalDbgCheckClassI();
|
||||
osalDbgCheck(channel < DAC_MAX_CHANNELS);
|
||||
osalDbgAssert(dacp->state == DAC_READY, "invalid state");
|
||||
|
||||
dac_lld_put_channel(dacp, channel, sample);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts a DAC conversion.
|
||||
* @details Starts an asynchronous conversion operation.
|
||||
|
|
|
@ -58,17 +58,22 @@ static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {
|
|||
/*
|
||||
* DAC streaming callback.
|
||||
*/
|
||||
size_t nx = 0, ny = 0;
|
||||
size_t nx = 0, ny = 0, nz = 0;
|
||||
static void end_cb1(DACDriver *dacp, const dacsample_t *buffer, size_t n) {
|
||||
|
||||
(void)dacp;
|
||||
|
||||
nz++;
|
||||
if (dac_buffer == buffer) {
|
||||
nx += n;
|
||||
}
|
||||
else {
|
||||
ny += n;
|
||||
}
|
||||
|
||||
if ((nz % 1000) == 0) {
|
||||
palTogglePad(GPIOD, GPIOD_LED3);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -82,14 +87,16 @@ static void error_cb1(DACDriver *dacp, dacerror_t err) {
|
|||
chSysHalt("DAC failure");
|
||||
}
|
||||
|
||||
static const DACConversionGroup daccfg1 = {
|
||||
num_channels: 1,
|
||||
end_cb: end_cb1,
|
||||
error_cb: error_cb1,
|
||||
datamode: DAC_DHRM_12BIT_RIGHT,
|
||||
trigger: DAC_TRG(0)
|
||||
static const DACConfig dac1cfg1 = {
|
||||
datamode: DAC_DHRM_12BIT_RIGHT
|
||||
};
|
||||
|
||||
static const DACConversionGroup dacgrpcfg1 = {
|
||||
num_channels: 1U,
|
||||
end_cb: end_cb1,
|
||||
error_cb: error_cb1,
|
||||
trigger: DAC_TRG(0)
|
||||
};
|
||||
|
||||
/*
|
||||
* GPT2 configuration.
|
||||
|
@ -121,7 +128,7 @@ int main(void) {
|
|||
* by the Reference Manual.
|
||||
*/
|
||||
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
|
||||
dacStart(&DACD1, NULL);
|
||||
dacStart(&DACD1, &dac1cfg1);
|
||||
|
||||
/*
|
||||
* Starting GPT6 driver, it is used for triggering the DAC.
|
||||
|
@ -131,7 +138,7 @@ int main(void) {
|
|||
/*
|
||||
* Starting a continuous conversion.
|
||||
*/
|
||||
dacStartConversion(&DACD1, &daccfg1, dac_buffer, DAC_BUFFER_SIZE);
|
||||
dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, DAC_BUFFER_SIZE);
|
||||
gptStartContinuous(&GPTD6, 2U);
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue