Landfall

pkg/devices/display/src/letux400/display-letux400.cc

285:f09c2fffc7a8
6 months ago Paul Boddie Moved GPIO pull-up/down configurations into the GPIO library and simplified the GPIO initialisation interface. cpm-library-improvements
     1 /*     2  * Export Letux 400 display operations as a server.     3  *     4  * Copyright (C) 2018, 2020, 2023, 2024 Paul Boddie <paul@boddie.org.uk>     5  *     6  * This program is free software; you can redistribute it and/or     7  * modify it under the terms of the GNU General Public License as     8  * published by the Free Software Foundation; either version 2 of     9  * the License, or (at your option) any later version.    10  *    11  * This program is distributed in the hope that it will be useful,    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    14  * GNU General Public License for more details.    15  *    16  * You should have received a copy of the GNU General Public License    17  * along with this program; if not, write to the Free Software    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor,    19  * Boston, MA  02110-1301, USA    20  */    21     22 #include <l4/devices/gpio-jz4730.h>    23 #include <l4/devices/memory.h>    24     25 #include <l4/re/env.h>    26     27 #include <ipc/server.h>    28     29 #include "activation_client.h"    30 #include "activation_server.h"    31     32     33     34 /* Virtual address for the GPIO register block. */    35     36 static l4_addr_t gpio_virt_base = 0, gpio_virt_base_end = 0;    37     38 /* GPIO abstraction. */    39     40 static Gpio_jz4730_chip *gpio_port_b = 0, *gpio_port_c = 0;    41     42     43     44 /* GPIO pin definitions. */    45     46 enum Jz4730_lcd_gpio_mask    47 {    48   Jz4730_lcd_gpio_func1 = 0xf8ffff00,    49   Jz4730_lcd_gpio_func2 = 0x07000000,    50 };    51     52 enum Jz4730_lcd_gpio    53 {    54   Jz4730_lcd_gpio_led_enable     = 28,    55   Jz4730_lcd_gpio_display_enable = 29,    56 };    57     58     59     60 static int setup_memory(void)    61 {    62   if (get_memory("jz4730-gpio", &gpio_virt_base, &gpio_virt_base_end))    63     return 1;    64     65   return 0;    66 }    67     68     69     70 /* Display device only implementing the activation interface. */    71     72 class DisplayObject_server : public Activation    73 {    74   Pin_slice lcd_mask1 = {.offset=0, .mask=Jz4730_lcd_gpio_func1};    75   Pin_slice lcd_mask2 = {.offset=0, .mask=Jz4730_lcd_gpio_func2};    76     77   Activation *_backlight;    78     79 public:    80   explicit DisplayObject_server(Activation *backlight)    81   : _backlight(backlight)    82   {    83     /* Set functions for the LCD pins. */    84     85     gpio_port_b->multi_config_pad(lcd_mask1, Hw::Gpio_chip::Function_alt, 1);    86     gpio_port_b->multi_config_pad(lcd_mask2, Hw::Gpio_chip::Function_alt, 2);    87     88     /* Enable LED, disable display. */    89     90     gpio_port_c->setup(Jz4730_lcd_gpio_led_enable, Hw::Gpio_chip::Output, 1);    91     gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 0);    92   }    93     94   /* Switch the display off. */    95     96   long disable(void)    97   {    98     gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 0);    99     _backlight->disable();   100     return L4_EOK;   101   }   102    103   /* Switch the display on. */   104    105   long enable(void)   106   {   107     gpio_port_c->setup(Jz4730_lcd_gpio_display_enable, Hw::Gpio_chip::Output, 1);   108     _backlight->enable();   109     return L4_EOK;   110   }   111 };   112    113    114    115 int main(void)   116 {   117   if (setup_memory())   118     return 1;   119    120   /* Initialise the GPIO abstractions. */   121    122   Gpio_jz4730_chip gpb(gpio_virt_base, 1);   123   Gpio_jz4730_chip gpc(gpio_virt_base, 2);   124    125   gpio_port_b = &gpb;   126   gpio_port_c = &gpc;   127    128   /* Obtain a reference to the backlight device. */   129    130   l4_cap_idx_t backlight = l4re_env_get_cap("backlight");   131    132   if (!l4_is_valid_cap(backlight))   133     return 1;   134    135   /* Use the activation interface with the backlight. */   136    137   client_Activation backlight_obj(backlight);   138    139   /* Initialise and register a new server object. */   140    141   DisplayObject_server obj(&backlight_obj);   142    143   /* Enter the IPC server loop. */   144    145   if (ipc_server_loop_for(Activation, &obj, "display"))   146     return 1;   147    148   return 0;   149 }