Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • flow3r/flow3r-firmware
  • Vespasian/flow3r-firmware
  • alxndr42/flow3r-firmware
  • pl/flow3r-firmware
  • Kari/flow3r-firmware
  • raimue/flow3r-firmware
  • grandchild/flow3r-firmware
  • mu5tach3/flow3r-firmware
  • Nervengift/flow3r-firmware
  • arachnist/flow3r-firmware
  • TheNewCivilian/flow3r-firmware
  • alibi/flow3r-firmware
  • manuel_v/flow3r-firmware
  • xeniter/flow3r-firmware
  • maxbachmann/flow3r-firmware
  • yGifoom/flow3r-firmware
  • istobic/flow3r-firmware
  • EiNSTeiN_/flow3r-firmware
  • gnudalf/flow3r-firmware
  • 999eagle/flow3r-firmware
  • toerb/flow3r-firmware
  • pandark/flow3r-firmware
  • teal/flow3r-firmware
  • x42/flow3r-firmware
  • alufers/flow3r-firmware
  • dos/flow3r-firmware
  • yrlf/flow3r-firmware
  • LuKaRo/flow3r-firmware
  • ThomasElRubio/flow3r-firmware
  • ai/flow3r-firmware
  • T_X/flow3r-firmware
  • highTower/flow3r-firmware
  • beanieboi/flow3r-firmware
  • Woazboat/flow3r-firmware
  • gooniesbro/flow3r-firmware
  • marvino/flow3r-firmware
  • kressnerd/flow3r-firmware
  • quazgar/flow3r-firmware
  • aoid/flow3r-firmware
  • jkj/flow3r-firmware
  • naomi/flow3r-firmware
