-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ROBOTIS-GIT/develop
Merge for Release 1.0.1
- Loading branch information
Showing
29 changed files
with
2,567 additions
and
278 deletions.
There are no files selected for viewing
Binary file not shown.
854 changes: 854 additions & 0 deletions
854
arduino/opencr_arduino/libraries/OpenCR_ILI9341/OpenCR_ILI9341.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
199 changes: 199 additions & 0 deletions
199
arduino/opencr_arduino/libraries/OpenCR_ILI9341/OpenCR_ILI9341.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/*************************************************** | ||
This is our library for the Adafruit ILI9341 Breakout and Shield | ||
----> http://www.adafruit.com/products/1651 | ||
Check out the links above for our tutorials and wiring diagrams | ||
These displays use SPI to communicate, 4 or 5 pins are required to | ||
interface (RST is optional) | ||
Adafruit invests time and resources providing this open source code, | ||
please support Adafruit and open-source hardware by purchasing | ||
products from Adafruit! | ||
Written by Limor Fried/Ladyada for Adafruit Industries. | ||
MIT license, all text above must be included in any redistribution | ||
****************************************************/ | ||
|
||
#ifndef _ADAFRUIT_ILI9341H_ | ||
#define _ADAFRUIT_ILI9341H_ | ||
|
||
#if ARDUINO >= 100 | ||
#include "Arduino.h" | ||
#include "Print.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
#include <Adafruit_GFX.h> | ||
#ifdef __AVR | ||
#include <avr/pgmspace.h> | ||
#elif defined(ESP8266) | ||
#include <pgmspace.h> | ||
#endif | ||
|
||
#ifdef ARDUINO_STM32_FEATHER | ||
typedef volatile uint32 RwReg; | ||
#endif | ||
#ifdef __OPENCR__ | ||
typedef uint32_t RwReg; | ||
#endif | ||
|
||
#if defined (__AVR__) || defined(TEENSYDUINO) || defined (__arm__) && !defined(__OPENCR__) | ||
#ifndef __OPENCR__ | ||
#define USE_FAST_PINIO | ||
#endif | ||
#endif | ||
|
||
#define ILI9341_TFTWIDTH 240 | ||
#define ILI9341_TFTHEIGHT 320 | ||
|
||
#define ILI9341_NOP 0x00 | ||
#define ILI9341_SWRESET 0x01 | ||
#define ILI9341_RDDID 0x04 | ||
#define ILI9341_RDDST 0x09 | ||
|
||
#define ILI9341_SLPIN 0x10 | ||
#define ILI9341_SLPOUT 0x11 | ||
#define ILI9341_PTLON 0x12 | ||
#define ILI9341_NORON 0x13 | ||
|
||
#define ILI9341_RDMODE 0x0A | ||
#define ILI9341_RDMADCTL 0x0B | ||
#define ILI9341_RDPIXFMT 0x0C | ||
#define ILI9341_RDIMGFMT 0x0D | ||
#define ILI9341_RDSELFDIAG 0x0F | ||
|
||
#define ILI9341_INVOFF 0x20 | ||
#define ILI9341_INVON 0x21 | ||
#define ILI9341_GAMMASET 0x26 | ||
#define ILI9341_DISPOFF 0x28 | ||
#define ILI9341_DISPON 0x29 | ||
|
||
#define ILI9341_CASET 0x2A | ||
#define ILI9341_PASET 0x2B | ||
#define ILI9341_RAMWR 0x2C | ||
#define ILI9341_RAMRD 0x2E | ||
|
||
#define ILI9341_PTLAR 0x30 | ||
#define ILI9341_MADCTL 0x36 | ||
#define ILI9341_PIXFMT 0x3A | ||
|
||
#define ILI9341_FRMCTR1 0xB1 | ||
#define ILI9341_FRMCTR2 0xB2 | ||
#define ILI9341_FRMCTR3 0xB3 | ||
#define ILI9341_INVCTR 0xB4 | ||
#define ILI9341_DFUNCTR 0xB6 | ||
|
||
#define ILI9341_PWCTR1 0xC0 | ||
#define ILI9341_PWCTR2 0xC1 | ||
#define ILI9341_PWCTR3 0xC2 | ||
#define ILI9341_PWCTR4 0xC3 | ||
#define ILI9341_PWCTR5 0xC4 | ||
#define ILI9341_VMCTR1 0xC5 | ||
#define ILI9341_VMCTR2 0xC7 | ||
|
||
#define ILI9341_RDID1 0xDA | ||
#define ILI9341_RDID2 0xDB | ||
#define ILI9341_RDID3 0xDC | ||
#define ILI9341_RDID4 0xDD | ||
|
||
#define ILI9341_GMCTRP1 0xE0 | ||
#define ILI9341_GMCTRN1 0xE1 | ||
/* | ||
#define ILI9341_PWCTR6 0xFC | ||
*/ | ||
|
||
// Color definitions | ||
#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */ | ||
#define ILI9341_NAVY 0x000F /* 0, 0, 128 */ | ||
#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */ | ||
#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */ | ||
#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */ | ||
#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */ | ||
#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */ | ||
#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */ | ||
#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */ | ||
#define ILI9341_BLUE 0x001F /* 0, 0, 255 */ | ||
#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */ | ||
#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */ | ||
#define ILI9341_RED 0xF800 /* 255, 0, 0 */ | ||
#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */ | ||
#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */ | ||
#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */ | ||
#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */ | ||
#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ | ||
#define ILI9341_PINK 0xF81F | ||
|
||
class Adafruit_ILI9341 : public Adafruit_GFX { | ||
|
||
public: | ||
|
||
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, | ||
int8_t _RST, int8_t _MISO); | ||
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1); | ||
|
||
void begin(void), | ||
setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1), | ||
pushColor(uint16_t color), | ||
fillScreen(uint16_t color), | ||
drawPixel(int16_t x, int16_t y, uint16_t color), | ||
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), | ||
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), | ||
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, | ||
uint16_t color), | ||
setRotation(uint8_t r), | ||
invertDisplay(boolean i); | ||
uint16_t color565(uint8_t r, uint8_t g, uint8_t b); | ||
uint16_t readID(void) { return _lcd_ID; }; | ||
void vertScroll(int16_t top, int16_t scrollines, int16_t offset); | ||
|
||
/* These are not for current use, 8-bit protocol only! */ | ||
uint8_t readdata(void), | ||
readcommand8(uint8_t reg, uint8_t index = 0); | ||
/* | ||
uint16_t readcommand16(uint8_t); | ||
uint32_t readcommand32(uint8_t); | ||
void dummyclock(void); | ||
*/ | ||
|
||
void spiwrite(uint8_t), | ||
writecommand(uint8_t c), | ||
writedata(uint8_t d), | ||
commandList(uint8_t *addr); | ||
void WriteCmdParamN(uint16_t cmd, int8_t N, uint8_t * block); | ||
uint8_t spiread(void); | ||
void spiwrite16(uint16_t c); | ||
void WriteCmdData(uint16_t cmd, uint16_t dat); | ||
|
||
void WriteCmd(uint16_t x) { digitalWrite(_dc, LOW); spiwrite16(x); }; | ||
void WriteData(uint16_t x) { digitalWrite(_dc, HIGH); spiwrite16(x); }; | ||
private: | ||
uint8_t tabcolor; | ||
|
||
|
||
|
||
boolean hwSPI; | ||
#if defined (__AVR__) || defined(TEENSYDUINO) | ||
uint8_t mySPCR; | ||
volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport; | ||
int8_t _cs, _dc, _rst, _mosi, _miso, _sclk; | ||
uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask; | ||
////This def is for the Arduino.ORG M0!!! | ||
//#elif defined(ARDUINO_SAM_ZERO) | ||
// volatile PORT_OUT_Type *mosiport, *clkport, *dcport, *rsport, *csport; | ||
// int32_t _cs, _dc, _rst, _mosi, _miso, _sclk; | ||
// PORT_OUT_Type mosipinmask, clkpinmask, cspinmask, dcpinmask; | ||
#elif defined (__arm__) | ||
volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport; | ||
int32_t _cs, _dc, _rst, _mosi, _miso, _sclk; | ||
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask; | ||
#elif defined (ESP8266) | ||
int32_t _cs, _dc, _rst, _mosi, _miso, _sclk; | ||
#else | ||
int8_t _cs, _dc, _rst, _mosi, _miso, _sclk; | ||
#endif | ||
|
||
uint16_t _lcd_ID, _lcd_rev, _lcd_madctl, _lcd_drivOut, _MC, _MP, _MW, _SC, _EC, _SP, _EP; | ||
uint16_t _lcd_xor, _lcd_capable; | ||
}; | ||
|
||
#endif |
21 changes: 21 additions & 0 deletions
21
arduino/opencr_arduino/libraries/OpenCR_ILI9341/README.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
This is a library for the Adafruit ILI9341 display products | ||
|
||
This library works with the Adafruit 2.8" Touch Shield V2 (SPI) | ||
----> http://www.adafruit.com/products/1651 | ||
|
||
Check out the links above for our tutorials and wiring diagrams. | ||
These displays use SPI to communicate, 4 or 5 pins are required | ||
to interface (RST is optional). | ||
|
||
Adafruit invests time and resources providing this open source code, | ||
please support Adafruit and open-source hardware by purchasing | ||
products from Adafruit! | ||
|
||
Written by Limor Fried/Ladyada for Adafruit Industries. | ||
MIT license, all text above must be included in any redistribution | ||
|
||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ILI9341. Check that the Adafruit_ILI9341 folder contains Adafruit_ILI9341.cpp and Adafruit_ILI9341. | ||
|
||
Place the Adafruit_ILI9341 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE | ||
|
||
Also requires the Adafruit_GFX library for Arduino. |
156 changes: 156 additions & 0 deletions
156
arduino/opencr_arduino/libraries/OpenCR_ILI9341/examples/dxl_ollo/dxl_ollo.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
|
||
#include <Adafruit_GFX.h> // Core graphics library | ||
#include "OpenCR_ILI9341.h" // Hardware-specific library | ||
#include <SPI.h> | ||
#include <SD.h> | ||
#include <IMU.h> | ||
#include <Dynamixel.h> | ||
#include <OLLO.h> | ||
|
||
OLLO myOLLO; | ||
Dynamixel Dxl; | ||
cIMU IMU; | ||
|
||
|
||
// TFT display and SD card will share the hardware SPI interface. | ||
// Hardware SPI pins are specific to the Arduino board type and | ||
// cannot be remapped to alternate pins. For Arduino Uno, | ||
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK. | ||
|
||
#define TFT_DC 6 | ||
#define TFT_CS 7 | ||
#define TFT_MOSI 3 | ||
#define TFT_MISO 2 | ||
#define TFT_CLK 4 | ||
#define TFT_RST 5 | ||
|
||
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC | ||
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); | ||
// If using the breakout, change pins as desired | ||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO); | ||
|
||
#define BLACK 0x0000 | ||
#define BLUE 0x001F | ||
#define RED 0xF800 | ||
#define GREEN 0x07E0 | ||
#define CYAN 0x07FF | ||
#define MAGENTA 0xF81F | ||
#define YELLOW 0xFFE0 | ||
#define WHITE 0xFFFF | ||
|
||
// work in line numbers. Font height in ht | ||
int16_t ht = 16, top = 0, line, lines = 19, scroll; | ||
|
||
|
||
int motor_id = 1; | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
|
||
uint16_t id = tft.readID(); | ||
tft.begin(); | ||
tft.setRotation(0); //Portrait | ||
tft.fillScreen(BLACK); | ||
tft.setTextColor(WHITE, BLACK); | ||
tft.setTextSize(2); // System font is 8 pixels. ht = 8*2=16 | ||
tft.setCursor(100, 0); | ||
tft.print("ID = 0x"); | ||
tft.println(id, HEX); | ||
|
||
lines = tft.height(); | ||
|
||
tft.setCursor(0, 0); | ||
tft.fillScreen(BLACK); | ||
|
||
IMU.begin(); | ||
|
||
|
||
myOLLO.begin(1, IR_SENSOR); | ||
|
||
Dxl.begin(3); | ||
Dxl.writeByte(motor_id, 64, 1 ); | ||
} | ||
|
||
uint8_t line_x_buf[320]; | ||
uint8_t line_y_buf[320]; | ||
uint8_t line_z_buf[320]; | ||
|
||
void loop() | ||
{ | ||
static int x = 0; | ||
static int y = 0; | ||
static int z = 0; | ||
static uint32_t tTime[2]; | ||
static uint32_t MotorIndex; | ||
|
||
if( millis()-tTime[0] > 5 ) | ||
{ | ||
tTime[0] = millis(); | ||
|
||
tft.setCursor(0, (scroll + top) * 1); | ||
//tft.setCursor(0,lines ); | ||
if (++scroll >= lines) scroll = 0; | ||
//tft.vertScroll(top*ht, lines * ht, (scroll) * ht); | ||
//tft.drawPixel( x, (scroll + top) * 1, YELLOW); | ||
//tft.vertScroll(top, lines, scroll*1); | ||
|
||
tft.drawPixel( line_x_buf[scroll], scroll, BLACK); | ||
tft.drawPixel( line_y_buf[scroll], scroll, BLACK); | ||
//tft.drawPixel( line_z_buf[scroll], scroll, BLACK); | ||
|
||
tft.drawPixel( x, scroll, YELLOW); | ||
tft.drawPixel( y, scroll, RED); | ||
//tft.drawPixel( z, scroll, RED); | ||
|
||
line_x_buf[scroll] = x; | ||
line_y_buf[scroll] = y; | ||
//line_z_buf[scroll] = z; | ||
|
||
tft.vertScroll(top, lines, scroll); | ||
|
||
line++; | ||
} | ||
|
||
IMU.update(); | ||
|
||
x = map(Dxl.readWord(motor_id, 132),0, 4096, -100, 100) + tft.width()/2+40; | ||
y = map(myOLLO.read(1, IR_SENSOR), 0, 1023, 0, -100) + tft.width()/2; | ||
//z = IMU.angle[2] + tft.width()/2; | ||
|
||
if( millis()-tTime[1] > 1000 ) | ||
{ | ||
tTime[1] = millis(); | ||
|
||
if( MotorIndex == 0 ) | ||
{ | ||
Dxl.writeDword(motor_id, 116, get_pos(0) ); | ||
} | ||
else | ||
{ | ||
Dxl.writeDword(motor_id, 116, get_pos(90) ); | ||
} | ||
|
||
MotorIndex ^= 1; | ||
} | ||
|
||
|
||
if( Serial.available() ) | ||
{ | ||
uint8_t ch; | ||
|
||
ch = Serial.read(); | ||
|
||
if( ch == '1' ) Dxl.writeByte(motor_id, 64, 1 ); | ||
if( ch == '2' ) Dxl.writeByte(motor_id, 64, 0 ); | ||
if( ch == '3' ) Dxl.writeDword(motor_id, 116, get_pos(0) ); | ||
if( ch == '4' ) Dxl.writeDword(motor_id, 116, get_pos(90) ); | ||
|
||
} | ||
} | ||
|
||
uint32_t get_pos( int pos ) | ||
{ | ||
return map( pos, -180, 180, 0, 4095); | ||
} | ||
|
Oops, something went wrong.