Skip to content

Commit 9e0c00d

Browse files
committed
adding a backlight polarity flag to Display
1 parent 7bba793 commit 9e0c00d

File tree

18 files changed

+42
-23
lines changed

18 files changed

+42
-23
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
@@ -108,7 +108,8 @@ void board_init(void) {
108108
false, // single_byte_bounds
109109
false, // data_as_commands
110110
true, // auto_refresh
111-
60); // native_frames_per_second
111+
60, // native_frames_per_second
112+
true); // backlight_on_high
112113
}
113114

114115
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
@@ -88,7 +88,8 @@ void board_init(void) {
8888
false, // single_byte_bounds
8989
false, // data_as_commands
9090
true, // auto_refresh
91-
60); // native_frames_per_second
91+
60, // native_frames_per_second
92+
true); // backlight_on_high
9293
}
9394

9495
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
@@ -89,7 +89,8 @@ void board_init(void) {
8989
false, // single_byte_bounds
9090
false, // data_as_commands
9191
true, // auto_refresh
92-
60); // native_frames_per_second
92+
60, // native_frames_per_second
93+
true); // backlight_on_high
9394
}
9495

9596
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
@@ -139,7 +139,8 @@ void board_init(void) {
139139
false, // single_byte_bounds
140140
false, // data_as_commands
141141
false, // auto_refresh
142-
20); // native_frames_per_second
142+
20, // native_frames_per_second
143+
true); // backlight_on_high
143144
}
144145

145146
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
@@ -111,7 +111,8 @@ void board_init(void) {
111111
false, // single_byte_bounds
112112
false, // data_as_commands
113113
true, // auto_refresh
114-
60); // native_frames_per_second
114+
60, // native_frames_per_second
115+
true); // backlight_on_high
115116
}
116117

117118
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ void board_init(void) {
8989
false, // single_byte_bounds
9090
false, // data_as_commands
9191
true, // auto_refresh
92-
60); // native_frames_per_second
92+
60, // native_frames_per_second
93+
true); // backlight_on_high
9394
}
9495

9596
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
@@ -111,7 +111,8 @@ void board_init(void) {
111111
false, // single_byte_bounds
112112
false, // data_as_commands
113113
true, // auto_refresh
114-
60); // native_frames_per_second
114+
60, // native_frames_per_second
115+
true); // backlight_on_high
115116
}
116117

117118
bool board_requests_safe_mode(void) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ void board_init(void) {
8989
false, // single_byte_bounds
9090
false, // data_as_commands
9191
true, // auto_refresh
92-
60); // native_frames_per_second
92+
60, // native_frames_per_second
93+
true); // backlight_on_high
9394
}
9495

9596
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
@@ -100,7 +100,8 @@ void board_init(void) {
100100
false, // single_byte_bounds
101101
false, // data_as_commands
102102
true, // auto_refresh
103-
60); // native_frames_per_second
103+
60, // native_frames_per_second
104+
true); // backlight_on_high
104105
}
105106

106107
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
@@ -117,7 +117,8 @@ void board_init(void) {
117117
false, // single_byte_bounds
118118
false, // data_as_commands
119119
true, // auto_refresh
120-
60); // native_frames_per_second
120+
60, // native_frames_per_second
121+
true); // backlight_on_high
121122
}
122123

123124
bool board_requests_safe_mode(void) {

ports/atmel-samd/boards/ugame10/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
false, // single_byte_bounds
109109
false, // data as commands
110110
true, // auto_refresh
111-
60); // native_frames_per_second
111+
60, // native_frames_per_second
112+
true); // backlight_on_high
112113
}
113114

114115
bool board_requests_safe_mode(void) {

ports/nrf/boards/clue_nrf52840_express/board.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ void board_init(void) {
8888
false, // single_byte_bounds
8989
false, // data_as_commands
9090
true, // auto_refresh
91-
60); // native_frames_per_second
91+
60, // native_frames_per_second
92+
true); // backlight_on_high
9293
}
9394

9495
bool board_requests_safe_mode(void) {

ports/nrf/boards/ohs2020_badge/board.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,15 @@ void board_init(void) {
8181
0x37, // set vertical scroll command
8282
display_init_sequence,
8383
sizeof(display_init_sequence),
84-
//NULL, // backlight pin
85-
&pin_P0_02, // backlight pin
84+
&pin_P0_02, // backlight pin
8685
NO_BRIGHTNESS_COMMAND,
87-
0.0f, // brightness (ignored)
88-
false, // auto_brightness
86+
1.0f, // brightness (ignored)
87+
true, // auto_brightness
8988
false, // single_byte_bounds
9089
false, // data_as_commands
9190
true, // auto_refresh
92-
60); // native_frames_per_second
93-
91+
60, // native_frames_per_second
92+
false); // backlight_on_high
9493
}
9594

9695
bool board_requests_safe_mode(void) {

ports/stm/boards/meowbit_v121/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
false, // single_byte_bounds
110110
false, // data_as_commands
111111
true, // auto_refresh
112-
60); // native_frames_per_second
112+
60, // native_frames_per_second
113+
true); // backlight_on_high
113114
}
114115

115116
bool board_requests_safe_mode(void) {

shared-bindings/displayio/Display.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@
104104
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
105105
//| :param bool auto_refresh: Automatically refresh the screen
106106
//| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
107+
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on.
107108
//|
108109
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
109-
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second };
110+
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
110111
static const mp_arg_t allowed_args[] = {
111112
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
112113
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -132,6 +133,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
132133
{ MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
133134
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
134135
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
136+
{ MP_QSTR_backlight_on_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
135137
};
136138
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
137139
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -178,7 +180,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
178180
args[ARG_single_byte_bounds].u_bool,
179181
args[ARG_data_as_commands].u_bool,
180182
args[ARG_auto_refresh].u_bool,
181-
args[ARG_native_frames_per_second].u_int
183+
args[ARG_native_frames_per_second].u_int,
184+
args[ARG_backlight_on_high].u_bool
182185
);
183186

184187
return self;

shared-bindings/displayio/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
4545
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
4646
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command,
4747
mp_float_t brightness, bool auto_brightness,
48-
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second);
48+
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high);
4949

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

shared-module/displayio/Display.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
5050
uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll,
5151
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin,
5252
uint16_t brightness_command, mp_float_t brightness, bool auto_brightness,
53-
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second) {
53+
bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high) {
5454
// Turn off auto-refresh as we init.
5555
self->auto_refresh = false;
5656
uint16_t ram_width = 0x100;
@@ -159,6 +159,9 @@ mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t*
159159

160160
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness) {
161161
self->updating_backlight = true;
162+
if (!self->backlight_on_high){
163+
brightness = 1.0-brightness;
164+
}
162165
bool ok = false;
163166
if (self->backlight_pwm.base.type == &pulseio_pwmout_type) {
164167
common_hal_pulseio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness));

shared-module/displayio/Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct {
5555
bool data_as_commands;
5656
bool auto_brightness;
5757
bool updating_backlight;
58+
bool backlight_on_high;
5859
} displayio_display_obj_t;
5960

6061
void displayio_display_background(displayio_display_obj_t* self);

0 commit comments

Comments
 (0)