Skip to content

Commit 80ae142

Browse files
authored
Merge pull request #6416 from FoamyGuy/display_brightness_pwm
display brightness pwm 500hz frequency
2 parents ac282b2 + 67de898 commit 80ae142

File tree

32 files changed

+67
-35
lines changed

32 files changed

+67
-35
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void board_init(void) {
111111
true, // auto_refresh
112112
60, // native_frames_per_second
113113
true, // backlight_on_high
114-
false); // not SH1107
114+
false, // not SH1107
115+
50000); // backlight pwm frequency
115116
}
116117

117118
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void board_init(void) {
9191
true, // auto_refresh
9292
60, // native_frames_per_second
9393
true, // backlight_on_high
94-
false); // not SH1107
94+
false, // not SH1107
95+
50000); // backlight pwm frequency
9596
}
9697

9798
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
true, // auto_refresh
9393
60, // native_frames_per_second
9494
true, // backlight_on_high
95-
false); // SH1107_addressing
95+
false, // SH1107_addressing
96+
50000); // backlight pwm frequency
9697
}
9798

9899
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ void board_init(void) {
9090
true, // auto_refresh
9191
2, // native_frames_per_second
9292
true, // backlight_on_high
93-
true); // SH1107_addressing
93+
true, // SH1107_addressing
94+
50000); // backlight pwm frequency
9495
}
9596

9697
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ void board_init(void) {
144144
false, // auto_refresh
145145
20, // native_frames_per_second
146146
true, // backlight_on_high
147-
false); // SH1107_addressing
147+
false, // SH1107_addressing
148+
50000); // backlight pwm frequency
148149
}
149150

150151
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ void board_init(void) {
114114
true, // auto_refresh
115115
60, // native_frames_per_second
116116
true, // backlight_on_high
117-
false); // SH1107_addressing
117+
false, // SH1107_addressing
118+
50000); // backlight pwm frequency
118119
}
119120

120121
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ void board_init(void) {
114114
true, // auto_refresh
115115
60, // native_frames_per_second
116116
true, // backlight_on_high
117-
false); // SH1107_addressing
117+
false, // SH1107_addressing
118+
50000); // backlight pwm frequency
118119
}
119120

120121
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ void board_init(void) {
101101
true, // auto_refresh
102102
60, // native_frames_per_second
103103
true, // backlight_on_high
104-
false); // SH1107_addressing
104+
false, // SH1107_addressing
105+
50000); // backlight pwm frequency
105106
}
106107

107108
bool board_requests_safe_mode(void) {

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) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void board_init(void) {
109109
true, // auto_refresh
110110
60, // native_frames_per_second
111111
true, // backlight_on_high
112-
false); // SH1107_addressing
112+
false, // SH1107_addressing
113+
50000); // backlight pwm frequency
113114

114115
// Enabling the Power of the 40-pin at the back
115116
CTR_5V.base.type = &digitalio_digitalinout_type;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void board_init(void) {
111111
true, // auto_refresh
112112
60, // native_frames_per_second
113113
true, // backlight_on_high
114-
false); // SH1107_addressing
114+
false, // SH1107_addressing
115+
50000); // backlight pwm frequency
115116
}
116117

117118
bool board_requests_safe_mode(void) {

ports/espressif/boards/adafruit_esp32s2_camera/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ void board_init(void) {
9696
true, // auto_refresh
9797
60, // native_frames_per_second
9898
true, // backlight_on_high
99-
false); // not SH1107
99+
false, // not SH1107
100+
50000); // backlight pwm frequency
100101
}
101102

102103
bool board_requests_safe_mode(void) {

ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ void board_init(void) {
125125
true, // auto_refresh
126126
60, // native_frames_per_second
127127
true, // backlight_on_high
128-
false // SH1107_addressing
128+
false, // SH1107_addressing
129+
50000 // backlight pwm frequency
129130
);
130131

131132
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin

ports/espressif/boards/adafruit_feather_esp32s2_tftback_nopsram/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ void board_init(void) {
101101
true, // auto_refresh
102102
60, // native_frames_per_second
103103
true, // backlight_on_high
104-
false); // not SH1107
104+
false, // not SH1107
105+
50000); // backlight pwm frequency
105106
*/
106107
}
107108

ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ void board_init(void) {
125125
true, // auto_refresh
126126
60, // native_frames_per_second
127127
true, // backlight_on_high
128-
false // SH1107_addressing
128+
false, // SH1107_addressing
129+
50000 // backlight pwm frequency
129130
);
130131

131132
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin

ports/espressif/boards/adafruit_funhouse/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ void board_init(void) {
104104
true, // auto_refresh
105105
60, // native_frames_per_second
106106
true, // backlight_on_high
107-
false); // not SH1107
107+
false, // not SH1107
108+
50000); // backlight pwm frequency
108109
}
109110

