-
Notifications
You must be signed in to change notification settings - Fork 1
mcp23009e: Add test scenario for I/O expander driver. #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
394e5a1
mcp23009e: Add test scenario for I/O expander driver.
nedseb 8552a67
tests: Pass i2c_address to hardware call_method invocations.
nedseb 39dd770
tests: Add hardware_script and interactive action types.
nedseb 7336ec7
mcp23009e: Add D-PAD button tests in polling and interrupt modes.
nedseb 127f938
tests: Address Copilot review feedback on PR #49.
nedseb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,268 @@ | ||
| driver: mcp23009e | ||
| driver_class: MCP23009E | ||
| i2c_address: 0x20 | ||
|
|
||
| # I2C config for hardware tests (STeaMi board - STM32WB55) | ||
| i2c: | ||
| id: 1 | ||
|
|
||
| # Extra constructor pins (FakePin instances for mock tests) | ||
| mock_pins: | ||
| reset_pin: 0 | ||
|
|
||
| # Custom hardware init (MCP23009E requires a reset pin) | ||
| hardware_init: | | ||
| from machine import Pin | ||
| dev = MCP23009E(i2c, address=0x20, reset_pin=Pin("RST_EXPANDER", Pin.OUT)) | ||
|
|
||
| # Register values for mock tests | ||
| mock_registers: | ||
| # IODIR (0x00): all inputs by default (0xFF) | ||
| 0x00: 0xFF | ||
| # IPOL (0x01): no inversion | ||
| 0x01: 0x00 | ||
| # GPINTEN (0x02): interrupts disabled | ||
| 0x02: 0x00 | ||
| # DEFVAL (0x03): default | ||
| 0x03: 0x00 | ||
| # INTCON (0x04): default | ||
| 0x04: 0x00 | ||
| # IOCON (0x05): default config | ||
| 0x05: 0x00 | ||
| # GPPU (0x06): no pull-ups | ||
| 0x06: 0x00 | ||
| # INTF (0x07): no interrupt flags | ||
| 0x07: 0x00 | ||
| # INTCAP (0x08): default | ||
| 0x08: 0x00 | ||
| # GPIO (0x09): D-PAD buttons (bits 4-7 as inputs with pull-ups) | ||
| 0x09: 0xF0 | ||
| # OLAT (0x0A): default | ||
| 0x0A: 0x00 | ||
|
|
||
| tests: | ||
| - name: "Read IODIR default value" | ||
| action: call | ||
| method: get_iodir | ||
| expect: 0xFF | ||
| mode: [mock, hardware] | ||
|
|
||
| - name: "Read GPIO register" | ||
| action: call | ||
| method: get_gpio | ||
| expect_not_none: true | ||
| mode: [mock, hardware] | ||
|
|
||
| - name: "Read individual GPIO level" | ||
| action: call | ||
| method: get_level | ||
| args: [0] | ||
| expect_not_none: true | ||
| mode: [mock] | ||
|
|
||
| - name: "D-PAD buttons state" | ||
| action: manual | ||
| display: | ||
| - method: get_level | ||
| args: [7] | ||
| label: "UP (GP7)" | ||
| unit: "(1=relâché, 0=appuyé)" | ||
| - method: get_level | ||
| args: [5] | ||
| label: "DOWN (GP5)" | ||
| unit: "(1=relâché, 0=appuyé)" | ||
| - method: get_level | ||
| args: [6] | ||
| label: "LEFT (GP6)" | ||
| unit: "(1=relâché, 0=appuyé)" | ||
| - method: get_level | ||
| args: [4] | ||
| label: "RIGHT (GP4)" | ||
| unit: "(1=relâché, 0=appuyé)" | ||
| prompt: "Tous les boutons sont-ils relâchés (valeur 1) ?" | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| # --- Polling tests (one per D-PAD button) --- | ||
| # LED_GREEN signals when the board is ready to read the button. | ||
|
|
||
| - name: "D-PAD UP button (polling)" | ||
| action: hardware_script | ||
| pre_prompt: "Test polling D-PAD : appuyez sur chaque bouton quand la LED verte s'allume (5s). Commençons par UP." | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_level(7) == 0: | ||
| detected = True | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| - name: "D-PAD DOWN button (polling)" | ||
| action: hardware_script | ||
| pre_prompt: "Bouton DOWN" | ||
| wait: false | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_level(5) == 0: | ||
| detected = True | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| - name: "D-PAD LEFT button (polling)" | ||
| action: hardware_script | ||
| pre_prompt: "Bouton LEFT" | ||
| wait: false | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_level(6) == 0: | ||
| detected = True | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| - name: "D-PAD RIGHT button (polling)" | ||
| action: hardware_script | ||
| pre_prompt: "Bouton RIGHT" | ||
| wait: false | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_level(4) == 0: | ||
| detected = True | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| # --- Interrupt tests (one per D-PAD button) --- | ||
| # LED_GREEN signals when the board is ready; polls INTF register. | ||
|
|
||
| - name: "D-PAD UP button (interrupt)" | ||
| action: hardware_script | ||
| pre_prompt: "Test interrupt D-PAD : appuyez brièvement sur chaque bouton quand la LED verte s'allume (5s). Commençons par UP." | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| dev.interrupt_on_change(7, lambda l: None) | ||
| dev.get_gpio() | ||
| led.on() | ||
|
nedseb marked this conversation as resolved.
|
||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_intf() & (1 << 7): | ||
| detected = True | ||
| dev.get_intcap() | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| - name: "D-PAD DOWN button (interrupt)" | ||
| action: hardware_script | ||
| pre_prompt: "Bouton DOWN" | ||
| wait: false | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| dev.interrupt_on_change(5, lambda l: None) | ||
| dev.get_gpio() | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_intf() & (1 << 5): | ||
| detected = True | ||
| dev.get_intcap() | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| - name: "D-PAD LEFT button (interrupt)" | ||
| action: hardware_script | ||
| pre_prompt: "Bouton LEFT" | ||
| wait: false | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| dev.interrupt_on_change(6, lambda l: None) | ||
| dev.get_gpio() | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_intf() & (1 << 6): | ||
| detected = True | ||
| dev.get_intcap() | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
|
|
||
| - name: "D-PAD RIGHT button (interrupt)" | ||
| action: hardware_script | ||
| pre_prompt: "Bouton RIGHT" | ||
| wait: false | ||
| script: | | ||
| from machine import Pin | ||
| from time import sleep_ms, ticks_ms, ticks_diff | ||
| led = Pin("LED_GREEN", Pin.OUT) | ||
| dev.interrupt_on_change(4, lambda l: None) | ||
| dev.get_gpio() | ||
| led.on() | ||
| start = ticks_ms() | ||
| detected = False | ||
| while ticks_diff(ticks_ms(), start) < 5000: | ||
| if dev.get_intf() & (1 << 4): | ||
| detected = True | ||
| dev.get_intcap() | ||
| break | ||
| sleep_ms(50) | ||
| led.off() | ||
| result = detected | ||
| expect_true: true | ||
| mode: [hardware] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.