8000 Fix hallowing and nrf builds · tannewt/circuitpython@ec03887 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec03887

Browse files
committed
Fix hallowing and nrf builds
1 parent 4672866 commit ec03887

File tree

9 files changed

+74
-65
lines changed

9 files changed

+74
-65
lines changed

ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ CHIP_FAMILY = samd21
1717

1818
# Include these Python libraries in firmware.
1919
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BusDevice
20-
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID
2120
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
2221
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel

ports/nrf/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ SRC_SHARED_MODULE = \
226226
displayio/OnDiskBitmap.c \
227227
displayio/Palette.c \
228228
displayio/Shape.c \
229-
displayio/Sprite.c \
230-
storage/__init__.c
229+
displayio/TileGrid.c \
230+
storage/__init__.c \
231+
terminalio/__init__.c \
232+
terminalio/Terminal.c
231233

232234

233235
ifndef EXCLUDE_PIXELBUF

ports/nrf/common-hal/pulseio/PWMOut.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,33 @@ STATIC NRF_PWM_Type* pwms[] = {
5555

5656
STATIC uint16_t pwm_seq[MP_ARRAY_SIZE(pwms)][CHANNELS_PER_PWM];
5757

58+
static uint8_t never_reset_pwm[MP_ARRAY_SIZE(pwms)];
59+
60+
void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
61+
for(int i=0; i < MP_ARRAY_SIZE(pwms); i++) {
62+
NRF_PWM_Type* pwm = pwms[i];
63+
if (pwm == self->pwm) {
64+
never_reset_pwm[i] += 1;
65+
}
66+
}
67+
68+
never_reset_pin_number(self->pin_number);
69+
}
70+
71+
void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
72+
for(int i=0; i < MP_ARRAY_SIZE(pwms); i++) {
73+
NRF_PWM_Type* pwm = pwms[i];
74+
if (pwm == self->pwm) {
75+
never_reset_pwm[i] -= 1;
76+
}
77+
}
78+
}
79+
5880
void pwmout_reset(void) {
5981
for(int i=0; i < MP_ARRAY_SIZE(pwms); i++) {
82+
if (never_reset_pwm[i] > 0) {
83+
continue;
84+
}
6085
NRF_PWM_Type* pwm = pwms[i];
6186

6287
pwm->ENABLE = 0;
@@ -104,19 +129,19 @@ bool convert_frequency(uint32_t frequency, uint16_t *countertop, nrf_pwm_clk_t *
104129
return false;
105130
}
106131

107-
void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
108-
const mcu_pin_obj_t* pin,
109-
uint16_t duty,
110-
uint32_t frequency,
111-
bool variable_frequency) {
132+
pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
133+
const mcu_pin_obj_t* pin,
134+
uint16_t duty,
135+
uint32_t frequency,
136+
bool variable_frequency) {
112137

113138
// We don't use the nrfx driver here because we want to dynamically allocate channels
114139
// as needed in an already-enabled PWM.
115140

116141
uint16_t countertop;
117142
nrf_pwm_clk_t base_clock;
118143
if (frequency == 0 || !convert_frequency(frequency, &countertop, &base_clock)) {
119-
mp_raise_ValueError(translate("Invalid PWM frequency"));
144+
return PWMOUT_INVALID_FREQUENCY;
120145
}
121146

122147
self->pwm = NULL;
@@ -158,7 +183,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
158183
}
159184

160185
if (self->pwm == NULL) {
161-
mp_raise_ValueError(translate("All PWM peripherals are in use"));
186+
return PWMOUT_ALL_TIMERS_IN_USE;
162187
}
163188

164189
self->pin_number = pin->number;
@@ -183,6 +208,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
183208
nrf_pwm_enable(pwm);
184209

185210
common_hal_pulseio_pwmout_set_duty_cycle(self, duty);
211+
return PWMOUT_OK;
186212
}
187213

