Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 26 additions & 36 deletions sim/components/brightness/BrightnessController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@
// #include <hal/nrf_gpio.h>
#include "displayapp/screens/Symbols.h"
#include "drivers/PinMap.h"

#include <tuple> // std::ignore

using namespace Pinetime::Controllers;

void BrightnessController::Init() {
// nrf_gpio_cfg_output(PinMap::LcdBacklightLow);
// nrf_gpio_cfg_output(PinMap::LcdBacklightMedium);
// nrf_gpio_cfg_output(PinMap::LcdBacklightHigh);
Set(level);
}

void BrightnessController::ApplyBrightness(uint16_t rawBrightness) {
std::ignore = rawBrightness;
}

void BrightnessController::Set(BrightnessController::Levels level) {
this->level = level;
// switch (level) {
// default:
// case Levels::High:
// nrf_gpio_pin_clear(PinMap::LcdBacklightLow);
// nrf_gpio_pin_clear(PinMap::LcdBacklightMedium);
// nrf_gpio_pin_clear(PinMap::LcdBacklightHigh);
// break;
// case Levels::Medium:
// nrf_gpio_pin_clear(PinMap::LcdBacklightLow);
// nrf_gpio_pin_clear(PinMap::LcdBacklightMedium);
// nrf_gpio_pin_set(PinMap::LcdBacklightHigh);
// break;
// case Levels::Low:
// nrf_gpio_pin_clear(PinMap::LcdBacklightLow);
// nrf_gpio_pin_set(PinMap::LcdBacklightMedium);
// nrf_gpio_pin_set(PinMap::LcdBacklightHigh);
// break;
// case Levels::Off:
// nrf_gpio_pin_set(PinMap::LcdBacklightLow);
// nrf_gpio_pin_set(PinMap::LcdBacklightMedium);
// nrf_gpio_pin_set(PinMap::LcdBacklightHigh);
// break;
// }
switch (level) {
default:
case Levels::High:
ApplyBrightness(3 * timerPeriod);
break;
case Levels::Medium:
ApplyBrightness(2 * timerPeriod);
break;
case Levels::Low:
ApplyBrightness(timerPeriod);
break;
case Levels::AlwaysOn:
ApplyBrightness(timerPeriod / 10);
break;
case Levels::Off:
ApplyBrightness(0);
break;
}
}

void BrightnessController::Lower() {
Expand Down Expand Up @@ -74,14 +73,6 @@ BrightnessController::Levels BrightnessController::Level() const {
return level;
}

void BrightnessController::Backup() {
backupLevel = level;
}

void BrightnessController::Restore() {
Set(backupLevel);
}

void BrightnessController::Step() {
switch (level) {
case Levels::Low:
Expand All @@ -97,7 +88,6 @@ void BrightnessController::Step() {
break;
}
}

const char* BrightnessController::GetIcon() {
switch (level) {
case Levels::Medium:
Expand All @@ -123,4 +113,4 @@ const char* BrightnessController::ToString() {
default:
return "???";
}
}
}
26 changes: 22 additions & 4 deletions sim/components/brightness/BrightnessController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include <cstdint>

//#include "nrf_ppi.h"
//#include "nrfx_gpiote.h"

namespace Pinetime {
namespace Controllers {
class BrightnessController {
Expand All @@ -15,15 +18,30 @@ namespace Pinetime {
void Higher();
void Step();

void Backup();
void Restore();

const char* GetIcon();
const char* ToString();

private:
Levels level = Levels::High;
Levels backupLevel = Levels::High;
static constexpr uint8_t UNSET = UINT8_MAX;
uint8_t lastPin = UNSET;
// Maximum time (μs) it takes for the RTC to fully stop
static constexpr uint8_t rtcStopTime = 46;
// Frequency of timer used for PWM (Hz)
static constexpr uint16_t timerFrequency = 32768;
// Backlight PWM frequency (Hz)
static constexpr uint16_t pwmFreq = 1000;
// Wraparound point in timer ticks
// Defines the number of brightness levels between each pin
static constexpr uint16_t timerPeriod = timerFrequency / pwmFreq;
// Warning: nimble reserves some PPIs
// https://github.com/InfiniTimeOrg/InfiniTime/blob/034d83fe6baf1ab3875a34f8cee387e24410a824/src/libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c#L53
// SpiMaster uses PPI 0 for an erratum workaround
// Channel 1, 2 should be free to use
//static constexpr nrf_ppi_channel_t ppiBacklightOn = NRF_PPI_CHANNEL1;
//static constexpr nrf_ppi_channel_t ppiBacklightOff = NRF_PPI_CHANNEL2;

void ApplyBrightness(uint16_t val);
};
}
}
Loading