diff --git a/Source/Juego/DisplayConnector.cs b/Source/Juego/DisplayConnector.cs index 4399c07..b5f779c 100644 --- a/Source/Juego/DisplayConnector.cs +++ b/Source/Juego/DisplayConnector.cs @@ -1,7 +1,8 @@ -using System; -using static Meadow.Hardware.DisplayConnector; +using Meadow.Hardware; +using System; +using static Meadow.Devices.DisplayConnector; -namespace Meadow.Hardware; +namespace Meadow.Devices; /// /// Represents the display connector on Juego diff --git a/Source/Juego/IJuegoHardware.cs b/Source/Juego/IJuegoHardware.cs index b3c0d39..6fddf6c 100644 --- a/Source/Juego/IJuegoHardware.cs +++ b/Source/Juego/IJuegoHardware.cs @@ -1,93 +1,92 @@ using Meadow.Foundation.Audio; -using Meadow.Foundation.Graphics; using Meadow.Foundation.Leds; using Meadow.Foundation.Sensors.Accelerometers; using Meadow.Foundation.Sensors.Buttons; using Meadow.Hardware; +using Meadow.Peripherals.Displays; -namespace WildernessLabs.Hardware.Juego +namespace Meadow.Devices; + +/// +/// Represents the hardware interface for the Juego device +/// +public interface IJuegoHardware { /// - /// Represents the hardware interface for the Juego device + /// Gets the graphics display interface /// - public interface IJuegoHardware - { - /// - /// Gets the graphics display interface - /// - public IGraphicsDisplay? Display { get; } + public IPixelDisplay? Display { get; } - /// - /// Gets the right/up button - /// - public PushButton? Right_UpButton { get; } - /// - /// Gets the right/down button - /// - public PushButton? Right_DownButton { get; } - /// - /// Gets the right/left button - /// - public PushButton? Right_LeftButton { get; } - /// - /// Gets the right/right button - /// - public PushButton? Right_RightButton { get; } + /// + /// Gets the right/up button + /// + public PushButton? Right_UpButton { get; } + /// + /// Gets the right/down button + /// + public PushButton? Right_DownButton { get; } + /// + /// Gets the right/left button + /// + public PushButton? Right_LeftButton { get; } + /// + /// Gets the right/right button + /// + public PushButton? Right_RightButton { get; } - /// - /// Gets the left/up button - /// - public PushButton? Left_UpButton { get; } - /// - /// Gets the left/down button - /// - public PushButton? Left_DownButton { get; } - /// - /// Gets the left/left button - /// - public PushButton? Left_LeftButton { get; } - /// - /// Gets the left/right button - /// - public PushButton? Left_RightButton { get; } + /// + /// Gets the left/up button + /// + public PushButton? Left_UpButton { get; } + /// + /// Gets the left/down button + /// + public PushButton? Left_DownButton { get; } + /// + /// Gets the left/left button + /// + public PushButton? Left_LeftButton { get; } + /// + /// Gets the left/right button + /// + public PushButton? Left_RightButton { get; } - /// - /// Gets the start button - /// - public PushButton? StartButton { get; } - /// - /// Gets the select button - /// - public PushButton? SelectButton { get; } + /// + /// Gets the start button + /// + public PushButton? StartButton { get; } + /// + /// Gets the select button + /// + public PushButton? SelectButton { get; } - // Speakers - /// - /// Gets the left speaker - /// - public PiezoSpeaker? LeftSpeaker { get; } - /// - /// Gets the right speaker - /// - public PiezoSpeaker? RightSpeaker { get; } + // Speakers + /// + /// Gets the left speaker + /// + public PiezoSpeaker? LeftSpeaker { get; } + /// + /// Gets the right speaker + /// + public PiezoSpeaker? RightSpeaker { get; } - /// - /// Gets the PWM LED - /// - public PwmLed? BlinkyLed { get; } + /// + /// Gets the PWM LED + /// + public PwmLed? BlinkyLed { get; } - /// - /// Gets the motion sensor - /// - public Bmi270? MotionSensor { get; } + /// + /// Gets the motion sensor + /// + public Bmi270? MotionSensor { get; } - /// - /// Gets the display header connector - /// - public DisplayConnector DisplayHeader { get; } + /// + /// Gets the display header connector + /// + public DisplayConnector DisplayHeader { get; } - /// - /// Gets the Stemma QT I2C Qwiic connector - /// - public I2cConnector? Qwiic { get; } - } + /// + /// Gets the Stemma QT I2C Qwiic connector + /// + public I2cConnector? Qwiic { get; } } \ No newline at end of file diff --git a/Source/Juego/Juego.cs b/Source/Juego/Juego.cs index 7ddb663..625b653 100644 --- a/Source/Juego/Juego.cs +++ b/Source/Juego/Juego.cs @@ -1,119 +1,117 @@ -using Meadow; -using Meadow.Foundation.Audio; +using Meadow.Foundation.Audio; using Meadow.Foundation.ICs.IOExpanders; using Meadow.Hardware; using Meadow.Logging; using System; -namespace WildernessLabs.Hardware.Juego +namespace Meadow.Devices; + +/// +/// Juego hardware factory class for Juego v1, v2, and v3 hardware +/// +public class Juego { + private Juego() { } + /// - /// Juego hardware factory class for Juego v1, v2, and v3 hardware + /// Create an instance of the Juego class for the current hardware /// - public class Juego + public static IJuegoHardware? Create() { - private Juego() { } + IJuegoHardware? hardware = null; + Logger? logger = Resolver.Log; + + logger?.Debug("Initializing Juego..."); - /// - /// Create an instance of the Juego class for the current hardware - /// - public static IJuegoHardware? Create() + var device = Resolver.Device; + + // make sure not getting instantiated before the App Initialize method + if (Resolver.Device == null) { - IJuegoHardware? hardware = null; - Logger? logger = Resolver.Log; + var msg = "Juego instance must be created no earlier than App.Initialize()"; + logger?.Error(msg); + throw new Exception(msg); + } - logger?.Debug("Initializing Juego..."); + if (device is IF7FeatherMeadowDevice { } feather) + { + logger?.Info("Instantiating Juego v1 hardware"); + hardware = new JuegoHardwareV1(feather); + } + else if (device is IF7CoreComputeMeadowDevice { } ccm) + { + II2cBus i2cBus; + Mcp23008? mcpVersion = null; + byte version = 0; - var device = Resolver.Device; + PiezoSpeaker? leftSpeaker = null; + PiezoSpeaker? rightSpeaker = null; - // make sure not getting instantiated before the App Initialize method - if (Resolver.Device == null) + try + { + logger?.Info("Instantiating speakers"); + // hack for PWM init bug .... move back into the hardware classes once it's fixed + leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8); + rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9); + } + catch { - var msg = "Juego instance must be created no earlier than App.Initialize()"; - logger?.Error(msg); - throw new Exception(msg); + logger?.Info("Failed to instantiate speakers"); } - if (device is IF7FeatherMeadowDevice { } feather) + try { - logger?.Info("Instantiating Juego v1 hardware"); - hardware = new JuegoHardwareV1(feather); + logger?.Info("Intantiating I2C Bus"); + i2cBus = ccm.CreateI2cBus(busSpeed: I2cBusSpeed.FastPlus); } - else if (device is IF7CoreComputeMeadowDevice { } ccm) + catch { - II2cBus i2cBus; - Mcp23008? mcpVersion = null; - byte version = 0; - - PiezoSpeaker? leftSpeaker = null; - PiezoSpeaker? rightSpeaker = null; - - try - { - logger?.Info("Instantiating speakers"); - // hack for PWM init bug .... move back into the hardware classes once it's fixed - leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8); - rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9); - } - catch - { - logger?.Info("Failed to instantiate speakers"); - } - - try - { - logger?.Info("Intantiating I2C Bus"); - i2cBus = ccm.CreateI2cBus(busSpeed: I2cBusSpeed.FastPlus); - } - catch - { - logger?.Info("Failed to instantiate I2C Bus"); - logger?.Info("Cannot instantiate Juego hardware"); - return null; - } + logger?.Info("Failed to instantiate I2C Bus"); + logger?.Info("Cannot instantiate Juego hardware"); + return null; + } - try - { - logger?.Info("Intantiating version MCP23008"); - mcpVersion = new Mcp23008(i2cBus, address: 0x23); - version = mcpVersion.ReadFromPorts(); - } - catch - { - logger?.Info("Failed to instantiate version MCP23008"); - } + try + { + logger?.Info("Instantiating version MCP23008"); + mcpVersion = new Mcp23008(i2cBus, address: 0x23); + version = mcpVersion.ReadFromPorts(); + } + catch + { + logger?.Info("Failed to instantiate version MCP23008"); + } - try + try + { + if (mcpVersion != null && + version >= JuegoHardwareV3.MinimumHardareVersion) { - if (mcpVersion != null && - version >= JuegoHardwareV3.MinimumHardareVersion) + logger?.Info("Instantiating Juego v3 hardware"); + hardware = new JuegoHardwareV3(ccm, i2cBus) { - logger?.Info("Instantiating Juego v3 hardware"); - hardware = new JuegoHardwareV3(ccm, i2cBus) - { - Mcp_VersionInfo = mcpVersion, - LeftSpeaker = leftSpeaker, - RightSpeaker = rightSpeaker, - }; - } - else - { - logger?.Info("Instantiating Juego v2 hardware"); - hardware = new JuegoHardwareV2(ccm, i2cBus) - { - Mcp_VersionInfo = mcpVersion!, - LeftSpeaker = leftSpeaker, - RightSpeaker = rightSpeaker, - }; - } + Mcp_VersionInfo = mcpVersion, + LeftSpeaker = leftSpeaker, + RightSpeaker = rightSpeaker, + }; } - catch + else { - logger?.Info("Failed to instantiate Juego hardware"); + logger?.Info("Instantiating Juego v2 hardware"); + hardware = new JuegoHardwareV2(ccm, i2cBus) + { + Mcp_VersionInfo = mcpVersion!, + LeftSpeaker = leftSpeaker, + RightSpeaker = rightSpeaker, + }; } } - - return hardware; + catch + { + logger?.Info("Failed to instantiate Juego hardware"); + } } + + return hardware; } } \ No newline at end of file diff --git a/Source/Juego/Juego.csproj b/Source/Juego/Juego.csproj index e87e822..4d103d5 100644 --- a/Source/Juego/Juego.csproj +++ b/Source/Juego/Juego.csproj @@ -1,6 +1,6 @@ - 1.8.0 + 1.9.0 true icon.png Wilderness Labs, Inc @@ -24,10 +24,10 @@ - - - - - + + + + + diff --git a/Source/Juego/JuegoHardwareV1.cs b/Source/Juego/JuegoHardwareV1.cs index 6f32413..fff947d 100644 --- a/Source/Juego/JuegoHardwareV1.cs +++ b/Source/Juego/JuegoHardwareV1.cs @@ -1,131 +1,132 @@ -using Meadow; -using Meadow.Foundation.Audio; +using Meadow.Foundation.Audio; using Meadow.Foundation.Displays; -using Meadow.Foundation.Graphics; using Meadow.Foundation.Leds; using Meadow.Foundation.Sensors.Accelerometers; using Meadow.Foundation.Sensors.Buttons; using Meadow.Foundation.Sensors.Hid; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Units; using System; -namespace WildernessLabs.Hardware.Juego +namespace Meadow.Devices; + +/// +/// Represents the hardware interface for the Juego v1 device +/// +public class JuegoHardwareV1 : IJuegoHardware { + /// + protected IF7FeatherMeadowDevice Device { get; } + + /// + public IPixelDisplay? Display { get; } + + /// + protected ISpiBus? SpiBus { get; } + + /// + public AnalogJoystick? AnalogJoystick { get; protected set; } + + /// + public PushButton? Right_UpButton { get; protected set; } + /// + public PushButton? Right_DownButton { get; protected set; } + /// + public PushButton? Right_LeftButton { get; protected set; } + /// + public PushButton? Right_RightButton { get; protected set; } + /// + public PushButton? Left_UpButton => null; + /// + public PushButton? Left_DownButton => null; + /// + public PushButton? Left_LeftButton => null; + /// + public PushButton? Left_RightButton => null; + /// + public PushButton? StartButton { get; protected set; } + /// + public PushButton? SelectButton { get; protected set; } + /// + public PiezoSpeaker? LeftSpeaker { get; protected set; } + /// + public PiezoSpeaker? RightSpeaker { get; protected set; } + /// + public PwmLed? BlinkyLed => null; + + /// + public Bmi270? MotionSensor => null; + + /// + public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0]!; + + /// + public I2cConnector? Qwiic => null; + + /// - /// Represents the hardware interface for the Juego v1 device + /// Collection of connectors on the Juego board /// - public class JuegoHardwareV1 : IJuegoHardware + public IConnector?[] Connectors { - /// - protected IF7FeatherMeadowDevice Device { get; } - - /// - public IGraphicsDisplay Display { get; } - - /// - protected ISpiBus SpiBus { get; } - - /// - public AnalogJoystick? AnalogJoystick { get; protected set; } - - /// - public PushButton? Right_UpButton { get; protected set; } - /// - public PushButton? Right_DownButton { get; protected set; } - /// - public PushButton? Right_LeftButton { get; protected set; } - /// - public PushButton? Right_RightButton { get; protected set; } - /// - public PushButton? Left_UpButton => null; - /// - public PushButton? Left_DownButton => null; - /// - public PushButton? Left_LeftButton => null; - /// - public PushButton? Left_RightButton => null; - /// - public PushButton? StartButton { get; protected set; } - /// - public PushButton? SelectButton { get; protected set; } - /// - public PiezoSpeaker? LeftSpeaker { get; protected set; } - /// - public PiezoSpeaker? RightSpeaker { get; protected set; } - /// - public PwmLed? BlinkyLed => null; - - /// - public Bmi270? MotionSensor => null; - - /// - public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0]; - - /// - public I2cConnector Qwiic => null; - - - /// - /// Collection of connectors on the Juego board - /// - public IConnector?[] Connectors + get { - get + if (_connectors == null) { - if (_connectors == null) - { - _connectors = new IConnector[1]; - _connectors[0] = CreateDisplayConnector(); - } - - return _connectors; + _connectors = new IConnector[1]; + _connectors[0] = CreateDisplayConnector(); } + + return _connectors; } + } - private IConnector?[]? _connectors; + private IConnector?[]? _connectors; - /// - /// Create a new Juego hardware v1 object - /// - public JuegoHardwareV1(IF7FeatherMeadowDevice device) - { - Device = device; + /// + /// Create a new Juego hardware v1 object + /// + public JuegoHardwareV1(IF7FeatherMeadowDevice device) + { + Device = device; - Resolver.Log.Info("Initialize hardware..."); + Resolver.Log.Info("Initialize hardware..."); - try - { - LeftSpeaker = new PiezoSpeaker(device.Pins.D12); - } - catch (Exception e) - { - Resolver.Log.Error($"Err Left Speaker: {e.Message}"); - } - try - { - RightSpeaker = new PiezoSpeaker(device.Pins.D13); - } - catch (Exception e) - { - Resolver.Log.Error($"Err Right Speaker: {e.Message}"); - } + try + { + LeftSpeaker = new PiezoSpeaker(device.Pins.D12); + } + catch (Exception e) + { + Resolver.Log.Error($"Err Left Speaker: {e.Message}"); + } + try + { + RightSpeaker = new PiezoSpeaker(device.Pins.D13); + } + catch (Exception e) + { + Resolver.Log.Error($"Err Right Speaker: {e.Message}"); + } - try - { - var config = new SpiClockConfiguration(new Frequency(48000, Frequency.UnitType.Kilohertz), SpiClockConfiguration.Mode.Mode0); - SpiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.COPI, Device.Pins.CIPO, config); - Resolver.Log.Info("SPI initialized"); - } - catch (Exception e) - { - Resolver.Log.Error($"Err initializing SPI: {e.Message}"); - } + try + { + var config = new SpiClockConfiguration(new Frequency(24, Frequency.UnitType.Megahertz), SpiClockConfiguration.Mode.Mode0); + SpiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.COPI, Device.Pins.CIPO, config); + Resolver.Log.Info("SPI initialized"); + } + catch (Exception e) + { + Resolver.Log.Error($"Err initializing SPI: {e.Message}"); + } - var chipSelectPort = Device.CreateDigitalOutputPort(Device.Pins.D03); - var dcPort = Device.CreateDigitalOutputPort(Device.Pins.D04); - var resetPort = Device.CreateDigitalOutputPort(Device.Pins.D14); + var chipSelectPort = Device.CreateDigitalOutputPort(Device.Pins.D03); + var dcPort = Device.CreateDigitalOutputPort(Device.Pins.D04); + var resetPort = Device.CreateDigitalOutputPort(Device.Pins.D14); + if (SpiBus != null) + { Display = new St7789( spiBus: SpiBus, chipSelectPort: chipSelectPort, @@ -133,29 +134,29 @@ public JuegoHardwareV1(IF7FeatherMeadowDevice device) resetPort: resetPort, width: 240, height: 240); Resolver.Log.Info("Display initialized"); - - Right_UpButton = new PushButton(device.Pins.D06, ResistorMode.InternalPullDown); - Right_DownButton = new PushButton(device.Pins.D05, ResistorMode.InternalPullDown); - Right_LeftButton = new PushButton(device.Pins.D12, ResistorMode.InternalPullDown); - Right_RightButton = new PushButton(device.Pins.D11, ResistorMode.InternalPullDown); - StartButton = new PushButton(device.Pins.D13, ResistorMode.InternalPullDown); - SelectButton = new PushButton(device.Pins.D15, ResistorMode.InternalPullDown); } - internal DisplayConnector CreateDisplayConnector() - { - Resolver.Log.Trace("Creating display connector"); - - return new DisplayConnector( - "Display", - new PinMapping - { - new PinMapping.PinAlias(DisplayConnector.PinNames.CS, Device.Pins.D03), - new PinMapping.PinAlias(DisplayConnector.PinNames.RST, Device.Pins.D14), - new PinMapping.PinAlias(DisplayConnector.PinNames.DC, Device.Pins.D04), - new PinMapping.PinAlias(DisplayConnector.PinNames.CLK, Device.Pins.SCK), - new PinMapping.PinAlias(DisplayConnector.PinNames.COPI, Device.Pins.COPI), - }); - } + Right_UpButton = new PushButton(device.Pins.D06, ResistorMode.InternalPullDown); + Right_DownButton = new PushButton(device.Pins.D05, ResistorMode.InternalPullDown); + Right_LeftButton = new PushButton(device.Pins.D12, ResistorMode.InternalPullDown); + Right_RightButton = new PushButton(device.Pins.D11, ResistorMode.InternalPullDown); + StartButton = new PushButton(device.Pins.D13, ResistorMode.InternalPullDown); + SelectButton = new PushButton(device.Pins.D15, ResistorMode.InternalPullDown); + } + + internal DisplayConnector CreateDisplayConnector() + { + Resolver.Log.Trace("Creating display connector"); + + return new DisplayConnector( + "Display", + new PinMapping + { + new PinMapping.PinAlias(DisplayConnector.PinNames.CS, Device.Pins.D03), + new PinMapping.PinAlias(DisplayConnector.PinNames.RST, Device.Pins.D14), + new PinMapping.PinAlias(DisplayConnector.PinNames.DC, Device.Pins.D04), + new PinMapping.PinAlias(DisplayConnector.PinNames.CLK, Device.Pins.SCK), + new PinMapping.PinAlias(DisplayConnector.PinNames.COPI, Device.Pins.COPI), + }); } } \ No newline at end of file diff --git a/Source/Juego/JuegoHardwareV2.cs b/Source/Juego/JuegoHardwareV2.cs index ca2dd8d..a0bf6db 100644 --- a/Source/Juego/JuegoHardwareV2.cs +++ b/Source/Juego/JuegoHardwareV2.cs @@ -1,179 +1,180 @@ -using Meadow; -using Meadow.Foundation.Audio; +using Meadow.Foundation.Audio; using Meadow.Foundation.Displays; -using Meadow.Foundation.Graphics; using Meadow.Foundation.ICs.IOExpanders; using Meadow.Foundation.Leds; using Meadow.Foundation.Sensors.Accelerometers; using Meadow.Foundation.Sensors.Buttons; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Units; using System; using System.Threading; -namespace WildernessLabs.Hardware.Juego +namespace Meadow.Devices; + +/// +/// Represents the hardware interface for the Juego v2 device +/// +public class JuegoHardwareV2 : IJuegoHardware { - /// - /// Represents the hardware interface for the Juego v2 device - /// - public class JuegoHardwareV2 : IJuegoHardware + /// + protected IF7CoreComputeMeadowDevice Device { get; } + /// + protected IDigitalInterruptPort? McpInterrupt_1 { get; } + /// + protected IDigitalInterruptPort? McpInterrupt_2 { get; } + /// + protected IDigitalOutputPort? Mcp_Reset { get; } + /// + public IPixelDisplay? Display { get; } + /// + public IDigitalOutputPort? DisplayBacklightPort { get; } + /// + protected II2cBus I2cBus { get; } + /// + protected ISpiBus? SpiBus { get; } + /// + public Mcp23008? Mcp_1 { get; protected set; } + /// + public Mcp23008? Mcp_2 { get; protected set; } + /// + public Mcp23008? Mcp_VersionInfo { get; set; } + /// + public PushButton? Right_UpButton { get; protected set; } + /// + public PushButton? Right_DownButton { get; protected set; } + /// + public PushButton? Right_LeftButton { get; protected set; } + /// + public PushButton? Right_RightButton { get; protected set; } + /// + public PushButton? Left_UpButton { get; protected set; } + /// + public PushButton? Left_DownButton { get; protected set; } + /// + public PushButton? Left_LeftButton { get; protected set; } + /// + public PushButton? Left_RightButton { get; protected set; } + /// + public PushButton? StartButton { get; protected set; } + /// + public PushButton? SelectButton { get; protected set; } + /// + public PiezoSpeaker? LeftSpeaker { get; set; } + /// + public PiezoSpeaker? RightSpeaker { get; set; } + /// + public PwmLed? BlinkyLed { get; protected set; } + /// + public Bmi270? MotionSensor => null; + + /// + public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0]!; + + /// + public I2cConnector? Qwiic => null; + + /// + public IConnector?[] Connectors { - /// - protected IF7CoreComputeMeadowDevice Device { get; } - /// - protected IDigitalInterruptPort McpInterrupt_1 { get; } - /// - protected IDigitalInterruptPort McpInterrupt_2 { get; } - /// - protected IDigitalOutputPort Mcp_Reset { get; } - /// - public IGraphicsDisplay Display { get; } - /// - public IDigitalOutputPort DisplayBacklightPort { get; } - /// - protected II2cBus I2cBus { get; } - /// - protected ISpiBus SpiBus { get; } - /// - public Mcp23008 Mcp_1 { get; protected set; } - /// - public Mcp23008 Mcp_2 { get; protected set; } - /// - public Mcp23008 Mcp_VersionInfo { get; set; } - /// - public PushButton? Right_UpButton { get; protected set; } - /// - public PushButton? Right_DownButton { get; protected set; } - /// - public PushButton? Right_LeftButton { get; protected set; } - /// - public PushButton? Right_RightButton { get; protected set; } - /// - public PushButton? Left_UpButton { get; protected set; } - /// - public PushButton? Left_DownButton { get; protected set; } - /// - public PushButton? Left_LeftButton { get; protected set; } - /// - public PushButton? Left_RightButton { get; protected set; } - /// - public PushButton? StartButton { get; protected set; } - /// - public PushButton? SelectButton { get; protected set; } - /// - public PiezoSpeaker? LeftSpeaker { get; set; } - /// - public PiezoSpeaker? RightSpeaker { get; set; } - /// - public PwmLed? BlinkyLed { get; protected set; } - /// - public Bmi270? MotionSensor => null; - - /// - public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0]; - - /// - public I2cConnector? Qwiic => null; - - /// - public IConnector?[] Connectors + get { - get + if (_connectors == null) { - if (_connectors == null) - { - _connectors = new IConnector[1]; - _connectors[0] = CreateDisplayConnector(); - } - - return _connectors; + _connectors = new IConnector[1]; + _connectors[0] = CreateDisplayConnector(); } + + return _connectors; } + } - private IConnector?[]? _connectors; + private IConnector?[]? _connectors; - /// - /// Create a new Juego hardware v2 object - /// - public JuegoHardwareV2(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) + /// + /// Create a new Juego hardware v2 object + /// + public JuegoHardwareV2(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) + { + Device = device; + I2cBus = i2cBus; + + Resolver.Log.Info("Initialize hardware..."); + + // DEV NOTE: **ALWAYS** Set up PWMs first - Nuttx PWM driver will step on pin configs otherwise + /* try - code left intentionally, restore once the PWM bug is fixed + { + LeftSpeaker = new PiezoSpeaker(device.Pins.PB8); //D03 + } + catch (Exception e) + { + Resolver.Log.Error($"Err Left Speaker: {e.Message}"); + } + + try + { + RightSpeaker = new PiezoSpeaker(device.Pins.PB9); //D04 + } + catch (Exception e) + { + Resolver.Log.Error($"Err Right Speaker: {e.Message}"); + } */ + + try { - Device = device; - I2cBus = i2cBus; - - Resolver.Log.Info("Initialize hardware..."); - - // DEV NOTE: **ALWAYS** Set up PWMs first - Nuttx PWM driver will step on pin configs otherwise - /* try - code left intentionally, restore once the PWM bug is fixed - { - LeftSpeaker = new PiezoSpeaker(device.Pins.PB8); //D03 - } - catch (Exception e) - { - Resolver.Log.Error($"Err Left Speaker: {e.Message}"); - } - - try - { - RightSpeaker = new PiezoSpeaker(device.Pins.PB9); //D04 - } - catch (Exception e) - { - Resolver.Log.Error($"Err Right Speaker: {e.Message}"); - } */ - - try - { - Mcp_Reset = Device.CreateDigitalOutputPort(Device.Pins.D11, true); - McpInterrupt_1 = Device.CreateDigitalInterruptPort(Device.Pins.D09, InterruptMode.EdgeRising); - Mcp_1 = new Mcp23008(I2cBus, 0x20, McpInterrupt_1, Mcp_Reset); - Resolver.Log.Info("Mcp23008 #1 initialized"); - } - catch (Exception e) - { - Resolver.Log.Error($"Err MCP 1: {e.Message}"); - } + Mcp_Reset = Device.CreateDigitalOutputPort(Device.Pins.D11, true); + McpInterrupt_1 = Device.CreateDigitalInterruptPort(Device.Pins.D09, InterruptMode.EdgeRising); + Mcp_1 = new Mcp23008(I2cBus, 0x20, McpInterrupt_1, Mcp_Reset); + Resolver.Log.Info("Mcp23008 #1 initialized"); + } + catch (Exception e) + { + Resolver.Log.Error($"Err MCP 1: {e.Message}"); + } - try - { - McpInterrupt_2 = Device.CreateDigitalInterruptPort(Device.Pins.D10, InterruptMode.EdgeRising); - Mcp_2 = new Mcp23008(I2cBus, 0x21, McpInterrupt_2); - Resolver.Log.Info("Mcp23008 #2 initialized"); - } - catch (Exception e) - { - Resolver.Log.Error($"Err MCP 2: {e.Message}"); - } + try + { + McpInterrupt_2 = Device.CreateDigitalInterruptPort(Device.Pins.D10, InterruptMode.EdgeRising); + Mcp_2 = new Mcp23008(I2cBus, 0x21, McpInterrupt_2); + Resolver.Log.Info("Mcp23008 #2 initialized"); + } + catch (Exception e) + { + Resolver.Log.Error($"Err MCP 2: {e.Message}"); + } - try - { - BlinkyLed = new PwmLed(device.Pins.D20, TypicalForwardVoltage.Green); - } - catch (Exception e) - { - Resolver.Log.Error($"Err BlinkyLed: {e.Message}"); - } + try + { + BlinkyLed = new PwmLed(device.Pins.D20, TypicalForwardVoltage.Green); + } + catch (Exception e) + { + Resolver.Log.Error($"Err BlinkyLed: {e.Message}"); + } - try - { - var config = new SpiClockConfiguration(new Frequency(48000, Frequency.UnitType.Kilohertz), SpiClockConfiguration.Mode.Mode0); - SpiBus = Device.CreateSpiBus(Device.Pins.SPI5_SCK, Device.Pins.SPI5_COPI, Device.Pins.SPI5_CIPO, config); - } - catch (Exception e) - { - Resolver.Log.Error($"Err initializing SPI: {e.Message}"); - } - Resolver.Log.Info("SPI initialized"); + try + { + var config = new SpiClockConfiguration(new Frequency(24, Frequency.UnitType.Megahertz), SpiClockConfiguration.Mode.Mode0); + SpiBus = Device.CreateSpiBus(Device.Pins.SPI5_SCK, Device.Pins.SPI5_COPI, Device.Pins.SPI5_CIPO, config); + } + catch (Exception e) + { + Resolver.Log.Error($"Err initializing SPI: {e.Message}"); + } + Resolver.Log.Info("SPI initialized"); - if (Mcp_1 != null) - { - DisplayBacklightPort = Device.CreateDigitalOutputPort(Device.Pins.D05, true); + if (Mcp_1 != null) + { + DisplayBacklightPort = Device.CreateDigitalOutputPort(Device.Pins.D05, true); - var chipSelectPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP5); - var dcPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP6); - var resetPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP7); + var chipSelectPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP5); + var dcPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP6); + var resetPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP7); - Thread.Sleep(50); + Thread.Sleep(50); + if (SpiBus != null) + { Display = new Ili9341( spiBus: SpiBus, chipSelectPort: chipSelectPort, @@ -181,58 +182,64 @@ public JuegoHardwareV2(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) resetPort: resetPort, width: 240, height: 320) { - SpiBusSpeed = new Frequency(48000, Frequency.UnitType.Kilohertz), + SpiBusSpeed = new Frequency(24, Frequency.UnitType.Megahertz), }; ((Ili9341)Display).SetRotation(RotationType._270Degrees); Resolver.Log.Info("Display initialized"); } + } - if (Mcp_1 != null) - { - var upPort = Mcp_1.Pins.GP1.CreateDigitalInterruptPort(InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var rightPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var downPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var leftPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - - Left_UpButton = new PushButton(upPort); - Left_RightButton = new PushButton(rightPort); - Left_DownButton = new PushButton(downPort); - Left_LeftButton = new PushButton(leftPort); - } - - if (Mcp_2 != null) - { - var upPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP5, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var rightPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var downPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var leftPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var startPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP1, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var selectPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP0, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - - Right_UpButton = new PushButton(upPort); - Right_RightButton = new PushButton(rightPort); - Right_DownButton = new PushButton(downPort); - Right_LeftButton = new PushButton(leftPort); - StartButton = new PushButton(startPort); - SelectButton = new PushButton(selectPort); - } + if (Mcp_1 != null) + { + var upPort = Mcp_1.Pins.GP1.CreateDigitalInterruptPort(InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var rightPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var downPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var leftPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + + Left_UpButton = new PushButton(upPort); + Left_RightButton = new PushButton(rightPort); + Left_DownButton = new PushButton(downPort); + Left_LeftButton = new PushButton(leftPort); } - internal DisplayConnector CreateDisplayConnector() + + if (Mcp_2 != null) { - Resolver.Log.Trace("Creating display connector"); + var upPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP5, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var rightPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var downPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var leftPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var startPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP1, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var selectPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP0, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + + Right_UpButton = new PushButton(upPort); + Right_RightButton = new PushButton(rightPort); + Right_DownButton = new PushButton(downPort); + Right_LeftButton = new PushButton(leftPort); + StartButton = new PushButton(startPort); + SelectButton = new PushButton(selectPort); + } + } - return new DisplayConnector( - "Display", - new PinMapping - { - new PinMapping.PinAlias(DisplayConnector.PinNames.CS, Mcp_1.Pins.GP5), - new PinMapping.PinAlias(DisplayConnector.PinNames.RST, Mcp_1.Pins.GP7), - new PinMapping.PinAlias(DisplayConnector.PinNames.DC, Mcp_1.Pins.GP6), - new PinMapping.PinAlias(DisplayConnector.PinNames.CLK, Device.Pins.SCK), - new PinMapping.PinAlias(DisplayConnector.PinNames.COPI, Device.Pins.COPI), - }); + internal DisplayConnector? CreateDisplayConnector() + { + Resolver.Log.Trace("Creating display connector"); + + if (Mcp_1 == null) + { + return null; } + + return new DisplayConnector( + "Display", + new PinMapping + { + new PinMapping.PinAlias(DisplayConnector.PinNames.CS, Mcp_1.Pins.GP5), + new PinMapping.PinAlias(DisplayConnector.PinNames.RST, Mcp_1.Pins.GP7), + new PinMapping.PinAlias(DisplayConnector.PinNames.DC, Mcp_1.Pins.GP6), + new PinMapping.PinAlias(DisplayConnector.PinNames.CLK, Device.Pins.SCK), + new PinMapping.PinAlias(DisplayConnector.PinNames.COPI, Device.Pins.COPI), + }); } } \ No newline at end of file diff --git a/Source/Juego/JuegoHardwareV3.cs b/Source/Juego/JuegoHardwareV3.cs index 2238a28..f658689 100644 --- a/Source/Juego/JuegoHardwareV3.cs +++ b/Source/Juego/JuegoHardwareV3.cs @@ -1,168 +1,169 @@ -using Meadow; -using Meadow.Foundation.Audio; +using Meadow.Foundation.Audio; using Meadow.Foundation.Displays; -using Meadow.Foundation.Graphics; using Meadow.Foundation.ICs.IOExpanders; using Meadow.Foundation.Leds; using Meadow.Foundation.Sensors.Accelerometers; using Meadow.Foundation.Sensors.Buttons; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Units; using System; using System.Threading; -namespace WildernessLabs.Hardware.Juego +namespace Meadow.Devices; + +/// +/// Represents the hardware interface for the Juego v1 device +/// +public class JuegoHardwareV3 : IJuegoHardware { /// - /// Represents the hardware interface for the Juego v1 device + /// The minimum hardware version for Juego v3 hardware + /// + public static int MinimumHardareVersion => 4; + + /// + protected IF7CoreComputeMeadowDevice Device { get; } + /// + protected IDigitalInterruptPort? McpInterrupt_1 { get; } + /// + protected IDigitalInterruptPort? McpInterrupt_2 { get; } + /// + protected IDigitalOutputPort? Mcp_Reset { get; } + /// + public IPixelDisplay? Display { get; } + /// + public IDigitalOutputPort? DisplayBacklightPort { get; } + /// + protected II2cBus I2cBus { get; } + /// + protected ISpiBus? SpiBus { get; } + /// + public Mcp23008? Mcp_1 { get; protected set; } + /// + public Mcp23008? Mcp_2 { get; protected set; } + /// + public Mcp23008? Mcp_VersionInfo { get; set; } + /// + public PushButton? Right_UpButton { get; protected set; } + /// + public PushButton? Right_DownButton { get; protected set; } + /// + public PushButton? Right_LeftButton { get; protected set; } + /// + public PushButton? Right_RightButton { get; protected set; } + /// + public PushButton? Left_UpButton { get; protected set; } + /// + public PushButton? Left_DownButton { get; protected set; } + /// + public PushButton? Left_LeftButton { get; protected set; } + /// + public PushButton? Left_RightButton { get; protected set; } + /// + public PushButton? StartButton { get; protected set; } + /// + public PushButton? SelectButton { get; protected set; } + /// + public PiezoSpeaker? LeftSpeaker { get; set; } + /// + public PiezoSpeaker? RightSpeaker { get; set; } + /// + public PwmLed? BlinkyLed { get; protected set; } + /// + public Bmi270? MotionSensor { get; protected set; } + + /// + public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0]!; + + /// + public I2cConnector? Qwiic => (I2cConnector?)Connectors[1]; + + /// + /// Collection of connectors on the Juego board /// - public class JuegoHardwareV3 : IJuegoHardware + public IConnector?[] Connectors { - /// - /// The minimum hardware version for Juego v3 hardware - /// - public static int MinimumHardareVersion => 3; - - /// - protected IF7CoreComputeMeadowDevice Device { get; } - /// - protected IDigitalInterruptPort McpInterrupt_1 { get; } - /// - protected IDigitalInterruptPort McpInterrupt_2 { get; } - /// - protected IDigitalOutputPort Mcp_Reset { get; } - /// - public IGraphicsDisplay Display { get; } - /// - public IDigitalOutputPort DisplayBacklightPort { get; } - /// - protected II2cBus I2cBus { get; } - /// - protected ISpiBus SpiBus { get; } - /// - public Mcp23008 Mcp_1 { get; protected set; } - /// - public Mcp23008 Mcp_2 { get; protected set; } - /// - public Mcp23008 Mcp_VersionInfo { get; set; } - /// - public PushButton? Right_UpButton { get; protected set; } - /// - public PushButton? Right_DownButton { get; protected set; } - /// - public PushButton? Right_LeftButton { get; protected set; } - /// - public PushButton? Right_RightButton { get; protected set; } - /// - public PushButton? Left_UpButton { get; protected set; } - /// - public PushButton? Left_DownButton { get; protected set; } - /// - public PushButton? Left_LeftButton { get; protected set; } - /// - public PushButton? Left_RightButton { get; protected set; } - /// - public PushButton? StartButton { get; protected set; } - /// - public PushButton? SelectButton { get; protected set; } - /// - public PiezoSpeaker? LeftSpeaker { get; set; } - /// - public PiezoSpeaker? RightSpeaker { get; set; } - /// - public PwmLed? BlinkyLed { get; protected set; } - /// - public Bmi270? MotionSensor { get; protected set; } - - /// - public DisplayConnector DisplayHeader => (DisplayConnector)Connectors[0]; - - /// - public I2cConnector? Qwiic => (I2cConnector)Connectors[1]; - - /// - /// Collection of connectors on the Juego board - /// - public IConnector?[] Connectors + get { - get + if (_connectors == null) { - if (_connectors == null) - { - _connectors = new IConnector[2]; - _connectors[0] = CreateDisplayConnector(); - _connectors[1] = CreateQwiicConnector(); - } - - return _connectors; + _connectors = new IConnector[2]; + _connectors[0] = CreateDisplayConnector(); + _connectors[1] = CreateQwiicConnector(); } + + return _connectors; } + } - private IConnector?[]? _connectors; + private IConnector?[]? _connectors; - /// - /// Create a new Juego hardware v3 object - /// - public JuegoHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) - { - Device = device; - I2cBus = i2cBus; + /// + /// Create a new Juego hardware v3 object + /// + public JuegoHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) + { + Device = device; + I2cBus = i2cBus; - Resolver.Log.Info("Initialize hardware..."); + Resolver.Log.Info("Initialize hardware..."); - try - { - Mcp_Reset = Device.CreateDigitalOutputPort(Device.Pins.PA10, true); - McpInterrupt_1 = Device.CreateDigitalInterruptPort(Device.Pins.PD5, InterruptMode.EdgeRising); - Mcp_1 = new Mcp23008(I2cBus, 0x20, McpInterrupt_1, Mcp_Reset); - Resolver.Log.Info("Mcp23008 #1 initialized"); - } - catch (Exception e) - { - Resolver.Log.Error($"Err MCP 1: {e.Message}"); - } + try + { + Mcp_Reset = Device.CreateDigitalOutputPort(Device.Pins.PA10, true); + McpInterrupt_1 = Device.CreateDigitalInterruptPort(Device.Pins.PD5, InterruptMode.EdgeRising); + Mcp_1 = new Mcp23008(I2cBus, 0x20, McpInterrupt_1, Mcp_Reset); + Resolver.Log.Info("Mcp23008 #1 initialized"); + } + catch (Exception e) + { + Resolver.Log.Error($"Err MCP 1: {e.Message}"); + } - try - { - McpInterrupt_2 = Device.CreateDigitalInterruptPort(Device.Pins.PI11, InterruptMode.EdgeRising); - Mcp_2 = new Mcp23008(I2cBus, 0x21, McpInterrupt_2); - Resolver.Log.Info("Mcp23008 #2 initialized"); - } - catch (Exception e) - { - Resolver.Log.Error($"Err MCP 2: {e.Message}"); - } + try + { + McpInterrupt_2 = Device.CreateDigitalInterruptPort(Device.Pins.PI11, InterruptMode.EdgeRising); + Mcp_2 = new Mcp23008(I2cBus, 0x21, McpInterrupt_2); + Resolver.Log.Info("Mcp23008 #2 initialized"); + } + catch (Exception e) + { + Resolver.Log.Error($"Err MCP 2: {e.Message}"); + } - try - { - BlinkyLed = new PwmLed(device.Pins.D20, TypicalForwardVoltage.Green); - } - catch (Exception e) - { - Resolver.Log.Error($"Err BlinkyLed: {e.Message}"); - } + try + { + BlinkyLed = new PwmLed(device.Pins.D20, TypicalForwardVoltage.Green); + } + catch (Exception e) + { + Resolver.Log.Error($"Err BlinkyLed: {e.Message}"); + } - try - { - var config = new SpiClockConfiguration(new Frequency(48000, Frequency.UnitType.Kilohertz), SpiClockConfiguration.Mode.Mode0); - SpiBus = Device.CreateSpiBus(Device.Pins.SPI5_SCK, Device.Pins.SPI5_COPI, Device.Pins.SPI5_CIPO, config); - } - catch (Exception e) - { - Resolver.Log.Error($"Err initializing SPI: {e.Message}"); - } - Resolver.Log.Info("SPI initialized"); + try + { + var config = new SpiClockConfiguration(new Frequency(24, Frequency.UnitType.Megahertz), SpiClockConfiguration.Mode.Mode0); + SpiBus = Device.CreateSpiBus(Device.Pins.SPI5_SCK, Device.Pins.SPI5_COPI, Device.Pins.SPI5_CIPO, config); + } + catch (Exception e) + { + Resolver.Log.Error($"Err initializing SPI: {e.Message}"); + } + Resolver.Log.Info("SPI initialized"); - if (Mcp_1 != null) - { - DisplayBacklightPort = Device.CreateDigitalOutputPort(Device.Pins.D05, true); + if (Mcp_1 != null) + { + DisplayBacklightPort = Device.CreateDigitalOutputPort(Device.Pins.D05, true); - var chipSelectPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP5); - var dcPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP6); - var resetPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP7); + var chipSelectPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP5); + var dcPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP6); + var resetPort = Mcp_1.CreateDigitalOutputPort(Mcp_1.Pins.GP7); - Thread.Sleep(50); + Thread.Sleep(50); + if (SpiBus != null) + { Display = new Ili9341( spiBus: SpiBus, chipSelectPort: chipSelectPort, @@ -170,84 +171,89 @@ public JuegoHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus) resetPort: resetPort, width: 240, height: 320) { - SpiBusSpeed = new Frequency(48000, Frequency.UnitType.Kilohertz), + SpiBusSpeed = new Frequency(24, Frequency.UnitType.Megahertz), }; ((Ili9341)Display).SetRotation(RotationType._270Degrees); Resolver.Log.Info("Display initialized"); } + } - try - { - Resolver.Log.Info("Instantiating motion sensor"); - MotionSensor = new Bmi270(I2cBus); - Resolver.Log.Info("Motion sensor up"); - } - catch (Exception ex) - { - Resolver.Log.Error($"Unable to create the BMI270 IMU: {ex.Message}"); - } + try + { + Resolver.Log.Info("Instantiating motion sensor"); + MotionSensor = new Bmi270(I2cBus); + Resolver.Log.Info("Motion sensor up"); + } + catch (Exception ex) + { + Resolver.Log.Error($"Unable to create the BMI270 IMU: {ex.Message}"); + } - if (Mcp_1 != null) - { - var upPort = Mcp_1.Pins.GP1.CreateDigitalInterruptPort(InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var rightPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var downPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var leftPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - - Left_UpButton = new PushButton(upPort); - Left_RightButton = new PushButton(rightPort); - Left_DownButton = new PushButton(downPort); - Left_LeftButton = new PushButton(leftPort); - } + if (Mcp_1 != null) + { + var upPort = Mcp_1.Pins.GP1.CreateDigitalInterruptPort(InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var rightPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var downPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var leftPort = Mcp_1.CreateDigitalInterruptPort(Mcp_1.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - if (Mcp_2 != null) - { - var upPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP5, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var rightPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var downPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var leftPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var startPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP1, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - var selectPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP0, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - - Right_UpButton = new PushButton(upPort); - Right_RightButton = new PushButton(rightPort); - Right_DownButton = new PushButton(downPort); - Right_LeftButton = new PushButton(leftPort); - StartButton = new PushButton(startPort); - SelectButton = new PushButton(selectPort); - } + Left_UpButton = new PushButton(upPort); + Left_RightButton = new PushButton(rightPort); + Left_DownButton = new PushButton(downPort); + Left_LeftButton = new PushButton(leftPort); } - internal DisplayConnector CreateDisplayConnector() + if (Mcp_2 != null) { - Resolver.Log.Trace("Creating display connector"); + var upPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP5, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var rightPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP4, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var downPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP3, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var leftPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP2, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var startPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP1, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); + var selectPort = Mcp_2.CreateDigitalInterruptPort(Mcp_2.Pins.GP0, InterruptMode.EdgeBoth, ResistorMode.InternalPullUp); - return new DisplayConnector( - "Display", - new PinMapping - { - new PinMapping.PinAlias(DisplayConnector.PinNames.CS, Mcp_1.Pins.GP5), - new PinMapping.PinAlias(DisplayConnector.PinNames.RST, Mcp_1.Pins.GP7), - new PinMapping.PinAlias(DisplayConnector.PinNames.DC, Mcp_1.Pins.GP6), - new PinMapping.PinAlias(DisplayConnector.PinNames.CLK, Device.Pins.SCK), - new PinMapping.PinAlias(DisplayConnector.PinNames.COPI, Device.Pins.COPI), - }); + Right_UpButton = new PushButton(upPort); + Right_RightButton = new PushButton(rightPort); + Right_DownButton = new PushButton(downPort); + Right_LeftButton = new PushButton(leftPort); + StartButton = new PushButton(startPort); + SelectButton = new PushButton(selectPort); } + } - internal I2cConnector CreateQwiicConnector() - { - Resolver.Log.Trace("Creating Qwiic I2C connector"); + internal DisplayConnector? CreateDisplayConnector() + { + Resolver.Log.Trace("Creating display connector"); - return new I2cConnector( - "Qwiic", - new PinMapping - { - new PinMapping.PinAlias(I2cConnector.PinNames.SCL, Device.Pins.D08), - new PinMapping.PinAlias(I2cConnector.PinNames.SDA, Device.Pins.D07), - }, - new I2cBusMapping(Device, 1)); + if (Mcp_1 == null) + { + return null; } + + return new DisplayConnector( + "Display", + new PinMapping + { + new PinMapping.PinAlias(DisplayConnector.PinNames.CS, Mcp_1.Pins.GP5), + new PinMapping.PinAlias(DisplayConnector.PinNames.RST, Mcp_1.Pins.GP7), + new PinMapping.PinAlias(DisplayConnector.PinNames.DC, Mcp_1.Pins.GP6), + new PinMapping.PinAlias(DisplayConnector.PinNames.CLK, Device.Pins.SCK), + new PinMapping.PinAlias(DisplayConnector.PinNames.COPI, Device.Pins.COPI), + }); + } + + internal I2cConnector CreateQwiicConnector() + { + Resolver.Log.Trace("Creating Qwiic I2C connector"); + + return new I2cConnector( + "Qwiic", + new PinMapping + { + new PinMapping.PinAlias(I2cConnector.PinNames.SCL, Device.Pins.D08), + new PinMapping.PinAlias(I2cConnector.PinNames.SDA, Device.Pins.D07), + }, + new I2cBusMapping(Device, 1)); } } \ No newline at end of file diff --git a/Source/Juego_Demo/DisplayController.cs b/Source/Juego_Demo/DisplayController.cs index 8dea4c9..228d1bb 100644 --- a/Source/Juego_Demo/DisplayController.cs +++ b/Source/Juego_Demo/DisplayController.cs @@ -1,6 +1,7 @@ using Meadow; using Meadow.Foundation; using Meadow.Foundation.Graphics; +using Meadow.Peripherals.Displays; using Meadow.Units; namespace Juego_Demo @@ -133,7 +134,7 @@ public bool SelectButtonState bool isUpdating = false; bool needsUpdate = false; - public DisplayController(IGraphicsDisplay display) + public DisplayController(IPixelDisplay display) { graphics = new MicroGraphics(display) { diff --git a/Source/Juego_Demo/MeadowApp.cs b/Source/Juego_Demo/MeadowApp.cs index 5d13936..83483ca 100644 --- a/Source/Juego_Demo/MeadowApp.cs +++ b/Source/Juego_Demo/MeadowApp.cs @@ -4,7 +4,6 @@ using Meadow.Units; using System; using System.Threading.Tasks; -using WildernessLabs.Hardware.Juego; namespace Juego_Demo { @@ -90,8 +89,11 @@ public override Task Initialize() startButton.PressEnded += (s, e) => displayController.StartButtonState = false; } - audioLeft = new MicroAudio(juego.LeftSpeaker); - audioRight = new MicroAudio(juego.RightSpeaker); + if (juego.LeftSpeaker != null) + { + audioLeft = new MicroAudio(juego.LeftSpeaker); + audioRight = new MicroAudio(juego.RightSpeaker); + } return Task.CompletedTask; } @@ -107,8 +109,11 @@ public async override Task Run() juego.MotionSensor.StartUpdating(TimeSpan.FromMilliseconds(250)); } - await audioLeft.PlaySystemSound(SystemSoundEffect.PowerUp); - await audioRight.PlayGameSound(GameSoundEffect.LevelComplete); + if (juego.LeftSpeaker != null) + { + await audioLeft.PlaySystemSound(SystemSoundEffect.PowerUp); + await audioRight.PlayGameSound(GameSoundEffect.LevelComplete); + } return; } diff --git a/Source/Juego_Prototype/Apps/Clock/Clock.Renderer.cs b/Source/Juego_Prototype/Apps/Clock/Clock.Renderer.cs index 5884e0e..ed0f28f 100644 --- a/Source/Juego_Prototype/Apps/Clock/Clock.Renderer.cs +++ b/Source/Juego_Prototype/Apps/Clock/Clock.Renderer.cs @@ -1,5 +1,4 @@ using Meadow; -using Meadow.Foundation; using Meadow.Foundation.Displays.UI; using Meadow.Foundation.Graphics; using System; @@ -32,13 +31,6 @@ public void Init(MicroGraphics gl) InitMenu(gl); return; - - gl.Clear(); - gl.DrawText(0, 0, "Meadow Clock"); - gl.DrawText(0, 16, "v0.1.0"); - gl.Show(); - - Thread.Sleep(500); } public void Update(IIOConfig ioConfig) diff --git a/Source/Juego_Prototype/Games/FrogIt/FrogItGame.Art.cs b/Source/Juego_Prototype/Games/FrogIt/FrogItGame.Art.cs index aa89c4a..f80a461 100644 --- a/Source/Juego_Prototype/Games/FrogIt/FrogItGame.Art.cs +++ b/Source/Juego_Prototype/Games/FrogIt/FrogItGame.Art.cs @@ -1,6 +1,5 @@ -using Juego; -using Meadow.Foundation.Graphics; -using Meadow.Foundation.Graphics.Buffers; +using Meadow.Foundation.Graphics.Buffers; +using Meadow.Peripherals.Displays; namespace Juego.Games { @@ -36,7 +35,7 @@ void InitBuffers() logDarkCenter = (new Buffer1bpp(8, 8, logDarkC)).RotateAndConvert(RotationType._90Degrees); logDarkRight = (new Buffer1bpp(8, 8, logDarkR)).RotateAndConvert(RotationType._90Degrees); - byte[] crocL= { 0x3f, 0x88, 0xc2, 0xe0, 0xf0, 0xa0, 0x01, 0xff }; //log left + byte[] crocL = { 0x3f, 0x88, 0xc2, 0xe0, 0xf0, 0xa0, 0x01, 0xff }; //log left byte[] crocC = { 0xff, 0x83, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x31 }; byte[] crocR = { 0xff, 0xff, 0xff, 0x0f, 0x07, 0x01, 0x70, 0xff }; @@ -67,18 +66,18 @@ void InitBuffers() { 0xe3, 0x3a, 0x5e, 0xfc, 0xfc, 0x5e, 0x3a, 0xe3 }, // {0x81, 0xE7, 0x3C, 0x7E, 0x7E, 0xDB, 0xBD, 0x99}, // Bigger logs - {0x3C, 0x7E, 0xD7, 0xB5, 0xAD, 0xBF, 0xFF, 0xED}, - {0xAD, 0xAD, 0xFF, 0xB7, 0xF5, 0xBF, 0xB7, 0xAD}, + {0x3C, 0x7E, 0xD7, 0xB5, 0xAD, 0xBF, 0xFF, 0xED}, + {0xAD, 0xAD, 0xFF, 0xB7, 0xF5, 0xBF, 0xB7, 0xAD}, {0xED, 0xBD, 0xC3, 0xBD, 0xA5, 0xBD, 0x42, 0x3C}, // Trucks {0x00, 0x7F, 0x41, 0x55, 0x55, 0x55, 0x55, 0x55}, - {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55}, + {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55}, {0x41, 0x7F, 0x22, 0x7F, 0x7F, 0x63, 0x22, 0x1C}, // Crocs {0x41, 0x63, 0x46, 0x6E, 0x7C, 0x7E, 0x7A, 0x3E}, - {0xBC, 0xFE, 0x7E, 0x3E, 0xBE, 0xBE, 0xFC, 0x7C}, + {0xBC, 0xFE, 0x7E, 0x3E, 0xBE, 0xBE, 0xFC, 0x7C}, {0x78, 0x38, 0x38, 0x38, 0x70, 0x60, 0x60, 0x40}, // Cars diff --git a/Source/Juego_Prototype/Games/Lander/LanderGame.Art.cs b/Source/Juego_Prototype/Games/Lander/LanderGame.Art.cs deleted file mode 100644 index 062d995..0000000 --- a/Source/Juego_Prototype/Games/Lander/LanderGame.Art.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Juego; - -namespace Juego.Games -{ - public partial class LanderGame - { - } -} \ No newline at end of file diff --git a/Source/Juego_Prototype/Games/Lander/LanderGame.Renderer.cs b/Source/Juego_Prototype/Games/Lander/LanderGame.Renderer.cs deleted file mode 100644 index b6cea15..0000000 --- a/Source/Juego_Prototype/Games/Lander/LanderGame.Renderer.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Meadow; -using Meadow.Foundation.Graphics; - -namespace Juego.Games -{ - public partial class LanderGame - { - readonly byte cellSize = 8; - - readonly DrawPixelDel DrawPixel; - - public void Init(MicroGraphics gl) - { - gl.Clear(); - gl.DrawText(0, 0, "Meadow Lander"); - gl.DrawText(0, 16, "v0.0.1"); - gl.Show(); - } - - public void Update(IIOConfig ioConfig) - { - var gl = ioConfig.Graphics; - - Update(); - - gl.Clear(); - DrawBackground(gl); - - // DrawLives(); - gl.Show(); - } - - void DrawBackground(MicroGraphics graphics) - { - - } - - void DrawLives(MicroGraphics graphics) - { - - } - - delegate void DrawPixelDel(int x, int y, bool colored, MicroGraphics graphics, Color color); - - void DrawPixel1x(int x, int y, bool colored, MicroGraphics graphics, Color color) - { - graphics.DrawPixel(x, y, colored ? color : Color.Black); - } - - void DrawPixel2x(int x, int y, bool colored, MicroGraphics graphics) - { - x *= 2; - y *= 2; - - graphics.DrawPixel(x, y, colored); - graphics.DrawPixel(x + 1, y, colored); - graphics.DrawPixel(x, y + 1, colored); - graphics.DrawPixel(x + 1, y + 1, colored); - } - - void DrawBitmap(int x, int y, int width, int height, byte[] bitmap, MicroGraphics graphics, Color color) - { - for (var ordinate = 0; ordinate < height; ordinate++) //y - { - for (var abscissa = 0; abscissa < width; abscissa++) //x - { - var b = bitmap[(ordinate * width) + abscissa]; - byte mask = 0x01; - - for (var pixel = 0; pixel < 8; pixel++) - { - DrawPixel(x + (8 * abscissa) + 7 - pixel, y + ordinate, (b & mask) > 0, graphics, color); - - mask <<= 1; - } - } - } - } - } -} \ No newline at end of file diff --git a/Source/Juego_Prototype/Games/Lander/LanderGame.cs b/Source/Juego_Prototype/Games/Lander/LanderGame.cs deleted file mode 100644 index 3e3426f..0000000 --- a/Source/Juego_Prototype/Games/Lander/LanderGame.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; - -namespace Juego.Games -{ - public partial class LanderGame : IGame - { - enum LanderState - { - Forward, - Left, - Right, - Dead - } - - LanderState landerState; - - public double GameTime { get; private set; } - public double TimeDelta => GameTime - lastTime; - - public double LanderX { get; set; } - public double LanderY { get; private set; } - - public int Lives { get; private set; } - - public int CellSize { get; private set; } - - - - DateTime gameStart; - UserInput lastInput; - - enum UserInput - { - None, - Up, - Down, - Left, - Right, - } - - public LanderGame(int cellSize = 8, int width = 128) - { - - Reset(); - } - - public void Reset() - { - gameStart = DateTime.UtcNow; - - Lives = 3; - - lastInput = UserInput.None; - } - - void ResetLander() - { - - } - - void GenerateGame() - { - - - - - } - - double lastTime; - public void Update() - { - lastTime = GameTime; - GameTime = (DateTime.UtcNow - gameStart).TotalSeconds; - - switch (lastInput) - { - case UserInput.Up: - - break; - case UserInput.Down: - - break; - case UserInput.Left: - - break; - case UserInput.Right: - - break; - } - //clear for next frame - lastInput = UserInput.None; - } - - public void Up() - { - lastInput = UserInput.Up; - } - - public void Down() - { - lastInput = UserInput.Down; - } - - public void Left() - { - lastInput = UserInput.Left; - } - - public void Right() - { - lastInput = UserInput.Right; - } - - void KillLander() - { - landerState = LanderState.Dead; - ResetLander(); - } - } -} \ No newline at end of file diff --git a/Source/Juego_Prototype/Games/SpaceRaid/SpaceRaid.Renderer.cs b/Source/Juego_Prototype/Games/SpaceRaid/SpaceRaid.Renderer.cs deleted file mode 100644 index 076b4c7..0000000 --- a/Source/Juego_Prototype/Games/SpaceRaid/SpaceRaid.Renderer.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Meadow.Foundation.Graphics; -using System; - -namespace Juego.Games -{ - public partial class SpaceRaid : IGame - { - int[] leftWall = new int[9]; - int[] rightWall = new int[9]; - - int offset = 0; - - - public void Init(MicroGraphics gl) - { - - } - - public void Update(IIOConfig ioConfig) - { - var gl = ioConfig.Graphics; - - gl.Clear(); - - gl.DrawText(0, 0, "Space"); - gl.DrawLine(0, 0, 10, 10, true); - - gl.Show(); - } - } -} diff --git a/Source/Juego_Prototype/Games/SpaceRaid/SpaceRaid.cs b/Source/Juego_Prototype/Games/SpaceRaid/SpaceRaid.cs deleted file mode 100644 index 67923f5..0000000 --- a/Source/Juego_Prototype/Games/SpaceRaid/SpaceRaid.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Juego.Games -{ - public partial class SpaceRaid : IGame - { - public void Down() - { - - } - - public void Left() - { - - } - - public void Reset() - { - - offset = 0; - - for(int i = 0; i < 9; i++) - { - leftWall[i] = 32; - rightWall[i] = 96; - } - } - - public void Right() - { - - } - - public void Up() - { - - } - } -} \ No newline at end of file diff --git a/Source/Juego_Prototype/IOConfig/Config_1a_St7789.cs b/Source/Juego_Prototype/IOConfig/Config_1a_St7789.cs index 8aeffbc..6a3106a 100644 --- a/Source/Juego_Prototype/IOConfig/Config_1a_St7789.cs +++ b/Source/Juego_Prototype/IOConfig/Config_1a_St7789.cs @@ -5,6 +5,7 @@ using Meadow.Foundation.Sensors.Buttons; using Meadow.Foundation.Sensors.Hid; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Peripherals.Leds; namespace Juego diff --git a/Source/Juego_Prototype/IOConfig/Config_1c_Ssd1351.cs b/Source/Juego_Prototype/IOConfig/Config_1c_Ssd1351.cs index f3a79d8..37bfc25 100644 --- a/Source/Juego_Prototype/IOConfig/Config_1c_Ssd1351.cs +++ b/Source/Juego_Prototype/IOConfig/Config_1c_Ssd1351.cs @@ -6,6 +6,7 @@ using Meadow.Foundation.Sensors.Buttons; using Meadow.Foundation.Sensors.Hid; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Peripherals.Leds; namespace Juego diff --git a/Source/Juego_Prototype/IOConfig/Config_1c_St7735.cs b/Source/Juego_Prototype/IOConfig/Config_1c_St7735.cs index 7f5faa3..30c0d5d 100644 --- a/Source/Juego_Prototype/IOConfig/Config_1c_St7735.cs +++ b/Source/Juego_Prototype/IOConfig/Config_1c_St7735.cs @@ -5,6 +5,7 @@ using Meadow.Foundation.Sensors.Buttons; using Meadow.Foundation.Sensors.Hid; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Peripherals.Leds; namespace Juego diff --git a/Source/Juego_Prototype/IOConfig/Config_1c_St7789.cs b/Source/Juego_Prototype/IOConfig/Config_1c_St7789.cs index 7ad1423..a260427 100644 --- a/Source/Juego_Prototype/IOConfig/Config_1c_St7789.cs +++ b/Source/Juego_Prototype/IOConfig/Config_1c_St7789.cs @@ -5,6 +5,7 @@ using Meadow.Foundation.Sensors.Buttons; using Meadow.Foundation.Sensors.Hid; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Peripherals.Leds; namespace Juego diff --git a/Source/Juego_Prototype/IOConfig/Config_proto_Sh1106_Spi.cs b/Source/Juego_Prototype/IOConfig/Config_proto_Sh1106_Spi.cs index a4c1b0a..e0917af 100644 --- a/Source/Juego_Prototype/IOConfig/Config_proto_Sh1106_Spi.cs +++ b/Source/Juego_Prototype/IOConfig/Config_proto_Sh1106_Spi.cs @@ -5,6 +5,7 @@ using Meadow.Foundation.Sensors.Buttons; using Meadow.Foundation.Sensors.Hid; using Meadow.Hardware; +using Meadow.Peripherals.Displays; using Meadow.Peripherals.Leds; namespace Juego diff --git a/Source/Juego_Prototype/Juego_Prototype.csproj b/Source/Juego_Prototype/Juego_Prototype.csproj index 0a4db35..f114ce9 100644 --- a/Source/Juego_Prototype/Juego_Prototype.csproj +++ b/Source/Juego_Prototype/Juego_Prototype.csproj @@ -16,12 +16,12 @@ - - - - - - + + + + + +