This commit is contained in:
Adrien VAN DAMME 2017-02-05 17:15:13 +01:00
parent 96f25a5597
commit 7680a92c16
4 changed files with 42 additions and 16 deletions

BIN
a.out Executable file

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include <avr/io.h> #include <avr/io.h>
#include <stdlib.h> #include <stdlib.h>
#include "ws2801.h"
/* /*
L'espace mémoir à envoyer au ci est constituer comme ça : L'espace mémoir à envoyer au ci est constituer comme ça :
@ -19,16 +20,17 @@ t[] |---0---|---1---|---2---||---3---|---4---|---5---||...||-3*N+0-|-3*N+1-|-3*
Pour l'envois, il faut commencer par le bit 7 ! Pour l'envois, il faut commencer par le bit 7 !
*/ */
main()
{}
ws2801::ws2801(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci) ws2801::ws2801(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci)
{ {
this->pin_clk = pin_clk; this->pin_clk = pin_clk;
this->pin_data = pin_data; this->pin_data = pin_data;
this->port = port; this->port = port;
this->nbr_ci = nbr_ci; this->nbr_ci = nbr_ci;
data = calloc(3*nbr_ci, 1); data = (uint8_t*)calloc(3*nbr_ci, 1);
ddr = port-1; ddr = port-1;
*ddr |= (1<<pin_ckl)|(1<<pin_data); *ddr |= (1<<pin_clk)|(1<<pin_data);
} }
void ws2801::conf(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci) void ws2801::conf(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci)
{ {
@ -36,13 +38,35 @@ Pour l'envois, il faut commencer par le bit 7 !
this->pin_data = pin_data; this->pin_data = pin_data;
this->port = port; this->port = port;
this->nbr_ci = nbr_ci; this->nbr_ci = nbr_ci;
data = realloc(data,3*nbr_ci); data = (uint8_t*)realloc(data,3*nbr_ci);
ddr = port-1; ddr = port-1;
*ddr |= (1<<pin_ckl)|(1<<pin_data); *ddr |= (1<<pin_clk)|(1<<pin_data);
} }
void ws2801::toSend(uint8_t ciN, uint8_t val, Color couleur) void ws2801::toSend(uint8_t LEDn, uint8_t val, Color couleur)
{ {
*(data+32*ciN+couleur) = val; *(data+32*LEDn+couleur) = val;
}
void ws2801::toSend(uint8_t LEDn, uint8_t val)
{
*(data+LEDn) = val;
}
void ws2801::send()
{
sendRaw(data, 3*nbr_ci);
}
void ws2801::sendRaw(uint8_t *data,uint8_t size)
{
int i,j,m;
for(i=0;i<size;i++)
{
for(j=0,m=0x80;j<8;j++)
{
*port &= ~(_BV(pin_clk));
*port = (*port&(~(_BV(pin_data))))|((data[i]&m)?_BV(pin_data):0);
if(m==0x01)
m=0x80;
else
m>>=1;
}
}
} }
void ws2801::send();
void ws2801::senRaw(uint8_t *data,uint8_t size);

View File

@ -3,28 +3,30 @@
* *
* Created: 26-12-16 21:57:26 * Created: 26-12-16 21:57:26
* Author: Adrien * Author: Adrien
*/ */
#ifndef WS2801_H_ #ifndef WS2801_H_
#define WS2801_H_ #define WS2801_H_
#include <stdint.h>
typedef enum {RED, GREEN, BLUE} Color; typedef enum {RED, GREEN, BLUE} Color;
class ws2801 class ws2801
{ {
private: private:
uint8_t pin_ckl, pin_data; uint8_t pin_clk, pin_data;
uint8_t *data; uint8_t *data;
uint8_t nbr_ci; uint8_t nbr_ci;
uint8_t *port, *ddr; uint8_t *port, *ddr;
public: public:
ws2801(uint8_t pin_clk, uint8_t pin_data, uint8_t *port); ws2801(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci);
void conf(uint8_t pin_clk, uint8_t pin_data, uint8_t *port); void conf(uint8_t pin_clk, uint8_t pin_data, uint8_t *port, uint8_t nbr_ci);
void toSend(uint8_t ciN, uint8_t val, Color couleur); void toSend(uint8_t LEDn, uint8_t val, Color couleur);
void toSend(uint8_t LEDn, uint8_t val);
void send(); void send();
void senRaw(uint8_t *data,uint8_t size); void sendRaw(uint8_t *data,uint8_t size);
}; };
#endif /* WS2801_H_ */ #endif /* WS2801_H_ */

BIN
ws2801.h.gch Normal file

Binary file not shown.