From 07493b94b141506e051b0adb9f68132ebfc583c0 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Thu, 8 Nov 2018 19:47:52 +0800 Subject: Added the max7219 stuff. --- rpi/max7219/max7219.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 rpi/max7219/max7219.c (limited to 'rpi/max7219/max7219.c') diff --git a/rpi/max7219/max7219.c b/rpi/max7219/max7219.c new file mode 100644 index 0000000..33a7fed --- /dev/null +++ b/rpi/max7219/max7219.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "max7219.h" + +#define wait nanosleep(&cl,NULL) +const struct timespec cl={0,10}; +/* + * _sendpacket(d) + * sends a 16 bit packet to the data line. + * for internal usage only. + */ +void _sendpacket(unsigned short d) +{ + unsigned char i; + for(i=16;i>0;--i) + { + unsigned short mask=1<<(i-1); + digitalWrite(P_CLK,0);wait; + digitalWrite(P_DATA,(d&mask)?1:0); + wait;digitalWrite(P_CLK,1);wait; + } +} +/* + * max7219_send(r,d,chip) + * sets the value of register #d in chip #chip to d. + * chips are 0-indexed. chip=-1 means send to all chips. + */ +void max7219_send(unsigned char r,unsigned char d,int chip) +{ + digitalWrite(P_CS,0);wait; + for(int i=0;i