--- /dev/null
+/*!
+ * \file
+ * <!--
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Giovanni Bajo
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Generic library to handle buzzers and leds
+ *
+ * This library is divided into three different layers:
+ *
+ * - The topmost portable layer is buzzerled.[ch] which exposes a common API
+ * enable/disable the devices. Basically, it handles the asynchronism to
+ * implement bld_beep and bld_repeat.
+ * - The middle layer is CPU-specific and exposes a single main function which
+ * turns on/off each device.
+ * - The lower layer is board-specific and communicates with the middle layer
+ * with any required API. The idea is that devices can be tied to the CPU in
+ * many different ways (many different pins), so this part should describe
+ * which devices are present, and how they are connected.
+ *
+ * \version $Id$
+ *
+ * \author Giovanni Bajo <rasky@develer.com>
+ */
+
+/*
+ * $Log$
+ * Revision 1.1 2004/05/23 18:36:05 bernie
+ * Import buzzerled driver.
+ *
+ */
+
+#include "buzzerled.h"
+#include "timer.h"
+
+#if defined(__m56800__)
+ #include "buzzerled_dsp56k.h"
+#else
+ #error Unsupported architecture
+#endif
+
+static struct Timer timers[NUM_BLDS];
+static bool timer_go[NUM_BLDS];
+
+INLINE enum BLD_DEVICE hook_parm_to_device(void* parm)
+{
+ struct Timer* t = (struct Timer*)parm;
+ int num_bld = t - &timers[0];
+
+ ASSERT(num_bld >= 0);
+ ASSERT(num_bld < NUM_BLDS);
+
+ return (enum BLD_DEVICE)num_bld;
+}
+
+static void hook_turn_off(void* parm)
+{
+ enum BLD_DEVICE num_bld = hook_parm_to_device(parm);
+ bld_set(num_bld, false);
+}
+
+void bld_init(void)
+{
+ bld_hw_init();
+}
+
+void bld_set(enum BLD_DEVICE device, bool enable)
+{
+ bld_hw_set(device, enable);
+}
+
+void bld_beep(enum BLD_DEVICE device, uint16_t duration)
+{
+ struct Timer* t = &timers[device];
+ timer_set_delay(t, duration);
+ timer_set_event_softint(t, hook_turn_off, t);
+ timer_add(t);
+
+ bld_set(device, true);
+}
+
+void bld_beep_and_wait(enum BLD_DEVICE device, uint16_t duration)
+{
+ bld_set(device, true);
+ timer_delay(duration);
+ bld_set(device, false);
+}
+
--- /dev/null
+/*!
+ * \file
+ * <!--
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Giovanni Bajo
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Generic library to handle buzzers and leds
+ *
+ * \version $Id$
+ *
+ * \author Giovanni Bajo <rasky@develer.com>
+ */
+
+/*
+ * $Log$
+ * Revision 1.1 2004/05/23 18:36:05 bernie
+ * Import buzzerled driver.
+ *
+ */
+
+#ifndef DRV_BUZZERLED_H
+#define DRV_BUZZERLED_H
+
+/*! Include hw.h. We expect hw.h to define enum BLD_DEVICE, which must contain
+ * an enumarator for each device, plus a special symbol NUM_BLDS containing the
+ * number of devices.
+ */
+#include <hw.h>
+
+/*! Initialize the buzzerled library.
+ *
+ * \note This function must be called before any other function in the library.
+ */
+void bld_init(void);
+
+/*! Set or reset a device.
+ *
+ * \param device Device to be set
+ * \param enable Enable/disable status
+ */
+void bld_set(enum BLD_DEVICE device, bool enable);
+
+/*! Enable a device for a certain interval of time
+ *
+ * \param device Device to be enabled
+ * \param duration Number of milliseconds the device must be enabled
+ *
+ * \note This function is non-blocking, so it will return immediately.
+ */
+void bld_beep(enum BLD_DEVICE device, uint16_t duration);
+
+
+/*! Enable a device for a certain interval of time and wait.
+ *
+ * \param device Device to be enabled
+ * \param duration Number of milliseconds the device must be enabled
+ *
+ * \note This function is blocking, so it will return after the specified period of time.
+ */
+void bld_beep_and_wait(enum BLD_DEVICE device, uint16_t duration);
+
+#endif /* DRV_BUZZERLED_H */
--- /dev/null
+/*!
+ * \file
+ * <!--
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Giovanni Bajo
+ * All Rights Reserved.
+ * -->
+ *
+ * \brief Hardware support for buzzers and leds in DSP56K-based boards
+ *
+ * \version $Id$
+ *
+ * \author Giovanni Bajo <rasky@develer.com>
+ */
+
+/*
+ * $Log$
+ * Revision 1.1 2004/05/23 18:36:05 bernie
+ * Import buzzerled driver.
+ *
+ */
+
+#include <compiler.h>
+#include <hw.h>
+#include "pwm.h"
+
+INLINE void bld_hw_init(void)
+{
+}
+
+INLINE void bld_hw_set(enum BLD_DEVICE device, bool enable)
+{
+ if (bld_is_inverted_intensity(device))
+ enable = !enable;
+
+ // Handle a BLD connected to a PWM
+ if (bld_is_pwm(device))
+ {
+ struct PWM* pwm = pwm_get_handle(bld_get_pwm(device));
+
+ pwm_set_enable(pwm, false);
+ pwm_set_dutycycle_percent(pwm, (enable ? 50 : 0));
+ pwm_set_enable(pwm, true);
+ }
+ else if (bld_is_timer(device))
+ {
+ struct REG_TIMER_STRUCT* timer = bld_get_timer(device);
+
+ // Check that the timer is currently stopped, and the OFLAG is not
+ // controlled by another timer. Otherwise, the led is already
+ // controlled by the timer, and we cannot correctly set it
+ // on/off without reprogramming the timer.
+ ASSERT((timer->CTRL & REG_TIMER_CTRL_MODE_MASK) == REG_TIMER_CTRL_MODE_STOP);
+ ASSERT(!(timer->SCR & REG_TIMER_SCR_EEOF));
+
+ // Check also that polarity is correct
+ ASSERT(!(timer->SCR & REG_TIMER_SCR_OPS));
+
+ // Without programming the timer, we have a way to manually force a certain
+ // value on the external pin. We also need to enable the output pin.
+ timer->SCR &= ~REG_TIMER_SCR_VAL_1;
+ timer->SCR |= REG_TIMER_SCR_OEN |
+ REG_TIMER_SCR_FORCE |
+ (!enable ? REG_TIMER_SCR_VAL_0 : REG_TIMER_SCR_VAL_1);
+ }
+ else
+ ASSERT(0);
+}
+