4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2004 Giovanni Bajo
6 * This file is part of DevLib - See devlib/README for information.
9 * \brief Hardware support for buzzers and leds in DSP56K-based boards
13 * \author Giovanni Bajo <rasky@develer.com>
18 * Revision 1.2 2004/06/03 11:27:09 bernie
19 * Add dual-license information.
21 * Revision 1.1 2004/05/23 18:36:05 bernie
22 * Import buzzerled driver.
30 INLINE void bld_hw_init(void)
34 INLINE void bld_hw_set(enum BLD_DEVICE device, bool enable)
36 if (bld_is_inverted_intensity(device))
39 // Handle a BLD connected to a PWM
40 if (bld_is_pwm(device))
42 struct PWM* pwm = pwm_get_handle(bld_get_pwm(device));
44 pwm_set_enable(pwm, false);
45 pwm_set_dutycycle_percent(pwm, (enable ? 50 : 0));
46 pwm_set_enable(pwm, true);
48 else if (bld_is_timer(device))
50 struct REG_TIMER_STRUCT* timer = bld_get_timer(device);
52 // Check that the timer is currently stopped, and the OFLAG is not
53 // controlled by another timer. Otherwise, the led is already
54 // controlled by the timer, and we cannot correctly set it
55 // on/off without reprogramming the timer.
56 ASSERT((timer->CTRL & REG_TIMER_CTRL_MODE_MASK) == REG_TIMER_CTRL_MODE_STOP);
57 ASSERT(!(timer->SCR & REG_TIMER_SCR_EEOF));
59 // Check also that polarity is correct
60 ASSERT(!(timer->SCR & REG_TIMER_SCR_OPS));
62 // Without programming the timer, we have a way to manually force a certain
63 // value on the external pin. We also need to enable the output pin.
64 timer->SCR &= ~REG_TIMER_SCR_VAL_1;
65 timer->SCR |= REG_TIMER_SCR_OEN |
67 (!enable ? REG_TIMER_SCR_VAL_0 : REG_TIMER_SCR_VAL_1);