aboutsummaryrefslogtreecommitdiff
path: root/src/gpio.spec.ts
diff options
context:
space:
mode:
authorUri Shaked2020-01-08 12:20:38 +0200
committerUri Shaked2020-01-08 12:20:38 +0200
commit6a9f238969fc0e877c7bef103a4953dabf0f2936 (patch)
tree1f3b639f2309e26624beec31649e7c4037526945 /src/gpio.spec.ts
parentchore: release 0.5.0 (diff)
downloadavr8js-6a9f238969fc0e877c7bef103a4953dabf0f2936.tar.gz
avr8js-6a9f238969fc0e877c7bef103a4953dabf0f2936.tar.bz2
avr8js-6a9f238969fc0e877c7bef103a4953dabf0f2936.zip
feat(gpio): add pinState() method
close #8
Diffstat (limited to '')
-rw-r--r--src/gpio.spec.ts34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/gpio.spec.ts b/src/gpio.spec.ts
index 03ebb84..e0ab7a1 100644
--- a/src/gpio.spec.ts
+++ b/src/gpio.spec.ts
@@ -1,5 +1,5 @@
import { CPU } from './cpu';
-import { AVRIOPort, portBConfig } from './gpio';
+import { AVRIOPort, portBConfig, PinState } from './gpio';
describe('GPIO', () => {
it('should invoke the listeners when the port is written to', () => {
@@ -37,4 +37,36 @@ describe('GPIO', () => {
expect(listener).not.toHaveBeenCalled();
});
});
+
+ describe('pinState', () => {
+ it('should return PinState.High when the pin set to output and HIGH', () => {
+ const cpu = new CPU(new Uint16Array(1024));
+ const port = new AVRIOPort(cpu, portBConfig);
+ cpu.writeData(0x24, 0x1); // DDRB <- 0x1
+ cpu.writeData(0x25, 0x1); // PORTB <- 0x1
+ expect(port.pinState(0)).toEqual(PinState.High);
+ });
+
+ it('should return PinState.Low when the pin set to output and LOW', () => {
+ const cpu = new CPU(new Uint16Array(1024));
+ const port = new AVRIOPort(cpu, portBConfig);
+ cpu.writeData(0x24, 0x8); // DDRB <- 0x8
+ cpu.writeData(0x25, 0xf7); // PORTB <- 0xF7 (~8)
+ expect(port.pinState(3)).toEqual(PinState.Low);
+ });
+
+ it('should return PinState.Input by default (reset state)', () => {
+ const cpu = new CPU(new Uint16Array(1024));
+ const port = new AVRIOPort(cpu, portBConfig);
+ expect(port.pinState(1)).toEqual(PinState.Input);
+ });
+
+ it('should return PinState.InputPullUp when the pin is set to input with pullup', () => {
+ const cpu = new CPU(new Uint16Array(1024));
+ const port = new AVRIOPort(cpu, portBConfig);
+ cpu.writeData(0x24, 0); // DDRB <- 0
+ cpu.writeData(0x25, 0x2); // PORTB <- 0x2
+ expect(port.pinState(1)).toEqual(PinState.InputPullUp);
+ });
+ });
});