diff --git a/Makefile b/Makefile index 87dd3a0..ad5b99f 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ OFILES = $(patsubst src/%.c, $(OUTDIR)/%.o, $(CFILES)) \ $(patsubst src/%.s, $(OUTDIR)/%.asm.o, $(AFILES)) LIBDIR = -Llib -LIBS = -llua +LIBS = HEX = main.hex diff --git a/include/serial.h b/include/serial.h new file mode 100644 index 0000000..5b90748 --- /dev/null +++ b/include/serial.h @@ -0,0 +1,8 @@ +#ifndef SERIAL_H_ +#define SERIAL_H_ + +void serial_init(void); +void serial_put(int c); +char serial_get(void); + +#endif // SERIAL_H_ diff --git a/lib/liblua.a b/lib/liblua.a deleted file mode 100644 index d5a4c6b..0000000 Binary files a/lib/liblua.a and /dev/null differ diff --git a/src/main.c b/src/main.c index d974ebc..30bb183 100644 --- a/src/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include #include #include +#include /** * Accomplishments: @@ -15,7 +16,8 @@ * - gpio lib * - lcd support * - initrd support - * - lua? + * - lua? - no, something better, smaller + * - serial IO */ void pulse(uint8_t byte); @@ -35,12 +37,14 @@ int main(void) gpio_mode(GPIOA, 5, OUTPUT); + serial_init(); + task_init(kmain); while (1); } -void task(void); +void serial_getter(void); void kmain(void) { asm("cpsie i"); @@ -48,12 +52,11 @@ void kmain(void) task_start(lcd_handler, 128); delay(200); - char *s = initrd_getfile("test.txt"); - const char *t = "Yoyoyo"; - - asm("mov r0, %0; svc 2" :: "r" (s)); - asm("mov r0, %0; svc 2" :: "r" (t)); + //char *s = initrd_getfile("test.txt"); + // svc puts + //asm("mov r0, %0; svc 2" :: "r" (s)); + task_start(serial_getter, 128); while (1) { gpio_dout(GPIOA, 5, 1); delay(500); @@ -62,3 +65,11 @@ void kmain(void) } } +void serial_getter(void) +{ + char buf[2] = { 0, 0 }; + while (1) { + buf[0] = serial_get(); + asm("mov r0, %0; svc 2" :: "r" (buf)); + } +} diff --git a/src/serial.c b/src/serial.c new file mode 100644 index 0000000..692faf0 --- /dev/null +++ b/src/serial.c @@ -0,0 +1,27 @@ +#include +#include + +void serial_init(void) +{ + gpio_mode(GPIOA, 2, ALTERNATE); + gpio_mode(GPIOA, 3, ALTERNATE); + GPIOA->AFR[0] &= ~(0x0000FF00); + GPIOA->AFR[0] |= 0x00007700; + RCC->APB1ENR1 |= RCC_APB1ENR1_USART2EN; + + // start usart device + USART2->BRR = 80000000L / 115200L; + USART2->CR1 |= USART_CR1_TE | USART_CR1_RE | USART_CR1_UE; +} + +void serial_put(int c) +{ + while (!(USART2->ISR & USART_ISR_TXE)); + USART2->TDR = c & 0xFF; +} + +char serial_get(void) +{ + while (!(USART2->ISR & USART_ISR_RXNE)); + return USART2->RDR & 0xFF; +}