Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MDD_L432KC USB2RS485 pathtracking odometry ... more
scrp_slave.hpp
- Committer:
- TanakaRobo
- Date:
- 2020-01-03
- Revision:
- 2:141358d84ff4
- Parent:
- 0:ca84ed7518f5
- Child:
- 3:28c77df7c0b6
File content as of revision 2:141358d84ff4:
#ifndef SCRP_SLAVE_H
#define SCRP_SLAVE_H
#include "mbed.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_;
Serial *serial_[2];
FlashIAP *flash_;
uint8_t send_data_[2][8];
uint8_t mode_;
uint8_t my_id_;
uint32_t address_;
int timeout_;
bool wait_data_[2];
bool stx_flag_[2];
bool id_ok_[2];
uint8_t tmp_data_[2][5];
uint8_t data_count_[2];
int16_t rx_data_[2];
bool (*procs_[256])(int rx_data, int& tx_data);
int16_t sending(int,uint8_t,uint8_t,int16_t);
void changeID(uint8_t);
void init(PinName,PinName);
void check(int port);
void port1();
void port2();
void data_send1();
void data_send2();
void prime(int);
};
#endif /* SCRP_SLAVE_H */
