Skip to content
Snippets Groups Projects
Commit cf185b61 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Changed the driver to use the CFTDI class instead of the CRS232 class

parent 16e690d8
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ADD_EXECUTABLE(test_usb_i2c test_usb_i2c.cpp) ...@@ -5,7 +5,7 @@ ADD_EXECUTABLE(test_usb_i2c test_usb_i2c.cpp)
TARGET_LINK_LIBRARIES(test_usb_i2c usb_i2c_adapter ${iriutils_LIBRARY} ${comm_LIBRARY}) TARGET_LINK_LIBRARIES(test_usb_i2c usb_i2c_adapter ${iriutils_LIBRARY} ${comm_LIBRARY})
# edit the following line to add the source code for the example and the name of the executable # edit the following line to add the source code for the example and the name of the executable
ADD_EXECUTABLE(test_battery battery_test.cpp) ADD_EXECUTABLE(test_camera test_camera.cpp)
# edit the following line to add the necessary libraries # edit the following line to add the necessary libraries
TARGET_LINK_LIBRARIES(test_battery usb_i2c_adapter ${iriutils_LIBRARY} ${comm_LIBRARY}) TARGET_LINK_LIBRARIES(test_camera usb_i2c_adapter ${iriutils_LIBRARY} ${comm_LIBRARY})
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include "usb_i2c.h" #include "usb_i2c.h"
#include <iostream> #include <iostream>
const std::string usb_port="/dev/ttyUSB0"; const std::string serial="A700ettt";
const unsigned char dev_id=0x22; const unsigned char dev_id=0x21;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -11,7 +11,7 @@ int main(int argc, char *argv[]) ...@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
int i=0; int i=0;
try{ try{
adapter.open(usb_port); adapter.open(serial);
std::cout << "Firmware revision: " << (int)adapter.get_revision() << std::endl; std::cout << "Firmware revision: " << (int)adapter.get_revision() << std::endl;
std::cout << "Turning the led off ..." << std::endl; std::cout << "Turning the led off ..." << std::endl;
adapter.turn_led_off(); adapter.turn_led_off();
......
...@@ -16,7 +16,7 @@ CUSBI2C::CUSBI2C(const std::string &adapter_id) ...@@ -16,7 +16,7 @@ CUSBI2C::CUSBI2C(const std::string &adapter_id)
else else
{ {
this->adapter_id=adapter_id; this->adapter_id=adapter_id;
this->comm_dev=new CRS232(comm_dev_id); this->comm_dev=NULL;
this->gpio_config[gpio1]=digital_input; this->gpio_config[gpio1]=digital_input;
this->gpio_config[gpio2]=i2c; this->gpio_config[gpio2]=i2c;
this->gpio_config[gpio3]=i2c; this->gpio_config[gpio3]=i2c;
...@@ -25,18 +25,42 @@ CUSBI2C::CUSBI2C(const std::string &adapter_id) ...@@ -25,18 +25,42 @@ CUSBI2C::CUSBI2C(const std::string &adapter_id)
} }
} }
void CUSBI2C::open(const std::string &port_id) void CUSBI2C::open(const std::string &serial)
{ {
TRS232_config config; CFTDIServer *ftdi_server=CFTDIServer::instance();
TFTDIconfig ftdi_config;
int i=0;
if(this->comm_dev!=NULL) if(this->comm_dev!=NULL)
this->comm_dev->open((void *)&port_id); {
config.baud=19200; this->comm_dev->close();
config.num_bits=8; delete this->comm_dev;
config.parity=none; this->comm_dev=NULL;
config.stop_bits=2; }
this->comm_dev->config(&config); if(ftdi_server->get_num_devices()>0)
this->rx_event_id=this->comm_dev->get_rx_event_id(); {
for(i=0;i<ftdi_server->get_num_devices();i++)
{
if(serial==ftdi_server->get_serial_number(i))
{
this->comm_dev=ftdi_server->get_device(ftdi_server->get_serial_number(i));
ftdi_config.baud_rate = 19200;
ftdi_config.word_length = 8;
ftdi_config.stop_bits = 2;
ftdi_config.parity = 0;
ftdi_config.read_timeout = 2;
ftdi_config.write_timeout = 2;
ftdi_config.latency_timer = 2;
this->comm_dev->config(&ftdi_config);
this->rx_event_id=this->comm_dev->get_rx_event_id();
}
}
if(this->comm_dev==NULL)/* the device has not been initialized */
{
/* handle exceptions */
throw CUSBI2CException(_HERE_,"No FTDI device available with the desired serial number.");
}
}
} }
unsigned char CUSBI2C::get_revision(void) unsigned char CUSBI2C::get_revision(void)
...@@ -385,7 +409,7 @@ int CUSBI2C::write_reg(unsigned char dev_id, short int address, unsigned char *d ...@@ -385,7 +409,7 @@ int CUSBI2C::write_reg(unsigned char dev_id, short int address, unsigned char *d
cmd[1]=dev_id<<1; cmd[1]=dev_id<<1;
cmd[2]=address; cmd[2]=address;
cmd[3]=num; cmd[3]=num;
memcpy(&data[total_written],&cmd[4],num); memcpy(&cmd[4],&data[total_written],num);
num+=4; num+=4;
} }
else else
......
#ifndef _USB_I2C_H #ifndef _USB_I2C_H
#define _USB_I2C_H #define _USB_I2C_H
#include "rs232.h" #include "ftdimodule.h"
#include "ftdiserver.h"
#include "eventserver.h" #include "eventserver.h"
typedef enum {gpio1=0,gpio2=1,gpio3=2} gpio_pins; typedef enum {gpio1=0,gpio2=1,gpio3=2} gpio_pins;
...@@ -11,14 +12,14 @@ typedef enum {digital_input=0x01,digital_output=0x02,analog_input=0x04,i2c=0x08} ...@@ -11,14 +12,14 @@ typedef enum {digital_input=0x01,digital_output=0x02,analog_input=0x04,i2c=0x08}
class CUSBI2C class CUSBI2C
{ {
private: private:
CRS232 *comm_dev; CFTDI *comm_dev;
std::string adapter_id; std::string adapter_id;
std::string rx_event_id; std::string rx_event_id;
unsigned char gpio_config[3]; unsigned char gpio_config[3];
CEventServer *event_server; CEventServer *event_server;
public: public:
CUSBI2C(const std::string &adapter_id); CUSBI2C(const std::string &adapter_id);
void open(const std::string &port_id); void open(const std::string &serial);
unsigned char get_revision(void); unsigned char get_revision(void);
void config_gpio(gpio_pins pin, gpio_types type); void config_gpio(gpio_pins pin, gpio_types type);
void set_gpio(gpio_pins pin, bool value); void set_gpio(gpio_pins pin, bool value);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment