Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CyanLight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fxk8y
CyanLight
Commits
cb10ece7
Commit
cb10ece7
authored
3 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Beginning the real controller dev
parent
d9f8cb1a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CLC-qthing/CyanLightControl.hpp
+22
-0
22 additions, 0 deletions
CLC-qthing/CyanLightControl.hpp
CLC-qthing/PWMChannel.cpp
+72
-0
72 additions, 0 deletions
CLC-qthing/PWMChannel.cpp
CLC-qthing/PWMChannel.hpp
+24
-0
24 additions, 0 deletions
CLC-qthing/PWMChannel.hpp
with
118 additions
and
0 deletions
CLC-qthing/CyanLightControl.hpp
0 → 100644
+
22
−
0
View file @
cb10ece7
#pragma once
#include
<cinttypes>
namespace
CyanLight
{
const
uint8_t
MAX_CHANNELS
=
6
;
class
Controller
{
public:
Controller
();
private:
PWMChannel
channels
[
MAX_CHANNELS
];
};
}
This diff is collapsed.
Click to expand it.
CLC-qthing/PWMChannel.cpp
0 → 100644
+
72
−
0
View file @
cb10ece7
#include
"FastDimmer.hpp"
#include
"driver/gpio.h"
#include
"driver/ledc.h"
static
uint8_t
_channel_cnt
=
0
;
uint8_t
getNextPWMChannel
()
{
return
_channel_cnt
++
;
}
static
bool
timerConfigured
=
false
;
static
void
configureTimer
()
{
if
(
!
timerConfigured
)
{
ledc_timer_config_t
ledc_timer
;
ledc_timer
.
duty_resolution
=
LEDC_TIMER_10_BIT
,
// resolution of PWM duty
ledc_timer
.
freq_hz
=
1000
,
// frequency of PWM signal; 2KHz is max for CN5711
ledc_timer
.
speed_mode
=
LEDC_HIGH_SPEED_MODE
,
// timer mode
ledc_timer
.
timer_num
=
LEDC_TIMER_0
,
// timer index
// Required for newer esp-idf:
//ledc_timer.clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock
ledc_timer_config
(
&
ledc_timer
);
ledc_fade_func_install
(
0
);
timerConfigured
=
true
;
}
}
PWMChannel
::
PWMChannel
(
uint8_t
gpio
)
{
configureTimer
();
gpio_config_t
conf
;
conf
.
intr_type
=
GPIO_INTR_DISABLE
;
conf
.
mode
=
GPIO_MODE_OUTPUT
;
conf
.
pin_bit_mask
=
1ULL
<<
gpio
;
conf
.
pull_up_en
=
GPIO_PULLUP_DISABLE
;
conf
.
pull_down_en
=
GPIO_PULLDOWN_DISABLE
;
gpio_config
(
&
conf
);
gpio_set_level
((
gpio_num_t
)
gpio
,
0
);
ledc_channel_config_t
ledc_channel
;
ledc_channel
.
channel
=
this
->
channel
;
ledc_channel
.
duty
=
0
;
ledc_channel
.
gpio_num
=
(
gpio_num_t
)
gpio
;
ledc_channel
.
speed_mode
=
LEDC_HIGH_SPEED_MODE
;
ledc_channel
.
hpoint
=
0
;
ledc_channel
.
timer_sel
=
LEDC_TIMER_0
;
ledc_channel_config
(
&
ledc_channel
);
setBrightness
(
0
);
}
const
float
maxPWM
=
1024.0
f
;
void
PWMChannel
::
setBrightness
(
float
b
)
{
uint16_t
pwm
=
(
uint16_t
)(
b
*
b
*
maxPWM
);
ledc_set_duty
(
LEDC_HIGH_SPEED_MODE
,
this
->
channel
,
pwm
);
ledc_update_duty
(
LEDC_HIGH_SPEED_MODE
,
this
->
channel
);
}
This diff is collapsed.
Click to expand it.
CLC-qthing/PWMChannel.hpp
0 → 100644
+
24
−
0
View file @
cb10ece7
#pragma once
#include
<qthing.h>
#include
"driver/ledc.h"
ledc_channel_t
getNextLEDChannel
();
namespace
CyanLight
{
class
PWMChannel
{
public:
PWMChannel
(
uint8_t
gpio
);
float
getBrightness
();
void
setBrightness
(
float
b
);
private:
ledc_channel_t
channel
=
getNextLEDChannel
();
};
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment