-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updated to RGBW mode #2
base: master
Are you sure you want to change the base?
Conversation
- select RGB / RGBW - added lots of documentation - updated SPL library files - updated main.c with documentation - updated main.c with gpio init()
Wow, this is my first PR from a stranger. Thank you for your effort, I will surely check this out. |
No hurry. Just wanted to let you know :) |
You know, I am thinking about removing SPL from this repo at all. Its not about SPL after all. SPL is here only because I don't like messing with registers directly (and keeping SPL here is stupid after all). |
I would be good to get rid of IAR Workbench too - it is not opensource, it is not free and it is for MS Windows only (( |
I tried to compile @mnemocron's fork with SDCC but failed because of differences in IAR and SDCC compilers, looking at it now. @mnemocron - it is not good to pass structures by values especially in weak MCU cases. Usually it is just a waste of CPU instructions. And SDCC doesn't support it ) |
I too discovered this repo just recently. I appreciate the effort but at the current stage it is just not productive.
@mixaz are you talking about the RGBColor_t type? |
@mnemocron, I understand that porting to SDCC is not a goal for you, that's OK. I have to work on it myself, if I need it. And I value your efforts in the PR code, actually. |
|
||
/* Includes ------------------------------------------------------------------*/ | ||
#include "ws2812b_LLD.h" | ||
#include "stm8l15x.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stm8l15x.h is not needed
so TIM4_PERIOD = (0.001 * 125000 - 1) = 124 */ | ||
|
||
/* Time base configuration */ | ||
TIM4_TimeBaseInit(TIM4_Prescaler_128, TIM4_PERIOD); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIM4_PRESCALER_128, not TIM4_Prescaler_128. The same for TIM4_FLAG_Update, TIM4_IT_Update (sorry for being sourish - just spent almost a day and started losing my hair on this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIM4_PRESCALER_128, not TIM4_Prescaler_128. The same for TIM4_FLAG_Update, TIM4_IT_Update (sorry for being sourish - just spent almost a day and started losing my hair on this)
Do we use the same SPL? I noticed, that ST was using inconsistent naming between the STM8S and STM8L libraries. Could it be that they changed it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIM4_PRESCALER_128 = ((uint8_t)0x07) |
* | ||
****************************************************************************** | ||
*/ | ||
/* Includes ------------------------------------------------------------------*/ | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include "stm8s_conf.h" | ||
#include "ws2812B_fx.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ws2812b_fx.h not ws2812B_fx.h - mind caps in file names. Doesn't compile on Unixes for this reason
static void CLK_Config(void); | ||
static void TIM4_Config(void); | ||
static void GPIO_Config(void); | ||
void _delay_ms(u16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u16 is not standard. Use uint16_t instead
z = 0; | ||
GPIO_WriteReverse(GPIOB, GPIO_PIN_5); | ||
} | ||
uptime++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static volatile uint16_t delay_time = 0;
void uptime_routine(void)
{
if(delay_time)
delay_time--;
}
void _delay_ms(uint16_t wait)
{
delay_time = wait;
while(delay_time){}
}
|
||
/* ---------------------------------------------------------------------------*/ | ||
/* GPIO Port Register Map */ | ||
/** @todo why not use SPL definitions? */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPL is STM library, there are other toolchains as well. It's better to not have dependencies on toolchains, and if you have them, place to separate file
LedsArray[LedId * COL_PER_LED +1] = Color.R; | ||
LedsArray[LedId * COL_PER_LED +2] = Color.B; | ||
LedsArray[LedId * COL_PER_LED +3] = Color.W; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be under WS2812B_MODE_RGB ifdef
// depending on RGBW or RGB type it is 3 or 4 bytes to manage | ||
#ifdef WS2812B_MODE_RGBW | ||
#define COL_PER_LED (4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sizeof() could be used
#endif | ||
|
||
#ifdef WS2812B_MODE_RGB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WS2812B_MODE_RGBW and WS2812B_MODE_RGB can be disabled both, that's not OK. I would use something like #define WS2812B_MODE WS2812B_MODE_RGBW
and a check for incorrect value
const RGBColor_t GREEN = { 0, 255, 0, 0}; | ||
const RGBColor_t BLUE = { 0, 0, 255, 0}; | ||
const RGBColor_t YELLOW = {255, 255, 0, 0}; | ||
const RGBColor_t MAGENTA = {255, 0, 255, 0}; | ||
const RGBColor_t BLACK = { 0, 0, 0, 0}; | ||
const RGBColor_t WHITE = {255, 255, 255, 0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLD file is about dealing with WS2812 protocol and hardware. Colors definitions should be placed to separate file then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now you are reviewing the original source code, not the changes in the my PR.
Thanks a lot, I am learning a lot today :)
While we are at it, can you recommend any literature on "good practices in embedded software design"?
Where you learn e.g.
- which code to separate into files / libraries
- generally how to build robust
ifdef
structures - when to use/avoid certain data types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I write comments because I spent quite a bit on this project, and I'm glad to share knowledge. I think you don't need to correct your PR, I'm going to make the changes myself. About literature - I'm an old guy, so books I read decades ago, may be not good for you )
These matters are somewhat advanced and you get it with experience. Reading others code, etc. Sorry I don't know any modern C/C++ book for embedded. I often work with Linux source code which is almost all plain C and some C++. But Linux is too complex for you (and me)), but keep your eye on RTOS (FreeRTOS, works for example on STM32, and STM supports it officially. It is part of Expressiv SDK ESP32 BTW).
You're probably working with baremetal code, next step is RTOS when you'll get out of sandbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the feedback! We have briefly touched Linux and RTOS in school where the focus was on the advantages and the new special mechanisms (threads, semaphores, mutexes etc.) but never about how to organize code in a project. So I have my own style in STM32 projects but never quite know if it is good or bad practice ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually my own code style is far from ideal too. Ability for learning is the greatest skill I know)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found this STM8 port of FastLED library: https://github.com/thielj/FastLED-STM8, I'm going to try it. Seems to be using IAR compiler
unsigned int nbLedsBytes = NB_LEDS * COL_PER_LED; | ||
extern unsigned char NodeId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to use sized types - uint8_t and uint16_t in this case. int
and char
is almost obsolete in modern C coding, they are used when size doesn't matter. Not in this case when the data is shared with ASM code
Thank you for the great library.
I changed a few things and added a way to select between RGB and RGBW type LEDs.
This pull request is to let you know that there are improvements that you might want to copy.
I tested the code on STM8S and STM8L MCUs - but did not run your exact example project.