明石高専ロボ研 mbedライブラリ

Dependencies:   mbed

Revision:
0:ca84ed7518f5
Child:
2:141358d84ff4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scrp_slave.hpp	Thu Jan 02 09:30:06 2020 +0000
@@ -0,0 +1,55 @@
+#ifndef SCRP_SLAVE_H
+#define SCRP_SLAVE_H
+#include "mbed.h"
+#include "BufferedSerial.h"
+
+/*USBでPCにつなぐポートと、基板上でRasPiとつなぐポートを同時に開く。
+ *RedePinの有り無しの選択、ポートを一つだけ開くことも可。
+ *以下から選択。
+ *ScrpSlave(PinName TX1,PinName RX1,uint32_t addr);//RedePinなし、1ポート
+ *ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,uint32_t addr);//RedePinあり、1ポート
+ *ScrpSlave(PinName TX1,PinName RX1,PinName TX2,PinName RX2,uint32_t addr);//RedePinなし、2ポート
+ *ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,PinName TX2,PinName RX2,uint32_t addr);//RedePinあり、1ポート+RedePinなし、1ポート
+ *example not usb port
+ *L432KC : TX = PA_9 , RX = PA_10 , REDE = PA_12 , addr = 0x0803e000
+ *F446RE : TX = PC_12 , RX = PD_2 , RDDE = PH_1 , addr = 0x0807ffff
+ */
+//ScrpSlave slave(SERIAL_TX,SERIAL_RX);
+
+inline int constrain(int x,int a,int b){
+    return (x < a ? a : x > b ? b : x);
+}
+
+inline double constrain(double x,double a,double b){
+    return (x < a ? a : x > b ? b : x);
+}
+
+class ScrpSlave{
+public:
+    ScrpSlave(PinName TX1,PinName RX1,uint32_t addr);//RedePinなし、1ポート
+    ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,uint32_t addr);//RedePinあり、1ポート
+    ScrpSlave(PinName TX1,PinName RX1,PinName TX2,PinName RX2,uint32_t addr);//RedePinなし、2ポート
+    ScrpSlave(PinName TX1,PinName RX1,PinName REDE1,PinName TX2,PinName RX2,uint32_t addr);//RedePinあり、1ポート+RedePinなし、1ポート
+    ~ScrpSlave();
+    void setTimeout(int);
+    void addCMD(uint8_t cmd, bool (*proc)(int rx_data,int& tx_data));
+    int16_t send(uint8_t id,uint8_t cmd,int16_t tx_data);
+    int16_t send2(uint8_t id,uint8_t cmd,int16_t tx_data);
+private:
+    DigitalOut *rede_;
+    BufferedSerial *serial_[2];
+    FlashIAP *flash_;
+    uint8_t mode_;
+    uint8_t my_id_;
+    uint32_t address_;
+    int timeout_;
+    bool (*procs_[256])(int rx_data, int& tx_data);
+    int16_t sending(int,uint8_t,uint8_t,int16_t);
+    void changeID(uint8_t);
+    void check(int port);
+    void init(PinName,PinName);
+    void port1();
+    void port2();
+};
+
+#endif /* SCRP_SLAVE_H */
\ No newline at end of file