![](/media/cache/profiles/ce7206100d5cf8e7bb691376c7d73526.jpg.50x50_q85.jpg)
An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
main.cpp@9:a988aa7a4652, 2019-01-24 (annotated)
- Committer:
- Helmut Tschemernjak
- Date:
- Thu Jan 24 14:27:11 2019 +0100
- Revision:
- 9:a988aa7a4652
- Parent:
- 5:c6a960febe80
- Child:
- 13:3c7a52b11316
Update with properties
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:3b6c2ce051a6 | 1 | /* |
Helmut Tschemernjak | 3:b5052f3fa638 | 2 | * Copyright (c) 2019 Helmut Tschemernjak |
Helmut64 | 0:3b6c2ce051a6 | 3 | * 30826 Garbsen (Hannover) Germany |
Helmut64 | 0:3b6c2ce051a6 | 4 | * Licensed under the Apache License, Version 2.0); |
Helmut64 | 0:3b6c2ce051a6 | 5 | */ |
Helmut Tschemernjak | 3:b5052f3fa638 | 6 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 7 | /* |
Helmut Tschemernjak | 3:b5052f3fa638 | 8 | * TODO: |
Helmut Tschemernjak | 3:b5052f3fa638 | 9 | * Compiler Date/Time is not set correctly on startup |
Helmut Tschemernjak | 3:b5052f3fa638 | 10 | */ |
Helmut Tschemernjak | 3:b5052f3fa638 | 11 | #include "main.h" |
Helmut Tschemernjak | 3:b5052f3fa638 | 12 | #include "RadioShuttle.h" |
Helmut Tschemernjak | 3:b5052f3fa638 | 13 | #include "RadioTest.h" |
Helmut Tschemernjak | 3:b5052f3fa638 | 14 | #include "GenericPingPong.h" |
Helmut Tschemernjak | 9:a988aa7a4652 | 15 | #ifdef FEATURE_NVPROPERTY |
Helmut Tschemernjak | 9:a988aa7a4652 | 16 | #include <NVPropertyProviderInterface.h> |
Helmut Tschemernjak | 9:a988aa7a4652 | 17 | #include "NVProperty.h" |
Helmut Tschemernjak | 9:a988aa7a4652 | 18 | #endif |
Helmut64 | 0:3b6c2ce051a6 | 19 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 20 | DigitalOut statusLED(LED); |
Helmut Tschemernjak | 3:b5052f3fa638 | 21 | DigitalOut redLED(LED2); |
Helmut Tschemernjak | 3:b5052f3fa638 | 22 | InterruptIn buttonIntr(USER_BUTTON); |
Helmut64 | 0:3b6c2ce051a6 | 23 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 24 | void switchInput(void) { |
Helmut Tschemernjak | 3:b5052f3fa638 | 25 | InterrruptMSG(INT_BUTTON1); |
Helmut Tschemernjak | 3:b5052f3fa638 | 26 | } |
Helmut64 | 0:3b6c2ce051a6 | 27 | |
Helmut64 | 0:3b6c2ce051a6 | 28 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 29 | void timerUpdate(void) { |
Helmut Tschemernjak | 5:c6a960febe80 | 30 | static LowPowerTimeout timeout; |
Helmut Tschemernjak | 3:b5052f3fa638 | 31 | if (redLED == 0) |
Helmut Tschemernjak | 3:b5052f3fa638 | 32 | timeout.attach_us(&timerUpdate, 20000); // setup to call timerUpdate after 20 millis |
Helmut Tschemernjak | 3:b5052f3fa638 | 33 | else |
Helmut Tschemernjak | 3:b5052f3fa638 | 34 | timeout.attach_us(&timerUpdate, 2000000); // setup to call timerUpdate after 2 seconds |
Helmut Tschemernjak | 3:b5052f3fa638 | 35 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 36 | InterrruptMSG(INT_TIMEOUT); |
Helmut Tschemernjak | 3:b5052f3fa638 | 37 | } |
Helmut Tschemernjak | 3:b5052f3fa638 | 38 | |
Helmut64 | 0:3b6c2ce051a6 | 39 | int main() { |
Helmut64 | 0:3b6c2ce051a6 | 40 | /* |
Helmut64 | 0:3b6c2ce051a6 | 41 | * inits the Serial or USBSerial when available (230400 baud). |
Helmut64 | 0:3b6c2ce051a6 | 42 | * If the serial uart is not is not connected it swiches to USB Serial |
Helmut64 | 0:3b6c2ce051a6 | 43 | * blinking LED means USBSerial detected, waiting for a connect. |
Helmut64 | 0:3b6c2ce051a6 | 44 | * It waits up to 30 seconds for a USB terminal connections |
Helmut64 | 0:3b6c2ce051a6 | 45 | */ |
Helmut Tschemernjak | 3:b5052f3fa638 | 46 | InitSerial(30*1000, &statusLED); |
Helmut Tschemernjak | 3:b5052f3fa638 | 47 | dprintf("Welcome to RadioShuttle v%d.%d", RS_MAJOR, RS_MINOR); |
Helmut Tschemernjak | 3:b5052f3fa638 | 48 | dprintf("Voltage: %.2f (%s powered)", BatteryVoltage(), BatterySource()); |
Helmut Tschemernjak | 9:a988aa7a4652 | 49 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 50 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 51 | #ifdef FEATURE_LORA |
Helmut Tschemernjak | 3:b5052f3fa638 | 52 | InitRadio(); |
Helmut Tschemernjak | 3:b5052f3fa638 | 53 | #endif |
Helmut Tschemernjak | 3:b5052f3fa638 | 54 | #ifdef FEATURE_LORA_PING_PONG |
Helmut Tschemernjak | 3:b5052f3fa638 | 55 | DeInitRadio(); |
Helmut Tschemernjak | 3:b5052f3fa638 | 56 | SX1276PingPong(); // basic LoRa raw ping/pong without RadioShuttle |
Helmut Tschemernjak | 3:b5052f3fa638 | 57 | #endif |
Helmut Tschemernjak | 3:b5052f3fa638 | 58 | dprintf("InitDefaults Done"); |
Helmut Tschemernjak | 3:b5052f3fa638 | 59 | timerUpdate(); // start timer |
Helmut Tschemernjak | 3:b5052f3fa638 | 60 | #if defined (USER_BUTTON_RISE) // attach switchInput function to the rising or falling edge |
Helmut Tschemernjak | 3:b5052f3fa638 | 61 | buttonIntr.rise(&switchInput); |
Helmut Tschemernjak | 3:b5052f3fa638 | 62 | #else |
Helmut Tschemernjak | 3:b5052f3fa638 | 63 | buttonIntr.fall(&switchInput); |
Helmut Tschemernjak | 3:b5052f3fa638 | 64 | #endif |
Helmut Tschemernjak | 3:b5052f3fa638 | 65 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 66 | /* |
Helmut Tschemernjak | 3:b5052f3fa638 | 67 | * Main event loop, process interrupts and go to sleep |
Helmut Tschemernjak | 3:b5052f3fa638 | 68 | * the green statusLED indicates CPU activity |
Helmut Tschemernjak | 5:c6a960febe80 | 69 | * the red redLED indicates that low power timeout function is running. |
Helmut Tschemernjak | 3:b5052f3fa638 | 70 | */ |
Helmut Tschemernjak | 3:b5052f3fa638 | 71 | while(true) { |
Helmut Tschemernjak | 3:b5052f3fa638 | 72 | while ((readPendingInterrupts() == 0)) { |
Helmut Tschemernjak | 3:b5052f3fa638 | 73 | statusLED = 0; |
Helmut Tschemernjak | 3:b5052f3fa638 | 74 | if (!(usb && usb->connected())) |
Helmut Tschemernjak | 3:b5052f3fa638 | 75 | sleep(); |
Helmut Tschemernjak | 3:b5052f3fa638 | 76 | statusLED = 1; |
Helmut Tschemernjak | 3:b5052f3fa638 | 77 | } |
Helmut Tschemernjak | 3:b5052f3fa638 | 78 | |
Helmut Tschemernjak | 3:b5052f3fa638 | 79 | uint32_t pendirqs = readclrPendingInterrupts(); |
Helmut Tschemernjak | 3:b5052f3fa638 | 80 | if (pendirqs & INT_BUTTON1) { |
Helmut Tschemernjak | 3:b5052f3fa638 | 81 | #ifdef FEATURE_LORA |
Helmut Tschemernjak | 3:b5052f3fa638 | 82 | statusLED = !statusLED; |
Helmut Tschemernjak | 3:b5052f3fa638 | 83 | RadioUpdate(true); // pass the pressed user button to RadioShuttle |
Helmut Tschemernjak | 3:b5052f3fa638 | 84 | #endif |
Helmut Tschemernjak | 3:b5052f3fa638 | 85 | } |
Helmut Tschemernjak | 3:b5052f3fa638 | 86 | if (pendirqs & INT_LORA) { |
Helmut Tschemernjak | 3:b5052f3fa638 | 87 | #ifdef FEATURE_LORA |
Helmut Tschemernjak | 3:b5052f3fa638 | 88 | RadioUpdate(false); |
Helmut Tschemernjak | 3:b5052f3fa638 | 89 | #endif |
Helmut Tschemernjak | 3:b5052f3fa638 | 90 | } |
Helmut Tschemernjak | 3:b5052f3fa638 | 91 | if (pendirqs & INT_TIMEOUT) { |
Helmut Tschemernjak | 3:b5052f3fa638 | 92 | redLED = ! redLED; |
Helmut Tschemernjak | 3:b5052f3fa638 | 93 | } |
Helmut Tschemernjak | 3:b5052f3fa638 | 94 | } |
Helmut64 | 0:3b6c2ce051a6 | 95 | } |