2022-06-26 16:45:27 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
|
|
|
|
|
|
|
This file is part of Savanni's AVR library.
|
|
|
|
|
|
|
|
Lumeto 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 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
Lumeto 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 Lumeto. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-06-26 16:40:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <display.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
#include <base.h>
|
|
|
|
|
|
|
|
void display_strobe_line(gpio_t *line) {
|
|
|
|
set_line(line);
|
2022-06-26 16:50:07 +00:00
|
|
|
_delay_us(50);
|
2022-06-26 16:40:04 +00:00
|
|
|
clear_line(line);
|
2022-06-26 16:50:07 +00:00
|
|
|
_delay_us(50);
|
2022-06-26 16:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void write_instruction(display_t *disp, uint8_t bitcode) {
|
|
|
|
clear_line(&disp->register_select);
|
|
|
|
sr_send_msb(&disp->reg, bitcode);
|
|
|
|
display_strobe_line(&disp->enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_char(display_t *disp, uint8_t bitcode) {
|
|
|
|
set_line(&disp->register_select);
|
|
|
|
sr_send_msb(&disp->reg, bitcode);
|
|
|
|
display_strobe_line(&disp->enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void display_init(display_t *disp) {
|
|
|
|
sr_initialize(&disp->reg);
|
|
|
|
set_line_direction(&disp->register_select, LINE_OUT);
|
|
|
|
set_line_direction(&disp->enable, LINE_OUT);
|
2022-06-26 17:28:23 +00:00
|
|
|
write_instruction(disp, 0b00111000);
|
2022-06-26 16:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void display_clear(display_t *disp) {
|
2022-06-28 00:03:49 +00:00
|
|
|
write_instruction(disp, 0b00000001);
|
|
|
|
_delay_ms(3);
|
|
|
|
write_instruction(disp, 0b00000010);
|
|
|
|
_delay_ms(3);
|
|
|
|
|
2022-06-26 16:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void display_enable(display_t *disp) {
|
2022-06-26 17:28:23 +00:00
|
|
|
write_instruction(disp, 0b00001100);
|
2022-06-28 00:03:49 +00:00
|
|
|
_delay_us(100);
|
|
|
|
write_instruction(disp, 0b00000100);
|
|
|
|
_delay_us(100);
|
2022-06-26 17:28:23 +00:00
|
|
|
}
|
|
|
|
|
2022-06-28 00:03:49 +00:00
|
|
|
void display_set_location(display_t *disp, size_t row, size_t column) {
|
2022-06-26 17:28:23 +00:00
|
|
|
size_t addr = row * 40 + column;
|
|
|
|
write_instruction(disp, 0b10000000 | addr);
|
2022-06-28 00:03:49 +00:00
|
|
|
_delay_us(100);
|
2022-06-26 16:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void display_write_message(display_t *disp, const char *msg) {
|
|
|
|
for (size_t i = 0; msg[i] != 0; i++) {
|
|
|
|
write_char(disp, msg[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|