From a1e53a911fa02e8739f1215276e71bc32b7600c6 Mon Sep 17 00:00:00 2001 From: Maix0 <39835848+Maix0@users.noreply.github.com> Date: Thu, 16 Apr 2026 10:08:48 +0200 Subject: [PATCH] feat(ex04): better control char handling and commenting unused functions --- ex04/Makefile | 2 +- ex04/src/main.c | 7 +++++++ ex04/src/timer.c | 38 -------------------------------------- ex04/src/uart.c | 3 ++- 4 files changed, 10 insertions(+), 40 deletions(-) delete mode 100644 ex04/src/timer.c diff --git a/ex04/Makefile b/ex04/Makefile index add8cae..5c58470 100644 --- a/ex04/Makefile +++ b/ex04/Makefile @@ -12,7 +12,7 @@ SERIAL=-P /dev/ttyUSB0 -b 115200 SRC_DIR=src OBJ_DIR=build -SRC_FILES=main.c utils.c uart.c timer.c +SRC_FILES=main.c utils.c uart.c OBJ_FILES=$(patsubst %.c,%.o,$(SRC_FILES)) SRC=$(addprefix $(SRC_DIR)/,$(SRC_FILES)) diff --git a/ex04/src/main.c b/ex04/src/main.c index eb2b200..8966adc 100644 --- a/ex04/src/main.c +++ b/ex04/src/main.c @@ -94,6 +94,10 @@ int main(void) { } continue; } + + // this is a control char -> we dont want it ! + if (data < ' ' || data > '~') + continue; uart_tx(data); if (cursor + 1 >= BUFFERSIZE) { @@ -119,6 +123,9 @@ int main(void) { } continue; } + // this is a control char -> we dont want it ! + if (data < ' ' || data > '~') + continue; uart_tx('*'); if (cursor + 1 >= BUFFERSIZE) { diff --git a/ex04/src/timer.c b/ex04/src/timer.c deleted file mode 100644 index bc35f18..0000000 --- a/ex04/src/timer.c +++ /dev/null @@ -1,38 +0,0 @@ - -#include -#include -#include "mystd.h" -#include "utils.h" - -#define PRESCALER 256 -#define TIMER_FREQ (F_CPU / PRESCALER) - -// at a high level: -// Set the OC1B (PB2) pin as output -// set the TIMER1 mode to COMPARE (CTC) -// say to compare against OC1A -// set the value to be compated at X count -// say the presacler for the timer is 512 -// -// all these information are on page ~140 -void timer1_init(void) { - // Set PB1 (OC1A) as output - DDRB |= _BV(PB1); - - // CTC mode (WGM12 = 1) - TCCR1B |= _BV(WGM12); - - // Toggle OC1B on compare match (COM1B0 = 1) - // TCCR1A |= _BV(COM1A0); - - // Set compare values - OCR1A = TIMER_FREQ / 2; - - // Start timer with prescaler 256 (CS12) - TCCR1B |= _BV(CS12); - - // set OCR1A interrupt - TIMSK1 = _BV(1); - - sei(); -} diff --git a/ex04/src/uart.c b/ex04/src/uart.c index e98d35f..182c08f 100644 --- a/ex04/src/uart.c +++ b/ex04/src/uart.c @@ -47,7 +47,7 @@ void uart_sendstring(const char* str) { str++; } } - +/* void uart_send_u8(uint8_t val) { char buf[4] = {0, 0, 0, 0}; uint8_t idx = 0; @@ -102,3 +102,4 @@ void uart_send_u16_hex(uint16_t val) { buf[3] = "0123456789abcdef"[(val >> 0) & 0x0F]; uart_sendstring(buf); } +*/