wokwi / avr8js

Arduino (8-bit AVR) simulator, written in JavaScript and runs in the browser / Node.js
https://blog.wokwi.com/avr8js-simulate-arduino-in-javascript/
MIT License
463 stars 73 forks source link

Calling `pinState()` inside a GPIO port listener returns incorrect values after changing DDR #47

Closed urish closed 4 years ago

urish commented 4 years ago

Reproduction test case:

it('should reflect the current port state when called inside a listener after DDR change', () => {
  const cpu = new CPU(new Uint16Array(1024));
  const port = new AVRIOPort(cpu, portBConfig);
  const listener = jest.fn(() => {
    expect(port.pinState(0)).toBe(PinState.Low);
  });
  expect(port.pinState(0)).toBe(PinState.Input);
  port.addListener(listener);
  cpu.writeData(0x24, 0x01); // DDRB <- 0x01
  expect(listener).toHaveBeenCalled();
});