// Define constants for LED on/off states, repeat flag, event and state types
#define LED_ON (0x1)
#define LED_OFF (0x0)
#define LED_REPEAT (0x1)
#define LED_EVENT_TYPE (0x0)
#define LED_STATE_TYPE (0x1)
// Define constants for various LED patterns
typedef enum {
LED_EVENT_POWER_ON,
LED_EVENT_POWER_OFF,
LED_EVENT_FACTORY_RESET,
LED_EVENT_CONNECTED,//3
LED_EVENT_LINEIN_PLUGININ,
LED_STATE_PAIRING,
LED_STATE_RECONNECT,
LED_STATE_CONNECTABLE,//7
LED_STATE_CONNECTED,
LED_STATE_POWER_OFF,
LED_STATE_NO_CONNECTION,
LED_STATE_BATTERY_LOW, //11
LED_STATE_BATTERY_CHARGING,
LED_STATE_BATTERY_FULL,
LED_STATE_FACTORY_BLUR,
LED_STATE_LINEIN,
LED_LAST_INDEX
} LedPattern_t;
#define LED_NUM_PATTERNS ( LED_LAST_INDEX )
// Define the LED entry structure, including LED mask, time parameters for lighting up and off, and blink count
typedef struct {
uint8_t led_mask; // LED mask, used to identify the specific LED channel
uint16_t rise_time; // Duration from off to the brightest state (milliseconds)
uint16_t brightest_time; // Duration of the brightest state (milliseconds)
uint16_t fall_time; // Duration from the brightest to off state (milliseconds)
uint16_t darkest_time; // Duration of the off state (milliseconds)
uint16_t blink_count; // Number of blinks
uint16_t total_time;
} LedEntry;
// Define the LED header structure, including LED pattern, state or event type, and timeout
typedef struct {
uint8_t num_entries;
LedPattern_t pattern; // LED pattern
uint8_t state_or_event; // State or event type
uint8_t on_or_off;
uint16_t timeout; // Timeout in milliseconds
} LedHeader;
// Define the LED structure, including header information and a pointer to the LED entry
typedef struct {
LedHeader header; // LED header information
const LedEntry* entries; // Pointer to the LED entry
} LedDisplayConfig;
extern const LedDisplayConfig gLedDisplayConfigs[];#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
// Define LED channel masks
#define BLUE_LED_MASK (HAL_ISINK_CHANNEL_1)
#define RED_LED_MASK (HAL_ISINK_CHANNEL_0)
// Blue LED power-on event pattern
static const LedEntry blue_led_power_on_pattern_event[] = {
// Blue flashes quickly twice
{BLUE_LED_MASK, 0, 250, 0, 250, 2, 0}
};
// Blue LED power-off event pattern
static const LedEntry blue_led_power_off_pattern_event[] = {
// Blue flashes quickly twice
{BLUE_LED_MASK, 0, 250, 0, 250, 2, 0}
};
// Blue LED factory reset event pattern
static const LedEntry blue_led_factory_reset_pattern_event[] = {
// Blue flashes quickly twice
{BLUE_LED_MASK, 0, 250, 0, 250, 2, 0}
};
// Blue LED connected event pattern
static const LedEntry blue_led_connected_pattern_event[] = {
// Blue stays on for 5 seconds then turns off
{BLUE_LED_MASK, 0, 5000, 0, 0, 1, 0}
};
// Blue LED pairing state pattern
static const LedEntry blue_led_pairing_pattern_state[] = {
// Blue flashes quickly
{BLUE_LED_MASK, 250, 150, 250, 150, 0, 0}
};
// Blue LED reconnected state pattern
static const LedEntry blue_led_reconnect_pattern_state[] = {
// Blue flashes slowly
{BLUE_LED_MASK, 1000, 500, 1000, 500, 0, 0}
};
// Blue LED connectable state pattern
static const LedEntry blue_led_connectable_pattern_state[] = {
// Blue flashes slowly
{BLUE_LED_MASK, 1000, 500, 1000, 500, 0, 0}
};
// Blue LED connected state pattern
static const LedEntry blue_led_connected_pattern_state[] = {
// Blue is off
{BLUE_LED_MASK, 0, 0, 0, 0, 0, 0}
};
// Blue LED power off state pattern
static const LedEntry blue_led_power_off_pattern_state[] = {
// Blue is off
{BLUE_LED_MASK, 0, 0, 0, 0, 0, 0}
};
// Blue LED bt no connection state pattern
static const LedEntry blue_led_no_connection_pattern_state[] = {
// Blue flashes slowly
{BLUE_LED_MASK, 1000, 500, 1000, 500, 0, 0}
};
// Red LED low battery state pattern
static const LedEntry red_led_battery_low_pattern_state[] = {
// Red flashes slowly
{RED_LED_MASK, 0, 500, 0, 2000, 0, 0}
};
// Red LED battery charging state pattern
static const LedEntry red_led_battery_charging_pattern_state[] = {
// Red stays on constantly
{RED_LED_MASK, 0, 500, 0, 0, 0, 0}
};
// Red LED battery full state pattern
static const LedEntry red_led_battery_full_pattern_state[] = {
// Red is off
{RED_LED_MASK, 0, 0, 0, 0, 0, 0}
};
// Blue LED fctory test event pattern
static const LedEntry blue_led_factory_test_pattern_event[] = {
// Blue stays on constant
{BLUE_LED_MASK, 0, 5000, 0, 0, 0, 0}
};
// Blue LED linein test event pattern
static const LedEntry blue_led_linein_pattern_state[] = {
// Blue stays on constant
{BLUE_LED_MASK, 0, 0, 0, 0, 0, 0}
};
static const LedEntry blue_led_linein_plugin_pattern_event[] = {
// Blue stays on constant
{BLUE_LED_MASK, 0, 200, 0, 200, 3, 1000},
{BLUE_LED_MASK, 0, 0, 0, 1000, 0, 1000},
{BLUE_LED_MASK, 0, 200, 0, 200, 3, 0},
};
// Define an array of LED patterns, including information for all LED patterns
const LedDisplayConfig gLedDisplayConfigs[LED_NUM_PATTERNS] = {
{ {ARRAY_SIZE(blue_led_power_on_pattern_event), LED_EVENT_POWER_ON, LED_EVENT_TYPE, LED_ON, 1200}, blue_led_power_on_pattern_event },
{ {ARRAY_SIZE(blue_led_power_off_pattern_event), LED_EVENT_POWER_OFF, LED_EVENT_TYPE, LED_ON, 1200}, blue_led_power_off_pattern_event },
{ {ARRAY_SIZE(blue_led_factory_reset_pattern_event), LED_EVENT_FACTORY_RESET, LED_EVENT_TYPE, LED_ON, 1200}, blue_led_factory_reset_pattern_event },
{ {ARRAY_SIZE(blue_led_connected_pattern_event), LED_EVENT_CONNECTED, LED_EVENT_TYPE, LED_ON, 5000}, blue_led_connected_pattern_event },
{ {ARRAY_SIZE(blue_led_linein_plugin_pattern_event), LED_EVENT_LINEIN_PLUGININ, LED_EVENT_TYPE, LED_ON, 3000}, blue_led_linein_plugin_pattern_event },
{ {ARRAY_SIZE(blue_led_pairing_pattern_state), LED_STATE_PAIRING, LED_STATE_TYPE, LED_ON, 0 }, blue_led_pairing_pattern_state },
{ {ARRAY_SIZE(blue_led_reconnect_pattern_state), LED_STATE_RECONNECT, LED_STATE_TYPE, LED_ON, 0 }, blue_led_reconnect_pattern_state },
{ {ARRAY_SIZE(blue_led_connectable_pattern_state), LED_STATE_CONNECTABLE, LED_STATE_TYPE, LED_ON, 0 }, blue_led_connectable_pattern_state },
{ {ARRAY_SIZE(blue_led_connected_pattern_state), LED_STATE_CONNECTED, LED_STATE_TYPE, LED_OFF, 0 }, blue_led_connected_pattern_state },
{ {ARRAY_SIZE(blue_led_power_off_pattern_state), LED_STATE_POWER_OFF, LED_STATE_TYPE, LED_OFF, 0 }, blue_led_power_off_pattern_state },
{ {ARRAY_SIZE(blue_led_no_connection_pattern_state), LED_STATE_NO_CONNECTION, LED_STATE_TYPE, LED_ON, 0 }, blue_led_no_connection_pattern_state },
{ {ARRAY_SIZE(red_led_battery_low_pattern_state), LED_STATE_BATTERY_LOW, LED_STATE_TYPE, LED_ON, 0 }, red_led_battery_low_pattern_state },
{ {ARRAY_SIZE(red_led_battery_charging_pattern_state), LED_STATE_BATTERY_CHARGING,LED_STATE_TYPE, LED_ON, 0 }, red_led_battery_charging_pattern_state },
{ {ARRAY_SIZE(red_led_battery_full_pattern_state), LED_STATE_BATTERY_FULL, LED_STATE_TYPE, LED_OFF, 0 }, red_led_battery_full_pattern_state },
{ {ARRAY_SIZE(blue_led_factory_test_pattern_event), LED_STATE_FACTORY_BLUR, LED_STATE_TYPE, LED_ON, 0 }, blue_led_factory_test_pattern_event },
{ {ARRAY_SIZE(blue_led_linein_pattern_state), LED_STATE_LINEIN, LED_STATE_TYPE, LED_OFF, 0 }, blue_led_linein_pattern_state }
};
void app_cchip_leds_show_event(uint8_t led_index);
void app_cchip_leds_show_state(uint8_t led_index);根据上面灯效数据,用C语音和和freertos操作系统实现这两个函数