Skip to content

Commit 8884f22

Browse files
Jason KridnerRobertCNelson
authored andcommitted
fb_ssd1306: add support for MikroElectronica OLED B Click
https://www.mikroe.com/oled-b-click
1 parent c100f15 commit 8884f22

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

drivers/staging/fbtft/fb_ssd1306.c

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ static int init_display(struct fbtft_par *par)
6464
write_reg(par, 0x3F);
6565
else if (par->info->var.yres == 48)
6666
write_reg(par, 0x2F);
67+
else if (par->info->var.yres == 39)
68+
write_reg(par, 0x27); /* https://libstock.mikroe.com/projects/download/1111/2577/1411057038_oled_b_click___e_mikroc_arm.zip */
6769
else
6870
write_reg(par, 0x1F);
6971

@@ -81,16 +83,24 @@ static int init_display(struct fbtft_par *par)
8183

8284
/* Set Memory Addressing Mode */
8385
write_reg(par, 0x20);
84-
/* Vertical addressing mode */
86+
/* Vertical Addressing mode */
8587
write_reg(par, 0x01);
8688

8789
/* Set Segment Re-map */
88-
/* column address 127 is mapped to SEG0 */
89-
write_reg(par, 0xA0 | 0x1);
90+
if (par->info->var.yres == 39)
91+
/* no segment re-map */
92+
write_reg(par, 0xA0 | 0x0);
93+
else
94+
/* column address 127 is mapped to SEG0 */
95+
write_reg(par, 0xA0 | 0x1);
9096

9197
/* Set COM Output Scan Direction */
92-
/* remapped mode. Scan from COM[N-1] to COM0 */
93-
write_reg(par, 0xC8);
98+
if (par->info->var.yres == 39)
99+
/* no columnt re-map mode. Scan from COM0 to COM[N-1] */
100+
write_reg(par, 0xC0 | 0x0);
101+
else
102+
/* remapped mode. Scan from COM[N-1] to COM0 */
103+
write_reg(par, 0xC0 | 0x8);
94104

95105
/* Set COM Pins Hardware Configuration */
96106
write_reg(par, 0xDA);
@@ -100,18 +110,27 @@ static int init_display(struct fbtft_par *par)
100110
else if (par->info->var.yres == 48)
101111
/* A[4]=1b, Alternative COM pin configuration */
102112
write_reg(par, 0x12);
113+
else if (par->info->var.yres == 39)
114+
/* A[4]=1b, Alternative COM pin configuration */
115+
write_reg(par, 0x12);
103116
else
104117
/* A[4]=0b, Sequential COM pin configuration */
105118
write_reg(par, 0x02);
106119

107120
/* Set Pre-charge Period */
108121
write_reg(par, 0xD9);
109-
write_reg(par, 0xF1);
122+
if (par->info->var.yres == 39)
123+
write_reg(par, 0x25);
124+
else
125+
write_reg(par, 0xF1);
110126

111127
/* Set VCOMH Deselect Level */
112128
write_reg(par, 0xDB);
113-
/* according to the datasheet, this value is out of bounds */
114-
write_reg(par, 0x40);
129+
if (par->info->var.yres == 39)
130+
write_reg(par, 0x20);
131+
else
132+
/* according to the datasheet, this value is out of bounds */
133+
write_reg(par, 0x40);
115134

116135
/* Entire Display ON */
117136
/* Resume to RAM content display. Output follows RAM content */
@@ -142,17 +161,35 @@ static void set_addr_win_64x48(struct fbtft_par *par)
142161
write_reg(par, 0x5);
143162
}
144163

164+
static void set_addr_win_96x39(struct fbtft_par *par)
165+
{
166+
/* Set Page Address */
167+
write_reg(par, 0xB0);
168+
169+
/* Set Column Address */
170+
write_reg(par, 0x21);
171+
write_reg(par, 0x00);
172+
write_reg(par, 0x5F);
173+
174+
/* Set Page Address Range */
175+
write_reg(par, 0x22);
176+
write_reg(par, 0x0);
177+
write_reg(par, 0x4);
178+
}
179+
145180
static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
146181
{
147-
/* Set Lower Column Start Address for Page Addressing Mode */
182+
/* Set Lower Column Start Address for Vertical Addressing Mode */
148183
write_reg(par, 0x00 | 0x0);
149-
/* Set Higher Column Start Address for Page Addressing Mode */
184+
/* Set Higher Column Start Address for Vertical Addressing Mode */
150185
write_reg(par, 0x10 | 0x0);
151186
/* Set Display Start Line */
152187
write_reg(par, 0x40 | 0x0);
153188

154189
if (par->info->var.xres == 64 && par->info->var.yres == 48)
155190
set_addr_win_64x48(par);
191+
else if (par->info->var.xres == 96 && par->info->var.yres == 39)
192+
set_addr_win_96x39(par);
156193
}
157194

158195
static int blank(struct fbtft_par *par, bool on)
@@ -196,11 +233,19 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
196233
*buf |= (vmem16[(y * 8 + i) * xres + x] ? 1 : 0) << i;
197234
buf++;
198235
}
236+
if (yres % 8) {
237+
*buf = 0x00;
238+
for (i = 0; i < (yres - (y * 8)); i++)
239+
*buf |= (vmem16[(y * 8 + i) * xres + x] ? 1 : 0) << i;
240+
buf++;
241+
y++;
242+
}
199243
}
200244

201245
/* Write data */
202246
gpio_set_value(par->gpio.dc, 1);
203-
ret = par->fbtftops.write(par, par->txbuf.buf, xres * yres / 8);
247+
ret = par->fbtftops.write(par, par->txbuf.buf, xres * (yres / 8 + (yres % 8 != 0)));
248+
//ret = par->fbtftops.write(par, par->txbuf.buf, xres * 128 / 8);
204249
if (ret < 0)
205250
dev_err(par->info->device, "write failed and returned: %d\n",
206251
ret);

drivers/staging/fbtft/fbtft_device.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,25 @@ static struct fbtft_device_display displays[] = {
391391
},
392392
}
393393
}
394+
}, {
395+
.name = "mikroe_oledb",
396+
.spi = &(struct spi_board_info) {
397+
.modalias = "fb_ssd1306",
398+
.max_speed_hz = 16000000,
399+
.mode = SPI_MODE_0,
400+
.platform_data = &(struct fbtft_platform_data) {
401+
.display = {
402+
.width = 96,
403+
.height = 39,
404+
.buswidth = 8,
405+
},
406+
.gpios = (const struct fbtft_gpio []) {
407+
{ "reset", 45 },
408+
{ "dc", 110 },
409+
{},
410+
},
411+
}
412+
}
394413
}, {
395414
.name = "admatec_c-berry28",
396415
.spi = &(struct spi_board_info) {

0 commit comments

Comments
 (0)