110111
bool board_requests_safe_mode(void) {

ports/espressif/boards/espressif_esp32s3_box/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ void board_init(void) {
8787
true, // auto_refresh
8888
60, // native_frames_per_second
8989
true, // backlight_on_high
90-
false); // SH1107_addressing
90+
false, // SH1107_addressing
91+
50000); // backlight pwm frequency
9192

9293
// Debug UART
9394
#ifdef DEBUG

ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ void board_init(void) {
115115
true, // auto_refresh
116116
60, // native_frames_per_second
117117
true, // backlight_on_high
118-
false); // SH1107_addressing
118+
false, // SH1107_addressing
119+
50000); // backlight pwm frequency
119120
}
120121

121122
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {

ports/espressif/boards/hexky_s2/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void board_init(void) {
119119
true, // auto_refresh
120120
60, // native_frames_per_second
121121
true, // backlight_on_high
122-
false // SH1107_addressing
122+
false, // SH1107_addressing
123+
50000 // backlight pwm frequency
123124
);
124125

125126
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin

ports/espressif/boards/hiibot_iots2/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ static void display_init(void) {
124124
true, // auto_refresh
125125
60, // native_frames_per_second
126126
true, // backlight_on_high
127-
false // SH1107_addressing
127+
false, // SH1107_addressing
128+
50000 // backlight pwm frequency
128129
);
129130

130131
common_hal_never_reset_pin(&pin_GPIO38); // backlight pin

ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ static void display_init(void) {
124124
true, // auto_refresh
125125
60, // native_frames_per_second
126126
true, // backlight_on_high
127-
false // SH1107_addressing
127+
false, // SH1107_addressing
128+
50000 // backlight pwm frequency
128129
);
129130

130131
common_hal_never_reset_pin(&pin_GPIO33); // backlight pin

ports/espressif/boards/morpheans_morphesp-240/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ void board_init(void) {
205205
true, // auto_refresh
206206
60, // native_frames_per_second
207207
false, // backlight_on_high
208-
false // SH1107_addressing
208+
false, // SH1107_addressing
209+
50000 // backlight pwm frequency
209210
);
210211
}
211212

ports/nrf/boards/clue_nrf52840_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void board_init(void) {
9191
true, // auto_refresh
9292
60, // native_frames_per_second
9393
true, // backlight_on_high
94-
false); // not SH1107
94+
false, // not SH1107
95+
50000); // backlight pwm frequency
9596
}
9697

9798
bool board_requests_safe_mode(void) {

ports/nrf/boards/hiibot_bluefi/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
true, // auto_refresh
9393
60, // native_frames_per_second
9494
true, // backlight_on_high
95-
false); // SH1107_addressing
95+
false, // SH1107_addressing
96+
50000); // backlight pwm frequency
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ void board_init(void) {
9292
true, // auto_refresh
9393
60, // native_frames_per_second
9494
true, // backlight_on_high
95-
false); // SH1107_addressing
95+
false, // SH1107_addressing
96+
50000); // backlight pwm frequency
9697
}
9798

9899
bool board_requests_safe_mode(void) {

ports/nrf/boards/ohs2020_badge/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void board_init(void) {
9191
true, // auto_refresh
9292
60, // native_frames_per_second
9393
false, // backlight_on_high
94-
false); // SH1107_addressing
94+
false, // SH1107_addressing
95+
50000); // backlight pwm frequency
9596
}
9697

9798
bool board_requests_safe_mode(void) {

ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ void board_init(void) {
103103
true, // auto_refresh
104104
60, // native_frames_per_second
105105
true, // backlight_on_high
106-
true); // SH1107_addressing
106+
true, // SH1107_addressing
107+
50000); // backlight pwm frequency
107108
}
108109

109110
bool board_requests_safe_mode(void) {

ports/raspberrypi/boards/pimoroni_picosystem/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ void board_init(void) {
108108
true, // auto_refresh
109109
60, // native_frames_per_second
110110
true, // backlight_on_high
111-
false); // SH1107_addressing
111+
false, // SH1107_addressing
112+
50000); // backlight pwm frequency
112113
}
113114

114115
void board_deinit(void) {

ports/stm/boards/meowbit_v121/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ void board_init(void) {
111111
true, // auto_refresh
112112
60, // native_frames_per_second
113113
true, // backlight_on_high
114-
false); // SH1107_addressing
114+
false, // SH1107_addressing
115+
50000); // backlight pwm frequency
115116

116117
board_buzz_obj.base.type = &audiopwmio_pwmaudioout_type;
117118
common_hal_audiopwmio_pwmaudioout_construct(&board_buzz_obj,

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, 50000, 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)