-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved RGBLedWrite to new file esp32-hal-rgb-led and created pinMode i…
…n variatn.cpp
- Loading branch information
1 parent
50b6356
commit 583e030
Showing
9 changed files
with
114 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "esp32-hal-rgb-led.h" | ||
|
||
#ifdef BOARD_HAS_NEOPIXEL | ||
|
||
void RGBLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){ | ||
log_d("RGB: %d %d %d", red_val, green_val, blue_val); | ||
rmt_data_t led_data[24]; | ||
static rmt_obj_t* rmt_send = NULL; | ||
static bool initialized = false; | ||
|
||
uint8_t _pin; | ||
if(pin == LED_BUILTIN){ | ||
_pin = LED_BUILTIN-SOC_GPIO_PIN_COUNT; | ||
}else{ | ||
_pin = pin; | ||
} | ||
|
||
if(!initialized){ | ||
if((rmt_send = rmtInit(_pin, RMT_TX_MODE, RMT_MEM_64)) == NULL){ | ||
log_e("RGB LED driver initialization failed!"); | ||
rmt_send = NULL; | ||
return; | ||
} | ||
rmtSetTick(rmt_send, 100); | ||
initialized = true; | ||
} | ||
|
||
int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE | ||
int i = 0; | ||
for(int col=0; col<3; col++ ){ | ||
for(int bit=0; bit<8; bit++){ | ||
if((color[col] & (1<<(7-bit)))){ | ||
// HIGH bit | ||
led_data[i].level0 = 1; // T1H | ||
led_data[i].duration0 = 8; // 0.8us | ||
led_data[i].level1 = 0; // T1L | ||
led_data[i].duration1 = 4; // 0.4us | ||
}else{ | ||
// LOW bit | ||
led_data[i].level0 = 1; // T0H | ||
led_data[i].duration0 = 4; // 0.4us | ||
led_data[i].level1 = 0; // T0L | ||
led_data[i].duration1 = 8; // 0.8us | ||
} | ||
i++; | ||
} | ||
} | ||
rmtWrite(rmt_send, led_data, 24); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef MAIN_ESP32_HAL_RGB_LED_H_ | ||
#define MAIN_ESP32_HAL_RGB_LED_H_ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "esp32-hal.h" | ||
/* | ||
#include "soc/soc_caps.h" | ||
#include "pins_arduino.h" | ||
*/ | ||
|
||
//#ifdef BOARD_HAS_NEOPIXEL | ||
void RGBLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); | ||
//#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* MAIN_ESP32_HAL_RGB_LED_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "esp32-hal-rgb-led.h" | ||
|
||
extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) | ||
{ | ||
log_d("foo"); | ||
#ifdef BOARD_HAS_NEOPIXEL | ||
if (pin == LED_BUILTIN){ | ||
__pinMode(LED_BUILTIN-SOC_GPIO_PIN_COUNT, mode); | ||
return; | ||
} | ||
#endif | ||
__pinMode(pin, mode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "esp32-hal-rgb-led.h" | ||
|
||
extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) | ||
{ | ||
log_d("foo"); | ||
#ifdef BOARD_HAS_NEOPIXEL | ||
if (pin == LED_BUILTIN){ | ||
__pinMode(LED_BUILTIN-SOC_GPIO_PIN_COUNT, mode); | ||
return; | ||
} | ||
#endif | ||
__pinMode(pin, mode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "esp32-hal-rgb-led.h" | ||
|
||
extern void ARDUINO_ISR_ATTR __pinMode(uint8_t pin, uint8_t mode) | ||
{ | ||
log_d("foo"); | ||
#ifdef BOARD_HAS_NEOPIXEL | ||
if (pin == LED_BUILTIN){ | ||
__pinMode(LED_BUILTIN-SOC_GPIO_PIN_COUNT, mode); | ||
return; | ||
} | ||
#endif | ||
__pinMode(pin, mode); | ||
} |