188214
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {

ports/nrf/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ extern const struct _mp_obj_module_t touchio_module;
229229
#define MICROPY_PORT_ROOT_POINTERS \
230230
const char *readline_hist[8]; \
231231
mp_obj_t gamepad_singleton; \
232+
mp_obj_t terminal_tilegrid_tiles; \
232233
FLASH_ROOT_POINTERS \
233234

234235
// We need to provide a declaration/definition of alloca()

shared-bindings/displayio/FourWire.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,7 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
9898
return self;
9999
}
100100

101-
102-
//| .. method:: send(command, data)
103-
//|
104-
//|
105-
STATIC mp_obj_t displayio_fourwire_obj_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
106-
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
107-
108-
return mp_const_none;
109-
}
110-
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_fourwire_send_obj, 1, displayio_fourwire_obj_send);
111-
112101
STATIC const mp_rom_map_elem_t displayio_fourwire_locals_dict_table[] = {
113-
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_fourwire_send_obj) },
114102
};
115103
STATIC MP_DEFINE_CONST_DICT(displayio_fourwire_locals_dict, displayio_fourwire_locals_dict_table);
116104

shared-bindings/displayio/ParallelBus.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,7 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
102102
return self;
103103
}
104104

105-
106-
//| .. method:: send(command, data)
107-
//|
108-
//|
109-
STATIC mp_obj_t displayio_parallelbus_obj_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
110-
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
111-
112-
return mp_const_none;
113-
}
114-
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_parallelbus_send_obj, 1, displayio_parallelbus_obj_send);
115-
116105
STATIC const mp_rom_map_elem_t displayio_parallelbus_locals_dict_table[] = {
117-
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_parallelbus_send_obj) },
118106
};
119107
STATIC MP_DEFINE_CONST_DICT(displayio_parallelbus_locals_dict, displayio_parallelbus_locals_dict_table);
120108

supervisor/shared/display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void supervisor_display_move_memory(void) {
9494
}
9595
uint16_t total_tiles = grid->width_in_tiles * grid->height_in_tiles;
9696

97-
tilegrid_tiles = allocate_memory(total_tiles, false);
97+
tilegrid_tiles = allocate_memory(align32_size(total_tiles), false);
9898
if (tilegrid_tiles != NULL) {
9999
memcpy(tilegrid_tiles->ptr, grid->tiles, total_tiles);
100100
grid->tiles = (uint8_t*) tilegrid_tiles->ptr;

supervisor/supervisor.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,12 @@ autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile
9292
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
9393
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
9494

95-
CIRCUITPY_DISPLAY_FONT = "../../tools/Tecate-bitmap-fonts/bitmap/cherry/cherry-10-r.bdf"
95+
CIRCUITPY_DISPLAY_FONT = "../../tools/Tecate-bitmap-fonts/bitmap/terminus-font-4.39/ter-u12n.bdf"
9696

9797
$(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD)
9898
$(STEPECHO) "GEN $@"
9999
$(Q)install -d $(BUILD)/genhdr
100100
$(Q)$(PYTHON3) ../../tools/gen_display_resources.py \
101101
--font $(CIRCUITPY_DISPLAY_FONT) \
102+
--sample_file $(HEADER_BUILD)/qstrdefs.generated.h \
102103
--output_c_file $(BUILD)/autogen_display_resources.c

tools/gen_display_resources.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
parser = argparse.ArgumentParser(description='Generate USB descriptors.')
1313
parser.add_argument('--font', type=str,
14-
help='manufacturer of the device', required=True)
14+
help='Font path', required=True)
15+
parser.add_argument('--extra_characters', type=str,
16+
help='Unicode string of extra characters')
17+
parser.add_argument('--sample_file', type=argparse.FileType('r'),
18+
help='Text file that includes strings to support.')
1519
parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True)
1620

1721
args = parser.parse_args()
@@ -25,32 +29,44 @@ def _load_row(self, y, row):
2529
self.rows[y] = bytes(row)
2630

