2020LOG_MODULE_REGISTER (auxdisplay_jhd1313 , CONFIG_AUXDISPLAY_LOG_LEVEL );
2121
2222/* 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)
2525
2626/* 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)
3030
3131/* 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)
3737
3838/* 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)
4747
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)
5151
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
5555
56- #define JHD1313_LINE_FIRST 0x80
57- #define JHD1313_LINE_SECOND 0xC0
56+ #define JHD1313_LINE_FIRST 0x80
57+ #define JHD1313_LINE_SECOND 0xC0
5858
59- #define CLEAR_DELAY_MS 20
60- #define UPDATE_DELAY_MS 5
59+ #define CLEAR_DELAY_MS 20
60+ #define UPDATE_DELAY_MS 5
6161
6262struct auxdisplay_jhd1313_data {
6363 uint8_t input_set ;
@@ -75,26 +75,26 @@ struct auxdisplay_jhd1313_config {
7575};
7676
7777static 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 */
8383};
8484
8585static void auxdisplay_jhd1313_reg_set (const struct device * dev , uint8_t addr , uint8_t data )
8686{
8787 const struct auxdisplay_jhd1313_config * config = dev -> config ;
8888 const struct device * i2c = config -> bus .bus ;
89- uint8_t command [2 ] = { addr , data };
89+ uint8_t command [2 ] = {addr , data };
9090
9191 i2c_write (i2c , command , sizeof (command ), config -> backlight_addr );
9292}
9393
9494static int auxdisplay_jhd1313_print (const struct device * dev , const uint8_t * data , uint16_t size )
9595{
9696 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 };
9898 int rc = 0 ;
9999 int16_t i ;
100100
@@ -133,7 +133,7 @@ static int auxdisplay_jhd1313_clear(const struct device *dev)
133133{
134134 int rc ;
135135 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 };
137137
138138 rc = i2c_write_dt (& config -> bus , clear , sizeof (clear ));
139139 LOG_DBG ("Clear, delay 20 ms" );
@@ -143,12 +143,11 @@ static int auxdisplay_jhd1313_clear(const struct device *dev)
143143 return rc ;
144144}
145145
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 )
149148{
150149 int rc ;
151- uint8_t buf [] = { 0 , JHD1313_CMD_DISPLAY_SWITCH };
150+ uint8_t buf [] = {0 , JHD1313_CMD_DISPLAY_SWITCH };
152151
153152 if (data -> power ) {
154153 buf [1 ] |= JHD1313_DS_DISPLAY_ON ;
@@ -192,7 +191,7 @@ static void auxdisplay_jhd1313_input_state_set(const struct device *dev, uint8_t
192191{
193192 const struct auxdisplay_jhd1313_config * config = dev -> config ;
194193 struct auxdisplay_jhd1313_data * data = dev -> data ;
195- uint8_t buf [] = { 0 , 0 };
194+ uint8_t buf [] = {0 , 0 };
196195
197196 data -> input_set = opt ;
198197 buf [1 ] = (opt | JHD1313_CMD_INPUT_SET );
@@ -232,7 +231,7 @@ static void auxdisplay_jhd1313_function_set(const struct device *dev, uint8_t op
232231{
233232 const struct auxdisplay_jhd1313_config * config = dev -> config ;
234233 struct auxdisplay_jhd1313_data * data = dev -> data ;
235- uint8_t buf [] = { 0 , 0 };
234+ uint8_t buf [] = {0 , 0 };
236235
237236 data -> function = opt ;
238237 buf [1 ] = (opt | JHD1313_CMD_FUNCTION_SET );
@@ -348,33 +347,30 @@ static DEVICE_API(auxdisplay, auxdisplay_jhd1313_auxdisplay_api) = {
348347 .write = auxdisplay_jhd1313_print ,
349348};
350349
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);
379375
380376DT_INST_FOREACH_STATUS_OKAY (AUXDISPLAY_JHD1313_DEVICE )
0 commit comments