Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
9a322b36f9 | |||
1cdfc0dd46 | |||
1eb92e4ac2 | |||
1466d7d7b7 | |||
f5d468ca75 | |||
|
572ac11d4e | ||
|
67cfe20124 | ||
09a8a38509 | |||
403899797e | |||
|
3888af0897 | ||
|
13caa9be2d | ||
68b68612bc | |||
db9acf73c7 | |||
b35fba020b | |||
0ed69f882b | |||
dd1b47ccef | |||
173b14e9c6 | |||
5365ee21d4 | |||
1a95acae24 | |||
|
a26ce94b70 | ||
581539ae81 | |||
c1a88864f6 | |||
85a9222ec2 | |||
4e6849a9c5 | |||
de0027b97d | |||
4addb8c974 | |||
c9cc2e7876 | |||
7cb77f2a68 | |||
a954f4749e | |||
5c445ac79f | |||
d3e4d2229e | |||
b9b5e40dd3 | |||
4c5aad63e2 | |||
f5e85192fd | |||
e3157ff9cb | |||
2a886045f6 | |||
31def3b096 | |||
4d08cdd37f | |||
af86d55583 | |||
3ca2af459e | |||
3c737ffaa8 | |||
9cd2d3d614 | |||
7476dcd4c4 | |||
3c43db92f6 | |||
04bfd6622c | |||
46e64840df | |||
b26149cfe2 | |||
5a59d32dc3 | |||
57a0245774 | |||
ae60699c7c | |||
bc8b59a1d5 | |||
b6db95ab78 |
@ -1,13 +0,0 @@
|
|||||||
#include "head_oled_i2c.h"
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
initialization();
|
|
||||||
Fill(255);
|
|
||||||
update();
|
|
||||||
Fill(0);
|
|
||||||
DrawCircle(50, 30, 20, 1, 0);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
}
|
|
211
protocol.md
Normal file
211
protocol.md
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
# Передача команды и параметров по шине SPI
|
||||||
|
|
||||||
|
При передаче пакета
|
||||||
|
1) Byte команды.
|
||||||
|
2) Byte[] массив параметров.
|
||||||
|
3) Byte контрольной суммы.
|
||||||
|
|
||||||
|
# Команды:
|
||||||
|
|
||||||
|
Условные обозначения:
|
||||||
|
|Обозначение|Описание|
|
||||||
|
|:-:|-|
|
||||||
|
|\||ИЛИ (значение слева или значение справа)|
|
||||||
|
|a<sub>1</sub>, a<sub>2</sub> , ..., a<sub>n</sub>|Диапазон (одно значение из диапазона)|
|
||||||
|
|\[...]|Несколько подобных значений|
|
||||||
|
|СxRC|Байт контрольной суммы|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Заполнение экрана белым или черным цветом
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x01
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Color|
|
||||||
|
|-|
|
||||||
|
|0x00\|0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x00|Заполнить экран черными пикселями|0x01 0x00 CxRC|
|
||||||
|
|0x01|Заполнить экран белыми пикселями|0x01 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Выбор строки на экране
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x02
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Page|
|
||||||
|
|-|
|
||||||
|
|0x00,0x01,...,0x07|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Page|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x03|Выбрать 3 строку|0x02 0x03 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Добавление нового символа
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x03
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Symbols|
|
||||||
|
|-|
|
||||||
|
|[0x01,0x02,...,0x16]|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Symbols|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x0e 0x10|Добавить символы 5 и 7|0x03 0x0e 0x10 CxRC|
|
||||||
|
|
||||||
|
**Описание:**
|
||||||
|
|
||||||
|
" " - 0x00
|
||||||
|
"(" - 0x01
|
||||||
|
")" - 0x02
|
||||||
|
"*" - 0x03
|
||||||
|
"+" - 0x04
|
||||||
|
"," - 0x05
|
||||||
|
"-" - 0x06
|
||||||
|
"." - 0x07
|
||||||
|
"/" - 0x08
|
||||||
|
"0" - 0x09
|
||||||
|
"1" - 0x0a
|
||||||
|
"2" - 0x0b
|
||||||
|
"3" - 0x0c
|
||||||
|
"4" - 0x0d
|
||||||
|
"5" - 0x0e
|
||||||
|
"6" - 0x0f
|
||||||
|
"7" - 0x10
|
||||||
|
"8" - 0x11
|
||||||
|
"9" - 0x12
|
||||||
|
":" - 0x13
|
||||||
|
"<" - 0x14
|
||||||
|
"=" - 0x15
|
||||||
|
">" - 0x16
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Удаление символов
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x04
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Amount|
|
||||||
|
|-|
|
||||||
|
|0x01,0x02,...,0xFF|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Amount|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x40|Удалить 64 символа|0x04 0x40 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Поставить пиксель белого или черного цвета по координатах
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x05
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|Color|
|
||||||
|
|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|
|
||||||
|
|0x24|0x04|0x01|Поставить белый пиксель в координатах x-36; y-4|0x05 0x24 0x04 0x01 CxRC|
|
||||||
|
|0x0B|0x16|0x00|Поставить черный пиксель в координатах x-11; y-22|0x05 0x0B 0x16 0x00 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать линию по координатам, белого или черного цвета
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x06
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|X2|Y2|Color|
|
||||||
|
|-|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|X2|Y2|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|-|
|
||||||
|
|0x02|0x02|0x05|0x05|0x01|Нарисовать линию белого цвета в координатах: начало x-2 , y-2; конец x-5, y-5 |0x06 0x02 0x02 0x05 0x05 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать круг белого или черного цвета по координатам и радиусу
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x07
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|R|Color|Fill|
|
||||||
|
|-|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x01,0x02,...,0xFF| 0x00 \| 0x01| 0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|R|Color|Fill|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|-|
|
||||||
|
|0x03|0x09|0x05|0x01|0x01|Нарисовать заполненный белый круг c координатами центра x-3, y-9 и радиусом 5|0x07 0x03 0x09 0x05 0x01 0x01 CxRC
|
||||||
|
|0x03|0x09|0x05|0x01|0x00|Нарисовать не заполненный белый круг c координатами центра x-3, y-9 и радиусом 5|0x07 0x03 0x09 0x05 0x01 0x00 CxRC|
|
||||||
|
|0x03|0x09|0x05|0x00|0x01|Нарисовать заполненный черный круг c координатами центра x-3, y-9 и радиусом 5|0x07 0x03 0x09 0x05 0x00 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать прямоугольник белого или черного цвета по координатам
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x08
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|Widht|Height|Color|Fill|
|
||||||
|
|-|-|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00,0x01, … ,0x10| 0x00 \| 0x01| 0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|Widht|Height|Color|Fill|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|-|-|
|
||||||
|
|0x05|0x0A|0x0A|0x0F|0x01|0x01|Нарисовать белый заполненный прямоугольник c координатами x-5, y-10 и размерами по ширине 10, по высоте 15 |0x05 0x0A 0x0A 0x07 0x01 0x01 CxRC|
|
||||||
|
|0x05|0x0A|0x0A|0x0F|0x01|0x00|Нарисовать белый не заполненный прямоугольник c координатами x-5, y-10 и размерами по ширине 10, по высоте 15 |0x05 0x0A 0x0A 0x07 0x01 0x00 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать символ по координатам
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x09
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|Charlndex|Color|
|
||||||
|
|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00,0x01, … ,0x16| 0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|Charlndex|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|
|
||||||
|
|0x05|0x0A|0x09|0x01|Нарисовать "0" белого цвета c координатами верхнего левого угла символа x-5, y-10|0x09 0x05 0x0A 0x09 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
159
slave/SPISlave.c
Normal file
159
slave/SPISlave.c
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
#include <avr/io.h>
|
||||||
|
#include "SPISlave.h"
|
||||||
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
|
static int index = 0;
|
||||||
|
static int arIndex = 0;
|
||||||
|
static char data[255];
|
||||||
|
|
||||||
|
void SPI_SlaveInit(void)
|
||||||
|
{
|
||||||
|
DDR_SPI = (1 << DD_MISO);
|
||||||
|
SPCR = (1 << SPE) | (1 << SPIE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCommand(char *data2, int length){
|
||||||
|
char command = data2[0];
|
||||||
|
// Отрезать 1 элемент от оставшихся
|
||||||
|
switch (command){
|
||||||
|
case 1:
|
||||||
|
AllClearCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
SetPageCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
AddSymbolCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
DelSymbolCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
DrawPixelCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
DrawLineCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
DrawCircleCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
DrawRectangleCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
DrawCharCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 1
|
||||||
|
void AllClearCommand(char *symbols, int lenght){
|
||||||
|
int param = symbols[0];
|
||||||
|
if (param == 0){
|
||||||
|
Fill(0);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Fill(255);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
ClearPages();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 2
|
||||||
|
void SetPageCommand(char *symbols, int lenght){
|
||||||
|
SetPage(symbols[0]);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 3
|
||||||
|
void AddSymbolCommand(char *symbols, int lenght) {
|
||||||
|
for (int i = 0; i < lenght - 1; i++) {
|
||||||
|
AddSymbol(symbols[i]);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 4
|
||||||
|
void DelSymbolCommand(char *symbols, int lenght) {
|
||||||
|
for (int i = 0; i < symbols[0]; i++) {
|
||||||
|
DelSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 5
|
||||||
|
void DrawPixelCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int color = symbols[2];
|
||||||
|
|
||||||
|
DrawPixel(x, y, color);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 6
|
||||||
|
void DrawLineCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int x1 = symbols[2];
|
||||||
|
int y1 = symbols[3];
|
||||||
|
int color = symbols[4];
|
||||||
|
|
||||||
|
DrawLine(x, y, x1, y1, color);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 7
|
||||||
|
void DrawCircleCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int r = symbols[2];
|
||||||
|
// white on black color=1, fill=0
|
||||||
|
int color = symbols[3];
|
||||||
|
int fill = symbols[4];
|
||||||
|
|
||||||
|
DrawCircle(x, y, r, color, fill);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 8
|
||||||
|
void DrawRectangleCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int width = symbols[2];
|
||||||
|
int height = symbols[3];
|
||||||
|
// white on black color=1, fill=0
|
||||||
|
int color = symbols[4];
|
||||||
|
int fill = symbols[5];
|
||||||
|
DrawRect(x, y, width, height, color, fill);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 9
|
||||||
|
void DrawCharCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int charIndex = symbols[2];
|
||||||
|
int fill = symbols[3];
|
||||||
|
// white on black color=1, fill=0
|
||||||
|
|
||||||
|
DrawChar(x, y, charIndex, fill);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
char crc8(char *data, int len) {
|
||||||
|
char crc = 0x00;
|
||||||
|
while (len--) {
|
||||||
|
crc ^= *data++;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if (crc & 0x80) {
|
||||||
|
crc = (crc << 1) ^ 0x07;
|
||||||
|
} else {
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
35
slave/SPISlave.h
Normal file
35
slave/SPISlave.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SPISlave_H
|
||||||
|
#define SPISlave_H
|
||||||
|
|
||||||
|
#define DDR_SPI DDRB
|
||||||
|
#define DD_MOSI PB3
|
||||||
|
#define DD_MISO PB4
|
||||||
|
#define DD_SCK PB5
|
||||||
|
#define DD_SS PB2
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void SPI_SlaveInit(void);
|
||||||
|
|
||||||
|
void SetCommand(char *data2, int length);
|
||||||
|
|
||||||
|
void AllClearCommand(char *symbols, int lenght);
|
||||||
|
void SetPageCommand(char *symbols, int lenght);
|
||||||
|
void AddSymbolCommand(char *symbols, int lenght);
|
||||||
|
void DelSymbolCommand(char *symbols, int lenght);
|
||||||
|
void DrawPixelCommand(char *symbols, int lenght);
|
||||||
|
void DrawLineCommand(char *symbols, int lenght);
|
||||||
|
void DrawCircleCommand(char *symbols, int lenght);
|
||||||
|
void DrawRectangleCommand(char *symbols, int lenght);
|
||||||
|
void DrawCharCommand(char *symbols, int lenght);
|
||||||
|
|
||||||
|
char crc8(char *data, int len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -70,6 +70,12 @@ void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t f
|
|||||||
void Fill(uint8_t fill);
|
void Fill(uint8_t fill);
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
void DrawChar(uint8_t x, uint8_t y, uint8_t charIndex, uint8_t fill);
|
||||||
|
void ClearPages();
|
||||||
|
void AddSymbol(uint8_t symbol);
|
||||||
|
void DelSymbol();
|
||||||
|
void SetPage(uint8_t p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
@ -238,3 +238,81 @@ void update() {
|
|||||||
for (int i = 0; i < OLED_BUFSIZE; i++) sendByte(_oled_buffer[i]);
|
for (int i = 0; i < OLED_BUFSIZE; i++) sendByte(_oled_buffer[i]);
|
||||||
endTransm();
|
endTransm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint8_t _charMap[][5] = {
|
||||||
|
{0x00, 0x00, 0x00, 0x00, 0x00}, // 0x00 32
|
||||||
|
{0x00, 0x1c, 0x22, 0x41, 0x00}, // ( 0x01 33
|
||||||
|
{0x00, 0x41, 0x22, 0x1c, 0x00}, // ) 0x02 34
|
||||||
|
{0x14, 0x08, 0x3e, 0x08, 0x14}, // * 0x03 35
|
||||||
|
{0x08, 0x08, 0x3e, 0x08, 0x08}, // + 0x04 36
|
||||||
|
{0x00, 0x50, 0x30, 0x00, 0x00}, // , 0x05 37
|
||||||
|
{0x08, 0x08, 0x08, 0x08, 0x08}, // - 0x06 38
|
||||||
|
{0x00, 0x60, 0x60, 0x00, 0x00}, // . 0x07 39
|
||||||
|
{0x20, 0x10, 0x08, 0x04, 0x02}, // / 0x08 40
|
||||||
|
{0x3e, 0x51, 0x49, 0x45, 0x3e}, // 0 0x09 41
|
||||||
|
{0x00, 0x42, 0x7f, 0x40, 0x00}, // 1 0x0a 42
|
||||||
|
{0x42, 0x61, 0x51, 0x49, 0x46}, // 2 0x0b 43
|
||||||
|
{0x21, 0x41, 0x45, 0x4b, 0x31}, // 3 0x0c 44
|
||||||
|
{0x18, 0x14, 0x12, 0x7f, 0x10}, // 4 0x0d 45
|
||||||
|
{0x27, 0x45, 0x45, 0x45, 0x39}, // 5 0x0e 46
|
||||||
|
{0x3c, 0x4a, 0x49, 0x49, 0x30}, // 6 0x0f 47
|
||||||
|
{0x01, 0x71, 0x09, 0x05, 0x03}, // 7 0x10 48
|
||||||
|
{0x36, 0x49, 0x49, 0x49, 0x36}, // 8 0x11 49
|
||||||
|
{0x06, 0x49, 0x49, 0x29, 0x1e}, // 9 0x12 50
|
||||||
|
{0x00, 0x36, 0x36, 0x00, 0x00}, // : 0x13 51
|
||||||
|
{0x08, 0x14, 0x22, 0x41, 0x00}, // < 0x14 52
|
||||||
|
{0x14, 0x14, 0x14, 0x14, 0x14}, // = 0x15 53
|
||||||
|
{0x00, 0x41, 0x22, 0x14, 0x08}, // > 0x16 54
|
||||||
|
};
|
||||||
|
|
||||||
|
void DrawChar(uint8_t x, uint8_t y, uint8_t charIndex, uint8_t fill) {
|
||||||
|
// Проверяем, что индекс символа находится в допустимых пределах
|
||||||
|
if (charIndex >= sizeof(_charMap) / sizeof(_charMap[0])) {
|
||||||
|
return; // Символ не найден
|
||||||
|
}
|
||||||
|
|
||||||
|
// Рисуем символ пиксель за пикселем
|
||||||
|
for (uint8_t col = 0; col < 5; col++) {
|
||||||
|
uint8_t columnData = _charMap[charIndex][col];
|
||||||
|
|
||||||
|
for (uint8_t row = 0; row < 8; row++) {
|
||||||
|
if (columnData & (1 << row)) {
|
||||||
|
DrawPixel(x + col, y + row, fill);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t page = 0;
|
||||||
|
uint8_t amountByteInPage[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
|
void SetPage(uint8_t p){
|
||||||
|
page = p;
|
||||||
|
if (p < 0) page = 0;
|
||||||
|
if (p > 8) page = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearPages(){
|
||||||
|
for (uint8_t row = 0; row < 8; row++) {
|
||||||
|
amountByteInPage[row] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddSymbol(uint8_t symbol){
|
||||||
|
if (amountByteInPage[page] + 5 < 128){
|
||||||
|
DrawChar(amountByteInPage[page],page*8,symbol,1);
|
||||||
|
amountByteInPage[page] += 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the last symbol from the display buffer
|
||||||
|
void DelSymbol(){
|
||||||
|
if (amountByteInPage[page] - 6 <= 0){
|
||||||
|
amountByteInPage[page] = 0;
|
||||||
|
DrawRect(amountByteInPage[page],page*8,127,8,0,1);
|
||||||
|
}else{
|
||||||
|
amountByteInPage[page] -= 6;
|
||||||
|
DrawRect(amountByteInPage[page],page*8,6,8,0,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
42
slave/slave.ino
Normal file
42
slave/slave.ino
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "SPISlave.h"
|
||||||
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
|
static int index = 0;
|
||||||
|
static int arIndex = 0;
|
||||||
|
static char data[64];
|
||||||
|
|
||||||
|
ISR(SPI_STC_vect)
|
||||||
|
{
|
||||||
|
char received = SPDR;
|
||||||
|
data[index] = received;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
SPI_SlaveInit();
|
||||||
|
initialization();
|
||||||
|
|
||||||
|
Fill(0);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if(PINB & (1 << 2)){
|
||||||
|
if(index > 0){
|
||||||
|
char sum = 0;
|
||||||
|
sum = crc8(data, index-1);
|
||||||
|
char last_1 = data[index - 1];
|
||||||
|
|
||||||
|
if (last_1 == sum){
|
||||||
|
SetCommand(data, index);
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user