Code Monkey home page Code Monkey logo

espruino's Introduction

Espruino JavaScript for Microcontrollers

 _____                 _
|   __|___ ___ ___ _ _|_|___ ___
|   __|_ -| . |  _| | | |   | . |
|_____|___|  _|_| |___|_|_|_|___|
          |_|

https://www.espruino.com           Join the chat at https://gitter.im/espruino/Espruino

About

Espruino is a JavaScript interpreter for microcontrollers. It is designed for devices with as little as 128kB Flash and 8kB RAM.

Please support Espruino by ordering one of our official boards or donating.

Documentation

If you have an Espruino board, please read the Quick Start Guide first.

Browse the Espruino Website (try using search in the top right), and read the FAQ.

There's also a Reference for JavaScript commands as well as Tutorials. However the documentation on the Espruino website will match the version available for download but not the latest version on GitHub.

Builds for the Espruino Board and Pico Board (built automatically for each Git commit) are available from here.

Other documentation of use is:

Support / Bugs

First, please try and check that your problem hasn't already been found or covered on our forum.

Submit bugs with clear steps to reproduce them: a small test case (not your whole program), and an actual and expected result. If you can't come up with these, please post on the forum first as it may just be something in your code that we can help out with.

Work on Espruino is supported by sales of our boards.

If your board isn't made by us but came pre-installed with Espruino then you should contact the manufacturers.

