Files
Last update 1 year 3 months
by
Darren Winter
FilesFirmwaremain | |
---|---|
.. | |
CMakeLists.txt | |
LEDLightDriver.h | |
LED_Light_Driver.c | |
main.c |
LED_Light_Driver.c//Driver for led light //Author: Darren Winter //Date: 29/09/23 #include "LEDLightDriver.h" //LEDC Config Settings //RED LEDS ledc_timer_config_t timer = { .speed_mode = LEDC_LOW_SPEED_MODE, .duty_resolution = LEDC_TIMER_10_BIT, .timer_num = LEDC_TIMER_0, .freq_hz = 5000, .clk_cfg = LEDC_AUTO_CLK }; ledc_channel_config_t R_D1_CH = { .gpio_num = 2, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_0, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //R_D1 ledc_channel_config_t R_D2_CH = { .gpio_num = 6, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_0, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //R_D2 ledc_channel_config_t R_D3_CH = { .gpio_num = 10, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_0, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //R_D3 //GREEN LEDS ledc_channel_config_t G_D1_CH = { .gpio_num = 4, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_1, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //G_D1 ledc_channel_config_t G_D2_CH = { .gpio_num = 8, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_1, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //G_D2 ledc_channel_config_t G_D3_CH = { .gpio_num = 12, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_1, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //G_D3 //BLUE LEDS ledc_channel_config_t B_D1_CH = { .gpio_num = 3, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_2, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //B_D1 ledc_channel_config_t B_D2_CH = { .gpio_num = 7, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_2, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //B_D2 ledc_channel_config_t B_D3_CH = { .gpio_num = 11, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_2, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //B_D3 //WHITE LED ledc_channel_config_t W_D1_CH = { .gpio_num = 5, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_3, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //W_D1 ledc_channel_config_t W_D2_CH = { .gpio_num = 9, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_3, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //W_D2 ledc_channel_config_t W_D3_CH = { .gpio_num = 13, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_3, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //W_D3 //WARM WHITE ledc_channel_config_t D4_SW_CH = { .gpio_num = 45, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_4, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //D4_SW ledc_channel_config_t D5_SW_CH = { .gpio_num = 46, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_4, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //D5_SW ledc_channel_config_t D6_SW_CH = { .gpio_num = 47, .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_4, .timer_sel = LEDC_TIMER_0, .duty = 0, .hpoint = 0 }; //D6_SW //Red 25% BRIGHTNESS void RED_BRIGHTNESS_25() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 250); //Setting duty cycle ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); //Updating duty cycle } //Red 50% BRIGHTNESS void RED_BRIGHTNESS_50() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 500); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); } //Red 75% BRIGHTNESS void RED_BRIGHTNESS_75() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 750); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); } //Red 100% BRIGHTNESS void RED_BRIGHTNESS_100() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 1000); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); } //Green 25% BRIGHTNESS void GREEN_BRIGHTNESS_25() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 250); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); } //Green 50% BRIGHTNESS void GREEN_BRIGHTNESS_50() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 500); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); } //Green 75% BRIGHTNESS void GREEN_BRIGHTNESS_75() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 750); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); } //Green 100% BRIGHTNESS void GREEN_BRIGHTNESS_100() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 1000); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); } //Blue 25% BRIGHTNESS void BLUE_BRIGHTNESS_25() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 250); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2); } //Blue 50% BRIGHTNESS void BLUE_BRIGHTNESS_50() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 500); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2); } //Blue 75% BRIGHTNESS void BLUE_BRIGHTNESS_75() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 750); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2); } //Blue 100% BRIGHTNESS void BLUE_BRIGHTNESS_100() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 1000); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2); } //White 25% BRIGHTNESS void WHITE_BRIGHTNESS_25() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3, 250); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3); } //White 50% BRIGHTNESS void WHITE_BRIGHTNESS_50() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3, 500); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3); } //White 75% BRIGHTNESS void WHITE_BRIGHTNESS_75() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3, 750); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3); } //White 100% BRIGHTNESS void WHITE_BRIGHTNESS_100() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3, 1000); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3); } //Warm White 25% BRIGHTNESS void WARM_WHITE_BRIGHTNESS_25() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4, 250); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4); } //Warm White 50% BRIGHTNESS void WARM_WHITE_BRIGHTNESS_50() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4, 500); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4); } //Warm White 75% BRIGHTNESS void WARM_WHITE_BRIGHTNESS_75() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4, 750); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4); } //Warm White 100% BRIGHTNESS void WARM_WHITE_BRIGHTNESS_100() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4, 1000); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4); } void Stop_RGBW_LEDs() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_3); } void Stop_Warm_LEDs() { ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4, 0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_4); } //LEDC Config void LEDC_Config_Set_RGBW() //Initialise ledc configs { ledc_timer_config(&timer); ledc_channel_config(&R_D1_CH); ledc_channel_config(&R_D2_CH); ledc_channel_config(&R_D3_CH); ledc_channel_config(&G_D1_CH); ledc_channel_config(&G_D2_CH); ledc_channel_config(&G_D3_CH); ledc_channel_config(&B_D1_CH); ledc_channel_config(&B_D2_CH); ledc_channel_config(&B_D3_CH); ledc_channel_config(&W_D1_CH); ledc_channel_config(&W_D2_CH); ledc_channel_config(&W_D3_CH); } void LEDC_Config_Set_Warm_LED() //Initialise ledc configs { ledc_timer_config(&timer); ledc_channel_config(&D4_SW_CH); ledc_channel_config(&D5_SW_CH); ledc_channel_config(&D6_SW_CH); }