@@ -76,21 +76,33 @@ public static Pcf8563 ReatTimeClock
7676 get => _rtc ;
7777 }
7878
79+ #if M5CORE2
80+
7981 /// <summary>
80- /// Sets on or off the Power Led .
82+ /// Sets on or off the Power LED .
8183 /// </summary>
8284 public static bool PowerLed
8385 {
8486 get => _powerLed ;
8587 set
8688 {
8789 _powerLed = value ;
88- _power . EnableLDO2 ( _powerLed ) ;
90+
91+ if ( _powerLed )
92+ {
93+ // turn ON by setting duty cycle to 100%
94+ _power . Pwm1DutyCycleSetting1 = 10 ;
95+ _power . Pwm1DutyCycleSetting2 = 10 ;
96+ }
97+ else
98+ {
99+ // tuen OFF by setting duty cycle to 0%
100+ _power . Pwm1DutyCycleSetting1 = 0 ;
101+ _power . Pwm1DutyCycleSetting2 = 0 ;
102+ }
89103 }
90104 }
91105
92- #if M5CORE2
93-
94106 /// <summary>
95107 /// Vibrate the M5Core2 when true.
96108 /// </summary>
@@ -136,21 +148,6 @@ public static Chs6540 TouchController
136148 return _touchController ;
137149 }
138150 }
139-
140- /// <summary>
141- /// Gets or sets the state of the display backlight.
142- /// Set to <see langword="true"/> to turn on and <see langword="false"/> to turn off.
143- /// </summary>
144- public static bool Backlight
145- {
146- get => _backLight ;
147- set
148- {
149- _backLight = value ;
150- _power . EnableLDO3 ( _backLight ) ;
151- }
152- }
153-
154151#endif
155152
156153 /// <summary>
@@ -292,7 +289,8 @@ static Tough()
292289 I2cDevice i2c = new ( new I2cConnectionSettings ( 1 , Axp192 . I2cDefaultAddress ) ) ;
293290 _power = new ( i2c ) ;
294291
295- // Configuration common for M5Core2 and Tough
292+ // Configuration common for M5Core2 and M5Tough
293+
296294 // VBUS-IPSOUT Pass-Through Management
297295 _power . SetVbusSettings ( false , false , VholdVoltage . V4_0 , true , VbusCurrentLimit . MilliAmper500 ) ;
298296 // Set Power off voltage 3.0v
@@ -303,87 +301,80 @@ static Tough()
303301 _power . SetChargingFunctions ( true , ChargingVoltage . V4_2 , ChargingCurrent . Current100mA , ChargingStopThreshold . Percent10 ) ;
304302 // Enable RTC BAT charge
305303 _power . SetBackupBatteryChargingControl ( true , BackupBatteryCharingVoltage . V3_0 , BackupBatteryChargingCurrent . MicroAmperes200 ) ;
306- // 128ms power on, 4s power off
307- _power . SetButtonBehavior ( LongPressTiming . S1 , ShortPressTiming . Ms128 , true , SignalDelayAfterPowerUp . Ms32 , ShutdownTiming . S4 ) ;
304+
308305 // Set ADC all on
309306 _power . AdcPinEnabled = AdcPinEnabled . All ;
310307 // Set ADC sample rate to 25Hz
311308 _power . AdcFrequency = AdcFrequency . Frequency25Hz ;
312309 _power . AdcPinCurrent = AdcPinCurrent . MicroAmperes80 ;
313310 _power . BatteryTemperatureMonitoring = true ;
314311 _power . AdcPinCurrentSetting = AdcPinCurrentSetting . AlwaysOn ;
312+
315313 // GPIO0 is LDO
316314 _power . Gpio0Behavior = Gpio0Behavior . LowNoiseLDO ;
317315 // GPIO0 LDO output 2.8V
318316 _power . PinOutputVoltage = PinOutputVoltage . V2_8 ;
319-
320- #if TOUGH
321- // PWM1 X
322- _power . Pwm1OutputFrequencySetting = 0 ;
323- // PWM1 Y1
324- _power . Pwm1DutyCycleSetting1 = 0xFF ;
325- // PWM1 Y2
326- _power . Pwm1DutyCycleSetting2 = 0xFF ;
327- #endif
328-
329- // enable pins
330- #if M5CORE2
331- _power . LdoDcPinsEnabled = LdoDcPinsEnabled . DcDc1 | LdoDcPinsEnabled . DcDc3 | LdoDcPinsEnabled . Ldo2 | LdoDcPinsEnabled . Ldo3 ;
332- #elif TOUGH
333- _power . LdoDcPinsEnabled = LdoDcPinsEnabled . DcDc1 | LdoDcPinsEnabled . Ldo2 | LdoDcPinsEnabled . Ldo3 ;
334- #endif
335-
336317 // Sets DCDC1 3350mV (ESP32 VDD)
337318 _power . DcDc1Voltage = ElectricPotential . FromVolts ( 3.35 ) ;
338- // Switch on the power
339- PowerLed = true ;
340319
341- // LCD + SD peripheral power supply
320+ // LCD and peripherals power supply
342321 _power . LDO2OutputVoltage = ElectricPotential . FromVolts ( 3.3 ) ;
343322 _power . EnableLDO2 ( true ) ;
344323
324+ // GPIO2 enables the speaker
325+ _power . Gpio2Behavior = Gpio12Behavior . MnosLeakOpenOutput ;
326+
327+ // GPIO4 LCD reset (and also Touch controller reset on M5Core2)
328+ _power . Gpio4Behavior = Gpio4Behavior . MnosLeakOpenOutput ;
329+
330+ // Set temperature protection
331+ _power . SetBatteryHighTemperatureThreshold ( ElectricPotential . FromVolts ( 3.2256 ) ) ;
332+
333+ // This part of the code will handle the button behavior
334+ _power . EnableButtonPressed ( ButtonPressed . LongPressed | ButtonPressed . ShortPressed ) ;
335+ // 128ms power on, 4s power off
336+ _power . SetButtonBehavior ( LongPressTiming . S1 , ShortPressTiming . Ms128 , true , SignalDelayAfterPowerUp . Ms32 , ShutdownTiming . S4 ) ;
337+
345338#if M5CORE2
339+ // enable DCO and LDO outputs
340+ _power . LdoDcPinsEnabled = LdoDcPinsEnabled . DcDc1 | LdoDcPinsEnabled . DcDc3 | LdoDcPinsEnabled . Ldo2 | LdoDcPinsEnabled . Ldo3 ;
341+
346342 // Sets the Vibrator voltage
347343 _power . LDO3OutputVoltage = ElectricPotential . FromVolts ( 2.0 ) ;
348344 // vibrator off
349345 Vibrate = false ;
350346
351- // Sets the LCD Voltage to 2.8V
347+ // Sets the LCD backlight voltage to 2.8V
352348 _power . DcDc3Voltage = ElectricPotential . FromVolts ( 2.8 ) ;
353349
354- // GPIO1 PWM
350+ // GPIO1 set to PWM to control power LED
355351 _power . Gpio1Behavior = Gpio12Behavior . PwmOutput ;
356352
353+ // Switch on the power LED
354+ PowerLed = true ;
355+
357356 // battery = 360mAh
358357 _power . ChargingCurrent = ChargingCurrent . Current360mA ;
359358
360359#elif TOUGH
361- // Sets backlight voltage to 3.0
362- //_power.LDO3OutputVoltage = ElectricPotential.FromVolts(3.0);
363- Backlight = true ;
364- _power . DcDc3Voltage = ElectricPotential . FromVolts ( 0 ) ;
360+ // PWM1 X
361+ _power . Pwm1OutputFrequencySetting = 0 ;
362+ // PWM1 Y1
363+ _power . Pwm1DutyCycleSetting1 = 0xFF ;
364+ // PWM1 Y2
365+ _power . Pwm1DutyCycleSetting2 = 0xFF ;
365366
366- // GPIO1 Touch Reset
367+ // enable DCO and LDO outputs
368+ _power . LdoDcPinsEnabled = LdoDcPinsEnabled . DcDc1 | LdoDcPinsEnabled . Ldo2 | LdoDcPinsEnabled . Ldo3 ;
369+
370+ // Sets the LCD backlight voltage to 3V
371+ _power . LDO3OutputVoltage = ElectricPotential . FromVolts ( 3.0 ) ;
372+
373+ // GPIO1 is reset for Touch controller
367374 _power . Gpio1Behavior = Gpio12Behavior . MnosLeakOpenOutput ;
368375
369376#endif
370377
371- // GPIO2 speaker enable
372- _power . Gpio2Behavior = Gpio12Behavior . MnosLeakOpenOutput ;
373-
374- // GPIO4 LCD reset (and Touch reset on M5Core2)
375- _power . Gpio4Behavior = Gpio4Behavior . MnosLeakOpenOutput ;
376-
377- // Set GPIO4 as output (rest LCD)
378- // _power.Gpio4Behavior = Gpio4Behavior.MnosLeakOpenOutput;
379-
380- // Set temperature protection
381- _power . SetBatteryHighTemperatureThreshold ( ElectricPotential . FromVolts ( 3.2256 ) ) ;
382-
383- // This part of the code will handle the button behavior
384- //_power.EnableButtonPressed(ButtonPressed.LongPressed | ButtonPressed.ShortPressed);
385- // _power.SetButtonBehavior(LongPressTiming.S2, ShortPressTiming.Ms128, true, SignalDelayAfterPowerUp.Ms32, ShutdownTiming.S10);
386-
387378 // Setup buttons
388379 _gpio = new ( ) ;
389380
0 commit comments