You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "main.h"
|
|
#include "semphr.h"
|
|
#include "spi.h"
|
|
|
|
#include "oled-driver/SSDInterface.hpp"
|
|
|
|
constexpr size_t OledWidth = 128;
|
|
constexpr size_t OledPages = 4;
|
|
|
|
constexpr auto UsedSpiPeripherie = &hspi2;
|
|
|
|
extern QueueHandle_t spiMutex;
|
|
extern void waitForSpiFinished();
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
//! SPI interface to a SSD1305/6 display controller.
|
|
class SSDSpiInterface : public SSDInterface
|
|
{
|
|
public:
|
|
void writeCommand(uint8_t cmd) override
|
|
{
|
|
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
|
|
|
setCommandPin();
|
|
setChipSelect(true);
|
|
HAL_SPI_Transmit_DMA(UsedSpiPeripherie, &cmd, 1);
|
|
waitForSpiFinished();
|
|
setChipSelect(false);
|
|
|
|
xSemaphoreGive(spiMutex);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void writeData(uint8_t data) override
|
|
{
|
|
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
|
|
|
setDataPin();
|
|
setChipSelect(true);
|
|
HAL_SPI_Transmit_DMA(UsedSpiPeripherie, &data, 1);
|
|
waitForSpiFinished();
|
|
setChipSelect(false);
|
|
|
|
xSemaphoreGive(spiMutex);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void writeData(const uint8_t *data, unsigned int length) override
|
|
{
|
|
if (length > OledWidth * OledPages)
|
|
return;
|
|
|
|
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
|
|
|
setDataPin();
|
|
setChipSelect(true);
|
|
HAL_SPI_Transmit_DMA(UsedSpiPeripherie, const_cast<uint8_t *>(data), length);
|
|
waitForSpiFinished();
|
|
setChipSelect(false);
|
|
|
|
xSemaphoreGive(spiMutex);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
private:
|
|
void setDataPin()
|
|
{
|
|
HAL_GPIO_WritePin(DisplayDC_GPIO_Port, DisplayDC_Pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void setCommandPin()
|
|
{
|
|
HAL_GPIO_WritePin(DisplayDC_GPIO_Port, DisplayDC_Pin, GPIO_PIN_RESET);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void setChipSelect(bool state)
|
|
{
|
|
HAL_GPIO_WritePin(DisplayCS_GPIO_Port, DisplayCS_Pin,
|
|
state ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
|
}
|
|
};
|