We try and support users of the boards we sell, but if you bought a non-official board your issue may not get addressed. In this case, please consider donating to help cover the time it takes to fix problems (even so, we can't guarantee to fix every problem).

License

Please see the LICENSE file.

Building

Check out the page on building Espruino.

Testing

There are a bunch of tests in the tests directory. See tests/README.md for examples on how to run them.

Current State

The officially supported boards 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 https://www.espruino.com/Download.

If you are a board manufacturer interested in getting your board officially supported, please check out this page.

For a list of supported boards, please see the boards folder.

Main supported platforms are:

  • STM32 (F1, F3, F4, L4)
  • nRF52
  • nRF51
  • ESP8266
  • ESP32
  • Linux

Espruino has been ported to other boards and platforms (such as EFM32 and SAMD), but these have a habit of being contributed and then never maintained. All boards that this has happened to reside in the UNMAINTAINED_BOARDS branch.

Modification

Check out the documentation on the build process first - this should clear up a lot of potential questions about the Espruino architecture.

Please see CONTRIBUTING.md for some hints about code style/etc.

You can auto-build documentation for all source files - see doxygen/README.md

Any more questions? ask on the forum.

Porting to new devices

If you're using an existing architecture everything can be done from boards/BOARDNAME.py. See a similar board's .py file as an example.

However for a new architecture there are a bunch of different files to modify.

  • boards/*.py files describe the CPU, available pins, and connections - so the relevant linker script, headers + docs can be created
  • boards/pins/*.csv are copies of the 'pin definitions' table in the chip's datasheet. They are read in for STM32 chips by the boards/*.py files, but they are not required - see boards/MICROBIT.py for an example.
  • Global build options are handled in Makefile
  • The make directory contains arch-specific Makefile fragments
  • Extra libraries like USB/LCD/filesystem are in Makefile
  • Processor-specific code in targets/ARCH - eg. targets/stm32, targets/linux
  • Processor-specific libs (like the SDK) in targetlibs/ARCH
  • src/jshardware.h is effectively a simple abstraction layer for SPI/I2C/etc, which should be implemented in targets/ARCH/jshardware.c

Adding libraries

  • Create jswrap_mylib.c/h in libs/
  • Create library functions (see examples in other jswrap files, also the comments in scripts/common.py)

See libs/README.md for a short tutorial on how to add your own libraries.

Using Espruino in your Projects

If you're using Espruino for your own personal projects - go ahead, we hope you have fun - and please let us know what you do with it on https://www.espruino.com/Forum!

If you're planning on selling the Espruino software on your own board, please:

  • Let us know, we might be able to help.
  • Read the terms of the MPLv2 Licence that Espruino is distributed under, and make sure you comply with it
  • MPLv2 dictates that any files that you modify must be made available in source form. New files that you create don't need to be made available (although we'd encourage it!)
  • You won't be able to call your board an 'Espruino' board unless it's agreed with us (we own the trademark)
  • You must explain clearly in your documentation that your device uses Espruino internally
  • Please don't fork Espruino - improvements get very hard to share, and in the long run everyone loses.
  • Please give something back to the project - be it code improvements, documentation or support.

We spend a lot of time supporting Espruino on the forums, but can only do so because we make money from the sales of Espruino boards. If your users request support from us then we have absolutely no obligation to help them. However, we'll be a lot more motivated if you're actively helping to improve Espruino for all its users (not just your own).

espruino's People

Contributors

andrewgoz avatar beanjs avatar bobrippling avatar cephdon avatar d3nd3 avatar deirdreobyrne avatar dependabot[bot] avatar drandreas avatar ebirger avatar fanoush avatar ganehag avatar gfwilliams avatar gyavolo avatar halemmerich avatar jalawson avatar jcw avatar jumjum123 avatar mabecker avatar mariusgundersen avatar mjdietzx avatar mrmossevig avatar nkolban avatar opichals avatar rigrig avatar storm64 avatar thomaschr avatar tve avatar urish avatar vvestm avatar wilberforce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

espruino's Issues

Compatibility with Tessel/Johnny-five etc

Tim from technical.io has come up with this proposal http://hardwarejs.io/ - but at the moment it's a big departure from Espruino's implementation (which already has a bunch of code written for it).

As a starting point (and to be compatible with J5-type arrangements where you can have more than one board) we'll want to have a 'hardware' object with all the existing API calls in. Hopefully this could be the root namespace, so you can still do digitalWrite(LED1,1) but also hardware.digitalWrite(hardware.LED1,1) in order to be compatible...

Array access speedup (2x speed)

While arrays are still linked lists, it's possible to speed access up by looking at the last element and working backwards if the index > last_element/2

Remove JsParse pointer

We only need one JsParse active at a time - it'd be good to remove this, we could save some code space as well as a few bytes of stack.

Broken on Olimexino STM32 board

When flashed onto Olimexino board it just lights up the green LED. This probably means that something bad happened during the hardware initialisation in jshInit

Serial + USB Wakeup in 'Deep' Sleep Mode

An important one - allow Espruino to be woken from deep sleep mode by Serial and USB. Currently not having this means that Deep sleep is disabled by default.

Fast String Appends

The first JSV_STRING in a chain could actually store only 8 characters (but a link to the last JSV_STRINGEXT in that chain). It'd allow us to do much faster appends which would help out in a number of areas.

Array.map method doesn't pass index and the array to the callback

Array.map must pass 3 arguments to the callback function: the current element, the current index and the array itself. But the current implementation passes only the first argument. Example:

var chars = ['a', 'b', 'c'];
chars.map(function( char, index, arr) {
 //do something
});

'short' toJSON mode

There should be a way of getting a 'shortened' JSON that can be used in the interactive console. For instance:

[0,1,2,3 ... 100,101,102]

and

function (a,b,c) { ... }

Add Exceptions

Add JavaScript exceptions - we just need to find a nice way of doing this that doesn't slow us down when we're not using them.

new ArrayBuffer(1) fails

I believe this is an ArrayBuffer iterator problem:

new ArrayBuffer(1)  ==> 'new ArrayBuffer([])' // bad
new ArrayBuffer(2)  ==> 'new ArrayBuffer([0,0])' // good

Line wrap for toJSON

toJSON should be aware of line wrappings - it'd really help when dumping to the console

Better I2C error reporting

Also better error reporting generally, but I2C often gives 'INTERNAL' timeout errors if it doesn't get a response on a certain address.

Missing empty "gen" dir

Immediately after checkout:

$ make
...
Outputting decision tree
Traceback (most recent call last):
  File "scripts/build_jswrapper.py", line 135, in <module>
Traceback (most recent call last):
  File "scripts/build_platform_config.py", line 90, in <module>
    wrapperFile = open('gen/jswrapper.c', 'w')
    IOErrorheaderFile = open(headerFilename, 'w')
: [Errno 2] No such file or directory: 'gen/jswrapper.c'IOError
: [Errno 2] No such file or directory: 'gen/platform_config.h'
make: *** [gen/platform_config.h] Error 1
make: *** Waiting for unfinished jobs....
make: *** [gen/jswrapper.c] Error 1

That's because there's missing "gen" folder, which is becasue git doesn't store empty dirs, and way to work that round is to add ".empty" or similar file.

Moving variables to front of Object

In functions and root scope - move a variable to the front when it is accessed - this should speed up accesses in things like loops quite a lot.

Pin (and I2C) state to be saved to flash

This would save you having to write initialisation code into an onInit function...

I believe SPI already saves state, so it's just a matter of adding other peripherals - although we'd require a jshGetPinState added to jshardware.h

Debounce in setWatch

It'd be nice if setWatch had some debounce capability. It'll be used quite a lot for interfacing switches, and it's quite a hurdle for beginners to implement debounce.

This could be handled quite easily by modifying the event in the event queue, but it would require that 'debounced' events weren't automatically pulled off of the event queue.

Ability to Input/Output at high(er) speeds

A common way of sending an Array or ArrayBuffer using:

  • Digital outputs (>1 at a time)
  • DAC
  • PWM

Or receiving into an Array/ArrayBuffer:

  • Digital inputs (>1 at a time)
  • ADC

Faster than you could manage with setInterval, but:

  • at a user-defined speed
  • optional repetition
  • a callback on completion or for new buffers

IMO this doesn't need to be complicated with DMA, and we have UTIL_TIMER which we should be able to extend to handle this.

Technical IO have something called 'Signal' that might be able to be extended: http://hardwarejs.io/

Integers as Strings in Arrays

a[5]===a["5"]
a[5]!=a["05"]

Espruino doesn't have this behaviour. Easy enough to fix but it's debatable if we want another check to slow down array access even more.

Overclocking/Underclocking

The STM32 chips can be overclocked - some people say by as much as 2x. It'd be fun to have a mode that allowed this :)

GDB-style built-in debugger

Firmly an 'enhancement', but it should be possible to modify the parser to have a built-in debugger that allows s/n/p/q type commands which can single-step through statements.

Ctrl-C could break into this and then Ctrl-C could break out of execution completely. It'd massively help with debugging.

Software SPI implementation (shiftOut)

We should be able to do:

new SPI({mosi:A0,miso:A1,sck:A2})

And have Espruino treat it like normal SPI - but to instead just bit-bash the output. This would be way more useful than a shiftOut function.

It'd also be super-handy if it could take an argument called bits, as the hardware SPI implementation doesn't support 9 bit output and many devices (like LCDs) can work without a Data/Command (DC) pin.

Rename numbered tests

The numbered tests are a pain - it'd help if each test was given a descriptive name, and then test fails could be seen easily.

jswHandleFunctionCall optimisations

This needs some experimentation to find a fast way of detecting built-in functions.

It seems like function names should be detected first, and the parent object should then be checked (rather than the other way around) but when I tried this it massively increased the code size.

setTimeout must return positive id

setTimeout must return positive id. Currently it starts from 0. Zero (false) id usually is used to distinguish initialized and not initialized values.
Example:

if( timer)
 clearTimeout(timer);

timer = setTimeout(function(){}, 1000);

'delete' keyword

Add the JavaScript delete keyword. Should be a lot easier now we have parentinfo

USB CDC bootloader required

We need a USB bootloader so that Espruino devices can be reflashed.

While we could use DFU, it makes a lot of sense to use a USB CDC (fake serial) bootloader implementing a protocol that's compatible with the built-in RS232 one. That way, Espruino can be reflashed from the Web IDE.

XON/XOFF flow control for Serial

There's the outline of some code for this in jsdevices.c/h already but it's not yet implemented. It'd be pretty handy when copy/pasting code over Bluetooth.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.