Skip to content

Commit 70680d5

Browse files
committed
EPaper displays work mostly.
1 parent 8fa8737 commit 70680d5

28 files changed

Lines changed: 1123 additions & 335 deletions

ports/atmel-samd/common-hal/displayio/ParallelBus.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
8484
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
8585
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
8686
never_reset_pin_number(reset->number);
87-
88-
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
89-
common_hal_mcu_delay_us(4);
90-
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
87+
common_hal_displayio_parallelbus_reset(self);
9188
}
9289

9390
never_reset_pin_number(command->number);
@@ -111,13 +108,25 @@ void common_hal_displayio_parallelbus_deinit(displayio_parallelbus_obj_t* self)
111108
reset_pin_number(self->reset.pin->number);
112109
}
113110

111+
void common_hal_displayio_parallelbus_reset(mp_obj_t obj) {
112+
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
113+
114+
common_hal_digitalio_digitalinout_set_value(&self->reset, false);
115+
common_hal_mcu_delay_us(4);
116+
common_hal_digitalio_digitalinout_set_value(&self->reset, true);
117+
}
118+
119+
bool common_hal_displayio_parallelbus_bus_free(mp_obj_t obj) {
120+
return true;
121+
}
122+
114123
bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
115124
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
116125
common_hal_digitalio_digitalinout_set_value(&self->chip_select, false);
117126
return true;
118127
}
119128

120-
void common_hal_displayio_parallelbus_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) {
129+
void common_hal_displayio_parallelbus_send(mp_obj_t obj, bool command, bool toggle_every_byte, uint8_t *data, uint32_t data_length) {
121130
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
122131
common_hal_digitalio_digitalinout_set_value(&self->command, !command);
123132
uint32_t* clear_write = (uint32_t*) &self->write_group->OUTCLR.reg;

py/circuitpy_defns.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ SRC_SHARED_MODULE_ALL = \
320320
displayio/Bitmap.c \
321321
displayio/ColorConverter.c \
322322
displayio/Display.c \
323+
displayio/EPaperDisplay.c \
323324
displayio/FourWire.c \
324325
displayio/Group.c \
325326
displayio/I2CDisplay.c \

shared-bindings/displayio/EPaperDisplay.c

Lines changed: 130 additions & 201 deletions
Large diffs are not rendered by default.

shared-bindings/displayio/EPaperDisplay.h

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,52 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_EPAPERDISPLAY_H
28-
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_EPAPERDISPLAY_H
27+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_EPAPERDISPLAY_H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_EPAPERDISPLAY_H
2929

3030
#include "common-hal/microcontroller/Pin.h"
3131

32-
#include "shared-module/displayio/Display.h"
32+
#include "shared-module/displayio/EPaperDisplay.h"
3333
#include "shared-module/displayio/Group.h"
3434

3535
extern const mp_obj_type_t displayio_epaperdisplay_type;
3636

3737
#define DELAY 0x80
3838

39-
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
40-
mp_obj_t bus, uint16_t width, uint16_t height, uint16_t seconds_per_frame,
41-
uint16_t rotation, uint16_t color_depth, bool grayscale,
42-
uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* busy_pin, uint16_t partial_command);
39+
#define NO_COMMAND 0x100
4340

44-
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self);
41+
void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t* self,
42+
mp_obj_t bus, uint8_t* start_sequence, uint16_t start_sequence_len, uint8_t* stop_sequence, uint16_t stop_sequence_len,
43+
uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation,
44+
uint16_t set_column_window_command, uint16_t set_row_window_command,
45+
uint16_t set_current_column_command, uint16_t set_current_row_command,
46+
uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t third_color, uint16_t refresh_display_command,
47+
const mcu_pin_obj_t* busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select);
4548

46-
void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group);
49+
int32_t common_hal_displayio_epaperdisplay_wait_for_frame(displayio_epaperdisplay_obj_t* self);
4750

48-
void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self);
51+
bool common_hal_displayio_epaperdisplay_show(displayio_epaperdisplay_obj_t* self, displayio_group_t* root_group);
4952

50-
bool displayio_display_begin_transaction(displayio_display_obj_t* self);
51-
void displayio_display_end_transaction(displayio_display_obj_t* self);
53+
void common_hal_displayio_epaperdisplay_refresh_soon(displayio_epaperdisplay_obj_t* self);
54+
55+
bool displayio_epaperdisplay_begin_transaction(displayio_epaperdisplay_obj_t* self);
56+
void displayio_epaperdisplay_end_transaction(displayio_epaperdisplay_obj_t* self);
5257

