Skip to content

Commit ffc451b

Browse files
committed
argument for backlight_pwm_frequency and use it in pyportal titano build
1 parent 6b04b7e commit ffc451b

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

ports/atmel-samd/boards/pyportal_titano/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ void board_init(void) {
118118
true, // auto_refresh
119119
60, // native_frames_per_second
120120
true, // backlight_on_high
121-
false); // SH1107_addressing
121+
false, // SH1107_addressing
122+
500); // backlight_pwm_frequency
122123
}
123124

124125
bool board_requests_safe_mode(void) {

shared-bindings/displayio/Display.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on.
112112
//| :param bool SH1107_addressing: Special quirk for SH1107, use upper/lower column set and page set
113113
//| :param int set_vertical_scroll: This parameter is accepted but ignored for backwards compatibility. It will be removed in a future release.
114+
//| :param int backlight_pwm_frequency: The frequency to use to drive the PWM for backlight brightness control. Default is 50000.
114115
//| """
115116
//| ...
116117
//|
@@ -123,7 +124,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
123124
ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command,
124125
ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands,
125126
ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high,
126-
ARG_SH1107_addressing };
127+
ARG_SH1107_addressing, ARG_backlight_pwm_frequency };
127128
static const mp_arg_t allowed_args[] = {
128129
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
129130
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -151,7 +152,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
151152
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
152153
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
153154
{ MP_QSTR_backlight_on_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
154-
{ MP_QSTR_SH1107_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }
155+
{ MP_QSTR_SH1107_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
156+
{ MP_QSTR_backlight_pwm_frequency, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50000} }
155157
};
156158
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
157159
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -200,7 +202,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
200202
args[ARG_auto_refresh].u_bool,
201203
args[ARG_native_frames_per_second].u_int,
202204
args[ARG_backlight_on_high].u_bool,
203-
sh1107_addressing
205+
sh1107_addressing,
206+
args[ARG_backlight_pwm_frequency].u_int
204207
);
205208

206209
return self;

shared-bindings/displayio/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
4444
uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin, uint16_t brightness_command,
4545
mp_float_t brightness, bool auto_brightness,
4646
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
47-
bool backlight_on_high, bool SH1107_addressing);
47+
bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency);
4848

4949
bool common_hal_displayio_display_show(displayio_display_obj_t *self,
5050
displayio_group_t *root_group);

shared-module/displayio/Display.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
5353
uint8_t *init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t *backlight_pin,
5454
uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
5555
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second,
56-
bool backlight_on_high, bool SH1107_addressing) {
56+
bool backlight_on_high, bool SH1107_addressing, uint16_t backlight_pwm_frequency) {
5757

5858
// Turn off auto-refresh as we init.
5959
self->auto_refresh = false;
@@ -116,7 +116,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
116116
if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) {
117117
// Avoid PWM types and functions when the module isn't enabled
118118
#if (CIRCUITPY_PWMIO)
119-
pwmout_result_t result = common_hal_pwmio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 500, false);
119+
pwmout_result_t result = common_hal_pwmio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, backlight_pwm_frequency, false);
120120
if (result != PWMOUT_OK) {
121121
self->backlight_inout.base.type = &digitalio_digitalinout_type;
122122
common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin);

0 commit comments

Comments
 (0)