mirror of https://github.com/ARMmbed/mbed-os.git
analogout: STM32: analogout_free implementation for F4
Implemented analogout_free for STM32F4 family and added new member "PinName pin" in dac_s structure.pull/14844/head
parent
d83494f54b
commit
b52b3b6d43
|
@ -23,6 +23,12 @@
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
#include "PeripheralPins.h"
|
#include "PeripheralPins.h"
|
||||||
|
|
||||||
|
// These variables are used for the "free" function
|
||||||
|
static int dac_channel1_used = 0;
|
||||||
|
#if defined(DAC_CHANNEL_2)
|
||||||
|
static int dac_channel2_used = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if STATIC_PINMAP_READY
|
#if STATIC_PINMAP_READY
|
||||||
#define ANALOGOUT_INIT_DIRECT analogout_init_direct
|
#define ANALOGOUT_INIT_DIRECT analogout_init_direct
|
||||||
void analogout_init_direct(dac_t *obj, const PinMap *pinmap)
|
void analogout_init_direct(dac_t *obj, const PinMap *pinmap)
|
||||||
|
@ -62,6 +68,9 @@ static void _analogout_init_direct(dac_t *obj, const PinMap *pinmap)
|
||||||
pin_function(pinmap->pin, pinmap->function);
|
pin_function(pinmap->pin, pinmap->function);
|
||||||
pin_mode(pinmap->pin, PullNone);
|
pin_mode(pinmap->pin, PullNone);
|
||||||
|
|
||||||
|
// Save the pin for future use
|
||||||
|
obj->pin = pinmap->pin;
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
|
||||||
__HAL_RCC_DAC_CLK_ENABLE();
|
__HAL_RCC_DAC_CLK_ENABLE();
|
||||||
|
@ -80,6 +89,14 @@ static void _analogout_init_direct(dac_t *obj, const PinMap *pinmap)
|
||||||
error("HAL_DAC_ConfigChannel failed");
|
error("HAL_DAC_ConfigChannel failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj->channel == DAC_CHANNEL_1) {
|
||||||
|
dac_channel1_used = 1;
|
||||||
|
}
|
||||||
|
#if defined(DAC_CHANNEL_2)
|
||||||
|
if (obj->channel == DAC_CHANNEL_2) {
|
||||||
|
dac_channel2_used = 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
analogout_write_u16(obj, 0);
|
analogout_write_u16(obj, 0);
|
||||||
HAL_DAC_Start(&obj->handle, obj->channel);
|
HAL_DAC_Start(&obj->handle, obj->channel);
|
||||||
}
|
}
|
||||||
|
@ -96,6 +113,28 @@ void analogout_init(dac_t *obj, PinName pin)
|
||||||
|
|
||||||
void analogout_free(dac_t *obj)
|
void analogout_free(dac_t *obj)
|
||||||
{
|
{
|
||||||
|
if (obj->channel == DAC_CHANNEL_1) {
|
||||||
|
dac_channel1_used = 0;
|
||||||
|
}
|
||||||
|
#if defined(DAC_CHANNEL_2)
|
||||||
|
if (obj->channel == DAC_CHANNEL_2) {
|
||||||
|
dac_channel2_used = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ((dac_channel1_used == 0)
|
||||||
|
#if defined(DAC_CHANNEL_2)
|
||||||
|
&& (dac_channel2_used == 0)
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
|
// Reset DAC and disable clock
|
||||||
|
__HAL_RCC_DAC_FORCE_RESET();
|
||||||
|
__HAL_RCC_DAC_RELEASE_RESET();
|
||||||
|
__HAL_RCC_DAC_CLK_DISABLE();
|
||||||
|
|
||||||
|
// Configure GPIO back to reset value
|
||||||
|
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const PinMap *analogout_pinmap()
|
const PinMap *analogout_pinmap()
|
||||||
|
|
|
@ -141,6 +141,7 @@ struct analogin_s {
|
||||||
#if DEVICE_ANALOGOUT
|
#if DEVICE_ANALOGOUT
|
||||||
struct dac_s {
|
struct dac_s {
|
||||||
DACName dac;
|
DACName dac;
|
||||||
|
PinName pin;
|
||||||
uint32_t channel;
|
uint32_t channel;
|
||||||
DAC_HandleTypeDef handle;
|
DAC_HandleTypeDef handle;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue