update ws2812 driver/config

pull/2666/head
Jack Humbert 6 years ago
parent 1c0d85c143
commit 3e282ab203

@ -40,16 +40,17 @@
#if !defined(WS2812_TIM_N) #if !defined(WS2812_TIM_N)
#error WS2812 timer not specified #error WS2812 timer not specified
#elif WS2812_TIM_N == 1 #endif
#define WS2812_DMA_STREAM STM32_DMA1_STREAM5 #if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX)
#elif WS2812_TIM_N == 2 #if WS2812_TIM_N <= 2
#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 #define WS2812_AF 1
#elif WS2812_TIM_N == 3 #elif WS2812_TIM_N <= 5
#define WS2812_DMA_STREAM STM32_DMA1_STREAM3 #define WS2812_AF 2
#elif WS2812_TIM_N == 4 #elif WS2812_TIM_N <= 11
#define WS2812_DMA_STREAM STM32_DMA1_STREAM7 #define WS2812_AF 3
#else #endif
#error WS2812 timer set to invalid value #elif !defined(WS2812_AF)
#error WS2812_AF timer alternate function not specified
#endif #endif
#if !defined(WS2812_TIM_CH) #if !defined(WS2812_TIM_CH)
@ -60,8 +61,8 @@
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ /* --- PRIVATE CONSTANTS ---------------------------------------------------- */
#define WS2812_PWM_FREQUENCY (72000000) /**< Clock frequency of PWM */ #define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */
#define WS2812_PWM_PERIOD (90) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ #define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */
/** /**
* @brief Number of bit-periods to hold the data line low at the end of a frame * @brief Number of bit-periods to hold the data line low at the end of a frame
@ -85,7 +86,7 @@
* a low period of (90 - 22)/(72 MHz) = 9.44 uS. These values are within the allowable * a low period of (90 - 22)/(72 MHz) = 9.44 uS. These values are within the allowable
* bounds, and intentionally skewed as far to the low duty-cycle side as possible * bounds, and intentionally skewed as far to the low duty-cycle side as possible
*/ */
#define WS2812_DUTYCYCLE_0 (22) #define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350))
/** /**
* @brief High period for a one, in ticks * @brief High period for a one, in ticks
@ -98,7 +99,7 @@
* a low period of (90 - 56)/(72 MHz) = 4.72 uS. These values are within the allowable * a low period of (90 - 56)/(72 MHz) = 4.72 uS. These values are within the allowable
* bounds, and intentionally skewed as far to the high duty-cycle side as possible * bounds, and intentionally skewed as far to the high duty-cycle side as possible
*/ */
#define WS2812_DUTYCYCLE_1 (56) #define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800))
/* --- PRIVATE MACROS ------------------------------------------------------- */ /* --- PRIVATE MACROS ------------------------------------------------------- */
@ -173,8 +174,12 @@ void ws2812_init(void)
for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle for (i = 0; i < WS2812_COLOR_BIT_N; i++) ws2812_frame_buffer[i] = WS2812_DUTYCYCLE_0; // All color bits are zero duty cycle
for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero
// Configure PA0 as AF output // Configure PA1 as AF output
palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATE(1)); #ifdef WS2812_EXTERNAL_PULLUP
palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN);
#else
palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF));
#endif
// PWM Configuration // PWM Configuration
#pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config #pragma GCC diagnostic ignored "-Woverride-init" // Turn off override-init warning for this struct. We use the overriding ability to set a "default" channel config
@ -199,6 +204,8 @@ void ws2812_init(void)
dmaStreamSetMode(WS2812_DMA_STREAM, dmaStreamSetMode(WS2812_DMA_STREAM,
STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_BYTE | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_BYTE |
STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3)); STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3));
//STM32_DMA_CR_CHSEL(WS2812_DMA_CHANNEL) | STM32_DMA_CR_DIR_M2P | STM32_DMA_CR_PSIZE_WORD | STM32_DMA_CR_MSIZE_WORD |
//STM32_DMA_CR_MINC | STM32_DMA_CR_CIRC | STM32_DMA_CR_PL(3));
// Start DMA // Start DMA
dmaStreamEnable(WS2812_DMA_STREAM); dmaStreamEnable(WS2812_DMA_STREAM);
@ -231,7 +238,6 @@ ws2812_err_t ws2812_write_led(uint32_t led_number, uint8_t r, uint8_t g, uint8_t
/** @} addtogroup WS2812 */ /** @} addtogroup WS2812 */
void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) { void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds) {
ws2812_init();
uint8_t i = 0; uint8_t i = 0;
while (i < number_of_leds) { while (i < number_of_leds) {
ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b); ws2812_write_led(i, ledarray[i].r, ledarray[i].g, ledarray[i].b);

@ -18,9 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#ifdef __AVR__
#include "config_common.h" #include "config_common.h"
#endif
/* USB Device descriptor parameter */ /* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED #define VENDOR_ID 0xFEED

@ -25,7 +25,7 @@
* Board identifier. * Board identifier.
*/ */
#define BOARD_GENERIC_STM32_F303XC #define BOARD_GENERIC_STM32_F303XC
#define BOARD_NAME "Clueboard 60 PCB" #define BOARD_NAME "Planck PCB"
/* /*
* Board oscillators-related settings. * Board oscillators-related settings.

@ -129,5 +129,10 @@
#define RGBLED_NUM WS2812_LED_N #define RGBLED_NUM WS2812_LED_N
#define WS2812_TIM_N 1 #define WS2812_TIM_N 1
#define WS2812_TIM_CH 1 #define WS2812_TIM_CH 1
#define PORT_WS2812 GPIOA
#define PIN_WS2812 1
#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA stream for TIMx_UP (look up in reference manual under DMA Channel selection)
//#define WS2812_DMA_CHANNEL 7 // DMA channel for TIMx_UP
//#define WS2812_EXTERNAL_PULLUP
#endif #endif

@ -184,7 +184,6 @@
#define STM32_PWM_USE_ADVANCED FALSE #define STM32_PWM_USE_ADVANCED FALSE
#define STM32_PWM_USE_TIM1 TRUE #define STM32_PWM_USE_TIM1 TRUE
#define STM32_PWM_USE_TIM2 FALSE #define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE
#define STM32_PWM_USE_TIM4 FALSE #define STM32_PWM_USE_TIM4 FALSE
#define STM32_PWM_USE_TIM8 FALSE #define STM32_PWM_USE_TIM8 FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY 7 #define STM32_PWM_TIM1_IRQ_PRIORITY 7

@ -17,6 +17,7 @@
#include "rgblight.h" #include "rgblight.h"
void matrix_init_kb(void) { void matrix_init_kb(void) {
ws2812_init();
rgblight_enable(); rgblight_enable();
rgblight_mode(1); rgblight_mode(1);
rgblight_setrgb(0xFF, 0xFF, 0xFF); rgblight_setrgb(0xFF, 0xFF, 0xFF);

Loading…
Cancel
Save