• Hi !

    I use a 7-segment led display like this one on a custom board with a NRF52832 (it runs espruino v2.01).

    I have a setInterval that triggers a refreshDisplay function. This function calls three time the function turnDigitOn to display the hour.

    function turnDigitOn(digit) {
      digitalWrite([D6, D5, D4, D3, D2], digit);
    }
    

    As the refreshDisplay is called with an interval of 2ms, I was wondering if I could write it in inlineC to speed up the thing. I tried the following:

    var c = E.compiledC(`
      // void turnDigitOn(int, int, int, int, int)
      void turnDigitOn(int ioDigit1Value, int ioDigit2Value, int ioDotsValue, int ioDigit3Value, int ioDigit4Value) {
        nrf_gpio_cfg_output(6);
        nrf_gpio_cfg_output(5);
        nrf_gpio_cfg_output(4);
        nrf_gpio_cfg_output(3);
        nrf_gpio_cfg_output(2);
    
        nrf_gpio_pin_write(6, ioDigit1Value);
        nrf_gpio_pin_write(5, ioDigit2Value);
        nrf_gpio_pin_write(4, ioDotsValue);
        nrf_gpio_pin_write(3, ioDigit3Value);
        nrf_gpio_pin_write(2, ioDigit4Value);
      }
    `);
    

    but when I then I have the following error message.

    >---------------------------------------­------------
                                     COMPILER MESSAGE
    ----------------------------------------­-----------
    out1069094144.cpp: In function 'void turnDigitOn(int, int, int, int, int)':
    out1069094144.cpp:59:26: error: 'nrf_gpio_cfg_output' was not declared in this scope
         nrf_gpio_cfg_output(6);
                              ^
    out1069094144.cpp:65:40: error: 'nrf_gpio_pin_write' was not declared in this scope
         nrf_gpio_pin_write(6, ioDigit1Value);
    

    So is there a way to use these nrf functions (nrf_gpio_cfg_output and nrf_gpio_pin_write) and most importantly, will inlineC really increase performances?

    Thanks and best regards.

  • Thr 2020.04.02

    Hi @benoit, although I am unable to provide a definitive answer, I am responding as the ones that most likely have that content have been busy in BangleLand, and most likely will respond by tomorrow. In the mean time, a couple of things really stick out.

    As you mentioned 'custom' board, had you seen this comment yet?

    'Note: This is an online service that is only provided for official Espruino boards.'
    http://www.espruino.com/InlineC

    I noticed that you have an official board from your other thread posts. Have you tried snippets of your custom code, to prove out whether the pin toggling may be done on a board we know is compiled for?

    Also, had all the items beneath the heading 'Caveats' been read and understood. While 'inlineC' is incredibly fast, in my simple tests, found and understood the caveats mentioned there.

    One item that might provide some insight is listed under:

    Link under Examples:

    http://www.espruino.com/Reference#l_E_ge­tAddressOf

    nRF52 Low Level Interface Library

  • You could actually get a big improvement with turnDigitOn = digitalWrite.bind(null,[D6, D5, D4, D3, D2])

    But there's no access to underlying APIs, so if you want access to the IO, you need to access the address of the register directly :)

  • I was wondering if I could write it in inlineC

    yes

    to speed up the thing.

    Not sure your example would benefit from it. you can configure pins for output once and not each time and then you just set five of them, that doesn't look like expensive operation, see also https://www.espruino.com/Performance if speed is important.

    Anyway fastest way to do this is to write OUT,OUTSET or OUTCLR GPIO register directly from javascript via poke32 command. So you can prepare the value and write all pins via single write (OUT) or two writes (OUTCLR,OUTSET). See the help here

    So e.g. to clear pins 23456 via single write you'd write value 4+8+16+32+64 to OUTCLR via poke32(124,0x50000000+0x50c) or to set them to 1 you'd write same value to 0x50000508. When writing OUT register you'd need to take care of pins you don't want to change by reading the value before.

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

InlineC with NRF52832 on custom board (nrf_gpio_pin_write)

Posted by Avatar for benoit @benoit

Actions