diff --git a/Metro/Metro_RP2350_Breakout/icon.bmp b/Metro/Metro_RP2350_Breakout/icon.bmp new file mode 100644 index 000000000..d78c04e66 Binary files /dev/null and b/Metro/Metro_RP2350_Breakout/icon.bmp differ diff --git a/Metro/Metro_RP2350_Breakout/metadata.json b/Metro/Metro_RP2350_Breakout/metadata.json new file mode 100644 index 000000000..cbfe8bfdf --- /dev/null +++ b/Metro/Metro_RP2350_Breakout/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "Breakout", + "icon": "icon.bmp" +} diff --git a/Metro/Metro_RP2350_Chips_Challenge/icon.bmp b/Metro/Metro_RP2350_Chips_Challenge/icon.bmp new file mode 100644 index 000000000..57b921b93 Binary files /dev/null and b/Metro/Metro_RP2350_Chips_Challenge/icon.bmp differ diff --git a/Metro/Metro_RP2350_Chips_Challenge/metadata.json b/Metro/Metro_RP2350_Chips_Challenge/metadata.json new file mode 100644 index 000000000..571444e9f --- /dev/null +++ b/Metro/Metro_RP2350_Chips_Challenge/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "Chip'sChall", + "icon": "icon.bmp" +} diff --git a/Metro/Metro_RP2350_CircuitPython_Matrix/icon.bmp b/Metro/Metro_RP2350_CircuitPython_Matrix/icon.bmp new file mode 100644 index 000000000..06e1ec0e1 Binary files /dev/null and b/Metro/Metro_RP2350_CircuitPython_Matrix/icon.bmp differ diff --git a/Metro/Metro_RP2350_CircuitPython_Matrix/metadata.json b/Metro/Metro_RP2350_CircuitPython_Matrix/metadata.json new file mode 100644 index 000000000..46ce5585a --- /dev/null +++ b/Metro/Metro_RP2350_CircuitPython_Matrix/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "Matrix", + "icon": "icon.bmp" +} diff --git a/Metro/Metro_RP2350_FlappyNyanCat/code.py b/Metro/Metro_RP2350_FlappyNyanCat/code.py index ca1925f5a..39454cd23 100644 --- a/Metro/Metro_RP2350_FlappyNyanCat/code.py +++ b/Metro/Metro_RP2350_FlappyNyanCat/code.py @@ -13,15 +13,14 @@ import random import sys import terminalio -from displayio import Group, TileGrid, Bitmap, release_displays, Palette +from displayio import Group, TileGrid, Bitmap, Palette import supervisor import bitmaptools from adafruit_display_text.bitmap_label import Label -import picodvi -import framebufferio -import board from micropython import const import adafruit_imageload +from adafruit_fruitjam.peripherals import request_display_config +from adafruit_pathlib import Path # how strong the gravity is FALL_SPEED = 1 @@ -42,23 +41,8 @@ # current score score = 0 -# initialize display -release_displays() - -fb = picodvi.Framebuffer( - 320, - 240, - clk_dp=board.CKP, - clk_dn=board.CKN, - red_dp=board.D0P, - red_dn=board.D0N, - green_dp=board.D1P, - green_dn=board.D1N, - blue_dp=board.D2P, - blue_dn=board.D2N, - color_depth=16, -) -display = framebufferio.FramebufferDisplay(fb) +request_display_config(320,240) +display = supervisor.runtime.display # initialize groups to hold visual elements main_group = Group() @@ -607,10 +591,11 @@ def shift_post(post): # if player pressed p if "p" in cur_btn_val: - supervisor.set_next_code_file(__file__) + supervisor.set_next_code_file(__file__, + working_directory=Path(__file__).parent.absolute()) supervisor.reload() # if player pressed q elif "q" in cur_btn_val: print("exiting") - break + supervisor.reload() diff --git a/Metro/Metro_RP2350_FlappyNyanCat/icon.bmp b/Metro/Metro_RP2350_FlappyNyanCat/icon.bmp new file mode 100644 index 000000000..1868cace8 Binary files /dev/null and b/Metro/Metro_RP2350_FlappyNyanCat/icon.bmp differ diff --git a/Metro/Metro_RP2350_FlappyNyanCat/metadata.json b/Metro/Metro_RP2350_FlappyNyanCat/metadata.json new file mode 100644 index 000000000..f3f5a9dc3 --- /dev/null +++ b/Metro/Metro_RP2350_FlappyNyanCat/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "FlapyNyan🐱", + "icon": "icon.bmp" +} diff --git a/Metro/Metro_RP2350_Match3/match3_game/icon.bmp b/Metro/Metro_RP2350_Match3/match3_game/icon.bmp new file mode 100644 index 000000000..941271e0d Binary files /dev/null and b/Metro/Metro_RP2350_Match3/match3_game/icon.bmp differ diff --git a/Metro/Metro_RP2350_Match3/match3_game/metadata.json b/Metro/Metro_RP2350_Match3/match3_game/metadata.json new file mode 100644 index 000000000..b6cb9040d --- /dev/null +++ b/Metro/Metro_RP2350_Match3/match3_game/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "Match3", + "icon": "icon.bmp" +} diff --git a/Metro/Metro_RP2350_Memory/memory_game/code.py b/Metro/Metro_RP2350_Memory/memory_game/code.py index eefd35ec3..4e2b38a0a 100644 --- a/Metro/Metro_RP2350_Memory/memory_game/code.py +++ b/Metro/Metro_RP2350_Memory/memory_game/code.py @@ -10,6 +10,7 @@ import array import random import time +import atexit from displayio import Group, OnDiskBitmap, TileGrid from adafruit_display_text.bitmap_label import Label from adafruit_display_text.text_box import TextBox @@ -18,6 +19,9 @@ import supervisor import terminalio import usb.core +from adafruit_fruitjam.peripherals import request_display_config +import adafruit_usb_host_descriptors +from adafruit_pathlib import Path def random_selection(lst, count): @@ -40,7 +44,7 @@ def update_score_text(): Update the score text on the display for each player """ for _ in range(2): - out_str = f"p{_+1} score: {player_scores[_]}" + out_str = f"p{_ + 1} score: {player_scores[_]}" score_lbls[_].text = out_str @@ -58,34 +62,8 @@ def update_score_text(): # initial state is title screen CUR_STATE = STATE_TITLE -# pylint: disable=ungrouped-imports -if hasattr(supervisor.runtime, "display") and supervisor.runtime.display is not None: - # use the built-in HSTX display for Metro RP2350 - display = supervisor.runtime.display -else: - # pylint: disable=ungrouped-imports - from displayio import release_displays - import picodvi - import board - import framebufferio - - # initialize display - release_displays() - - fb = picodvi.Framebuffer( - 320, - 240, - clk_dp=board.CKP, - clk_dn=board.CKN, - red_dp=board.D0P, - red_dn=board.D0N, - green_dp=board.D1P, - green_dn=board.D1N, - blue_dp=board.D2P, - blue_dn=board.D2N, - color_depth=16, - ) - display = framebufferio.FramebufferDisplay(fb) +request_display_config(320, 240) +display = supervisor.runtime.display # main group will hold all the visual elements main_group = Group() @@ -312,6 +290,9 @@ def update_score_text(): # wait a second for USB devices to be ready time.sleep(1) +mouse_interface_index, mouse_endpoint_address = None, None +mouse = None + # scan for connected USB devices for device in usb.core.find(find_all=True): # print information about the found devices @@ -319,17 +300,45 @@ def update_score_text(): print(device.manufacturer, device.product) print(device.serial_number) - # assume this device is the mouse - mouse = device + config_descriptor = adafruit_usb_host_descriptors.get_configuration_descriptor( + device, 0 + ) - # detach from kernel driver if active + _possible_interface_index, _possible_endpoint_address = ( + adafruit_usb_host_descriptors.find_boot_mouse_endpoint(device)) + + if _possible_interface_index is not None and _possible_endpoint_address is not None: + mouse = device + mouse_interface_index = _possible_interface_index + mouse_endpoint_address = _possible_endpoint_address + print(f"mouse interface: {mouse_interface_index}", end="") + print(f"endpoint_address: {hex(mouse_endpoint_address)}") + +mouse_was_attached = None +if mouse is not None: + # detach the kernel driver if needed if mouse.is_kernel_driver_active(0): + mouse_was_attached = True mouse.detach_kernel_driver(0) + else: + mouse_was_attached = False - # set the mouse configuration so it can be used + # set configuration on the mouse so we can use it mouse.set_configuration() +def atexit_callback(): + """ + re-attach USB devices to kernel if needed. + :return: + """ + print("inside atexit callback") + if mouse_was_attached and not mouse.is_kernel_driver_active(0): + mouse.attach_kernel_driver(0) + + +atexit.register(atexit_callback) + # Buffer to hold data read from the mouse # Boot mice have 4 byte reports buf = array.array("b", [0] * 4) @@ -354,7 +363,7 @@ def update_score_text(): try: # try to read data from the mouse, small timeout so the code will move on # quickly if there is no data - data_len = mouse.read(0x81, buf, timeout=10) + data_len = mouse.read(mouse_endpoint_address, buf, timeout=20) # if there was data, then update the mouse cursor on the display # using min and max to keep it within the bounds of the display @@ -391,8 +400,8 @@ def update_score_text(): # if both cards were the same i.e. they found a match if ( - card_tgs[cards_flipped_this_turn[0]][0] - == card_tgs[cards_flipped_this_turn[1]][0] + card_tgs[cards_flipped_this_turn[0]][0] + == card_tgs[cards_flipped_this_turn[1]][0] ): # set the cards tile index to show a blank spot instead of a card @@ -409,8 +418,8 @@ def update_score_text(): # of cards then the code knows the game is over because each pair is worth 1 # point if ( - player_scores[0] + player_scores[1] - >= (grid_size[0] * grid_size[1]) // 2 + player_scores[0] + player_scores[1] + >= (grid_size[0] * grid_size[1]) // 2 ): # if the player's scores are equal @@ -493,12 +502,13 @@ def update_score_text(): # button bounding box if play_again_btn.contains(coords): # set next code file to this one - supervisor.set_next_code_file(__file__) + supervisor.set_next_code_file(__file__, + working_directory=Path(__file__).parent.absolute()) # reload supervisor.reload() # if the mouse point is within the exit # button bounding box if exit_btn.contains(coords): - # break to exit out of this script - break + # restart back to code.py + supervisor.reload() diff --git a/Metro/Metro_RP2350_Memory/memory_game/icon.bmp b/Metro/Metro_RP2350_Memory/memory_game/icon.bmp new file mode 100644 index 000000000..c268a6b33 Binary files /dev/null and b/Metro/Metro_RP2350_Memory/memory_game/icon.bmp differ diff --git a/Metro/Metro_RP2350_Memory/memory_game/metadata.json b/Metro/Metro_RP2350_Memory/memory_game/metadata.json new file mode 100644 index 000000000..cbf41d7da --- /dev/null +++ b/Metro/Metro_RP2350_Memory/memory_game/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "Memory", + "icon": "icon.bmp" +} diff --git a/Metro/Metro_RP2350_Snake/code.py b/Metro/Metro_RP2350_Snake/code.py index f6031cff8..065496d6e 100644 --- a/Metro/Metro_RP2350_Snake/code.py +++ b/Metro/Metro_RP2350_Snake/code.py @@ -3,13 +3,11 @@ import sys import time from micropython import const -import board -import picodvi -import framebufferio import supervisor import displayio import terminalio from adafruit_display_text.text_box import TextBox +from adafruit_fruitjam.peripherals import request_display_config from snake_helpers import World, Snake, GameOverException, SpeedAdjuster # state machine constant @@ -34,26 +32,8 @@ # variable for the players score score = 0 -# initialize display -displayio.release_displays() -fb = picodvi.Framebuffer( - 320, - 240, - clk_dp=board.CKP, - clk_dn=board.CKN, - red_dp=board.D0P, - red_dn=board.D0N, - green_dp=board.D1P, - green_dn=board.D1N, - blue_dp=board.D2P, - blue_dn=board.D2N, - color_depth=16, -) -display = framebufferio.FramebufferDisplay(fb) - -# In future release the default HSTX display -# will get initialized by default by circuitpython -# display = supervisor.runtime.display +request_display_config(320,240) +display = supervisor.runtime.display # load title splash screen bitmap title_bmp = displayio.OnDiskBitmap("snake_splash.bmp") @@ -263,5 +243,5 @@ supervisor.reload() # if the q button is pressed for exit if cur_btn_val in {"q", "Q"}: - # break out of main while True loop. - break + # reload to go back to code.py + supervisor.reload() diff --git a/Metro/Metro_RP2350_Snake/icon.bmp b/Metro/Metro_RP2350_Snake/icon.bmp new file mode 100644 index 000000000..3bc712748 Binary files /dev/null and b/Metro/Metro_RP2350_Snake/icon.bmp differ diff --git a/Metro/Metro_RP2350_Snake/metadata.json b/Metro/Metro_RP2350_Snake/metadata.json new file mode 100644 index 000000000..e94aba03e --- /dev/null +++ b/Metro/Metro_RP2350_Snake/metadata.json @@ -0,0 +1,4 @@ +{ + "title": "🐍 Snake 🐍", + "icon": "icon.bmp" +}