2#ifndef SA_OLED_SSD130X_H
3#define SA_OLED_SSD130X_H
9#include "stm32h7xx_hal.h"
45 uint8_t buf[2] = {0X00, cmd};
51 for(
size_t i = 0; i < size; i++)
53 uint8_t buf[2] = {0X40, buff[i]};
146 SCB_CleanInvalidateDCache_by_Addr(buff, size);
148 spi_.
DmaTransmit(buff, size, NULL, end_callback, context);
210 SoftSpiTransmit(cmd);
216 for(
size_t i = 0; i < size; i++)
217 SoftSpiTransmit(buff[i]);
221 void SoftSpiTransmit(uint8_t val)
224 val = ((val & 0x01) << 7) | ((val & 0x02) << 5) | ((val & 0x04) << 3)
225 | ((val & 0x08) << 1) | ((val & 0x10) >> 1) | ((val & 0x20) >> 3)
226 | ((val & 0x40) >> 5) | ((val & 0x80) >> 7);
228 for(uint8_t bit = 0u; bit < 8u; bit++)
230 pin_mosi_.
Write((val & (1 << bit)) ? 1 : 0);
253template <
size_t w
idth,
size_t height,
typename Transport>
358 size_t Width()
const {
return width; };
359 size_t Height()
const {
return height; };
363 if(x >= width || y >= height)
366 buffer_[x + (y / 8) * width] |= (1 << (y % 8));
368 buffer_[x + (y / 8) * width] &= ~(1 << (y % 8));
373 for(
size_t i = 0; i <
sizeof(
buffer_); i++)
385 uint8_t high_column_addr;
388 case 32: high_column_addr = 0x12;
break;
390 default: high_column_addr = 0x10;
break;
392 for(i = 0; i < (height / 8); i++)
478template <
size_t w
idth,
size_t height,
typename Transport>
494 uint8_t uDispayOffset;
499 uDispayOffset = 0x60;
504 uDispayOffset = 0x68;
510 uDispayOffset = 0x00;
516 transport_.SendCommand(0xaE);
519 transport_.SendCommand(0x20);
522 transport_.SendCommand(0xA6);
525 transport_.SendCommand(0xA8);
526 transport_.SendCommand(uMultiplex);
529 transport_.SendCommand(0xA4);
532 transport_.SendCommand(0xD3);
533 transport_.SendCommand(uDispayOffset);
536 transport_.SendCommand(0xD5);
537 transport_.SendCommand(0x80);
540 transport_.SendCommand(0xD9);
541 transport_.SendCommand(0x22);
544 transport_.SendCommand(0xDA);
545 transport_.SendCommand(0x12);
548 transport_.SendCommand(0xDB);
549 transport_.SendCommand(0x35);
552 transport_.SendCommand(0x81);
553 transport_.SendCommand(0x80);
556 transport_.SendCommand(0xAF);
559 size_t Width()
const {
return width; };
560 size_t Height()
const {
return height; };
562 void DrawPixel(uint_fast8_t x, uint_fast8_t y,
bool on)
564 if(x >= width || y >= height)
567 buffer_[x + (y / 8) * width] |= (1 << (y % 8));
569 buffer_[x + (y / 8) * width] &= ~(1 << (y % 8));
564 if(x >= width || y >= height) {
…}
574 for(
size_t i = 0; i <
sizeof(buffer_); i++)
576 buffer_[i] = on ? 0xff : 0x00;
587 transferPagesCount_ = (height / 8);
588 if(transferPagesCount_)
597 uint8_t high_column_addr;
600 case 32: high_column_addr = 0x12;
break;
602 default: high_column_addr = 0x10;
break;
604 for(i = 0; i < (height / 8); i++)
606 transport_.SendCommand(0xB0 + i);
607 transport_.SendCommand(0x00);
608 transport_.SendCommand(high_column_addr);
609 transport_.SendData(&buffer_[width * i], width);
621 Transport transport_;
622 uint8_t buffer_[width * height / 8];
624 uint8_t transferPagesCount_;
625 uint8_t transferingPage_;
628 void TransferPageDma(uint8_t page)
630 transferingPage_ = page;
632 uint8_t high_column_addr;
635 case 32: high_column_addr = 0x12;
break;
637 default: high_column_addr = 0x10;
break;
639 uint8_t commands[] = {
static_cast<uint8_t
>(0xB0 + transferingPage_),
642 transport_.SendCommands(commands, 3);
646 transport_.SendDataDma(&buffer_[width * transferingPage_],
648 SpiPageCompleteCallback,
653 void PageTransfered(
void)
655 if(transferingPage_ < transferPagesCount_ - 1)
657 TransferPageDma(transferingPage_ + 1);
663 static void SpiPageCompleteCallback(
void* context,
General Purpose I/O control.
Definition gpio.h:22
void Write(bool state)
Changes the state of the GPIO hardware when configured as an OUTPUT.
void Init()
Initialize the GPIO using the internal Config struct.
void Toggle()
flips the current state of the GPIO. If it was HIGH, it will go LOW, and vice versa.
Result Init(const Config &config)
Result TransmitBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Definition oled_ssd130x.h:472
void Init(Config config)
Definition oled_ssd130x.h:479
size_t Width() const
Definition oled_ssd130x.h:551
bool UpdateFinished()
Definition oled_ssd130x.h:610
void DrawPixel(uint_fast8_t x, uint_fast8_t y, bool on)
Definition oled_ssd130x.h:554
void Update()
Definition oled_ssd130x.h:575
void Fill(bool on)
Definition oled_ssd130x.h:564
size_t Height() const
Definition oled_ssd130x.h:552
Definition oled_ssd130x.h:161
void SendData(uint8_t *buff, size_t size)
Definition oled_ssd130x.h:213
void SendCommand(uint8_t cmd)
Definition oled_ssd130x.h:207
void Init(const Config &config)
Definition oled_ssd130x.h:189
Definition oled_ssd130x.h:67
void SendCommand(uint8_t cmd)
Definition oled_ssd130x.h:123
void SendDataDma(uint8_t *buff, size_t size, SpiHandle::EndCallbackFunctionPtr end_callback, void *context)
Definition oled_ssd130x.h:141
void SendData(uint8_t *buff, size_t size)
Definition oled_ssd130x.h:135
void SendCommands(uint8_t *buff, size_t size)
Definition oled_ssd130x.h:129
void Init(const Config &config)
Definition oled_ssd130x.h:107
Definition oled_ssd130x.h:255
void Update()
Definition oled_ssd130x.h:382
size_t Height() const
Definition oled_ssd130x.h:359
void Fill(bool on)
Definition oled_ssd130x.h:371
size_t Width() const
Definition oled_ssd130x.h:358
void Init(Config config)
Definition oled_ssd130x.h:262
bool UpdateFinished()
Definition oled_ssd130x.h:404
Transport transport_
Definition oled_ssd130x.h:407
void DrawPixel(uint_fast8_t x, uint_fast8_t y, bool on)
Definition oled_ssd130x.h:361
uint8_t buffer_[width *height/8]
Definition oled_ssd130x.h:408
Definition oled_ssd130x.h:17
void Init(const Config &config)
Definition oled_ssd130x.h:38
void SendData(uint8_t *buff, size_t size)
Definition oled_ssd130x.h:49
void SendCommand(uint8_t cmd)
Definition oled_ssd130x.h:43
Result DmaTransmit(uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result Init(const Config &config)
void(*) EndCallbackFunctionPtr(void *context, Result result)
Definition spi.h:137
Result
Definition spi.h:116
static void Delay(uint32_t delay_ms)
static void DelayTicks(uint32_t delay_ticks)
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTX
Definition daisy_core.h:188
@ PORTB
Definition daisy_core.h:178
@ PORTC
Definition daisy_core.h:179
@ PORTD
Definition daisy_core.h:180
@ PORTG
Definition daisy_core.h:183
daisy::SSD1307Driver< 128, 64, SSD130x4WireSpiTransport > SSD13074WireSpi128x64Driver
Definition oled_ssd130x.h:665
struct daisy::I2CHandle::Config::@15 pin_config
Mode mode
Definition i2c.h:65
Pin scl
Definition i2c.h:60
Speed speed
Definition i2c.h:64
Peripheral periph
Definition i2c.h:57
Pin sda
Definition i2c.h:61
representation of hardware port/pin combination
Definition daisy_core.h:193
Definition oled_ssd130x.h:475
Transport::Config transport_config
Definition oled_ssd130x.h:476
Definition oled_ssd130x.h:164
void Defaults()
Definition oled_ssd130x.h:178
Config()
Definition oled_ssd130x.h:165
uint32_t sclk_delay
Definition oled_ssd130x.h:172
Pin reset
Definition oled_ssd130x.h:176
Pin mosi
Definition oled_ssd130x.h:174
struct daisy::SSD130x4WireSoftSpiTransport::Config::@10 pin_config
Pin dc
Definition oled_ssd130x.h:175
Pin sclk
Definition oled_ssd130x.h:173
Definition oled_ssd130x.h:70
Pin reset
Definition oled_ssd130x.h:80
Pin dc
Definition oled_ssd130x.h:79
SpiHandle::Config spi_config
Definition oled_ssd130x.h:76
void Defaults()
Definition oled_ssd130x.h:83
struct daisy::SSD130x4WireSpiTransport::Config::@9 pin_config
bool useDma
Definition oled_ssd130x.h:82
Config()
Definition oled_ssd130x.h:71
Definition oled_ssd130x.h:258
Transport::Config transport_config
Definition oled_ssd130x.h:259
Definition oled_ssd130x.h:20
uint8_t i2c_address
Definition oled_ssd130x.h:27
void Defaults()
Definition oled_ssd130x.h:28
I2CHandle::Config i2c_config
Definition oled_ssd130x.h:26
Config()
Definition oled_ssd130x.h:21
ClockPolarity clock_polarity
Definition spi.h:104
Peripheral periph
Definition spi.h:100
Pin nss
Definition spi.h:88
struct daisy::SpiHandle::Config::@18 pin_config
Mode mode
Definition spi.h:101
Pin mosi
Definition spi.h:87
Pin sclk
Definition spi.h:85
ClockPhase clock_phase
Definition spi.h:105
BaudPrescaler baud_prescaler
Definition spi.h:107
Pin miso
Definition spi.h:86
Direction direction
Definition spi.h:102
unsigned long datasize
Definition spi.h:103