Numworks Epsilon  1.4.1
Graphing Calculator Operating System
backlight.cpp
Go to the documentation of this file.
1 #include <ion.h>
2 #include "regs/regs.h"
3 #include "backlight.h"
4 
5 /* This driver controls the RT9365 LED driver.
6  * This chip allows the brightness to be set to 16 different values. It starts
7  * at full brightness on power on. Applying a pulse on the EN pin will select
8  * the next value in decreasing order. Once it reaches the minimal value, the
9  * next pulse will loop back to full brightness. */
10 
11 // Public Ion::Backlight methods
12 
13 namespace Ion {
14 namespace Backlight {
15 
17  Device::setLevel(b >> 4);
18 }
19 
21  return Device::level() << 4;
22 }
23 
24 }
25 }
26 
27 // Private Ion::Backlight::Device methods
28 
29 namespace Ion {
30 namespace Backlight {
31 namespace Device {
32 
33 static uint8_t sLevel;
34 
35 void init() {
37  sLevel = 0xF;
38  resume();
39 }
40 
41 void shutdown() {
44 }
45 
46 void suspend() {
47  GPIOC.ODR()->set(6, false);
48  msleep(3); // Might not need to be blocking
49 }
50 
51 void resume() {
52  GPIOC.ODR()->set(6, true);
53  usleep(50);
54  uint8_t level = sLevel;
55  sLevel = 0xF;
56  setLevel(level);
57 }
58 
60  // From sLevel = 12 to level 7 : 5 pulses
61  // From sLevel = 5 to level 9 : 12 pulses (5 to go to level 16, and 7 to 9)
62  if (sLevel < level) {
63  sendPulses(16 + sLevel - level);
64  } else {
65  sendPulses(sLevel - level);
66  }
67  sLevel = level;
68 }
69 
71  return sLevel;
72 }
73 
74 void sendPulses(int n) {
75  for (int i=0; i<n; i++) {
76  GPIOC.ODR()->set(6, false);
77  usleep(20);
78  GPIOC.ODR()->set(6, true);
79  usleep(20);
80  }
81 }
82 
83 }
84 }
85 }
void setLevel(uint8_t level)
Definition: backlight.cpp:59
void msleep(long ms)
Definition: ion.cpp:4
void Backlight(const char *input)
Definition: backlight.cpp:10
unsigned char uint8_t
Definition: stdint.h:4
void setBrightness(uint8_t b)
Definition: backlight.cpp:16
Definition: gpio.h:47
void sendPulses(int n)
Definition: backlight.cpp:74
void setPull(int index, Pull pull) volatile
Definition: gpio.h:39
uint8_t brightness()
Definition: backlight.cpp:20
void usleep(long us)
Definition: device.cpp:31
void setMode(int index, Mode mode) volatile
Definition: gpio.h:17
Definition: backlight.h:6
void set(int index, bool state) volatile
Definition: gpio.h:50
constexpr GPIO GPIOC(2)