Skip to content

Commit 21f9e58

Browse files
committed
adds --task-stack-size build argument.
This sets the stack size for a FreeRTOS task. We ran into an issue with the HX8369 driver where there was not enough stack memory to pass some of the init parameters. This allows the user to adjust the stack size if they encounter this issue.
1 parent c584ef9 commit 21f9e58

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

api_drivers/common_api_drivers/display/hx8369/_hx8369_init_type1.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
from micropython import const # NOQA
44

55

6+
_SETEXTC = const(0xB9)
7+
_SETPOWER = const(0xB1)
8+
_SETDISP = const(0xB2)
9+
_SETCYC = const(0xB4)
10+
_SETVCOM = const(0xB6)
11+
_SETGIP = const(0xD5)
12+
_SETGAMMA = const(0xE0)
13+
_SETDGCLUT = const(0xC1)
14+
_SETCOLOR = const(0x2D)
15+
616
_COLMOD = const(0x3A)
717
_MADCTL = const(0x36)
818
_SLPOUT = const(0x11)
@@ -17,7 +27,7 @@ def init(self):
1727

1828
# SET password
1929
param_buf[:3] = bytearray([0xFF, 0x83, 0x69])
20-
self.set_params(0xB9, param_mv[:3])
30+
self.set_params(_SETEXTC, param_mv[:3])
2131

2232
# # SET Freq for fps
2333
# param_buf[:2] = bytearray([0x01, 0x08])
@@ -28,30 +38,30 @@ def init(self):
2838
0x01, 0x00, 0x34, 0x06, 0x00, 0x0f, 0x0f, 0x2a, 0x32, 0x3f,
2939
0x3f, 0x07, 0x23, 0x01, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6])
3040

31-
self.set_params(0xB1, param_mv[:19])
41+
self.set_params(_SETPOWER, param_mv[:19])
3242

3343
# SET Display 480x800
3444
param_buf[:15] = bytearray([
3545
0x00, 0x20, 0x03, 0x03, 0x70, 0x00, 0xff, 0x00,
3646
0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x01])
3747

38-
self.set_params(0xB2, param_mv[:15])
48+
self.set_params(_SETDISP, param_mv[:15])
3949

4050
# SET Display column inversion
4151
param_buf[:5] = bytearray([0x00, 0x0C, 0xA0, 0x0E, 0x06])
42-
self.set_params(0xB4, param_mv[:5])
52+
self.set_params(_SETCYC, param_mv[:5])
4353

4454
# SET VCOM
4555
param_buf[:2] = bytearray([0x2C, 0x2C])
46-
self.set_params(0xB6, param_mv[:2])
56+
self.set_params(_SETVCOM, param_mv[:2])
4757

4858
# SET GIP
4959
param_buf[:26] = bytearray([
5060
0x00, 0x05, 0x03, 0x00, 0x01, 0x09, 0x10, 0x80, 0x37,
5161
0x37, 0x20, 0x31, 0x46, 0x8a, 0x57, 0x9b, 0x20, 0x31,
5262
0x46, 0x8a, 0x57, 0x9b, 0x07, 0x0f, 0x02, 0x00])
5363

54-
self.set_params(0xD5, param_mv[:26])
64+
self.set_params(_SETGIP, param_mv[:26])
5565

5666
# Set Gamma
5767
param_buf[:34] = bytearray([
@@ -60,7 +70,7 @@ def init(self):
6070
0x08, 0x0d, 0x2d, 0x34, 0x3f, 0x19, 0x38, 0x09, 0x0e,
6171
0x0e, 0x12, 0x14, 0x12, 0x14, 0x13, 0x19])
6272

63-
self.set_params(0xE0, param_mv[:34])
73+
self.set_params(_SETGAMMA, param_mv[:34])
6474

6575
# Set DGC
6676
param_buf[:127] = bytearray([
@@ -79,7 +89,7 @@ def init(self):
7989
0xb6, 0xbe, 0xc7, 0xce, 0xd6, 0xde, 0xe6, 0xef, 0xf5,
8090
0xfb, 0xfc, 0xfe, 0x8c, 0xa4, 0x19, 0xec, 0x1b, 0x4c, 0x40])
8191

82-
self.set_params(0xC1, param_mv[:127])
92+
self.set_params(_SETDGCLUT, param_mv[:127])
8393

8494
# Colour Set
8595
for i in range(64):
@@ -91,7 +101,7 @@ def init(self):
91101
for i in range(128, 192, 1):
92102
param_buf[i] = i * 8
93103

94-
self.set_params(0x2D, param_mv[:192])
104+
self.set_params(_SETCOLOR, param_mv[:192])
95105

96106
# LCD goes into sleep mode and display will be turned off after
97107
# power on reset, exit sleep mode first
@@ -113,4 +123,3 @@ def init(self):
113123

114124
self.set_params(_COLMOD, param_mv[:1])
115125
self.set_params(_DISPON)
116-

builder/esp32.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_espidf():
162162
ota = False
163163

164164
dual_core_threads = False
165-
task_stack_size = 16 * 1024
165+
task_stack_size = 6 * 1024 + 512
166166

167167

168168
def common_args(extra_args):
@@ -271,18 +271,11 @@ def common_args(extra_args):
271271
action='store_true'
272272
)
273273

274-
def multiple_of_16(value):
275-
value = int(value)
276-
if value % 1024:
277-
raise ValueError('task stack size must be a multiple of 1024')
278-
279-
return value
280-
281274
esp_argParser.add_argument(
282275
'--task-stack-size',
283276
dest='task_stack_size',
284277
default=task_stack_size,
285-
type=multiple_of_16,
278+
type=int,
286279
action='store'
287280
)
288281

@@ -851,23 +844,29 @@ def set_thread_core():
851844
data = data.replace(pattern, text)
852845
break
853846

854-
data = data.split('\n')
855-
for i, line in enumerate(data[:]):
856-
if line.startswith('#ifndef MICROPY_CONFIG_ROM_LEVEL'):
857-
last_line = data[i - 2]
858-
859-
if not last_line.startswith('#define MICROPY_TASK_STACK_SIZE'):
860-
data.insert(i - 1, '')
861-
862-
multiple = int(task_stack_size / 1024)
863-
864-
data[i - 2] = (
865-
f'#define MICROPY_TASK_STACK_SIZE ({multiple} * 1024)'
866-
)
867-
868-
break
869-
870-
data = '\n'.join(data)
847+
if '#ifdef MICROPY_TASK_STACK_SIZE' not in data:
848+
new_lines = [
849+
'#ifdef MICROPY_TASK_STACK_SIZE',
850+
' #undef MICROPY_TASK_STACK_SIZE'
851+
'#endif'
852+
''
853+
f'#define MICROPY_TASK_STACK_SIZE ({task_stack_size})'
854+
''
855+
'#ifndef MICROPY_CONFIG_ROM_LEVEL'
856+
]
857+
data = data.replace(
858+
'#ifndef MICROPY_CONFIG_ROM_LEVEL',
859+
'\n'.join(new_lines), 1)
860+
else:
861+
data = data.split('\n')
862+
for i, line in enumerate(data):
863+
if line.startswith('#define MICROPY_TASK_STACK_SIZE'):
864+
data[i] = (
865+
f'#define MICROPY_TASK_STACK_SIZE'
866+
f' ({task_stack_size})'
867+
)
868+
break
869+
data = '\n'.join(data)
871870

872871
with open(MPCONFIGPORT_PATH, 'wb') as f:
873872
f.write(data.encode('utf-8'))

0 commit comments

Comments
 (0)