STM32F4 Analogout driver: Add explicit pinmap support

pull/11892/head
Przemyslaw Stekiel 2019-08-26 14:10:54 +02:00
parent 4a79e59ef6
commit eab08d7047
1 changed files with 21 additions and 4 deletions

View File

@ -35,14 +35,20 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
#include "PeripheralPins.h" #include "PeripheralPins.h"
void analogout_init(dac_t *obj, PinName pin) #if EXPLICIT_PINMAP_READY
#define ANALOGOUT_INIT_DIRECT analogout_init_direct
void analogout_init_direct(dac_t* obj, const PinMap *pinmap)
#else
#define ANALOGOUT_INIT_DIRECT _analogout_init_direct
static void _analogout_init_direct(dac_t* obj, const PinMap *pinmap)
#endif
{ {
DAC_ChannelConfTypeDef sConfig = {0}; DAC_ChannelConfTypeDef sConfig = {0};
// Get the peripheral name (DAC_1, ...) from the pin and assign it to the object // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); obj->dac = (DACName)pinmap->peripheral;
// Get the functions (dac channel) from the pin and assign it to the object // Get the functions (dac channel) from the pin and assign it to the object
uint32_t function = pinmap_function(pin, PinMap_DAC); uint32_t function = (uint32_t)pinmap->function;
MBED_ASSERT(function != (uint32_t)NC); MBED_ASSERT(function != (uint32_t)NC);
// Save the channel for the write and read functions // Save the channel for the write and read functions
@ -65,7 +71,8 @@ void analogout_init(dac_t *obj, PinName pin)
} }
// Configure GPIO // Configure GPIO
pinmap_pinout(pin, PinMap_DAC); pin_function(pinmap->pin, pinmap->function);
pin_mode(pinmap->pin, PullNone);
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
@ -88,6 +95,16 @@ void analogout_init(dac_t *obj, PinName pin)
analogout_write_u16(obj, 0); analogout_write_u16(obj, 0);
} }
void analogout_init(dac_t *obj, PinName pin)
{
int peripheral = (int)pinmap_peripheral(pin, PinMap_DAC);
int function = (int)pinmap_find_function(pin, PinMap_DAC);
const PinMap explicit_pinmap = {pin, peripheral, function};
ANALOGOUT_INIT_DIRECT(obj, &explicit_pinmap);
}
void analogout_free(dac_t *obj) void analogout_free(dac_t *obj)
{ {
} }