From e0d4a112c0464413c879713dd11a52357b959283 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 10 Feb 2025 18:54:17 +0100 Subject: [PATCH] Rename blink.c to main.c --- Makefile | 4 +++- blink.c | 19 ------------------- main.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 20 deletions(-) delete mode 100644 blink.c create mode 100644 main.c diff --git a/Makefile b/Makefile index f90a85b..72efea9 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ CC := $(TOOL_PREFIX)-gcc OBJDUMP := $(TOOL_PREFIX)-objdump OBJCOPY := $(TOOL_PREFIX)-objcopy +SRC := ch32fun.c main.c + CFLAGS = -g \ -Os \ -flto \ @@ -36,7 +38,7 @@ EXTFLAGS := -march=rv32ec \ default: $(TARGET).bin -$(TARGET).elf: ch32fun.c blink.c | ch32v003.ld ch32fun.h ch32v003hw.h +$(TARGET).elf: $(SRC) | ch32v003.ld ch32fun.h ch32v003hw.h @echo CC $@ @$(CC) $(CFLAGS) $(LDFLAGS) $(EXTFLAGS) -o $@ $^ diff --git a/blink.c b/blink.c deleted file mode 100644 index 4b37dc7..0000000 --- a/blink.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "ch32fun.h" - -#define LED_PIN PD6 - -int main() { - SystemInit(); - - // Enable GPIOs - funGpioInitAll(); - - funPinMode(LED_PIN, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP); - - while (1) { - funDigitalWrite(LED_PIN, FUN_HIGH); - Delay_Ms(250); - funDigitalWrite(LED_PIN, FUN_LOW); - Delay_Ms(250); - } -} diff --git a/main.c b/main.c new file mode 100644 index 0000000..f7fded8 --- /dev/null +++ b/main.c @@ -0,0 +1,39 @@ +#include +#include + +#define LED_PIN PD6 +#define FREQ 2 +#define BLINK_DELAY 1000 / FREQ + +void exit_blink() { + for (int i = 0; i < 4; i++) { + funDigitalWrite(LED_PIN, FUN_HIGH); + Delay_Ms(50); + funDigitalWrite(LED_PIN, FUN_LOW); + Delay_Ms(50); + } + + while (1){}; + + funDigitalWrite(LED_PIN, FUN_HIGH); +} + +int main() { + SystemInit(); + + // Enable GPIOs + funGpioInitAll(); + + funPinMode(LED_PIN, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP); + + int i = 0; + while (i < gcd(930, 10)) { + i++; + funDigitalWrite(LED_PIN, FUN_HIGH); + Delay_Ms(BLINK_DELAY); + funDigitalWrite(LED_PIN, FUN_LOW); + Delay_Ms(BLINK_DELAY); + } + + exit_blink(); +}