From cc0eac299ebffb0dbee013bb378a2eb90cc12252 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 9 Feb 2025 17:44:00 +0100 Subject: [PATCH 1/3] Clang format --- .clang-format | 8 ++++++++ .gitignore | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..41e7b1a --- /dev/null +++ b/.clang-format @@ -0,0 +1,8 @@ +BasedOnStyle: LLVM +IndentWidth: 4 # Use 4 spaces for indentation +TabWidth: 4 # Tab width is also 4 spaces +UseTab: Never # Always use spaces instead of tabs +ColumnLimit: 80 # Wrap lines after 80 characters +AllowShortLoopsOnASingleLine: true +AlwaysBreakTemplateDeclarations: true +BreakConstructorInitializers: BeforeComma diff --git a/.gitignore b/.gitignore index 1b8f046..b8e4dc0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ ch32fun.h ch32fun.ld ch32v003hw.h ch32v003.ld +.cache +compile_commands.json From 48ef6cc25828498cf48dfa16c57035c84aead02e Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 9 Feb 2025 17:44:13 +0100 Subject: [PATCH 2/3] Refactor makefile a bit --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 71ef99e..f90a85b 100644 --- a/Makefile +++ b/Makefile @@ -52,14 +52,14 @@ ch32%: @echo "Fetching $@" @curl $(CURL_FLAGS) $(BASE)/$@ -$(TARGET).bin : $(TARGET).elf - @$(OBJCOPY) -O binary $< $(TARGET).bin +%.bin : %.elf + $(OBJCOPY) -O binary $< $@ -$(TARGET).lst : $(TARGET).elf - @$(OBJDUMP) -S $^ > $(TARGET).lst +%.lst : %.elf + $(OBJDUMP) -S $^ > $@ -$(TARGET).hex : $(TARGET).elf - @$(OBJCOPY) -O ihex $< $(TARGET).hex +%.hex : %.elf + $(OBJCOPY) -O ihex $< $@ flash: $(TARGET).bin minichlink -w $(TARGET).bin flash -b From 973e3bbd28d6b954a507376c565d81499867671c Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 9 Feb 2025 17:44:25 +0100 Subject: [PATCH 3/3] Reduce initial example code to bare minimum --- blink.c | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/blink.c b/blink.c index b44ceba..4b37dc7 100644 --- a/blink.c +++ b/blink.c @@ -1,35 +1,19 @@ #include "ch32fun.h" -#include -// use defines to make more meaningful names for our GPIO pins -#define PIN_1 PD0 -#define PIN_K PD4 -#define PIN_BOB PD6 -#define PIN_KEVIN PC0 +#define LED_PIN PD6 -int main() -{ - SystemInit(); +int main() { + SystemInit(); - // Enable GPIOs - funGpioInitAll(); - - funPinMode( PIN_1, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); - funPinMode( PIN_K, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); - funPinMode( PIN_BOB, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); - funPinMode( PIN_KEVIN, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP ); + // Enable GPIOs + funGpioInitAll(); - while(1) - { - funDigitalWrite( PIN_1, FUN_HIGH ); - funDigitalWrite( PIN_K, FUN_HIGH ); - funDigitalWrite( PIN_BOB, FUN_HIGH ); - funDigitalWrite( PIN_KEVIN, FUN_HIGH ); - Delay_Ms( 250 ); - funDigitalWrite( PIN_1, FUN_LOW ); - funDigitalWrite( PIN_K, FUN_LOW ); - funDigitalWrite( PIN_BOB, FUN_LOW ); - funDigitalWrite( PIN_KEVIN, FUN_LOW ); - Delay_Ms( 250 ); - } + 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); + } }