<commit_before>/*
open-dobot firmware that controls Dobot FPGA.

Find driver and SDK at https://github.com/maxosprojects/open-dobot

Author: maxosprojects (March 18 2016)
Additional Authors: <put your name here>

Version: 0.5.0

License: MIT
*/

#ifndef DOBOT_H_INCLUDED
#define DOBOT_H_INCLUDED

#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>

#define NOP __asm__ __volatile__ ("nop\n\t")

typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long ulong;

typedef byte(*funcPtrs)(void);
typedef void(*implFuncPtrs)(void);

// typedef struct {
//   byte j1dir : 1;
//   byte j2dir : 1;
//   byte j3dir : 1;
//   // byte deferred : 1;
// } ControlByte;

// DO NOT FORGET TO UPDATE implementationFunctions SIZE!
enum CommandType {
  Move = 0,
  LaserOn,
  LaserOff,
  PumpOn,
  PumpOff,
  ValveOn,
  ValveOff
};
implFuncPtrs implementationFunctions[7];

typedef struct {
  ulong j1;
  ulong j2;
  ulong j3;
  // ControlByte control;
  byte control;
  uint servoGrab;
  uint servoRot;
  CommandType type;
} Command;

typedef struct {
  volatile byte* portin;
  byte pin;
  volatile byte* ddr;
} SwitchPort;

byte cmdReady();
byte cmdSteps();
byte cmdExecQueue();
byte cmdGetAccels();
byte cmdSwitchToAccelReportMode();
byte cmdCalibrateJoint();
byte cmdEmergencyStop();
byte cmdSetCounters();
byte cmdGetCounters();
byte cmdLaserOn();
byte cmdPumpOn();
byte cmdValveOn();
void crcCcitt(byte data[], int len);
void crcCcitt(byte data[], int len, byte keepSeed);
byte read13(byte data[]);
void write0();
void write1(byte data[]);
byte write22(byte data[], uint* val1, uint* val2);
byte write4(byte data[]);
byte write4Continue(byte data[], ulong* val);
byte write444(byte data[], ulong* val1, ulong* val2, ulong* val3);
byte checkCrc(byte data[], int len);
byte confirmCrc(byte data[], int len);
void resetCrc();
void serialInit(void);
void serialWrite(byte c);
void serialWrite(byte data[], byte num);
void serialRead();
byte serialReadNum(byte data[], byte num);
uint accelRead(unsigned char pin);
void initDebug();
void debugOn();
void debugOff();
void laserOn();
void laserOff();
void pumpOn();
void pumpOff();
void valveOn();
void valveOff();

// Rest
volatile byte sequenceRest[19] = {
0xa5, // start signature
0x2,  // motor1 block start (middle driver - Stepper_Rot)
0x42,
0xf0,
0x0,
0x2,  // motor2 block start (left driver - Stepper_R)
0x42,
0xf0,
0x0,
0x2,  // motor3 block start (right driver - Stepper_L)
0x42,
0xf0,
0x0,
0xe0, // motors direction ([bit7-bit0]: bit7 - motor1, bit6 - motor2, bit5 - motor3)
0x2f, // servoGrab
0x80,
0x2f, // servoRot
0x80,
0x5a // end signature
};

/*
 * Refer to open-dobot/docs/images/arduino.jpg
 * 
 * Communication and control pins in use are:
 * D0-1 (USB serial), D12 (laser), D18-21 (bluetooth serial, I2C),
 * D40-53 (FPGA control, D48 - bluetooth enable, D41 - pump, D43 - valve)
 *
 * Unused pins:
 * D59-D61 (unknown, but soldered)
 * 
 * Some of the unused pins are not soldered through to the FPGA board
 * and can be used here:
 * D54-58, D62-69, D22-39
 *
 * This is the list of pins unused by the top board (FPGA board).
 * !!!!! BEFORE CHANGING ANY OF THESE:  !!!!!!
 * 1. Check you're not targeting USART pins
 * 2. Check you're not targeting any communication and control pins
 */
