last commit for glasser code

This commit is contained in:
Jack Humbert 2018-05-23 00:50:58 -04:00
parent 3e282ab203
commit d233737c95
6 changed files with 33 additions and 21 deletions

View File

@ -41,6 +41,7 @@
#if !defined(WS2812_TIM_N) #if !defined(WS2812_TIM_N)
#error WS2812 timer not specified #error WS2812 timer not specified
#endif #endif
// values for these might be found in table 14 in DM00058181 (STM32F303)
#if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX) #if defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32F7XX)
#if WS2812_TIM_N <= 2 #if WS2812_TIM_N <= 2
#define WS2812_AF 1 #define WS2812_AF 1
@ -61,8 +62,10 @@
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */ /* --- PRIVATE CONSTANTS ---------------------------------------------------- */
#define WS2812_PWM_FREQUENCY (STM32_SYSCLK/2) /**< Clock frequency of PWM */ //#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 (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 * @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 * 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 (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 * @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 * 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 (WS2812_PWM_FREQUENCY/(1000000000/800)) //#define WS2812_DUTYCYCLE_1 (WS2812_PWM_FREQUENCY/(1000000000/800))
#define WS2812_DUTYCYCLE_1 (56)
/* --- PRIVATE MACROS ------------------------------------------------------- */ /* --- 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 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 // Configure PA1 as AF output
#ifdef WS2812_EXTERNAL_PULLUP //#ifdef WS2812_EXTERNAL_PULLUP
palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN); // palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF) | PAL_STM32_OTYPE_OPENDRAIN);
#else //#else
palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(WS2812_AF)); palSetPadMode(PORT_WS2812, PIN_WS2812, PAL_MODE_ALTERNATE(1));
#endif //#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

View File

@ -245,7 +245,7 @@
* PA15 - ROW4 * PA15 - ROW4
*/ */
#define VAL_GPIOA_MODER (PIN_MODE_INPUT(GPIOA_PIN0) | \ #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_PIN2) | \
PIN_MODE_INPUT(GPIOA_PIN3) | \ PIN_MODE_INPUT(GPIOA_PIN3) | \
PIN_MODE_INPUT(GPIOA_PIN4) | \ PIN_MODE_INPUT(GPIOA_PIN4) | \
@ -325,7 +325,7 @@
PIN_ODR_HIGH(GPIOA_SWCLK) | \ PIN_ODR_HIGH(GPIOA_SWCLK) | \
PIN_ODR_HIGH(GPIOA_PIN15)) PIN_ODR_HIGH(GPIOA_PIN15))
#define VAL_GPIOA_AFRL (PIN_AFIO_AF(GPIOA_PIN0, 0) | \ #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_PIN2, 0) | \
PIN_AFIO_AF(GPIOA_PIN3, 0) | \ PIN_AFIO_AF(GPIOA_PIN3, 0) | \
PIN_AFIO_AF(GPIOA_PIN4, 0) | \ PIN_AFIO_AF(GPIOA_PIN4, 0) | \

View File

@ -41,7 +41,7 @@
* @brief System time counter resolution. * @brief System time counter resolution.
* @note Allowed values are 16 or 32 bits. * @note Allowed values are 16 or 32 bits.
*/ */
#define CH_CFG_ST_RESOLUTION 32 #define CH_CFG_ST_RESOLUTION 16
/** /**
* @brief System tick frequency. * @brief System tick frequency.

View File

@ -125,10 +125,10 @@
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 1 //#define MIDI_TONE_KEYCODE_OCTAVES 1
#define WS2812_LED_N 1 #define WS2812_LED_N 2
#define RGBLED_NUM WS2812_LED_N #define RGBLED_NUM WS2812_LED_N
#define WS2812_TIM_N 1 #define WS2812_TIM_N 2
#define WS2812_TIM_CH 1 #define WS2812_TIM_CH 2
#define PORT_WS2812 GPIOA #define PORT_WS2812 GPIOA
#define PIN_WS2812 1 #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_STREAM STM32_DMA1_STREAM2 // DMA stream for TIMx_UP (look up in reference manual under DMA Channel selection)

View File

@ -182,8 +182,8 @@
* PWM driver system settings. * PWM driver system settings.
*/ */
#define STM32_PWM_USE_ADVANCED FALSE #define STM32_PWM_USE_ADVANCED FALSE
#define STM32_PWM_USE_TIM1 TRUE #define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE #define STM32_PWM_USE_TIM2 TRUE
#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
@ -224,7 +224,7 @@
* ST driver system settings. * ST driver system settings.
*/ */
#define STM32_ST_IRQ_PRIORITY 8 #define STM32_ST_IRQ_PRIORITY 8
#define STM32_ST_USE_TIMER 2 #define STM32_ST_USE_TIMER 3
/* /*
* UART driver system settings. * UART driver system settings.

View File

@ -17,13 +17,20 @@
#include "rgblight.h" #include "rgblight.h"
void matrix_init_kb(void) { void matrix_init_kb(void) {
// rgblight_enable();
// rgblight_mode(1);
// rgblight_setrgb(0xFF, 0xFF, 0xFF);
ws2812_init(); ws2812_init();
rgblight_enable();
rgblight_mode(1);
rgblight_setrgb(0xFF, 0xFF, 0xFF);
matrix_init_user(); matrix_init_user();
} }
void matrix_scan_kb(void) { void matrix_scan_kb(void) {
matrix_scan_user(); 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;
} }