Skip to content

Commit fc136c7

Browse files
committed
【添加】lcd_set_color 设置前后背景颜色函数
1 parent 0e9307b commit fc136c7

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

examples/stm32l4_pandora/lcd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
lcd = LCD() # Create a LCD object
1414
lcd.light(False) # Close the backlight
1515
lcd.light(True) # Open the backlight
16+
lcd.set_color(WHITE, BLACK) # Set background color and foreground color
1617
lcd.fill(lcd.BLACK) # Fill the entire LCD with black
1718
lcd.fill(lcd.RED) # Fill the entire LCD with red
1819
lcd.fill(lcd.GRAY) # Fill the entire LCD with gray

port/genhdr/qstrdefs.generated.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,5 @@ QDEF(MP_QSTR_Timer, (const byte*)"\xa2\x05" "Timer")
761761
QDEF(MP_QSTR_ONE_SHOT, (const byte*)"\x5e\x08" "ONE_SHOT")
762762
QDEF(MP_QSTR_PERIODIC, (const byte*)"\x0a\x08" "PERIODIC")
763763
QDEF(MP_QSTR_period, (const byte*)"\xa0\x06" "period")
764+
QDEF(MP_QSTR_set_color, (const byte*)"\x25\x09" "set_color")
764765
// This file was automatically generated by makeqstrdata.py

port/machine_lcd.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ STATIC mp_obj_t machine_lcd_circle(size_t n_args, const mp_obj_t *args) {
176176
}
177177
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lcd_circle_obj, 4, 4, machine_lcd_circle);
178178

179+
/// \method set_color(back, fore)
180+
///
181+
/// Set background color and foreground color.
182+
///
183+
STATIC mp_obj_t machine_lcd_set_color(size_t n_args, const mp_obj_t *args) {
184+
rt_uint16_t back = mp_obj_get_int(args[1]);
185+
rt_uint16_t fore = mp_obj_get_int(args[2]);
186+
187+
lcd_set_color(back, fore);
188+
return mp_const_none;
189+
}
190+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lcd_set_color_obj, 3, 3, machine_lcd_set_color);
191+
179192
STATIC const mp_rom_map_elem_t machine_lcd_locals_dict_table[] = {
180193
// instance methods
181194
{ MP_ROM_QSTR(MP_QSTR_light), MP_ROM_PTR(&machine_lcd_light_obj) },
@@ -185,6 +198,7 @@ STATIC const mp_rom_map_elem_t machine_lcd_locals_dict_table[] = {
185198
{ MP_ROM_QSTR(MP_QSTR_line), MP_ROM_PTR(&machine_lcd_line_obj) },
186199
{ MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&machine_lcd_rectangle_obj) },
187200
{ MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&machine_lcd_circle_obj) },
201+
{ MP_ROM_QSTR(MP_QSTR_set_color), MP_ROM_PTR(&machine_lcd_set_color_obj) },
188202
// color
189203
{ MP_ROM_QSTR(MP_QSTR_WHITE), MP_ROM_INT(WHITE) },
190204
{ MP_ROM_QSTR(MP_QSTR_BLACK), MP_ROM_INT(BLACK) },

0 commit comments

Comments
 (0)