serial_extend library for array data transmission and reception
Dependents: receives_robot_wheel
Diff: serial_extend.h
- Revision:
- 0:fbf5705f90cc
- Child:
- 1:e808dd01f134
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/serial_extend.h Sat Oct 04 12:19:26 2014 +0000 @@ -0,0 +1,121 @@ +/* + *mbed array data serial Library + *This comment is available in Japanese only + */ + + +#ifndef serial_extend_H +#define serial_extend_H + +#include "mbed.h" + +#define __SIZE(array) (sizeof(array) / sizeof(array[0])) + + +#define MAX_DATA_NUM 10 +#define KEY 0//number of first data + +/** 多バイト通信用クラス + * + * Example: + * @code + * #include"mbed.h" + * #include"serial_extend.h" + * BusOut check(LED3,LED4); + + * uint8_t send_data[2]={0,0xF}; + * uint8_t get_data[2]; + * serial_extend send(p9,p10); + * serial_extend get(p28,p27); + * + * int main(){ + * + * send.write(send_data,0x0A); + * get.read(get_data,0x0A); + * for(int i=1;;i++){ + * + * check = get_data[i]; + * wait(0.1); + * if(i==2){i=0;} + * + * } + * } + * @endcode + */ + +/* + typedef enum { + write, + read, + both + + }dir_state; + */ + +class serial_extend{ + + public: + + /** 多バイト通信用オブジェクト作成 Serialにそのままつなげるよ + * + * @param tx Serial tx pin + * @param rx Serial rx pin + * @param state 通信方向 read,write,both + */ + + serial_extend(PinName tx,PinName rx); + + /**データ読み込みするよ + * + * @param readData 読み込み先の配列アドレス + * @param readKey 多バイト通信のキーコード + */ + + void read_data(uint8_t* readData,uint8_t readKey); + + /**データカキコするよ + * + * @param writeData 送るデーターの配列アドレス + * @param writeKey 多バイト通信のキーコード + */ + + void write_data(uint8_t* writeData,uint8_t writeKey); + + /**送信割り込み用関数 + * + *@param none + */ + void TX(void); + /**受信割り込み用関数 + * + *@param none + */ + void RX(void); + + void start_read(); + + void stop_read(); + + void start_write(); + + void stop_write(); + + uint8_t readable_check(); + + protected: + + RawSerial __serial__; + + volatile uint8_t* __readData; + volatile uint8_t __readSize; + volatile uint8_t __readKey; + + volatile uint8_t* __writeData; + volatile uint8_t __writeSize; + volatile uint8_t __writeKey; + + volatile uint8_t __stop_read; + volatile uint8_t __stop_write; + +}; +#endif \ No newline at end of file