Skip to content

Commit

Permalink
Fix warnings + add -Wall
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Mar 23, 2023
1 parent 6c06cef commit 1d26dfa
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 31 deletions.
1 change: 0 additions & 1 deletion ch32v003fun/ch32v003fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion examples/blink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified examples/blink/blink.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/debugprintfdemo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CFLAGS:= \
-I/usr/include/newlib \
-I$(CH32V003FUN) \
-nostdlib \
-I.
-I. -Wall

LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections

Expand Down
4 changes: 2 additions & 2 deletions examples/debugprintfdemo/debugprintfdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
2 changes: 1 addition & 1 deletion examples/external_crystal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/run_from_ram/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/sandbox/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CFLAGS:= \
-I/usr/include/newlib \
-I$(CH32V003FUN) \
-nostdlib \
-I.
-I. -Wall

LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections

Expand Down
1 change: 1 addition & 0 deletions examples/sandbox/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/self_modify_code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CFLAGS:= \
-I/usr/include/newlib \
-I$(CH32V003FUN) \
-nostdlib \
-I.
-I. -Wall

LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections

Expand Down
2 changes: 1 addition & 1 deletion examples/self_modify_code/self_modify_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(;;);
Expand Down
2 changes: 1 addition & 1 deletion examples/uartdemo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/uartdemo/uartdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++ );
}
}
2 changes: 1 addition & 1 deletion examples/ws2812bdemo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CFLAGS:= \
-I/usr/include/newlib \
-I$(CH32V003FUN) \
-nostdlib \
-I.
-I. -Wall

LDFLAGS:=-T $(CH32V003FUN)/ch32v003fun.ld -Wl,--gc-sections

Expand Down
6 changes: 5 additions & 1 deletion examples/ws2812bdemo/color_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
26 changes: 18 additions & 8 deletions examples/ws2812bdemo/ws2812b_dma_spi_led_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 );
Expand Down Expand Up @@ -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 =
Expand Down
19 changes: 10 additions & 9 deletions examples/ws2812bdemo/ws2812bdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
#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 )
{
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()
Expand Down Expand Up @@ -65,19 +66,19 @@ int main()

if( frameno == 1024 )
{
tweendir = 4;
tweendir = 1;
}
if( frameno == 2048 )
{
tweendir = -4;
tweendir = -1;
frameno = 0;
}

if( tweendir )
{
int t = tween + tweendir;
if( t > 255 ) t = 255;
if( t < 0 ) t = 0;
if( t < -NR_LEDS ) t = -NR_LEDS;
tween = t;
}

Expand Down

0 comments on commit 1d26dfa

Please sign in to comment.