diff --git a/main.c b/main.c index e964d62..dcd45c8 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,4 @@ +#include "adc.h" #include "derivative.h" #include "systick.h" #include "tftlcd.h" @@ -5,20 +6,47 @@ #include #include +#define ADC_M 2048 + int main(void) { // Initialize - SysTick_Config(CORCLK / 1000); // Period of systick timer : 1ms - uart_init(UART_MSG, 9600); // Initialize UART1 with PC - uart_rie_enable(UART_MSG); // Enable UART1 receive interrupt - LCD_Init(); // Initialize LCD + uart_init(UART_MSG, 9600); // Initialize UART1 with PC + uart_rie_enable(UART_MSG); // Enable UART1 receive interrupt + LCD_Init(); // Initialize LCD + adc0_Init(); // Initialize ADC0 uart_printf(UART_MSG, "System Clock: %lu\r\n", CORCLK); uart_printf(UART_MSG, "Bus Clock: %lu\r\n", BUSCLK); + LCD_ShowString(LCD_W / 3, 0, "Audio Sample", 16, 0, 1); + LCD_DrawLine(0, 16, LCD_W - 1, 16); + + uint16_t x0 = 16, y0 = 32; + uint16_t x1 = LCD_W - 8, y1 = LCD_H - 16; + uint16_t ym = (y0 + y1) / 2; + LCD_DrawLine(x0, y0, x0, y1); + LCD_DrawLine(x0, ym, x1, ym); + LCD_ShowChar(0, y0, 'A', 16, 0); + LCD_ShowChar(x1, ym, 'T', 16, 0); + + LCD_SetColor(BACK_COLOR); + + int16_t res; + uint16_t pos[x1 - x0 - 1]; + uint16_t x = x0 + 1, y; uint32_t timer = 0; + for (;;) { - if (timer_expired(&timer, 1000)) { - uart_printf(UART_MSG, "UART RD: %d, tick: %lu\r\n", UART_MSG->S1 & UART_S1_RDRF_MASK ? 1 : 0, ms_ticks); + if (timer_expired_10us(&timer, 5)) { + LCD_DrawPoint(x, pos[x - x0 - 1], BACK_COLOR); + + res = adc0_TR_DATA() - 1550; + y = ym + res * (y1 - ym) / ADC_M; + LCD_DrawPoint(x, y, RED); + LCD_DrawPoint(x, ym, BLACK); + + pos[x - x0 - 1] = y; + x = x + 1 < x1 ? x + 1 : x0 + 1; } } }