From 49d8791d0f401e952b30337f8f13532225572617 Mon Sep 17 00:00:00 2001 From: cnlohr 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&plT0oePGeTr%IByqYbP#T3b8wtJ diff --git a/examples/blink/blink.c b/examples/blink/blink.c index e2d55705..b12dc6f3 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 00000000..9fb166e1 --- /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_^%PELOK|NZy=dvLc5&qFU&Fto-OoFqxj9V{dj@IVv3rgnZ8z40Yu$yWGGA@jM zU248cxRZ?ex$PDx(%KPUaz=K&MO<^q6Ur0^IM#+BRp5 ziby-7AX8PWIGaf}F6fHG=m}KXHUXiVFy8jw95H!FOBagR28FHRrm}uievN1_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 00000000..e2d55705 --- /dev/null +++ b/examples/blink_raw/blink_raw.c @@ -0,0 +1,36 @@ +#include "ch32v003fun.h" +#include + +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 00000000..998cf76f --- /dev/null +++ b/examples/blink_raw/funconfig.h @@ -0,0 +1,7 @@ +#ifndef _FUNCONFIG_H +#define _FUNCONFIG_H + +#define CH32V003 1 + +#endif +