forked from dangiu/PicoMemcard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathled.c
72 lines (66 loc) · 1.42 KB
/
led.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "led.h"
#include "config.h"
#include "hardware/gpio.h"
#include "hardware/pio.h"
#ifdef RP2040ZERO
#include "ws2812.pio.h"
#endif
#ifdef PICO
#define PICO_LED_PIN 25
#endif
static uint smWs2813;
static uint offsetWs2813;
#ifdef RP2040ZERO
void ws2812_put_pixel(uint32_t pixel_grb) {
pio_sm_put_blocking(pio1, smWs2813, pixel_grb << 8u);
}
void ws2812_put_rgb(uint8_t red, uint8_t green, uint8_t blue) {
uint32_t mask = (green << 16) | (red << 8) | (blue << 0);
ws2812_put_pixel(mask);
}
#endif
void led_init() {
#ifdef RP2040ZERO
offsetWs2813 = pio_add_program(pio1, &ws2812_program);
smWs2813 = pio_claim_unused_sm(pio1, true);
ws2812_program_init(pio1, smWs2813, offsetWs2813, 16, 800000, true);
#endif
}
void led_output_sync_status(bool out_of_sync) {
#ifdef PICO
gpio_put(PICO_LED_PIN, !out_of_sync);
#endif
#ifdef RP2040ZERO
if(out_of_sync)
ws2812_put_rgb(255, 255, 0);
else
ws2812_put_rgb(0, 255, 0);
#endif
}
void led_blink_error(int amount) {
/* ensure led is off */
#ifdef PICO
gpio_put(PICO_LED_PIN, false);
#endif
#ifdef RP2040ZERO
ws2812_put_rgb(0, 0, 0);
#endif
sleep_ms(500);
/* start blinking */
for(int i = 0; i < amount; ++i) {
#ifdef PICO
gpio_put(PICO_LED_PIN, true);
#endif
#ifdef RP2040ZERO
ws2812_put_rgb(255, 0, 0);
#endif
sleep_ms(500);
#ifdef PICO
gpio_put(PICO_LED_PIN, false);
#endif
#ifdef RP2040ZERO
ws2812_put_rgb(0, 0, 0);
#endif
sleep_ms(500);
}
}