feat: GUI Audio Sample

This commit is contained in:
liuyihui 2023-04-28 00:19:56 +08:00
parent b03493a411
commit c9af85ad08

40
main.c
View File

@ -1,3 +1,4 @@
#include "adc.h"
#include "derivative.h" #include "derivative.h"
#include "systick.h" #include "systick.h"
#include "tftlcd.h" #include "tftlcd.h"
@ -5,20 +6,47 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define ADC_M 2048
int main(void) { int main(void) {
// Initialize // Initialize
SysTick_Config(CORCLK / 1000); // Period of systick timer : 1ms uart_init(UART_MSG, 9600); // Initialize UART1 with PC
uart_init(UART_MSG, 9600); // Initialize UART1 with PC uart_rie_enable(UART_MSG); // Enable UART1 receive interrupt
uart_rie_enable(UART_MSG); // Enable UART1 receive interrupt LCD_Init(); // Initialize LCD
LCD_Init(); // Initialize LCD adc0_Init(); // Initialize ADC0
uart_printf(UART_MSG, "System Clock: %lu\r\n", CORCLK); uart_printf(UART_MSG, "System Clock: %lu\r\n", CORCLK);
uart_printf(UART_MSG, "Bus Clock: %lu\r\n", BUSCLK); 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; uint32_t timer = 0;
for (;;) { for (;;) {
if (timer_expired(&timer, 1000)) { if (timer_expired_10us(&timer, 5)) {
uart_printf(UART_MSG, "UART RD: %d, tick: %lu\r\n", UART_MSG->S1 & UART_S1_RDRF_MASK ? 1 : 0, ms_ticks); 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;
} }
} }
} }