Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed for Teensy's, added SPI.transaction (where applicable) #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 38 additions & 26 deletions ArduCAM/ArduCAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#include <Wire.h>
#include <SPI.h>

#if defined(__arm__)
#if defined(__arm__) && !defined(TEENSYDUINO)
#define Wire Wire1
#endif

Expand Down Expand Up @@ -157,25 +157,38 @@ void ArduCAM::set_mode(uint8_t mode)

//Low level SPI write operation
int ArduCAM::bus_write(int address, int value) {
#if defined(SPI_HAS_TRANSACTION)
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
#endif
// take the SS pin low to select the chip:
cbi(P_CS, B_CS);
// send in the address and value via SPI:
SPI.transfer(address);
SPI.transfer(value);
// take the SS pin high to de-select the chip:
sbi(P_CS, B_CS);
#if defined(SPI_HAS_TRANSACTION)
SPI.endTransaction();
#endif
return 1;
}

//Low level SPI read operation
uint8_t ArduCAM::bus_read(int address) {
uint8_t value = 0;
#if defined(SPI_HAS_TRANSACTION)
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
#endif
// take the SS pin low to select the chip:
cbi(P_CS, B_CS);
// send in the address and value via SPI:
SPI.transfer(address);
value = SPI.transfer(0x00);
// take the SS pin high to de-select the chip:
sbi(P_CS, B_CS);
#if defined(SPI_HAS_TRANSACTION)
SPI.endTransaction();
#endif
return value;
}

Expand All @@ -201,7 +214,7 @@ ArduCAM::ArduCAM()

