4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
6
6
7
+ #if defined(CONFIG_DT_HAS_SOLOMON_SSD1306FB_ENABLED )
7
8
#define DT_DRV_COMPAT solomon_ssd1306fb
9
+ #elif defined(CONFIG_DT_HAS_SINOWEALTH_SH1106_ENABLED )
10
+ #define DT_DRV_COMPAT sinowealth_sh1106
11
+ #endif
8
12
9
13
#include <zephyr/logging/log.h>
10
14
LOG_MODULE_REGISTER (ssd1306 , CONFIG_DISPLAY_LOG_LEVEL );
@@ -48,6 +52,7 @@ struct ssd1306_config {
48
52
bool com_invdir ;
49
53
bool com_sequential ;
50
54
bool color_inversion ;
55
+ bool sh1106_compatible ;
51
56
int ready_time_ms ;
52
57
};
53
58
@@ -155,15 +160,11 @@ static inline int ssd1306_set_hardware_config(const struct device *dev)
155
160
156
161
static inline int ssd1306_set_charge_pump (const struct device * dev )
157
162
{
163
+ const struct ssd1306_config * config = dev -> config ;
158
164
uint8_t cmd_buf [] = {
159
- #if defined(CONFIG_SSD1306_DEFAULT )
160
- SSD1306_SET_CHARGE_PUMP_ON ,
161
- SSD1306_SET_CHARGE_PUMP_ON_ENABLED ,
162
- #endif
163
- #if defined(CONFIG_SSD1306_SH1106_COMPATIBLE )
164
- SH1106_SET_DCDC_MODE ,
165
- SH1106_SET_DCDC_ENABLED ,
166
- #endif
165
+ (config -> sh1106_compatible ? SH1106_SET_DCDC_MODE : SSD1306_SET_CHARGE_PUMP_ON ),
166
+ (config -> sh1106_compatible ? SH1106_SET_DCDC_ENABLED
167
+ : SSD1306_SET_CHARGE_PUMP_ON_ENABLED ),
167
168
SSD1306_PANEL_PUMP_VOLTAGE ,
168
169
};
169
170
@@ -188,37 +189,10 @@ static int ssd1306_suspend(const struct device *dev)
188
189
return ssd1306_write_bus (dev , cmd_buf , sizeof (cmd_buf ), true);
189
190
}
190
191
191
- static int ssd1306_write (const struct device * dev , const uint16_t x , const uint16_t y ,
192
- const struct display_buffer_descriptor * desc ,
193
- const void * buf )
192
+ static int ssd1306_write_default (const struct device * dev , const uint16_t x , const uint16_t y ,
193
+ const struct display_buffer_descriptor * desc , const void * buf ,
194
+ const size_t buf_len )
194
195
{
195
- size_t buf_len ;
196
-
197
- if (desc -> pitch < desc -> width ) {
198
- LOG_ERR ("Pitch is smaller then width" );
199
- return -1 ;
200
- }
201
-
202
- buf_len = MIN (desc -> buf_size , desc -> height * desc -> width / 8 );
203
- if (buf == NULL || buf_len == 0U ) {
204
- LOG_ERR ("Display buffer is not available" );
205
- return -1 ;
206
- }
207
-
208
- if (desc -> pitch > desc -> width ) {
209
- LOG_ERR ("Unsupported mode" );
210
- return -1 ;
211
- }
212
-
213
- if ((y & 0x7 ) != 0U ) {
214
- LOG_ERR ("Unsupported origin" );
215
- return -1 ;
216
- }
217
-
218
- LOG_DBG ("x %u, y %u, pitch %u, width %u, height %u, buf_len %u" ,
219
- x , y , desc -> pitch , desc -> width , desc -> height , buf_len );
220
-
221
- #if defined(CONFIG_SSD1306_DEFAULT )
222
196
uint8_t cmd_buf [] = {
223
197
SSD1306_SET_MEM_ADDRESSING_MODE ,
224
198
SSD1306_ADDRESSING_MODE ,
@@ -236,8 +210,12 @@ static int ssd1306_write(const struct device *dev, const uint16_t x, const uint1
236
210
}
237
211
238
212
return ssd1306_write_bus (dev , (uint8_t * )buf , buf_len , false);
213
+ }
239
214
240
- #elif defined(CONFIG_SSD1306_SH1106_COMPATIBLE )
215
+ static int ssd1306_write_sh1106 (const struct device * dev , const uint16_t x , const uint16_t y ,
216
+ const struct display_buffer_descriptor * desc , const void * buf ,
217
+ const size_t buf_len )
218
+ {
241
219
const struct ssd1306_config * config = dev -> config ;
242
220
uint8_t x_offset = x + config -> segment_offset ;
243
221
uint8_t cmd_buf [] = {
@@ -268,11 +246,47 @@ static int ssd1306_write(const struct device *dev, const uint16_t x, const uint1
268
246
return -1 ;
269
247
}
270
248
}
271
- #endif
272
249
273
250
return 0 ;
274
251
}
275
252
253
+ static int ssd1306_write (const struct device * dev , const uint16_t x , const uint16_t y ,
254
+ const struct display_buffer_descriptor * desc , const void * buf )
255
+ {
256
+ const struct ssd1306_config * config = dev -> config ;
257
+ size_t buf_len ;
258
+
259
+ if (desc -> pitch < desc -> width ) {
260
+ LOG_ERR ("Pitch is smaller then width" );
261
+ return -1 ;
262
+ }
263
+
264
+ buf_len = MIN (desc -> buf_size , desc -> height * desc -> width / 8 );
265
+ if (buf == NULL || buf_len == 0U ) {
266
+ LOG_ERR ("Display buffer is not available" );
267
+ return -1 ;
268
+ }
269
+
270
+ if (desc -> pitch > desc -> width ) {
271
+ LOG_ERR ("Unsupported mode" );
272
+ return -1 ;
273
+ }
274
+
275
+ if ((y & 0x7 ) != 0U ) {
276
+ LOG_ERR ("Unsupported origin" );
277
+ return -1 ;
278
+ }
279
+
280
+ LOG_DBG ("x %u, y %u, pitch %u, width %u, height %u, buf_len %u" , x , y , desc -> pitch ,
281
+ desc -> width , desc -> height , buf_len );
282
+
283
+ if (config -> sh1106_compatible ) {
284
+ return ssd1306_write_sh1106 (dev , x , y , desc , buf , buf_len );
285
+ }
286
+
287
+ return ssd1306_write_default (dev , x , y , desc , buf , buf_len );
288
+ }
289
+
276
290
static int ssd1306_read (const struct device * dev , const uint16_t x ,
277
291
const uint16_t y ,
278
292
const struct display_buffer_descriptor * desc ,
@@ -438,6 +452,7 @@ static const struct ssd1306_config ssd1306_config = {
438
452
.com_sequential = DT_INST_PROP (0 , com_sequential ),
439
453
.prechargep = DT_INST_PROP (0 , prechargep ),
440
454
.color_inversion = DT_INST_PROP (0 , inversion_on ),
455
+ .sh1106_compatible = DT_NODE_HAS_COMPAT (0 , sinowealth_sh1106 ),
441
456
.ready_time_ms = DT_INST_PROP (0 , ready_time_ms ),
442
457
};
443
458
0 commit comments