uint8_t型とunsigned char型に対応した多バイトシリアル通信用ライブラリ
Dependents: multiserial_test serial_check_controller receiverA receiver_transmitter ... more
MultiSerial.h@6:49c82ca5aa37, 2014-08-21 (annotated)
- Committer:
- Hatter
- Date:
- Thu Aug 21 21:29:25 2014 +0000
- Revision:
- 6:49c82ca5aa37
- Parent:
- 1:123ee4ce9fe4
- Child:
- 7:f15a96ec54e1
????????????????????????????????????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hatter | 0:77c15e33dfd1 | 1 | /* |
Hatter | 0:77c15e33dfd1 | 2 | *mbed Multibyte Serial Library |
Hatter | 0:77c15e33dfd1 | 3 | *This comment is available in Japanese only |
Hatter | 0:77c15e33dfd1 | 4 | */ |
Hatter | 0:77c15e33dfd1 | 5 | |
Hatter | 0:77c15e33dfd1 | 6 | |
Hatter | 0:77c15e33dfd1 | 7 | |
Hatter | 0:77c15e33dfd1 | 8 | #ifndef MBED_MULTISERIAL |
Hatter | 0:77c15e33dfd1 | 9 | #define MBED_MULTISERIAL |
Hatter | 0:77c15e33dfd1 | 10 | |
Hatter | 0:77c15e33dfd1 | 11 | #include"mbed.h" |
Hatter | 0:77c15e33dfd1 | 12 | |
Hatter | 0:77c15e33dfd1 | 13 | #define __SIZE(array) (sizeof(array) / sizeof(array[0])) |
Hatter | 0:77c15e33dfd1 | 14 | |
Hatter | 6:49c82ca5aa37 | 15 | #define MAX_DATA_NUM 30 |
Hatter | 6:49c82ca5aa37 | 16 | |
Hatter | 1:123ee4ce9fe4 | 17 | /** 多バイト通信用クラス |
Hatter | 0:77c15e33dfd1 | 18 | * |
Hatter | 0:77c15e33dfd1 | 19 | * Example: |
Hatter | 0:77c15e33dfd1 | 20 | * @code |
Hatter | 0:77c15e33dfd1 | 21 | * #include"mbed.h" |
Hatter | 0:77c15e33dfd1 | 22 | * #include"MultiSerial.h" |
Hatter | 0:77c15e33dfd1 | 23 | * |
Hatter | 0:77c15e33dfd1 | 24 | * MultiSerial test1(p9,p10); |
Hatter | 0:77c15e33dfd1 | 25 | * MultiSerial test2(USBTX,USBRX); |
Hatter | 0:77c15e33dfd1 | 26 | * |
Hatter | 0:77c15e33dfd1 | 27 | * int main(){ |
Hatter | 0:77c15e33dfd1 | 28 | * |
Hatter | 0:77c15e33dfd1 | 29 | * uint8_t data1[5]={0}; |
Hatter | 0:77c15e33dfd1 | 30 | * test1.write(data1, 0xAA); |
Hatter | 0:77c15e33dfd1 | 31 | * uint8_t data2[8]={0}; |
Hatter | 0:77c15e33dfd1 | 32 | * test2.read(data2, 0xAA); |
Hatter | 0:77c15e33dfd1 | 33 | * |
Hatter | 0:77c15e33dfd1 | 34 | * |
Hatter | 0:77c15e33dfd1 | 35 | * for(;;); |
Hatter | 0:77c15e33dfd1 | 36 | * } |
Hatter | 0:77c15e33dfd1 | 37 | * @endcode |
Hatter | 0:77c15e33dfd1 | 38 | */ |
Hatter | 0:77c15e33dfd1 | 39 | |
Hatter | 0:77c15e33dfd1 | 40 | |
Hatter | 0:77c15e33dfd1 | 41 | class MultiSerial { |
Hatter | 0:77c15e33dfd1 | 42 | |
Hatter | 0:77c15e33dfd1 | 43 | public: |
Hatter | 6:49c82ca5aa37 | 44 | |
Hatter | 6:49c82ca5aa37 | 45 | /** 多バイト通信用オブジェクト作成 Serialにそのままつなげるよ |
Hatter | 6:49c82ca5aa37 | 46 | * |
Hatter | 6:49c82ca5aa37 | 47 | * @param tx Serial tx pin |
Hatter | 6:49c82ca5aa37 | 48 | * @param rx Serial rx pin |
Hatter | 6:49c82ca5aa37 | 49 | */ |
Hatter | 0:77c15e33dfd1 | 50 | MultiSerial(PinName tx,PinName rx); |
Hatter | 6:49c82ca5aa37 | 51 | |
Hatter | 6:49c82ca5aa37 | 52 | /**データ読み込みするよ |
Hatter | 6:49c82ca5aa37 | 53 | * |
Hatter | 6:49c82ca5aa37 | 54 | * @param value 読み込み先の配列アドレス |
Hatter | 6:49c82ca5aa37 | 55 | * @param size 配列の要素数 |
Hatter | 6:49c82ca5aa37 | 56 | * @param keycode 多バイト通信のキーコード |
Hatter | 6:49c82ca5aa37 | 57 | */ |
Hatter | 0:77c15e33dfd1 | 58 | void start_read(uint8_t* value,int size,uint8_t keycode); |
Hatter | 0:77c15e33dfd1 | 59 | |
Hatter | 6:49c82ca5aa37 | 60 | /**データカキコするよ |
Hatter | 6:49c82ca5aa37 | 61 | * |
Hatter | 6:49c82ca5aa37 | 62 | * @param value 送るデーターの配列アドレス |
Hatter | 6:49c82ca5aa37 | 63 | * @param size 配列の要素数 |
Hatter | 6:49c82ca5aa37 | 64 | * @param keycode 多バイト通信のキーコード |
Hatter | 6:49c82ca5aa37 | 65 | */ |
Hatter | 0:77c15e33dfd1 | 66 | |
Hatter | 0:77c15e33dfd1 | 67 | void start_write(uint8_t* value,int size,uint8_t keycode); |
Hatter | 6:49c82ca5aa37 | 68 | /* |
Hatter | 6:49c82ca5aa37 | 69 | void writeAttach(void (*func)()){ |
Hatter | 6:49c82ca5aa37 | 70 | __serial__.attach(func,Serial::TxIrq); |
Hatter | 6:49c82ca5aa37 | 71 | } |
Hatter | 6:49c82ca5aa37 | 72 | |
Hatter | 6:49c82ca5aa37 | 73 | void readAttach(void(*func)()){ |
Hatter | 6:49c82ca5aa37 | 74 | __serial__.attach(func,Serial::RxIrq); |
Hatter | 6:49c82ca5aa37 | 75 | } |
Hatter | 6:49c82ca5aa37 | 76 | */ |
Hatter | 0:77c15e33dfd1 | 77 | /**シリアル通信 受信割り込み ルーチン |
Hatter | 6:49c82ca5aa37 | 78 | * @param none |
Hatter | 6:49c82ca5aa37 | 79 | */ |
Hatter | 0:77c15e33dfd1 | 80 | void RX(void); |
Hatter | 6:49c82ca5aa37 | 81 | /**シリアル通信 送信バッファ空き割り込みルーチン |
Hatter | 6:49c82ca5aa37 | 82 | * @param none |
Hatter | 6:49c82ca5aa37 | 83 | */ |
Hatter | 0:77c15e33dfd1 | 84 | void TX(void); |
Hatter | 6:49c82ca5aa37 | 85 | |
Hatter | 6:49c82ca5aa37 | 86 | /** データ読み込み起動するよ |
Hatter | 6:49c82ca5aa37 | 87 | * |
Hatter | 6:49c82ca5aa37 | 88 | * @param value 読み込み先の配列アドレス |
Hatter | 6:49c82ca5aa37 | 89 | * @param keycode 多バイト通信のキーコード |
Hatter | 6:49c82ca5aa37 | 90 | */ |
Hatter | 0:77c15e33dfd1 | 91 | void read(uint8_t* value,uint8_t keycode); |
Hatter | 6:49c82ca5aa37 | 92 | /**データカキコ起動するよ |
Hatter | 6:49c82ca5aa37 | 93 | * |
Hatter | 6:49c82ca5aa37 | 94 | * @param value 送信データの配列アドレス |
Hatter | 6:49c82ca5aa37 | 95 | * @param keycode 多バイト通信のキーコード |
Hatter | 6:49c82ca5aa37 | 96 | */ |
Hatter | 0:77c15e33dfd1 | 97 | |
Hatter | 0:77c15e33dfd1 | 98 | void write(uint8_t* value,uint8_t keycode); |
Hatter | 6:49c82ca5aa37 | 99 | |
Hatter | 6:49c82ca5aa37 | 100 | protected: |
Hatter | 6:49c82ca5aa37 | 101 | |
Hatter | 6:49c82ca5aa37 | 102 | Serial __serial__; |
Hatter | 6:49c82ca5aa37 | 103 | uint8_t *__readData; |
Hatter | 6:49c82ca5aa37 | 104 | uint8_t *__writeData; |
Hatter | 6:49c82ca5aa37 | 105 | int __readSize; |
Hatter | 6:49c82ca5aa37 | 106 | int __writeSize; |
Hatter | 6:49c82ca5aa37 | 107 | uint8_t __readKey; |
Hatter | 6:49c82ca5aa37 | 108 | uint8_t __writeKey; |
Hatter | 0:77c15e33dfd1 | 109 | }; |
Hatter | 0:77c15e33dfd1 | 110 | #endif |