Skip to content

Commit 3a7a87a

Browse files
committed
[heartbleed] Move the backlight control to lcd_init function
Signed-off-by: Douglas Reis <doreis@lowrisc.org>
1 parent 0927c78 commit 3a7a87a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

examples/heartbleed/legacy/heartbleed.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ int main()
289289
// Initialise UART drivers for debug logging
290290
uart0 = UART_FROM_BASE_ADDR(UART0_BASE);
291291
uart_init(uart0);
292+
pwm_t lcd_bl = PWM_FROM_ADDR_AND_INDEX(PWM_BASE, PWM_LCD);
292293

293294
write_to_uart("\n\nInitialized UART driver\n");
294295

@@ -301,13 +302,9 @@ int main()
301302
spi_t lcdSpi;
302303
St7735Context lcd;
303304
spi_init(&lcdSpi, LCD_SPI, LcdSpiSpeedHz);
304-
lcd_init(&lcdSpi, &lcd, &lcdInterface);
305+
lcd_init(&lcdSpi, lcd_bl, &lcd, &lcdInterface);
305306
lcd_clean(&lcd, BACKGROUND_COLOR);
306307

307-
// Turn on LCD backlight via PWM
308-
pwm_t lcd_bl = PWM_FROM_ADDR_AND_INDEX(PWM_BASE, PWM_LCD);
309-
set_pwm(lcd_bl, 1, 255);
310-
311308
size_t req_len = 8;
312309
while (true)
313310
{

examples/heartbleed/legacy/lcd.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <lucida_console_12pt.h>
1010
#include <m3x6_16pt.h>
1111
#include <m5x7_16pt.h>
12+
#include <pwm.h>
1213
#include <sonata_system.h>
1314
#include <spi.h>
1415
#include <stdarg.h>
@@ -43,7 +44,10 @@ static uint32_t gpio_write(void *handle, bool cs, bool dc)
4344
return 0;
4445
}
4546

46-
int lcd_init(spi_t *spi, St7735Context *lcd, LCD_Interface *interface)
47+
int lcd_init(spi_t *spi,
48+
pwm_t backlight,
49+
St7735Context *lcd,
50+
LCD_Interface *interface)
4751
{
4852
// Set the initial state of the LCD control pins
4953
spi_set_cs(spi, LcdDcPin, 0x00);
@@ -70,6 +74,7 @@ int lcd_init(spi_t *spi, St7735Context *lcd, LCD_Interface *interface)
7074

7175
// Clean display with a white rectangle.
7276
lcd_st7735_clean(lcd);
77+
set_pwm(backlight, 1, 255);
7378

7479
return 0;
7580
}

examples/heartbleed/legacy/lcd.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define _HEARTBLEED_LCD_H_
77

88
#include <lcd_st7735.h>
9+
#include <pwm.h>
910
#include <spi.h>
1011

1112
#ifdef __cplusplus
@@ -49,10 +50,15 @@ extern "C"
4950
* @brief Initialise the LCD, starting and clearing the screen.
5051
*
5152
* @param spi contains an initialized SPI handle to use to write to the LCD.
53+
* @param backlight contains an initialized pwm handle to use to control the
54+
* LCD backlight.
5255
* @param lcd is an outparam to store the initialized LCD handle.
5356
* @param interface is an outparam storing the initialized LCD interface.
5457
*/
55-
int lcd_init(spi_t *spi, St7735Context *lcd, LCD_Interface *interface);
58+
int lcd_init(spi_t *spi,
59+
pwm_t backlight,
60+
St7735Context *lcd,
61+
LCD_Interface *interface);
5662

5763
/**
5864
* @brief Formats and draws a string to the LCD display based upon the

0 commit comments

Comments
 (0)