Add OLED display support
This commit is contained in:
parent
6ec7d1b8bb
commit
548549f067
14 changed files with 322 additions and 68 deletions
src
|
@ -1,11 +1,21 @@
|
|||
#include "FreeRTOS.h"
|
||||
#include "gpio.h"
|
||||
#include "main.h"
|
||||
#include "semphr.h"
|
||||
#include "spi.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "BME68x-Sensor-API/bme68x.h"
|
||||
#include "oled-driver/Renderer.hpp"
|
||||
|
||||
extern QueueHandle_t spiMutex;
|
||||
extern void waitForSpiFinished();
|
||||
extern Renderer renderer;
|
||||
|
||||
constexpr auto MaximumChars = 22 * 4;
|
||||
char buffer[MaximumChars];
|
||||
|
||||
constexpr auto SPI_DEVICE = &hspi2;
|
||||
uint8_t txBuffer[512];
|
||||
|
@ -29,17 +39,15 @@ uint16_t dur_prof[10] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
|
|||
|
||||
void setChipSelect(bool state)
|
||||
{
|
||||
HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, state ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void waitForSpiFinished()
|
||||
{
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
HAL_GPIO_WritePin(VocSensorCS_GPIO_Port, VocSensorCS_Pin,
|
||||
state ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
// SPI read function map
|
||||
BME68X_INTF_RET_TYPE bme68x_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *)
|
||||
{
|
||||
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
||||
|
||||
setChipSelect(true);
|
||||
HAL_SPI_Transmit_DMA(SPI_DEVICE, ®_addr, 1);
|
||||
waitForSpiFinished();
|
||||
|
@ -47,6 +55,8 @@ BME68X_INTF_RET_TYPE bme68x_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32
|
|||
waitForSpiFinished();
|
||||
setChipSelect(false);
|
||||
|
||||
xSemaphoreGive(spiMutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -60,11 +70,15 @@ BME68X_INTF_RET_TYPE bme68x_spi_write(uint8_t reg_addr, const uint8_t *reg_data,
|
|||
txBuffer[0] = reg_addr;
|
||||
std::memcpy(&txBuffer[1], reg_data, len);
|
||||
|
||||
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
||||
|
||||
setChipSelect(true);
|
||||
HAL_SPI_Transmit_DMA(SPI_DEVICE, const_cast<uint8_t *>(txBuffer), len + 1);
|
||||
waitForSpiFinished();
|
||||
setChipSelect(false);
|
||||
|
||||
xSemaphoreGive(spiMutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -153,10 +167,33 @@ void bmeRun()
|
|||
/* Check if res == BME68X_OK, report or handle if otherwise */
|
||||
for (uint8_t i = 0; i < n_fields; i++)
|
||||
{
|
||||
// printf("%u, %u, %d, %u, %u, %u, 0x%x, %d, %d\n", sampleCount,
|
||||
// time_ms,(bmeData[i].temperature / 100), bmeData[i].pressure, (bmeData[i].humidity /
|
||||
// 1000),bmeData[i].gas_resistance,
|
||||
// bmeData[i].status,data[i].gas_index,data[i].meas_index);
|
||||
renderer.clearAll();
|
||||
|
||||
snprintf(buffer, MaximumChars,
|
||||
"%d°C, %luhPa, %lu%%\n%lukOhm, status: 0x%x\ngas_index: %d\nmeas_index: %d",
|
||||
bmeData[i].temperature / 100, //
|
||||
bmeData[i].pressure / 100, //
|
||||
bmeData[i].humidity / 1000, //
|
||||
bmeData[i].gas_resistance / 1000, //
|
||||
bmeData[i].status, //
|
||||
bmeData[i].gas_index, //
|
||||
bmeData[i].meas_index);
|
||||
|
||||
renderer.print({0, 0}, buffer);
|
||||
renderer.render();
|
||||
/*
|
||||
snprintf(buffer, MaximumChars, "sampleCount: %u\n, time_ms: %u\n \
|
||||
temperature; %d°C\n \
|
||||
pressure: %u\n \
|
||||
humidity: %u\n \
|
||||
gas_resistance: %u\n \
|
||||
// status: 0x%x\n \
|
||||
//gas_index: %d\n \
|
||||
meas_index: %d\n",
|
||||
sampleCount, time_ms, (bmeData[i].temperature / 100), bmeData[i].pressure,
|
||||
(bmeData[i].humidity / 1000), bmeData[i].gas_resistance, bmeData[i].status,
|
||||
bmeData[i].gas_index, bmeData[i].meas_index);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue