# HG changeset patch # User Paul Boddie # Date 1609364908 -3600 # Node ID 06667c54641063e65d05778298bcc98ef086ec04 # Parent 2a6150981419c6f4f6d1cd0b1a12149443755f88 Introduced interface descriptions and tool usage for the Ben NanoNote backlight. diff -r 2a6150981419 -r 06667c546410 pkg/devices/Makefile --- a/pkg/devices/Makefile Sun Dec 27 00:27:16 2020 +0100 +++ b/pkg/devices/Makefile Wed Dec 30 22:48:28 2020 +0100 @@ -1,17 +1,18 @@ PKGDIR = . L4DIR ?= $(PKGDIR)/../.. -TARGET = backlight cpm display fb input keypad lcd lib pwm spi util +TARGET = backlight cpm display fb include input keypad lcd lib pwm spi util include $(L4DIR)/mk/subdir.mk # Internal dependencies. # lib provides driver libraries # util provides peripheral memory access +# include provides general IPC headers -backlight: pwm spi +backlight: pwm spi include cpm: lib util -display: backlight cpm lib util +display: backlight cpm lib util include fb: lcd lib util input: keypad lib keypad: lib util diff -r 2a6150981419 -r 06667c546410 pkg/devices/backlight/src/spi-ili8960/Makefile --- a/pkg/devices/backlight/src/spi-ili8960/Makefile Sun Dec 27 00:27:16 2020 +0100 +++ b/pkg/devices/backlight/src/spi-ili8960/Makefile Wed Dec 30 22:48:28 2020 +0100 @@ -3,12 +3,43 @@ TARGET = dev_backlight_spi_ili8960 MODE = shared -PC_FILENAME := devices-backlight-spi-ili8960 +PC_FILENAME = devices-backlight-spi-ili8960 + +# Locations for interface input and generated output. + +IDL_DIR = $(PKGDIR)/idl +IDL_MK_DIR = $(L4DIR)/idl4re/mk +IDL_BUILD_DIR = . +IDL_EXPORT_DIR = . -SRC_CC := backlight-spi-ili8960.cc +include $(IDL_MK_DIR)/idl.mk + +# Compound interface definitions. + +backlight_object_NAME = BacklightObject +backlight_object_INTERFACES = activation backlight + +COMP_INTERFACES_CC = backlight_object -PRIVATE_INCDIR += $(PKGDIR)/backlight/include +# Individual interfaces. + +SERVER_INTERFACES_CC = $(call common_interfaces,$(COMP_INTERFACES_CC)) + +# Generated and plain source files. + +SERVER_INTERFACES_SRC_CC = $(call interfaces_to_server_cc,$(SERVER_INTERFACES_CC) $(COMP_INTERFACES_CC)) -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-spi-client +PLAIN_SRC_CC = backlight-spi-ili8960.cc + +# Normal definitions. + +SRC_CC = $(SERVER_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) + +REQUIRES_LIBS = l4re_c l4re_c-util libdevice-spi-client libipc + +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) include $(L4DIR)/mk/prog.mk +include $(IDL_MK_DIR)/interface_rules.mk + +$(PLAIN_SRC_CC): $(SERVER_INTERFACES_SRC_CC) diff -r 2a6150981419 -r 06667c546410 pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc --- a/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Sun Dec 27 00:27:16 2020 +0100 +++ b/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Wed Dec 30 22:48:28 2020 +0100 @@ -5,7 +5,7 @@ * the Giantplus GPM940B0 panel datasheet also describes this controller * interface. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2018, 2020 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -23,15 +23,16 @@ * Boston, MA 02110-1301, USA */ -#include #include -#include #include +#include -#include +#include #include -#include "backlight-ops.h" + +#include +#include "backlight_object_server.h" /* SPI access abstractions. */ @@ -41,7 +42,7 @@ /* Backlight device. */ -class Backlight_device_server : public L4::Server_object_t +class server_BacklightObject : public BacklightObject { int _min = 55, _max = 90, _start = 70; @@ -61,57 +62,32 @@ } public: - /* Dispatch incoming requests. */ - - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) - { - l4_msgtag_t tag; - int arg; - - (void) obj; - ios >> tag; + /* Disable the backlight. */ - switch (tag.label()) - { - case Backlight_op_disable: - disable(); - return L4_EOK; - - case Backlight_op_enable: - enable(); - return L4_EOK; - - case Backlight_op_set_brightness: - ios >> arg; - set_brightness(arg); - return L4_EOK; - - default: - return -L4_EBADPROTO; - } + long disable() + { + spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */ + return L4_EOK; } - void disable() - { - spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */ - } + /* Enable the backlight. */ - void enable() + long enable() { set_duty(_start); + return L4_EOK; } /* Use the SPI device to update the brightness level. */ - void set_brightness(int level) + long set_brightness(int level) { level = level < _min ? _min : (level > _max ? _max : level); spi_device->send(16, 0x0300 | level); /* R03h: brightness */ + return L4_EOK; } }; -static L4Re::Util::Registry_server<> server; - int main(void) @@ -123,11 +99,20 @@ /* Initialise and register a new server object. */ - Backlight_device_server server_obj; - server.registry()->register_obj(&server_obj, "backlight"); + server_BacklightObject obj; + l4_cap_idx_t server; + + long err = ipc_server_bind("backlight", (l4_umword_t) &obj, &server); + + if (err) + { + printf("Could not bind server: %s\n", l4sys_errtostr(err)); + return 1; + } /* Enter the IPC server loop. */ - server.loop(); + ipc_server_loop(BacklightObject_expected_items, &obj, + (ipc_server_handler_type) handle_BacklightObject); return 0; } diff -r 2a6150981419 -r 06667c546410 pkg/devices/display/src/qi_lb60/Makefile --- a/pkg/devices/display/src/qi_lb60/Makefile Sun Dec 27 00:27:16 2020 +0100 +++ b/pkg/devices/display/src/qi_lb60/Makefile Wed Dec 30 22:48:28 2020 +0100 @@ -3,12 +3,36 @@ TARGET = dev_display_qi_lb60 MODE = shared -PC_FILENAME := devices-display-qi_lb60 +PC_FILENAME = devices-display-qi_lb60 + +# Locations for interface input and generated output. -SRC_CC := display-qi_lb60.cc +IDL_DIR = $(PKGDIR)/idl +IDL_MK_DIR = $(L4DIR)/idl4re/mk +IDL_BUILD_DIR = . +IDL_EXPORT_DIR = . + +include $(IDL_MK_DIR)/idl.mk + +# Individual interfaces. -PRIVATE_INCDIR += $(PKGDIR)/display/include +CLIENT_INTERFACES_CC = activation + +# Generated and plain source files. + +CLIENT_INTERFACES_SRC_CC = $(call interfaces_to_client_cc,$(CLIENT_INTERFACES_CC)) + +PLAIN_SRC_CC = display-qi_lb60.cc -REQUIRES_LIBS := l4re_c l4re_c-util libdevice-backlight-client libdrivers-lcd-jz4740 libdrivers-gpio libdevice-util +# Normal definitions. + +SRC_CC = $(CLIENT_INTERFACES_SRC_CC) $(PLAIN_SRC_CC) + +REQUIRES_LIBS = l4re_c l4re_c-util libdrivers-lcd-jz4740 libdrivers-gpio libdevice-util libipc + +PRIVATE_INCDIR = $(PKGDIR)/display/include $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR) include $(L4DIR)/mk/prog.mk +include $(IDL_MK_DIR)/interface_rules.mk + +$(PLAIN_SRC_CC): $(CLIENT_INTERFACES_SRC_CC) diff -r 2a6150981419 -r 06667c546410 pkg/devices/display/src/qi_lb60/display-qi_lb60.cc --- a/pkg/devices/display/src/qi_lb60/display-qi_lb60.cc Sun Dec 27 00:27:16 2020 +0100 +++ b/pkg/devices/display/src/qi_lb60/display-qi_lb60.cc Wed Dec 30 22:48:28 2020 +0100 @@ -1,7 +1,7 @@ /* * Export Ben NanoNote display operations as a server. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2018, 2020 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,26 +20,26 @@ */ #include -#include #include #include #include #include #include +#include #include #include +#include "activation_client.h" #include "display-ops.h" /* Virtual address for the GPIO register block. */ static l4_addr_t gpio_virt_base = 0, gpio_virt_base_end = 0; -/* GPIO and backlight device abstractions. */ +/* GPIO abstraction. */ static Gpio_jz4740_chip *gpio_port_c = 0; -static L4::Cap backlight_device; @@ -76,7 +76,14 @@ Pin_slice slcd8_mask = {.offset=0, .mask=(1 << Jz4740_lcd_gpio_cs) | (1 << Jz4740_lcd_gpio_rs) | (1 << Jz4740_lcd_gpio_clk) | Jz4740_lcd_gpio_d0_d7}; + Activation *_backlight; + public: + explicit Display_device_server(Activation *backlight) + : _backlight(backlight) + { + } + /* Dispatch incoming requests. */ int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios) @@ -108,7 +115,7 @@ /* Configure SLCD8 pins. */ gpio_port_c->multi_setup(slcd8_mask, Hw::Gpio_chip::Input, 0); - backlight_device->disable(); + _backlight->disable(); } /* Switch the display on. */ @@ -118,7 +125,7 @@ /* Configure SLCD8 pins. */ gpio_port_c->multi_config_pad(slcd8_mask, Hw::Gpio_chip::Function_alt, 0); - backlight_device->enable(); + _backlight->enable(); } }; @@ -138,12 +145,16 @@ /* Obtain a reference to the backlight device. */ - backlight_device = L4Re::Env::env()->get_cap("backlight"); - if (!backlight_device.is_valid()) return 1; + l4_cap_idx_t backlight = l4re_env_get_cap("backlight"); + if (!l4_is_valid_cap(backlight)) return 1; + + /* Use the activation interface with the backlight. */ + + client_Activation backlight_obj(backlight); /* Initialise and register a new server object. */ - Display_device_server server_obj; + Display_device_server server_obj(&backlight_obj); server.registry()->register_obj(&server_obj, "display"); /* Enter the IPC server loop. */ diff -r 2a6150981419 -r 06667c546410 pkg/devices/idl/activation.idl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/devices/idl/activation.idl Wed Dec 30 22:48:28 2020 +0100 @@ -0,0 +1,9 @@ +#include + +[protocol(LANDFALL_ACTIVATION)] +interface Activation +{ + void disable(); + + void enable(); +}; diff -r 2a6150981419 -r 06667c546410 pkg/devices/idl/backlight.idl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/devices/idl/backlight.idl Wed Dec 30 22:48:28 2020 +0100 @@ -0,0 +1,10 @@ +#include + +/* A backlight interface. Backlights may also support the Activation + interface. */ + +[protocol(LANDFALL_BACKLIGHT)] +interface Backlight +{ + void set_brightness(in int level); +}; diff -r 2a6150981419 -r 06667c546410 pkg/devices/include/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/devices/include/Makefile Wed Dec 30 22:48:28 2020 +0100 @@ -0,0 +1,4 @@ +PKGDIR = .. +L4DIR ?= $(PKGDIR)/../.. + +include $(L4DIR)/mk/include.mk diff -r 2a6150981419 -r 06667c546410 pkg/devices/include/protocols.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pkg/devices/include/protocols.h Wed Dec 30 22:48:28 2020 +0100 @@ -0,0 +1,25 @@ +/* + * Interface protocols. + * + * Copyright (C) 2020 Paul Boddie + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA + */ + +#pragma once + +#define LANDFALL_ACTIVATION 0x1f01 +#define LANDFALL_BACKLIGHT 0x1f02