1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-11-16 21:23:42 +02:00
iris/source/buzzer.ccp

98 lines
2.6 KiB
Plaintext
Raw Normal View History

2009-10-04 20:47:20 +03:00
#pypp 0
// Iris: micro-kernel for a capability-based operating system.
// boot-programs/buzzer.ccp: Piezo buzzer driver.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "devices.hh"
#define ARCH
#include "arch.hh"
class DevBuzzer:
static unsigned const pwm = 4
Iris::Cap event
2009-10-10 02:31:10 +03:00
bool is_beeping
2009-10-04 20:47:20 +03:00
public:
DevBuzzer ():
is_beeping = false
tcu_stop_counter (pwm)
2009-12-18 10:00:38 +02:00
tcu_select_extalclk (pwm)
2009-10-04 20:47:20 +03:00
tcu_select_clk_div64 (pwm)
tcu_enable_pwm_output (pwm)
void stop ():
if !is_beeping:
return
tcu_stop_counter (pwm)
event.invoke ()
Iris::free_cap (event)
2009-10-10 02:31:10 +03:00
is_beeping = false
void beep (unsigned freq, unsigned ms, Iris::Cap cb):
2009-10-04 20:47:20 +03:00
stop ()
event = cb
unsigned full = JZ_EXTAL / 64 / freq
tcu_set_full_data (pwm, full)
tcu_set_half_data (pwm, full / 2)
tcu_set_count (pwm, 0)
tcu_start_counter (pwm)
Iris::my_receiver.set_alarm (ms * HZ / 1000)
2009-10-04 20:47:20 +03:00
is_beeping = true
enum codes:
BUZZER = 32
Iris::Num start ():
2009-10-04 20:47:20 +03:00
map_tcu ()
DevBuzzer buzzer
2010-05-05 02:09:32 +03:00
Iris::Buzzer dev = Iris::my_receiver.create_capability (BUZZER)
Iris::my_parent.provide_capability <Iris::Buzzer> (dev.copy ())
Iris::free_cap (dev)
Iris::my_parent.init_done ()
2009-10-04 20:47:20 +03:00
while true:
Iris::wait ()
2010-05-05 02:09:32 +03:00
if Iris::recv.protected_data.h == ~0:
// Alarm.
buzzer.stop ()
continue
2010-05-05 02:09:32 +03:00
switch Iris::recv.protected_data.l:
2009-10-04 20:47:20 +03:00
case BUZZER:
// Buzzer device user request.
switch Iris::recv.data[0].l:
2010-05-05 02:09:32 +03:00
case Iris::Device::RESET:
buzzer.stop ()
Iris::recv.reply.invoke ()
break
case Iris::Buzzer::BEEP:
2009-10-10 02:31:10 +03:00
// Volume is not used by this buzzer.
Iris::Cap arg = Iris::get_arg ()
Iris::Cap reply = Iris::get_reply ()
buzzer.beep (Iris::recv.data[1].l, Iris::recv.data[1].h, arg)
2009-10-04 20:47:20 +03:00
reply.invoke ()
Iris::free_cap (reply)
2009-10-04 20:47:20 +03:00
break
case Iris::Buzzer::STOP:
2009-10-04 20:47:20 +03:00
buzzer.stop ()
Iris::recv.reply.invoke ()
2009-10-04 20:47:20 +03:00
break
default:
2009-12-27 01:12:35 +02:00
kdebug ("Buzzer: other\n")
2009-10-04 20:47:20 +03:00
break
break
default:
2009-12-27 01:12:35 +02:00
kdebug ("Buzzer: unknown num: ")
2010-05-05 02:09:32 +03:00
kdebug_num (Iris::recv.protected_data.l)
2009-10-04 20:47:20 +03:00
kdebug ("\n")