Func-Gen - basic setup

Dependencies:   mbed

Committer:
stkiegerl
Date:
Tue Mar 23 17:13:12 2021 +0000
Revision:
3:9fd12684fa88
Parent:
0:e1bc83101929
-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hollegha3 0:e1bc83101929 1
hollegha3 0:e1bc83101929 2 #ifndef Serial_HL_h
hollegha3 0:e1bc83101929 3 #define Serial_HL_h
hollegha3 0:e1bc83101929 4
hollegha3 0:e1bc83101929 5 #include "platform.h"
hollegha3 0:e1bc83101929 6 // #include "Stream.h"
hollegha3 0:e1bc83101929 7 #include "FunctionPointer.h"
hollegha3 0:e1bc83101929 8 #include "serial_api.h"
hollegha3 0:e1bc83101929 9 #include "SvProtocol.h"
hollegha3 0:e1bc83101929 10
hollegha3 0:e1bc83101929 11 namespace mbed {
hollegha3 0:e1bc83101929 12
hollegha3 0:e1bc83101929 13 class SerialBLK : public IStreamHL {
hollegha3 0:e1bc83101929 14 public:
hollegha3 0:e1bc83101929 15 SerialBLK(PinName tx, PinName rx);
hollegha3 0:e1bc83101929 16 void baud(int baudrate);
hollegha3 0:e1bc83101929 17
hollegha3 0:e1bc83101929 18 virtual void PutChar(int aCh);
hollegha3 0:e1bc83101929 19 virtual int GetChar();
hollegha3 0:e1bc83101929 20 virtual void Write(void* aData, uint32_t aLenBytes);
hollegha3 0:e1bc83101929 21 virtual void Read(void* aData, uint32_t aLenBytes);
hollegha3 0:e1bc83101929 22
hollegha3 0:e1bc83101929 23 enum Parity {
hollegha3 0:e1bc83101929 24 None = 0,
hollegha3 0:e1bc83101929 25 Odd,
hollegha3 0:e1bc83101929 26 Even,
hollegha3 0:e1bc83101929 27 Forced1,
hollegha3 0:e1bc83101929 28 Forced0
hollegha3 0:e1bc83101929 29 };
hollegha3 0:e1bc83101929 30 enum IrqType {
hollegha3 0:e1bc83101929 31 RxIrq = 0,
hollegha3 0:e1bc83101929 32 TxIrq
hollegha3 0:e1bc83101929 33 };
hollegha3 0:e1bc83101929 34
hollegha3 0:e1bc83101929 35 void format(int bits=8, Parity parity=SerialBLK::None, int stop_bits=1);
hollegha3 0:e1bc83101929 36
hollegha3 0:e1bc83101929 37 int readable();
hollegha3 0:e1bc83101929 38 int writeable();
hollegha3 0:e1bc83101929 39 int IsDataAvail()
hollegha3 0:e1bc83101929 40 { return readable(); }
hollegha3 0:e1bc83101929 41
hollegha3 0:e1bc83101929 42 // fptr A pointer to a void function, or 0 to set as none
hollegha3 0:e1bc83101929 43 // type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
hollegha3 0:e1bc83101929 44 void attach(void (*fptr)(void), IrqType type=RxIrq);
hollegha3 0:e1bc83101929 45
hollegha3 0:e1bc83101929 46 // tptr pointer to the object to call the member function on
hollegha3 0:e1bc83101929 47 // mptr pointer to the member function to be called
hollegha3 0:e1bc83101929 48 // type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
hollegha3 0:e1bc83101929 49 template<typename T>
hollegha3 0:e1bc83101929 50 void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
hollegha3 0:e1bc83101929 51 if((mptr != NULL) && (tptr != NULL)) {
hollegha3 0:e1bc83101929 52 _irq[type].attach(tptr, mptr);
hollegha3 0:e1bc83101929 53 serial_irq_set(&_serial, (SerialIrq)type, 1);
hollegha3 0:e1bc83101929 54 }
hollegha3 0:e1bc83101929 55 }
hollegha3 0:e1bc83101929 56
hollegha3 0:e1bc83101929 57 static void _irq_handler(uint32_t id, SerialIrq irq_type);
hollegha3 0:e1bc83101929 58 protected:
hollegha3 0:e1bc83101929 59 serial_t _serial;
hollegha3 0:e1bc83101929 60 FunctionPointer _irq[2];
hollegha3 0:e1bc83101929 61 int _baud;
hollegha3 0:e1bc83101929 62 };
hollegha3 0:e1bc83101929 63
hollegha3 0:e1bc83101929 64 } // namespace mbed
hollegha3 0:e1bc83101929 65
hollegha3 0:e1bc83101929 66 #endif
hollegha3 0:e1bc83101929 67