41 results
Select Git revision
Show changes
Showing
with 1657 additions and 0 deletions
//simple instrument example implementation
//trad_osc is made up rn, didn't check how the existing implementation works
typedef struct{
unsigned int * sample_rate;
hardware_inputs_t * hw;
trad_osc_t[30] osc;
unsigned int sample_rate;
hardware_inputs_t * hw;
float last_freq; //frequency of last note played to write to display
} minimal_example_t;
void minimal_example_render_sample(instrument_handle inst, float * stereo_output){
float acc = 0;
for(int i = 0; i < 30; i++){
acc += trad_osc_run(&inst.osc[i], inst.sample_rate);
}
stereo_output[0] = acc; // both channels the same -> mono
stereo_output[1] = acc;
}
void minimal_example_process_user_input(instrument_handle inst){
static int petal_prev[10];
for(int i = 0; i < 10; i++){
if(inst->hw.petals[i].intensity > 0){ //if the pad is touched...
if(!petal_prev[i]){ //and it's a new touch...
if(button != 2){ //if button isn't pressed: play single note in different octaves
int j = i + (inst->hw.button + 1) * 10; //choose osc
trad_osc_start(&inst.osc[j]); //play a tone
inst->last_freq = inst.osc[j].freq;
} else { //for button center: all the octaves at once
trad_osc_start(&inst.osc[i]); //play a tone
trad_osc_start(&inst.osc[i+10]); //play a tone
trad_osc_start(&inst.osc[i+20]); //play a tone
inst->last_freq = inst.osc[i+10].freq;
}
}
petal_prev[i] = 1;
} else {
petal_prev[i] = 0;
}
}
}
void minimal_example_update_display(instrument_handle inst){
display_print("%f", inst->last_freq);
}
static float pad_to_freq(int pad){
int j = pad % 10;
if(j) j++; //skip min 2nd
if(j>8) j++; //skip maj 6th
j += (pad/10) * 12; //add octaves
float freq = 440 * pow(2., j/12.);
}
instrument_t new_minimal_example(
const struct _instrument_descriptor * descriptor,
unsigned int sample_rate,
hardware_inputs_t * hw)
{
instrument_t inst = malloc(sizeof(minimal_example_t));
if(inst == NULL) return NULL;
inst->sample_rate = sample_rate;
inst->hw = hw;
for(int i = 0; i < 30; i++){
inst->osc[i] = trad_osc_new(pad_to_freq(i), sample_rate);
//other osc parameters (wave, envelope, etc.) omitted for clarity
}
return inst;
}
void delete_minimal_example(instrument_t inst){
free(inst);
}
const instrument_descriptor_t * minimal_example_descriptor(){
instrument_descriptor_t * inst = malloc(sizeof(instrument_descriptor_t));
if(inst == NULL) return NULL;
inst->unique_id = 0;
inst->name = "simple instrument";
inst->render_audio_sample = &minimal_example_render_sample;
inst->new_instrument = &new_minimal_example;
inst->delete_instrument = &delete_minimal_example;
inst->update_display = NULL;
inst->process_user_input = minimal_example_user_input;
inst->update_leds = NULL;
}
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "esp_system.h"
#include "badge23/leds.h"
#include "badge23_hwconfig.h"
#if defined(CONFIG_BADGE23_HW_GEN_P1)
#define LED_SPI_PORT
#elif defined(CONFIG_BADGE23_HW_GEN_P3) || defined(CONFIG_BADGE23_HW_GEN_P4)
#define LED_ASYNC_PORT
#else
#error "leds not implemented for this badge generation"
#endif
typedef struct leds_cfg {
int leaf;
size_t size;
size_t position;
size_t slot;
int timer;
} leds_cfg_t;
static leds_cfg_t active_leds[11];
struct RGB
{
unsigned char R;
unsigned char G;
unsigned char B;
};
struct HSV
{
double H;
double S;
double V;
};
struct RGB HSVToRGB(struct HSV hsv) {
double r = 0, g = 0, b = 0;
if (hsv.S == 0)
{
r = hsv.V;
g = hsv.V;
b = hsv.V;
}
else
{
int i;
double f, p, q, t;
if (hsv.H == 360)
hsv.H = 0;
else
hsv.H = hsv.H / 60;
i = (int)trunc(hsv.H);
f = hsv.H - i;
p = hsv.V * (1.0 - hsv.S);
q = hsv.V * (1.0 - (hsv.S * f));
t = hsv.V * (1.0 - (hsv.S * (1.0 - f)));
switch (i)
{
case 0:
r = hsv.V;
g = t;
b = p;
break;
case 1:
r = q;
g = hsv.V;
b = p;
break;
case 2:
r = p;
g = hsv.V;
b = t;
break;
case 3:
r = p;
g = q;
b = hsv.V;
break;
case 4:
r = t;
g = p;
b = hsv.V;
break;
default:
r = hsv.V;
g = p;
b = q;
break;
}
}
struct RGB rgb;
rgb.R = r * 255;
rgb.G = g * 255;
rgb.B = b * 255;
return rgb;
}
#ifdef LED_SPI_PORT
#include "driver/spi_master.h"
#include "badge23/apa102LEDStrip.h"
#define totalPixels 40
#define bytesPerPixel 4
static struct apa102LEDStrip leds;
static spi_device_handle_t spi_led;
static spi_transaction_t spiTransObject;
static esp_err_t ret;
static spi_bus_config_t buscfg;
static spi_device_interface_config_t devcfg;
#define maxSPIFrameInBytes 8000
#define maxSPIFrequency 10000000
void renderLEDs()
{
spi_device_queue_trans(spi_led, &spiTransObject, portMAX_DELAY);
}
static int setupSPI()
{
//Set up the Bus Config struct
buscfg.miso_io_num=-1;
buscfg.mosi_io_num=18;
buscfg.sclk_io_num=8;
buscfg.quadwp_io_num=-1;
buscfg.quadhd_io_num=-1;
buscfg.max_transfer_sz=maxSPIFrameInBytes;
//Set up the SPI Device Configuration Struct
devcfg.clock_speed_hz=maxSPIFrequency;
devcfg.mode=0;
devcfg.spics_io_num=-1;
devcfg.queue_size=1;
//Initialize the SPI driver
ret=spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO);
ESP_ERROR_CHECK(ret);
//Add SPI port to bus
ret=spi_bus_add_device(SPI2_HOST, &devcfg, &spi_led);
ESP_ERROR_CHECK(ret);
return ret;
}
void set_single_led(uint8_t index, uint8_t c[3]){
setPixel(&leds, index, c);
}
static void _leds_init() {
memset(active_leds, 0 , sizeof(active_leds));
setupSPI();
initLEDs(&leds, totalPixels, bytesPerPixel, 255);
//Set up SPI tx/rx storage Object
memset(&spiTransObject, 0, sizeof(spiTransObject));
spiTransObject.length = leds._frameLength*8;
spiTransObject.tx_buffer = leds.LEDs;
TaskHandle_t handle;
//xTaskCreate(&leds_task, "LEDs player", 4096, NULL, configMAX_PRIORITIES - 2, &handle);
}
#endif
#ifdef LED_ASYNC_PORT
#include "../../espressif__led_strip/include/led_strip.h"
led_strip_t *led_strip_init(uint8_t channel, uint8_t gpio, uint16_t led_num);
#define LED_GPIO_NUM 14
#define LED_RMT_CHAN 0
led_strip_t * led_strip;
static void _leds_init(){
memset(active_leds, 0 , sizeof(active_leds));
led_strip = led_strip_init(LED_RMT_CHAN, LED_GPIO_NUM, 40);
}
void set_single_led(uint8_t index, uint8_t c[3]){
index = ((39-index) + 1 + 32)%40;
led_strip->set_pixel(led_strip, index, c[0], c[1], c[2]);
}
static void renderLEDs(){
led_strip->refresh(led_strip, 1000);
}
#endif
void leds_set_single_rgb(uint8_t index, uint8_t red, uint8_t green, uint8_t blue){
index = (index + 3) % 40;
uint8_t c[3];
c[0] = red;
c[1] = green;
c[2] = blue;
set_single_led(index, c);
}
void leds_set_single_hsv(uint8_t index, float hue, float sat, float val){
index = (index + 3) % 40;
struct RGB rgb;
struct HSV hsv;
hsv.H = hue;
hsv.S = sat;
hsv.V = val;
rgb = HSVToRGB(hsv);
uint8_t c[3];
c[0] = rgb.R;
c[1] = rgb.G;
c[2] = rgb.B;
set_single_led(index, c);
}
void leds_update(){
vTaskDelay(10 / portTICK_PERIOD_MS); //do we...
renderLEDs();
vTaskDelay(10 / portTICK_PERIOD_MS); //...need these?
}
void leds_init() { _leds_init(); }
#include "badge23/scope.h"
#include <string.h>
scope_t * scope;
void init_scope(uint16_t size){
scope_t * scp = malloc(sizeof(scope_t));
if(scp == NULL) scope = NULL;
scp->buffer_size = size;
scp->buffer = malloc(sizeof(int16_t) * scp->buffer_size);
if(scp->buffer == NULL){
free(scp);
scope = NULL;
} else {
memset(scp->buffer, 0, sizeof(int16_t) * scp->buffer_size);
scope = scp;
}
}
void write_to_scope(int16_t value){
if(scope->is_being_read) return;
if(scope == NULL) return;
scope->write_head_position++;
if(scope->write_head_position >= scope->buffer_size) scope->write_head_position = 0;
scope->buffer[scope->write_head_position] = value;
}
void begin_scope_read(){
if(scope == NULL) return;
scope->is_being_read = 1; //best mutex
}
void read_line_from_scope(uint16_t * line, int16_t point){
memset(line, 0, 480);
int16_t startpoint = scope->write_head_position - point;
while(startpoint < 0){
startpoint += scope->buffer_size;
}
int16_t stoppoint = startpoint - 1;
if(stoppoint < 0){
stoppoint += scope->buffer_size;
}
int16_t start = (scope->buffer[point]/32 + 120);
int16_t stop = (scope->buffer[point+1]/32 + 120);
if(start>240) start = 240;
if(start<0) start = 0;
if(stop>240) stop = 240;
if(stop<0) stop = 0;
if(start > stop){
int16_t inter = start;
start = stop;
stop = inter;
}
for(int16_t i = start; i <= stop; i++){
line[i] = 255;
}
}
void end_scope_read(){
if(scope == NULL) return;
scope->is_being_read = 0; //best mutex
}
//special purpose input outputs
#include "driver/gpio.h"
#include "badge23_hwconfig.h"
#include "stdint.h"
static int8_t leftbutton = 0;
static int8_t rightbutton = 0;
#if defined(CONFIG_BADGE23_HW_GEN_P1)
#define RIGHT_BUTTON_LEFT 37
#define RIGHT_BUTTON_MID 0
#define RIGHT_BUTTON_RIGHT 35
#define LEFT_BUTTON_LEFT 7
#define LEFT_BUTTON_MID 6
#define LEFT_BUTTON_RIGHT 5
static void _init_buttons(){
//configure all buttons as pullup
uint64_t mask = 0;
mask |= (1ULL << RIGHT_BUTTON_LEFT);
mask |= (1ULL << RIGHT_BUTTON_RIGHT);
mask |= (1ULL << LEFT_BUTTON_LEFT);
mask |= (1ULL << LEFT_BUTTON_MID);
mask |= (1ULL << LEFT_BUTTON_RIGHT);
gpio_config_t cfg = {
.pin_bit_mask = mask,
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
ESP_ERROR_CHECK(gpio_config(&cfg));
cfg.pin_bit_mask = 1;
cfg.pull_up_en = GPIO_PULLUP_DISABLE;
ESP_ERROR_CHECK(gpio_config(&cfg));
}
void update_button_state(){
if(!gpio_get_level(RIGHT_BUTTON_LEFT)){
rightbutton = -1;
} else if(!gpio_get_level(RIGHT_BUTTON_MID)){
rightbutton = 2;
} else if(!gpio_get_level(RIGHT_BUTTON_RIGHT)){
rightbutton = 1;
} else {
rightbutton = 0;
}
if(!gpio_get_level(LEFT_BUTTON_LEFT)){
leftbutton = -1;
} else if(!gpio_get_level(LEFT_BUTTON_MID)){
leftbutton = 2;
} else if(!gpio_get_level(LEFT_BUTTON_RIGHT)){
leftbutton = 1;
} else {
leftbutton = 0;
}
}
#elif defined(CONFIG_BADGE23_HW_GEN_P3) || defined(CONFIG_BADGE23_HW_GEN_P4)
#include "driver/i2c.h"
#define I2C_MASTER_NUM 0
#define TIMEOUT_MS 1000
//on ESP32
#define LEFT_BUTTON_LEFT 3
#define LEFT_BUTTON_MID 0
//on PORTEXPANDER
#define LEFT_BUTTON_RIGHT 0
#define RIGHT_BUTTON_LEFT 6
#define RIGHT_BUTTON_MID 5
#define RIGHT_BUTTON_RIGHT 7
static void _init_buttons(){
//configure all buttons as pullup
gpio_config_t cfg = {
.pin_bit_mask = 1 << LEFT_BUTTON_LEFT,
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
ESP_ERROR_CHECK(gpio_config(&cfg));
cfg.pin_bit_mask = 1;
cfg.pull_up_en = GPIO_PULLUP_DISABLE;
ESP_ERROR_CHECK(gpio_config(&cfg));
printf("nya\n");
}
void update_button_state(){
uint8_t port;
esp_err_t ret = i2c_master_read_from_device(I2C_MASTER_NUM, 0b1101101, &port, sizeof(port), TIMEOUT_MS / portTICK_PERIOD_MS);
uint8_t rr = port & (1ULL << RIGHT_BUTTON_RIGHT);
uint8_t rm = port & (1ULL << RIGHT_BUTTON_MID);
uint8_t rl = port & (1ULL << RIGHT_BUTTON_LEFT);
uint8_t lr = port & (1ULL << LEFT_BUTTON_RIGHT);
uint8_t ll = gpio_get_level(LEFT_BUTTON_LEFT);
uint8_t lm = gpio_get_level(LEFT_BUTTON_MID);
if(!rl){
rightbutton = -1;
} else if(!rm){
rightbutton = 2;
} else if(!rr){
rightbutton = 1;
} else {
rightbutton = 0;
}
if(!ll){
leftbutton = -1;
} else if(!lm){
leftbutton = 2;
} else if(!lr){
leftbutton = 1;
} else {
leftbutton = 0;
}
}
#else
#error "spio not implemented for this badge generation"
#endif
void init_buttons(){
_init_buttons();
}
//#define ALWAYS_UPDATE_BUTTON
int8_t get_button_state(bool left){
#ifdef ALWAYS_UPDATE_BUTTON
update_button_state();
#endif
if(left) return leftbutton;
return rightbutton;
}
#include "badge23/synth.h"
#include "badge23/audio.h"
#include <math.h>
float ks_osc(ks_osc_t * ks, float input){
//TODO: FIX THIS
ks->real_feedback = ks->feedback;
float delay_time = ((float) (SAMPLE_RATE))/ks->freq;
if(delay_time >= (KS_BUFFER_SIZE)) delay_time = (KS_BUFFER_SIZE) - 1;
//ks->tape[0] = input + real_feedback * ks->tape[delay_time];
return ks->tape[0];
}
float waveshaper(uint8_t shape, float in);
float nes_noise(uint16_t * reg, uint8_t mode, uint8_t run);
void run_trad_env(trad_osc_t * osc){
switch(osc->env_phase){
case 0:
osc->env = 0; osc->counter = 0; osc->env_counter = 0;
break;
case 1:
if(osc->attack_steps){
if(osc->env == 0){
osc->env = (TRAD_OSC_MIN_ATTACK_ENV);
} else {
osc->env_counter++;
if(osc->env_counter > osc->attack_steps){
osc->env *= (1. + (TRAD_OSC_ATTACK_STEP));
osc->env_counter = 0;
}
}
} else {
osc->env += osc->vol/TRAD_OSC_ATTACK_POP_BLOCK;
}
if(osc->env > osc->vol){
osc->env_phase = 2;
osc->env = osc->vol;
}
break;
case 2:
osc->env = osc->vol;
osc->env_counter = 0;
if(osc->skip_hold) osc->env_phase = 3;
break;
case 3:
if(osc->decay_steps){
osc->env_counter++;
if(osc->env_counter > osc->decay_steps){
osc->env *= (1. - (TRAD_OSC_DECAY_STEP));
osc->env_counter = 0;
}
if(osc->env < osc->gate){
osc->env_phase = 0; osc->env = 0; osc->counter = 0;
}
} else {
osc->env_phase = 0; osc->env = 0; osc->counter = 0;
}
break;
}
}
float run_trad_osc(trad_osc_t * osc){
run_trad_env(osc);
if(!osc->env_phase) return 0;
float ret = 0;
//run core sawtooth
float freq = osc->freq * osc->bend;
if(freq > 10000) freq = 10000;
if(freq < -10000) freq = -10000;
if(freq != freq) freq = 0;
osc->counter += 2. * freq / ((float)(SAMPLE_RATE));
if(osc->counter != osc->counter){
printf("trad_osc counter is NaN");
abort();
}
while(osc->counter > 1.){
osc->counter -= 2.;
osc->overflow_event = 1;
}
while(osc->counter < -1.){
osc->counter += 2.;
osc->overflow_event = -1;
}
if(osc->waveform >= 7){
ret = nes_noise(&(osc->noise_reg), osc->waveform == 7, osc->overflow_event);
osc->overflow_event = 0;
} else {
//apply waveshaper
ret = waveshaper(osc->waveform, osc->counter);
}
//apply volume
ret *= osc->env;
return ret;
}
float nes_noise(uint16_t * reg, uint8_t mode, uint8_t run){
if(run) {
uint8_t fb = *reg;
if(mode){
fb = fb>>6;
} else {
fb = fb>>1;
}
fb = (fb ^ (*reg)) & 1;
*reg = (*reg >> 1);
*reg = (*reg) | (((uint16_t) fb) << 14);
}
return ((float) ((*reg) & 1)) * 2 - 1;
}
float waveshaper(uint8_t shape, float in){
//expects sawtooth input in [-1..1] range
switch(shape){
case 0: // TODO: implement proper sine
in = sin(in * 3.1415);
break;
case 1: //fast sine
in = waveshaper(2, in);
if(in > 0.){
in = 1. - in;
in *= in;
in = 1. - in;
} else {
in = 1. + in;
in *= in;
in = in - 1.;
}
break;
case 2: //triangle
in += 0.5;
if(in > 1.0) in -= 2;
if(in > 0.) in = -in;
in = (2. * in) + 1.;
break;
case 3: //sawtooth
break;
case 4: //square
if(in > 0){
in = 1.;
} else {
in = -1.;
}
break;
case 5: //33% pulse
if(in > 0.33){
in = 1.;
} else {
in = -1.;
}
break;
case 6: //25% pulse
if(in > 0.5){
in = 1.;
} else {
in = -1.;
}
break;
}
return in;
}
#define NAT_LOG_SEMITONE 0.05776226504666215
void trad_osc_set_freq_semitone(trad_osc_t * osc, float bend){
osc->freq = 440. * exp(bend * NAT_LOG_SEMITONE);
}
void trad_osc_set_freq_Hz(trad_osc_t * osc, float freq){
osc->freq = freq;
}
void trad_osc_set_waveform(trad_osc_t * osc, uint8_t waveform){
osc->waveform = waveform;
}
void trad_osc_set_attack(trad_osc_t * osc, uint16_t attack){
osc->attack_steps = attack;
}
void trad_osc_set_decay(trad_osc_t * osc, uint16_t decay){
osc->decay_steps = decay;
}
void trad_env_stop(trad_osc_t * osc){
if(osc->env_phase) osc->env_phase = 3;
}
void trad_env_fullstop(trad_osc_t * osc){
osc->env_phase = 0; //stop and skip decay phase
}
void trad_env_start(trad_osc_t * osc){
osc->env_phase = 1; //put into attack phase;
}
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_EXCMD mixed /number, pattern, mixed, or combineV2/
!_TAG_OUTPUT_FILESEP slash /slash or backslash/
!_TAG_OUTPUT_MODE u-ctags /u-ctags or e-ctags/
!_TAG_PATTERN_LENGTH_LIMIT 96 /0 for no limit/
!_TAG_PROC_CWD /home/zjfms/fluff/badge2023/bootstrap/software/espan/main/ //
!_TAG_PROGRAM_AUTHOR Universal Ctags Team //
!_TAG_PROGRAM_NAME Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL https://ctags.io/ /official site/
!_TAG_PROGRAM_VERSION 5.9.0 /p5.9.20220828.0/
AD7147_BASE_ADDR captouch.c /^#define AD7147_BASE_ADDR /;" d file:
AD7147_REG_DEVICE_ID captouch.c /^#define AD7147_REG_DEVICE_ID /;" d file:
AD7147_REG_PWR_CONTROL captouch.c /^#define AD7147_REG_PWR_CONTROL /;" d file:
AD7147_REG_STAGE_CAL_EN captouch.c /^#define AD7147_REG_STAGE_CAL_EN /;" d file:
AD7147_REG_STAGE_HIGH_INT_ENABLE captouch.c /^#define AD7147_REG_STAGE_HIGH_INT_ENABLE /;" d file:
CIN captouch.c /^#define CIN /;" d file:
CIN_BIAS captouch.c /^#define CIN_BIAS /;" d file:
CIN_CDC_NEG captouch.c /^#define CIN_CDC_NEG /;" d file:
CIN_CDC_POS captouch.c /^#define CIN_CDC_POS /;" d file:
CONFIG_I2C_MASTER_SCL Kconfig.projbuild /^ config I2C_MASTER_SCL$/;" c menu:Example Configuration
CONFIG_I2C_MASTER_SCL_MODULE Kconfig.projbuild /^ config I2C_MASTER_SCL$/;" c menu:Example Configuration
CONFIG_I2C_MASTER_SDA Kconfig.projbuild /^ config I2C_MASTER_SDA$/;" c menu:Example Configuration
CONFIG_I2C_MASTER_SDA_MODULE Kconfig.projbuild /^ config I2C_MASTER_SDA$/;" c menu:Example Configuration
DEF_apa102LEDStrip apa102LEDStrip.h /^#define DEF_apa102LEDStrip$/;" d
DMA_BUFFER_COUNT audio.c /^#define DMA_BUFFER_COUNT /;" d file:
DMA_BUFFER_SIZE audio.c /^#define DMA_BUFFER_SIZE /;" d file:
ESP_INTR_FLAG_DEFAULT captouch.c /^#define ESP_INTR_FLAG_DEFAULT /;" d file:
Example Configuration Kconfig.projbuild /^menu "Example Configuration"$/;" m
I2C_MASTER_FREQ_HZ espan.c /^#define I2C_MASTER_FREQ_HZ /;" d file:
I2C_MASTER_NUM captouch.c /^#define I2C_MASTER_NUM /;" d file:
I2C_MASTER_NUM espan.c /^#define I2C_MASTER_NUM /;" d file:
I2C_MASTER_RX_BUF_DISABLE espan.c /^#define I2C_MASTER_RX_BUF_DISABLE /;" d file:
I2C_MASTER_SCL Kconfig.projbuild /^ config I2C_MASTER_SCL$/;" c menu:Example Configuration
I2C_MASTER_SCL_IO espan.c /^#define I2C_MASTER_SCL_IO /;" d file:
I2C_MASTER_SDA Kconfig.projbuild /^ config I2C_MASTER_SDA$/;" c menu:Example Configuration
I2C_MASTER_SDA_IO espan.c /^#define I2C_MASTER_SDA_IO /;" d file:
I2C_MASTER_TX_BUF_DISABLE espan.c /^#define I2C_MASTER_TX_BUF_DISABLE /;" d file:
LEDs apa102LEDStrip.h /^ unsigned char *LEDs;$/;" m struct:apa102LEDStrip typeref:typename:unsigned char *
MIN audio.c /^#define MIN(/;" d file:
SAMPLE_RATE audio.c /^#define SAMPLE_RATE /;" d file:
TAG captouch.c /^static const char *TAG = "captouch";$/;" v typeref:typename:const char * file:
TAG espan.c /^static const char *TAG = "espan";$/;" v typeref:typename:const char * file:
TIMEOUT_MS captouch.c /^#define TIMEOUT_MS /;" d file:
_audio_init audio.c /^static void _audio_init(int i2s_num) {$/;" f typeref:typename:void file:
_bytesPerLED apa102LEDStrip.h /^ unsigned char _bytesPerLED;$/;" m struct:apa102LEDStrip typeref:typename:unsigned char
_counter apa102LEDStrip.h /^ short int _counter;$/;" m struct:apa102LEDStrip typeref:typename:short int
_endFrameLength apa102LEDStrip.h /^ short int _endFrameLength;$/;" m struct:apa102LEDStrip typeref:typename:short int
_frameLength apa102LEDStrip.h /^ short int _frameLength;$/;" m struct:apa102LEDStrip typeref:typename:short int
_globalBrightness apa102LEDStrip.h /^ unsigned char _globalBrightness;$/;" m struct:apa102LEDStrip typeref:typename:unsigned char
_numLEDs apa102LEDStrip.h /^ short int _numLEDs;$/;" m struct:apa102LEDStrip typeref:typename:short int
active_paddles espan.c /^static bool active_paddles[10];$/;" v typeref:typename:bool[10] file:
active_sounds audio.c /^static sound_cfg_t active_sounds[11];$/;" v typeref:typename:sound_cfg_t[11] file:
ad7147_device_config captouch.c /^struct ad7147_device_config {$/;" s file:
ad7147_stage_config captouch.c /^struct ad7147_stage_config {$/;" s file:
ad714x_chip captouch.c /^struct ad714x_chip {$/;" s file:
ad714x_default_config captouch.c /^static struct ad7147_stage_config ad714x_default_config(void)$/;" f typeref:struct:ad7147_stage_config file:
ad714x_i2c_read captouch.c /^static esp_err_t ad714x_i2c_read(const struct ad714x_chip *chip, const uint16_t reg, uint16_t *d/;" f typeref:typename:esp_err_t file:
ad714x_i2c_write captouch.c /^static esp_err_t ad714x_i2c_write(const struct ad714x_chip *chip, const uint16_t reg, const uint/;" f typeref:typename:esp_err_t file:
ad714x_set_device_config captouch.c /^static void ad714x_set_device_config(const struct ad714x_chip *chip, const struct ad7147_device_/;" f typeref:typename:void file:
ad714x_set_stage_config captouch.c /^static void ad714x_set_stage_config(const struct ad714x_chip *chip, const uint8_t stage, const s/;" f typeref:typename:void file:
addr captouch.c /^ uint8_t addr;$/;" m struct:ad714x_chip typeref:typename:uint8_t file:
afe_offsets captouch.c /^ int afe_offsets[13];$/;" m struct:ad714x_chip typeref:typename:int[13] file:
apa102LEDStrip apa102LEDStrip.h /^struct apa102LEDStrip$/;" s
app_main espan.c /^void app_main(void)$/;" f typeref:typename:void
audio_init audio.c /^void audio_init() { _audio_init(0); }$/;" f typeref:typename:void
audio_player_task audio.c /^static void audio_player_task(void* arg) {$/;" f typeref:typename:void file:
avg_fp_skip captouch.c /^ unsigned int avg_fp_skip:2;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:2 file:
avg_lp_skip captouch.c /^ unsigned int avg_lp_skip:2;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:2 file:
bank2 captouch.c /^static const uint16_t bank2 = 0x80;$/;" v typeref:typename:const uint16_t file:
black espan.c /^uint8_t black[] = {0,0,0};$/;" v typeref:typename:uint8_t[]
blue espan.c /^uint8_t blue[] = {0,0,32};$/;" v typeref:typename:uint8_t[]
bot_map espan.c /^uint8_t bot_map[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4};$/;" v typeref:typename:uint8_t[]
buffer audio.c /^ const int16_t* buffer;$/;" m struct:sound_cfg typeref:typename:const int16_t * file:
buscfg espan.c /^spi_bus_config_t buscfg;$/;" v typeref:typename:spi_bus_config_t
bytesPerPixel espan.c /^#define bytesPerPixel /;" d file:
captouch_init captouch.c /^void captouch_init(void)$/;" f typeref:typename:void
captouch_init_chip captouch.c /^static void captouch_init_chip(const struct ad714x_chip* chip)$/;" f typeref:typename:void file:
captouch_print_debug_info captouch.c /^void captouch_print_debug_info(void)$/;" f typeref:typename:void
captouch_print_debug_info_chip captouch.c /^static void captouch_print_debug_info_chip(const struct ad714x_chip* chip)$/;" f typeref:typename:void file:
cdc_bias captouch.c /^ unsigned int cdc_bias:2;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:2 file:
chip_bot captouch.c /^static const struct ad714x_chip chip_bot = {.addr = AD7147_BASE_ADDR, .gpio = 3, .afe_offsets = /;" v typeref:typename:const struct ad714x_chip file:
chip_top captouch.c /^static const struct ad714x_chip chip_top = {.addr = AD7147_BASE_ADDR + 1, .gpio = 48, .afe_offse/;" v typeref:typename:const struct ad714x_chip file:
cinX_connection_setup captouch.c /^ unsigned int cinX_connection_setup[13];$/;" m struct:ad7147_stage_config typeref:typename:unsigned int[13] file:
decimation captouch.c /^ unsigned int decimation:2;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:2 file:
devcfg espan.c /^spi_device_interface_config_t devcfg;$/;" v typeref:typename:spi_device_interface_config_t
espan_handle_captouch espan.c /^void espan_handle_captouch(uint16_t pressed_top, uint16_t pressed_bot)$/;" f typeref:typename:void
ext_source captouch.c /^ unsigned int ext_source:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
free_buffer audio.c /^ bool free_buffer;$/;" m struct:sound_cfg typeref:typename:bool file:
getPixel apa102LEDStrip.c /^void getPixel(struct apa102LEDStrip *ledObject, short int pixelIndex, unsigned char *pixelColour/;" f typeref:typename:void
gpio captouch.c /^ uint8_t gpio;$/;" m struct:ad714x_chip typeref:typename:uint8_t file:
gpio_event_handler captouch.c /^static void gpio_event_handler(void* arg)$/;" f typeref:typename:void file:
gpio_evt_queue captouch.c /^static QueueHandle_t gpio_evt_queue = NULL;$/;" v typeref:typename:QueueHandle_t file:
gpio_isr_handler captouch.c /^static void IRAM_ATTR gpio_isr_handler(void* arg)$/;" f typeref:typename:void IRAM_ATTR file:
i2c_master_init espan.c /^static esp_err_t i2c_master_init(void)$/;" f typeref:typename:esp_err_t file:
initLEDs apa102LEDStrip.c /^void initLEDs(struct apa102LEDStrip *ledObject, short int numLEDs, unsigned char bytesPerLED, un/;" f typeref:typename:void
int_pol captouch.c /^ unsigned int int_pol:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
leds espan.c /^struct apa102LEDStrip leds;$/;" v typeref:struct:apa102LEDStrip
lp_conv_delay captouch.c /^ unsigned int lp_conv_delay:2;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:2 file:
maxSPIFrameInBytes espan.c /^#define maxSPIFrameInBytes /;" d file:
maxSPIFrequency espan.c /^#define maxSPIFrequency /;" d file:
maxValuePerColour espan.c /^#define maxValuePerColour /;" d file:
neg_afe_offset captouch.c /^ unsigned int neg_afe_offset:6;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:6 file:
neg_afe_offset_disable captouch.c /^ unsigned int neg_afe_offset_disable:1;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:1 file:
neg_afe_offset_swap captouch.c /^ unsigned int neg_afe_offset_swap:1;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:1 file:
neg_peak_detect captouch.c /^ unsigned int neg_peak_detect:3;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:3 file:
neg_threshold_sensitivity captouch.c /^ unsigned int neg_threshold_sensitivity:4;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:4 file:
paddle_leds espan.c /^static const uint8_t paddle_leds[][9] = {$/;" v typeref:typename:const uint8_t[][9] file:
play_bootsound audio.c /^void play_bootsound() {$/;" f typeref:typename:void
play_pan audio.c /^void play_pan(int pan) {$/;" f typeref:typename:void
pos_afe_offset captouch.c /^ unsigned int pos_afe_offset:6;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:6 file:
pos_afe_offset_disable captouch.c /^ unsigned int pos_afe_offset_disable:1;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:1 file:
pos_afe_offset_swap captouch.c /^ unsigned int pos_afe_offset_swap:1;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:1 file:
pos_peak_detect captouch.c /^ unsigned int pos_peak_detect:3;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:3 file:
pos_threshold_sensitivity captouch.c /^ unsigned int pos_threshold_sensitivity:4;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:4 file:
position audio.c /^ size_t position;$/;" m struct:sound_cfg typeref:typename:size_t file:
power_mode captouch.c /^ unsigned int power_mode:2;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:2 file:
pressed_bot captouch.c /^static uint16_t pressed_top, pressed_bot;$/;" v typeref:typename:uint16_t file:
pressed_top captouch.c /^static uint16_t pressed_top, pressed_bot;$/;" v typeref:typename:uint16_t file:
red espan.c /^uint8_t red[] = {32,0,0};$/;" v typeref:typename:uint8_t[]
renderLEDs espan.c /^void renderLEDs()$/;" f typeref:typename:void
ret espan.c /^esp_err_t ret;$/;" v typeref:typename:esp_err_t
se_connection_setup captouch.c /^ unsigned int se_connection_setup:2;$/;" m struct:ad7147_stage_config typeref:typename:unsigned int:2 file:
sequence_stage_num captouch.c /^ unsigned int sequence_stage_num:4;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:4 file:
setPixel apa102LEDStrip.c /^void setPixel(struct apa102LEDStrip *ledObject, short int pixelIndex, unsigned char *pixelColour/;" f typeref:typename:void
setupSPI espan.c /^int setupSPI()$/;" f typeref:typename:int
size audio.c /^ size_t size;$/;" m struct:sound_cfg typeref:typename:size_t file:
slot audio.c /^ size_t slot;$/;" m struct:sound_cfg typeref:typename:size_t file:
sound_active audio.c /^static bool sound_active(void)$/;" f typeref:typename:bool file:
sound_cfg audio.c /^typedef struct sound_cfg {$/;" s file:
sound_cfg_t audio.c /^} sound_cfg_t;$/;" t typeref:struct:sound_cfg file:
sound_queue audio.c /^static QueueHandle_t sound_queue = NULL;$/;" v typeref:typename:QueueHandle_t file:
spiTransObject espan.c /^spi_transaction_t spiTransObject;$/;" v typeref:typename:spi_transaction_t
spi_led espan.c /^spi_device_handle_t spi_led;$/;" v typeref:typename:spi_device_handle_t
stage0_cal_en captouch.c /^ unsigned int stage0_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage0_high_int_enable captouch.c /^ unsigned int stage0_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage10_cal_en captouch.c /^ unsigned int stage10_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage10_high_int_enable captouch.c /^ unsigned int stage10_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage11_cal_en captouch.c /^ unsigned int stage11_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage11_high_int_enable captouch.c /^ unsigned int stage11_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage1_cal_en captouch.c /^ unsigned int stage1_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage1_high_int_enable captouch.c /^ unsigned int stage1_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage2_cal_en captouch.c /^ unsigned int stage2_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage2_high_int_enable captouch.c /^ unsigned int stage2_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage3_cal_en captouch.c /^ unsigned int stage3_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage3_high_int_enable captouch.c /^ unsigned int stage3_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage4_cal_en captouch.c /^ unsigned int stage4_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage4_high_int_enable captouch.c /^ unsigned int stage4_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage5_cal_en captouch.c /^ unsigned int stage5_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage5_high_int_enable captouch.c /^ unsigned int stage5_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage6_cal_en captouch.c /^ unsigned int stage6_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage6_high_int_enable captouch.c /^ unsigned int stage6_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage7_cal_en captouch.c /^ unsigned int stage7_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage7_high_int_enable captouch.c /^ unsigned int stage7_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage8_cal_en captouch.c /^ unsigned int stage8_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage8_high_int_enable captouch.c /^ unsigned int stage8_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage9_cal_en captouch.c /^ unsigned int stage9_cal_en:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stage9_high_int_enable captouch.c /^ unsigned int stage9_high_int_enable:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
stages captouch.c /^ int stages;$/;" m struct:ad714x_chip typeref:typename:int file:
sw_reset captouch.c /^ unsigned int sw_reset:1;$/;" m struct:ad7147_device_config typeref:typename:unsigned int:1 file:
top_map espan.c /^uint8_t top_map[] = {1, 1, 1, 0, 0, 4, 4, 4, 3, 3, 2, 2};$/;" v typeref:typename:uint8_t[]
totalPixels espan.c /^#define totalPixels /;" d file:
idf_component_register(
SRCS
badge23_hwconfig.c
INCLUDE_DIRS
include
)
#include "badge23_hwconfig.h"
#if defined(CONFIG_BADGE23_HW_GEN_P1)
const char *badge23_hw_name = "proto1";
#elif defined(CONFIG_BADGE23_HW_GEN_P3)
const char *badge23_hw_name = "proto3";
#elif defined(CONFIG_BADGE23_HW_GEN_P4)
const char *badge23_hw_name = "proto4";
#elif defined(CONFIG_BADGE23_HW_GEN_ADILESS)
const char *badge23_hw_name = "adiless";
#else
#error "Badge23 Hardware Generation must be set!"
#endif
#pragma once
#include "sdkconfig.h"
// internal name of the badge hardware version (proto1, proto3, etc).
const char *badge23_hw_name;
idf_component_register(SRCS "led_strip_rmt_ws2812.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES "driver"
)
# LED Strip Component
This directory contains an implementation for addressable LEDs using the RMT peripheral.
It's compatible with:
* [WS2812](http://www.world-semi.com/Certifications/WS2812B.html)
* SK68XX
This component is used as part of the following ESP-IDF examples:
- [Blink Example](../../get-started/blink).
- [LED Strip Example](../../peripherals/rmt/led_strip).
To learn more about how to use this component, please check API Documentation from header file [led_strip.h](./include/led_strip.h).
Please note that this component is not considered to be a part of ESP-IDF stable API. It may change and it may be removed in the future releases.
version: "1.1.0-alpha"
description: C driver, based on RMT peripheral, for WS2812 and SK6812 smart RGB diodes
dependencies:
# Required IDF version
idf:
version: ">=4.0"
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_err.h"
/**
* @brief LED Strip Type
*
*/
typedef struct led_strip_s led_strip_t;
/**
* @brief LED Strip Device Type
*
*/
typedef void *led_strip_dev_t;
/**
* @brief Declare of LED Strip Type
*
*/
struct led_strip_s {
/**
* @brief Set RGB for a specific pixel
*
* @param strip: LED strip
* @param index: index of pixel to set
* @param red: red part of color
* @param green: green part of color
* @param blue: blue part of color
*
* @return
* - ESP_OK: Set RGB for a specific pixel successfully
* - ESP_ERR_INVALID_ARG: Set RGB for a specific pixel failed because of invalid parameters
* - ESP_FAIL: Set RGB for a specific pixel failed because other error occurred
*/
esp_err_t (*set_pixel)(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue);
/**
* @brief Refresh memory colors to LEDs
*
* @param strip: LED strip
* @param timeout_ms: timeout value for refreshing task
*
* @return
* - ESP_OK: Refresh successfully
* - ESP_ERR_TIMEOUT: Refresh failed because of timeout
* - ESP_FAIL: Refresh failed because some other error occurred
*
* @note:
* After updating the LED colors in the memory, a following invocation of this API is needed to flush colors to strip.
*/
esp_err_t (*refresh)(led_strip_t *strip, uint32_t timeout_ms);
/**
* @brief Clear LED strip (turn off all LEDs)
*
* @param strip: LED strip
* @param timeout_ms: timeout value for clearing task
*
* @return
* - ESP_OK: Clear LEDs successfully
* - ESP_ERR_TIMEOUT: Clear LEDs failed because of timeout
* - ESP_FAIL: Clear LEDs failed because some other error occurred
*/
esp_err_t (*clear)(led_strip_t *strip, uint32_t timeout_ms);
/**
* @brief Free LED strip resources
*
* @param strip: LED strip
*
* @return
* - ESP_OK: Free resources successfully
* - ESP_FAIL: Free resources failed because error occurred
*/
esp_err_t (*del)(led_strip_t *strip);
};
/**
* @brief LED Strip Configuration Type
*
*/
typedef struct {
uint32_t max_leds; /*!< Maximum LEDs in a single strip */
led_strip_dev_t dev; /*!< LED strip device (e.g. RMT channel, PWM channel, etc) */
} led_strip_config_t;
/**
* @brief Default configuration for LED strip
*
*/
#define LED_STRIP_DEFAULT_CONFIG(number, dev_hdl) \
{ \
.max_leds = number, \
.dev = dev_hdl, \
}
/**
* @brief Install a new ws2812 driver (based on RMT peripheral)
*
* @param config: LED strip configuration
* @return
* LED strip instance or NULL
*/
led_strip_t *led_strip_new_rmt_ws2812(const led_strip_config_t *config);
/**
* @brief Init the RMT peripheral and LED strip configuration.
*
* @param[in] channel: RMT peripheral channel number.
* @param[in] gpio: GPIO number for the RMT data output.
* @param[in] led_num: number of addressable LEDs.
* @return
* LED strip instance or NULL
*/
led_strip_t *led_strip_init(uint8_t channel, uint8_t gpio, uint16_t led_num);
/**
* @brief Denit the RMT peripheral.
*
* @param[in] strip: LED strip
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t led_strip_denit(led_strip_t *strip);
#ifdef __cplusplus
}
#endif
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdlib.h>
#include <string.h>
#include <sys/cdefs.h>
#include "esp_log.h"
#include "esp_attr.h"
#include "led_strip.h"
#include "driver/rmt.h"
#define RMT_TX_CHANNEL RMT_CHANNEL_0
static const char *TAG = "ws2812";
#define STRIP_CHECK(a, str, goto_tag, ret_value, ...) \
do \
{ \
if (!(a)) \
{ \
ESP_LOGE(TAG, "%s(%d): " str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
ret = ret_value; \
goto goto_tag; \
} \
} while (0)
#define WS2812_T0H_NS (350)
#define WS2812_T0L_NS (1000)
#define WS2812_T1H_NS (1000)
#define WS2812_T1L_NS (350)
#define WS2812_RESET_US (280)
static uint32_t ws2812_t0h_ticks = 0;
static uint32_t ws2812_t1h_ticks = 0;
static uint32_t ws2812_t0l_ticks = 0;
static uint32_t ws2812_t1l_ticks = 0;
typedef struct {
led_strip_t parent;
rmt_channel_t rmt_channel;
uint32_t strip_len;
uint8_t buffer[0];
} ws2812_t;
/**
* @brief Conver RGB data to RMT format.
*
* @note For WS2812, R,G,B each contains 256 different choices (i.e. uint8_t)
*
* @param[in] src: source data, to converted to RMT format
* @param[in] dest: place where to store the convert result
* @param[in] src_size: size of source data
* @param[in] wanted_num: number of RMT items that want to get
* @param[out] translated_size: number of source data that got converted
* @param[out] item_num: number of RMT items which are converted from source data
*/
static void IRAM_ATTR ws2812_rmt_adapter(const void *src, rmt_item32_t *dest, size_t src_size,
size_t wanted_num, size_t *translated_size, size_t *item_num)
{
if (src == NULL || dest == NULL) {
*translated_size = 0;
*item_num = 0;
return;
}
const rmt_item32_t bit0 = {{{ ws2812_t0h_ticks, 1, ws2812_t0l_ticks, 0 }}}; //Logical 0
const rmt_item32_t bit1 = {{{ ws2812_t1h_ticks, 1, ws2812_t1l_ticks, 0 }}}; //Logical 1
size_t size = 0;
size_t num = 0;
uint8_t *psrc = (uint8_t *)src;
rmt_item32_t *pdest = dest;
while (size < src_size && num < wanted_num) {
for (int i = 0; i < 8; i++) {
// MSB first
if (*psrc & (1 << (7 - i))) {
pdest->val = bit1.val;
} else {
pdest->val = bit0.val;
}
num++;
pdest++;
}
size++;
psrc++;
}
*translated_size = size;
*item_num = num;
}
static esp_err_t ws2812_set_pixel(led_strip_t *strip, uint32_t index, uint32_t red, uint32_t green, uint32_t blue)
{
esp_err_t ret = ESP_OK;
ws2812_t *ws2812 = __containerof(strip, ws2812_t, parent);
STRIP_CHECK(index < ws2812->strip_len, "index out of the maximum number of leds", err, ESP_ERR_INVALID_ARG);
uint32_t start = index * 3;
// In thr order of GRB
ws2812->buffer[start + 0] = green & 0xFF;
ws2812->buffer[start + 1] = red & 0xFF;
ws2812->buffer[start + 2] = blue & 0xFF;
return ESP_OK;
err:
return ret;
}
static esp_err_t ws2812_refresh(led_strip_t *strip, uint32_t timeout_ms)
{
esp_err_t ret = ESP_OK;
ws2812_t *ws2812 = __containerof(strip, ws2812_t, parent);
STRIP_CHECK(rmt_write_sample(ws2812->rmt_channel, ws2812->buffer, ws2812->strip_len * 3, true) == ESP_OK,
"transmit RMT samples failed", err, ESP_FAIL);
return rmt_wait_tx_done(ws2812->rmt_channel, pdMS_TO_TICKS(timeout_ms));
err:
return ret;
}
static esp_err_t ws2812_clear(led_strip_t *strip, uint32_t timeout_ms)
{
ws2812_t *ws2812 = __containerof(strip, ws2812_t, parent);
// Write zero to turn off all leds
memset(ws2812->buffer, 0, ws2812->strip_len * 3);
return ws2812_refresh(strip, timeout_ms);
}
static esp_err_t ws2812_del(led_strip_t *strip)
{
ws2812_t *ws2812 = __containerof(strip, ws2812_t, parent);
free(ws2812);
return ESP_OK;
}
led_strip_t *led_strip_new_rmt_ws2812(const led_strip_config_t *config)
{
led_strip_t *ret = NULL;
STRIP_CHECK(config, "configuration can't be null", err, NULL);
// 24 bits per led
uint32_t ws2812_size = sizeof(ws2812_t) + config->max_leds * 3;
ws2812_t *ws2812 = calloc(1, ws2812_size);
STRIP_CHECK(ws2812, "request memory for ws2812 failed", err, NULL);
uint32_t counter_clk_hz = 0;
STRIP_CHECK(rmt_get_counter_clock((rmt_channel_t)config->dev, &counter_clk_hz) == ESP_OK,
"get rmt counter clock failed", err, NULL);
// ns -> ticks
float ratio = (float)counter_clk_hz / 1e9;
ws2812_t0h_ticks = (uint32_t)(ratio * WS2812_T0H_NS);
ws2812_t0l_ticks = (uint32_t)(ratio * WS2812_T0L_NS);
ws2812_t1h_ticks = (uint32_t)(ratio * WS2812_T1H_NS);
ws2812_t1l_ticks = (uint32_t)(ratio * WS2812_T1L_NS);
// set ws2812 to rmt adapter
rmt_translator_init((rmt_channel_t)config->dev, ws2812_rmt_adapter);
ws2812->rmt_channel = (rmt_channel_t)config->dev;
ws2812->strip_len = config->max_leds;
ws2812->parent.set_pixel = ws2812_set_pixel;
ws2812->parent.refresh = ws2812_refresh;
ws2812->parent.clear = ws2812_clear;
ws2812->parent.del = ws2812_del;
return &ws2812->parent;
err:
return ret;
}
led_strip_t *led_strip_init(uint8_t channel, uint8_t gpio, uint16_t led_num)
{
static led_strip_t *pStrip;
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(gpio, channel);
// set counter clock to 40MHz
config.clk_div = 2;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
// install ws2812 driver
led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(led_num, (led_strip_dev_t)config.channel);
pStrip = led_strip_new_rmt_ws2812(&strip_config);
if ( !pStrip ) {
ESP_LOGE(TAG, "install WS2812 driver failed");
return NULL;
}
// Clear LED strip (turn off all LEDs)
// This will fail for inverted output
//ESP_ERROR_CHECK(pStrip->clear(pStrip, 100));
return pStrip;
}
esp_err_t led_strip_denit(led_strip_t *strip)
{
ws2812_t *ws2812 = __containerof(strip, ws2812_t, parent);
ESP_ERROR_CHECK(rmt_driver_uninstall(ws2812->rmt_channel));
return strip->del(strip);
}
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
idf_component_register(SRCS "gc9a01.c" REQUIRES driver badge23_hwconfig INCLUDE_DIRS ".")
BSD 3-Clause License
Copyright (c) 2021, liyanboy74
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed.
//--------------------------------------------------------------------------------------------------------
// Nadyrshin Ruslan - [YouTube-channel: https://www.youtube.com/channel/UChButpZaL5kUUl_zTyIDFkQ]
// Liyanboy74
//--------------------------------------------------------------------------------------------------------
#ifndef _GC9A01_H
#define _GC9A01_H
#include "sdkconfig.h"
#include <stdint.h>
#include "badge23_hwconfig.h"
#ifdef CONFIG_GC9A01_PIN_NUM_MOSI
#warning "idf menuconfig is ignored for display config, it breaks hardware revision switching atm"
#endif
#if defined(CONFIG_BADGE23_HW_GEN_P1)
#define USE_SPI3_HOST 1
#define GC9A01_SPI_HOST 2
#define GC9A01_PIN_NUM_SCK 39
#define GC9A01_PIN_NUM_MOSI 41
#define GC9A01_PIN_NUM_CS 40
#define GC9A01_PIN_NUM_DC 42
#define GC9A01_SPI_SCK_FREQ_M 80
#define GC9A01_RESET_USED 1
#define GC9A01_PIN_NUM_RST 38
#define GC9A01_BUFFER_MODE 1
#elif defined(CONFIG_BADGE23_HW_GEN_P3) || defined(CONFIG_BADGE23_HW_GEN_P4)
#define USE_SPI3_HOST 1
#define GC9A01_SPI_HOST 2
#define GC9A01_PIN_NUM_SCK 41
#define GC9A01_PIN_NUM_MOSI 42
#define GC9A01_PIN_NUM_CS 40
#define GC9A01_PIN_NUM_DC 38
#define GC9A01_SPI_SCK_FREQ_M 80
#define GC9A01_CONTROL_BACK_LIGHT_USED 1
#define GC9A01_PIN_NUM_BCKL 46
#define GC9A01_BACK_LIGHT_MODE_PWM 1
#define GC9A01_CONTROL_BACK_LIGHT_MODE 1
#define GC9A01_BUFFER_MODE 1
#else
#error "gc9a01 unimplemented for this badge generation"
#endif
#define GC9A01_Width 240
#define GC9A01_Height 240
extern uint16_t ScreenBuff[GC9A01_Height * GC9A01_Width];
uint16_t GC9A01_GetWidth();
uint16_t GC9A01_GetHeight();
void GC9A01_Init();
void GC9A01_SleepMode(uint8_t Mode);
void GC9A01_DisplayPower(uint8_t On);
void GC9A01_DrawPixel(int16_t x, int16_t y, uint16_t color);
void GC9A01_FillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void GC9A01_Update();
void GC9A01_SetBL(uint8_t Value);
uint16_t GC9A01_GetPixel(int16_t x, int16_t y);
void GC9A01_Screen_Shot(uint16_t x,uint16_t y,uint16_t width ,uint16_t height,uint16_t * Buffer);
void GC9A01_Screen_Load(uint16_t x,uint16_t y,uint16_t width ,uint16_t height,uint16_t * Buffer);
#endif
# GC9A01 ESP-IDF Component
Clone to `components` folder and run `idf.py menuconfig`
![ESP-IDF_menuconfig](https://user-images.githubusercontent.com/64005694/111914456-43582400-8a87-11eb-9173-375262b5a261.jpg)
**Add as submodule:**
`git submodule add https://github.com/liyanboy74/gc9a01-esp-idf.git components/gc9a01`
**Example Test:**
```c
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "gc9a01.h"
#define STACK_SIZE 2048
void LCD(void * arg)
{
uint16_t Color;
GC9A01_Init();
for(;;)
{
Color=rand();
GC9A01_FillRect(0,0,239,239,Color);
GC9A01_Update();
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}
void app_main(void)
{
TaskHandle_t LCDHandle;
xTaskCreate(LCD,"Test LCD",STACK_SIZE,NULL,tskIDLE_PRIORITY,&LCDHandle);
configASSERT(LCDHandle);
}
```
- If you succeed, it's time to go one layer higher! Try [Dispcolor](https://github.com/liyanboy74/dispcolor)
- You can also use the [BMP24 to RGB565](https://github.com/liyanboy74/bmp24-to-rgb565) tools to convert and display images