Merge branch 'master' into experimental_compact_vars
46
.gdbinit
@ -1,7 +1,7 @@
|
||||
break jsAssertFail
|
||||
break jsError
|
||||
define jsvTrace
|
||||
print jsvTrace(execInfo.root, 0)
|
||||
print jsvTrace($arg0, 0)
|
||||
end
|
||||
define whereami
|
||||
print jslPrintPosition(jsiConsolePrintString, 0, lex->tokenLastStart)
|
||||
@ -31,4 +31,48 @@ end
|
||||
define wdt_off
|
||||
p (*(uint32_t*)0x4001050C)=1
|
||||
end
|
||||
define execflags
|
||||
if execInfo.execute==0
|
||||
printf "EXEC_NO\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_YES
|
||||
printf "EXEC_YES\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_BREAK
|
||||
printf "EXEC_BREAK\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_CONTINUE
|
||||
printf "EXEC_CONTINUE\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_RETURN
|
||||
printf "EXEC_RETURN\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_INTERRUPTED
|
||||
printf "EXEC_INTERRUPTED\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_EXCEPTION
|
||||
printf "EXEC_EXCEPTION\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_ERROR
|
||||
printf "EXEC_ERROR\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_ERROR_LINE_REPORTED
|
||||
printf "EXEC_ERROR_LINE_REPORTED\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_FOR_INIT
|
||||
printf "EXEC_FOR_INIT\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_IN_LOOP
|
||||
printf "EXEC_IN_LOOP\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_IN_SWITCH
|
||||
printf "EXEC_IN_SWITCH\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_CTRL_C
|
||||
printf "EXEC_CTRL_C\n"
|
||||
end
|
||||
if execInfo.execute&EXEC_CTRL_C_WAIT
|
||||
printf "EXEC_CTRL_C_WAIT\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
13
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
*.o
|
||||
*.elf
|
||||
/*.hex
|
||||
/*.app_hex
|
||||
*.lst
|
||||
*.srec
|
||||
*.bin
|
||||
@ -28,6 +29,7 @@ node_modules
|
||||
/build/
|
||||
esp_iot_sdk_v1.5.0
|
||||
esp_iot_sdk_v2.0.0.p1
|
||||
ESP8266_NONOS_SDK-2.2.1
|
||||
xtensa-lx106-elf
|
||||
app
|
||||
esp-idf
|
||||
@ -39,7 +41,18 @@ gcc-arm-none-eabi*
|
||||
targetlibs/nrf5x_12/examples
|
||||
targetlibs/nrf5x_12/documentation/
|
||||
targetlibs/nrf5x_14
|
||||
targetlibs/nrf5x_15/components
|
||||
targetlibs/nrf5x_15/config
|
||||
targetlibs/nrf5x_15/example_config
|
||||
targetlibs/nrf5x_15/examples
|
||||
targetlibs/nrf5x_15/external
|
||||
targetlibs/nrf5x_15/external_tools
|
||||
targetlibs/nrf5x_15/integration
|
||||
targetlibs/nrf5x_15/modules
|
||||
targetlibs/nrf5x_mesh
|
||||
targetlibs/raspberrypi
|
||||
/.vscode
|
||||
/CURRENT_BOARD.make
|
||||
/topreadonly
|
||||
/topstrings
|
||||
|
||||
|
||||
29
.travis.yml
@ -7,7 +7,9 @@ before_script:
|
||||
- python --version
|
||||
|
||||
after_script:
|
||||
- ls *.bin *.hex *.tgz *.zip | xargs -I {} curl -v -F "binary=@{}" "http://www.espruino.com/travis_upload.php?commit=$TRAVIS_COMMIT&branch=$TRAVIS_BRANCH"
|
||||
- "if [[ -n \"$UPLOADTOKEN\" ]]; then
|
||||
ls *.bin *.hex *.tgz *.zip | xargs -I {} curl -v -F \"binary=@{}\" \"http://www.espruino.com/travis_upload.php?commit=$TRAVIS_COMMIT&branch=$TRAVIS_BRANCH&token=$UPLOADTOKEN\";
|
||||
fi"
|
||||
# upload to an S3 bucket, requires S3_BUCKET, AWS_ACCESS_KEY_ID and AWS_SECRET_KEY to be set
|
||||
# in environment using travis' repository settings
|
||||
- "if [[ -n \"$S3_BUCKET\" && -n \"$AWS_ACCESS_KEY_ID\" ]]; then
|
||||
@ -27,32 +29,27 @@ env:
|
||||
- V=0
|
||||
- RELEASE=1
|
||||
matrix:
|
||||
- BOARD=LINUX
|
||||
- BOARD=ESPRUINOBOARD PAD_FOR_BOOTLOADER=1
|
||||
- BOARD=PICO_R1_3 PAD_FOR_BOOTLOADER=1
|
||||
- BOARD=ESPRUINOWIFI PAD_FOR_BOOTLOADER=1
|
||||
- BOARD=PUCKJS DFU_UPDATE_BUILD=1
|
||||
- BOARD=PIXLJS DFU_UPDATE_BUILD=1
|
||||
- BOARD=HEXBADGE DFU_UPDATE_BUILD=1
|
||||
- BOARD=MDBT42Q DFU_UPDATE_BUILD=1
|
||||
- BOARD=ESP32
|
||||
- BOARD=ESP8266_BOARD
|
||||
- BOARD=ESP8266_4MB
|
||||
- BOARD=MICROBIT
|
||||
- BOARD=NRF52832DK
|
||||
- BOARD=OLIMEXINO_STM32
|
||||
- BOARD=MAPLERET6_STM32
|
||||
- BOARD=HYSTM32_24
|
||||
- BOARD=HYSTM32_28
|
||||
- BOARD=HYSTM32_32
|
||||
- BOARD=STM32VLDISCOVERY
|
||||
- BOARD=STM32F3DISCOVERY
|
||||
- BOARD=STM32F4DISCOVERY
|
||||
- BOARD=NUCLEOF401RE
|
||||
- BOARD=NUCLEOF411RE
|
||||
- BOARD=LINUX
|
||||
- BOARD=EFM32GGSTK
|
||||
- BOARD=NUCLEOL476RG
|
||||
- BOARD=RUUVITAG DFU_UPDATE_BUILD=1
|
||||
- BOARD=WIO_LTE
|
||||
- BOARD=HEXBADGE DFU_UPDATE_BUILD=1
|
||||
- BOARD=MDBT42Q DFU_UPDATE_BUILD=1
|
||||
- BOARD=THINGY52
|
||||
- BOARD=THINGY52 DFU_UPDATE_BUILD=1
|
||||
- BOARD=SMARTIBOT DFU_UPDATE_BUILD=1
|
||||
- BOARD=STM32L496GDISCOVERY
|
||||
- BOARD=RAK8211
|
||||
- BOARD=RAK8212
|
||||
|
||||
script: make
|
||||
|
||||
|
||||
267
ChangeLog
@ -1,4 +1,261 @@
|
||||
ESP8266: no callback if SSID is not available (fix #1297)
|
||||
Fix string index calculation when using some regexes (fix #1602)
|
||||
Ensure Function.replaceWith puts scope after parameters (fix #1601)
|
||||
Ensure Graphics.* return the Graphics instance, to allow call chaining (fix #1580)
|
||||
Ensure DataView.byteOffset/byteLength is always set even if not specified (fix #1567)
|
||||
Added HttpServerResponse.setHeader
|
||||
HttpServerResponse now automatically sends `Connection:close` unless overridden (fix #1596)
|
||||
Fix sign of RSSI reporting with setRSSIHandler
|
||||
nRF52: Add docs for properties that weren't documented before
|
||||
nRF52: Add ability to connect to device with passkey authentication
|
||||
nRF52: Allow startNotifications to use Indicate if Notify doesn't exist (as per spec)
|
||||
nRF52: Add option for static passkey pairing with NRF.setSecurity
|
||||
ESP32: update EspruinoBuildTools to esp-idf V3.1.2 - fix Wifi connect issues (multiple ssid)
|
||||
Revert PR #1459 as it broke neopixel functionality that worked previously
|
||||
nRF52: Disconnect RX pin after UART test at boot (saves power when in deep sleep)
|
||||
Serial.unsetup now sets pin state to STATE_UNDEFINED, which disconnects the pins internally
|
||||
Removed modulo on `new Date` h/m/s/ms arguments as it seems desktop JS is fine with out of range values
|
||||
Added `active` option to NRF.setScan/findDevices/requestDevices to allow scan response packets to be requested
|
||||
Add I2C/SPI baud rate checks (#1619)
|
||||
STM32: Add `E.setRTCPrescaler` to allow the RTC to be calibrated on Espruino Pico (fix #1607)
|
||||
nRF52: Fix slow Bluetooth connection if previously disconnected while using low power connection interval (fix #1605)
|
||||
Allow `Graphics.clear(true)` to reset state (font, color, etc) to default as well as clearing the screen (fix #1615)
|
||||
nRF52: Fix setScanResponse regression from 2v00
|
||||
nRF5x: Execute SWI1_IRQHandler when radio turns off instead of on+off. More efficient, fixed multiple advertising.
|
||||
Smartibot build added
|
||||
ESP32: update EspruinoBuildTools to esp-idf V3.1.3
|
||||
nRF52: Add FAT Filesystem support to MDBT42Q module
|
||||
Now save file modification time with FAT
|
||||
|
||||
2v01 : ESP32: update to esp-idf V3.1
|
||||
Fix issues with Class Extends
|
||||
Improve Tab Completions for extended classes
|
||||
Fix Storage.readJSON/readArrayBuffer memory leak (fix #1532)
|
||||
Fix potential out of bounds Graphics.scroll
|
||||
Serial.setConsole now warns if not used on hardware Serial
|
||||
ESP8266: implement hw_timer (fix #1511) to make soft serial and pwm work
|
||||
Fix Storage write error when skipping pages (fix #1539)
|
||||
nRF5x: When scanning, only use as much of IO queue as is needed
|
||||
nRF5x: If BLE/NFC/etc data won't fit in IO queue, drop whole packet
|
||||
Allow `a in b` to search 'fake' objects (#1534)
|
||||
Improve fast path when iterating over Uint8Array/ArrayBuffer
|
||||
Allow deletion of function properties (fix #1549)
|
||||
Add `{callback:...}` option for `.write` style functions - improve docs.
|
||||
ESP8266: deepSleep invalid microseconds (fix #1547)
|
||||
ESP8266: ESP_FLASH_MAX for ESP8266_4MB is wrong (fix #1551, #1553)
|
||||
Fix buffer overflow if bytesize/stopbits used in `Serial.setup` (fix #1510)
|
||||
Ensure jsvNewFlatStringOfLength tries twice (even if GC doesn't release memory, it reorders the free list) (#1559)
|
||||
ESP8266: Missing variable Flash Mode (--flash_mode, -fm) in ESP8266.make files (fix #1563)
|
||||
ESP8266: Remove hack added to get around SDK 1.4 bug (fix #1568)
|
||||
Reduce available hardware SPI/I2C instances to 1 on nRF52 (since this is all we implement atm)
|
||||
Add E.dumpFragmentation to show memory fragmentation (only for debug builds)
|
||||
Fix parsing of dates from before 1970
|
||||
nRF52: Fix some regressions in requestDevice (flagged up by asserts in debug build)
|
||||
Allow built-in objects to be created with `new X()`
|
||||
nRF52: Ensure Bluetooth stack doesn't do a reboot for non-fatal errors (just report them to console)
|
||||
BluetoothRemoteGATTServer.disconnect now returns a Promise
|
||||
nRF52: Jump out of low power mode after less BLE activity (2 reads/writes in 10 radio packets) (#1546)
|
||||
nRF5x: Fix NRF.setConnectionInterval when there's no connection (fix #1546)
|
||||
Explicitly mention Espruino not supporting CASE after DEFAULT in error (fix #1570)
|
||||
Ensure scope is saved for Class constructors (fix #1576)
|
||||
Add setNBCellOn for RAK8211-NB (fix #1581)
|
||||
Now escape chars <8 as octal, and add escape of vertical tab
|
||||
Add Graphics.createArrayBuffer(... {interleavex:true}) to allow faster support for P3 LED panels
|
||||
Add Graphics.fill/drawEllipse and move fill/drawCircle to use the same code
|
||||
CC3000-specific build removed on Original Espruino board (lack of space)
|
||||
|
||||
2v00 : Allow changeInterval with large (>32 bit) intervals (fix #1438)
|
||||
changeInterval now changes the interval immediately when it's called inside the interval it is changing (fix #1440)
|
||||
Fix parsing of try..catch when not executing (fix #1439)
|
||||
Add extra ReferenceError checks, even if variable is not used
|
||||
Allow Ctrl-C out of while...continue loop (fix #1441)
|
||||
Fix bug if using an undefined member of an object for for..in (fix #1437)
|
||||
Allow for..in to iterate over prototype chains down from Array and Object
|
||||
Add for(var i of array) to iterate over elements
|
||||
Added getter and setter support
|
||||
Stop parsing blocks if not executing (fix #572)
|
||||
Fix stack overflow if interpreting a file full of '{' (fix #1448)
|
||||
Fix exception when performing record access on object from getter (fix #1454)
|
||||
Switch to non-recursive StringExt copy (fix #1451)
|
||||
Fix rounding errors in fillPoly -> improve vector font rendering
|
||||
Fix issue that caused 'dump()' not to report variables/functions on Pixl.js
|
||||
Add E.lookupNoCase to allow searching case-insensitively for Object keys
|
||||
Fix HTTP Chunked transfers when the server uses lowercase headers (fix #1458)
|
||||
Fix TypedArray.indexOf (fix #1468)
|
||||
Allow require('Storage').write('a','',0,15) (zero length data) (fix #1465)
|
||||
edit() now chooses the shortest way to describe the function
|
||||
Fixed bug when RegExp.match/test called on non-strings
|
||||
Added Global isFinite
|
||||
Add missing ArrayBufferView.filter
|
||||
Added Array.find and findIndex (also for ArrayBufferViews)
|
||||
Fix unreliable ArrayBufferView.indexOf (#1468)
|
||||
Added String.startsWith/endsWith/includes (#1302)
|
||||
parseFloat(".s") now returns NaN
|
||||
Fixed /\S+/.test(" ")
|
||||
Added Storage.getFree() to return available space
|
||||
Enable E.setTimeZone on boards with very little flash memory
|
||||
Lower saved code area to 2k on micro:bit (from 3)
|
||||
Remove RGB colour handling in setColor on devices with low flash
|
||||
Reduce available variable count on STM32VL - we were too low on RAM
|
||||
Added Graphics.asBMP/asURL/dump - allowing easy debugging of Graphics via IDE
|
||||
Allow '.then' on already-resolved promise (fix #1476)
|
||||
Stop atob adding trailing 0s when strings are not a multiple of 3 long
|
||||
Reconstruct start and end newlines when dumping multi-line functions
|
||||
Fix regression parsing methods in classes on embedded (fix #1479)
|
||||
nRF5x: Add options argument to NRF.connect and BluetoothDevice.gatt.connect, allowing a connection interval to be specified
|
||||
nRF5x: Start renegotiating speed after 0.1ms, not 5s. Massively improves connect speed.
|
||||
nRF5x: Now queue up to 5 UART TX packets per transmit interval (was 1 previously)
|
||||
nRF52: Add Dynamic Interval Adjustment - default to 2x connection speed, but idle at 10x slower if not used for 2 minutes
|
||||
nRF5x: Add NRF.setConnectionInterval() to allow connection speed to be set manually
|
||||
RuuviTag: invert LED1, LED2 & BTN in software so LED.set() does what you'd expect
|
||||
Console now doesn't print quotes around object keys if it's not needed
|
||||
Added `E.toJS` to allow very compact JS data stringification (similar to `JSON.stringify`)
|
||||
Output the current timer number as a comment in `dump()`
|
||||
Don't print `=undefined` to console if line is empty
|
||||
Added RAK8212 (and include SMS/GPRS code in RAK8211/2 builds)
|
||||
Graphics.stringWidth now takes account of newlines
|
||||
nRF52: NRF.requestDevice now resolves as soon as a device is found. Faster and better in congested areas
|
||||
Replace use of obsolete 'usleep' function in Linux builds (fix #1455)
|
||||
Add Ethernet.getIP/setIP callbacks for Wiznet to bring them in line with WiFi (fix #1482)
|
||||
Fix Math.round for numbers > 32 bit (fix #1485)
|
||||
Pixl.js menu now resets font alignment, and down arrow icon is fixed
|
||||
Now check for ReferenceErrors in global scope
|
||||
Fix Array.shift (returned a NAME, rather than the value)
|
||||
Add sanity check for names returned from Functions and fix Array.pop
|
||||
Stop characters getting dropped when pasting large amounts of data into Linux build
|
||||
nRF5x increase JsSysTime accuracy to 2^-20 from 2^-16 - drastically improves Util Timer accuracy
|
||||
Added support for Software Serial ports (for low baud rates, eg. 9600)
|
||||
Fix JS state restoration issue (eg. Pixl.menu inside switch would cause errors)
|
||||
Added Graphics.drawPoly
|
||||
Add Graphics.asImage to turn a Graphics instance into an Image that can be used with drawImage
|
||||
Add Graphics.createImage to allow creation of a 1 bit image direct from a string
|
||||
Use 32 bit floats for E.FFT, not 64 (fix #1443)
|
||||
Automatically shut down UART if both pin states are changed
|
||||
Fix `setDeviceClockCmd: Unknown Device` when using `LoopbackB.setConsole()` on WiFi board
|
||||
Fix non-UART serial regressions (after software serial additions)
|
||||
Pixl.js: Add Pixl.setLCDPower to allow the LCD to be powered off, more than halving power consumption
|
||||
nRF5x: Allow NRF.setScan and NRF.findDevices to take the same search filters NRF.requestDevice does (fix #1496)
|
||||
Fix buffer overrun if we have to reallocate a pointer to argument lists when calling a function (fix #1491)
|
||||
Fix stack overflow if executing regex full of hundreds of open brackets (fix #1487)
|
||||
Fix issue where STM32F4 USB could lock up if TX during heavy RX
|
||||
Improve `E.mapInPlace` docs, and allow it to work with no map (eg pass straight through)
|
||||
Added non-standard Uint24Array, because it's very useful for RGB
|
||||
ESP8266: add CFLAGs to shrink binaray files (fix #1499)
|
||||
ESP8266: fully integration of analog pin A0 (fix #1495)
|
||||
ESP32: update sdk to esp-idf 3.0.1, set Espruino build tools back to master branch
|
||||
Allow btoa to work for arrays as well as Strings (fix #1509)
|
||||
Allow E.mapInPlace to merge bits from multiple source elements, also add option for msb/lsb first
|
||||
Remove Graphics.scroll/drawCircle/fillCircle on devices with low flash to allow builds to fit again
|
||||
Remove BluetoothRemoteGATTCharacteristic.writeValue on NRF51 (accidental inclusion - it's not required)
|
||||
Double IO buffer size to 256 (1k bytes) on boards with 96k of RAM or more (or NRF52)
|
||||
nRF5x: allow arbirtary baud rates to be specified for UART
|
||||
On devices with low flash, ensure atan2 uses the slower/smaller atan implementation
|
||||
Move FFT back to 64 bit if low flash (it uses less memory!) and optimise for flash space
|
||||
Remove new Graphics.createImage/asBML/asURL/dump on Original Espruino Board (not enough space)
|
||||
Remove Olimexino from build (too difficult to slim down build and very low usage)
|
||||
Remove Software Serial from boards where we're low on flash
|
||||
Increase size of saved code area from 3*4k to 10*4k on RAK821x boards
|
||||
Fix 'Can't extend undefined' when using Object.setPrototypeOf on a function
|
||||
nRF52: Added NRF.HID event for two-way BLE HID communications
|
||||
nRF5x: Remove multiple writes per connection interval (more trouble than the speed improvement is worth)
|
||||
Fixed hang if trying to allocate Storage greater than total storage size in a fully erased Storage area.
|
||||
Pixl.js: Fix 30s pause when closing sockets on WIZnet W5100 (fix #1306)
|
||||
Remove HASH/hashlib from all builds as it was confusingly in some and not others. Now use 'crypto'
|
||||
require('crypto').SHA1 is now JS in Espruino Original to cut down on the flash required
|
||||
Added 'heatshrink' library to expose built-in heatshrink compression to users
|
||||
Fix assert fail when calling Function.apply with an Object with non-numeric keys
|
||||
Fix issue when AT lib has to process multiple custom line handers in one packet
|
||||
Espruino WiFi: Fix unreliable send when receiving lots of data on another socket
|
||||
Espruino WiFi: Only rename `EspruinoWiFi` to `WiFi` if not found (allows easier debug)
|
||||
Check Flash Storage for modules when using `require`
|
||||
Add 'bits' option for Software SPI
|
||||
STM32 reset pin IRQs before storing the state - makes lost setWatches far less likely
|
||||
Ensure that setBusyIndicator updates output state after the very first initialisation.
|
||||
MDBT42Q: Add LED2 var in the Espruino interpreter, but don't use it for the bootloader
|
||||
ESP8266: release heap used by logDebug(true) (fix #1508)
|
||||
ESP8266: remove SHA256 SHA512 (fix #1517)
|
||||
Ensure `Date.getTimezoneOffset()` returns the correct timezone offset (fix #1515)
|
||||
Search for and execute files '.boot0'/1/2/3 in Storage at boot time if they exist
|
||||
Pixl.js: reduce saved code area to 9 x 4kb to allow for extra features
|
||||
ESP8266: switch to SDK 2.2.1 (fix #1207)
|
||||
Fix Serial port path regression on Linux, and add docs
|
||||
microbit: remove line-by-line debug capability to free up some space
|
||||
Added ES6 String.prototype.repeat
|
||||
|
||||
1v99 : Increase jslMatch error buffer size to handle "UNFINISHED TEMPLATE LITERAL" string (#1426)
|
||||
nRF5x: Make FlashWrite cope with flash writes > 4k
|
||||
Increase max size of native strings on platforms that support it - 16 bit to 32 bit (#1432)
|
||||
Fix stack size detection on Linux (fix #1427)
|
||||
Fix strncat/cpy bounding issues (fix #1425)
|
||||
Promises now ignore a second resolve/reject (fix #1433)
|
||||
Fix stack overflow if void void void... is repeated many times (fix #1434)
|
||||
Fix font rendering issue caused by signed bit field handling by GCC on non-x86 platforms (fix #1436)
|
||||
Added E.reboot() to allow hard reboots from software (fix #1429)
|
||||
Added 'Graphics.getInstance()' for more platform independent graphics
|
||||
Added VT100 'erase in Display' to Terminal
|
||||
In REPL, use x.toString() for objects if we know their name and it is available
|
||||
Pixl.js add BLE aerial test to self-test, now also start immediately on BTN4 at boot
|
||||
|
||||
1v98 : Allow Crypto SHA1 without SHA256/512 (for ESP8266 where flash is scarce)
|
||||
Add better docs for the form of Wifi callback functions
|
||||
Modify ESP8266/ESP32 callbacks to match the node.js style used elsewhere
|
||||
nRF52: fix pin.toggle() on software-negated pins
|
||||
Pixl.js: Reorder pins so 0..13 are also D0..13 for better Arduino compatibility
|
||||
Fix dump() when used with code written using E.setBootCode(..), (fix #1398)
|
||||
Allow parseInt/parseFloat to be used on very large strings if the number doesn't extend right to the end (fix #1397)
|
||||
nRF5x: Fix memory leak on NRF.connect
|
||||
Fix memory leak if an exception is thrown within a rejected promise
|
||||
ESP8266: rewrite wifi.save and restore to use the storage lib (imp #1380)
|
||||
ESP8266: Add missing option ssid_hidden for Wifi.startAP() (imp #1358)
|
||||
Fixed double-connect issue for TCP sockets
|
||||
Pixl.js: Ensure Pixl.menu changes to bitmap fonts
|
||||
Pixl.js: tweaked bias/contrast to improve display quality
|
||||
ESP32: update esp-idf to v3.0. BLE support - thanks to @jumjum. Erase flash before flashing. vars now 2500
|
||||
ESP8266: rearange rf_cal_sector (fix #1294)
|
||||
ESP8266: Wifi.scan() now return authmode as text
|
||||
ESP32: Fix accidental initialisation of UART3 when switching to Telnet (fix #1362)
|
||||
nRF52: Added `NRF.setAddress` to allow the MAC address to be changed
|
||||
Added Graphics.setFontAlign for font alignment and rotation
|
||||
Make software I2C bitrate and waveform more accurate
|
||||
Move default I2C bitrate to 100kbit/sec
|
||||
Linux: don't create a espruino.flash file if we're not writing to flash
|
||||
Add height check for Graphics.createArrayBuffer(...vertical_byte:true) (fix #1421)
|
||||
Add sanity check for debug trace print statement (fix #1420)
|
||||
Fix handling of exceptions in switch statements (fix #1352)
|
||||
Fix 'return when not in function' regression when returning inside a catch block (fix #1422)
|
||||
Don't load saved firmware images from different firmware versions - saved JS code still loaded (fix #1174)
|
||||
Remove Graphics.setFontAlign and Graphics.getModified on devices with low flash memory
|
||||
|
||||
1v97 : nRF52: fix NRF.on('connect',...) issue
|
||||
STM32: Fix setDeviceClockCmd error for USB.setConsole()
|
||||
nRF5x: Fix getPinMode, which fixes SW I2C after save()
|
||||
Thingy52: Don't report contents of 'Thingy' in 'dump()'
|
||||
Thingy52: Allow multiple sounds to play at once
|
||||
nRF5x: Ensure Waveform triggers a finished event
|
||||
Thingy52: Enable simple bootloader, add travis build for DFU
|
||||
Add Serial.inject to allow data to be added as if it was received from that device
|
||||
Fix UDP handling so that it copes with packets not all being received in one go
|
||||
STM32L496: increase variables - use full 320kB of RAM as it is contiguous
|
||||
Add a maximum time for setTimeout/setInterval (100 years)
|
||||
Fix Storage.write when writing partial file of the same length and initial contents
|
||||
Fix corrupted timer channels returned by Pin.getInfo
|
||||
Add command history to debugger
|
||||
Remove process.env.EXPORTS (EXPTR does the same but takes less space)
|
||||
Thingy52: Add 9 axis MPU support
|
||||
Errors now store message in 'message', not 'msg' (fix #1366)
|
||||
Ensure 'in' operator checks the prototype chain (fix #1365)
|
||||
Promise.resolve now handles promises/thenables as arguments (fix #1363)
|
||||
try..catch now creates exception in its own scope (fix #1367)
|
||||
Thingy52,Pixl.js: add default NFC URL of the Espruino IDE
|
||||
Add ArrayBuffer.byteLength property (fix #1374)
|
||||
setWatch(..., {edge:"rising",debounce:25}) is now default for built-in buttons
|
||||
Pixl.js: add Pixl.menu function for easy menus, build in graphical_menu.js
|
||||
Fix regression in MDBT42Q advertised name
|
||||
nRF52: Add E.getBattery as a more global battery percentage function, deprecate `Puck.getBatteryPercentage`
|
||||
Fix '.buffer' regression in 'JSON.stringify(new Uint8Array([1,2,3,4]).buffer)'
|
||||
Allow `typeof 123 .testing` without an exception (fix #1351)
|
||||
Add crypto.AES to Puck.js and other nRF52 Espruino devices
|
||||
|
||||
1v96 : ESP8266: no callback if SSID is not available (fix #1297)
|
||||
ESP8266: esp8266 wifi getStatus doesn't show savedMode (fix #752)
|
||||
ESP8266: cleanup defines WIFI_DBG and NET_DBG for RELEASE
|
||||
ESP8266: switch to single ld file eagle.app.v6.new.2048.ld for ESP8266_4MB board
|
||||
@ -41,6 +298,14 @@
|
||||
Allow STM32LL port to write 32 bits to flash at a time to bring it in line with other ports
|
||||
Allow flash writes *from* unaligned addresses on nRF52 and ESP8266 (previously this crashed the ESP8266)
|
||||
Update process.ENV.EXPORTS to bring it in line with what the compiler uses
|
||||
Now set 'this' correctly for Arrow Functions
|
||||
Add ES6 classes and 'super'
|
||||
nRF5x: Move all bluetooth events to event queue (removing MEMORY_BUSY issues)
|
||||
Fix potential issue where EV_TYPE_MASK enum could be set incorrectly
|
||||
setWatch's edge argument can also be an integer now
|
||||
Add 'data' option to setWatch to allow clocked data to be decoded easily
|
||||
nRF52: Increase flash available for stored code from 12kB for 40kB
|
||||
Now store/display appreviated commit in process.env, remove build date
|
||||
|
||||
1v95 : nRF5x: Swap to UART fifo to avoid overrun errors at high baud rates
|
||||
Ensure Exceptions/errors are reported on a blank line
|
||||
|
||||
40
Dockerfile
@ -1,12 +1,40 @@
|
||||
FROM ubuntu:14.04
|
||||
# Usage:
|
||||
#
|
||||
# Note: if you're in Linux you need to run socker with 'sudo'.
|
||||
# But honestly if you're on linux you should just save yourself
|
||||
# gigabytes of downloads and disk space and build Espruino directly.
|
||||
#
|
||||
# 1: Build the container image
|
||||
#
|
||||
# docker build . -t img_name
|
||||
#
|
||||
# 2: Run container image so it builds espruino
|
||||
#
|
||||
# docker run -e BOARD='PICO_R1_3' --name container_name img_name
|
||||
#
|
||||
# This will run the container and save build results into the container's filesystem.
|
||||
# Near the end of the build the filename will be displayed, for example espruino_2v00_pico_1r3.bin
|
||||
#
|
||||
# 3: Copy build results from the container into your filesystem
|
||||
#
|
||||
# docker cp container_name:espruino/espruino_2v00_pico_1r3.bin ./
|
||||
#
|
||||
|
||||
RUN git clone https://github.com/espruino/Espruino espruino
|
||||
FROM python:3
|
||||
|
||||
COPY . /espruino
|
||||
WORKDIR /espruino
|
||||
|
||||
# Change these to provision and compile for a different board
|
||||
RUN source scripts/provision.sh PICO_R1_3
|
||||
ENV BOARD PICO_R1_3
|
||||
# Workaround add some stuff that the provision script uses
|
||||
# in here so it doesn't have to use sudo
|
||||
RUN apt-get update
|
||||
RUN apt-get install -qq -y python3-pip
|
||||
RUN pip install pyserial
|
||||
RUN pip install nrfutil
|
||||
|
||||
# This ensures ALL dependencies are installed beforehand
|
||||
RUN bash -c "source scripts/provision.sh ALL"
|
||||
|
||||
ENV RELEASE 1
|
||||
CMD ["bash", "-c", "source scripts/provision.sh ALL && make"]
|
||||
|
||||
CMD ["make"]
|
||||
|
||||
107
Makefile
@ -63,11 +63,11 @@ endif
|
||||
INCLUDE?=-I$(ROOT) -I$(ROOT)/targets -I$(ROOT)/src -I$(GENDIR)
|
||||
LIBS?=
|
||||
DEFINES?=
|
||||
CFLAGS?=-Wall -Wextra -Wconversion -Werror=implicit-function-declaration -fno-strict-aliasing -Wno-packed-bitfield-compat
|
||||
LDFLAGS?=-Winline
|
||||
CFLAGS?=-Wall -Wextra -Wconversion -Werror=implicit-function-declaration -fno-strict-aliasing -Wno-packed-bitfield-compat -g
|
||||
LDFLAGS?=-Winline -g
|
||||
OPTIMIZEFLAGS?=
|
||||
#-fdiagnostics-show-option - shows which flags can be used with -Werror
|
||||
DEFINES+=-DGIT_COMMIT=$(shell git log -1 --format="%H")
|
||||
DEFINES+=-DGIT_COMMIT=$(shell git log -1 --format="%h")
|
||||
|
||||
ifeq ($(shell uname),Darwin)
|
||||
MACOSX=1
|
||||
@ -128,7 +128,7 @@ BASEADDRESS=0x08000000
|
||||
|
||||
ifeq ($(BOARD),)
|
||||
# Try and guess board names
|
||||
ifeq ($(shell uname -m),armv6l)
|
||||
ifneq ($(shell grep Raspbian /etc/os-release),)
|
||||
BOARD=RASPBERRYPI # just a guess
|
||||
else ifeq ($(shell uname -n),beaglebone)
|
||||
BOARD=BEAGLEBONE
|
||||
@ -266,6 +266,7 @@ src/jsinteractive.c \
|
||||
src/jsdevices.c \
|
||||
src/jstimer.c \
|
||||
src/jsi2c.c \
|
||||
src/jsserial.c \
|
||||
src/jsspi.c \
|
||||
src/jshardware_common.c \
|
||||
$(WRAPPERFILE)
|
||||
@ -307,12 +308,13 @@ SOURCES += \
|
||||
libs/compression/heatshrink/heatshrink_encoder.c \
|
||||
libs/compression/heatshrink/heatshrink_decoder.c \
|
||||
libs/compression/compress_heatshrink.c
|
||||
|
||||
WRAPPERSOURCES += \
|
||||
libs/compression/jswrap_heatshrink.c
|
||||
endif
|
||||
|
||||
ifndef BOOTLOADER # ------------------------------------------------------------------------------ DON'T USE IN BOOTLOADER
|
||||
|
||||
ifdef USE_FILESYSTEM
|
||||
ifeq ($(USE_FILESYSTEM),1)
|
||||
DEFINES += -DUSE_FILESYSTEM
|
||||
INCLUDE += -I$(ROOT)/libs/filesystem
|
||||
WRAPPERSOURCES += \
|
||||
@ -325,7 +327,7 @@ libs/filesystem/fat_sd/fattime.c \
|
||||
libs/filesystem/fat_sd/ff.c \
|
||||
libs/filesystem/fat_sd/option/unicode.c # for LFN support (see _USE_LFN in ff.h)
|
||||
|
||||
ifdef USE_FILESYSTEM_SDIO
|
||||
ifeq ($(USE_FILESYSTEM_SDIO),1)
|
||||
DEFINES += -DUSE_FILESYSTEM_SDIO
|
||||
SOURCES += \
|
||||
libs/filesystem/fat_sd/sdio_diskio.c \
|
||||
@ -355,7 +357,7 @@ else
|
||||
LIBS += -lm
|
||||
endif
|
||||
|
||||
ifdef USE_GRAPHICS
|
||||
ifeq ($(USE_GRAPHICS),1)
|
||||
DEFINES += -DUSE_GRAPHICS
|
||||
INCLUDE += -I$(ROOT)/libs/graphics
|
||||
WRAPPERSOURCES += libs/graphics/jswrap_graphics.c
|
||||
@ -365,7 +367,7 @@ libs/graphics/graphics.c \
|
||||
libs/graphics/lcd_arraybuffer.c \
|
||||
libs/graphics/lcd_js.c
|
||||
|
||||
ifdef USE_LCD_SDL
|
||||
ifeq ($(USE_LCD_SDL),1)
|
||||
DEFINES += -DUSE_LCD_SDL
|
||||
SOURCES += libs/graphics/lcd_sdl.c
|
||||
LIBS += -lSDL
|
||||
@ -377,18 +379,19 @@ ifdef USE_LCD_FSMC
|
||||
SOURCES += libs/graphics/lcd_fsmc.c
|
||||
endif
|
||||
|
||||
ifdef USE_TERMINAL
|
||||
|
||||
ifeq ($(USE_TERMINAL),1)
|
||||
DEFINES += -DUSE_TERMINAL
|
||||
WRAPPERSOURCES += libs/graphics/jswrap_terminal.c
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
ifdef USE_USB_HID
|
||||
ifeq ($(USE_USB_HID),1)
|
||||
DEFINES += -DUSE_USB_HID
|
||||
endif
|
||||
|
||||
ifdef USE_NET
|
||||
ifeq ($(USE_NET),1)
|
||||
DEFINES += -DUSE_NET
|
||||
INCLUDE += -I$(ROOT)/libs/network -I$(ROOT)/libs/network -I$(ROOT)/libs/network/http
|
||||
WRAPPERSOURCES += \
|
||||
@ -511,7 +514,7 @@ ifdef USE_NET
|
||||
endif
|
||||
endif # USE_NET
|
||||
|
||||
ifdef USE_TV
|
||||
ifeq ($(USE_TV),1)
|
||||
DEFINES += -DUSE_TV
|
||||
WRAPPERSOURCES += libs/tv/jswrap_tv.c
|
||||
INCLUDE += -I$(ROOT)/libs/tv
|
||||
@ -519,7 +522,7 @@ ifdef USE_TV
|
||||
libs/tv/tv.c
|
||||
endif
|
||||
|
||||
ifdef USE_TRIGGER
|
||||
ifeq ($(USE_TRIGGER),1)
|
||||
DEFINES += -DUSE_TRIGGER
|
||||
WRAPPERSOURCES += libs/trigger/jswrap_trigger.c
|
||||
INCLUDE += -I$(ROOT)/libs/trigger
|
||||
@ -527,82 +530,35 @@ ifdef USE_TRIGGER
|
||||
libs/trigger/trigger.c
|
||||
endif
|
||||
|
||||
ifdef USE_HASHLIB
|
||||
INCLUDE += -I$(ROOT)/libs/hashlib
|
||||
WRAPPERSOURCES += \
|
||||
libs/hashlib/jswrap_hashlib.c
|
||||
SOURCES += \
|
||||
libs/hashlib/sha2.c
|
||||
endif
|
||||
|
||||
ifdef USE_WIRINGPI
|
||||
ifeq ($(USE_WIRINGPI),1)
|
||||
DEFINES += -DUSE_WIRINGPI
|
||||
LIBS += -lwiringPi
|
||||
INCLUDE += -I/usr/local/include -L/usr/local/lib
|
||||
endif
|
||||
|
||||
ifdef USE_BLUETOOTH
|
||||
ifeq ($(USE_BLUETOOTH),1)
|
||||
DEFINES += -DBLUETOOTH
|
||||
INCLUDE += -I$(ROOT)/libs/bluetooth
|
||||
WRAPPERSOURCES += libs/bluetooth/jswrap_bluetooth.c
|
||||
SOURCES += libs/bluetooth/bluetooth_utils.c
|
||||
endif
|
||||
|
||||
ifdef USE_CRYPTO
|
||||
DEFINES += -DUSE_CRYPTO
|
||||
INCLUDE += -I$(ROOT)/libs/crypto
|
||||
INCLUDE += -I$(ROOT)/libs/crypto/mbedtls
|
||||
INCLUDE += -I$(ROOT)/libs/crypto/mbedtls/include
|
||||
WRAPPERSOURCES += libs/crypto/jswrap_crypto.c
|
||||
SOURCES += \
|
||||
libs/crypto/mbedtls/library/sha1.c \
|
||||
libs/crypto/mbedtls/library/sha256.c \
|
||||
libs/crypto/mbedtls/library/sha512.c
|
||||
|
||||
ifdef USE_TLS
|
||||
USE_AES=1
|
||||
DEFINES += -DUSE_TLS
|
||||
SOURCES += \
|
||||
libs/crypto/mbedtls/library/bignum.c \
|
||||
libs/crypto/mbedtls/library/ctr_drbg.c \
|
||||
libs/crypto/mbedtls/library/debug.c \
|
||||
libs/crypto/mbedtls/library/ecp.c \
|
||||
libs/crypto/mbedtls/library/ecp_curves.c \
|
||||
libs/crypto/mbedtls/library/entropy.c \
|
||||
libs/crypto/mbedtls/library/entropy_poll.c \
|
||||
libs/crypto/mbedtls/library/md5.c \
|
||||
libs/crypto/mbedtls/library/pk.c \
|
||||
libs/crypto/mbedtls/library/pkparse.c \
|
||||
libs/crypto/mbedtls/library/pk_wrap.c \
|
||||
libs/crypto/mbedtls/library/rsa.c \
|
||||
libs/crypto/mbedtls/library/ssl_ciphersuites.c \
|
||||
libs/crypto/mbedtls/library/ssl_cli.c \
|
||||
libs/crypto/mbedtls/library/ssl_tls.c \
|
||||
libs/crypto/mbedtls/library/ssl_srv.c \
|
||||
libs/crypto/mbedtls/library/x509.c \
|
||||
libs/crypto/mbedtls/library/x509_crt.c
|
||||
endif
|
||||
ifdef USE_AES
|
||||
DEFINES += -DUSE_AES
|
||||
SOURCES += \
|
||||
libs/crypto/mbedtls/library/aes.c \
|
||||
libs/crypto/mbedtls/library/asn1parse.c \
|
||||
libs/crypto/mbedtls/library/cipher.c \
|
||||
libs/crypto/mbedtls/library/cipher_wrap.c \
|
||||
libs/crypto/mbedtls/library/md.c \
|
||||
libs/crypto/mbedtls/library/md_wrap.c \
|
||||
libs/crypto/mbedtls/library/oid.c \
|
||||
libs/crypto/mbedtls/library/pkcs5.c
|
||||
endif
|
||||
ifeq ($(USE_CRYPTO),1)
|
||||
cryptofound:=$(shell if test -f make/crypto/$(FAMILY).make; then echo yes;fi)
|
||||
ifeq ($(cryptofound),yes)
|
||||
include make/crypto/$(FAMILY).make
|
||||
else
|
||||
include make/crypto/default.make
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef USE_NEOPIXEL
|
||||
ifeq ($(USE_NEOPIXEL),1)
|
||||
DEFINES += -DUSE_NEOPIXEL
|
||||
INCLUDE += -I$(ROOT)/libs/neopixel
|
||||
WRAPPERSOURCES += libs/neopixel/jswrap_neopixel.c
|
||||
endif
|
||||
|
||||
ifdef USE_NFC
|
||||
ifeq ($(USE_NFC),1)
|
||||
DEFINES += -DUSE_NFC -DNFC_HAL_ENABLED=1
|
||||
INCLUDE += -I$(NRF5X_SDK_PATH)/components/nfc/t2t_lib
|
||||
INCLUDE += -I$(NRF5X_SDK_PATH)/components/nfc/ndef/uri
|
||||
@ -615,7 +571,7 @@ ifdef USE_NFC
|
||||
TARGETSOURCES += $(NRF5X_SDK_PATH)/components/nfc/t2t_lib/hal_t2t/hal_nfc_t2t.c
|
||||
endif
|
||||
|
||||
ifdef USE_WIO_LTE
|
||||
ifeq ($(USE_WIO_LTE),1)
|
||||
INCLUDE += -I$(ROOT)/libs/wio_lte
|
||||
WRAPPERSOURCES += libs/wio_lte/jswrap_wio_lte.c
|
||||
SOURCES += targets/stm32/stm32_ws2812b_driver.c
|
||||
@ -656,6 +612,7 @@ CFLAGS += $(OPTIMIZEFLAGS) -c $(ARCHFLAGS) $(DEFINES) $(INCLUDE)
|
||||
|
||||
# -Wl,--gc-sections helps remove unused code
|
||||
# -Wl,--whole-archive checks for duplicates
|
||||
# --specs=nano.specs uses newlib-nano
|
||||
ifdef NRF5X
|
||||
LDFLAGS += $(OPTIMIZEFLAGS) $(ARCHFLAGS) --specs=nano.specs -lc -lnosys
|
||||
else ifdef STM32
|
||||
@ -790,12 +747,12 @@ else # NO_COMPILE
|
||||
$(info WRAPPERSOURCES=$(WRAPPERSOURCES));
|
||||
endif
|
||||
|
||||
lst:
|
||||
$(PROJ_NAME).lst
|
||||
lst: $(PROJ_NAME).lst
|
||||
|
||||
clean:
|
||||
@echo Cleaning targets
|
||||
$(Q)find . -name \*.o | grep -v "./arm-bcm2708\|./gcc-arm-none-eabi" | xargs rm -f
|
||||
$(Q)find . -name \*.d | grep -v "./arm-bcm2708\|./gcc-arm-none-eabi" | xargs rm -f
|
||||
$(Q)rm -f $(ROOT)/gen/*.c $(ROOT)/gen/*.h $(ROOT)/gen/*.ld
|
||||
$(Q)rm -f $(ROOT)/scripts/*.pyc $(ROOT)/boards/*.pyc
|
||||
$(Q)rm -f $(PROJ_NAME).elf
|
||||
|
||||
25
README.md
@ -77,38 +77,41 @@ There are a bunch of tests in the `tests` directory. See [`tests/README.md`](tes
|
||||
Current State
|
||||
-------------
|
||||
|
||||
The officially supported boards are the [Original Espruino Board](http://www.espruino.com/EspruinoBoard) and the [Espruino Pico Board](http://www.espruino.com/Pico). The [Web IDE](http://www.espruino.com/webide) is able to automatically download and flash the latest version of Espruino for you.
|
||||
The [officially supported boards](http://www.espruino.com/Order) are the best supported. They come pre-installed with Espruino and you are able to easily download and flash the latest versions of Espruino to them.
|
||||
|
||||
While Espruino can run on other boards, we make no money from them and so cannot afford to test, fix or support the firmware on them. We're dependent on the community.
|
||||
|
||||
You can download binaries from http://www.espruino.com/Download (these aren't the latest, but are more likely to work with your board).
|
||||
You can download binaries from http://www.espruino.com/Download
|
||||
|
||||
If you are a board manufacturer interested in getting your board officially supported, please [Contact Us](http://www.espruino.com/Contact+Us).
|
||||
|
||||
If you are a board manufacturer interested in getting your board officially supported, please [check out this page](http://www.espruino.com/Business).
|
||||
|
||||
* [Original Espruino Board](http://www.espruino.com/EspruinoBoard) - great support.
|
||||
* [Espruino Pico Board](http://www.espruino.com/Pico) - great support.
|
||||
* [Puck.js](http://www.espruino.com/Puck.js) - great support.
|
||||
* [MDBT42Q module and breakout board](http://www.espruino.com/MDBT42Q) - great support.
|
||||
* [Espruino WiFi Board](http://www.espruino.com/WiFi) - great support.
|
||||
* Linux - WORKING
|
||||
* [BBC micro:bit](http://www.espruino.com/MicroBit) - WORKING
|
||||
* [STM32VLDISCOVERY](http://www.espruino.com/ReferenceSTM32VLDISCOVERY) - WORKING - limited memory so some features removed
|
||||
* [STM32F3DISCOVERY](http://www.espruino.com/ReferenceSTM32F3DISCOVERY) - USB BROKEN
|
||||
* [STM32F4DISCOVERY](http://www.espruino.com/ReferenceSTM32F4DISCOVERY) - WORKING
|
||||
* [BBC micro:bit](http://www.espruino.com/MicroBit) - WORKING, builds available
|
||||
* [STM32VLDISCOVERY](http://www.espruino.com/ReferenceSTM32VLDISCOVERY) - WORKING, builds available - limited memory so some features removed
|
||||
* [STM32F3DISCOVERY](http://www.espruino.com/ReferenceSTM32F3DISCOVERY) - NO LONGER SUPPORTED
|
||||
* [STM32F4DISCOVERY](http://www.espruino.com/ReferenceSTM32F4DISCOVERY) - WORKING, builds available
|
||||
* STM32F401CDISCOVERY - appears WORKING, but very little testing done
|
||||
* STM32F429IDISCOVERY - WORKING over serial (A9/A10). No USB and no LCD support
|
||||
* NRF51822 Development Kit - WORKING
|
||||
* NRF52832 Development Kit - WORKING
|
||||
* NRF52832 Development Kit - WORKING, builds available
|
||||
* [HY STM32 2.4"](http://www.espruino.com/ReferenceHYSTM32_24) - WORKING
|
||||
* [HY STM32 2.8"](http://www.espruino.com/ReferenceHYSTM32_28) - WORKING - limited memory so some features removed
|
||||
* [HY STM32 3.2"](http://www.espruino.com/ReferenceHYSTM32_32) - WORKING
|
||||
* [Olimexino STM32 / Leaflabs Maple](http://www.espruino.com/ReferenceOLIMEXINO_STM32) - WORKING - limited memory so some features removed
|
||||
* Carambola - WORKING - GPIO via filesystem (no I2C)
|
||||
* Raspberry Pi - WORKING - GPIO via filesystem or wiringPi (no I2C)
|
||||
* Sony SmartWatch - NOT WORKING - USB VCP support for F2 still needed
|
||||
* LC-TECH STM32F103RBT6 - WORKING, but with some issues (LED inverted logic, BTN needs pullup to work)
|
||||
* [ST NUCLEO-F401RE](http://www.espruino.com/ReferenceNUCLEOF401RE) - WORKING
|
||||
* ST NUCLEO-F411RE - WORKING
|
||||
* ESP8266 - WORKING - Reasonably stable, but expect to find issues
|
||||
* [ESP8266](http://www.espruino.com/EspruinoESP8266) - WORKING
|
||||
* [ESP32](http://www.espruino.com/ESP32) - WORKING - Reasonably stable, but expect to find issues
|
||||
* [HY STM32 3.2"](http://www.espruino.com/ReferenceHYSTM32_32) - NO LONGER SUPPORTED
|
||||
* [Olimexino STM32 / Leaflabs Maple](http://www.espruino.com/ReferenceOLIMEXINO_STM32) - NO LONGER SUPPORTED
|
||||
* Arduino (AVR) - NOT POSSIBLE due to the Hardward architecture of AVRs, even though it would fit into an ATMEGA2560. If `avr-gcc` ever gains an easy way to emulate Von Neumann architecture then it might be portable, but for now it isn't.
|
||||
|
||||
|
||||
|
||||
@ -99,9 +99,26 @@ These contain:
|
||||
* `binaries` - available binaries - this is used by the Web IDE to allow the user to choose which binary to upload
|
||||
* `build` - controls what gets build via the Makefile:
|
||||
* `optimizeflags` - flags like `-O3` to give to the compiler
|
||||
* `libraries` - list of libraries to include
|
||||
* `libraries` - list of libraries to include - these get transformed into `USE_LIBNAME` defines
|
||||
* `makefile` - list of commands/definitions to execute in the Makefile
|
||||
|
||||
#### info.makefile definitions
|
||||
|
||||
This is a partial list of definitions that can be added in a `BOARD.py` file's `info.build.makefile` array, eg: `'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Puck.js"\''`
|
||||
|
||||
* `SAVE_ON_FLASH` - Remove some features (like any ES6 support) to target devices with ~128kB Flash
|
||||
* `SAVE_ON_FLASH_MATH` - Remove some less-used Maths functions that use a bunch of Flash memory
|
||||
* `SAVE_ON_FLASH_EXTREME` - Pull out as many features as possible to target devices with ~128kB Flash that also want things like Filesystem support
|
||||
* `BLUETOOTH_NAME_PREFIX="..."` - Make the Bluetooth LE device's name `BLUETOOTH_NAME_PREFIX` followed by the last 2 bytes of the MAC address.
|
||||
* `NFC_DEFAULT_URL="http://foo"` - If defined, set the advertised NFC URL to the one given, plus `?a=ble_address`. Only do it for a fresh boot - not when code has been saved.
|
||||
* `PIN_NAMES_DIRECT=1` - Package skips out some pins (maybe there's `D0`,`D1`,`D3` but no `D2`), so the code must search rather than just offsetting based on pin number.
|
||||
* `DUMP_IGNORE_VARIABLES="...\0"` - string containing zero-terminated list of global variable names to ignore when `dump()` is called. Must be explicityly zero-terminated so there are 2 trailing 0s
|
||||
* `FSMC_BITBANG` - if using a built-in FSMC Graphics LCD, don't use the hardware but instead do it in software
|
||||
* `FLASH_64BITS_ALIGNMENT=1` - For testing 64 bit flash writes on linux
|
||||
* `JSMODULESOURCES+=libs/.../foo.min.js` - include the given JS file as a module that can be used via `require("foo")`
|
||||
* `JSVAR_MALLOC` - Allocate space for variables at jsvInit time, rather than statically
|
||||
|
||||
|
||||
### chip
|
||||
|
||||
* `part` - Chip part number (this is defined in the compiler - eg if the part is `STM32F401CDU6`, `-DSTM32F401CDU6` is put on the GCC command-line)
|
||||
|
||||
@ -214,16 +214,19 @@ Dependant on the board, either usb or bluetooth can be used to program the board
|
||||
* USB
|
||||
* the board appears as a drive to drop a hex on
|
||||
|
||||
#### for [Puck.js](http://www.espruino.com/Puck.js)
|
||||
#### for [Puck.js](http://www.espruino.com/Puck.js) and [Pixl.js](http://www.espruino.com/Pixl.js)
|
||||
|
||||
The Puck.js is based on the nRF52
|
||||
The Puck.js and Pixl.js are based on the nRF52
|
||||
|
||||
```bash
|
||||
# Puck.js
|
||||
make clean && DFU_UPDATE_BUILD=1 BOARD=PUCKJS RELEASE=1 make
|
||||
# Pixl.js
|
||||
make clean && DFU_UPDATE_BUILD=1 BOARD=PIXLJS RELEASE=1 make
|
||||
```
|
||||
|
||||
The resulting file is a zip that has to be transferred to the puck.js via a Bluetooth low energy device.
|
||||
See <https://www.espruino.com/Puck.js+Quick+Start> for information concerning transferring the zip to the puck.js.
|
||||
The resulting file is a zip that has to be transferred via Bluetooth Low Energy.
|
||||
See the [Puck.js](http://www.espruino.com/Puck.js#firmware-updates) and [Pixl.js](http://www.espruino.com/Pixl.js#firmware-updates) pages for information concerning transferring the ZIP.
|
||||
|
||||
#### for [NRF52-DK](https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF52-DK)
|
||||
|
||||
|
||||
@ -25,9 +25,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'TLS',
|
||||
'HASHLIB',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'TELNET',
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -25,9 +25,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'HASHLIB',
|
||||
'TELNET',
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -24,9 +24,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'HASHLIB',
|
||||
'TELNET',
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -24,9 +24,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'HASHLIB',
|
||||
'TELNET',
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -7,7 +7,7 @@ info = {
|
||||
'link': [ "https://www.silabs.com/products/mcu/lowpower/Pages/efm32gg-stk3700.aspx" ],
|
||||
'variables': 1720,
|
||||
'binary_name': 'espruino_%v_efm32ggstk.bin',
|
||||
'default_console' : "EV_SERIAL4",
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "E0",
|
||||
'default_console_rx' : "E1",
|
||||
'default_console_baudrate' : "115200",
|
||||
|
||||
@ -19,7 +19,7 @@ info = {
|
||||
'espruino_page_link' : 'ESP32',
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_baudrate' : "115200",
|
||||
'variables' : 5000,
|
||||
'variables' : 2500, # JSVAR_MALLOC is defined below - so this can vary depending on what is initialised
|
||||
'binary_name' : 'espruino_%v_esp32.bin',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Og',
|
||||
@ -27,15 +27,17 @@ info = {
|
||||
'ESP32',
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'TELNET',
|
||||
'NEOPIXEL',
|
||||
'FILESYSTEM',
|
||||
'FLASHFS'
|
||||
'FLASHFS',
|
||||
'BLUETOOTH'
|
||||
],
|
||||
'makefile' : [
|
||||
'DEFINES+=-DESP_PLATFORM -DESP32=1'
|
||||
'DEFINES+=-DESP_PLATFORM -DESP32=1',
|
||||
'DEFINES+=-DJSVAR_MALLOC' # Allocate space for variables at jsvInit time
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -53,10 +55,10 @@ chip = {
|
||||
'adc' : 2,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : 0x100000,
|
||||
'address' : 0x2C0000,
|
||||
'page_size' : 4096,
|
||||
'pages' : 16,
|
||||
'flash_available' : 960, # firmware can be up to this size
|
||||
'pages' : 64,
|
||||
'flash_available' : 1344, # firmware can be up to this size - see paritions_espruino.csv
|
||||
},
|
||||
};
|
||||
devices = {
|
||||
|
||||
@ -33,7 +33,7 @@ info = {
|
||||
],
|
||||
'makefile' : [
|
||||
'FLASH_4MB=1',
|
||||
'ESP_FLASH_MAX=962560',
|
||||
'ESP_FLASH_MAX=831488',
|
||||
'FLASH_BAUD=460800'
|
||||
]
|
||||
}
|
||||
@ -111,10 +111,25 @@ board_esp01 = {
|
||||
boards = [ board_esp12 ];
|
||||
|
||||
def get_pins():
|
||||
pins = pinutils.generate_pins(0,16)
|
||||
pinutils.findpin(pins, "PD0", True)["functions"]["LED_1"]=0;
|
||||
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
|
||||
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
|
||||
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
|
||||
# just fake pins D0 .. D16
|
||||
return pins
|
||||
# add pins D0 .. D16,A0
|
||||
pins = [
|
||||
{ "name":"PD0", "sortingname":"D00", "port":"D", "num":"0", "functions":{"LED_1":0}, "csv":{} },
|
||||
{ "name":"PD1", "sortingname":"D01", "port":"D", "num":"1", "functions":{"USART1_TX":0}, "csv":{} },
|
||||
{ "name":"PD2", "sortingname":"D02", "port":"D", "num":"2", "functions":{"USART2_TX":0}, "csv":{} },
|
||||
{ "name":"PD3", "sortingname":"D03", "port":"D", "num":"3", "functions":{"USART1_RX":0}, "csv":{} },
|
||||
{ "name":"PD4", "sortingname":"D04", "port":"D", "num":"4", "functions":{}, "csv":{} },
|
||||
{ "name":"PD5", "sortingname":"D05", "port":"D", "num":"5", "functions":{}, "csv":{} },
|
||||
{ "name":"PD6", "sortingname":"D06", "port":"D", "num":"6", "functions":{}, "csv":{} },
|
||||
{ "name":"PD7", "sortingname":"D07", "port":"D", "num":"7", "functions":{}, "csv":{} },
|
||||
{ "name":"PD8", "sortingname":"D08", "port":"D", "num":"8", "functions":{}, "csv":{} },
|
||||
{ "name":"PD9", "sortingname":"D09", "port":"D", "num":"9", "functions":{}, "csv":{} },
|
||||
{ "name":"PD10", "sortingname":"D10", "port":"D", "num":"10", "functions":{}, "csv":{} },
|
||||
{ "name":"PD11", "sortingname":"D11", "port":"D", "num":"11", "functions":{}, "csv":{} },
|
||||
{ "name":"PD12", "sortingname":"D12", "port":"D", "num":"12", "functions":{}, "csv":{} },
|
||||
{ "name":"PD13", "sortingname":"D13", "port":"D", "num":"13", "functions":{}, "csv":{} },
|
||||
{ "name":"PD14", "sortingname":"D14", "port":"D", "num":"14", "functions":{}, "csv":{} },
|
||||
{ "name":"PD15", "sortingname":"D15", "port":"D", "num":"15", "functions":{}, "csv":{} },
|
||||
{ "name":"PD16", "sortingname":"D16", "port":"D", "num":"16", "functions":{}, "csv":{} },
|
||||
{ "name":"PA0", "sortingname":"A00", "port":"A", "num":"17", "functions":{ "ADC1_IN0":0 }, "csv":{} }
|
||||
]
|
||||
return pins;
|
||||
|
||||
@ -44,9 +44,9 @@ chip = {
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : 0x78000,
|
||||
'address' : 0x77000,
|
||||
'page_size' : 4096,
|
||||
'pages' : 3,
|
||||
'pages' : 4,
|
||||
'flash_available' : 468, # firmware can be up to this size
|
||||
},
|
||||
};
|
||||
@ -132,10 +132,25 @@ board_esp01["_css"] = """
|
||||
boards = [ board_esp12, board_esp01 ];
|
||||
|
||||
def get_pins():
|
||||
pins = pinutils.generate_pins(0,16)
|
||||
pinutils.findpin(pins, "PD0", True)["functions"]["LED_1"]=0;
|
||||
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
|
||||
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
|
||||
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
|
||||
# just fake pins D0 .. D16
|
||||
return pins
|
||||
# add pins D0 .. D16,A0
|
||||
pins = [
|
||||
{ "name":"PD0", "sortingname":"D00", "port":"D", "num":"0", "functions":{"LED_1":0}, "csv":{} },
|
||||
{ "name":"PD1", "sortingname":"D01", "port":"D", "num":"1", "functions":{"USART1_TX":0}, "csv":{} },
|
||||
{ "name":"PD2", "sortingname":"D02", "port":"D", "num":"2", "functions":{"USART2_TX":0}, "csv":{} },
|
||||
{ "name":"PD3", "sortingname":"D03", "port":"D", "num":"3", "functions":{"USART1_RX":0}, "csv":{} },
|
||||
{ "name":"PD4", "sortingname":"D04", "port":"D", "num":"4", "functions":{}, "csv":{} },
|
||||
{ "name":"PD5", "sortingname":"D05", "port":"D", "num":"5", "functions":{}, "csv":{} },
|
||||
{ "name":"PD6", "sortingname":"D06", "port":"D", "num":"6", "functions":{}, "csv":{} },
|
||||
{ "name":"PD7", "sortingname":"D07", "port":"D", "num":"7", "functions":{}, "csv":{} },
|
||||
{ "name":"PD8", "sortingname":"D08", "port":"D", "num":"8", "functions":{}, "csv":{} },
|
||||
{ "name":"PD9", "sortingname":"D09", "port":"D", "num":"9", "functions":{}, "csv":{} },
|
||||
{ "name":"PD10", "sortingname":"D10", "port":"D", "num":"10", "functions":{}, "csv":{} },
|
||||
{ "name":"PD11", "sortingname":"D11", "port":"D", "num":"11", "functions":{}, "csv":{} },
|
||||
{ "name":"PD12", "sortingname":"D12", "port":"D", "num":"12", "functions":{}, "csv":{} },
|
||||
{ "name":"PD13", "sortingname":"D13", "port":"D", "num":"13", "functions":{}, "csv":{} },
|
||||
{ "name":"PD14", "sortingname":"D14", "port":"D", "num":"14", "functions":{}, "csv":{} },
|
||||
{ "name":"PD15", "sortingname":"D15", "port":"D", "num":"15", "functions":{}, "csv":{} },
|
||||
{ "name":"PD16", "sortingname":"D16", "port":"D", "num":"16", "functions":{}, "csv":{} },
|
||||
{ "name":"PA0", "sortingname":"A00", "port":"A", "num":"17", "functions":{ "ADC1_IN0":0 }, "csv":{} }
|
||||
]
|
||||
return pins;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
import pinutils;
|
||||
info = {
|
||||
'name' : "Original Espruino Board rev 1.3/1.4",
|
||||
'link' : [ "http://www.espruino.com/EspruinoBoard" ],
|
||||
'link' : [ "http://www.espruino.com/Original" ],
|
||||
'espruino_page_link' : "EspruinoBoard",
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "A9",
|
||||
@ -26,8 +26,8 @@ info = {
|
||||
'serial_bootloader' : True,
|
||||
'binary_name' : 'espruino_%v_espruino_1r3.bin',
|
||||
'binaries' : [
|
||||
{ 'filename' : 'espruino_%v_espruino_1r3_wiznet.bin', 'description' : "WIZNet W5500 Ethernet Networking"},
|
||||
{ 'filename' : 'espruino_%v_espruino_1r3.bin', 'description' : "TI CC3000 WiFi Networking"},
|
||||
{ 'filename' : 'espruino_%v_espruino_1r3_wiznet.bin', 'description' : "WIZNet W5500 Ethernet Networking (no crypto lib)"},
|
||||
{ 'filename' : 'espruino_%v_espruino_1r3.bin', 'description' : "AT Command Networking only"},
|
||||
],
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
@ -35,7 +35,7 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'NEOPIXEL',
|
||||
'HASHLIB',
|
||||
'CRYPTO','SHA1_JS',
|
||||
# 'TV', # TV had to be removed because of flash usage
|
||||
'FILESYSTEM'
|
||||
],
|
||||
|
||||
@ -34,9 +34,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'TV',
|
||||
'HASHLIB',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'NEOPIXEL'
|
||||
],
|
||||
@ -46,7 +45,7 @@ info = {
|
||||
'WIZNET=1', # Add support for W5500 by default (not CC3000)
|
||||
'STLIB=STM32F411xE',
|
||||
'PRECOMPILED_OBJS+=$(ROOT)/targetlibs/stm32f4/lib/startup_stm32f401xx.o',
|
||||
'JSMODULESOURCES+=libs/js/espruino_wifi/AT.min.js',
|
||||
'JSMODULESOURCES+=libs/js/AT.min.js',
|
||||
'JSMODULESOURCES+=libs/js/espruino_wifi/Wifi.min.js',
|
||||
]
|
||||
}
|
||||
|
||||
@ -55,15 +55,15 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 5) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 5,
|
||||
'flash_available' : 512 - ((31 + 8 + 1 + 5)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 5. Each page is 4 kb.
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -24,9 +24,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'HASHLIB',
|
||||
'TELNET',
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -27,7 +27,6 @@ info = {
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'TV',
|
||||
'HASHLIB'
|
||||
],
|
||||
'makefile' : [
|
||||
'STLIB=STM32F10X_HD',
|
||||
|
||||
@ -17,6 +17,8 @@ import pinutils;
|
||||
|
||||
info = {
|
||||
'name' : "MDBT42Q Module",
|
||||
'link' : [ "http://www.espruino.com/MDBT42Q" ],
|
||||
'espruino_page_link' : 'MDBT42Q',
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D6",
|
||||
'default_console_rx' : "D8",
|
||||
@ -30,17 +32,17 @@ info = {
|
||||
'BLUETOOTH',
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'AES',
|
||||
'NFC',
|
||||
'NEOPIXEL'
|
||||
#'HASHLIB'
|
||||
#'FILESYSTEM'
|
||||
'NEOPIXEL',
|
||||
'FILESYSTEM'
|
||||
#'TLS'
|
||||
],
|
||||
'makefile' : [
|
||||
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
|
||||
'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"MQBT42Q"\'',
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"MDBT42Q"\'',
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C'
|
||||
]
|
||||
@ -55,53 +57,121 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 3) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 3,
|
||||
'flash_available' : 512 - ((31 + 8 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 3. Each page is 4 kb.
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
devices = {
|
||||
'LED1' : { 'pin' : 'D1' },
|
||||
'LED2' : { 'pin' : 'D2', 'no_bootloader':True }, # don't use LED2 in the bootloader since we may be using a bare module
|
||||
'BTN1' : { 'pin' : 'D0', 'pinstate' : 'IN_PULLDOWN' },
|
||||
'NFC': { 'pin_a':'D9', 'pin_b':'D10' },
|
||||
# Pin D22 is used for clock when driving neopixels - as not specifying a pin seems to break things
|
||||
};
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
board_module = {
|
||||
'left' : [ 'GND','','','','D25','D26','D27','D28','D29','D30','D31','DEC4','DCC','VDD'],
|
||||
'right' : [ 'GND','D22','SWDIO','SWDCLK','D21/NRST','D20','D19','D18','D17','D16','D15','D14','D13','D12','D11' ],
|
||||
'right2' : [ 'D24', '', 'D23'],
|
||||
'right' : [ 'GND','D22','SWDIO','SWDCLK','D21','D20','D19','D18','D17','D16','D15','D14','D13','D12','D11' ],
|
||||
'bottom' : [ 'GND','D0','D1','D2','D3','D4','D5','D6','D7','D8','D9','D10','GND' ],
|
||||
'_notes' : {
|
||||
'D21' : "Also NRST if configured"
|
||||
}
|
||||
};
|
||||
|
||||
board["_css"] = """
|
||||
board_module["_css"] = """
|
||||
#board {
|
||||
width: 800px;
|
||||
height: 800px;
|
||||
width: 359px;
|
||||
height: 484px;
|
||||
top: 0px;
|
||||
left : 0px;
|
||||
left : 200px;
|
||||
background-image: url(img/MDBT42Q.jpg);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 900px;
|
||||
height: 650px;
|
||||
}
|
||||
#bottom {
|
||||
top: 639px;
|
||||
left: 291px;
|
||||
#board #bottom {
|
||||
top: 440px;
|
||||
left: 56px;
|
||||
}
|
||||
#right {
|
||||
top: 304px;
|
||||
left: 640px;
|
||||
#board #left {
|
||||
top: 115px;
|
||||
right: 316px;
|
||||
}
|
||||
#board #right2 {
|
||||
top: 115px;
|
||||
right: 110px;
|
||||
}
|
||||
#board #right {
|
||||
top: 115px;
|
||||
left: 316px;
|
||||
}
|
||||
|
||||
#board .leftpin { height: 17px; }
|
||||
#board .left2pin { height: 17px; }
|
||||
#board .rightpin { height: 17px; }
|
||||
#board .bottompin { width: 15px; padding:0px; }
|
||||
""";
|
||||
|
||||
board_breakout = {
|
||||
'left' : [ 'D25','D26','D27','D28','D29','D30','D31','D3','D4','D5','D11' ],
|
||||
'right' : [ 'D22','D20','D19','D18','D17','D16','D15','D14','3.3','Vin','GND'],
|
||||
'bottom' : [ 'D6','D8','D7','Vin','GND' ],
|
||||
'top' : [ 'D9','D10' ],
|
||||
'_hide_not_on_connectors' : True,
|
||||
'_class' : "board_breakout",
|
||||
'_notes' : {
|
||||
'D8' : "Serial Console RX when Bluetooth disconnected",
|
||||
'D6' : "Serial Console TX when Bluetooth disconnected",
|
||||
}
|
||||
};
|
||||
|
||||
board_breakout["_css"] = """
|
||||
#board {
|
||||
width: 255px;
|
||||
height: 400px;
|
||||
top: 0px;
|
||||
left : 200px;
|
||||
background-image: url(img/MDBT42Q_BREAKOUT.png);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 600px;
|
||||
}
|
||||
#board #bottom {
|
||||
top: 410px;
|
||||
left: 40px;
|
||||
}
|
||||
#board #top {
|
||||
bottom: 75px;
|
||||
left: 167px;
|
||||
}
|
||||
#board #left {
|
||||
top: 17px;
|
||||
right: 256px;
|
||||
}
|
||||
#board #right {
|
||||
top: 17px;
|
||||
left: 256px;
|
||||
}
|
||||
|
||||
#board .leftpin { height: 33px; }
|
||||
#board .rightpin { height: 33px; }
|
||||
#board .toppin { width: 15px; padding:0px; }
|
||||
#board .bottompin { width: 31px; padding:0px; }
|
||||
""";
|
||||
|
||||
boards = [board_module, board_breakout];
|
||||
|
||||
|
||||
def get_pins():
|
||||
pins = pinutils.generate_pins(0,31) # 32 General Purpose I/O Pins.
|
||||
pinutils.findpin(pins, "PD0", True)["functions"]["XL1"]=0;
|
||||
|
||||
@ -34,7 +34,7 @@ info = {
|
||||
'makefile' : [
|
||||
'SAVE_ON_FLASH=1',
|
||||
'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES+=-DUSE_DEBUGGER -DUSE_TAB_COMPLETE',
|
||||
'DEFINES+=-DUSE_TAB_COMPLETE', # Removed -DUSE_DEBUGGER due to firmware size issues
|
||||
'INCLUDE += -I$(ROOT)/libs/microbit',
|
||||
'WRAPPERSOURCES += libs/microbit/jswrap_microbit.c'
|
||||
]
|
||||
@ -55,10 +55,10 @@ chip = {
|
||||
# If using DFU bootloader, it sits at 0x3C000 - 0x40000 (0x40000 is end of flash)
|
||||
# Might want to change 256 -> 240 in the code below
|
||||
'saved_code' : {
|
||||
'address' : ((256 - 3) * 1024),
|
||||
'address' : ((256 - 2) * 1024),
|
||||
'page_size' : 1024,
|
||||
'pages' : 3,
|
||||
'flash_available' : (256 - 108 - 3) # total flash pages - softdevice - saved code
|
||||
'pages' : 2,
|
||||
'flash_available' : (256 - 108 - 2) # total flash pages - softdevice - saved code
|
||||
}
|
||||
};
|
||||
|
||||
@ -107,18 +107,18 @@ board["_css"] = """
|
||||
|
||||
def get_pins():
|
||||
pins = [
|
||||
{ "name":"PD0", "sortingname":"D00", "port":"D", "num":"1", "functions":{ "ADC1_IN4":0 }, "csv":{} },
|
||||
{ "name":"PD0", "sortingname":"D00", "port":"D", "num":"1", "functions":{ "ADC1_IN2":0 }, "csv":{} },
|
||||
{ "name":"PD1", "sortingname":"D01", "port":"D", "num":"2", "functions":{ "ADC1_IN3":0 }, "csv":{} },
|
||||
{ "name":"PD2", "sortingname":"D02", "port":"D", "num":"3", "functions":{ "ADC1_IN2":0 }, "csv":{} },
|
||||
{ "name":"PD2", "sortingname":"D02", "port":"D", "num":"3", "functions":{ "ADC1_IN4":0 }, "csv":{} },
|
||||
{ "name":"PD3", "sortingname":"D03", "port":"D", "num":"4", "functions":{ "ADC1_IN5":0 }, "csv":{} }, # LED col 1
|
||||
{ "name":"PD4", "sortingname":"D04", "port":"D", "num":"5", "functions":{}, "csv":{} }, # BTNA
|
||||
{ "name":"PD5", "sortingname":"D05", "port":"D", "num":"17", "functions":{ "ADC1_IN6":0 }, "csv":{} }, # LED col 2
|
||||
{ "name":"PD4", "sortingname":"D04", "port":"D", "num":"5", "functions":{ "ADC1_IN6":0 }, "csv":{} }, # BTNA
|
||||
{ "name":"PD5", "sortingname":"D05", "port":"D", "num":"17", "functions":{}, "csv":{} }, # LED col 2
|
||||
{ "name":"PD6", "sortingname":"D06", "port":"D", "num":"12", "functions":{}, "csv":{} }, # LED row 2
|
||||
{ "name":"PD7", "sortingname":"D07", "port":"D", "num":"11", "functions":{}, "csv":{} }, # LED row 1
|
||||
{ "name":"PD8", "sortingname":"D08", "port":"D", "num":"18", "functions":{}, "csv":{} },
|
||||
{ "name":"PD9", "sortingname":"D09", "port":"D", "num":"10", "functions":{}, "csv":{} }, # LED row 3
|
||||
{ "name":"PD10", "sortingname":"D10", "port":"D", "num":"6", "functions":{ "ADC1_IN7":0 }, "csv":{} }, # LED col 3
|
||||
{ "name":"PD11", "sortingname":"D11", "port":"D", "num":"26", "functions":{}, "csv":{} }, # BTNB
|
||||
{ "name":"PD11", "sortingname":"D11", "port":"D", "num":"26", "functions":{ "ADC1_IN0":0 }, "csv":{} }, # BTNB
|
||||
{ "name":"PD12", "sortingname":"D12", "port":"D", "num":"20", "functions":{}, "csv":{} },
|
||||
{ "name":"PD13", "sortingname":"D13", "port":"D", "num":"23", "functions":{ "SPI1_SCK":0 }, "csv":{} },
|
||||
{ "name":"PD14", "sortingname":"D14", "port":"D", "num":"22", "functions":{ "SPI1_MISO":0 }, "csv":{} },
|
||||
|
||||
@ -16,8 +16,9 @@
|
||||
import pinutils;
|
||||
|
||||
info = {
|
||||
'name' : "nRF52 Preview Development Kit",
|
||||
'link' : [ "https://www.nordicsemi.com/Products/Bluetooth-Smart-Bluetooth-low-energy/nRF52832" ],
|
||||
'name' : "nRF52 Development Kit",
|
||||
'link' : [ "https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF52-DK" ],
|
||||
'espruino_page_link' : 'nRF52832DK',
|
||||
# This is the PCA10036
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D6",
|
||||
@ -25,7 +26,7 @@ info = {
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2250, # 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_nrf52832.bin',
|
||||
'binary_name' : 'espruino_%v_nrf52832.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
@ -51,15 +52,15 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 3) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 3,
|
||||
'flash_available' : 512 - ((31 + 8 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 3. Each page is 4 kb.
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
@ -81,10 +82,39 @@ devices = {
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
'left' : [ 'VDD', 'VDD', 'RESET', 'VDD','5V','GND','GND','PD3','PD4','PD28','PD29','PD30','PD31'],
|
||||
'right' : [ 'PD27', 'PD26', 'PD2', 'GND', 'PD25','PD24','PD23', 'PD22','PD20','PD19','PD18','PD17','PD16','PD15','PD14','PD13','PD12','PD11','PD10','PD9','PD8','PD7','PD6','PD5','PD21','PD1','PD0'],
|
||||
'left' : [ 'VDD', 'VDD', 'RESET', 'VDD','5V','GND','GND','','','D3','D4','D28','D29','D30','D31'],
|
||||
'right' : [
|
||||
'D27', 'D26', 'D2', 'GND', 'D25','D24','D23', 'D22','D20','D19','',
|
||||
'D18','D17','D16','D15','D14','D13','D12','D11','',
|
||||
'D10','D9','D8','D7','D6','D5','D21','D1','D0'],
|
||||
'_notes' : {
|
||||
'D6' : "Serial console RX",
|
||||
'D8' : "Serial console TX"
|
||||
}
|
||||
};
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 528px;
|
||||
height: 800px;
|
||||
top: 0px;
|
||||
left : 200px;
|
||||
background-image: url(img/NRF52832DK.jpg);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 900px;
|
||||
}
|
||||
|
||||
#left {
|
||||
top: 219px;
|
||||
right: 466px;
|
||||
}
|
||||
#right {
|
||||
top: 150px;
|
||||
left: 466px;
|
||||
}
|
||||
|
||||
.leftpin { height: 17px; }
|
||||
.rightpin { height: 17px; }
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
@ -114,7 +144,7 @@ def get_pins():
|
||||
pinutils.findpin(pins, "PD18", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PD19", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PD20", True)["functions"]["NEGATED"]=0;
|
||||
|
||||
|
||||
# everything is non-5v tolerant
|
||||
for pin in pins:
|
||||
pin["functions"]["3.3"]=0;
|
||||
|
||||
@ -60,7 +60,7 @@ chip = {
|
||||
'page_size' : 131072, # size of pages : on STM32F401, last 2 pages are 128 Kbytes
|
||||
# we use the last flash page only, furthermore it persists after a firmware flash of the board
|
||||
'pages' : 1, # count of pages we're using to save RAM to Flash,
|
||||
'flash_available' : 512 # binary will have a hole in it, so we just want to test against full size
|
||||
'flash_available' : 384 # we use the last 128k page
|
||||
},
|
||||
#'place_text_section' : 0x08010000, # note flash_available above # TODO USELESS
|
||||
};
|
||||
|
||||
@ -60,7 +60,7 @@ chip = {
|
||||
'page_size' : 131072, # size of pages : on STM32F411, last 2 pages are 128 Kbytes
|
||||
# we use the last flash page only, furthermore it persists after a firmware flash of the board
|
||||
'pages' : 1, # count of pages we're using to save RAM to Flash,
|
||||
'flash_available' : 512 # binary will have a hole in it, so we just want to test against full size
|
||||
'flash_available' : 384 # we use the last 128k page
|
||||
},
|
||||
#'place_text_section' : 0x08010000, # note flash_available above # TODO USELESS
|
||||
};
|
||||
|
||||
@ -60,7 +60,7 @@ chip = {
|
||||
'page_size' : 131072, # size of pages : on STM32F411, last 2 pages are 128 Kbytes
|
||||
# we use the last flash page only, furthermore it persists after a firmware flash of the board
|
||||
'pages' : 1, # count of pages we're using to save RAM to Flash,
|
||||
'flash_available' : 512 # binary will have a hole in it, so we just want to test against full size
|
||||
'flash_available' : 384 # we use the last 128k page
|
||||
},
|
||||
#'place_text_section' : 0x08010000, # note flash_available above # TODO USELESS
|
||||
};
|
||||
|
||||
@ -27,7 +27,6 @@ info = {
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'TV',
|
||||
'HASHLIB'
|
||||
],
|
||||
'makefile' : [
|
||||
'STLIB=STM32F10X_HD',
|
||||
|
||||
@ -35,9 +35,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'TV',
|
||||
'HASHLIB',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'NEOPIXEL'
|
||||
],
|
||||
|
||||
@ -24,7 +24,7 @@ info = {
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2500, # 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_pixljs.bin',
|
||||
'binary_name' : 'espruino_%v_pixljs.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
@ -34,16 +34,23 @@ info = {
|
||||
'NFC',
|
||||
'NEOPIXEL',
|
||||
'PIXLJS',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'AES',
|
||||
'FILESYSTEM',
|
||||
'TERMINAL'
|
||||
],
|
||||
'makefile' : [
|
||||
'WIZNET=1','W5100=1', # Add WIZnet support - W5100 is the most common Arduino shield
|
||||
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
|
||||
# 'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Pixl.js"\'',
|
||||
'DEFINES+=-DNFC_DEFAULT_URL=\'"https://www.espruino.com/ide"\'',
|
||||
'DEFINES+=-DDUMP_IGNORE_VARIABLES=\'"g\\0"\'',
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
|
||||
'INCLUDE += -I$(ROOT)/libs/pixljs',
|
||||
'WRAPPERSOURCES += libs/pixljs/jswrap_pixljs.c'
|
||||
'WRAPPERSOURCES += libs/pixljs/jswrap_pixljs.c',
|
||||
'JSMODULESOURCES += libs/js/graphical_menu.min.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -57,15 +64,15 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 5) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'address' : ((118 - 9) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 5,
|
||||
'flash_available' : 512 - ((31 + 8 + 1 + 5)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 5. Each page is 4 kb.
|
||||
'pages' : 9,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 9)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
@ -89,19 +96,50 @@ devices = {
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
'top' : [ 'D0','D1','D2','D3','D4','D5','D6','D7','','D8','D9','D10','D11','D12','D13','GND','','A4','A5' ],
|
||||
'bottom' : [ 'A5','A4','A3','A2','A1','A0','','Vin','GND','GND','5V','3.3V','RST','3.3V','','','GND','Vin'],
|
||||
'bottom2' : [ '3.3V','SWIO','SWCK','GND'],
|
||||
|
||||
'_notes' : {
|
||||
'D0' : "Serial Console RX when Bluetooth disconnected",
|
||||
'D1' : "Serial Console TX when Bluetooth disconnected",
|
||||
'A4' : "Also used for the pin marked SDA",
|
||||
'A5' : "Also used for the pin marked SCL",
|
||||
'5V' : "Pixl.js has no 5v rail so this is not connected by default. A solder jumper can be used to connect it to Vin or 3.3v"
|
||||
}
|
||||
};
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 650px;
|
||||
height: 568px;
|
||||
top: 100px;
|
||||
left : 100px;
|
||||
background-image: url(img/PIXLJS.png);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 800px;
|
||||
}
|
||||
#top {
|
||||
bottom: 553px;
|
||||
left: 74px;
|
||||
}
|
||||
#bottom {
|
||||
top: 555px;
|
||||
left: 74px;
|
||||
}
|
||||
#bottom2 {
|
||||
top: 374px;
|
||||
left: 64px;
|
||||
}
|
||||
|
||||
.toppin { width: 21px; }
|
||||
.bottompin { width: 21px; }
|
||||
.bottom2pin { width: 21px; }
|
||||
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
pins = [
|
||||
{ "name":"PA0", "sortingname":"A00", "port":"A", "num":"2", "functions":{ "ADC1_IN0":0 }, "csv":{} },
|
||||
{ "name":"PA1", "sortingname":"A01", "port":"A", "num":"3", "functions":{ "ADC1_IN1":0 }, "csv":{} },
|
||||
{ "name":"PA2", "sortingname":"A02", "port":"A", "num":"4", "functions":{ "ADC1_IN2":0 }, "csv":{} },
|
||||
{ "name":"PA3", "sortingname":"A03", "port":"A", "num":"5", "functions":{ "ADC1_IN3":0 }, "csv":{} },
|
||||
{ "name":"PA4", "sortingname":"A04", "port":"A", "num":"28", "functions":{ "ADC1_IN4":0 }, "csv":{} },
|
||||
{ "name":"PA5", "sortingname":"A05", "port":"A", "num":"29", "functions":{ "ADC1_IN5":0 }, "csv":{} },
|
||||
|
||||
{ "name":"PD0", "sortingname":"D00", "port":"D", "num":"25", "functions":{}, "csv":{} },
|
||||
{ "name":"PD1", "sortingname":"D01", "port":"D", "num":"26", "functions":{}, "csv":{} },
|
||||
{ "name":"PD2", "sortingname":"D02", "port":"D", "num":"27", "functions":{}, "csv":{} },
|
||||
@ -117,11 +155,18 @@ def get_pins():
|
||||
{ "name":"PD12", "sortingname":"D12", "port":"D", "num":"19", "functions":{}, "csv":{} },
|
||||
{ "name":"PD13", "sortingname":"D13", "port":"D", "num":"20", "functions":{}, "csv":{} },
|
||||
|
||||
{ "name":"PA0", "sortingname":"A00", "port":"A", "num":"2", "functions":{ "ADC1_IN0":0 }, "csv":{} },
|
||||
{ "name":"PA1", "sortingname":"A01", "port":"A", "num":"3", "functions":{ "ADC1_IN1":0 }, "csv":{} },
|
||||
{ "name":"PA2", "sortingname":"A02", "port":"A", "num":"4", "functions":{ "ADC1_IN2":0 }, "csv":{} },
|
||||
{ "name":"PA3", "sortingname":"A03", "port":"A", "num":"5", "functions":{ "ADC1_IN3":0 }, "csv":{} },
|
||||
{ "name":"PA4", "sortingname":"A04", "port":"A", "num":"28", "functions":{ "ADC1_IN4":0 }, "csv":{} },
|
||||
{ "name":"PA5", "sortingname":"A05", "port":"A", "num":"29", "functions":{ "ADC1_IN5":0 }, "csv":{} },
|
||||
|
||||
{ "name":"PH0", "sortingname":"H0", "port":"H", "num":"16", "functions":{}, "csv":{} }, # LED
|
||||
{ "name":"PH1", "sortingname":"H1", "port":"H", "num":"24", "functions":{}, "csv":{} }, # BTN1
|
||||
{ "name":"PH2", "sortingname":"H2", "port":"H", "num":"23", "functions":{}, "csv":{} }, # 2
|
||||
{ "name":"PH1", "sortingname":"H1", "port":"H", "num":"23", "functions":{}, "csv":{} }, # BTN1
|
||||
{ "name":"PH2", "sortingname":"H2", "port":"H", "num":"21", "functions":{}, "csv":{} }, # 2
|
||||
{ "name":"PH3", "sortingname":"H3", "port":"H", "num":"22", "functions":{}, "csv":{} }, # 3
|
||||
{ "name":"PH4", "sortingname":"H4", "port":"H", "num":"21", "functions":{}, "csv":{} }, # 4
|
||||
{ "name":"PH4", "sortingname":"H4", "port":"H", "num":"24", "functions":{}, "csv":{} }, # 4
|
||||
{ "name":"PH5", "sortingname":"H5", "port":"H", "num":"13", "functions":{}, "csv":{} }, # LCD DC
|
||||
{ "name":"PH6", "sortingname":"H6", "port":"H", "num":"12", "functions":{}, "csv":{} }, # LCD CS
|
||||
{ "name":"PH7", "sortingname":"H7", "port":"H", "num":"11", "functions":{}, "csv":{} }, # LCD RST
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
import pinutils;
|
||||
|
||||
info = {
|
||||
'name' : "PuckJS",
|
||||
'name' : "Puck.js",
|
||||
'link' : [ "http://www.espruino.com/PuckJS" ],
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D28",
|
||||
@ -31,10 +31,10 @@ info = {
|
||||
'BLUETOOTH',
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'AES',
|
||||
'NFC',
|
||||
'NEOPIXEL'
|
||||
#'HASHLIB'
|
||||
'NEOPIXEL',
|
||||
#'FILESYSTEM'
|
||||
#'TLS'
|
||||
],
|
||||
@ -42,6 +42,7 @@ info = {
|
||||
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
|
||||
'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Puck.js"\'',
|
||||
'DEFINES+=-DNFC_DEFAULT_URL=\'"https://puck-js.com/go"\'',
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
|
||||
'INCLUDE += -I$(ROOT)/libs/puckjs',
|
||||
@ -58,15 +59,15 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 3) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 3,
|
||||
'flash_available' : 512 - ((31 + 8 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 3. Each page is 4 kb.
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
163
boards/RAK8211.py
Normal file
@ -0,0 +1,163 @@
|
||||
#!/bin/false
|
||||
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
#
|
||||
# Copyright (C) 2018 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;
|
||||
|
||||
# Schematic http://docs.rakwireless.com/en/RAK8211/Hardware%20Design/RAK8211_iTRACKER_M35_V20_20171203.pdf
|
||||
# GPS HW https://www.quectel.com/UploadImage/Downlad/L70_Hardware_Design_V2.0.pdf
|
||||
# GPS SW http://docs-europe.electrocomponents.com/webdocs/147d/0900766b8147dbdd.pdf
|
||||
|
||||
info = {
|
||||
'name' : "iTracker RAK8211",
|
||||
#https://github.com/RAKWireless/ITRACKER-Arduino-SDK
|
||||
'link' : [ "http://www.rakwireless.com/en/download/Cellular/RAK8211" ],
|
||||
'espruino_page_link' : 'RAK8211',
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D29",
|
||||
'default_console_rx' : "D28",
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2500, # 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_RAK8211.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
'BLUETOOTH',
|
||||
'NET'
|
||||
],
|
||||
'makefile' : [
|
||||
'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES+=-DCONFIG_NFCT_PINS_AS_GPIOS', # Don't use NFC - the pins are used for GPS
|
||||
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"iTracker"\'',
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
|
||||
'JSMODULESOURCES += libs/js/AT.min.js',
|
||||
'JSMODULESOURCES += libs/js/GPS.min.js',
|
||||
'JSMODULESOURCES += libs/js/BME280.min.js',
|
||||
'JSMODULESOURCES += libs/js/LIS2MDL.min.js',
|
||||
'JSMODULESOURCES += libs/js/LIS3DH.min.js',
|
||||
'JSMODULESOURCES += libs/js/OPT3001.min.js',
|
||||
'JSMODULESOURCES += libs/js/ATSMS.min.js',
|
||||
'JSMODULESOURCES += libs/js/QuectelM35.min.js',
|
||||
'JSMODULESOURCES += iTracker:libs/js/rak/RAK8211.min.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
chip = {
|
||||
'part' : "NRF52832",
|
||||
'family' : "NRF52",
|
||||
'package' : "QFN48",
|
||||
'ram' : 64,
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 3,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((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' : 'D30', 'pinstate' : 'IN_PULLDOWN' },
|
||||
'GPRS' : {'pin_tx' : 'D12', 'pin_rx' : 'D20', 'pin_reset' : 'D14', 'pin_pwrkey' : 'D15', 'pin_pwron' : 'D6'},
|
||||
'GPS' : {'pin_tx' : 'D9', 'pin_rx' : 'D8', 'pin_standby' : 'D7', 'pin_pwron' : 'D10', 'pin_reset' : 'D31'},
|
||||
'BME' : {'pin_cs' : 'D2', 'pin_sdi' : 'D3', 'pin_sck': 'D4', 'pin_sdo' : 'D5'},
|
||||
'LIS2MDL' : {'pin_scl' : 'D11', 'pin_sda': 'D13', 'pin_int' : 'D16'},
|
||||
'LIS3DH' : {'pin_scl' : 'D18', 'pin_sda' : 'D19', 'pin_int1' : 'D25', 'pin_res' : 'D26', 'pin_int2' : 'D27'},
|
||||
'OPT' : {'pin_sda' : '21', 'pin_scl' : 'D23', 'pin_int' : 'D22'}
|
||||
# Pin D22 is used for clock when driving neopixels - as not specifying a pin seems to break things
|
||||
};
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
'right' : [ 'D21', '3V', 'GND', 'D30', '',
|
||||
'GND', '3V', 'D29', 'D28', '',
|
||||
'3V', 'SWDIO', 'SWDCLK', 'GND' ],
|
||||
'_hide_not_on_connectors' : True,
|
||||
'_notes' : {
|
||||
'D21' : "Also RESET if configured",
|
||||
'D30' : "Labelled TILT_DOUT",
|
||||
'D29' : "Labelled SENSOR_DOUT2",
|
||||
'D28' : "Labelled SENSOR_DOUT1"
|
||||
}
|
||||
};
|
||||
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 400px;
|
||||
height: 506px;
|
||||
top: 0px;
|
||||
left : 0px;
|
||||
background-image: url(img/RAK8211.png);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 506px;
|
||||
}
|
||||
#right {
|
||||
top: 73px;
|
||||
left: 405px;
|
||||
}
|
||||
.rightpin {
|
||||
height: 18px;
|
||||
}
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
pins = pinutils.generate_pins(0,31) # 32 General Purpose I/O Pins.
|
||||
pinutils.findpin(pins, "PD0", True)["functions"]["XL1"]=0;
|
||||
pinutils.findpin(pins, "PD1", True)["functions"]["XL2"]=0;
|
||||
pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0;
|
||||
pinutils.findpin(pins, "PD28", True)["functions"]["USART1_TX"]=0;
|
||||
pinutils.findpin(pins, "PD29", True)["functions"]["USART1_RX"]=0;
|
||||
pinutils.findpin(pins, "PD12", True)["functions"]["GPRS_TX"]=0;
|
||||
pinutils.findpin(pins, "PD20", True)["functions"]["GPRS_RX"]=0;
|
||||
pinutils.findpin(pins, "PD14", True)["functions"]["GPRS_RESET"]=0;
|
||||
pinutils.findpin(pins, "PD15", True)["functions"]["GPRS_PWRKEY"]=0;
|
||||
pinutils.findpin(pins, "PD6", True)["functions"]["GPRS_PWN_ON"]=0;
|
||||
pinutils.findpin(pins, "PD9", True)["functions"]["GPS_TX"]=0;
|
||||
pinutils.findpin(pins, "PD8", True)["functions"]["GPS_RX"]=0;
|
||||
pinutils.findpin(pins, "PD7", True)["functions"]["GPS_STANDBY"]=0;
|
||||
pinutils.findpin(pins, "PD10", True)["functions"]["GPS_PWR_ON"]=0;
|
||||
pinutils.findpin(pins, "PD31", True)["functions"]["GPS_RESET"]=0;
|
||||
pinutils.findpin(pins, "PD2", True)["functions"]["BME_CS"]=0;
|
||||
pinutils.findpin(pins, "PD3", True)["functions"]["BME_SDI"]=0;
|
||||
pinutils.findpin(pins, "PD4", True)["functions"]["BME_SCK"]=0;
|
||||
pinutils.findpin(pins, "PD5", True)["functions"]["BME_SDO"]=0;
|
||||
pinutils.findpin(pins, "PD11", True)["functions"]["LIS2MDL_SCL"]=0;
|
||||
pinutils.findpin(pins, "PD13", True)["functions"]["LIS2MDL_SDA"]=0;
|
||||
pinutils.findpin(pins, "PD16", True)["functions"]["LIS2MDL_INT"]=0;
|
||||
pinutils.findpin(pins, "PD18", True)["functions"]["LIS3DH_SCL"]=0;
|
||||
pinutils.findpin(pins, "PD19", True)["functions"]["LIS3DH_SDA"]=0;
|
||||
pinutils.findpin(pins, "PD25", True)["functions"]["LIS3DH_INT1"]=0;
|
||||
pinutils.findpin(pins, "PD27", True)["functions"]["LIS3DH_INT2"]=0;
|
||||
pinutils.findpin(pins, "PD26", True)["functions"]["OPT_SDA"]=0;
|
||||
pinutils.findpin(pins, "PD23", True)["functions"]["OPT_SCL"]=0;
|
||||
pinutils.findpin(pins, "PD22", True)["functions"]["OPT_INT"]=0;
|
||||
|
||||
|
||||
# everything is non-5v tolerant
|
||||
for pin in pins:
|
||||
pin["functions"]["3.3"]=0;
|
||||
|
||||
#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
|
||||
163
boards/RAK8212.py
Normal file
@ -0,0 +1,163 @@
|
||||
#!/bin/false
|
||||
# This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
#
|
||||
# Copyright (C) 2018 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;
|
||||
|
||||
# Schematic http://docs.rakwireless.com/en/Cellular/RAK8212/Hardware%20Specification/RAK8212_iTRACKER_BG96_V30_20180322.pdf
|
||||
|
||||
info = {
|
||||
'name' : "iTracker RAK8212",
|
||||
#https://github.com/RAKWireless/ITRACKER-Arduino-SDK
|
||||
'link' : [ "http://www.rakwireless.com/en/download/Cellular/RAK8212" ],
|
||||
'espruino_page_link' : 'RAK8212',
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D29",
|
||||
'default_console_rx' : "D28",
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2500, # 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_RAK8212.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
'BLUETOOTH',
|
||||
'NET'
|
||||
],
|
||||
'makefile' : [
|
||||
'DEFINES+=-DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES+=-DCONFIG_NFCT_PINS_AS_GPIOS', # Don't use NFC - the pins are used for GPS
|
||||
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"iTracker"\'',
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
|
||||
'JSMODULESOURCES += libs/js/AT.min.js',
|
||||
'JSMODULESOURCES += libs/js/GPS.min.js',
|
||||
'JSMODULESOURCES += libs/js/BME280.min.js',
|
||||
'JSMODULESOURCES += libs/js/LIS2MDL.min.js',
|
||||
'JSMODULESOURCES += libs/js/LIS3DH.min.js',
|
||||
'JSMODULESOURCES += libs/js/OPT3001.min.js',
|
||||
'JSMODULESOURCES += libs/js/ATSMS.min.js',
|
||||
'JSMODULESOURCES += libs/js/QuectelBG96.min.js',
|
||||
'JSMODULESOURCES += iTracker:libs/js/rak/RAK8212.min.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
chip = {
|
||||
'part' : "NRF52832",
|
||||
'family' : "NRF52",
|
||||
'package' : "QFN48",
|
||||
'ram' : 64,
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 3,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
devices = {
|
||||
'LED1' : { 'pin' : 'D12' }, # Pin negated in software
|
||||
'BTN1' : { 'pin' : 'D30', 'pinstate' : 'IN_PULLDOWN' },
|
||||
'GPRS' : {'pin_tx' : 'D12', 'pin_rx' : 'D20', 'pin_reset' : 'D14', 'pin_pwrkey' : 'D15', 'pin_pwron' : 'D6'},
|
||||
'GPS' : {'pin_tx' : 'D9', 'pin_rx' : 'D8', 'pin_standby' : 'D7', 'pin_pwron' : 'D10', 'pin_reset' : 'D31'},
|
||||
'BME' : {'pin_cs' : 'D2', 'pin_sdi' : 'D3', 'pin_sck': 'D4', 'pin_sdo' : 'D5'},
|
||||
'LIS2MDL' : {'pin_scl' : 'D11', 'pin_sda': 'D13', 'pin_int' : 'D16'},
|
||||
'LIS3DH' : {'pin_scl' : 'D18', 'pin_sda' : 'D19', 'pin_int1' : 'D25', 'pin_res' : 'D26', 'pin_int2' : 'D27'},
|
||||
'OPT' : {'pin_sda' : '21', 'pin_scl' : 'D23', 'pin_int' : 'D22'},
|
||||
# Pin D22 is used for clock when driving neopixels - as not specifying a pin seems to break things
|
||||
};
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
'right' : [ 'D21', '3V', 'GND', 'D30', '',
|
||||
'GND', '3V', 'D29', 'D28', '',
|
||||
'3V', 'SWDIO', 'SWDCLK', 'GND' ],
|
||||
'_hide_not_on_connectors' : True,
|
||||
'_notes' : {
|
||||
'D21' : "Also RESET if configured",
|
||||
'D30' : "Labelled TILT_DOUT",
|
||||
'D29' : "Labelled SENSOR_DOUT2",
|
||||
'D28' : "Labelled SENSOR_DOUT1"
|
||||
}
|
||||
};
|
||||
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 480px;
|
||||
height: 526px;
|
||||
top: 0px;
|
||||
left : 0px;
|
||||
background-image: url(img/RAK8212.png);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 506px;
|
||||
}
|
||||
#right {
|
||||
top: 59px;
|
||||
left: 480px;
|
||||
}
|
||||
.rightpin {
|
||||
height: 26px;
|
||||
}
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
pins = pinutils.generate_pins(0,31) # 32 General Purpose I/O Pins.
|
||||
# Software negation LED1
|
||||
pinutils.findpin(pins, "PD12", True)["functions"]["NEGATED"]=0;
|
||||
# Add pin functions
|
||||
pinutils.findpin(pins, "PD0", True)["functions"]["XL1"]=0;
|
||||
pinutils.findpin(pins, "PD1", True)["functions"]["XL2"]=0;
|
||||
pinutils.findpin(pins, "PD28", True)["functions"]["ADC1_IN4"]=0;
|
||||
pinutils.findpin(pins, "PD7", True)["functions"]["LTE_RX"]=0;
|
||||
pinutils.findpin(pins, "PD8", True)["functions"]["LTE_CTS"]=0;
|
||||
pinutils.findpin(pins, "PD9", True)["functions"]["LTE_TX"]=0;
|
||||
pinutils.findpin(pins, "PD10", True)["functions"]["LTE_RTS"]=0;
|
||||
pinutils.findpin(pins, "PD28", True)["functions"]["USART1_TX"]=0;
|
||||
pinutils.findpin(pins, "PD29", True)["functions"]["USART1_RX"]=0;
|
||||
pinutils.findpin(pins, "PD14", True)["functions"]["GPRS_RESET"]=0;
|
||||
pinutils.findpin(pins, "PD15", True)["functions"]["GPRS_PWRKEY"]=0;
|
||||
pinutils.findpin(pins, "PD6", True)["functions"]["GPRS_PWN_ON"]=0;
|
||||
pinutils.findpin(pins, "PD31", True)["functions"]["GPS_RESET"]=0;
|
||||
pinutils.findpin(pins, "PD2", True)["functions"]["BME_CS"]=0;
|
||||
pinutils.findpin(pins, "PD3", True)["functions"]["BME_SDI"]=0;
|
||||
pinutils.findpin(pins, "PD4", True)["functions"]["BME_SCK"]=0;
|
||||
pinutils.findpin(pins, "PD5", True)["functions"]["BME_SDO"]=0;
|
||||
pinutils.findpin(pins, "PD11", True)["functions"]["LIS2MDL_SCL"]=0;
|
||||
pinutils.findpin(pins, "PD13", True)["functions"]["LIS2MDL_SDA"]=0;
|
||||
pinutils.findpin(pins, "PD16", True)["functions"]["LIS2MDL_INT"]=0;
|
||||
pinutils.findpin(pins, "PD18", True)["functions"]["LIS3DH_SCL"]=0;
|
||||
pinutils.findpin(pins, "PD19", True)["functions"]["LIS3DH_SDA"]=0;
|
||||
pinutils.findpin(pins, "PD25", True)["functions"]["LIS3DH_INT1"]=0;
|
||||
pinutils.findpin(pins, "PD27", True)["functions"]["LIS3DH_INT2"]=0;
|
||||
pinutils.findpin(pins, "PD26", True)["functions"]["OPT_SDA"]=0;
|
||||
pinutils.findpin(pins, "PD23", True)["functions"]["OPT_SCL"]=0;
|
||||
pinutils.findpin(pins, "PD22", True)["functions"]["OPT_INT"]=0;
|
||||
|
||||
|
||||
# everything is non-5v tolerant
|
||||
for pin in pins:
|
||||
pin["functions"]["3.3"]=0;
|
||||
|
||||
#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
|
||||
@ -25,9 +25,8 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'FILESYSTEM',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'HASHLIB',
|
||||
'TELNET',
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -32,10 +32,9 @@ info = {
|
||||
'BLUETOOTH',
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'NFC',
|
||||
'NEOPIXEL'
|
||||
#'HASHLIB'
|
||||
#'FILESYSTEM'
|
||||
#'TLS'
|
||||
],
|
||||
@ -57,22 +56,22 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((115 - 3) * 4096), # Bootloader takes pages 117-127 on RuuviTag, FS takes 115-116
|
||||
'address' : ((115 - 10) * 4096), # Bootloader takes pages 117-127 on RuuviTag, FS takes 115-116
|
||||
'page_size' : 4096,
|
||||
'pages' : 3,
|
||||
'flash_available' : 512 - ((31 + 11 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 11, code 3. Each page is 4 kb.
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 11 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 11, fs 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
devices = {
|
||||
'LED1' : { 'pin' : 'D17', 'inverted' : True },
|
||||
'LED2' : { 'pin' : 'D19', 'inverted' : True },
|
||||
'BTN1' : { 'pin' : 'D13', 'inverted' : True, 'pinstate' : 'IN_PULLUP' },
|
||||
'LED1' : { 'pin' : 'D17' }, # Pin negated in software (see below)
|
||||
'LED2' : { 'pin' : 'D19' }, # Pin negated in software (see below)
|
||||
'BTN1' : { 'pin' : 'D13', 'pinstate' : 'IN_PULLDOWN' }, # Pin negated in software (see below)
|
||||
'CSBME' : { 'pin' : 'D3', 'inverted' : True, 'pinstate' : 'IN_PULLUP' },
|
||||
'CSLIS' : { 'pin' : 'D8', 'inverted' : True, 'pinstate' : 'IN_PULLUP' },
|
||||
'RX_PIN_NUMBER' : { 'pin' : 'D5'},
|
||||
@ -117,5 +116,11 @@ def get_pins():
|
||||
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;
|
||||
#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.
|
||||
# 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.
|
||||
|
||||
# Make buttons and LEDs negated
|
||||
pinutils.findpin(pins, "PD17", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PD19", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PD13", True)["functions"]["NEGATED"]=0;
|
||||
|
||||
return pins
|
||||
|
||||
115
boards/SMARTIBOT.py
Normal file
@ -0,0 +1,115 @@
|
||||
#!/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' : "Smartibot",
|
||||
'link' : [ "http://thecraftyrobot.net" ],
|
||||
'espruino_page_link' : 'Smartibot',
|
||||
'bootloader' : 1,
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D22",
|
||||
'default_console_rx' : "D23",
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2250, # How many variables are allocated for Espruino to use. RAM will be overflowed if this number is too high and code won't compile.
|
||||
'binary_name' : 'espruino_%v_smartibot.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
'BLUETOOTH',
|
||||
'GRAPHICS',
|
||||
'NEOPIXEL'
|
||||
],
|
||||
'makefile' : [
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
|
||||
'DEFINES += -DCONFIG_GPIO_AS_PINRESET', # Allow the reset pin to work
|
||||
'DEFINES += -DCONFIG_NFCT_PINS_AS_GPIOS=1', # Use NFC for GPIOs
|
||||
# 'JSMODULESOURCES+=libs/js/PCA9685.min.js',
|
||||
# 'JSMODULESOURCES+=libs/js/Smartibot.min.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
chip = {
|
||||
'part' : "NRF52832",
|
||||
'family' : "NRF52",
|
||||
'package' : "QFN48",
|
||||
'ram' : 64,
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((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' : 'D29', 'pinstate' : 'IN_PULLUP' }, # Pin negated in software
|
||||
'BTN2' : { 'pin' : 'D13', 'pinstate' : 'IN_PULLUP' }, # Pin negated in software
|
||||
'LED1' : { 'pin' : 'D20' },
|
||||
'RX_PIN_NUMBER' : { 'pin' : 'D23'},
|
||||
'TX_PIN_NUMBER' : { 'pin' : 'D22'},
|
||||
};
|
||||
|
||||
# left-right, or top-bottom order
|
||||
board = {
|
||||
'_notes' : {
|
||||
'D23' : "Serial console RX",
|
||||
'D22' : "Serial console TX"
|
||||
}
|
||||
};
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 600px;
|
||||
height: 595px;
|
||||
background-image: url(img/SMARTIBOT.jpg);
|
||||
}
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
pins = pinutils.generate_pins(0,31) # 32 General Purpose I/O 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, "PD22", True)["functions"]["TXD"]=0;
|
||||
pinutils.findpin(pins, "PD7", True)["functions"]["CTS"]=0;
|
||||
pinutils.findpin(pins, "PD23", True)["functions"]["RXD"]=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 BTN1 + BTN2 negated
|
||||
pinutils.findpin(pins, "PD29", True)["functions"]["NEGATED"]=0; # BTN1
|
||||
pinutils.findpin(pins, "PD13", True)["functions"]["NEGATED"]=0; # BTN2
|
||||
|
||||
# everything is non-5v tolerant
|
||||
for pin in pins:
|
||||
pin["functions"]["3.3"]=0;
|
||||
#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
|
||||
@ -134,6 +134,15 @@ board["_css"] = """
|
||||
top: 320px;
|
||||
left: 530px;
|
||||
}
|
||||
/* prevent pins overlay legends from overlapping when hovering */
|
||||
#boardcontainer:hover #left { opacity: 0.1; }
|
||||
#boardcontainer:hover #left2 { opacity: 0.1; }
|
||||
#boardcontainer:hover #right { opacity: 0.1; }
|
||||
#boardcontainer:hover #right2 { opacity: 0.1; }
|
||||
#boardcontainer:hover #left:hover { opacity: 1; z-index: 10; }
|
||||
#boardcontainer:hover #left2:hover { opacity: 1; z-index: 10; }
|
||||
#boardcontainer:hover #right2:hover { opacity: 1; z-index: 10; }
|
||||
#boardcontainer:hover #right:hover { opacity: 1; z-index: 10; }
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
|
||||
@ -18,10 +18,12 @@
|
||||
import pinutils;
|
||||
info = {
|
||||
'name' : "STM32L496 Discovery",
|
||||
'link' : [ "www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-eval-tools/mcu-eval-tools/stm32-mcu-eval-tools/stm32-mcu-discovery-kits/32l496gdiscovery.html" ],
|
||||
'default_console' : "EV_USBSERIAL",
|
||||
|
||||
'variables' : 15359, # variables computed from available RAM size : (256-16)*1024/16-1
|
||||
'link' : [ "http://www.st.com/en/evaluation-tools/32l496gdiscovery.html" ],
|
||||
'espruino_page_link' : 'STM32L496GDISCOVERY',
|
||||
'default_console' : "EV_SERIAL2",
|
||||
'default_console_tx' : "A2",
|
||||
'default_console_rx' : "D6",
|
||||
'variables' : 19200, # variables computed from available RAM size : (256-16)*1024/16-1
|
||||
'binary_name' : 'espruino_%v_stm32l496gdiscovery.bin',
|
||||
'build' : {
|
||||
'optimizeflags' : '-O3',
|
||||
@ -29,7 +31,7 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'NEOPIXEL',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS',
|
||||
'FILESYSTEM'
|
||||
],
|
||||
@ -59,7 +61,7 @@ chip = {
|
||||
# so we have some left room for Espruino firmware and no risk to clear it while saving
|
||||
'address' : 0x080D0000, # We have 0 -> 0xFFFFF (1MB), so this is at the end of flash
|
||||
'page_size' : 2048, # size of pages, 256 pages on bank1, 256 pages on bank2
|
||||
'pages' : 64, # count of pages we're using to save RAM to Flash
|
||||
'pages' : 64, # count of pages we're using to save RAM to Flash
|
||||
'flash_available' : 832 # kb - quantity reserved to receive the Firmware
|
||||
},
|
||||
};
|
||||
@ -103,49 +105,56 @@ board = {
|
||||
'top2' : [ 'G11', 'B6', 'G10', 'G12', 'GND','5V', 'B8', 'I3', 'D3', 'B7' ],
|
||||
'top' : [ 'H2', 'B2', 'A4', 'A0', '5V','GND', 'C7', 'C2', 'B12', 'C2' ],
|
||||
# PMOD+ connector
|
||||
'right' : [ 'G11','B6','G10','G12','GND','3V3' ],
|
||||
'right2' : [ 'H2','B2','NC','NC','GND','3V3' ],
|
||||
'right' : [ 'H2','B2','NC','NC','GND','3V3' ],
|
||||
'right2' : [ 'G11','B6','G10','G12','GND','3V3' ],
|
||||
|
||||
# verso side
|
||||
# ARDUIMO connector
|
||||
'bottom' : [ 'C4','C1','C3','F10','C1','C4','','VIN','GND','5V','3V3','RESET','VDD (IOREF)','' ],
|
||||
'bottom2' : [ 'G8','G7','G13','H15','I11','B9','I6','G6', '', 'G15','H13','A15','B5','B4','A5','GND','AVDD','B7','B8' ],
|
||||
# ARDUINO connector
|
||||
'bottom2' : [ 'C4','C1','C3','F10','C1','C4','','VIN','GND','5V','3V3','RESET','VDD (IOREF)','' ],
|
||||
'bottom' : [ 'G8','G7','G13','H15','I11','B9','I6','G6', '', 'G15','H13','A15','B5','B4','A5','GND','AVDD','B7','B8' ],
|
||||
};
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 1203px;
|
||||
height: 1500px;
|
||||
top: 0px;
|
||||
background-image: url(img/DISCOL496G.jpg);
|
||||
width: 800px;
|
||||
height: 864px;
|
||||
top: 250px;
|
||||
background-image: url(img/STM32L496GDISCOVERY.jpg);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 1500px;
|
||||
height: 1450px;
|
||||
}
|
||||
#top {
|
||||
top: 100px;
|
||||
left: 100px;
|
||||
bottom: 843px;
|
||||
left: 518px;
|
||||
}
|
||||
#top2 {
|
||||
top: 100px;
|
||||
left: 500px;
|
||||
top: 20px;
|
||||
left: 518px;
|
||||
}
|
||||
|
||||
#right {
|
||||
top: 50px;
|
||||
left: 1000px;
|
||||
top: 55px;
|
||||
left: 782px;
|
||||
}
|
||||
#right2 {
|
||||
top: 50px;
|
||||
left: 1400px
|
||||
top: 55px;
|
||||
right: 20px
|
||||
}
|
||||
#bottom {
|
||||
top: 500px;
|
||||
right: 100px;
|
||||
top: 796px;
|
||||
right: 221px;
|
||||
}
|
||||
#bottom2 {
|
||||
top: 500px;
|
||||
right: 500px;
|
||||
bottom: 360px;
|
||||
right: 283px;
|
||||
}
|
||||
|
||||
.toppin { width: 15px; padding:0px; }
|
||||
.top2pin { width: 15px; padding:0px; }
|
||||
.rightpin { height: 15px; }
|
||||
.right2pin { height: 15px; }
|
||||
.bottompin { width: 15px; padding:0px; }
|
||||
.bottom2pin { width: 15px; padding:0px; }
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
|
||||
@ -29,7 +29,7 @@ info = {
|
||||
'NET',
|
||||
'GRAPHICS',
|
||||
'NEOPIXEL',
|
||||
'CRYPTO',
|
||||
'CRYPTO','SHA256','SHA512',
|
||||
'TLS'
|
||||
],
|
||||
'makefile' : [
|
||||
|
||||
@ -17,7 +17,7 @@ import pinutils;
|
||||
info = {
|
||||
'name' : "STM32 VL Discovery",
|
||||
'link' : [ "http://www.st.com/stm32-discovery" ],
|
||||
'variables' : 500,
|
||||
'variables' : 400,
|
||||
'binary_name' : 'espruino_%v_stm32vldiscovery.bin',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
|
||||
@ -18,34 +18,39 @@ import pinutils;
|
||||
info = {
|
||||
'name' : "Nordic Thingy:52",
|
||||
'link' : [ "https://www.nordicsemi.com/eng/Products/Nordic-Thingy-52" ],
|
||||
'espruino_page_link' : 'Thingy52',
|
||||
'default_console' : "EV_SERIAL1",
|
||||
'default_console_tx' : "D2",
|
||||
'default_console_rx' : "D3",
|
||||
'default_console_baudrate' : "9600",
|
||||
'variables' : 2500, # 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_thingy52.bin',
|
||||
'bootloader' : 1,
|
||||
'binary_name' : 'espruino_%v_thingy52.hex',
|
||||
'build' : {
|
||||
'optimizeflags' : '-Os',
|
||||
'libraries' : [
|
||||
'BLUETOOTH',
|
||||
# 'NET',
|
||||
'GRAPHICS',
|
||||
'NFC'
|
||||
'NFC',
|
||||
'NEOPIXEL'
|
||||
],
|
||||
'makefile' : [
|
||||
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
|
||||
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Thingy"\'',
|
||||
'DEFINES+=-DNFC_DEFAULT_URL=\'"https://www.espruino.com/ide"\'',
|
||||
'DEFINES+=-DDUMP_IGNORE_VARIABLES=\'"Thingy\\0"\'',
|
||||
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
|
||||
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
|
||||
'INCLUDE += -I$(ROOT)/libs/nordic_thingy',
|
||||
'WRAPPERSOURCES += libs/nordic_thingy/jswrap_thingy.c',
|
||||
'JSMODULESOURCES+=libs/nordic_thingy/LIS2DH12.min.js',
|
||||
'JSMODULESOURCES+=libs/nordic_thingy/LPS22HB.min.js',
|
||||
'JSMODULESOURCES+=libs/nordic_thingy/HTS221.min.js',
|
||||
'JSMODULESOURCES+=libs/nordic_thingy/CCS811.min.js',
|
||||
'JSMODULESOURCES+=libs/nordic_thingy/BH1745.min.js',
|
||||
'JSMODULESOURCES+=libs/nordic_thingy/Thingy.min.js'
|
||||
'JSMODULESOURCES+=libs/js/LIS2DH12.min.js',
|
||||
'JSMODULESOURCES+=libs/js/MPU9250.min.js',
|
||||
'JSMODULESOURCES+=libs/js/LPS22HB.min.js',
|
||||
'JSMODULESOURCES+=libs/js/HTS221.min.js',
|
||||
'JSMODULESOURCES+=libs/js/CCS811.min.js',
|
||||
'JSMODULESOURCES+=libs/js/BH1745.min.js',
|
||||
'JSMODULESOURCES+=libs/js/nordic/Thingy.min.js'
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -59,15 +64,15 @@ chip = {
|
||||
'flash' : 512,
|
||||
'speed' : 64,
|
||||
'usart' : 1,
|
||||
'spi' : 3,
|
||||
'i2c' : 2,
|
||||
'spi' : 1,
|
||||
'i2c' : 1,
|
||||
'adc' : 1,
|
||||
'dac' : 0,
|
||||
'saved_code' : {
|
||||
'address' : ((118 - 3) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'address' : ((118 - 10) * 4096), # Bootloader takes pages 120-127, FS takes 118-119
|
||||
'page_size' : 4096,
|
||||
'pages' : 3,
|
||||
'flash_available' : 512 - ((31 + 8 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 3. Each page is 4 kb.
|
||||
'pages' : 10,
|
||||
'flash_available' : 512 - ((31 + 8 + 2 + 10)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 2, code 10. Each page is 4 kb.
|
||||
},
|
||||
};
|
||||
|
||||
@ -163,7 +168,7 @@ def get_pins():
|
||||
pinutils.findpin(pins, "PV5", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PV6", True)["functions"]["NEGATED"]=0;
|
||||
pinutils.findpin(pins, "PV7", True)["functions"]["NEGATED"]=0;
|
||||
|
||||
|
||||
|
||||
# everything is non-5v tolerant
|
||||
for pin in pins:
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
import pinutils;
|
||||
info = {
|
||||
'name' : "WIO TRACKER LTE",
|
||||
'link' : [ "http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1199/PF252419" ],
|
||||
'link' : [ "http://www.espruino.com/WioLTE" ],
|
||||
'espruino_page_link' : 'WioLTE',
|
||||
'default_console' : "EV_SERIAL2", # FIXME: This was S2 because of pin conflict. Not sure if it's really an issue?
|
||||
'variables' : 5450,
|
||||
'binary_name' : 'espruino_%v_Wio_LTE.bin',
|
||||
@ -93,24 +94,24 @@ board = {
|
||||
};
|
||||
board["_css"] = """
|
||||
#board {
|
||||
width: 457px;
|
||||
height: 480px;
|
||||
width: 500px;
|
||||
height: 588px;
|
||||
left: 200px;
|
||||
background-image: url(img/WIO_LTE.jpg);
|
||||
}
|
||||
#boardcontainer {
|
||||
height: 468px;
|
||||
height: 588px;
|
||||
}
|
||||
#left {
|
||||
top: 98px;
|
||||
right: 352px;
|
||||
top: 123px;
|
||||
right: 412px;
|
||||
}
|
||||
#right {
|
||||
top: 98px;
|
||||
left: 352px;
|
||||
top: 123px;
|
||||
left: 412px;
|
||||
}
|
||||
.leftpin { height: 18px; padding:0px; }
|
||||
.rightpin { height: 18px; padding:0px; }
|
||||
.leftpin { height: 23px; padding:0px; }
|
||||
.rightpin { height: 23px; padding:0px; }
|
||||
""";
|
||||
|
||||
def get_pins():
|
||||
|
||||
|
Before Width: | Height: | Size: 241 KiB |
BIN
boards/img/MDBT42Q.jpg
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
boards/img/MDBT42Q_BREAKOUT.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
boards/img/NRF52832DK.jpg
Normal file
|
After Width: | Height: | Size: 180 KiB |
BIN
boards/img/PIXLJS.jpg
Normal file
|
After Width: | Height: | Size: 59 KiB |
BIN
boards/img/PIXLJS.png
Normal file
|
After Width: | Height: | Size: 234 KiB |
BIN
boards/img/RAK8211.png
Normal file
|
After Width: | Height: | Size: 56 KiB |
BIN
boards/img/RAK8212.png
Normal file
|
After Width: | Height: | Size: 453 KiB |
BIN
boards/img/SMARTIBOT.jpg
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
boards/img/STM32L496GDISCOVERY.jpg
Normal file
|
After Width: | Height: | Size: 319 KiB |
BIN
boards/img/THINGY52.jpg
Normal file
|
After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 77 KiB |
@ -35,6 +35,14 @@ espruino_#v##_puckjs.zip
|
||||
- The firmware image for Espruino Puck.js Devices
|
||||
See http://www.espruino.com/Puck.js#firmware-updates for more information
|
||||
|
||||
espruino_#v##_pixljs.zip
|
||||
- The firmware image for Espruino Pixl.js Devices
|
||||
See http://www.espruino.com/Pixl.js#firmware-updates for more information
|
||||
|
||||
espruino_#v##_mdbt42q.zip
|
||||
- The firmware image for Espruino MDBT42Q modules
|
||||
See http://www.espruino.com/MDBT42Q#firmware-updates for more information
|
||||
|
||||
espruino_#v##_hystm32_24_ve.bin
|
||||
- 'HY'STM32F103VET6 ARM with 2.4" LCD display
|
||||
This is available from eBay
|
||||
@ -43,22 +51,12 @@ espruino_#v##_hystm32_28_rb.bin
|
||||
- 'HY'STM32F103RBT6 ARM with 2.8" LCD display
|
||||
This is available from eBay
|
||||
|
||||
espruino_#v##_hystm32_32_vc.bin
|
||||
- 'HY'STM32F103VCT6 ARM with 3.2" LCD display
|
||||
This is available from eBay
|
||||
|
||||
espruino_#v##_olimexino_stm32.bin
|
||||
- You will need to overwrite the Maple bootloader to install this.
|
||||
Espruino is now too large to fit in flash alongside it.
|
||||
- Olimexino-STM32 Arduino form factor board
|
||||
- Leaf Labs Maple Arduino form factor board
|
||||
espruino_#v##_stm32l496gdiscovery.bin
|
||||
- STM32F496GDISCOVERY board
|
||||
|
||||
espruino_#v##_stm32vldiscovery.bin
|
||||
- STM32VLDISCOVERY board
|
||||
|
||||
espruino_#v##_stm32f3discovery.bin
|
||||
- STM32F3DISCOVERY board
|
||||
|
||||
espruino_#v##_stm32f4discovery.bin
|
||||
- STM32F4DISCOVERY board
|
||||
|
||||
@ -86,6 +84,30 @@ espruino_#v##_Wio_LTE.zip
|
||||
- The firmware image for Seed Wio LTE Devices
|
||||
See http://www.espruino.com/WioLTE for more information
|
||||
|
||||
espruino_#v##_thingy52.hex
|
||||
- The firmware image for Nordic Thing:52 Devices
|
||||
See http://www.espruino.com/Thingy52 for more information
|
||||
|
||||
espruino_#v##nrf52832.hex
|
||||
- The firmware image for Nordic Thing:52 Devices
|
||||
See http://www.espruino.com/nRF52832DK for more information
|
||||
|
||||
espruino_#v##stm32l496gdiscovery.bin
|
||||
- The firmware image for the STM32L496G Discovery Board
|
||||
See http://www.espruino.com/STM32L496GDISCOVERY for more information
|
||||
|
||||
espruino_#v##rak8211.hex
|
||||
- The firmware image for the RAK8211 iTracker
|
||||
See http://www.espruino.com/RAK8211 for more information
|
||||
|
||||
espruino_#v##rak8212.hex
|
||||
- The firmware image for the RAK8212 iTracker
|
||||
See http://www.espruino.com/RAK8212 for more information
|
||||
|
||||
espruino_#v##smartibot.zip
|
||||
- The firmware image for the Smartibot robot board
|
||||
See http://www.espruino.com/Smartibot for more information
|
||||
|
||||
|
||||
|
||||
ESP8266 / ESP32
|
||||
|
||||
@ -18,12 +18,18 @@
|
||||
#include "jsdevices.h"
|
||||
|
||||
#ifdef NRF5X
|
||||
#if NRF_SD_BLE_API_VERSION>5
|
||||
#include "nrf_sdh_ble.h"
|
||||
#define BLE_GAP_ADV_MAX_SIZE BLE_GAP_ADV_SET_DATA_SIZE_MAX
|
||||
#else
|
||||
#include "ble.h"
|
||||
#endif
|
||||
#include "ble_advdata.h"
|
||||
#else
|
||||
typedef struct {
|
||||
uint16_t uuid;
|
||||
uint8_t type;
|
||||
uint8_t type; //see BLE_UUID_TYPE_... definitions
|
||||
uint8_t uuid128[16]; //BLE knows 16/32/128 bit uuids. Espruino supports 16/128.
|
||||
} PACKED_FLAGS ble_uuid_t;
|
||||
typedef struct {
|
||||
//uint8_t addr_id_peer;
|
||||
@ -44,10 +50,13 @@ typedef struct {
|
||||
#define BLE_GAP_AD_TYPE_MANUFACTURER_SPECIFIC_DATA 0xFF
|
||||
#define BLE_UUID_TYPE_UNKNOWN (0)
|
||||
#define BLE_UUID_TYPE_BLE (1)
|
||||
#define BLE_UUID_TYPE_128 2
|
||||
#define MSEC_TO_UNITS(MS,MEH) MS
|
||||
#define GATT_MTU_SIZE_DEFAULT 23
|
||||
#define BLE_NUS_MAX_DATA_LEN 20 //GATT_MTU_SIZE_DEFAULT - 3
|
||||
#endif
|
||||
|
||||
#ifdef NRF52
|
||||
#if defined(NRF52) || defined(ESP32)
|
||||
// nRF52 gets the ability to connect to other
|
||||
#define CENTRAL_LINK_COUNT 1 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
#define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
|
||||
@ -69,44 +78,65 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
BLE_NONE = 0,
|
||||
BLE_IS_SENDING = 1, // sending data with jswrap_nrf_transmit_string?
|
||||
BLE_IS_SCANNING = 2, // scanning for BLE devices?
|
||||
BLE_IS_ADVERTISING = 4, // currently advertising info? stops when connected
|
||||
BLE_NEEDS_SOFTDEVICE_RESTART = 8, // We need to reset the services we're reporting, but we can't because we're connected
|
||||
BLE_SERVICES_WERE_SET = 16, // setServices was called already, so we need to restart softdevice before we can call it again
|
||||
BLE_IS_SENDING = 1, //< sending data with jswrap_ble_transmit_string?
|
||||
BLE_IS_SCANNING = 2, //< scanning for BLE devices?
|
||||
BLE_IS_ADVERTISING = 4, //< currently advertising info? stops when connected
|
||||
BLE_NEEDS_SOFTDEVICE_RESTART = 8, //< We need to reset the services we're reporting, but we can't because we're connected
|
||||
BLE_SERVICES_WERE_SET = 16, //< setServices was called already, so we need to restart softdevice before we can call it again
|
||||
|
||||
BLE_NUS_INITED = 32, // Has the Nordic UART service been initialised?
|
||||
BLE_HID_INITED = 64, // Has the BLE HID service been initialised?
|
||||
BLE_IS_SENDING_HID = 128, // Are we waiting to send data for USB HID?
|
||||
BLE_IS_RSSI_SCANNING = 256, // Are we scanning for RSSI values
|
||||
BLE_IS_SLEEPING = 512, // NRF.sleep has been called
|
||||
BLE_PM_INITIALISED = 1024, // Set when the Peer Manager has been initialised (only needs doing once, even after SD restart)
|
||||
BLE_IS_NOT_CONNECTABLE = 2048, // Is the device connectable?
|
||||
BLE_WHITELIST_ON_BOND = 4096, // Should we write to the whitelist whenever we bond to a device?
|
||||
BLE_NUS_INITED = 32, //< Has the Nordic UART service been initialised?
|
||||
BLE_HID_INITED = 64, //< Has the BLE HID service been initialised?
|
||||
BLE_IS_SENDING_HID = 128, //< Are we waiting to send data for USB HID?
|
||||
BLE_IS_RSSI_SCANNING = 256, //< Are we scanning for RSSI values
|
||||
BLE_IS_SLEEPING = 512, //< NRF.sleep has been called
|
||||
BLE_PM_INITIALISED = 1024, //< Set when the Peer Manager has been initialised (only needs doing once, even after SD restart)
|
||||
BLE_IS_NOT_CONNECTABLE = 2048, //< Is the device connectable?
|
||||
BLE_WHITELIST_ON_BOND = 4096, //< Should we write to the whitelist whenever we bond to a device?
|
||||
|
||||
BLE_IS_ADVERTISING_MULTIPLE = 8192, // We have multiple different advertising packets
|
||||
BLE_ADVERTISING_MULTIPLE_ONE = 16384,
|
||||
BLE_DISABLE_DYNAMIC_INTERVAL = 8192, //< Disable automatically changing interval based on BLE peripheral activity
|
||||
|
||||
BLE_IS_ADVERTISING_MULTIPLE = 16384, // We have multiple different advertising packets
|
||||
BLE_ADVERTISING_MULTIPLE_ONE = 32768,
|
||||
BLE_ADVERTISING_MULTIPLE_SHIFT = GET_BIT_NUMBER(BLE_ADVERTISING_MULTIPLE_ONE),
|
||||
BLE_ADVERTISING_MULTIPLE_MASK = 255 << BLE_ADVERTISING_MULTIPLE_SHIFT,
|
||||
} BLEStatus;
|
||||
|
||||
typedef enum {
|
||||
BLEP_NONE,
|
||||
BLEP_DISCONNECTED,
|
||||
BLEP_RSSI_CENTRAL,
|
||||
BLEP_RSSI_PERIPH,
|
||||
BLEP_ADV_REPORT,
|
||||
BLEP_TASK_FAIL_CONN_TIMEOUT,
|
||||
BLEP_TASK_FAIL_DISCONNECTED,
|
||||
BLEP_TASK_CENTRAL_CONNECTED,
|
||||
BLEP_GATT_SERVER_DISCONNECTED,
|
||||
BLEP_NFC_STATUS,
|
||||
BLEP_ERROR, //< Softdevice threw some error (code in data)
|
||||
BLEP_CONNECTED, //< Peripheral connected (address as buffer)
|
||||
BLEP_DISCONNECTED, //< Peripheral disconnected
|
||||
BLEP_RSSI_PERIPH, //< RSSI data from peripheral connection (rssi as data)
|
||||
BLEP_ADV_REPORT, //< Advertising received (as buffer)
|
||||
BLEP_RSSI_CENTRAL, //< RSSI data from central connection (rssi as data)
|
||||
BLEP_TASK_FAIL_CONN_TIMEOUT, //< Central: Connection timeout
|
||||
BLEP_TASK_FAIL_DISCONNECTED, //< Central: Task failed because disconnected
|
||||
BLEP_TASK_CENTRAL_CONNECTED, //< Central: Connected
|
||||
BLEP_TASK_DISCOVER_SERVICE, //< New service discovered (as buffer)
|
||||
BLEP_TASK_DISCOVER_SERVICE_COMPLETE, //< Service discovery complete
|
||||
BLEP_TASK_DISCOVER_CHARACTERISTIC, //< New characteristic discovered (as buffer)
|
||||
BLEP_TASK_DISCOVER_CHARACTERISTIC_COMPLETE, //< Characteristic discovery complete
|
||||
BLEP_TASK_DISCOVER_CCCD, //< Discovery of CCCD for characteristic finished (cccd in data)
|
||||
BLEP_TASK_CHARACTERISTIC_READ, //< Central: Characteristic read finished (as buffer)
|
||||
BLEP_TASK_CHARACTERISTIC_WRITE, //< Central: Characteristic write finished
|
||||
BLEP_TASK_CHARACTERISTIC_NOTIFY, //< Central: Started requesting notifications
|
||||
BLEP_CENTRAL_DISCONNECTED, //< Central: Disconnected (reason as data)
|
||||
BLEP_TASK_BONDING, //< Bonding negotiation complete (success in data)
|
||||
BLEP_NFC_STATUS, //< NFC changed state
|
||||
BLEP_NFC_RX, //< NFC data received (as buffer)
|
||||
BLEP_NFC_TX, //< NFC data sent
|
||||
BLEP_HID_SENT, //< A HID report has been sent
|
||||
BLEP_HID_VALUE, //< A HID value was received (eg caps lock)
|
||||
BLEP_WRITE, //< One of our characteristics written by someone else
|
||||
BLEP_NOTIFICATION, //< A characteristic we were watching has changes
|
||||
BLEP_TASK_PASSKEY_DISPLAY, //< We're pairing and have been provided with a passkey to display
|
||||
BLEP_TASK_PASSKEY_REQUEST, //< We're pairing and the device wants a passkey from us
|
||||
} BLEPending;
|
||||
|
||||
|
||||
extern volatile BLEStatus bleStatus;
|
||||
extern uint16_t bleAdvertisingInterval; /**< The advertising interval (in units of 0.625 ms). */
|
||||
extern volatile uint16_t m_conn_handle; /**< Handle of the current connection. */
|
||||
extern volatile uint16_t m_peripheral_conn_handle; /**< Handle of the current connection. */
|
||||
#if CENTRAL_LINK_COUNT>0
|
||||
extern volatile uint16_t m_central_conn_handle; /**< Handle for central mode connection */
|
||||
#endif
|
||||
@ -115,12 +145,12 @@ extern volatile uint16_t m_central_conn_handle; /**< Han
|
||||
void jsble_init();
|
||||
/** Completely deinitialise the BLE stack */
|
||||
void jsble_kill();
|
||||
/** Add a task to the queue to be executed (to be called mainly from IRQ-land) */
|
||||
void jsble_queue_pending(BLEPending blep);
|
||||
/** Add a task to the queue to be executed (to be called mainly from IRQ-land) */
|
||||
void jsble_queue_pending_d(BLEPending blep, uint16_t data);
|
||||
/** Execute a task that was added by jsble_queue_pending - this is done outside of IRQ land*/
|
||||
void jsble_exec_pending(IOEvent *event);
|
||||
/** Add a task to the queue to be executed (to be called mainly from IRQ-land) - with a buffer of data */
|
||||
void jsble_queue_pending_buf(BLEPending blep, uint16_t data, char *ptr, size_t len);
|
||||
/** Add a task to the queue to be executed (to be called mainly from IRQ-land) - with simple data */
|
||||
void jsble_queue_pending(BLEPending blep, uint16_t data);
|
||||
/** Execute a task that was added by jsble_queue_pending - this is done outside of IRQ land. Returns number of events handled */
|
||||
int jsble_exec_pending(IOEvent *event);
|
||||
|
||||
/** Stop and restart the softdevice so that we can update the services in it -
|
||||
* both user-defined as well as UART/HID */
|
||||
@ -137,13 +167,20 @@ bool jsble_has_connection();
|
||||
bool jsble_has_central_connection();
|
||||
|
||||
/** Is BLE connected to a server device at all (eg, the simple, 'slave' mode)? */
|
||||
bool jsble_has_simple_connection();
|
||||
bool jsble_has_peripheral_connection();
|
||||
|
||||
/** Call this when something happens on BLE with this as
|
||||
* a peripheral - used with Dynamic Interval Adjustment */
|
||||
void jsble_peripheral_activity();
|
||||
|
||||
/// Checks for error and reports an exception if there was one. Return true on error
|
||||
bool jsble_check_error(uint32_t err_code);
|
||||
|
||||
/// Scanning for advertisign packets
|
||||
uint32_t jsble_set_scanning(bool enabled);
|
||||
/** Set the connection interval of the peripheral connection. Returns an error code */
|
||||
uint32_t jsble_set_periph_connection_interval(JsVarFloat min, JsVarFloat max);
|
||||
|
||||
/// Scanning for advertising packets
|
||||
uint32_t jsble_set_scanning(bool enabled, bool activeScan);
|
||||
|
||||
/// returning RSSI values for current connection
|
||||
uint32_t jsble_set_rssi_scan(bool enabled);
|
||||
@ -159,6 +196,9 @@ uint32_t jsble_disconnect(uint16_t conn_handle);
|
||||
/// For BLE HID, send an input report to the receiver. Must be <= HID_KEYS_MAX_LEN
|
||||
void jsble_send_hid_input_report(uint8_t *data, int length);
|
||||
|
||||
/// Update the current security settings from the info in hiddenRoot.BLE_NAME_SECURITY
|
||||
void jsble_update_security();
|
||||
|
||||
// ------------------------------------------------- lower-level utility fns
|
||||
|
||||
#ifdef NRF5X
|
||||
@ -199,8 +239,14 @@ void jsble_nfc_send_rsp(const uint8_t data, size_t len);
|
||||
#endif
|
||||
|
||||
#if CENTRAL_LINK_COUNT>0
|
||||
/// Connect to the given peer address. When done call bleCompleteTask
|
||||
void jsble_central_connect(ble_gap_addr_t peer_addr);
|
||||
/** Connect to the given peer address. When done call bleCompleteTask.
|
||||
options is an optional object containing optional fields:
|
||||
{
|
||||
minInterval // min connection interval in milliseconds, 7.5 ms to 4 s
|
||||
maxInterval // max connection interval in milliseconds, 7.5 ms to 4 s
|
||||
}
|
||||
See BluetoothRemoteGATTServer.connect docs for more docs */
|
||||
void jsble_central_connect(ble_gap_addr_t peer_addr, JsVar *options);
|
||||
/// Get primary services. Filter by UUID unless UUID is invalid, in which case return all. When done call bleCompleteTask
|
||||
void jsble_central_getPrimaryServices(ble_uuid_t uuid);
|
||||
/// Get characteristics. Filter by UUID unless UUID is invalid, in which case return all. When done call bleCompleteTask
|
||||
@ -219,8 +265,10 @@ void jsble_central_startBonding(bool forceRePair);
|
||||
JsVar *jsble_central_getSecurityStatus();
|
||||
/// RSSI monitoring in central mode
|
||||
uint32_t jsble_set_central_rssi_scan(bool enabled);
|
||||
// Set whether or not the whitelist is enabled
|
||||
/// Set whether or not the whitelist is enabled
|
||||
void jsble_central_setWhitelist(bool whitelist);
|
||||
/// Send a passkey if one was requested (passkey = 6 bytes long)
|
||||
uint32_t jsble_central_send_passkey(char *passkey);
|
||||
#endif
|
||||
|
||||
#endif // BLUETOOTH_H
|
||||
|
||||
@ -24,7 +24,20 @@
|
||||
|
||||
/// Return true if two UUIDs are equal
|
||||
bool bleUUIDEqual(ble_uuid_t a, ble_uuid_t b) {
|
||||
return a.type==b.type && a.uuid==b.uuid;
|
||||
#ifdef NRF5X
|
||||
return a.type==b.type && a.uuid==b.uuid;
|
||||
#else
|
||||
switch(a.type){
|
||||
case BLE_UUID_TYPE_UNKNOWN:
|
||||
return a.type == b.type;
|
||||
case BLE_UUID_TYPE_BLE:
|
||||
return a.type == b.type && a.uuid == b.uuid;
|
||||
case BLE_UUID_TYPE_128:
|
||||
return a.type == b.type && a.uuid128 == b.uuid128;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
JsVar *bleUUID128ToStr(const uint8_t *data) {
|
||||
@ -52,8 +65,7 @@ JsVar *bleUUIDToStr(ble_uuid_t uuid) {
|
||||
assert(dataLen==16); // it should always be 16 as we checked above
|
||||
return bleUUID128ToStr(&data[0]);
|
||||
#else
|
||||
jsiConsolePrintf("FIXME\n");
|
||||
return 0;
|
||||
return bleUUID128ToStr(&uuid.uuid128);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -73,9 +85,9 @@ bool bleVarToAddr(JsVar *mac, ble_gap_addr_t *addr) {
|
||||
for (i=0;i<6;i++)
|
||||
addr->addr[5-i] = (chtod(jsvGetCharInString(mac, i*3))<<4) | chtod(jsvGetCharInString(mac, (i*3)+1));
|
||||
if (jsvGetStringLength(mac)!=17) {
|
||||
if (jsvIsStringEqualOrStartsWithOffset(mac, " public", false, 17))
|
||||
if (jsvIsStringEqualOrStartsWithOffset(mac, " public", false, 17, false))
|
||||
addr->addr_type = BLE_GAP_ADDR_TYPE_PUBLIC; // default
|
||||
else if (jsvIsStringEqualOrStartsWithOffset(mac, " random", false, 17))
|
||||
else if (jsvIsStringEqualOrStartsWithOffset(mac, " random", false, 17, false))
|
||||
addr->addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
|
||||
else return false;
|
||||
}
|
||||
@ -163,7 +175,10 @@ const char *bleVarToUUID(ble_uuid_t *uuid, JsVar *v) {
|
||||
}
|
||||
return err_code ? "BLE device error adding UUID" : 0;
|
||||
#else
|
||||
jsiConsolePrintf("FIXME\n");
|
||||
uuid->uuid = ((data[13]<<8) | data[12]);
|
||||
for(int i = 0; i < 16; i++){
|
||||
uuid->uuid128[i] = data[i];
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#define BLE_NAME_NUS "BLE_UART"
|
||||
#define BLE_NAME_FLAGS "BLE_FLAGS"
|
||||
#define BLE_NAME_GATT_SERVER "BLE_GATTS"
|
||||
#define BLE_NAME_SECURITY "BLE_SEC"
|
||||
|
||||
typedef enum {
|
||||
BLE_FLAGS_NONE = 0,
|
||||
|
||||
@ -19,6 +19,7 @@ typedef enum {
|
||||
BLETASK_REQUEST_DEVICE, ///< Waiting for requestDevice to finish
|
||||
BLETASK_CENTRAL_START, // =========================================== Start of central tasks
|
||||
BLETASK_CONNECT = BLETASK_CENTRAL_START, ///< Connect in central mode
|
||||
BLETASK_DISCONNECT, ///< Disconnect from Central
|
||||
BLETASK_PRIMARYSERVICE, ///< Find primary service
|
||||
BLETASK_CHARACTERISTIC, ///< Find characteristics
|
||||
BLETASK_CHARACTERISTIC_WRITE, ///< Write to a characteristic
|
||||
@ -33,6 +34,7 @@ typedef enum {
|
||||
#define BLETASK_IS_CENTRAL(x) ((x)>=BLETASK_CENTRAL_START && ((x)<=BLETASK_CENTRAL_END))
|
||||
|
||||
extern JsVar *bleTaskInfo; // info related to the current task
|
||||
|
||||
bool bleInTask(BleTask task);
|
||||
BleTask bleGetCurrentTask();
|
||||
bool bleNewTask(BleTask task, JsVar *taskInfo);
|
||||
@ -50,56 +52,60 @@ JsVar *bleGetActiveBluetoothGattServer();
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
void jswrap_nrf_init();
|
||||
bool jswrap_nrf_idle();
|
||||
void jswrap_nrf_kill();
|
||||
void jswrap_ble_init();
|
||||
bool jswrap_ble_idle();
|
||||
void jswrap_ble_kill();
|
||||
// Used to dump bluetooth initialisation info for 'dump'
|
||||
void jswrap_nrf_dumpBluetoothInitialisation(vcbprintf_callback user_callback, void *user_data);
|
||||
void jswrap_ble_dumpBluetoothInitialisation(vcbprintf_callback user_callback, void *user_data);
|
||||
/** Reconfigure the softdevice (on init or after restart) to have all the services/advertising we need */
|
||||
void jswrap_nrf_reconfigure_softdevice();
|
||||
void jswrap_ble_reconfigure_softdevice();
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void jswrap_nrf_bluetooth_disconnect();
|
||||
void jswrap_nrf_bluetooth_sleep();
|
||||
void jswrap_nrf_bluetooth_wake();
|
||||
void jswrap_nrf_bluetooth_restart();
|
||||
JsVar *jswrap_nrf_bluetooth_getAddress();
|
||||
void jswrap_ble_disconnect();
|
||||
void jswrap_ble_sleep();
|
||||
void jswrap_ble_wake();
|
||||
void jswrap_ble_restart();
|
||||
JsVar *jswrap_ble_getAddress();
|
||||
void jswrap_ble_setAddress(JsVar *address);
|
||||
|
||||
JsVarFloat jswrap_nrf_bluetooth_getBattery();
|
||||
void jswrap_nrf_bluetooth_setAdvertising(JsVar *data, JsVar *options);
|
||||
JsVar *jswrap_nrf_bluetooth_getAdvertisingData(JsVar *data, JsVar *options);
|
||||
void jswrap_nrf_bluetooth_setScanResponse(JsVar *data);
|
||||
void jswrap_nrf_bluetooth_setServices(JsVar *data, JsVar *options);
|
||||
void jswrap_nrf_bluetooth_updateServices(JsVar *data);
|
||||
void jswrap_nrf_bluetooth_setScan(JsVar *callback);
|
||||
void jswrap_nrf_bluetooth_findDevices(JsVar *callback, JsVar *timeout);
|
||||
void jswrap_nrf_bluetooth_setRSSIHandler(JsVar *callback);
|
||||
void jswrap_nrf_bluetooth_setTxPower(JsVarInt pwr);
|
||||
void jswrap_nrf_bluetooth_setLowPowerConnection(bool lowPower);
|
||||
JsVarFloat jswrap_ble_getBattery();
|
||||
void jswrap_ble_setAdvertising(JsVar *data, JsVar *options);
|
||||
JsVar *jswrap_ble_getAdvertisingData(JsVar *data, JsVar *options);
|
||||
void jswrap_ble_setScanResponse(JsVar *data);
|
||||
void jswrap_ble_setServices(JsVar *data, JsVar *options);
|
||||
void jswrap_ble_updateServices(JsVar *data);
|
||||
void jswrap_ble_setScan(JsVar *callback, JsVar *options);
|
||||
void jswrap_ble_findDevices(JsVar *callback, JsVar *options);
|
||||
void jswrap_ble_setRSSIHandler(JsVar *callback);
|
||||
void jswrap_ble_setTxPower(JsVarInt pwr);
|
||||
void jswrap_ble_setLowPowerConnection(bool lowPower);
|
||||
|
||||
void jswrap_nrf_nfcURL(JsVar *url);
|
||||
void jswrap_nrf_nfcRaw(JsVar *payload);
|
||||
JsVar *jswrap_nrf_nfcStart(JsVar *payload);
|
||||
void jswrap_nrf_nfcStop();
|
||||
void jswrap_nrf_nfcSend(JsVar *payload);
|
||||
void jswrap_nrf_sendHIDReport(JsVar *data, JsVar *callback);
|
||||
void jswrap_nfc_URL(JsVar *url);
|
||||
void jswrap_nfc_raw(JsVar *payload);
|
||||
JsVar *jswrap_nfc_start(JsVar *payload);
|
||||
void jswrap_nfc_stop();
|
||||
void jswrap_nfc_send(JsVar *payload);
|
||||
void jswrap_ble_sendHIDReport(JsVar *data, JsVar *callback);
|
||||
|
||||
JsVar *jswrap_nrf_bluetooth_requestDevice(JsVar *options);
|
||||
JsVar *jswrap_nrf_bluetooth_connect(JsVar *mac);
|
||||
void jswrap_nrf_setWhitelist(bool whitelist);
|
||||
JsVar *jswrap_ble_requestDevice(JsVar *options);
|
||||
JsVar *jswrap_ble_connect(JsVar *mac, JsVar *options);
|
||||
void jswrap_ble_setWhitelist(bool whitelist);
|
||||
void jswrap_ble_setConnectionInterval(JsVar *interval);
|
||||
void jswrap_ble_setSecurity(JsVar *options);
|
||||
|
||||
JsVar *jswrap_BluetoothDevice_gatt(JsVar *parent);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_connect(JsVar *parent);
|
||||
void jswrap_BluetoothRemoteGATTServer_disconnect(JsVar *parent);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_startBonding(JsVar *parent, bool forceRePair);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTServer_getSecurityStatus(JsVar *parent);
|
||||
void jswrap_ble_BluetoothDevice_sendPasskey(JsVar *parent, JsVar *passkeyVar);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTServer_connect(JsVar *parent, JsVar *options);
|
||||
JsVar *jswrap_BluetoothRemoteGATTServer_disconnect(JsVar *parent);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTServer_startBonding(JsVar *parent, bool forceRePair);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTServer_getSecurityStatus(JsVar *parent);
|
||||
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryService(JsVar *parent, JsVar *service);
|
||||
JsVar *jswrap_BluetoothRemoteGATTServer_getPrimaryServices(JsVar *parent);
|
||||
void jswrap_BluetoothRemoteGATTServer_setRSSIHandler(JsVar *parent, JsVar *callback);
|
||||
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristic(JsVar *parent, JsVar *characteristic);
|
||||
JsVar *jswrap_BluetoothRemoteGATTService_getCharacteristics(JsVar *parent);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_writeValue(JsVar *characteristic, JsVar *data);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_readValue(JsVar *characteristic);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_startNotifications(JsVar *characteristic);
|
||||
JsVar *jswrap_nrf_BluetoothRemoteGATTCharacteristic_stopNotifications(JsVar *characteristic);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTCharacteristic_writeValue(JsVar *characteristic, JsVar *data);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTCharacteristic_readValue(JsVar *characteristic);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTCharacteristic_startNotifications(JsVar *characteristic);
|
||||
JsVar *jswrap_ble_BluetoothRemoteGATTCharacteristic_stopNotifications(JsVar *characteristic);
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
|
||||
#define BUFFERSIZE 128
|
||||
|
||||
/** gets data from array, writes to callback */
|
||||
void heatshrink_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata) {
|
||||
/** gets data from array, writes to callback if nonzero. Returns total length. */
|
||||
uint32_t heatshrink_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata) {
|
||||
heatshrink_encoder hse;
|
||||
uint8_t outBuf[BUFFERSIZE];
|
||||
heatshrink_encoder_reset(&hse);
|
||||
@ -43,8 +43,9 @@ void heatshrink_encode(unsigned char *data, size_t dataLen, void (*callback)(uns
|
||||
do {
|
||||
pres = heatshrink_encoder_poll(&hse, outBuf, sizeof(outBuf), &count);
|
||||
assert(pres >= 0);
|
||||
for (i=0;i<count;i++)
|
||||
callback(outBuf[i], cbdata);
|
||||
if (callback)
|
||||
for (i=0;i<count;i++)
|
||||
callback(outBuf[i], cbdata);
|
||||
polled += count;
|
||||
} while (pres == HSER_POLL_MORE);
|
||||
assert(pres == HSER_POLL_EMPTY);
|
||||
@ -52,12 +53,14 @@ void heatshrink_encode(unsigned char *data, size_t dataLen, void (*callback)(uns
|
||||
heatshrink_encoder_finish(&hse);
|
||||
}
|
||||
}
|
||||
return (uint32_t)polled;
|
||||
}
|
||||
|
||||
/** gets data from callback, writes it into array */
|
||||
void heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data) {
|
||||
/** gets data from callback, writes it into array if nonzero. Returns total length */
|
||||
uint32_t heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data) {
|
||||
heatshrink_decoder hsd;
|
||||
uint8_t inBuf[BUFFERSIZE];
|
||||
uint8_t outBuf[BUFFERSIZE];
|
||||
heatshrink_decoder_reset(&hsd);
|
||||
|
||||
size_t count = 0;
|
||||
@ -89,8 +92,9 @@ void heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsi
|
||||
|
||||
HSE_poll_res pres;
|
||||
do {
|
||||
pres = heatshrink_decoder_poll(&hsd, &data[polled], 0xFFFFFF/*bad!*/, &count); // TODO: range check?
|
||||
pres = heatshrink_decoder_poll(&hsd, outBuf, sizeof(outBuf), &count);
|
||||
assert(pres >= 0);
|
||||
if (data) memcpy(&data[polled], outBuf, count);
|
||||
polled += count;
|
||||
} while (pres == HSER_POLL_MORE);
|
||||
assert(pres == HSER_POLL_EMPTY);
|
||||
@ -98,4 +102,6 @@ void heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsi
|
||||
heatshrink_decoder_finish(&hsd);
|
||||
}
|
||||
}
|
||||
return (uint32_t)polled;
|
||||
}
|
||||
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/** gets data from array, writes to callback */
|
||||
void heatshrink_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata);
|
||||
/** gets data from array, writes to callback if nonzero. Returns total length. */
|
||||
uint32_t heatshrink_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata);
|
||||
|
||||
/** gets data from callback, writes it into array */
|
||||
void heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data);
|
||||
/** gets data from callback, writes it into array if nonzero. Returns total length */
|
||||
uint32_t heatshrink_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data);
|
||||
|
||||
@ -14,13 +14,15 @@
|
||||
|
||||
#include "compress_rle.h"
|
||||
|
||||
// gets data from array, writes to callback
|
||||
void rle_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata) {
|
||||
/** gets data from array, writes to callback if nonzero. Returns total length. */
|
||||
uint32_t rle_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata) {
|
||||
uint32_t outputLen = 0;
|
||||
int lastCh = -1; // not a valid char
|
||||
while (dataLen) {
|
||||
unsigned char ch = *(data++);
|
||||
dataLen--;
|
||||
callback(ch, cbdata);
|
||||
outputLen++;
|
||||
if (callback) callback(ch, cbdata);
|
||||
if (ch==lastCh) {
|
||||
int cnt = 0;
|
||||
while (dataLen && lastCh==*data && cnt<255) {
|
||||
@ -28,25 +30,31 @@ void rle_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned c
|
||||
dataLen--;
|
||||
cnt++;
|
||||
}
|
||||
callback((unsigned char)cnt, cbdata);
|
||||
outputLen++;
|
||||
if (callback) callback((unsigned char)cnt, cbdata);
|
||||
}
|
||||
lastCh = ch;
|
||||
}
|
||||
return outputLen;
|
||||
}
|
||||
|
||||
// gets data from callback, writes it into array
|
||||
void rle_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data) {
|
||||
/** gets data from callback, writes it into array if nonzero. Returns total length */
|
||||
uint32_t rle_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data) {
|
||||
uint32_t outputLen = 0;
|
||||
int lastCh = -256; // not a valid char
|
||||
while (true) {
|
||||
int ch = callback(cbdata);
|
||||
if (ch<0) return;
|
||||
*(data++) = (unsigned char)ch;
|
||||
if (ch<0) return outputLen;
|
||||
if (data) data[outputLen] = (unsigned char)ch;
|
||||
outputLen++;
|
||||
if (ch==lastCh) {
|
||||
int cnt = callback(cbdata);
|
||||
while (cnt-->0) {
|
||||
*(data++) = (unsigned char)ch;
|
||||
if (data) data[outputLen] = (unsigned char)ch;
|
||||
outputLen++;
|
||||
}
|
||||
}
|
||||
lastCh = ch;
|
||||
}
|
||||
return outputLen;
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
|
||||
#include "jsutils.h"
|
||||
|
||||
/** gets data from array, writes to callback */
|
||||
void rle_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata);
|
||||
/** gets data from array, writes to callback if nonzero. Returns total length. */
|
||||
uint32_t rle_encode(unsigned char *data, size_t dataLen, void (*callback)(unsigned char ch, uint32_t *cbdata), uint32_t *cbdata);
|
||||
|
||||
/** gets data from callback, writes it into array */
|
||||
void rle_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data);
|
||||
/** gets data from callback, writes it into array if nonzero. Returns total length */
|
||||
uint32_t rle_decode(int (*callback)(uint32_t *cbdata), uint32_t *cbdata, unsigned char *data);
|
||||
|
||||
109
libs/compression/jswrap_heatshrink.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2018 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 is designed to be parsed during the build process
|
||||
*
|
||||
* Simple compression/decompression using the heatshrink library
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
#include "jsvariterator.h"
|
||||
#include "compress_heatshrink.h"
|
||||
#include "jswrap_heatshrink.h"
|
||||
#include "jsparse.h"
|
||||
|
||||
|
||||
/*JSON{
|
||||
"type" : "library",
|
||||
"class" : "heatshrink",
|
||||
"ifndef" : "SAVE_ON_FLASH"
|
||||
}
|
||||
Simple library for compression/decompression using [heatshrink](https://github.com/atomicobject/heatshrink), an [LZSS](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Storer%E2%80%93Szymanski) compression tool.
|
||||
|
||||
Espruino uses heatshrink internally to compress RAM down to fit in Flash memory when `save()` is used. This just exposes that functionality.
|
||||
|
||||
Functions here take and return buffers of data. There is no support for streaming, so both the compressed and decompressed data must be able to fit in memory at the same time.
|
||||
*/
|
||||
typedef struct {
|
||||
char *ptr;
|
||||
size_t len;
|
||||
} DecompressInfo;
|
||||
|
||||
static void _jswrap_heatshrink_compress_output(unsigned char ch, uint32_t *cbdata) {
|
||||
unsigned char **outPtr = (unsigned char**)cbdata;
|
||||
*((*outPtr)++) = ch;
|
||||
}
|
||||
static int _jswrap_heatshrink_decompress_input(uint32_t *cbdata) {
|
||||
DecompressInfo *decompressInfo = (DecompressInfo *)cbdata;
|
||||
if (!decompressInfo->len) return -1;
|
||||
decompressInfo->len--;
|
||||
return (unsigned char)*(decompressInfo->ptr++);
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
"class" : "heatshrink",
|
||||
"name" : "compress",
|
||||
"generate" : "jswrap_heatshrink_compress",
|
||||
"params" : [
|
||||
["data","JsVar","The data to compress"]
|
||||
],
|
||||
"return" : ["JsVar","Returns the result as an ArrayBuffer"],
|
||||
"return_object" : "ArrayBuffer",
|
||||
"ifndef" : "SAVE_ON_FLASH"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_heatshrink_compress(JsVar *data) {
|
||||
JSV_GET_AS_CHAR_ARRAY(dataPtr, dataLen, data);
|
||||
if (!dataPtr) return 0;
|
||||
uint32_t compressedSize = heatshrink_encode((unsigned char*)dataPtr, dataLen, NULL, NULL);
|
||||
|
||||
char *outPtr = 0;
|
||||
JsVar *outArr = jsvNewArrayBufferWithPtr((unsigned int)compressedSize, &outPtr);
|
||||
if (!outPtr) {
|
||||
jsError("Not enough memory for result");
|
||||
return 0;
|
||||
}
|
||||
heatshrink_encode((unsigned char*)dataPtr, dataLen, _jswrap_heatshrink_compress_output, (uint32_t*)&outPtr);
|
||||
return outArr;
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
"class" : "heatshrink",
|
||||
"name" : "decompress",
|
||||
"generate" : "jswrap_heatshrink_decompress",
|
||||
"params" : [
|
||||
["data","JsVar","The data to decompress"]
|
||||
],
|
||||
"return" : ["JsVar","Returns the result as an ArrayBuffer"],
|
||||
"return_object" : "ArrayBuffer",
|
||||
"ifndef" : "SAVE_ON_FLASH"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_heatshrink_decompress(JsVar *data) {
|
||||
JSV_GET_AS_CHAR_ARRAY(dataPtr, dataLen, data);
|
||||
if (!dataPtr) return 0;
|
||||
DecompressInfo decompressInfo;
|
||||
decompressInfo.ptr = dataPtr;
|
||||
decompressInfo.len = dataLen;
|
||||
uint32_t decompressedSize = heatshrink_decode(_jswrap_heatshrink_decompress_input, (uint32_t*)&decompressInfo, NULL);
|
||||
|
||||
char *outPtr = 0;
|
||||
JsVar *outArr = jsvNewArrayBufferWithPtr((unsigned int)decompressedSize, &outPtr);
|
||||
if (!outPtr) {
|
||||
jsError("Not enough memory for result");
|
||||
return 0;
|
||||
}
|
||||
decompressInfo.ptr = dataPtr;
|
||||
decompressInfo.len = dataLen;
|
||||
heatshrink_decode(_jswrap_heatshrink_decompress_input, (uint32_t*)&decompressInfo, (unsigned char*)outPtr);
|
||||
return outArr;
|
||||
}
|
||||
@ -1,22 +1,17 @@
|
||||
/*
|
||||
* This file is part of Espruino, a JavaScript interpreter for Microcontrollers
|
||||
*
|
||||
* Copyright (C) 2015 Gordon Williams <gw@pur3.co.uk>
|
||||
* Copyright (C) 2018 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 is designed to be parsed during the build process
|
||||
*
|
||||
* Contains ESP8266 board specific functions.
|
||||
* Simple compression/decompression using the heatshrink library
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsvar.h"
|
||||
|
||||
#ifndef TARGETS_ESP8266_EMULATOR_USER_CONFIG_H_
|
||||
#define TARGETS_ESP8266_EMULATOR_USER_CONFIG_H_
|
||||
|
||||
|
||||
|
||||
#endif /* TARGETS_ESP8266_EMULATOR_USER_CONFIG_H_ */
|
||||
JsVar *jswrap_heatshrink_compress(JsVar *data);
|
||||
JsVar *jswrap_heatshrink_decompress(JsVar *data);
|
||||
@ -16,13 +16,20 @@
|
||||
#include "jsvar.h"
|
||||
#include "jsvariterator.h"
|
||||
#include "jswrap_crypto.h"
|
||||
#include "jsparse.h"
|
||||
|
||||
#ifdef USE_AES
|
||||
#include "mbedtls/include/mbedtls/aes.h"
|
||||
#endif
|
||||
#ifndef USE_SHA1_JS
|
||||
#include "mbedtls/include/mbedtls/sha1.h"
|
||||
#endif
|
||||
#ifdef USE_SHA256
|
||||
#include "mbedtls/include/mbedtls/sha256.h"
|
||||
#endif
|
||||
#ifdef USE_SHA512
|
||||
#include "mbedtls/include/mbedtls/sha512.h"
|
||||
#endif
|
||||
#include "mbedtls/include/mbedtls/pkcs5.h"
|
||||
#ifdef USE_TLS
|
||||
#include "mbedtls/include/mbedtls/pk.h"
|
||||
@ -38,7 +45,7 @@
|
||||
}
|
||||
Cryptographic functions
|
||||
|
||||
**Note:** This library is currently only included in builds for the Espruino Pico and Espruino WiFi. For other boards you will have to make build your own firmware, and you may need to remove other features in order to make room.
|
||||
**Note:** This library is currently only included in builds for boards where there is space. For other boards there is `crypto.js` which implements SHA1 in JS.
|
||||
*/
|
||||
|
||||
|
||||
@ -46,11 +53,11 @@ Cryptographic functions
|
||||
"type" : "class",
|
||||
"library" : "crypto",
|
||||
"class" : "AES",
|
||||
"ifdef" : "USE_TLS"
|
||||
"ifdef" : "USE_AES"
|
||||
}
|
||||
Class containing AES encryption/decryption
|
||||
|
||||
**Note:** This library is currently only included in builds for the Espruino Pico and Espruino WiFi. For other boards you will have to make build your own firmware, and you may need to remove other features in order to make room.
|
||||
**Note:** This library is currently only included in builds for boards where there is space. For other boards there is `crypto.js` which implements SHA1 in JS.
|
||||
*/
|
||||
/*JSON{
|
||||
"type" : "staticproperty",
|
||||
@ -118,16 +125,29 @@ CryptoMode jswrap_crypto_getMode(JsVar *mode) {
|
||||
}
|
||||
|
||||
mbedtls_md_type_t jswrap_crypto_getHasher(JsVar *hasher) {
|
||||
#ifndef USE_SHA1_JS
|
||||
if (jsvIsStringEqual(hasher, "SHA1")) return MBEDTLS_MD_SHA1;
|
||||
#endif
|
||||
#ifdef USE_SHA256
|
||||
if (jsvIsStringEqual(hasher, "SHA224")) return MBEDTLS_MD_SHA224;
|
||||
if (jsvIsStringEqual(hasher, "SHA256")) return MBEDTLS_MD_SHA256;
|
||||
#endif
|
||||
#ifdef USE_SHA512
|
||||
if (jsvIsStringEqual(hasher, "SHA384")) return MBEDTLS_MD_SHA384;
|
||||
if (jsvIsStringEqual(hasher, "SHA512")) return MBEDTLS_MD_SHA512;
|
||||
#endif
|
||||
jsExceptionHere(JSET_ERROR, "Unknown Hasher %q", hasher);
|
||||
return MBEDTLS_MD_NONE;
|
||||
}
|
||||
|
||||
JsVar *jswrap_crypto_SHAx(JsVar *message, int shaNum) {
|
||||
#ifdef USE_SHA1_JS
|
||||
if (shaNum==1) {
|
||||
// (c) 2016 Rhys Williams, @jumjum. https://github.com/espruino/EspruinoDocs/blob/master/modules/crypto.js
|
||||
return jspExecuteJSFunction("(function(b){function n(a){for(d=3;0<=d;d--)g.push(a>>8*d&255)}var d,a;b=E.toString(b)+'\\x80';var v=new Int32Array([1518500249,1859775393,2400959708,3395469782]);var k=Math.ceil((b.length/4+2)/16);var g=Array(k);b=E.toUint8Array(b);for(d=0;d<k;d++){var f=d<<6;var e=new Int32Array(16);for(a=0;16>a;a++){var c=f+(a<<2);e[a]=b[c]<<24|b[c+1]<<16|b[c+2]<<8|b[c+3]}g[d]=e}g[k-1][14]=8*(b.length-1)/Math.pow(2,32);g[k-1][14]=Math.floor(g[k-1][14]);g[k-1][15]=8*(b.length-1)&4294967295;b=1732584193;var p=4023233417;var q=2562383102;var r=271733878;var t=3285377520;var l=new Int32Array(80);for(d=0;d<k;d++){for(a=0;16>a;a++)l[a]=g[d][a];for(a=16;80>a;a++)f=l[a-3]^l[a-8]^l[a-14]^l[a-16],l[a]=f<<1|f>>>31;f=b;c=p;e=q;var h=r;var u=t;for(a=0;80>a;a++){var m=Math.floor(a/20);var w=f<<5|f>>>27;var x=0===m?c&e^~c&h:1===m?c^e^h:2===m?c&e^c&h^e&h:c^e^h;m=w+x+u+v[m]+l[a]&4294967295;u=h;h=e;e=c<<30|c>>>2;c=f;f=m}b=b+f&4294967295;p=p+c&4294967295;q=q+e&4294967295;r=r+h&4294967295;t=t+u&4294967295}g=[];n(b);n(p);n(q);n(r);n(t);return E.toUint8Array(g).buffer})",0,1,&message);
|
||||
}
|
||||
#endif
|
||||
|
||||
JSV_GET_AS_CHAR_ARRAY(msgPtr, msgLen, message);
|
||||
if (!msgPtr) return 0;
|
||||
|
||||
@ -141,11 +161,17 @@ JsVar *jswrap_crypto_SHAx(JsVar *message, int shaNum) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef USE_SHA1_JS
|
||||
if (shaNum==1) mbedtls_sha1((unsigned char *)msgPtr, msgLen, (unsigned char *)outPtr);
|
||||
#endif
|
||||
#ifdef USE_SHA256
|
||||
else if (shaNum==224) mbedtls_sha256((unsigned char *)msgPtr, msgLen, (unsigned char *)outPtr, true/*224*/);
|
||||
else if (shaNum==256) mbedtls_sha256((unsigned char *)msgPtr, msgLen, (unsigned char *)outPtr, false/*256*/);
|
||||
#endif
|
||||
#ifdef USE_SHA512
|
||||
else if (shaNum==384) mbedtls_sha512((unsigned char *)msgPtr, msgLen, (unsigned char *)outPtr, true/*384*/);
|
||||
else if (shaNum==512) mbedtls_sha512((unsigned char *)msgPtr, msgLen, (unsigned char *)outPtr, false/*512*/);
|
||||
#endif
|
||||
return outArr;
|
||||
}
|
||||
|
||||
@ -162,7 +188,11 @@ JsVar *jswrap_crypto_SHAx(JsVar *message, int shaNum) {
|
||||
"ifdef" : "USE_CRYPTO"
|
||||
}
|
||||
|
||||
Performs a SHA1 hash and returns the result as a 20 byte ArrayBuffer
|
||||
Performs a SHA1 hash and returns the result as a 20 byte ArrayBuffer.
|
||||
|
||||
**Note:** On some boards (currently only Espruino Original) there
|
||||
isn't space for a fully unrolled SHA1 implementation so a slower
|
||||
all-JS implementation is used instead.
|
||||
*/
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
@ -174,7 +204,7 @@ Performs a SHA1 hash and returns the result as a 20 byte ArrayBuffer
|
||||
],
|
||||
"return" : ["JsVar","Returns a 20 byte ArrayBuffer"],
|
||||
"return_object" : "ArrayBuffer",
|
||||
"ifdef" : "USE_CRYPTO"
|
||||
"ifdef" : "USE_SHA256"
|
||||
}
|
||||
|
||||
Performs a SHA224 hash and returns the result as a 28 byte ArrayBuffer
|
||||
@ -189,7 +219,7 @@ Performs a SHA224 hash and returns the result as a 28 byte ArrayBuffer
|
||||
],
|
||||
"return" : ["JsVar","Returns a 20 byte ArrayBuffer"],
|
||||
"return_object" : "ArrayBuffer",
|
||||
"ifdef" : "USE_CRYPTO"
|
||||
"ifdef" : "USE_SHA256"
|
||||
}
|
||||
|
||||
Performs a SHA256 hash and returns the result as a 32 byte ArrayBuffer
|
||||
@ -204,7 +234,7 @@ Performs a SHA256 hash and returns the result as a 32 byte ArrayBuffer
|
||||
],
|
||||
"return" : ["JsVar","Returns a 20 byte ArrayBuffer"],
|
||||
"return_object" : "ArrayBuffer",
|
||||
"ifdef" : "USE_CRYPTO"
|
||||
"ifdef" : "USE_SHA512"
|
||||
}
|
||||
|
||||
Performs a SHA384 hash and returns the result as a 48 byte ArrayBuffer
|
||||
@ -219,7 +249,7 @@ Performs a SHA384 hash and returns the result as a 48 byte ArrayBuffer
|
||||
],
|
||||
"return" : ["JsVar","Returns a 32 byte ArrayBuffer"],
|
||||
"return_object" : "ArrayBuffer",
|
||||
"ifdef" : "USE_CRYPTO"
|
||||
"ifdef" : "USE_SHA512"
|
||||
}
|
||||
|
||||
Performs a SHA512 hash and returns the result as a 64 byte ArrayBuffer
|
||||
@ -299,8 +329,9 @@ JsVar *jswrap_crypto_PBKDF2(JsVar *passphrase, JsVar *salt, JsVar *options) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef USE_AES
|
||||
static NO_INLINE JsVar *jswrap_crypto_AEScrypt(JsVar *message, JsVar *key, JsVar *options, bool encrypt) {
|
||||
int err;
|
||||
|
||||
@ -411,8 +442,6 @@ static NO_INLINE JsVar *jswrap_crypto_AEScrypt(JsVar *message, JsVar *key, JsVar
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_AES
|
||||
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
|
||||
@ -34,37 +34,28 @@
|
||||
|
||||
// See aes.c. Do we want 10kB of data full of constants? no.
|
||||
#define MBEDTLS_AES_ROM_TABLES
|
||||
// Use non-unrolled SHA256
|
||||
#define MBEDTLS_SHA256_SMALLER
|
||||
|
||||
|
||||
#ifdef USE_TLS
|
||||
|
||||
/* mbed TLS feature support */
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_CIPHER_MODE_CFB
|
||||
#define MBEDTLS_CIPHER_MODE_CTR
|
||||
|
||||
#define MBEDTLS_PKCS1_V15
|
||||
#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
|
||||
#define MBEDTLS_SSL_PROTO_TLS1_2
|
||||
|
||||
/* mbed TLS modules */
|
||||
#define MBEDTLS_AES_C
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
#define MBEDTLS_BIGNUM_C
|
||||
#define MBEDTLS_CIPHER_C
|
||||
#define MBEDTLS_CTR_DRBG_C
|
||||
#define MBEDTLS_ECP_C
|
||||
#define MBEDTLS_ENTROPY_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_MD5_C
|
||||
#define MBEDTLS_OID_C
|
||||
#define MBEDTLS_PKCS5_C
|
||||
#define MBEDTLS_PK_C
|
||||
#define MBEDTLS_PK_PARSE_C
|
||||
#define MBEDTLS_RSA_C
|
||||
#define MBEDTLS_SHA1_C
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SHA512_C
|
||||
|
||||
#define MBEDTLS_SSL_CLI_C
|
||||
#define MBEDTLS_SSL_SRV_C
|
||||
#define MBEDTLS_SSL_TLS_C
|
||||
@ -88,26 +79,25 @@
|
||||
#define MBEDTLS_ECP_DP_BP512R1_ENABLED
|
||||
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
|
||||
|
||||
#else // !USE_TLS
|
||||
#endif
|
||||
|
||||
/* mbed TLS feature support */
|
||||
/* common mbed TLS feature support */
|
||||
#define MBEDTLS_CIPHER_MODE_CBC
|
||||
#define MBEDTLS_CIPHER_MODE_CFB
|
||||
#define MBEDTLS_CIPHER_MODE_CTR
|
||||
|
||||
/* mbed TLS modules */
|
||||
/* common mbed TLS modules */
|
||||
#define MBEDTLS_AES_C
|
||||
#define MBEDTLS_ASN1_PARSE_C
|
||||
#define MBEDTLS_CIPHER_C
|
||||
#define MBEDTLS_MD_C
|
||||
#define MBEDTLS_OID_C
|
||||
#define MBEDTLS_PKCS5_C
|
||||
#ifndef USE_SHA1_JS
|
||||
#define MBEDTLS_SHA1_C
|
||||
#endif
|
||||
#define MBEDTLS_SHA256_C
|
||||
#define MBEDTLS_SHA512_C
|
||||
|
||||
#endif
|
||||
|
||||
#include "jsvar.h"
|
||||
|
||||
#define MBEDTLS_PLATFORM_C
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
/* Martin Thomas 4/2009 */
|
||||
/* Martin Thomas 4/2009
|
||||
* Gordon Williams 2019 */
|
||||
|
||||
#include "integer.h"
|
||||
#include "fattime.h"
|
||||
//#include "rtc.h"
|
||||
#include "jswrap_date.h"
|
||||
|
||||
DWORD get_fattime (void)
|
||||
{
|
||||
JsVarFloat time = jswrap_date_now();
|
||||
TimeInDay tid = getTimeFromMilliSeconds(time, false);
|
||||
CalendarDate date = getCalendarDate(tid.daysSinceEpoch);
|
||||
|
||||
DWORD res;
|
||||
/*RTC_t rtc;
|
||||
|
||||
rtc_gettime( &rtc );*/
|
||||
|
||||
res = (((DWORD)2012/*rtc.year*/ - 1980) << 25)
|
||||
| ((DWORD)1/*rtc.month*/ << 21)
|
||||
| ((DWORD)1/*rtc.mday*/ << 16)
|
||||
| (WORD)(0/*rtc.hour*/ << 11)
|
||||
| (WORD)(0/*rtc.min*/ << 5)
|
||||
| (WORD)(0/*rtc.sec*/ >> 1);
|
||||
|
||||
res = (((DWORD)date.year - 1980) << 25)
|
||||
| ((DWORD)(date.month+1) << 21)
|
||||
| ((DWORD)date.day << 16)
|
||||
| (WORD)(tid.hour << 11)
|
||||
| (WORD)(tid.min << 5)
|
||||
| (WORD)(tid.sec >> 1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -208,6 +208,7 @@
|
||||
/ System Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef SAVE_ON_FLASH
|
||||
#define _FS_NORTC 1
|
||||
#define _NORTC_MON 1
|
||||
#define _NORTC_MDAY 1
|
||||
@ -220,6 +221,10 @@
|
||||
/ to be added to the project to read current time from RTC. _NORTC_MON,
|
||||
/ _NORTC_MDAY and _NORTC_YEAR have no effect.
|
||||
/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
|
||||
#else
|
||||
#define _FS_NORTC 0
|
||||
// we have time!
|
||||
#endif
|
||||
|
||||
|
||||
#define _FS_LOCK 0
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
#include "jsflags.h"
|
||||
|
||||
#define JS_FS_DATA_NAME JS_HIDDEN_CHAR_STR"FSd" // the data in each file
|
||||
#define JS_FS_OPEN_FILES_NAME JS_HIDDEN_CHAR_STR"FSo" // the list of open files
|
||||
#define JS_FS_OPEN_FILES_NAME "FSopen" // the list of open files
|
||||
#if !defined(LINUX) && !defined(USE_FILESYSTEM_SDIO) && !defined(USE_FLASHFS)
|
||||
#define SD_CARD_ANYWHERE
|
||||
#endif
|
||||
@ -239,6 +239,7 @@ static bool allocateJsFile(JsFile* file,FileMode mode, FileType type) {
|
||||
|
||||
JsVar *data = jsvNewFlatStringOfLength(sizeof(JsFileData));
|
||||
if (!data) { // out of memory for flat string
|
||||
jsErrorFlags |= JSERR_LOW_MEMORY; // flag this up as an issue
|
||||
jsvUnLock(parent);
|
||||
return false;
|
||||
}
|
||||
@ -603,9 +604,11 @@ Before first use the media needs to be formatted.
|
||||
|
||||
```
|
||||
fs=require("fs");
|
||||
if ( typeof(fs.readdirSync())==="undefined" ) {
|
||||
console.log("Formatting FS");
|
||||
E.flashFatFS({format:true});
|
||||
try {
|
||||
fs.readdirSync();
|
||||
} catch (e) { //'Uncaught Error: Unable to mount media : NO_FILESYSTEM'
|
||||
console.log('Formatting FS - only need to do once');
|
||||
E.flashFatFS({ format: true });
|
||||
}
|
||||
fs.writeFileSync("bang.txt", "This is the way the world ends\nnot with a bang but a whimper.\n");
|
||||
fs.readdirSync();
|
||||
|
||||
@ -73,21 +73,48 @@ void graphicsFallbackScroll(JsGraphics *gfx, int xdir, int ydir) {
|
||||
if (xdir==0 && ydir==0) return;
|
||||
int y;
|
||||
if (ydir<=0) {
|
||||
int h = gfx->data.height+xdir;
|
||||
int h = gfx->data.height+ydir;
|
||||
for (y=0;y<h;y++)
|
||||
graphicsFallbackScrollX(gfx, xdir, y-ydir, y);
|
||||
} else { // >0
|
||||
for (y=gfx->data.height-ydir-1;y>=0;y--)
|
||||
graphicsFallbackScrollX(gfx, xdir, y, y+ydir);
|
||||
}
|
||||
#ifndef SAVE_ON_FLASH
|
||||
gfx->data.modMinX=0;
|
||||
gfx->data.modMinY=0;
|
||||
gfx->data.modMaxX=gfx->data.width-1;
|
||||
gfx->data.modMaxY=gfx->data.height-1;
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
void graphicsStructResetState(JsGraphics *gfx) {
|
||||
gfx->data.fgColor = 0xFFFFFFFF;
|
||||
gfx->data.bgColor = 0;
|
||||
gfx->data.fontSize = JSGRAPHICS_FONTSIZE_4X6;
|
||||
#ifndef SAVE_ON_FLASH
|
||||
gfx->data.fontAlignX = 3;
|
||||
gfx->data.fontAlignY = 3;
|
||||
gfx->data.fontRotate = 0;
|
||||
#endif
|
||||
gfx->data.cursorX = 0;
|
||||
gfx->data.cursorY = 0;
|
||||
}
|
||||
|
||||
void graphicsStructInit(JsGraphics *gfx) {
|
||||
// type/width/height/bpp should be set elsewhere...
|
||||
gfx->data.flags = JSGRAPHICSFLAGS_NONE;
|
||||
graphicsStructResetState(gfx);
|
||||
#ifndef SAVE_ON_FLASH
|
||||
gfx->data.modMaxX = -32768;
|
||||
gfx->data.modMaxY = -32768;
|
||||
gfx->data.modMinX = 32767;
|
||||
gfx->data.modMinY = 32767;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool graphicsGetFromVar(JsGraphics *gfx, JsVar *parent) {
|
||||
gfx->graphicsVar = parent;
|
||||
JsVar *data = jsvObjectGetChild(parent, JS_HIDDEN_CHAR_STR"gfx", 0);
|
||||
@ -160,10 +187,12 @@ void graphicsToDeviceCoordinates(const JsGraphics *gfx, short *x, short *y) {
|
||||
|
||||
static void graphicsSetPixelDevice(JsGraphics *gfx, int x, int y, unsigned int col) {
|
||||
if (x<0 || y<0 || x>=gfx->data.width || y>=gfx->data.height) return;
|
||||
#ifndef SAVE_ON_FLASH
|
||||
if (x < gfx->data.modMinX) gfx->data.modMinX=(short)x;
|
||||
if (x > gfx->data.modMaxX) gfx->data.modMaxX=(short)x;
|
||||
if (y < gfx->data.modMinY) gfx->data.modMinY=(short)y;
|
||||
if (y > gfx->data.modMaxY) gfx->data.modMaxY=(short)y;
|
||||
#endif
|
||||
gfx->setPixel(gfx,(short)x,(short)y,col & (unsigned int)((1L<<gfx->data.bpp)-1));
|
||||
}
|
||||
|
||||
@ -188,12 +217,12 @@ static void graphicsFillRectDevice(JsGraphics *gfx, int x1, int y1, int x2, int
|
||||
if (x2>=gfx->data.width) x2 = gfx->data.width - 1;
|
||||
if (y2>=gfx->data.height) y2 = gfx->data.height - 1;
|
||||
if (x2<x1 || y2<y1) return; // nope
|
||||
|
||||
#ifndef SAVE_ON_FLASH
|
||||
if (x1 < gfx->data.modMinX) gfx->data.modMinX=(short)x1;
|
||||
if (x2 > gfx->data.modMaxX) gfx->data.modMaxX=(short)x2;
|
||||
if (y1 < gfx->data.modMinY) gfx->data.modMinY=(short)y1;
|
||||
if (y2 > gfx->data.modMaxY) gfx->data.modMaxY=(short)y2;
|
||||
|
||||
#endif
|
||||
if (x1==x2 && y1==y2) {
|
||||
gfx->setPixel(gfx,(short)x1,(short)y1,gfx->data.fgColor);
|
||||
return;
|
||||
@ -240,57 +269,68 @@ void graphicsDrawRect(JsGraphics *gfx, short x1, short y1, short x2, short y2) {
|
||||
graphicsFillRectDevice(gfx,x1,y2,x1,y1);
|
||||
}
|
||||
|
||||
void graphicsDrawCircle(JsGraphics *gfx, short posX, short posY, short rad) {
|
||||
graphicsToDeviceCoordinates(gfx, &posX, &posY);
|
||||
|
||||
int radY = 0,
|
||||
radX = rad;
|
||||
// Decision criterion divided by 2 evaluated at radX=radX, radY=0
|
||||
int decisionOver2 = 1 - radX;
|
||||
|
||||
while (radX >= radY) {
|
||||
graphicsSetPixelDevice(gfx, radX + posX, radY + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, radY + posX, radX + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, -radX + posX, radY + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, -radY + posX, radX + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, -radX + posX, -radY + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, -radY + posX, -radX + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, radX + posX, -radY + posY, gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx, radY + posX, -radX + posY, gfx->data.fgColor);
|
||||
radY++;
|
||||
|
||||
if (decisionOver2 <= 0) {
|
||||
// Change in decision criterion for radY -> radY+1
|
||||
decisionOver2 += 2 * radY + 1;
|
||||
}
|
||||
else {
|
||||
radX--;
|
||||
// Change for radY -> radY+1, radX -> radX-1
|
||||
decisionOver2 += 2 * (radY - radX) + 1;
|
||||
void graphicsDrawEllipse(JsGraphics *gfx, short posX1, short posY1, short posX2, short posY2){
|
||||
graphicsToDeviceCoordinates(gfx, &posX1, &posY1);
|
||||
graphicsToDeviceCoordinates(gfx, &posX2, &posY2);
|
||||
int posX = (posX1+posX2)/2;
|
||||
int posY = (posY1+posY2)/2;
|
||||
int width = (posX2-posX1)/2;
|
||||
int height = (posY2-posY1)/2;
|
||||
if (width<0) width=-width;
|
||||
if (height<0) height=-height;
|
||||
int hh = height * height;
|
||||
int ww = width * width;
|
||||
int hhww = hh * ww;
|
||||
int x0 = width;
|
||||
int dx = 0;
|
||||
int y;
|
||||
graphicsSetPixelDevice(gfx,posX - width,posY,gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx,posX + width,posY,gfx->data.fgColor);
|
||||
for (y = 1; y <= height; y++) {
|
||||
int x1 = x0 - (dx - 1);
|
||||
for(; x1> 0; x1--)
|
||||
if (x1 * x1 * hh + y * y * ww <= hhww)
|
||||
break;
|
||||
dx = x0 - x1;
|
||||
x0 = x1;
|
||||
if(dx<2){
|
||||
graphicsSetPixelDevice(gfx,posX - x0, posY - y,gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx,posX + x0, posY - y,gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx,posX - x0, posY + y,gfx->data.fgColor);
|
||||
graphicsSetPixelDevice(gfx,posX + x0, posY + y,gfx->data.fgColor);
|
||||
} else {
|
||||
graphicsFillRectDevice(gfx,posX - x0, posY - y, posX - x0 - dx + 1, posY - y);
|
||||
graphicsFillRectDevice(gfx,posX + x0, posY - y, posX + x0 + dx - 1, posY - y);
|
||||
graphicsFillRectDevice(gfx,posX - x0, posY + y, posX - x0 - dx + 1, posY + y);
|
||||
graphicsFillRectDevice(gfx,posX + x0, posY + y, posX + x0 + dx - 1, posY + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void graphicsFillCircle(JsGraphics *gfx, short x, short y, short rad) {
|
||||
graphicsToDeviceCoordinates(gfx, &x, &y);
|
||||
|
||||
int radY = 0;
|
||||
int decisionOver2 = 1 - rad;
|
||||
|
||||
while (rad >= radY) {
|
||||
graphicsFillRectDevice(gfx, rad + x, radY + y, -rad + x, -radY + y);
|
||||
graphicsFillRectDevice(gfx, radY + x, rad + y, -radY + x, -rad + y);
|
||||
graphicsFillRectDevice(gfx, -rad + x, radY + y, rad + x, -radY + y);
|
||||
graphicsFillRectDevice(gfx, -radY + x, rad + y, radY + x, -rad + y);
|
||||
radY++;
|
||||
if (decisionOver2 <= 0){
|
||||
// Change in decision criterion for radY -> radY+1
|
||||
decisionOver2 += 2 * radY + 1;
|
||||
}else{
|
||||
rad--;
|
||||
// Change for radY -> radY+1, rad -> rad-1
|
||||
decisionOver2 += 2 * (radY - rad) + 1;
|
||||
}
|
||||
void graphicsFillEllipse(JsGraphics *gfx, short posX1, short posY1, short posX2, short posY2){
|
||||
graphicsToDeviceCoordinates(gfx, &posX1, &posY1);
|
||||
graphicsToDeviceCoordinates(gfx, &posX2, &posY2);
|
||||
int posX = (posX1+posX2)/2;
|
||||
int posY = (posY1+posY2)/2;
|
||||
int width = (posX2-posX1)/2;
|
||||
int height = (posY2-posY1)/2;
|
||||
if (width<0) width=-width;
|
||||
if (height<0) height=-height;
|
||||
int hh = height * height;
|
||||
int ww = width * width;
|
||||
int hhww = hh * ww;
|
||||
int x0 = width;
|
||||
int dx = 0;
|
||||
graphicsFillRectDevice(gfx, posX - width, posY, posX + width, posY);
|
||||
for (int y = 1; y <= height; y++) {
|
||||
int x1 = x0 - (dx - 1);
|
||||
for ( ; x1 > 0; x1--)
|
||||
if (x1*x1*hh + y*y*ww <= hhww)
|
||||
break;
|
||||
dx = x0 - x1;
|
||||
x0 = x1;
|
||||
graphicsFillRectDevice(gfx, posX - x0, posY - y, posX + x0, posY - y);
|
||||
graphicsFillRectDevice(gfx, posX - x0, posY + y, posX + x0, posY + y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,30 +380,31 @@ void graphicsDrawLine(JsGraphics *gfx, short x1, short y1, short x2, short y2) {
|
||||
}
|
||||
|
||||
static inline void graphicsFillPolyCreateScanLines(JsGraphics *gfx, short *minx, short *maxx, short x1, short y1,short x2, short y2) {
|
||||
if (y2 < y1) {
|
||||
short t;
|
||||
t=x1;x1=x2;x2=t;
|
||||
t=y1;y1=y2;y2=t;
|
||||
}
|
||||
int xh = x1*256;
|
||||
int yl = y2-y1;
|
||||
if (yl==0) yl=1;
|
||||
int stepx = (x2-x1)*256 / yl;
|
||||
short y;
|
||||
for (y=y1;y<=y2;y++) {
|
||||
int x = xh>>8;
|
||||
if (x<-32768) x=-32768;
|
||||
if (x>32767) x=32767;
|
||||
if (y>=0 && y<gfx->data.height) {
|
||||
if (x<minx[y]) {
|
||||
minx[y] = (short)x;
|
||||
}
|
||||
if (x>maxx[y]) {
|
||||
maxx[y] = (short)x;
|
||||
}
|
||||
}
|
||||
xh += stepx;
|
||||
if (y2 < y1) {
|
||||
short t;
|
||||
t=x1;x1=x2;x2=t;
|
||||
t=y1;y1=y2;y2=t;
|
||||
}
|
||||
int xh = x1*256 + 128/*do rounding here rather than when we >>8*/;
|
||||
int yl = (1+y2)-y1;
|
||||
int stepx = ((x2-x1)*256 + (yl/2)/*rounding*/) / yl;
|
||||
short y;
|
||||
int x = xh>>8;
|
||||
if (x<-32768) x=-32768;
|
||||
if (x>32767) x=32767;
|
||||
for (y=y1;y<=y2;y++) {
|
||||
int oldx = x;
|
||||
xh += stepx;
|
||||
x = xh>>8;
|
||||
if (x<-32768) x=-32768;
|
||||
if (x>32767) x=32767;
|
||||
if (y>=0 && y<gfx->data.height) {
|
||||
if (oldx<minx[y]) minx[y] = (short)oldx;
|
||||
if (oldx>maxx[y]) maxx[y] = (short)oldx;
|
||||
if (x<minx[y]) minx[y] = (short)x;
|
||||
if (x>maxx[y]) maxx[y] = (short)x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
|
||||
|
||||
@ -30,17 +30,19 @@ typedef enum {
|
||||
JSGRAPHICSFLAGS_ARRAYBUFFER_ZIGZAG = 1, ///< ArrayBuffer: zig-zag (even rows reversed)
|
||||
JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE = 2, ///< ArrayBuffer: if 1 bpp, treat bytes as stacked vertically
|
||||
JSGRAPHICSFLAGS_ARRAYBUFFER_MSB = 4, ///< ArrayBuffer: store pixels MSB first
|
||||
JSGRAPHICSFLAGS_SWAP_XY = 8, //< All devices: swap X and Y over
|
||||
JSGRAPHICSFLAGS_INVERT_X = 16, //< All devices: x = getWidth() - (x+1) - where x is DEVICE X
|
||||
JSGRAPHICSFLAGS_INVERT_Y = 32, //< All devices: y = getHeight() - (y+1) - where y is DEVICE Y
|
||||
JSGRAPHICSFLAGS_ARRAYBUFFER_INTERLEAVEX = 8, //< ArrayBuffer: Pixels 0,2,4,etc are from the top half of the image, 1,3,5,etc from the bottom half. Used for P3 LED panels
|
||||
JSGRAPHICSFLAGS_SWAP_XY = 16, //< All devices: swap X and Y over
|
||||
JSGRAPHICSFLAGS_INVERT_X = 32, //< All devices: x = getWidth() - (x+1) - where x is DEVICE X
|
||||
JSGRAPHICSFLAGS_INVERT_Y = 64, //< All devices: y = getHeight() - (y+1) - where y is DEVICE Y
|
||||
JSGRAPHICSFLAGS_COLOR_BASE = 128,
|
||||
|
||||
JSGRAPHICSFLAGS_COLOR_RGB = 0,
|
||||
JSGRAPHICSFLAGS_COLOR_BRG = 64, //< All devices: color order is BRG
|
||||
JSGRAPHICSFLAGS_COLOR_BGR = 128, //< All devices: color order is BGR
|
||||
JSGRAPHICSFLAGS_COLOR_GBR = 64+128, //< All devices: color order is GBR
|
||||
JSGRAPHICSFLAGS_COLOR_GRB = 256, //< All devices: color order is GRB
|
||||
JSGRAPHICSFLAGS_COLOR_RBG = 256+64, //< All devices: color order is RBG
|
||||
JSGRAPHICSFLAGS_COLOR_MASK = 64+128+256, //< All devices: color order is BRG
|
||||
JSGRAPHICSFLAGS_COLOR_BRG = JSGRAPHICSFLAGS_COLOR_BASE, //< All devices: color order is BRG
|
||||
JSGRAPHICSFLAGS_COLOR_BGR = JSGRAPHICSFLAGS_COLOR_BASE*2, //< All devices: color order is BGR
|
||||
JSGRAPHICSFLAGS_COLOR_GBR = JSGRAPHICSFLAGS_COLOR_BASE*3, //< All devices: color order is GBR
|
||||
JSGRAPHICSFLAGS_COLOR_GRB = JSGRAPHICSFLAGS_COLOR_BASE*4, //< All devices: color order is GRB
|
||||
JSGRAPHICSFLAGS_COLOR_RBG = JSGRAPHICSFLAGS_COLOR_BASE*5, //< All devices: color order is RBG
|
||||
JSGRAPHICSFLAGS_COLOR_MASK = JSGRAPHICSFLAGS_COLOR_BASE*7, //< All devices: color order is BRG
|
||||
} JsGraphicsFlags;
|
||||
|
||||
#define JSGRAPHICS_FONTSIZE_4X6 (-1) // a bitmap font
|
||||
@ -60,7 +62,14 @@ typedef struct {
|
||||
unsigned int fgColor, bgColor; ///< current foreground and background colors
|
||||
short fontSize; ///< See JSGRAPHICS_FONTSIZE_ constants
|
||||
short cursorX, cursorY; ///< current cursor positions
|
||||
#ifndef SAVE_ON_FLASH
|
||||
unsigned char fontAlignX : 2;
|
||||
unsigned char fontAlignY : 2;
|
||||
unsigned char fontRotate : 2;
|
||||
#endif
|
||||
#ifndef SAVE_ON_FLASH
|
||||
short modMinX, modMinY, modMaxX, modMaxY; ///< area that has been modified
|
||||
#endif
|
||||
} PACKED_FLAGS JsGraphicsData;
|
||||
|
||||
typedef struct JsGraphics {
|
||||
@ -75,23 +84,14 @@ typedef struct JsGraphics {
|
||||
void (*scroll)(struct JsGraphics *gfx, int xdir, int ydir); // scroll - leave unscrolled area undefined
|
||||
} PACKED_FLAGS JsGraphics;
|
||||
|
||||
static inline void graphicsStructInit(JsGraphics *gfx) {
|
||||
// type/width/height/bpp should be set elsewhere...
|
||||
gfx->data.flags = JSGRAPHICSFLAGS_NONE;
|
||||
gfx->data.fgColor = 0xFFFFFFFF;
|
||||
gfx->data.bgColor = 0;
|
||||
gfx->data.fontSize = JSGRAPHICS_FONTSIZE_4X6;
|
||||
gfx->data.cursorX = 0;
|
||||
gfx->data.cursorY = 0;
|
||||
gfx->data.modMaxX = -32768;
|
||||
gfx->data.modMaxY = -32768;
|
||||
gfx->data.modMinX = 32767;
|
||||
gfx->data.modMinY = 32767;
|
||||
}
|
||||
|
||||
// ---------------------------------- these are in graphics.c
|
||||
// Access a JsVar and get/set the relevant info in JsGraphics
|
||||
/// Reset graphics structure state (eg font size, color, etc)
|
||||
void graphicsStructResetState(JsGraphics *gfx);
|
||||
/// Completely reset graphics structure including flags
|
||||
void graphicsStructInit(JsGraphics *gfx);
|
||||
/// Access the Graphics Instance JsVar and get the relevant info in a JsGraphics structure
|
||||
bool graphicsGetFromVar(JsGraphics *gfx, JsVar *parent);
|
||||
/// Access the Graphics Instance JsVar and set the relevant info from JsGraphics structure
|
||||
void graphicsSetVar(JsGraphics *gfx);
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
/// Get the memory requires for this graphics's pixels if everything was packed as densely as possible
|
||||
@ -105,8 +105,8 @@ void graphicsClear(JsGraphics *gfx);
|
||||
void graphicsFillRect(JsGraphics *gfx, short x1, short y1, short x2, short y2);
|
||||
void graphicsFallbackFillRect(JsGraphics *gfx, short x1, short y1, short x2, short y2); // Simple fillrect - doesn't call device-specific FR
|
||||
void graphicsDrawRect(JsGraphics *gfx, short x1, short y1, short x2, short y2);
|
||||
void graphicsDrawCircle(JsGraphics *gfx, short posX, short posY, short rad);
|
||||
void graphicsFillCircle(JsGraphics *gfx, short x, short y, short rad);
|
||||
void graphicsDrawEllipse(JsGraphics *gfx, short x, short y, short x2, short y2);
|
||||
void graphicsFillEllipse(JsGraphics *gfx, short x, short y, short x2, short y2);
|
||||
void graphicsDrawString(JsGraphics *gfx, short x1, short y1, const char *str);
|
||||
void graphicsDrawLine(JsGraphics *gfx, short x1, short y1, short x2, short y2);
|
||||
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices); // may overwrite vertices...
|
||||
|
||||
@ -21,33 +21,43 @@
|
||||
bool jswrap_graphics_idle();
|
||||
void jswrap_graphics_init();
|
||||
|
||||
JsVar *jswrap_graphics_getInstance();
|
||||
// For creating graphics classes
|
||||
JsVar *jswrap_graphics_createArrayBuffer(int width, int height, int bpp, JsVar *options);
|
||||
JsVar *jswrap_graphics_createCallback(int width, int height, int bpp, JsVar *callback);
|
||||
#ifdef USE_LCD_SDL
|
||||
JsVar *jswrap_graphics_createSDL(int width, int height);
|
||||
#endif
|
||||
JsVar *jswrap_graphics_createImage(JsVar *data);
|
||||
|
||||
|
||||
int jswrap_graphics_getWidthOrHeight(JsVar *parent, bool height);
|
||||
void jswrap_graphics_clear(JsVar *parent);
|
||||
void jswrap_graphics_fillRect(JsVar *parent, int x1, int y1, int x2, int y2);
|
||||
void jswrap_graphics_drawRect(JsVar *parent, int x1, int y1, int x2, int y2);
|
||||
void jswrap_graphics_drawCircle(JsVar *parent, int x, int y, int rad);
|
||||
void jswrap_graphics_fillCircle(JsVar *parent, int x, int y, int rad);
|
||||
JsVar *jswrap_graphics_clear(JsVar *parent, bool resetState);
|
||||
JsVar *jswrap_graphics_fillRect(JsVar *parent, int x1, int y1, int x2, int y2);
|
||||
JsVar *jswrap_graphics_drawRect(JsVar *parent, int x1, int y1, int x2, int y2);
|
||||
JsVar *jswrap_graphics_drawCircle(JsVar *parent, int x, int y, int rad);
|
||||
JsVar *jswrap_graphics_fillCircle(JsVar *parent, int x, int y, int rad);
|
||||
JsVar *jswrap_graphics_drawEllipse(JsVar *parent, int x, int y, int x2, int y2);
|
||||
JsVar *jswrap_graphics_fillEllipse(JsVar *parent, int x, int y, int x2, int y2);
|
||||
int jswrap_graphics_getPixel(JsVar *parent, int x, int y);
|
||||
void jswrap_graphics_setPixel(JsVar *parent, int x, int y, JsVar *color);
|
||||
void jswrap_graphics_setColorX(JsVar *parent, JsVar *r, JsVar *g, JsVar *b, bool isForeground);
|
||||
JsVar *jswrap_graphics_setPixel(JsVar *parent, int x, int y, JsVar *color);
|
||||
JsVar *jswrap_graphics_setColorX(JsVar *parent, JsVar *r, JsVar *g, JsVar *b, bool isForeground);
|
||||
JsVarInt jswrap_graphics_getColorX(JsVar *parent, bool isForeground);
|
||||
void jswrap_graphics_setFontSizeX(JsVar *parent, int size, bool checkValid);
|
||||
void jswrap_graphics_setFontCustom(JsVar *parent, JsVar *bitmap, int firstChar, JsVar *width, int height);
|
||||
void jswrap_graphics_drawString(JsVar *parent, JsVar *str, int x, int y);
|
||||
JsVar *jswrap_graphics_setFontSizeX(JsVar *parent, int size, bool checkValid);
|
||||
JsVar *jswrap_graphics_setFontCustom(JsVar *parent, JsVar *bitmap, int firstChar, JsVar *width, int height);
|
||||
JsVar *jswrap_graphics_setFontAlign(JsVar *parent, int x, int y, int r);
|
||||
JsVar *jswrap_graphics_drawString(JsVar *parent, JsVar *str, int x, int y);
|
||||
JsVarInt jswrap_graphics_stringWidth(JsVar *parent, JsVar *var);
|
||||
void jswrap_graphics_drawLine(JsVar *parent, int x1, int y1, int x2, int y2);
|
||||
void jswrap_graphics_lineTo(JsVar *parent, int x, int y);
|
||||
void jswrap_graphics_moveTo(JsVar *parent, int x, int y);
|
||||
void jswrap_graphics_fillPoly(JsVar *parent, JsVar *poly);
|
||||
void jswrap_graphics_setRotation(JsVar *parent, int rotation, bool reflect);
|
||||
void jswrap_graphics_drawImage(JsVar *parent, JsVar *image, int xPos, int yPos);
|
||||
JsVar *jswrap_graphics_drawLine(JsVar *parent, int x1, int y1, int x2, int y2);
|
||||
JsVar *jswrap_graphics_lineTo(JsVar *parent, int x, int y);
|
||||
JsVar *jswrap_graphics_moveTo(JsVar *parent, int x, int y);
|
||||
JsVar *jswrap_graphics_drawPoly(JsVar *parent, JsVar *poly, bool closed);
|
||||
JsVar *jswrap_graphics_fillPoly(JsVar *parent, JsVar *poly);
|
||||
JsVar *jswrap_graphics_setRotation(JsVar *parent, int rotation, bool reflect);
|
||||
JsVar *jswrap_graphics_drawImage(JsVar *parent, JsVar *image, int xPos, int yPos);
|
||||
JsVar *jswrap_graphics_asImage(JsVar *parent);
|
||||
JsVar *jswrap_graphics_getModified(JsVar *parent, bool reset);
|
||||
void jswrap_graphics_scroll(JsVar *parent, int x, int y);
|
||||
JsVar *jswrap_graphics_scroll(JsVar *parent, int x, int y);
|
||||
JsVar *jswrap_graphics_asBMP(JsVar *parent);
|
||||
JsVar *jswrap_graphics_asURL(JsVar *parent);
|
||||
void jswrap_graphics_dump(JsVar *parent);
|
||||
|
||||
@ -28,37 +28,11 @@
|
||||
}
|
||||
A simple VT100 terminal emulator.
|
||||
|
||||
When data is sent to this, it searches for a Graphics variable called either
|
||||
`g` or `LCD` and starts writing characters to it.
|
||||
When data is sent to the `Terminal` object, `Graphics.getInstance()`
|
||||
is called and if an instance of `Graphics` is found then characters
|
||||
are written to it.
|
||||
*/
|
||||
|
||||
|
||||
/* We can't add properties to Terminal at the moment because of build_jswrapper
|
||||
* and the hacks used to add devices, but this would be really handy. */
|
||||
/*FIXME{
|
||||
"type" : "method",
|
||||
"class" : "Terminal",
|
||||
"name" : "in",
|
||||
"generate" : "jswrap_telnet_in",
|
||||
"params": [
|
||||
[ "args", "JsVarArray", "One or more items to feed into the Terminal" ]
|
||||
]
|
||||
}
|
||||
Send characters to the given Telnet device *as if they were received*.
|
||||
|
||||
For instance if you had set the console to terminal with `Terminal.setConsole()`
|
||||
then you could feed keypresses in via `Terminal.in`.
|
||||
*/
|
||||
/*void jswrap_telnet_in_cb(int item, void *callbackData) {
|
||||
NOT_USED(callbackData);
|
||||
jshPushIOCharEvent(EV_TERMINAL, (char)item);
|
||||
}
|
||||
void jswrap_telnet_in(JsVar *parent, JsVar *args) {
|
||||
NOT_USED(parent);
|
||||
jsvIterateCallback(args, jswrap_telnet_in_cb, 0);
|
||||
}*/
|
||||
|
||||
|
||||
#define terminalHeight (10)
|
||||
#define terminalCharW (4)
|
||||
#define terminalCharH (6)
|
||||
@ -78,8 +52,7 @@ static void terminalControlCharsReset() {
|
||||
|
||||
// Try and find something to use for Graphics - MUST call terminalSetGFX after if this returns true
|
||||
bool terminalGetGFX(JsGraphics *gfx) {
|
||||
JsVar *v = jsvObjectGetChild(execInfo.root, "g", 0);
|
||||
if (!v) v = jsvObjectGetChild(execInfo.root, "LCD", 0);
|
||||
JsVar *v = jswrap_graphics_getInstance();
|
||||
if (!v) return false;
|
||||
if (graphicsGetFromVar(gfx, v))
|
||||
return true;
|
||||
@ -93,18 +66,20 @@ void terminalFlip(JsGraphics *gfx) {
|
||||
if (flip) jsvUnLock2(jspExecuteFunction(flip,gfx->graphicsVar,0,0),flip);
|
||||
}
|
||||
|
||||
/// Setup the graphics var state and flip the screen
|
||||
void terminalSetGFX(JsGraphics *gfx) {
|
||||
terminalFlip(gfx);
|
||||
graphicsSetVar(gfx);
|
||||
terminalFlip(gfx); // this will read from/save to graphicsVar
|
||||
jsvUnLock(gfx->graphicsVar);
|
||||
}
|
||||
|
||||
/// Scroll up to leave one more line free at the bottom
|
||||
void terminalScroll() {
|
||||
terminalY--;
|
||||
JsGraphics gfx;
|
||||
if (terminalGetGFX(&gfx)) {
|
||||
graphicsScroll(&gfx, 0, -terminalCharH);
|
||||
terminalSetGFX(&gfx);
|
||||
terminalSetGFX(&gfx); // save and flip
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +92,6 @@ void terminalSendChar(char chn) {
|
||||
terminalX = 0; terminalY++;
|
||||
while (terminalY >= terminalHeight)
|
||||
terminalScroll();
|
||||
// TODO: scroll!
|
||||
} else if (chn==13) { // carriage return
|
||||
terminalX = 0;
|
||||
} else if (chn==27) {
|
||||
@ -162,6 +136,22 @@ void terminalSendChar(char chn) {
|
||||
case 66: terminalY++; while (terminalY >= terminalHeight) terminalScroll(); break; // down
|
||||
case 67: if (terminalX<255) terminalX++; break; // right
|
||||
case 68: if (terminalX > 0) terminalX--; break; // left
|
||||
case 74: { // delete all to right and down
|
||||
JsGraphics gfx;
|
||||
if (terminalGetGFX(&gfx)) {
|
||||
short cx = (short)(terminalOffsetX + terminalX*terminalCharW);
|
||||
short cy = (short)(terminalOffsetY + terminalY*terminalCharH);
|
||||
short w = (gfx.data.flags & JSGRAPHICSFLAGS_SWAP_XY) ? gfx.data.height : gfx.data.width;
|
||||
short h = (gfx.data.flags & JSGRAPHICSFLAGS_SWAP_XY) ? gfx.data.width : gfx.data.height;
|
||||
// Clear to right and down
|
||||
unsigned int c = gfx.data.fgColor;
|
||||
gfx.data.fgColor = gfx.data.bgColor;
|
||||
graphicsFillRect(&gfx, cx, cy, w-1, cy+terminalCharH-1); // current line
|
||||
graphicsFillRect(&gfx, terminalOffsetX, cy+terminalCharH, w-1, h-1); // everything under
|
||||
gfx.data.fgColor = c;
|
||||
terminalSetGFX(&gfx);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,15 @@ unsigned int lcdGetPixelIndex_ArrayBuffer(JsGraphics *gfx, int x, int y, int pix
|
||||
if (gfx->data.flags & JSGRAPHICSFLAGS_ARRAYBUFFER_ZIGZAG) {
|
||||
if (y&1) x = gfx->data.width - (x+pixelCount);
|
||||
}
|
||||
if (gfx->data.flags & JSGRAPHICSFLAGS_ARRAYBUFFER_INTERLEAVEX) {
|
||||
int h = gfx->data.height>>1;
|
||||
unsigned int idx = 0;
|
||||
if (y >= h) {
|
||||
y-=h;
|
||||
idx=gfx->data.bpp;
|
||||
}
|
||||
return idx + (unsigned int)((x + y*gfx->data.width)*(gfx->data.bpp<<1));
|
||||
}
|
||||
if (gfx->data.flags & JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE)
|
||||
return (unsigned int)(((x + (y>>3)*gfx->data.width)<<3) | (y&7));
|
||||
else
|
||||
@ -59,6 +68,11 @@ void lcdSetPixels_ArrayBuffer(JsGraphics *gfx, short x, short y, short pixelCoun
|
||||
|
||||
unsigned int whiteMask = (1U<<gfx->data.bpp)-1;
|
||||
bool shortCut = (col==0 || (col&whiteMask)==whiteMask) && (!(gfx->data.flags&JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE)); // simple black or white fill
|
||||
int bppStride = gfx->data.bpp;
|
||||
if (gfx->data.flags&JSGRAPHICSFLAGS_ARRAYBUFFER_INTERLEAVEX) {
|
||||
bppStride <<= 1;
|
||||
shortCut = false;
|
||||
}
|
||||
|
||||
while (pixelCount--) { // writing individual bits
|
||||
if (gfx->data.bpp&7/*not a multiple of one byte*/) {
|
||||
@ -84,7 +98,7 @@ void lcdSetPixels_ArrayBuffer(JsGraphics *gfx, short x, short y, short pixelCoun
|
||||
if (gfx->data.flags & JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE) {
|
||||
jsvArrayBufferIteratorNext(&it);
|
||||
} else {
|
||||
idx += gfx->data.bpp;
|
||||
idx += bppStride;
|
||||
if (idx>=8) jsvArrayBufferIteratorNext(&it);
|
||||
}
|
||||
} else { // we're writing whole bytes
|
||||
@ -140,6 +154,11 @@ void lcdSetPixels_ArrayBuffer_flat(JsGraphics *gfx, short x, short y, short pixe
|
||||
|
||||
unsigned int whiteMask = (1U<<gfx->data.bpp)-1;
|
||||
bool shortCut = (col==0 || (col&whiteMask)==whiteMask) && (!(gfx->data.flags&JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE)); // simple black or white fill
|
||||
int bppStride = gfx->data.bpp;
|
||||
if (gfx->data.flags&JSGRAPHICSFLAGS_ARRAYBUFFER_INTERLEAVEX) {
|
||||
bppStride <<= 1;
|
||||
shortCut = false;
|
||||
}
|
||||
|
||||
while (pixelCount--) { // writing individual bits
|
||||
if (gfx->data.bpp&7/*not a multiple of one byte*/) {
|
||||
@ -161,11 +180,12 @@ void lcdSetPixels_ArrayBuffer_flat(JsGraphics *gfx, short x, short y, short pixe
|
||||
unsigned int mask = (unsigned int)(1<<gfx->data.bpp)-1;
|
||||
unsigned int existing = (unsigned int)*ptr;
|
||||
unsigned int bitIdx = (gfx->data.flags & JSGRAPHICSFLAGS_ARRAYBUFFER_MSB) ? 8-(idx+gfx->data.bpp) : idx;
|
||||
assert(ptr>=(unsigned char*)gfx->backendData && ptr<((unsigned char*)gfx->backendData + graphicsGetMemoryRequired(gfx)));
|
||||
*ptr = (char)((existing&~(mask<<bitIdx)) | ((col&mask)<<bitIdx));
|
||||
if (gfx->data.flags & JSGRAPHICSFLAGS_ARRAYBUFFER_VERTICAL_BYTE) {
|
||||
ptr++;
|
||||
} else {
|
||||
idx += gfx->data.bpp;
|
||||
idx += bppStride;
|
||||
if (idx>=8) ptr++;
|
||||
}
|
||||
} else { // we're writing whole bytes
|
||||
|
||||
@ -1,227 +0,0 @@
|
||||
/*
|
||||
* 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 is designed to be parsed during the build process
|
||||
*
|
||||
* Contains built-in functions for SHA hashes
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "jswrap_hashlib.h"
|
||||
|
||||
const JsHash256 ctx256;
|
||||
// const JsHash512 ctx512;
|
||||
|
||||
JsHashLib hashFunctions[4] = {
|
||||
{ .name="sha224", .data=(char*)&ctx256.context, .init=sha224_init, .update=sha224_update,
|
||||
.final=sha224_final, .digest_size=SHA224_DIGEST_SIZE, .block_size=SHA224_BLOCK_SIZE, .ctx_size=sizeof(ctx256.context) },
|
||||
{ .name="sha256", .data=(char*)&ctx256.context, .init=sha256_init, .update=sha256_update,
|
||||
.final=sha256_final, .digest_size=SHA256_DIGEST_SIZE, .block_size=SHA256_BLOCK_SIZE, .ctx_size=sizeof(ctx256.context) }/*,
|
||||
{ .name="sha384", .data=(char*)&ctx512.context, .init=sha384_init, .update=sha384_update,
|
||||
.final=sha384_final, .digest_size=SHA384_DIGEST_SIZE, .block_size=SHA384_BLOCK_SIZE, .ctx_size=sizeof(ctx512.context) },
|
||||
{ .name="sha512", .data=(char*)&ctx512.context, .init=sha512_init, .update=sha512_update,
|
||||
.final=sha512_final, .digest_size=SHA512_DIGEST_SIZE, .block_size=SHA512_BLOCK_SIZE, .ctx_size=sizeof(ctx512.context) }*/
|
||||
};
|
||||
|
||||
/*JSON{
|
||||
"type" : "library",
|
||||
"class" : "hashlib"
|
||||
}
|
||||
**Note:** This library is currently only included in builds for the original Espruino boards.
|
||||
For other boards you will have to make build your own firmware.
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
/*JSON{
|
||||
"type" : "class",
|
||||
"library" : "hashlib",
|
||||
"class" : "HASH"
|
||||
}
|
||||
**Note:** This class is currently only included in builds for the original Espruino boards.
|
||||
For other boards you will have to make build your own firmware.
|
||||
*/
|
||||
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
"class" : "hashlib",
|
||||
"name" : "sha224",
|
||||
"generate" : "jswrap_hashlib_sha224",
|
||||
"params" : [
|
||||
["message","JsVar","message to hash"]
|
||||
],
|
||||
"return" : ["JsVar","Returns a new HASH SHA224 Object"],
|
||||
"return_object" : "HASH"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_hashlib_sha224(JsVar *message) {
|
||||
JsVar *hashobj = jswrap_hashlib_sha2(HASH_SHA224);
|
||||
|
||||
if (jsvIsString(message)) {
|
||||
jswrap_hashlib_hash_update(hashobj, message);
|
||||
}
|
||||
return hashobj;
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "staticmethod",
|
||||
"class" : "hashlib",
|
||||
"name" : "sha256",
|
||||
"generate" : "jswrap_hashlib_sha256",
|
||||
"params" : [
|
||||
["message","JsVar","message to hash"]
|
||||
],
|
||||
"return" : ["JsVar","Returns a new HASH SHA256 Object"],
|
||||
"return_object" : "HASH"
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_hashlib_sha256(JsVar *message) {
|
||||
JsVar *hashobj = jswrap_hashlib_sha2(HASH_SHA256);
|
||||
|
||||
if (jsvIsString(message)) {
|
||||
jswrap_hashlib_hash_update(hashobj, message);
|
||||
}
|
||||
return hashobj;
|
||||
}
|
||||
|
||||
|
||||
JsVar *jswrap_hashlib_sha2(JsHashType hash_type) {
|
||||
JsVar *hashobj = jspNewObject(0, "HASH");
|
||||
|
||||
if (!hashobj) {
|
||||
return 0; // out of memory
|
||||
}
|
||||
|
||||
hashFunctions[hash_type].init(hashFunctions[hash_type].data);
|
||||
|
||||
JsVar *jsCtx = jsvNewStringOfLength(hashFunctions[hash_type].ctx_size, hashFunctions[hash_type].data);
|
||||
|
||||
jsvObjectSetChildAndUnLock(hashobj, "block_size", jsvNewFromInteger((JsVarInt)hashFunctions[hash_type].block_size));
|
||||
jsvObjectSetChildAndUnLock(hashobj, "context", jsCtx);
|
||||
jsvObjectSetChildAndUnLock(hashobj, "digest_size", jsvNewFromInteger((JsVarInt)hashFunctions[hash_type].digest_size));
|
||||
jsvObjectSetChildAndUnLock(hashobj, "hash_type", jsvNewFromInteger(hash_type));
|
||||
jsvObjectSetChildAndUnLock(hashobj, "name", jsvNewFromString(hashFunctions[hash_type].name));
|
||||
|
||||
return hashobj;
|
||||
}
|
||||
|
||||
|
||||
/*JSON{
|
||||
"type" : "method",
|
||||
"class" : "HASH",
|
||||
"name" : "update",
|
||||
"generate" : "jswrap_hashlib_hash_update",
|
||||
"params" : [
|
||||
["message","JsVar","part of message"]
|
||||
]
|
||||
}
|
||||
*/
|
||||
void jswrap_hashlib_hash_update(JsVar *parent, JsVar *message) {
|
||||
int type;
|
||||
char buff[SHA256_DIGEST_SIZE];
|
||||
|
||||
JsVar *jsCtx = jsvObjectGetChild(parent, "context", 0);
|
||||
JsVar *child = jsvObjectGetChild(parent, "hash_type", 0);
|
||||
|
||||
type = jsvGetInteger(child);
|
||||
jsvUnLock(child);
|
||||
|
||||
jsvGetString(jsCtx, hashFunctions[type].data, hashFunctions[type].ctx_size + 1); // trailing zero
|
||||
|
||||
if (jsvIsString(message)) {
|
||||
size_t i;
|
||||
size_t len = jsvGetStringLength(message);
|
||||
for(i = 0; i < len; i += sizeof(buff)) {
|
||||
int read = (int)jsvGetStringChars(message, i, buff, sizeof(buff));
|
||||
hashFunctions[type].update(hashFunctions[type].data, buff, read);
|
||||
}
|
||||
jsvSetString(jsCtx, hashFunctions[type].data, hashFunctions[type].ctx_size);
|
||||
}
|
||||
|
||||
jsvUnLock(jsCtx);
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "method",
|
||||
"class" : "HASH",
|
||||
"name" : "digest",
|
||||
"generate" : "jswrap_hashlib_hash_digest",
|
||||
"params" : [
|
||||
["message","JsVar","part of message"]
|
||||
],
|
||||
"return" : ["JsVar","Hash digest"]
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_hashlib_hash_digest(JsVar *parent) {
|
||||
int type;
|
||||
char buff[SHA256_DIGEST_SIZE];
|
||||
JsVar *jsCtx = NULL;
|
||||
JsVar *child = NULL;
|
||||
|
||||
child = jsvObjectGetChild(parent, "hash_type", 0);
|
||||
type = jsvGetInteger(child);
|
||||
jsvUnLock(child);
|
||||
|
||||
jsCtx = jsvObjectGetChild(parent, "context", 0);
|
||||
|
||||
jsvGetString(jsCtx, hashFunctions[type].data, hashFunctions[type].ctx_size + 1); // trailing zero
|
||||
jsvUnLock(jsCtx);
|
||||
|
||||
hashFunctions[type].final(hashFunctions[type].data, buff);
|
||||
JsVar *digest = jsvNewStringOfLength(hashFunctions[type].digest_size, buff);
|
||||
|
||||
return digest;
|
||||
}
|
||||
|
||||
/*JSON{
|
||||
"type" : "method",
|
||||
"class" : "HASH",
|
||||
"name" : "hexdigest",
|
||||
"generate" : "jswrap_hashlib_hash_hexdigest",
|
||||
"params" : [
|
||||
["message","JsVar","part of message"]
|
||||
],
|
||||
"return" : ["JsVar","Hash hexdigest"]
|
||||
}
|
||||
*/
|
||||
JsVar *jswrap_hashlib_hash_hexdigest(JsVar *parent) {
|
||||
int type;
|
||||
char buff[SHA256_DIGEST_SIZE];
|
||||
char a[] = "0123456789abcdef";
|
||||
JsVar *jsCtx = NULL;
|
||||
JsVar *child = NULL;
|
||||
JsVar *digest = NULL;
|
||||
|
||||
child = jsvObjectGetChild(parent, "hash_type", 0);
|
||||
type = jsvGetInteger(child);
|
||||
jsvUnLock(child);
|
||||
|
||||
digest = jsvNewFromEmptyString(); // hashFunctions[type].digest_size*2
|
||||
if (!digest) return 0; // out of memory
|
||||
|
||||
jsCtx = jsvObjectGetChild(parent, "context", 0);
|
||||
jsvGetString(jsCtx, hashFunctions[type].data, hashFunctions[type].ctx_size + 1); // trailing zero
|
||||
jsvUnLock(jsCtx);
|
||||
|
||||
hashFunctions[type].final(hashFunctions[type].data, buff);
|
||||
|
||||
unsigned int i;
|
||||
for(i = 0; i < hashFunctions[type].digest_size; i++) {
|
||||
char c[2];
|
||||
c[0] = a[ (unsigned char)(buff[i]) >> 4 ];
|
||||
c[1] = a[ (unsigned char)(buff[i]) & 0x0F ];
|
||||
jsvAppendStringBuf(digest, c, sizeof(c));
|
||||
}
|
||||
|
||||
return digest;
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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/.
|
||||
*
|
||||
* ----------------------------------------------------------------------------
|
||||
* Contains built-in functions for SHA hashes
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
#include "jsutils.h"
|
||||
#include "jsparse.h"
|
||||
#include "jsvar.h"
|
||||
#include "sha2.h"
|
||||
|
||||
typedef struct {
|
||||
sha256_ctx context;
|
||||
unsigned char _blank; ///< this is needed as jsvGetString for 'context' wants to add a trailing zero
|
||||
} PACKED_FLAGS JsHash256;
|
||||
|
||||
typedef struct {
|
||||
sha512_ctx context;
|
||||
unsigned char _blank; ///< this is needed as jsvGetString for 'context' wants to add a trailing zero
|
||||
} PACKED_FLAGS JsHash512;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *data;
|
||||
void (*init)(); // (void *ctx);
|
||||
void (*update)(); // (void *ctx, const unsigned char *message, unsigned int len);
|
||||
void (*final)(); // (void *, unsigned char *digest);
|
||||
unsigned int digest_size;
|
||||
unsigned int block_size;
|
||||
unsigned int ctx_size;
|
||||
} JsHashLib;
|
||||
|
||||
typedef enum {
|
||||
HASH_SHA224,
|
||||
HASH_SHA256/*,
|
||||
HASH_SHA384,
|
||||
HASH_SHA512*/
|
||||
} JsHashType;
|
||||
|
||||
JsVar *jswrap_hashlib_sha224(JsVar *message);
|
||||
JsVar *jswrap_hashlib_sha256(JsVar *message);
|
||||
// JsVar *jswrap_hashlib_sha384(JsVar *message);
|
||||
// JsVar *jswrap_hashlib_sha512(JsVar *message);
|
||||
|
||||
JsVar *jswrap_hashlib_sha2(JsHashType hash_type);
|
||||
|
||||
JsVar *jswrap_hashlib_hash_digest(JsVar *parent);
|
||||
JsVar *jswrap_hashlib_hash_hexdigest(JsVar *parent);
|
||||
void jswrap_hashlib_hash_update(JsVar *parent, JsVar *message);
|
||||
@ -1,949 +0,0 @@
|
||||
/*
|
||||
* FIPS 180-2 SHA-224/256/384/512 implementation
|
||||
* Last update: 02/02/2007
|
||||
* Issue date: 04/30/2005
|
||||
*
|
||||
* Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#define UNROLL_LOOPS /* Enable loops unrolling */
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sha2.h"
|
||||
|
||||
#define SHFR(x, n) (x >> n)
|
||||
#define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
|
||||
#define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
|
||||
#define CH(x, y, z) ((x & y) ^ (~x & z))
|
||||
#define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))
|
||||
|
||||
#define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
|
||||
#define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
|
||||
#define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3))
|
||||
#define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10))
|
||||
|
||||
#define SHA512_F1(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39))
|
||||
#define SHA512_F2(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41))
|
||||
#define SHA512_F3(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHFR(x, 7))
|
||||
#define SHA512_F4(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHFR(x, 6))
|
||||
|
||||
#define UNPACK32(x, str) \
|
||||
{ \
|
||||
*((str) + 3) = (uint8) ((x) ); \
|
||||
*((str) + 2) = (uint8) ((x) >> 8); \
|
||||
*((str) + 1) = (uint8) ((x) >> 16); \
|
||||
*((str) + 0) = (uint8) ((x) >> 24); \
|
||||
}
|
||||
|
||||
#define PACK32(str, x) \
|
||||
{ \
|
||||
*(x) = ((uint32) *((str) + 3) ) \
|
||||
| ((uint32) *((str) + 2) << 8) \
|
||||
| ((uint32) *((str) + 1) << 16) \
|
||||
| ((uint32) *((str) + 0) << 24); \
|
||||
}
|
||||
|
||||
#define UNPACK64(x, str) \
|
||||
{ \
|
||||
*((str) + 7) = (uint8) ((x) ); \
|
||||
*((str) + 6) = (uint8) ((x) >> 8); \
|
||||
*((str) + 5) = (uint8) ((x) >> 16); \
|
||||
*((str) + 4) = (uint8) ((x) >> 24); \
|
||||
*((str) + 3) = (uint8) ((x) >> 32); \
|
||||
*((str) + 2) = (uint8) ((x) >> 40); \
|
||||
*((str) + 1) = (uint8) ((x) >> 48); \
|
||||
*((str) + 0) = (uint8) ((x) >> 56); \
|
||||
}
|
||||
|
||||
#define PACK64(str, x) \
|
||||
{ \
|
||||
*(x) = ((uint64) *((str) + 7) ) \
|
||||
| ((uint64) *((str) + 6) << 8) \
|
||||
| ((uint64) *((str) + 5) << 16) \
|
||||
| ((uint64) *((str) + 4) << 24) \
|
||||
| ((uint64) *((str) + 3) << 32) \
|
||||
| ((uint64) *((str) + 2) << 40) \
|
||||
| ((uint64) *((str) + 1) << 48) \
|
||||
| ((uint64) *((str) + 0) << 56); \
|
||||
}
|
||||
|
||||
/* Macros used for loops unrolling */
|
||||
|
||||
#define SHA256_SCR(i) \
|
||||
{ \
|
||||
w[i] = SHA256_F4(w[i - 2]) + w[i - 7] \
|
||||
+ SHA256_F3(w[i - 15]) + w[i - 16]; \
|
||||
}
|
||||
|
||||
#define SHA512_SCR(i) \
|
||||
{ \
|
||||
w[i] = SHA512_F4(w[i - 2]) + w[i - 7] \
|
||||
+ SHA512_F3(w[i - 15]) + w[i - 16]; \
|
||||
}
|
||||
|
||||
#define SHA256_EXP(a, b, c, d, e, f, g, h, j) \
|
||||
{ \
|
||||
t1 = wv[h] + SHA256_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \
|
||||
+ sha256_k[j] + w[j]; \
|
||||
t2 = SHA256_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \
|
||||
wv[d] += t1; \
|
||||
wv[h] = t1 + t2; \
|
||||
}
|
||||
|
||||
#define SHA512_EXP(a, b, c, d, e, f, g ,h, j) \
|
||||
{ \
|
||||
t1 = wv[h] + SHA512_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \
|
||||
+ sha512_k[j] + w[j]; \
|
||||
t2 = SHA512_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \
|
||||
wv[d] += t1; \
|
||||
wv[h] = t1 + t2; \
|
||||
}
|
||||
|
||||
const uint32 sha224_h0[8] =
|
||||
{0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
||||
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4};
|
||||
|
||||
const uint32 sha256_h0[8] =
|
||||
{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
|
||||
|
||||
const uint64 sha384_h0[8] =
|
||||
{0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL,
|
||||
0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL,
|
||||
0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL,
|
||||
0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL};
|
||||
|
||||
const uint64 sha512_h0[8] =
|
||||
{0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};
|
||||
|
||||
const uint32 sha256_k[64] =
|
||||
{0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
|
||||
|
||||
const uint64 sha512_k[80] =
|
||||
{0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
|
||||
0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
|
||||
0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
|
||||
0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
|
||||
0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
|
||||
0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
|
||||
0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
|
||||
0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
|
||||
0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
|
||||
0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
|
||||
0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
|
||||
0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
|
||||
0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
|
||||
0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
|
||||
0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
|
||||
0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
|
||||
0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
|
||||
0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
|
||||
0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
|
||||
0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
|
||||
0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
|
||||
0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
|
||||
0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
|
||||
0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
|
||||
0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
|
||||
0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
|
||||
0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
|
||||
0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
|
||||
0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
|
||||
0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
|
||||
0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
|
||||
0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
|
||||
0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
|
||||
0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
|
||||
0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
|
||||
0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
|
||||
0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
|
||||
0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
|
||||
0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
|
||||
0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL};
|
||||
|
||||
/* SHA-256 functions */
|
||||
|
||||
void sha256_transf(sha256_ctx *ctx, const unsigned char *message,
|
||||
unsigned int block_nb)
|
||||
{
|
||||
uint32 w[64];
|
||||
uint32 wv[8];
|
||||
uint32 t1, t2;
|
||||
const unsigned char *sub_block;
|
||||
int i;
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
int j;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < (int) block_nb; i++) {
|
||||
sub_block = message + (i << 6);
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
for (j = 0; j < 16; j++) {
|
||||
PACK32(&sub_block[j << 2], &w[j]);
|
||||
}
|
||||
|
||||
for (j = 16; j < 64; j++) {
|
||||
SHA256_SCR(j);
|
||||
}
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
wv[j] = ctx->h[j];
|
||||
}
|
||||
|
||||
for (j = 0; j < 64; j++) {
|
||||
t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6])
|
||||
+ sha256_k[j] + w[j];
|
||||
t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]);
|
||||
wv[7] = wv[6];
|
||||
wv[6] = wv[5];
|
||||
wv[5] = wv[4];
|
||||
wv[4] = wv[3] + t1;
|
||||
wv[3] = wv[2];
|
||||
wv[2] = wv[1];
|
||||
wv[1] = wv[0];
|
||||
wv[0] = t1 + t2;
|
||||
}
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
ctx->h[j] += wv[j];
|
||||
}
|
||||
#else
|
||||
PACK32(&sub_block[ 0], &w[ 0]); PACK32(&sub_block[ 4], &w[ 1]);
|
||||
PACK32(&sub_block[ 8], &w[ 2]); PACK32(&sub_block[12], &w[ 3]);
|
||||
PACK32(&sub_block[16], &w[ 4]); PACK32(&sub_block[20], &w[ 5]);
|
||||
PACK32(&sub_block[24], &w[ 6]); PACK32(&sub_block[28], &w[ 7]);
|
||||
PACK32(&sub_block[32], &w[ 8]); PACK32(&sub_block[36], &w[ 9]);
|
||||
PACK32(&sub_block[40], &w[10]); PACK32(&sub_block[44], &w[11]);
|
||||
PACK32(&sub_block[48], &w[12]); PACK32(&sub_block[52], &w[13]);
|
||||
PACK32(&sub_block[56], &w[14]); PACK32(&sub_block[60], &w[15]);
|
||||
|
||||
SHA256_SCR(16); SHA256_SCR(17); SHA256_SCR(18); SHA256_SCR(19);
|
||||
SHA256_SCR(20); SHA256_SCR(21); SHA256_SCR(22); SHA256_SCR(23);
|
||||
SHA256_SCR(24); SHA256_SCR(25); SHA256_SCR(26); SHA256_SCR(27);
|
||||
SHA256_SCR(28); SHA256_SCR(29); SHA256_SCR(30); SHA256_SCR(31);
|
||||
SHA256_SCR(32); SHA256_SCR(33); SHA256_SCR(34); SHA256_SCR(35);
|
||||
SHA256_SCR(36); SHA256_SCR(37); SHA256_SCR(38); SHA256_SCR(39);
|
||||
SHA256_SCR(40); SHA256_SCR(41); SHA256_SCR(42); SHA256_SCR(43);
|
||||
SHA256_SCR(44); SHA256_SCR(45); SHA256_SCR(46); SHA256_SCR(47);
|
||||
SHA256_SCR(48); SHA256_SCR(49); SHA256_SCR(50); SHA256_SCR(51);
|
||||
SHA256_SCR(52); SHA256_SCR(53); SHA256_SCR(54); SHA256_SCR(55);
|
||||
SHA256_SCR(56); SHA256_SCR(57); SHA256_SCR(58); SHA256_SCR(59);
|
||||
SHA256_SCR(60); SHA256_SCR(61); SHA256_SCR(62); SHA256_SCR(63);
|
||||
|
||||
wv[0] = ctx->h[0]; wv[1] = ctx->h[1];
|
||||
wv[2] = ctx->h[2]; wv[3] = ctx->h[3];
|
||||
wv[4] = ctx->h[4]; wv[5] = ctx->h[5];
|
||||
wv[6] = ctx->h[6]; wv[7] = ctx->h[7];
|
||||
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7, 0); SHA256_EXP(7,0,1,2,3,4,5,6, 1);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5, 2); SHA256_EXP(5,6,7,0,1,2,3,4, 3);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3, 4); SHA256_EXP(3,4,5,6,7,0,1,2, 5);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1, 6); SHA256_EXP(1,2,3,4,5,6,7,0, 7);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7, 8); SHA256_EXP(7,0,1,2,3,4,5,6, 9);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,10); SHA256_EXP(5,6,7,0,1,2,3,4,11);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,12); SHA256_EXP(3,4,5,6,7,0,1,2,13);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,14); SHA256_EXP(1,2,3,4,5,6,7,0,15);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7,16); SHA256_EXP(7,0,1,2,3,4,5,6,17);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,18); SHA256_EXP(5,6,7,0,1,2,3,4,19);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,20); SHA256_EXP(3,4,5,6,7,0,1,2,21);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,22); SHA256_EXP(1,2,3,4,5,6,7,0,23);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7,24); SHA256_EXP(7,0,1,2,3,4,5,6,25);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,26); SHA256_EXP(5,6,7,0,1,2,3,4,27);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,28); SHA256_EXP(3,4,5,6,7,0,1,2,29);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,30); SHA256_EXP(1,2,3,4,5,6,7,0,31);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7,32); SHA256_EXP(7,0,1,2,3,4,5,6,33);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,34); SHA256_EXP(5,6,7,0,1,2,3,4,35);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,36); SHA256_EXP(3,4,5,6,7,0,1,2,37);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,38); SHA256_EXP(1,2,3,4,5,6,7,0,39);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7,40); SHA256_EXP(7,0,1,2,3,4,5,6,41);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,42); SHA256_EXP(5,6,7,0,1,2,3,4,43);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,44); SHA256_EXP(3,4,5,6,7,0,1,2,45);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,46); SHA256_EXP(1,2,3,4,5,6,7,0,47);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7,48); SHA256_EXP(7,0,1,2,3,4,5,6,49);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,50); SHA256_EXP(5,6,7,0,1,2,3,4,51);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,52); SHA256_EXP(3,4,5,6,7,0,1,2,53);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,54); SHA256_EXP(1,2,3,4,5,6,7,0,55);
|
||||
SHA256_EXP(0,1,2,3,4,5,6,7,56); SHA256_EXP(7,0,1,2,3,4,5,6,57);
|
||||
SHA256_EXP(6,7,0,1,2,3,4,5,58); SHA256_EXP(5,6,7,0,1,2,3,4,59);
|
||||
SHA256_EXP(4,5,6,7,0,1,2,3,60); SHA256_EXP(3,4,5,6,7,0,1,2,61);
|
||||
SHA256_EXP(2,3,4,5,6,7,0,1,62); SHA256_EXP(1,2,3,4,5,6,7,0,63);
|
||||
|
||||
ctx->h[0] += wv[0]; ctx->h[1] += wv[1];
|
||||
ctx->h[2] += wv[2]; ctx->h[3] += wv[3];
|
||||
ctx->h[4] += wv[4]; ctx->h[5] += wv[5];
|
||||
ctx->h[6] += wv[6]; ctx->h[7] += wv[7];
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
}
|
||||
}
|
||||
|
||||
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
|
||||
{
|
||||
sha256_ctx ctx;
|
||||
|
||||
sha256_init(&ctx);
|
||||
sha256_update(&ctx, message, len);
|
||||
sha256_final(&ctx, digest);
|
||||
}
|
||||
|
||||
void sha256_init(sha256_ctx *ctx)
|
||||
{
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ctx->h[i] = sha256_h0[i];
|
||||
}
|
||||
#else
|
||||
ctx->h[0] = sha256_h0[0]; ctx->h[1] = sha256_h0[1];
|
||||
ctx->h[2] = sha256_h0[2]; ctx->h[3] = sha256_h0[3];
|
||||
ctx->h[4] = sha256_h0[4]; ctx->h[5] = sha256_h0[5];
|
||||
ctx->h[6] = sha256_h0[6]; ctx->h[7] = sha256_h0[7];
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
|
||||
ctx->len = 0;
|
||||
ctx->tot_len = 0;
|
||||
}
|
||||
|
||||
void sha256_update(sha256_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int new_len, rem_len, tmp_len;
|
||||
const unsigned char *shifted_message;
|
||||
|
||||
tmp_len = SHA256_BLOCK_SIZE - ctx->len;
|
||||
rem_len = len < tmp_len ? len : tmp_len;
|
||||
|
||||
memcpy(&ctx->block[ctx->len], message, rem_len);
|
||||
|
||||
if (ctx->len + len < SHA256_BLOCK_SIZE) {
|
||||
ctx->len += len;
|
||||
return;
|
||||
}
|
||||
|
||||
new_len = len - rem_len;
|
||||
block_nb = new_len / SHA256_BLOCK_SIZE;
|
||||
|
||||
shifted_message = message + rem_len;
|
||||
|
||||
sha256_transf(ctx, ctx->block, 1);
|
||||
sha256_transf(ctx, shifted_message, block_nb);
|
||||
|
||||
rem_len = new_len % SHA256_BLOCK_SIZE;
|
||||
|
||||
memcpy(ctx->block, &shifted_message[block_nb << 6],
|
||||
rem_len);
|
||||
|
||||
ctx->len = rem_len;
|
||||
ctx->tot_len += (block_nb + 1) << 6;
|
||||
}
|
||||
|
||||
void sha256_final(sha256_ctx *ctx, unsigned char *digest)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int pm_len;
|
||||
unsigned int len_b;
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
#endif
|
||||
|
||||
block_nb = (1 + ((SHA256_BLOCK_SIZE - 9)
|
||||
< (ctx->len % SHA256_BLOCK_SIZE)));
|
||||
|
||||
len_b = (ctx->tot_len + ctx->len) << 3;
|
||||
pm_len = block_nb << 6;
|
||||
|
||||
memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
|
||||
ctx->block[ctx->len] = 0x80;
|
||||
UNPACK32(len_b, ctx->block + pm_len - 4);
|
||||
|
||||
sha256_transf(ctx, ctx->block, block_nb);
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
for (i = 0 ; i < 8; i++) {
|
||||
UNPACK32(ctx->h[i], &digest[i << 2]);
|
||||
}
|
||||
#else
|
||||
UNPACK32(ctx->h[0], &digest[ 0]);
|
||||
UNPACK32(ctx->h[1], &digest[ 4]);
|
||||
UNPACK32(ctx->h[2], &digest[ 8]);
|
||||
UNPACK32(ctx->h[3], &digest[12]);
|
||||
UNPACK32(ctx->h[4], &digest[16]);
|
||||
UNPACK32(ctx->h[5], &digest[20]);
|
||||
UNPACK32(ctx->h[6], &digest[24]);
|
||||
UNPACK32(ctx->h[7], &digest[28]);
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
}
|
||||
|
||||
/* SHA-512 functions */
|
||||
|
||||
void sha512_transf(sha512_ctx *ctx, const unsigned char *message,
|
||||
unsigned int block_nb)
|
||||
{
|
||||
uint64 w[80];
|
||||
uint64 wv[8];
|
||||
uint64 t1, t2;
|
||||
const unsigned char *sub_block;
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < (int) block_nb; i++) {
|
||||
sub_block = message + (i << 7);
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
for (j = 0; j < 16; j++) {
|
||||
PACK64(&sub_block[j << 3], &w[j]);
|
||||
}
|
||||
|
||||
for (j = 16; j < 80; j++) {
|
||||
SHA512_SCR(j);
|
||||
}
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
wv[j] = ctx->h[j];
|
||||
}
|
||||
|
||||
for (j = 0; j < 80; j++) {
|
||||
t1 = wv[7] + SHA512_F2(wv[4]) + CH(wv[4], wv[5], wv[6])
|
||||
+ sha512_k[j] + w[j];
|
||||
t2 = SHA512_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]);
|
||||
wv[7] = wv[6];
|
||||
wv[6] = wv[5];
|
||||
wv[5] = wv[4];
|
||||
wv[4] = wv[3] + t1;
|
||||
wv[3] = wv[2];
|
||||
wv[2] = wv[1];
|
||||
wv[1] = wv[0];
|
||||
wv[0] = t1 + t2;
|
||||
}
|
||||
|
||||
for (j = 0; j < 8; j++) {
|
||||
ctx->h[j] += wv[j];
|
||||
}
|
||||
#else
|
||||
PACK64(&sub_block[ 0], &w[ 0]); PACK64(&sub_block[ 8], &w[ 1]);
|
||||
PACK64(&sub_block[ 16], &w[ 2]); PACK64(&sub_block[ 24], &w[ 3]);
|
||||
PACK64(&sub_block[ 32], &w[ 4]); PACK64(&sub_block[ 40], &w[ 5]);
|
||||
PACK64(&sub_block[ 48], &w[ 6]); PACK64(&sub_block[ 56], &w[ 7]);
|
||||
PACK64(&sub_block[ 64], &w[ 8]); PACK64(&sub_block[ 72], &w[ 9]);
|
||||
PACK64(&sub_block[ 80], &w[10]); PACK64(&sub_block[ 88], &w[11]);
|
||||
PACK64(&sub_block[ 96], &w[12]); PACK64(&sub_block[104], &w[13]);
|
||||
PACK64(&sub_block[112], &w[14]); PACK64(&sub_block[120], &w[15]);
|
||||
|
||||
SHA512_SCR(16); SHA512_SCR(17); SHA512_SCR(18); SHA512_SCR(19);
|
||||
SHA512_SCR(20); SHA512_SCR(21); SHA512_SCR(22); SHA512_SCR(23);
|
||||
SHA512_SCR(24); SHA512_SCR(25); SHA512_SCR(26); SHA512_SCR(27);
|
||||
SHA512_SCR(28); SHA512_SCR(29); SHA512_SCR(30); SHA512_SCR(31);
|
||||
SHA512_SCR(32); SHA512_SCR(33); SHA512_SCR(34); SHA512_SCR(35);
|
||||
SHA512_SCR(36); SHA512_SCR(37); SHA512_SCR(38); SHA512_SCR(39);
|
||||
SHA512_SCR(40); SHA512_SCR(41); SHA512_SCR(42); SHA512_SCR(43);
|
||||
SHA512_SCR(44); SHA512_SCR(45); SHA512_SCR(46); SHA512_SCR(47);
|
||||
SHA512_SCR(48); SHA512_SCR(49); SHA512_SCR(50); SHA512_SCR(51);
|
||||
SHA512_SCR(52); SHA512_SCR(53); SHA512_SCR(54); SHA512_SCR(55);
|
||||
SHA512_SCR(56); SHA512_SCR(57); SHA512_SCR(58); SHA512_SCR(59);
|
||||
SHA512_SCR(60); SHA512_SCR(61); SHA512_SCR(62); SHA512_SCR(63);
|
||||
SHA512_SCR(64); SHA512_SCR(65); SHA512_SCR(66); SHA512_SCR(67);
|
||||
SHA512_SCR(68); SHA512_SCR(69); SHA512_SCR(70); SHA512_SCR(71);
|
||||
SHA512_SCR(72); SHA512_SCR(73); SHA512_SCR(74); SHA512_SCR(75);
|
||||
SHA512_SCR(76); SHA512_SCR(77); SHA512_SCR(78); SHA512_SCR(79);
|
||||
|
||||
wv[0] = ctx->h[0]; wv[1] = ctx->h[1];
|
||||
wv[2] = ctx->h[2]; wv[3] = ctx->h[3];
|
||||
wv[4] = ctx->h[4]; wv[5] = ctx->h[5];
|
||||
wv[6] = ctx->h[6]; wv[7] = ctx->h[7];
|
||||
|
||||
j = 0;
|
||||
|
||||
do {
|
||||
SHA512_EXP(0,1,2,3,4,5,6,7,j); j++;
|
||||
SHA512_EXP(7,0,1,2,3,4,5,6,j); j++;
|
||||
SHA512_EXP(6,7,0,1,2,3,4,5,j); j++;
|
||||
SHA512_EXP(5,6,7,0,1,2,3,4,j); j++;
|
||||
SHA512_EXP(4,5,6,7,0,1,2,3,j); j++;
|
||||
SHA512_EXP(3,4,5,6,7,0,1,2,j); j++;
|
||||
SHA512_EXP(2,3,4,5,6,7,0,1,j); j++;
|
||||
SHA512_EXP(1,2,3,4,5,6,7,0,j); j++;
|
||||
} while (j < 80);
|
||||
|
||||
ctx->h[0] += wv[0]; ctx->h[1] += wv[1];
|
||||
ctx->h[2] += wv[2]; ctx->h[3] += wv[3];
|
||||
ctx->h[4] += wv[4]; ctx->h[5] += wv[5];
|
||||
ctx->h[6] += wv[6]; ctx->h[7] += wv[7];
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
}
|
||||
}
|
||||
|
||||
void sha512(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest)
|
||||
{
|
||||
sha512_ctx ctx;
|
||||
|
||||
sha512_init(&ctx);
|
||||
sha512_update(&ctx, message, len);
|
||||
sha512_final(&ctx, digest);
|
||||
}
|
||||
|
||||
void sha512_init(sha512_ctx *ctx)
|
||||
{
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ctx->h[i] = sha512_h0[i];
|
||||
}
|
||||
#else
|
||||
ctx->h[0] = sha512_h0[0]; ctx->h[1] = sha512_h0[1];
|
||||
ctx->h[2] = sha512_h0[2]; ctx->h[3] = sha512_h0[3];
|
||||
ctx->h[4] = sha512_h0[4]; ctx->h[5] = sha512_h0[5];
|
||||
ctx->h[6] = sha512_h0[6]; ctx->h[7] = sha512_h0[7];
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
|
||||
ctx->len = 0;
|
||||
ctx->tot_len = 0;
|
||||
}
|
||||
|
||||
void sha512_update(sha512_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int new_len, rem_len, tmp_len;
|
||||
const unsigned char *shifted_message;
|
||||
|
||||
tmp_len = SHA512_BLOCK_SIZE - ctx->len;
|
||||
rem_len = len < tmp_len ? len : tmp_len;
|
||||
|
||||
memcpy(&ctx->block[ctx->len], message, rem_len);
|
||||
|
||||
if (ctx->len + len < SHA512_BLOCK_SIZE) {
|
||||
ctx->len += len;
|
||||
return;
|
||||
}
|
||||
|
||||
new_len = len - rem_len;
|
||||
block_nb = new_len / SHA512_BLOCK_SIZE;
|
||||
|
||||
shifted_message = message + rem_len;
|
||||
|
||||
sha512_transf(ctx, ctx->block, 1);
|
||||
sha512_transf(ctx, shifted_message, block_nb);
|
||||
|
||||
rem_len = new_len % SHA512_BLOCK_SIZE;
|
||||
|
||||
memcpy(ctx->block, &shifted_message[block_nb << 7],
|
||||
rem_len);
|
||||
|
||||
ctx->len = rem_len;
|
||||
ctx->tot_len += (block_nb + 1) << 7;
|
||||
}
|
||||
|
||||
void sha512_final(sha512_ctx *ctx, unsigned char *digest)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int pm_len;
|
||||
unsigned int len_b;
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
#endif
|
||||
|
||||
block_nb = 1 + ((SHA512_BLOCK_SIZE - 17)
|
||||
< (ctx->len % SHA512_BLOCK_SIZE));
|
||||
|
||||
len_b = (ctx->tot_len + ctx->len) << 3;
|
||||
pm_len = block_nb << 7;
|
||||
|
||||
memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
|
||||
ctx->block[ctx->len] = 0x80;
|
||||
UNPACK32(len_b, ctx->block + pm_len - 4);
|
||||
|
||||
sha512_transf(ctx, ctx->block, block_nb);
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
for (i = 0 ; i < 8; i++) {
|
||||
UNPACK64(ctx->h[i], &digest[i << 3]);
|
||||
}
|
||||
#else
|
||||
UNPACK64(ctx->h[0], &digest[ 0]);
|
||||
UNPACK64(ctx->h[1], &digest[ 8]);
|
||||
UNPACK64(ctx->h[2], &digest[16]);
|
||||
UNPACK64(ctx->h[3], &digest[24]);
|
||||
UNPACK64(ctx->h[4], &digest[32]);
|
||||
UNPACK64(ctx->h[5], &digest[40]);
|
||||
UNPACK64(ctx->h[6], &digest[48]);
|
||||
UNPACK64(ctx->h[7], &digest[56]);
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
}
|
||||
|
||||
/* SHA-384 functions */
|
||||
|
||||
void sha384(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest)
|
||||
{
|
||||
sha384_ctx ctx;
|
||||
|
||||
sha384_init(&ctx);
|
||||
sha384_update(&ctx, message, len);
|
||||
sha384_final(&ctx, digest);
|
||||
}
|
||||
|
||||
void sha384_init(sha384_ctx *ctx)
|
||||
{
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ctx->h[i] = sha384_h0[i];
|
||||
}
|
||||
#else
|
||||
ctx->h[0] = sha384_h0[0]; ctx->h[1] = sha384_h0[1];
|
||||
ctx->h[2] = sha384_h0[2]; ctx->h[3] = sha384_h0[3];
|
||||
ctx->h[4] = sha384_h0[4]; ctx->h[5] = sha384_h0[5];
|
||||
ctx->h[6] = sha384_h0[6]; ctx->h[7] = sha384_h0[7];
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
|
||||
ctx->len = 0;
|
||||
ctx->tot_len = 0;
|
||||
}
|
||||
|
||||
void sha384_update(sha384_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int new_len, rem_len, tmp_len;
|
||||
const unsigned char *shifted_message;
|
||||
|
||||
tmp_len = SHA384_BLOCK_SIZE - ctx->len;
|
||||
rem_len = len < tmp_len ? len : tmp_len;
|
||||
|
||||
memcpy(&ctx->block[ctx->len], message, rem_len);
|
||||
|
||||
if (ctx->len + len < SHA384_BLOCK_SIZE) {
|
||||
ctx->len += len;
|
||||
return;
|
||||
}
|
||||
|
||||
new_len = len - rem_len;
|
||||
block_nb = new_len / SHA384_BLOCK_SIZE;
|
||||
|
||||
shifted_message = message + rem_len;
|
||||
|
||||
sha512_transf(ctx, ctx->block, 1);
|
||||
sha512_transf(ctx, shifted_message, block_nb);
|
||||
|
||||
rem_len = new_len % SHA384_BLOCK_SIZE;
|
||||
|
||||
memcpy(ctx->block, &shifted_message[block_nb << 7],
|
||||
rem_len);
|
||||
|
||||
ctx->len = rem_len;
|
||||
ctx->tot_len += (block_nb + 1) << 7;
|
||||
}
|
||||
|
||||
void sha384_final(sha384_ctx *ctx, unsigned char *digest)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int pm_len;
|
||||
unsigned int len_b;
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
#endif
|
||||
|
||||
block_nb = (1 + ((SHA384_BLOCK_SIZE - 17)
|
||||
< (ctx->len % SHA384_BLOCK_SIZE)));
|
||||
|
||||
len_b = (ctx->tot_len + ctx->len) << 3;
|
||||
pm_len = block_nb << 7;
|
||||
|
||||
memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
|
||||
ctx->block[ctx->len] = 0x80;
|
||||
UNPACK32(len_b, ctx->block + pm_len - 4);
|
||||
|
||||
sha512_transf(ctx, ctx->block, block_nb);
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
for (i = 0 ; i < 6; i++) {
|
||||
UNPACK64(ctx->h[i], &digest[i << 3]);
|
||||
}
|
||||
#else
|
||||
UNPACK64(ctx->h[0], &digest[ 0]);
|
||||
UNPACK64(ctx->h[1], &digest[ 8]);
|
||||
UNPACK64(ctx->h[2], &digest[16]);
|
||||
UNPACK64(ctx->h[3], &digest[24]);
|
||||
UNPACK64(ctx->h[4], &digest[32]);
|
||||
UNPACK64(ctx->h[5], &digest[40]);
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
}
|
||||
|
||||
/* SHA-224 functions */
|
||||
|
||||
void sha224(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest)
|
||||
{
|
||||
sha224_ctx ctx;
|
||||
|
||||
sha224_init(&ctx);
|
||||
sha224_update(&ctx, message, len);
|
||||
sha224_final(&ctx, digest);
|
||||
}
|
||||
|
||||
void sha224_init(sha224_ctx *ctx)
|
||||
{
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
for (i = 0; i < 8; i++) {
|
||||
ctx->h[i] = sha224_h0[i];
|
||||
}
|
||||
#else
|
||||
ctx->h[0] = sha224_h0[0]; ctx->h[1] = sha224_h0[1];
|
||||
ctx->h[2] = sha224_h0[2]; ctx->h[3] = sha224_h0[3];
|
||||
ctx->h[4] = sha224_h0[4]; ctx->h[5] = sha224_h0[5];
|
||||
ctx->h[6] = sha224_h0[6]; ctx->h[7] = sha224_h0[7];
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
|
||||
ctx->len = 0;
|
||||
ctx->tot_len = 0;
|
||||
}
|
||||
|
||||
void sha224_update(sha224_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int new_len, rem_len, tmp_len;
|
||||
const unsigned char *shifted_message;
|
||||
|
||||
tmp_len = SHA224_BLOCK_SIZE - ctx->len;
|
||||
rem_len = len < tmp_len ? len : tmp_len;
|
||||
|
||||
memcpy(&ctx->block[ctx->len], message, rem_len);
|
||||
|
||||
if (ctx->len + len < SHA224_BLOCK_SIZE) {
|
||||
ctx->len += len;
|
||||
return;
|
||||
}
|
||||
|
||||
new_len = len - rem_len;
|
||||
block_nb = new_len / SHA224_BLOCK_SIZE;
|
||||
|
||||
shifted_message = message + rem_len;
|
||||
|
||||
sha256_transf(ctx, ctx->block, 1);
|
||||
sha256_transf(ctx, shifted_message, block_nb);
|
||||
|
||||
rem_len = new_len % SHA224_BLOCK_SIZE;
|
||||
|
||||
memcpy(ctx->block, &shifted_message[block_nb << 6],
|
||||
rem_len);
|
||||
|
||||
ctx->len = rem_len;
|
||||
ctx->tot_len += (block_nb + 1) << 6;
|
||||
}
|
||||
|
||||
void sha224_final(sha224_ctx *ctx, unsigned char *digest)
|
||||
{
|
||||
unsigned int block_nb;
|
||||
unsigned int pm_len;
|
||||
unsigned int len_b;
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
int i;
|
||||
#endif
|
||||
|
||||
block_nb = (1 + ((SHA224_BLOCK_SIZE - 9)
|
||||
< (ctx->len % SHA224_BLOCK_SIZE)));
|
||||
|
||||
len_b = (ctx->tot_len + ctx->len) << 3;
|
||||
pm_len = block_nb << 6;
|
||||
|
||||
memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
|
||||
ctx->block[ctx->len] = 0x80;
|
||||
UNPACK32(len_b, ctx->block + pm_len - 4);
|
||||
|
||||
sha256_transf(ctx, ctx->block, block_nb);
|
||||
|
||||
#ifndef UNROLL_LOOPS
|
||||
for (i = 0 ; i < 7; i++) {
|
||||
UNPACK32(ctx->h[i], &digest[i << 2]);
|
||||
}
|
||||
#else
|
||||
UNPACK32(ctx->h[0], &digest[ 0]);
|
||||
UNPACK32(ctx->h[1], &digest[ 4]);
|
||||
UNPACK32(ctx->h[2], &digest[ 8]);
|
||||
UNPACK32(ctx->h[3], &digest[12]);
|
||||
UNPACK32(ctx->h[4], &digest[16]);
|
||||
UNPACK32(ctx->h[5], &digest[20]);
|
||||
UNPACK32(ctx->h[6], &digest[24]);
|
||||
#endif /* !UNROLL_LOOPS */
|
||||
}
|
||||
|
||||
#ifdef TEST_VECTORS
|
||||
|
||||
/* FIPS 180-2 Validation tests */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void test(const char *vector, unsigned char *digest,
|
||||
unsigned int digest_size)
|
||||
{
|
||||
char output[2 * SHA512_DIGEST_SIZE + 1];
|
||||
int i;
|
||||
|
||||
output[2 * digest_size] = '\0';
|
||||
|
||||
for (i = 0; i < (int) digest_size ; i++) {
|
||||
sprintf(output + 2 * i, "%02x", digest[i]);
|
||||
}
|
||||
|
||||
printf("H: %s\n", output);
|
||||
if (strcmp(vector, output)) {
|
||||
fprintf(stderr, "Test failed.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static const char *vectors[4][3] =
|
||||
{ /* SHA-224 */
|
||||
{
|
||||
"23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7",
|
||||
"75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525",
|
||||
"20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67",
|
||||
},
|
||||
/* SHA-256 */
|
||||
{
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
|
||||
"248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1",
|
||||
"cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0",
|
||||
},
|
||||
/* SHA-384 */
|
||||
{
|
||||
"cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed"
|
||||
"8086072ba1e7cc2358baeca134c825a7",
|
||||
"09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712"
|
||||
"fcc7c71a557e2db966c3e9fa91746039",
|
||||
"9d0e1809716474cb086e834e310a4a1ced149e9c00f248527972cec5704c2a5b"
|
||||
"07b8b3dc38ecc4ebae97ddd87f3d8985",
|
||||
},
|
||||
/* SHA-512 */
|
||||
{
|
||||
"ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a"
|
||||
"2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f",
|
||||
"8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018"
|
||||
"501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909",
|
||||
"e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"
|
||||
"de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b"
|
||||
}
|
||||
};
|
||||
|
||||
static const char message1[] = "abc";
|
||||
static const char message2a[] = "abcdbcdecdefdefgefghfghighijhi"
|
||||
"jkijkljklmklmnlmnomnopnopq";
|
||||
static const char message2b[] = "abcdefghbcdefghicdefghijdefghijkefghij"
|
||||
"klfghijklmghijklmnhijklmnoijklmnopjklm"
|
||||
"nopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
||||
unsigned char *message3;
|
||||
unsigned int message3_len = 1000000;
|
||||
unsigned char digest[SHA512_DIGEST_SIZE];
|
||||
|
||||
message3 = malloc(message3_len);
|
||||
if (message3 == NULL) {
|
||||
fprintf(stderr, "Can't allocate memory\n");
|
||||
return -1;
|
||||
}
|
||||
memset(message3, 'a', message3_len);
|
||||
|
||||
printf("SHA-2 FIPS 180-2 Validation tests\n\n");
|
||||
printf("SHA-224 Test vectors\n");
|
||||
|
||||
sha224((const unsigned char *) message1, strlen(message1), digest);
|
||||
test(vectors[0][0], digest, SHA224_DIGEST_SIZE);
|
||||
sha224((const unsigned char *) message2a, strlen(message2a), digest);
|
||||
test(vectors[0][1], digest, SHA224_DIGEST_SIZE);
|
||||
sha224(message3, message3_len, digest);
|
||||
test(vectors[0][2], digest, SHA224_DIGEST_SIZE);
|
||||
printf("\n");
|
||||
|
||||
printf("SHA-256 Test vectors\n");
|
||||
|
||||
sha256((const unsigned char *) message1, strlen(message1), digest);
|
||||
test(vectors[1][0], digest, SHA256_DIGEST_SIZE);
|
||||
sha256((const unsigned char *) message2a, strlen(message2a), digest);
|
||||
test(vectors[1][1], digest, SHA256_DIGEST_SIZE);
|
||||
sha256(message3, message3_len, digest);
|
||||
test(vectors[1][2], digest, SHA256_DIGEST_SIZE);
|
||||
printf("\n");
|
||||
|
||||
printf("SHA-384 Test vectors\n");
|
||||
|
||||
sha384((const unsigned char *) message1, strlen(message1), digest);
|
||||
test(vectors[2][0], digest, SHA384_DIGEST_SIZE);
|
||||
sha384((const unsigned char *)message2b, strlen(message2b), digest);
|
||||
test(vectors[2][1], digest, SHA384_DIGEST_SIZE);
|
||||
sha384(message3, message3_len, digest);
|
||||
test(vectors[2][2], digest, SHA384_DIGEST_SIZE);
|
||||
printf("\n");
|
||||
|
||||
printf("SHA-512 Test vectors\n");
|
||||
|
||||
sha512((const unsigned char *) message1, strlen(message1), digest);
|
||||
test(vectors[3][0], digest, SHA512_DIGEST_SIZE);
|
||||
sha512((const unsigned char *) message2b, strlen(message2b), digest);
|
||||
test(vectors[3][1], digest, SHA512_DIGEST_SIZE);
|
||||
sha512(message3, message3_len, digest);
|
||||
test(vectors[3][2], digest, SHA512_DIGEST_SIZE);
|
||||
printf("\n");
|
||||
|
||||
printf("All tests passed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* TEST_VECTORS */
|
||||
|
||||
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* FIPS 180-2 SHA-224/256/384/512 implementation
|
||||
* Last update: 02/02/2007
|
||||
* Issue date: 04/30/2005
|
||||
*
|
||||
* Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the project nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef SHA2_H
|
||||
#define SHA2_H
|
||||
|
||||
#define SHA224_DIGEST_SIZE ( 224 / 8)
|
||||
#define SHA256_DIGEST_SIZE ( 256 / 8)
|
||||
#define SHA384_DIGEST_SIZE ( 384 / 8)
|
||||
#define SHA512_DIGEST_SIZE ( 512 / 8)
|
||||
|
||||
#define SHA256_BLOCK_SIZE ( 512 / 8)
|
||||
#define SHA512_BLOCK_SIZE (1024 / 8)
|
||||
#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
|
||||
#define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
|
||||
|
||||
#ifndef SHA2_TYPES
|
||||
#define SHA2_TYPES
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned long long uint64;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
unsigned int tot_len;
|
||||
unsigned int len;
|
||||
unsigned char block[2 * SHA256_BLOCK_SIZE];
|
||||
uint32 h[8];
|
||||
} sha256_ctx;
|
||||
|
||||
typedef struct {
|
||||
unsigned int tot_len;
|
||||
unsigned int len;
|
||||
unsigned char block[2 * SHA512_BLOCK_SIZE];
|
||||
uint64 h[8];
|
||||
} sha512_ctx;
|
||||
|
||||
typedef sha512_ctx sha384_ctx;
|
||||
typedef sha256_ctx sha224_ctx;
|
||||
|
||||
void sha224_init(sha224_ctx *ctx);
|
||||
void sha224_update(sha224_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len);
|
||||
void sha224_final(sha224_ctx *ctx, unsigned char *digest);
|
||||
void sha224(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest);
|
||||
|
||||
void sha256_init(sha256_ctx * ctx);
|
||||
void sha256_update(sha256_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len);
|
||||
void sha256_final(sha256_ctx *ctx, unsigned char *digest);
|
||||
void sha256(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest);
|
||||
|
||||
void sha384_init(sha384_ctx *ctx);
|
||||
void sha384_update(sha384_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len);
|
||||
void sha384_final(sha384_ctx *ctx, unsigned char *digest);
|
||||
void sha384(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest);
|
||||
|
||||
void sha512_init(sha512_ctx *ctx);
|
||||
void sha512_update(sha512_ctx *ctx, const unsigned char *message,
|
||||
unsigned int len);
|
||||
void sha512_final(sha512_ctx *ctx, unsigned char *digest);
|
||||
void sha512(const unsigned char *message, unsigned int len,
|
||||
unsigned char *digest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !SHA2_H */
|
||||
|
||||
@ -198,7 +198,7 @@ Return an approximate battery percentage remaining based on
|
||||
a normal CR2032 battery (2.8 - 2.2v)
|
||||
*/
|
||||
int jswrap_badge_getBatteryPercentage() {
|
||||
JsVarFloat v = jswrap_nrf_bluetooth_getBattery();
|
||||
JsVarFloat v = jswrap_ble_getBattery();
|
||||
int pc = (v-2.2)*100/0.6;
|
||||
if (pc>100) pc=100;
|
||||
if (pc<0) pc=0;
|
||||
|
||||
4
libs/js/AT.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
exports.connect=function(n){var m=!1,b="",g,d=0,l,e={},h={},k=[];n.on("data",function q(a){if(d){b&&(a=b+a,b="");if(a.length<=d){d-=a.length;l(a);0==d&&(l=void 0);return}l(a.substr(0,d));a=a.substr(d);d=0;l=void 0}b+=a;m&&console.log("] "+JSON.stringify(a));"\n"==b[0]&&(b=b.substr(1));if(e)for(var c in e)for(;b.substr(0,c.length)==c;)if(a=b,b=e[c](b),a==b)return;for(a=b.indexOf("\r");0<=a;){var f=b.substr(0,a),p=!1;if(0<f.length){for(c in h)f.substr(0,c.length)==c&&(h[c](f),p=!0);p||g&&
|
||||
g(f)}b=b.substr(a+1);if(p&&d)return q("");"\n"==b[0]&&(b=b.substr(1));if(b.length&&e)for(c in e)b.substr(0,c.length)==c&&(b=e[c](b));a=b.indexOf("\r")}});var f={debug:function(a){m=!1!==a;return{line:b,lineCallback:g,handlers:e,lineHandlers:h,waiting:k,dataCount:d}},cmd:function(a,b,c){if(g)m&&console.log("Queued "+JSON.stringify(a)),k.push([a,b,c]);else if(m&&console.log("["+JSON.stringify(a)),n.write(a),b){var d=setTimeout(function(){g=void 0;c&&c();void 0===g&&0<k.length&&f.cmd.apply(f,k.shift())},
|
||||
b),e=function(a){g=void 0;var b;c&&(b=c(a))?(g=e,c=b):clearTimeout(d);void 0===g&&0<k.length&&f.cmd.apply(f,k.shift())};g=e}},write:function(a){n.write(a)},cmdReg:function(a,b,c,d,e){f.registerLine(c,d);f.cmd(a,b,function(a){f.unregisterLine(c);e(a)})},registerLine:function(a,b){if(h[a])throw Error(a+" already registered");h[a]=b},unregisterLine:function(a){delete h[a]},register:function(a,b){if(e[a])throw Error(a+" already registered");e[a]=b},unregister:function(a){delete e[a]},isBusy:function(){return void 0!==
|
||||
g},getData:function(a,b){if(d)throw Error("Already grabbing data");d=a;l=b}};return f}
|
||||
4
libs/js/ATSMS.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
function c(a,e){var d=this;this.serial=a;this.at=require("AT").connect(a);this.at.registerLine('+CMTI: "SM",',function(a){d.emit("message",a.substr(12));return""})}function g(a){if(0!=(a.length&3))return a;for(var e="",d=0;d<a.length;d+=4){var b=parseInt(a.substr(d,4),16);if(isNaN(b))return a;e+=String.fromCharCode(b)}return e}c.prototype.init=function(a){var e=this.at;this.at.cmd("ATE0\r\n",3E3,function k(b){if("ATE0"==b)return k;"OK"!=b&&a("ATE0 ERROR "+b);e.cmd("AT+CMGF=1\r\n",1E3,
|
||||
function(b){a&&a("OK"==b?null:"CMGF ERROR "+b)})})};c.prototype.send=function(a,e,d){var b=this.at;b.register(">",function(){b.unregister(">");b.write(e+"\u001a\r");return""});b.cmd('AT+CMGS="'+a+'"\r\n',1E4,function f(a){b.unregister(">");if(a&&"+CMGS"==a.substr(0,5))return f;d&&d("OK"==a?null:"CMGS ERROR "+a)})};c.prototype.list=function(a,e){var d=[],b;this.at.cmd('AT+CMGL="'+a+'"\r\n',1E4,function f(a){if(void 0!==b&&void 0!==a)return b.text=g(a),b=void 0,f;if(a&&"+CMGL: "==a.substr(0,7)){try{var c=
|
||||
JSON.parse("["+a.substr(7)+"]");b={index:c[0],isRead:"REC READ"==c[1],oaddr:c[2],oname:c[3],time:c[4],text:""};d.push(b)}catch(m){}return f}e&&e("OK"==a?null:"CMGL ERROR "+a,d)})};c.prototype.get=function(a,e){var d;this.at.cmd("AT+CMGR="+a+"\r\n",1E4,function h(a){if("OK"==a)return e(null,d);if(void 0!==d&&void 0!==a&&"OK"!=a)return d.text=g(a),h;if(a&&"+CMGR: "==a.substr(0,7)){try{var c=JSON.parse("["+a.substr(7)+"]");d={isRead:"REC READ"==c[0],oaddr:c[1],oname:c[2],time:c[3],text:""}}catch(l){}return h}e&&
|
||||
e("OK"==a?null:"CMGR ERROR "+a,list)})};c.prototype["delete"]=function(a,c){"ALL"==a&&(a="1,4");this.at.cmd("AT+CMGD="+a+"\r\n",1E3,function(a){c&&c("OK"==a?null:"CMGD ERROR "+a)})};exports=c
|
||||
4
libs/js/BME280.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
function f(a,b,c){this.read=b;this.write=c;this.write(242,1);this.write(244,39);this.write(245,160);this.readCoefficients()}function d(a,b){var c=(a[b+1]<<8)+a[b];c&32768&&(c-=65536);return c}f.prototype.setPower=function(a){this.read(244,1)};f.prototype.readCoefficients=function(){var a=new Uint8Array(32);a.set(this.read(136,24),0);a.set(this.read(161,1),24);a.set(this.read(225,7),25);this.dT=[,a[1]<<8|a[0],d(a,2),d(a,4)];this.dP=[,a[7]<<8|a[6],d(a,8),d(a,10),d(a,12),d(a,14),d(a,16),
|
||||
d(a,18),d(a,20),d(a,22)];this.dH=[,a[24],d(a,25),a[27],a[28]<<4|15&a[29],a[30]<<4|a[29]>>4&15,a[31]]};f.prototype.readRawData=function(){var a=this.read(247,8);this.pres_raw=a[0]<<12|a[1]<<4|a[2]>>4;this.temp_raw=a[3]<<12|a[4]<<4|a[5]>>4;this.hum_raw=a[6]<<8|a[7]};f.prototype.calibration_T=function(a){var b,c=this.dT;b=(a/16384-c[1]/1024)*c[2];a=(a/131072-c[1]/8192)*(a/131072-c[1]/8192)*c[3];this.t_fine=b+a;return(b+a)/5120*100};f.prototype.calibration_P=function(a){var b,c,e=this.dP;b=this.t_fine/
|
||||
2-64E3;c=b*b*e[6]/32768;c+=b*e[5]*2;c=c/4+65536*e[4];b=(e[3]*b*b/524288+e[2]*b)/524288;b=(1+b/32768)*e[1];if(0===b)return 0;a=6250*(1048576-a-c/4096)/b;b=e[9]*a*a/2147483648;c=a*e[8]/32768;return a+=(b+c+e[7])/16};f.prototype.calibration_H=function(a){var b,c=this.dH;b=this.t_fine-76800;b=((a<<14)-(c[4]<<20)-c[5]*b+16384>>15)*((((b*c[6]>>10)*((b*c[3]>>11)+32768)>>10)+2097152)*c[2]+8192>>14);b-=((b>>15)*(b>>15)>>7)*c[1]>>4;b=Math.clip(b,0,419430400);return b>>12};f.prototype.getData=function(a){this.readRawData();
|
||||
return{temp:this.calibration_T(this.temp_raw)/100,pressure:this.calibration_P(this.pres_raw)/100,humidity:this.calibration_H(this.hum_raw)/1024}};exports.connect=function(a,b){return new f(b,function(b,e){a.writeTo(118,b);return a.readFrom(118,e)},function(b,e){a.writeTo(118,[b,e])})};exports.connectSPI=function(a,b,c){return new f(c,function(c,d){new Uint8Array(d+1);return a.send([c|128,new Uint8Array(d)],b).slice(1)},function(c,d){a.write(c&127,d,b)})}
|
||||
2
libs/js/GPS.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
exports.connect=function(f,e){var b={line:""};if(e)b.on("line",function(a){var b;if(b="GGA"==a.substr(3,3)){b=a.length;for(var c=0,d=1;d<b-3;d++)c^=a.charCodeAt(d);b=parseInt(a.substr(b-2),16)===c}b&&(a=a.split(","),b=a[2].indexOf("."),c=a[4].indexOf("."),e({time:a[1].substr(0,2)+":"+a[1].substr(2,2)+":"+a[1].substr(4,2),lat:(parseInt(a[2].substr(0,b-2),10)+parseFloat(a[2].substr(b-2))/60)*("S"==a[3]?-1:1),lon:(parseInt(a[4].substr(0,c-2),10)+parseFloat(a[4].substr(c-2))/60)*("W"==a[5]?
|
||||
-1:1),fix:parseInt(a[6],10),satellites:parseInt(a[7],10),altitude:parseFloat(a[9])}))});f.on("data",function(a){b.line+=a;for(a=b.line.indexOf("\n");0<=a;)b.emit("line",b.line.substr(0,a-1)),b.line=b.line.substr(a+1),a=b.line.indexOf("\n");80<b.line.length&&(b.line=b.line.substr(-80))});return b}
|
||||
2
libs/js/LIS2MDL.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
function b(c,e,d){this.r=e;this.w=d;if(64!=this.r(a.WHO_AM_I,1)[0])throw Error("WHO_AM_I incorrect");this.w(a.CFG_A,128);this.w(a.CFG_B,1);this.w(a.CFG_C,17)}var a={WHO_AM_I:79,OUTX_L:104,CFG_A:96,CFG_B:97,CFG_C:98};b.prototype.off=function(){this.w(a.CFG_A,3)};b.prototype.read=function(){var c=new DataView(this.r(a.OUTX_L,6).buffer);return{x:c.getInt16(0,1),y:c.getInt16(2,1),z:c.getInt16(4,1)}};exports.LIS2MDL=b;exports.connectI2C=function(c,a){var d=a&&a.addr||30;return new b(a,function(a,
|
||||
b){c.writeTo(d,a);return c.readFrom(d,b)},function(a,b){c.writeTo(d,[a,b])})}
|
||||
2
libs/js/LIS3DH.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
function b(c,e,d){this.r=e;this.w=d;if(51!=this.r(a.WHO_AM_I,1)[0])throw Error("WHO_AM_I incorrect");this.w(a.CTRL1,39);this.w(a.CTRL4,136)}var a={WHO_AM_I:15,OUTX_L:40,CTRL1:32,CTRL3:34,CTRL4:35,TEMPCFG:31};b.prototype.off=function(){this.w(a.CTRL1,0)};b.prototype.read=function(){var c=new DataView(this.r(a.OUTX_L,6).buffer);return{x:c.getInt16(0,1)/16384,y:c.getInt16(2,1)/16384,z:c.getInt16(4,1)/16384}};exports.LIS3DH=b;exports.connectI2C=function(c,a){var d=a&&a.addr||25;return new b(a,
|
||||
function(a,b){c.writeTo(d,a|128);return c.readFrom(d,b)},function(a,b){c.writeTo(d,[a,b])})}
|
||||
4
libs/js/MPU9250.min.js
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
function c(a,b,d,e,c){this.r=a;this.w=b;this.rmag=d;this.wmag=e;this.Gscale=this.Ascale=0;this.gyrosensitivity=131;this.accelsensitivity=16384;this.samplerate=200}c.prototype.calibrateMPU9250=function(){return new Promise(function(a){a("calibrateMPU9250 not working at the moment")})};c.prototype.initMPU9250=function(){if(113!=this.r(117,1)[0])throw"MPU9250 WHO_AM_I check failed";var a=this;return(new Promise(function(b){a.w(107,0);setTimeout(b,100)})).then(function(){a.w(107,1);return new Promise(function(a){setTimeout(a,
|
||||
200)})}).then(function(){a.w(26,3);a.w(25,Math.clip(Math.round(1E3/a.samplerate)-1,0,255));var b=a.r(27,1)[0];b=b&-27|a.Gscale<<3;a.w(27,b);b=a.r(28,1)[0];b=b&-25|a.Ascale<<3;a.w(28,b);b=a.r(29,1)[0];a.w(29,b&-16|3);a.w(55,34);a.w(56,1);a.wmag(10,18);return new Promise(function(a){setTimeout(a,100)})})};c.prototype.dataReady=function(){return this.r(58,1)&1};c.prototype.readAccel=function(){var a=new DataView((new Uint8Array(this.r(59,6))).buffer);return{x:a.getInt16(0,0)/this.accelsensitivity,y:a.getInt16(2,
|
||||
0)/this.accelsensitivity,z:a.getInt16(4,0)/this.accelsensitivity}};c.prototype.readGyro=function(){var a=new DataView((new Uint8Array(this.r(67,6))).buffer);return{x:a.getInt16(0,0)/this.gyrosensitivity,y:a.getInt16(2,0)/this.gyrosensitivity,z:a.getInt16(4,0)/this.gyrosensitivity}};c.prototype.readMag=function(){var a=new DataView((new Uint8Array(this.rmag(3,7))).buffer),b=49120/32760;return{x:a.getInt16(0,1)*b,y:a.getInt16(2,1)*b,z:a.getInt16(4,1)*b}};c.prototype.read=function(){return{accel:this.readAccel(),
|
||||
gyro:this.readGyro(),mag:this.readMag(),"new":this.dataReady()}};exports.connectI2C=function(a,b){return new c(function(b,c){a.writeTo(104,b);return a.readFrom(104,c)},function(b,c){a.writeTo(104,b,c)},function(b,c){a.writeTo(12,b);return a.readFrom(12,c)},function(b,c){a.writeTo(12,b,c)},b)}
|
||||
2
libs/js/OPT3001.min.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
function a(e,a,d){this.r=a;this.w=d;if(21577!=this.r(b.MANUFACTUREID))throw Error("Unexpected Manufacturer ID");if(12289!=this.r(b.DEVICEID))throw Error("Unexpected Device ID");this.on()}var b={RESULT:0,CONFIG:1,LOWLIMIT:2,HIGHLIMIT:3,MANUFACTUREID:126,DEVICEID:127};a.prototype.on=function(){this.w(b.CONFIG,52240)};a.prototype.off=function(){this.w(b.CONFIG,51216)};a.prototype.read=function(){var a=this.r(b.RESULT);return.01*((a&4095)<<(a>>12))};exports.OPT3001=a;exports.connectI2C=function(b,
|
||||
c){var d=c&&c.addr||68;return new a(c,function(a){b.writeTo(d,a);a=b.readFrom(d,2);return a[1]|a[0]<<8},function(a,c){b.writeTo(d,[a,c>>8,c])})}
|
||||
6
libs/js/QuectelBG96.min.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
function l(){}function h(a,b){return new Promise(function(c,f){var m="";d.cmd(a+"\r\n",b||1E3,function p(b){if(void 0===b||"ERROR"==b)f(a+": "+b?b:"TIMEOUT");else if("OK"==b)c(m);else return m+=(m?"\n":"")+b,p})})}var d,g=[],e=" ".split(" "),k=!1,q={create:function(a,b){var c=0;if(void 0===a)return l("Server not implemented"),-1;for(;void 0!==g[c];)c++;if(6<=c)throw Error("No free sockets.");g[c]="Wait";e[c]="";k=!0;d.cmd("AT+QIOPEN=1,"+c+',"TCP",'+JSON.stringify(a)+","+b+",0,1\r\n",
|
||||
1E4,function(a){"OK"!=a&&(g[c]=void 0,k=!1)});return c},close:function(a){void 0!==g[a]&&(e[a]="",d.cmd("AT+QICLOSE="+a+"\r\n",1E3,function(){g[a]=void 0}))},accept:function(a){return-1},recv:function(a,b){if(e[a]){if(e[a].length>b){var c=e[a].substr(0,b);e[a]=e[a].substr(b)}else c=e[a],e[a]="";return c}return g[a]?"":-1},send:function(a,b){if(k||d.isBusy()||"Wait"==g[a])return 0;if(!g[a])return-1;k=!0;d.cmd("AT+QISEND="+a+","+b.length+"\r\n",1E4,function m(f){l("AT+QISEND response "+JSON.stringify(f));
|
||||
if("OK"==f)return d.register("> ",function(a){d.unregister("> ");d.write(b);return a.substr(2)}),m;"SEND OK"==f?k=!1:(d.unregister("> "),g[a]=null)});return b.length}},n={debug:function(a){l=a||void 0===a?function(a){print("[BG96]",a)}:function(){};return{socks:g,sockData:e,busy:k}},getVersion:function(a){h("AT+GMR").then(function(b){a(null,b)})["catch"](function(b){a(b)})},getIP:function(a){var b;d.cmd("AT+QISTATE=0,1\r\n",1E3,function(c){"OK"==c?a(null,b):c.startsWith("+QISTATE")?b=c.split(",")[2]:
|
||||
a(null,c)})}};exports.connect=function(a,b,c){b=b||{};a.removeAllListeners();n.at=d=require("AT").connect(a);require("NetworkJS").create(q);d.register('+QIURC: "recv"',function(a){var b=a.indexOf("\r\n");if(0>b)return a;var f=a.split(",");a=a.substr(b+2);e[0|f[1]]+=a;l(f);d.getData((0|f[2])-a.length,function(a){e[0|f[1]]+=a});return""});d.registerLine('+QIURC: "closed"',function(a){g[0|a.substr(17)]=null;k=!1});d.registerLine("+QIOPEN: ",function(a){a=a.substr(9).split(",");g[0|a[0]]=0==a[1]?!0:void 0;
|
||||
k=!1});d.registerLine("+CME ERROR",function(a){console.log(a)});h("ATE0").then(function(){return h("AT+CEREG=2")}).then(function(){return new Promise(function(a,c){var f=60,e=setInterval(function(){d.cmd(b.lte?"AT+CEREG?\r":"AT+CREG?\r",500,function(b){b=b.split(",")[1];if(1==b||5==b)clearInterval(e),a()});0>=f--&&(clearInterval(e),c("Timeout while registering."))},1E3)})}).then(function(a){return h("AT+CGATT=1",1E4)}).then(function(){return h("AT+CGREG?")}).then(function(a){var b=a.split(",")[1];
|
||||
if(2==b)throw Error("GPRS still connecting, "+a);if(1!=b&&5!=b)throw Error("GPRS not registered, "+a);return h("AT+COPS?")}).then(function(a){var c=a.split(",")[2];if(!c)throw Error("No Operator, "+a);l("Operator "+c);return h("AT+QICSGP=1,1,"+JSON.stringify(b.apn||"")+","+JSON.stringify(b.username||"")+","+JSON.stringify(b.password||""),6E4)}).then(function(){return h("AT+QIACT=1",6E4)}).then(function(){c&&c(null)})["catch"](function(a){c&&c(a)});return n}
|
||||
6
libs/js/QuectelM35.min.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
function g(){}function p(a){var b=a.substring(10).split(",");g(b);d.getData(0|b[1],function(a){e[0|b[0]]+=a})}function q(a){g(a);var b=a[0];a=a.substr(3);"CONNECT OK"==a?c[b]=!0:"CONNECT FAIL"==a?c[b]=void 0:"CLOSED"==a?c[b]=void 0:"SEND OK"!=a&&"SEND FAIL"==a&&(c[b]=void 0);k=!1;return""}function h(a,b){return new Promise(function(c,f){var l="";d.cmd(a+"\r\n",b||1E3,function r(b){if(void 0===b||"ERROR"==b)f(a+": "+b?b:"TIMEOUT");else if("OK"==b)c(l);else return l+=(l?"\n":"")+b,r})})}
|
||||
var d,c=[],e=" ".split(" "),k=!1,t={create:function(a,b){function m(a){d.cmd("AT+QIOPEN="+f+',"TCP",'+JSON.stringify(a)+","+b+"\r\n",1E4,function(a){"OK"!=a&&(c[f]=void 0,k=!1)})}var f=0;if(void 0===a)return g("Server not implemented"),-1;for(;void 0!==c[f];)f++;if(6<=f)throw Error("No free sockets.");c[f]="Wait";e[f]="";k=!0;a.match(/\d+.\d+.\d+.\d+/)?m(a):(g("Lookup host "+a),d.cmd("AT+QIDNSGIP="+JSON.stringify(a)+"\r\n",1E4,function(a){if("OK"==a)return function(a){m(a)};c[f]=void 0;k=!1;g("Host not found")}));
|
||||
return f},close:function(a){c[a]&&d.cmd("AT+QICLOSE="+a+"\r\n",1E3,function(){c[a]=void 0})},accept:function(a){return-1},recv:function(a,b){if(e[a]){if(e[a].length>b){var d=e[a].substr(0,b);e[a]=e[a].substr(b)}else d=e[a],e[a]="";return d}return c[a]?"":-1},send:function(a,b){if(k||d.isBusy()||"Wait"==c[a])return 0;if(!c[a])return-1;k=!0;d.write("AT+QISEND="+a+","+b.length+"\r\n");setTimeout(function(){d.write(b)},1E3);return b.length}},n={debug:function(a){g=a||void 0===a?function(a){print("[M35]",
|
||||
a)}:function(){};return{socks:c,sockData:e}},getVersion:function(a){h("AT+GMR").then(function(b){a(null,b)})["catch"](function(b){a(b)})},getIP:function(a){d.cmd("AT+QILOCIP\r\n",1E3,function(b){"ERROR"==b?a(b):a(null,b)})}};exports.connect=function(a,b,c){a.removeAllListeners();n.at=d=require("AT").connect(a);require("NetworkJS").create(t);d.registerLine("+RECEIVE",p);for(a=0;6>a;a++)d.registerLine(a+", ",q);d.registerLine("+CME ERROR",function(a){console.log(a)});h("ATE0").then(function(){return h("AT+CREG?")}).then(function(a){var b=
|
||||
a.split(",")[1];if(1!=b&&5!=b)throw Error("GSM not registered, "+a);g("Forcing GPRS connect");return h("AT+CGATT=1",1E4)}).then(function(){return h("AT+CGREG?")}).then(function(a){var b=a.split(",")[1];if(2==b)throw Error("GPRS still connecting, "+a);if(1!=b&&5!=b)throw Error("GPRS not registered, "+a);return h("AT+COPS?")}).then(function(a){var b=a.split(",")[2];if(!b)throw Error("No Operator, "+a);g("Operator "+b);return h("AT+QIMUX=1")}).then(function(){return h("AT+QIPROMPT=0")}).then(function(){c&&
|
||||
c(null)})["catch"](function(a){c&&c(a)});return n}
|
||||
24
libs/js/UG96.min.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
function k(a){console.log(a)}function b(a){B&&console.log(a)}function v(a,e,f,h){p?(b("Opening is not yet possible, busy state on socket "+a),5>h?setTimeout(function(){k("opening later...");v(a,e,f,h+1)},500):(b("Force the closure of socket "+a),g[a]="tobeclosed")):c.isBusy()?(b("Opening is not yet possible, AT busy state on socket "+a),5>h?setTimeout(function(){k("opening later...");v(a,e,f,h+1)},500):(b("Force the closure of socket "+a),g[a]="tobeclosed")):(b("AT+QIOPEN=1,"+a+',"TCP",'+
|
||||
JSON.stringify(e)+","+f+",0,1"),c.cmd("AT+QIOPEN=1,"+a+',"TCP",'+JSON.stringify(e)+","+f+",0,1\r\n",15E3,function d(c){if("OK"==c)return d;c=="+QIOPEN: "+a+",0"?(b(c),b("AT+QIOPEN completed with socket: "+a),g[a]=!0):c=="+QIOPEN: "+a+",565"?(b("AT+QIOPEN failure DNS parse failed..."),5>h?setTimeout(function(){k("repeat opening the socket ...");v(a,e,f,h+1)},1E3):(b("Force the closure of socket "+a),g[a]="tobeclosed")):c=="+QIOPEN: "+a+",566"?(b("AT+QIOPEN failure could not connect socket ..."),5>
|
||||
h?setTimeout(function(){k("repeat opening the socket ...");v(a,e,f,h+1)},3E3):(b("Force the closure of socket "+a),g[a]="tobeclosed")):(c=="+QIOPEN: "+a+",563"?b("AT+QIOPEN socket identity has been used..., socket is:"+a):b("AT+QIOPEN failed on socket:"+a),g[a]="tobeclosed");return""}))}function q(a,e){g[a]?0<m[a].length&&5>e?(k("socket "+a+" is emptying..."),setTimeout(function(){k("closing later...");q(a,e+1)},500)):p?(b("at register currenly programmed"),5>e?setTimeout(function(){k("closing later...");
|
||||
q(a,e+1)},500):(b("several busy situation on socket "+a),g[a]=void 0)):c.isBusy()?(b("AT busy"),5>e?setTimeout(function(){k("closing again...");q(a,e+1)},500):(b("several AT busy situation on socket "+a),g[a]=void 0)):(b("sending AT+QICLOSE for socket "+a),c.cmd("AT+QICLOSE="+a+"\r\n",2E3,function G(c){if(void 0===c)return 5>e?setTimeout(function(){k("closing again...");q(a,e+1)},500):(b("cannot properly close socket "+a),g[a]=void 0),"";if("OK"==c)return b("socket "+a+" is properly closed"),g[a]=
|
||||
void 0,"";b("socket "+a+" is not yet closed");return G})):b("socket already closed")}function C(a){var e=a.indexOf("\r\n");if(0>e)return a;var b=a.substring(15,e).split(",");b[1]|=0;var h=a.length-(e+2);if(h>=b[1])return 1==g[b[0]]&&(m[b[0]]+=a.substr(e+2,b[1])),a.substr(e+b[1]+3);m[b[0]]+=a.substr(e+2,h);c.getData(b[1]-h,function(a){m[b[0]]+=a});return""}function H(a){b("closehandler:"+a);var e=a.indexOf("\r\n");if(0>e&&(b("not enough data "+a),e=a.indexOf("\r"),0>e))return b("definitively not enough data "+
|
||||
a),a;a=a.substring(0,e).split(",");a[1]|=0;q(a[1],0);return""}function I(a){b("pdpdeacthandler:"+a);c.cmd("AT+QIDEACT=1\r\n",1E3,function(a){b(a);for(a=0;12>a;a++)g[a]=void 0,m[a]=""});return""}function J(a){b("QindHandler in: "+a);var e=a.indexOf("\r\n"),c=a.substr(e,a.length);k(a.substr(e,a.length));return c}function K(a){b("QusimHandler in: "+a);var e=a.indexOf("\r\n"),c=a.substr(e,a.length);k(a.substr(e,a.length));return c}function L(a){b("CfunHandler in: "+a);var e=a.indexOf("\r\n"),c=a.substr(e,
|
||||
a.length);k(a.substr(e,a.length));return c}function M(a){b("RdyHandler in: "+a);var c=a.indexOf("\r\n"),f=a.substr(c,a.length);k(a.substr(c,a.length));return f}function N(a){b("PowerDownHandler in: "+a);k("Modem is entering in power down");digitalWrite(w,y);return""}var c,p=!1,g=[],m=" ".split(" "),r,z,w,y,D=!1,t="",A=!1,B=!1,F,u=0,n=0,O={create:function(a,e){var f=0;if(void 0===a)return b("WARNING: this has not been fully ported for UGxx"),f=12,g[f]="Wait",m[f]="",c.cmd("AT+CIPSERVER=1,"+
|
||||
e+"\r\n",1E4,function(a){if("OK"==a)g[f]=!0;else throw g[f]=void 0,Error("CIPSERVER failed");}),12;for(;void 0!==g[f];)f++;12<=f&&(b("WORKAROUND closing the socket: "+f),f--,q(f,0));g[f]="Wait";m[f]="";443==e?(b("delaying the TLS socket opening"),setTimeout(function(){v(f,a,e,0)},3E3)):v(f,a,e,0);b("(create) sckt "+f+" state = "+g[f]);return f},close:function(a){b("(local) Closing of the socket: "+a);q(a,0)},accept:function(a){b("Accept Socket "+a);for(a=0;12>a;a++)if(m[a]&&void 0===g[a])return g[a]=
|
||||
!0,a;return-1},recv:function(a,b){if(c.isBusy()||"Wait"==g[a])return"";if(m[a]){if(m[a].length>b){var e=m[a].substr(0,b);m[a]=m[a].substr(b)}else e=m[a],m[a]="";return e}return g[a]&&"tobeclosed"!=g[a]?"":-1},send:function(a,e){if(p||c.isBusy()||"Wait"==g[a])return 0;if("tobeclosed"==g[a]||!g[a])return-1;if(1460<e.length)return b("data too big"),-1;p=!0;n=setTimeout(function(){b("Abort waiting modem response (sending data) on socket "+a);p=!1;n=0;c.unregisterLine("SEND OK");c.unregisterLine("SEND FAIL");
|
||||
c.unregisterLine("ERROR");g[a]="tobeclosed"},6E3);u=setTimeout(function(){b("Abort waiting prompt (for sending data) on socket "+a);p=!1;u=0;n&&(clearTimeout(n),n=0,c.unregisterLine("SEND OK"),c.unregisterLine("SEND FAIL"),c.unregisterLine("ERROR"));c.unregister(">");g[a]="tobeclosed"},5E3);c.register(">",function(){b("Prompt coming, sending data ...");c.unregister(">");clearTimeout(u);u=0;b("writing data amount of "+e.length);c.write(e);return""});c.registerLine("SEND OK",function(){b("UGxx - SEND OK");
|
||||
c.unregisterLine("SEND OK");c.unregisterLine("SEND FAIL");c.unregisterLine("ERROR");clearTimeout(n);n=0;p=!1;return""});c.registerLine("SEND FAIL",function(a){b("UGxx - SEND FAIL");c.unregisterLine("SEND OK");c.unregisterLine("SEND FAIL");c.unregisterLine("ERROR");clearTimeout(n);n=0;p=!1;g[a]="tobeclosed";return""});c.registerLine("ERROR",function(a){b("UGxx - ERROR communication");u&&(c.unregister(">"),clearTimeout(u),u=0);c.unregisterLine("SEND OK");c.unregisterLine("SEND FAIL");c.unregisterLine("ERROR");
|
||||
clearTimeout(n);n=0;p=!1;g[a]="tobeclosed";return""});b("AT+QISEND="+a+","+e.length);c.write("AT+QISEND="+a+","+e.length+"\r\n");b("(send) sckt "+a+" state = "+g[a]);b("send "+e.length);return e.length}},x={receiveHandler:C,debug:function(a,b){B=void 0===a?!1:a;(void 0===b?0:b)&&c.debug();return{socks:g,sockData:m}},init:function(a){var e=0,f=0,h=0,g=!1,l=function(d){switch(h){case 0:b("debug AT_SYNCHRO :"+d);if("AT"===d)return l;"OK"===d?(k("Synchronisation with module passed"),h=1,c.cmd("ATV1\r\n",
|
||||
1E3,l)):(h=0,e++,b("AT sync failed: "+d),10>=e?setTimeout(function(){c.cmd("AT\r\n",1E3,l)},500):(b("No OK return after 10 times"),b("Check the module is power on"),a("Error in AT sync: "+d)));break;case 1:b("debug AT_RSP_FORMAT :"+d);if("OK"===d)h=2,c.cmd("ATE0\r\n",1E3,l);else{if("ATV1"===d)return l;d&&a("Error in ATV1: "+d)}void 0===d&&(b("Cannot set TA response format"),a("ATV1 time-out !!!"));break;case 2:b("debug AT_ECHO_OFF :"+d);if("IIIIATE0"===d||d==="IIII"+String.fromCharCode(255)+"ATE0"||
|
||||
"ATE0"===d)return l;"OK"===d?(b("ATE0 passed: "+d),D?(h=11,c.cmd("AT+IFC=2,2\r\n",2E3,l)):(h=3,c.cmd("AT+CPIN?\r\n",5E3,l))):"atE0"===d?(b("UGxx returns "+d),h=3,c.cmd("AT+CPIN?\r\n",5E3,l)):d&&a("Error in ATE0: "+d);void 0===d&&(b("ATE0 time-out !!!"),h=3,c.cmd("AT+CPIN?\r\n",5E3,l));break;case 11:b("debug AT_HW_FLOW_CONTROL :"+d);"OK"===d?b("HW flow control establismnent succeeded"):a("HW flow control establismnent failed");h=3;c.cmd("AT+CPIN?\r\n",5E3,l);break;case 3:b("debug AT_CPIN :"+d);if("+CPIN: READY"===
|
||||
d)return l;"OK"===d?(h=4,c.cmd("AT+QCCID\r\n",2E3,l)):d&&a("Error in CPIN: "+d);void 0===d&&(b("SIM cannot be read, SIM is either protected, blocked or not accessible"),a("AT+CPIN time-out !!!"));break;case 4:b("debug AT_SHOW_SIM_ID :"+d);if(d&&"+QCCID:"==d.substr(0,7))return b("SIM ID :"+d),F=d.substring(8,d.length-1),l;"OK"===d?(h=5,c.cmd("AT+CFUN=1\r\n",15E3,l)):d&&a("Error in QCCID: "+d);void 0===d&&a("AT+QCCID time-out !!!");break;case 5:b("debug AT_RADIO_ON :"+d);"OK"===d?(h=6,c.cmd("AT+CSQ\r\n",
|
||||
2E3,l)):d&&a("Error in CFUN: "+d);void 0===d&&a("AT+CFUN time-out !!!");break;case 6:b("debug AT_QUERY_SIGNAL_QUALITY :"+d);if(d&&"+CSQ:"==d.substr(0,5))return d&&"+CSQ: 99,99"==d.substr(0,11)?(b("Signal not known or not detectable yet"),g=!1):(g=!0,d=d.substring(6,d.length).split(","),d[0]|=0,k("quality_level_dbm = "+(-113+2*d[0])+"dBm")),l;"OK"===d?g?(h=7,b("PS attachment is starting. It may take until a minute, please wait ... "),setTimeout(function(){c.cmd("AT+CGATT=1\r\n",75E3,l)},5E3)):setTimeout(function(){c.cmd("AT+CSQ\r\n",
|
||||
2E3,l)},1E3):d&&a("Error in QCCID: "+d);void 0===d&&a("AT+CSQ time-out !!!");break;case 7:b("debug AT_PS_ATTACMENT :"+d);"OK"===d?(k("PS attachment succeeded"),h=10,c.cmd("AT+COPS?\r\n",2E4,l)):d&&(f+=1,b("Error in CGATT: "+d+" - retry: "+f),1==f?(b("Trying an automatic registration first. It may take until 3 minutes, please wait ..."),h=8,setTimeout(function(){c.cmd("AT+COPS=0\r\n",18E4,l)},2E3)):4>f?(b("Retrying CGATT with retry "+f),h=7,b("PS attacment is attempting again. It may take until a minute, please wait ... "),
|
||||
setTimeout(function(){c.cmd("AT+CGATT=1\r\n",75E3,l)},2E3*f)):a("Unrecoverable Error, PS attachment failed: "+d));break;case 8:b("COPS returns: "+d);h=9;setTimeout(function(){c.cmd("AT+COPS?\r\n",1E4,l)},5E3);break;case 9:b(d+" - Now retrying PS attachment");h=7;setTimeout(function(){c.cmd("AT+CGATT=1\r\n",3E4,l)},3E4);break;case 10:b("debug AT_CURRENT_OPERATOR :"+d);if("OK"===d)a(null);else{if(d&&"+COPS:"==d.substr(0,6))return k("currently selected operator :"+d),l;d&&a("Error in COPS? "+d)}void 0===
|
||||
d&&a("AT+COPS? time-out !!!")}};setTimeout(function(){c.cmd("AT\r\n",1E3,l)},500)},reset:function(a){function c(a){digitalWrite(r,z);setTimeout(function(){digitalWrite(r,!z);setTimeout(function(){x.init(a)},6E3)},200)}function f(a){digitalWrite(w,y);setTimeout(function(){digitalWrite(w,!y);setTimeout(function(){r?c(a):x.init(a)},5E3)},200)}for(var h=0;12>h;h++)g[h]=void 0,m[h]="";if(void 0===r&&void 0===w)return x.init(a);b("Here we go trhough reset sequence");r&&digitalWrite(r,!z);w?f(a):c(a);k("Cellular module initialization started, please wait ...")},
|
||||
getVersion:function(a){c.cmd("AT+GMR\r\n",1E3,function(b){a(null,b)})},connect:function(a,e,f,h){var g=0,l=function(a){switch(g){case 0:b("connect callback after PDP context configuration");"OK"===a?(g=1,b("PDP context successfully configured"),c.cmd("AT+QIACT=1\r\n",3E4,l)):a&&h("Error in "+g+": "+a);void 0===a&&b("PDP context activation failed, timeout...");break;case 1:b("connect callback after PDP context activation"),"OK"===a?(k("PDP context successfully activated"),h(null)):a?h("Error in "+
|
||||
g+": "+a):h(null)}};b("in the connect function: AT+QICSGP stage");c.cmd('AT+QICSGP=1,1,"'+a+'", "'+e+'", "'+f+'"\r\n',3E4,l)},initflowctrl:function(a){D=void 0===a?!1:a},getIP:function(a){var e="",f=function(c){b("AT+CGPADDR callback: "+c);if(void 0===c)b("timeout : any IP address allocated ..."),a(null,e);else if("OK"===c)a(null,e),k("IP address allocated, modem is ready to use");else return e+=c,b(c),f};b("getIP is AT+CGPADDR");c.cmd("AT+CGPADDR=1\r\n",3E4,f)},geoLocGet:function(a){k("Getting geolocalization data");
|
||||
a(t)},geoLocStart:function(a){k("Starting GeoLocalization");1E4>a&&k("unpredictive behaviour with period not greater than 10 s !");A=!0;var e=function(f){if(void 0===f)b("GeoLocalization timeout"),t="";else if("OK"===f)k("GeoLocalization acquisition done : "+t);else{if(f&&"+QCELLLOC:"==f.substr(0,10)){var g=f.length,m=f.indexOf(" ");t=f.substring(1+m,g);b(t);return e}t="";k("Geolocalization error : "+f)}A&&setTimeout(function(){c.cmd("AT+QCELLLOC=1\r\n",2E3,e)},a)};c.cmd("AT+QCELLLOC=1\r\n",2E3,e)},
|
||||
geoLocStop:function(){k("Stopping GeoLocalization");A=!1;t=""},turnOff:function(){k("Turning Off the modem");c.cmd("AT+QPOWD=1\r\n",2E3,function(a){"OK"===a?k("Please wait, disconnecting and saving data. It may last until 60 s"):k("Turn off error : "+a)})},getCCID:function(){return F}};resetOptions={rst:void 0,pwrkey:void 0,rst_active_level:1,pwrkey_active_level:1};exports.connect=function(a,b,f){b=b||{};r=b.rst||void 0;w=b.pwrkey||void 0;z=b.rst_active_level||0;y=b.pwrkey_active_level||0;x.at=c=
|
||||
require("AT").connect(a);require("NetworkJS").create(O);c.register('+QIURC: "recv"',C);c.register('+QIURC: "closed"',H);c.register('+QIURC: "pdpdeact"',I);c.register("+QIND:",J);c.register("+QUSIM:",K);c.register("+CFUN:",L);c.register("RDY",M);c.register("POWERED DOWN",N);x.reset(f);return x}
|
||||
4
libs/js/espruino_wifi/AT.min.js
vendored
@ -1,4 +0,0 @@
|
||||
exports.connect=function(p){var n=!1,b="",d,f=0,m,c={},k={},l=[];p.on("data",function(a){if(f){if(a.length<=f){f-=a.length;m(a);0==f&&(m=void 0);return}m(a.substr(0,f));a=a.substr(f);f=0;m=void 0}b+=a;n&&console.log("] "+JSON.stringify(a));"\n"==b[0]&&(b=b.substr(1));if(c)for(var e in c)b.substr(0,e.length)==e&&(b=c[e](b));for(a=b.indexOf("\r");0<=a;){var g=b.substr(0,a);if(0<g.length){var h=!1;for(e in k)g.substr(0,e.length)==e&&(k[e](g),h=!0);h||d&&d(g)}b=b.substr(a+1);"\n"==b[0]&&(b=
|
||||
b.substr(1));if(b.length&&c)for(e in c[">"]&&">"==b[0]&&(b=c[">"](b)),c)b.substr(0,e.length)==e&&(b=c[e](b));a=b.indexOf("\r")}});var h={debug:function(a){n=!1!==a;return{line:b,lineCallback:d,handlers:c,lineHandlers:k,waiting:l}},cmd:function(a,b,g){if(d)n&&console.log("Queued "+JSON.stringify(a)),l.push([a,b,g]);else if(n&&console.log("["+JSON.stringify(a)),p.write(a),b){var e=setTimeout(function(){d=void 0;g&&g();void 0===d&&0<l.length&&h.cmd.apply(h,l.shift())},b),c=function(a){d=void 0;var b;
|
||||
g&&(b=g(a))?(d=c,g=b):clearTimeout(e);void 0===d&&0<l.length&&h.cmd.apply(h,l.shift())};d=c}},write:function(a){p.write(a)},cmdReg:function(a,b,c,d,f){h.registerLine(c,d);h.cmd(a,b,function(a){h.unregisterLine(c);f(a)})},registerLine:function(a,b){if(k[a])throw Error(a+" already registered");k[a]=b},unregisterLine:function(a){delete k[a]},register:function(a,b){if(c[a])throw Error(a+" already registered");c[a]=b},unregister:function(a){delete c[a]},isBusy:function(){return void 0!==d},getData:function(a,
|
||||
b){if(f)throw Error("Already grabbing data");f=a;m=b}};return h}
|
||||