forked from phdussud/pico-dirtyJtag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.c
51 lines (43 loc) · 1.27 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
#include "led.h"
#include "hardware/gpio.h"
bool LedInverted = false;
int LedRxPin = 0;
int LedTxPin = 0;
int LedErrorPin = 0;
void led_init( bool inverted, int ledRxPin, int ledTXPin, int ledErrorPin_ ) {
LedTxPin = ledTXPin;
LedRxPin = ledRxPin;
LedErrorPin = ledErrorPin_;
LedInverted = inverted;
if ( LedTxPin != -1 ) {
gpio_init( LedTxPin);
gpio_set_dir(LedTxPin, GPIO_OUT);
gpio_put(LedTxPin, (LedInverted) ? 1 : 0);
}
if ( LedTxPin != LedRxPin ) {
if ( LedRxPin != -1 ) {
gpio_init( LedRxPin);
gpio_set_dir(LedRxPin, GPIO_OUT);
gpio_put(LedRxPin, (LedInverted) ? 1 : 0);
}
}
if ( ( LedErrorPin != LedRxPin ) && ( LedErrorPin != LedTxPin ) ) {
if ( LedErrorPin != -1 ) {
gpio_init( LedErrorPin);
gpio_set_dir(LedErrorPin, GPIO_OUT);
gpio_put(LedErrorPin, (LedInverted) ? 1 : 0 );
}
}
}
void led_tx( bool state ) {
if ( LedTxPin != -1 )
gpio_put(LedRxPin, LedInverted ^ state);
}
void led_rx( bool state ) {
if ( LedRxPin != -1 )
gpio_put(LedRxPin, LedInverted ^ state);
}
void led_error( bool state ) {
if ( LedErrorPin != -1 )
gpio_put(LedErrorPin, LedInverted ^ state);
}