Files
timely-reference/DisplayDriver.h
Max Regan a7f1ffc1b5 Huge refactoring for C++ and low-power mode
The display currently shows the time, with hours and minutes, and is
capable of receiving input with buttons (though does nothing). It
sleeps during intervals where nothing is happening. The display task
runs once per second, and RTC alarm A is used for periodic alarms to
update the system time.
2019-04-17 21:51:35 -07:00

94 lines
2.6 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(unsigned int x, unsigned int y, uint8_t val);
void set_byte(unsigned int x, unsigned int y, uint8_t val);
void char_at(int *x_off, int y_off, char c, const struct font *font);
void string_at(int x_off, int 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);
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;
};
}