1.1 --- a/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Thu Dec 31 01:11:34 2020 +0100
1.2 +++ b/pkg/devices/backlight/src/spi-ili8960/backlight-spi-ili8960.cc Thu Dec 31 16:53:56 2020 +0100
1.3 @@ -23,17 +23,11 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <l4/re/env>
1.8 -#include <l4/sys/capability>
1.9 -
1.10 -#include <l4/devices/spi-client.h>
1.11 +#include <l4/re/env.h>
1.12
1.13 #include <ipc/server.h>
1.14 #include "backlight_object_server.h"
1.15 -
1.16 -/* SPI access abstractions. */
1.17 -
1.18 -static L4::Cap<Spi_device_interface> spi_device;
1.19 +#include "spi_client.h"
1.20
1.21
1.22
1.23 @@ -41,6 +35,7 @@
1.24
1.25 class server_BacklightObject : public BacklightObject
1.26 {
1.27 + SPI *_spi;
1.28 int _min = 55, _max = 90, _start = 70;
1.29
1.30 void set_duty(int level)
1.31 @@ -51,19 +46,24 @@
1.32
1.33 int duty = ((level - _min) / 5) << 3;
1.34
1.35 - spi_device->send(16, 0x0516 | duty); /* R05h: GRB=0 (reset); PWM_DUTY=duty; SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
1.36 - spi_device->send(16, 0x0546 | duty); /* R05h: GRB=1 (normal operation); ... */
1.37 - spi_device->send(16, 0x078d); /* R07h: HBLK=141 (horizontal blanking period from start of hsync pulse to data start) */
1.38 - spi_device->send(16, 0x1301); /* R13h: IN_SEL=1 (alignment mode) */
1.39 - spi_device->send(16, 0x0547 | duty); /* R05h: ...; STB=1 (not standby) */
1.40 + _spi->send(16, 0x0516 | duty); /* R05h: GRB=0 (reset); PWM_DUTY=duty; SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
1.41 + _spi->send(16, 0x0546 | duty); /* R05h: GRB=1 (normal operation); ... */
1.42 + _spi->send(16, 0x078d); /* R07h: HBLK=141 (horizontal blanking period from start of hsync pulse to data start) */
1.43 + _spi->send(16, 0x1301); /* R13h: IN_SEL=1 (alignment mode) */
1.44 + _spi->send(16, 0x0547 | duty); /* R05h: ...; STB=1 (not standby) */
1.45 }
1.46
1.47 public:
1.48 + explicit server_BacklightObject(SPI *spi)
1.49 + : _spi(spi)
1.50 + {
1.51 + }
1.52 +
1.53 /* Disable the backlight. */
1.54
1.55 long disable()
1.56 {
1.57 - spi_device->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
1.58 + _spi->send(16, 0x0546); /* R05h: GRB=1 (normal operation); SHDB2=1, SHDB1=1 (power-related); STB=0 (standby) */
1.59 return L4_EOK;
1.60 }
1.61
1.62 @@ -80,7 +80,7 @@
1.63 long set_brightness(int level)
1.64 {
1.65 level = level < _min ? _min : (level > _max ? _max : level);
1.66 - spi_device->send(16, 0x0300 | level); /* R03h: brightness */
1.67 + _spi->send(16, 0x0300 | level); /* R03h: brightness */
1.68 return L4_EOK;
1.69 }
1.70 };
1.71 @@ -91,12 +91,14 @@
1.72 {
1.73 /* Obtain a reference to the SPI device. */
1.74
1.75 - spi_device = L4Re::Env::env()->get_cap<Spi_device_interface>("spi");
1.76 - if (!spi_device.is_valid()) return 1;
1.77 + l4_cap_idx_t spi = l4re_env_get_cap("spi");
1.78 + if (!l4_is_valid_cap(spi)) return 1;
1.79 +
1.80 + client_SPI spi_obj(spi);
1.81
1.82 /* Initialise and register a new server object. */
1.83
1.84 - server_BacklightObject obj;
1.85 + server_BacklightObject obj(&spi_obj);
1.86 l4_cap_idx_t server;
1.87
1.88 if (ipc_server_bind("backlight", (l4_umword_t) &obj, &server)) return 1;