SwitchPort calibrationPins[] = {
  {
    // D3 - reference 0
    &PINE,
    PE5,
    &DDRE
  },
  {
    // D4 - reference 1
    &PING,
    PG5,
    &DDRG
  },
  {
    // D5 - reference 2
    &PINE,
    PE3,<commit_msg>Update dobot.h<commit_after>/*
open-dobot firmware that controls Dobot FPGA.

Find driver and SDK at https://github.com/maxosprojects/open-dobot

Author: maxosprojects (March 18 2016)
Additional Authors: <put your name here>

Version: 0.5.0

License: MIT
*/

#ifndef DOBOT_H_INCLUDED
#define DOBOT_H_INCLUDED

#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>

#define NOP __asm__ __volatile__ ("nop\n\t")

typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long ulong;

typedef byte(*funcPtrs)(void);
typedef void(*implFuncPtrs)(void);

// typedef struct {
//   byte j1dir : 1;
//   byte j2dir : 1;
//   byte j3dir : 1;
//   // byte deferred : 1;
// } ControlByte;

// DO NOT FORGET TO UPDATE implementationFunctions SIZE!
enum CommandType {
  Move = 0,
  LaserOn,
  LaserOff,
  PumpOn,
  PumpOff,
  ValveOn,
  ValveOff
};
implFuncPtrs implementationFunctions[7];

typedef struct {
  ulong j1;
  ulong j2;
  ulong j3;
  // ControlByte control;
  byte control;
  uint servoGrab;
  uint servoRot;
  CommandType type;
} Command;

typedef struct {
  volatile byte* portin;
  byte pin;
  volatile byte* ddr;
} SwitchPort;

byte cmdReady();
byte cmdSteps();
byte cmdExecQueue();
byte cmdGetAccels();
byte cmdSwitchToAccelReportMode();
byte cmdCalibrateJoint();
byte cmdEmergencyStop();
byte cmdSetCounters();
byte cmdGetCounters();
byte cmdLaserOn();
byte cmdPumpOn();
byte cmdValveOn();
void crcCcitt(byte data[], int len);
void crcCcitt(byte data[], int len, byte keepSeed);
byte read13(byte data[]);
void write0();
void write1(byte data[]);
byte write22(byte data[], uint* val1, uint* val2);
byte write4(byte data[]);
byte write4Continue(byte data[], ulong* val);
byte write444(byte data[], ulong* val1, ulong* val2, ulong* val3);
byte checkCrc(byte data[], int len);
byte confirmCrc(byte data[], int len);
void resetCrc();
void serialInit(void);
void serialWrite(byte c);
void serialWrite(byte data[], byte num);
void serialRead();
byte serialReadNum(byte data[], byte num);
uint accelRead(unsigned char pin);
void initDebug();
void debugOn();
void debugOff();
void laserOn();
void laserOff();
void pumpOn();
void pumpOff();
void valveOn();
void valveOff();

// Rest
volatile byte sequenceRest[19] = {
0xa5, // start signature
0x2,  // motor1 block start (middle driver - Stepper_Rot)
0x42,
0xf0,
0x0,
0x2,  // motor2 block start (left driver - Stepper_R)
0x42,
0xf0,
0x0,
0x2,  // motor3 block start (right driver - Stepper_L)
0x42,
0xf0,
0x0,
0xe0, // motors direction ([bit7-bit0]: bit7 - motor1, bit6 - motor2, bit5 - motor3)
0x2f, // servoGrab
0x80,
0x2f, // servoRot
0x80,
0x5a // end signature
};

/*
 * Refer to open-dobot/docs/images/arduino.jpg
 * 
 * Communication and control pins in use are:
 * D0-1 (USB serial), D12 (laser), D18-19 (bluetooth serial),
 * D40-53 (FPGA control, D48 - bluetooth enable, D41 - pump, D43 - valve)
 *
 * Unused pins:
 * D59-D61 (unknown, but soldered), D20-21 (I2C)
 * 
 * Some of the unused pins are not soldered through to the FPGA board
 * and can be used here:
 * D54-58, D62-69, D22-39
 *
 * This is the list of pins unused by the top board (FPGA board).
 * !!!!! BEFORE CHANGING ANY OF THESE:  !!!!!!
 * 1. Check you're not targeting USART pins
 * 2. Check you're not targeting any communication and control pins
 */
SwitchPort calibrationPins[] = {
  {
    // D3 - reference 0
    &PINE,
    PE5,
    &DDRE
  },
  {
    // D4 - reference 1
    &PING,
    PG5,
    &DDRG
  },
  {
    // D5 - reference 2
    &PINE,
    PE3,
{'fraction_non_alphanumeric': 0.13149673388241978, 'fraction_numerical': 0.04004544163589889, 'mean_word_length': 3.8943710910354414, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1962593', 'n_tokens_mistral': 2746, 'n_tokens_neox': 2563, 'n_words': 821}