@@ -96,26 +96,26 @@ describe('SPI', () => {
96
96
expect ( spi . isMaster ) . toBe ( true ) ;
97
97
} ) ;
98
98
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' , ( ) => {
100
100
const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
101
101
const spi = new AVRSPI ( cpu , spiConfig , FREQ_16MHZ ) ;
102
- spi . onTransfer = jest . fn ( ) ;
102
+ spi . onByte = jest . fn ( ) ;
103
103
104
104
cpu . writeData ( SPCR , SPE | MSTR ) ;
105
105
cpu . writeData ( SPDR , 0x8f ) ;
106
106
107
- expect ( spi . onTransfer ) . toHaveBeenCalledWith ( 0x8f ) ;
107
+ expect ( spi . onByte ) . toHaveBeenCalledWith ( 0x8f ) ;
108
108
} ) ;
109
109
110
110
it ( 'should ignore SPDR writes when the SPE bit in SPCR is clear' , ( ) => {
111
111
const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
112
112
const spi = new AVRSPI ( cpu , spiConfig , FREQ_16MHZ ) ;
113
- spi . onTransfer = jest . fn ( ) ;
113
+ spi . onByte = jest . fn ( ) ;
114
114
115
115
cpu . writeData ( SPCR , MSTR ) ;
116
116
cpu . writeData ( SPDR , 0x8f ) ;
117
117
118
- expect ( spi . onTransfer ) . not . toHaveBeenCalled ( ) ;
118
+ expect ( spi . onByte ) . not . toHaveBeenCalled ( ) ;
119
119
} ) ;
120
120
121
121
it ( 'should transmit a byte successfully (integration)' , ( ) => {
@@ -155,9 +155,9 @@ describe('SPI', () => {
155
155
156
156
let byteReceivedFromAsmCode : number | null = null ;
157
157
158
- spi . onTransfer = ( value ) => {
158
+ spi . onByte = ( value ) => {
159
159
byteReceivedFromAsmCode = value ;
160
- return 0x5b ; // we copy this byte to
160
+ cpu . addClockEvent ( ( ) => spi . completeTransfer ( 0x5b ) , spi . transferCycles ) ;
161
161
} ;
162
162
163
163
const runner = new TestProgramRunner ( cpu , ( ) => 0 ) ;
@@ -228,7 +228,9 @@ describe('SPI', () => {
228
228
it ( 'should should only update SPDR when tranfer finishes (double buffering)' , ( ) => {
229
229
const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
230
230
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
+ } ;
232
234
233
235
cpu . writeData ( SPCR , SPE | MSTR ) ;
234
236
cpu . writeData ( SPDR , 0x8f ) ;
0 commit comments