afLib 1.3 which is supporting both SPI and UART

Dependencies:   vt100 mbed afLib_1_3

Committer:
Rhyme
Date:
Mon Apr 23 06:15:26 2018 +0000
Revision:
0:87662653a3c6
First UART working version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:87662653a3c6 1 #include "mbed.h"
Rhyme 0:87662653a3c6 2 #include "string.h"
Rhyme 0:87662653a3c6 3 #include "edge_mgr.h"
Rhyme 0:87662653a3c6 4 #include "edge_time.h"
Rhyme 0:87662653a3c6 5 #include "edge_pin.h"
Rhyme 0:87662653a3c6 6 #include "afLib.h"
Rhyme 0:87662653a3c6 7 #include "af_attributes.h"
Rhyme 0:87662653a3c6 8 #include "afTransport.h"
Rhyme 0:87662653a3c6 9 #include "msg_types.h"
Rhyme 0:87662653a3c6 10 #include "mbedSPI.h"
Rhyme 0:87662653a3c6 11 #include "mbedUART.h"
Rhyme 0:87662653a3c6 12 #include "af_mgr.h"
Rhyme 0:87662653a3c6 13
Rhyme 0:87662653a3c6 14 #define ASR_USE_SPI 0
Rhyme 0:87662653a3c6 15 #define ASR_USE_UART 1
Rhyme 0:87662653a3c6 16
Rhyme 0:87662653a3c6 17 afLib *afero = 0 ;
Rhyme 0:87662653a3c6 18 InterruptIn *afero_int = 0 ;
Rhyme 0:87662653a3c6 19 afTransport *afero_spi = 0 ;
Rhyme 0:87662653a3c6 20 afTransport *afero_uart = 0 ;
Rhyme 0:87662653a3c6 21 DigitalOut *afero_reset ;
Rhyme 0:87662653a3c6 22 bool gLinked = false ;
Rhyme 0:87662653a3c6 23 bool gConnected = false ;
Rhyme 0:87662653a3c6 24
Rhyme 0:87662653a3c6 25 void afero_isr(void)
Rhyme 0:87662653a3c6 26 {
Rhyme 0:87662653a3c6 27 afero->mcuISR() ;
Rhyme 0:87662653a3c6 28 }
Rhyme 0:87662653a3c6 29
Rhyme 0:87662653a3c6 30 void init_aflib(void)
Rhyme 0:87662653a3c6 31 {
Rhyme 0:87662653a3c6 32 afero_reset = new DigitalOut(PIN_ASR_RESET, 1) ; /* create as deasserted */
Rhyme 0:87662653a3c6 33 Serial *theLog = new Serial(USBTX, USBRX, 115200) ;
Rhyme 0:87662653a3c6 34
Rhyme 0:87662653a3c6 35 #if (ASR_USE_SPI)
Rhyme 0:87662653a3c6 36 tty->printf("afero is using SPI\n") ;
Rhyme 0:87662653a3c6 37 afero_spi = (afTransport*) new mbedSPI(PIN_MOSI, PIN_MISO, PIN_SCK, PIN_CS) ;
Rhyme 0:87662653a3c6 38 afero = new afLib(
Rhyme 0:87662653a3c6 39 PIN_INTR,
Rhyme 0:87662653a3c6 40 afero_isr,
Rhyme 0:87662653a3c6 41 attributeChangeRequest,
Rhyme 0:87662653a3c6 42 attributeUpdatedReport,
Rhyme 0:87662653a3c6 43 theLog, /* Stream for log */
Rhyme 0:87662653a3c6 44 (afTransport *)afero_spi ) ;
Rhyme 0:87662653a3c6 45 #elif (ASR_USE_UART)
Rhyme 0:87662653a3c6 46 tty->printf("afero is using UART2\n") ;
Rhyme 0:87662653a3c6 47 afero_uart = (afTransport*) new mbedUART(PIN_UART2_RX, PIN_UART2_TX, theLog) ;
Rhyme 0:87662653a3c6 48 afero = new afLib(
Rhyme 0:87662653a3c6 49 PIN_INTR,
Rhyme 0:87662653a3c6 50 0,
Rhyme 0:87662653a3c6 51 attributeChangeRequest,
Rhyme 0:87662653a3c6 52 attributeUpdatedReport,
Rhyme 0:87662653a3c6 53 theLog, /* Stream for log */
Rhyme 0:87662653a3c6 54 (afTransport *)afero_uart ) ;
Rhyme 0:87662653a3c6 55 #endif
Rhyme 0:87662653a3c6 56
Rhyme 0:87662653a3c6 57 wait(0.1) ;
Rhyme 0:87662653a3c6 58 *afero_reset = 0 ;
Rhyme 0:87662653a3c6 59 wait(0.5) ; /* required 250ms ~ time for reset */
Rhyme 0:87662653a3c6 60 *afero_reset = 1 ;
Rhyme 0:87662653a3c6 61 wait(0.5) ;
Rhyme 0:87662653a3c6 62 }