Compare commits

...

7 commits

Author SHA1 Message Date
953649725b Remove colon from "BACK" setup menu entry
Rename "BACK:" to "BACK" in setup menu.
2021-09-24 23:41:21 +02:00
dada6fe5d4 Allow to print larger integers
Use `uint32_t` instead of `uint8_t` when printing integers with
`lcd_write_integer_page()`.
2021-09-24 23:39:56 +02:00
22095d6e78 Pass kerning when writing string
In order to be able to print more compact strings also pass the
kerning parameter to `lcd_write_string_page()`.
2021-09-24 23:39:27 +02:00
a34a58535b Improve and add symbols
Add symbols for `D` and `M` and improve `U`.
2021-09-24 23:19:02 +02:00
45bfe04537 Also move and rename drawing the splash screen
For consistency `lcd_splash()` was moved before `draw_home()` and
renamed to `draw_splash()`.
2021-09-24 12:29:35 +02:00
144da8d7f2 Add flag to invert output of twi_error()
This is only for convinience for the eye to be able to print
"debugging" information not inverted.
2021-09-24 12:27:53 +02:00
2beecbe722 Move shifting of TWI slave address
As this may be obscure the shifting of the TWI slave address is moved
to where it is used instead of where it is set.
2021-09-24 12:25:47 +02:00

View file

