From 1d26dfa4b2985ee695c59b3bca5fc92e3f87edc0 Mon Sep 17 00:00:00 2001 From: cnlohr <lohr85@gmail.com> Date: Thu, 23 Mar 2023 02:35:46 -0400 Subject: [PATCH] Fix warnings + add -Wall --- ch32v003fun/ch32v003fun.c | 1 - examples/blink/Makefile | 2 +- examples/blink/blink.bin | Bin 544 -> 548 bytes examples/debugprintfdemo/Makefile | 2 +- examples/debugprintfdemo/debugprintfdemo.c | 4 +-- examples/external_crystal/Makefile | 2 +- examples/run_from_ram/Makefile | 2 +- examples/sandbox/Makefile | 2 +- examples/sandbox/sandbox.c | 1 + examples/self_modify_code/Makefile | 2 +- examples/self_modify_code/self_modify_code.c | 2 +- examples/uartdemo/Makefile | 2 +- examples/uartdemo/uartdemo.c | 2 +- examples/ws2812bdemo/Makefile | 2 +- examples/ws2812bdemo/color_utilities.h | 6 +++- .../ws2812bdemo/ws2812b_dma_spi_led_driver.h | 26 ++++++++++++------ examples/ws2812bdemo/ws2812bdemo.c | 19 +++++++------ 17 files changed, 46 insertions(+), 31 deletions(-) diff --git a/ch32v003fun/ch32v003fun.c b/ch32v003fun/ch32v003fun.c index 0d38126..1a77cbc 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 aaddf1d..903895a 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 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/examples/debugprintfdemo/Makefile b/examples/debugprintfdemo/Makefile index 0bd546a..64e8f95 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 676b024..7c19fac 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 4f4b542..74326f1 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 41dd42d..e6c6caa 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 d2c3451..621e2fc 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 742254c..33b76fd 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 ebe3d0b..f4d72fe 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 bf33dc5..3e897f3 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 9e1925e..24d8be3 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 b7e562c..3907a46 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 d387c58..50fb288 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 3a9d200..3b6f1b7 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 d47d8a0..15a62d3 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 c2661ac..c4a8262 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; } -- GitLab