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 "vt100.h"
Rhyme 0:87662653a3c6 3 #include "edgeSerial.h"
Rhyme 0:87662653a3c6 4 #include "edge_reset_mgr.h"
Rhyme 0:87662653a3c6 5 extern vt100 *tty ;
Rhyme 0:87662653a3c6 6
Rhyme 0:87662653a3c6 7 edgeSerial::edgeSerial(PinName txPin, PinName rxPin, int baud)
Rhyme 0:87662653a3c6 8 : Serial(txPin, rxPin, baud)
Rhyme 0:87662653a3c6 9 {
Rhyme 0:87662653a3c6 10 _is_peeked = false ;
Rhyme 0:87662653a3c6 11 _peeked_byte = 0 ;
Rhyme 0:87662653a3c6 12 }
Rhyme 0:87662653a3c6 13
Rhyme 0:87662653a3c6 14 char edgeSerial::edge_peek(void)
Rhyme 0:87662653a3c6 15 {
Rhyme 0:87662653a3c6 16 _peeked_byte = getc() ;
Rhyme 0:87662653a3c6 17 _is_peeked = true ;
Rhyme 0:87662653a3c6 18 return( _peeked_byte ) ;
Rhyme 0:87662653a3c6 19 }
Rhyme 0:87662653a3c6 20
Rhyme 0:87662653a3c6 21 void edgeSerial::edge_read(uint8_t *buffer, int len)
Rhyme 0:87662653a3c6 22 {
Rhyme 0:87662653a3c6 23 int i ;
Rhyme 0:87662653a3c6 24 if (_is_peeked) {
Rhyme 0:87662653a3c6 25 buffer[0] = _peeked_byte ;
Rhyme 0:87662653a3c6 26 _is_peeked = false ;
Rhyme 0:87662653a3c6 27 #if 1
Rhyme 0:87662653a3c6 28 for (i = 1 ; i < len ; i++) {
Rhyme 0:87662653a3c6 29 buffer[i] = Serial::getc() ;
Rhyme 0:87662653a3c6 30 }
Rhyme 0:87662653a3c6 31 #else
Rhyme 0:87662653a3c6 32 Serial::read(&buffer[1], len) ;
Rhyme 0:87662653a3c6 33 #endif
Rhyme 0:87662653a3c6 34 } else {
Rhyme 0:87662653a3c6 35 #if 1
Rhyme 0:87662653a3c6 36 for (i = 0 ; i < len ; i++) {
Rhyme 0:87662653a3c6 37 buffer[i] = Serial::getc() ;
Rhyme 0:87662653a3c6 38 }
Rhyme 0:87662653a3c6 39 #else
Rhyme 0:87662653a3c6 40 Serial::read(buffer, len) ;
Rhyme 0:87662653a3c6 41 #endif
Rhyme 0:87662653a3c6 42 }
Rhyme 0:87662653a3c6 43 }
Rhyme 0:87662653a3c6 44
Rhyme 0:87662653a3c6 45 char edgeSerial::edge_read(void)
Rhyme 0:87662653a3c6 46 {
Rhyme 0:87662653a3c6 47 char c ;
Rhyme 0:87662653a3c6 48 // tty->printf("edge_read\n") ;
Rhyme 0:87662653a3c6 49 if (_is_peeked) {
Rhyme 0:87662653a3c6 50 c = _peeked_byte ;
Rhyme 0:87662653a3c6 51 _is_peeked = false ;
Rhyme 0:87662653a3c6 52 } else {
Rhyme 0:87662653a3c6 53 // Serial::read((uint8_t*)&c, 1) ;
Rhyme 0:87662653a3c6 54 c = Serial::getc() ;
Rhyme 0:87662653a3c6 55 }
Rhyme 0:87662653a3c6 56 return( c ) ;
Rhyme 0:87662653a3c6 57 }
Rhyme 0:87662653a3c6 58
Rhyme 0:87662653a3c6 59 void edgeSerial::edge_write(uint8_t *buffer, int len)
Rhyme 0:87662653a3c6 60 {
Rhyme 0:87662653a3c6 61 #if 1
Rhyme 0:87662653a3c6 62 for (int i = 0 ; i < len ; i++ ) {
Rhyme 0:87662653a3c6 63 Serial::write(&buffer[i], 1) ;
Rhyme 0:87662653a3c6 64 }
Rhyme 0:87662653a3c6 65 #else
Rhyme 0:87662653a3c6 66 Serial::write(buffer, len) ;
Rhyme 0:87662653a3c6 67 #endif
Rhyme 0:87662653a3c6 68 }