#include "WS281x.h"
#include "stdio.h"
#include "stm32f10x_tim.h"
#include "stm32f10x_dma.h"
#include "stm32f10x_gpio.h"
#include "misc.h"
uint16_t WS_SendBuff[(LED_NUM*24) + 58] = {0,0,0};
uint16_t WS2_SendBuff[(LED_NUM*24) + 58] = {29,58,0};
uint16_t WS3_SendBuff[(LED_NUM*24) + 58] = {0,0,0};
uint16_t WS4_SendBuff[(LED_NUM*24) + 58] = {0,0,0};
//ÈýÖÖÔÉ« RGB
uint8_t colorss[][3] =
{
{0xFF, 0x00, 0x00}, // ºì
{0x00, 0xFF, 0x00}, // ÂÌ
{0x00, 0x00, 0xFF}, // ˦
// {0xFF, 0xFF, 0xFF}, //
// {0xFF, 0xFF, 0x00}, //
// {0x00, 0xFF, 0xFF}, //
// {0x00, 0xFF, 0xFF}, //
// {0x00, 0x80, 0xFF}, //
// {0x00, 0x00, 0xFF}, //
// {0x80, 0x00, 0xFF}, //
// {0xFF, 0x00, 0xFF}, //
// {0xFF, 0x00, 0x80} //
};
/************************
**³ÌÐòÃû³Æ:Delay
**²ÎÊý:
**·µ»ØÖµ: none
**˵Ã÷:
************************/
void Delay(__IO uint32_t nCount)
{
while(nCount--)
{
}
}
/************************
**³ÌÐòÃû³Æ:WS_RCC_Config
**²ÎÊý: ÎÞ
**·µ»ØÖµ: none
**˵Ã÷: TIM \ GPIO \ DMA µÈʹÄÜÇëÇóÅäÖÃ
************************/
void WS_RCC_Config(void)
{
/*ʹÄܶ¨Ê±Æ÷ʱÖÓ */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* GPIOA and GPIOB clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
/*ʹÄܶ¨Ê±Æ÷ʱÖÓ */ //sq add 2018-8-21 20:01:38
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* DMA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
}
/************************
**³ÌÐòÃû³Æ:WS_GPIO_Config
**²ÎÊý: ÎÞ
**·µ»ØÖµ: none
**˵Ã÷: IO ¹Ü½ÅÅäÖÃ
************************/
void WS_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//sq add 2018-8-21 15:35:22
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
/************************
**³ÌÐòÃû³Æ:WS_TIM1_ModeConfig
**²ÎÊý: none
**·µ»ØÖµ: none
**˵Ã÷: ÅäÖÃTIM1Êä³öµÄPWMÐźŵÄģʽ£¬ÈçÖÜÆÚ¡¢¼«ÐÔ¡¢Õ¼¿Õ±È
************************/
static void WS_TIM1_ModeConfig(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //ʱ¼ä¼ÆÊý½á¹¹Ìå
TIM_OCInitTypeDef TIM_OCInitStructure; //¶¨Ê±Æ÷³õʼ»¯½á¹¹Ìå
// NVIC_InitTypeDef NVIC_InitStructure;
/*******************
PWM1+CH1ͨµÀ£¬ÅäÖÃPWM1ΪÊä³öģʽ ÅäÖÃΪ800KHzµÄƵÂÊ ÄÚºËʱÖÓ 72/90 = 800kHz£¬ WS2812B µÄ¸ßµÍµçƽÈçÏÂ
TIMCLK = 72ZHZ WSTIM=WSH+WSL = 1.25
0Â룺 H0(0.4us) + L0(0.85us) = 1.25us Îó²î ¡À150ns ¼´ pulseL0 = (0.85 *90) / 1.25 = 61.2
1Â룺 H1(0.8us) + L1(0.45us) = 1.25us Îó²î ¡À150ns ¼´ pulseL1 = (0.45 *90) / 1.25 = 32
***************************/
//ÉèÖÃÏÂÒ»¸ö¸üÐÂʼþתÈë»î¶¯µÄ×Ô¶¯ÖØ×°¼Ä´æÆ÷ÖÜÆÚµÄÖµ È¡Öµ·¶Î§±ØÐëÔÚ0x0000 ~ 0xFFFF
TIM_TimeBaseStructure.TIM_Period = TIMER_PERIOD - 1;
//ÉèÖÃʱÖÓƵÂʳýÊýµÄÔ¤·ÖƵֵ = ϵͳʱÖÓ/ TIM_Prescaler
TIM_TimeBaseStructure.TIM_Prescaler = 0;
//ÉèÖÃʱÖÓ·Ö¸î
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
//Ñ¡Ôñ¼ÆÊýÆ÷ģʽ ÉèÖÃΪÏòÉϼÆÊýģʽ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1