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.
This commit is contained in:
2019-04-17 21:51:35 -07:00
parent 6747d6c831
commit a7f1ffc1b5
22 changed files with 1051 additions and 231 deletions

View File

@@ -40,20 +40,7 @@ DisplayDriver::DisplayDriver(Common::Schedule::TaskScheduler &scheduler, SpiDriv
ReturnCode DisplayDriver::init()
{
/** Enable Port A,B clock */
SET(RCC->IOPENR, RCC_IOPENR_IOPBEN);
/** Enable pin P3 for output */
SET_TO(GPIOB->MODER,
GPIO_MODER_MODE3,
GPIO_MODER_MODE3_0);
CLR(GPIOB->OTYPER, GPIO_OTYPER_OT_3);
CLR(GPIOB->PUPDR, GPIO_PUPDR_PUPD3);
return Common::ReturnCode::OK;
return ReturnCode::OK;
return Common::ReturnCode::OK;
}
NextTime DisplayDriver::execute()
@@ -66,7 +53,7 @@ void DisplayDriver::buffer_init()
for (size_t i = 0; i < ARRAY_SIZE(m_buffer.lines); i++) {
struct display_line *line = &m_buffer.lines[i];
line->mode = 1; // Update display
line->line = i;
line->line = i + 1; // Line numbers start at 1
for (size_t j = 0; j < ARRAY_SIZE(line->data); j++) {
line->data[j] = 0xFF;
}
@@ -126,21 +113,32 @@ void DisplayDriver::char_at(int *x_off, int y_off, char c, const struct font *fo
return;
}
// TODO: Don't hardcode this
int byte_cols = (g->cols / 8);
int byte_cols = g->cols / 8;
if (g->cols & 7) {
byte_cols++;
}
if (byte_cols & 1) {
byte_cols++;
}
for (size_t x = 0; x < g->left; x++) {
for (size_t y = 0; y < g->rows; y++) {
set_bit(*x_off + x, y_off + y + font->size - g->top, 0);
}
}
for (size_t x = g->left + g->cols; x < g->advance; x++) {
for (size_t y = 0; y < g->rows; y++) {
set_bit(*x_off + x, y_off + y + font->size - g->top, 0);
}
}
for (size_t x = 0; x < g->cols; x++) {
for (size_t y = 0; y < g->rows; y++) {
int byte_x = x >> 3;
int byte_x = x / 8;
int byte_y = y;
uint8_t bit = (g->bitmap[byte_y * byte_cols + byte_x] >> (7 - (x & 7))) & 1;
/* 16 is font max height */
set_bit(g->left + *x_off + x, y_off + y + 16 - g->top, bit);
set_bit(g->left + *x_off + x, y_off + y + font->size - g->top, bit);
}
}
*x_off += g->advance;