-
Notifications
You must be signed in to change notification settings - Fork 2k
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
light_ws2812 #17618
base: master
Are you sure you want to change the base?
light_ws2812 #17618
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 BISSELL Homecare, Inc. | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_ws281x | ||
* | ||
* @{ | ||
* | ||
* @file | ||
* @brief Implementation of `ws281x_write_buffer()` for the ARM CPU | ||
* | ||
* @author David VanKampen <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
#include <assert.h> | ||
#include <errno.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include "ws281x.h" | ||
#include "ws281x_params.h" | ||
#include "ws281x_constants.h" | ||
|
||
#include "light_ws2812_cortex.h" | ||
|
||
void ws281x_write_buffer(ws281x_t *dev, const void *buf, size_t size) | ||
{ | ||
assert(dev); | ||
ws2812_sendarray((uint8_t*)buf, size); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# name of the application | ||
APPLICATION = light_ws2812 | ||
|
||
# If no BOARD is found in the environment, use this default: | ||
BOARD ?= nucleo-g070rb | ||
|
||
# This has to be the absolute path to the RIOT base directory: | ||
RIOTBASE ?= $(CURDIR)/../.. | ||
|
||
# required packages | ||
USEPKG += light_ws2812 | ||
USEMODULE += xtimer | ||
USEMODULE += random | ||
|
||
# Comment this out to disable code in RIOT that does safety checking | ||
# which is not needed in a production environment but helps in the | ||
# development process: | ||
DEVELHELP ?= 1 | ||
|
||
# Change this to 0 show compiler invocation lines by default: | ||
QUIET ?= 1 | ||
|
||
CFLAGS += -DLIGHT_WS2812_UC_STM32G0XX | ||
|
||
CFLAGS += -DLIGHT_WS2812_GPIO_PIN=7 | ||
CFLAGS += -DLIGHT_WS2812_GPIO_PORT=GPIOA | ||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would make sense to provide an The main advantage would be that there would always be a valid fall-back configuration (so that the CI can compile applications using the pkg) and the macros could be documented there and would pop up in Doxygen. An application could provide its own |
||
|
||
include $(RIOTBASE)/Makefile.include |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
light_ws2812 | ||
============ | ||
|
||
Demonstrates using the light_ws2812 package to drive some LEDs | ||
|
||
Usage | ||
===== | ||
|
||
Uses the random module to generate random numbers to write out to the LEDs |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||||||
/* | ||||||||||
* Copyright (C) 2022 BISSELL Homecare, Inc. | ||||||||||
* | ||||||||||
* This file is subject to the terms and conditions of the GNU Lesser | ||||||||||
* General Public License v2.1. See the file LICENSE in the top level | ||||||||||
* directory for more details. | ||||||||||
*/ | ||||||||||
|
||||||||||
/** | ||||||||||
* @ingroup examples | ||||||||||
* @{ | ||||||||||
* | ||||||||||
* @file | ||||||||||
* @brief light ws2812 example | ||||||||||
* | ||||||||||
* @author Dave VanKampen <[email protected]> | ||||||||||
* | ||||||||||
* @} | ||||||||||
*/ | ||||||||||
|
||||||||||
#include <stdio.h> | ||||||||||
#include "light_ws2812_cortex.h" | ||||||||||
#include "xtimer.h" | ||||||||||
#include "random.h" | ||||||||||
#define SEED 234 | ||||||||||
|
||||||||||
#define NUM_LEDS 5 | ||||||||||
uint8_t leds[NUM_LEDS] = { 0x00}; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Shouldn't there be three bytes per LED? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes you're right. Good catch. |
||||||||||
int main(void) | ||||||||||
{ | ||||||||||
puts("Generated RIOT application: 'light_ws2812'"); | ||||||||||
random_init(SEED); | ||||||||||
while (1) { | ||||||||||
for (uint8_t idx = 0; idx < NUM_LEDS; idx++) { | ||||||||||
leds[idx] = (uint8_t)random_uint32(); | ||||||||||
} | ||||||||||
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
ws2812_sendarray(leds, NUM_LEDS); | ||||||||||
xtimer_usleep(50000); | ||||||||||
} | ||||||||||
return 0; | ||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PKG_NAME=light_ws2812 | ||
PKG_URL=https://github.com/cpldcpu/light_ws2812.git | ||
PKG_VERSION=cd149996012fe96bc3d7883cb18a0103fd8e8b3a | ||
PKG_LICENSE=GPL-3 | ||
|
||
include $(RIOTBASE)/pkg/pkg.mk | ||
|
||
all: | ||
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/light_ws2812_ARM/ -f $(CURDIR)/$(PKG_NAME).mk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Put the package dependencies here | ||
|
||
# required features | ||
FEATURES_REQUIRED += periph_gpio |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INCLUDES += -I$(PKGDIRBASE)/light_ws2812/light_ws2812_ARM |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @defgroup pkg_light_ws2812 light_ws2812 | ||
* @ingroup pkg | ||
* @brief lightweight ws2811/2812 driver | ||
* | ||
* # Introduction | ||
* | ||
* Lightweight package for controlling ws281x LEDs | ||
* | ||
* # License | ||
* | ||
* Licensed under GPL-3. | ||
* | ||
* @see https://github.com/cpldcpu/light_ws2812.git | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MODULE = light_ws2812 | ||
|
||
include $(RIOTBASE)/Makefile.base |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
From c5eaf14a5e26b0f325ab1edb9d0ac599f86519ba Mon Sep 17 00:00:00 2001 | ||
From: Dave VanKampen <[email protected]> | ||
Date: Fri, 4 Feb 2022 10:18:39 -0500 | ||
Subject: [PATCH] stm32g0 changes for RIOT compatibility | ||
|
||
--- | ||
light_ws2812_ARM/light_ws2812_cortex.c | 4 ++-- | ||
light_ws2812_ARM/light_ws2812_cortex.h | 14 ++++++++++++-- | ||
2 files changed, 14 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/light_ws2812_ARM/light_ws2812_cortex.c b/light_ws2812_ARM/light_ws2812_cortex.c | ||
index a183888..7a21340 100644 | ||
--- a/light_ws2812_ARM/light_ws2812_cortex.c | ||
+++ b/light_ws2812_ARM/light_ws2812_cortex.c | ||
@@ -34,13 +34,13 @@ void ws2812_sendarray(uint8_t *data,int datlen) | ||
uint32_t masklo = ws2812_mask_clr; | ||
volatile uint32_t *set = ws2812_port_set; | ||
volatile uint32_t *clr = ws2812_port_clr; | ||
- uint32_t i; | ||
+ uint32_t i = 0; | ||
uint32_t curbyte; | ||
|
||
while (datlen--) { | ||
curbyte=*data++; | ||
|
||
- asm volatile( | ||
+ __asm__ volatile( | ||
" lsl %[dat],#24 \n\t" | ||
" movs %[ctr],#8 \n\t" | ||
"ilop%=: \n\t" | ||
diff --git a/light_ws2812_ARM/light_ws2812_cortex.h b/light_ws2812_ARM/light_ws2812_cortex.h | ||
index 6c43cbe..c7389b3 100644 | ||
--- a/light_ws2812_ARM/light_ws2812_cortex.h | ||
+++ b/light_ws2812_ARM/light_ws2812_cortex.h | ||
@@ -22,6 +22,9 @@ | ||
#elif defined(LIGHT_WS2812_UC_STM32L0XX) | ||
#include "stm32l0xx_hal.h" | ||
#define LIGHT_WS2812_STM32 | ||
+#elif defined(LIGHT_WS2812_UC_STM32G0XX) | ||
+ #include "stm32g0xx.h" | ||
+ #define LIGHT_WS2812_STM32 | ||
#elif defined(LIGHT_WS2812_UC_FSL) | ||
#include "fsl_port.h" | ||
#include "fsl_gpio.h" | ||
@@ -57,11 +60,16 @@ | ||
#endif | ||
#ifdef LIGHT_WS2812_STM32 | ||
// This example is for STM32 family | ||
+#if defined(LIGHT_WS2812_UC_STM32L0XX) | ||
#define ws2812_port_set ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->BSRR) // Address of the data port register to set the pin | ||
#define ws2812_port_clr ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->BRR) // Address of the data port register to clear the pin | ||
+#elif defined(LIGHT_WS2812_UC_STM32G0XX) | ||
+ #define ws2812_port_set ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->BSRR) // Address of the data port register to set the pin | ||
+ #define ws2812_port_clr ((uint32_t*)&LIGHT_WS2812_GPIO_PORT->BSRR) // Address of the data port register to clear the pin | ||
+#endif | ||
|
||
- #define ws2812_mask_set LIGHT_WS2812_GPIO_PIN // Bitmask to set the data out pin | ||
- #define ws2812_mask_clr LIGHT_WS2812_GPIO_PIN // Bitmask to clear the data out pin | ||
+ #define ws2812_mask_set 1 << LIGHT_WS2812_GPIO_PIN // Bitmask to set the data out pin | ||
+ #define ws2812_mask_clr 1 << (LIGHT_WS2812_GPIO_PIN+16) // Bitmask to clear the data out pin | ||
#endif | ||
#ifdef LIGHT_WS2812_FSL | ||
// This example is for Freescale family | ||
@@ -102,6 +110,8 @@ | ||
// predictable code execution timing. | ||
/////////////////////////////////////////////////////////////////////// | ||
|
||
+#include "clk.h" | ||
+#define F_CPU CLOCK_CORECLOCK | ||
#ifndef F_CPU | ||
#error "Error: F_CPU (CPU clock speed) is not defined" | ||
#endif | ||
-- | ||
2.25.1 | ||
|
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.
Maybe the module could be named after the pkg that provides the implementation? After all,
light_ws2812
also contains an implementation for AVR MCUs, so one could use it there as well. (Even though I think that at least one would have to change the#include "light_ws2812_cortex.h"
with some preprocessor magic to pick the header corresponding to the arch.)