Skip to content

Commit

Permalink
add support Arduino UNO R4 board
Browse files Browse the repository at this point in the history
  • Loading branch information
ArduCAM committed Aug 7, 2023
1 parent 792b6c9 commit 22477c3
Show file tree
Hide file tree
Showing 15 changed files with 1,248 additions and 21 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@

Arducam released Mega SDK for mega camera. The specific test is as follows:

| Board | Development Environment | Mega SDK Version | Board Manager URL<br />/SDK  | Test Status |
| ------------- | ----------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------- | ----------- |
| UNO | Arduino IDE 2.0.1 | 2.0.2/2.0.4 | / | Tested |
| Mega2560 | Arduino IDE 2.0.1 | 2.0.2/2.0.4 | / | Tested |
| DUE | Arduino IDE 2.0.1 | 2.0.2/2.0.4 | / | Tested |
| Nano33Ble | Arduino IDE 2.0.1 | 2.0.4 | / | Testing |
| Microbit | Arduino IDE 2.0.1 | 2.0.4 | / | Testing |
| Esp8266 | Arduino IDE 2.0.1 | 2.0.4 | [esp8266 board url](http://arduino.esp8266.com/stable/package_esp8266com_index.json) | Tested |
| Esp32-c3 | Arduino IDE 2.0.1 | 2.0.4 | [esp32s board url](https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json) | Tested |
| Esp32-c3 | ESP-IDF 4.4.2 | 2.0.4 | [esp-idf](https://dl.espressif.cn/dl/esp-idf/?idf=4.4) | Tested |
| Esp32s | Arduino IDE 2.0.1 | 2.0.4 | [esp32c-c3 board url](https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json) | Tested |
| Esp32s | ESP-IDF 4.4.2 | 2.0.4 | [esp-idf](https://dl.espressif.cn/dl/esp-idf/?idf=4.4) | Tested |
| Pico | pico | 2.0.4 | [pico sdk](https://github.com/raspberrypi/pico-sdk) | Tested |
| Pico | Arduino IDE 2.0.1 | 2.0.4 | Arduino Mbed OS RP2040 Boards | Tested |
| Stm32f103c8t6 | MDK5 | 2.0.4 | / | Tested |
| Rpi | Bullseye | 2.0.2/2.0.4 | / | Tested |
| EK-RA6M4 | [Renesas e² studio 23.1.0](https://github.com/renesas/fsp/releases/download/v4.3.0/setup_fsp_v4_3_0_e2s_v2023-01.exe)| 2.0.4 | RA6M4-EK Board Support Files v4.3.0 | Tested |
| Board | Development Environment | Mega SDK Version | Board Manager URL<br />/SDK  | Test Status |
| ------------- | ------------------------------------------------------------------------------------------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------- | ----------- |
| UNO | Arduino IDE 2.0.1 | 2.0.2/2.0.4 | / | Tested |
| Mega2560 | Arduino IDE 2.0.1 | 2.0.2/2.0.4 | / | Tested |
| DUE | Arduino IDE 2.0.1 | 2.0.2/2.0.4 | / | Tested |
| Nano33Ble | Arduino IDE 2.0.1 | 2.0.4 | / | Testing |
| Microbit | Arduino IDE 2.0.1 | 2.0.4 | / | Testing |
| Esp8266 | Arduino IDE 2.0.1 | 2.0.4 | [esp8266 board url](http://arduino.esp8266.com/stable/package_esp8266com_index.json) | Tested |
| Esp32-c3 | Arduino IDE 2.0.1 | 2.0.4 | [esp32s board url](https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json) | Tested |
| Esp32-c3 | ESP-IDF 4.4.2 | 2.0.4 | [esp-idf](https://dl.espressif.cn/dl/esp-idf/?idf=4.4) | Tested |
| Esp32s | Arduino IDE 2.0.1 | 2.0.4 | [esp32c-c3 board url](https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json) | Tested |
| Esp32s | ESP-IDF 4.4.2 | 2.0.4 | [esp-idf](https://dl.espressif.cn/dl/esp-idf/?idf=4.4) | Tested |
| Pico | pico | 2.0.4 | [pico sdk](https://github.com/raspberrypi/pico-sdk) | Tested |
| Pico | Arduino IDE 2.0.1 | 2.0.4 | Arduino Mbed OS RP2040 Boards | Tested |
| Stm32f103c8t6 | MDK5 | 2.0.4 | / | Tested |
| Rpi | Bullseye | 2.0.2/2.0.4 | / | Tested |
| EK-RA6M4 | [Renesas e² studio 23.1.0](https://github.com/renesas/fsp/releases/download/v4.3.0/setup_fsp_v4_3_0_e2s_v2023-01.exe) | 2.0.4 | RA6M4-EK Board Support Files v4.3.0 | Tested |
| UNOR4Minima | Arduino IDE 2.1.1 | 2.0.5 | / | Tested |
| UNOR4WIFI | Arduino IDE 2.1.1 | 2.0.5 | / | Tested |
| ProtentaC33 | Arduino IDE 2.1.1 | 2.0.5 | / | Tested |

## Specific Disclaimer

Expand Down
236 changes: 236 additions & 0 deletions examples/ArduinoProtentaC33/full_featured/ArducamLink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
/*
* This file is part of the Arducam SPI Camera project.
*
* Copyright 2021 Arducam Technology co., Ltd. All Rights Reserved.
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
*/
#include "ArducamLink.h"
#include "ArducamUart.h"

ArducamLink::ArducamLink() {}

ArducamLink::~ArducamLink() {}

void ArducamLink::arducamUartBegin(uint32_t baudRate)
{
SerialBegin(baudRate);
}

void ArducamLink::reportVerInfo(Arducam_Mega* myCamera)
{
ArducamCamera* cameraInstance = myCamera->getCameraInstance();
uint8_t headAndtail[] = {0xff, 0xaa, 0x03, 0xff, 0xbb};

uint32_t len = 6;
arducamUartWriteBuff(&headAndtail[0], 3);
arducamUartWriteBuff((uint8_t*)&len, 4);
arducamUartWriteBuff(cameraInstance->verDateAndNumber, 4);
printf("\r\n");
arducamUartWriteBuff(&headAndtail[3], 2);
}

void ArducamLink::reportSdkVerInfo(Arducam_Mega* myCamera)
{
ArducamCamera* cameraInstance = myCamera->getCameraInstance();
uint8_t headAndtail[] = {0xff, 0xaa, 0x05, 0xff, 0xbb};

uint32_t len = 6;
arducamUartWriteBuff(&headAndtail[0], 3);
arducamUartWriteBuff((uint8_t*)&len, 4);
arducamUartWriteBuff((uint8_t*)&cameraInstance->currentSDK->sdkVersion, 4);
printf("\r\n");
arducamUartWriteBuff(&headAndtail[3], 2);
}

void ArducamLink::reportCameraInfo(Arducam_Mega* myCamera)
{
ArducamCamera* cameraInstance = myCamera->getCameraInstance();
uint8_t headAndtail[] = {0xff, 0xaa, 0x02, 0xff, 0xbb};

uint32_t len = 0;
char buff[400];
arducamUartWriteBuff(&headAndtail[0], 3);
sprintf(buff,
"ReportCameraInfo\r\nCamera Type:%s\r\nCamera Support Resolution:%d\r\nCamera Support "
"specialeffects:%d\r\nCamera Support Focus:%d\r\nCamera Exposure Value Max:%ld\r\nCamera Exposure Value "
"Min:%d\r\nCamera Gain Value Max:%d\r\nCamera Gain Value Min:%d\r\nCamera Support Sharpness:%d\r\n",
cameraInstance->myCameraInfo.cameraId, cameraInstance->myCameraInfo.supportResolution,
cameraInstance->myCameraInfo.supportSpecialEffects, cameraInstance->myCameraInfo.supportFocus,
cameraInstance->myCameraInfo.exposureValueMax, cameraInstance->myCameraInfo.exposureValueMin,
cameraInstance->myCameraInfo.gainValueMax, cameraInstance->myCameraInfo.gainValueMin,
cameraInstance->myCameraInfo.supportSharpness);
len = strlen(buff);
arducamUartWriteBuff((uint8_t*)&len, 4);
printf(buff);
arducamUartWriteBuff(&headAndtail[3], 2);
}

void ArducamLink::cameraGetPicture(Arducam_Mega* myCamera)
{
ArducamCamera* cameraInstance = myCamera->getCameraInstance();
uint8_t headAndtail[] = {0xff, 0xaa, 0x01, 0xff, 0xbb};
uint8_t buff[READ_IMAGE_LENGTH] = {0};

uint8_t rtLength = 0;
uint32_t len = myCamera->getTotalLength();
arducamUartWriteBuff(&headAndtail[0], 3);
arducamUartWriteBuff((uint8_t*)(&len), 4);
arducamUartWrite(((cameraInstance->currentPictureMode & 0x0f) << 4) | 0x01);
while (myCamera->getReceivedLength()) {
rtLength = readBuff(cameraInstance, buff, READ_IMAGE_LENGTH);
arducamUartWriteBuff(buff, rtLength);
}
arducamUartWriteBuff(&headAndtail[3], 2);
}

void ArducamLink::send_data_pack(char cmd_type, char* msg)
{
uint8_t headAndtail[] = {0xff, 0xaa, 0x07, 0xff, 0xbb};
headAndtail[2] = cmd_type;
uint32_t len = strlen(msg) + 2;
arducamUartWriteBuff(&headAndtail[0], 3);
arducamUartWriteBuff((uint8_t*)&len, 4);
printf(msg);
printf("\r\n");
arducamUartWriteBuff(&headAndtail[3], 2);
}

uint8_t ArducamLink::uartCommandProcessing(Arducam_Mega* myCAM, uint8_t* commandBuff)
{
ArducamCamera* cameraInstance = myCAM->getCameraInstance();
CamStatus state;
uint16_t gainValue = 0;
uint32_t exposureValue = 0;
uint32_t exposureLen1 = 0;
uint32_t exposureLen2 = 0;
uint32_t exposureLen3 = 0;

uint8_t cameraResolution = cameraInstance->currentPictureMode;
uint8_t cameraFarmat = cameraInstance->currentPixelFormat;
switch (commandBuff[0]) {
case SET_PICTURE_RESOLUTION: // Set Camera Resolution
cameraResolution = commandBuff[1] & 0x0f;
cameraFarmat = (commandBuff[1] & 0x70) >> 4;
myCAM->takePicture((CAM_IMAGE_MODE)cameraResolution, (CAM_IMAGE_PIX_FMT)cameraFarmat);
break;
case SET_VIDEO_RESOLUTION: // Set Video Resolution
cameraResolution = commandBuff[1] & 0x0f;
state = myCAM->startPreview((CAM_VIDEO_MODE)cameraResolution);
if (state == CAM_ERR_NO_CALLBACK) {
printf("callback function is not registered\n");
}
break;
case SET_BRIGHTNESS: // Set brightness
myCAM->setBrightness((CAM_BRIGHTNESS_LEVEL)commandBuff[1]);
break;
case SET_CONTRAST: // Set Contrast
myCAM->setContrast((CAM_CONTRAST_LEVEL)commandBuff[1]);
break;
case SET_SATURATION: // Set saturation
myCAM->setSaturation((CAM_STAURATION_LEVEL)commandBuff[1]);
break;
case SET_EV: // Set EV
myCAM->setEV((CAM_EV_LEVEL)commandBuff[1]);
break;
case SET_WHITEBALANCE: // Set White balance
myCAM->setAutoWhiteBalanceMode((CAM_WHITE_BALANCE)commandBuff[1]);
break;
case SET_SPECIAL_EFFECTS: // Set Special effects
myCAM->setColorEffect((CAM_COLOR_FX)commandBuff[1]);
break;
case SET_FOCUS_CONTROL: // Focus Control
myCAM->setAutoFocus(commandBuff[1]);
if (commandBuff[1] == 0) {
myCAM->setAutoFocus(0x02);
}
break;
case SET_EXPOSUREANDGAIN_CONTROL: // exposure and Gain control
myCAM->setAutoExposure(commandBuff[1] & 0x01);
myCAM->setAutoISOSensitive(commandBuff[1] & 0x01);
break;
case SET_WHILEBALANCE_CONTROL: // while balance control
myCAM->setAutoWhiteBalance(commandBuff[1] & 0x01);
break;
case SET_SHARPNESS:
myCAM->setSharpness((CAM_SHARPNESS_LEVEL)commandBuff[1]);
break;
case SET_MANUAL_GAIN: // manual gain control
gainValue = (commandBuff[1] << 8) | commandBuff[2];
myCAM->setISOSensitivity(gainValue);
break;
case SET_MANUAL_EXPOSURE: // manual exposure control
exposureLen1 = commandBuff[1];
exposureLen2 = commandBuff[2];
exposureLen3 = commandBuff[3];
exposureValue = (exposureLen1 << 16) | (exposureLen2 << 8) | exposureLen3;
myCAM->setAbsoluteExposure(exposureValue);
break;
case GET_CAMERA_INFO: // Get Camera info
reportCameraInfo(myCAM);
break;
case TAKE_PICTURE:
myCAM->takePicture((CAM_IMAGE_MODE)cameraResolution, (CAM_IMAGE_PIX_FMT)cameraFarmat);
cameraGetPicture(myCAM);
break;
case DEBUG_WRITE_REGISTER:
myCAM->debugWriteRegister(commandBuff + 1);
break;
case STOP_STREAM:
myCAM->stopPreview();
break;
case GET_FRM_VER_INFO: // Get Firmware version info
reportVerInfo(myCAM);
break;
case GET_SDK_VER_INFO: // Get sdk version info
reportSdkVerInfo(myCAM);
break;
case RESET_CAMERA:
myCAM->reset();
case SET_IMAGE_QUALITY:
myCAM->setImageQuality((IMAGE_QUALITY)commandBuff[1]);
default:
break;
}
return CAM_ERR_SUCCESS;
}

void ArducamLink::arducamUartWrite(uint8_t data)
{
SerialWrite(data);
delayUs(12);
}

void ArducamLink::arducamUartWriteBuff(uint8_t* buff, uint16_t length)
{
// SerialWriteBuff(buff, length);
// delayUs(12);
for (uint16_t i = 0; i < length; i++)
arducamUartWrite(buff[i]);
}

void ArducamLink::printf(char* buff)
{
uint16_t len = strlen(buff);
// SerialPrintf(buff);
// delayUs(12);
arducamUartWriteBuff((uint8_t*)buff, len);
}

uint32_t ArducamLink::arducamUartAvailable(void)
{
return SerialAvailable();
}

uint8_t ArducamLink::arducamUartRead(void)
{
return SerialRead();
}

void ArducamLink::arducamFlush(void)
{
while (arducamUartAvailable()) {
arducamUartRead();
}
}
64 changes: 64 additions & 0 deletions examples/ArduinoProtentaC33/full_featured/ArducamLink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* This file is part of the Arducam SPI Camera project.
*
* Copyright 2021 Arducam Technology co., Ltd. All Rights Reserved.
*
* This work is licensed under the MIT license, see the file LICENSE for details.
*
*/
#ifndef __ARDUCAMLINK_H
#define __ARDUCAMLINK_H
#include "Arducam_Mega.h"
#include "stdint.h"

#define RESET_CAMERA 0XFF
#define SET_PICTURE_RESOLUTION 0X01
#define SET_VIDEO_RESOLUTION 0X02
#define SET_BRIGHTNESS 0X03
#define SET_CONTRAST 0X04
#define SET_SATURATION 0X05
#define SET_EV 0X06
#define SET_WHITEBALANCE 0X07
#define SET_SPECIAL_EFFECTS 0X08
#define SET_FOCUS_CONTROL 0X09
#define SET_EXPOSUREANDGAIN_CONTROL 0X0A
// #define SET_GAIN_CONTROL 0X0B
#define SET_WHILEBALANCE_CONTROL 0X0C
#define SET_MANUAL_GAIN 0X0D
#define SET_MANUAL_EXPOSURE 0X0E
#define GET_CAMERA_INFO 0X0F
#define TAKE_PICTURE 0X10
#define SET_SHARPNESS 0X11
#define DEBUG_WRITE_REGISTER 0X12
#define STOP_STREAM 0X21
#define GET_FRM_VER_INFO 0X30
#define GET_SDK_VER_INFO 0X40
#define SET_IMAGE_QUALITY 0X50

#define READ_IMAGE_LENGTH 255

class ArducamLink
{
public:
uint8_t uartCommandProcessing(Arducam_Mega*, uint8_t*);

public:
ArducamLink();
~ArducamLink();
void arducamUartBegin(uint32_t);
void reportCameraInfo(Arducam_Mega*);
void reportVerInfo(Arducam_Mega* myCamera);
void reportSdkVerInfo(Arducam_Mega* myCamera);
void cameraGetPicture(Arducam_Mega*);
void arducamFlush(void);
void send_data_pack(char cmd_type, char* msg);

public:
void printf(char* buff);
void arducamUartWrite(uint8_t);
void arducamUartWriteBuff(uint8_t*, uint16_t);
uint32_t arducamUartAvailable(void);
uint8_t arducamUartRead(void);
};

#endif /*__ARDUCAMLINK_H*/
12 changes: 12 additions & 0 deletions examples/ArduinoProtentaC33/full_featured/ArducamUart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __ARDUCAM_SLOT_H
#define __ARDUCAM_SLOT_H
#include <Arduino.h>

#define SerialBegin(baudRate) Serial.begin(baudRate)
#define SerialWrite(ch) Serial.write(ch)
#define SerialWriteBuff(buf, len) Serial.write(buf, len)
#define SerialPrintf(str) Serial.print(str)
#define SerialAvailable() Serial.available()
#define SerialRead() Serial.read()
#define delayUs(us) delayMicroseconds(us)
#endif
Loading

0 comments on commit 22477c3

Please sign in to comment.