Skip to content

Commit

Permalink
tft led brightness from DAC, with npn transistor
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Apr 7, 2018
1 parent e80e17f commit 6d088c4
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
12 changes: 6 additions & 6 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1926534107" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.185803216" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.1980434817" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1247237580" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1247237580" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include\c++\5.4.1\arm-none-eabi&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include\c++\5.4.1&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1894739617" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.478307011" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.779679999" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.779679999" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include\c++\5.4.1\arm-none-eabi&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include\c++\5.4.1&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.483994060" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1299738692" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.390578237" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.390578237" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include\c++\5.4.1\arm-none-eabi&quot;"/>
<listOptionValue builtIn="false" value="&quot;C:\cygwin64\usr\local\arm-none-eabi\include\c++\5.4.1&quot;"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1859782615" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
Expand Down
15 changes: 14 additions & 1 deletion kc/gui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Ada4_ST7735.h"
#include "FreeSans9pt7b.h"

extern KC_Main kc;

// menu draw util
//------------------------------------------------------
Expand Down Expand Up @@ -144,11 +145,23 @@ void Gui::Draw()
tm = rtc_get();
int h = tm/3600%24, m = tm/60%60, s = tm%60;

d->setCursor(0, 32);
d->setCursor(W/2, 0);
d->setTextColor(RGB(10,28,18));

sprintf(a,"%2d:%02d:%02d", h,m,s);
d->print(a);

d->setFont(0);

// brightness, dac ---
d->setCursor(0, 32);
d->setTextColor(RGB(31,31,12));

sprintf(a,"Brightness: %d %d %%",
kc.valDac-3595, 100*(kc.valDac-3600)/(4095-3600));
//todo
// fade time, fade to brightness
d->print(a);
}
}

Expand Down
11 changes: 11 additions & 0 deletions kc/gui_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ void Gui::KeyPress()
4 Ent * Num M / V C
5 F12 - N B */


// Mapping edit modes
//............................................
if (ym == M_Display && mlevel == 1)
{
if (kUp)
{ kc.valDac += kUp * 10; kc.setDac = 1; }
if (kPgUp)
{ kc.valDac += kPgUp * 40; kc.setDac = 1; }
}

// Mapping edit modes
//............................................
if (ym == M_Mapping && mlevel == 1)
Expand Down
10 changes: 10 additions & 0 deletions kc/kc_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
#include "usb_keyboard.h"
#include "matrix.h"
#include "keys_usb.h"
#include "WProgram.h"


// update layer
//------------------------------------------------
void KC_Main::UpdLay()
{
// dac led
if (setDac)
{ setDac = 0;
if (valDac > 4095)
valDac = 4095;
//analogWrite(A14, val);
analogWriteDAC0(valDac);
}

// all matrix scan codes
uint c,r; int id;
for (c=0; c < NumCols; ++c)
Expand Down
13 changes: 5 additions & 8 deletions kc/kc_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@ struct KC_Key // for each scan code
KC_Key() : layUse(0) // nothing
{ }

// number of set bits
int numLays() const
{
uint8_t b = layUse;
b = b - ((b >> 1) & 0x55);
b = (b & 0x33) + ((b >> 2) & 0x33);
return (((b + (b >> 4)) & 0x0F) * 0x01);
}
// test use bit
#define hasLay(n) (layUse & (1ul << n))

Expand Down Expand Up @@ -72,6 +64,7 @@ struct KC_Setup

struct KC_Main // main, state
{
// current layer, by keys
int8_t nLayer = 0;

// sequence running vars
Expand All @@ -82,6 +75,10 @@ struct KC_Main // main, state
uint32_t tiSeq = 0;
void SeqModClear();

int8_t setDac = 1;
int16_t valDac = 3900;

// const from grp
uint8_t grpStart[grpMax], grpEnd[grpMax];

KC_Setup set;
Expand Down
3 changes: 3 additions & 0 deletions kc/kc_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void KC_Main::SeqModClear()

KC_Main::KC_Main()
{
setDac = 1;
valDac = 3980; // default

SeqModClear();

// init grp Start and End
Expand Down
8 changes: 7 additions & 1 deletion kc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,24 @@ void main_periodic()
//-------------------------------------------------------------------------
int main()
{
// dac for tft led
analogWriteRes(12);
analogWriteDAC0(0); // dark

Ada4_ST7735 tft;
tft.begin();

gui.Init(&tft);
tft.clear();
tft.display(); // black


// kbd
Matrix_setup();

// 40000 1.2 kHz d: 50 fps
// 50000 960 Hz d: 52 fps
Periodic_init( 50000 );
Periodic_init( 50000 ); // par
Periodic_function( &main_periodic );


Expand Down

0 comments on commit 6d088c4

Please sign in to comment.