【19】DMA PWM WS2812 GPIO输出16组

所属分类:单片机开发
开发工具:C/C++
文件大小:2318KB
下载次数:175
上传日期:2017-08-29 16:03:44
上 传 者我是来抄袭源码的
说明:  STM32作为主控芯片,72Mhz,利用DMA+PWM实现驱动WS2812,创建16个并行800kBit / s数据流的想法如下: 使用定时器每1.25us创建一个800kHz的时基和一个DMA请求。 使用2个比较模块在低位时间(350ns)和高位时间(700ns)下创建DMA请求 1.25us DMA请求将GPIO端口的所有位设置为高电平 350ns DMA请求将数据从帧缓冲区传输到GPIO端口。如果该位为0,GPIO引脚将变为低电平,否则将保持高电平。 700ns DMA请求将所有GPIO引脚设置为低电平。 重复步骤1到3,直到发送所有位。 这产生脉冲周期为1.25us,脉冲宽度为350ns或700ns的脉冲流,具体取决于脉冲表示的位值,通过DMA将数据传输到GPIO端口意味着每16个LED每位需要一个字(两个字节)。每个LED 24位,每16个LED 24个字(48个字节)。
(The idea to create 16 parallel 800kBit/s data streams is the following: Use a Timer to create an 800kHz time base and a DMA request every 1.25us. Use 2 compare modules to create DMA requests at the low bit time (350ns) and the high bit time (700ns) The 1.25us DMA request sets all bits of the GPIO port high The 350ns DMA request transfers the data from the frame buffer to the GPIO port. If the bit is a 0, the GPIO pin will go low, otherwise it will stay high. The 700ns DMA request sets all GPIO pins low. Repeat steps 1 to 3 until all bits have been transmitted. This creates a stream of pulses with a pulse period of 1.25us and a pulse width of either 350ns or 700ns depending on the bit value the pulse represents. Transferring the data via DMA to the GPIO port means that per 16 LEDs one half word (two bytes) is needed per bit. At 24 bits per LED that makes 24 half words (48 bytes) per 16 LEDs.)

