adafruit / Adafruit_Python_PlatformDetect

MIT License
58 stars 233 forks source link

Add Fake Microchip MCP2221 #347

Closed brentru closed 5 months ago

brentru commented 5 months ago

Adding a fake Microchip MCP2221A board and chip for use with stubbing the blinka API for usage with no hardware attached.

Test result after setting environment variable to BLINKA_FAKE_MCP2221 and running python3 bin/detect.py

Board Detection Test

Check that the Chip and Board IDs match your board and that this it is
correctly detecting whether or not it is a Linux board.

Chip id:  FAKE_MCP2221
Board id:  FAKE_MICROCHIP_MCP2221

Linux Detection
---------------
Is this an embedded Linux system? False

Raspberry Pi Boards
-------------------
Is this a Pi 3B+? False
Is this a Pi 4B? False
Is this a 40-pin Raspberry Pi? False
Is this a Raspberry Pi Compute Module? False

Other Boards
-------------------
Is this a Siemens Simatic IOT2000 Gateway? False
Is this a 96boards board? False
Is this a BeagleBone board? False
Is this a Giant board? False
Is this a Coral Dev board? False
Is this a MaaXBoard? False
Is this a SiFive board?  False
Is this a PYNQ board? False
Is this a Rock Pi board? False
Is this a NanoPi board? False
Is this a Khadas VIM3 board? False
Is this a Clockwork Pi board? False
Is this a Seeed Board? False
Is this a UDOO board? False
Is this an ASUS Tinker board? False
Is this an STM32MP1 board? False
Is this a MilkV board? False
Is this a generic Linux PC? False
Is this an OS environment variable special case? False
makermelissa commented 5 months ago

Is there a reason you are making it MCP2221 specific instead of a more generic board that we can use to CI test all of the functions?

makermelissa commented 5 months ago

I was thinking more about this and thought it might be better to adding a way to force a board and then remembered, I had added a feature like this a while back and completely forgotten about it. There are a couple of environment variables BLINKA_FORCEBOARD and BLINKA_FORCECHIP that can be set with the constant of the board/chip you are trying to set.

brentru commented 5 months ago

Is there a reason you are making it MCP2221 specific instead of a more generic board that we can use to CI test all of the functions?

I was using the MCP2221 to test WipperSnapper Python. Open to suggestions for using a generic target.

I was thinking more about this and thought it might be better to adding a way to force a board and then remembered, I had added a feature like this a while back and completely forgotten about it. There are a couple of environment variables BLINKA_FORCEBOARD and BLINKA_FORCECHIP that can be set with the constant of the board/chip you are trying to set.

I don't really understand how the FORCEBOARD/FORCECHIP env. variables come into play for the purpose of this PR, could you explain more about them?

makermelissa commented 5 months ago

Sure. Since the MCP2221a is already a board, to force Platform detect to return the correct board IDs, you could use something like those environment variables. For instance, in the detect script, it you added:

os.environ["BLINKA_FORCEBOARD"] = "MICROCHIP_MCP2221"
os.environ["BLINKA_ FORCECHIP"] = "MCP2221"

Then it should return that it detected those. Likewise, in your Python Wipper script, you could set those before calling Blinka. Now in the Blinka code, you would probably want to check if those variables are set in order to know that it's actually a fake board rather than a real one. This way, you wouldn't need to modify PlatformDetect at all.

brentru commented 5 months ago

Closing this conditionally in favor of the forcechip approach