[ion] Add a backlight namespace

Change-Id: I0b9ec9a1b342d4b949776f0303eca69a28d1de91
This commit is contained in:
Romain Goyet
2017-01-05 10:05:30 +01:00
parent 9b2fecfb12
commit c1db79b5f9
8 changed files with 126 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
#ifndef ION_ION_H
#define ION_ION_H
#include <ion/backlight.h>
#include <ion/battery.h>
#include <ion/display.h>
#include <ion/events.h>

View File

@@ -0,0 +1,15 @@
#ifndef ION_BACKLIGHT_H
#define ION_BACKLIGHT_H
#include <stdint.h>
namespace Ion {
namespace Backlight {
void setBrightness(uint8_t b);
uint8_t brightness();
}
}
#endif

View File

@@ -21,8 +21,6 @@ void pushRect(KDRect r, const KDColor * pixels);
void pushRectUniform(KDRect r, KDColor c);
void pullRect(KDRect r, KDColor * pixels);
void setBacklightIntensity(uint8_t intensity);
constexpr int Width = 320;
constexpr int Height = 240;

View File

@@ -1,6 +1,7 @@
include ion/src/shared/Makefile
include ion/src/device/boot/Makefile
objs += $(addprefix ion/src/device/, \
backlight.o \
battery.o\
device.o\
display.o\

View File

@@ -0,0 +1,80 @@
#include <ion.h>
#include "regs/regs.h"
#include "backlight.h"
/* This driver controls the RT9365 LED driver.
* This chip allows the brightness to be set to 16 different values. It starts
* at full brightness on power on. Applying a pulse on the EN pin will select
* the next value in decreasing order. Once it reaches the minimal value, the
* next pulse will loop back to full brightness. */
// Public Ion::Backlight methods
namespace Ion {
namespace Backlight {
void setBrightness(uint8_t b) {
Device::setLevel(b >> 4);
}
uint8_t brightness() {
return Device::level() << 4;
}
}
}
// Private Ion::Backlight::Device methods
namespace Ion {
namespace Backlight {
namespace Device {
static uint8_t sLevel;
void init() {
GPIOC.MODER()->setMode(6, GPIO::MODER::Mode::Output);
sLevel = 0xF;
resume();
}
void suspend() {
GPIOC.ODR()->set(6, false);
msleep(3); // Might not need to be blocking
}
void resume() {
GPIOC.ODR()->set(6, true);
usleep(50);
uint8_t level = sLevel;
sLevel = 0xF;
setLevel(level);
}
void setLevel(uint8_t level) {
// From sLevel = 12 to level 7 : 5 pulses
// From sLevel = 5 to level 9 : 12 pulses (5 to go to level 16, and 7 to 9)
if (sLevel < level) {
sendPulses(16 + sLevel - level);
} else {
sendPulses(sLevel - level);
}
sLevel = level;
}
uint8_t level() {
return sLevel;
}
void sendPulses(int n) {
for (int i=0; i<n; i++) {
GPIOC.ODR()->set(6, false);
usleep(20);
GPIOC.ODR()->set(6, true);
usleep(20);
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
#ifndef ION_DEVICE_BACKLIGHT_H
#define ION_DEVICE_BACKLIGHT_H
#include <ion/backlight.h>
namespace Ion {
namespace Backlight {
namespace Device {
/* Pin | Role | Mode | Function
* -----+-------------------+-----------------------+----------
* PC6 | Backlight Enable | Output |
*/
void init();
void suspend();
void resume();
void setLevel(uint8_t level);
uint8_t level();
void sendPulses(int n);
}
}
}
#endif

View File

@@ -9,6 +9,7 @@ extern "C" {
#include "keyboard.h"
#include "battery.h"
#include "sd_card.h"
#include "backlight.h"
#define USE_SD_CARD 0
@@ -37,8 +38,7 @@ void Ion::Device::init() {
Display::Device::init();
Keyboard::Device::init();
Battery::Device::init();
Display::setBacklightIntensity(0xFF);
Backlight::Device::init();
#if USE_SD_CARD
SDCard::Device::init();
#endif

View File

@@ -11,9 +11,6 @@ void Ion::LED::setColor(KDColor c) {
TIM3.CCR4()->set(Device::dutyCycleForUInt8(c.green()));
}
void Ion::Display::setBacklightIntensity(uint8_t intensity) {
}
// Private Ion::Device::LED methods
namespace Ion {