Compare commits

..

No commits in common. "953649725b6ffa2a782acb538184a9e2c1d0dc18" and "c0f8cac065634bf5ff77950bfd32578e56f9f1e9" have entirely different histories.

View file

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