@ -22,7 +22,7 @@
#define TWI_SDA PC4 #define TWI_SDA PC4
#define TWI_SCL PC5 #define TWI_SCL PC5
#define SI5351_ADDRESS (0x60 << 1) #define SI5351_ADDRESS 0x60
#define SYM_ENTRY(SYM) { SYM, sizeof(SYM) / 2 } #define SYM_ENTRY(SYM) { SYM, sizeof(SYM) / 2 }
@ -68,6 +68,8 @@ static const __flash uint8_t sym_b[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0xFC, 0x78,
0x3F, 0x3F, 0x31, 0x31, 0x3F, 0x1E }; 0x3F, 0x3F, 0x31, 0x31, 0x3F, 0x1E };
static const __flash uint8_t sym_c[] = { 0xF8, 0xFC, 0x0C, 0x1C, 0x18, static const __flash uint8_t sym_c[] = { 0xF8, 0xFC, 0x0C, 0x1C, 0x18,
0x1F, 0x3F, 0x30, 0x38, 0x18 }; 0x1F, 0x3F, 0x30, 0x38, 0x18 };
static const __flash uint8_t sym_d[] = { 0xFC, 0xFC, 0x0C, 0x1C, 0xF8, 0xF0,
0x3F, 0x3F, 0x30, 0x38, 0x1F, 0x0F };
static const __flash uint8_t sym_e[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0x0C, static const __flash uint8_t sym_e[] = { 0xFC, 0xFC, 0x8C, 0x8C, 0x0C,
0x3F, 0x3F, 0x31, 0x31, 0x30 }; 0x3F, 0x3F, 0x31, 0x31, 0x30 };
static const __flash uint8_t sym_g[] = { 0xF8, 0xFC, 0x0C, 0x0C, 0x3C, 0x38, static const __flash uint8_t sym_g[] = { 0xF8, 0xFC, 0x0C, 0x0C, 0x3C, 0x38,
@ -80,6 +82,8 @@ static const __flash uint8_t sym_k[] = { 0xFC, 0xFC, 0xC0, 0xF0, 0x7C, 0x1C,
0x3F, 0x3F, 0x03, 0x0F, 0x3E, 0x38 }; 0x3F, 0x3F, 0x03, 0x0F, 0x3E, 0x38 };
static const __flash uint8_t sym_l[] = { 0xFC, 0xFC, 0x00, 0x00, 0x00, static const __flash uint8_t sym_l[] = { 0xFC, 0xFC, 0x00, 0x00, 0x00,
0x3F, 0x3F, 0x30, 0x30, 0x30 }; 0x3F, 0x3F, 0x30, 0x30, 0x30 };
static const __flash uint8_t sym_m[] = { 0xFC, 0xFC, 0x38, 0x70, 0xE0, 0x70, 0x38, 0xFC, 0xFC,
0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F };
static const __flash uint8_t sym_n[] = { 0xFC, 0xFC, 0xF0, 0xC0, 0x00, 0xFC, 0xFC, static const __flash uint8_t sym_n[] = { 0xFC, 0xFC, 0xF0, 0xC0, 0x00, 0xFC, 0xFC,
0x3F, 0x3F, 0x00, 0x03, 0x0F, 0x3F, 0x3F }; 0x3F, 0x3F, 0x00, 0x03, 0x0F, 0x3F, 0x3F };
static const __flash uint8_t sym_o[] = { 0xF8, 0xFC, 0x0C, 0x0C, 0xFC, 0xF8, static const __flash uint8_t sym_o[] = { 0xF8, 0xFC, 0x0C, 0x0C, 0xFC, 0xF8,
@ -93,7 +97,7 @@ static const __flash uint8_t sym_s[] = { 0xF8, 0xFC, 0x8C, 0x8C, 0x9C, 0x18,
static const __flash uint8_t sym_t[] = { 0x0C, 0x0C, 0xFC, 0xFC, 0x0C, 0x0C, static const __flash uint8_t sym_t[] = { 0x0C, 0x0C, 0xFC, 0xFC, 0x0C, 0x0C,
0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00 }; 0x00, 0x00, 0x3F, 0x3F, 0x00, 0x00 };
static const __flash uint8_t sym_u[] = { 0xFC, 0xFC, 0x00, 0x00, 0xFC, 0xFC, static const __flash uint8_t sym_u[] = { 0xFC, 0xFC, 0x00, 0x00, 0xFC, 0xFC,
0x3F, 0x3F, 0x30, 0x30, 0x3F, 0x3F }; 0x1F, 0x3F, 0x30, 0x30, 0x3F, 0x1F };
static const __flash uint8_t sym_underscore[] = { 0x00, 0x00, 0x00, 0x00, 0x00, static const __flash uint8_t sym_underscore[] = { 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0x20, 0x20, 0x20, 0x20 }; 0x20, 0x20, 0x20, 0x20, 0x20 };
@ -126,7 +130,7 @@ static const struct symbol symbol_table[] = { SYM_ENTRY(sym_0),
SYM_ENTRY(sym_a), SYM_ENTRY(sym_a),
SYM_ENTRY(sym_b), SYM_ENTRY(sym_b),
SYM_ENTRY(sym_c), SYM_ENTRY(sym_c),
SYM_ENTRY(sym_invalid), SYM_ENTRY(sym_d),
SYM_ENTRY(sym_e), SYM_ENTRY(sym_e),
SYM_ENTRY(sym_invalid), SYM_ENTRY(sym_invalid),
SYM_ENTRY(sym_g), SYM_ENTRY(sym_g),
@ -135,7 +139,7 @@ static const struct symbol symbol_table[] = { SYM_ENTRY(sym_0),
SYM_ENTRY(sym_invalid), SYM_ENTRY(sym_invalid),
SYM_ENTRY(sym_k), SYM_ENTRY(sym_k),
SYM_ENTRY(sym_l), SYM_ENTRY(sym_l),
SYM_ENTRY(sym_invalid), SYM_ENTRY(sym_m),
SYM_ENTRY(sym_n), SYM_ENTRY(sym_n),
SYM_ENTRY(sym_o), SYM_ENTRY(sym_o),
SYM_ENTRY(sym_p), SYM_ENTRY(sym_p),
@ -285,15 +289,16 @@ static void lcd_write_character_page(const char character,
} }
static void lcd_write_string_page(const char* string, static void lcd_write_string_page(const char* string,
const uint8_t kerning,
const uint8_t page, const uint8_t page,
const bool invert) { const bool invert) {
for (uint8_t i = 0; string[i] != 0; i++) { for (uint8_t i = 0; string[i] != 0; i++) {
lcd_write_kerning(2, invert); lcd_write_kerning(kerning, invert);
lcd_write_character_page(string[i], page, invert); lcd_write_character_page(string[i], page, invert);
} }
} }
static void lcd_write_integer_page(const uint8_t integer, static void lcd_write_integer_page(const uint32_t integer,
const uint8_t digits, const uint8_t digits,
const uint8_t page, const uint8_t page,
const bool invert) { const bool invert) {
@ -316,40 +321,24 @@ static void lcd_write_integer_page(const uint8_t integer,
} }
} }
static void lcd_splash(void) { static void twi_error(bool inverted) {
lcd_fill(0x00); if (inverted)
lcd_fill(0xFF);
for (uint8_t i = 0; i < 5; i++) { else
lcd_move_cursor(31, 1 + i); lcd_fill(0x00);
for (uint8_t j = 0; j < 40; j++)
lcd_write(sacred_chao[i * 40 + j]);
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(26, 6 + i);
for (uint8_t j = 0; j < 48; j++)
lcd_write(onders_org[i * 48 + j]);
}
}
static void twi_error(void) {
lcd_fill(0xFF);
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, i); lcd_move_cursor(0, i);
lcd_write_string_page("TW_STATUS:\0", i, true); lcd_write_string_page("TW_STATUS:\0", 2, i, inverted);
lcd_write_kerning(2, true); lcd_write_kerning(2, inverted);
lcd_write_integer_page(TW_STATUS, 3, i, true); lcd_write_integer_page(TW_STATUS, 3, i, inverted);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, i + 2); lcd_move_cursor(0, i + 2);
lcd_write_string_page("TW_DATA:\0", i, true); lcd_write_string_page("TW_DATA:\0", 2, i, inverted);
lcd_write_kerning(16, true); lcd_write_kerning(16, inverted);
lcd_write_integer_page(TWDR, 3, i, true); lcd_write_integer_page(TWDR, 3, i, inverted);
} }
for (;;); for (;;);
@ -360,7 +349,7 @@ static void twi_start(void) {
while (!(TWCR & (1 << TWINT))); // Wait until start is transmitted while (!(TWCR & (1 << TWINT))); // Wait until start is transmitted
if (TW_STATUS != TW_START) // Check status if (TW_STATUS != TW_START) // Check status
twi_error(); twi_error(true);
} }
static uint8_t twi_transmit(const uint8_t data) { static uint8_t twi_transmit(const uint8_t data) {
@ -386,11 +375,11 @@ static uint8_t twi_read_register(const uint8_t address,
const uint8_t reg) { const uint8_t reg) {
twi_start(); twi_start();
if (twi_transmit(address) != TW_MT_SLA_ACK) if (twi_transmit(address << 1) != TW_MT_SLA_ACK)
twi_error(); twi_error(true);
if (twi_transmit(reg) != TW_MT_DATA_ACK) if (twi_transmit(reg) != TW_MT_DATA_ACK)
twi_error(); twi_error(true);
twi_stop(); twi_stop();
@ -398,11 +387,11 @@ static uint8_t twi_read_register(const uint8_t address,
twi_start(); twi_start();
if (twi_transmit(address + 1) != TW_MR_SLA_ACK) if (twi_transmit((address << 1) + 1) != TW_MR_SLA_ACK)
twi_error(); twi_error(true);
if (twi_receive() != TW_MR_DATA_NACK) if (twi_receive() != TW_MR_DATA_NACK)
twi_error(); twi_error(true);
twi_stop(); twi_stop();
@ -414,18 +403,36 @@ static void twi_write_register(const uint8_t address,
const uint8_t data) { const uint8_t data) {
twi_start(); twi_start();
if (twi_transmit(address) != TW_MT_SLA_ACK) if (twi_transmit(address << 1) != TW_MT_SLA_ACK)
twi_error(); twi_error(true);
if (twi_transmit(reg) != TW_MT_DATA_ACK) if (twi_transmit(reg) != TW_MT_DATA_ACK)
twi_error(); twi_error(true);
if (twi_transmit(data) != TW_MT_DATA_ACK) if (twi_transmit(data) != TW_MT_DATA_ACK)
twi_error(); twi_error(true);
twi_stop(); twi_stop();
} }
static void draw_splash(void) {
lcd_fill(0x00);
for (uint8_t i = 0; i < 5; i++) {
lcd_move_cursor(31, 1 + i);
for (uint8_t j = 0; j < 40; j++)
lcd_write(sacred_chao[i * 40 + j]);
}
for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(26, 6 + i);
for (uint8_t j = 0; j < 48; j++)
lcd_write(onders_org[i * 48 + j]);
}
}
static void draw_home(void) { static void draw_home(void) {
lcd_fill(0x00); lcd_fill(0x00);
@ -451,19 +458,19 @@ static void draw_home(void) {
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, i); lcd_move_cursor(0, i);
lcd_write_string_page("CH1\0", i, ch1_selected); lcd_write_string_page("CH1\0", 2, i, ch1_selected);
lcd_write_kerning(2, ch1_selected); lcd_write_kerning(2, ch1_selected);
lcd_move_cursor(0, 2 + i); lcd_move_cursor(0, 2 + i);
lcd_write_string_page("CH2\0", i, ch2_selected); lcd_write_string_page("CH2\0", 2, i, ch2_selected);
lcd_write_kerning(2, ch2_selected); lcd_write_kerning(2, ch2_selected);
lcd_move_cursor(0, 4 + i); lcd_move_cursor(0, 4 + i);
lcd_write_string_page("CH3\0", i, ch3_selected); lcd_write_string_page("CH3\0", 2, i, ch3_selected);
lcd_write_kerning(2, ch3_selected); lcd_write_kerning(2, ch3_selected);
lcd_move_cursor(33, 6 + i); lcd_move_cursor(33, 6 + i);
lcd_write_string_page("SETUP\0", i, setup_selected); lcd_write_string_page("SETUP\0", 2, i, setup_selected);
lcd_write_kerning(2, setup_selected); lcd_write_kerning(2, setup_selected);
} }
} }
@ -498,13 +505,13 @@ static void draw_setup(void) {
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, i); lcd_move_cursor(0, i);
lcd_write_kerning(30, true); lcd_write_kerning(30, true);
lcd_write_string_page("SETUP\0", i, true); lcd_write_string_page("SETUP\0", 2, i, true);
lcd_write_kerning(33, true); lcd_write_kerning(33, true);
} }
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, 2 + i); lcd_move_cursor(0, 2 + i);
lcd_write_string_page("CONTRAST:\0", i, contrast_selected); lcd_write_string_page("CONTRAST:\0", 2, i, contrast_selected);
lcd_write_kerning(2, contrast_selected); lcd_write_kerning(2, contrast_selected);
lcd_write_kerning(16, false); lcd_write_kerning(16, false);
lcd_write_integer_page(value_contrast, 2, i, lcd_write_integer_page(value_contrast, 2, i,
@ -514,7 +521,7 @@ static void draw_setup(void) {
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(0, 4 + i); lcd_move_cursor(0, 4 + i);
lcd_write_string_page("BACKLIGHT:\0", i, backlight_selected); lcd_write_string_page("BACKLIGHT:\0", 2, i, backlight_selected);
lcd_write_kerning(2, backlight_selected); lcd_write_kerning(2, backlight_selected);
lcd_write_kerning(5, false); lcd_write_kerning(5, false);
lcd_write_integer_page(value_backlight, 3, i, lcd_write_integer_page(value_backlight, 3, i,
@ -524,7 +531,7 @@ static void draw_setup(void) {
for (uint8_t i = 0; i < 2; i++) { for (uint8_t i = 0; i < 2; i++) {
lcd_move_cursor(33, 6 + i); lcd_move_cursor(33, 6 + i);
lcd_write_string_page("BACK:\0", i, back_selected); lcd_write_string_page("BACK\0", 2, i, back_selected);
lcd_write_kerning(2, back_selected); lcd_write_kerning(2, back_selected);
} }
} }
@ -790,7 +797,7 @@ int main(void) {
TIMSK1 |= (1 << OCIE1A); // Enable match compare A TIMSK1 |= (1 << OCIE1A); // Enable match compare A
// Show splash screen // Show splash screen
lcd_splash(); draw_splash();
_delay_ms(2000); _delay_ms(2000);
// Load the menu // Load the menu