Skip to content

Commit

Permalink
examples/light_ws2812,pkg/light_ws812: added lightweight (assembly ba…
Browse files Browse the repository at this point in the history
…sed) ws2812 package, and example app using it
  • Loading branch information
david-vankampen committed Apr 17, 2024
1 parent ad9d501 commit 80f315f
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/light_ws2812/Makefile
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

include $(RIOTBASE)/Makefile.include
9 changes: 9 additions & 0 deletions examples/light_ws2812/README.md
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
41 changes: 41 additions & 0 deletions examples/light_ws2812/main.c
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};
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();
}
ws2812_sendarray(leds, NUM_LEDS);
xtimer_usleep(50000);
}
return 0;
}
9 changes: 9 additions & 0 deletions pkg/light_ws2812/Makefile
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
4 changes: 4 additions & 0 deletions pkg/light_ws2812/Makefile.dep
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
1 change: 1 addition & 0 deletions pkg/light_ws2812/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INCLUDES += -I$(PKGDIRBASE)/light_ws2812/light_ws2812_ARM
15 changes: 15 additions & 0 deletions pkg/light_ws2812/doc.txt
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
*/
3 changes: 3 additions & 0 deletions pkg/light_ws2812/light_ws2812.mk
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

0 comments on commit 80f315f

Please sign in to comment.