Test program for my Multi_WS2811 library that started out as a fork of heroic/WS2811. My library uses hardware DMA on the FRDM-KL25Z to drive up to 16 strings of WS2811 or WS2812 LEDs in parallel.
Dependencies: Multi_WS2811 mbed MMA8451Q
Fork of WS2811 by
NOTE: I have accidentally pushed changes for another fork of this program that I used in the recent Georgetown Carnival Power Tool Races. When I get some time, I will restore the test program to its original glory.
You can see my power tool racer (Nevermore's Revenge) here

This tests my FRDM-KL25Z multi-string WS2811/WS2812 library. It uses the accelerometer to change the rainbow phase on two strings of LEDs as well as the touch sense to change brightness.
A video of this program in operation is here.
Here is the library that I developed to run the LEDs:
Import libraryMulti_WS2811
Library allowing up to 16 strings of 60 WS2811 or WS2812 LEDs to be driven from a single FRDM-KL25Z board. Uses hardware DMA to do a full 800 KHz rate without much CPU burden.
bitband.h@16:5f75ea93f15d, 2013-10-10 (annotated)
- Committer:
- heroic
- Date:
- Thu Oct 10 21:52:59 2013 +0000
- Revision:
- 16:5f75ea93f15d
Bump version, add register debug.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| heroic | 16:5f75ea93f15d | 1 | //***************************************************************************** |
| heroic | 16:5f75ea93f15d | 2 | // +--+ |
| heroic | 16:5f75ea93f15d | 3 | // | ++----+ |
| heroic | 16:5f75ea93f15d | 4 | // +-++ | |
| heroic | 16:5f75ea93f15d | 5 | // | | |
| heroic | 16:5f75ea93f15d | 6 | // +-+--+ | |
| heroic | 16:5f75ea93f15d | 7 | // | +--+--+ |
| heroic | 16:5f75ea93f15d | 8 | // +----+ Copyright (c) 2011 Code Red Technologies Ltd. |
| heroic | 16:5f75ea93f15d | 9 | // |
| heroic | 16:5f75ea93f15d | 10 | // Header file containing C macros to provide bitbanding on Cortex-M3 MCU's |
| heroic | 16:5f75ea93f15d | 11 | // |
| heroic | 16:5f75ea93f15d | 12 | // Software License Agreement |
| heroic | 16:5f75ea93f15d | 13 | // |
| heroic | 16:5f75ea93f15d | 14 | // The software is owned by Code Red Technologies and/or its suppliers, and is |
| heroic | 16:5f75ea93f15d | 15 | // protected under applicable copyright laws. All rights are reserved. Any |
| heroic | 16:5f75ea93f15d | 16 | // use in violation of the foregoing restrictions may subject the user to criminal |
| heroic | 16:5f75ea93f15d | 17 | // sanctions under applicable laws, as well as to civil liability for the breach |
| heroic | 16:5f75ea93f15d | 18 | // of the terms and conditions of this license. |
| heroic | 16:5f75ea93f15d | 19 | // |
| heroic | 16:5f75ea93f15d | 20 | // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED |
| heroic | 16:5f75ea93f15d | 21 | // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
| heroic | 16:5f75ea93f15d | 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. |
| heroic | 16:5f75ea93f15d | 23 | // USE OF THIS SOFTWARE FOR COMMERCIAL DEVELOPMENT AND/OR EDUCATION IS SUBJECT |
| heroic | 16:5f75ea93f15d | 24 | // TO A CURRENT END USER LICENSE AGREEMENT (COMMERCIAL OR EDUCATIONAL) WITH |
| heroic | 16:5f75ea93f15d | 25 | // CODE RED TECHNOLOGIES LTD. |
| heroic | 16:5f75ea93f15d | 26 | // |
| heroic | 16:5f75ea93f15d | 27 | //***************************************************************************** |
| heroic | 16:5f75ea93f15d | 28 | |
| heroic | 16:5f75ea93f15d | 29 | #ifndef BITBAND_H_ |
| heroic | 16:5f75ea93f15d | 30 | #define BITBAND_H_ |
| heroic | 16:5f75ea93f15d | 31 | |
| heroic | 16:5f75ea93f15d | 32 | /* The Cortex-M3 memory map includes two bit-band regions. These occupy the lowest |
| heroic | 16:5f75ea93f15d | 33 | * 1MB of the SRAM and peripheral memory regions respectively. |
| heroic | 16:5f75ea93f15d | 34 | * + SRAM: Bit-band region: 0x20000000 - 0x20100000 |
| heroic | 16:5f75ea93f15d | 35 | * Bit-band alias: 0x22000000 - 0x23FFFFFF |
| heroic | 16:5f75ea93f15d | 36 | * + PERI: Bit-band region: 0x40000000 - 0x40100000 |
| heroic | 16:5f75ea93f15d | 37 | * Bit-band alias: 0x42000000 - 0x43FFFFFF |
| heroic | 16:5f75ea93f15d | 38 | * The mapping formula: |
| heroic | 16:5f75ea93f15d | 39 | * bit_word_offset = (byte_offset * 32) + (bit_number * 4) |
| heroic | 16:5f75ea93f15d | 40 | * bit_word_address = bit_band_base + bit_word_offset |
| heroic | 16:5f75ea93f15d | 41 | * where: |
| heroic | 16:5f75ea93f15d | 42 | * + bit_word_offset: the position of the target bit in the bit-band memory region |
| heroic | 16:5f75ea93f15d | 43 | * + bit_word_addr: the address of the word in the alias memory region that maps to the target bit |
| heroic | 16:5f75ea93f15d | 44 | * + bit_band_base: the starting address of the alias region |
| heroic | 16:5f75ea93f15d | 45 | * + byte_offset: the number of byte in the bit-band region that contains the targeted bit |
| heroic | 16:5f75ea93f15d | 46 | * + bit_number: is the bit position (0-7) of the targeted bit |
| heroic | 16:5f75ea93f15d | 47 | */ |
| heroic | 16:5f75ea93f15d | 48 | |
| heroic | 16:5f75ea93f15d | 49 | /* Bit band SRAM definitions */ |
| heroic | 16:5f75ea93f15d | 50 | #define BITBAND_SRAM_REF 0x20000000 |
| heroic | 16:5f75ea93f15d | 51 | #define BITBAND_SRAM_BASE 0x22000000 |
| heroic | 16:5f75ea93f15d | 52 | |
| heroic | 16:5f75ea93f15d | 53 | #define BITBAND_SRAM(a,b) ((BITBAND_SRAM_BASE + ((a-BITBAND_SRAM_REF)<<5) + (b<<2))) // Convert SRAM address |
| heroic | 16:5f75ea93f15d | 54 | |
| heroic | 16:5f75ea93f15d | 55 | /* Bit band PERIPHERAL definitions */ |
| heroic | 16:5f75ea93f15d | 56 | #define BITBAND_PERI_REF 0x40000000 |
| heroic | 16:5f75ea93f15d | 57 | #define BITBAND_PERI_BASE 0x42000000 |
| heroic | 16:5f75ea93f15d | 58 | |
| heroic | 16:5f75ea93f15d | 59 | #define BITBAND_PERI(a,b) ((BITBAND_PERI_BASE + ((a-BITBAND_PERI_REF)<<5) + (b<<2))) // Convert PERI address |
| heroic | 16:5f75ea93f15d | 60 | |
| heroic | 16:5f75ea93f15d | 61 | /* Basic bit band function definitions */ |
| heroic | 16:5f75ea93f15d | 62 | #define BITBAND_SRAM_ClearBit(a,b) (*(volatile uint32_t *) (BITBAND_SRAM(a,b)) = 0) |
| heroic | 16:5f75ea93f15d | 63 | #define BITBAND_SRAM_SetBit(a,b) (*(volatile uint32_t *) (BITBAND_SRAM(a,b)) = 1) |
| heroic | 16:5f75ea93f15d | 64 | #define BITBAND_SRAM_GetBit(a,b) (*(volatile uint32_t *) (BITBAND_SRAM(a,b))) |
| heroic | 16:5f75ea93f15d | 65 | |
| heroic | 16:5f75ea93f15d | 66 | #define BITBAND_PERI_ClearBit(a,b) (*(volatile uint32_t *) (BITBAND_PERI(a,b)) = 0) |
| heroic | 16:5f75ea93f15d | 67 | #define BITBAND_PERI_SetBit(a,b) (*(volatile uint32_t *) (BITBAND_PERI(a,b)) = 1) |
| heroic | 16:5f75ea93f15d | 68 | #define BITBAND_PERI_GetBit(a,b) (*(volatile uint32_t *) (BITBAND_PERI(a,b))) |
| heroic | 16:5f75ea93f15d | 69 | |
| heroic | 16:5f75ea93f15d | 70 | |
| heroic | 16:5f75ea93f15d | 71 | #endif /* BITBAND_H_ */ |
Ned Konz


Generic WS2811/WS2812