1.1 --- a/pkg/devices/Makefile Sun Dec 27 00:27:16 2020 +0100
1.2 +++ b/pkg/devices/Makefile Wed Dec 30 22:48:28 2020 +0100
1.3 @@ -1,17 +1,18 @@
1.4 PKGDIR = .
1.5 L4DIR ?= $(PKGDIR)/../..
1.6
1.7 -TARGET = backlight cpm display fb input keypad lcd lib pwm spi util
1.8 +TARGET = backlight cpm display fb include input keypad lcd lib pwm spi util
1.9
1.10 include $(L4DIR)/mk/subdir.mk
1.11
1.12 # Internal dependencies.
1.13 # lib provides driver libraries
1.14 # util provides peripheral memory access
1.15 +# include provides general IPC headers
1.16
1.17 -backlight: pwm spi
1.18 +backlight: pwm spi include
1.19 cpm: lib util
1.20 -display: backlight cpm lib util
1.21 +display: backlight cpm lib util include
1.22 fb: lcd lib util
1.23 input: keypad lib
1.24 keypad: lib util
2.1 --- a/pkg/devices/backlight/src/spi-ili8960/Makefile Sun Dec 27 00:27:16 2020 +0100
2.2 +++ b/pkg/devices/backlight/src/spi-ili8960/Makefile Wed Dec 30 22:48:28 2020 +0100
2.3 @@ -3,12 +3,43 @@
2.4
2.5 TARGET = dev_backlight_spi_ili8960
2.6 MODE = shared
2.7 -PC_FILENAME := devices-backlight-spi-ili8960
2.8 +PC_FILENAME = devices-backlight-spi-ili8960
2.9 +
2.10 +# Locations for interface input and generated output.
2.11 +
2.12 +IDL_DIR = $(PKGDIR)/idl
2.13 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
2.14 +IDL_BUILD_DIR = .
2.15 +IDL_EXPORT_DIR = .
2.16
2.17 -SRC_CC := backlight-spi-ili8960.cc
2.18 +include $(IDL_MK_DIR)/idl.mk
2.19 +
2.20 +# Compound interface definitions.
2.21 +
2.22 +backlight_object_NAME = BacklightObject
2.23 +backlight_object_INTERFACES = activation backlight
2.24 +
2.25 +COMP_INTERFACES_CC = backlight_object
2.26
2.27 -PRIVATE_INCDIR += $(PKGDIR)/backlight/include
2.28 +# Individual interfaces.
2.29 +
2.30 +SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC))
2.31 +
2.32 +# Generated and plain source files.
2.33 +
2.34 +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC))
2.35
2.36 -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-spi-client
2.37 +PLAIN_SRC_CC = backlight-spi-ili8960.cc
2.38 +
2.39 +# Normal definitions.
2.40 +
2.41 +SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC)
2.42 +
2.43 +REQUIRES_LIBS = l4re_c l4re_c-util libdevice-spi-client libipc
2.44 +
2.45 +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
2.46
2.47 include $(L4DIR)/mk/prog.mk
2.48 +include $(IDL_MK_DIR)/interface_rules.mk
2.49 +
2.50 +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC)
3.1 --- a/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Sun Dec 27 00:27:16 2020 +0100
3.2 +++ b/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Wed Dec 30 22:48:28 2020 +0100
3.3 @@ -5,7 +5,7 @@
3.4 * the Giantplus GPM940B0 panel datasheet also describes this controller
3.5 * interface.
3.6 *
3.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
3.8 + * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
3.9 *
3.10 * This program is free software; you can redistribute it and/or
3.11 * modify it under the terms of the GNU General Public License as
3.12 @@ -23,15 +23,16 @@
3.13 * Boston, MA 02110-1301, USA
3.14 */
3.15
3.16 -#include <l4/cxx/ipc_server>
3.17 #include <l4/re/env>
3.18 -#include <l4/re/util/object_registry>
3.19 #include <l4/sys/capability>
3.20 +#include <l4/sys/err.h>
3.21
3.22 -#include <stdlib.h>
3.23 +#include <stdio.h>
3.24
3.25 #include <l4/devices/spi-client.h>
3.26 -#include "backlight-ops.h"
3.27 +
3.28 +#include <ipc/server.h>
3.29 +#include "backlight_object_server.h"
3.30
3.31 /* SPI access abstractions. */
3.32
3.33 @@ -41,7 +42,7 @@
3.34
3.35 /* Backlight device. */
3.36
3.37 -class Backlight_device_server : public L4::Server_object_t<L4::Kobject>
3.38 +class server_BacklightObject : public BacklightObject
3.39 {
3.40 int _min = 55, _max = 90, _start = 70;
3.41
3.42 @@ -61,57 +62,32 @@
3.43 }
3.44
3.45 public:
3.46 - /* Dispatch incoming requests. */
3.47 -
3.48 - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
3.49 - {
3.50 - l4_msgtag_t tag;
3.51 - int arg;
3.52 -
3.53 - (void) obj;
3.54 - ios >> tag;
3.55 + /* Disable the backlight. */
3.56
3.57 - switch (tag.label())
3.58 - {
3.59 - case Backlight_op_disable:
3.60 - disable();
3.61 - return L4_EOK;
3.62 -
3.63 - case Backlight_op_enable:
3.64 - enable();
3.65 - return L4_EOK;
3.66 -
3.67 - case Backlight_op_set_brightness:
3.68 - ios >> arg;
3.69 - set_brightness(arg);
3.70 - return L4_EOK;
3.71 -
3.72 - default:
3.73 - return -L4_EBADPROTO;
3.74 - }
3.75 + long disable()
3.76 + {
3.77 + spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
3.78 + return L4_EOK;
3.79 }
3.80
3.81 - void disable()
3.82 - {
3.83 - spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
3.84 - }
3.85 + /* Enable the backlight. */
3.86
3.87 - void enable()
3.88 + long enable()
3.89 {
3.90 set_duty(_start);
3.91 + return L4_EOK;
3.92 }
3.93
3.94 /* Use the SPI device to update the brightness level. */
3.95
3.96 - void set_brightness(int level)
3.97 + long set_brightness(int level)
3.98 {
3.99 level = level < _min ? _min : (level > _max ? _max : level);
3.100 spi_device->send(16, 0x0300 | level); /* R03h: brightness */
3.101 + return L4_EOK;
3.102 }
3.103 };
3.104
3.105 -static L4Re::Util::Registry_server<> server;
3.106 -
3.107
3.108
3.109 int main(void)
3.110 @@ -123,11 +99,20 @@
3.111
3.112 /* Initialise and register a new server object. */
3.113
3.114 - Backlight_device_server server_obj;
3.115 - server.registry()->register_obj(&server_obj, "backlight");
3.116 + server_BacklightObject obj;
3.117 + l4_cap_idx_t server;
3.118 +
3.119 + long err = ipc_server_bind("backlight", (l4_umword_t) &obj, &server);
3.120 +
3.121 + if (err)
3.122 + {
3.123 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
3.124 + return 1;
3.125 + }
3.126
3.127 /* Enter the IPC server loop. */
3.128
3.129 - server.loop();
3.130 + ipc_server_loop(BacklightObject_expected_items, &obj,
3.131 + (ipc_server_handler_type) handle_BacklightObject);
3.132 return 0;
3.133 }
4.1 --- a/pkg/devices/display/src/qi_lb60/Makefile Sun Dec 27 00:27:16 2020 +0100
4.2 +++ b/pkg/devices/display/src/qi_lb60/Makefile Wed Dec 30 22:48:28 2020 +0100
4.3 @@ -3,12 +3,36 @@
4.4
4.5 TARGET = dev_display_qi_lb60
4.6 MODE = shared
4.7 -PC_FILENAME := devices-display-qi_lb60
4.8 +PC_FILENAME = devices-display-qi_lb60
4.9 +
4.10 +# Locations for interface input and generated output.
4.11
4.12 -SRC_CC := display-qi_lb60.cc
4.13 +IDL_DIR = $(PKGDIR)/idl
4.14 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
4.15 +IDL_BUILD_DIR = .
4.16 +IDL_EXPORT_DIR = .
4.17 +
4.18 +include $(IDL_MK_DIR)/idl.mk
4.19 +
4.20 +# Individual interfaces.
4.21
4.22 -PRIVATE_INCDIR += $(PKGDIR)/display/include
4.23 +CLIENT_INTERFACES_CC = activation
4.24 +
4.25 +# Generated and plain source files.
4.26 +
4.27 +CLIENT_INTERFACES_SRC_CC = $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC))
4.28 +
4.29 +PLAIN_SRC_CC = display-qi_lb60.cc
4.30
4.31 -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-backlight-client libdrivers-lcd-jz4740 libdrivers-gpio libdevice-util
4.32 +# Normal definitions.
4.33 +
4.34 +SRC_CC = $(CLIENT_INTERFACES_SRC_CC) $(PLAIN_SRC_CC)
4.35 +
4.36 +REQUIRES_LIBS = l4re_c l4re_c-util libdrivers-lcd-jz4740 libdrivers-gpio libdevice-util libipc
4.37 +
4.38 +PRIVATE_INCDIR = $(PKGDIR)/display/include $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
4.39
4.40 include $(L4DIR)/mk/prog.mk
4.41 +include $(IDL_MK_DIR)/interface_rules.mk
4.42 +
4.43 +$(PLAIN_SRC_CC): $(CLIENT_INTERFACES_SRC_CC)
5.1 --- a/pkg/devices/display/src/qi_lb60/display-qi_lb60.cc Sun Dec 27 00:27:16 2020 +0100
5.2 +++ b/pkg/devices/display/src/qi_lb60/display-qi_lb60.cc Wed Dec 30 22:48:28 2020 +0100
5.3 @@ -1,7 +1,7 @@
5.4 /*
5.5 * Export Ben NanoNote display operations as a server.
5.6 *
5.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
5.8 + * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
5.9 *
5.10 * This program is free software; you can redistribute it and/or
5.11 * modify it under the terms of the GNU General Public License as
5.12 @@ -20,26 +20,26 @@
5.13 */
5.14
5.15 #include <l4/devices/gpio-jz4740.h>
5.16 -#include <l4/devices/backlight-client.h>
5.17 #include <l4/devices/lcd-jz4740-config.h>
5.18 #include <l4/devices/lcd-jz4740-panel.h>
5.19 #include <l4/devices/memory.h>
5.20
5.21 #include <l4/cxx/ipc_server>
5.22 #include <l4/re/env>
5.23 +#include <l4/re/env.h>
5.24 #include <l4/re/util/object_registry>
5.25 #include <l4/sys/capability>
5.26
5.27 +#include "activation_client.h"
5.28 #include "display-ops.h"
5.29
5.30 /* Virtual address for the GPIO register block. */
5.31
5.32 static l4_addr_t gpio_virt_base = 0, gpio_virt_base_end = 0;
5.33
5.34 -/* GPIO and backlight device abstractions. */
5.35 +/* GPIO abstraction. */
5.36
5.37 static Gpio_jz4740_chip *gpio_port_c = 0;
5.38 -static L4::Cap<Backlight_device_interface> backlight_device;
5.39
5.40
5.41
5.42 @@ -76,7 +76,14 @@
5.43 Pin_slice slcd8_mask = {.offset=0, .mask=(1 << Jz4740_lcd_gpio_cs) | (1 << Jz4740_lcd_gpio_rs) |
5.44 (1 << Jz4740_lcd_gpio_clk) | Jz4740_lcd_gpio_d0_d7};
5.45
5.46 + Activation *_backlight;
5.47 +
5.48 public:
5.49 + explicit Display_device_server(Activation *backlight)
5.50 + : _backlight(backlight)
5.51 + {
5.52 + }
5.53 +
5.54 /* Dispatch incoming requests. */
5.55
5.56 int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
5.57 @@ -108,7 +115,7 @@
5.58 /* Configure SLCD8 pins. */
5.59
5.60 gpio_port_c->multi_setup(slcd8_mask, Hw::Gpio_chip::Input, 0);
5.61 - backlight_device->disable();
5.62 + _backlight->disable();
5.63 }
5.64
5.65 /* Switch the display on. */
5.66 @@ -118,7 +125,7 @@
5.67 /* Configure SLCD8 pins. */
5.68
5.69 gpio_port_c->multi_config_pad(slcd8_mask, Hw::Gpio_chip::Function_alt, 0);
5.70 - backlight_device->enable();
5.71 + _backlight->enable();
5.72 }
5.73 };
5.74
5.75 @@ -138,12 +145,16 @@
5.76
5.77 /* Obtain a reference to the backlight device. */
5.78
5.79 - backlight_device = L4Re::Env::env()->get_cap<Backlight_device_interface>("backlight");
5.80 - if (!backlight_device.is_valid()) return 1;
5.81 + l4_cap_idx_t backlight = l4re_env_get_cap("backlight");
5.82 + if (!l4_is_valid_cap(backlight)) return 1;
5.83 +
5.84 + /* Use the activation interface with the backlight. */
5.85 +
5.86 + client_Activation backlight_obj(backlight);
5.87
5.88 /* Initialise and register a new server object. */
5.89
5.90 - Display_device_server server_obj;
5.91 + Display_device_server server_obj(&backlight_obj);
5.92 server.registry()->register_obj(&server_obj, "display");
5.93
5.94 /* Enter the IPC server loop. */
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/pkg/devices/idl/activation.idl Wed Dec 30 22:48:28 2020 +0100
6.3 @@ -0,0 +1,9 @@
6.4 +#include <l4/devices/protocols.h>
6.5 +
6.6 +[protocol(LANDFALL_ACTIVATION)]
6.7 +interface Activation
6.8 +{
6.9 + void disable();
6.10 +
6.11 + void enable();
6.12 +};
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/pkg/devices/idl/backlight.idl Wed Dec 30 22:48:28 2020 +0100
7.3 @@ -0,0 +1,10 @@
7.4 +#include <l4/devices/protocols.h>
7.5 +
7.6 +/* A backlight interface. Backlights may also support the Activation
7.7 + interface. */
7.8 +
7.9 +[protocol(LANDFALL_BACKLIGHT)]
7.10 +interface Backlight
7.11 +{
7.12 + void set_brightness(in int level);
7.13 +};
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/pkg/devices/include/Makefile Wed Dec 30 22:48:28 2020 +0100
8.3 @@ -0,0 +1,4 @@
8.4 +PKGDIR = ..
8.5 +L4DIR ?= $(PKGDIR)/../..
8.6 +
8.7 +include $(L4DIR)/mk/include.mk
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/pkg/devices/include/protocols.h Wed Dec 30 22:48:28 2020 +0100
9.3 @@ -0,0 +1,25 @@
9.4 +/*
9.5 + * Interface protocols.
9.6 + *
9.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
9.8 + *
9.9 + * This program is free software; you can redistribute it and/or
9.10 + * modify it under the terms of the GNU General Public License as
9.11 + * published by the Free Software Foundation; either version 2 of
9.12 + * the License, or (at your option) any later version.
9.13 + *
9.14 + * This program is distributed in the hope that it will be useful,
9.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.17 + * GNU General Public License for more details.
9.18 + *
9.19 + * You should have received a copy of the GNU General Public License
9.20 + * along with this program; if not, write to the Free Software
9.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
9.22 + * Boston, MA 02110-1301, USA
9.23 + */
9.24 +
9.25 +#pragma once
9.26 +
9.27 +#define LANDFALL_ACTIVATION 0x1f01
9.28 +#define LANDFALL_BACKLIGHT 0x1f02