3bc-lang icon indicating copy to clipboard operation
3bc-lang copied to clipboard

arduino framework support discussion

Open RodrigoDornelles opened this issue 3 years ago • 6 comments

I'm bringing the discussion about supporting the arduino framework.

my initial idea is to have a memory configuration, which behaves like GPIO, so if you want to have better names than their numbers port, you can work with pointers.

Blink Example

equivalent in C

const int LED = 1;

setup() {
    pinMode(LED, OUTPUT);
}

loop() {
    sleep(1000);
    digitalWrite(!digitalRead(LED));
}

proposed in 3BC

# SETUP
MODE    NILL    0d06
TCNF    0x01    DOUT # Type config digital output
ALOC    "LED"   0x01 # Led set address of gpio 1 

# LOOP
MODE    NILL    ???? # some future mode for wait
NILL    NILL    "BLINK_FUNFC"
????    NILL    1 # some register to sleep for 1 seconds
MODE    NILLL   0d07
PULL    "LED"   NILL
MODE    NILL    0d08
ZGTO    NILL    "TURN_ON"

# LIGHT OFF LED
MODE    NILL    0d07
ALOC    "LED"   0    # write 0 in LED pointer
MODE    NILL    0d08
GOTO    NILL    "BLINK_FUNFC"

# LIGHT ON LED
MODE    NILL    0d07
NILL    NILL    "TURN_ON" 
ALOC    "LED"   1    # write 1 in LED pointer
MODE    NILL    0d08
GOTO    NILL    "BLINK_FUNFC"

RodrigoDornelles avatar Jul 07 '21 14:07 RodrigoDornelles

cool

Lrv-dev avatar Jul 07 '21 20:07 Lrv-dev

Sounds like microcontrollers in University all over again. It's very cool doing things using a low level of abstraction.

mateustoin avatar Jul 07 '21 21:07 mateustoin

The implementation was very nice, You would continue with this implementation! ;)!

kadu avatar Jul 08 '21 00:07 kadu

for internal development, I came up with the idea of these memory modifications.

#define MEM_CONFIG_RESERVED         (0b00000001) /** unused for a while **/
#define MEM_CONFIG_MAX_VALUE        (0b00000010) /** exists maximum value **/
#define MEM_CONFIG_MIN_VALUE        (0b00000100) /** exists minimum value **/
#define MEM_CONFIG_NORMALIZE        (0b00001000) /** transform clamp to map **/
#define MEM_CONFIG_GPIO_SEND        (0b00010000) /** digital output **/
#define MEM_CONFIG_GPIO_READ        (0b00100000) /** digital input **/
#define MEM_CONFIG_GPIO_PULL        (0b01000000) /** pullup input **/
#define MEM_CONFIG_GPIO_ANAL        (0b10000000) /** analogic/pwd **/

reflection

  • to use MEM_CONFIG_GPIO_ANAL you must use it together with MEM_CONFIG_GPIO_READ or MEM_CONFIG_GPIO_SEND

  • using MEM_CONFIG_GPIO_PULL with MEM_CONFIG_GPIO_ANAL will cause an error

  • using MEM_CONFIG_GPIO_PULL with MEM_CONFIG_GPIO_SEND will cause an error

  • using MEM_CONFIG_GPIO_ANAL or MEM_CONFIG_GPIO_PULL alone (whitout MEM_CONFIG_GPIO_READ or MEM_CONFIG_GPIO_SEND) will cause an error

RodrigoDornelles avatar Jul 17 '21 14:07 RodrigoDornelles

now fully supports GPIO 9e27da1964097dc909f642fc5ff7a2b9164110ce, this was the first test turning on lights from an LED bulltin.

#include <3bc.h>

void setup() {
  lang_driver_init();
  lang_line(MODE, NILL, 6);
  lang_line(MUSE, 13, MEM_CONFIG_GPIO_SEND);
  lang_line(ALOC, 13, HIGH);
  lang_driver_run();
  lang_driver_exit();
}

void loop() {}
  • NOTE the mcfg register (old tcfg) no longer exists, using the improved one instead of muse 63a6177a086a5d8c75068f4da68e25f7c10956f5.

RodrigoDornelles avatar Jul 18 '21 02:07 RodrigoDornelles

implemented in 8d710c42e18a18fe38f9833057066ef5adedd2e1

RodrigoDornelles avatar Jul 24 '21 21:07 RodrigoDornelles