Rename blink.c to main.c

This commit is contained in:
Imbus 2025-02-10 18:54:17 +01:00
parent 973e3bbd28
commit e0d4a112c0
3 changed files with 42 additions and 20 deletions

View file

@ -10,6 +10,8 @@ CC := $(TOOL_PREFIX)-gcc
OBJDUMP := $(TOOL_PREFIX)-objdump OBJDUMP := $(TOOL_PREFIX)-objdump
OBJCOPY := $(TOOL_PREFIX)-objcopy OBJCOPY := $(TOOL_PREFIX)-objcopy
SRC := ch32fun.c main.c
CFLAGS = -g \ CFLAGS = -g \
-Os \ -Os \
-flto \ -flto \
@ -36,7 +38,7 @@ EXTFLAGS := -march=rv32ec \
default: $(TARGET).bin 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 $@ @echo CC $@
@$(CC) $(CFLAGS) $(LDFLAGS) $(EXTFLAGS) -o $@ $^ @$(CC) $(CFLAGS) $(LDFLAGS) $(EXTFLAGS) -o $@ $^

19
blink.c
View file

@ -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);
}
}

39
main.c Normal file
View file

@ -0,0 +1,39 @@
#include <ch32fun.h>
#include <rsa.h>
#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();
}