forked from espruino/Espruino
-
Notifications
You must be signed in to change notification settings - Fork 7
/
JOLTJS.py
246 lines (234 loc) · 9.21 KB
/
JOLTJS.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/false
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
#
# Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# ----------------------------------------------------------------------------------------
# This file contains information for a specific board - the available pins, and where LEDs,
# Buttons, and other in-built peripherals are. It is used to build documentation as well
# as various source and header files for Espruino.
# ----------------------------------------------------------------------------------------
import pinutils;
info = {
'name' : "Jolt.js",
'link' : [ "https://www.espruino.com/Jolt.js" ],
'espruino_page_link' : 'Jolt.js',
# 'default_console' : "EV_SERIAL1",
# 'default_console_tx' : "D6",
# 'default_console_rx' : "D8",
# 'default_console_baudrate' : "9600",
'variables' : 12000, # How many variables are allocated for Espruino to use. RAM will be overflowed if this number is too high and code won't compile.
'bootloader' : 1,
'binary_name' : 'espruino_%v_joltjs.hex',
'build' : {
'optimizeflags' : '-Os',
'libraries' : [
'BLUETOOTH',
# 'NET',
'GRAPHICS',
# 'NFC',
'NEOPIXEL',
'JIT' # JIT compiler enabled
],
'makefile' : [
# 'DEFINES += -DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
'DEFINES += -DNRF_USB=1 -DUSB',
'DEFINES += -DNEOPIXEL_SCK_PIN=1 -DNEOPIXEL_LRCK_PIN=26', # nRF52840 needs LRCK pin defined for neopixel
'DEFINES += -DESPR_USE_STEPPER_TIMER=1', # Build in the code for stepping using the timer
'DEFINES += -DNRF_SDH_BLE_GATT_MAX_MTU_SIZE=131', # 23+x*27 rule as per https://devzone.nordicsemi.com/f/nordic-q-a/44825/ios-mtu-size-why-only-185-bytes
'DEFINES += -DCENTRAL_LINK_COUNT=2 -DNRF_SDH_BLE_CENTRAL_LINK_COUNT=2', # allow two outgoing connections at once
'LDFLAGS += -Xlinker --defsym=LD_APP_RAM_BASE=0x3660', # set RAM base to match MTU=131 + CENTRAL_LINK_COUNT=2
'DEFINES += -DAPP_TIMER_OP_QUEUE_SIZE=6',
'DEFINES+= -DBLUETOOTH_NAME_PREFIX=\'"Jolt.js"\'',
# see targets/nrf5x/app_config.h for USB descriptors
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0xa9,0xae,0xb6',
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
'DEFINES += -DNRF_BOOTLOADER_NO_WRITE_PROTECT=1', # By default the bootloader protects flash. Avoid this (a patch for NRF_BOOTLOADER_NO_WRITE_PROTECT must be applied first)
#'DEFINES += -DBUTTONPRESS_TO_REBOOT_BOOTLOADER', # not enabled so watchdog isn't started
'BOOTLOADER_SETTINGS_FAMILY=NRF52840',
'INCLUDE += -I$(ROOT)/libs/jolt.js',
'WRAPPERSOURCES += libs/joltjs/jswrap_jolt.c libs/joltjs/jswrap_qwiic.c',
'NRF_SDK15=1',
]
}
};
chip = {
'part' : "NRF52840",
'family' : "NRF52",
'package' : "AQFN73",
'ram' : 256,
'flash' : 1024,
'speed' : 64,
'usart' : 2,
'spi' : 3,
'i2c' : 2,
'adc' : 1,
'dac' : 0,
'saved_code' : {
'address' : ((246 - 10) * 4096), # Bootloader takes pages 248-255, FS takes 246-247
'page_size' : 4096,
'pages' : 10,
'flash_available' : 1024 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
},
};
devices = {
'BTN1' : { 'pin' : 'D0', 'pinstate' : 'IN_PULLDOWN' },
'LED1' : { 'pin' : 'D6' }, # Pin negated in software
'LED2' : { 'pin' : 'D8' }, # Pin negated in software
'LED3' : { 'pin' : 'D41' }, # Pin negated in software
# See Espruino/libs/joltjs/jswrap_jolt.c for other pins
'QWIIC0' : {
'pin_sda' : 'D3',
'pin_scl' : 'D29',
'pin_fet' : 'D7',
},
'QWIIC1' : {
'pin_sda' : 'D2',
'pin_scl' : 'D31',
'pin_fet' : 'D27',
},
'QWIIC2' : {
'pin_sda' : 'D44', # P1.12
'pin_scl' : 'D45', # P1.13
'pin_gnd' : 'D36', # P1.04
'pin_vcc' : 'D43', # P1.11
},
'QWIIC3' : {
'pin_sda' : 'D39', # P1.07
'pin_scl' : 'D38', # P1.06
'pin_gnd' : 'D37', # P1.05
'pin_vcc' : 'D42', # P1.10
},
'DRIVER0' : {
'pin_nsleep' : 'D21',
'pin_nfault' : 'D19',
'pin_mode' : 'D16',
'pin_trq' : 'D12',
'pin_d0' : 'D17',
'pin_d1' : 'D15',
'pin_d2' : 'D13',
'pin_d3' : 'D14'
},
'DRIVER1' : {
'pin_nsleep' : 'D23',
'pin_nfault' : 'D20',
'pin_mode' : 'D24',
'pin_trq' : 'D35',
'pin_d0' : 'D22',
'pin_d1' : 'D32',
'pin_d2' : 'D25',
'pin_d3' : 'D34'
}
};
# left-right, or top-bottom order
board = {
'bottom' : [ 'GND', '+V', 'H0', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7' ],
'top' : [ 'Q0.scl', 'Q0.sda', 'VCC', 'Q0.fet', '','',#'D29', 'D3', 'VCC', 'D7', # Q0
'Q1.scl', 'Q1.sda', 'VCC', 'Q1.fet', '','',#'D31', 'D2', 'VCC', 'D27', # Q1
'Q2.scl', 'Q2.sda', 'Q2.vcc', 'Q2.gnd', '','',#'D45', 'D44', 'D43', 'D36', # Q2
'Q3.scl', 'Q3.sda', 'Q3.vcc', 'Q3.gnd',#'D38', 'D39', 'D42', 'D37', # Q3
],
'right' : ['NFC','NFC'],
'_hide_not_on_connectors' : True,
'_notes' : {
'H0' : "Motor driver 0, output 0. This pin is also connected to analog input D4 via a 39k/220k potential divider", # D17
'H1' : "Motor driver 0, output 1.", # D15
'H2' : "Motor driver 0, output 2. This pin is also connected to analog input D5 via a 39k/220k potential divider", # D13
'H3' : "Motor driver 0, output 3.", # D14
'H4' : "Motor driver 1, output 0. This pin is also connected to analog input D30 via a 39k/220k potential divider", # D22
'H5' : "Motor driver 1, output 1.", # D32
'H6' : "Motor driver 1, output 2. This pin is also connected to analog input D28 via a 39k/220k potential divider", # D35
'H7' : "Motor driver 1, output 3.", # D34
'Q0.fet' : "INVERTED. Connected to 500mA FET. When 1, GND on Q0 is pulled low. When 0, GND on Q0 is open circuit",
'Q1.fet' : "INVERTED. Connected to 500mA FET. When 1, GND on Q1 is pulled low. When 0, GND on Q1 is open circuit",
},
'_pinfunctions' : {
'Q0.scl' : ["ADC1_IN5","3.3"],
'Q0.sda' : ["ADC1_IN1","3.3"],
'Q1.scl' : ["ADC1_IN7","3.3"],
'Q1.sda' : ["ADC1_IN0","3.3"],
'Q2.scl' : ["3.3"],
'Q2.sda' : ["3.3"],
'Q2.vcc' : ["3.3"],
'Q2.gnd' : ["3.3"],
'Q3.scl' : ["3.3"],
'Q3.sda' : ["3.3"],
'Q3.vcc' : ["3.3"],
'Q3.gnd' : ["3.3"],
'VCC' : ["3.3"]
}
};
board["_css"] = """
#board {
width: 800px;
height: 742px;
top: 0px;
left : 100px;
background-image: url(img/JOLTJS.jpg);
}
#boardcontainer {
height: 742px;
}
#top {
top: 106px;
left: 272px;
}
#bottom {
top: 599px;
left: 125px;
}
#right {
top: 536px;
left: 714px;
}
.toppin { width: 13px; }
.leftpin { height: 17px; }
.bottompin { width: 52px; }
""";
def get_pins():
pins = pinutils.generate_pins(0,47,"D") + pinutils.generate_pins(0,7,"H"); # 48 General Purpose I/O Pins, 8 High power pins
pinutils.findpin(pins, "PD0", True)["functions"]["XL1"]=0;
pinutils.findpin(pins, "PD1", True)["functions"]["XL2"]=0;
pinutils.findpin(pins, "PD5", True)["functions"]["RTS"]=0;
pinutils.findpin(pins, "PD6", True)["functions"]["TXD"]=0;
pinutils.findpin(pins, "PD7", True)["functions"]["CTS"]=0;
pinutils.findpin(pins, "PD8", True)["functions"]["RXD"]=0;
pinutils.findpin(pins, "PD9", True)["functions"]["NFC1"]=0;
pinutils.findpin(pins, "PD10", True)["functions"]["NFC2"]=0;
pinutils.findpin(pins, "PD2", True)["functions"]["ADC1_IN0"]=0;
pinutils.findpin(pins, "PD3", True)["functions"]["ADC1_IN1"]=0;
pinutils.findpin(pins, "PD4", True)["functions"]["ADC1_IN2"]=0;
pinutils.findpin(pins, "PD5", True)["functions"]["ADC1_IN3"]=0;
pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0;
pinutils.findpin(pins, "PD29", True)["functions"]["ADC1_IN5"]=0;
pinutils.findpin(pins, "PD30", True)["functions"]["ADC1_IN6"]=0;
pinutils.findpin(pins, "PD31", True)["functions"]["ADC1_IN7"]=0;
# Make buttons and LEDs negated
pinutils.findpin(pins, "PD6", True)["functions"]["NEGATED"]=0;
pinutils.findpin(pins, "PD8", True)["functions"]["NEGATED"]=0;
pinutils.findpin(pins, "PD41", True)["functions"]["NEGATED"]=0;
# High power analogs
pinutils.findpin(pins, "PH0", True)["functions"]["ADC1_IN2"]=0;
pinutils.findpin(pins, "PH2", True)["functions"]["ADC1_IN3"]=0;
pinutils.findpin(pins, "PH4", True)["functions"]["ADC1_IN6"]=0;
pinutils.findpin(pins, "PH6", True)["functions"]["ADC1_IN4"]=0;
# renumber high power pins - the idea is despite being 'H' the pins still point to the correct 'real' pin number
pinutils.findpin(pins, "PH0", True)["num"] = '17';
pinutils.findpin(pins, "PH1", True)["num"] = '15';
pinutils.findpin(pins, "PH2", True)["num"] = '13';
pinutils.findpin(pins, "PH3", True)["num"] = '14';
pinutils.findpin(pins, "PH4", True)["num"] = '22';
pinutils.findpin(pins, "PH5", True)["num"] = '32';
pinutils.findpin(pins, "PH6", True)["num"] = '25';
pinutils.findpin(pins, "PH7", True)["num"] = '34';
# everything is non-5v tolerant
for pin in pins:
if pin["port"]!="H":
pin["functions"]["3.3"]=0;
pin["functions"]["NO_BLOCKLY"]=0; # hide in blockly
#The boot/reset button will function as a reset button in normal operation. Pin reset on PD21 needs to be enabled on the nRF52832 device for this to work.
return pins