Ver Fonte

Merge pull request #97 from SummerGGift/update_doc

【添加】lcd_set_color 设置前后背景颜色函数
朱天龙 (Armink) há 6 anos atrás
pai
commit
ef00b4d488
3 ficheiros alterados com 16 adições e 0 exclusões
  1. 1 0
      examples/stm32l4_pandora/lcd.py
  2. 1 0
      port/genhdr/qstrdefs.generated.h
  3. 14 0
      port/machine_lcd.c

+ 1 - 0
examples/stm32l4_pandora/lcd.py

@@ -13,6 +13,7 @@ from machine import LCD     # Import the LCD class from machine
 lcd = LCD()                             # Create a LCD object
 lcd.light(False)                        # Close the backlight
 lcd.light(True)                         # Open the backlight
+lcd.set_color(WHITE, BLACK)             # Set background color and foreground color
 lcd.fill(lcd.BLACK)                     # Fill the entire LCD with black
 lcd.fill(lcd.RED)                       # Fill the entire LCD with red
 lcd.fill(lcd.GRAY)                      # Fill the entire LCD with gray

+ 1 - 0
port/genhdr/qstrdefs.generated.h

@@ -761,4 +761,5 @@ QDEF(MP_QSTR_Timer, (const byte*)"\xa2\x05" "Timer")
 QDEF(MP_QSTR_ONE_SHOT, (const byte*)"\x5e\x08" "ONE_SHOT")
 QDEF(MP_QSTR_PERIODIC, (const byte*)"\x0a\x08" "PERIODIC")
 QDEF(MP_QSTR_period, (const byte*)"\xa0\x06" "period")
+QDEF(MP_QSTR_set_color, (const byte*)"\x25\x09" "set_color")
 // This file was automatically generated by makeqstrdata.py

+ 14 - 0
port/machine_lcd.c

@@ -176,6 +176,19 @@ STATIC mp_obj_t machine_lcd_circle(size_t n_args, const mp_obj_t *args) {
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lcd_circle_obj, 4, 4, machine_lcd_circle);
 
+/// \method set_color(back, fore)
+///
+/// Set background color and foreground color.
+///
+STATIC mp_obj_t machine_lcd_set_color(size_t n_args, const mp_obj_t *args) {
+    rt_uint16_t back = mp_obj_get_int(args[1]);
+    rt_uint16_t fore = mp_obj_get_int(args[2]);
+
+    lcd_set_color(back, fore);
+    return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lcd_set_color_obj, 3, 3, machine_lcd_set_color);
+
 STATIC const mp_rom_map_elem_t machine_lcd_locals_dict_table[] = {
     // instance methods
     { 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[] = {
     { MP_ROM_QSTR(MP_QSTR_line),  MP_ROM_PTR(&machine_lcd_line_obj)  },
     { MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&machine_lcd_rectangle_obj) },
     { MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&machine_lcd_circle_obj) }, 
+    { MP_ROM_QSTR(MP_QSTR_set_color), MP_ROM_PTR(&machine_lcd_set_color_obj) }, 
     // color
     { MP_ROM_QSTR(MP_QSTR_WHITE), MP_ROM_INT(WHITE) },
     { MP_ROM_QSTR(MP_QSTR_BLACK), MP_ROM_INT(BLACK) },