не в тему STM: не понимаю почему вы ищите постоянно какие то библиотеки для дисплеев, если гораздо проще написать самим, есть то…SPI переделать, да инициализацию дисплея.
А если уж так надо и именно для STM32 ST7735, то ниже выложил, заняло час от силы чтоб по 411 чип переделать.
Спойлер
/*
* f4spi.cpp
*
* Created on: Sep 3, 2024
* Author: seleznev_a
*/
#include "f4spi.h"
#include "stm32f4xx.h"
#include "f4base.h"
#include <stdio.h>
void f4initSPI1(void) {
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // GPIO port A
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; // SPI ON
// pin SCK PA5 AF5 push-pull
GPIOA->MODER &= ~GPIO_MODER_MODER5; // 00 — clear bits
GPIOA->MODER |= GPIO_MODER_MODER5_1; // 10 — режим альтернативной функции.
GPIOA->MODER &= ~GPIO_MODER_MODER5_0; // 10 — режим альтернативной функции.
GPIOA->OTYPER &= ~GPIO_OTYPER_OT_5; // 0 - двухтактный выход или push-pull сокращено PP (после сброса)
GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR5; // 11 — 50 MHz
GPIOA->AFR[0] |=(0x05 << 20); // Назначаем PA5 выводу альтернативную функцию AF5
// pin MISO PA6 input pull-up
GPIOA->MODER &= ~GPIO_MODER_MODER6; // 00 — clear bits
GPIOA->MODER |= GPIO_MODER_MODER6_1; // 10 — режим альтернативной функции.
GPIOA->MODER &= ~GPIO_MODER_MODER6_0; // 10 — режим альтернативной функции.
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR6; // 00 — reset bits
GPIOA->PUPDR &= ~GPIO_PUPDR_PUPDR6_1; // 01 — подтяжка к плюсу питания или pull-up сокращено PU
GPIOA->PUPDR |= GPIO_PUPDR_PUPDR6_0; // 01 — подтяжка к плюсу питания или pull-up сокращено PU
GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR6; // 11 — 50 MHz
GPIOA->AFR[0] |=(0x05 << 24); // Назначаем PA6 выводу альтернативную функцию AF5
// pin MOSI PA7 AF5 push-pull
GPIOA->MODER |= GPIO_MODER_MODER7_1; // 10 — режим альтернативной функции.
GPIOA->MODER &= ~GPIO_MODER_MODER7_0; // 10 — режим альтернативной функции.
GPIOA->OTYPER &= ~GPIO_OTYPER_OT_7; // 0 - двухтактный выход или push-pull сокращено PP (после сброса)
GPIOA->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR7; // 11 — 50 MHz
GPIOA->AFR[0] |=(0x05 << 28); // Назначаем PA7 выводу альтернативную функцию AF5
// init SPI1
SPI1->CR1 = 0;
SPI1->CR2 = 0;
//SPI1->CR1 &= ~SPI_CR1_BR; // 000: fPCLK/2
//SPI1->CR1 &= ~SPI_CR1_CPOL; // Clock polarity 0/1
//SPI1->CR1 &= ~SPI_CR1_CPHA; // Clock phase // 0: The first clock transition is the first data capture edge // The second clock transition is the first data capture edge
//SPI1->CR1 &= ~SPI_CR1_DFF; // 0: 8-bit data frame format is selected for transmission/reception
//SPI1->CR1 &= ~SPI_CR1_LSBFIRST; // 0 - MSB передается первым
SPI1->CR1 |= SPI_CR1_SSM; // Программное управление SS
SPI1->CR1 |= SPI_CR1_SSI; // I/O value of the NSS pin is ignored
SPI1->CR1 |= SPI_CR1_MSTR; // master mode
SPI1->CR1 |= SPI_CR1_SPE; // включить SPI
}
void f4sendSPI1(unsigned char cmd) {
*((__IO uint8_t *)&SPI1->DR) = cmd;
while ((!(SPI1->SR & SPI_SR_TXE)) && (SPI1->SR & SPI_SR_BSY));
}
void f4writeSPI1(unsigned char * buff, unsigned long buff_size) {
for(unsigned long i = 0; i < buff_size; ++i) {
while(!(SPI1->SR & SPI_SR_TXE)); // do not remark - its not good
*((__IO uint8_t *)&SPI1->DR) = *(buff++);
}
while ((!(SPI1->SR & SPI_SR_TXE)) && (SPI1->SR & SPI_SR_BSY));
}
Спойлер
/*
* f4st7735.cpp
*
* Created on: Sep 3, 2024
* Author: seleznev_a
*/
#include "f4st7735.h"
#include "f4spi.h"
#include "stm32f4xx.h"
#include "f4base.h"
#include <stdlib.h>
#include <string.h>
/*
* FR08x08.c
*
* Created on: 25 нояб. 2021 г.
* Author: http://forum.easyelectronics.ru/viewtopic.php?f=9&t=18271
*/
const unsigned char frus08x08[256][8] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E},
{0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E},
{0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00},
{0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00},
{0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x7C, 0x38, 0x7C},
{0x10, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C},
{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},
{0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78},
{0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18},
{0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0},
{0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0},
{0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99},
{0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00},
{0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00},
{0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18},
{0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00},
{0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00},
{0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0xCC, 0x78},
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00},
{0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF},
{0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00},
{0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00},
{0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00},
{0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00},
{0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00},
{0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00},
{0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00},
{0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x60, 0xF0, 0xF0, 0x60, 0x60, 0x00, 0x60, 0x00},
{0xD8, 0xD8, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x6C, 0xFE, 0x6C, 0x6C, 0xFE, 0x6C, 0x00, 0x00},
{0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00},
{0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00},
{0x38, 0x6C, 0x38, 0x6E, 0xDC, 0xCC, 0x76, 0x00},
{0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x30, 0x60, 0xC0, 0xC0, 0xC0, 0x60, 0x30, 0x00},
{0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00},
{0x00, 0xCC, 0x78, 0xFC, 0x78, 0xCC, 0x00, 0x00},
{0x00, 0x30, 0x30, 0xFC, 0x30, 0x30, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x60},
{0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00},
{0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00},
{0x7C, 0xC6, 0xCE, 0xDE, 0xF6, 0xE6, 0x7C, 0x00},
{0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00},
{0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00},
{0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00},
{0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00},
{0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00},
{0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00},
{0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00},
{0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00},
{0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00},
{0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x00},
{0x00, 0x30, 0x30, 0x00, 0x00, 0x30, 0x30, 0x60},
{0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00},
{0x00, 0x00, 0xFC, 0x00, 0x00, 0xFC, 0x00, 0x00},
{0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00},
{0x78, 0xCC, 0x0C, 0x18, 0x30, 0x00, 0x30, 0x00},
{0x7C, 0xC6, 0xDE, 0xDE, 0xDE, 0xC0, 0x78, 0x00},
{0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00},
{0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00},
{0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00},
{0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00},
{0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00},
{0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00},
{0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3E, 0x00},
{0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00},
{0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00},
{0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00},
{0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00},
{0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00},
{0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00},
{0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00},
{0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00},
{0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00},
{0x78, 0xCC, 0xCC, 0xCC, 0xDC, 0x78, 0x1C, 0x00},
{0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00},
{0x78, 0xCC, 0xE0, 0x70, 0x1C, 0xCC, 0x78, 0x00},
{0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00},
{0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00},
{0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00},
{0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00},
{0xC6, 0xC6, 0x6C, 0x38, 0x38, 0x6C, 0xC6, 0x00},
{0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00},
{0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00},
{0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00},
{0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00},
{0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00},
{0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF},
{0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00},
{0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00},
{0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00},
{0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00},
{0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00},
{0x38, 0x6C, 0x60, 0xF0, 0x60, 0x60, 0xF0, 0x00},
{0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8},
{0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00},
{0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00},
{0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78},
{0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00},
{0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00},
{0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xC6, 0x00},
{0x00, 0x00, 0xF8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00},
{0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00},
{0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0},
{0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E},
{0x00, 0x00, 0xDC, 0x76, 0x66, 0x60, 0xF0, 0x00},
{0x00, 0x00, 0x7C, 0xC0, 0x78, 0x0C, 0xF8, 0x00},
{0x10, 0x30, 0x7C, 0x30, 0x30, 0x34, 0x18, 0x00},
{0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00},
{0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00},
{0x00, 0x00, 0xC6, 0xD6, 0xFE, 0xFE, 0x6C, 0x00},
{0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00},
{0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8},
{0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00},
{0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00},
{0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00},
{0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00},
{0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00},
{0x1E, 0x36, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00},
{0x7C, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0x7E, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00},
{0x38, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0xFE, 0xC6},
{0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00},
{0xDB, 0xDB, 0x7E, 0x3C, 0x7E, 0xDB, 0xDB, 0x00},
{0xFE, 0x00, 0x00, 0xFE, 0x00, 0x00, 0xFE, 0x00},
{0x66, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00},
{0x3C, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00},
{0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66, 0x00},
{0x1E, 0x36, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00},
{0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00},
{0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00},
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00},
{0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00},
{0x7E, 0x81, 0xA5, 0x81, 0xA5, 0x99, 0x81, 0x7E},
{0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C, 0x00},
{0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00},
{0x66, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C, 0x00},
{0x7E, 0xDB, 0xDB, 0xDB, 0x7E, 0x18, 0x18, 0x00},
{0x00, 0x38, 0x7C, 0x7C, 0x7C, 0x38, 0x00, 0x00},
{0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7F, 0x03},
{0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00},
{0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xFF, 0x00},
{0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xFF, 0x03},
{0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0xC6, 0xC6, 0xC6, 0xF6, 0xDE, 0xDE, 0xF6, 0x00},
{0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0x78, 0x8C, 0x06, 0x3E, 0x06, 0x8C, 0x78, 0x00},
{0xCE, 0xDB, 0xDB, 0xFB, 0xDB, 0xDB, 0xCE, 0x00},
{0x3E, 0x66, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x00},
{0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00},
{0x00, 0x3C, 0x60, 0x3C, 0x66, 0x66, 0x3C, 0x00},
{0x00, 0x00, 0x7C, 0x66, 0x7C, 0x66, 0x7C, 0x00},
{0x00, 0x00, 0x7E, 0x60, 0x60, 0x60, 0x60, 0x00},
{0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x6C, 0xFE, 0xC6},
{0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00},
{0x00, 0x00, 0xDB, 0x7E, 0x3C, 0x7E, 0xDB, 0x00},
{0x00, 0x00, 0x3C, 0x66, 0x0C, 0x66, 0x3C, 0x00},
{0x7E, 0x60, 0x60, 0x7E, 0x60, 0x60, 0x7E, 0x00},
{0x00, 0x18, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x00},
{0x00, 0x00, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x00},
{0x00, 0x00, 0x1E, 0x36, 0x66, 0x66, 0x66, 0x00},
{0x00, 0x00, 0xC6, 0xFE, 0xFE, 0xD6, 0xC6, 0x00},
{0x00, 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00},
{0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00},
{0x00, 0x00, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x00},
{0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44},
{0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA},
{0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77},
{0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18},
{0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18},
{0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, 0x18},
{0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, 0x36},
{0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, 0x36},
{0x24, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00},
{0x8E, 0x88, 0xC8, 0xA8, 0x98, 0x88, 0x88, 0x00},
{0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36},
{0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, 0x36},
{0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, 0x00},
{0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, 0x00},
{0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, 0x18},
{0x1E, 0x36, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00},
{0x7C, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0x7E, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00},
{0x38, 0x6C, 0x6C, 0x6C, 0x6C, 0x6C, 0xFE, 0xC6},
{0x7E, 0x60, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00},
{0xDB, 0xDB, 0x7E, 0x3C, 0x7E, 0xDB, 0xDB, 0x00},
{0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0x00},
{0x66, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00},
{0x3C, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x66, 0x00},
{0x66, 0x6C, 0x78, 0x70, 0x78, 0x6C, 0x66, 0x00},
{0x1E, 0x36, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00},
{0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00},
{0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00},
{0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00},
{0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00},
{0x7C, 0x66, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x00},
{0x3C, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3C, 0x00},
{0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00},
{0x66, 0x66, 0x66, 0x3E, 0x06, 0x66, 0x3C, 0x00},
{0x7E, 0xDB, 0xDB, 0xDB, 0x7E, 0x18, 0x18, 0x00},
{0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00},
{0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7F, 0x03},
{0x66, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x06, 0x00},
{0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xFF, 0x00},
{0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xDB, 0xFF, 0x03},
{0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0xC6, 0xC6, 0xC6, 0xF6, 0xDE, 0xDE, 0xF6, 0x00},
{0x60, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00},
{0x78, 0x8C, 0x06, 0x3E, 0x06, 0x8C, 0x78, 0x00},
{0xCE, 0xDB, 0xDB, 0xFB, 0xDB, 0xDB, 0xCE, 0x00},
{0x3E, 0x66, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x00},
{0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00},
{0x00, 0x3C, 0x60, 0x3C, 0x66, 0x66, 0x3C, 0x00},
{0x00, 0x00, 0x7C, 0x66, 0x7C, 0x66, 0x7C, 0x00},
{0x00, 0x00, 0x7E, 0x60, 0x60, 0x60, 0x60, 0x00},
{0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x6C, 0xFE, 0xC6},
{0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00},
{0x00, 0x00, 0xDB, 0x7E, 0x3C, 0x7E, 0xDB, 0x00},
{0x00, 0x00, 0x3C, 0x66, 0x0C, 0x66, 0x3C, 0x00},
{0x00, 0x00, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x00},
{0x00, 0x18, 0x66, 0x6E, 0x7E, 0x76, 0x66, 0x00},
{0x00, 0x00, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x00},
{0x00, 0x00, 0x1E, 0x36, 0x66, 0x66, 0x66, 0x00},
{0x00, 0x00, 0xC6, 0xFE, 0xFE, 0xD6, 0xC6, 0x00},
{0x00, 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00},
{0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00},
{0x00, 0x00, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x00},
{0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x00},
{0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C, 0x00},
{0x00, 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00},
{0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C, 0x00},
{0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x18, 0x00},
{0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00},
{0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7F, 0x03},
{0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x00},
{0x00, 0x00, 0xDB, 0xDB, 0xDB, 0xDB, 0xFF, 0x00},
{0x00, 0x00, 0xDB, 0xDB, 0xDB, 0xDB, 0xFF, 0x03},
{0x00, 0x00, 0xE0, 0x60, 0x7C, 0x66, 0x7C, 0x00},
{0x00, 0x00, 0xC6, 0xC6, 0xF6, 0xDE, 0xF6, 0x00},
{0x00, 0x00, 0x60, 0x60, 0x7C, 0x66, 0x7C, 0x00},
{0x00, 0x00, 0x7C, 0x06, 0x3E, 0x06, 0x7C, 0x00},
{0x00, 0x00, 0xCE, 0xDB, 0xFB, 0xDB, 0xCE, 0x00},
{0x00, 0x00, 0x3E, 0x66, 0x3E, 0x36, 0x66, 0x00}};
/************************ (C) COPYRIGHT andycat2013@yandex.ru *****END OF FILE****/
unsigned char fontSizeX[4] = {fontWsize0, fontWsize1, fontWsize2, fontWsize3};
unsigned char fontSizeY[4] = {fontHsize0, fontHsize1, fontHsize2, fontHsize3};
void tftCSenable(void) {GPIOB->BSRR |= GPIO_BSRR_BR10;} // PB10 LOW // говорим slave устройству что начинаем работать
void tftCSdisable(void) {GPIOB->BSRR |= GPIO_BSRR_BS10;} // PB10 HIGH // закончили передачу SPI устройству
unsigned char nextXchar = 0;
unsigned char nextYchar = 0;
unsigned short nextColor = ST77XX_WHITE;
unsigned short nextBack = ST77XX_BLACK;
unsigned char nextSize = 0;
unsigned short oneCharBuf[fontWsize3 * fontHsize3];
void f1tftSendCommand(unsigned char cmd) {
GPIOB->BSRR |= GPIO_BSRR_BR0; // PB0 LOW
f4sendSPI1(cmd);
}
void f1tftWriteData(unsigned char * buff, unsigned long buff_size) {
GPIOB->BSRR |= GPIO_BSRR_BS0; // PB0 HIGH
f4writeSPI1(buff, buff_size);
}
void f4st7735init(void) {
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN; // GPIO port B
// PB1 - RESET ST7735
GPIOB->MODER |= GPIO_MODER_MODE1_0; // 01: Output mode
GPIOB->MODER &= ~GPIO_MODER_MODE1_1; // 01: Output mode
GPIOB->OTYPER &= ~GPIO_OTYPER_OT_1; // 0: Output push-pull (reset state)
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR1; // 00: Low speed
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR1; // No pull-up, pull-down
// PB0 - RS(A0) ST7735 cmd/data select
GPIOB->MODER |= GPIO_MODER_MODE0_0; // 01: Output mode
GPIOB->MODER &= ~GPIO_MODER_MODE0_1; // 01: Output mode
GPIOB->OTYPER &= ~GPIO_OTYPER_OT_0; // 0: Output push-pull (reset state)
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR0; // 00: Low speed
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR0; // No pull-up, pull-down
// PB10 - CS ST7735
GPIOB->MODER |= GPIO_MODER_MODE10_0; // 01: Output mode
GPIOB->MODER &= ~GPIO_MODER_MODE10_1; // 01: Output mode
GPIOB->OTYPER &= ~GPIO_OTYPER_OT_10; // 0: Output push-pull (reset state)
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR10; // 00: Low speed
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR10; // No pull-up, pull-down
// init tft
tftCSdisable(); // chip select off
// hardware reset
GPIOB->BSRR |= GPIO_BSRR_BR1; // PB1 LOW
delay_ms(10);
GPIOB->BSRR |= GPIO_BSRR_BS1; // PB1 HIGH
delay_ms(10);
// init routine
tftCSenable();
unsigned char dataSend[16];
f1tftSendCommand(ST77XX_SWRESET); // 0x01
delay_ms(150);
f1tftSendCommand(ST77XX_SLPOUT); // 0x11
delay_ms(150);
f1tftSendCommand(ST7735_FRMCTR1); // 0xB1
dataSend[0] = 0x01;
dataSend[1] = 0x2C;
dataSend[2] = 0x2D;
f1tftWriteData((unsigned char *)&dataSend, 3);
f1tftSendCommand(ST7735_FRMCTR2);
dataSend[0] = 0x01;
dataSend[1] = 0x2C;
dataSend[2] = 0x2D;
f1tftWriteData((unsigned char *)&dataSend, 3);
f1tftSendCommand(ST7735_FRMCTR3);
dataSend[0] = 0x01;
dataSend[1] = 0x2C;
dataSend[2] = 0x2D;
dataSend[3] = 0x01;
dataSend[4] = 0x2C;
dataSend[5] = 0x2D;
f1tftWriteData((unsigned char *)&dataSend, 6);
f1tftSendCommand(ST7735_INVCTR);
dataSend[0] = 0x07;
f1tftWriteData((unsigned char *)&dataSend, 1);
f1tftSendCommand(ST7735_PWCTR1);
dataSend[0] = 0xA2;
dataSend[1] = 0x02;
dataSend[2] = 0x84;
f1tftWriteData((unsigned char *)&dataSend, 3);
f1tftSendCommand(ST7735_PWCTR2);
dataSend[0] = 0xC5;
f1tftWriteData((unsigned char *)&dataSend, 1);
f1tftSendCommand(ST7735_PWCTR3);
dataSend[0] = 0x0A;
dataSend[1] = 0x00;
f1tftWriteData((unsigned char *)&dataSend, 2);
f1tftSendCommand(ST7735_PWCTR4);
dataSend[0] = 0x8A;
dataSend[1] = 0x2A;
f1tftWriteData((unsigned char *)&dataSend, 2);
f1tftSendCommand(ST7735_PWCTR5);
dataSend[0] = 0x8A;
dataSend[1] = 0xEE;
f1tftWriteData((unsigned char *)&dataSend, 2);
f1tftSendCommand(ST7735_VMCTR1);
dataSend[0] = 0x0E;
f1tftWriteData((unsigned char *)&dataSend, 1);
f1tftSendCommand(ST77XX_INVOFF);
f1tftSendCommand(ST77XX_MADCTL);
dataSend[0] = 0x00; // rotation 180
//dataSend[0] = 0xC0; // original string
f1tftWriteData((unsigned char *)&dataSend, 1);
f1tftSendCommand(ST77XX_COLMOD);
dataSend[0] = 0x05;
f1tftWriteData((unsigned char *)&dataSend, 1);
f1tftSendCommand(ST7735_GMCTRP1);
dataSend[0] = 0x02;
dataSend[1] = 0x1C;
dataSend[2] = 0x07;
dataSend[3] = 0x12;
dataSend[4] = 0x37;
dataSend[5] = 0x32;
dataSend[6] = 0x29;
dataSend[7] = 0x2D;
dataSend[8] = 0x29;
dataSend[9] = 0x25;
dataSend[10] = 0x2B;
dataSend[11] = 0x39;
dataSend[12] = 0x00;
dataSend[13] = 0x01;
dataSend[14] = 0x03;
dataSend[15] = 0x10;
f1tftWriteData((unsigned char *)&dataSend, 16);
f1tftSendCommand(ST7735_GMCTRN1);
dataSend[0] = 0x03;
dataSend[1] = 0x1D;
dataSend[2] = 0x07;
dataSend[3] = 0x06;
dataSend[4] = 0x2E;
dataSend[5] = 0x2C;
dataSend[6] = 0x29;
dataSend[7] = 0x2D;
dataSend[8] = 0x2E;
dataSend[9] = 0x2E;
dataSend[10] = 0x37;
dataSend[11] = 0x3F;
dataSend[12] = 0x00;
dataSend[13] = 0x00;
dataSend[14] = 0x02;
dataSend[15] = 0x10;
f1tftWriteData((unsigned char *)&dataSend, 16);
f1tftSendCommand(ST77XX_NORON);
delay_ms(10);
f1tftSendCommand(ST77XX_DISPON);
delay_ms(100);
tftCSdisable();
}
void f4tftSetAddrWindow(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1) {
static unsigned char pos_data[4];
// column address set
f1tftSendCommand(ST77XX_CASET); // CASET
pos_data[0] = (x0 & 0xFF00) >> 8;
pos_data[1] = x0 & 0x00FF;
pos_data[2] = (x1 & 0xFF00) >> 8;
pos_data[3] = x1 & 0x00FF;
f1tftWriteData((unsigned char *)&pos_data, 4);
// row address set
f1tftSendCommand(ST77XX_RASET); // RASET
pos_data[0] = (y0 & 0xFF00) >> 8;
pos_data[1] = y0 & 0x00FF;
pos_data[2] = (y1 & 0xFF00) >> 8;
pos_data[3] = y1 & 0x00FF;
f1tftWriteData((unsigned char *)&pos_data, 4);
// write to RAM
f1tftSendCommand(ST77XX_RAMWR); // RAMWR
}
void f4st7735fillRect(unsigned short value, unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1) {
tftCSenable(); // chip select on
f4tftSetAddrWindow(x0, y0, x1, y1);
// 16 bit transfer mode
SPI1->CR1 &= ~SPI_CR1_SPE;
GPIOB->BSRR |= GPIO_BSRR_BS0; // PB0 HIGH
SPI1->CR1 |= SPI_CR1_DFF;
SPI1->CR1 |= SPI_CR1_SPE;
unsigned long countPix = (unsigned long)((x1-x0+1)*(y1-y0+1));
while (countPix--) {
while (!(SPI1->SR & SPI_SR_TXE)); // do not remark - its not good
*(volatile uint16_t *)&(SPI1->DR) = value;
}
// wait end transfer
while (!(SPI1->SR & SPI_SR_TXE) || (SPI1->SR & SPI_SR_BSY));
// return 8bit transfer mode
SPI1->CR1 &= ~SPI_CR1_SPE;
tftCSdisable(); // chip select off
SPI1->CR1 &= ~SPI_CR1_DFF;
SPI1->CR1 |= SPI_CR1_SPE;
}
void f4st7735fillScreen(uint16_t value) {
f4st7735fillRect(value, 0, 0, st7735sizeX-1, st7735sizeY-1);
}
void f4st7735showRect(unsigned short * dataPoint, unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1) {
tftCSenable(); // chip select on
f4tftSetAddrWindow(x0, y0, x1, y1);
// 16 bit transfer mode
SPI1->CR1 &= ~SPI_CR1_SPE;
GPIOB->BSRR |= GPIO_BSRR_BS0; // PB0 HIGH
SPI1->CR1 |= SPI_CR1_DFF;
SPI1->CR1 |= SPI_CR1_SPE;
unsigned long countPix = (unsigned long)((x1-x0+1)*(y1-y0+1));
for (unsigned long i=0; i < countPix; i++) {
while (!(SPI1->SR & SPI_SR_TXE)); // do not remark - its not good
*(volatile uint16_t *)&(SPI1->DR) = *(dataPoint+i);
}
// wait end transfer
while (!(SPI1->SR & SPI_SR_TXE) || (SPI1->SR & SPI_SR_BSY));
// return 8bit transfer mode
SPI1->CR1 &= ~SPI_CR1_SPE;
tftCSdisable(); // chip select off
SPI1->CR1 &= ~SPI_CR1_DFF;
SPI1->CR1 |= SPI_CR1_SPE;
}
void f4st7735printOneChar(unsigned char inChar, unsigned short colChar, unsigned short colBackground, unsigned char sizeChar, unsigned char xChar, unsigned char yChar) {
unsigned char inSize = sizeChar & 0x03; // size 0...3
unsigned short locPosInBuf = 0; // абсолютная позиция в буфере где мы формируем картинку
unsigned short outColor;
for(unsigned char lineY = 0; lineY < fontSizeY[0]; ++lineY) { // цикл по строкам шрифта
for(unsigned char bitY = fontSizeX[0]; bitY > 0; --bitY) { // обратный цикл по горизонтальным битам строки шрифта
if (bitRead(frus08x08[inChar][lineY], (bitY-1))) outColor = colChar; else outColor = colBackground;
if (inSize == 0) { // самый маленький шрифт 8 на 8
oneCharBuf[locPosInBuf] = outColor;
++locPosInBuf;
} else { // необходимо масштабирование
unsigned char countHpoints; // количество точек по горизонтали
switch (inSize) {
case 1: {
if (bitRead(bitY, 0)) countHpoints = 1; else countHpoints = 2;
break;
}
case 2: {
if ((bitY == 7) || (bitY == 3)) countHpoints = 3; else countHpoints = 2;
break;
}
default: { // 3 size
countHpoints = 3;
}
}
for (unsigned char v = 0; v < countHpoints; ++v) { // сколько точек надо нарисовать в строке
for (unsigned char h = 0; h < (inSize+1); ++h) { // дублируем вниз точку на нужное количество увеличения шрифта
oneCharBuf[locPosInBuf + h * fontSizeX[inSize]] = outColor;
}
++locPosInBuf;
}
}
}
locPosInBuf += fontSizeX[inSize] * inSize;
}
f4st7735showRect((unsigned short *)&oneCharBuf, xChar, yChar, xChar+fontSizeX[inSize]-1, yChar+fontSizeY[inSize]-1);
nextSize = inSize;
nextColor = colChar;
nextBack = colBackground;
nextXchar = xChar+fontSizeX[inSize];
nextYchar = yChar;
if (nextXchar >= st7735sizeX) {
nextXchar = 0;
nextYchar += fontSizeY[inSize];
if (nextYchar >= st7735sizeY) nextYchar = 0;
}
}
void f4st7735printString(const unsigned char * inStr, unsigned short colChar, unsigned short colBackground, unsigned char sizeChar, unsigned char xChar, unsigned char yChar) {
unsigned char inSize = sizeChar & 0x03; // size 0...3
unsigned char posStr = 0;
unsigned char inChar;
while ((inChar = *(inStr + posStr)) > 0) {
f4st7735printOneChar(inChar, colChar, colBackground, inSize, xChar + fontSizeX[inSize] * posStr, yChar);
++posStr;
}
}
void f4st7735printUInt(unsigned long inVal, unsigned short colChar, unsigned short colBackground, unsigned char sizeChar, unsigned char xChar, unsigned char yChar) {
unsigned char outStr[32];
utoa(inVal, (char *)outStr, 10);
f4st7735printString((unsigned char *)&outStr, colChar, colBackground, sizeChar, xChar, yChar);
}
void f4st7735printHEX(unsigned long inVal, unsigned short colChar, unsigned short colBackground, unsigned char sizeChar, unsigned char xChar, unsigned char yChar) {
unsigned char outStr[32];
utoa(inVal, (char *)outStr, 16);
f4st7735printString((unsigned char *)&outStr, colChar, colBackground, sizeChar, xChar, yChar);
}
void f4st7735printText(const unsigned char * inText) {
unsigned char posStr = 0;
unsigned char inChar;
while ((inChar = *(inText + posStr)) > 0) {
f4st7735printOneChar(inChar, nextColor, nextBack, nextSize, nextXchar, nextYchar);
++posStr;
}
}
void f4st7735speedtest(void) {
unsigned short countPics = 0;
unsigned long timerSec =0UL;
while ((millis() - timerSec) < 1000UL) {
f4st7735fillScreen(0x55AA);
++countPics;
}
unsigned long speedSPI = st7735sizeX * st7735sizeY * 16 * countPics / 1000;
f4st7735printString((const unsigned char *)"Screens/sec", ST7735_WHITE, ST7735_BLACK, 0, 0, 0);
f4st7735printUInt(countPics, ST7735_WHITE, ST7735_BLACK, 0, 0, fontSizeY[0]);
f4st7735printString((const unsigned char *)"SPI speed (KHz)", ST7735_WHITE, ST7735_BLACK, 0, 0, fontSizeY[0] * 3);
f4st7735printUInt(speedSPI, ST7735_WHITE, ST7735_BLACK, 0, 0, fontSizeY[0] * 4);
f4st7735printString((const unsigned char *)"SPI1=APB2/2", ST7735_WHITE, ST7735_BLACK, 0, 0, fontSizeY[0] * 5);
delay_ms(10000UL);
}