mirror of
https://github.com/whowechina/popn_pico.git
synced 2025-01-19 07:57:24 +01:00
Minor refactoring
This commit is contained in:
parent
882b9d6794
commit
868c530aa2
@ -90,23 +90,25 @@ uint16_t button_read()
|
||||
return buttons;
|
||||
}
|
||||
|
||||
void button_auto_light()
|
||||
#define HID_EXPIRE_DURATION 1000000ULL
|
||||
static uint32_t hid_expire_time = 0;
|
||||
static bool hid_lights[BUTTON_NUM];
|
||||
|
||||
void button_update_light()
|
||||
{
|
||||
bool hid_active = (time_us_64() < hid_expire_time);
|
||||
for (int i = 0; i < BUTTON_NUM; i++) {
|
||||
bool val = hid_active ? hid_lights[i] : sw_val[i];
|
||||
if (BUTTON_DEFS[i].led_gpio >= 0) {
|
||||
gpio_put(BUTTON_DEFS[i].led_gpio, sw_val[i]);
|
||||
gpio_put(BUTTON_DEFS[i].led_gpio, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void button_set_light(bool lights[], uint8_t num)
|
||||
void button_set_light(uint8_t const *lights, uint8_t num)
|
||||
{
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (i >= BUTTON_NUM) {
|
||||
break;
|
||||
}
|
||||
if (BUTTON_DEFS[i].led_gpio >= 0) {
|
||||
gpio_put(BUTTON_DEFS[i].led_gpio, lights[i]);
|
||||
}
|
||||
for (int i = 0; (i < num) && (i < BUTTON_NUM); i++) {
|
||||
hid_lights[i] = (lights[i] > 0);
|
||||
}
|
||||
hid_expire_time = time_us_64() + HID_EXPIRE_DURATION;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ void button_init();
|
||||
uint8_t button_num();
|
||||
uint16_t button_read();
|
||||
|
||||
void button_auto_light();
|
||||
void button_set_light(bool lights[], uint8_t num);
|
||||
void button_update_light();
|
||||
void button_set_light(uint8_t const *lights, uint8_t num);
|
||||
|
||||
#endif
|
||||
|
@ -13,18 +13,12 @@
|
||||
#include "buttons.h"
|
||||
#include "rgb.h"
|
||||
|
||||
uint64_t hid_lights_timeout = 0;
|
||||
|
||||
#define BUTTON_LIGHT_MAX_NUM 32 /* Must be larger than number of buttons */
|
||||
bool button_lights[BUTTON_LIGHT_MAX_NUM] = {0};
|
||||
|
||||
void update_lights()
|
||||
{
|
||||
if (time_us_64() < hid_lights_timeout) {
|
||||
button_set_light(button_lights, button_num());
|
||||
} else {
|
||||
button_auto_light();
|
||||
}
|
||||
button_update_light();
|
||||
}
|
||||
|
||||
struct report
|
||||
@ -92,9 +86,9 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
|
||||
for (int i = 0; i < button_num(); i++) {
|
||||
button_lights[i] = (buffer[i] > 0);
|
||||
}
|
||||
button_set_light(buffer, button_num());
|
||||
|
||||
uint8_t const *rgb = buffer + button_num();
|
||||
rgb_update_logo(rgb[0], rgb[1], rgb[2]);
|
||||
|
||||
hid_lights_timeout = time_us_64() + 1000000; /* 1 second */
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ void update_led()
|
||||
}
|
||||
|
||||
#define HID_EXPIRE_DURATION 1000000ULL
|
||||
uint32_t hid_expire_time = 0;
|
||||
static uint32_t hid_expire_time = 0;
|
||||
|
||||
#define RAINBOW_SPEED_MAX 100
|
||||
#define RAINBOW_SPEED_MIN 4
|
||||
|
Loading…
x
Reference in New Issue
Block a user