Landfall

Annotated pkg/devices/input/src/server/input-event-server.cc

153:929b5f0a63e4
16 months ago Paul Boddie Converted the remaining code to use libipc and generated IPC components. idl4re-libipc-libsystypes
paul@153 1
/*
paul@153 2
 * Provide access to keypad events on the configured device.
paul@153 3
 *
paul@153 4
 * Copyright (C) 2018, 2023 Paul Boddie <paul@boddie.org.uk>
paul@153 5
 *
paul@153 6
 * This program is free software; you can redistribute it and/or
paul@153 7
 * modify it under the terms of the GNU General Public License as
paul@153 8
 * published by the Free Software Foundation; either version 2 of
paul@153 9
 * the License, or (at your option) any later version.
paul@153 10
 *
paul@153 11
 * This program is distributed in the hope that it will be useful,
paul@153 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@153 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@153 14
 * GNU General Public License for more details.
paul@153 15
 *
paul@153 16
 * You should have received a copy of the GNU General Public License
paul@153 17
 * along with this program; if not, write to the Free Software
paul@153 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@153 19
 * Boston, MA  02110-1301, USA
paul@153 20
 */
paul@153 21
paul@153 22
#include "input-event-server.h"
paul@153 23
paul@153 24
#include <l4/re/event>
paul@153 25
#include <l4/sys/irq.h>
paul@153 26
#include <l4/sys/kip.h>
paul@153 27
paul@153 28
paul@153 29
paul@153 30
/* Reset the buffer state and return the buffer memory capability. */
paul@153 31
paul@153 32
long Input_event_server::get_buffer(l4re_ds_t *mem)
paul@153 33
{
paul@153 34
  _events.reset();
paul@153 35
  *mem = _mem;
paul@153 36
  return L4_EOK;
paul@153 37
}
paul@153 38
paul@153 39
/* Obtain the interrupt capability. */
paul@153 40
paul@153 41
long Input_event_server::bind(unsigned int irqnum, l4_cap_idx_t irq)
paul@153 42
{
paul@153 43
  (void) irqnum;
paul@153 44
paul@153 45
  _irq = irq;
paul@153 46
  return L4_EOK;
paul@153 47
}
paul@153 48
paul@153 49
paul@153 50
paul@153 51
/* Event sending methods. */
paul@153 52
paul@153 53
void Input_event_server::send_event(int type, int code, int value)
paul@153 54
{
paul@153 55
  L4Re::Event_buffer::Event event;
paul@153 56
paul@153 57
  event.time = l4_kip_clock(l4re_kip());
paul@153 58
  event.payload.stream_id = 0;
paul@153 59
  event.payload.type = type;
paul@153 60
  event.payload.code = code;
paul@153 61
  event.payload.value = value;
paul@153 62
paul@153 63
  /* Queue the event and trigger the interrupt. */
paul@153 64
paul@153 65
  _events.put(event);
paul@153 66
  l4_irq_trigger(_irq);
paul@153 67
}