文件列表:
【19】DMA PWM WS2812 GPIO输出16组\CORE\core_cm3.c (17273, 2010-06-07)
【19】DMA PWM WS2812 GPIO输出16组\CORE\core_cm3.h (85714, 2011-02-09)
【19】DMA PWM WS2812 GPIO输出16组\CORE\startup_stm32f10x_hd.s (15503, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\misc.h (8982, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_adc.h (21690, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_bkp.h (7555, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_can.h (27559, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_cec.h (6573, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_crc.h (2162, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_dac.h (15233, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_dbgmcu.h (3818, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_dma.h (20754, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_exti.h (6824, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_flash.h (25445, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_fsmc.h (27016, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_gpio.h (20175, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_i2c.h (30029, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_iwdg.h (3828, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_pwr.h (4383, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_rcc.h (30452, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_rtc.h (3857, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_sdio.h (21863, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_spi.h (17725, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_tim.h (52427, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_usart.h (16548, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\inc\stm32f10x_wwdg.h (2966, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\misc.c (7046, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_adc.c (47201, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_bkp.c (8463, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_can.c (45103, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_cec.c (11656, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_crc.c (3347, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_dac.c (19087, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_dbgmcu.c (5149, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_dma.c (29607, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_exti.c (6959, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_flash.c (62551, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_fsmc.c (35484, 2011-03-10)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_gpio.c (23221, 2011-03-11)
【19】DMA PWM WS2812 GPIO输出16组\FWLIB\src\stm32f10x_i2c.c (45781, 2011-03-10)
... ...

#include void Delay(__IO uint32_t nCount) { while(nCount--) { } } #define TIM3_CCR1_Address 0x40000434 // physical memory address of Timer 3 CCR1 register #define d2r (3.14159265/180) TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; GPIO_InitTypeDef GPIO_InitStructure; DMA_InitTypeDef DMA_InitStructure; /* Buffer that holds one complete DMA transmission * Ensure that this buffer is big enough to hold * all data bytes that need to be sent * * The buffer size can be calculated as follows: number of LEDs * 24 bytes + 42 bytes * * This leaves us with a maximum string length of (2^16 bytes per DMA stream - 42 bytes) / 24 bytes per LED = 2728 LEDs */ uint16_t LED_BYTE_Buffer[ 100 ]; /* this array holds the RGB values to represent a color wheel using 256 steps on each emitter 256^3 = 16777216 colors */ uint8_t eightbit[ 766 ][ 3 ] = { { 255, 0, 0 }, { 254, 1, 0 }, { 253, 2, 0 }, { 252, 3, 0 }, { 251, 4, 0 }, { 250, 5, 0 }, { 249, 6, 0 }, { 248, 7, 0 }, { 247, 8, 0 }, { 246, 9, 0 }, { 245, 10, 0 }, { 244, 11, 0 }, { 243, 12, 0 }, { 242, 13, 0 }, { 241, 14, 0 }, { 240, 15, 0 }, { 239, 16, 0 }, { 238, 17, 0 }, { 237, 18, 0 }, { 236, 19, 0 }, { 235, 20, 0 }, { 234, 21, 0 }, { 233, 22, 0 }, { 232, 23, 0 }, { 231, 24, 0 }, { 230, 25, 0 }, { 229, 26, 0 }, { 228, 27, 0 }, { 227, 28, 0 }, { 226, 29, 0 }, { 225, 30, 0 }, { 224, 31, 0 }, { 223, 32, 0 }, { 222, 33, 0 }, { 221, 34, 0 }, { 220, 35, 0 }, { 219, 36, 0 }, { 218, 37, 0 }, { 217, 38, 0 }, { 216, 39, 0 }, { 215, 40, 0 }, { 214, 41, 0 }, { 213, 42, 0 }, { 212, 43, 0 }, { 211, 44, 0 }, { 210, 45, 0 }, { 209, 46, 0 }, { 208, 47, 0 }, { 207, 48, 0 }, { 206, 49, 0 }, { 205, 50, 0 }, { 204, 51, 0 }, { 203, 52, 0 }, { 202, 53, 0 }, { 201, 54, 0 }, { 200, 55, 0 }, { 199, 56, 0 }, { 1***, 57, 0 }, { 197, 58, 0 }, { 196, 59, 0 }, { 195, 60, 0 }, { 194, 61, 0 }, { 193, 62, 0 }, { 192, 63, 0 }, { 191, ***, 0 }, { 190, 65, 0 }, { 189, 66, 0 }, { 188, 67, 0 }, { 187, 68, 0 }, { 186, 69, 0 }, { 185, 70, 0 }, { 184, 71, 0 }, { 183, 72, 0 }, { 182, 73, 0 }, { 181, 74, 0 }, { 180, 75, 0 }, { 179, 76, 0 }, { 178, 77, 0 }, { 177, 78, 0 }, { 176, 79, 0 }, { 175, 80, 0 }, { 174, 81, 0 }, { 173, 82, 0 }, { 172, 83, 0 }, { 171, 84, 0 }, { 170, 85, 0 }, { 169, 86, 0 }, { 168, 87, 0 }, { 167, 88, 0 }, { 166, 89, 0 }, { 165, 90, 0 }, { 1***, 91, 0 }, { 163, 92, 0 }, { 162, 93, 0 }, { 161, 94, 0 }, { 160, 95, 0 }, { 159, 96, 0 }, { 158, 97, 0 }, { 157, ***, 0 }, { 156, 99, 0 }, { 155, 100, 0 }, { 154, 101, 0 }, { 153, 102, 0 }, { 152, 103, 0 }, { 151, 104, 0 }, { 150, 105, 0 }, { 149, 106, 0 }, { 148, 107, 0 }, { 147, 108, 0 }, { 146, 109, 0 }, { 145, 110, 0 }, { 144, 111, 0 }, { 143, 112, 0 }, { 142, 113, 0 }, { 141, 114, 0 }, { 140, 115, 0 }, { 139, 116, 0 }, { 138, 117, 0 }, { 137, 118, 0 }, { 136, 119, 0 }, { 135, 120, 0 }, { 134, 121, 0 }, { 133, 122, 0 }, { 132, 123, 0 }, { 131, 124, 0 }, { 130, 125, 0 }, { 129, 126, 0 }, { 128, 127, 0 }, { 127, 128, 0 }, { 126, 129, 0 }, { 125, 130, 0 }, { 124, 131, 0 }, { 123, 132, 0 }, { 122, 133, 0 }, { 121, 134, 0 }, { 120, 135, 0 }, { 119, 136, 0 }, { 118, 137, 0 }, { 117, 138, 0 }, { 116, 139, 0 }, { 115, 140, 0 }, { 114, 141, 0 }, { 113, 142, 0 }, { 112, 143, 0 }, { 111, 144, 0 }, { 110, 145, 0 }, { 109, 146, 0 }, { 108, 147, 0 }, { 107, 148, 0 }, { 106, 149, 0 }, { 105, 150, 0 }, { 104, 151, 0 }, { 103, 152, 0 }, { 102, 153, 0 }, { 101, 154, 0 }, { 100, 155, 0 }, { 99, 156, 0 }, { ***, 157, 0 }, { 97, 158, 0 }, { 96, 159, 0 }, { 95, 160, 0 }, { 94, 161, 0 }, { 93, 162, 0 }, { 92, 163, 0 }, { 91, 1***, 0 }, { 90, 165, 0 }, { 89, 166, 0 }, { 88, 167, 0 }, { 87, 168, 0 }, { 86, 169, 0 }, { 85, 170, 0 }, { 84, 171, 0 }, { 83, 172, 0 }, { 82, 173, 0 }, { 81, 174, 0 }, { 80, 175, 0 }, { 79, 176, 0 }, { 78, 177, 0 }, { 77, 178, 0 }, { 76, 179, 0 }, { 75, 180, 0 }, { 74, 181, 0 }, { 73, 182, 0 }, { 72, 183, 0 }, { 71, 184, 0 }, { 70, 185, 0 }, { 69, 186, 0 }, { 68, 187, 0 }, { 67, 188, 0 }, { 66, 189, 0 }, { 65, 190, 0 }, { ***, 191, 0 }, { 63, 192, 0 }, { 62, 193, 0 }, { 61, 194, 0 }, { 60, 195, 0 }, { 59, 196, 0 }, { 58, 197, 0 }, { 57, 1***, 0 }, { 56, 199, 0 }, { 55, 200, 0 }, { 54, 201, 0 }, { 53, 202, 0 }, { 52, 203, 0 }, { 51, 204, 0 }, { 50, 205, 0 }, { 49, 206, 0 }, { 48, 207, 0 }, { 47, 208, 0 }, { 46, 209, 0 }, { 45, 210, 0 }, { 44, 211, 0 }, { 43, 212, 0 }, { 42, 213, 0 }, { 41, 214, 0 }, { 40, 215, 0 }, { 39, 216, 0 }, { 38, 217, 0 }, { 37, 218, 0 }, { 36, 219, 0 }, { 35, 220, 0 }, { 34, 221, 0 }, { 33, 222, 0 }, { 32, 223, 0 }, { 31, 224, 0 }, { 30, 225, 0 }, { 29, 226, 0 }, { 28, 227, 0 }, { 27, 228, 0 }, { 26, 229, 0 }, { 25, 230, 0 }, { 24, 231, 0 }, { 23, 232, 0 }, { 22, 233, 0 }, { 21, 234, 0 }, { 20, 235, 0 }, { 19, 236, 0 }, { 18, 237, 0 }, { 17, 238, 0 }, { 16, 239, 0 }, { 15, 240, 0 }, { 14, 241, 0 }, { 13, 242, 0 }, { 12, 243, 0 }, { 11, 244, 0 }, { 10, 245, 0 }, { 9, 246, 0 }, { 8, 247, 0 }, { 7, 248, 0 }, { 6, 249, 0 }, { 5, 250, 0 }, { 4, 251, 0 }, { 3, 252, 0 }, { 2, 253, 0 }, { 1, 254, 0 }, { 0, 255, 0 }, { 0, 254, 1 }, { 0, 253, 2 }, { 0, 252, 3 }, { 0, 251, 4 }, { 0, 250, 5 }, { 0, 249, 6 }, { 0, 248, 7 }, { 0, 247, 8 }, { 0, 246, 9 }, { 0, 245, 10 }, { 0, 244, 11 }, { 0, 243, 12 }, { 0, 242, 13 }, { 0, 241, 14 }, { 0, 240, 15 }, { 0, 239, 16 }, { 0, 238, 17 }, { 0, 237, 18 }, { 0, 236, 19 }, { 0, 235, 20 }, { 0, 234, 21 }, { 0, 233, 22 }, { 0, 232, 23 }, { 0, 231, 24 }, { 0, 230, 25 }, { 0, 229, 26 }, { 0, 228, 27 }, { 0, 227, 28 }, { 0, 226, 29 }, { 0, 225, 30 }, { 0, 224, 31 }, { 0, 223, 32 }, { 0, 222, 33 }, { 0, 221, 34 }, { 0, 220, 35 }, { 0, 219, 36 }, { 0, 218, 37 }, { 0, 217, 38 }, { 0, 216, 39 }, { 0, 215, 40 }, { 0, 214, 41 }, { 0, 213, 42 }, { 0, 212, 43 }, { 0, 211, 44 }, { 0, 210, 45 }, { 0, 209, 46 }, { 0, 208, 47 }, { 0, 207, 48 }, { 0, 206, 49 }, { 0, 205, 50 }, { 0, 204, 51 }, { 0, 203, 52 }, { 0, 202, 53 }, { 0, 201, 54 }, { 0, 200, 55 }, { 0, 199, 56 }, { 0, 1***, 57 }, { 0, 197, 58 }, { 0, 196, 59 }, { 0, 195, 60 }, { 0, 194, 61 }, { 0, 193, 62 }, { 0, 192, 63 }, { 0, 191, *** }, { 0, 190, 65 }, { 0, 189, 66 }, { 0, 188, 67 }, { 0, 187, 68 }, { 0, 186, 69 }, { 0, 185, 70 }, { 0, 184, 71 }, { 0, 183, 72 }, { 0, 182, 73 }, { 0, 181, 74 }, { 0, 180, 75 }, { 0, 179, 76 }, { 0, 178, 77 }, { 0, 177, 78 }, { 0, 176, 79 }, { 0, 175, 80 }, { 0, 174, 81 }, { 0, 173, 82 }, { 0, 172, 83 }, { 0, 171, 84 }, { 0, 170, 85 }, { 0, 169, 86 }, { 0, 168, 87 }, { 0, 167, 88 }, { 0, 166, 89 }, { 0, 165, 90 }, { 0, 1***, 91 }, { 0, 163, 92 }, { 0, 162, 93 }, { 0, 161, 94 }, { 0, 160, 95 }, { 0, 159, 96 }, { 0, 158, 97 }, { 0, 157, *** }, { 0, 156, 99 }, { 0, 155, 100 }, { 0, 154, 101 }, { 0, 153, 102 }, { 0, 152, 103 }, { 0, 151, 104 }, { 0, 150, 105 }, { 0, 149, 106 }, { 0, 148, 107 }, { 0, 147, 108 }, { 0, 146, 109 }, { 0, 145, 110 }, { 0, 144, 111 }, { 0, 143, 112 }, { 0, 142, 113 }, { 0, 141, 114 }, { 0, 140, 115 }, { 0, 139, 116 }, { 0, 138, 117 }, { 0, 137, 118 }, { 0, 136, 119 }, { 0, 135, 120 }, { 0, 134, 121 }, { 0, 133, 122 }, { 0, 132, 123 }, { 0, 131, 124 }, { 0, 130, 125 }, { 0, 129, 126 }, { 0, 128, 127 }, { 0, 127, 128 }, { 0, 126, 129 }, { 0, 125, 130 }, { 0, 124, 131 }, { 0, 123, 132 }, { 0, 122, 133 }, { 0, 121, 134 }, { 0, 120, 135 }, { 0, 119, 136 }, { 0, 118, 137 }, { 0, 117, 138 }, { 0, 116, 139 }, { 0, 115, 140 }, { 0, 114, 141 }, { 0, 113, 142 }, { 0, 112, 143 }, { 0, 111, 144 }, { 0, 110, 145 }, { 0, 109, 146 }, { 0, 108, 147 }, { 0, 107, 148 }, { 0, 106, 149 }, { 0, 105, 150 }, { 0, 104, 151 }, { 0, 103, 152 }, { 0, 102, 153 }, { 0, 101, 154 }, { 0, 100, 155 }, { 0, 99, 156 }, { 0, ***, 157 }, { 0, 97, 158 }, { 0, 96, 159 }, { 0, 95, 160 }, { 0, 94, 161 }, { 0, 93, 162 }, { 0, 92, 163 }, { 0, 91, 1*** }, { 0, 90, 165 }, { 0, 89, 166 }, { 0, 88, 167 }, { 0, 87, 168 }, { 0, 86, 169 }, { 0, 85, 170 }, { 0, 84, 171 }, { 0, 83, 172 }, { 0, 82, 173 }, { 0, 81, 174 }, { 0, 80, 175 }, { 0, 79, 176 }, { 0, 78, 177 }, { 0, 77, 178 }, { 0, 76, 179 }, { 0, 75, 180 }, { 0, 74, 181 }, { 0, 73, 182 }, { 0, 72, 183 }, { 0, 71, 184 }, { 0, 70, 185 }, { 0, 69, 186 }, { 0, 68, 187 }, { 0, 67, 188 }, { 0, 66, 189 }, { 0, 65, 190 }, { 0, ***, 191 }, { 0, 63, 192 }, { 0, 62, 193 }, { 0, 61, 194 }, { 0, 60, 195 }, { 0, 59, 196 }, { 0, 58, 197 }, { 0, 57, 1*** }, { 0, 56, 199 }, { 0, 55, 200 }, { 0, 54, 201 }, { 0, 53, 202 }, { 0, 52, 203 }, { 0, 51, 204 }, { 0, 50, 205 }, { 0, 49, 206 }, { 0, 48, 207 }, { 0, 47, 208 }, { 0, 46, 209 }, { 0, 45, 210 }, { 0, 44, 211 }, { 0, 43, 212 }, { 0, 42, 213 }, { 0, 41, 214 }, { 0, 40, 215 }, { 0, 39, 216 }, { 0, 38, 217 }, { 0, 37, 218 }, { 0, 36, 219 }, { 0, 35, 220 }, { 0, 34, 221 }, { 0, 33, 222 }, { 0, 32, 223 }, { 0, 31, 224 }, { 0, 30, 225 }, { 0, 29, 226 }, { 0, 28, 227 }, { 0, 27, 228 }, { 0, 26, 229 }, { 0, 25, 230 }, { 0, 24, 231 }, { 0, 23, 232 }, { 0, 22, 233 }, { 0, 21, 234 }, { 0, 20, 235 }, { 0, 19, 236 }, { 0, 18, 237 }, { 0, 17, 238 }, { 0, 16, 239 }, { 0, 15, 240 }, { 0, 14, 241 }, { 0, 13, 242 }, { 0, 12, 243 }, { 0, 11, 244 }, { 0, 10, 245 }, { 0, 9, 246 }, { 0, 8, 247 }, { 0, 7, 248 }, { 0, 6, 249 }, { 0, 5, 250 }, { 0, 4, 251 }, { 0, 3, 252 }, { 0, 2, 253 }, { 0, 1, 254 }, { 0, 0, 255 }, { 1, 0, 254 }, { 2, 0, 253 }, { 3, 0, 252 }, { 4, 0, 251 }, { 5, 0, 250 }, { 6, 0, 249 }, { 7, 0, 248 }, { 8, 0, 247 }, { 9, 0, 246 }, { 10, 0, 245 }, { 11, 0, 244 }, { 12, 0, 243 }, { 13, 0, 242 }, { 14, 0, 241 }, { 15, 0, 240 }, { 16, 0, 239 }, { 17, 0, 238 }, { 18, 0, 237 }, { 19, 0, 236 }, { 20, 0, 235 }, { 21, 0, 234 }, { 22, 0, 233 }, { 23, 0, 232 }, { 24, 0, 231 }, { 25, 0, 230 }, { 26, 0, 229 }, { 27, 0, 228 }, { 28, 0, 227 }, { 29, 0, 226 }, { 30, 0, 225 }, { 31, 0, 224 }, { 32, 0, 223 }, { 33, 0, 222 }, { 34, 0, 221 }, { 35, 0, 220 }, { 36, 0, 219 }, { 37, 0, 218 }, { 38, 0, 217 }, { 39, 0, 216 }, { 40, 0, 215 }, { 41, 0, 214 }, { 42, 0, 213 }, { 43, 0, 212 }, { 44, 0, 211 }, { 45, 0, 210 }, { 46, 0, 209 }, { 47, 0, 208 }, { 48, 0, 207 }, { 49, 0, 206 }, { 50, 0, 205 }, { 51, 0, 204 }, { 52, 0, 203 }, { 53, 0, 202 }, { 54, 0, 201 }, { 55, 0, 200 }, { 56, 0, 199 }, { 57, 0, 1*** }, { 58, 0, 197 }, { 59, 0, 196 }, { 60, 0, 195 }, { 61, 0, 194 }, { 62, 0, 193 }, { 63, 0, 192 }, { ***, 0, 191 }, { 65, 0, 190 }, { 66, 0, 189 }, { 67, 0, 188 }, { 68, 0, 187 }, { 69, 0, 186 }, { 70, 0, 185 }, { 71, 0, 184 }, { 72, 0, 183 }, { 73, 0, 182 }, { 74, 0, 181 }, { 75, 0, 180 }, { 76, 0, 179 }, { 77, 0, 178 }, { 78, 0, 177 }, { 79, 0, 176 }, { 80, 0, 175 }, { 81, 0, 174 }, { 82, 0, 173 }, { 83, 0, 172 }, { 84, 0, 171 }, { 85, 0, 170 }, { 86, 0, 169 }, { 87, 0, 168 }, { 88, 0, 167 }, { 89, 0, 166 }, { 90, 0, 165 }, { 91, 0, 1*** }, { 92, 0, 163 }, { 93, 0, 162 }, { 94, 0, 161 }, { 95, 0, 160 }, { 96, 0, 159 }, { 97, 0, 158 }, { ***, 0, 157 }, { 99, 0, 156 }, { 100, 0, 155 }, { 101, 0, 154 }, { 102, 0, 153 }, { 103, 0, 152 }, { 104, 0, 151 }, { 105, 0, 150 }, { 106, 0, 149 }, { 107, 0, 148 }, { 108, 0, 147 }, { 109, 0, 146 }, { 110, 0, 145 }, { 111, 0, 144 }, { 112, 0, 143 }, { 113, 0, 142 }, { 114, 0, 141 }, { 115, 0, 140 }, { 116, 0, 139 }, { 117, 0, 138 }, { 118, 0, 137 }, { 119, 0, 136 }, { 120, 0, 135 }, { 121, 0, 134 }, { 122, 0, 133 }, { 123, 0, 132 }, { 124, 0, 131 }, { 125, 0, 130 }, { 126, 0, 129 }, { 127, 0, 128 }, { 128, 0, 127 }, { 129, 0, 126 }, { 130, 0, 125 }, { 131, 0, 124 }, { 132, 0, 123 }, { 133, 0, 122 }, { 134, 0, 121 }, { 135, 0, 120 }, { 136, 0, 119 }, { 137, 0, 118 }, { 138, 0, 117 }, { 139, 0, 116 }, { 140, 0, 115 }, { 141, 0, 114 }, { 142, 0, 113 }, { 143, 0, 112 }, { 144, 0, 111 }, { 145, 0, 110 }, { 146, 0, 109 }, { 147, 0, 108 }, { 148, 0, 107 }, { 149, 0, 106 }, { 150, 0, 105 }, { 151, 0, 104 }, { 152, 0, 103 }, { 153, 0, 102 }, { 154, 0, 101 }, { 155, 0, 100 }, { 156, 0, 99 }, { 157, 0, *** }, { 158, 0, 97 }, { 159, 0, 96 }, { 160, 0, 95 }, { 161, 0, 94 }, { 162, 0, 93 }, { 163, 0, 92 }, { 1***, 0, 91 }, { 165, 0, 90 }, { 166, 0, 89 }, { 167, 0, 88 }, { 168, 0, 87 }, { 169, 0, 86 }, { 170, 0, 85 }, { 171, 0, 84 }, { 172, 0, 83 }, { 173, 0, 82 }, { 174, 0, 81 }, { 175, 0, 80 }, { 176, 0, 79 }, { 177, 0, 78 }, { 178, 0, 77 }, { 179, 0, 76 }, { 180, 0, 75 }, { 181, 0, 74 }, { 182, 0, 73 }, { 183, 0, 72 }, { 184, 0, 71 }, { 185, 0, 70 }, { 186, 0, 69 }, { 187, 0, 68 }, { 188, 0, 67 }, { 189, 0, 66 }, { 190, 0, 65 }, { 191, 0, *** }, { 192, 0, 63 }, { 193, 0, 62 }, { 194, 0, 61 }, { 195, 0, 60 }, { 196, 0, 59 }, { 197, 0, 58 }, { 1***, 0, 57 }, { 199, 0, 56 }, { 200, 0, 55 }, { 201, 0, 54 }, { 202, 0, 53 }, { 203, 0, 52 }, { 204, 0, 51 }, { 205, 0, 50 }, { 206, 0, 49 }, { 207, 0, 48 }, { 208, 0, 47 }, { 209, 0, 46 }, { 210, 0, 45 }, { 211, 0, 44 }, { 212, 0, 43 }, { 213, 0, 42 }, { 214, 0, 41 }, { 215, 0, 40 }, { 216, 0, 39 }, { 217, 0, 38 }, { 218, 0, 37 }, { 219, 0, 36 }, { 220, 0, 35 }, { 221, 0, 34 }, { 222, 0, 33 }, { 223, 0, 32 }, { 224, 0, 31 }, { 225, 0, 30 }, { 226, 0, 29 }, { 227, 0, 28 }, { 228, 0, 27 }, { 229, 0, 26 }, { 230, 0, 25 }, { 231, 0, 24 }, { 232, 0, 23 }, { 233, 0, 22 }, { 234, 0, 21 }, { 235, 0, 20 }, { 236, 0, 19 }, { 237, 0, 18 }, { 238, 0, 17 }, { 239, 0, 16 }, { 240, 0, 15 }, { 241, 0, 14 }, { 242, 0, 13 }, { 243, 0, 12 }, { 244, 0, 11 }, { 245, 0, 10 }, { 246, 0, 9 }, { 247, 0, 8 }, { 248, 0, 7 }, { 249, 0, 6 }, { 250, 0, 5 }, { 251, 0, 4 }, { 252, 0, 3 }, { 253, 0, 2 }, { 254, 0, 1 }, { 255, 0, 0 }, }; void Timer3_init( void ) { uint16_t PrescalerValue; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE ); /* GPIOA Configuration: TIM3 Channel 1 as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( GPIOA, &GPIO_InitStructure ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE ); /* Compute the prescaler value */ PrescalerValue = (uint16_t) ( SystemCoreClock / 24000000 ) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 29; // 800kHz TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure ); /* PWM1 Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init( TIM3, &TIM_OCInitStructure ); /* configure DMA */ /* DMA clock enable */ RCC_AHBPeriphClockCmd( RCC_AHBPeriph_DMA1, ENABLE ); /* DMA1 Channel6 Config */ DMA_DeInit( DMA1_Channel6 ); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) TIM3_CCR1_Address; // physical address of Timer 3 CCR1 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) LED_BYTE_Buffer; // this is the buffer memory DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // data shifted from memory to peripheral DMA_InitStructure.DMA_BufferSize = 42; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // automatically increase buffer index DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // stop DMA feed after buffer size is reached DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init( DMA1_Channel6, &DMA_InitStructure ); /* TIM3 CC1 DMA Request enable */ TIM_DMACmd( TIM3, TIM_DMA_CC1, ENABLE ); } /* This function sends data bytes out to a string of WS2812s * The first argument is a pointer to the first RGB triplet to be sent -- color * The seconds argument is the number of LEDs in the chain -- len * * This will result in the RGB triplet passed by argument 1 being sent to * the LED that is the furthest away from the controller (the point where * data is injected into the chain) */ void WS2812_send( uint8_t (*color)[ 3 ], uint16_t len ) { uint8_t i, j; uint8_t led; uint16_t memaddr; uint16_t buffersize; buffersize = ( len * 24 ) + 42; // number of bytes needed is #LEDs * 24 bytes + 42 trailing bytes memaddr = 0; // reset buffer memory index led = 0; // reset led index // fill transmit buffer with correct compare values to achieve // correct pulse widths according to color values while ( len ) { for ( j = 0; j < 8; j++ ) // GREEN data { if ( ( color[ led ][ 1 ] << j ) & 0x80 ) // data sent MSB first, j = 0 is MSB j = 7 is LSB { LED_BYTE_Buffer[ memaddr ] = 17; // compare value for logical 1 } else { LED_BYTE_Buffer[ memaddr ] = 9; // compare value for logical 0 } memaddr++; } for ( j = 0; j < 8; j++ ) // RED data { if ( ( color[ led ][ 0 ] << j ) & 0x80 ) // data sent MSB first, j = 0 is MSB j = 7 is LSB { LED_BYTE_Buffer[ memaddr ] = 17; // compare value for logical 1 } else { LED_BYTE_Buffer[ memaddr ] = 9; // compare value for logical 0 } memaddr++; } for ( j = 0; j < 8; j++ ) // BLUE data { if ( ( color[ led ][ 2 ] << j ) & 0x80 ) // data sent MSB first, j = 0 is MSB j = 7 is LSB { LED_BYTE_Buffer[ memaddr ] = 17; // compare value for logical 1 } else { LED_BYTE_Buffer[ memaddr ] = 9; // compare value for logical 0 } memaddr++; } led++; len--; } // add needed delay at end of byte cycle, pulsewidth = 0 while ( memaddr < buffersize ) { LED_BYTE_Buffer[ memaddr ] = 0; memaddr++; } DMA_SetCurrDataCounter( DMA1_Channel6, buffersize ); // load number of bytes to be transferred DMA_Cmd( DMA1_Channel6, ENABLE ); // enable DMA channel 6 TIM_Cmd( TIM3, ENABLE ); // enable Timer 3 while ( !DMA_GetFlagStatus( DMA1_FLAG_TC6 ) ) ; // wait until transfer complete TIM_Cmd( TIM3, DISABLE ); // disable Timer 3 ... ...

近期下载者

相关文件


收藏者