5358
// The second point of the region is exclusive.
54-
void displayio_display_set_region_to_update(displayio_display_obj_t* self, displayio_area_t* area);
55-
bool displayio_display_frame_queued(displayio_display_obj_t* self);
59+
void displayio_epaperdisplay_set_region_to_update(displayio_epaperdisplay_obj_t* self, displayio_area_t* area);
60+
bool displayio_epaperdisplay_frame_queued(displayio_epaperdisplay_obj_t* self);
5661

57-
bool displayio_display_refresh_queued(displayio_display_obj_t* self);
58-
void displayio_display_finish_refresh(displayio_display_obj_t* self);
59-
void displayio_display_send_pixels(displayio_display_obj_t* self, uint8_t* pixels, uint32_t length);
62+
bool displayio_epaperdisplay_refresh_queued(displayio_epaperdisplay_obj_t* self);
63+
void displayio_epaperdisplay_finish_refresh(displayio_epaperdisplay_obj_t* self);
64+
void displayio_epaperdisplay_send_pixels(displayio_epaperdisplay_obj_t* self, uint8_t* pixels, uint32_t length);
6065

61-
bool common_hal_displayio_display_get_auto_brightness(displayio_display_obj_t* self);
62-
void common_hal_displayio_display_set_auto_brightness(displayio_display_obj_t* self, bool auto_brightness);
66+
bool common_hal_displayio_epaperdisplay_get_auto_brightness(displayio_epaperdisplay_obj_t* self);
67+
void common_hal_displayio_epaperdisplay_set_auto_brightness(displayio_epaperdisplay_obj_t* self, bool auto_brightness);
6368

64-
uint16_t common_hal_displayio_display_get_width(displayio_display_obj_t* self);
65-
uint16_t common_hal_displayio_display_get_height(displayio_display_obj_t* self);
69+
uint16_t common_hal_displayio_epaperdisplay_get_width(displayio_epaperdisplay_obj_t* self);
70+
uint16_t common_hal_displayio_epaperdisplay_get_height(displayio_epaperdisplay_obj_t* self);
6671

67-
mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* self);
68-
bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness);
72+
mp_float_t common_hal_displayio_epaperdisplay_get_brightness(displayio_epaperdisplay_obj_t* self);
73+
bool common_hal_displayio_epaperdisplay_set_brightness(displayio_epaperdisplay_obj_t* self, mp_float_t brightness);
6974

70-
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_EPAPERDISPLAY_H
75+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_EPAPERDISPLAY_H

shared-bindings/displayio/FourWire.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,31 +103,41 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
103103
return self;
104104
}
105105

106-
//| .. method:: send(command, data)
106+
//| .. method:: send(command, data, *, toggle_every_byte=False)
107107
//|
108108
//| Sends the given command value followed by the full set of data. Display state, such as
109109
//| vertical scroll, set via ``send`` may or may not be reset once the code is done.
110110
//|
111-
STATIC mp_obj_t displayio_fourwire_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) {
112-
mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj);
113-
if (!MP_OBJ_IS_SMALL_INT(command_obj) || command_int > 255 || command_int < 0) {
111+
STATIC mp_obj_t displayio_fourwire_obj_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
112+
enum { ARG_command, ARG_data, ARG_toggle_every_byte };
113+
static const mp_arg_t allowed_args[] = {
114+
{ MP_QSTR_command, MP_ARG_INT | MP_ARG_REQUIRED },
115+
{ MP_QSTR_data, MP_ARG_OBJ | MP_ARG_REQUIRED },
116+
{ MP_QSTR_toggle_every_byte, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
117+
};
118+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
119+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
120+
121+
mp_int_t command_int = args[ARG_command].u_int;
122+
if (command_int > 255 || command_int < 0) {
114123
mp_raise_ValueError(translate("Command must be an int between 0 and 255"));
115124
}
125+
displayio_fourwire_obj_t *self = pos_args[0];
116126
uint8_t command = command_int;
117127
mp_buffer_info_t bufinfo;
118-
mp_get_buffer_raise(data_obj, &bufinfo, MP_BUFFER_READ);
128+
mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ);
119129

120130
// Wait for display bus to be available.
121131
while (!common_hal_displayio_fourwire_begin_transaction(self)) {
122132
RUN_BACKGROUND_TASKS;
123133
}
124-
common_hal_displayio_fourwire_send(self, true, &command, 1);
125-
common_hal_displayio_fourwire_send(self, false, ((uint8_t*) bufinfo.buf), bufinfo.len);
134+
common_hal_displayio_fourwire_send(self, true, args[ARG_toggle_every_byte].u_bool, &command, 1);
135+
common_hal_displayio_fourwire_send(self, false, args[ARG_toggle_every_byte].u_bool, ((uint8_t*) bufinfo.buf), bufinfo.len);
126136
common_hal_displayio_fourwire_end_transaction(self);
127137

128138
return mp_const_none;
129139
}
130-
MP_DEFINE_CONST_FUN_OBJ_3(displayio_fourwire_send_obj, displayio_fourwire_obj_send);
140+
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_fourwire_send_obj, 3, displayio_fourwire_obj_send);
131141

