Custom board definition (MYBOARD.py) and pin aliases

Posted on
  • Assuming that the MCU is already supported by Espruino (STM32, ESP8266, nRF5x etc.), how would one define pin aliases (e.g. ADC=D1) without sacrificing a JS variable (e.g. RAM-constrained board) ?

    It does not seem to be sufficient to add

    devices = {
      'ADC' : { 'pin' : 'D1' },
    };
    

    to MYBOARD.py to have ADC automatically available as a global variable in JS as an alias to D1

  • It's a bit of a hack at the moment - LEDs and Buttons are treated differently.

    The best method is to make your own jswrap_xx.c file, and to put something like this in it:

    /*JSON{
      "type" : "variable",
      "name" : "ADC",
      "generate_full" : "JSH_PORTD_OFFSET+1",
      "return" : ["pin","My ADC"]
    }*/
    
  • Right! I had not thought of that... :)

    I have 2 goals (not mutually exclusive):

    1. avoid repeating ADC=D1 in every program (convenience)
    2. avoid "burning" JS variables on simple aliases (resource optimisation)

    I guess this solution addresses 1. but would there be a way to address 2. as well ?

  • It doesn't burn JS variables either - it's one of the big things about Espruino - that all built-in variables/functions exist without taking up any RAM :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Custom board definition (MYBOARD.py) and pin aliases

Posted by Avatar for ddm @ddm

Actions