uboot/board/gdsys/common/osd_cmd.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * (C) Copyright 2017
   4 * Mario Six,  Guntermann & Drunck GmbH, mario.six@gdsys.cc
   5 *
   6 * based on the gdsys osd driver, which is
   7 *
   8 * (C) Copyright 2010
   9 * Dirk Eibach,  Guntermann & Drunck GmbH, eibach@gdsys.de
  10 */
  11
  12#include <common.h>
  13#include <dm.h>
  14#include <hexdump.h>
  15#include <video_osd.h>
  16#include <malloc.h>
  17
  18static int do_osd_write(cmd_tbl_t *cmdtp, int flag, int argc,
  19                        char * const argv[])
  20{
  21        struct udevice *dev;
  22        uint x, y;
  23        uint count;
  24        char *hexstr;
  25        u8 *buffer;
  26        size_t buflen;
  27        int res;
  28
  29        if (argc < 4 || (strlen(argv[3])) % 2)
  30                return CMD_RET_USAGE;
  31
  32        x = simple_strtoul(argv[1], NULL, 16);
  33        y = simple_strtoul(argv[2], NULL, 16);
  34        hexstr = argv[3];
  35        count = (argc > 4) ? simple_strtoul(argv[4], NULL, 16) : 1;
  36
  37        buflen = strlen(hexstr) / 2;
  38
  39        buffer = malloc(buflen);
  40        if (!buffer) {
  41                puts("Memory allocation failure\n");
  42                return CMD_RET_FAILURE;
  43        }
  44
  45        res = hex2bin(buffer, hexstr, buflen);
  46        if (res) {
  47                free(buffer);
  48                puts("Hexadecimal input contained invalid characters\n");
  49                return CMD_RET_FAILURE;
  50        }
  51
  52        for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
  53             dev;
  54             uclass_next_device(&dev)) {
  55                int res;
  56
  57                res = video_osd_set_mem(dev, x, y, buffer, buflen, count);
  58                if (res) {
  59                        free(buffer);
  60                        printf("Could not write to video mem on osd %s\n",
  61                               dev->name);
  62                        return CMD_RET_FAILURE;
  63                }
  64        }
  65
  66        free(buffer);
  67
  68        return CMD_RET_SUCCESS;
  69}
  70
  71static int do_osd_print(cmd_tbl_t *cmdtp, int flag, int argc,
  72                        char * const argv[])
  73{
  74        struct udevice *dev;
  75        uint x, y;
  76        u8 color;
  77        char *text;
  78
  79        if (argc < 5)
  80                return CMD_RET_USAGE;
  81
  82        x = simple_strtoul(argv[1], NULL, 16);
  83        y = simple_strtoul(argv[2], NULL, 16);
  84        color = simple_strtoul(argv[3], NULL, 16);
  85        text = argv[4];
  86
  87        for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
  88             dev;
  89             uclass_next_device(&dev)) {
  90                int res;
  91
  92                res = video_osd_print(dev, x, y, color, text);
  93                if (res) {
  94                        printf("Could not print string to osd %s\n", dev->name);
  95                        return CMD_RET_FAILURE;
  96                }
  97        }
  98
  99        return CMD_RET_SUCCESS;
 100}
 101
 102static int do_osd_size(cmd_tbl_t *cmdtp, int flag, int argc,
 103                       char * const argv[])
 104{
 105        struct udevice *dev;
 106        uint x, y;
 107
 108        if (argc < 3)
 109                return CMD_RET_USAGE;
 110
 111        x = simple_strtoul(argv[1], NULL, 16);
 112        y = simple_strtoul(argv[2], NULL, 16);
 113
 114        for (uclass_first_device(UCLASS_VIDEO_OSD, &dev);
 115             dev;
 116             uclass_next_device(&dev)) {
 117                int res;
 118
 119                res = video_osd_set_size(dev, x, y);
 120
 121                if (res) {
 122                        printf("Could not set size on osd %s\n", dev->name);
 123                        return CMD_RET_FAILURE;
 124                }
 125        }
 126
 127        return CMD_RET_SUCCESS;
 128}
 129
 130U_BOOT_CMD(
 131        osdw, 5, 0, do_osd_write,
 132        "write 16-bit hex encoded buffer to osd memory",
 133        "osdw [pos_x] [pos_y] [buffer] [count] - write 8-bit hex encoded buffer to osd memory\n"
 134);
 135
 136U_BOOT_CMD(
 137        osdp, 5, 0, do_osd_print,
 138        "write ASCII buffer to osd memory",
 139        "osdp [pos_x] [pos_y] [color] [text] - write ASCII buffer to osd memory\n"
 140);
 141
 142U_BOOT_CMD(
 143        osdsize, 3, 0, do_osd_size,
 144        "set OSD XY size in characters",
 145        "osdsize [size_x] [size_y] - set OSD XY size in characters\n"
 146);
 147