Ticket #22867: patch-arduino.c.diff

File patch-arduino.c.diff, 1.6 KB (added by ranauei@…, 14 years ago)
  • arduino.c

    old new  
    1717 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1818 */
    1919
    20 /* $Id: arduino.c 808 2009-02-25 09:39:04Z joerg_wunsch $ */
     20/* $Id: arduino.c 874 2009-11-02 23:52:52Z mludvig $ */
    2121
    2222/*
    2323 * avrdude interface for Arduino programmer
     
    3030
    3131#include <stdio.h>
    3232#include <string.h>
     33#include <unistd.h>
    3334
    3435#include "avrdude.h"
    3536#include "pgm.h"
     
    8283  return 3;
    8384}
    8485
     86static int arduino_open(PROGRAMMER * pgm, char * port)
     87{
     88  strcpy(pgm->port, port);
     89  serial_open(port, pgm->baudrate? pgm->baudrate: 115200, &pgm->fd);
     90
     91  /* Clear DTR and RTS to unload the RESET capacitor
     92   * (for example in Arduino) */
     93  serial_set_dtr_rts(&pgm->fd, 0);
     94  usleep(50*1000);
     95  /* Set DTR and RTS back to high */
     96  serial_set_dtr_rts(&pgm->fd, 1);
     97  usleep(50*1000);
     98
     99  /*
     100   * drain any extraneous input
     101   */
     102  stk500_drain(pgm, 0);
     103
     104  if (stk500_getsync(pgm) < 0)
     105    return -1;
     106
     107  return 0;
     108}
     109
     110static void arduino_close(PROGRAMMER * pgm)
     111{
     112  serial_set_dtr_rts(&pgm->fd, 0);
     113  serial_close(&pgm->fd);
     114  pgm->fd.ifd = -1;
     115}
     116
    85117void arduino_initpgm(PROGRAMMER * pgm)
    86118{
    87119        /* This is mostly a STK500; just the signature is read
    88      differently than on real STK500v1 */
     120     differently than on real STK500v1
     121     and the DTR signal is set when opening the serial port
     122     for the Auto-Reset feature */
    89123  stk500_initpgm(pgm);
    90124
    91125  strcpy(pgm->type, "Arduino");
    92126  pgm->read_sig_bytes = arduino_read_sig_bytes;
    93 
     127  pgm->open = arduino_open;
     128  pgm->close = arduino_close;
    94129}