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.5 2005/04/11 19:10:27 bernie
19 *#* Include top-level headers from cfg/ subdir.
21 *#* Revision 1.4 2004/11/16 21:54:43 bernie
22 *#* Changes for SC Monoboard support.
24 *#* Revision 1.3 2004/08/25 14:12:08 rasky
25 *#* Aggiornato il comment block dei log RCS
27 *#* Revision 1.2 2004/06/03 11:27:09 bernie
28 *#* Add dual-license information.
30 *#* Revision 1.1 2004/05/23 18:36:05 bernie
31 *#* Import buzzerled driver.
35 #ifndef DRV_BUZZERLED_DSP56K_H
36 #define DRV_BUZZERLED_DSP56K_H
38 #include <cfg/compiler.h>
45 * \name Connection of the leds to the DSP:
48 * ---------------------------
55 INLINE bool bld_is_inverted_intensity(enum BLD_DEVICE device)
57 return (device == BLD_GREEN_LED
58 || device == BLD_YELLOW_LED
59 || device == BLD_RED_LED);
62 INLINE bool bld_is_pwm(enum BLD_DEVICE device)
64 // Only the buzzer is connected to a PWM
65 return (device == BLD_BUZZER || device == BLD_READY_LED);
68 INLINE bool bld_is_timer(enum BLD_DEVICE device)
70 // LEDs are connected to timers
71 return (device == BLD_GREEN_LED || device == BLD_YELLOW_LED || device == BLD_RED_LED);
74 INLINE uint16_t bld_get_pwm(enum BLD_DEVICE device)
79 case BLD_BUZZER: return 5; // PWMA5
80 case BLD_READY_LED: return 9; // PWMB3
85 INLINE struct REG_TIMER_STRUCT* bld_get_timer(enum BLD_DEVICE device)
90 case BLD_GREEN_LED: return ®_TIMER_B[2];
91 case BLD_RED_LED: return ®_TIMER_B[1];
92 case BLD_YELLOW_LED: return ®_TIMER_B[3];
96 INLINE void bld_hw_init(void)
100 INLINE void bld_hw_set(enum BLD_DEVICE device, bool enable)
102 if (bld_is_inverted_intensity(device))
105 // Handle a BLD connected to a PWM
106 if (bld_is_pwm(device))
108 struct PWM* pwm = pwm_get_handle(bld_get_pwm(device));
110 pwm_set_enable(pwm, false);
111 pwm_set_dutycycle_percent(pwm, (enable ? 50 : 0));
112 pwm_set_enable(pwm, true);
114 else if (bld_is_timer(device))
116 struct REG_TIMER_STRUCT* timer = bld_get_timer(device);
118 // Check that the timer is currently stopped, and the OFLAG is not
119 // controlled by another timer. Otherwise, the led is already
120 // controlled by the timer, and we cannot correctly set it
121 // on/off without reprogramming the timer.
122 ASSERT((timer->CTRL & REG_TIMER_CTRL_MODE_MASK) == REG_TIMER_CTRL_MODE_STOP);
123 ASSERT(!(timer->SCR & REG_TIMER_SCR_EEOF));
125 // Check also that polarity is correct
126 ASSERT(!(timer->SCR & REG_TIMER_SCR_OPS));
128 // Without programming the timer, we have a way to manually force a certain
129 // value on the external pin. We also need to enable the output pin.
130 timer->SCR &= ~REG_TIMER_SCR_VAL_1;
131 timer->SCR |= REG_TIMER_SCR_OEN |
132 REG_TIMER_SCR_FORCE |
133 (!enable ? REG_TIMER_SCR_VAL_0 : REG_TIMER_SCR_VAL_1);
141 // We do not need inline functions here, because constant propagation is not big deal here
142 void bld_hw_init(void);
143 void bld_hw_set(enum BLD_DEVICE device, bool enable);
147 #endif /* DRV_BUZZERLED_DSP56K_H */