From 49d8791d0f401e952b30337f8f13532225572617 Mon Sep 17 00:00:00 2001
From: cnlohr <lohr85@gmail.com>
Date: Sun, 21 Jan 2024 20:56:36 -0800
Subject: [PATCH] Switch blink example to using easy mode

---
 examples/blink/blink.bin         | Bin 576 -> 548 bytes
 examples/blink/blink.c           |  35 ++++++++++++------------------
 examples/blink_raw/Makefile      |  10 +++++++++
 examples/blink_raw/blink_raw.bin | Bin 0 -> 552 bytes
 examples/blink_raw/blink_raw.c   |  36 +++++++++++++++++++++++++++++++
 examples/blink_raw/funconfig.h   |   7 ++++++
 6 files changed, 67 insertions(+), 21 deletions(-)
 create mode 100644 examples/blink_raw/Makefile
 create mode 100644 examples/blink_raw/blink_raw.bin
 create mode 100644 examples/blink_raw/blink_raw.c
 create mode 100644 examples/blink_raw/funconfig.h

diff --git a/examples/blink/blink.bin b/examples/blink/blink.bin
index af4d4a767892ea6c14c592527ecd43cb320b4288..517e40364a5159f4b16fa9abae76d3d8c41ce00f 100755
GIT binary patch
delta 163
zcmX@WvV>*A6D9|xiO*Kni!nNwvwi$O`FS|A%=yXfYz{M=YsJh(866yF3#W@S%s4#5
z*)e%LlK?|uzhhcpKZtM6#_+LLtgs(QGlE5&plT0oe<sFY{+;2$<Tf@l<rV1+$}7Sd
x%-I|mCY)B*NM+!0-!@giowx6?AKO1xw+W{Yy7rtFo6O3<(sNqiB(mhq?Eq4RJsSW3

delta 191
zcmZ3&a)4#R6D9_giO*Knvwi&kS8Vcgc4nFL+r=3jn3uCVOlA;ZWp#F(t-Rnln7^GV
zkl|pmaJo1HOr*3Q#yXf53TJO;WBB-23?T>PGeTr%IByqYbP#T3b8wtJ<M0e;kXbVh
xn?Dz0Fxvi|;ejwayP2|vD1-8fG=?7cT~jBx^Y%UVWBaG95egJ5LlJwp9{^o4M+5)>

diff --git a/examples/blink/blink.c b/examples/blink/blink.c
index e2d5570..b12dc6f 100644
--- a/examples/blink/blink.c
+++ b/examples/blink/blink.c
@@ -6,31 +6,24 @@ int main()
 	SystemInit();
 
 	// Enable GPIOs
-	RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC;
-
-	// GPIO D0 Push-Pull
-	GPIOD->CFGLR &= ~(0xf<<(4*0));
-	GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*0);
-
-	// GPIO D4 Push-Pull
-	GPIOD->CFGLR &= ~(0xf<<(4*4));
-	GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*4);
-
-	// GPIO D6 Push-Pull
-	GPIOD->CFGLR &= ~(0xf<<(4*6));
-	GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*6);
-
-	// GPIO C0 Push-Pull
-	GPIOC->CFGLR &= ~(0xf<<(4*0));
-	GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*0);
+	funGpioInitAll();
+	
+	funPinMode( PD0, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP );
+	funPinMode( PD4, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP );
+	funPinMode( PD6, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP );
+	funPinMode( PC0, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP );
 
 	while(1)
 	{
-		GPIOD->BSHR = (1<<0) | (1<<4) | (1<<6);	 // Turn on GPIOs
-		GPIOC->BSHR = (1<<0);
+		funDigitalWrite( PD0, FUN_HIGH );
+		funDigitalWrite( PD4, FUN_HIGH );
+		funDigitalWrite( PD6, FUN_HIGH );
+		funDigitalWrite( PC0, FUN_HIGH );
 		Delay_Ms( 250 );
-		GPIOD->BSHR = (1<<16) | (1<<(16+4)) | (1<<(16+6)); // Turn off GPIOs
-		GPIOC->BSHR = (1<<16);
+		funDigitalWrite( PD0, FUN_LOW );
+		funDigitalWrite( PD4, FUN_LOW );
+		funDigitalWrite( PD6, FUN_LOW );
+		funDigitalWrite( PC0, FUN_LOW );
 		Delay_Ms( 250 );
 	}
 }
diff --git a/examples/blink_raw/Makefile b/examples/blink_raw/Makefile
new file mode 100644
index 0000000..9fb166e
--- /dev/null
+++ b/examples/blink_raw/Makefile
@@ -0,0 +1,10 @@
+all : flash
+
+TARGET:=blink_raw
+
+include ../../ch32v003fun/ch32v003fun.mk
+
+flash : cv_flash
+clean : cv_clean
+
+
diff --git a/examples/blink_raw/blink_raw.bin b/examples/blink_raw/blink_raw.bin
new file mode 100644
index 0000000000000000000000000000000000000000..4c86c4525963d86c0b634527880c398e707f73e6
GIT binary patch
literal 552
zcmcIfF-XHe6#W;uyC7O3iH%5yYCs)3h_^<A%~t79UAh%r9g1#36%;|NN-8ZCRD?ni
z7l)crN-Q14!A-CdFmq6Gi(V>%PELOK|NZy=dvLc5&<ng`2w<4^U-j+ziQ)bq9loWE
zAa1RrRe2qOj6uvxII){lF>qFU&Fto-OoFqxj9V{dj@IVv3rgnZ8z40Yu$yWGGA@jM
zU248cxRZ?ex$PDx(<SaWz;3k_*zeH6X2r2+d?>%KPUaz=K&MO<^q6Ur0^IM#+BRp5
ziby-7AX8PWIGaf}F6fHG=m}KXHUXiVFy8jw9<zoW6?Ff|^2Q<SjF=BImpksU7uXa!
z+69fs6h!UZi)<9q1LP*dy2&|4{ExM$<<XwlEmM(hQL2{=Hpn-SaI;!+N(MG;Ar01Z
z6hhX_`Na^Ym+rdA2>5H!FOBagR28FHRrm}uievN1_<yY}GNsj3&?Xk4&%8R6%>JUA
PB7s(4;M&SB?dkdx%j%3u

literal 0
HcmV?d00001

diff --git a/examples/blink_raw/blink_raw.c b/examples/blink_raw/blink_raw.c
new file mode 100644
index 0000000..e2d5570
--- /dev/null
+++ b/examples/blink_raw/blink_raw.c
@@ -0,0 +1,36 @@
+#include "ch32v003fun.h"
+#include <stdio.h>
+
+int main()
+{
+	SystemInit();
+
+	// Enable GPIOs
+	RCC->APB2PCENR |= RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC;
+
+	// GPIO D0 Push-Pull
+	GPIOD->CFGLR &= ~(0xf<<(4*0));
+	GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*0);
+
+	// GPIO D4 Push-Pull
+	GPIOD->CFGLR &= ~(0xf<<(4*4));
+	GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*4);
+
+	// GPIO D6 Push-Pull
+	GPIOD->CFGLR &= ~(0xf<<(4*6));
+	GPIOD->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*6);
+
+	// GPIO C0 Push-Pull
+	GPIOC->CFGLR &= ~(0xf<<(4*0));
+	GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP)<<(4*0);
+
+	while(1)
+	{
+		GPIOD->BSHR = (1<<0) | (1<<4) | (1<<6);	 // Turn on GPIOs
+		GPIOC->BSHR = (1<<0);
+		Delay_Ms( 250 );
+		GPIOD->BSHR = (1<<16) | (1<<(16+4)) | (1<<(16+6)); // Turn off GPIOs
+		GPIOC->BSHR = (1<<16);
+		Delay_Ms( 250 );
+	}
+}
diff --git a/examples/blink_raw/funconfig.h b/examples/blink_raw/funconfig.h
new file mode 100644
index 0000000..998cf76
--- /dev/null
+++ b/examples/blink_raw/funconfig.h
@@ -0,0 +1,7 @@
+#ifndef _FUNCONFIG_H
+#define _FUNCONFIG_H
+
+#define CH32V003           1
+
+#endif
+
-- 
GitLab