Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Horn
ch32v003fun
Commits
02c531f2
Commit
02c531f2
authored
2 years ago
by
cnlohr
Browse files
Options
Downloads
Patches
Plain Diff
* Disable profiling on WS2812B demo
* Fix sandbox compiling.
parent
2af39089
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/sandbox/sandbox.c
+3
-184
3 additions, 184 deletions
examples/sandbox/sandbox.c
examples/ws2812demo/ws2812b_dma_spi_led_driver.h
+2
-2
2 additions, 2 deletions
examples/ws2812demo/ws2812b_dma_spi_led_driver.h
with
5 additions
and
186 deletions
examples/sandbox/sandbox.c
+
3
−
184
View file @
02c531f2
...
...
@@ -5,10 +5,6 @@
#include
<stdio.h>
#include
<string.h>
#define WS2812DMA_IMPLEMENTATION
#include
"ws2812b_dma_spi_led_driver.h"
#define APB_CLOCK SYSTEM_CORE_CLOCK
// Working on WS2812 driving.
...
...
@@ -65,165 +61,6 @@ void SystemInit(void)
USART1
->
CTLR1
|=
CTLR1_UE_Set
;
}
uint32_t
EHSVtoHEX
(
uint8_t
hue
,
uint8_t
sat
,
uint8_t
val
)
{
#define SIXTH1 43
#define SIXTH2 85
#define SIXTH3 128
#define SIXTH4 171
#define SIXTH5 213
uint16_t
or
=
0
,
og
=
0
,
ob
=
0
;
hue
-=
SIXTH1
;
//Off by 60 degrees.
//TODO: There are colors that overlap here, consider
//tweaking this to make the best use of the colorspace.
if
(
hue
<
SIXTH1
)
//Ok: Yellow->Red.
{
or
=
255
;
og
=
255
-
((
uint16_t
)
hue
*
255
)
/
(
SIXTH1
);
}
else
if
(
hue
<
SIXTH2
)
//Ok: Red->Purple
{
or
=
255
;
ob
=
(
uint16_t
)
hue
*
255
/
SIXTH1
-
255
;
}
else
if
(
hue
<
SIXTH3
)
//Ok: Purple->Blue
{
ob
=
255
;
or
=
((
SIXTH3
-
hue
)
*
255
)
/
(
SIXTH1
);
}
else
if
(
hue
<
SIXTH4
)
//Ok: Blue->Cyan
{
ob
=
255
;
og
=
(
hue
-
SIXTH3
)
*
255
/
SIXTH1
;
}
else
if
(
hue
<
SIXTH5
)
//Ok: Cyan->Green.
{
og
=
255
;
ob
=
((
SIXTH5
-
hue
)
*
255
)
/
SIXTH1
;
}
else
//Green->Yellow
{
og
=
255
;
or
=
(
hue
-
SIXTH5
)
*
255
/
SIXTH1
;
}
uint16_t
rv
=
val
;
if
(
rv
>
128
)
rv
++
;
uint16_t
rs
=
sat
;
if
(
rs
>
128
)
rs
++
;
//or, og, ob range from 0...255 now.
//Need to apply saturation and value.
or
=
(
or
*
val
)
>>
8
;
og
=
(
og
*
val
)
>>
8
;
ob
=
(
ob
*
val
)
>>
8
;
//OR..OB == 0..65025
or
=
or
*
rs
+
255
*
(
256
-
rs
);
og
=
og
*
rs
+
255
*
(
256
-
rs
);
ob
=
ob
*
rs
+
255
*
(
256
-
rs
);
//printf( "__%d %d %d =-> %d\n", or, og, ob, rs );
or
>>=
8
;
og
>>=
8
;
ob
>>=
8
;
return
or
|
(
og
<<
8
)
|
((
uint32_t
)
ob
<<
16
);
}
const
unsigned
char
huetable
[]
=
{
0x00
,
0x06
,
0x0c
,
0x12
,
0x18
,
0x1e
,
0x24
,
0x2a
,
0x30
,
0x36
,
0x3c
,
0x42
,
0x48
,
0x4e
,
0x54
,
0x5a
,
0x60
,
0x66
,
0x6c
,
0x72
,
0x78
,
0x7e
,
0x84
,
0x8a
,
0x90
,
0x96
,
0x9c
,
0xa2
,
0xa8
,
0xae
,
0xb4
,
0xba
,
0xc0
,
0xc6
,
0xcc
,
0xd2
,
0xd8
,
0xde
,
0xe4
,
0xea
,
0xf0
,
0xf6
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xff
,
0xf9
,
0xf3
,
0xed
,
0xe7
,
0xe1
,
0xdb
,
0xd5
,
0xcf
,
0xc9
,
0xc3
,
0xbd
,
0xb7
,
0xb1
,
0xab
,
0xa5
,
0x9f
,
0x99
,
0x93
,
0x8d
,
0x87
,
0x81
,
0x7b
,
0x75
,
0x6f
,
0x69
,
0x63
,
0x5d
,
0x57
,
0x51
,
0x4b
,
0x45
,
0x3f
,
0x39
,
0x33
,
0x2d
,
0x27
,
0x21
,
0x1b
,
0x15
,
0x0f
,
0x09
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
};
const
unsigned
char
rands
[]
=
{
0x67
,
0xc6
,
0x69
,
0x73
,
0x51
,
0xff
,
0x4a
,
0xec
,
0x29
,
0xcd
,
0xba
,
0xab
,
0xf2
,
0xfb
,
0xe3
,
0x46
,
0x7c
,
0xc2
,
0x54
,
0xf8
,
0x1b
,
0xe8
,
0xe7
,
0x8d
,
0x76
,
0x5a
,
0x2e
,
0x63
,
0x33
,
0x9f
,
0xc9
,
0x9a
,
0x66
,
0x32
,
0x0d
,
0xb7
,
0x31
,
0x58
,
0xa3
,
0x5a
,
0x25
,
0x5d
,
0x05
,
0x17
,
0x58
,
0xe9
,
0x5e
,
0xd4
,
0xab
,
0xb2
,
0xcd
,
0xc6
,
0x9b
,
0xb4
,
0x54
,
0x11
,
0x0e
,
0x82
,
0x74
,
0x41
,
0x21
,
0x3d
,
0xdc
,
0x87
,
0x70
,
0xe9
,
0x3e
,
0xa1
,
0x41
,
0xe1
,
0xfc
,
0x67
,
0x3e
,
0x01
,
0x7e
,
0x97
,
0xea
,
0xdc
,
0x6b
,
0x96
,
0x8f
,
0x38
,
0x5c
,
0x2a
,
0xec
,
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70
,
0x6d
,
0x6a
,
0x67
,
0x64
,
0x61
,
0x5e
,
0x5b
,
0x58
,
0x55
,
0x52
,
0x4f
,
0x4c
,
0x49
,
0x47
,
0x44
,
0x41
,
0x3e
,
0x3c
,
0x39
,
0x36
,
0x34
,
0x31
,
0x2f
,
0x2d
,
0x2a
,
0x28
,
0x26
,
0x24
,
0x21
,
0x1f
,
0x1d
,
0x1b
,
0x1a
,
0x18
,
0x16
,
0x14
,
0x13
,
0x11
,
0x10
,
0x0e
,
0x0d
,
0x0b
,
0x0a
,
0x09
,
0x08
,
0x07
,
0x06
,
0x05
,
0x04
,
0x04
,
0x03
,
0x02
,
0x02
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x01
,
0x02
,
0x02
,
0x03
,
0x04
,
0x04
,
0x05
,
0x06
,
0x07
,
0x08
,
0x09
,
0x0a
,
0x0b
,
0x0d
,
0x0e
,
0x10
,
0x11
,
0x13
,
0x14
,
0x16
,
0x18
,
0x1a
,
0x1b
,
0x1d
,
0x1f
,
0x21
,
0x24
,
0x26
,
0x28
,
0x2a
,
0x2d
,
0x2f
,
0x31
,
0x34
,
0x36
,
0x39
,
0x3c
,
0x3e
,
0x41
,
0x44
,
0x47
,
0x49
,
0x4c
,
0x4f
,
0x52
,
0x55
,
0x58
,
0x5b
,
0x5e
,
0x61
,
0x64
,
0x67
,
0x6a
,
0x6d
,
0x70
,
0x73
,
0x76
,
0x79
,
0x7d
,
};
#define NR_LEDS 197
uint16_t
phases
[
NR_LEDS
];
int
frameno
;
int
tween
=
0
;
uint32_t
TweenHexColors
(
uint32_t
hexa
,
uint32_t
hexb
,
int
tween
)
{
int32_t
aamt
=
255
-
tween
;
int32_t
bamt
=
tween
;
int32_t
hab
=
hexa
&
0xff
;
int32_t
har
=
(
hexa
>>
8
)
&
0xff
;
int32_t
hag
=
(
hexa
>>
16
)
&
0xff
;
int32_t
hbb
=
hexb
&
0xff
;
int32_t
hbr
=
(
hexb
>>
8
)
&
0xff
;
int32_t
hbg
=
(
hexb
>>
16
)
&
0xff
;
int32_t
b
=
(
hab
*
aamt
+
hbb
*
bamt
+
128
)
>>
8
;
int32_t
r
=
(
har
*
aamt
+
hbr
*
bamt
+
128
)
>>
8
;
int32_t
g
=
(
hag
*
aamt
+
hbg
*
bamt
+
128
)
>>
8
;
return
b
|
(
r
<<
8
)
|
(
g
<<
16
);
}
// Callbacks that you must implement.
uint32_t
WS2812BLEDCallback
(
int
ledno
)
{
uint8_t
index
=
(
phases
[
ledno
])
>>
8
;
uint8_t
rs
=
sintable
[
index
]
>>
3
;
uint32_t
fire
=
huetable
[(
rs
+
190
&
0xff
)]
|
(
huetable
[(
rs
+
30
&
0xff
)]
<<
8
)
|
(
huetable
[(
rs
+
0
)]
<<
16
);
uint32_t
ice
=
0xff
|
((
rs
)
<<
8
)
|
(
rs
<<
16
);
return
TweenHexColors
(
fire
,
ice
,
tween
);
// Where "tween" is a value from 0 ... 255
}
int
main
()
{
int
k
;
...
...
@@ -232,32 +69,14 @@ int main()
RCC
->
APB2PCENR
|=
RCC_APB2Periph_GPIOD
;
GPIOD
->
CFGLR
&=
~
(
0xf
<<
(
4
*
0
));
GPIOD
->
CFGLR
|=
(
GPIO_Speed_10MHz
|
GPIO_CNF_OUT_PP
)
<<
(
4
*
0
);
WS2812BDMAInit
(
);
GPIOD
->
BSHR
=
1
;
// Turn on GPIOD0
GPIOD
->
BSHR
=
1
<<
16
;
// Turn off GPIOD0
printf
(
"CFG: %08x
\n
"
,
SPI1
->
CTLR1
);
frameno
=
0
;
for
(
k
=
0
;
k
<
NR_LEDS
;
k
++
)
phases
[
k
]
=
k
<<
8
;
while
(
1
)
{
while
(
!
WS2812BLEDDone
);
frameno
++
;
if
(
frameno
<
1024
)
tween
=
0
;
else
if
(
frameno
<
(
1024
+
256
)
)
tween
=
frameno
-
1024
;
else
if
(
frameno
<
2048
)
tween
=
255
;
else
if
(
frameno
<
2048
+
256
)
tween
=
255
-
(
frameno
-
2048
);
else
frameno
=
0
;
for
(
k
=
0
;
k
<
NR_LEDS
;
k
++
)
{
phases
[
k
]
+=
((((
rands
[
k
&
0xff
])
+
0xf
)
<<
2
)
+
(((
rands
[
k
&
0xff
])
+
0xf
)
<<
1
))
>>
1
;
}
WS2812BDMAStart
(
NR_LEDS
);
Delay_Ms
(
100
);
}
}
This diff is collapsed.
Click to expand it.
examples/ws2812demo/ws2812b_dma_spi_led_driver.h
+
2
−
2
View file @
02c531f2
...
...
@@ -113,7 +113,7 @@ static void WS2812FillBuffSec( uint16_t * ptr, int numhalfwords, int ending )
void
DMA1_Channel3_IRQHandler
(
void
)
__attribute__
((
interrupt
));
void
DMA1_Channel3_IRQHandler
(
void
)
{
GPIOD
->
BSHR
=
1
;
// Turn on GPIOD0
//
GPIOD->BSHR = 1; // Turn on GPIOD0
// Backup flags.
int
intfr
=
DMA1
->
INTFR
;
...
...
@@ -132,7 +132,7 @@ void DMA1_Channel3_IRQHandler( void )
WS2812FillBuffSec
(
WS2812dmabuff
,
DMA_BUFFER_LEN
/
2
,
0
);
}
GPIOD
->
BSHR
=
1
<<
16
;
// Turn off GPIOD0
//
GPIOD->BSHR = 1<<16; // Turn off GPIOD0
}
void
WS2812BDMAStart
(
int
leds
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment