Skip to content

Commit 1214b69

Browse files
committed
Pervasive Displays Aurora E-paper driver
1 parent d86e072 commit 1214b69

File tree

14 files changed

+903
-1
lines changed

14 files changed

+903
-1
lines changed

py/circuitpy_defns.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ endif
134134
ifeq ($(CIRCUITPY_AUDIOMP3),1)
135135
SRC_PATTERNS += audiomp3/%
136136
endif
137+
ifeq ($(CIRCUITPY_AURORA_EPAPER),1)
138+
SRC_PATTERNS += aurora_epaper/%
139+
endif
137140
ifeq ($(CIRCUITPY_BITBANGIO),1)
138141
SRC_PATTERNS += bitbangio/%
139142
endif
@@ -618,6 +621,8 @@ SRC_SHARED_MODULE_ALL = \
618621
audiomp3/MP3Decoder.c \
619622
audiomp3/__init__.c \
620623
audiopwmio/__init__.c \
624+
aurora_epaper/aurora_framebuffer.c \
625+
aurora_epaper/__init__.c \
621626
bitbangio/I2C.c \
622627
bitbangio/SPI.c \
623628
bitbangio/__init__.c \

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG)
138138
CIRCUITPY_AUDIOMP3 ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_AUDIOCORE))
139139
CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3)
140140

