Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
84c1d491da | |||
200455aa58 | |||
764677d761 | |||
928615bb5f | |||
94afaa30fb | |||
d19aaad727 | |||
36543140d0 | |||
ca1230d713 | |||
979a66a221 | |||
8d1374de00 |
13
Oled_I2C[1].ino
Normal file
13
Oled_I2C[1].ino
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
initialization();
|
||||||
|
Fill(255);
|
||||||
|
update();
|
||||||
|
Fill(0);
|
||||||
|
DrawCircle(50, 30, 20, 1, 0);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
}
|
@ -1,85 +1,79 @@
|
|||||||
#ifndef head_oled_i2c
|
#ifndef head_oled_i2c
|
||||||
#define head_oled_i2c
|
#define head_oled_i2c
|
||||||
|
|
||||||
#define OLED_HEIGHT_64 0x12
|
#define OLED_HEIGHT_64 0x12
|
||||||
#define OLED_64 0x3F
|
#define OLED_64 0x3F
|
||||||
|
|
||||||
#define OLED_DISPLAY_OFF 0xAE
|
#define OLED_DISPLAY_OFF 0xAE
|
||||||
#define OLED_DISPLAY_ON 0xAF
|
#define OLED_DISPLAY_ON 0xAF
|
||||||
|
|
||||||
#define OLED_COMMAND_MODE 0x00
|
#define OLED_COMMAND_MODE 0x00
|
||||||
#define OLED_ONE_COMMAND_MODE 0x80
|
#define OLED_ONE_COMMAND_MODE 0x80
|
||||||
#define OLED_DATA_MODE 0x40
|
#define OLED_DATA_MODE 0x40
|
||||||
|
|
||||||
#define OLED_ADDRESSING_MODE 0x20
|
#define OLED_ADDRESSING_MODE 0x20
|
||||||
#define OLED_VERTICAL 0x01
|
#define OLED_VERTICAL 0x01
|
||||||
|
|
||||||
#define OLED_NORMAL_V 0xC8
|
#define OLED_NORMAL_V 0xC8
|
||||||
#define OLED_NORMAL_H 0xA1
|
#define OLED_NORMAL_H 0xA1
|
||||||
|
|
||||||
#define OLED_CONTRAST 0x81
|
#define OLED_CONTRAST 0x81
|
||||||
#define OLED_SETCOMPINS 0xDA
|
#define OLED_SETCOMPINS 0xDA
|
||||||
#define OLED_SETVCOMDETECT 0xDB
|
#define OLED_SETVCOMDETECT 0xDB
|
||||||
#define OLED_CLOCKDIV 0xD5
|
#define OLED_CLOCKDIV 0xD5
|
||||||
#define OLED_SETMULTIPLEX 0xA8
|
#define OLED_SETMULTIPLEX 0xA8
|
||||||
#define OLED_COLUMNADDR 0x21
|
#define OLED_COLUMNADDR 0x21
|
||||||
#define OLED_PAGEADDR 0x22
|
#define OLED_PAGEADDR 0x22
|
||||||
#define OLED_CHARGEPUMP 0x8D
|
#define OLED_CHARGEPUMP 0x8D
|
||||||
|
|
||||||
#define OLED_NORMALDISPLAY 0xA6
|
#define OLED_NORMALDISPLAY 0xA6
|
||||||
|
|
||||||
#define OLED_BUFSIZE (128*64/8)
|
#define OLED_BUFSIZE (128*64/8)
|
||||||
|
|
||||||
#define OLED_MAX_X 127
|
#define OLED_MAX_X 127
|
||||||
#define OLED_MAX_Y 63
|
#define OLED_MAX_Y 63
|
||||||
#define OLED_MAX_ROW 7
|
#define OLED_MAX_ROW 7
|
||||||
|
|
||||||
#define OLED_ADDR 0x3C
|
#define OLED_ADDR 0x3C
|
||||||
#define OLED_I2C_FREQ 100000UL
|
#define OLED_I2C_FREQ 100000UL
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void i2c_begin(uint8_t address);
|
void i2c_begin(uint8_t address);
|
||||||
void i2c_endTransaction();
|
void i2c_endTransaction();
|
||||||
void i2c_beginTransmission(uint8_t address);
|
void i2c_beginTransmission(uint8_t address);
|
||||||
void i2c_write(uint8_t data);
|
void i2c_write(uint8_t data);
|
||||||
|
|
||||||
void endTransm();
|
void endTransm();
|
||||||
void sendByteRaw(uint8_t data);
|
void sendByteRaw(uint8_t data);
|
||||||
void startTransm();
|
void startTransm();
|
||||||
void beginData();
|
void beginData();
|
||||||
void sendByte(uint8_t data);
|
void sendByte(uint8_t data);
|
||||||
|
|
||||||
void sendCommand(uint8_t cmd1);
|
void sendCommand(uint8_t cmd1);
|
||||||
void sendCommandData(uint8_t cmd1, uint8_t cmd2);
|
void sendCommandData(uint8_t cmd1, uint8_t cmd2);
|
||||||
uint8_t constrainValue(uint8_t value, uint8_t min, uint8_t max);
|
uint8_t constrainValue(uint8_t value, uint8_t min, uint8_t max);
|
||||||
void setWindow(int x0, int y0, int x1, int y1);
|
void setWindow(int x0, int y0, int x1, int y1);
|
||||||
|
|
||||||
void beginCommand();
|
void beginCommand();
|
||||||
void beginOneCommand();
|
void beginOneCommand();
|
||||||
|
|
||||||
void initialization();
|
void initialization();
|
||||||
|
|
||||||
void setBit(uint8_t *value, uint8_t bitIndex, uint8_t bitValue);
|
void setBit(uint8_t *value, uint8_t bitIndex, uint8_t bitValue);
|
||||||
void DrawPixel(uint8_t x, uint8_t y, uint8_t fill);
|
void DrawPixel(uint8_t x, uint8_t y, uint8_t fill);
|
||||||
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
|
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
|
||||||
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t fill);
|
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t fill);
|
||||||
void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t fill);
|
void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t fill);
|
||||||
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);
|
#ifdef __cplusplus
|
||||||
void DelSymbol();
|
}
|
||||||
void SetPage(uint8_t p);
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,318 +1,240 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include "head_oled_i2c.h"
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
uint8_t _oled_buffer[OLED_BUFSIZE];
|
uint8_t _oled_buffer[OLED_BUFSIZE];
|
||||||
uint8_t _writes = 0;
|
uint8_t _writes = 0;
|
||||||
|
|
||||||
void i2c_begin(uint8_t address) {
|
void i2c_begin(uint8_t address) {
|
||||||
TWBR = ((F_CPU / OLED_I2C_FREQ) - 16) / 2;
|
TWBR = ((F_CPU / OLED_I2C_FREQ) - 16) / 2;
|
||||||
TWAR = (address << 1);
|
TWAR = (address << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_endTransaction() {
|
void i2c_endTransaction() {
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
|
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_beginTransmission(uint8_t address) {
|
void i2c_beginTransmission(uint8_t address) {
|
||||||
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
|
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
|
||||||
while (!(TWCR & (1 << TWINT)));
|
while (!(TWCR & (1 << TWINT)));
|
||||||
|
|
||||||
TWDR = (address << 1);
|
TWDR = (address << 1);
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN);
|
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||||
while (!(TWCR & (1 << TWINT)));
|
while (!(TWCR & (1 << TWINT)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_write(uint8_t data) {
|
void i2c_write(uint8_t data) {
|
||||||
TWDR = data; // Запись данных
|
TWDR = data; // Запись данных
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN);
|
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||||
while (!(TWCR & (1 << TWINT)));
|
while (!(TWCR & (1 << TWINT)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void endTransm() {
|
void endTransm() {
|
||||||
i2c_endTransaction();
|
i2c_endTransaction();
|
||||||
_writes = 0;
|
_writes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendByteRaw(uint8_t data) {
|
void sendByteRaw(uint8_t data) {
|
||||||
i2c_write(data);
|
i2c_write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startTransm() {
|
void startTransm() {
|
||||||
i2c_beginTransmission(OLED_ADDR);
|
i2c_beginTransmission(OLED_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginCommand() {
|
void beginCommand() {
|
||||||
startTransm();
|
startTransm();
|
||||||
sendByteRaw(OLED_COMMAND_MODE);
|
sendByteRaw(OLED_COMMAND_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginData() {
|
void beginData() {
|
||||||
startTransm();
|
startTransm();
|
||||||
sendByteRaw(OLED_DATA_MODE);
|
sendByteRaw(OLED_DATA_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendByte(uint8_t data) {
|
void sendByte(uint8_t data) {
|
||||||
sendByteRaw(data);
|
sendByteRaw(data);
|
||||||
_writes++;
|
_writes++;
|
||||||
if (_writes >= 16) {
|
if (_writes >= 16) {
|
||||||
endTransm();
|
endTransm();
|
||||||
beginData();
|
beginData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void beginOneCommand() {
|
void beginOneCommand() {
|
||||||
startTransm();
|
startTransm();
|
||||||
sendByteRaw(OLED_ONE_COMMAND_MODE);
|
sendByteRaw(OLED_ONE_COMMAND_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendCommand(uint8_t cmd1) {
|
void sendCommand(uint8_t cmd1) {
|
||||||
beginOneCommand();
|
beginOneCommand();
|
||||||
sendByteRaw(cmd1);
|
sendByteRaw(cmd1);
|
||||||
endTransm();
|
endTransm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendCommandData(uint8_t cmd1, uint8_t cmd2) {
|
void sendCommandData(uint8_t cmd1, uint8_t cmd2) {
|
||||||
beginCommand();
|
beginCommand();
|
||||||
sendByteRaw(cmd1);
|
sendByteRaw(cmd1);
|
||||||
sendByteRaw(cmd2);
|
sendByteRaw(cmd2);
|
||||||
endTransm();
|
endTransm();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t constrainValue(uint8_t value, uint8_t min, uint8_t max) {
|
uint8_t constrainValue(uint8_t value, uint8_t min, uint8_t max) {
|
||||||
if (value < min) {
|
if (value < min) {
|
||||||
return min;
|
return min;
|
||||||
} else if (value > max) {
|
} else if (value > max) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setWindow(int x0, int y0, int x1, int y1) {
|
void setWindow(int x0, int y0, int x1, int y1) {
|
||||||
beginCommand();
|
beginCommand();
|
||||||
sendByteRaw(OLED_COLUMNADDR);
|
sendByteRaw(OLED_COLUMNADDR);
|
||||||
sendByteRaw(constrainValue(x0, 0, OLED_MAX_X));
|
sendByteRaw(constrainValue(x0, 0, OLED_MAX_X));
|
||||||
sendByteRaw(constrainValue(x1, 0, OLED_MAX_X));
|
sendByteRaw(constrainValue(x1, 0, OLED_MAX_X));
|
||||||
sendByteRaw(OLED_PAGEADDR);
|
sendByteRaw(OLED_PAGEADDR);
|
||||||
sendByteRaw(constrainValue(y0, 0, OLED_MAX_ROW));
|
sendByteRaw(constrainValue(y0, 0, OLED_MAX_ROW));
|
||||||
sendByteRaw(constrainValue(y1, 0, OLED_MAX_ROW));
|
sendByteRaw(constrainValue(y1, 0, OLED_MAX_ROW));
|
||||||
endTransm();
|
endTransm();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialization() {
|
void initialization() {
|
||||||
i2c_begin(OLED_ADDR);
|
i2c_begin(OLED_ADDR);
|
||||||
|
|
||||||
beginCommand();
|
beginCommand();
|
||||||
sendByte(OLED_DISPLAY_OFF);
|
sendByte(OLED_DISPLAY_OFF);
|
||||||
sendByte(OLED_CLOCKDIV);
|
sendByte(OLED_CLOCKDIV);
|
||||||
sendByte(0x80);
|
sendByte(0x80);
|
||||||
sendByte(OLED_CHARGEPUMP);
|
sendByte(OLED_CHARGEPUMP);
|
||||||
sendByte(0x14);
|
sendByte(0x14);
|
||||||
sendByte(OLED_ADDRESSING_MODE);
|
sendByte(OLED_ADDRESSING_MODE);
|
||||||
sendByte(OLED_VERTICAL);
|
sendByte(OLED_VERTICAL);
|
||||||
sendByte(OLED_NORMAL_H);
|
sendByte(OLED_NORMAL_H);
|
||||||
sendByte(OLED_NORMAL_V);
|
sendByte(OLED_NORMAL_V);
|
||||||
sendByte(OLED_CONTRAST);
|
sendByte(OLED_CONTRAST);
|
||||||
sendByte(0x7F);
|
sendByte(0x7F);
|
||||||
sendByte(OLED_SETVCOMDETECT);
|
sendByte(OLED_SETVCOMDETECT);
|
||||||
sendByte(0x40);
|
sendByte(0x40);
|
||||||
sendByte(OLED_NORMALDISPLAY);
|
sendByte(OLED_NORMALDISPLAY);
|
||||||
sendByte(OLED_DISPLAY_ON);
|
sendByte(OLED_DISPLAY_ON);
|
||||||
endTransm();
|
endTransm();
|
||||||
|
|
||||||
beginCommand();
|
beginCommand();
|
||||||
sendByte(OLED_SETCOMPINS);
|
sendByte(OLED_SETCOMPINS);
|
||||||
sendByte(OLED_HEIGHT_64);
|
sendByte(OLED_HEIGHT_64);
|
||||||
sendByte(OLED_SETMULTIPLEX);
|
sendByte(OLED_SETMULTIPLEX);
|
||||||
sendByte(OLED_64);
|
sendByte(OLED_64);
|
||||||
endTransm();
|
endTransm();
|
||||||
|
|
||||||
setWindow(0, 0, OLED_MAX_X, OLED_MAX_ROW);
|
setWindow(0, 0, OLED_MAX_X, OLED_MAX_ROW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBit(uint8_t *value, uint8_t bitIndex, uint8_t bitValue) {
|
void setBit(uint8_t *value, uint8_t bitIndex, uint8_t bitValue) {
|
||||||
if (bitValue != 0) {
|
if (bitValue != 0) {
|
||||||
*value |= (1 << bitIndex);
|
*value |= (1 << bitIndex);
|
||||||
} else {
|
} else {
|
||||||
*value &= ~(1 << bitIndex);
|
*value &= ~(1 << bitIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawPixel(uint8_t x, uint8_t y, uint8_t fill) {
|
void DrawPixel(uint8_t x, uint8_t y, uint8_t fill) {
|
||||||
if (x < 0 || x > OLED_MAX_X || y < 0 || y > OLED_MAX_Y) return;
|
if (x < 0 || x > OLED_MAX_X || y < 0 || y > OLED_MAX_Y) return;
|
||||||
uint16_t _bufIndex = ((y) >> 3) + ((x) << (3));
|
uint16_t _bufIndex = ((y) >> 3) + ((x) << (3));
|
||||||
setBit(&_oled_buffer[_bufIndex], y & 0b111, fill);
|
setBit(&_oled_buffer[_bufIndex], y & 0b111, fill);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color) {
|
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color) {
|
||||||
uint8_t dx = abs(x2 - x1);
|
uint8_t dx = abs(x2 - x1);
|
||||||
uint8_t dy = abs(y2 - y1);
|
uint8_t dy = abs(y2 - y1);
|
||||||
uint8_t sx = x1 < x2 ? 1 : -1;
|
uint8_t sx = x1 < x2 ? 1 : -1;
|
||||||
uint8_t sy = y1 < y2 ? 1 : -1;
|
uint8_t sy = y1 < y2 ? 1 : -1;
|
||||||
uint8_t err = dx - dy;
|
uint8_t err = dx - dy;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
DrawPixel(x1, y1, color);
|
DrawPixel(x1, y1, color);
|
||||||
|
|
||||||
if (x1 == x2 && y1 == y2) break;
|
if (x1 == x2 && y1 == y2) break;
|
||||||
|
|
||||||
uint8_t e2 = 2 * err;
|
uint8_t e2 = 2 * err;
|
||||||
|
|
||||||
if (e2 > -dy) {
|
if (e2 > -dy) {
|
||||||
err -= dy;
|
err -= dy;
|
||||||
x1 += sx;
|
x1 += sx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e2 < dx) {
|
if (e2 < dx) {
|
||||||
err += dx;
|
err += dx;
|
||||||
y1 += sy;
|
y1 += sy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t fill) {
|
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t fill) {
|
||||||
if (fill) {
|
if (fill) {
|
||||||
for (uint8_t i = y; i < y + height; i++) {
|
for (uint8_t i = y; i < y + height; i++) {
|
||||||
DrawLine(x, i, x + width - 1, i, color);
|
DrawLine(x, i, x + width - 1, i, color);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t i = x; i < x + width; i++) {
|
for (uint8_t i = x; i < x + width; i++) {
|
||||||
DrawPixel(i, y, color);
|
DrawPixel(i, y, color);
|
||||||
DrawPixel(i, y + height - 1, color);
|
DrawPixel(i, y + height - 1, color);
|
||||||
}
|
}
|
||||||
for (uint8_t i = y; i < y + height; i++) {
|
for (uint8_t i = y; i < y + height; i++) {
|
||||||
DrawPixel(x, i, color);
|
DrawPixel(x, i, color);
|
||||||
DrawPixel(x + width - 1, i, color);
|
DrawPixel(x + width - 1, i, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t fill) {
|
void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t fill) {
|
||||||
int8_t x = radius;
|
int8_t x = radius;
|
||||||
int8_t y = 0;
|
int8_t y = 0;
|
||||||
int8_t err = 0;
|
int8_t err = 0;
|
||||||
|
|
||||||
while (x >= y) {
|
while (x >= y) {
|
||||||
if (fill) {
|
if (fill) {
|
||||||
for (int8_t i = x0 - x; i <= x0 + x; i++) {
|
for (int8_t i = x0 - x; i <= x0 + x; i++) {
|
||||||
DrawPixel(i, y0 + y, color);
|
DrawPixel(i, y0 + y, color);
|
||||||
DrawPixel(i, y0 - y, color);
|
DrawPixel(i, y0 - y, color);
|
||||||
}
|
}
|
||||||
for (int8_t i = x0 - y; i <= x0 + y; i++) {
|
for (int8_t i = x0 - y; i <= x0 + y; i++) {
|
||||||
DrawPixel(i, y0 + x, color);
|
DrawPixel(i, y0 + x, color);
|
||||||
DrawPixel(i, y0 - x, color);
|
DrawPixel(i, y0 - x, color);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawPixel(x0 + x, y0 + y, color);
|
DrawPixel(x0 + x, y0 + y, color);
|
||||||
DrawPixel(x0 - x, y0 + y, color);
|
DrawPixel(x0 - x, y0 + y, color);
|
||||||
DrawPixel(x0 + x, y0 - y, color);
|
DrawPixel(x0 + x, y0 - y, color);
|
||||||
DrawPixel(x0 - x, y0 - y, color);
|
DrawPixel(x0 - x, y0 - y, color);
|
||||||
DrawPixel(x0 + y, y0 + x, color);
|
DrawPixel(x0 + y, y0 + x, color);
|
||||||
DrawPixel(x0 - y, y0 + x, color);
|
DrawPixel(x0 - y, y0 + x, color);
|
||||||
DrawPixel(x0 + y, y0 - x, color);
|
DrawPixel(x0 + y, y0 - x, color);
|
||||||
DrawPixel(x0 - y, y0 - x, color);
|
DrawPixel(x0 - y, y0 - x, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
y++;
|
y++;
|
||||||
err += 1 + 2 * y;
|
err += 1 + 2 * y;
|
||||||
if (2 * (err - x) + 1 > 0) {
|
if (2 * (err - x) + 1 > 0) {
|
||||||
x--;
|
x--;
|
||||||
err += 1 - 2 * x;
|
err += 1 - 2 * x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Заполнить дисплей
|
// Заполнить дисплей
|
||||||
void Fill(uint8_t fill) {
|
void Fill(uint8_t fill) {
|
||||||
memset(_oled_buffer, fill, OLED_BUFSIZE);
|
memset(_oled_buffer, fill, OLED_BUFSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновить дисплей
|
// Обновить дисплей
|
||||||
void update() {
|
void update() {
|
||||||
setWindow(0, 0, OLED_MAX_X, OLED_MAX_ROW);
|
setWindow(0, 0, OLED_MAX_X, OLED_MAX_ROW);
|
||||||
beginData();
|
beginData();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
211
protocol.md
211
protocol.md
@ -1,211 +0,0 @@
|
|||||||
# Передача команды и параметров по шине 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
159
slave/SPISlave.c
@ -1,159 +0,0 @@
|
|||||||
#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;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
#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
|
|
@ -1,42 +0,0 @@
|
|||||||
#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