/*************************************************************************** * Copyright (C) 02/2021 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License, * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "pwm.h" /* *********************************************************************** */ #define PWM_TIM_INIT() { \ /* enable output for OC1A, OC1B, OC3A */ \ DDRB |= (1<= PWM_CH0_MAX) { PWM_CH0_ON(); } else { PWM_CH0_PWM(value); } if (PWM_CH0_CHECK()) { PWM_CH0_ENABLE(); } else { PWM_CH0_DISABLE(); } break; case 1: if (value <= PWM_CH1_MIN) { PWM_CH1_OFF(); } else if (value >= PWM_CH1_MAX) { PWM_CH1_ON(); } else { PWM_CH1_PWM(value); } if (PWM_CH1_CHECK()) { PWM_CH1_ENABLE(); } else { PWM_CH1_DISABLE(); } break; case 2: if (value <= PWM_CH2_MIN) { PWM_CH2_OFF(); } else if (value >= PWM_CH2_MAX) { PWM_CH2_ON(); } else { PWM_CH2_PWM(value); } if (PWM_CH2_CHECK()) { PWM_CH2_ENABLE(); } else { PWM_CH2_DISABLE(); } break; } } /* pwm_update */ void pwm_event_handler(event_entry_t * p_event) { if (p_event->type == EVENT_TYPE_PWM_VALUE) { pwm_update(p_event->num, p_event->value); } } /* pwm_event_handler */ uint8_t pwm_need_hw_clock(void) { return !!(PWM_CH0_RUNNING() || PWM_CH1_RUNNING() || PWM_CH2_RUNNING()); } /* pwm_need_hw_clock */ void pwm_init(void) { PWM_TIM_INIT(); } /* pwm_init */