ws2801/ws2801.cpp

49 lines
1.4 KiB
C++

/*
* ws2801.cpp
*
* Created: 26-12-16 21:57:10
* Author: Adrien
*/
#include <avr/io.h>
#include <stdlib.h>
/*
L'espace mémoir à envoyer au ci est constituer comme ça :
ciN |-----------0-----------||-----------1-----------||...||-----------N-----------| Ci numéro
coulB |R7...R0|G7...G0|B7...B0||R7...R0|G7...G0|B7...B0||...||R7...R0|G7...G0|B7...B0| Valeur Couleurs bit n
coul |--RED--|-GREEN-|--BLUE-||--RED--|-GREEN-|--BLUE-||...||--RED--|-GREEN-|--BLUE-| Valeur Couleurs
bitN |7.....0|7.....0|7.....0||7.....0|7.....0|7.....0||...||7.....0|7.....0|7.....0| Bit n
t[] |---0---|---1---|---2---||---3---|---4---|---5---||...||-3*N+0-|-3*N+1-|-3*N+3-| Emplacement dans le tableau
Pour l'envois, il faut commencer par le bit 7 !
*/
ws2801::ws2801(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci)
{
this->pin_clk = pin_clk;
this->pin_data = pin_data;
this->port = port;
this->nbr_ci = nbr_ci;
data = calloc(3*nbr_ci, 1);
ddr = port-1;
*ddr |= (1<<pin_ckl)|(1<<pin_data);
}
void ws2801::conf(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci)
{
this->pin_clk = pin_clk;
this->pin_data = pin_data;
this->port = port;
this->nbr_ci = nbr_ci;
data = realloc(data,3*nbr_ci);
ddr = port-1;
*ddr |= (1<<pin_ckl)|(1<<pin_data);
}
void ws2801::toSend(uint8_t ciN, uint8_t val, Color couleur)
{
*(data+32*ciN+couleur) = val;
}
void ws2801::send();
void ws2801::senRaw(uint8_t *data,uint8_t size);