blob: 4875ebe8eb4c8ca140f43443fa0837de591bfa97 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fcntl.h>
#include <fuchsia/hardware/dotmatrixdisplay/c/fidl.h>
#include <fuchsia/hardware/ftdi/c/fidl.h>
#include <lib/fdio/fdio.h>
#include <stdio.h>
#include <unistd.h>
#include <zircon/syscalls.h>
#include <filesystem>
#include <iostream>
#include <vector>
constexpr int kWidth = 128;
constexpr int kHeight = 64;
const uint8_t fuchsia_logo[] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x80, 0x80,
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
0xc0, 0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x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, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0};
int CreateLogo() {
const char* path = "/dev/class/dotmatrix-display/";
int fd_display = -1;
for (const auto& entry : std::filesystem::directory_iterator(path)) {
fd_display = open(entry.path().c_str(), O_RDWR);
if (fd_display > 0) {
break;
}
}
if (fd_display <= 0) {
printf("Open dotmatrix-display failed with %d\n", fd_display);
return 1;
}
zx_handle_t handle_display;
zx_status_t status = fdio_get_service_handle(fd_display, &handle_display);
if (status != ZX_OK) {
printf("Ftdio get handle failed with %d\n", status);
return 1;
}
fuchsia_hardware_dotmatrixdisplay_DotmatrixDisplayConfig display_config;
fuchsia_hardware_dotmatrixdisplay_DotmatrixDisplayGetConfig(handle_display,
&display_config);
if (display_config.width != kWidth || display_config.height != kHeight ||
display_config.format !=
fuchsia_hardware_dotmatrixdisplay_PixelFormat_MONOCHROME ||
display_config.layout !=
fuchsia_hardware_dotmatrixdisplay_ScreenLayout_COLUMN_TB_ROW_LR) {
printf("Error: Display configs do not match supported config\n");
printf("Width: Support: %d Recieved: %d \n", kWidth, display_config.width);
printf("Height: Support: %d Recieved: %d \n", kHeight,
display_config.height);
printf("Format: Support: %d Recieved: %d \n",
fuchsia_hardware_dotmatrixdisplay_PixelFormat_MONOCHROME,
display_config.format);
printf("Layout: Support: %d Recieved: %d \n",
fuchsia_hardware_dotmatrixdisplay_ScreenLayout_COLUMN_TB_ROW_LR,
display_config.layout);
return 1;
}
std::vector<uint8_t> display_buf(display_config.width *
display_config.height / 8);
fuchsia_hardware_dotmatrixdisplay_DotmatrixDisplaySetScreen(
handle_display, display_buf.data(), display_buf.size(), &status);
if (status != ZX_OK) {
printf("Display SetScreen failed with %d\n", status);
return 1;
}
std::vector<uint8_t> frame_buffer(kWidth * 8);
size_t logo_index = 0;
for (size_t i = 0; i < 8; i++) {
for (size_t j = 0; j < kWidth; j++) {
frame_buffer[i * kWidth + j] = fuchsia_logo[logo_index++];
}
}
fuchsia_hardware_dotmatrixdisplay_DotmatrixDisplaySetScreen(
handle_display, frame_buffer.data(), frame_buffer.size(), &status);
if (status != ZX_OK) {
printf("Display SetScreen failed with %d\n", status);
return 1;
}
return 0;
}