diff options
| author | Uri Shaked | 2021-10-30 21:55:31 +0300 |
|---|---|---|
| committer | Uri Shaked | 2021-10-30 21:55:31 +0300 |
| commit | 64736a76f0989dbc86e86df85349b1ee7e51ee8f (patch) | |
| tree | 1eaddd2144ea35d97cb33f919a3f52bd40171534 /src/peripherals/spi.spec.ts | |
| parent | 0.18.5 (diff) | |
| download | avr8js-64736a76f0989dbc86e86df85349b1ee7e51ee8f.tar.gz avr8js-64736a76f0989dbc86e86df85349b1ee7e51ee8f.tar.bz2 avr8js-64736a76f0989dbc86e86df85349b1ee7e51ee8f.zip | |
feat(spi): add `onByte` callback
a more versatile alternative to the `onTransfer` callback.
Depracate `onTransfer()`.
Diffstat (limited to 'src/peripherals/spi.spec.ts')
| -rw-r--r-- | src/peripherals/spi.spec.ts | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/peripherals/spi.spec.ts b/src/peripherals/spi.spec.ts index 9e6dac5..da429fe 100644 --- a/src/peripherals/spi.spec.ts +++ b/src/peripherals/spi.spec.ts @@ -96,26 +96,26 @@ describe('SPI', () => { expect(spi.isMaster).toBe(true); }); - it('should call the `onTransfer` callback when initiating an SPI trasfer by writing to SPDR', () => { + it('should call the `onByteTransfer` callback when initiating an SPI trasfer by writing to SPDR', () => { const cpu = new CPU(new Uint16Array(1024)); const spi = new AVRSPI(cpu, spiConfig, FREQ_16MHZ); - spi.onTransfer = jest.fn(); + spi.onByte = jest.fn(); cpu.writeData(SPCR, SPE | MSTR); cpu.writeData(SPDR, 0x8f); - expect(spi.onTransfer).toHaveBeenCalledWith(0x8f); + expect(spi.onByte).toHaveBeenCalledWith(0x8f); }); it('should ignore SPDR writes when the SPE bit in SPCR is clear', () => { const cpu = new CPU(new Uint16Array(1024)); const spi = new AVRSPI(cpu, spiConfig, FREQ_16MHZ); - spi.onTransfer = jest.fn(); + spi.onByte = jest.fn(); cpu.writeData(SPCR, MSTR); cpu.writeData(SPDR, 0x8f); - expect(spi.onTransfer).not.toHaveBeenCalled(); + expect(spi.onByte).not.toHaveBeenCalled(); }); it('should transmit a byte successfully (integration)', () => { @@ -155,9 +155,9 @@ describe('SPI', () => { let byteReceivedFromAsmCode: number | null = null; - spi.onTransfer = (value) => { + spi.onByte = (value) => { byteReceivedFromAsmCode = value; - return 0x5b; // we copy this byte to + cpu.addClockEvent(() => spi.completeTransfer(0x5b), spi.transferCycles); }; const runner = new TestProgramRunner(cpu, () => 0); @@ -228,7 +228,9 @@ describe('SPI', () => { it('should should only update SPDR when tranfer finishes (double buffering)', () => { const cpu = new CPU(new Uint16Array(1024)); const spi = new AVRSPI(cpu, spiConfig, FREQ_16MHZ); - spi.onTransfer = jest.fn(() => 0x88); + spi.onByte = () => { + cpu.addClockEvent(() => spi.completeTransfer(0x88), spi.transferCycles); + }; cpu.writeData(SPCR, SPE | MSTR); cpu.writeData(SPDR, 0x8f); |
