@@ -60,23 +60,22 @@ struct st7789v_data {
6060#define ST7789V_PIXEL_SIZE 3u
6161#endif
6262
63- static void st7789v_set_lcd_margins (const struct device * dev ,
64- uint16_t x_offset , uint16_t y_offset )
63+ static void st7789v_set_lcd_margins (const struct device * dev , uint16_t x_offset , uint16_t y_offset )
6564{
6665 struct st7789v_data * data = dev -> data ;
6766
6867 data -> x_offset = x_offset ;
6968 data -> y_offset = y_offset ;
7069}
7170
72- static void st7789v_transmit (const struct device * dev , uint8_t cmd ,
73- uint8_t * tx_data , size_t tx_count )
71+ static void st7789v_transmit (const struct device * dev , uint8_t cmd , uint8_t * tx_data ,
72+ size_t tx_count )
7473{
7574 const struct st7789v_config * config = dev -> config ;
7675 uint16_t data = cmd ;
7776
78- struct spi_buf tx_buf = { .buf = & cmd , .len = 1 };
79- struct spi_buf_set tx_bufs = { .buffers = & tx_buf , .count = 1 };
77+ struct spi_buf tx_buf = {.buf = & cmd , .len = 1 };
78+ struct spi_buf_set tx_bufs = {.buffers = & tx_buf , .count = 1 };
8079
8180 if (config -> cmd_data_gpio .port != NULL ) {
8281 if (cmd != ST7789V_CMD_NONE ) {
@@ -142,8 +141,8 @@ static int st7789v_blanking_off(const struct device *dev)
142141 return 0 ;
143142}
144143
145- static void st7789v_set_mem_area (const struct device * dev , const uint16_t x ,
146- const uint16_t y , const uint16_t w , const uint16_t h )
144+ static void st7789v_set_mem_area (const struct device * dev , const uint16_t x , const uint16_t y ,
145+ const uint16_t w , const uint16_t h )
147146{
148147 struct st7789v_data * data = dev -> data ;
149148 uint16_t spi_data [2 ];
@@ -160,22 +159,18 @@ static void st7789v_set_mem_area(const struct device *dev, const uint16_t x,
160159 st7789v_transmit (dev , ST7789V_CMD_RASET , (uint8_t * )& spi_data [0 ], 4 );
161160}
162161
163- static int st7789v_write (const struct device * dev ,
164- const uint16_t x ,
165- const uint16_t y ,
166- const struct display_buffer_descriptor * desc ,
167- const void * buf )
162+ static int st7789v_write (const struct device * dev , const uint16_t x , const uint16_t y ,
163+ const struct display_buffer_descriptor * desc , const void * buf )
168164{
169- const uint8_t * write_data_start = (uint8_t * ) buf ;
165+ const uint8_t * write_data_start = (uint8_t * )buf ;
170166 uint16_t nbr_of_writes ;
171167 uint16_t write_h ;
172168
173169 __ASSERT (desc -> width <= desc -> pitch , "Pitch is smaller then width" );
174170 __ASSERT ((desc -> pitch * ST7789V_PIXEL_SIZE * desc -> height ) <= desc -> buf_size ,
175- "Input buffer to small" );
171+ "Input buffer to small" );
176172
177- LOG_DBG ("Writing %dx%d (w,h) @ %dx%d (x,y)" ,
178- desc -> width , desc -> height , x , y );
173+ LOG_DBG ("Writing %dx%d (w,h) @ %dx%d (x,y)" , desc -> width , desc -> height , x , y );
179174 st7789v_set_mem_area (dev , x , y , desc -> width , desc -> height );
180175
181176 if (desc -> pitch > desc -> width ) {
@@ -188,16 +183,16 @@ static int st7789v_write(const struct device *dev,
188183
189184 for (uint16_t write_cnt = 0U ; write_cnt < nbr_of_writes ; ++ write_cnt ) {
190185 st7789v_transmit (dev , write_cnt == 0U ? ST7789V_CMD_RAMWR : ST7789V_CMD_NONE ,
191- (void * ) write_data_start ,
192- desc -> width * ST7789V_PIXEL_SIZE * write_h );
186+ (void * )write_data_start ,
187+ desc -> width * ST7789V_PIXEL_SIZE * write_h );
193188 write_data_start += (desc -> pitch * ST7789V_PIXEL_SIZE );
194189 }
195190
196191 return 0 ;
197192}
198193
199194static void st7789v_get_capabilities (const struct device * dev ,
200- struct display_capabilities * capabilities )
195+ struct display_capabilities * capabilities )
201196{
202197 const struct st7789v_config * config = dev -> config ;
203198
@@ -216,7 +211,7 @@ static void st7789v_get_capabilities(const struct device *dev,
216211}
217212
218213static int st7789v_set_pixel_format (const struct device * dev ,
219- const enum display_pixel_format pixel_format )
214+ const enum display_pixel_format pixel_format )
220215{
221216#ifdef CONFIG_ST7789V_RGB565
222217 if (pixel_format == PIXEL_FORMAT_RGB_565 ) {
@@ -230,7 +225,7 @@ static int st7789v_set_pixel_format(const struct device *dev,
230225}
231226
232227static int st7789v_set_orientation (const struct device * dev ,
233- const enum display_orientation orientation )
228+ const enum display_orientation orientation )
234229{
235230 if (orientation == DISPLAY_ORIENTATION_NORMAL ) {
236231 return 0 ;
@@ -245,15 +240,12 @@ static void st7789v_lcd_init(const struct device *dev)
245240 const struct st7789v_config * config = dev -> config ;
246241 uint8_t tmp ;
247242
248- st7789v_set_lcd_margins (dev , data -> x_offset ,
249- data -> y_offset );
243+ st7789v_set_lcd_margins (dev , data -> x_offset , data -> y_offset );
250244
251- st7789v_transmit (dev , ST7789V_CMD_CMD2EN ,
252- (uint8_t * )config -> cmd2en_param ,
245+ st7789v_transmit (dev , ST7789V_CMD_CMD2EN , (uint8_t * )config -> cmd2en_param ,
253246 sizeof (config -> cmd2en_param ));
254247
255- st7789v_transmit (dev , ST7789V_CMD_PORCTRL ,
256- (uint8_t * )config -> porch_param ,
248+ st7789v_transmit (dev , ST7789V_CMD_PORCTRL , (uint8_t * )config -> porch_param ,
257249 sizeof (config -> porch_param ));
258250
259251 /* Digital Gamma Enable, default disabled */
@@ -281,8 +273,7 @@ static void st7789v_lcd_init(const struct device *dev)
281273 st7789v_transmit (dev , ST7789V_CMD_VDS , & tmp , 1 );
282274 }
283275
284- st7789v_transmit (dev , ST7789V_CMD_PWCTRL1 ,
285- (uint8_t * )config -> pwctrl1_param ,
276+ st7789v_transmit (dev , ST7789V_CMD_PWCTRL1 , (uint8_t * )config -> pwctrl1_param ,
286277 sizeof (config -> pwctrl1_param ));
287278
288279 /* Memory Data Access Control */
@@ -305,20 +296,16 @@ static void st7789v_lcd_init(const struct device *dev)
305296 st7789v_transmit (dev , ST7789V_CMD_INV_OFF , NULL , 0 );
306297 }
307298
308- st7789v_transmit (dev , ST7789V_CMD_PVGAMCTRL ,
309- (uint8_t * )config -> pvgam_param ,
299+ st7789v_transmit (dev , ST7789V_CMD_PVGAMCTRL , (uint8_t * )config -> pvgam_param ,
310300 sizeof (config -> pvgam_param ));
311301
312- st7789v_transmit (dev , ST7789V_CMD_NVGAMCTRL ,
313- (uint8_t * )config -> nvgam_param ,
302+ st7789v_transmit (dev , ST7789V_CMD_NVGAMCTRL , (uint8_t * )config -> nvgam_param ,
314303 sizeof (config -> nvgam_param ));
315304
316- st7789v_transmit (dev , ST7789V_CMD_RAMCTRL ,
317- (uint8_t * )config -> ram_param ,
305+ st7789v_transmit (dev , ST7789V_CMD_RAMCTRL , (uint8_t * )config -> ram_param ,
318306 sizeof (config -> ram_param ));
319307
320- st7789v_transmit (dev , ST7789V_CMD_RGBCTRL ,
321- (uint8_t * )config -> rgb_param ,
308+ st7789v_transmit (dev , ST7789V_CMD_RGBCTRL , (uint8_t * )config -> rgb_param ,
322309 sizeof (config -> rgb_param ));
323310}
324311
@@ -367,8 +354,7 @@ static int st7789v_init(const struct device *dev)
367354}
368355
369356#ifdef CONFIG_PM_DEVICE
370- static int st7789v_pm_action (const struct device * dev ,
371- enum pm_device_action action )
357+ static int st7789v_pm_action (const struct device * dev , enum pm_device_action action )
372358{
373359 int ret = 0 ;
374360
@@ -397,47 +383,45 @@ static const struct display_driver_api st7789v_api = {
397383 .set_orientation = st7789v_set_orientation ,
398384};
399385
400- #define ST7789V_WORD_SIZE (inst ) \
401- COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, cmd_data_gpios), (8), (9))
402-
403- #define ST7789V_INIT (inst ) \
404- static const struct st7789v_config st7789v_config_ ## inst = { \
405- .bus = SPI_DT_SPEC_INST_GET(inst, SPI_OP_MODE_MASTER | \
406- SPI_WORD_SET(ST7789V_WORD_SIZE(inst)), 0), \
407- .cmd_data_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, cmd_data_gpios, {}), \
408- .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {}), \
409- .vcom = DT_INST_PROP(inst, vcom), \
410- .gctrl = DT_INST_PROP(inst, gctrl), \
411- .vdv_vrh_enable = (DT_INST_NODE_HAS_PROP(inst, vrhs) \
412- && DT_INST_NODE_HAS_PROP(inst, vdvs)), \
413- .vrh_value = DT_INST_PROP_OR(inst, vrhs, 0), \
414- .vdv_value = DT_INST_PROP_OR(inst, vdvs, 0), \
415- .mdac = DT_INST_PROP(inst, mdac), \
416- .gamma = DT_INST_PROP(inst, gamma), \
417- .colmod = DT_INST_PROP(inst, colmod), \
418- .lcm = DT_INST_PROP(inst, lcm), \
419- .inversion_on = !DT_INST_PROP(inst, inversion_off), \
420- .porch_param = DT_INST_PROP(inst, porch_param), \
421- .cmd2en_param = DT_INST_PROP(inst, cmd2en_param), \
422- .pwctrl1_param = DT_INST_PROP(inst, pwctrl1_param), \
423- .pvgam_param = DT_INST_PROP(inst, pvgam_param), \
424- .nvgam_param = DT_INST_PROP(inst, nvgam_param), \
425- .ram_param = DT_INST_PROP(inst, ram_param), \
426- .rgb_param = DT_INST_PROP(inst, rgb_param), \
427- .width = DT_INST_PROP(inst, width), \
428- .height = DT_INST_PROP(inst, height), \
429- }; \
430- \
431- static struct st7789v_data st7789v_data_ ## inst = { \
432- .x_offset = DT_INST_PROP(inst, x_offset), \
433- .y_offset = DT_INST_PROP(inst, y_offset), \
434- }; \
435- \
436- PM_DEVICE_DT_INST_DEFINE(inst, st7789v_pm_action); \
437- \
438- DEVICE_DT_INST_DEFINE(inst, &st7789v_init, PM_DEVICE_DT_INST_GET(inst), \
439- &st7789v_data_ ## inst, &st7789v_config_ ## inst, \
440- POST_KERNEL, CONFIG_DISPLAY_INIT_PRIORITY, \
441- &st7789v_api);
386+ #define ST7789V_WORD_SIZE (inst ) COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, cmd_data_gpios), (8), (9))
387+
388+ #define ST7789V_INIT (inst ) \
389+ static const struct st7789v_config st7789v_config_##inst = { \
390+ .bus = SPI_DT_SPEC_INST_GET( \
391+ inst, SPI_OP_MODE_MASTER | SPI_WORD_SET(ST7789V_WORD_SIZE(inst)), 0), \
392+ .cmd_data_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, cmd_data_gpios, {}), \
393+ .reset_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {}), \
394+ .vcom = DT_INST_PROP(inst, vcom), \
395+ .gctrl = DT_INST_PROP(inst, gctrl), \
396+ .vdv_vrh_enable = \
397+ (DT_INST_NODE_HAS_PROP(inst, vrhs) && DT_INST_NODE_HAS_PROP(inst, vdvs)), \
398+ .vrh_value = DT_INST_PROP_OR(inst, vrhs, 0), \
399+ .vdv_value = DT_INST_PROP_OR(inst, vdvs, 0), \
400+ .mdac = DT_INST_PROP(inst, mdac), \
401+ .gamma = DT_INST_PROP(inst, gamma), \
402+ .colmod = DT_INST_PROP(inst, colmod), \
403+ .lcm = DT_INST_PROP(inst, lcm), \
404+ .inversion_on = !DT_INST_PROP(inst, inversion_off), \
405+ .porch_param = DT_INST_PROP(inst, porch_param), \
406+ .cmd2en_param = DT_INST_PROP(inst, cmd2en_param), \
407+ .pwctrl1_param = DT_INST_PROP(inst, pwctrl1_param), \
408+ .pvgam_param = DT_INST_PROP(inst, pvgam_param), \
409+ .nvgam_param = DT_INST_PROP(inst, nvgam_param), \
410+ .ram_param = DT_INST_PROP(inst, ram_param), \
411+ .rgb_param = DT_INST_PROP(inst, rgb_param), \
412+ .width = DT_INST_PROP(inst, width), \
413+ .height = DT_INST_PROP(inst, height), \
414+ }; \
415+ \
416+ static struct st7789v_data st7789v_data_##inst = { \
417+ .x_offset = DT_INST_PROP(inst, x_offset), \
418+ .y_offset = DT_INST_PROP(inst, y_offset), \
419+ }; \
420+ \
421+ PM_DEVICE_DT_INST_DEFINE(inst, st7789v_pm_action); \
422+ \
423+ DEVICE_DT_INST_DEFINE(inst, &st7789v_init, PM_DEVICE_DT_INST_GET(inst), \
424+ &st7789v_data_##inst, &st7789v_config_##inst, POST_KERNEL, \
425+ CONFIG_DISPLAY_INIT_PRIORITY, &st7789v_api);
442426
443427DT_INST_FOREACH_STATUS_OKAY (ST7789V_INIT )
0 commit comments