2023-04-28 00:19:56 +08:00
|
|
|
#include "adc.h"
|
2023-04-17 21:56:42 +08:00
|
|
|
#include "derivative.h"
|
|
|
|
#include "systick.h"
|
2023-04-27 01:30:27 +08:00
|
|
|
#include "tftlcd.h"
|
2023-04-17 21:56:42 +08:00
|
|
|
#include "uart.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2023-04-28 00:19:56 +08:00
|
|
|
#define ADC_M 2048
|
|
|
|
|
2023-04-17 21:56:42 +08:00
|
|
|
int main(void) {
|
|
|
|
// Initialize
|
2023-04-28 00:19:56 +08:00
|
|
|
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
|
2023-04-17 21:56:42 +08:00
|
|
|
|
|
|
|
uart_printf(UART_MSG, "System Clock: %lu\r\n", CORCLK);
|
|
|
|
uart_printf(UART_MSG, "Bus Clock: %lu\r\n", BUSCLK);
|
|
|
|
|
2023-04-28 00:19:56 +08:00
|
|
|
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;
|
2023-04-17 21:56:42 +08:00
|
|
|
uint32_t timer = 0;
|
2023-04-28 00:19:56 +08:00
|
|
|
|
2023-04-17 21:56:42 +08:00
|
|
|
for (;;) {
|
2023-04-28 00:19:56 +08:00
|
|
|
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;
|
2023-04-17 21:56:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|