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
......@@ -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})
# 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
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 @@
#include "usb_i2c.h"
#include <iostream>
const std::string usb_port="/dev/ttyUSB0";
const unsigned char dev_id=0x22;
const std::string serial="A700ettt";
const unsigned char dev_id=0x21;
int main(int argc, char *argv[])
{
......@@ -11,7 +11,7 @@ int main(int argc, char *argv[])
int i=0;
try{
adapter.open(usb_port);
adapter.open(serial);
std::cout << "Firmware revision: " << (int)adapter.get_revision() << std::endl;
std::cout << "Turning the led off ..." << std::endl;
adapter.turn_led_off();
......
......@@ -16,7 +16,7 @@ CUSBI2C::CUSBI2C(const std::string &adapter_id)
else
{
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[gpio2]=i2c;
this->gpio_config[gpio3]=i2c;
......@@ -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)
this->comm_dev->open((void *)&port_id);
config.baud=19200;
config.num_bits=8;
config.parity=none;
config.stop_bits=2;
this->comm_dev->config(&config);
this->rx_event_id=this->comm_dev->get_rx_event_id();
{
this->comm_dev->close();
delete this->comm_dev;
this->comm_dev=NULL;
}
if(ftdi_server->get_num_devices()>0)
{
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)
......@@ -385,7 +409,7 @@ int CUSBI2C::write_reg(unsigned char dev_id, short int address, unsigned char *d
cmd[1]=dev_id<<1;
cmd[2]=address;
cmd[3]=num;
memcpy(&data[total_written],&cmd[4],num);
memcpy(&cmd[4],&data[total_written],num);
num+=4;
}
else
......
#ifndef _USB_I2C_H
#define _USB_I2C_H
#include "rs232.h"
#include "ftdimodule.h"
#include "ftdiserver.h"
#include "eventserver.h"
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}
class CUSBI2C
{
private:
CRS232 *comm_dev;
CFTDI *comm_dev;
std::string adapter_id;
std::string rx_event_id;
unsigned char gpio_config[3];
CEventServer *event_server;
public:
CUSBI2C(const std::string &adapter_id);
void open(const std::string &port_id);
void open(const std::string &serial);
unsigned char get_revision(void);
void config_gpio(gpio_pins pin, gpio_types type);
void set_gpio(gpio_pins pin, bool value);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment