2020-07-11 12:41:08 +02:00
|
|
|
#include <avr/io.h>
|
2020-07-27 21:39:29 +02:00
|
|
|
#include <avr/interrupt.h>
|
2020-07-19 18:40:44 +02:00
|
|
|
#include <avr/pgmspace.h>
|
2020-07-27 21:39:29 +02:00
|
|
|
#include <util/delay.h>
|
2020-07-19 18:40:44 +02:00
|
|
|
#include "oled-display/lcd.h"
|
2020-07-27 21:39:29 +02:00
|
|
|
#include "input.h"
|
|
|
|
#include "systick.h"
|
2020-07-11 12:41:08 +02:00
|
|
|
|
2020-07-19 18:40:44 +02:00
|
|
|
#define PORT_SPI(t) t##B
|
|
|
|
#define PIN_SPI_CS (1 << 2)
|
|
|
|
|
2020-07-27 21:39:29 +02:00
|
|
|
int dbg = 0;
|
|
|
|
|
|
|
|
void spi_init()
|
|
|
|
{
|
|
|
|
SPCR = (1 << SPE);
|
|
|
|
SPSR = (1 << SPI2X);
|
|
|
|
DDRB |= (1 << 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t spi_proc()
|
2020-07-11 12:41:08 +02:00
|
|
|
{
|
2020-07-19 21:20:30 +02:00
|
|
|
static uint8_t new_data = 0;
|
2020-07-19 18:40:44 +02:00
|
|
|
static uint8_t x = 0;
|
|
|
|
static uint8_t y = DISPLAY_HEIGHT / 8 - 1;
|
|
|
|
uint8_t spi_cs;
|
2020-07-27 21:39:29 +02:00
|
|
|
|
2020-07-19 18:40:44 +02:00
|
|
|
spi_cs = !(PORT_SPI(PIN) & PIN_SPI_CS);
|
2020-07-27 21:39:29 +02:00
|
|
|
|
2020-07-19 18:40:44 +02:00
|
|
|
if (spi_cs) {
|
|
|
|
if (SPSR & (1 << SPIF)) {
|
2020-07-27 21:39:29 +02:00
|
|
|
//SPDR = get_rotary_delta();
|
|
|
|
SPDR = get_switch_event();
|
|
|
|
//SPDR = dbg;
|
2020-07-19 18:40:44 +02:00
|
|
|
lcd_set_buffer(x, y, SPDR);
|
|
|
|
if (y == 0) {
|
|
|
|
y = DISPLAY_HEIGHT / 8 - 1;
|
|
|
|
x++;
|
2020-07-19 21:20:30 +02:00
|
|
|
if (x == DISPLAY_WIDTH) {
|
2020-07-19 18:40:44 +02:00
|
|
|
x = 0;
|
2020-07-19 21:20:30 +02:00
|
|
|
new_data = 1; // Only update the display if a full frame was received
|
|
|
|
}
|
2020-07-19 18:40:44 +02:00
|
|
|
} else {
|
|
|
|
y--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-07-19 21:20:30 +02:00
|
|
|
if (new_data) {
|
2020-07-19 18:40:44 +02:00
|
|
|
lcd_display();
|
2020-07-19 21:20:30 +02:00
|
|
|
new_data = 0;
|
2020-07-19 18:40:44 +02:00
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
y = DISPLAY_HEIGHT / 8 - 1;
|
|
|
|
}
|
2020-07-27 21:39:29 +02:00
|
|
|
|
|
|
|
return spi_cs;
|
2020-07-19 18:40:44 +02:00
|
|
|
}
|
|
|
|
|
2020-07-27 21:39:29 +02:00
|
|
|
void lcd_startup()
|
|
|
|
{
|
2020-07-19 18:40:44 +02:00
|
|
|
lcd_init(LCD_DISP_ON);
|
|
|
|
lcd_gotoxy(0, 0);
|
|
|
|
lcd_puts_p(PSTR("== Internet Radio =="));
|
|
|
|
lcd_drawLine(0, 9, 120, 9, WHITE);
|
|
|
|
lcd_gotoxy(0, 2);
|
|
|
|
lcd_puts_p(PSTR("Starting up."));
|
|
|
|
lcd_gotoxy(0, 3);
|
|
|
|
lcd_puts_p(PSTR("Please wait..."));
|
|
|
|
lcd_display();
|
2020-07-27 21:39:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
cli();
|
|
|
|
|
|
|
|
lcd_startup();
|
|
|
|
spi_init();
|
|
|
|
systick_init();
|
|
|
|
input_init();
|
|
|
|
|
2020-07-19 18:40:44 +02:00
|
|
|
_delay_ms(10);
|
2020-07-27 21:39:29 +02:00
|
|
|
|
2020-07-19 18:40:44 +02:00
|
|
|
while (1) {
|
2020-07-27 21:39:29 +02:00
|
|
|
if (!spi_proc()) {
|
|
|
|
timer_proc();
|
|
|
|
input_proc();
|
|
|
|
}
|
2020-07-19 18:40:44 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2020-07-11 12:41:08 +02:00
|
|
|
}
|