void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig; // Get the peripheral name from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT(obj->dac != (DACName)NC); // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the pin for future use obj->pin = pin; // Enable DAC clock __DAC1_CLK_ENABLE(); // Configure DAC DacHandle.Instance = (DAC_TypeDef *)(obj->dac); sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); analogout_write_u16(obj, 0); }
/** Initialize the analogout peripheral * * Configures the pin used by analogout. * @param obj The analogout object to initialize * @param pin The analogout pin name */ void analogout_init(dac_t *obj, PinName pin) { /* get the peripheral name from the pin and assign it to the object */ 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 = GD_PIN_CHANNEL_GET(function); MBED_ASSERT(obj->channel <= DAC1); /* configure GPIO */ pinmap_pinout(pin, PinMap_DAC); /* save the pin for future use */ obj->pin = pin; /* enable DAC clock */ rcu_periph_clock_enable(RCU_DAC); /* configure DAC */ dac_wave_mode_config(obj->channel, DAC_WAVE_DISABLE); dac_trigger_disable(obj->channel); dac_output_buffer_enable(obj->channel); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig; DacHandle.Instance = DAC; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the channel for future use obj->pin = pin; // Enable DAC clock __DAC_CLK_ENABLE(); // Configure DAC sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig; DacHandle.Instance = DAC; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT(obj->dac != (DACName)NC); // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the channel for future use obj->pin = pin; // Enable DAC clock __DAC_CLK_ENABLE(); // Configure DAC sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; if (pin == PA_4) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); pa4_used = 1; } else { // PA_5 HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_2); pa5_used = 1; } analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_TypeDef *dac; DAC_InitTypeDef DAC_InitStructure; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } dac = (DAC_TypeDef *)(obj->dac); // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the channel for future use obj->pin = pin; // Enable DAC clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // Configure and enable DAC channel DAC_StructInit(&DAC_InitStructure); DAC_Init(dac, DAC_Channel_1, &DAC_InitStructure); DAC_Cmd(dac, DAC_Channel_1, ENABLE); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig; // Get the peripheral name from the pin and assign it to the object 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); // Save the pin for future use obj->pin = pin; // Enable DAC clock if (obj->dac == DAC_1) { __DAC1_CLK_ENABLE(); } #if defined(DAC2) if (obj->dac == DAC_2) { __DAC2_CLK_ENABLE(); } #endif // Configure DAC DacHandle.Instance = (DAC_TypeDef *)(obj->dac); sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE; if (pin == PA_4) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); pa4_used = 1; } #if defined(DAC_CHANNEL_2) if (pin == PA_5) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_2); pa5_used = 1; } #endif if (pin == PA_6) { HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1); } analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); MBED_ASSERT(obj->dac != (DACName)NC); // DAC enable bit must be set LPC_IOCON->P0_26 |= (1 << 16); // DACEN // map out (must be done before accessing registers) pinmap_pinout(pin, PinMap_DAC); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { if (pin != P0_12) { error("DAC pin mapping failed"); } LPC_SYSCON->SYSAHBCLKCTRL0 |= (1 << 29); LPC_SYSCON->PDRUNCFG &= ~(1 << 12); LPC_IOCON->PIO0_12 = 0; LPC_SWM->PINENABLE0 &= ~(1 << 24); LPC_DAC->CTRL = 0; analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); // Get the functions (dac channel) from the pin and assign it to the object uint32_t function = pinmap_function(pin, PinMap_DAC); MBED_ASSERT(function != (uint32_t)NC); // Save the channel for the write and read functions switch (STM_PIN_CHANNEL(function)) { case 1: obj->channel = DAC_CHANNEL_1; break; #if defined(DAC_CHANNEL_2) case 2: obj->channel = DAC_CHANNEL_2; break; #endif default: error("Unknown DAC channel"); break; } if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } // Configure GPIO pinmap_pinout(pin, PinMap_DAC); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_DAC_CLK_ENABLE(); obj->handle.Instance = DAC; obj->handle.State = HAL_DAC_STATE_RESET; if (HAL_DAC_Init(&obj->handle) != HAL_OK ) { error("HAL_DAC_Init failed"); } sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; if (HAL_DAC_ConfigChannel(&obj->handle, &sConfig, obj->channel) != HAL_OK) { error("HAL_DAC_ConfigChannel failed"); } analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name from the pin and assign it to the object 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); // Save the pin for future use obj->pin = pin; // Enable DAC clock __HAL_RCC_DAC1_CLK_ENABLE(); // Configure DAC DacHandle.Instance = DAC; if (HAL_DAC_Init(&DacHandle) != HAL_OK) { error("Cannot initialize DAC\n"); } sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE; sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE; sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY; if (obj->channel == 2) { if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_2) != HAL_OK) { error("Cannot configure DAC channel 2\n"); } channel2_used = 1; } else { // channel 1 per default if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DAC_CHANNEL_1) != HAL_OK) { error("Cannot configure DAC channel 1\n"); } obj->channel = 1; channel1_used = 1; } analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } // power is on by default, set DAC clk divider is /4 LPC_SC->PCLKSEL0 &= ~(0x3 << 22); // map out (must be done before accessing registers) pinmap_pinout(pin, PinMap_DAC); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (uint32_t)NC) { error("DAC pin mapping failed"); } // DAC enable bit must be set LPC_IOCON->P0_26 |= (1 << 16); // DACEN // map out (must be done before accessing registers) pinmap_pinout(pin, PinMap_DAC); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } SIM->SCGC2 |= SIM_SCGC2_DAC0_MASK; DAC0->DAT[obj->dac].DATH = 0; DAC0->DAT[obj->dac].DATL = 0; DAC0->C1 = DAC_C1_DACBFMD(2); // One-Time Scan Mode DAC0->C0 = DAC_C0_DACEN_MASK // Enable | DAC_C0_DACSWTRG_MASK // Software Trigger | DAC_C0_DACRFS_MASK; // VDDA selected analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (uint32_t)NC) { error("DAC pin mapping failed"); } #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) // power is on by default, set DAC clk divider is /4 LPC_SC->PCLKSEL0 &= ~(0x3 << 22); #elif defined(TARGET_LPC4088) // DAC enable bit must be set LPC_IOCON->P0_26 |= (1 << 16); // DACEN #endif // map out (must be done before accessing registers) pinmap_pinout(pin, PinMap_DAC); analogout_write_u16(obj, 0); }
void analogout_init(dac_t *obj, PinName pin) { DAC_InitTypeDef DAC_InitStructure; // Get the peripheral name (DAC_1, ...) from the pin and assign it to the object obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC); if (obj->dac == (DACName)NC) { error("DAC pin mapping failed"); } // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the pin for future use obj->pin = pin; // Enable DAC clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); // Configure and enable DAC channel DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; if (obj->pin == PA_4) { DAC_Init(DAC_Channel_1, &DAC_InitStructure); DAC_Cmd(DAC_Channel_1, ENABLE); } if (obj->pin == PA_5) { DAC_Init(DAC_Channel_2, &DAC_InitStructure); DAC_Cmd(DAC_Channel_2, ENABLE); } analogout_write_u16(obj, 0); }
//****************************************************************************** void analogout_write(dac_t *obj, float value) { analogout_write_u16(obj, (uint16_t)((value/1.0) * 0xFFFF)); }
void analogout_init(dac_t *obj, PinName pin) { DAC_ChannelConfTypeDef sConfig = {0}; // Get the peripheral name from the pin and assign it to the object 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); // Save the channel for the write and read functions switch (STM_PIN_CHANNEL(function)) { case 1: obj->channel = DAC_CHANNEL_1; break; #if defined(DAC_CHANNEL_2) case 2: obj->channel = DAC_CHANNEL_2; break; #endif default: error("Unknown DAC channel"); break; } // Configure GPIO pinmap_pinout(pin, PinMap_DAC); // Save the pin for future use obj->pin = pin; // Enable DAC clock if (obj->dac == DAC_1) { __HAL_RCC_DAC1_CLK_ENABLE(); } #if defined(DAC2) if (obj->dac == DAC_2) { __HAL_RCC_DAC2_CLK_ENABLE(); } #endif // Configure DAC obj->handle.Instance = (DAC_TypeDef *)(obj->dac); obj->handle.State = HAL_DAC_STATE_RESET; if (HAL_DAC_Init(&obj->handle) != HAL_OK) { error("HAL_DAC_Init failed"); } /* Enable both Buffer and Switch in the configuration, * letting HAL layer in charge of selecting either one * or the other depending on the actual DAC instance and * channel being configured. */ sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; #if defined(DAC_OUTPUTSWITCH_ENABLE) sConfig.DAC_OutputSwitch = DAC_OUTPUTSWITCH_ENABLE; #endif if (pin == PA_4) { pa4_used = 1; } if (pin == PA_5) { pa5_used = 1; } if (HAL_DAC_ConfigChannel(&obj->handle, &sConfig, obj->channel) != HAL_OK) { error("HAL_DAC_ConfigChannel failed"); } analogout_write_u16(obj, 0); }