ProcVisDemo_Accel

Dependencies:   MMA7660 mbed

Committer:
Wizo
Date:
Thu Nov 15 18:04:08 2018 +0000
Revision:
0:fca9076d3362
ProcVisDemo_Accel

Who changed what in which revision?

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