aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2022-11-20 01:35:41 +0100
committerLouis Burda <quent.burda@gmail.com>2022-11-20 01:35:53 +0100
commit5c2cb697aa8d03eed27b45f8dc67957c45a3d722 (patch)
tree056e08b0e4d4aa0d6f65f84043beb151d6c6245f /src/main.c
parent12a423434352af137bda357001ac824aa23fdf77 (diff)
downloadsxkbd-5c2cb697aa8d03eed27b45f8dc67957c45a3d722.tar.gz
sxkbd-5c2cb697aa8d03eed27b45f8dc67957c45a3d722.zip
Onboard neopixel led support
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/main.c b/src/main.c
index 25f6204..d73c530 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,12 +1,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <sys/types.h>
#include "bsp/board.h"
#include "tusb.h"
+#include "neopix.h"
/* Blink pattern
- * - 250 ms : device not mounted
+ * - 250 ms : device not mounted
* - 1000 ms : device mounted
* - 2500 ms : device is suspended
*/
@@ -18,19 +20,20 @@ enum {
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
+static struct neopix onboard_led;
+
void led_blinking_task(void);
-/*------------- MAIN -------------*/
int main(void)
{
board_init();
- // init device stack on configured roothub port
+ neopix_init(&onboard_led, pio0, 0, 25);
+
tud_init(BOARD_TUD_RHPORT);
- while (1)
- {
- tud_task(); // tinyusb device task
+ while (1) {
+ tud_task();
led_blinking_task();
}
@@ -78,7 +81,6 @@ void tud_resume_cb(void)
uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id,
hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
{
- // TODO not Implemented
(void) itf;
(void) report_id;
(void) report_type;
@@ -93,27 +95,24 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id,
void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
{
- // This example doesn't use multiple report and report ID
(void) itf;
(void) report_id;
(void) report_type;
- // echo back anything we received from host
tud_hid_report(0, buffer, bufsize);
}
-//--------------------------------------------------------------------+
-// BLINKING TASK
-//--------------------------------------------------------------------+
-void led_blinking_task(void)
+void
+led_blinking_task(void)
{
static uint32_t start_ms = 0;
- static bool led_state = false;
+ static bool state = false;
- // Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
- start_ms += blink_interval_ms;
+ if (board_millis() - start_ms < blink_interval_ms)
+ return;
+
+ neopix_put(&onboard_led, neopix_u32rgb(255 * state, 0, 0));
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
+ start_ms += blink_interval_ms;
+ state ^= true;
}