Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/leds/i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
#include <logging.h>

#if CONFIG_LEDS_I2S_ENABLED
i2s_port_t leds_interface_i2s_port(enum leds_interface interface)
{
switch(interface) {
#if LEDS_I2S_INTERFACE_COUNT > 0
case LEDS_INTERFACE_I2S0:
return I2S_PORT_0;
#endif

#if LEDS_I2S_INTERFACE_COUNT > 1
case LEDS_INTERFACE_I2S1:
return I2S_PORT_1;
#endif

default:
LOG_FATAL("%u", interface);
}
}

size_t leds_i2s_serial_buffer_size(enum leds_protocol protocol, unsigned led_count)
{
const struct leds_protocol_type *protocol_type = leds_protocol_type(protocol);
Expand Down
19 changes: 16 additions & 3 deletions components/leds/include/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

#if CONFIG_LEDS_I2S_ENABLED
# include <i2s_out.h>
# define LEDS_I2S_INTERFACE_COUNT I2S_PORT_MAX
# define LEDS_I2S_GPIO_PINS_ENABLED I2S_OUT_GPIO_PINS_SUPPORTED
# define LEDS_I2S_GPIO_PINS_SIZE I2S_OUT_GPIO_PINS_MAX
# define LEDS_I2S_PARALLEL_ENABLED I2S_OUT_PARALLEL_SUPPORTED
# define LEDS_I2S_PARALLEL_MAX I2S_OUT_PARALLEL_DATA_BITS_MAX
# define LEDS_I2S_REPEAT_MAX 64

# define LEDS_INTERFACE_I2S(i) (LEDS_INTERFACE_I2S0 + (i))
#endif

#if CONFIG_LEDS_SPI_ENABLED && CONFIG_IDF_TARGET_ESP8266
Expand Down Expand Up @@ -47,7 +50,7 @@ enum leds_interface {
* - LEDS_PROTOCOL_APA102
* - LEDS_PROTOCOL_P9813
*/
LEDS_INTERFACE_SPI = 1,
LEDS_INTERFACE_SPI,
#endif

#if CONFIG_LEDS_UART_ENABLED
Expand All @@ -56,7 +59,7 @@ enum leds_interface {
* - LEDS_PROTOCOL_SK6812_GRBW
* - LEDS_PROTOCOL_WS2811
*/
LEDS_INTERFACE_UART = 2,
LEDS_INTERFACE_UART,
#endif

#if CONFIG_LEDS_I2S_ENABLED
Expand All @@ -66,7 +69,12 @@ enum leds_interface {
* - LEDS_PROTOCOL_SK6812_GRBW
* - LEDS_PROTOCOL_SK9822
*/
LEDS_INTERFACE_I2S = 3,
#if LEDS_I2S_INTERFACE_COUNT > 0
LEDS_INTERFACE_I2S0,
#endif
#if LEDS_I2S_INTERFACE_COUNT > 1
LEDS_INTERFACE_I2S1,
#endif
#endif

LEDS_INTERFACE_COUNT
Expand Down Expand Up @@ -244,6 +252,11 @@ enum leds_interface leds_interface_for_protocol(enum leds_protocol protocol);
unsigned repeat; // LEDS_I2S_REPEAT_MAX
};

/*
* Return port for interface
*/
i2s_port_t leds_interface_i2s_port(enum leds_interface interface);

/*
* Returns total TX buffer size, align required for protocol with `led_count` LEDs on one serial pin.
*
Expand Down
20 changes: 14 additions & 6 deletions components/leds/include/leds_stats.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#pragma once

#include <leds.h>
#include <stats.h>

#include <sdkconfig.h>

#if CONFIG_LEDS_I2S_ENABLED
struct leds_interface_i2s_stats {
struct stats_timer open;
struct stats_timer write;
struct stats_timer flush;
};
#endif

struct leds_interface_stats {
#if CONFIG_LEDS_SPI_ENABLED
struct leds_interface_spi_stats {
Expand All @@ -17,12 +26,11 @@ struct leds_interface_stats {
struct stats_timer tx;
} uart;
#endif
#if CONFIG_LEDS_I2S_ENABLED
struct leds_interface_i2s_stats {
struct stats_timer open;
struct stats_timer write;
struct stats_timer flush;
} i2s;
#if LEDS_I2S_INTERFACE_COUNT > 0
struct leds_interface_i2s_stats i2s0;
#endif
#if LEDS_I2S_INTERFACE_COUNT > 1
struct leds_interface_i2s_stats i2s1;
#endif
};

Expand Down
10 changes: 8 additions & 2 deletions components/leds/interface.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <leds.h>
#include "leds.h"
#include "interface.h"
#include "stats.h"

#include <logging.h>

Expand Down Expand Up @@ -42,12 +43,17 @@ int leds_interface_init(union leds_interface_state *interface, const struct leds
#endif

#if CONFIG_LEDS_I2S_ENABLED
case LEDS_INTERFACE_I2S:
# if LEDS_I2S_INTERFACE_COUNT > 0
case LEDS_INTERFACE_I2S0:
# endif
# if LEDS_I2S_INTERFACE_COUNT > 1
case LEDS_INTERFACE_I2S1:
# endif
if (!protocol_type->i2s_interface_mode) {
LOG_ERROR("unsupported interface=I2S for protocol=%d", options->protocol);
return -1;

} else if ((err = leds_interface_i2s_init(&interface->i2s, &options->i2s, protocol_type->i2s_interface_mode, protocol_type->i2s_interface_func))) {
} else if ((err = leds_interface_i2s_init(&interface->i2s, &options->i2s, protocol_type->i2s_interface_mode, protocol_type->i2s_interface_func, leds_interface_i2s_stats(options->interface)))) {
LOG_ERROR("leds_interface_i2s_init");
return err;
}
Expand Down
3 changes: 2 additions & 1 deletion components/leds/interfaces/i2s.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ struct leds_interface_i2s {
struct i2s_out_options i2s_out_options;

struct leds_interface_options_gpio gpio;
struct leds_interface_i2s_stats *stats;
};

size_t leds_interface_i2s_buffer_size(enum leds_interface_i2s_mode mode, unsigned led_count, unsigned pin_count);
size_t leds_interface_i2s_buffer_align(enum leds_interface_i2s_mode mode, unsigned pin_count);

int leds_interface_i2s_init(struct leds_interface_i2s *interface, const struct leds_interface_i2s_options *options, enum leds_interface_i2s_mode mode, union leds_interface_i2s_func func);
int leds_interface_i2s_init(struct leds_interface_i2s *interface, const struct leds_interface_i2s_options *options, enum leds_interface_i2s_mode mode, union leds_interface_i2s_func func, struct leds_interface_i2s_stats *stats);
int leds_interface_i2s_tx(struct leds_interface_i2s *interface, const struct leds_color *pixels, unsigned count, const struct leds_limit *limit);

#endif
10 changes: 5 additions & 5 deletions components/leds/interfaces/i2s/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static int leds_interface_i2s_tx_write(struct leds_interface_i2s *interface, con
}
}

int leds_interface_i2s_init(struct leds_interface_i2s *interface, const struct leds_interface_i2s_options *options, enum leds_interface_i2s_mode mode, union leds_interface_i2s_func func)
int leds_interface_i2s_init(struct leds_interface_i2s *interface, const struct leds_interface_i2s_options *options, enum leds_interface_i2s_mode mode, union leds_interface_i2s_func func, struct leds_interface_i2s_stats *stats)
{
interface->mode = mode;
interface->func = func;
Expand Down Expand Up @@ -283,13 +283,13 @@ int leds_interface_i2s_init(struct leds_interface_i2s *interface, const struct l
#endif

interface->gpio = options->gpio;
interface->stats = stats;

return 0;
}

int leds_interface_i2s_tx(struct leds_interface_i2s *interface, const struct leds_color *pixels, unsigned count, const struct leds_limit *limit)
{
struct leds_interface_i2s_stats *stats = &leds_interface_stats.i2s;
int err;

switch (interface->mode) {
Expand Down Expand Up @@ -317,7 +317,7 @@ int leds_interface_i2s_tx(struct leds_interface_i2s *interface, const struct led
LOG_FATAL("unknown mode=%d", interface->mode);
}

WITH_STATS_TIMER(&stats->open) {
WITH_STATS_TIMER(&interface->stats->open) {
if ((err = i2s_out_open(interface->i2s_out, &interface->i2s_out_options))) {
LOG_ERROR("i2s_out_open");
return err;
Expand All @@ -328,7 +328,7 @@ int leds_interface_i2s_tx(struct leds_interface_i2s *interface, const struct led
leds_gpio_setup(&interface->gpio);
#endif

WITH_STATS_TIMER(&stats->write) {
WITH_STATS_TIMER(&interface->stats->write) {
if ((err = leds_interface_i2s_tx_write(interface, pixels, count, limit))) {
goto error;
}
Expand All @@ -341,7 +341,7 @@ int leds_interface_i2s_tx(struct leds_interface_i2s *interface, const struct led
}
}

WITH_STATS_TIMER(&stats->flush) {
WITH_STATS_TIMER(&interface->stats->flush) {
if ((err = i2s_out_flush(interface->i2s_out))) {
LOG_ERROR("i2s_out_flush");
goto error;
Expand Down
9 changes: 7 additions & 2 deletions components/leds/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,13 @@ int leds_tx(struct leds *leds)
#endif

#if CONFIG_LEDS_I2S_ENABLED
case LEDS_INTERFACE_I2S:
return leds_interface_i2s_tx(&leds->interface.i2s, leds->pixels, leds->options.count, &leds->limit);
# if LEDS_I2S_INTERFACE_COUNT > 0
case LEDS_INTERFACE_I2S0:
# endif
# if LEDS_I2S_INTERFACE_COUNT > 1
case LEDS_INTERFACE_I2S1:
# endif
return leds_interface_i2s_tx(&leds->interface.i2s, leds->pixels, leds->options.count, &leds->limit);
#endif

default:
Expand Down
8 changes: 7 additions & 1 deletion components/leds/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ enum leds_interface leds_interface_for_protocol(enum leds_protocol protocol)

#if CONFIG_LEDS_I2S_ENABLED
if (protocol_type->i2s_interface_mode) {
return LEDS_INTERFACE_I2S;
# if LEDS_I2S_INTERFACE_COUNT > 1
return LEDS_INTERFACE_I2S1;
# elif LEDS_I2S_INTERFACE_COUNT > 0
return LEDS_INTERFACE_I2S0;
# else
return LEDS_INTERFACE_NONE;
# endif
}
#endif

Expand Down
31 changes: 27 additions & 4 deletions components/leds/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "leds.h"
#include "leds_stats.h"

#include <logging.h>

struct leds_interface_stats leds_interface_stats;

void leds_reset_interface_stats()
Expand All @@ -14,14 +16,35 @@ void leds_reset_interface_stats()
stats_timer_init(&leds_interface_stats.uart.open);
stats_timer_init(&leds_interface_stats.uart.tx);
#endif
#if CONFIG_LEDS_I2S_ENABLED
stats_timer_init(&leds_interface_stats.i2s.open);
stats_timer_init(&leds_interface_stats.i2s.write);
stats_timer_init(&leds_interface_stats.i2s.flush);
#if LEDS_I2S_INTERFACE_COUNT > 0
stats_timer_init(&leds_interface_stats.i2s0.open);
stats_timer_init(&leds_interface_stats.i2s0.write);
stats_timer_init(&leds_interface_stats.i2s0.flush);
#endif
#if LEDS_I2S_INTERFACE_COUNT > 1
stats_timer_init(&leds_interface_stats.i2s1.open);
stats_timer_init(&leds_interface_stats.i2s1.write);
stats_timer_init(&leds_interface_stats.i2s1.flush);
#endif
}

void leds_get_interface_stats(struct leds_interface_stats *stats)
{
*stats = leds_interface_stats;
}

struct leds_interface_i2s_stats *leds_interface_i2s_stats(enum leds_interface interface)
{
switch(interface) {
#if LEDS_I2S_INTERFACE_COUNT > 0
case LEDS_INTERFACE_I2S0:
return &leds_interface_stats.i2s0;
#endif
#if LEDS_I2S_INTERFACE_COUNT > 1
case LEDS_INTERFACE_I2S1:
return &leds_interface_stats.i2s1;
#endif
default:
LOG_FATAL("%u", interface);
}
}
2 changes: 2 additions & 0 deletions components/leds/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#include <leds_stats.h>

extern struct leds_interface_stats leds_interface_stats;

struct leds_interface_i2s_stats *leds_interface_i2s_stats(enum leds_interface interface);
4 changes: 0 additions & 4 deletions main/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ const struct configmod config_modules[] = {
.description = "LEDS UART interface",
.table = leds_uart_configtab,
},
{ "leds-i2s",
.description = "LEDS I2S interface",
.table = leds_i2s_configtab,
},
{ "leds-sequence",
.description = "LEDS Sequence support",
.table = leds_sequence_configtab,
Expand Down
12 changes: 8 additions & 4 deletions main/leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ int init_leds()
#endif

#if CONFIG_LEDS_I2S_ENABLED
if ((err = init_leds_i2s())) {
LOG_ERROR("init_leds_i2s");
return 0;
for (unsigned i = 0; i < LEDS_I2S_INTERFACE_COUNT; i++) {
if ((err = init_leds_i2s(i))) {
LOG_ERROR("init_leds_i2s%u", i);
return 0;
}
}
#endif

Expand Down Expand Up @@ -155,8 +157,10 @@ int check_leds_interface(struct leds_state *state)
}

switch (leds_interface(state->leds)) {
case LEDS_INTERFACE_I2S:
#if CONFIG_IDF_TARGET_ESP8266
case LEDS_INTERFACE_I2S0:
return check_leds_i2s(state);
#endif

default:
return 0;
Expand Down
1 change: 0 additions & 1 deletion main/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
extern const struct configtab leds_gpio_configtab[];
extern const struct configtab leds_spi_configtab[];
extern const struct configtab leds_uart_configtab[];
extern const struct configtab leds_i2s_configtab[];
extern const struct configtab leds_sequence_configtab[];
extern const struct configtab *leds_configtabs[LEDS_COUNT];
extern const struct cmdtab leds_cmdtab;
Expand Down
14 changes: 10 additions & 4 deletions main/leds_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,16 @@ int leds_cmd_stats(int argc, char **argv, void *ctx)
printf("\n");
#endif

#if CONFIG_LEDS_I2S_ENABLED
print_stats_timer("i2s", "open", &stats.i2s.open);
print_stats_timer("i2s", "write", &stats.i2s.write);
print_stats_timer("i2s", "flush", &stats.i2s.flush);
#if LEDS_I2S_INTERFACE_COUNT > 0
print_stats_timer("i2s0", "open", &stats.i2s0.open);
print_stats_timer("i2s0", "write", &stats.i2s0.write);
print_stats_timer("i2s0", "flush", &stats.i2s0.flush);
printf("\n");
#endif
#if LEDS_I2S_INTERFACE_COUNT > 1
print_stats_timer("i2s1", "open", &stats.i2s1.open);
print_stats_timer("i2s1", "write", &stats.i2s1.write);
print_stats_timer("i2s1", "flush", &stats.i2s1.flush);
printf("\n");
#endif
}
Expand Down
Loading
Loading