4 * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2004 Giovanni Bajo
6 * This file is part of DevLib - See README.devlib for information.
9 * \brief Generic library to handle buzzers and leds
11 * This library is divided into three different layers:
13 * - The topmost portable layer is buzzerled.[ch] which exposes a common API
14 * enable/disable the devices. Basically, it handles the asynchronism to
15 * implement bld_beep and bld_repeat.
16 * - The middle layer is CPU-specific and exposes a single main function which
17 * turns on/off each device.
18 * - The lower layer is board-specific and communicates with the middle layer
19 * with any required API. The idea is that devices can be tied to the CPU in
20 * many different ways (many different pins), so this part should describe
21 * which devices are present, and how they are connected.
25 * \author Giovanni Bajo <rasky@develer.com>
30 *#* Revision 1.7 2006/07/19 12:56:25 bernie
31 *#* Convert to new Doxygen style.
33 *#* Revision 1.6 2005/11/04 16:20:02 bernie
34 *#* Fix reference to README.devlib in header.
36 *#* Revision 1.5 2004/12/08 09:43:41 bernie
39 *#* Revision 1.4 2004/08/25 14:12:08 rasky
40 *#* Aggiornato il comment block dei log RCS
42 *#* Revision 1.3 2004/07/14 14:04:29 rasky
43 *#* Merge da SC: spostata bld_set inline perché si ottimizza parecchio tramite propagazione di costanti
45 *#* Revision 1.2 2004/06/03 11:27:09 bernie
46 *#* Add dual-license information.
48 *#* Revision 1.1 2004/05/23 18:36:05 bernie
49 *#* Import buzzerled driver.
53 #include "buzzerled.h"
56 static struct Timer timers[NUM_BLDS];
57 static bool timer_go[NUM_BLDS];
59 INLINE enum BLD_DEVICE hook_parm_to_device(void* parm)
61 struct Timer* t = (struct Timer*)parm;
62 int num_bld = t - &timers[0];
65 ASSERT(num_bld < NUM_BLDS);
67 return (enum BLD_DEVICE)num_bld;
70 static void hook_turn_off(void* parm)
72 enum BLD_DEVICE num_bld = hook_parm_to_device(parm);
73 bld_set(num_bld, false);
81 void bld_beep(enum BLD_DEVICE device, uint16_t duration)
83 // \todo This is not reentrant for the same device. FIXME!
84 struct Timer *t = &timers[device];
85 timer_set_delay(t, duration);
86 timer_set_event_softint(t, hook_turn_off, t);
89 bld_set(device, true);
92 void bld_beep_and_wait(enum BLD_DEVICE device, uint16_t duration)
94 bld_set(device, true);
95 timer_delay(duration);
96 bld_set(device, false);