2929#include <string.h>
3030
3131#include "py/runtime.h"
32+ #include "py/mphal.h"
3233#include "timer.h"
3334#include "dac.h"
3435#include "dma.h"
@@ -144,7 +145,7 @@ typedef struct _pyb_dac_obj_t {
144145 mp_obj_base_t base ;
145146 uint32_t dac_channel ; // DAC_CHANNEL_1 or DAC_CHANNEL_2
146147 const dma_descr_t * tx_dma_descr ;
147- uint16_t pin ; // GPIO_PIN_4 or GPIO_PIN_5
148+ mp_hal_pin_obj_t pin ; // pin_A4 or pin_A5
148149 uint8_t bits ; // 8 or 12
149150 uint8_t state ;
150151 uint8_t outbuf_single ;
@@ -162,11 +163,7 @@ STATIC mp_obj_t pyb_dac_init_helper(pyb_dac_obj_t *self, size_t n_args, const mp
162163 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
163164
164165 // GPIO configuration
165- GPIO_InitTypeDef GPIO_InitStructure ;
166- GPIO_InitStructure .Pin = self -> pin ;
167- GPIO_InitStructure .Mode = GPIO_MODE_ANALOG ;
168- GPIO_InitStructure .Pull = GPIO_NOPULL ;
169- HAL_GPIO_Init (GPIOA , & GPIO_InitStructure );
166+ mp_hal_pin_config (self -> pin , MP_HAL_PIN_MODE_ANALOG , MP_HAL_PIN_PULL_NONE , 0 );
170167
171168 // DAC peripheral clock
172169 #if defined(STM32F4 ) || defined(STM32F7 )
@@ -251,11 +248,11 @@ STATIC mp_obj_t pyb_dac_make_new(const mp_obj_type_t *type, size_t n_args, size_
251248 dac -> base .type = & pyb_dac_type ;
252249
253250 if (dac_id == 1 ) {
254- dac -> pin = GPIO_PIN_4 ;
251+ dac -> pin = pin_A4 ;
255252 dac -> dac_channel = DAC_CHANNEL_1 ;
256253 dac -> tx_dma_descr = & dma_DAC_1_TX ;
257254 } else if (dac_id == 2 ) {
258- dac -> pin = GPIO_PIN_5 ;
255+ dac -> pin = pin_A5 ;
259256 dac -> dac_channel = DAC_CHANNEL_2 ;
260257 dac -> tx_dma_descr = & dma_DAC_2_TX ;
261258 } else {
0 commit comments