141+
CIRCUITPY_AURORA_EPAPER ?=$(CIRCUITPY_FRAMEBUFFERIO)
142+
CFLAGS += -DCIRCUITPY_AURORA_EPAPER=$(CIRCUITPY_AURORA_EPAPER)
143+
141144
CIRCUITPY_BINASCII ?= $(CIRCUITPY_FULL_BUILD)
142145
CFLAGS += -DCIRCUITPY_BINASCII=$(CIRCUITPY_BINASCII)
143146

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdint.h>
2+
3+
#include "py/obj.h"
4+
#include "py/runtime.h"
5+
6+
#include "shared-bindings/aurora_epaper/aurora_framebuffer.h"
7+
8+
STATIC const mp_rom_map_elem_t aurora_epaper_module_globals_table[] = {
9+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_aurora_epaper) },
10+
{ MP_ROM_QSTR(MP_QSTR_AuroraMemoryFramebuffer), MP_ROM_PTR(&aurora_framebuffer_type) },
11+
};
12+
13+
static MP_DEFINE_CONST_DICT(aurora_epaper_globals, aurora_epaper_module_globals_table);
14+
15+
const mp_obj_module_t aurora_epaper_module = {
16+
.base = {&mp_type_module},
17+
.globals = (mp_obj_dict_t *)&aurora_epaper_globals,
18+
};
19+
20+
MP_REGISTER_MODULE(MP_QSTR_aurora_epaper, aurora_epaper_module);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#pragma once
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (c) wyrdsec (MIT License)
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
* - The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
* - The Software is provided "as is", without warranty of any kind, express or
13+
* implied, including but not limited to the warranties of merchantability,
14+
* fitness for a particular purpose and noninfringement. In no event shall the
15+
* authors or copyright holders be liable for any claim, damages or other
16+
* liability, whether in an action of contract, tort or otherwise, arising from,
17+
* out of or in connection with the Software or the use or other dealings in the
18+
* Software.
19+
*/
20+
#include "py/objarray.h"
21+
#include "py/runtime.h"
22+
#include "py/objproperty.h"
23+
24+
25+
#include "shared-bindings/aurora_epaper/aurora_framebuffer.h"
26+
#include "shared-module/aurora_epaper/aurora_framebuffer.h"
27+
#include "shared-bindings/busio/SPI.h"
28+
#include "shared-bindings/microcontroller/Pin.h"
29+
#include "shared-module/displayio/__init__.h"
30+
31+
32+
static mp_obj_t aurora_epaper_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
33+
enum { ARG_spi_bus, ARG_chip_select, ARG_reset, ARG_busy, ARG_discharge, ARG_width, ARG_height, ARG_power, ARG_free_bus, NUM_ARGS };
34+
static const mp_arg_t allowed_args[] = {
35+
{ MP_QSTR_spi_bus, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} },
36+
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} },
37+
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} },
38+
{ MP_QSTR_busy, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} },
39+
{ MP_QSTR_discharge, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} },
40+
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED, {.u_int = 0} },
41+
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED, {.u_int = 0} },
42+
{ MP_QSTR_power, MP_ARG_OBJ, {.u_obj = mp_const_none} },
43+
{ MP_QSTR_free_bus, MP_ARG_BOOL, {.u_bool = true} },
44+
};
45+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
46+
MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS);
47+
48+
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
49+
50+
// Pins
51+
const mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj, MP_QSTR_chip_select);
52+
const mcu_pin_obj_t *reset = validate_obj_is_free_pin(args[ARG_reset].u_obj, MP_QSTR_reset);
53+
const mcu_pin_obj_t *busy = validate_obj_is_free_pin(args[ARG_busy].u_obj, MP_QSTR_busy);
54+
const mcu_pin_obj_t *discharge = validate_obj_is_free_pin(args[ARG_discharge].u_obj, MP_QSTR_discharge);
55+
const mcu_pin_obj_t *power = validate_obj_is_free_pin_or_none(args[ARG_power].u_obj, MP_QSTR_power);
56+
57+
busio_spi_obj_t *spi = validate_obj_is_spi_bus(args[ARG_spi_bus].u_obj, MP_QSTR_spi_bus);
58+
aurora_epaper_framebuffer_obj_t *self = &allocate_display_bus_or_raise()->aurora_epaper;
59+
self->base.type = &aurora_framebuffer_type;
60+
61+
common_hal_aurora_epaper_framebuffer_construct(self, spi, chip_select, reset, busy, discharge, power, args[ARG_width].u_int, args[ARG_height].u_int, args[ARG_free_bus].u_bool);
62+
return MP_OBJ_FROM_PTR(self);
63+
}
64+
65+
static mp_int_t aurora_epaper_framebuffer_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
66+
aurora_epaper_framebuffer_obj_t *self = self_in;
67+
if ((flags & MP_BUFFER_WRITE) && !(self->bufinfo.typecode & MP_OBJ_ARRAY_TYPECODE_FLAG_RW)) {
68+
return 1;
69+
}
70+
*bufinfo = self->bufinfo;
71+
return 0;
72+
}
73+
74+
75+
static mp_obj_t aurora_epaper_framebuffer_deinit(mp_obj_t self_in) {
76+
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
77+
common_hal_aurora_epaper_framebuffer_deinit(self);
78+
79+
return mp_const_none;
80+
}
81+
static MP_DEFINE_CONST_FUN_OBJ_1(aurora_epaper_framebuffer_deinit_obj, aurora_epaper_framebuffer_deinit);
82+
83+
84+
static mp_obj_t aurora_epaper_frambuffer_set_temperature(mp_obj_t self_in, mp_obj_t temperature) {
85+
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
86+
87+
common_hal_aurora_epaper_framebuffer_set_temperature(self, mp_obj_get_float(temperature));
88+
89+
return mp_const_none;
90+
}
91+
static MP_DEFINE_CONST_FUN_OBJ_2(aurora_epaper_frambuffer_set_temperature_obj, aurora_epaper_frambuffer_set_temperature);
92+
93+
94+
static mp_obj_t aurora_epaper_framebuffer_get_free_bus(mp_obj_t self_in) {
95+
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
96+
return mp_obj_new_bool(self->free_bus);
97+
}
98+
static MP_DEFINE_CONST_FUN_OBJ_1(aurora_epaper_framebuffer_get_free_bus_obj, aurora_epaper_framebuffer_get_free_bus);
99+
100+
101+
static mp_obj_t aurora_epaper_framebuffer_set_free_bus(mp_obj_t self_in, mp_obj_t free_bus) {
102+
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
103+
common_hal_aurora_epaper_framebuffer_set_free_bus(self, mp_obj_is_true(free_bus));
104+
return mp_const_none;
105+
}
106+
static MP_DEFINE_CONST_FUN_OBJ_2(aurora_epaper_framebuffer_set_free_bus_obj, aurora_epaper_framebuffer_set_free_bus);
107+
108+
MP_PROPERTY_GETSET(aurora_epaper_framebuffer_free_bus_obj,
109+
(mp_obj_t)&aurora_epaper_framebuffer_get_free_bus_obj,
110+
(mp_obj_t)&aurora_epaper_framebuffer_set_free_bus_obj);
111+
112+
static const mp_rom_map_elem_t aurora_epaper_framebuffer_locals_dict_table[] = {
113+
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&aurora_epaper_framebuffer_deinit_obj) },
114+
{ MP_ROM_QSTR(MP_QSTR_set_temperature), MP_ROM_PTR(&aurora_epaper_frambuffer_set_temperature_obj) },
115+
{ MP_ROM_QSTR(MP_QSTR_free_bus), MP_ROM_PTR(&aurora_epaper_framebuffer_free_bus_obj) },
116+
};
117+
static MP_DEFINE_CONST_DICT(aurora_epaper_framebuffer_locals_dict, aurora_epaper_framebuffer_locals_dict_table);
118+
119+
MP_DEFINE_CONST_OBJ_TYPE(
120+
aurora_framebuffer_type,
121+
MP_QSTR_AuroraEpaperFramebuffer,
122+
MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS,
123+
make_new, aurora_epaper_framebuffer_make_new,
124+
locals_dict, &aurora_epaper_framebuffer_locals_dict,
125+
buffer, aurora_epaper_framebuffer_get_buffer,
126+
protocol, &aurora_epaper_framebuffer_proto
127+
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#include "py/objtype.h"
4+
#include "shared-module/aurora_epaper/aurora_framebuffer.h"
5+
6+
extern const mp_obj_type_t aurora_framebuffer_type;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
// No module functions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
#pragma once

0 commit comments

Comments
 (0)