103 lines
3.2 KiB
C++
103 lines
3.2 KiB
C++
/*
|
|
* Copyright (C) 2019 Max Regan
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Task.h"
|
|
#include "SpiDriver.h"
|
|
#include "font.h"
|
|
|
|
namespace BSP {
|
|
|
|
class DisplayDriver : public Common::Schedule::Task {
|
|
public:
|
|
DisplayDriver(Common::Schedule::TaskScheduler &scheduler, SpiDriver &spi);
|
|
|
|
|
|
|
|
/**
|
|
* Common::Schedule::Task
|
|
*/
|
|
Common::ReturnCode init();
|
|
Common::Schedule::NextTime execute() override;
|
|
|
|
/**
|
|
* DisplayDriver
|
|
*/
|
|
void set_bit(uint32_t x, uint32_t y, uint8_t val);
|
|
void set_byte(uint32_t x, uint32_t y, uint8_t val);
|
|
void char_at(uint32_t *x_off, uint32_t y_off, char c, const struct font *font);
|
|
void string_at(uint32_t *x_off, uint32_t y_off,
|
|
const char *string, const struct font *font);
|
|
void refresh();
|
|
void clear();
|
|
|
|
inline uint32_t get_width() {
|
|
return DISPLAY_WIDTH;
|
|
}
|
|
|
|
inline uint32_t get_height() {
|
|
return DISPLAY_HEIGHT;
|
|
}
|
|
|
|
private:
|
|
void buffer_init();
|
|
void set_dirty(unsigned int y);
|
|
const struct glyph *glyph_for_char(const struct font *font, char c);
|
|
void clear_glyph_aligned(uint32_t x_off, uint32_t y_off,
|
|
const struct font * font, const struct glyph *g);
|
|
void clear_glyph_unaligned(uint32_t x_off, uint32_t y_off,
|
|
const struct font * font, const struct glyph *g);
|
|
void write_glyph_aligned(uint32_t x_off, uint32_t y_off,
|
|
const struct font * font, const struct glyph *g);
|
|
void write_glyph_unaligned(uint32_t x_off, uint32_t y_off,
|
|
const struct font * font, const struct glyph *g);
|
|
|
|
static constexpr uint32_t DISPLAY_WIDTH = 144;
|
|
static constexpr uint32_t DISPLAY_HEIGHT = 168;
|
|
|
|
struct display_line
|
|
{
|
|
uint8_t mode;
|
|
uint8_t line;
|
|
uint8_t data[DISPLAY_WIDTH / 8];
|
|
};
|
|
|
|
struct display_buffer
|
|
{
|
|
struct display_line lines[DISPLAY_HEIGHT];
|
|
uint16_t dummy;
|
|
};
|
|
|
|
|
|
Common::Schedule::TaskScheduler &m_scheduler;
|
|
SpiDriver &m_spi;
|
|
|
|
struct display_buffer m_buffer;
|
|
|
|
bool m_is_dirty;
|
|
uint8_t m_dirty_line_min;
|
|
uint8_t m_dirty_line_max;
|
|
|
|
};
|
|
|
|
}
|