mca-pendel/sketches/djhgfjh/WS2812B_Atmega.h

35 lines
1.0 KiB
C
Raw Normal View History

/**
* This header files includes all function for the LEDs WS2812B.
* It uses assambler for the PWM-Protocol and is designed for
* a 20 MHz external oscillator.
*/
#ifndef WS2812B_ATMEGA
#define WS2812B_ATMEGA
#define F_CPU 20000000UL
#include <util/delay.h>
#include <avr/io.h>
#include <stdint.h>
#define DATAPIN PORTC
// https://github.com/cpldcpu/light_ws2812/blob/master/light_ws2812_AVR/Light_WS2812/light_ws2812.c
#define w_nop1 __asm__("nop \n\t")
#define w_nop2 __asm__("rjmp .+0 \n\t")
#define w_nop4 w_nop2; w_nop2
// f=20MHz -> T=0,05 µs
#define wait6 w_nop2; w_nop4 // == 0.3 µs ~ 0.4 µs (+- 150ns) == [0.25, 0.55] µs
#define wait8 w_nop4; w_nop4 // == 0.4 µs ~ 0.45µs (+- 150ns) == [0.30, 0.60] µs
#define wait14 wait8; wait6 // == 0.7 µs ~ 0.8 µs (+- 150ns) == [0.65, 0.95] µs
#define wait15 wait14; w_nop1 // == 0.75 µs ~ 0.85µs (+- 150ns) == [0.70, 1.00] µs
#define waitRES _delay_us(51) // > 50 µs
void writeZero(void);
void writeOne(void);
void writeRGB(uint8_t r, uint8_t g, uint8_t b);
#endif