Aggiornato il comment block dei log RCS
[bertos.git] / drv / buzzerled_dsp56k.h
1 /*!
2  * \file
3  * <!--
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.
7  * -->
8  *
9  * \brief Hardware support for buzzers and leds in DSP56K-based boards
10  *
11  * \version $Id$
12  *
13  * \author Giovanni Bajo <rasky@develer.com>
14  */
15
16 /*#*
17  *#* $Log$
18  *#* Revision 1.3  2004/08/25 14:12:08  rasky
19  *#* Aggiornato il comment block dei log RCS
20  *#*
21  *#* Revision 1.2  2004/06/03 11:27:09  bernie
22  *#* Add dual-license information.
23  *#*
24  *#* Revision 1.1  2004/05/23 18:36:05  bernie
25  *#* Import buzzerled driver.
26  *#*
27  *#*/
28
29 #include <compiler.h>
30 #include <hw.h>
31 #include "pwm.h"
32
33 INLINE void bld_hw_init(void)
34 {
35 }
36
37 INLINE void bld_hw_set(enum BLD_DEVICE device, bool enable)
38 {
39         if (bld_is_inverted_intensity(device))
40                 enable = !enable;
41
42         // Handle a BLD connected to a PWM
43         if (bld_is_pwm(device))
44         {
45                 struct PWM* pwm = pwm_get_handle(bld_get_pwm(device));
46
47                 pwm_set_enable(pwm, false);
48                 pwm_set_dutycycle_percent(pwm, (enable ? 50 : 0));
49                 pwm_set_enable(pwm, true);
50         }
51         else if (bld_is_timer(device))
52         {
53                 struct REG_TIMER_STRUCT* timer = bld_get_timer(device);
54
55                 // Check that the timer is currently stopped, and the OFLAG is not
56                 //  controlled by another timer. Otherwise, the led is already 
57                 //  controlled by the timer, and we cannot correctly set it 
58                 //  on/off without reprogramming the timer.
59                 ASSERT((timer->CTRL & REG_TIMER_CTRL_MODE_MASK) == REG_TIMER_CTRL_MODE_STOP);
60                 ASSERT(!(timer->SCR & REG_TIMER_SCR_EEOF));
61
62                 // Check also that polarity is correct
63                 ASSERT(!(timer->SCR & REG_TIMER_SCR_OPS));
64
65                 // Without programming the timer, we have a way to manually force a certain
66                 //  value on the external pin. We also need to enable the output pin.
67                 timer->SCR &= ~REG_TIMER_SCR_VAL_1;
68                 timer->SCR |= REG_TIMER_SCR_OEN |
69                               REG_TIMER_SCR_FORCE |
70                               (!enable ? REG_TIMER_SCR_VAL_0 : REG_TIMER_SCR_VAL_1);
71         }
72         else
73                 ASSERT(0);
74 }
75