ArduCAM::ArduCAM(byte model,int CS)
{
#if defined(ESP8266)
#if defined(ESP8266) || defined(TEENSYDUINO)
B_CS = CS;
#else
P_CS = portOutputRegister(digitalPinToPort(CS));
Expand Down Expand Up @@ -447,7 +460,7 @@ byte ArduCAM::rdSensorReg16_16(uint16_t regID, uint16_t* regDat)
//I2C Array Write 8bit address, 8bit data
int ArduCAM::wrSensorRegs8_8(const struct sensor_reg reglist[])
{
int err = 0;

uint16_t reg_addr = 0;
uint16_t reg_val = 0;
const struct sensor_reg *next = reglist;
Expand All @@ -456,7 +469,7 @@ int ArduCAM::wrSensorRegs8_8(const struct sensor_reg reglist[])
{
reg_addr = pgm_read_word(&next->reg);
reg_val = pgm_read_word(&next->val);
err = wrSensorReg8_8(reg_addr, reg_val);
wrSensorReg8_8(reg_addr, reg_val);
next++;
#if defined(ESP8266)
yield();
Expand All @@ -469,16 +482,17 @@ int ArduCAM::wrSensorRegs8_8(const struct sensor_reg reglist[])
//I2C Array Write 8bit address, 16bit data
int ArduCAM::wrSensorRegs8_16(const struct sensor_reg reglist[])
{
int err = 0;

unsigned int reg_addr,reg_val;

unsigned int reg_addr = 0;
unsigned int reg_val = 0;
//unsigned int reg_addr,reg_val;
const struct sensor_reg *next = reglist;

while ((reg_addr != 0xff) | (reg_val != 0xffff))
{
reg_addr = pgm_read_word(&next->reg);
reg_val = pgm_read_word(&next->val);
err = wrSensorReg8_16(reg_addr, reg_val);
wrSensorReg8_16(reg_addr, reg_val);
// if (!err)
//return err;
next++;
Expand All @@ -493,17 +507,16 @@ int ArduCAM::wrSensorRegs8_16(const struct sensor_reg reglist[])
//I2C Array Write 16bit address, 8bit data
int ArduCAM::wrSensorRegs16_8(const struct sensor_reg reglist[])
{
int err = 0;

unsigned int reg_addr;
unsigned char reg_val;
unsigned int reg_addr = 0;
unsigned char reg_val = 0;
const struct sensor_reg *next = reglist;

while ((reg_addr != 0xffff) | (reg_val != 0xff))
{
reg_addr = pgm_read_word(&next->reg);
reg_val = pgm_read_word(&next->val);
err = wrSensorReg16_8(reg_addr, reg_val);
wrSensorReg16_8(reg_addr, reg_val);
//if (!err)
//return err;
next++;
Expand All @@ -518,15 +531,15 @@ int ArduCAM::wrSensorRegs16_8(const struct sensor_reg reglist[])
//I2C Array Write 16bit address, 16bit data
int ArduCAM::wrSensorRegs16_16(const struct sensor_reg reglist[])
{
int err = 0;
//int err = 0;

unsigned int reg_addr,reg_val;
const struct sensor_reg *next = reglist;
reg_addr = pgm_read_word(&next->reg);
reg_val = pgm_read_word(&next->val);
while ((reg_addr != 0xffff) | (reg_val != 0xffff))
{
err = wrSensorReg16_16(reg_addr, reg_val);
wrSensorReg16_16(reg_addr, reg_val);
//if (!err)
// return err;
next++;
Expand Down Expand Up @@ -583,7 +596,7 @@ void ArduCAM::OV2640_set_JPEG_size(uint8_t size)
void ArduCAM::OV5642_set_JPEG_size(uint8_t size)
{
#if defined OV5642_CAM
uint8_t reg_val;
//uint8_t reg_val;

wrSensorRegs16_8(ov5642_dvp_fmt_global_init);
delay(100);
Expand Down Expand Up @@ -647,17 +660,17 @@ void ArduCAM::set_format(byte fmt)

void ArduCAM::InitCAM()
{
byte rtn = 0;
//byte rtn = 0;
byte reg_val;
uint16_t val;
//uint16_t val;
switch(sensor_model)
{
case OV7660:
{
#if defined OV7660_CAM
wrSensorReg8_8(0x12, 0x80);
delay(100);
rtn = wrSensorRegs8_8(OV7660_QVGA);
wrSensorRegs8_8(OV7660_QVGA);
#endif
break;
}
Expand All @@ -666,7 +679,7 @@ void ArduCAM::InitCAM()
#if defined OV7725_CAM
wrSensorReg8_8(0x12, 0x80);
delay(100);
rtn = wrSensorRegs8_8(OV7725_QVGA);
wrSensorRegs8_8(OV7725_QVGA);
rdSensorReg8_8(0x15,&reg_val);
wrSensorReg8_8(0x15, (reg_val | 0x02));
#endif
Expand All @@ -677,7 +690,7 @@ void ArduCAM::InitCAM()
#if defined OV7670_CAM
wrSensorReg8_8(0x12, 0x80);
delay(100);
rtn = wrSensorRegs8_8(OV7670_QVGA);
wrSensorRegs8_8(OV7670_QVGA);
#endif
break;
}
Expand All @@ -686,8 +699,7 @@ void ArduCAM::InitCAM()
#if defined OV7675_CAM
wrSensorReg8_8(0x12, 0x80);
delay(100);
rtn = wrSensorRegs8_8(OV7675_QVGA);

wrSensorRegs8_8(OV7675_QVGA);
#endif
break;
}
Expand All @@ -701,8 +713,8 @@ void ArduCAM::InitCAM()
wrSensorReg8_16(0xf0, 0x00);
wrSensorReg8_16(0x21, 0x8403); //Mirror Column
wrSensorReg8_16(0xC6, 0xA103);//SEQ_CMD
wrSensorReg8_16(0xC8, 0x0005); //SEQ_CMD
#endif
wrSensorReg8_16(0xC8, 0x0005); //SEQ_CMD
#endif
break;

}
Expand Down Expand Up @@ -792,8 +804,8 @@ void ArduCAM::InitCAM()
wrSensorReg8_16(0xf0, 0x00);
wrSensorReg8_16(0x21, 0x8403); //Mirror Column
wrSensorReg8_16(0xC6, 0xA103);//SEQ_CMD
wrSensorReg8_16(0xC8, 0x0005); //SEQ_CMD
#endif
wrSensorReg8_16(0xC8, 0x0005); //SEQ_CMD
#endif
break;
}
case OV5640:
Expand Down
29 changes: 26 additions & 3 deletions ArduCAM/ArduCAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
- Arduino DUE (Tested)
- Arduino Yun (Tested)
- Raspberry Pi (Tested)
- ESP8266-12 (Tested)
- ESP8266-12 (Tested)
- Teensy 3.0 (compile)
- Teensy LC (compile)
- Teensy 3.1/3.2 (compile)

If you make any modifications or improvements to the code, I would appreciate
that you share the code with me so that I might include it in the next release.
Expand Down Expand Up @@ -81,7 +84,8 @@
2015/06/22 V3.4.5 by Lee Add support for MT9M001 camera.
2015/08/05 V3.4.6 by Lee Add support for MT9T112 camera.
2015/08/08 V3.4.7 by Lee Add support for MT9D112 camera.
2015/09/20 V3.4.8 by Lee Add support for ESP8266 processor.
2015/09/20 V3.4.8 by Lee Add support for ESP8266 processor.
2015/11/25 V3.4.9 added support for Teensy's (by sumotoy)
--------------------------------------*/


Expand Down Expand Up @@ -109,7 +113,7 @@

#endif

#if defined(__arm__)
#if defined(__arm__) && !defined(TEENSYDUINO)

#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
Expand Down Expand Up @@ -145,6 +149,25 @@


#endif
//teensy' ARM
#if defined(TEENSYDUINO)

#define cbi(reg, bitmask) digitalWriteFast(bitmask, LOW)
#define sbi(reg, bitmask) digitalWriteFast(bitmask, HIGH)
#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask);
#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask);

#define cport(port, data) port &= data
#define sport(port, data) port |= data

#define swap(type, i, j) {type t = i; i = j; j = t;}

#define fontbyte(x) cfont.font[x]

#define regtype volatile uint8_t
#define regsize uint8_t

#endif

#if defined(ESP8266)

Expand Down
18 changes: 17 additions & 1 deletion UTFT4ArduCAM_SPI/HW_AVR_SPI_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define bitmapdatatype unsigned int*
#endif

#if defined(__arm__)
#if defined(__arm__) && !defined(TEENSYDUINO)

#define UTFT_cbi(reg, bitmask) *reg &= ~bitmask
#define UTFT_sbi(reg, bitmask) *reg |= bitmask
Expand All @@ -35,13 +35,29 @@
#define pgm_read_byte(data) *data
#define bitmapdatatype unsigned short*

/*
#if defined(TEENSYDUINO) && TEENSYDUINO >= 117
#define regtype volatile uint8_t
#define regsize uint8_t
#else
#define regtype volatile uint32_t
#define regsize uint32_t
#endif
*/

#endif

//teensy' ARM
#if defined(TEENSYDUINO)
#define UTFT_cbi(reg, bitmask) digitalWriteFast(bitmask,LOW)
#define UTFT_sbi(reg, bitmask) digitalWriteFast(bitmask,HIGH)

#define swap(type, i, j) {type t = i; i = j; j = t;}

#define fontbyte(x) cfont.font[x]
#define bitmapdatatype unsigned short*
#define regtype volatile uint8_t
#define regsize uint8_t

#endif

Expand Down