@@ -6,13 +6,23 @@ describe('GPIO', () => {
66 const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
77 const port = new AVRIOPort ( cpu , portBConfig ) ;
88 const listener = jest . fn ( ) ;
9- port . addListener ( listener ) ;
109 cpu . writeData ( 0x24 , 0x0f ) ; // DDRB <- 0x0f
10+ port . addListener ( listener ) ;
1111 cpu . writeData ( 0x25 , 0x55 ) ; // PORTB <- 0x55
1212 expect ( listener ) . toHaveBeenCalledWith ( 0x05 , 0 ) ;
1313 expect ( cpu . data [ 0x23 ] ) . toEqual ( 0x5 ) ; // PINB should return port value
1414 } ) ;
1515
16+ it ( 'should invoke the listeners when DDR changes (issue #28)' , ( ) => {
17+ const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
18+ const port = new AVRIOPort ( cpu , portBConfig ) ;
19+ const listener = jest . fn ( ) ;
20+ cpu . writeData ( 0x25 , 0x55 ) ; // PORTB <- 0x55
21+ port . addListener ( listener ) ;
22+ cpu . writeData ( 0x24 , 0xf0 ) ; // DDRB <- 0xf0
23+ expect ( listener ) . toHaveBeenCalledWith ( 0x50 , 0 ) ;
24+ } ) ;
25+
1626 it ( 'should toggle the pin when writing to the PIN register' , ( ) => {
1727 const cpu = new CPU ( new Uint16Array ( 1024 ) ) ;
1828 const port = new AVRIOPort ( cpu , portBConfig ) ;
@@ -34,7 +44,7 @@ describe('GPIO', () => {
3444 cpu . writeData ( 0x24 , 0x0f ) ; // DDRB <- 0x0f
3545 port . removeListener ( listener ) ;
3646 cpu . writeData ( 0x25 , 0x99 ) ; // PORTB <- 0x99
37- expect ( listener ) . not . toHaveBeenCalled ( ) ;
47+ expect ( listener ) . toBeCalledTimes ( 1 ) ;
3848 } ) ;
3949 } ) ;
4050
@@ -76,9 +86,9 @@ describe('GPIO', () => {
7686 const listener = jest . fn ( ( ) => {
7787 expect ( port . pinState ( 0 ) ) . toBe ( PinState . High ) ;
7888 } ) ;
79- port . addListener ( listener ) ;
8089 expect ( port . pinState ( 0 ) ) . toBe ( PinState . Input ) ;
8190 cpu . writeData ( 0x24 , 0x01 ) ; // DDRB <- 0x01
91+ port . addListener ( listener ) ;
8292 cpu . writeData ( 0x25 , 0x01 ) ; // PORTB <- 0x01
8393 expect ( listener ) . toHaveBeenCalled ( ) ;
8494 } ) ;
0 commit comments