|
@@ -0,0 +1,470 @@
|
|
|
+#include <stdio.h>
|
|
|
+#include <string.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <stdint.h>
|
|
|
+#include <armbianio.h>
|
|
|
+#include "max7219.h"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const uint8_t ucFont[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x81,0x95,0xb1,0xb1,0x95,0x81,0x7e,
|
|
|
+ 0x7e,0xff,0xeb,0xcf,0xcf,0xeb,0xff,0x7e,0x0e,0x1f,0x3f,0x7e,0x3f,0x1f,0x0e,0x00,
|
|
|
+ 0x08,0x1c,0x3e,0x7f,0x3e,0x1c,0x08,0x00,0x38,0x9a,0x9f,0xff,0x9f,0x9a,0x38,0x00,
|
|
|
+ 0x10,0xb8,0xfc,0xfe,0xfc,0xb8,0x10,0x00,0x00,0x00,0x18,0x3c,0x3c,0x18,0x00,0x00,
|
|
|
+ 0xff,0xff,0xe7,0xc3,0xc3,0xe7,0xff,0xff,0x00,0x3c,0x66,0x42,0x42,0x66,0x3c,0x00,
|
|
|
+ 0xff,0xc3,0x99,0xbd,0xbd,0x99,0xc3,0xff,0x70,0xf8,0x88,0x88,0xfd,0x7f,0x07,0x0f,
|
|
|
+ 0x00,0x4e,0x5f,0xf1,0xf1,0x5f,0x4e,0x00,0xc0,0xe0,0xff,0x7f,0x05,0x05,0x07,0x07,
|
|
|
+ 0xc0,0xff,0x7f,0x05,0x05,0x65,0x7f,0x3f,0x99,0x5a,0x3c,0xe7,0xe7,0x3c,0x5a,0x99,
|
|
|
+ 0x7f,0x3e,0x3e,0x1c,0x1c,0x08,0x08,0x00,0x08,0x08,0x1c,0x1c,0x3e,0x3e,0x7f,0x00,
|
|
|
+ 0x00,0x24,0x66,0xff,0xff,0x66,0x24,0x00,0x00,0x5f,0x5f,0x00,0x00,0x5f,0x5f,0x00,
|
|
|
+ 0x06,0x0f,0x09,0x7f,0x7f,0x01,0x7f,0x7f,0xc0,0x9a,0xbf,0xa5,0xbd,0xd9,0x43,0x02,
|
|
|
+ 0x00,0x70,0x70,0x70,0x70,0x70,0x70,0x00,0x80,0x94,0xb6,0xff,0xff,0xb6,0x94,0x80,
|
|
|
+ 0x00,0x04,0x06,0x7f,0x7f,0x06,0x04,0x00,0x00,0x10,0x30,0x7f,0x7f,0x30,0x10,0x00,
|
|
|
+ 0x08,0x08,0x08,0x2a,0x3e,0x1c,0x08,0x00,0x08,0x1c,0x3e,0x2a,0x08,0x08,0x08,0x00,
|
|
|
+ 0x3c,0x3c,0x20,0x20,0x20,0x20,0x20,0x00,0x08,0x1c,0x3e,0x08,0x08,0x3e,0x1c,0x08,
|
|
|
+ 0x30,0x38,0x3c,0x3e,0x3e,0x3c,0x38,0x30,0x06,0x0e,0x1e,0x3e,0x3e,0x1e,0x0e,0x06,
|
|
|
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x5f,0x5f,0x06,0x00,0x00,
|
|
|
+ 0x00,0x07,0x07,0x00,0x07,0x07,0x00,0x00,0x14,0x7f,0x7f,0x14,0x7f,0x7f,0x14,0x00,
|
|
|
+ 0x24,0x2e,0x2a,0x6b,0x6b,0x3a,0x12,0x00,0x46,0x66,0x30,0x18,0x0c,0x66,0x62,0x00,
|
|
|
+ 0x30,0x7a,0x4f,0x5d,0x37,0x7a,0x48,0x00,0x00,0x04,0x07,0x03,0x00,0x00,0x00,0x00,
|
|
|
+ 0x00,0x1c,0x3e,0x63,0x41,0x00,0x00,0x00,0x00,0x41,0x63,0x3e,0x1c,0x00,0x00,0x00,
|
|
|
+ 0x08,0x2a,0x3e,0x1c,0x1c,0x3e,0x2a,0x08,0x00,0x08,0x08,0x3e,0x3e,0x08,0x08,0x00,
|
|
|
+ 0x00,0x00,0x80,0xe0,0x60,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x00,
|
|
|
+ 0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x60,0x30,0x18,0x0c,0x06,0x03,0x01,0x00,
|
|
|
+ 0x3e,0x7f,0x59,0x4d,0x47,0x7f,0x3e,0x00,0x40,0x42,0x7f,0x7f,0x40,0x40,0x00,0x00,
|
|
|
+ 0x62,0x73,0x59,0x49,0x6f,0x66,0x00,0x00,0x22,0x63,0x49,0x49,0x7f,0x36,0x00,0x00,
|
|
|
+ 0x18,0x1c,0x16,0x53,0x7f,0x7f,0x50,0x00,0x27,0x67,0x45,0x45,0x7d,0x39,0x00,0x00,
|
|
|
+ 0x3c,0x7e,0x4b,0x49,0x79,0x30,0x00,0x00,0x03,0x03,0x71,0x79,0x0f,0x07,0x00,0x00,
|
|
|
+ 0x36,0x7f,0x49,0x49,0x7f,0x36,0x00,0x00,0x06,0x4f,0x49,0x69,0x3f,0x1e,0x00,0x00,
|
|
|
+ 0x00,0x00,0x00,0x66,0x66,0x00,0x00,0x00,0x00,0x00,0x80,0xe6,0x66,0x00,0x00,0x00,
|
|
|
+ 0x08,0x1c,0x36,0x63,0x41,0x00,0x00,0x00,0x00,0x14,0x14,0x14,0x14,0x14,0x14,0x00,
|
|
|
+ 0x00,0x41,0x63,0x36,0x1c,0x08,0x00,0x00,0x00,0x02,0x03,0x59,0x5d,0x07,0x02,0x00,
|
|
|
+ 0x3e,0x7f,0x41,0x5d,0x5d,0x5f,0x0e,0x00,0x7c,0x7e,0x13,0x13,0x7e,0x7c,0x00,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x49,0x49,0x7f,0x36,0x00,0x1c,0x3e,0x63,0x41,0x41,0x63,0x22,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x41,0x63,0x3e,0x1c,0x00,0x41,0x7f,0x7f,0x49,0x5d,0x41,0x63,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x49,0x1d,0x01,0x03,0x00,0x1c,0x3e,0x63,0x41,0x51,0x33,0x72,0x00,
|
|
|
+ 0x7f,0x7f,0x08,0x08,0x7f,0x7f,0x00,0x00,0x00,0x41,0x7f,0x7f,0x41,0x00,0x00,0x00,
|
|
|
+ 0x30,0x70,0x40,0x41,0x7f,0x3f,0x01,0x00,0x41,0x7f,0x7f,0x08,0x1c,0x77,0x63,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x41,0x40,0x60,0x70,0x00,0x7f,0x7f,0x0e,0x1c,0x0e,0x7f,0x7f,0x00,
|
|
|
+ 0x7f,0x7f,0x06,0x0c,0x18,0x7f,0x7f,0x00,0x1c,0x3e,0x63,0x41,0x63,0x3e,0x1c,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x49,0x09,0x0f,0x06,0x00,0x1e,0x3f,0x21,0x31,0x61,0x7f,0x5e,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x09,0x19,0x7f,0x66,0x00,0x26,0x6f,0x4d,0x49,0x59,0x73,0x32,0x00,
|
|
|
+ 0x03,0x41,0x7f,0x7f,0x41,0x03,0x00,0x00,0x7f,0x7f,0x40,0x40,0x7f,0x7f,0x00,0x00,
|
|
|
+ 0x1f,0x3f,0x60,0x60,0x3f,0x1f,0x00,0x00,0x3f,0x7f,0x60,0x30,0x60,0x7f,0x3f,0x00,
|
|
|
+ 0x63,0x77,0x1c,0x08,0x1c,0x77,0x63,0x00,0x07,0x4f,0x78,0x78,0x4f,0x07,0x00,0x00,
|
|
|
+ 0x47,0x63,0x71,0x59,0x4d,0x67,0x73,0x00,0x00,0x7f,0x7f,0x41,0x41,0x00,0x00,0x00,
|
|
|
+ 0x01,0x03,0x06,0x0c,0x18,0x30,0x60,0x00,0x00,0x41,0x41,0x7f,0x7f,0x00,0x00,0x00,
|
|
|
+ 0x08,0x0c,0x06,0x03,0x06,0x0c,0x08,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
|
|
|
+ 0x00,0x00,0x03,0x07,0x04,0x00,0x00,0x00,0x20,0x74,0x54,0x54,0x3c,0x78,0x40,0x00,
|
|
|
+ 0x41,0x7f,0x3f,0x48,0x48,0x78,0x30,0x00,0x38,0x7c,0x44,0x44,0x6c,0x28,0x00,0x00,
|
|
|
+ 0x30,0x78,0x48,0x49,0x3f,0x7f,0x40,0x00,0x38,0x7c,0x54,0x54,0x5c,0x18,0x00,0x00,
|
|
|
+ 0x48,0x7e,0x7f,0x49,0x03,0x06,0x00,0x00,0x98,0xbc,0xa4,0xa4,0xf8,0x7c,0x04,0x00,
|
|
|
+ 0x41,0x7f,0x7f,0x08,0x04,0x7c,0x78,0x00,0x00,0x44,0x7d,0x7d,0x40,0x00,0x00,0x00,
|
|
|
+ 0x60,0xe0,0x80,0x84,0xfd,0x7d,0x00,0x00,0x41,0x7f,0x7f,0x10,0x38,0x6c,0x44,0x00,
|
|
|
+ 0x00,0x41,0x7f,0x7f,0x40,0x00,0x00,0x00,0x7c,0x7c,0x18,0x78,0x1c,0x7c,0x78,0x00,
|
|
|
+ 0x7c,0x78,0x04,0x04,0x7c,0x78,0x00,0x00,0x38,0x7c,0x44,0x44,0x7c,0x38,0x00,0x00,
|
|
|
+ 0x84,0xfc,0xf8,0xa4,0x24,0x3c,0x18,0x00,0x18,0x3c,0x24,0xa4,0xf8,0xfc,0x84,0x00,
|
|
|
+ 0x44,0x7c,0x78,0x4c,0x04,0x0c,0x18,0x00,0x48,0x5c,0x54,0x74,0x64,0x24,0x00,0x00,
|
|
|
+ 0x04,0x04,0x3e,0x7f,0x44,0x24,0x00,0x00,0x3c,0x7c,0x40,0x40,0x3c,0x7c,0x40,0x00,
|
|
|
+ 0x1c,0x3c,0x60,0x60,0x3c,0x1c,0x00,0x00,0x3c,0x7c,0x60,0x30,0x60,0x7c,0x3c,0x00,
|
|
|
+ 0x44,0x6c,0x38,0x10,0x38,0x6c,0x44,0x00,0x9c,0xbc,0xa0,0xa0,0xfc,0x7c,0x00,0x00,
|
|
|
+ 0x4c,0x64,0x74,0x5c,0x4c,0x64,0x00,0x00,0x08,0x08,0x3e,0x77,0x41,0x41,0x00,0x00,
|
|
|
+ 0x00,0x00,0x00,0x77,0x77,0x00,0x00,0x00,0x41,0x41,0x77,0x3e,0x08,0x08,0x00,0x00,
|
|
|
+ 0x02,0x03,0x01,0x03,0x02,0x03,0x01,0x00,0x70,0x78,0x4c,0x46,0x4c,0x78,0x70,0x00};
|
|
|
+
|
|
|
+
|
|
|
+const uint8_t ucSmallFont[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x45,0x51,0x45,0x3e,0x00,0x3e,0x6b,0x6f,
|
|
|
+ 0x6b,0x3e,0x00,0x1c,0x3e,0x7c,0x3e,0x1c,0x00,0x18,0x3c,0x7e,0x3c,0x18,0x00,0x30,
|
|
|
+ 0x36,0x7f,0x36,0x30,0x00,0x18,0x5c,0x7e,0x5c,0x18,0x00,0x00,0x18,0x18,0x00,0x00,
|
|
|
+ 0x00,0xff,0xe7,0xe7,0xff,0xff,0x00,0x3c,0x24,0x24,0x3c,0x00,0x00,0xc3,0xdb,0xdb,
|
|
|
+ 0xc3,0xff,0x00,0x30,0x48,0x4a,0x36,0x0e,0x00,0x06,0x29,0x79,0x29,0x06,0x00,0x60,
|
|
|
+ 0x70,0x3f,0x02,0x04,0x00,0x60,0x7e,0x0a,0x35,0x3f,0x00,0x2a,0x1c,0x36,0x1c,0x2a,
|
|
|
+ 0x00,0x00,0x7f,0x3e,0x1c,0x08,0x00,0x08,0x1c,0x3e,0x7f,0x00,0x00,0x14,0x36,0x7f,
|
|
|
+ 0x36,0x14,0x00,0x00,0x5f,0x00,0x5f,0x00,0x00,0x06,0x09,0x7f,0x01,0x7f,0x00,0x22,
|
|
|
+ 0x4d,0x55,0x59,0x22,0x00,0x60,0x60,0x60,0x60,0x00,0x00,0x14,0xb6,0xff,0xb6,0x14,
|
|
|
+ 0x00,0x04,0x06,0x7f,0x06,0x04,0x00,0x10,0x30,0x7f,0x30,0x10,0x00,0x08,0x08,0x3e,
|
|
|
+ 0x1c,0x08,0x00,0x08,0x1c,0x3e,0x08,0x08,0x00,0x78,0x40,0x40,0x40,0x40,0x00,0x08,
|
|
|
+ 0x3e,0x08,0x3e,0x08,0x00,0x30,0x3c,0x3f,0x3c,0x30,0x00,0x03,0x0f,0x3f,0x0f,0x03,
|
|
|
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x5f,0x06,0x00,0x00,0x07,0x03,0x00,
|
|
|
+ 0x07,0x03,0x00,0x24,0x7e,0x24,0x7e,0x24,0x00,0x24,0x2b,0x6a,0x12,0x00,0x00,0x63,
|
|
|
+ 0x13,0x08,0x64,0x63,0x00,0x36,0x49,0x56,0x20,0x50,0x00,0x00,0x07,0x03,0x00,0x00,
|
|
|
+ 0x00,0x00,0x3e,0x41,0x00,0x00,0x00,0x00,0x41,0x3e,0x00,0x00,0x00,0x08,0x3e,0x1c,
|
|
|
+ 0x3e,0x08,0x00,0x08,0x08,0x3e,0x08,0x08,0x00,0x00,0xe0,0x60,0x00,0x00,0x00,0x08,
|
|
|
+ 0x08,0x08,0x08,0x08,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,
|
|
|
+ 0x00,0x3e,0x51,0x49,0x45,0x3e,0x00,0x00,0x42,0x7f,0x40,0x00,0x00,0x62,0x51,0x49,
|
|
|
+ 0x49,0x46,0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x18,0x14,0x12,0x7f,0x10,0x00,0x2f,
|
|
|
+ 0x49,0x49,0x49,0x31,0x00,0x3c,0x4a,0x49,0x49,0x30,0x00,0x01,0x71,0x09,0x05,0x03,
|
|
|
+ 0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x06,0x49,0x49,0x29,0x1e,0x00,0x00,0x6c,0x6c,
|
|
|
+ 0x00,0x00,0x00,0x00,0xec,0x6c,0x00,0x00,0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x24,
|
|
|
+ 0x24,0x24,0x24,0x24,0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x02,0x01,0x59,0x09,0x06,
|
|
|
+ 0x00,0x3e,0x41,0x5d,0x55,0x1e,0x00,0x7e,0x11,0x11,0x11,0x7e,0x00,0x7f,0x49,0x49,
|
|
|
+ 0x49,0x36,0x00,0x3e,0x41,0x41,0x41,0x22,0x00,0x7f,0x41,0x41,0x41,0x3e,0x00,0x7f,
|
|
|
+ 0x49,0x49,0x49,0x41,0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x3e,0x41,0x49,0x49,0x7a,
|
|
|
+ 0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,0x41,0x7f,0x41,0x00,0x00,0x30,0x40,0x40,
|
|
|
+ 0x40,0x3f,0x00,0x7f,0x08,0x14,0x22,0x41,0x00,0x7f,0x40,0x40,0x40,0x40,0x00,0x7f,
|
|
|
+ 0x02,0x04,0x02,0x7f,0x00,0x7f,0x02,0x04,0x08,0x7f,0x00,0x3e,0x41,0x41,0x41,0x3e,
|
|
|
+ 0x00,0x7f,0x09,0x09,0x09,0x06,0x00,0x3e,0x41,0x51,0x21,0x5e,0x00,0x7f,0x09,0x09,
|
|
|
+ 0x19,0x66,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x01,0x01,0x7f,0x01,0x01,0x00,0x3f,
|
|
|
+ 0x40,0x40,0x40,0x3f,0x00,0x1f,0x20,0x40,0x20,0x1f,0x00,0x3f,0x40,0x3c,0x40,0x3f,
|
|
|
+ 0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x71,0x49,0x45,
|
|
|
+ 0x43,0x00,0x00,0x00,0x7f,0x41,0x41,0x00,0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00,
|
|
|
+ 0x41,0x41,0x7f,0x00,0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x80,0x80,0x80,0x80,0x80,
|
|
|
+ 0x00,0x00,0x03,0x07,0x00,0x00,0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x7f,0x44,0x44,
|
|
|
+ 0x44,0x38,0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x38,0x44,0x44,0x44,0x7f,0x00,0x38,
|
|
|
+ 0x54,0x54,0x54,0x08,0x00,0x08,0x7e,0x09,0x09,0x00,0x00,0x18,0xa4,0xa4,0xa4,0x7c,
|
|
|
+ 0x00,0x7f,0x04,0x04,0x78,0x00,0x00,0x00,0x00,0x7d,0x40,0x00,0x00,0x40,0x80,0x84,
|
|
|
+ 0x7d,0x00,0x00,0x7f,0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x7f,0x40,0x00,0x00,0x7c,
|
|
|
+ 0x04,0x18,0x04,0x78,0x00,0x7c,0x04,0x04,0x78,0x00,0x00,0x38,0x44,0x44,0x44,0x38,
|
|
|
+ 0x00,0xfc,0x44,0x44,0x44,0x38,0x00,0x38,0x44,0x44,0x44,0xfc,0x00,0x44,0x78,0x44,
|
|
|
+ 0x04,0x08,0x00,0x08,0x54,0x54,0x54,0x20,0x00,0x04,0x3e,0x44,0x24,0x00,0x00,0x3c,
|
|
|
+ 0x40,0x20,0x7c,0x00,0x00,0x1c,0x20,0x40,0x20,0x1c,0x00,0x3c,0x60,0x30,0x60,0x3c,
|
|
|
+ 0x00,0x6c,0x10,0x10,0x6c,0x00,0x00,0x9c,0xa0,0x60,0x3c,0x00,0x00,0x64,0x54,0x54,
|
|
|
+ 0x4c,0x00,0x00,0x08,0x3e,0x41,0x41,0x00,0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00,
|
|
|
+ 0x41,0x41,0x3e,0x08,0x00,0x02,0x01,0x02,0x01,0x00,0x00,0x3c,0x26,0x23,0x26,0x3c};
|
|
|
+
|
|
|
+static uint8_t iNumControllers, iCSPin;
|
|
|
+static int file_spi = -1;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSendSequence(uint8_t *pSequence, uint8_t len)
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ AIOWriteGPIO(iCSPin, 0);
|
|
|
+ AIOWriteSPI(file_spi, pSequence, len);
|
|
|
+ AIOWriteGPIO(iCSPin, 1);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxPowerUp(uint8_t bPowerUp)
|
|
|
+{
|
|
|
+uint8_t i;
|
|
|
+uint8_t *d, bTemp[32];
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = 0x0C;
|
|
|
+ *d++ = bPowerUp;
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSetIntensity(uint8_t bIntensity)
|
|
|
+{
|
|
|
+uint8_t *d, bTemp[32];
|
|
|
+uint8_t i;
|
|
|
+
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = 0x0A;
|
|
|
+ *d++ = bIntensity;
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSetSegmentMode(uint8_t bMode)
|
|
|
+{
|
|
|
+uint8_t i, *d, bTemp[32];
|
|
|
+
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = 0x09;
|
|
|
+ *d++ = (bMode) ? 0xff : 0x00;
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+}
|
|
|
+
|
|
|
+static unsigned char lookup[16] = {
|
|
|
+0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
|
|
|
+0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf, };
|
|
|
+
|
|
|
+uint8_t reverse(uint8_t n) {
|
|
|
+
|
|
|
+ return (lookup[n&0b1111] << 4) | lookup[n>>4];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSendImage(uint8_t *pImage, int iPitch, uint8_t rotated)
|
|
|
+{
|
|
|
+uint8_t i, j;
|
|
|
+uint8_t *s, *d, bTemp[32];
|
|
|
+ if(rotated) {
|
|
|
+ for (j=0; j<8; j++)
|
|
|
+ {
|
|
|
+ s = &pImage[iPitch * (j+1) - 1];
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = (8-j);
|
|
|
+ *d++ = reverse(*s--);
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (j=0; j<8; j++)
|
|
|
+ {
|
|
|
+ s = &pImage[iPitch * j];
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = (j+1);
|
|
|
+ *d++ = *s++;
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSetTestMode(uint8_t bOn)
|
|
|
+{
|
|
|
+uint8_t i, *d, bTemp[32];
|
|
|
+
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = 0x0F;
|
|
|
+ *d++ = bOn;
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSetLimit(uint8_t bLimit)
|
|
|
+{
|
|
|
+uint8_t i, *d, bTemp[32];
|
|
|
+
|
|
|
+ d = bTemp;
|
|
|
+ for (i=0; i<iNumControllers; i++)
|
|
|
+ {
|
|
|
+ *d++ = 0x0B;
|
|
|
+ *d++ = (bLimit - 1);
|
|
|
+ }
|
|
|
+ maxSendSequence(bTemp, iNumControllers * 2);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxSegmentString(char *pString)
|
|
|
+{
|
|
|
+unsigned char ucTemp[4];
|
|
|
+int iDigit;
|
|
|
+
|
|
|
+ memset(ucTemp, 0, sizeof(ucTemp));
|
|
|
+ iDigit = 0;
|
|
|
+ while (*pString && iDigit < 8)
|
|
|
+ {
|
|
|
+ ucTemp[0] = 8 - (iDigit & 7);
|
|
|
+ if (pString[0] >= '0' && pString[0] <= '9')
|
|
|
+ {
|
|
|
+ ucTemp[1] = *pString++;
|
|
|
+ if (pString[0] == '.')
|
|
|
+ {
|
|
|
+ ucTemp[1] |= 0x80;
|
|
|
+ pString++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ucTemp[1] = 0xf;
|
|
|
+ pString++;
|
|
|
+ }
|
|
|
+ iDigit++;
|
|
|
+ maxSendSequence(ucTemp, 2);
|
|
|
+ }
|
|
|
+ while (iDigit < 8)
|
|
|
+ {
|
|
|
+ ucTemp[0] = 8 - (iDigit & 7);
|
|
|
+ ucTemp[1] = 0xf;
|
|
|
+ iDigit++;
|
|
|
+ maxSendSequence(ucTemp, 2);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxDrawString(char *pString, uint8_t *pImage, uint8_t iPitch, uint8_t bSmall)
|
|
|
+{
|
|
|
+uint8_t b, bMask, i, j, *d, bCol;
|
|
|
+const uint8_t *pFont;
|
|
|
+const uint8_t *s;
|
|
|
+int iWidth;
|
|
|
+
|
|
|
+ d = pImage;
|
|
|
+ bCol = 0;
|
|
|
+ if (bSmall)
|
|
|
+ {
|
|
|
+ pFont = ucSmallFont;
|
|
|
+ iWidth = 6;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pFont = ucFont;
|
|
|
+ iWidth = 8;
|
|
|
+ }
|
|
|
+ while (*pString)
|
|
|
+ {
|
|
|
+ b = *pString++;
|
|
|
+ s = &pFont[(int)b * iWidth];
|
|
|
+ for (i=0; i<iWidth; i++)
|
|
|
+ {
|
|
|
+ bMask = (0x80 >> (bCol & 7));
|
|
|
+ b = *s++;
|
|
|
+ for (j=0; j<8; j++)
|
|
|
+ {
|
|
|
+ if (b & 1)
|
|
|
+ d[j*iPitch] |= bMask;
|
|
|
+ else
|
|
|
+ d[j*iPitch] &= ~bMask;
|
|
|
+ b >>= 1;
|
|
|
+ }
|
|
|
+ bCol++;
|
|
|
+ if ((bCol & 7) == 0)
|
|
|
+ d++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void maxScrollBitmap(uint8_t *pBitmap, int iPitch, int iScroll)
|
|
|
+{
|
|
|
+uint8_t b, bEdge, *s;
|
|
|
+int col, row;
|
|
|
+
|
|
|
+ if (iScroll > 0)
|
|
|
+ {
|
|
|
+ for (row=0; row<8; row++)
|
|
|
+ {
|
|
|
+ s = &pBitmap[row * iPitch];
|
|
|
+ bEdge = s[0] >> (8-iScroll);
|
|
|
+ for (col=0; col<iPitch; col++)
|
|
|
+ {
|
|
|
+ b = s[col] << iScroll;
|
|
|
+ b |= (col == iPitch-1) ? bEdge : (s[col+1] >> (8-iScroll));
|
|
|
+ s[col] = b;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ iScroll = 0 - iScroll;
|
|
|
+ for (row=0; row<8; row++)
|
|
|
+ {
|
|
|
+ s = &pBitmap[row * iPitch];
|
|
|
+ bEdge = s[iPitch-1] << (8-iScroll);
|
|
|
+ for (col=iPitch-1; col>=0; col--)
|
|
|
+ {
|
|
|
+ b = s[col] >> iScroll;
|
|
|
+ b |= (col == 0) ? bEdge : (s[col-1] << (8-iScroll));
|
|
|
+ s[col] = b;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int maxInit(uint8_t iNum, uint8_t bDecodeMode, uint8_t iChannel, uint8_t iSelect)
|
|
|
+{
|
|
|
+
|
|
|
+ if (!AIOInit())
|
|
|
+ {
|
|
|
+ fprintf(stderr, "Error initializing ArmbianIO library\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ iNumControllers = iNum;
|
|
|
+ iCSPin = iSelect;
|
|
|
+ file_spi = AIOOpenSPI(iChannel, 2000000);
|
|
|
+ if (file_spi == -1)
|
|
|
+ {
|
|
|
+ fprintf(stderr, "Failed to open the SPI bus\n");
|
|
|
+ file_spi = -1;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ AIOAddGPIO(iCSPin, GPIO_OUT);
|
|
|
+ AIOWriteGPIO(iCSPin, 1);
|
|
|
+
|
|
|
+ maxPowerUp(1);
|
|
|
+ maxSetLimit(8);
|
|
|
+ maxSetIntensity(0);
|
|
|
+ maxSetSegmentMode(bDecodeMode);
|
|
|
+ maxSetTestMode(0);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+void maxShutdown(void)
|
|
|
+{
|
|
|
+ maxPowerUp(0);
|
|
|
+ AIOCloseSPI(file_spi);
|
|
|
+ file_spi = -1;
|
|
|
+ AIOShutdown();
|
|
|
+}
|