diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index 0d3812687d89ded516bf9f7b54b3d5f21506fa86..1a77cbc42bc7290ced106e6a7dd08f2ca426669e 100644 --- a/ch32v003fun/ch32v003fun.c +++ b/ch32v003fun/ch32v003fun.c @@ -897,7 +897,6 @@ int _write(int fd, const char *buf, int size) if( timeout-- == 0 ) return place; timeout = 160000; - uint32_t d; int t = 3; while( t < tosend ) { diff --git a/examples/blink/Makefile b/examples/blink/Makefile index aaddf1dbac01fa6f4b4e66bac09eed1932ba8a7f..903895a7dfe36edc07add43fa87c8924522fc280 100644 --- a/examples/blink/Makefile +++ b/examples/blink/Makefile @@ -27,7 +27,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. -DTINYVECTOR + -I. -DTINYVECTOR -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/blink/blink.bin b/examples/blink/blink.bin index b3a46101b449bc35e39918f5f26d29ececf14ff7..b0cf5a4fa20b888e4185c78fd1a5230786bc2059 100755 Binary files a/examples/blink/blink.bin and b/examples/blink/blink.bin differ diff --git a/examples/debugprintfdemo/Makefile b/examples/debugprintfdemo/Makefile index 0bd546aa383413b1469e7b74ef3f03bc6a9d9be7..64e8f95c1556a04f31d402622a4e3e74959e067b 100644 --- a/examples/debugprintfdemo/Makefile +++ b/examples/debugprintfdemo/Makefile @@ -17,7 +17,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. + -I. -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/debugprintfdemo/debugprintfdemo.c b/examples/debugprintfdemo/debugprintfdemo.c index 676b024b734618cb986f0a92e461e4f7d3703e07..7c19fac0fc675c73d73c4188a184d2949811bad8 100644 --- a/examples/debugprintfdemo/debugprintfdemo.c +++ b/examples/debugprintfdemo/debugprintfdemo.c @@ -30,10 +30,10 @@ int main() { GPIOD->BSHR = 1 | (1<<4); // Turn on GPIOs GPIOC->BSHR = 1; - printf( "+%d\n", count++ ); + printf( "+%lu\n", count++ ); GPIOD->BSHR = (1<<16) | (1<<(16+4)); // Turn off GPIODs GPIOC->BSHR = (1<<16); - printf( "-%d\n", count++ ); + printf( "-%lu\n", count++ ); count++; //_write( 0, "xxxxxxx", 7 ); } diff --git a/examples/external_crystal/Makefile b/examples/external_crystal/Makefile index 4f4b542e0ff670e4b1ad4cf990adcb7e55d552b0..74326f1b80c99f4ed601439deb3c7f84d5aaf9b9 100644 --- a/examples/external_crystal/Makefile +++ b/examples/external_crystal/Makefile @@ -27,7 +27,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. -DTINYVECTOR + -I. -DTINYVECTOR -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/run_from_ram/Makefile b/examples/run_from_ram/Makefile index 41dd42d3616849f0e9271561530dcb6926610b6a..e6c6caa645228db5ff67ff6f952f52b1afa7e4a6 100644 --- a/examples/run_from_ram/Makefile +++ b/examples/run_from_ram/Makefile @@ -27,7 +27,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. -DTINYVECTOR + -I. -DTINYVECTOR -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/sandbox/Makefile b/examples/sandbox/Makefile index d2c3451040d0ad87ecbd1bef27a9780bd1c19d44..621e2fca5a82b124604734d3a979ccc72698d992 100644 --- a/examples/sandbox/Makefile +++ b/examples/sandbox/Makefile @@ -17,7 +17,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. + -I. -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/sandbox/sandbox.c b/examples/sandbox/sandbox.c index 742254cd6ac53cd22462a0c758a4a517a0c89634..33b76fdefb866b36fdd030c949f2710a7ad3fee0 100644 --- a/examples/sandbox/sandbox.c +++ b/examples/sandbox/sandbox.c @@ -21,6 +21,7 @@ void SRAMCode( ) "1: c.sw a1, 0(a0)\n" " c.sw a2, 0(a0)\n" " j 1b\n" ); + __builtin_unreachable(); } int main() diff --git a/examples/self_modify_code/Makefile b/examples/self_modify_code/Makefile index ebe3d0b89b3d4b8a8de1aac99def670d88fd6492..f4d72fe826a2957824323d10c34e57799ffd6c27 100644 --- a/examples/self_modify_code/Makefile +++ b/examples/self_modify_code/Makefile @@ -17,7 +17,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. + -I. -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/self_modify_code/self_modify_code.c b/examples/self_modify_code/self_modify_code.c index bf33dc5b56cbd76408260709067db4aaf65bcaa6..3e897f312eec2ef2a0a6ce02bcee91d104c4caf0 100644 --- a/examples/self_modify_code/self_modify_code.c +++ b/examples/self_modify_code/self_modify_code.c @@ -91,7 +91,7 @@ int main() { uint32_t rv = ReadCSRSelfModifySimple( i ); if( rv ) - printf( "%03x = %08x\n", i, rv ); + printf( "%03x = %08lx\n", i, rv ); } printf( "Done\n" ); for(;;); diff --git a/examples/uartdemo/Makefile b/examples/uartdemo/Makefile index 9e1925e9012e971f48a1efb4053a822441823952..24d8be31704bb8159fccfdbd9d6dea5d559934ed 100644 --- a/examples/uartdemo/Makefile +++ b/examples/uartdemo/Makefile @@ -17,7 +17,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. -DSTDOUT_UART + -I. -DSTDOUT_UART -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/uartdemo/uartdemo.c b/examples/uartdemo/uartdemo.c index b7e562c9c81e7666653f36a14a86f8963c7c8246..3907a466357e4a8f8eb14b56a6df01b0898c0f96 100644 --- a/examples/uartdemo/uartdemo.c +++ b/examples/uartdemo/uartdemo.c @@ -29,6 +29,6 @@ int main() Delay_Ms( 50 ); GPIOD->BSHR = 1<<16; // Turn off GPIOD0 Delay_Ms( 50 ); - printf( "Count: %d\n", count++ ); + printf( "Count: %lu\n", count++ ); } } diff --git a/examples/ws2812bdemo/Makefile b/examples/ws2812bdemo/Makefile index d387c58f1a82b858685ebcb51b6f2da3ad415f23..50fb288bf17931ce8b572b7a9dedac01a0585e7c 100644 --- a/examples/ws2812bdemo/Makefile +++ b/examples/ws2812bdemo/Makefile @@ -15,7 +15,7 @@ CFLAGS:= \ -I/usr/include/newlib \ -I$(CH32V003FUN) \ -nostdlib \ - -I. + -I. -Wall LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections diff --git a/examples/ws2812bdemo/color_utilities.h b/examples/ws2812bdemo/color_utilities.h index 3a9d20095c1a2ea8435b5cd19a95c8e949d1f569..3b6f1b74bac1e269eff0a6668f6712e483a5038f 100644 --- a/examples/ws2812bdemo/color_utilities.h +++ b/examples/ws2812bdemo/color_utilities.h @@ -7,7 +7,9 @@ #ifndef _COLOR_UTILITIES_H #define _COLOR_UTILITIES_H - +// To stop warnings about unused functions. +static uint32_t EHSVtoHEX( uint8_t hue, uint8_t sat, uint8_t val ) __attribute__((used)); +static uint32_t TweenHexColors( uint32_t hexa, uint32_t hexb, int tween ) __attribute__((used)); static uint32_t EHSVtoHEX( uint8_t hue, uint8_t sat, uint8_t val ) { @@ -136,6 +138,8 @@ static const unsigned char sintable[] = { static uint32_t TweenHexColors( uint32_t hexa, uint32_t hexb, int tween ) { + if( tween <= 0 ) return hexa; + if( tween >= 255 ) return hexb; int32_t aamt = 255-tween; int32_t bamt = tween; int32_t hab = hexa & 0xff; diff --git a/examples/ws2812bdemo/ws2812b_dma_spi_led_driver.h b/examples/ws2812bdemo/ws2812b_dma_spi_led_driver.h index d47d8a0090217cac540fe680878284d0bfe60ad4..15a62d391aeff540d781992b68eae629fa9b0d66 100644 --- a/examples/ws2812bdemo/ws2812b_dma_spi_led_driver.h +++ b/examples/ws2812bdemo/ws2812b_dma_spi_led_driver.h @@ -34,14 +34,14 @@ uint32_t WS2812BLEDCallback( int ledno ); #ifdef WS2812DMA_IMPLEMENTATION -// Note first 2 LEDs of DMA Buffer are 0's as a "break" +// Must be divisble by 4. +#define DMALEDS 16 + +// Note first n LEDs of DMA Buffer are 0's as a "break" // Need one extra LED at end to leave line high. // This must be greater than WS2812B_RESET_PERIOD. -// 1: Divisble by 2. -// 2: -#define DMALEDS 16 #define WS2812B_RESET_PERIOD 2 -#define DMA_BUFFER_LEN (((DMALEDS+1)/2)*6) +#define DMA_BUFFER_LEN (((DMALEDS)/2)*6) // The +1 is for the buffered start. static uint16_t WS2812dmabuff[DMA_BUFFER_LEN]; static volatile int WS2812LEDs; @@ -98,12 +98,22 @@ static void WS2812FillBuffSec( uint16_t * ptr, int numhalfwords, int tce ) // Use a LUT to figure out how we should set the SPI line. uint32_t ledval24bit = WS2812BLEDCallback( place++ ); + +#ifdef WSRBG + ptr[0] = bitquartets[(ledval24bit>>12)&0xf]; + ptr[1] = bitquartets[(ledval24bit>>8)&0xf]; + ptr[2] = bitquartets[(ledval24bit>>20)&0xf]; + ptr[3] = bitquartets[(ledval24bit>>16)&0xf]; + ptr[4] = bitquartets[(ledval24bit>>4)&0xf]; + ptr[5] = bitquartets[(ledval24bit>>0)&0xf]; +#else ptr[0] = bitquartets[(ledval24bit>>20)&0xf]; ptr[1] = bitquartets[(ledval24bit>>16)&0xf]; ptr[2] = bitquartets[(ledval24bit>>12)&0xf]; ptr[3] = bitquartets[(ledval24bit>>8)&0xf]; ptr[4] = bitquartets[(ledval24bit>>4)&0xf]; ptr[5] = bitquartets[(ledval24bit>>0)&0xf]; +#endif ptr += 6; i += 6; } @@ -122,12 +132,12 @@ void DMA1_Channel3_IRQHandler( void ) // Clear all possible flags. DMA1->INTFCR = DMA1_IT_GL3; - if( intfr & DMA1_IT_HT3 ) + if( intfr & DMA1_IT_TC3 ) { // Halfwaay (Fill in first part) WS2812FillBuffSec( WS2812dmabuff, DMA_BUFFER_LEN / 2, 1 ); } - if( intfr & DMA1_IT_TC3 ) + if( intfr & DMA1_IT_HT3 ) { // Complete (Fill in second part) WS2812FillBuffSec( WS2812dmabuff + DMA_BUFFER_LEN / 2, DMA_BUFFER_LEN / 2, 0 ); @@ -164,7 +174,7 @@ void WS2812BDMAInit( ) // MOSI, Configure GPIO Pin GPIOC->CFGLR &= ~(0xf<<(4*6)); - GPIOC->CFGLR |= (GPIO_Speed_50MHz | GPIO_CNF_OUT_PP_AF)<<(4*6); + GPIOC->CFGLR |= (GPIO_Speed_10MHz | GPIO_CNF_OUT_PP_AF)<<(4*6); // Configure SPI SPI1->CTLR1 = diff --git a/examples/ws2812bdemo/ws2812bdemo.c b/examples/ws2812bdemo/ws2812bdemo.c index c2661ac5bb3f5d627af9311c51edbad9afb37276..c4a826218a452ba3a7f925feaec988c690f11dff 100644 --- a/examples/ws2812bdemo/ws2812bdemo.c +++ b/examples/ws2812bdemo/ws2812bdemo.c @@ -7,16 +7,17 @@ #include <string.h> #define WS2812DMA_IMPLEMENTATION +#define WSRBG //For WS2816C's. +#define NR_LEDS 191 #include "ws2812b_dma_spi_led_driver.h" #include "color_utilities.h" -#define NR_LEDS 191 uint16_t phases[NR_LEDS]; int frameno; -volatile int tween = 0; +volatile int tween = -NR_LEDS; // Callbacks that you must implement. uint32_t WS2812BLEDCallback( int ledno ) @@ -24,11 +25,11 @@ uint32_t WS2812BLEDCallback( int ledno ) uint8_t index = (phases[ledno])>>8; uint8_t rsbase = sintable[index]; uint8_t rs = rsbase>>3; - uint32_t fire = huetable[(rs+190&0xff)] | (huetable[(rs+30&0xff)]<<8) | (huetable[(rs+0)]<<16); - uint32_t ice = 0xff | ((rsbase)<<8) | ((rsbase)<<16); + uint32_t fire = (huetable[(rs+190)&0xff]<<16) | (huetable[(rs+30)&0xff]) | (huetable[(rs+0)]<<8); + uint32_t ice = 0xff0000 | ((rsbase)<<8) | ((rsbase)); - // Because this chip doesn't natively support multiplies, this can be very slow. - return TweenHexColors( fire, ice, tween ); // Where "tween" is a value from 0 ... 255 + // Because this chip doesn't natively support multiplies, we are going to avoid tweening of 1..254. + return TweenHexColors( fire, ice, ((tween + ledno)>0)?255:0 ); // Where "tween" is a value from 0 ... 255 } int main() @@ -65,11 +66,11 @@ int main() if( frameno == 1024 ) { - tweendir = 4; + tweendir = 1; } if( frameno == 2048 ) { - tweendir = -4; + tweendir = -1; frameno = 0; } @@ -77,7 +78,7 @@ int main() { int t = tween + tweendir; if( t > 255 ) t = 255; - if( t < 0 ) t = 0; + if( t < -NR_LEDS ) t = -NR_LEDS; tween = t; }