Skip to content

Simpler API? Request for comments #87

Open
@urish

Description

@urish

As part of the discussion in #67, I started working on creating a simpler API for using the simulator.

For instance, creating an ATmega328p simulation, will look something like:

import { createAVR, ATmega328p } from 'avr8js';

const { cpu } = createAVR(ATmega328p);

// Microcontroller loop
while (...) {
  avrInstruction(cpu);
  cpu.tick();
}

The idea is that createAVR() will return an object that contains the CPU and all the peripherals:

{
  cpu: CPU;
  timers: AVRTimer[];
  clock: AVRClock[];
  eeprom: AVREEPROM;
  spi: AVRSPI;
  usart: AVRUSART[];
  twi: AVRTWI;
  gpio: { [key: string]: AVRIOPort };
};

e.g. if you need accept to GPIO port B and the first hardware USART peripheral you could do something like:

const { cpu, gpio, usart } = createAVR(ATmega328p);

gpio.B.addListener(() => {
  // listener code
});

usart[0].onLineTransmit = () => {
  // listener code
};

I've created a prototype in the simpler-api branch, and would love to hear your thoughts - especially from people who worked with the current API in the past, e.g. @gfeun, @elliottkember, @ricardojlrufino, @SebastianZug, @tawjaw, @yiivon.

Should we keep the API the way it is? Do you like the proposed API better? What can we improve?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions