Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        /// <param name="memoryBitMapAllocation">The memory allocation.</param>
        public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
        {
            if (_isInitialized)
            {
                return;
            }

            // We're allocating anough memory for the full screen as this is a SPRAM board
            MemoryAllocationBitmap = memoryBitMapAllocation;
            BackLightPin           = -1;
            _power = M5Stack.M5Core2.Power;
            // Enable the screen
            Enabled = true;
            // Reset
            _power.Gpio4Value = PinValue.Low;
            Thread.Sleep(100);
            _power.Gpio4Value = PinValue.High;
            Thread.Sleep(100);
            // Create the screen
            DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap);

            // For M5Core2, values from 2.5 to 3V are working fine
            // 3.0V for the screen
            LuminosityPercentage = 100;
            _power.EnableDCDC3(true);
            _isInitialized = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        /// <param name="memoryBitMapAllocation">The memory allocation.</param>
        public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
        {
            if (_isInitialized)
            {
                return;
            }

            // We're allocating enough memory for the full screen because these targets have PSRAM
            MemoryAllocationBitmap = memoryBitMapAllocation;
            // backligth is not controlled by the screen driver
            BackLightPin = -1;

#if M5CORE2
            _power = M5Stack.M5Core2.Power;
#elif TOUGH
            _power = M5Stack.Tough.Power;
#endif

            // Reset screen
            _power.Gpio4Value = PinValue.Low;
            Thread.Sleep(100);
            _power.Gpio4Value = PinValue.High;
            Thread.Sleep(100);

#if TOUGH
            // Reset touch controller
            _power.Gpio1Value = PinValue.Low;
            Thread.Sleep(100);
            _power.Gpio1Value = PinValue.High;
            Thread.Sleep(100);
#endif

            // Create the screen
            var displaySpiConfig = new SpiConfiguration(
                1,
                ChipSelect,
                DataCommand,
                Reset,
                BackLightPin);

            var screenConfig = new ScreenConfiguration(
                0,
                0,
                320,
                240);

            _ = DisplayControl.Initialize(
                displaySpiConfig,
                screenConfig,
                (uint)MemoryAllocationBitmap);

            // set initial value for brightness
            BrightnessPercentage = DefaultScreenBrightness;

            // enable back-light
            Enabled = true;

            _isInitialized = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        /// <param name="memoryBitMapAllocation">The memory allocation.</param>
        public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap)
        {
            if (_isInitialized)
            {
                return;
            }

            MemoryAllocationBitmap = memoryBitMapAllocation;
            // Not used in Stick versions, AXP is doing this
            BackLightPin = -1;

#if M5STICKC
            _power = M5StickC.Power;
#else
            _power = M5StickCPlus.Power;
#endif

            var displaySpiConfig = new SpiConfiguration(
                1,
                ChipSelect,
                DataCommand,
                Reset,
                BackLightPin);

#if M5STICKC
            var screenConfig = new ScreenConfiguration(
                26,
                1,
                80,
                160);
#else
            var screenConfig = new ScreenConfiguration(
                52,
                40,
                135,
                240);
#endif

            _ = DisplayControl.Initialize(
                displaySpiConfig,
                screenConfig,
                (uint)MemoryAllocationBitmap);

            // Enable the screen
            Enabled = true;

            // For M5Stick, values from 2.6 to 3V are working fine
            LuminosityPercentage = 100;
            _power.EnableLDO3(true);
            _isInitialized = true;
        }
Ejemplo n.º 4
0
        public static void InitiM5Stick()
        {
            Debug.WriteLine("This is the sequence to power on the Axp192 for M5 Stick");

            Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
            Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);

            I2cDevice i2cAxp192 = new(new I2cConnectionSettings(1, Axp192.I2cDefaultAddress));

            power = new Axp192(i2cAxp192);

            // NOTE: the comments include code which was originally used
            // to setup the AXP192 and can be found in the M5Stick repository
            // This allows to understand the selection dome.
            // Set LDO2 & LDO3(TFT_LED & TFT) 3.0V
            // I2cWrite(Register.VoltageSettingLdo2_3, 0xcc);
            power.LDO2OutputVoltage = ElectricPotential.FromVolts(3);
            power.LDO3OutputVoltage = ElectricPotential.FromVolts(3);
            // Set ADC sample rate to 200hz
            // I2cWrite(Register.AdcFrequency, 0xF2);
            power.AdcFrequency  = AdcFrequency.Frequency200Hz;
            power.AdcPinCurrent = AdcPinCurrent.MicroAmperes80;
            power.BatteryTemperatureMonitoring = true;
            power.AdcPinCurrentSetting         = AdcPinCurrentSetting.AlwaysOn;
            // Set ADC to All Enable
            // I2cWrite(Register.AdcPin1, 0xff);
            power.AdcPinEnabled = AdcPinEnabled.All;
            // Bat charge voltage to 4.2, Current 100MA
            // I2cWrite(Register.ChargeControl1, 0xc0);
            power.SetChargingFunctions(true, ChargingVoltage.V4_2, ChargingCurrent.Current100mA, ChargingStopThreshold.Percent10);
            // Depending on configuration enable LDO2, LDO3, DCDC1, DCDC3.
            // byte data = I2cRead(Register.SwitchControleDcDC1_3LDO2_3);
            // data = (byte)((data & 0xEF) | 0x4D);
            // I2cWrite(Register.SwitchControleDcDC1_3LDO2_3, data);
            power.LdoDcPinsEnabled = LdoDcPinsEnabled.All;
            // 128ms power on, 4s power off
            // I2cWrite(Register.ParameterSetting, 0x0C);
            power.SetButtonBehavior(LongPressTiming.S1, ShortPressTiming.Ms128, true, SignalDelayAfterPowerUp.Ms64, ShutdownTiming.S10);
            // Set RTC voltage to 3.3V
            // I2cWrite(Register.VoltageOutputSettingGpio0Ldo, 0xF0);
            power.PinOutputVoltage = PinOutputVoltage.V3_3;
            // Set GPIO0 to LDO
            // I2cWrite(Register.ControlGpio0, 0x02);
            power.Gpio0Behavior = Gpio0Behavior.LowNoiseLDO;
            // Disable vbus hold limit
            // I2cWrite(Register.PathSettingVbus, 0x80);
            power.SetVbusSettings(true, false, VholdVoltage.V4_0, false, VbusCurrentLimit.MilliAmper500);
            // Set temperature protection
            // I2cWrite(Register.HigTemperatureAlarm, 0xfc);
            power.SetBatteryHighTemperatureThreshold(ElectricPotential.FromVolts(3.2256));
            // Enable RTC BAT charge
            // I2cWrite(Register.BackupBatteryChargingControl, 0xa2);
            power.SetBackupBatteryChargingControl(true, BackupBatteryCharingVoltage.V3_0, BackupBatteryChargingCurrent.MicroAmperes200);
            // Enable bat detection
            // I2cWrite(Register.ShutdownBatteryDetectionControl, 0x46);
            // Note 0x46 is not a possible value, most likely 0x4A
            power.SetShutdownBatteryDetectionControl(false, true, ShutdownBatteryPinFunction.HighResistance, true, ShutdownBatteryTiming.S2);
            // Set Power off voltage 3.0v
            // data = I2cRead(Register.VoltageSettingOff);
            // data = (byte)((data & 0xF8) | (1 << 2));
            // I2cWrite(Register.VoltageSettingOff, data);
            power.VoffVoltage = VoffVoltage.V3_0;
        }