14 changed files with 322 additions and 68 deletions
@ -1,3 +1,6 @@
|
||||
[submodule "src/BME68x-Sensor-API"] |
||||
path = src/BME68x-Sensor-API |
||||
url = https://github.com/BoschSensortec/BME68x-Sensor-API.git |
||||
[submodule "src/oled-driver"] |
||||
path = src/oled-driver |
||||
url = git@github.com:MG-5/oled-driver.git |
||||
|
@ -0,0 +1,88 @@
|
||||
#pragma once |
||||
|
||||
#include "main.h" |
||||
#include "semphr.h" |
||||
#include "spi.h" |
||||
|
||||
#include "oled-driver/SSD1306Interface.hpp" |
||||
|
||||
constexpr size_t OledWidth = 128; |
||||
constexpr size_t OledPages = 4; |
||||
|
||||
namespace |
||||
{ |
||||
constexpr auto DisplaySpiPeripherie = &hspi2; |
||||
} // namespace
|
||||
|
||||
extern QueueHandle_t spiMutex; |
||||
extern void waitForSpiFinished(); |
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
//! SPI interface to a SSD1305/6 display controller.
|
||||
class SSD1306_SPI : public SSD1306Interface |
||||
{ |
||||
public: |
||||
void writeCommand(uint8_t cmd) override |
||||
{ |
||||
xSemaphoreTake(spiMutex, portMAX_DELAY); |
||||
|
||||
setCommandPin(); |
||||
setChipSelect(true); |
||||
HAL_SPI_Transmit_DMA(DisplaySpiPeripherie, &cmd, 1); |
||||
waitForSpiFinished(); |
||||
setChipSelect(false); |
||||
|
||||
xSemaphoreGive(spiMutex); |
||||
} |
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void writeData(uint8_t data) override |
||||
{ |
||||
xSemaphoreTake(spiMutex, portMAX_DELAY); |
||||
|
||||
setDataPin(); |
||||
setChipSelect(true); |
||||
HAL_SPI_Transmit_DMA(DisplaySpiPeripherie, &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(DisplaySpiPeripherie, 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); |
||||
} |
||||
}; |
Loading…
Reference in new issue