diff --git a/drivers/arm/ws2812.c b/drivers/arm/ws2812.c index f8730c6e1..91eb3a7c0 100644 --- a/drivers/arm/ws2812.c +++ b/drivers/arm/ws2812.c @@ -41,6 +41,7 @@ #if !defined(WS2812_TIM_N) #error WS2812 timer not specified #endif +// values for these might be found in table 14 in DM00058181 (STM32F303) #if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX) #if WS2812_TIM_N <= 2 #define WS2812_AF 1 @@ -61,8 +62,10 @@ /* --- PRIVATE CONSTANTS ---------------------------------------------------- */ -#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ -#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ +//#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ +#define WS2812_PWM_FREQUENCY (72000000) /**< Clock frequency of PWM */ +//#define WS2812_PWM_PERIOD (WS2812_PWM_FREQUENCY/800000) /**< Clock period in ticks. 90/(72 MHz) = 1.25 uS (as per datasheet) */ +#define WS2812_PWM_PERIOD (90) /**< 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 @@ -86,7 +89,8 @@ * 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 */ -#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350)) +//#define WS2812_DUTYCYCLE_0 (WS2812_PWM_FREQUENCY/(1000000000/350)) +#define WS2812_DUTYCYCLE_0 (22) /** * @brief High period for a one, in ticks @@ -99,7 +103,8 @@ * 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 */ -#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800)) +//#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800)) +#define WS2812_DUTYCYCLE_1 (56) /* --- PRIVATE MACROS ------------------------------------------------------- */ @@ -175,11 +180,11 @@ void ws2812_init(void) for (i = 0; i < WS2812_RESET_BIT_N; i++) ws2812_frame_buffer[i + WS2812_COLOR_BIT_N] = 0; // All reset bits are zero // Configure PA1 as AF output -#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 +//#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(1)); +//#endif // 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 diff --git a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h index 77c1ee951..a748628ab 100644 --- a/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h +++ b/keyboards/planck/rev6/boards/GENERIC_STM32_F303XC/board.h @@ -245,7 +245,7 @@ * PA15 - ROW4 */ #define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | \ - PIN_MODE_INPUT(GPIOA_PIN1) | \ + PIN_MODE_ALTERNATE(GPIOA_PIN1) | \ PIN_MODE_INPUT(GPIOA_PIN2) | \ PIN_MODE_INPUT(GPIOA_PIN3) | \ PIN_MODE_INPUT(GPIOA_PIN4) | \ @@ -325,7 +325,7 @@ PIN_ODR_HIGH(GPIOA_SWCLK) | \ PIN_ODR_HIGH(GPIOA_PIN15)) #define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | \ - PIN_AFIO_AF(GPIOA_PIN1, 0) | \ + PIN_AFIO_AF(GPIOA_PIN1, 1) | \ PIN_AFIO_AF(GPIOA_PIN2, 0) | \ PIN_AFIO_AF(GPIOA_PIN3, 0) | \ PIN_AFIO_AF(GPIOA_PIN4, 0) | \ diff --git a/keyboards/planck/rev6/chconf.h b/keyboards/planck/rev6/chconf.h index 5a9b83310..b52ca7d2c 100644 --- a/keyboards/planck/rev6/chconf.h +++ b/keyboards/planck/rev6/chconf.h @@ -41,7 +41,7 @@ * @brief System time counter resolution. * @note Allowed values are 16 or 32 bits. */ -#define CH_CFG_ST_RESOLUTION 32 +#define CH_CFG_ST_RESOLUTION 16 /** * @brief System tick frequency. diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h index aaa49710c..0e462180b 100644 --- a/keyboards/planck/rev6/config.h +++ b/keyboards/planck/rev6/config.h @@ -125,10 +125,10 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 1 -#define WS2812_LED_N 1 +#define WS2812_LED_N 2 #define RGBLED_NUM WS2812_LED_N -#define WS2812_TIM_N 1 -#define WS2812_TIM_CH 1 +#define WS2812_TIM_N 2 +#define WS2812_TIM_CH 2 #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) diff --git a/keyboards/planck/rev6/mcuconf.h b/keyboards/planck/rev6/mcuconf.h index d30f08563..e2be2a62a 100644 --- a/keyboards/planck/rev6/mcuconf.h +++ b/keyboards/planck/rev6/mcuconf.h @@ -182,8 +182,8 @@ * PWM driver system settings. */ #define STM32_PWM_USE_ADVANCED FALSE -#define STM32_PWM_USE_TIM1 TRUE -#define STM32_PWM_USE_TIM2 FALSE +#define STM32_PWM_USE_TIM1 FALSE +#define STM32_PWM_USE_TIM2 TRUE #define STM32_PWM_USE_TIM4 FALSE #define STM32_PWM_USE_TIM8 FALSE #define STM32_PWM_TIM1_IRQ_PRIORITY 7 @@ -224,7 +224,7 @@ * ST driver system settings. */ #define STM32_ST_IRQ_PRIORITY 8 -#define STM32_ST_USE_TIMER 2 +#define STM32_ST_USE_TIMER 3 /* * UART driver system settings. diff --git a/keyboards/planck/rev6/rev6.c b/keyboards/planck/rev6/rev6.c index 6789ff5c0..d53b2224a 100644 --- a/keyboards/planck/rev6/rev6.c +++ b/keyboards/planck/rev6/rev6.c @@ -17,13 +17,20 @@ #include "rgblight.h" void matrix_init_kb(void) { + // rgblight_enable(); + // rgblight_mode(1); + // rgblight_setrgb(0xFF, 0xFF, 0xFF); ws2812_init(); - rgblight_enable(); - rgblight_mode(1); - rgblight_setrgb(0xFF, 0xFF, 0xFF); 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; }