132142
STATIC const mp_rom_map_elem_t displayio_fourwire_locals_dict_table[] = {
133143
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_fourwire_send_obj) },

shared-bindings/displayio/FourWire.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
4040

4141
void common_hal_displayio_fourwire_deinit(displayio_fourwire_obj_t* self);
4242

43+
void common_hal_displayio_fourwire_reset(mp_obj_t self);
44+
bool common_hal_displayio_fourwire_bus_free(mp_obj_t self);
45+
4346
bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t self);
4447

45-
void common_hal_displayio_fourwire_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
48+
void common_hal_displayio_fourwire_send(mp_obj_t self, bool command, bool toggle_every_byte, uint8_t *data, uint32_t data_length);
4649

4750
void common_hal_displayio_fourwire_end_transaction(mp_obj_t self);
4851

shared-bindings/displayio/I2CDisplay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_ob
116116
uint8_t full_command[bufinfo.len + 1];
117117
full_command[0] = command;
118118
memcpy(full_command + 1, ((uint8_t*) bufinfo.buf), bufinfo.len);
119-
common_hal_displayio_i2cdisplay_send(self, true, full_command, bufinfo.len + 1);
119+
common_hal_displayio_i2cdisplay_send(self, true, false, full_command, bufinfo.len + 1);
120120
common_hal_displayio_i2cdisplay_end_transaction(self);
121121

122122
return mp_const_none;

shared-bindings/displayio/I2CDisplay.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ void common_hal_displayio_i2cdisplay_construct(displayio_i2cdisplay_obj_t* self,
3737

3838
void common_hal_displayio_i2cdisplay_deinit(displayio_i2cdisplay_obj_t* self);
3939

40+
void common_hal_displayio_i2cdisplay_reset(mp_obj_t self);
41+
bool common_hal_displayio_i2cdisplay_bus_free(mp_obj_t self);
42+
4043
bool common_hal_displayio_i2cdisplay_begin_transaction(mp_obj_t self);
4144

42-
void common_hal_displayio_i2cdisplay_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
45+
void common_hal_displayio_i2cdisplay_send(mp_obj_t self, bool command, bool toggle_every_byte, uint8_t *data, uint32_t data_length);
4346

4447
void common_hal_displayio_i2cdisplay_end_transaction(mp_obj_t self);
4548

shared-bindings/displayio/ParallelBus.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ STATIC mp_obj_t displayio_parallelbus_obj_send(mp_obj_t self, mp_obj_t command_o
124124
while (!common_hal_displayio_parallelbus_begin_transaction(self)) {
125125
RUN_BACKGROUND_TASKS;
126126
}
127-
common_hal_displayio_parallelbus_send(self, true, &command, 1);
128-
common_hal_displayio_parallelbus_send(self, false, ((uint8_t*) bufinfo.buf), bufinfo.len);
127+
common_hal_displayio_parallelbus_send(self, true, false, &command, 1);
128+
common_hal_displayio_parallelbus_send(self, false, false, ((uint8_t*) bufinfo.buf), bufinfo.len);
129129
common_hal_displayio_parallelbus_end_transaction(self);
130130

131131
return mp_const_none;

shared-bindings/displayio/ParallelBus.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* sel
4040

4141
void common_hal_displayio_parallelbus_deinit(displayio_parallelbus_obj_t* self);
4242

43+
void common_hal_displayio_parallelbus_reset(mp_obj_t self);
44+
bool common_hal_displayio_parallelbus_bus_free(mp_obj_t self);
45+
4346
bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t self);
4447

45-
void common_hal_displayio_parallelbus_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
48+
void common_hal_displayio_parallelbus_send(mp_obj_t self, bool command, bool toggle_every_byte, uint8_t *data, uint32_t data_length);
4649

4750
void common_hal_displayio_parallelbus_end_transaction(mp_obj_t self);
4851

0 commit comments

Comments
 (0)