|
@@ -1,4 +1,3 @@
|
|
-/* vim: set ai et ts=4 sw=4: */
|
|
|
|
#include "ch.h"
|
|
#include "ch.h"
|
|
#include "hal.h"
|
|
#include "hal.h"
|
|
#include "malloc.h"
|
|
#include "malloc.h"
|
|
@@ -102,17 +101,58 @@ static void ST7735_Reset(void) {
|
|
//HAL_GPIO_WritePin(ST7735_RES_GPIO_Port, ST7735_RES_Pin, GPIO_PIN_SET);
|
|
//HAL_GPIO_WritePin(ST7735_RES_GPIO_Port, ST7735_RES_Pin, GPIO_PIN_SET);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Send command
|
|
|
|
+ *
|
|
|
|
+ * @param cmd command for display
|
|
|
|
+ */
|
|
static void ST7735_WriteCommand(uint8_t cmd) {
|
|
static void ST7735_WriteCommand(uint8_t cmd) {
|
|
LCD_DC_CMD;
|
|
LCD_DC_CMD;
|
|
- // !!! TODO: немає сенсу пересилати 1 байт за допомогою DMA. треба переробити
|
|
|
|
- spiSend(&ST7735_SPI_PORT, sizeof(cmd), &cmd);
|
|
|
|
|
|
+
|
|
|
|
+ // wite while spi is busy
|
|
|
|
+ while (!(SPI1->SR & SPI_SR_TXE));
|
|
|
|
+ // send data
|
|
|
|
+ SPI1->DR = cmd;
|
|
|
|
+ // wite for data to be transmitted
|
|
|
|
+ while (!(SPI1->SR & SPI_SR_TXE));
|
|
|
|
+ // ... and spi is busy
|
|
|
|
+ while ((SPI1->SR & SPI_SR_BSY));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Send 8-bit data using DMA
|
|
|
|
+ *
|
|
|
|
+ * @param buff data to be sended
|
|
|
|
+ * @param buff_size amount of bytes
|
|
|
|
+ */
|
|
static void ST7735_WriteData(uint8_t* buff, size_t buff_size) {
|
|
static void ST7735_WriteData(uint8_t* buff, size_t buff_size) {
|
|
LCD_DC_DATA;
|
|
LCD_DC_DATA;
|
|
spiSend(&ST7735_SPI_PORT, buff_size, buff);
|
|
spiSend(&ST7735_SPI_PORT, buff_size, buff);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Send 16-bit data trough reg
|
|
|
|
+ *
|
|
|
|
+ * @param data to send to display
|
|
|
|
+ */
|
|
|
|
+static void ST7735_WriteData16(uint16_t data) {
|
|
|
|
+ LCD_DC_DATA;
|
|
|
|
+ //spiSend(&ST7735_SPI_PORT, buff_size, buff);
|
|
|
|
+
|
|
|
|
+ // set 16-bit data
|
|
|
|
+ SPI1->CR1 |= SPI_CR1_DFF;
|
|
|
|
+ // wite while spi is busy
|
|
|
|
+ while (!(SPI1->SR & SPI_SR_TXE));
|
|
|
|
+ // send data
|
|
|
|
+ SPI1->DR = data;
|
|
|
|
+ // wite for data too be transmitted
|
|
|
|
+ while (!(SPI1->SR & SPI_SR_TXE));
|
|
|
|
+ // ... and spi is unbusy
|
|
|
|
+ while ((SPI1->SR & SPI_SR_BSY));
|
|
|
|
+ // set 8-bit data
|
|
|
|
+ SPI1->CR1 &= ~(SPI_CR1_DFF);
|
|
|
|
+}
|
|
|
|
+
|
|
static void ST7735_ExecuteCommandList(const uint8_t *addr) {
|
|
static void ST7735_ExecuteCommandList(const uint8_t *addr) {
|
|
uint8_t numCommands, numArgs;
|
|
uint8_t numCommands, numArgs;
|
|
uint16_t ms;
|
|
uint16_t ms;
|
|
@@ -157,7 +197,7 @@ static void ST7735_SetAddressWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t
|
|
ST7735_WriteCommand(ST7735_RAMWR);
|
|
ST7735_WriteCommand(ST7735_RAMWR);
|
|
}
|
|
}
|
|
|
|
|
|
-void ST7735_Init() {
|
|
|
|
|
|
+void ST7735_Init(void) {
|
|
ST7735_Select();
|
|
ST7735_Select();
|
|
ST7735_Reset();
|
|
ST7735_Reset();
|
|
ST7735_ExecuteCommandList(init_cmds1);
|
|
ST7735_ExecuteCommandList(init_cmds1);
|
|
@@ -166,18 +206,21 @@ void ST7735_Init() {
|
|
ST7735_Unselect();
|
|
ST7735_Unselect();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @brief Draw single pixel
|
|
|
|
+ *
|
|
|
|
+ * @param x coordinate
|
|
|
|
+ * @param y coordinate
|
|
|
|
+ * @param color pixel colour
|
|
|
|
+ */
|
|
void ST7735_DrawPixel(uint16_t x, uint16_t y, uint16_t color) {
|
|
void ST7735_DrawPixel(uint16_t x, uint16_t y, uint16_t color) {
|
|
if ((x >= ST7735_WIDTH) || (y >= ST7735_HEIGHT)) {
|
|
if ((x >= ST7735_WIDTH) || (y >= ST7735_HEIGHT)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
ST7735_Select();
|
|
ST7735_Select();
|
|
-
|
|
|
|
ST7735_SetAddressWindow(x, y, x+1, y+1);
|
|
ST7735_SetAddressWindow(x, y, x+1, y+1);
|
|
- uint8_t data[] = {color >> 8, color & 0xFF};
|
|
|
|
- // !!! TODO: тут пересилається 2 байти за допомогою DMA. треба переробити
|
|
|
|
- ST7735_WriteData(data, sizeof(data));
|
|
|
|
-
|
|
|
|
|
|
+ ST7735_WriteData16(color);
|
|
ST7735_Unselect();
|
|
ST7735_Unselect();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -189,16 +232,10 @@ static void ST7735_WriteChar(uint16_t x, uint16_t y, char ch, FontDef font, uint
|
|
for(i = 0; i < font.height; i++) {
|
|
for(i = 0; i < font.height; i++) {
|
|
b = font.data[(ch - 32) * font.height + i];
|
|
b = font.data[(ch - 32) * font.height + i];
|
|
for(j = 0; j < font.width; j++) {
|
|
for(j = 0; j < font.width; j++) {
|
|
- //unnecessary transformations
|
|
|
|
- //if ((b << j) & 0x8000) {
|
|
|
|
if (b & 0x8000) {
|
|
if (b & 0x8000) {
|
|
- uint8_t data[] = {color >> 8, color & 0xFF};
|
|
|
|
- // !!! TODO: тут пересилається 2 байти за допомогою DMA. треба переробити
|
|
|
|
- ST7735_WriteData(data, sizeof(data));
|
|
|
|
|
|
+ ST7735_WriteData16(color);
|
|
} else {
|
|
} else {
|
|
- uint8_t data[] = {bgcolor >> 8, bgcolor & 0xFF};
|
|
|
|
- // !!! TODO: тут пересилається 2 байти за допомогою DMA. треба переробити
|
|
|
|
- ST7735_WriteData(data, sizeof(data));
|
|
|
|
|
|
+ ST7735_WriteData16(bgcolor);
|
|
}
|
|
}
|
|
b <<= 1;
|
|
b <<= 1;
|
|
}
|
|
}
|
|
@@ -218,7 +255,7 @@ void ST7735_WriteString(uint16_t x, uint16_t y, const char* str, FontDef font, u
|
|
|
|
|
|
if (*str == ' ') {
|
|
if (*str == ' ') {
|
|
// skip spaces in the beginning of the new line
|
|
// skip spaces in the beginning of the new line
|
|
- str++;
|
|
|
|
|
|
+ str ++;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -246,11 +283,10 @@ void ST7735_FillRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16
|
|
ST7735_Select();
|
|
ST7735_Select();
|
|
ST7735_SetAddressWindow(x, y, x+w-1, y+h-1);
|
|
ST7735_SetAddressWindow(x, y, x+w-1, y+h-1);
|
|
|
|
|
|
- uint8_t data[] = {color >> 8, color & 0xFF};
|
|
|
|
LCD_DC_DATA;
|
|
LCD_DC_DATA;
|
|
for (y = h; y > 0; y--) {
|
|
for (y = h; y > 0; y--) {
|
|
for (x = w; x > 0; x--) {
|
|
for (x = w; x > 0; x--) {
|
|
- spiSend(&ST7735_SPI_PORT, sizeof(data), data);
|
|
|
|
|
|
+ ST7735_WriteData16(color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|