forked from espruino/Espruino
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a compiled-in md380 module. Use via md380 = require("md380").get()
File is in libs/md380/md380_lib.js. Happy hacking.
- Loading branch information
Showing
6 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "jsinteractive.h" | ||
#include "jsvar.h" | ||
#include "jswrap_modules.h" | ||
|
||
/*JSON{ | ||
"type" : "init", | ||
"generate" : "jswrap_md380_modules" | ||
}*/ | ||
|
||
/* | ||
* Currently, only supports 64k, though extra 64k chunks could be added. | ||
*/ | ||
|
||
extern char _md380_lib_js_start[]; | ||
extern uint32_t _md380_lib_js_size; | ||
|
||
void jswrap_md380_modules(void) | ||
{ | ||
if (_md380_lib_js_size > 0 && _md380_lib_js_size <= 65535) { | ||
JsVar *src = jsvNewWithFlags(JSV_NATIVE_STRING); | ||
if (!src) { | ||
jsiConsolePrintf("Unable to create Native String\n"); | ||
return; | ||
} | ||
JsVar *mod = jsvNewFromString("md380"); | ||
if (!mod) { | ||
jsiConsolePrintf("Unable to create Module name\n"); | ||
jsvUnLock(src); | ||
return; | ||
} | ||
src->varData.nativeStr.ptr = _md380_lib_js_start; | ||
src->varData.nativeStr.len = _md380_lib_js_size; | ||
jswrap_modules_addCached(mod, src); | ||
//jsvUnLock(src); | ||
//jsvUnLock(mod); | ||
} | ||
else | ||
jsiConsolePrintf("Size %d out of range\n", _md380_lib_js_size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
void jswrap_md380_modules(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function md380() { | ||
} | ||
|
||
md380.prototype.ReadSecurity = function(addr) { | ||
var ret; | ||
|
||
D7.reset(); | ||
SPI1.setup({sck:B3, miso:B4, mosi:B5, baud:84000000, mode:3}); | ||
SPI1.send([0x48, (addr>>16)&0xff, (addr>>8)&0xff, (addr)&0xff, 0xA5]); | ||
ret = SPI1.send([0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5]); | ||
D7.set(); | ||
return ret; | ||
}; | ||
|
||
exports.get = function() { | ||
return new md380(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.section .rodata | ||
.global _md380_lib_js_start | ||
.type _md380_lib_js_start, %object | ||
.balign 1 | ||
|
||
_md380_lib_js_start: | ||
.incbin "md380_lib.js" | ||
|
||
.global _md380_lib_js_size | ||
.type _md380_lib_js_size, %object | ||
.balign 1 | ||
|
||
_md380_lib_js_size: | ||
.int _md380_lib_js_size - _md380_lib_js_start |