20
20
LOG_MODULE_REGISTER (auxdisplay_jhd1313 , CONFIG_AUXDISPLAY_LOG_LEVEL );
21
21
22
22
/* Defines for the JHD1313_CMD_CURSOR_SHIFT */
23
- #define JHD1313_CS_DISPLAY_SHIFT (1 << 3)
24
- #define JHD1313_CS_RIGHT_SHIFT (1 << 2)
23
+ #define JHD1313_CS_DISPLAY_SHIFT (1 << 3)
24
+ #define JHD1313_CS_RIGHT_SHIFT (1 << 2)
25
25
26
26
/* Defines for the JHD1313_CMD_INPUT_SET to change text direction */
27
- #define JHD1313_IS_INCREMENT (1 << 1)
28
- #define JHD1313_IS_DECREMENT (0 << 1)
29
- #define JHD1313_IS_SHIFT (1 << 0)
27
+ #define JHD1313_IS_INCREMENT (1 << 1)
28
+ #define JHD1313_IS_DECREMENT (0 << 1)
29
+ #define JHD1313_IS_SHIFT (1 << 0)
30
30
31
31
/* Defines for the JHD1313_CMD_FUNCTION_SET */
32
- #define JHD1313_FS_8BIT_MODE (1 << 4)
33
- #define JHD1313_FS_ROWS_2 (1 << 3)
34
- #define JHD1313_FS_ROWS_1 (0 << 3)
35
- #define JHD1313_FS_DOT_SIZE_BIG (1 << 2)
36
- #define JHD1313_FS_DOT_SIZE_LITTLE (0 << 2)
32
+ #define JHD1313_FS_8BIT_MODE (1 << 4)
33
+ #define JHD1313_FS_ROWS_2 (1 << 3)
34
+ #define JHD1313_FS_ROWS_1 (0 << 3)
35
+ #define JHD1313_FS_DOT_SIZE_BIG (1 << 2)
36
+ #define JHD1313_FS_DOT_SIZE_LITTLE (0 << 2)
37
37
38
38
/* LCD Display Commands */
39
- #define JHD1313_CMD_SCREEN_CLEAR (1 << 0)
40
- #define JHD1313_CMD_CURSOR_RETURN (1 << 1)
41
- #define JHD1313_CMD_INPUT_SET (1 << 2)
42
- #define JHD1313_CMD_DISPLAY_SWITCH (1 << 3)
43
- #define JHD1313_CMD_CURSOR_SHIFT (1 << 4)
44
- #define JHD1313_CMD_FUNCTION_SET (1 << 5)
45
- #define JHD1313_CMD_SET_CGRAM_ADDR (1 << 6)
46
- #define JHD1313_CMD_SET_DDRAM_ADDR (1 << 7)
39
+ #define JHD1313_CMD_SCREEN_CLEAR (1 << 0)
40
+ #define JHD1313_CMD_CURSOR_RETURN (1 << 1)
41
+ #define JHD1313_CMD_INPUT_SET (1 << 2)
42
+ #define JHD1313_CMD_DISPLAY_SWITCH (1 << 3)
43
+ #define JHD1313_CMD_CURSOR_SHIFT (1 << 4)
44
+ #define JHD1313_CMD_FUNCTION_SET (1 << 5)
45
+ #define JHD1313_CMD_SET_CGRAM_ADDR (1 << 6)
46
+ #define JHD1313_CMD_SET_DDRAM_ADDR (1 << 7)
47
47
48
- #define JHD1313_DS_DISPLAY_ON (1 << 2)
49
- #define JHD1313_DS_CURSOR_ON (1 << 1)
50
- #define JHD1313_DS_BLINK_ON (1 << 0)
48
+ #define JHD1313_DS_DISPLAY_ON (1 << 2)
49
+ #define JHD1313_DS_CURSOR_ON (1 << 1)
50
+ #define JHD1313_DS_BLINK_ON (1 << 0)
51
51
52
- #define JHD1313_LED_REG_R 0x04
53
- #define JHD1313_LED_REG_G 0x03
54
- #define JHD1313_LED_REG_B 0x02
52
+ #define JHD1313_LED_REG_R 0x04
53
+ #define JHD1313_LED_REG_G 0x03
54
+ #define JHD1313_LED_REG_B 0x02
55
55
56
- #define JHD1313_LINE_FIRST 0x80
57
- #define JHD1313_LINE_SECOND 0xC0
56
+ #define JHD1313_LINE_FIRST 0x80
57
+ #define JHD1313_LINE_SECOND 0xC0
58
58
59
- #define CLEAR_DELAY_MS 20
60
- #define UPDATE_DELAY_MS 5
59
+ #define CLEAR_DELAY_MS 20
60
+ #define UPDATE_DELAY_MS 5
61
61
62
62
struct auxdisplay_jhd1313_data {
63
63
uint8_t input_set ;
@@ -75,26 +75,26 @@ struct auxdisplay_jhd1313_config {
75
75
};
76
76
77
77
static const uint8_t colour_define [][4 ] = {
78
- { 0 , 0 , 0 }, /* Off */
79
- { 255 , 255 , 255 }, /* White */
80
- { 255 , 0 , 0 }, /* Red */
81
- { 0 , 255 , 0 }, /* Green */
82
- { 0 , 0 , 255 }, /* Blue */
78
+ {0 , 0 , 0 }, /* Off */
79
+ {255 , 255 , 255 }, /* White */
80
+ {255 , 0 , 0 }, /* Red */
81
+ {0 , 255 , 0 }, /* Green */
82
+ {0 , 0 , 255 }, /* Blue */
83
83
};
84
84
85
85
static void auxdisplay_jhd1313_reg_set (const struct device * dev , uint8_t addr , uint8_t data )
86
86
{
87
87
const struct auxdisplay_jhd1313_config * config = dev -> config ;
88
88
const struct device * i2c = config -> bus .bus ;
89
- uint8_t command [2 ] = { addr , data };
89
+ uint8_t command [2 ] = {addr , data };
90
90
91
91
i2c_write (i2c , command , sizeof (command ), config -> backlight_addr );
92
92
}
93
93
94
94
static int auxdisplay_jhd1313_print (const struct device * dev , const uint8_t * data , uint16_t size )
95
95
{
96
96
const struct auxdisplay_jhd1313_config * config = dev -> config ;
97
- uint8_t buf [] = { JHD1313_CMD_SET_CGRAM_ADDR , 0 };
97
+ uint8_t buf [] = {JHD1313_CMD_SET_CGRAM_ADDR , 0 };
98
98
int rc = 0 ;
99
99
int16_t i ;
100
100
@@ -133,7 +133,7 @@ static int auxdisplay_jhd1313_clear(const struct device *dev)
133
133
{
134
134
int rc ;
135
135
const struct auxdisplay_jhd1313_config * config = dev -> config ;
136
- uint8_t clear [] = { 0 , JHD1313_CMD_SCREEN_CLEAR };
136
+ uint8_t clear [] = {0 , JHD1313_CMD_SCREEN_CLEAR };
137
137
138
138
rc = i2c_write_dt (& config -> bus , clear , sizeof (clear ));
139
139
LOG_DBG ("Clear, delay 20 ms" );
@@ -143,12 +143,11 @@ static int auxdisplay_jhd1313_clear(const struct device *dev)
143
143
return rc ;
144
144
}
145
145
146
- static int auxdisplay_jhd1313_update_display_state (
147
- const struct auxdisplay_jhd1313_config * config ,
148
- struct auxdisplay_jhd1313_data * data )
146
+ static int auxdisplay_jhd1313_update_display_state (const struct auxdisplay_jhd1313_config * config ,
147
+ struct auxdisplay_jhd1313_data * data )
149
148
{
150
149
int rc ;
151
- uint8_t buf [] = { 0 , JHD1313_CMD_DISPLAY_SWITCH };
150
+ uint8_t buf [] = {0 , JHD1313_CMD_DISPLAY_SWITCH };
152
151
153
152
if (data -> power ) {
154
153
buf [1 ] |= JHD1313_DS_DISPLAY_ON ;
@@ -192,7 +191,7 @@ static void auxdisplay_jhd1313_input_state_set(const struct device *dev, uint8_t
192
191
{
193
192
const struct auxdisplay_jhd1313_config * config = dev -> config ;
194
193
struct auxdisplay_jhd1313_data * data = dev -> data ;
195
- uint8_t buf [] = { 0 , 0 };
194
+ uint8_t buf [] = {0 , 0 };
196
195
197
196
data -> input_set = opt ;
198
197
buf [1 ] = (opt | JHD1313_CMD_INPUT_SET );
@@ -232,7 +231,7 @@ static void auxdisplay_jhd1313_function_set(const struct device *dev, uint8_t op
232
231
{
233
232
const struct auxdisplay_jhd1313_config * config = dev -> config ;
234
233
struct auxdisplay_jhd1313_data * data = dev -> data ;
235
- uint8_t buf [] = { 0 , 0 };
234
+ uint8_t buf [] = {0 , 0 };
236
235
237
236
data -> function = opt ;
238
237
buf [1 ] = (opt | JHD1313_CMD_FUNCTION_SET );
@@ -348,33 +347,30 @@ static DEVICE_API(auxdisplay, auxdisplay_jhd1313_auxdisplay_api) = {
348
347
.write = auxdisplay_jhd1313_print ,
349
348
};
350
349
351
- #define AUXDISPLAY_JHD1313_DEVICE (inst ) \
352
- static const struct auxdisplay_jhd1313_config auxdisplay_jhd1313_config_##inst = { \
353
- .capabilities = { \
354
- .columns = 16, \
355
- .rows = 2, \
356
- .mode = 0, \
357
- .brightness.minimum = AUXDISPLAY_LIGHT_NOT_SUPPORTED, \
358
- .brightness.maximum = AUXDISPLAY_LIGHT_NOT_SUPPORTED, \
359
- .backlight.minimum = 0, \
360
- .backlight.maximum = ARRAY_SIZE(colour_define), \
361
- .custom_characters = 0, \
362
- }, \
363
- .bus = I2C_DT_SPEC_INST_GET(inst), \
364
- .backlight_addr = DT_INST_PROP(inst, backlight_addr), \
365
- }; \
366
- static struct auxdisplay_jhd1313_data auxdisplay_jhd1313_data_##inst = { \
367
- .power = true, \
368
- .cursor = false, \
369
- .blinking = false, \
370
- }; \
371
- DEVICE_DT_INST_DEFINE(inst, \
372
- &auxdisplay_jhd1313_initialize, \
373
- NULL, \
374
- &auxdisplay_jhd1313_data_##inst, \
375
- &auxdisplay_jhd1313_config_##inst, \
376
- POST_KERNEL, \
377
- CONFIG_AUXDISPLAY_INIT_PRIORITY, \
378
- &auxdisplay_jhd1313_auxdisplay_api);
350
+ #define AUXDISPLAY_JHD1313_DEVICE (inst ) \
351
+ static const struct auxdisplay_jhd1313_config auxdisplay_jhd1313_config_##inst = { \
352
+ .capabilities = \
353
+ { \
354
+ .columns = 16, \
355
+ .rows = 2, \
356
+ .mode = 0, \
357
+ .brightness.minimum = AUXDISPLAY_LIGHT_NOT_SUPPORTED, \
358
+ .brightness.maximum = AUXDISPLAY_LIGHT_NOT_SUPPORTED, \
359
+ .backlight.minimum = 0, \
360
+ .backlight.maximum = ARRAY_SIZE(colour_define), \
361
+ .custom_characters = 0, \
362
+ }, \
363
+ .bus = I2C_DT_SPEC_INST_GET(inst), \
364
+ .backlight_addr = DT_INST_PROP(inst, backlight_addr), \
365
+ }; \
366
+ static struct auxdisplay_jhd1313_data auxdisplay_jhd1313_data_##inst = { \
367
+ .power = true, \
368
+ .cursor = false, \
369
+ .blinking = false, \
370
+ }; \
371
+ DEVICE_DT_INST_DEFINE(inst, &auxdisplay_jhd1313_initialize, NULL, \
372
+ &auxdisplay_jhd1313_data_##inst, &auxdisplay_jhd1313_config_##inst, \
373
+ POST_KERNEL, CONFIG_AUXDISPLAY_INIT_PRIORITY, \
374
+ &auxdisplay_jhd1313_auxdisplay_api);
379
375
380
376
DT_INST_FOREACH_STATUS_OKAY (AUXDISPLAY_JHD1313_DEVICE )
0 commit comments