libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
oled_ssd1327.h
Go to the documentation of this file.
1#pragma once
2
3#include "per/spi.h"
4#include "per/gpio.h"
5#include "sys/system.h"
6
7namespace daisy
8{
13{
14 public:
50 void Init(const Config& config)
51 {
52 // Initialize both GPIO
53 pin_dc_.Init(config.pin_config.dc, GPIO::Mode::OUTPUT);
54 pin_reset_.Init(config.pin_config.reset, GPIO::Mode::OUTPUT);
55
56 // Initialize SPI
57 spi_.Init(config.spi_config);
58
59 // Reset and Configure OLED.
60 pin_reset_.Write(false);
61 System::Delay(10);
62 pin_reset_.Write(true);
63 System::Delay(10);
64 };
66 {
67 pin_dc_.Write(false);
68 spi_.BlockingTransmit(&cmd, 1);
69 };
70
71 void SendData(uint8_t* buff, size_t size)
72 {
73 pin_dc_.Write(true);
75 };
76
77 private:
78 SpiHandle spi_;
79 GPIO pin_reset_;
80 GPIO pin_dc_;
81};
82
83
87template <size_t width, size_t height, typename Transport>
89{
90 public:
91 struct Config
92 {
93 typename Transport::Config transport_config;
94 };
95
97 {
98 color_ = 0x0f;
99 transport_.Init(config.transport_config);
100
101 transport_.SendCommand(0x15); // set column address
102 transport_.SendCommand(0x00); // start column 0
103 transport_.SendCommand(0x3f); // end column 63*2 (two pixels / byte)
104
105 transport_.SendCommand(0x75); // set row address
106 transport_.SendCommand(0x00); // start row 0
107 transport_.SendCommand(0x7f); // end row 127
108
109 transport_.SendCommand(0x81); // set contrast control
110 transport_.SendCommand(0x80);
111
112 transport_.SendCommand(0xa0); // Set Re-map (0x51)
113 transport_.SendCommand(
114 0x51); // Column Address Remapping, COM Remapping, Splitting of Odd / Even COM Signals
115
116 transport_.SendCommand(0xa1); // start line
117 transport_.SendCommand(0x00);
118
119 transport_.SendCommand(0xa2); // display offset
120 transport_.SendCommand(0x00);
121
122 transport_.SendCommand(0xa4); // normal display
123 transport_.SendCommand(0xa8); // set multiplex ratio
124 transport_.SendCommand(0x7f);
125
126 transport_.SendCommand(0xb1); // set phase length
127 transport_.SendCommand(0xf1);
128
129 transport_.SendCommand(0xb3); // set dclk
130 transport_.SendCommand(
131 0x00); // 80Hz:0xc1 / 90Hz:0xe1 / 100Hz:0x00 / 110Hz:0x30 / 120Hz:0x50 / 130Hz:0x70
132
133 transport_.SendCommand(0xab); // Function Selection A
134 transport_.SendCommand(0x01);
135
136 transport_.SendCommand(0xb6); // set phase length
137 transport_.SendCommand(0x0f);
138
139 transport_.SendCommand(0xbe); // Set VCOMH
140 transport_.SendCommand(0x0f);
141
142 transport_.SendCommand(0xbc); // Set Pre-charge voltage
143 transport_.SendCommand(0x08);
144
145 transport_.SendCommand(0xd5); // Function Selection B
146 transport_.SendCommand(0x62); // Enable second pre-charge
147
148 transport_.SendCommand(0xfd); // unlock command
149 transport_.SendCommand(0x12);
150
151 System::Delay(200); // wait 200ms
152 transport_.SendCommand(0xaf); // turn on display
153 Fill(false);
154 };
155
156 size_t Width() const { return width; };
157 size_t Height() const { return height; };
158
160 {
162 uint32_t line = width / 2;
163
164 if((x >= width) || (y >= height))
165 return;
166
167 if(on)
168 {
169 pixel = buffer_[y * line + (x / 2)];
170 if(x % 2)
171 {
172 pixel &= 0xf0;
173 pixel |= color_;
174 }
175 else
176 {
177 pixel &= 0x0f;
178 pixel |= color_ << 4;
179 }
180 buffer_[y * line + (x / 2)] = pixel;
181 }
182 else
183 {
184 pixel = buffer_[y * line + (x / 2)];
185 if(x % 2)
186 {
187 pixel &= 0xf0;
188 }
189 else
190 {
191 pixel &= 0x0f;
192 }
193 buffer_[y * line + (x / 2)] = pixel;
194 }
195 };
196
197 void Fill(bool on)
198 {
199 for(size_t i = 0; i < sizeof(buffer_); i++)
200 {
201 buffer_[i] = on ? 0xff : 0x00;
202 }
203 };
204
208 void Update()
209 {
210 transport_.SendCommand(0x15); // column
211 transport_.SendCommand(0x00);
212 transport_.SendCommand((width / 2) - 1);
213
214 transport_.SendCommand(0x75); // row
215 transport_.SendCommand(0x00);
216 transport_.SendCommand(height - 1);
217
218 //write data
219 transport_.SendData(buffer_, 8192);
220 };
221
222 void Set_Color(uint8_t in_col) { color_ = in_col & 0x0f; };
223
224 protected:
226 uint8_t buffer_[width / 2 * height];
228};
229
235
236}; // namespace daisy
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.
Definition leddriver.h:33
void Init(I2CHandle i2c, const uint8_t(&addresses)[numDrivers], DmaBuffer dma_buffer_a, DmaBuffer dma_buffer_b, Pin oe_pin=Pin(PORTX, 0))
Definition leddriver.h:65
Definition oled_ssd1327.h:13
void Init(const Config &config)
Definition oled_ssd1327.h:50
void SendCommand(uint8_t cmd)
Definition oled_ssd1327.h:65
void SendData(uint8_t *buff, size_t size)
Definition oled_ssd1327.h:71
Definition oled_ssd1327.h:89
size_t Width() const
Definition oled_ssd1327.h:156
void Fill(bool on)
Definition oled_ssd1327.h:197
uint8_t color_
Definition oled_ssd1327.h:227
uint8_t buffer_[width/2 *height]
Definition oled_ssd1327.h:226
void Set_Color(uint8_t in_col)
Definition oled_ssd1327.h:222
void Update()
Definition oled_ssd1327.h:208
Transport transport_
Definition oled_ssd1327.h:225
size_t Height() const
Definition oled_ssd1327.h:157
void Init(Config config)
Definition oled_ssd1327.h:96
void DrawPixel(uint_fast8_t x, uint_fast8_t y, bool on)
Definition oled_ssd1327.h:159
Definition spi.h:24
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result Init(const Config &config)
static void Delay(uint32_t delay_ms)
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTX
Definition daisy_core.h:188
@ PORTB
Definition daisy_core.h:178
@ PORTG
Definition daisy_core.h:183
representation of hardware port/pin combination
Definition daisy_core.h:193
Definition oled_ssd1327.h:16
SpiHandle::Config spi_config
Definition oled_ssd1327.h:22
Pin reset
Definition oled_ssd1327.h:26
struct daisy::SSD13274WireSpiTransport::Config::@11 pin_config
void Defaults()
Definition oled_ssd1327.h:28
Pin dc
Definition oled_ssd1327.h:25
Config()
Definition oled_ssd1327.h:17
Definition oled_ssd1327.h:92
Transport::Config transport_config
Definition oled_ssd1327.h:93
Definition spi.h:27
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
ClockPhase clock_phase
Definition spi.h:105
BaudPrescaler baud_prescaler
Definition spi.h:107
Direction direction
Definition spi.h:102
unsigned long datasize
Definition spi.h:103