![](/media/cache/group/Semtech_stack_color_logo_highres.jpg.50x50_q85.jpg)
This code holds the complete demo set for the sx1280: PingPong, PER and Ranging Outdoor demo application. >>>>> This code MUST run on the mbed library release 127 or everything will be painfully slow.
Dependencies: mbed SX1280Lib DmTftLibrary
* This code MUST run on the mbed library release 127 or everything will be painfully slow.*
main.cpp@19:45d0ce0f0677, 2018-11-08 (annotated)
- Committer:
- mverdy
- Date:
- Thu Nov 08 10:13:23 2018 +0000
- Revision:
- 19:45d0ce0f0677
- Parent:
- 17:a0bbfc228415
Synchronize with v1.5.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:9c0917bfde97 | 1 | /* |
GregCr | 0:9c0917bfde97 | 2 | ______ _ |
GregCr | 0:9c0917bfde97 | 3 | / _____) _ | | |
GregCr | 0:9c0917bfde97 | 4 | ( (____ _____ ____ _| |_ _____ ____| |__ |
GregCr | 0:9c0917bfde97 | 5 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
GregCr | 0:9c0917bfde97 | 6 | _____) ) ____| | | || |_| ____( (___| | | | |
GregCr | 0:9c0917bfde97 | 7 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
GregCr | 0:9c0917bfde97 | 8 | (C)2016 Semtech |
GregCr | 0:9c0917bfde97 | 9 | |
GregCr | 0:9c0917bfde97 | 10 | Description: Main program |
GregCr | 0:9c0917bfde97 | 11 | |
GregCr | 0:9c0917bfde97 | 12 | Maintainer: Gregory Cristian & Gilbert Menth |
GregCr | 0:9c0917bfde97 | 13 | */ |
GregCr | 0:9c0917bfde97 | 14 | |
GregCr | 0:9c0917bfde97 | 15 | #include "mbed.h" |
GregCr | 0:9c0917bfde97 | 16 | #include "Timers.h" |
GregCr | 0:9c0917bfde97 | 17 | #include "Menu.h" |
GregCr | 0:9c0917bfde97 | 18 | #include "Eeprom.h" |
GregCr | 0:9c0917bfde97 | 19 | #include "GpsMax7.h" |
GregCr | 0:9c0917bfde97 | 20 | #include "SX9306.h" |
mverdy | 14:ebd89dacc807 | 21 | #include "sx1280-hal.h" |
mverdy | 15:ed7ed20b7114 | 22 | #include "main.h" |
mverdy | 19:45d0ce0f0677 | 23 | #include "app_config.h" |
GregCr | 0:9c0917bfde97 | 24 | |
GregCr | 0:9c0917bfde97 | 25 | |
GregCr | 0:9c0917bfde97 | 26 | /*! |
GregCr | 0:9c0917bfde97 | 27 | * \brief Define IO for Unused Pin |
GregCr | 0:9c0917bfde97 | 28 | */ |
GregCr | 0:9c0917bfde97 | 29 | DigitalOut F_CS( D6 ); // MBED description of pin |
GregCr | 0:9c0917bfde97 | 30 | DigitalOut SD_CS( D8 ); // MBED description of pin |
mverdy | 15:ed7ed20b7114 | 31 | DigitalIn userButton( USER_BUTTON ); |
mverdy | 15:ed7ed20b7114 | 32 | |
mverdy | 19:45d0ce0f0677 | 33 | void PrintCompileSupportMessage( void ); |
GregCr | 0:9c0917bfde97 | 34 | |
GregCr | 0:9c0917bfde97 | 35 | /*! |
GregCr | 0:9c0917bfde97 | 36 | * \brief Specify serial datarate for UART debug output |
GregCr | 0:9c0917bfde97 | 37 | */ |
GregCr | 0:9c0917bfde97 | 38 | void baud( int baudrate ) |
GregCr | 0:9c0917bfde97 | 39 | { |
GregCr | 0:9c0917bfde97 | 40 | Serial s( USBTX, USBRX ); |
GregCr | 0:9c0917bfde97 | 41 | s.baud( baudrate ); |
GregCr | 0:9c0917bfde97 | 42 | } |
GregCr | 0:9c0917bfde97 | 43 | |
mverdy | 14:ebd89dacc807 | 44 | extern SX1280Hal Radio; |
mverdy | 14:ebd89dacc807 | 45 | |
GregCr | 0:9c0917bfde97 | 46 | int main( ) |
GregCr | 0:9c0917bfde97 | 47 | { |
GregCr | 0:9c0917bfde97 | 48 | uint8_t currentPage = START_PAGE; |
GregCr | 0:9c0917bfde97 | 49 | uint8_t demoStatusUpdate = 0; // used for screen display status |
GregCr | 0:9c0917bfde97 | 50 | |
GregCr | 0:9c0917bfde97 | 51 | baud( 115200 ); |
GregCr | 0:9c0917bfde97 | 52 | |
GregCr | 0:9c0917bfde97 | 53 | F_CS = 1; |
GregCr | 0:9c0917bfde97 | 54 | SD_CS = 1; |
GregCr | 0:9c0917bfde97 | 55 | |
mverdy | 19:45d0ce0f0677 | 56 | printf( "Starting SX1280DevKit %s (%s)\n\r", FIRMWARE_VERSION, FIRMWARE_DATE ); |
mverdy | 19:45d0ce0f0677 | 57 | PrintCompileSupportMessage(); |
mverdy | 14:ebd89dacc807 | 58 | |
GregCr | 0:9c0917bfde97 | 59 | EepromInit( ); |
mverdy | 15:ed7ed20b7114 | 60 | |
mverdy | 15:ed7ed20b7114 | 61 | if( userButton == 0 ) |
mverdy | 15:ed7ed20b7114 | 62 | { |
mverdy | 15:ed7ed20b7114 | 63 | FactoryReset( ); |
mverdy | 15:ed7ed20b7114 | 64 | } |
mverdy | 15:ed7ed20b7114 | 65 | |
GregCr | 0:9c0917bfde97 | 66 | InitDemoApplication( ); |
GregCr | 0:9c0917bfde97 | 67 | MenuInit( ); |
GregCr | 17:a0bbfc228415 | 68 | |
mverdy | 19:45d0ce0f0677 | 69 | #if defined(HAS_GPS_SENSOR) || defined (HAS_PROXIMITY_SENSOR) |
GregCr | 0:9c0917bfde97 | 70 | TimersInit( ); |
mverdy | 19:45d0ce0f0677 | 71 | #endif |
mverdy | 19:45d0ce0f0677 | 72 | #if defined(HAS_GPS_SENSOR) |
GregCr | 0:9c0917bfde97 | 73 | Max7GpsInit( ); |
mverdy | 19:45d0ce0f0677 | 74 | #endif |
mverdy | 19:45d0ce0f0677 | 75 | #if defined(HAS_PROXIMITY_SENSOR) |
GregCr | 0:9c0917bfde97 | 76 | SX9306ProximityInit( ); |
mverdy | 19:45d0ce0f0677 | 77 | #endif |
GregCr | 0:9c0917bfde97 | 78 | |
mverdy | 14:ebd89dacc807 | 79 | printf( "Radio version: 0x%x\n\r", Radio.GetFirmwareVersion( ) ); |
GregCr | 0:9c0917bfde97 | 80 | |
GregCr | 0:9c0917bfde97 | 81 | while( 1 ) |
GregCr | 0:9c0917bfde97 | 82 | { |
GregCr | 0:9c0917bfde97 | 83 | currentPage = MenuHandler( demoStatusUpdate ); |
GregCr | 0:9c0917bfde97 | 84 | |
GregCr | 0:9c0917bfde97 | 85 | switch( currentPage ) |
GregCr | 0:9c0917bfde97 | 86 | { |
GregCr | 0:9c0917bfde97 | 87 | case START_PAGE: |
GregCr | 0:9c0917bfde97 | 88 | break; |
GregCr | 0:9c0917bfde97 | 89 | |
GregCr | 0:9c0917bfde97 | 90 | case PAGE_PING_PONG: |
GregCr | 0:9c0917bfde97 | 91 | demoStatusUpdate = RunDemoApplicationPingPong( ); |
GregCr | 0:9c0917bfde97 | 92 | break; |
GregCr | 0:9c0917bfde97 | 93 | |
GregCr | 0:9c0917bfde97 | 94 | case PAGE_PER: |
GregCr | 0:9c0917bfde97 | 95 | demoStatusUpdate = RunDemoApplicationPer( ); |
GregCr | 0:9c0917bfde97 | 96 | break; |
GregCr | 0:9c0917bfde97 | 97 | |
GregCr | 0:9c0917bfde97 | 98 | case PAGE_RANGING_MASTER: |
GregCr | 0:9c0917bfde97 | 99 | case PAGE_RANGING_SLAVE: |
GregCr | 0:9c0917bfde97 | 100 | demoStatusUpdate = RunDemoApplicationRanging( ); |
GregCr | 0:9c0917bfde97 | 101 | break; |
GregCr | 0:9c0917bfde97 | 102 | |
GregCr | 0:9c0917bfde97 | 103 | case PAGE_SLEEP_MODE: |
GregCr | 0:9c0917bfde97 | 104 | demoStatusUpdate = RunDemoSleepMode( ); |
GregCr | 0:9c0917bfde97 | 105 | break; |
GregCr | 0:9c0917bfde97 | 106 | |
GregCr | 0:9c0917bfde97 | 107 | case PAGE_STBY_RC_MODE: |
GregCr | 0:9c0917bfde97 | 108 | demoStatusUpdate = RunDemoStandbyRcMode( ); |
GregCr | 0:9c0917bfde97 | 109 | break; |
GregCr | 0:9c0917bfde97 | 110 | |
GregCr | 0:9c0917bfde97 | 111 | case PAGE_STBY_XOSC_MODE: |
GregCr | 0:9c0917bfde97 | 112 | demoStatusUpdate = RunDemoStandbyXoscMode( ); |
GregCr | 0:9c0917bfde97 | 113 | break; |
GregCr | 0:9c0917bfde97 | 114 | |
GregCr | 0:9c0917bfde97 | 115 | case PAGE_TX_CW: |
GregCr | 0:9c0917bfde97 | 116 | demoStatusUpdate = RunDemoTxCw( ); |
GregCr | 0:9c0917bfde97 | 117 | break; |
GregCr | 0:9c0917bfde97 | 118 | |
GregCr | 0:9c0917bfde97 | 119 | case PAGE_CONT_MODULATION: |
GregCr | 0:9c0917bfde97 | 120 | demoStatusUpdate = RunDemoTxContinuousModulation( ); |
GregCr | 0:9c0917bfde97 | 121 | break; |
GregCr | 0:9c0917bfde97 | 122 | |
GregCr | 0:9c0917bfde97 | 123 | case PAGE_UTILITIES: |
GregCr | 0:9c0917bfde97 | 124 | // Extracts time and position information from the GPS module |
mverdy | 19:45d0ce0f0677 | 125 | #if defined(HAS_GPS_SENSOR) |
GregCr | 0:9c0917bfde97 | 126 | Max7GpsHandle( ); |
mverdy | 19:45d0ce0f0677 | 127 | #endif |
mverdy | 19:45d0ce0f0677 | 128 | #if defined(HAS_PROXIMITY_SENSOR) |
GregCr | 0:9c0917bfde97 | 129 | SX9306ProximityHandle( ); //Deals with the proximity IC readings |
mverdy | 19:45d0ce0f0677 | 130 | #endif |
GregCr | 0:9c0917bfde97 | 131 | break; |
GregCr | 0:9c0917bfde97 | 132 | |
GregCr | 0:9c0917bfde97 | 133 | default: // Any page not running a demo |
GregCr | 0:9c0917bfde97 | 134 | break; |
GregCr | 0:9c0917bfde97 | 135 | } |
GregCr | 0:9c0917bfde97 | 136 | } |
GregCr | 0:9c0917bfde97 | 137 | } |
mverdy | 15:ed7ed20b7114 | 138 | |
mverdy | 15:ed7ed20b7114 | 139 | void FactoryReset( void ) |
mverdy | 15:ed7ed20b7114 | 140 | { |
mverdy | 15:ed7ed20b7114 | 141 | EepromFactoryReset( ); |
mverdy | 15:ed7ed20b7114 | 142 | HAL_NVIC_SystemReset( ); |
mverdy | 15:ed7ed20b7114 | 143 | } |
mverdy | 19:45d0ce0f0677 | 144 | |
mverdy | 19:45d0ce0f0677 | 145 | void PrintCompileSupportMessage( void ) |
mverdy | 19:45d0ce0f0677 | 146 | { |
mverdy | 19:45d0ce0f0677 | 147 | printf( "\nCompile time configuration:\n" ); |
mverdy | 19:45d0ce0f0677 | 148 | #if defined(HAS_GPS_SENSOR) |
mverdy | 19:45d0ce0f0677 | 149 | printf( " + gps\n" ); |
mverdy | 19:45d0ce0f0677 | 150 | #else |
mverdy | 19:45d0ce0f0677 | 151 | printf( " - gps\n" ); |
mverdy | 19:45d0ce0f0677 | 152 | #endif |
mverdy | 19:45d0ce0f0677 | 153 | #if defined(HAS_PROXIMITY_SENSOR) |
mverdy | 19:45d0ce0f0677 | 154 | printf( " + proximity\n" ); |
mverdy | 19:45d0ce0f0677 | 155 | #else |
mverdy | 19:45d0ce0f0677 | 156 | printf( " - proximity\n" ); |
mverdy | 19:45d0ce0f0677 | 157 | #endif |
mverdy | 19:45d0ce0f0677 | 158 | printf("( '+ <FEAT>' means <FEAT> is enabled, '- <FEAT>' means <FEAT> is disabled)\n"); |
mverdy | 19:45d0ce0f0677 | 159 | } |