diff --git a/scripts/libraries/display.py b/scripts/libraries/display.py index 828559b3a..77587991f 100644 --- a/scripts/libraries/display.py +++ b/scripts/libraries/display.py @@ -5,13 +5,39 @@ # # This work is licensed under the MIT license, see the file LICENSE for details. # -# This is an extension to the display C user-module. Add any display-related -# drivers here, and freeze this module in the board's manifest, and those -# drivers will be importable from display. +# This is an extension to the display C user-module. Add or import any display-related +# drivers here, and freeze this module in the board's manifest, and those drivers will +# be importable from display. from udisplay import * import time +class DACBacklight: + def __init__(self, channel, bits=8): + from pyb import DAC + self.bits = bits + self.dac = DAC(channel, bits=bits, buffering=True) + self.backlight(100) + + def deinit(self): + self.dac.deinit() + + def backlight(self, value): + self.dac.write(int(value / 100 * (2 ** self.bits - 1))) + +class PWMBacklight: + def __init__(self, pin, timer=3, channel=3, frequency=200): + from machine import Pin + from pyb import Timer + self.timer = Timer(timer, freq=frequency) + self.channel = self.timer.channel(channel, Timer.PWM, pin=Pin(pin)) + self.backlight(100) + + def deinit(self): + self.timer.deinit() + + def backlight(self, value): + self.channel.pulse_width_percent(value * 100 // 100) class ST7701: DSI_CMD2_BKX_SEL = const(0xFF) diff --git a/src/omv/boards/ARDUINO_PORTENTA_H7/manifest.py b/src/omv/boards/ARDUINO_PORTENTA_H7/manifest.py index aa6e5549c..611fa8268 100644 --- a/src/omv/boards/ARDUINO_PORTENTA_H7/manifest.py +++ b/src/omv/boards/ARDUINO_PORTENTA_H7/manifest.py @@ -13,6 +13,7 @@ freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "bno055.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") # Networking require("ntptime") diff --git a/src/omv/boards/OPENMV2/manifest.py b/src/omv/boards/OPENMV2/manifest.py index 407a15716..c6b7971ca 100644 --- a/src/omv/boards/OPENMV2/manifest.py +++ b/src/omv/boards/OPENMV2/manifest.py @@ -10,3 +10,4 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") diff --git a/src/omv/boards/OPENMV3/manifest.py b/src/omv/boards/OPENMV3/manifest.py index 407a15716..c6b7971ca 100644 --- a/src/omv/boards/OPENMV3/manifest.py +++ b/src/omv/boards/OPENMV3/manifest.py @@ -10,3 +10,4 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") diff --git a/src/omv/boards/OPENMV4/manifest.py b/src/omv/boards/OPENMV4/manifest.py index 3ae7aa433..6424c9f64 100644 --- a/src/omv/boards/OPENMV4/manifest.py +++ b/src/omv/boards/OPENMV4/manifest.py @@ -12,6 +12,7 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") # Networking require("ntptime") diff --git a/src/omv/boards/OPENMV4P/manifest.py b/src/omv/boards/OPENMV4P/manifest.py index 3ae7aa433..6424c9f64 100644 --- a/src/omv/boards/OPENMV4P/manifest.py +++ b/src/omv/boards/OPENMV4P/manifest.py @@ -12,6 +12,7 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") # Networking require("ntptime") diff --git a/src/omv/boards/OPENMV4_PRO/manifest.py b/src/omv/boards/OPENMV4_PRO/manifest.py index 3ae7aa433..6424c9f64 100644 --- a/src/omv/boards/OPENMV4_PRO/manifest.py +++ b/src/omv/boards/OPENMV4_PRO/manifest.py @@ -12,6 +12,7 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") # Networking require("ntptime") diff --git a/src/omv/boards/OPENMVPT/manifest.py b/src/omv/boards/OPENMVPT/manifest.py index 3ae7aa433..6424c9f64 100644 --- a/src/omv/boards/OPENMVPT/manifest.py +++ b/src/omv/boards/OPENMVPT/manifest.py @@ -12,6 +12,7 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") # Networking require("ntptime") diff --git a/src/omv/boards/OPENMV_RT1060/manifest.py b/src/omv/boards/OPENMV_RT1060/manifest.py index a4c1dd7df..dedbb1e35 100644 --- a/src/omv/boards/OPENMV_RT1060/manifest.py +++ b/src/omv/boards/OPENMV_RT1060/manifest.py @@ -12,6 +12,7 @@ freeze ("$(OMV_LIB_DIR)/", "ssd1306.py") freeze ("$(OMV_LIB_DIR)/", "tb6612.py") freeze ("$(OMV_LIB_DIR)/", "vl53l1x.py") freeze ("$(OMV_LIB_DIR)/", "machine.py") +freeze ("$(OMV_LIB_DIR)/", "display.py") # Networking require("ntptime")