Skip to content

Commit db86a75

Browse files
committed
Add mutable brightness
1 parent e5fb28d commit db86a75

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

ports/espressif/common-hal/microcontroller/Pin.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,8 @@ static const uint64_t pin_mask_reset_forbidden =
204204
#endif // ESP32H2
205205

206206
#if defined(CONFIG_IDF_TARGET_ESP32P4)
207-
// Never ever reset pins used to communicate with the SPI flash.
208-
GPIO_SEL_28 |
209-
GPIO_SEL_29 |
210-
GPIO_SEL_30 |
211-
GPIO_SEL_32 |
212-
GPIO_SEL_33 |
213-
GPIO_SEL_34 |
207+
// SPI flash is on dedicated pins.
208+
214209
// USB is on the FS OTG
215210
#if CIRCUITPY_USB_DEVICE_INSTANCE == 0
216211
#if CIRCUITPY_ESP32P4_SWAP_LSFS == 1

ports/espressif/common-hal/mipidsi/Display.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,40 @@ void common_hal_mipidsi_display_refresh(mipidsi_display_obj_t *self) {
222222
// sends data from the framebuffer to the display
223223
}
224224

225+
mp_float_t common_hal_mipidsi_display_get_brightness(mipidsi_display_obj_t *self) {
226+
return self->current_brightness;
227+
}
228+
229+
bool common_hal_mipidsi_display_set_brightness(mipidsi_display_obj_t *self, mp_float_t brightness) {
230+
if (!self->backlight_on_high) {
231+
brightness = 1.0 - brightness;
232+
}
233+
bool ok = false;
234+
235+
// Avoid PWM types and functions when the module isn't enabled
236+
#if (CIRCUITPY_PWMIO)
237+
bool ispwm = (self->backlight_pwm.base.type == &pwmio_pwmout_type) ? true : false;
238+
#else
239+
bool ispwm = false;
240+
#endif
241+
242+
if (ispwm) {
243+
#if (CIRCUITPY_PWMIO)
244+
common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t)(0xffff * brightness));
245+
ok = true;
246+
#else
247+
ok = false;
248+
#endif
249+
} else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) {
250+
common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99);
251+
ok = true;
252+
}
253+
if (ok) {
254+
self->current_brightness = brightness;
255+
}
256+
return ok;
257+
}
258+
225259
int common_hal_mipidsi_display_get_width(mipidsi_display_obj_t *self) {
226260
return self->width;
227261
}

ports/espressif/common-hal/mipidsi/Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ typedef struct {
3434
#endif
3535
};
3636
bool backlight_on_high;
37+
mp_float_t current_brightness;
3738
} mipidsi_display_obj_t;

shared-bindings/mipidsi/Display.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ static void mipidsi_display_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufi
220220
common_hal_mipidsi_display_get_buffer(self_in, bufinfo, 0);
221221
}
222222

223+
static float mipidsi_display_get_brightness_proto(mp_obj_t self_in) {
224+
return common_hal_mipidsi_display_get_brightness(self_in);
225+
}
226+
227+
static bool mipidsi_display_set_brightness_proto(mp_obj_t self_in, mp_float_t value) {
228+
common_hal_mipidsi_display_set_brightness(self_in, value);
229+
return true;
230+
}
231+
223232
// These versions exist so that the prototype matches the protocol,
224233
// avoiding a type cast that can hide errors
225234
static void mipidsi_display_swapbuffers(mp_obj_t self_in, uint8_t *dirty_row_bitmap) {
@@ -266,6 +275,8 @@ static int mipidsi_display_get_row_stride_proto(mp_obj_t self_in) {
266275
static const framebuffer_p_t mipidsi_display_proto = {
267276
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
268277
.get_bufinfo = mipidsi_display_get_bufinfo,
278+
.set_brightness = mipidsi_display_set_brightness_proto,
279+
.get_brightness = mipidsi_display_get_brightness_proto,
269280
.get_width = mipidsi_display_get_width_proto,
270281
.get_height = mipidsi_display_get_height_proto,
271282
.get_color_depth = mipidsi_display_get_color_depth_proto,

shared-bindings/mipidsi/Display.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void common_hal_mipidsi_display_construct(mipidsi_display_obj_t *self,
3535
void common_hal_mipidsi_display_deinit(mipidsi_display_obj_t *self);
3636
bool common_hal_mipidsi_display_deinited(mipidsi_display_obj_t *self);
3737
void common_hal_mipidsi_display_refresh(mipidsi_display_obj_t *self);
38+
mp_float_t common_hal_mipidsi_display_get_brightness(mipidsi_display_obj_t *self);
39+
bool common_hal_mipidsi_display_set_brightness(mipidsi_display_obj_t *self, mp_float_t brightness);
3840
int common_hal_mipidsi_display_get_width(mipidsi_display_obj_t *self);
3941
int common_hal_mipidsi_display_get_height(mipidsi_display_obj_t *self);
4042
int common_hal_mipidsi_display_get_row_stride(mipidsi_display_obj_t *self);

0 commit comments

Comments
 (0)