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