Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-stm32l0/l1-src by
Diff: targets/hal/TARGET_STM/TARGET_STM32F3/analogout_api.c
- Revision:
- 544:1af5f1c39e80
- Parent:
- 508:4f5903e025e6
--- a/targets/hal/TARGET_STM/TARGET_STM32F3/analogout_api.c Wed May 20 08:45:07 2015 +0100 +++ b/targets/hal/TARGET_STM/TARGET_STM32F3/analogout_api.c Thu May 21 09:45:08 2015 +0100 @@ -1,5 +1,5 @@ /* mbed Microcontroller Library - * Copyright (c) 2014, STMicroelectronics + * Copyright (c) 2015, STMicroelectronics * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,6 +51,11 @@ obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT(obj->dac != (DACName)NC); + // Get the pin function and assign the used channel to the object + uint32_t function = pinmap_function(pin, PinMap_DAC); + MBED_ASSERT(function != (uint32_t)NC); + obj->channel = STM_PIN_CHANNEL(function); + // Configure GPIO pinmap_pinout(pin, PinMap_DAC); @@ -61,7 +66,7 @@ if (obj->dac == DAC_1) { __DAC1_CLK_ENABLE(); } -#if defined(__DAC2_FORCE_RESET) +#if defined(DAC2) if (obj->dac == DAC_2) { __DAC2_CLK_ENABLE(); } @@ -104,7 +109,7 @@ __DAC1_CLK_DISABLE(); } -#if defined(__DAC2_FORCE_RESET) +#if defined(DAC2) if (obj->pin == PA_6) { __DAC2_FORCE_RESET(); __DAC2_RELEASE_RESET(); @@ -118,13 +123,12 @@ static inline void dac_write(dac_t *obj, uint16_t value) { - if ((obj->pin == PA_4) || (obj->pin == PA_6)) { + if (obj->channel == 1) { HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_1, DAC_ALIGN_12B_R, value); HAL_DAC_Start(&DacHandle, DAC_CHANNEL_1); } - #if defined(DAC_CHANNEL_2) - if (obj->pin == PA_5) { + if (obj->channel == 2) { HAL_DAC_SetValue(&DacHandle, DAC_CHANNEL_2, DAC_ALIGN_12B_R, value); HAL_DAC_Start(&DacHandle, DAC_CHANNEL_2); } @@ -133,15 +137,15 @@ static inline int dac_read(dac_t *obj) { - if ((obj->pin == PA_4) || (obj->pin == PA_6)) { + if (obj->channel == 1) { return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_1); + } #if defined(DAC_CHANNEL_2) - } else if (obj->pin == PA_5) { + if (obj->channel == 2) { return (int)HAL_DAC_GetValue(&DacHandle, DAC_CHANNEL_2); + } #endif - } else { - return 0; - } + return 0; } void analogout_write(dac_t *obj, float value)