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 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.2 2004/06/03 11:27:09 bernie
31 * Add dual-license information.
33 * Revision 1.1 2004/05/23 18:36:05 bernie
34 * Import buzzerled driver.
38 #include "buzzerled.h"
41 #if defined(__m56800__)
42 #include "buzzerled_dsp56k.h"
44 #error Unsupported architecture
47 static struct Timer timers[NUM_BLDS];
48 static bool timer_go[NUM_BLDS];
50 INLINE enum BLD_DEVICE hook_parm_to_device(void* parm)
52 struct Timer* t = (struct Timer*)parm;
53 int num_bld = t - &timers[0];
56 ASSERT(num_bld < NUM_BLDS);
58 return (enum BLD_DEVICE)num_bld;
61 static void hook_turn_off(void* parm)
63 enum BLD_DEVICE num_bld = hook_parm_to_device(parm);
64 bld_set(num_bld, false);
72 void bld_set(enum BLD_DEVICE device, bool enable)
74 bld_hw_set(device, enable);
77 void bld_beep(enum BLD_DEVICE device, uint16_t duration)
79 struct Timer* t = &timers[device];
80 timer_set_delay(t, duration);
81 timer_set_event_softint(t, hook_turn_off, t);
84 bld_set(device, true);
87 void bld_beep_and_wait(enum BLD_DEVICE device, uint16_t duration)
89 bld_set(device, true);
90 timer_delay(duration);
91 bld_set(device, false);