working example
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -1,102 +1,31 @@
|
||||
/**
|
||||
* @file ws2812.h
|
||||
* @author Austin Glaser <austin.glaser@gmail.com>
|
||||
* @brief Interface to WS2812 LED driver
|
||||
/*
|
||||
* LEDDriver.h
|
||||
*
|
||||
* Copyright (C) 2016 Austin Glaser
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*
|
||||
* @todo Put in names and descriptions of variables which need to be defined to use this file
|
||||
* Created on: Aug 26, 2013
|
||||
* Author: Omri Iluz
|
||||
*/
|
||||
|
||||
#ifndef WS2812_H_
|
||||
#define WS2812_H_
|
||||
|
||||
/**
|
||||
* @defgroup WS2812 WS2812 Driver
|
||||
* @{
|
||||
*
|
||||
* @brief DMA-based WS2812 LED driver
|
||||
*
|
||||
* A driver for WS2812 LEDs
|
||||
*/
|
||||
|
||||
/* --- PUBLIC DEPENDENCIES -------------------------------------------------- */
|
||||
|
||||
// Standard
|
||||
#include <stdint.h>
|
||||
#include "hal.h"
|
||||
#include "rgblight_types.h"
|
||||
|
||||
/* --- PUBLIC CONSTANTS ----------------------------------------------------- */
|
||||
#define sign(x) (( x > 0 ) - ( x < 0 ))
|
||||
|
||||
/**
|
||||
* @brief Return codes from ws2812 interface functions
|
||||
*/
|
||||
typedef enum {
|
||||
WS2812_SUCCESS = 0x00, /**< Operation completeed successfully */
|
||||
WS2812_LED_INVALID, /**< Attempted to index an invalid LED (@ref WS2812_N_LEDS) */
|
||||
MAX_WS2812_ERR, /**< Total number of possible error codes */
|
||||
WS2812_ERR_INVALID /**< Invalid error value */
|
||||
} ws2812_err_t;
|
||||
typedef struct Color Color;
|
||||
struct Color {
|
||||
uint8_t R;
|
||||
uint8_t G;
|
||||
uint8_t B;
|
||||
};
|
||||
|
||||
/* --- PUBLIC FUNCTIONS ----------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Initialize the driver
|
||||
*
|
||||
* After this function is called, all necessary background tasks will be started.
|
||||
* The frame is initially dark.
|
||||
*/
|
||||
void ws2812_init(void);
|
||||
|
||||
/**
|
||||
* @brief Write the value of a single LED in the chain
|
||||
*
|
||||
* The color value is written to a frame buffer, and will not
|
||||
* be updated until the next frame is written. Frames are written
|
||||
* at the maximum possible speed -- the longest latency between a
|
||||
* call to this function and the value being displayed is
|
||||
* 1.25uS*(24*@ref WS2812_LED_N + 50)
|
||||
*
|
||||
* @param[in] led_number: The index of the LED to be written. Must be strictly less than
|
||||
* @ref WS2812_N_LEDS
|
||||
* @param[in] r: The red level of the LED
|
||||
* @param[in] g: The green level of the LED
|
||||
* @param[in] b: The blue level of the LED
|
||||
*
|
||||
* @retval WS2812_SUCCESS: The write was successful
|
||||
* @retval WS2812_LED_INVALID: The write was to an invalid LED index
|
||||
*/
|
||||
ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
/** @} defgroup WS2812 */
|
||||
void ledDriverInit(int leds, stm32_gpio_t *port, uint32_t mask, uint8_t **o_fb);
|
||||
void setColorRGB(Color c, uint8_t *buf, uint32_t mask);
|
||||
void testPatternFB(uint8_t *fb);
|
||||
void ledDriverWaitCycle(void);
|
||||
|
||||
void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
|
||||
|
||||
/**
|
||||
* @brief Concatenates two symbols s1 and s2 exactly, without expanding either
|
||||
*
|
||||
* @param[in] s1: The first symbol to concatenate
|
||||
* @param[in] s2: The second symbol to concatenate
|
||||
*
|
||||
* @return A single symbol containing s1 and s2 concatenated without expansion
|
||||
*/
|
||||
#define CONCAT_SYMBOLS(s1, s2) s1##s2
|
||||
|
||||
/**
|
||||
* @brief Concatenate the symbols s1 and s2, expanding both of them
|
||||
*
|
||||
* This is important because simply applying s1##s2 doesn't expand them if they're
|
||||
* preprocessor tokens themselves
|
||||
*
|
||||
* @param[in] s1: The first symbol to concatenate
|
||||
* @param[in] s2: The second symbol to concatenate
|
||||
*
|
||||
* @return A single symbol containing s1 expanded followed by s2 expanded
|
||||
*/
|
||||
#define CONCAT_EXPANDED_SYMBOLS(s1, s2) CONCAT_SYMBOLS(s1, s2)
|
||||
|
||||
#endif /* WS2812_H_ */
|
||||
#endif /* LEDDRIVER_H_ */
|
||||
|
@ -277,7 +277,7 @@
|
||||
PIN_OTYPE_PUSHPULL(GPIOA_SWCLK) | \
|
||||
PIN_OTYPE_PUSHPULL(GPIOA_PIN15))
|
||||
#define VAL_GPIOA_OSPEEDR (PIN_OSPEED_VERYLOW(GPIOA_PIN0) | \
|
||||
PIN_OSPEED_VERYLOW(GPIOA_PIN1) | \
|
||||
PIN_OSPEED_HIGH(GPIOA_PIN1) | \
|
||||
PIN_OSPEED_VERYLOW(GPIOA_PIN2) | \
|
||||
PIN_OSPEED_VERYLOW(GPIOA_PIN3) | \
|
||||
PIN_OSPEED_VERYLOW(GPIOA_PIN4) | \
|
||||
@ -293,7 +293,7 @@
|
||||
PIN_OSPEED_HIGH(GPIOA_SWCLK) | \
|
||||
PIN_OSPEED_VERYLOW(GPIOA_PIN15))
|
||||
#define VAL_GPIOA_PUPDR (PIN_PUPDR_FLOATING(GPIOA_PIN0) | \
|
||||
PIN_PUPDR_PULLUP(GPIOA_PIN1) | \
|
||||
PIN_PUPDR_FLOATING(GPIOA_PIN1) | \
|
||||
PIN_PUPDR_PULLUP(GPIOA_PIN2) | \
|
||||
PIN_PUPDR_PULLUP(GPIOA_PIN3) | \
|
||||
PIN_PUPDR_PULLUP(GPIOA_PIN4) | \
|
||||
|
@ -184,6 +184,7 @@
|
||||
#define STM32_PWM_USE_ADVANCED FALSE
|
||||
#define STM32_PWM_USE_TIM1 FALSE
|
||||
#define STM32_PWM_USE_TIM2 TRUE
|
||||
#define STM32_PWM_USE_TIM3 TRUE
|
||||
#define STM32_PWM_USE_TIM4 FALSE
|
||||
#define STM32_PWM_USE_TIM8 FALSE
|
||||
#define STM32_PWM_TIM1_IRQ_PRIORITY 7
|
||||
@ -224,7 +225,7 @@
|
||||
* ST driver system settings.
|
||||
*/
|
||||
#define STM32_ST_IRQ_PRIORITY 8
|
||||
#define STM32_ST_USE_TIMER 3
|
||||
#define STM32_ST_USE_TIMER 4
|
||||
|
||||
/*
|
||||
* UART driver system settings.
|
||||
|
@ -16,21 +16,20 @@
|
||||
#include "rev6.h"
|
||||
#include "rgblight.h"
|
||||
|
||||
uint8_t *o_fb;
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
// rgblight_enable();
|
||||
// rgblight_mode(1);
|
||||
// rgblight_setrgb(0xFF, 0xFF, 0xFF);
|
||||
ws2812_init();
|
||||
|
||||
ledDriverInit(2, GPIOA, 0b00000010, &o_fb);
|
||||
testPatternFB(o_fb);
|
||||
|
||||
matrix_init_user();
|
||||
}
|
||||
|
||||
void matrix_scan_kb(void) {
|
||||
matrix_scan_user();
|
||||
|
||||
int s = 0;
|
||||
for (int n = 0; n < WS2812_LED_N; n++) {
|
||||
int s0 = s + 10*n;
|
||||
ws2812_write_led(n, s0%255, (s0+85)%255, (s0+170)%255);
|
||||
}
|
||||
s += 10;
|
||||
testPatternFB(o_fb);
|
||||
}
|
||||
|
Reference in New Issue
Block a user