/********************************************************************//** * @brief Enable/Disable PWM channel output * @param[in] pwmId The Id of the expected PWM component * * @param[in] PWMChannel PWM channel, should be in range from 1 to 6 * @param[in] NewState New State of this function, should be: * - ENABLE: Enable this PWM channel output * - DISABLE: Disable this PWM channel output * @return None *********************************************************************/ void PWM_ChannelCmd(uint8_t pwmId, uint8_t PWMChannel, FunctionalState NewState) { LPC_PWM_TypeDef* pPwm = PWM_GetPointer(pwmId); if (NewState == ENABLE) { pPwm->PCR |= PWM_PCR_PWMENAn(PWMChannel); } else { pPwm->PCR &= (~ PWM_PCR_PWMENAn(PWMChannel)) & PWM_PCR_BITMASK; } }
/********************************************************************//** * @brief Enable/Disable PWM channel output * @param[in] PWMx PWM peripheral selected, should be LPC_PWM1 * @param[in] PWMChannel PWM channel, should be in range from 1 to 6 * @param[in] NewState New State of this function, should be: * - ENABLE: Enable this PWM channel output * - DISABLE: Disable this PWM channel output * @return None *********************************************************************/ void PWM_ChannelCmd(LPC_PWM_TypeDef *PWMx, uint8_t PWMChannel, FunctionalState NewState) { CHECK_PARAM(PARAM_PWMx(PWMx)); CHECK_PARAM(PARAM_PWM1_CHANNEL(PWMChannel)); if (NewState == ENABLE) { PWMx->PCR |= PWM_PCR_PWMENAn(PWMChannel); } else { PWMx->PCR &= (~PWM_PCR_PWMENAn(PWMChannel)) & PWM_PCR_BITMASK; } }
/* dac_init * * Initialize the DAC. This must be called once after reset. */ void COLD dac_init() { /* Turn on the PWM and timer peripherals. */ CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCPWM1, ENABLE); CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_PWM1, CLKPWR_PCLKSEL_CCLK_DIV_4); /* Set up the SSP to communicate with the DAC, and initialize to 0 */ hw_dac_init(); /* ... and LDAC on the PWM peripheral */ LPC_PINCON->PINSEL4 |= (1 << 8); /* Get the pin set up to produce a low LDAC puslse */ LPC_GPIO2->FIODIR |= (1 << 4); LPC_GPIO2->FIOCLR = (1 << 4); /* The PWM peripheral is used to generate LDAC pulses. Set it up, * but hold it in reset until go time. */ LPC_PWM1->TCR = PWM_TCR_COUNTER_RESET | PWM_TCR_COUNTER_ENABLE; /* Reset on match channel 0 */ LPC_PWM1->MCR = PWM_MCR_RESET_ON_MATCH(0) | PWM_MCR_INT_ON_MATCH(0); /* Enable single-edge PWM on channel 5 */ LPC_PWM1->PCR = PWM_PCR_PWMENAn(5); /* The match registers themselves will be set by dac_start(). */ /* Enable the write-to-DAC interrupt with the highest priority. */ NVIC_SetPriority(PWM1_IRQn, 0); NVIC_EnableIRQ(PWM1_IRQn); dac_control.state = DAC_IDLE; dac_control.irq_do = IRQ_DO_PANIC; dac_control.count = 0; dac_current_pps = 0; dac_control.color_control.word = 0; delay_line_reset(); dac_control.red_gain = COORD_MAX; dac_control.green_gain = COORD_MAX; dac_control.blue_gain = COORD_MAX; if (hw_dac_16bit) { memcpy(PWM1_IRQHandler, goto_dac16_handle_irq, goto_dac16_handle_irq_end - goto_dac16_handle_irq); } }