@@ -96,26 +96,26 @@ describe('SPI', () => {
9696 expect ( spi . isMaster ) . toBe ( true ) ;
9797 } ) ;
9898
99- it ( 'should call the `onTransfer ` callback when initiating an SPI trasfer by writing to SPDR' , ( ) => {
99+ it ( 'should call the `onByteTransfer ` callback when initiating an SPI trasfer by writing to SPDR' , ( ) => {
100100 const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
101101 const spi = new AVRSPI ( cpu , spiConfig , FREQ_16MHZ ) ;
102- spi . onTransfer = jest . fn ( ) ;
102+ spi . onByte = jest . fn ( ) ;
103103
104104 cpu . writeData ( SPCR , SPE | MSTR ) ;
105105 cpu . writeData ( SPDR , 0x8f ) ;
106106
107- expect ( spi . onTransfer ) . toHaveBeenCalledWith ( 0x8f ) ;
107+ expect ( spi . onByte ) . toHaveBeenCalledWith ( 0x8f ) ;
108108 } ) ;
109109
110110 it ( 'should ignore SPDR writes when the SPE bit in SPCR is clear' , ( ) => {
111111 const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
112112 const spi = new AVRSPI ( cpu , spiConfig , FREQ_16MHZ ) ;
113- spi . onTransfer = jest . fn ( ) ;
113+ spi . onByte = jest . fn ( ) ;
114114
115115 cpu . writeData ( SPCR , MSTR ) ;
116116 cpu . writeData ( SPDR , 0x8f ) ;
117117
118- expect ( spi . onTransfer ) . not . toHaveBeenCalled ( ) ;
118+ expect ( spi . onByte ) . not . toHaveBeenCalled ( ) ;
119119 } ) ;
120120
121121 it ( 'should transmit a byte successfully (integration)' , ( ) => {
@@ -155,9 +155,9 @@ describe('SPI', () => {
155155
156156 let byteReceivedFromAsmCode : number | null = null ;
157157
158- spi . onTransfer = ( value ) => {
158+ spi . onByte = ( value ) => {
159159 byteReceivedFromAsmCode = value ;
160- return 0x5b ; // we copy this byte to
160+ cpu . addClockEvent ( ( ) => spi . completeTransfer ( 0x5b ) , spi . transferCycles ) ;
161161 } ;
162162
163163 const runner = new TestProgramRunner ( cpu , ( ) => 0 ) ;
@@ -228,7 +228,9 @@ describe('SPI', () => {
228228 it ( 'should should only update SPDR when tranfer finishes (double buffering)' , ( ) => {
229229 const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
230230 const spi = new AVRSPI ( cpu , spiConfig , FREQ_16MHZ ) ;
231- spi . onTransfer = jest . fn ( ( ) => 0x88 ) ;
231+ spi . onByte = ( ) => {
232+ cpu . addClockEvent ( ( ) => spi . completeTransfer ( 0x88 ) , spi . transferCycles ) ;
233+ } ;
232234
233235 cpu . writeData ( SPCR , SPE | MSTR ) ;
234236 cpu . writeData ( SPDR , 0x8f ) ;
0 commit comments