2731
f = bitmap_font.load_font(args.font, BitmapStub)
28-
f.load_glyphs(range(0x20, 0x7f))
29-
30-
print(f.get_bounding_box())
3132
real_bb = [0, 0]
3233

34+
# Load extra characters from the sample file.
35+
sample_characters = set()
36+
if args.sample_file:
37+
for line in args.sample_file:
38+
# Skip comments because we add additional characters in our huffman comments.
39+
if line.startswith("//"):
40+
continue
41+
for c in line.strip():
42+
sample_characters.add(c)
43+
44+
# Merge visible ascii, sample characters and extra characters.
3345
visible_ascii = bytes(range(0x20, 0x7f)).decode("utf-8")
34-
extra_characters = "üàêùéáçãÍóíαψ◌"
35-
all_characters = visible_ascii + extra_characters
46+
all_characters = visible_ascii
47+
for c in sample_characters:
48+
if c not in all_characters:
49+
all_characters += c
50+
if args.extra_characters:
51+
all_characters.extend(args.extra_characters)
3652
filtered_characters = all_characters
53+
54+
# Try to pre-load all of the glyphs. Misses will still be slow later.
55+
f.load_glyphs(set(all_characters))
56+
57+
# Get each glyph.
3758
for c in all_characters:
3859
g = f.get_glyph(ord(c))
3960
if not g:
4061
print("Font missing character:", c, ord(c))
4162
filtered_characters = filtered_characters.replace(c, "")
42-
extra_characters = extra_characters.replace(c, "")
4363
continue
4464
x, y, dx, dy = g["bounds"]
45-
#print(c, g["bounds"], g["shift"])
4665
if g["shift"][1] != 0:
4766
raise RuntimeError("y shift")
4867
real_bb[0] = max(real_bb[0], x - dx)
4968
real_bb[1] = max(real_bb[1], y - dy)
5069

51-
#real_bb[1] += 1
52-
#print(real_bb)
53-
5470
tile_x, tile_y = real_bb
5571
total_bits = tile_x * len(all_characters)
5672
total_bits += 32 - total_bits % 32
@@ -61,31 +77,19 @@ def _load_row(self, y, row):
6177
g = f.get_glyph(ord(c))
6278
start_bit = x * tile_x + g["bounds"][2]
6379
start_y = (tile_y - 2) - (g["bounds"][1] + g["bounds"][3])
64-
# print(c, g["bounds"], g["shift"], tile_y, start_y)
6580
for y, row in enumerate(g["bitmap"].rows):
6681
for i in range(g["bounds"][0]):
6782
byte = i // 8
6883
bit = i % 8
6984
if row[byte] & (1 << (7-bit)) != 0:
7085
overall_bit = start_bit + (start_y + y) * bytes_per_row * 8 + i
7186
b[overall_bit // 8] |= 1 << (7 - (overall_bit % 8))
72-
# print("*",end="")
73-
# else:
74-
# print("_",end="")
75-
#print()
76-
77-
# print(b)
78-
# print("tile_x = {}".format(tile_x))
79-
# print("tile_y = {}".format(tile_y))
80-
# print("tiles = {}".format(len(all_characters)))
81-
# print("font = displayio.Bitmap(tile_x * tiles, tile_y, 2)")
82-
# for row in range(tile_y):
83-
# print("font._load_row({}, {})".format(row, bytes(b[row*bytes_per_row:row*bytes_per_row+bytes_per_row])))
84-
85-
# for row in range(tile_y):
86-
# for byte in b[row*bytes_per_row:row*bytes_per_row+bytes_per_row]:
87-
# print("{:08b} ".format(byte),end="")
88-
# print()
87+
88+
89+
extra_characters = ""
90+
for c in filtered_characters:
91+
if c not in visible_ascii:
92+
extra_characters += c
8993

9094
c_file = args.output_c_file
9195

0 commit comments

Comments
 (0)
0