2015-07-08 11:39:24 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LCD_ILI9341_H__
|
|
|
|
#define __LCD_ILI9341_H__
|
|
|
|
|
|
|
|
#include "ui.hpp"
|
|
|
|
#include "ui_text.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
namespace lcd {
|
|
|
|
|
|
|
|
class ILI9341 {
|
|
|
|
public:
|
|
|
|
constexpr ILI9341(
|
|
|
|
) : scroll_state { 0, 0, 320, 0 }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ILI9341(const ILI9341&) = delete;
|
|
|
|
ILI9341(ILI9341&&) = delete;
|
|
|
|
void operator=(const ILI9341&) = delete;
|
|
|
|
|
|
|
|
void init();
|
2015-08-01 17:36:27 -04:00
|
|
|
void shutdown();
|
2015-07-08 11:39:24 -04:00
|
|
|
|
2016-01-31 03:34:24 -05:00
|
|
|
void sleep();
|
|
|
|
void wake();
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
void fill_rectangle(ui::Rect r, const ui::Color c);
|
2015-08-22 23:08:38 -04:00
|
|
|
void draw_line(const ui::Point start, const ui::Point end, const ui::Color color);
|
2015-07-08 11:39:24 -04:00
|
|
|
void fill_circle(
|
|
|
|
const ui::Point center,
|
|
|
|
const ui::Dim radius,
|
|
|
|
const ui::Color foreground,
|
|
|
|
const ui::Color background
|
|
|
|
);
|
|
|
|
|
|
|
|
void draw_pixel(const ui::Point p, const ui::Color color);
|
2016-05-27 00:48:04 -04:00
|
|
|
void drawBMP(const ui::Point p, const uint8_t * bitmap, const bool transparency);
|
2015-09-04 14:37:27 -04:00
|
|
|
void render_line(const ui::Point p, const uint8_t count, const ui::Color* line_buffer);
|
2016-01-29 18:28:05 -05:00
|
|
|
void render_box(const ui::Point p, const ui::Size s, const ui::Color* line_buffer);
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
template<size_t N>
|
|
|
|
void draw_pixels(
|
|
|
|
const ui::Rect r,
|
|
|
|
const std::array<ui::Color, N>& colors
|
|
|
|
) {
|
|
|
|
draw_pixels(r, colors.data(), colors.size());
|
|
|
|
}
|
|
|
|
|
2016-02-19 18:31:56 -05:00
|
|
|
template<size_t N>
|
|
|
|
void read_pixels(
|
|
|
|
const ui::Rect r,
|
|
|
|
std::array<ui::ColorRGB888, N>& colors
|
|
|
|
) {
|
|
|
|
read_pixels(r, colors.data(), colors.size());
|
|
|
|
}
|
|
|
|
|
2016-02-03 13:33:54 -05:00
|
|
|
void draw_bitmap(
|
|
|
|
const ui::Point p,
|
|
|
|
const ui::Size size,
|
|
|
|
const uint8_t* const data,
|
|
|
|
const ui::Color foreground,
|
|
|
|
const ui::Color background
|
|
|
|
);
|
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
void draw_glyph(
|
|
|
|
const ui::Point p,
|
|
|
|
const ui::Glyph& glyph,
|
|
|
|
const ui::Color foreground,
|
|
|
|
const ui::Color background
|
|
|
|
);
|
|
|
|
|
|
|
|
void scroll_set_area(const ui::Coord top_y, const ui::Coord bottom_y);
|
|
|
|
ui::Coord scroll_set_position(const ui::Coord position);
|
|
|
|
ui::Coord scroll(const int32_t delta);
|
|
|
|
ui::Coord scroll_area_y(const ui::Coord y) const;
|
|
|
|
void scroll_disable();
|
|
|
|
|
|
|
|
constexpr ui::Dim width() const { return 240; }
|
|
|
|
constexpr ui::Dim height() const { return 320; }
|
|
|
|
constexpr ui::Rect screen_rect() const { return { 0, 0, width(), height() }; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct scroll_t {
|
|
|
|
uint16_t top_area;
|
|
|
|
uint16_t bottom_area;
|
|
|
|
uint16_t height;
|
|
|
|
uint16_t current_position;
|
|
|
|
};
|
2016-08-01 14:06:17 -04:00
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
2016-08-06 02:49:45 -04:00
|
|
|
struct bmp_header_t {
|
2016-08-01 14:06:17 -04:00
|
|
|
uint16_t signature;
|
|
|
|
uint32_t size;
|
|
|
|
uint16_t reserved_1;
|
|
|
|
uint16_t reserved_2;
|
|
|
|
uint32_t image_data;
|
|
|
|
uint32_t BIH_size;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint16_t planes;
|
|
|
|
uint16_t bpp;
|
|
|
|
uint32_t compression;
|
|
|
|
uint32_t data_size;
|
|
|
|
uint32_t h_res;
|
|
|
|
uint32_t v_res;
|
|
|
|
uint32_t colors_count;
|
|
|
|
uint32_t icolors_count;
|
2016-08-06 02:49:45 -04:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
struct bmp_palette_t {
|
|
|
|
struct color_t {
|
2016-08-01 14:06:17 -04:00
|
|
|
uint8_t B;
|
|
|
|
uint8_t G;
|
|
|
|
uint8_t R;
|
|
|
|
uint8_t A;
|
2016-08-06 02:49:45 -04:00
|
|
|
} color[16];
|
2016-08-01 14:06:17 -04:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
2016-08-06 02:49:45 -04:00
|
|
|
|
2015-07-08 11:39:24 -04:00
|
|
|
scroll_t scroll_state;
|
|
|
|
|
|
|
|
void draw_pixels(const ui::Rect r, const ui::Color* const colors, const size_t count);
|
2016-02-19 18:31:56 -05:00
|
|
|
void read_pixels(const ui::Rect r, ui::ColorRGB888* const colors, const size_t count);
|
2015-07-08 11:39:24 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace lcd */
|
|
|
|
|
|
|
|
#endif/*__LCD_ILI9341_H__*/
|