1.1 --- a/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Sun Dec 27 00:27:16 2020 +0100
1.2 +++ b/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Wed Dec 30 22:48:28 2020 +0100
1.3 @@ -5,7 +5,7 @@
1.4 * the Giantplus GPM940B0 panel datasheet also describes this controller
1.5 * interface.
1.6 *
1.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -23,15 +23,16 @@
1.13 * Boston, MA 02110-1301, USA
1.14 */
1.15
1.16 -#include <l4/cxx/ipc_server>
1.17 #include <l4/re/env>
1.18 -#include <l4/re/util/object_registry>
1.19 #include <l4/sys/capability>
1.20 +#include <l4/sys/err.h>
1.21
1.22 -#include <stdlib.h>
1.23 +#include <stdio.h>
1.24
1.25 #include <l4/devices/spi-client.h>
1.26 -#include "backlight-ops.h"
1.27 +
1.28 +#include <ipc/server.h>
1.29 +#include "backlight_object_server.h"
1.30
1.31 /* SPI access abstractions. */
1.32
1.33 @@ -41,7 +42,7 @@
1.34
1.35 /* Backlight device. */
1.36
1.37 -class Backlight_device_server : public L4::Server_object_t<L4::Kobject>
1.38 +class server_BacklightObject : public BacklightObject
1.39 {
1.40 int _min = 55, _max = 90, _start = 70;
1.41
1.42 @@ -61,57 +62,32 @@
1.43 }
1.44
1.45 public:
1.46 - /* Dispatch incoming requests. */
1.47 -
1.48 - int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
1.49 - {
1.50 - l4_msgtag_t tag;
1.51 - int arg;
1.52 -
1.53 - (void) obj;
1.54 - ios >> tag;
1.55 + /* Disable the backlight. */
1.56
1.57 - switch (tag.label())
1.58 - {
1.59 - case Backlight_op_disable:
1.60 - disable();
1.61 - return L4_EOK;
1.62 -
1.63 - case Backlight_op_enable:
1.64 - enable();
1.65 - return L4_EOK;
1.66 -
1.67 - case Backlight_op_set_brightness:
1.68 - ios >> arg;
1.69 - set_brightness(arg);
1.70 - return L4_EOK;
1.71 -
1.72 - default:
1.73 - return -L4_EBADPROTO;
1.74 - }
1.75 + long disable()
1.76 + {
1.77 + spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
1.78 + return L4_EOK;
1.79 }
1.80
1.81 - void disable()
1.82 - {
1.83 - spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
1.84 - }
1.85 + /* Enable the backlight. */
1.86
1.87 - void enable()
1.88 + long enable()
1.89 {
1.90 set_duty(_start);
1.91 + return L4_EOK;
1.92 }
1.93
1.94 /* Use the SPI device to update the brightness level. */
1.95
1.96 - void set_brightness(int level)
1.97 + long set_brightness(int level)
1.98 {
1.99 level = level < _min ? _min : (level > _max ? _max : level);
1.100 spi_device->send(16, 0x0300 | level); /* R03h: brightness */
1.101 + return L4_EOK;
1.102 }
1.103 };
1.104
1.105 -static L4Re::Util::Registry_server<> server;
1.106 -
1.107
1.108
1.109 int main(void)
1.110 @@ -123,11 +99,20 @@
1.111
1.112 /* Initialise and register a new server object. */
1.113
1.114 - Backlight_device_server server_obj;
1.115 - server.registry()->register_obj(&server_obj, "backlight");
1.116 + server_BacklightObject obj;
1.117 + l4_cap_idx_t server;
1.118 +
1.119 + long err = ipc_server_bind("backlight", (l4_umword_t) &obj, &server);
1.120 +
1.121 + if (err)
1.122 + {
1.123 + printf("Could not bind server: %s\n", l4sys_errtostr(err));
1.124 + return 1;
1.125 + }
1.126
1.127 /* Enter the IPC server loop. */
1.128
1.129 - server.loop();
1.130 + ipc_server_loop(BacklightObject_expected_items, &obj,
1.131 + (ipc_server_handler_type) handle_BacklightObject);
1.132 return 0;
1.133 }