Skip to content

Commit 4bbc25e

Browse files
Rename pin map to lmic_pins and make it const
This should decrease the likelyhood of a naming conflict, and making it const might help the compiler optimize. In the future, configuring pins might change to use some initialization function to pass the pin mapping, but for now this approach seems simple and efficient.
1 parent db786f3 commit 4bbc25e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

examples/raw/raw.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
config.h in the lmic library to set it.
2626
#endif
2727

28-
lmic_pinmap pins = {
28+
const lmic_pinmap lmic_pins = {
2929
.nss = SS,
3030
.rxtx = 8, // Not connected
3131
.rst = A7, // Not connected

src/hal/hal.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
// I/O
1919

2020
static void hal_io_init () {
21-
pinMode(pins.nss, OUTPUT);
22-
pinMode(pins.rxtx, OUTPUT);
23-
pinMode(pins.rst, OUTPUT);
24-
pinMode(pins.dio[0], INPUT);
25-
pinMode(pins.dio[1], INPUT);
26-
pinMode(pins.dio[2], INPUT);
21+
pinMode(lmic_pins.nss, OUTPUT);
22+
pinMode(lmic_pins.rxtx, OUTPUT);
23+
pinMode(lmic_pins.rst, OUTPUT);
24+
pinMode(lmic_pins.dio[0], INPUT);
25+
pinMode(lmic_pins.dio[1], INPUT);
26+
pinMode(lmic_pins.dio[2], INPUT);
2727
}
2828

2929
// val == 1 => tx 1
3030
void hal_pin_rxtx (u1_t val) {
31-
digitalWrite(pins.rxtx, val);
31+
digitalWrite(lmic_pins.rxtx, val);
3232
}
3333

3434
// set radio RST pin to given value (or keep floating!)
3535
void hal_pin_rst (u1_t val) {
3636
if(val == 0 || val == 1) { // drive pin
37-
pinMode(pins.rst, OUTPUT);
38-
digitalWrite(pins.rst, val);
37+
pinMode(lmic_pins.rst, OUTPUT);
38+
digitalWrite(lmic_pins.rst, val);
3939
} else { // keep pin floating
40-
pinMode(pins.rst, INPUT);
40+
pinMode(lmic_pins.rst, INPUT);
4141
}
4242
}
4343

@@ -46,7 +46,7 @@ static bool dio_states[NUM_DIO] = {0};
4646
static void hal_io_check() {
4747
uint8_t i;
4848
for (i = 0; i < NUM_DIO; ++i) {
49-
if (dio_states[i] != digitalRead(pins.dio[i])) {
49+
if (dio_states[i] != digitalRead(lmic_pins.dio[i])) {
5050
dio_states[i] = !dio_states[i];
5151
if (dio_states[i])
5252
radio_irq_handler(i);
@@ -70,7 +70,7 @@ void hal_pin_nss (u1_t val) {
7070
SPI.endTransaction();
7171

7272
//Serial.println(val?">>":"<<");
73-
digitalWrite(pins.nss, val);
73+
digitalWrite(lmic_pins.nss, val);
7474
}
7575

7676
// perform SPI transaction with radio

src/hal/hal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ struct lmic_pinmap {
2020
};
2121

2222
// Declared here, to be defined an initialized by the application
23-
extern lmic_pinmap pins;
23+
extern const lmic_pinmap lmic_pins;
2424

2525
#endif // _hal_hal_h_

0 commit comments

Comments
 (0)